main.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  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. #include "../idlib/precompiled.h"
  21. #include "../sys/sys_local.h"
  22. #pragma hdrstop
  23. #include "TypeInfoGen.h"
  24. idSession * session = NULL;
  25. idDeclManager * declManager = NULL;
  26. idEventLoop * eventLoop = NULL;
  27. int idEventLoop::JournalLevel( void ) const { return 0; }
  28. /*
  29. ==============================================================
  30. idCommon
  31. ==============================================================
  32. */
  33. #define STDIO_PRINT( pre, post ) \
  34. va_list argptr; \
  35. va_start( argptr, fmt ); \
  36. printf( pre ); \
  37. vprintf( fmt, argptr ); \
  38. printf( post ); \
  39. va_end( argptr )
  40. class idCommonLocal : public idCommon {
  41. public:
  42. idCommonLocal( void ) {}
  43. virtual void Init( int argc, const char **argv, const char *cmdline ) {}
  44. virtual void Shutdown( void ) {}
  45. virtual void Quit( void ) {}
  46. virtual bool IsInitialized( void ) const { return true; }
  47. virtual void Frame( void ) {}
  48. virtual void GUIFrame( bool execCmd, bool network ) {}
  49. virtual void Async( void ) {}
  50. virtual void StartupVariable( const char *match, bool once ) {}
  51. virtual void InitTool( const toolFlag_t tool, const idDict *dict ) {}
  52. virtual void ActivateTool( bool active ) {}
  53. virtual void WriteConfigToFile( const char *filename ) {}
  54. virtual void WriteFlaggedCVarsToFile( const char *filename, int flags, const char *setCmd ) {}
  55. virtual void BeginRedirect( char *buffer, int buffersize, void (*flush)( const char * ) ) {}
  56. virtual void EndRedirect( void ) {}
  57. virtual void SetRefreshOnPrint( bool set ) {}
  58. virtual void Printf( const char *fmt, ... ) { STDIO_PRINT( "", "" ); }
  59. virtual void VPrintf( const char *fmt, va_list arg ) { vprintf( fmt, arg ); }
  60. virtual void DPrintf( const char *fmt, ... ) { /*STDIO_PRINT( "", "" );*/ }
  61. virtual void Warning( const char *fmt, ... ) { STDIO_PRINT( "WARNING: ", "\n" ); }
  62. virtual void DWarning( const char *fmt, ...) { /*STDIO_PRINT( "WARNING: ", "\n" );*/ }
  63. virtual void PrintWarnings( void ) {}
  64. virtual void ClearWarnings( const char *reason ) {}
  65. virtual void Error( const char *fmt, ... ) { STDIO_PRINT( "ERROR: ", "\n" ); exit(0); }
  66. virtual void FatalError( const char *fmt, ... ) { STDIO_PRINT( "FATAL ERROR: ", "\n" ); exit(0); }
  67. virtual const idLangDict *GetLanguageDict() { return NULL; }
  68. virtual const char * KeysFromBinding( const char *bind ) { return NULL; }
  69. virtual const char * BindingFromKey( const char *key ) { return NULL; }
  70. virtual int ButtonState( int key ) { return 0; }
  71. virtual int KeyState( int key ) { return 0; }
  72. };
  73. idCommonLocal commonLocal;
  74. idCommon * common = &commonLocal;
  75. /*
  76. ==============================================================
  77. idSys
  78. ==============================================================
  79. */
  80. void Sys_Mkdir( const char *path ) {}
  81. ID_TIME_T Sys_FileTimeStamp( FILE *fp ) { return 0; }
  82. #ifdef _WIN32
  83. #include <io.h>
  84. #include <direct.h>
  85. const char *Sys_Cwd( void ) {
  86. static char cwd[1024];
  87. _getcwd( cwd, sizeof( cwd ) - 1 );
  88. cwd[sizeof( cwd ) - 1] = 0;
  89. int i = idStr::FindText( cwd, CD_BASEDIR, false );
  90. if ( i >= 0 ) {
  91. cwd[i + strlen( CD_BASEDIR )] = '\0';
  92. }
  93. return cwd;
  94. }
  95. const char *Sys_DefaultCDPath( void ) {
  96. return "";
  97. }
  98. const char *Sys_DefaultBasePath( void ) {
  99. return Sys_Cwd();
  100. }
  101. const char *Sys_DefaultSavePath( void ) {
  102. return cvarSystem->GetCVarString( "fs_basepath" );
  103. }
  104. const char *Sys_EXEPath( void ) {
  105. return "";
  106. }
  107. int Sys_ListFiles( const char *directory, const char *extension, idStrList &list ) {
  108. idStr search;
  109. struct _finddata_t findinfo;
  110. int findhandle;
  111. int flag;
  112. if ( !extension) {
  113. extension = "";
  114. }
  115. // passing a slash as extension will find directories
  116. if ( extension[0] == '/' && extension[1] == 0 ) {
  117. extension = "";
  118. flag = 0;
  119. } else {
  120. flag = _A_SUBDIR;
  121. }
  122. sprintf( search, "%s\\*%s", directory, extension );
  123. // search
  124. list.Clear();
  125. findhandle = _findfirst( search, &findinfo );
  126. if ( findhandle == -1 ) {
  127. return -1;
  128. }
  129. do {
  130. if ( flag ^ ( findinfo.attrib & _A_SUBDIR ) ) {
  131. list.Append( findinfo.name );
  132. }
  133. } while ( _findnext( findhandle, &findinfo ) != -1 );
  134. _findclose( findhandle );
  135. return list.Num();
  136. }
  137. #else
  138. const char * Sys_DefaultCDPath( void ) { return ""; }
  139. const char * Sys_DefaultBasePath( void ) { return ""; }
  140. const char * Sys_DefaultSavePath( void ) { return ""; }
  141. int Sys_ListFiles( const char *directory, const char *extension, idStrList &list ) { return 0; }
  142. #endif
  143. xthreadInfo * g_threads[MAX_THREADS];
  144. int g_thread_count;
  145. void Sys_CreateThread( xthread_t function, void *parms, xthreadPriority priority, xthreadInfo &info, const char *name, xthreadInfo *threads[MAX_THREADS], int *thread_count ) {}
  146. void Sys_DestroyThread( xthreadInfo& info ) {}
  147. void Sys_EnterCriticalSection( int index ) {}
  148. void Sys_LeaveCriticalSection( int index ) {}
  149. void Sys_WaitForEvent( int index ) {}
  150. void Sys_TriggerEvent( int index ) {}
  151. /*
  152. ==============
  153. idSysLocal stub
  154. ==============
  155. */
  156. void idSysLocal::DebugPrintf( const char *fmt, ... ) {}
  157. void idSysLocal::DebugVPrintf( const char *fmt, va_list arg ) {}
  158. double idSysLocal::GetClockTicks( void ) { return 0.0; }
  159. double idSysLocal::ClockTicksPerSecond( void ) { return 1.0; }
  160. cpuid_t idSysLocal::GetProcessorId( void ) { return (cpuid_t)0; }
  161. const char * idSysLocal::GetProcessorString( void ) { return ""; }
  162. const char * idSysLocal::FPU_GetState( void ) { return ""; }
  163. bool idSysLocal::FPU_StackIsEmpty( void ) { return true; }
  164. void idSysLocal::FPU_SetFTZ( bool enable ) {}
  165. void idSysLocal::FPU_SetDAZ( bool enable ) {}
  166. bool idSysLocal::LockMemory( void *ptr, int bytes ) { return false; }
  167. bool idSysLocal::UnlockMemory( void *ptr, int bytes ) { return false; }
  168. void idSysLocal::GetCallStack( address_t *callStack, const int callStackSize ) { memset( callStack, 0, callStackSize * sizeof( callStack[0] ) ); }
  169. const char * idSysLocal::GetCallStackStr( const address_t *callStack, const int callStackSize ) { return ""; }
  170. const char * idSysLocal::GetCallStackCurStr( int depth ) { return ""; }
  171. void idSysLocal::ShutdownSymbols( void ) {}
  172. int idSysLocal::DLL_Load( const char *dllName ) { return 0; }
  173. void * idSysLocal::DLL_GetProcAddress( int dllHandle, const char *procName ) { return NULL; }
  174. void idSysLocal::DLL_Unload( int dllHandle ) { }
  175. void idSysLocal::DLL_GetFileName( const char *baseName, char *dllName, int maxLength ) { }
  176. sysEvent_t idSysLocal::GenerateMouseButtonEvent( int button, bool down ) { sysEvent_t ev; memset( &ev, 0, sizeof( ev ) ); return ev; }
  177. sysEvent_t idSysLocal::GenerateMouseMoveEvent( int deltax, int deltay ) { sysEvent_t ev; memset( &ev, 0, sizeof( ev ) ); return ev; }
  178. void idSysLocal::OpenURL( const char *url, bool quit ) { }
  179. void idSysLocal::StartProcess( const char *exeName, bool quit ) { }
  180. void idSysLocal::FPU_EnableExceptions( int exceptions ) { }
  181. idSysLocal sysLocal;
  182. idSys * sys = &sysLocal;
  183. /*
  184. ==============================================================
  185. main
  186. ==============================================================
  187. */
  188. int main( int argc, char** argv ) {
  189. idStr fileName, sourcePath;
  190. idTypeInfoGen *generator;
  191. idLib::common = common;
  192. idLib::cvarSystem = cvarSystem;
  193. idLib::fileSystem = fileSystem;
  194. idLib::sys = sys;
  195. idLib::Init();
  196. cmdSystem->Init();
  197. cvarSystem->Init();
  198. idCVar::RegisterStaticVars();
  199. fileSystem->Init();
  200. generator = new idTypeInfoGen;
  201. if ( argc > 1 ) {
  202. sourcePath = idStr( "../"SOURCE_CODE_BASE_FOLDER"/" ) + argv[1];
  203. } else {
  204. sourcePath = "../"SOURCE_CODE_BASE_FOLDER"/game";
  205. }
  206. if ( argc > 2 ) {
  207. fileName = idStr( "../"SOURCE_CODE_BASE_FOLDER"/" ) + argv[2];
  208. } else {
  209. fileName = "../"SOURCE_CODE_BASE_FOLDER"/game/gamesys/GameTypeInfo.h";
  210. }
  211. if ( argc > 3 ) {
  212. for ( int i = 3; i < argc; i++ ) {
  213. generator->AddDefine( argv[i] );
  214. }
  215. } else {
  216. generator->AddDefine( "__cplusplus" );
  217. generator->AddDefine( "GAME_DLL" );
  218. generator->AddDefine( "ID_TYPEINFO" );
  219. }
  220. generator->CreateTypeInfo( sourcePath );
  221. generator->WriteTypeInfo( fileName );
  222. delete generator;
  223. fileName.Clear();
  224. sourcePath.Clear();
  225. fileSystem->Shutdown( false );
  226. cvarSystem->Shutdown();
  227. cmdSystem->Shutdown();
  228. idLib::ShutDown();
  229. return 0;
  230. }