00001 #ifndef ARCH_HOOKS_H 00002 #define ARCH_HOOKS_H 00003 00004 class ArchHooks 00005 { 00006 public: 00007 /* This is called as soon as SDL is set up, the loading window is shown 00008 * and we can safely log and throw. */ 00009 virtual void DumpDebugInfo() { } 00010 00011 virtual ~ArchHooks() { } 00012 /* This is called once each time through the game loop */ 00013 virtual void Update(float delta) { } 00014 00015 /* Re-exec the game. If this is implemented, it doesn't return. */ 00016 virtual void RestartProgram() { } 00017 00018 /* Call this to temporarily enter a high-priority or realtime scheduling (depending 00019 * on the implementation) mode. This is used to improve timestamp accuracy. Do as 00020 * little as possible in this mode; hanging in it might hang the system entirely. */ 00021 virtual void EnterTimeCriticalSection() { } 00022 virtual void ExitTimeCriticalSection() { } 00023 00024 virtual void SetTime( tm newtime ) { } 00025 00026 /* 00027 * Return the amount of time since the program started. (This may actually be 00028 * since the initialization of HOOKS. 00029 * 00030 * Full microsecond accuracy may not be available. 00031 * 00032 * bAccurate is a hint: it specifies whether to prefer short-term precision 00033 * or long-term accuracy. If false, the implementation may give higher resolution 00034 * results, but not be as stable over long periods (eg. may drift depending on 00035 * clock speed shifts on laptops). If true, lower precision results (usually with 00036 * no less than a 1ms granularity) are returned, but the results should be stable 00037 * over long periods of time. 00038 * 00039 * Note that bAccurate may change the result significantly; it may use a different 00040 * timer, and may have a different concept of when the program "started". 00041 * 00042 * This is a static function, implemented in whichever ArchHooks source is used, 00043 * so it can be used at any time (such as in global constructors), before HOOKS 00044 * is initialized. 00045 * 00046 * RageTimer layers on top of this, and attempts to correct wrapping, as the 00047 * underlying timers may be 32-bit, but implementations should try to avoid 00048 * wrapping if possible. 00049 */ 00050 static int64_t GetMicrosecondsSinceStart( bool bAccurate ); 00051 00052 private: 00053 /* This are helpers for GetMicrosecondsSinceStart on systems with a timer 00054 * that may loop or move backwards. */ 00055 static uint64_t FixupTimeIfLooped( uint64_t usecs ); 00056 static uint64_t FixupTimeIfBackwards( uint64_t usecs ); 00057 }; 00058 00059 ArchHooks *MakeArchHooks(); 00060 00061 #endif 00062 00063 extern ArchHooks *HOOKS; // global and accessable from anywhere in our program 00064 00065 /* 00066 * (c) 2003-2004 Glenn Maynard, Chris Danford 00067 * All rights reserved. 00068 * 00069 * Permission is hereby granted, free of charge, to any person obtaining a 00070 * copy of this software and associated documentation files (the 00071 * "Software"), to deal in the Software without restriction, including 00072 * without limitation the rights to use, copy, modify, merge, publish, 00073 * distribute, and/or sell copies of the Software, and to permit persons to 00074 * whom the Software is furnished to do so, provided that the above 00075 * copyright notice(s) and this permission notice appear in all copies of 00076 * the Software and that both the above copyright notice(s) and this 00077 * permission notice appear in supporting documentation. 00078 * 00079 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00080 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00081 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00082 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00083 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00084 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00085 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00086 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00087 * PERFORMANCE OF THIS SOFTWARE. 00088 */