[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Rao Jinghai <address@hidden>] Help on Selector
From: |
Marcus G. Daniels |
Subject: |
Re: [Rao Jinghai <address@hidden>] Help on Selector |
Date: |
09 Apr 2000 19:47:28 -0700 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
RJ> I need to pass variable i as an argument to the getStrength method
#import <simtools.h>
#import <defobj/Create.h>
#import <simtoolsgui/GUISwarm.h>
#import <analysis.h> // ActiveGraph
#import <gui.h> // Graph, GraphElement
#import <random.h> // uniformDblRand
#define COUNT 12
@interface Database: CreateDrop
{
}
- (double)getAgentValue: (double)offset;
@end
@implementation Database
- (double)getAgentValue: (double)offset
{
return [uniformDblRand getDoubleWithMin: 0.0 withMax: 1.0] + offset;
}
@end
@interface ObserverSwarm: GUISwarm
{
id <Schedule> schedule;
id <Graph> graph;
id <ActiveGraph> graphers[COUNT];
}
- createEnd;
- buildActions;
- step;
@end
@implementation ObserverSwarm
const char *colors[COUNT] = {
"blue", "orange", "yellow", "green",
"red", "purple", "violet", "cyan",
"grey50", "darkgreen", "goldenrod", "seagreen"
};
- createEnd
{
unsigned i;
[super createEnd];
{
id database = [Database create: globalZone];
graph = [Graph create: globalZone];
[graph setTitle: "Graph"];
[graph pack];
for (i = 0; i < COUNT; i++)
{
id <GraphElement> graphElement;
id <ActiveGraph> grapher;
char buf[1 + DSIZE (unsigned) + 1];
graphElement = [graph createElement];
sprintf (buf, "S%u", i);
[graphElement setLabel: buf];
[graphElement setColor: colors[i]];
grapher = [ActiveGraph createBegin: globalZone];
[grapher setElement: graphElement];
[grapher setDataFeed: database];
[grapher setProbedSelector: M(getAgentValue:)];
graphers[i] = [grapher createEnd];
{
char valbuf[DSIZE (unsigned) + 1];
sprintf (valbuf, "%u", i);
[graphers[i] setArg: 0 ToString: valbuf];
}
}
}
return self;
}
- buildActions
{
schedule = [[[Schedule createBegin: self]
setRepeatInterval: 1]
createEnd];
[schedule at: 0 createActionTo: self message: M(step)];
return self;
}
- step
{
unsigned i;
for (i = 0; i < COUNT; i++)
[graphers[i] step];
[actionCache doTkEvents];
return self;
}
- activateIn: swarmContext
{
[super activateIn: swarmContext];
[schedule activateIn: self];
return [self getActivity];
}
@end
int
main (int argc, const char **argv)
{
id observerSwarm;
initSwarm (argc, argv);
observerSwarm = [ObserverSwarm create: globalZone];
[observerSwarm buildObjects];
[observerSwarm buildActions];
[observerSwarm activateIn: nil];
[observerSwarm go];
return 0;
}
/*
Local Variables:
compile-command: "$SWARMHOME/bin/libtool-swarm --mode=link gcc -o activegraph
-Wall -Werror -g -Wno-import -I$SWARMHOME/include/swarm -L$SWARMHOME/lib/swarm
activegraph.m -lswarm -lobjc"
End:
*/
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.