sys_local.cpp (7347B)
1 /* 2 =========================================================================== 3 4 Doom 3 BFG Edition GPL Source Code 5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). 8 9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 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. 23 24 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. 25 26 =========================================================================== 27 */ 28 29 #pragma hdrstop 30 #include "../idlib/precompiled.h" 31 #include "sys_local.h" 32 33 const char * sysLanguageNames[] = { 34 ID_LANG_ENGLISH, ID_LANG_FRENCH, ID_LANG_ITALIAN, ID_LANG_GERMAN, ID_LANG_SPANISH, ID_LANG_JAPANESE, NULL 35 }; 36 37 const int numLanguages = sizeof( sysLanguageNames ) / sizeof sysLanguageNames[ 0 ] - 1; 38 39 idCVar sys_lang( "sys_lang", ID_LANG_ENGLISH, CVAR_SYSTEM | CVAR_INIT, "", sysLanguageNames, idCmdSystem::ArgCompletion_String<sysLanguageNames> ); 40 41 idSysLocal sysLocal; 42 idSys * sys = &sysLocal; 43 44 void idSysLocal::DebugPrintf( const char *fmt, ... ) { 45 va_list argptr; 46 47 va_start( argptr, fmt ); 48 Sys_DebugVPrintf( fmt, argptr ); 49 va_end( argptr ); 50 } 51 52 void idSysLocal::DebugVPrintf( const char *fmt, va_list arg ) { 53 Sys_DebugVPrintf( fmt, arg ); 54 } 55 56 double idSysLocal::GetClockTicks() { 57 return Sys_GetClockTicks(); 58 } 59 60 double idSysLocal::ClockTicksPerSecond() { 61 return Sys_ClockTicksPerSecond(); 62 } 63 64 cpuid_t idSysLocal::GetProcessorId() { 65 return Sys_GetProcessorId(); 66 } 67 68 const char *idSysLocal::GetProcessorString() { 69 return Sys_GetProcessorString(); 70 } 71 72 const char *idSysLocal::FPU_GetState() { 73 return Sys_FPU_GetState(); 74 } 75 76 bool idSysLocal::FPU_StackIsEmpty() { 77 return Sys_FPU_StackIsEmpty(); 78 } 79 80 void idSysLocal::FPU_SetFTZ( bool enable ) { 81 Sys_FPU_SetFTZ( enable ); 82 } 83 84 void idSysLocal::FPU_SetDAZ( bool enable ) { 85 Sys_FPU_SetDAZ( enable ); 86 } 87 88 bool idSysLocal::LockMemory( void *ptr, int bytes ) { 89 return Sys_LockMemory( ptr, bytes ); 90 } 91 92 bool idSysLocal::UnlockMemory( void *ptr, int bytes ) { 93 return Sys_UnlockMemory( ptr, bytes ); 94 } 95 96 void idSysLocal::GetCallStack( address_t *callStack, const int callStackSize ) { 97 Sys_GetCallStack( callStack, callStackSize ); 98 } 99 100 const char * idSysLocal::GetCallStackStr( const address_t *callStack, const int callStackSize ) { 101 return Sys_GetCallStackStr( callStack, callStackSize ); 102 } 103 104 const char * idSysLocal::GetCallStackCurStr( int depth ) { 105 return Sys_GetCallStackCurStr( depth ); 106 } 107 108 void idSysLocal::ShutdownSymbols() { 109 Sys_ShutdownSymbols(); 110 } 111 112 int idSysLocal::DLL_Load( const char *dllName ) { 113 return Sys_DLL_Load( dllName ); 114 } 115 116 void *idSysLocal::DLL_GetProcAddress( int dllHandle, const char *procName ) { 117 return Sys_DLL_GetProcAddress( dllHandle, procName ); 118 } 119 120 void idSysLocal::DLL_Unload( int dllHandle ) { 121 Sys_DLL_Unload( dllHandle ); 122 } 123 124 void idSysLocal::DLL_GetFileName( const char *baseName, char *dllName, int maxLength ) { 125 idStr::snPrintf( dllName, maxLength, "%s" CPUSTRING ".dll", baseName ); 126 } 127 128 sysEvent_t idSysLocal::GenerateMouseButtonEvent( int button, bool down ) { 129 sysEvent_t ev; 130 ev.evType = SE_KEY; 131 ev.evValue = K_MOUSE1 + button - 1; 132 ev.evValue2 = down; 133 ev.evPtrLength = 0; 134 ev.evPtr = NULL; 135 return ev; 136 } 137 138 sysEvent_t idSysLocal::GenerateMouseMoveEvent( int deltax, int deltay ) { 139 sysEvent_t ev; 140 ev.evType = SE_MOUSE; 141 ev.evValue = deltax; 142 ev.evValue2 = deltay; 143 ev.evPtrLength = 0; 144 ev.evPtr = NULL; 145 return ev; 146 } 147 148 void idSysLocal::FPU_EnableExceptions( int exceptions ) { 149 Sys_FPU_EnableExceptions( exceptions ); 150 } 151 152 /* 153 ================= 154 Sys_TimeStampToStr 155 ================= 156 */ 157 const char *Sys_TimeStampToStr( ID_TIME_T timeStamp ) { 158 static char timeString[MAX_STRING_CHARS]; 159 timeString[0] = '\0'; 160 161 time_t ts = (time_t)timeStamp; 162 tm* time = localtime( &ts ); 163 if ( time == NULL ) { 164 return "??/??/???? ??:??"; 165 } 166 167 idStr out; 168 169 idStr lang = cvarSystem->GetCVarString( "sys_lang" ); 170 if ( lang.Icmp( ID_LANG_ENGLISH ) == 0 ) { 171 // english gets "month/day/year hour:min" + "am" or "pm" 172 out = va( "%02d", time->tm_mon + 1 ); 173 out += "/"; 174 out += va( "%02d", time->tm_mday ); 175 out += "/"; 176 out += va( "%d", time->tm_year + 1900 ); 177 out += " "; // changed to spaces since flash doesn't recognize \t 178 if ( time->tm_hour > 12 ) { 179 out += va( "%02d", time->tm_hour - 12 ); 180 } else if ( time->tm_hour == 0 ) { 181 out += "12"; 182 } else { 183 out += va( "%02d", time->tm_hour ); 184 } 185 out += ":"; 186 out +=va( "%02d", time->tm_min ); 187 if ( time->tm_hour >= 12 ) { 188 out += "pm"; 189 } else { 190 out += "am"; 191 } 192 } else { 193 // europeans get "day/month/year 24hour:min" 194 out = va( "%02d", time->tm_mday ); 195 out += "/"; 196 out += va( "%02d", time->tm_mon + 1 ); 197 out += "/"; 198 out += va( "%d", time->tm_year + 1900 ); 199 out += " "; // changed to spaces since flash doesn't recognize \t 200 out += va( "%02d", time->tm_hour ); 201 out += ":"; 202 out += va( "%02d", time->tm_min ); 203 } 204 idStr::Copynz( timeString, out, sizeof( timeString ) ); 205 206 return timeString; 207 } 208 209 /* 210 ======================== 211 Sys_SecToStr 212 ======================== 213 */ 214 const char * Sys_SecToStr( int sec ) { 215 static char timeString[MAX_STRING_CHARS]; 216 217 int weeks = sec / ( 3600 * 24 * 7 ); 218 sec -= weeks * ( 3600 * 24 * 7 ); 219 220 int days = sec / ( 3600 * 24 ); 221 sec -= days * ( 3600 * 24 ); 222 223 int hours = sec / 3600; 224 sec -= hours * 3600; 225 226 int min = sec / 60; 227 sec -= min * 60; 228 229 if ( weeks > 0 ) { 230 sprintf( timeString, "%dw, %dd, %d:%02d:%02d", weeks, days, hours, min, sec ); 231 } else if ( days > 0 ) { 232 sprintf( timeString, "%dd, %d:%02d:%02d", days, hours, min, sec ); 233 } else { 234 sprintf( timeString, "%d:%02d:%02d", hours, min, sec ); 235 } 236 237 return timeString; 238 } 239 240 // return number of supported languages 241 int Sys_NumLangs() { 242 return numLanguages; 243 } 244 245 // get language name by index 246 const char * Sys_Lang( int idx ) { 247 if ( idx >= 0 && idx < numLanguages ) { 248 return sysLanguageNames[ idx ]; 249 } 250 return ""; 251 } 252 253 const char * Sys_DefaultLanguage() { 254 // sku breakdowns are as follows 255 // EFIGS Digital 256 // EF S North America 257 // FIGS EU 258 // E UK 259 // JE Japan 260 261 // If japanese exists, default to japanese 262 // else if english exists, defaults to english 263 // otherwise, french 264 265 if ( !fileSystem->UsingResourceFiles() ) { 266 return ID_LANG_ENGLISH; 267 } 268 269 return ID_LANG_ENGLISH; 270 }