doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
main.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 #include "../sys/sys_local.h"
31 #pragma hdrstop
32 
33 #include "TypeInfoGen.h"
34 
38 
39 int idEventLoop::JournalLevel( void ) const { return 0; }
40 
41 /*
42 ==============================================================
43 
44  idCommon
45 
46 ==============================================================
47 */
48 
49 #define STDIO_PRINT( pre, post ) \
50  va_list argptr; \
51  va_start( argptr, fmt ); \
52  printf( pre ); \
53  vprintf( fmt, argptr ); \
54  printf( post ); \
55  va_end( argptr )
56 
57 
58 class idCommonLocal : public idCommon {
59 public:
60  idCommonLocal( void ) {}
61 
62  virtual void Init( int argc, const char **argv, const char *cmdline ) {}
63  virtual void Shutdown( void ) {}
64  virtual void Quit( void ) {}
65  virtual bool IsInitialized( void ) const { return true; }
66  virtual void Frame( void ) {}
67  virtual void GUIFrame( bool execCmd, bool network ) {}
68  virtual void Async( void ) {}
69  virtual void StartupVariable( const char *match, bool once ) {}
70  virtual void InitTool( const toolFlag_t tool, const idDict *dict ) {}
71  virtual void ActivateTool( bool active ) {}
72  virtual void WriteConfigToFile( const char *filename ) {}
73  virtual void WriteFlaggedCVarsToFile( const char *filename, int flags, const char *setCmd ) {}
74  virtual void BeginRedirect( char *buffer, int buffersize, void (*flush)( const char * ) ) {}
75  virtual void EndRedirect( void ) {}
76  virtual void SetRefreshOnPrint( bool set ) {}
77  virtual void Printf( const char *fmt, ... ) { STDIO_PRINT( "", "" ); }
78  virtual void VPrintf( const char *fmt, va_list arg ) { vprintf( fmt, arg ); }
79  virtual void DPrintf( const char *fmt, ... ) { /*STDIO_PRINT( "", "" );*/ }
80  virtual void Warning( const char *fmt, ... ) { STDIO_PRINT( "WARNING: ", "\n" ); }
81  virtual void DWarning( const char *fmt, ...) { /*STDIO_PRINT( "WARNING: ", "\n" );*/ }
82  virtual void PrintWarnings( void ) {}
83  virtual void ClearWarnings( const char *reason ) {}
84  virtual void Error( const char *fmt, ... ) { STDIO_PRINT( "ERROR: ", "\n" ); exit(0); }
85  virtual void FatalError( const char *fmt, ... ) { STDIO_PRINT( "FATAL ERROR: ", "\n" ); exit(0); }
86  virtual const idLangDict *GetLanguageDict() { return NULL; }
87  virtual const char * KeysFromBinding( const char *bind ) { return NULL; }
88  virtual const char * BindingFromKey( const char *key ) { return NULL; }
89  virtual int ButtonState( int key ) { return 0; }
90  virtual int KeyState( int key ) { return 0; }
91 };
92 
93 idCVar com_developer( "developer", "0", CVAR_BOOL|CVAR_SYSTEM, "developer mode" );
94 
97 
98 /*
99 ==============================================================
100 
101  idSys
102 
103 ==============================================================
104 */
105 
106 void Sys_Mkdir( const char *path ) {}
107 ID_TIME_T Sys_FileTimeStamp( FILE *fp ) { return 0; }
108 
109 #ifdef _WIN32
110 
111 #include <io.h>
112 #include <direct.h>
113 
114 const char *Sys_Cwd( void ) {
115  static char cwd[1024];
116 
117  _getcwd( cwd, sizeof( cwd ) - 1 );
118  cwd[sizeof( cwd ) - 1] = 0;
119 
120  /*int i = idStr::FindText( cwd, CD_BASEDIR, false );
121  if ( i >= 0 ) {
122  cwd[i + strlen( CD_BASEDIR )] = '\0';
123  }*/
124 
125  return cwd;
126 }
127 
128 const char *Sys_DefaultCDPath( void ) {
129  return "";
130 }
131 
132 const char *Sys_DefaultBasePath( void ) {
133  return Sys_Cwd();
134 }
135 
136 const char *Sys_DefaultSavePath( void ) {
137  return cvarSystem->GetCVarString( "fs_basepath" );
138 }
139 
140 const char *Sys_EXEPath( void ) {
141  return "";
142 }
143 
144 int Sys_ListFiles( const char *directory, const char *extension, idStrList &list ) {
145  idStr search;
146  struct _finddata_t findinfo;
147  int findhandle;
148  int flag;
149 
150  if ( !extension) {
151  extension = "";
152  }
153 
154  // passing a slash as extension will find directories
155  if ( extension[0] == '/' && extension[1] == 0 ) {
156  extension = "";
157  flag = 0;
158  } else {
159  flag = _A_SUBDIR;
160  }
161 
162  sprintf( search, "%s\\*%s", directory, extension );
163 
164  // search
165  list.Clear();
166 
167  findhandle = _findfirst( search, &findinfo );
168  if ( findhandle == -1 ) {
169  return -1;
170  }
171 
172  do {
173  if ( flag ^ ( findinfo.attrib & _A_SUBDIR ) ) {
174  list.Append( findinfo.name );
175  }
176  } while ( _findnext( findhandle, &findinfo ) != -1 );
177 
178  _findclose( findhandle );
179 
180  return list.Num();
181 }
182 
183 #else
184 
185 const char * Sys_DefaultCDPath( void ) { return ""; }
186 const char * Sys_DefaultBasePath( void ) { return ""; }
187 const char * Sys_DefaultSavePath( void ) { return ""; }
188 int Sys_ListFiles( const char *directory, const char *extension, idStrList &list ) { return 0; }
189 
190 #endif
191 
194 
195 void Sys_CreateThread( xthread_t function, void *parms, xthreadPriority priority, xthreadInfo &info, const char *name, xthreadInfo *threads[MAX_THREADS], int *thread_count ) {}
197 
200 
201 void Sys_WaitForEvent( int index ) {}
202 void Sys_TriggerEvent( int index ) {}
203 
204 /*
205 ==============
206 idSysLocal stub
207 ==============
208 */
209 void idSysLocal::DebugPrintf( const char *fmt, ... ) {}
210 void idSysLocal::DebugVPrintf( const char *fmt, va_list arg ) {}
211 
212 double idSysLocal::GetClockTicks( void ) { return 0.0; }
213 double idSysLocal::ClockTicksPerSecond( void ) { return 1.0; }
214 cpuid_t idSysLocal::GetProcessorId( void ) { return (cpuid_t)0; }
215 const char * idSysLocal::GetProcessorString( void ) { return ""; }
216 const char * idSysLocal::FPU_GetState( void ) { return ""; }
217 bool idSysLocal::FPU_StackIsEmpty( void ) { return true; }
218 void idSysLocal::FPU_SetFTZ( bool enable ) {}
219 void idSysLocal::FPU_SetDAZ( bool enable ) {}
220 
221 bool idSysLocal::LockMemory( void *ptr, int bytes ) { return false; }
222 bool idSysLocal::UnlockMemory( void *ptr, int bytes ) { return false; }
223 
224 void idSysLocal::GetCallStack( address_t *callStack, const int callStackSize ) { memset( callStack, 0, callStackSize * sizeof( callStack[0] ) ); }
225 const char * idSysLocal::GetCallStackStr( const address_t *callStack, const int callStackSize ) { return ""; }
226 const char * idSysLocal::GetCallStackCurStr( int depth ) { return ""; }
227 void idSysLocal::ShutdownSymbols( void ) {}
228 
229 int idSysLocal::DLL_Load( const char *dllName ) { return 0; }
230 void * idSysLocal::DLL_GetProcAddress( int dllHandle, const char *procName ) { return NULL; }
231 void idSysLocal::DLL_Unload( int dllHandle ) { }
232 void idSysLocal::DLL_GetFileName( const char *baseName, char *dllName, int maxLength ) { }
233 
234 sysEvent_t idSysLocal::GenerateMouseButtonEvent( int button, bool down ) { sysEvent_t ev; memset( &ev, 0, sizeof( ev ) ); return ev; }
235 sysEvent_t idSysLocal::GenerateMouseMoveEvent( int deltax, int deltay ) { sysEvent_t ev; memset( &ev, 0, sizeof( ev ) ); return ev; }
236 
237 void idSysLocal::OpenURL( const char *url, bool quit ) { }
238 void idSysLocal::StartProcess( const char *exeName, bool quit ) { }
239 
240 void idSysLocal::FPU_EnableExceptions( int exceptions ) { }
241 
244 
245 
246 /*
247 ==============================================================
248 
249  main
250 
251 ==============================================================
252 */
253 
254 int main( int argc, char** argv ) {
255  idStr fileName, sourcePath;
256  idTypeInfoGen *generator;
257 
261  idLib::sys = sys;
262 
263  idLib::Init();
264  cmdSystem->Init();
265  cvarSystem->Init();
267  fileSystem->Init();
268 
269  generator = new idTypeInfoGen;
270 
271  if ( argc > 1 ) {
272  sourcePath = idStr( "../"SOURCE_CODE_BASE_FOLDER"/" ) + argv[1];
273  } else {
274  sourcePath = "../"SOURCE_CODE_BASE_FOLDER"/game";
275  }
276 
277  if ( argc > 2 ) {
278  fileName = idStr( "../"SOURCE_CODE_BASE_FOLDER"/" ) + argv[2];
279  } else {
280  fileName = "../"SOURCE_CODE_BASE_FOLDER"/game/gamesys/GameTypeInfo.h";
281  }
282 
283  if ( argc > 3 ) {
284  for ( int i = 3; i < argc; i++ ) {
285  generator->AddDefine( argv[i] );
286  }
287  } else {
288  generator->AddDefine( "__cplusplus" );
289  generator->AddDefine( "GAME_DLL" );
290  generator->AddDefine( "ID_TYPEINFO" );
291  }
292 
293  generator->CreateTypeInfo( sourcePath );
294  generator->WriteTypeInfo( fileName );
295 
296  delete generator;
297 
298  fileName.Clear();
299  sourcePath.Clear();
300 
301  fileSystem->Shutdown( false );
302  cvarSystem->Shutdown();
303  cmdSystem->Shutdown();
304  idLib::ShutDown();
305 
306  return 0;
307 }
virtual const idLangDict * GetLanguageDict()
Definition: main.cpp:86
virtual double GetClockTicks(void)
Definition: sys_local.cpp:55
virtual void DPrintf(const char *fmt,...)
Definition: main.cpp:79
#define SOURCE_CODE_BASE_FOLDER
Definition: Licensee.h:54
xthreadInfo * g_threads[MAX_THREADS]
Definition: main.cpp:192
virtual void Quit(void)
Definition: main.cpp:64
virtual const char * GetProcessorString(void)
Definition: sys_local.cpp:67
virtual const char * GetCallStackCurStr(int depth)
Definition: sys_local.cpp:103
void Sys_DestroyThread(xthreadInfo &info)
Definition: main.cpp:196
idCVarSystem * cvarSystem
Definition: CVarSystem.cpp:487
const char * Sys_DefaultSavePath(void)
Definition: main.cpp:119
static void ShutDown(void)
Definition: Lib.cpp:91
virtual void DLL_Unload(int dllHandle)
Definition: sys_local.cpp:119
virtual sysEvent_t GenerateMouseButtonEvent(int button, bool down)
Definition: sys_local.cpp:135
xthreadPriority
Definition: sys_public.h:482
idCommonLocal commonLocal
Definition: main.cpp:95
virtual double ClockTicksPerSecond(void)
Definition: sys_local.cpp:59
virtual int KeyState(int key)
Definition: main.cpp:90
virtual void * DLL_GetProcAddress(int dllHandle, const char *procName)
Definition: sys_local.cpp:115
void WriteTypeInfo(const char *fileName) const
ID_TIME_T Sys_FileTimeStamp(FILE *fp)
Definition: main.cpp:107
idCVar com_developer("developer","0", CVAR_BOOL|CVAR_SYSTEM,"developer mode")
idFileSystem * fileSystem
Definition: FileSystem.cpp:500
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glext.h:2878
virtual void Error(const char *fmt,...)
Definition: main.cpp:84
virtual cpuid_t GetProcessorId(void)
Definition: sys_local.cpp:63
void Sys_LeaveCriticalSection(int index)
Definition: main.cpp:199
virtual void FPU_SetDAZ(bool enable)
Definition: sys_local.cpp:83
idCmdSystem * cmdSystem
Definition: CmdSystem.cpp:116
virtual const char * FPU_GetState(void)
Definition: sys_local.cpp:71
static class idSys * sys
Definition: Lib.h:52
virtual void StartupVariable(const char *match, bool once)
Definition: main.cpp:69
virtual void DWarning(const char *fmt,...)
Definition: main.cpp:81
virtual void Shutdown(void)
Definition: main.cpp:63
int i
Definition: process.py:33
void Sys_TriggerEvent(int index)
Definition: main.cpp:202
idSysLocal sysLocal
Definition: main.cpp:242
virtual void Warning(const char *fmt,...)
Definition: main.cpp:80
int Sys_ListFiles(const char *directory, const char *extension, idStrList &list)
Definition: main.cpp:188
virtual void InitTool(const toolFlag_t tool, const idDict *dict)
Definition: main.cpp:70
virtual void Init(int argc, const char **argv, const char *cmdline)
Definition: main.cpp:62
int main(int argc, const char **argv)
Definition: main.cpp:545
virtual bool LockMemory(void *ptr, int bytes)
Definition: sys_local.cpp:87
virtual void Init(void)=0
virtual void ClearWarnings(const char *reason)
Definition: main.cpp:83
virtual void ShutdownSymbols(void)
Definition: sys_local.cpp:107
virtual void GUIFrame(bool execCmd, bool network)
Definition: main.cpp:67
static class idFileSystem * fileSystem
Definition: Lib.h:55
idDeclManager * declManager
Definition: main.cpp:36
GLuint index
Definition: glext.h:3476
void Sys_CreateThread(xthread_t function, void *parms, xthreadPriority priority, xthreadInfo &info, const char *name, xthreadInfo *threads[MAX_THREADS], int *thread_count)
Definition: main.cpp:195
idSession * session
Definition: main.cpp:35
Definition: Dict.h:65
#define NULL
Definition: Lib.h:88
virtual const char * GetCVarString(const char *name) const =0
cpuid_t
Definition: sys_public.h:142
#define STDIO_PRINT(pre, post)
Definition: main.cpp:49
virtual void SetRefreshOnPrint(bool set)
Definition: main.cpp:76
GLuint buffer
Definition: glext.h:3108
virtual void Async(void)
Definition: main.cpp:68
virtual bool UnlockMemory(void *ptr, int bytes)
Definition: sys_local.cpp:91
const char * path
Definition: sws.c:117
virtual void FatalError(const char *fmt,...)
Definition: main.cpp:85
void Clear(void)
Definition: Str.h:724
void AddDefine(const char *define)
virtual const char * GetCallStackStr(const address_t *callStack, const int callStackSize)
Definition: sys_local.cpp:99
unsigned int(* xthread_t)(void *)
Definition: sys_public.h:480
static void RegisterStaticVars(void)
Definition: CVarSystem.h:300
virtual void Shutdown(void)=0
void Sys_EnterCriticalSection(int index)
Definition: main.cpp:198
idEventLoop * eventLoop
Definition: main.cpp:37
virtual void FPU_SetFTZ(bool enable)
Definition: sys_local.cpp:79
virtual void ActivateTool(bool active)
Definition: main.cpp:71
virtual bool IsInitialized(void) const
Definition: main.cpp:65
virtual void BeginRedirect(char *buffer, int buffersize, void(*flush)(const char *))
Definition: main.cpp:74
virtual void OpenURL(const char *url, bool quit)
Definition: main.cpp:421
const char * Sys_Cwd(void)
Definition: win_main.cpp:490
virtual const char * BindingFromKey(const char *key)
Definition: main.cpp:88
virtual bool FPU_StackIsEmpty(void)
Definition: sys_local.cpp:75
int Append(const type &obj)
Definition: List.h:646
virtual int ButtonState(int key)
Definition: main.cpp:89
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
virtual const char * KeysFromBinding(const char *bind)
Definition: main.cpp:87
static void Init(void)
Definition: Lib.cpp:57
int Num(void) const
Definition: List.h:265
const GLcharARB * name
Definition: glext.h:3629
virtual void WriteFlaggedCVarsToFile(const char *filename, int flags, const char *setCmd)
Definition: main.cpp:73
static class idCVarSystem * cvarSystem
Definition: Lib.h:54
virtual void VPrintf(const char *fmt, va_list arg)
Definition: main.cpp:78
virtual void PrintWarnings(void)
Definition: main.cpp:82
Definition: Str.h:116
virtual void WriteConfigToFile(const char *filename)
Definition: main.cpp:72
toolFlag_t
Definition: Common.h:40
const int MAX_THREADS
Definition: sys_public.h:494
virtual void StartProcess(const char *exeName, bool quit)
Definition: posix_main.cpp:132
int JournalLevel(void) const
Definition: EventLoop.cpp:272
GLsizei maxLength
Definition: glext.h:3627
virtual void Printf(const char *fmt,...)
Definition: main.cpp:77
virtual void FPU_EnableExceptions(int exceptions)
Definition: sys_local.cpp:155
virtual void EndRedirect(void)
Definition: main.cpp:75
virtual void Shutdown(bool reloading)=0
const char * Sys_DefaultCDPath(void)
Definition: main.cpp:185
virtual void virtual void DebugVPrintf(const char *fmt, va_list arg)
Definition: sys_local.cpp:51
void Sys_Mkdir(const char *path)
Definition: main.cpp:106
unsigned long address_t
Definition: sys_public.h:234
void CreateTypeInfo(const char *path)
virtual void DebugPrintf(const char *fmt,...) id_attribute((format(printf
Definition: sys_local.cpp:43
idCommon * common
Definition: main.cpp:96
virtual void Frame(void)
Definition: main.cpp:66
virtual void Shutdown(void)=0
idSys * sys
Definition: main.cpp:243
virtual void GetCallStack(address_t *callStack, const int callStackSize)
Definition: sys_local.cpp:95
idCommonLocal(void)
Definition: main.cpp:60
virtual void Init(void)=0
int sprintf(idStr &string, const char *fmt,...)
Definition: Str.cpp:1528
const char * Sys_EXEPath(void)
Definition: main.cpp:132
virtual void Init(void)=0
void Sys_WaitForEvent(int index)
Definition: main.cpp:201
const char * Sys_DefaultBasePath(void)
Definition: main.cpp:158
static class idCommon * common
Definition: Lib.h:53
virtual void DLL_GetFileName(const char *baseName, char *dllName, int maxLength)
Definition: sys_local.cpp:123
int g_thread_count
Definition: main.cpp:193
void Clear(void)
Definition: List.h:184