random_utils/src/TimeableObject.cpp

Go to the documentation of this file.
00001 #ifdef __APPLE__
00002 #include <GLUT/glut.h>
00003 #else
00004 #include <GL/glut.h>
00005 #endif
00006 
00007 #include <random_utils/TimeableObject.h>
00008 
00009 
00010 namespace random_utils
00011 {
00012 
00013 TimeableObject::TimeableObject()
00014 {
00015     m_state = INITIALIZED;
00016 }
00017 
00018 TimeableObject::~TimeableObject()
00019 {
00020     m_state = SHUTDOWN;
00021 }
00022 
00023 void
00024 TimeableObject::wrapperFunction(int p_self)
00025 {
00026     ((TimeableObject*)p_self)->internalTimerTick();
00027 }
00028 
00029 void
00030 TimeableObject::internalTimerTick()
00031 {
00032     if(m_state == SHUTDOWN)
00033     {
00034         m_state = INITIALIZED;
00035         return;
00036     }
00037 
00038     timerTick();
00039 
00040     if(m_state == RUNNING)
00041         restartTimer();
00042 
00043     else if(m_state == SHUTDOWN)
00044         m_state = INITIALIZED;
00045 }
00046 
00047 void
00048 TimeableObject::startTimer(unsigned int p_milliseconds)
00049 {
00050     m_currentDelay = p_milliseconds;
00051 
00052     if(m_state == RUNNING)
00053         return;
00054 
00055 
00056     if(m_state == SHUTDOWN)
00057         m_state = RUNNING;
00058 
00059     else
00060     {
00061         m_state = RUNNING;
00062 
00063         restartTimer();
00064     }
00065 }
00066 
00067 void
00068 TimeableObject::stopTimer()
00069 {
00070     if(m_state == RUNNING)
00071         m_state = SHUTDOWN;
00072 }
00073 
00074 void
00075 TimeableObject::changeTimer(unsigned int p_milliseconds)
00076 {
00077     m_currentDelay = p_milliseconds;
00078 }
00079 
00080 void
00081 TimeableObject::restartTimer()
00082 {
00083     glutTimerFunc(
00084         m_currentDelay, TimeableObject::wrapperFunction, (int)this);
00085 }
00086 
00087 } // namespace random_utils

Generated on Fri May 11 21:01:58 2007 for Random Racer by  doxygen 1.5.1