From 9337596fa81a6d390a019f2297fa2e351c7d3431 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Sat, 15 Jun 2024 21:33:49 +0200 Subject: [PATCH] Started rbdmap.exe CMake project --- neo/CMakeLists.txt | 1 + neo/framework/File.cpp | 5 +- neo/framework/File.h | 4 +- neo/framework/FileSystem.cpp | 8 +- neo/framework/File_Resource.cpp | 6 + neo/framework/Zip.h | 2 +- neo/stub/EngineStub.cpp | 464 +++++++++++++++++++++++ neo/stub/EngineStubPosix.cpp | 556 ++++++++++++++++++++++++++++ neo/tools/compilers/CMakeLists.txt | 155 ++++++++ neo/tools/compilers/precompiled.cpp | 29 ++ neo/tools/compilers/precompiled.h | 1 + 11 files changed, 1224 insertions(+), 7 deletions(-) create mode 100644 neo/stub/EngineStub.cpp create mode 100644 neo/stub/EngineStubPosix.cpp create mode 100644 neo/tools/compilers/CMakeLists.txt create mode 100644 neo/tools/compilers/precompiled.cpp create mode 100644 neo/tools/compilers/precompiled.h diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index b46ab1b2..ccb3dec4 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -452,6 +452,7 @@ if(OPTICK) endif() add_subdirectory(idlib) +add_subdirectory(tools/compilers) file(GLOB NATVIS_SOURCES .natvis) diff --git a/neo/framework/File.cpp b/neo/framework/File.cpp index a5712d25..0aef340e 100644 --- a/neo/framework/File.cpp +++ b/neo/framework/File.cpp @@ -1712,6 +1712,8 @@ idFile_InZip ================================================================================= */ +#if !defined( TYPEINFOPROJECT ) && !defined( DMAP ) + /* ================= idFile_InZip::idFile_InZip @@ -1872,7 +1874,7 @@ int idFile_InZip::Seek( long offset, fsOrigin_t origin ) return -1; } -#if 1 +#endif /* ================================================================================= @@ -2003,7 +2005,6 @@ int idFile_InnerResource::Seek( long offset, fsOrigin_t origin ) } return -1; } -#endif /* ================================================================================================ diff --git a/neo/framework/File.h b/neo/framework/File.h index a9452136..8f4a73d2 100644 --- a/neo/framework/File.h +++ b/neo/framework/File.h @@ -330,6 +330,7 @@ private: }; +#if !defined( TYPEINFOPROJECT ) && !defined( DMAP ) class idFile_InZip : public idFile { friend class idFileSystemLocal; @@ -364,8 +365,8 @@ private: int fileSize; // size of the file void* z; // unzip info }; +#endif -#if 1 class idFile_InnerResource : public idFile { friend class idFileSystemLocal; @@ -412,7 +413,6 @@ private: int internalFilePos; // seek offset byte* resourceBuffer; // if using the temp save memory }; -#endif /* ================================================ diff --git a/neo/framework/FileSystem.cpp b/neo/framework/FileSystem.cpp index 2acacc36..320bfae0 100644 --- a/neo/framework/FileSystem.cpp +++ b/neo/framework/FileSystem.cpp @@ -30,8 +30,10 @@ If you have questions concerning this license or the applicable additional terms #include "precompiled.h" #pragma hdrstop -#include "Unzip.h" -#include "Zip.h" +#if !defined( TYPEINFOPROJECT ) && !defined( DMAP ) + #include "Unzip.h" + #include "Zip.h" +#endif #ifdef WIN32 #include // for _read @@ -3315,7 +3317,9 @@ idFile* idFileSystemLocal::GetResourceFile( const char* fileName, bool memFile ) { idLib::Printf( "RES: loading file %s\n", rc.filename.c_str() ); } + idFile_InnerResource* file = new idFile_InnerResource( rc.filename, resourceFiles[ rc.containerIndex ]->resourceFile, rc.offset, rc.length ); + // DG: add parenthesis to make sure this block is only entered when file != NULL - bug found by clang. if( file != NULL && ( ( memFile || rc.length <= resourceBufferAvailable ) || rc.length < 8 * 1024 * 1024 ) ) { diff --git a/neo/framework/File_Resource.cpp b/neo/framework/File_Resource.cpp index d0e68339..18c29a32 100644 --- a/neo/framework/File_Resource.cpp +++ b/neo/framework/File_Resource.cpp @@ -367,11 +367,13 @@ void idResourceContainer::ExtractResourceFile( const char* _fileName, const char int _numFileResources; memFile.ReadBig( _numFileResources ); +#if !defined( TYPEINFOPROJECT ) && !defined( DMAP ) CommandlineProgressBar progressBar( _numFileResources, renderSystem->GetWidth(), renderSystem->GetHeight() ); if( _copyWavs ) { progressBar.Start(); } +#endif for( int i = 0; i < _numFileResources; i++ ) { @@ -383,6 +385,7 @@ void idResourceContainer::ExtractResourceFile( const char* _fileName, const char if( _copyWavs && ( rt.filename.Find( ".idwav" ) >= 0 || rt.filename.Find( ".idxma" ) >= 0 || rt.filename.Find( ".idmsf" ) >= 0 ) ) { +#if !defined( TYPEINFOPROJECT ) && !defined( DMAP ) idFileLocal fileIn( fileSystem->OpenFileReadMemory( rt.filename ) ); if( fileIn != NULL ) { @@ -457,6 +460,7 @@ void idResourceContainer::ExtractResourceFile( const char* _fileName, const char Mem_Free( buffers[ i ].buffer ); } } +#endif } else { @@ -493,10 +497,12 @@ void idResourceContainer::ExtractResourceFile( const char* _fileName, const char Mem_Free( fbuf ); } +#if !defined( TYPEINFOPROJECT ) && !defined( DMAP ) if( _copyWavs ) { progressBar.Increment( true ); } +#endif } delete inFile; Mem_Free( buf ); diff --git a/neo/framework/Zip.h b/neo/framework/Zip.h index 22b29636..5c4d2a2d 100644 --- a/neo/framework/Zip.h +++ b/neo/framework/Zip.h @@ -31,7 +31,7 @@ If you have questions concerning this license or the applicable additional terms #include // DG: all the zip access stuff from minizip is now in minizip/zip.h -#ifndef TYPEINFOPROJECT +#if !defined( TYPEINFOPROJECT ) && !defined( DMAP ) #include "libs/zlib/minizip/zip.h" #endif diff --git a/neo/stub/EngineStub.cpp b/neo/stub/EngineStub.cpp new file mode 100644 index 00000000..a2fb8cb7 --- /dev/null +++ b/neo/stub/EngineStub.cpp @@ -0,0 +1,464 @@ +#include "precompiled.h" +#include "../sys/sys_local.h" +#include "../framework/EventLoop.h" +#include "../framework/DeclManager.h" + +#include +#include + +idEventLoop* eventLoop; +idDeclManager* declManager; +idSys* sys = NULL; + +#define STDIO_PRINT( pre, post ) \ + va_list argptr; \ + va_start( argptr, fmt ); \ + printf( pre ); \ + vprintf( fmt, argptr ); \ + printf( post ); \ + OutputDebugStringA(post); \ + va_end( argptr ) + +idCVar com_productionMode( "com_productionMode", "0", CVAR_SYSTEM | CVAR_BOOL, "0 - no special behavior, 1 - building a production build, 2 - running a production build" ); + + +/* +============== +Sys_Mkdir +============== +*/ +void Sys_Mkdir( const char* path ) +{ + _mkdir( path ); +} + + +/* +======================== +Sys_Rmdir +======================== +*/ +bool Sys_Rmdir( const char* path ) +{ + return _rmdir( path ) == 0; +} + +/* +============== +Sys_EXEPath +============== +*/ +const char* Sys_EXEPath() +{ + static char exe[MAX_OSPATH]; + GetModuleFileName( NULL, exe, sizeof( exe ) - 1 ); + return exe; +} + +/* +============== +Sys_ListFiles +============== +*/ +int Sys_ListFiles( const char* directory, const char* extension, idStrList& list ) +{ + idStr search; + struct _finddata_t findinfo; + // RB: 64 bit fixes, changed int to intptr_t + intptr_t findhandle; + // RB end + int flag; + + if( !extension ) + { + extension = ""; + } + + // passing a slash as extension will find directories + if( extension[0] == '/' && extension[1] == 0 ) + { + extension = ""; + flag = 0; + } + else + { + flag = _A_SUBDIR; + } + + sprintf( search, "%s\\*%s", directory, extension ); + + // search + list.Clear(); + + findhandle = _findfirst( search, &findinfo ); + if( findhandle == -1 ) + { + return -1; + } + + do + { + if( flag ^ ( findinfo.attrib & _A_SUBDIR ) ) + { + list.Append( findinfo.name ); + } + } + while( _findnext( findhandle, &findinfo ) != -1 ); + + _findclose( findhandle ); + + return list.Num(); +} + + + +int idEventLoop::JournalLevel() const +{ + return 0; +} + +/* +======================== +Sys_IsFolder +======================== +*/ +sysFolder_t Sys_IsFolder( const char* path ) +{ + struct _stat buffer; + if( _stat( path, &buffer ) < 0 ) + { + return FOLDER_ERROR; + } + return ( buffer.st_mode & _S_IFDIR ) != 0 ? FOLDER_YES : FOLDER_NO; +} + +const char* Sys_DefaultSavePath() +{ + return ""; +} + +const char* Sys_Lang( int ) +{ + return ""; +} + + +/* +================= +Sys_FileTimeStamp +================= +*/ +ID_TIME_T Sys_FileTimeStamp( idFileHandle fp ) +{ + FILETIME writeTime; + GetFileTime( fp, NULL, NULL, &writeTime ); + + /* + FILETIME = number of 100-nanosecond ticks since midnight + 1 Jan 1601 UTC. time_t = number of 1-second ticks since + midnight 1 Jan 1970 UTC. To translate, we subtract a + FILETIME representation of midnight, 1 Jan 1970 from the + time in question and divide by the number of 100-ns ticks + in one second. + */ + + SYSTEMTIME base_st = + { + 1970, // wYear + 1, // wMonth + 0, // wDayOfWeek + 1, // wDay + 0, // wHour + 0, // wMinute + 0, // wSecond + 0 // wMilliseconds + }; + + FILETIME base_ft; + SystemTimeToFileTime( &base_st, &base_ft ); + + LARGE_INTEGER itime; + itime.QuadPart = reinterpret_cast( writeTime ).QuadPart; + itime.QuadPart -= reinterpret_cast( base_ft ).QuadPart; + itime.QuadPart /= 10000000LL; + return itime.QuadPart; +} + +/* +============== +Sys_Cwd +============== +*/ +const char* Sys_Cwd() +{ + static char cwd[MAX_OSPATH]; + + _getcwd( cwd, sizeof( cwd ) - 1 ); + cwd[MAX_OSPATH - 1] = 0; + + return cwd; +} + +/* +============== +Sys_DefaultBasePath +============== +*/ +const char* Sys_DefaultBasePath() +{ + return Sys_Cwd(); +} + +int Sys_NumLangs() +{ + return 0; +} + +/* +================ +Sys_Milliseconds +================ +*/ +int Sys_Milliseconds() +{ + static DWORD sys_timeBase = timeGetTime(); + return timeGetTime() - sys_timeBase; +} + +class idCommonLocal : public idCommon +{ +public: + + // Initialize everything. + // if the OS allows, pass argc/argv directly (without executable name) + // otherwise pass the command line in a single string (without executable name) + virtual void Init( int argc, const char* const* argv, const char* cmdline ) { }; + + // Shuts down everything. + virtual void Shutdown() { }; + virtual bool IsShuttingDown() const + { + return false; + }; + + virtual void CreateMainMenu() { }; + + // Shuts down everything. + virtual void Quit() { }; + + // Returns true if common initialization is complete. + virtual bool IsInitialized() const + { + return true; + }; + + // Called repeatedly as the foreground thread for rendering and game logic. + virtual void Frame() { }; + + // Redraws the screen, handling games, guis, console, etc + // in a modal manner outside the normal frame loop + virtual void UpdateScreen() { }; + + virtual void UpdateLevelLoadPacifier() { }; + + + // Checks for and removes command line "+set var arg" constructs. + // If match is NULL, all set commands will be executed, otherwise + // only a set with the exact name. + virtual void StartupVariable( const char* match ) { }; + + // Begins redirection of console output to the given buffer. + virtual void BeginRedirect( char* buffer, int buffersize, void ( *flush )( const char* ) ) { }; + + // Stops redirection of console output. + virtual void EndRedirect() { }; + + // Update the screen with every message printed. + virtual void SetRefreshOnPrint( bool set ) { }; + + virtual void Printf( const char* fmt, ... ) + { + STDIO_PRINT( "", "" ); + } + virtual void VPrintf( const char* fmt, va_list arg ) + { + vprintf( fmt, arg ); + } + virtual void DPrintf( const char* fmt, ... ) + { + /*STDIO_PRINT( "", "" );*/ + } + virtual void Warning( const char* fmt, ... ) + { + STDIO_PRINT( "WARNING: ", "\n" ); + } + virtual void DWarning( const char* fmt, ... ) + { + /*STDIO_PRINT( "WARNING: ", "\n" );*/ + } + + // Prints all queued warnings. + virtual void PrintWarnings() { }; + + // Removes all queued warnings. + virtual void ClearWarnings( const char* reason ) { }; + + virtual void Error( const char* fmt, ... ) + { + STDIO_PRINT( "ERROR: ", "\n" ); + exit( 0 ); + } + virtual void FatalError( const char* fmt, ... ) + { + STDIO_PRINT( "FATAL ERROR: ", "\n" ); + exit( 0 ); + } + + // Returns key bound to the command + virtual const char* KeysFromBinding( const char* bind ) + { + return NULL; + }; + + // Returns the binding bound to the key + virtual const char* BindingFromKey( const char* key ) + { + return NULL; + }; + + // Directly sample a button. + virtual int ButtonState( int key ) + { + return 0; + }; + + // Directly sample a keystate. + virtual int KeyState( int key ) + { + return 0; + }; + + // Returns true if a multiplayer game is running. + // CVars and commands are checked differently in multiplayer mode. + virtual bool IsMultiplayer() + { + return false; + }; + virtual bool IsServer() + { + return false; + }; + virtual bool IsClient() + { + return false; + }; + + // Returns true if the player has ever enabled the console + virtual bool GetConsoleUsed() + { + return false; + }; + + // Returns the rate (in ms between snaps) that we want to generate snapshots + virtual int GetSnapRate() + { + return 0; + }; + + virtual void NetReceiveReliable( int peer, int type, idBitMsg& msg ) { }; + virtual void NetReceiveSnapshot( class idSnapShot& ss ) { }; + virtual void NetReceiveUsercmds( int peer, idBitMsg& msg ) { }; + + // Processes the given event. + virtual bool ProcessEvent( const sysEvent_t* event ) + { + return false; + }; + + virtual bool LoadGame( const char* saveName ) + { + return false; + }; + virtual bool SaveGame( const char* saveName ) + { + return false; + }; + + virtual idGame* Game() + { + return NULL; + }; + virtual idRenderWorld* RW() + { + return NULL; + }; + virtual idSoundWorld* SW() + { + return NULL; + }; + virtual idSoundWorld* MenuSW() + { + return NULL; + }; + virtual idSession* Session() + { + return NULL; + }; + virtual idCommonDialog& Dialog() + { + static idCommonDialog useless; + return useless; + }; + + virtual void OnSaveCompleted( idSaveLoadParms& parms ) { }; + virtual void OnLoadCompleted( idSaveLoadParms& parms ) { }; + virtual void OnLoadFilesCompleted( idSaveLoadParms& parms ) { }; + virtual void OnEnumerationCompleted( idSaveLoadParms& parms ) { }; + virtual void OnDeleteCompleted( idSaveLoadParms& parms ) { }; + virtual void TriggerScreenWipe( const char* _wipeMaterial, bool hold ) { }; + + virtual void OnStartHosting( idMatchParameters& parms ) { }; + + virtual int GetGameFrame() + { + return 0; + }; + + virtual void LaunchExternalTitle( int titleIndex, int device, const lobbyConnectInfo_t* const connectInfo ) { }; + + virtual void InitializeMPMapsModes() { }; + virtual const idStrList& GetModeList() const + { + static idStrList useless; + return useless; + }; + virtual const idStrList& GetModeDisplayList() const + { + static idStrList useless; + return useless; + }; + virtual const idList& GetMapList() const + { + static idList useless; + return useless; + }; + + virtual void ResetPlayerInput( int playerIndex ) { }; + + virtual bool JapaneseCensorship() const + { + return false; + }; + + virtual void QueueShowShell() { }; // Will activate the shell on the next frame. + virtual void idCommon::UpdateScreen( bool, bool ) { } + void idCommon::InitTool( const toolFlag_t, const idDict*, idEntity* ) { } + + //virtual currentGame_t GetCurrentGame() const { + // return DOOM_CLASSIC; + //}; + //virtual void SwitchToGame(currentGame_t newGame) { }; +}; + +idCommonLocal commonLocal; +idCommon* common = &commonLocal; diff --git a/neo/stub/EngineStubPosix.cpp b/neo/stub/EngineStubPosix.cpp new file mode 100644 index 00000000..6e98f6b0 --- /dev/null +++ b/neo/stub/EngineStubPosix.cpp @@ -0,0 +1,556 @@ +/* +=========================================================================== + +Doom 3 BFG Edition GPL Source Code +Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. + +This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). + +Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Doom 3 BFG Edition Source Code. If not, see . + +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. + +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. + +=========================================================================== +*/ +#include "precompiled.h" + +#include "../sys/sys_local.h" +#include "../framework/EventLoop.h" +#include "../framework/DeclManager.h" + +#include +#include +#include +#include +#include + +idEventLoop* eventLoop; +idDeclManager* declManager; +idSys* sys = NULL; + +#define STDIO_PRINT( pre, post ) \ + va_list argptr; \ + va_start( argptr, fmt ); \ + printf( pre ); \ + vprintf( fmt, argptr ); \ + printf( post ); \ + printf(post); \ + va_end( argptr ) + +idCVar com_productionMode( "com_productionMode", "0", CVAR_SYSTEM | CVAR_BOOL, "0 - no special behavior, 1 - building a production build, 2 - running a production build" ); + +void Sys_Printf( const char* fmt, ... ) +{ + va_list argptr; + + //tty_Hide(); + va_start( argptr, fmt ); + vprintf( fmt, argptr ); + va_end( argptr ); + //tty_Show(); +} + +/* +============== +Sys_Mkdir +============== +*/ +void Sys_Mkdir( const char* path ) +{ + mkdir( path, 0777 ); +} + + +/* +======================== +Sys_Rmdir +======================== +*/ +bool Sys_Rmdir( const char* path ) +{ + return ( rmdir( path ) == 0 ); +} + +/* +============== +Sys_EXEPath +============== +*/ +const char* Sys_EXEPath() +{ + static char buf[ 1024 ]; + idStr linkpath; + int len; + + buf[ 0 ] = '\0'; + sprintf( linkpath, "/proc/%d/exe", getpid() ); + len = readlink( linkpath.c_str(), buf, sizeof( buf ) ); + if( len == -1 ) + { + Sys_Printf( "couldn't stat exe path link %s\n", linkpath.c_str() ); + // RB: fixed array subscript is below array bounds + buf[ 0 ] = '\0'; + // RB end + } + return buf; +} + +/* +============== +Sys_ListFiles +============== +*/ +int Sys_ListFiles( const char* directory, const char* extension, idStrList& list ) +{ + struct dirent* d; + DIR* fdir; + bool dironly = false; + char search[MAX_OSPATH]; + struct stat st; + bool debug; + + list.Clear(); + + debug = cvarSystem->GetCVarBool( "fs_debug" ); + // DG: we use fnmatch for shell-style pattern matching + // so the pattern should at least contain "*" to match everything, + // the extension will be added behind that (if !dironly) + idStr pattern( "*" ); + + // passing a slash as extension will find directories + if( extension[0] == '/' && extension[1] == 0 ) + { + dironly = true; + } + else + { + // so we have *, the same as in the windows code basically + pattern += extension; + } + // DG end + + // NOTE: case sensitivity of directory path can screw us up here + if( ( fdir = opendir( directory ) ) == NULL ) + { + if( debug ) + { + common->Printf( "Sys_ListFiles: opendir %s failed\n", directory ); + } + return -1; + } + + // DG: use readdir_r instead of readdir for thread safety + // the following lines are from the readdir_r manpage.. fscking ugly. + int nameMax = pathconf( directory, _PC_NAME_MAX ); + if( nameMax == -1 ) + { + nameMax = 255; + } + int direntLen = offsetof( struct dirent, d_name ) + nameMax + 1; + + struct dirent* entry = ( struct dirent* )Mem_Alloc( direntLen, TAG_CRAP ); + + if( entry == NULL ) + { + common->Warning( "Sys_ListFiles: Mem_Alloc for entry failed!" ); + closedir( fdir ); + return 0; + } + + while( readdir_r( fdir, entry, &d ) == 0 && d != NULL ) + { + // DG end + idStr::snPrintf( search, sizeof( search ), "%s/%s", directory, d->d_name ); + if( stat( search, &st ) == -1 ) + { + continue; + } + if( !dironly ) + { + // DG: the original code didn't work because d3 bfg abuses the extension + // to match whole filenames and patterns in the savegame-code, not just file extensions... + // so just use fnmatch() which supports matching shell wildcard patterns ("*.foo" etc) + // if we should ever need case insensitivity, use FNM_CASEFOLD as third flag + if( fnmatch( pattern.c_str(), d->d_name, 0 ) != 0 ) + { + continue; + } + // DG end + } + if( ( dironly && !( st.st_mode & S_IFDIR ) ) || + ( !dironly && ( st.st_mode & S_IFDIR ) ) ) + { + continue; + } + + list.Append( d->d_name ); + } + + closedir( fdir ); + Mem_Free( entry ); + + if( debug ) + { + common->Printf( "Sys_ListFiles: %d entries in %s\n", list.Num(), directory ); + } + + return list.Num(); +} + + + +int idEventLoop::JournalLevel() const +{ + return 0; +} + +/* +======================== +Sys_IsFolder +======================== +*/ +sysFolder_t Sys_IsFolder( const char* path ) +{ + struct stat buffer; + + if( stat( path, &buffer ) < 0 ) + { + return FOLDER_ERROR; + } + + return ( buffer.st_mode & S_IFDIR ) != 0 ? FOLDER_YES : FOLDER_NO; +} + +const char* Sys_DefaultSavePath() +{ + return ""; +} + +const char* Sys_Lang( int ) +{ + return ""; +} + + +/* +================= +Sys_FileTimeStamp +================= +*/ +ID_TIME_T Sys_FileTimeStamp( idFileHandle fp ) +{ + struct stat st; + fstat( fileno( fp ), &st ); + return st.st_mtime; +} + +/* +============== +Sys_DefaultBasePath +============== +*/ +const char* Sys_DefaultBasePath() +{ + return Sys_EXEPath(); +} + +int Sys_NumLangs() +{ + return 0; +} + +/* +================ +Sys_Milliseconds +================ +*/ +/* base time in seconds, that's our origin + timeval:tv_sec is an int: + assuming this wraps every 0x7fffffff - ~68 years since the Epoch (1970) - we're safe till 2038 + using unsigned long data type to work right with Sys_XTimeToSysTime */ + +#ifdef CLOCK_MONOTONIC_RAW + // use RAW monotonic clock if available (=> not subject to NTP etc) + #define D3_CLOCK_TO_USE CLOCK_MONOTONIC_RAW +#else + #define D3_CLOCK_TO_USE CLOCK_MONOTONIC +#endif + +// RB: changed long to int +unsigned int sys_timeBase = 0; +// RB end +/* current time in ms, using sys_timeBase as origin + NOTE: sys_timeBase*1000 + curtime -> ms since the Epoch + 0x7fffffff ms - ~24 days + or is it 48 days? the specs say int, but maybe it's casted from unsigned int? +*/ +int Sys_Milliseconds() +{ + // DG: use clock_gettime on all platforms + int curtime; + struct timespec ts; + + clock_gettime( D3_CLOCK_TO_USE, &ts ); + + if( !sys_timeBase ) + { + sys_timeBase = ts.tv_sec; + return ts.tv_nsec / 1000000; + } + + curtime = ( ts.tv_sec - sys_timeBase ) * 1000 + ts.tv_nsec / 1000000; + + return curtime; + // DG end +} + +class idCommonLocal : public idCommon +{ +public: + + // Initialize everything. + // if the OS allows, pass argc/argv directly (without executable name) + // otherwise pass the command line in a single string (without executable name) + virtual void Init( int argc, const char* const* argv, const char* cmdline ) { }; + + // Shuts down everything. + virtual void Shutdown() { }; + virtual bool IsShuttingDown() const + { + return false; + }; + + virtual void CreateMainMenu() { }; + + // Shuts down everything. + virtual void Quit() { }; + + // Returns true if common initialization is complete. + virtual bool IsInitialized() const + { + return true; + }; + + // Called repeatedly as the foreground thread for rendering and game logic. + virtual void Frame() { }; + + // Redraws the screen, handling games, guis, console, etc + // in a modal manner outside the normal frame loop + virtual void UpdateScreen() { }; + + virtual void UpdateLevelLoadPacifier() { }; + + + // Checks for and removes command line "+set var arg" constructs. + // If match is NULL, all set commands will be executed, otherwise + // only a set with the exact name. + virtual void StartupVariable( const char* match ) { }; + + // Begins redirection of console output to the given buffer. + virtual void BeginRedirect( char* buffer, int buffersize, void ( *flush )( const char* ) ) { }; + + // Stops redirection of console output. + virtual void EndRedirect() { }; + + // Update the screen with every message printed. + virtual void SetRefreshOnPrint( bool set ) { }; + + virtual void Printf( const char* fmt, ... ) + { + STDIO_PRINT( "", "" ); + } + virtual void VPrintf( const char* fmt, va_list arg ) + { + vprintf( fmt, arg ); + } + virtual void DPrintf( const char* fmt, ... ) + { + /*STDIO_PRINT( "", "" );*/ + } + virtual void Warning( const char* fmt, ... ) + { + STDIO_PRINT( "WARNING: ", "\n" ); + } + virtual void DWarning( const char* fmt, ... ) + { + /*STDIO_PRINT( "WARNING: ", "\n" );*/ + } + + // Prints all queued warnings. + virtual void PrintWarnings() { }; + + // Removes all queued warnings. + virtual void ClearWarnings( const char* reason ) { }; + + virtual void Error( const char* fmt, ... ) + { + STDIO_PRINT( "ERROR: ", "\n" ); + exit( 0 ); + } + virtual void FatalError( const char* fmt, ... ) + { + STDIO_PRINT( "FATAL ERROR: ", "\n" ); + exit( 0 ); + } + + // Returns key bound to the command + virtual const char* KeysFromBinding( const char* bind ) + { + return NULL; + }; + + // Returns the binding bound to the key + virtual const char* BindingFromKey( const char* key ) + { + return NULL; + }; + + // Directly sample a button. + virtual int ButtonState( int key ) + { + return 0; + }; + + // Directly sample a keystate. + virtual int KeyState( int key ) + { + return 0; + }; + + // Returns true if a multiplayer game is running. + // CVars and commands are checked differently in multiplayer mode. + virtual bool IsMultiplayer() + { + return false; + }; + virtual bool IsServer() + { + return false; + }; + virtual bool IsClient() + { + return false; + }; + + // Returns true if the player has ever enabled the console + virtual bool GetConsoleUsed() + { + return false; + }; + + // Returns the rate (in ms between snaps) that we want to generate snapshots + virtual int GetSnapRate() + { + return 0; + }; + + virtual void NetReceiveReliable( int peer, int type, idBitMsg& msg ) { }; + virtual void NetReceiveSnapshot( class idSnapShot& ss ) { }; + virtual void NetReceiveUsercmds( int peer, idBitMsg& msg ) { }; + + // Processes the given event. + virtual bool ProcessEvent( const sysEvent_t* event ) + { + return false; + }; + + virtual bool LoadGame( const char* saveName ) + { + return false; + }; + virtual bool SaveGame( const char* saveName ) + { + return false; + }; + + virtual idGame* Game() + { + return NULL; + }; + virtual idRenderWorld* RW() + { + return NULL; + }; + virtual idSoundWorld* SW() + { + return NULL; + }; + virtual idSoundWorld* MenuSW() + { + return NULL; + }; + virtual idSession* Session() + { + return NULL; + }; + virtual idCommonDialog& Dialog() + { + static idCommonDialog useless; + return useless; + }; + + virtual void OnSaveCompleted( idSaveLoadParms& parms ) { }; + virtual void OnLoadCompleted( idSaveLoadParms& parms ) { }; + virtual void OnLoadFilesCompleted( idSaveLoadParms& parms ) { }; + virtual void OnEnumerationCompleted( idSaveLoadParms& parms ) { }; + virtual void OnDeleteCompleted( idSaveLoadParms& parms ) { }; + virtual void TriggerScreenWipe( const char* _wipeMaterial, bool hold ) { }; + + virtual void OnStartHosting( idMatchParameters& parms ) { }; + + virtual int GetGameFrame() + { + return 0; + }; + + virtual void LaunchExternalTitle( int titleIndex, int device, const lobbyConnectInfo_t* const connectInfo ) { }; + + virtual void InitializeMPMapsModes() { }; + virtual const idStrList& GetModeList() const + { + static idStrList useless; + return useless; + }; + virtual const idStrList& GetModeDisplayList() const + { + static idStrList useless; + return useless; + }; + virtual const idList& GetMapList() const + { + static idList useless; + return useless; + }; + + virtual void ResetPlayerInput( int playerIndex ) { }; + + virtual bool JapaneseCensorship() const + { + return false; + }; + + virtual void QueueShowShell() { }; // Will activate the shell on the next frame. + virtual void UpdateScreen( bool, bool ) { } + void InitTool( const toolFlag_t, const idDict*, idEntity* ) { } + + //virtual currentGame_t GetCurrentGame() const { + // return DOOM_CLASSIC; + //}; + //virtual void SwitchToGame(currentGame_t newGame) { }; +}; + +idCommonLocal commonLocal; +idCommon* common = &commonLocal; diff --git a/neo/tools/compilers/CMakeLists.txt b/neo/tools/compilers/CMakeLists.txt new file mode 100644 index 00000000..39e230f5 --- /dev/null +++ b/neo/tools/compilers/CMakeLists.txt @@ -0,0 +1,155 @@ + +add_definitions(-DDMAP -D__DOOM_DLL__) + +set(TP_INCLUDES + #TypeInfoGen.h + ) +set(TP_SOURCES + #TypeInfoGen.cpp + #main.cpp + precompiled.cpp + ) + +file(GLOB DMAP_INCLUDES dmap/*.h) +file(GLOB DMAP_SOURCES dmap/*.cpp) + +if(WIN32) + list(APPEND TP_SOURCES ../../stub/EngineStub.cpp) +else() + list(APPEND TP_SOURCES ../../stub/EngineStubPosix.cpp) +endif() + +set(TP_FRAMEWORK_INCLUDES + ../../framework/CmdSystem.h + ../../framework/CVarSystem.h + ../../framework/File.h + ../../framework/File_Manifest.h + ../../framework/File_Resource.h + ../../framework/FileSystem.h + ../../framework/Licensee.h + ../../idlib/precompiled.h + ) +set(TP_FRAMEWORK_SOURCES + ../../framework/CmdSystem.cpp + ../../framework/CVarSystem.cpp + ../../framework/File.cpp + ../../framework/File_Manifest.cpp + ../../framework/File_Resource.cpp + ../../framework/FileSystem.cpp + ) + +#if(NOT ZLIB_FOUND) +# file(GLOB TP_ZLIB_INCLUDES ../../libs/zlib/*.h) +# file(GLOB TP_ZLIB_SOURCES ../../libs/zlib/*.c) +# list(APPEND TP_ZLIB_SOURCES ../../libs/zlib/minizip/unzip.cpp) +# list(APPEND TP_ZLIB_SOURCES ../../libs/zlib/minizip/ioapi.c) +#else (NOT ZLIB_FOUND) +# set(TP_ZLIB_INCLUDES "") +# set(TP_ZLIB_SOURCES "") +#endif() + + +set(TP_INCLUDES_ALL + ${TP_INCLUDES} + ${TP_FRAMEWORK_INCLUDES} + ${TP_ZLIB_INCLUDES} + ${DMAP_INCLUDES} + ) + +set(TP_SOURCES_ALL + ${TP_SOURCES} + ${TP_FRAMEWORK_SOURCES} + ${TP_ZLIB_SOURCES} + ${DMAP_SOURCES} + ) + +source_group("main" FILES ${TP_INCLUDES}) +source_group("main" FILES ${TP_SOURCES}) +source_group("dmap" FILES ${DMAP_INCLUDES}) +source_group("dmap" FILES ${DMAP_SOURCES}) +source_group("framework" FILES ${TP_FRAMEWORK_INCLUDES}) +source_group("framework" FILES ${TP_FRAMEWORK_SOURCES}) +#source_group("zlib" FILES ${TP_ZLIB_INCLUDES}) +#source_group("zlib" FILES ${TP_ZLIB_SOURCES}) + +set(TP_PRECOMPILED_SOURCES ${TP_SOURCES_ALL}) +#list(REMOVE_ITEM TP_PRECOMPILED_SOURCES ${TP_ZLIB_SOURCES}) + +include_directories( + . + ../../idlib + ../../libs/zlib + ) + +if(MSVC) + list(REMOVE_ITEM TP_PRECOMPILED_SOURCES precompiled.cpp) + + #foreach( src_file ${TP_PRECOMPILED_SOURCES} ) + # message(STATUS "-include precompiled.h for ${src_file}") + #endforeach() + + #set_target_properties(idlib PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h") + set_source_files_properties(precompiled.cpp + PROPERTIES + COMPILE_FLAGS "/Ycprecompiled.h" + OBJECT_OUTPUTS "precompiled.pch" + ) + + set_source_files_properties( + ${TP_PRECOMPILED_SOURCES} + PROPERTIES + COMPILE_FLAGS "/Yuprecompiled.h" + OBJECT_DEPENDS "precompiled.pch" + ) + + add_executable(rbdmap ${TP_SOURCES_ALL} ${TP_INCLUDES_ALL}) + add_dependencies(rbdmap idlib) + target_link_libraries(rbdmap idlib winmm) + +else() + if (USE_PRECOMPILED_HEADERS) + foreach( src_file ${TP_PRECOMPILED_SOURCES} ) + #message(STATUS "-include precompiled.h for ${src_file}") + set_source_files_properties( + ${src_file} + PROPERTIES + COMPILE_FLAGS "-include ${CMAKE_CURRENT_SOURCE_DIR}/precompiled.h" + ) + endforeach() + endif() + + include_directories(.) + + if (USE_PRECOMPILED_HEADERS) + # precompiled magic for GCC/clang, adapted from https://gist.github.com/573926 + STRING(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" _flags_var_name) + SET(_compiler_FLAGS "${${_flags_var_name}} -std=c++${CMAKE_CXX_STANDARD}") + GET_DIRECTORY_PROPERTY(_directory_flags INCLUDE_DIRECTORIES) + FOREACH(item ${_directory_flags}) + LIST(APPEND _compiler_FLAGS " -I${item}") + ENDFOREACH(item) + endif() + + GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS) + LIST(APPEND _compiler_FLAGS ${_directory_flags}) + + SEPARATE_ARGUMENTS(_compiler_FLAGS) + + if (USE_PRECOMPILED_HEADERS) + add_custom_target(precomp_header_typeinfo ALL + COMMAND ${CMAKE_CXX_COMPILER} ${_compiler_FLAGS} -x c++-header precompiled.h -o precompiled.h.gch + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Creating idlib/precompiled.h.gch for typeinfogen" + ) + endif() + + add_executable(typeinfogen ${TP_SOURCES_ALL} ${TP_INCLUDES_ALL}) + add_dependencies(typeinfogen idlib) + if (USE_PRECOMPILED_HEADERS) + add_dependencies(typeinfogen precomp_header_typeinfo) + endif() + target_link_libraries(typeinfogen idlib) + +endif() + + diff --git a/neo/tools/compilers/precompiled.cpp b/neo/tools/compilers/precompiled.cpp new file mode 100644 index 00000000..e669d27b --- /dev/null +++ b/neo/tools/compilers/precompiled.cpp @@ -0,0 +1,29 @@ +/* +=========================================================================== + +Doom 3 BFG Edition GPL Source Code +Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. + +This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). + +Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Doom 3 BFG Edition Source Code. If not, see . + +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. + +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. + +=========================================================================== +*/ + +#include "precompiled.h" diff --git a/neo/tools/compilers/precompiled.h b/neo/tools/compilers/precompiled.h new file mode 100644 index 00000000..40ed0473 --- /dev/null +++ b/neo/tools/compilers/precompiled.h @@ -0,0 +1 @@ +#include "../idlib/precompiled.h" \ No newline at end of file