sys_local.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "sys_local.h"
  23. const char * sysLanguageNames[] = {
  24. "english", "spanish", "italian", "german", "french", "russian",
  25. "polish", "korean", "japanese", "chinese", NULL
  26. };
  27. idCVar sys_lang( "sys_lang", "english", CVAR_SYSTEM | CVAR_ARCHIVE, "", sysLanguageNames, idCmdSystem::ArgCompletion_String<sysLanguageNames> );
  28. idSysLocal sysLocal;
  29. idSys * sys = &sysLocal;
  30. void idSysLocal::DebugPrintf( const char *fmt, ... ) {
  31. va_list argptr;
  32. va_start( argptr, fmt );
  33. Sys_DebugVPrintf( fmt, argptr );
  34. va_end( argptr );
  35. }
  36. void idSysLocal::DebugVPrintf( const char *fmt, va_list arg ) {
  37. Sys_DebugVPrintf( fmt, arg );
  38. }
  39. double idSysLocal::GetClockTicks( void ) {
  40. return Sys_GetClockTicks();
  41. }
  42. double idSysLocal::ClockTicksPerSecond( void ) {
  43. return Sys_ClockTicksPerSecond();
  44. }
  45. cpuid_t idSysLocal::GetProcessorId( void ) {
  46. return Sys_GetProcessorId();
  47. }
  48. const char *idSysLocal::GetProcessorString( void ) {
  49. return Sys_GetProcessorString();
  50. }
  51. const char *idSysLocal::FPU_GetState( void ) {
  52. return Sys_FPU_GetState();
  53. }
  54. bool idSysLocal::FPU_StackIsEmpty( void ) {
  55. return Sys_FPU_StackIsEmpty();
  56. }
  57. void idSysLocal::FPU_SetFTZ( bool enable ) {
  58. Sys_FPU_SetFTZ( enable );
  59. }
  60. void idSysLocal::FPU_SetDAZ( bool enable ) {
  61. Sys_FPU_SetDAZ( enable );
  62. }
  63. bool idSysLocal::LockMemory( void *ptr, int bytes ) {
  64. return Sys_LockMemory( ptr, bytes );
  65. }
  66. bool idSysLocal::UnlockMemory( void *ptr, int bytes ) {
  67. return Sys_UnlockMemory( ptr, bytes );
  68. }
  69. void idSysLocal::GetCallStack( address_t *callStack, const int callStackSize ) {
  70. Sys_GetCallStack( callStack, callStackSize );
  71. }
  72. const char * idSysLocal::GetCallStackStr( const address_t *callStack, const int callStackSize ) {
  73. return Sys_GetCallStackStr( callStack, callStackSize );
  74. }
  75. const char * idSysLocal::GetCallStackCurStr( int depth ) {
  76. return Sys_GetCallStackCurStr( depth );
  77. }
  78. void idSysLocal::ShutdownSymbols( void ) {
  79. Sys_ShutdownSymbols();
  80. }
  81. int idSysLocal::DLL_Load( const char *dllName ) {
  82. return Sys_DLL_Load( dllName );
  83. }
  84. void *idSysLocal::DLL_GetProcAddress( int dllHandle, const char *procName ) {
  85. return Sys_DLL_GetProcAddress( dllHandle, procName );
  86. }
  87. void idSysLocal::DLL_Unload( int dllHandle ) {
  88. Sys_DLL_Unload( dllHandle );
  89. }
  90. void idSysLocal::DLL_GetFileName( const char *baseName, char *dllName, int maxLength ) {
  91. #ifdef _WIN32
  92. idStr::snPrintf( dllName, maxLength, "%s" CPUSTRING ".dll", baseName );
  93. #elif defined( __linux__ )
  94. idStr::snPrintf( dllName, maxLength, "%s" CPUSTRING ".so", baseName );
  95. #elif defined( MACOS_X )
  96. idStr::snPrintf( dllName, maxLength, "%s" ".dylib", baseName );
  97. #else
  98. #error OS define is required
  99. #endif
  100. }
  101. sysEvent_t idSysLocal::GenerateMouseButtonEvent( int button, bool down ) {
  102. sysEvent_t ev;
  103. ev.evType = SE_KEY;
  104. ev.evValue = K_MOUSE1 + button - 1;
  105. ev.evValue2 = down;
  106. ev.evPtrLength = 0;
  107. ev.evPtr = NULL;
  108. return ev;
  109. }
  110. sysEvent_t idSysLocal::GenerateMouseMoveEvent( int deltax, int deltay ) {
  111. sysEvent_t ev;
  112. ev.evType = SE_MOUSE;
  113. ev.evValue = deltax;
  114. ev.evValue2 = deltay;
  115. ev.evPtrLength = 0;
  116. ev.evPtr = NULL;
  117. return ev;
  118. }
  119. void idSysLocal::FPU_EnableExceptions( int exceptions ) {
  120. Sys_FPU_EnableExceptions( exceptions );
  121. }
  122. /*
  123. =================
  124. Sys_TimeStampToStr
  125. =================
  126. */
  127. const char *Sys_TimeStampToStr( ID_TIME_T timeStamp ) {
  128. static char timeString[MAX_STRING_CHARS];
  129. timeString[0] = '\0';
  130. tm* time = localtime( &timeStamp );
  131. idStr out;
  132. idStr lang = cvarSystem->GetCVarString( "sys_lang" );
  133. if ( lang.Icmp( "english" ) == 0 ) {
  134. // english gets "month/day/year hour:min" + "am" or "pm"
  135. out = va( "%02d", time->tm_mon + 1 );
  136. out += "/";
  137. out += va( "%02d", time->tm_mday );
  138. out += "/";
  139. out += va( "%d", time->tm_year + 1900 );
  140. out += "\t";
  141. if ( time->tm_hour > 12 ) {
  142. out += va( "%02d", time->tm_hour - 12 );
  143. } else if ( time->tm_hour == 0 ) {
  144. out += "12";
  145. } else {
  146. out += va( "%02d", time->tm_hour );
  147. }
  148. out += ":";
  149. out +=va( "%02d", time->tm_min );
  150. if ( time->tm_hour >= 12 ) {
  151. out += "pm";
  152. } else {
  153. out += "am";
  154. }
  155. } else {
  156. // europeans get "day/month/year 24hour:min"
  157. out = va( "%02d", time->tm_mday );
  158. out += "/";
  159. out += va( "%02d", time->tm_mon + 1 );
  160. out += "/";
  161. out += va( "%d", time->tm_year + 1900 );
  162. out += "\t";
  163. out += va( "%02d", time->tm_hour );
  164. out += ":";
  165. out += va( "%02d", time->tm_min );
  166. }
  167. idStr::Copynz( timeString, out, sizeof( timeString ) );
  168. return timeString;
  169. }