]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/sys/sys_local.cpp
hello world
[icculus/iodoom3.git] / neo / sys / sys_local.cpp
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
40 idSysLocal                      sysLocal;
41 idSys *                         sys = &sysLocal;
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
59 double idSysLocal::ClockTicksPerSecond( void ) {
60         return Sys_ClockTicksPerSecond();
61 }
62
63 cpuid_t idSysLocal::GetProcessorId( void ) {
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
75 bool idSysLocal::FPU_StackIsEmpty( void ) {
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
103 const char * idSysLocal::GetCallStackCurStr( int depth ) {
104         return Sys_GetCallStackCurStr( depth );
105 }
106
107 void idSysLocal::ShutdownSymbols( void ) {
108         Sys_ShutdownSymbols();
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
135 sysEvent_t idSysLocal::GenerateMouseButtonEvent( int button, bool down ) {
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
145 sysEvent_t idSysLocal::GenerateMouseMoveEvent( int deltax, int deltay ) {
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