From 005677494f2e7101b672542b6740c1f155655096 Mon Sep 17 00:00:00 2001 From: dhewg Date: Tue, 20 Dec 2011 16:12:17 +0100 Subject: [PATCH] Initial SDL setup Use SDL_main on all platforms. Fix main() for non-const argv so it matches with the SDL prototype. Adapt win32 WinMain() to main() and get rid of the win32 special case in Common::Init(). --- neo/CMakeLists.txt | 5 +++++ neo/SConstruct | 3 +++ neo/framework/Common.cpp | 14 ++++---------- neo/framework/Common.h | 2 +- neo/sys/linux/main.cpp | 8 +++++--- neo/sys/osx/DOOMController.mm | 12 +++++++----- neo/sys/osx/macosx_sys.mm | 4 ++-- neo/sys/scons/SConscript.core | 2 +- neo/sys/win32/win_main.cpp | 18 ++++++++++-------- 9 files changed, 38 insertions(+), 30 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 3f8197d2..8f86cb48 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -85,6 +85,9 @@ include_directories(${OPENAL_INCLUDE_DIR}) find_package(OpenGL REQUIRED) include_directories(${OPENGL_INCLUDE_DIR}) +find_package(SDL REQUIRED) +include_directories(${SDL_INCLUDE_DIR}) + if (UNIX AND NOT APPLE) find_package(X11 REQUIRED) add_definitions(-DXTHREADS) @@ -694,6 +697,7 @@ if (CORE) ${VORBIS_LIBRARIES} ${CURL_LIBRARY} ${JPEG_LIBRARY} + ${SDL_LIBRARY} ${sys_libs} ) endif() @@ -716,6 +720,7 @@ if (DEDICATED) ${VORBIS_LIBRARIES} ${CURL_LIBRARY} ${JPEG_LIBRARY} + ${SDL_LIBRARY} ${sys_libs} ) endif() diff --git a/neo/SConstruct b/neo/SConstruct index 6d6ba4ed..6866282b 100644 --- a/neo/SConstruct +++ b/neo/SConstruct @@ -287,7 +287,10 @@ BASECPPFLAGS.append( '-fvisibility=hidden' ) if ( "BSD" in g_os ): BASECPPFLAGS.append( '-I/usr/local/include' ) + BASECPPFLAGS.append( '-I/usr/local/include/SDL' ) BASELINKFLAGS.append('-L/usr/local/lib') +else: + BASECPPFLAGS.append( '-I/usr/include/SDL' ) BASECPPFLAGS.append( '-I.' ) diff --git a/neo/framework/Common.cpp b/neo/framework/Common.cpp index 72ee8fe5..01903b20 100644 --- a/neo/framework/Common.cpp +++ b/neo/framework/Common.cpp @@ -133,7 +133,7 @@ class idCommonLocal : public idCommon { public: idCommonLocal( void ); - virtual void Init( int argc, const char **argv, const char *cmdline ); + virtual void Init( int argc, char **argv ); virtual void Shutdown( void ); virtual void Quit( void ); virtual bool IsInitialized( void ) const; @@ -181,7 +181,7 @@ private: void InitRenderSystem( void ); void InitSIMD( void ); bool AddStartupCommands( void ); - void ParseCommandLine( int argc, const char **argv ); + void ParseCommandLine( int argc, char **argv ); void ClearCommandLine( void ); bool SafeMode( void ); void CheckToolMode( void ); @@ -834,7 +834,7 @@ idCmdArgs com_consoleLines[MAX_CONSOLE_LINES]; idCommonLocal::ParseCommandLine ================== */ -void idCommonLocal::ParseCommandLine( int argc, const char **argv ) { +void idCommonLocal::ParseCommandLine( int argc, char **argv ) { int i; com_numConsoleLines = 0; @@ -2782,7 +2782,7 @@ void idCommonLocal::SetMachineSpec( void ) { idCommonLocal::Init ================= */ -void idCommonLocal::Init( int argc, const char **argv, const char *cmdline ) { +void idCommonLocal::Init( int argc, char **argv ) { try { // set interface pointers used by idLib @@ -2798,12 +2798,6 @@ void idCommonLocal::Init( int argc, const char **argv, const char *cmdline ) { ClearWarnings( GAME_NAME " initialization" ); // parse command line options - idCmdArgs args; - if ( cmdline ) { - // tokenize if the OS doesn't do it for us - args.TokenizeString( cmdline, true ); - argv = args.GetArgs( &argc ); - } ParseCommandLine( argc, argv ); // init console command system diff --git a/neo/framework/Common.h b/neo/framework/Common.h index 70886845..3380eee1 100644 --- a/neo/framework/Common.h +++ b/neo/framework/Common.h @@ -120,7 +120,7 @@ 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 **argv, const char *cmdline ) = 0; + virtual void Init( int argc, char **argv ) = 0; // Shuts down everything. virtual void Shutdown( void ) = 0; diff --git a/neo/sys/linux/main.cpp b/neo/sys/linux/main.cpp index 8d672fd0..1eb406d2 100644 --- a/neo/sys/linux/main.cpp +++ b/neo/sys/linux/main.cpp @@ -37,6 +37,8 @@ If you have questions concerning this license or the applicable additional terms #include #endif +#include + #include "sys/platform.h" #include "framework/Licensee.h" #include "framework/FileSystem.h" @@ -645,7 +647,7 @@ void abrt_func( mcheck_status status ) { main =============== */ -int main(int argc, const char **argv) { +int main(int argc, char **argv) { #ifdef ID_MCHECK // must have -lmcheck linkage mcheck( abrt_func ); @@ -655,9 +657,9 @@ int main(int argc, const char **argv) { Posix_EarlyInit( ); if ( argc > 1 ) { - common->Init( argc-1, &argv[1], NULL ); + common->Init( argc-1, &argv[1] ); } else { - common->Init( 0, NULL, NULL ); + common->Init( 0, NULL ); } Posix_LateInit( ); diff --git a/neo/sys/osx/DOOMController.mm b/neo/sys/osx/DOOMController.mm index ddbeb0a2..dc2bb977 100644 --- a/neo/sys/osx/DOOMController.mm +++ b/neo/sys/osx/DOOMController.mm @@ -39,6 +39,8 @@ If you have questions concerning this license or the applicable additional terms #import #import +#import + #import "sys/platform.h" #import "idlib/Str.h" #import "framework/Licensee.h" @@ -243,7 +245,7 @@ extern void CL_Quit_f(void); { NSAutoreleasePool *pool; int argc = 0; - const char *argv[MAX_ARGC]; + char *argv[MAX_ARGC]; NSProcessInfo *processInfo; NSArray *arguments; unsigned int argumentIndex, argumentCount; @@ -338,9 +340,9 @@ extern void CL_Quit_f(void); // Finder passes the process serial number as only argument after the program path // nuke it if we see it if ( argc > 1 && strncmp( argv[ 1 ], "-psn", 4 ) ) { - common->Init( argc-1, &argv[1], NULL ); + common->Init( argc-1, &argv[1] ); } else { - common->Init( 0, NULL, NULL ); + common->Init( 0, NULL ); } Posix_LateInit( ); @@ -837,8 +839,8 @@ void OSX_GetVideoCard( int& outVendorId, int& outDeviceId ) main =============== */ -int main( int argc, const char *argv[] ) { - return NSApplicationMain( argc, argv ); +int main( int argc, char *argv[] ) { + return NSApplicationMain( argc, (const char **)argv ); } bool FormatRegCode(const char* inRegCode, char* outRegCode) diff --git a/neo/sys/osx/macosx_sys.mm b/neo/sys/osx/macosx_sys.mm index e1268c0c..2b75d415 100644 --- a/neo/sys/osx/macosx_sys.mm +++ b/neo/sys/osx/macosx_sys.mm @@ -56,8 +56,8 @@ char *Sys_GetClipboardData( void ); // note that this isn't journaled... void Sys_Print( const char *msg ); //=========================================================================== -int main(int argc, const char *argv[]) { - return NSApplicationMain(argc, argv); +int main(int argc, char *argv[]) { + return NSApplicationMain(argc, (const char **)argv); } //=========================================================================== diff --git a/neo/sys/scons/SConscript.core b/neo/sys/scons/SConscript.core index b95e8303..ff26403b 100644 --- a/neo/sys/scons/SConscript.core +++ b/neo/sys/scons/SConscript.core @@ -240,7 +240,7 @@ if ( local_demo == 1 ): if ( local_curl == 0 ): local_env.Append( CPPDEFINES = [ 'ID_ENABLE_CURL=0' ] ) -local_env.Append( LIBS = [ 'pthread', 'jpeg', 'vorbisfile' ] ) +local_env.Append( LIBS = [ 'SDL', 'SDLmain', 'pthread', 'jpeg', 'vorbisfile' ] ) if ( local_dedicated == 0 ): local_env.Append( LIBS = [ 'GL' ] ) diff --git a/neo/sys/win32/win_main.cpp b/neo/sys/win32/win_main.cpp index 4a814e6a..0c46a35b 100644 --- a/neo/sys/win32/win_main.cpp +++ b/neo/sys/win32/win_main.cpp @@ -50,6 +50,8 @@ If you have questions concerning this license or the applicable additional terms #include #endif +#include + idCVar Win32Vars_t::sys_arch( "sys_arch", "", CVAR_SYSTEM | CVAR_INIT, "" ); idCVar Win32Vars_t::sys_cpustring( "sys_cpustring", "detect", CVAR_SYSTEM | CVAR_INIT, "" ); idCVar Win32Vars_t::in_mouse( "in_mouse", "1", CVAR_SYSTEM | CVAR_BOOL, "enable mouse input" ); @@ -66,8 +68,6 @@ idCVar Win32Vars_t::win_allowMultipleInstances( "win_allowMultipleInstances", "0 Win32Vars_t win32; -static char sys_cmdline[MAX_STRING_CHARS]; - // not a hard limit, just what we keep track of for debugging xthreadInfo *g_threads[MAX_THREADS]; @@ -1220,16 +1220,14 @@ int Sys_FPU_PrintStateFlags( char *ptr, int ctrl, int stat, int tags, int inof, WinMain ================== */ -int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { - +int main(int argc, char *argv[]) { const HCURSOR hcurSave = ::SetCursor( LoadCursor( 0, IDC_WAIT ) ); Sys_SetPhysicalWorkMemory( 192 << 20, 1024 << 20 ); Sys_GetCurrentMemoryStatus( exeLaunchMemoryStats ); - win32.hInstance = hInstance; - idStr::Copynz( sys_cmdline, lpCmdLine, sizeof( sys_cmdline ) ); + win32.hInstance = GetModuleHandle(NULL); // done before Com/Sys_Init since we need this for error output Sys_CreateConsole(); @@ -1252,7 +1250,11 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin // Sys_FPU_EnableExceptions( TEST_FPU_EXCEPTIONS ); Sys_FPU_SetPrecision( FPU_PRECISION_DOUBLE_EXTENDED ); - common->Init( 0, NULL, lpCmdLine ); + if ( argc > 1 ) { + common->Init( argc-1, &argv[1] ); + } else { + common->Init( 0, NULL ); + } #if TEST_FPU_EXCEPTIONS != 0 common->Printf( Sys_FPU_GetState() ); @@ -1281,7 +1283,7 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin ::SetCursor( hcurSave ); // Launch the script debugger - if ( strstr( lpCmdLine, "+debugger" ) ) { + if ( strstr( GetCommandLine(), "+debugger" ) ) { // DebuggerClientInit( lpCmdLine ); return 0; }