Пример #1
0
int main(int argc, char* argv[])
{
   // default configuration filename
   std::string configFilename = "configs/senderUdpBroadcast.edl";
   // parse command line arguments
   for (int i = 1; i < argc; i++) {
      if ( std::string(argv[i]) == "-f" ) {
         configFilename = argv[++i];
      }
   }

   // build an endpoint
   Endpoint* endpoint = builder(configFilename);

   // send a reset event
   std::cout << "Reset event: which will establish the networks." << std::endl;
   endpoint->event(oe::base::Component::RESET_EVENT);

   // system time of day
   const double dt = 1.0 / static_cast<double>(UPDATE_RATE);   // Delta time
   double simTime = 0.0;                         // Simulator time reference
   double startTime = oe::base::getComputerTime();   // Time of day (sec) run started

   // main loop
   std::cout << "Starting main loop ..." << std::endl;
   for(;;) {

      endpoint->updateTC( static_cast<double>(dt) );
      endpoint->updateData( static_cast<double>(dt) );

      simTime += dt;                             // time of next frame
      double timeNow = oe::base::getComputerTime();  // time now

      double elapsedTime = timeNow - startTime;
      double nextFrameStart = simTime - elapsedTime;
      const auto sleepTime = static_cast<int>(nextFrameStart*1000.0);

      // wait for the next frame
      if (sleepTime > 0)
         oe::base::msleep(sleepTime);
   }

   return EXIT_SUCCESS;
}