doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sys_local.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 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.
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 #include "../idlib/precompiled.h"
30 #pragma hdrstop
31 #include "sys_local.h"
32 
33 const char * sysLanguageNames[] = {
34  "english", "spanish", "italian", "german", "french", "russian",
35  "polish", "korean", "japanese", "chinese", NULL
36 };
37 
38 idCVar sys_lang( "sys_lang", "english", CVAR_SYSTEM | CVAR_ARCHIVE, "", sysLanguageNames, idCmdSystem::ArgCompletion_String<sysLanguageNames> );
39 
42 
43 void idSysLocal::DebugPrintf( const char *fmt, ... ) {
44  va_list argptr;
45 
46  va_start( argptr, fmt );
47  Sys_DebugVPrintf( fmt, argptr );
48  va_end( argptr );
49 }
50 
51 void idSysLocal::DebugVPrintf( const char *fmt, va_list arg ) {
52  Sys_DebugVPrintf( fmt, arg );
53 }
54 
55 double idSysLocal::GetClockTicks( void ) {
56  return Sys_GetClockTicks();
57 }
58 
60  return Sys_ClockTicksPerSecond();
61 }
62 
64  return Sys_GetProcessorId();
65 }
66 
67 const char *idSysLocal::GetProcessorString( void ) {
68  return Sys_GetProcessorString();
69 }
70 
71 const char *idSysLocal::FPU_GetState( void ) {
72  return Sys_FPU_GetState();
73 }
74 
76  return Sys_FPU_StackIsEmpty();
77 }
78 
79 void idSysLocal::FPU_SetFTZ( bool enable ) {
80  Sys_FPU_SetFTZ( enable );
81 }
82 
83 void idSysLocal::FPU_SetDAZ( bool enable ) {
84  Sys_FPU_SetDAZ( enable );
85 }
86 
87 bool idSysLocal::LockMemory( void *ptr, int bytes ) {
88  return Sys_LockMemory( ptr, bytes );
89 }
90 
91 bool idSysLocal::UnlockMemory( void *ptr, int bytes ) {
92  return Sys_UnlockMemory( ptr, bytes );
93 }
94 
95 void idSysLocal::GetCallStack( address_t *callStack, const int callStackSize ) {
96  Sys_GetCallStack( callStack, callStackSize );
97 }
98 
99 const char * idSysLocal::GetCallStackStr( const address_t *callStack, const int callStackSize ) {
100  return Sys_GetCallStackStr( callStack, callStackSize );
101 }
102 
104  return Sys_GetCallStackCurStr( depth );
105 }
106 
109 }
110 
111 int idSysLocal::DLL_Load( const char *dllName ) {
112  return Sys_DLL_Load( dllName );
113 }
114 
115 void *idSysLocal::DLL_GetProcAddress( int dllHandle, const char *procName ) {
116  return Sys_DLL_GetProcAddress( dllHandle, procName );
117 }
118 
119 void idSysLocal::DLL_Unload( int dllHandle ) {
120  Sys_DLL_Unload( dllHandle );
121 }
122 
123 void idSysLocal::DLL_GetFileName( const char *baseName, char *dllName, int maxLength ) {
124 #ifdef _WIN32
125  idStr::snPrintf( dllName, maxLength, "%s" CPUSTRING ".dll", baseName );
126 #elif defined( __linux__ )
127  idStr::snPrintf( dllName, maxLength, "%s" CPUSTRING ".so", baseName );
128 #elif defined( MACOS_X )
129  idStr::snPrintf( dllName, maxLength, "%s" ".dylib", baseName );
130 #else
131 #error OS define is required
132 #endif
133 }
134 
136  sysEvent_t ev;
137  ev.evType = SE_KEY;
138  ev.evValue = K_MOUSE1 + button - 1;
139  ev.evValue2 = down;
140  ev.evPtrLength = 0;
141  ev.evPtr = NULL;
142  return ev;
143 }
144 
146  sysEvent_t ev;
147  ev.evType = SE_MOUSE;
148  ev.evValue = deltax;
149  ev.evValue2 = deltay;
150  ev.evPtrLength = 0;
151  ev.evPtr = NULL;
152  return ev;
153 }
154 
155 void idSysLocal::FPU_EnableExceptions( int exceptions ) {
156  Sys_FPU_EnableExceptions( exceptions );
157 }
158 
159 /*
160 =================
161 Sys_TimeStampToStr
162 =================
163 */
164 const char *Sys_TimeStampToStr( ID_TIME_T timeStamp ) {
165  static char timeString[MAX_STRING_CHARS];
166  timeString[0] = '\0';
167 
168  tm* time = localtime( &timeStamp );
169  idStr out;
170 
171  idStr lang = cvarSystem->GetCVarString( "sys_lang" );
172  if ( lang.Icmp( "english" ) == 0 ) {
173  // english gets "month/day/year hour:min" + "am" or "pm"
174  out = va( "%02d", time->tm_mon + 1 );
175  out += "/";
176  out += va( "%02d", time->tm_mday );
177  out += "/";
178  out += va( "%d", time->tm_year + 1900 );
179  out += "\t";
180  if ( time->tm_hour > 12 ) {
181  out += va( "%02d", time->tm_hour - 12 );
182  } else if ( time->tm_hour == 0 ) {
183  out += "12";
184  } else {
185  out += va( "%02d", time->tm_hour );
186  }
187  out += ":";
188  out +=va( "%02d", time->tm_min );
189  if ( time->tm_hour >= 12 ) {
190  out += "pm";
191  } else {
192  out += "am";
193  }
194  } else {
195  // europeans get "day/month/year 24hour:min"
196  out = va( "%02d", time->tm_mday );
197  out += "/";
198  out += va( "%02d", time->tm_mon + 1 );
199  out += "/";
200  out += va( "%d", time->tm_year + 1900 );
201  out += "\t";
202  out += va( "%02d", time->tm_hour );
203  out += ":";
204  out += va( "%02d", time->tm_min );
205  }
206  idStr::Copynz( timeString, out, sizeof( timeString ) );
207 
208  return timeString;
209 }
210 
virtual double GetClockTicks(void)
Definition: sys_local.cpp:55
static int snPrintf(char *dest, int size, const char *fmt,...) id_attribute((format(printf
Definition: Str.cpp:1465
double Sys_ClockTicksPerSecond(void)
Definition: main.cpp:283
virtual const char * GetProcessorString(void)
Definition: sys_local.cpp:67
int evPtrLength
Definition: sys_public.h:219
virtual const char * GetCallStackCurStr(int depth)
Definition: sys_local.cpp:103
idCVarSystem * cvarSystem
Definition: CVarSystem.cpp:487
double Sys_GetClockTicks(void)
Definition: main.cpp:245
virtual void DLL_Unload(int dllHandle)
Definition: sys_local.cpp:119
const char * sysLanguageNames[]
Definition: sys_local.cpp:33
virtual sysEvent_t GenerateMouseButtonEvent(int button, bool down)
Definition: sys_local.cpp:135
void Sys_FPU_EnableExceptions(int exceptions)
Definition: main.cpp:227
const char * Sys_GetCallStackStr(const address_t *callStack, int callStackSize)
Definition: stack.cpp:100
idCVar sys_lang("sys_lang","english", CVAR_SYSTEM|CVAR_ARCHIVE,"", sysLanguageNames, idCmdSystem::ArgCompletion_String< sysLanguageNames >)
virtual double ClockTicksPerSecond(void)
Definition: sys_local.cpp:59
virtual void * DLL_GetProcAddress(int dllHandle, const char *procName)
Definition: sys_local.cpp:115
void Sys_DLL_Unload(int handle)
Definition: posix_main.cpp:415
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glext.h:2878
void Sys_FPU_SetDAZ(bool enable)
Definition: main.cpp:475
virtual cpuid_t GetProcessorId(void)
Definition: sys_local.cpp:63
virtual void FPU_SetDAZ(bool enable)
Definition: sys_local.cpp:83
virtual const char * FPU_GetState(void)
Definition: sys_local.cpp:71
const char * Sys_FPU_GetState(void)
Definition: posix_main.cpp:478
int Icmp(const char *text) const
Definition: Str.h:667
bool Sys_UnlockMemory(void *ptr, int bytes)
Definition: posix_main.cpp:499
int Sys_DLL_Load(const char *path)
Definition: posix_main.cpp:388
void * evPtr
Definition: sys_public.h:220
virtual bool LockMemory(void *ptr, int bytes)
Definition: sys_local.cpp:87
bool Sys_FPU_StackIsEmpty(void)
Definition: posix_main.cpp:471
virtual void ShutdownSymbols(void)
Definition: sys_local.cpp:107
#define MAX_STRING_CHARS
Definition: Lib.h:95
#define NULL
Definition: Lib.h:88
virtual const char * GetCVarString(const char *name) const =0
cpuid_t
Definition: sys_public.h:142
void * Sys_DLL_GetProcAddress(int handle, const char *sym)
Definition: posix_main.cpp:401
int evValue2
Definition: sys_public.h:218
virtual bool UnlockMemory(void *ptr, int bytes)
Definition: sys_local.cpp:91
static void Copynz(char *dest, const char *src, int destsize)
Definition: Str.cpp:1376
void Sys_GetCallStack(address_t *callStack, const int callStackSize)
Definition: stack.cpp:87
bool Sys_LockMemory(void *ptr, int bytes)
Definition: posix_main.cpp:490
idSysLocal sysLocal
Definition: sys_local.cpp:40
virtual const char * GetCallStackStr(const address_t *callStack, const int callStackSize)
Definition: sys_local.cpp:99
virtual void FPU_SetFTZ(bool enable)
Definition: sys_local.cpp:79
sysEventType_t evType
Definition: sys_public.h:216
void Sys_ShutdownSymbols(void)
Definition: stack.cpp:35
virtual bool FPU_StackIsEmpty(void)
Definition: sys_local.cpp:75
const char * Sys_GetProcessorString(void)
Definition: main.cpp:218
virtual sysEvent_t GenerateMouseMoveEvent(int deltax, int deltay)
Definition: sys_local.cpp:145
virtual int DLL_Load(const char *dllName)
Definition: sys_local.cpp:111
void Sys_DebugVPrintf(const char *fmt, va_list arg)
Definition: Str.h:116
const char * Sys_GetCallStackCurStr(int depth)
Definition: stack.cpp:120
const char * Sys_TimeStampToStr(ID_TIME_T timeStamp)
Definition: sys_local.cpp:164
GLsizei maxLength
Definition: glext.h:3627
virtual void FPU_EnableExceptions(int exceptions)
Definition: sys_local.cpp:155
void Sys_FPU_SetFTZ(bool enable)
Definition: main.cpp:498
idSys * sys
Definition: sys_local.cpp:41
virtual void virtual void DebugVPrintf(const char *fmt, va_list arg)
Definition: sys_local.cpp:51
unsigned long address_t
Definition: sys_public.h:234
char * va(const char *fmt,...)
Definition: Str.cpp:1568
struct tm * localtime(const time_t *)
virtual void DebugPrintf(const char *fmt,...) id_attribute((format(printf
Definition: sys_local.cpp:43
virtual void GetCallStack(address_t *callStack, const int callStackSize)
Definition: sys_local.cpp:95
cpuid_t Sys_GetProcessorId(void)
Definition: main.cpp:209
virtual void DLL_GetFileName(const char *baseName, char *dllName, int maxLength)
Definition: sys_local.cpp:123