Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
get_time.hGo to the documentation of this file.00001 #ifndef INCLUDED_get_time_h 00002 #define INCLUDED_get_time_h 00003 00004 #ifdef PLATFORM_APERIOS 00005 00006 //! a simple way to get the current time since boot in milliseconds (see TimeET for better accuracy) 00007 unsigned int get_time(); 00008 00009 //! just to provide compatability with simulator code, this function always returns '1' since we're running in realtime on real hardware 00010 float getTimeScale(); 00011 00012 #else //PLATFORM_LOCAL 00013 00014 //! If we're running locally, these will let users in "project" space control time for simulation 00015 namespace project_get_time { 00016 //! This will default to -1, which signals get_time() to use get_time_callback. Any other value will cause that value to be used instead. 00017 extern unsigned int simulation_time; 00018 //! This by default will return the time in milliseconds since the first call was made. Note this is a function pointer, so you can reassign it to your own implementation! 00019 /*! For instance, the simulator can assign a function which forwards 00020 * the call to SharedGlobals::get_time(), so that all processes get 00021 * consistent time values under control of the simulator 00022 * Note that this is a slightly different usage paradigm than get_timeScale_callback(), which is probably cleaner, but trying to avoid spreading dependency on TimeET.h */ 00023 extern unsigned int (*get_time_callback)(); 00024 00025 /*! @brief You can reassign this to your own implementation if you might play games with time control. 00026 * For instance, the simulator can assign a function which 00027 * simply returns SharedGlobals::timeScale. 00028 * By default this is NULL, which indicates to getTimeScale that it should use the default implementation. 00029 * Note that this is a slightly different usage paradigm than get_time_callback(), which is assumed to always be non-NULL (at least, unless you assign a value to #simulation_time...) */ 00030 extern float (*get_timeScale_callback)(); 00031 } 00032 00033 //! This will call and return project_get_time::get_time_callback if project_get_time::simulation_time is -1. Otherwise simulation_time is returned. 00034 /*! Default values are set such that the system clock will be used, 00035 * and values will range from 0 (first call) onward. However, by 00036 * reassigning project_get_time::get_time_callback to your own 00037 * function, you can control the flow of time however you wish. */ 00038 inline unsigned int get_time() { 00039 if(project_get_time::simulation_time==-1U) 00040 return (*project_get_time::get_time_callback)(); 00041 else 00042 return project_get_time::simulation_time; 00043 } 00044 00045 //! If project_get_time::get_timeScale_callback is NULL, this will return 1 if project_get_time::simulation_time is -1U (the default value), and -1 otherwise. If the callback is available, returns that. 00046 inline float getTimeScale() { 00047 if(project_get_time::get_timeScale_callback) 00048 return (*project_get_time::get_timeScale_callback)(); 00049 else if(project_get_time::simulation_time==-1U) 00050 return 1; 00051 else 00052 return -1; 00053 } 00054 00055 #endif 00056 00057 00058 /*! @file 00059 * @brief prototype for get_time(), a simple way to get the current time since boot in milliseconds 00060 * @author ejt (Creator) 00061 */ 00062 00063 #endif |
Tekkotsu v5.1CVS |
Generated Mon May 9 04:58:41 2016 by Doxygen 1.6.3 |