source.cc
Go to the documentation of this file.
1 #include "stage.hh"
2 using namespace Stg;
3 
4 
5 const double FLAGSZ = 0.25;
6 
7 typedef struct
8 {
9  unsigned int capacity;
10  unsigned int interval;
11 } info_t;
12 
13 int Update( Model* mod, info_t* info )
14 {
15  if(( mod->GetWorld()->GetUpdateCount() % info->interval == 0 )
16  && ( mod->GetFlagCount() < info->capacity) )
17  mod->PushFlag( new Model::Flag( Color( 1,1,0 ), FLAGSZ ) );
18 
19  return 0; // run again
20 }
21 
22 void split( const std::string& text,
23  const std::string& separators,
24  std::vector<std::string>& words)
25 {
26  int n = text.length();
27  int start, stop;
28  start = text.find_first_not_of(separators);
29  while ((start >= 0) && (start < n))
30  {
31  stop = text.find_first_of(separators, start);
32  if ((stop < 0) || (stop > n)) stop = n;
33  words.push_back(text.substr(start, stop - start));
34  start = text.find_first_not_of(separators, stop+1);
35  }
36 }
37 
38 
39 // Stage calls this when the model starts up
40 extern "C" int Init( Model* mod, CtrlArgs* args )
41 {
42  // tokenize the argument string into words
43  std::vector<std::string> words;
44  split( args->worldfile, std::string(" \t"), words );
45 
46  // expect an interval as the 1th argument
47  assert( words.size() == 3 );
48  assert( words[1].size() > 0 );
49 
50  info_t* info = new info_t;
51  info->interval = atoi( words[1].c_str() );
52  info->capacity = atoi( words[2].c_str() );
53 
55  mod->Subscribe();
56  return 0; //ok
57 }
58 
Model class
Definition: stage.hh:1742
unsigned int GetFlagCount() const
Definition: stage.hh:2261
The Stage library uses its own namespace.
Definition: canvas.hh:8
const double FLAGSZ
Definition: source.cc:5
void Init(int *argc, char **argv[])
Definition: stage.cc:18
int(* model_callback_t)(Model *mod, void *user)
Definition: stage.hh:568
void split(const std::string &text, const std::string &separators, std::vector< std::string > &words)
Definition: source.cc:22
World * GetWorld() const
Definition: stage.hh:2302
void AddCallback(callback_type_t type, model_callback_t cb, void *user)
int Update(Model *mod, info_t *info)
Definition: source.cc:13
void PushFlag(Flag *flag)
Definition: model.cc:399
void Subscribe()
Definition: model.cc:646
Definition: source.cc:7
unsigned int interval
Definition: source.cc:10
std::string worldfile
Definition: stage.hh:805
unsigned int capacity
Definition: source.cc:9
uint64_t GetUpdateCount() const
Definition: stage.hh:1184


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Jun 10 2019 15:06:09