sys_local.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition 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 BFG Edition 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. #pragma hdrstop
  21. #include "../idlib/precompiled.h"
  22. #include "sys_local.h"
  23. const char * sysLanguageNames[] = {
  24. ID_LANG_ENGLISH, ID_LANG_FRENCH, ID_LANG_ITALIAN, ID_LANG_GERMAN, ID_LANG_SPANISH, ID_LANG_JAPANESE, NULL
  25. };
  26. const int numLanguages = sizeof( sysLanguageNames ) / sizeof sysLanguageNames[ 0 ] - 1;
  27. idCVar sys_lang( "sys_lang", ID_LANG_ENGLISH, CVAR_SYSTEM | CVAR_INIT, "", 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() {
  40. return Sys_GetClockTicks();
  41. }
  42. double idSysLocal::ClockTicksPerSecond() {
  43. return Sys_ClockTicksPerSecond();
  44. }
  45. cpuid_t idSysLocal::GetProcessorId() {
  46. return Sys_GetProcessorId();
  47. }
  48. const char *idSysLocal::GetProcessorString() {
  49. return Sys_GetProcessorString();
  50. }
  51. const char *idSysLocal::FPU_GetState() {
  52. return Sys_FPU_GetState();
  53. }
  54. bool idSysLocal::FPU_StackIsEmpty() {
  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() {
  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. idStr::snPrintf( dllName, maxLength, "%s" CPUSTRING ".dll", baseName );
  92. }
  93. sysEvent_t idSysLocal::GenerateMouseButtonEvent( int button, bool down ) {
  94. sysEvent_t ev;
  95. ev.evType = SE_KEY;
  96. ev.evValue = K_MOUSE1 + button - 1;
  97. ev.evValue2 = down;
  98. ev.evPtrLength = 0;
  99. ev.evPtr = NULL;
  100. return ev;
  101. }
  102. sysEvent_t idSysLocal::GenerateMouseMoveEvent( int deltax, int deltay ) {
  103. sysEvent_t ev;
  104. ev.evType = SE_MOUSE;
  105. ev.evValue = deltax;
  106. ev.evValue2 = deltay;
  107. ev.evPtrLength = 0;
  108. ev.evPtr = NULL;
  109. return ev;
  110. }
  111. void idSysLocal::FPU_EnableExceptions( int exceptions ) {
  112. Sys_FPU_EnableExceptions( exceptions );
  113. }
  114. /*
  115. =================
  116. Sys_TimeStampToStr
  117. =================
  118. */
  119. const char *Sys_TimeStampToStr( ID_TIME_T timeStamp ) {
  120. static char timeString[MAX_STRING_CHARS];
  121. timeString[0] = '\0';
  122. time_t ts = (time_t)timeStamp;
  123. tm* time = localtime( &ts );
  124. if ( time == NULL ) {
  125. return "??/??/???? ??:??";
  126. }
  127. idStr out;
  128. idStr lang = cvarSystem->GetCVarString( "sys_lang" );
  129. if ( lang.Icmp( ID_LANG_ENGLISH ) == 0 ) {
  130. // english gets "month/day/year hour:min" + "am" or "pm"
  131. out = va( "%02d", time->tm_mon + 1 );
  132. out += "/";
  133. out += va( "%02d", time->tm_mday );
  134. out += "/";
  135. out += va( "%d", time->tm_year + 1900 );
  136. out += " "; // changed to spaces since flash doesn't recognize \t
  137. if ( time->tm_hour > 12 ) {
  138. out += va( "%02d", time->tm_hour - 12 );
  139. } else if ( time->tm_hour == 0 ) {
  140. out += "12";
  141. } else {
  142. out += va( "%02d", time->tm_hour );
  143. }
  144. out += ":";
  145. out +=va( "%02d", time->tm_min );
  146. if ( time->tm_hour >= 12 ) {
  147. out += "pm";
  148. } else {
  149. out += "am";
  150. }
  151. } else {
  152. // europeans get "day/month/year 24hour:min"
  153. out = va( "%02d", time->tm_mday );
  154. out += "/";
  155. out += va( "%02d", time->tm_mon + 1 );
  156. out += "/";
  157. out += va( "%d", time->tm_year + 1900 );
  158. out += " "; // changed to spaces since flash doesn't recognize \t
  159. out += va( "%02d", time->tm_hour );
  160. out += ":";
  161. out += va( "%02d", time->tm_min );
  162. }
  163. idStr::Copynz( timeString, out, sizeof( timeString ) );
  164. return timeString;
  165. }
  166. /*
  167. ========================
  168. Sys_SecToStr
  169. ========================
  170. */
  171. const char * Sys_SecToStr( int sec ) {
  172. static char timeString[MAX_STRING_CHARS];
  173. int weeks = sec / ( 3600 * 24 * 7 );
  174. sec -= weeks * ( 3600 * 24 * 7 );
  175. int days = sec / ( 3600 * 24 );
  176. sec -= days * ( 3600 * 24 );
  177. int hours = sec / 3600;
  178. sec -= hours * 3600;
  179. int min = sec / 60;
  180. sec -= min * 60;
  181. if ( weeks > 0 ) {
  182. sprintf( timeString, "%dw, %dd, %d:%02d:%02d", weeks, days, hours, min, sec );
  183. } else if ( days > 0 ) {
  184. sprintf( timeString, "%dd, %d:%02d:%02d", days, hours, min, sec );
  185. } else {
  186. sprintf( timeString, "%d:%02d:%02d", hours, min, sec );
  187. }
  188. return timeString;
  189. }
  190. // return number of supported languages
  191. int Sys_NumLangs() {
  192. return numLanguages;
  193. }
  194. // get language name by index
  195. const char * Sys_Lang( int idx ) {
  196. if ( idx >= 0 && idx < numLanguages ) {
  197. return sysLanguageNames[ idx ];
  198. }
  199. return "";
  200. }
  201. const char * Sys_DefaultLanguage() {
  202. // sku breakdowns are as follows
  203. // EFIGS Digital
  204. // EF S North America
  205. // FIGS EU
  206. // E UK
  207. // JE Japan
  208. // If japanese exists, default to japanese
  209. // else if english exists, defaults to english
  210. // otherwise, french
  211. if ( !fileSystem->UsingResourceFiles() ) {
  212. return ID_LANG_ENGLISH;
  213. }
  214. return ID_LANG_ENGLISH;
  215. }