void ElevatorSimWindow::pauseSimCB(Fl_Widget* w, void* userData) {
   if(isDebugBuild()) {

      std::stringstream dbgSS;
      dbgSS << "in pauseSimCB with widget ptr " << w
         << " and userData " << userData << std::endl;
      LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
   }

   Fl_Button* pauseButton = (Fl_Button*)w;

   if(pauseButton->value()) {
      if(isDebugBuild()) {
         std::stringstream dbgSS;
         dbgSS << "pauseSimCB fired " << std::endl;
         LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
      }

      if( SimulationState::acquire().togglePause() ) {
         w->label("Resume");
      } else {
         w->label("Pause");
      }
   }
}
Beispiel #2
0
IPersonCarrier::~IPersonCarrier() {
   /* print debug info */
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "with IPersonCarrier @ " << this
               << " with " << people.size()
               << " people. destructing them...\n";

      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer( dbgSS ));
   }

   for(std::unordered_set<Person*>::iterator iter = people.begin();
            iter != people.end();
   ) {
      Person* currentMutablePerson = *iter;
      iter = people.erase(iter++);
      delete currentMutablePerson;
   }

   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "destructing in IPersonCarrier @ " << this
               << " complete" << std::endl;

      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer( dbgSS ));
   }
}
void ElevatorSimWindow::stopSimCB(Fl_Widget* w, void* userData) {
   if(isDebugBuild()) {

      std::stringstream dbgSS;
      dbgSS << "in stopSimCB with widget ptr " << w
               << " and userData " << userData << std::endl;
      LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
   }

   Fl_Button* stopButton = (Fl_Button*) w;
   ElevatorSimWindow* thisWin = (ElevatorSimWindow*) userData;

   if(stopButton->value()) {

      if(isDebugBuild()) {
         std::stringstream dbgSS;
         dbgSS << "stopSimCB fired " << std::endl;
         LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
      }

      SimulationState::acquire().stop();
      thisWin -> resultsWin -> updateChartData();
      thisWin -> resultsWin -> show();
   }
}
   int ElevatorSimRenderWindow::handle(int event) {
      if(isDebugBuild()) {
         printf("RenderWin: event: %s (%d)\n", fl_eventnames[event], event);
      }

      return Fl_Gl_Window::handle(event);
   }
