swarm-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [swarm-hackers] Re: Swarm, Heatbugs, and forEach loops...


From: Scott Christley
Subject: Re: [swarm-hackers] Re: Swarm, Heatbugs, and forEach loops...
Date: Tue, 10 Nov 2009 08:46:09 -0800

Hey Nima,

Swarm was a written a long time ago before there was a framework like OpenStep available, so it had to implement many of its own collection classes, like List, and as you can see the interface seems somewhat foreign.

My suggestion would be to try changing Heatbugs so that it uses an NSArray instead of List.  Then you can do you operations using standard OpenStep code.  I think making the Heatbugs code look as close as possible to a normal OpenStep application is good.

Otherwise, I think your code is ok.  One major functionality that is missing from the OpenStep version of Swarm is the probe display.  This essentially provides a popup window to do very similar to what you have done, though the probe display is more general and provides display and edit capability to all of a Heatbug's instance variables.

Scott

On Nov 10, 2009, at 5:44 AM, Nima Talebi wrote:

Nevermind, I figured it out.

I've updated my clone of Heatbugs (git tree), which now allows user to interact with the state of the Heatbug agents, changing their idealTemp and outputHeat minimums and maximums.

I did that like so...

- (void)reconfigureHeatbugs {
    [heatbugList forEach:M(setRandomIdealTemperatureInRange:to:) :minIdealTemp :maxIdealTemp];
    [heatbugList forEach:M(setRandomOutputHeatInRange:to:) :minOutputHeat :maxOutputHeat];
}

...and each time the user moves the sliders, MyDocument calls this method...

- (IBAction)setMaxOutputHeat:(id)sender {
    ...
        int tA = min([sender intValue], (int)[sender maxValue] - 100);
        [swarm setMaxOutputHeat:NSInt(tA)];
        
        int tB = min(tA, [[swarm minOutputHeat] intValue]);
        [swarm setMinOutputHeat:NSInt(tB)];
        [minOutputHeat setIntValue:tB];
        [minOutputHeat setNeedsDisplay];
        
        [swarm reconfigureHeatbugs];
   ....
}


...does anyone see anything wrong with that?  I ask because I still feel a little daunted by the amount of code in this framework, so I'm never quite certain that I'm going about things the right way.

Nima

On Tue, Nov 10, 2009 at 9:52 PM, Nima Talebi <address@hidden> wrote:
Hi, I'm a little confused (as I usually am looking at Swarm) on how iteration is supposed to work...

I have added some sliders and input widgets to my own branch of heatbugs, and so each time the user acts on these input widgets, I need to update the state variables stored in each Heatbug object.

For example, I would like to have something like this...

- (void)reconfigureHeatbug:(Heatbug *)hbug;

- (void)reconfigureHeatbugs {
    int i;
    Heatbug *hbug;
    for(i=0; i<numBugs; i++) {
        hbug = [heatbugList objectAtIndex:i];
        [self reconfigureHeatbug:hbug];
    }
}    

Of course that's not possible, as the heatbugList is not an NSArray, it is an id conforming to the <List> protocol.  Looking at surrounding code, I think maybe I'm supposed to do something along the lines of...

- (void)reconfigureHeatbugs {
    id fEAction = [modelActions createActionForEach:heatbugList
                                            message:M(reconfigureHeatbug:)];
}

..but that's obviously wrong since I have no idea what I'm doing - and what is M?

As a side-question - What would make life easier is being able to highlight a function/method/class/whatever in Xcode - say M - then right-click and select 'Jump to definition' - Anyone know how I can get that working?

Nima



--
Nima Talebi
web: http://ai.autonomy.net.au/People/Nima
gpg: B51D 1F18 D8E2 B702 B027 23A4 E06B DAC1 BE70 ADC0
_______________________________________________
swarm-hackers mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/swarm-hackers


reply via email to

[Prev in Thread] Current Thread [Next in Thread]