source.cc
Go to the documentation of this file.
00001 #include "stage.hh"
00002 using namespace Stg;
00003 
00004 
00005 const double FLAGSZ = 0.25;
00006 
00007 typedef struct 
00008 {
00009   unsigned int capacity;
00010   unsigned int interval;
00011 } info_t;
00012 
00013 int Update( Model* mod, info_t* info )
00014 {
00015   if((  mod->GetWorld()->GetUpdateCount() % info->interval  == 0 )
00016           && ( mod->GetFlagCount() < info->capacity) )
00017                 mod->PushFlag( new Model::Flag( Color( 1,1,0 ), FLAGSZ ) );
00018 
00019   return 0; // run again
00020 }
00021 
00022 void split( const std::string& text, 
00023                                 const std::string& separators, 
00024                                 std::vector<std::string>& words)
00025 {
00026   int n = text.length();
00027   int start, stop;
00028   start = text.find_first_not_of(separators);
00029   while ((start >= 0) && (start < n))
00030          {
00031                 stop = text.find_first_of(separators, start);
00032                 if ((stop < 0) || (stop > n)) stop = n;
00033                 words.push_back(text.substr(start, stop - start));
00034                 start = text.find_first_not_of(separators, stop+1);
00035          }
00036 }
00037 
00038 
00039 // Stage calls this when the model starts up
00040 extern "C" int Init( Model* mod, CtrlArgs* args )
00041 {  
00042   // tokenize the argument string into words
00043   std::vector<std::string> words;
00044   split( args->worldfile, std::string(" \t"), words );
00045   
00046   // expect an interval as the 1th argument
00047   assert( words.size() == 3 );
00048   assert( words[1].size() > 0 );
00049   
00050   info_t* info = new info_t;
00051   info->interval = atoi( words[1].c_str() );
00052   info->capacity = atoi( words[2].c_str() );
00053 
00054   mod->AddCallback( Model::CB_UPDATE, (model_callback_t)Update, info );  
00055   mod->Subscribe();
00056   return 0; //ok
00057 }
00058 


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 Thu Aug 27 2015 15:20:57