ElevatorSimRenderWindow::~ElevatorSimRenderWindow() {
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "destroying sim render window @ " << this << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer(dbgSS) );
   }
}
void ElevatorSimWindow::updateButtonAvailability() {

   SimulationState& simState = SimulationState::acquire();
   
   if(isDebugBuild()) {
      LOG_INFO( Logger::SUB_FLTK, "updating button availability...");
   }

   switch(simState.getState()) {
   case SimulationState::SIMULATION_RUNNING:
      startButton->deactivate();
      stopButton->activate();
      pauseButton->activate();
      pauseButton->label("Pause");
      break;

   case SimulationState::SIMULATION_READY:
      startButton->activate();
      stopButton->deactivate();
      pauseButton->deactivate();
      break;

   case SimulationState::SIMULATION_PAUSED:
      startButton->deactivate();
      stopButton->activate();
      pauseButton->activate();
      pauseButton->label("Resume");
      break;

   default:

      break;
   }
}
Beispiel #7
0
PyObject* IPersonCarrier::peopleToTuple() const {
   PyObject* peopleTuple = PyTuple_New( people.size() );

   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "created tuple at: " << peopleTuple << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer(dbgSS) );
   }

   if( peopleTuple == NULL || PyErr_Occurred() ) {
      PyErr_Print();
   }

   assert( peopleTuple != NULL );

   int i = 0;
   for( std::unordered_set<Person*>::const_iterator iter = people.begin(); 
      iter != people.end();
      ++iter) {
         Person* const currentPerson = *iter;
         currentPerson->updateTuple();
         PyTuple_SET_ITEM(peopleTuple, i, currentPerson->stealTuple());
         ++i;
   }

   return peopleTuple;
}
ElevatorSimResultsWindow::~ElevatorSimResultsWindow() {
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "finished destroying results window @ " << this << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer(dbgSS) );
   }
}
Beispiel #9
0
void Person::updateTuple() {
   if(pythonRepr != NULL) {
      freeTuple();
   }

   /* convert from logical coordinate to floor ordinal */
   int startFloorOrdinal = startYVal / Floor::YVALS_PER_FLOOR;
   int destFloorOrdinal = destinationYVal / Floor::YVALS_PER_FLOOR;

   pythonRepr = Py_BuildValue("(ii)",
      startFloorOrdinal,
      destFloorOrdinal);

   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "created tuple at: " << pythonRepr << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer(dbgSS) );
   }

   if(PyErr_Occurred()) {
      PyErr_Print();
   }

   assert(pythonRepr != NULL);
}
Beispiel #10
0
Person::~Person() {
   /* print debug info */
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "destructing person @ " << this << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer( dbgSS ));
   }
}
void ElevatorSimWindow::menuOpenCB(Fl_Widget* w, void* userData) {
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "menuNewCB fired with widget ptr " << w
         << "and userData " << userData << std::endl;
      LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
   }
}
int ElevatorSimResultsWindow::handle(int event) {
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS <<  fl_eventnames[event]  << std::endl;
      LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
   }

   return Fl_Window::handle(event);
}
Beispiel #13
0
Floor::~Floor() {
   init();

   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "destructing floor @" << this << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer(dbgSS) );
   }
}
void ElevatorSimWindow::menuHelpCB(Fl_Widget* w, void* userData) {
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "menuHelpCB fired with widget ptr " << w << std::endl;
      LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
   }

   ElevatorSimWindow* thisWindow = (ElevatorSimWindow*) userData;
   thisWindow->helpWin->show();
}
void ElevatorSimWindow::startSimCB(Fl_Widget* w, void* userData) {
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "in startSimCB with widget ptr " << w
               << " and userData " << userData << std::endl;
   }

   Fl_Button* startButton = (Fl_Button*) w;

   if(startButton->value()) {
      if(isDebugBuild() ) {
         std::stringstream dbgSS;
         dbgSS << "startSim CB fired" << std::endl;
      }

      ElevatorSimWindow* thisWindow = (ElevatorSimWindow*) userData;
      thisWindow->startWin->show();
   }
}
/* private static methods */
void ElevatorSimWindow::windowCloseCB(Fl_Window* w, void* userData) {
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "windowCloseCB fired with widget ptr " << w << std::endl;
      LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
   }

   ElevatorSimWindow* thisWin = (ElevatorSimWindow*) userData;
   thisWin->confirmDialog->show();
}
void ElevatorSimWindow::dismissAboutCB(Fl_Widget* w, void* userData) {
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "dismissAboutCB fired with widget " << w << std::endl;
      LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
   }

   ElevatorSimWindow* thisWindow = (ElevatorSimWindow*) userData;
   thisWindow->aboutWin->hide();
}
/* private methods */
int ElevatorSimWindow::handle(int event) {
   int lastKey = Fl::event_key();

   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "MainWin: event: " << fl_eventnames[event] << std::endl;
      LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
   }

   if(event == FL_KEYDOWN) {
      if(lastKey == FL_Escape) {
         confirmDialog->hotspot(15, 15);
         confirmDialog->show();

         return Fl_Window::handle(event);
      } else {
         SimulationState::acquire().getKeyManager().down(lastKey);
         return true;
      }
   } else if (event == FL_KEYUP) {
      SimulationState::acquire().getKeyManager().up(lastKey);
      return true;
   } else if (event == FL_FOCUS) {
      Fl_Window::handle(event);

      if(isDebugBuild()) {
         LOG_INFO(Logger::SUB_FLTK, "after focus event");
      }

      if(welcomeWin->isFirstRun()) {
         welcomeWin->hotspot(15, 15);
         welcomeWin->show();
      }

      /* check simState for which buttons to activate and deactivate */
      updateButtonAvailability();

      return true;
   } else {
      return Fl_Window::handle(event);
   }
}
void ElevatorSimWindow::quitCancelledCB(Fl_Button* noButton, void* userData) {
   if(isDebugBuild()) {

      std::stringstream dbgSS;
      dbgSS << "quitCancelledCB fired with widget ptr " << noButton
         << " and userData " << userData << std::endl;
      LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
   }

   ElevatorSimWindow* thisWin = (ElevatorSimWindow*) userData;
   thisWin->confirmDialog->hide();
}
ElevatorSimWindow::~ElevatorSimWindow() {
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "started to destroy sim window @ " << this << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer(dbgSS) );
   }

   /* de-register the re-draw callback for the render window */
   Fl::remove_timeout(ElevatorSimRenderWindow::timerCB);

   /* free class-local heap-allocated widgets */
   delete stopButton;
   delete pauseButton;
   delete startButton;

   delete aboutDoneButton;
   delete aboutDisplay;
   delete aboutTextBuffer;
   delete aboutWin;

   delete helpDoneButton;
   delete helpLabel;
   delete helpWin;

   delete noButton;
   delete yesButton;
   delete confirmDialog;

   /* free class-extra heap-allocated instances */
   delete startWin;
   delete welcomeWin;
   delete renderWindow;
   delete resultsWin;

   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "finished destroying sim window @ " << this << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer(dbgSS) );
   }
}
ElevatorSimWindow::ElevatorSimWindow() :
   Fl_Window(WINDOW_WIDTH,  WINDOW_HEIGHT, WINDOW_TITLE) {
      renderWindow = new ElevatorSimRenderWindow(
         ElevatorSimRenderWindow::LEFT_MARGIN,
         ElevatorSimRenderWindow::TOP_MARGIN,
         WINDOW_WIDTH -
            (ElevatorSimRenderWindow::LEFT_MARGIN +
            ElevatorSimRenderWindow::RIGHT_MARGIN),
         WINDOW_HEIGHT -
            (ElevatorSimRenderWindow::TOP_MARGIN +
            ElevatorSimRenderWindow::BOTTOM_MARGIN));

      resizable(*renderWindow);
      buildMenu();
      buildButtons();

      /* add more widgets to main window here */

      end();

      buildDialogs();

      welcomeWin = new ElevatorSimWelcomeWindow();
      startWin = new ElevatorSimStartWindow();
      resultsWin = new ElevatorSimResultsWindow();

      /* some hackery to set the application icon in windows */
      #ifdef _ES_WINNT
      HANDLE iconImage = LoadImage(
         GetModuleHandle(NULL),
         MAKEINTRESOURCE(IDI_ELEVATOR_SIM_ICON),
         IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);

      if(iconImage == NULL) {
         std::cout << "warning: failed to load application icon!" << std::endl;
      } else {
         if(isDebugBuild()) {
            std::stringstream dbgSS;
            dbgSS << "loaded app icon OK @ " << (void*)iconImage << std::endl;
            LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
         }

         icon( (const void*) iconImage );
      }
      #endif

      callback((Fl_Callback*)windowCloseCB, this);

      /* add more callbacks to main window here */

      /* initialize any other main window member variables here */
}
Beispiel #22
0
SimulationState::~SimulationState() {
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "starting to destroy simulation state @ " << this << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer(dbgSS) );
   }

   init();

   delete building;

   delete cameraManager;
   delete renderObjs;
   delete keyManager;
   delete timeManager;

   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "finished destroying simulation state @ " << this << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer(dbgSS) );
   }
}
void ElevatorSimWindow::menuQuitCB(Fl_Widget* w, void* userData) {
   if(isDebugBuild()) {

      std::stringstream dbgSS;
      dbgSS << "menuQuitCB fired with widget ptr " << w
         << " and userData " << userData << std::endl;
      LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer(dbgSS) );
   }

   ElevatorSimWindow* thisWin = (ElevatorSimWindow*) userData;
   thisWin->confirmDialog->hotspot(15, 15);
   thisWin->confirmDialog->show();
}
Beispiel #24
0
void Elevator::scheduleAccelsToFloor( const int srcFloor, const int destfloor ) {
   SimulationState& simState = SimulationState::acquire();

   assert(destfloor >= 0 &&
      destfloor < simState.getBuilding().getStories() &&
      srcFloor == (yVal / Floor::YVALS_PER_FLOOR));

   /* height of the target floor in yVals */
   int targetFloorHeight = destfloor *  Floor::YVALS_PER_FLOOR;
   int thisFloorHeight = srcFloor *  Floor::YVALS_PER_FLOOR;

   /* the distance traveled at the maximum speed */
   int maxVelTimeInterval =
      (abs(yVal - targetFloorHeight) - 2 * stoppingDistance) / maxVel;

   /* retrieve current logic clock */
   const int currentTime =
      SimulationState::acquire().getTime();

   /* ensure that the total distance scheduled to be traveled is exactly
    * equal to the different in heights between current and distination */
   assert(maxVelTimeInterval * maxVel + 2 * stoppingDistance ==
      abs(targetFloorHeight - thisFloorHeight));

   /* print debug info */
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "with elevator @ " << this
         << " time t=" << currentTime
         << " a = " << currentAccel << " v = " << currentVel << " y = " << yVal
         << " and " << scheduledAccels.size() << " scheduled accels. " << std::endl;

      LOG_INFO( Logger::SUB_ELEVATOR_LOGIC, sstreamToBuffer( dbgSS ));
   }

   /* push them onto the back of the vector in reverse order */
   scheduledAccels.push_back(
      std::pair<int, int> ( currentTime + 2 * accelTimeInterval + maxVelTimeInterval, 0 ));

   scheduledAccels.push_back(
      std::pair<int, int> ( currentTime + accelTimeInterval + maxVelTimeInterval,
      ( yVal < targetFloorHeight) ? ( -maxAccel ) : ( maxAccel )));

   scheduledAccels.push_back(
      std::pair<int, int> ( currentTime + accelTimeInterval, 0 ));

   scheduledAccels.push_back(
      std::pair<int, int> ( currentTime,
      ( yVal < targetFloorHeight) ? ( maxAccel ) : ( -maxAccel )));
}
int ElevatorSimRenderWindow::handle(int event) {
   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "RenderWin: event: " << fl_eventnames[event] << std::endl;
      LOG_INFO( Logger::SUB_FLTK, sstreamToBuffer( dbgSS ) );
   }

   if( event == FL_PUSH ) {
      rayCasting( Fl::event_x(), Fl::event_y());
      return true;
   } else {
      return Fl_Gl_Window::handle(event);
   }
}
Beispiel #26
0
/* constructors */
Building::Building(unsigned int _nStory, unsigned int _nElevator, int _invPersonArriveProb) :
   gfxScaleHeight(_nStory * cRenderObjs::BUILDING_GAP_HEIGHT),
   gfxScaleWidth(_nElevator * cRenderObjs::ELEV_GAP_WIDTH),
   gfxEachFloorHeight(gfxScaleHeight * 2 / _nStory ),
   gfxEachElevWidth(gfxScaleWidth * 2 / _nElevator),
   invPersonArriveProb(_invPersonArriveProb) {

      if(isDebugBuild()) {
         std::stringstream dbgSS;
         dbgSS << "in Building(" << _nStory << ", " << _nElevator
            << ") with address @" << this << std::endl;
         LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer( dbgSS ));
      }

      floors = std::vector<Floor*> (_nStory);

      for(unsigned int i=0; i < _nStory ; ++i) {
         floors[i] =
            new Floor(
               i * Floor::YVALS_PER_FLOOR,
               i,
               gfxScaleWidth,
               i != _nStory-1,
               i != 0);
      }

      elevators = std::vector<Elevator*> (_nElevator);
      for(unsigned int i=0; i < _nElevator ; ++i ) {
         elevators[i] = new Elevator(0);
      }

      if(isDebugBuild()) {
         std::stringstream dbgSS;
         dbgSS << "finished constructing building @" << this << std::endl;
         LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer( dbgSS ));
      }
}
ElevatorSimRenderWindow::ElevatorSimRenderWindow(
         int X, int Y, int W, int H, const char* Label) :
                              Fl_Gl_Window(X, Y, W, H, Label) {

   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "constructring sim render window @ " << this << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer(dbgSS) );
   }

   spin = 0.0;
   m_bRenderFPS = true;

   GLWindow_width = W;
   GLWindow_height = H;

   Fl::add_timeout(cTimeManager::redrawInterval, timerCB, (void*)this);
   take_focus();
}
Beispiel #28
0
/* constructors */
Person::Person(
   int _startYVal,
   int _destinationYVal,
   enum PRIORITY p) {
      startYVal = _startYVal;
      destinationYVal = _destinationYVal;
      priority = p;

      /* print debug info */
      if(isDebugBuild()) {
         std::stringstream dbgSS;
         dbgSS << "with person @ " << this
            << " start " << startYVal
            << ", dest " << destinationYVal
            << ", pri = " << (int)priority << std::endl;

         LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer( dbgSS ));
      }
}
Beispiel #29
0
/* constructors */
Person::Person(
    Location startLoc,
    Location dest,
    enum PRIORITY p) {
    start = startLoc;
    destination = dest;
    priority = p;

    /* print debug info */
    if(isDebugBuild()) {
        std::stringstream dbgSS;
        dbgSS << "with person @ " << this
              << " start " << start.getYVal()
              << ", dest " << destination.getYVal()
              << ", pri = " << (int)priority << std::endl;

        LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer( dbgSS ));
    }
}
Beispiel #30
0
void cCameraManager::init()
{
   m_vecCamPos.Set(0.f, 0.f, 20.f);
   m_vecCamLookAt.Set(0.f, 0.f, 0.f);
   m_vecCamUp.Set(0.0f, 1.0f, 0.0f);

   Vec3f lookingVec = m_vecCamPos - m_vecCamLookAt;
   Vec3f right = getRight();
   Vec3f::Cross3(m_vecCamUp, right, lookingVec);

   m_fPitchAngle = 0.f;
   m_fYawAngle = 0.f;
   m_fRollAngle = 0.f;

   if(isDebugBuild()) {
      std::stringstream dbgSS;
      dbgSS << "initializing camera manager @" << this << std::endl;
      LOG_INFO( Logger::SUB_MEMORY, sstreamToBuffer( dbgSS ));
   }
}