From a34196919ed992e3cda24ef9603daf262669b267 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sun, 31 Dec 2017 17:21:00 +0100 Subject: [PATCH] radiant: add optional pakpath support - add optional pakpath support currently an hardcoded number of 5 extra pakpath are possible this is still better than nothing - if build profile use [ExtraQ3map2Args] keyword, radiant pass the extra pakpaths options to q3map2 thanks to the -fs_pakpath switch that was added in a previous commit --- radiant/mainframe.cpp | 133 ++++++++++++++++++++++++++++++++++++++++-- radiant/mainframe.h | 4 ++ radiant/map.cpp | 13 ++++- radiant/qe3.cpp | 18 ++++++ 4 files changed, 163 insertions(+), 5 deletions(-) diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 0baee487..662f6332 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -371,6 +371,59 @@ void setEnginePath( const char* path ){ } } +// Pak Path + +CopiedString g_strPakPath[g_pakPathCount] = { "", "", "", "", "" }; +ModuleObservers g_pakPathObservers[g_pakPathCount]; +std::size_t g_pakpath_unrealised[g_pakPathCount] = { 1, 1, 1, 1, 1 }; + +void Radiant_attachPakPathObserver( int num, ModuleObserver& observer ){ + g_pakPathObservers[num].attach( observer ); +} + +void Radiant_detachPakPathObserver( int num, ModuleObserver& observer ){ + g_pakPathObservers[num].detach( observer ); +} + + +void PakPath_Realise( int num ){ + if ( --g_pakpath_unrealised[num] == 0 ) { + g_pakPathObservers[num].realise(); + } +} + +const char* PakPath_get( int num ){ + std::string message = "PakPath_get: pak path " + std::to_string(num) + " not realised"; + ASSERT_MESSAGE( g_pakpath_unrealised[num] == 0, message.c_str() ); + return g_strPakPath[num].c_str(); +} + +void PakPath_Unrealise( int num ){ + if ( ++g_pakpath_unrealised[num] == 1 ) { + g_pakPathObservers[num].unrealise(); + } +} + +void setPakPath( int num, const char* path ){ + if (!g_strcmp0( path, "")) { + g_strPakPath[num] = ""; + return; + } + + StringOutputStream buffer( 256 ); + buffer << DirectoryCleaned( path ); + if ( !path_equal( buffer.c_str(), g_strPakPath[num].c_str() ) ) { + std::string message = "Changing Pak Path " + std::to_string(num); + ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", message.c_str() ); + + PakPath_Unrealise(num); + + g_strPakPath[num] = buffer.c_str(); + + PakPath_Realise(num); + } +} + // App Path @@ -420,12 +473,79 @@ struct EnginePath { } static void Import(CopiedString &self, const char *value) { - setEnginePath(value); + setEnginePath( value ); +} +}; + +struct PakPath0 { + static void Export( const CopiedString &self, const Callback &returnz ) { + returnz( self.c_str() ); + } + + static void Import( CopiedString &self, const char *value ) { + setPakPath( 0, value ); + } +}; +struct PakPath1 { + static void Export( const CopiedString &self, const Callback &returnz ) { + returnz( self.c_str() ); + } + + static void Import( CopiedString &self, const char *value ) { + setPakPath( 1, value ); + } +}; +struct PakPath2 { + static void Export( const CopiedString &self, const Callback &returnz ) { + returnz( self.c_str() ); + } + + static void Import( CopiedString &self, const char *value ) { + setPakPath( 2, value ); + } +}; +struct PakPath3 { + static void Export( const CopiedString &self, const Callback &returnz ) { + returnz( self.c_str() ); + } + + static void Import( CopiedString &self, const char *value ) { + setPakPath( 3, value ); + } +}; +struct PakPath4 { + static void Export( const CopiedString &self, const Callback &returnz ) { + returnz( self.c_str() ); + } + + static void Import( CopiedString &self, const char *value ) { + setPakPath( 4, value ); } }; void Paths_constructPreferences( PreferencesPage& page ){ page.appendPathEntry( "Engine Path", true, make_property(g_strEnginePath) ); + + for ( int i = 0; i < g_pakPathCount; i++ ) { + std::string label = "Pak Path " + std::to_string(i); + switch (i) { + case 0: + page.appendPathEntry( label.c_str(), true, make_property( g_strPakPath[i] ) ); + break; + case 1: + page.appendPathEntry( label.c_str(), true, make_property( g_strPakPath[i] ) ); + break; + case 2: + page.appendPathEntry( label.c_str(), true, make_property( g_strPakPath[i] ) ); + break; + case 3: + page.appendPathEntry( label.c_str(), true, make_property( g_strPakPath[i] ) ); + break; + case 4: + page.appendPathEntry( label.c_str(), true, make_property( g_strPakPath[i] ) ); + break; + } + } } void Paths_constructPage( PreferenceGroup& group ){ PreferencesPage page( group.createPage( "Paths", "Path Settings" ) ); @@ -2659,11 +2779,11 @@ ui::Window create_splash(){ gtk_window_set_decorated(window, false); gtk_window_set_resizable(window, false); gtk_window_set_modal(window, true); - gtk_window_set_default_size(window, -1, -1); - gtk_window_set_position(window, GTK_WIN_POS_CENTER); + gtk_window_set_default_size( window, -1, -1 ); + gtk_window_set_position( window, GTK_WIN_POS_CENTER ); gtk_container_set_border_width(window, 0); - auto image = new_local_image("splash.png"); + auto image = new_local_image( "splash.png" ); image.show(); window.add(image); @@ -3320,6 +3440,11 @@ void MainFrame_Construct(){ GlobalPreferenceSystem().registerPreference( "EnginePath", make_property_string( g_strEnginePath ) ); + for ( int i = 0; i < g_pakPathCount; i++ ) { + std::string label = "PakPath" + std::to_string(i); + GlobalPreferenceSystem().registerPreference( label.c_str(), make_property_string( g_strPakPath[i] ) ); + } + g_Layout_viewStyle.useLatched(); g_Layout_enableDetachableMenus.useLatched(); g_Layout_enablePatchToolbar.useLatched(); diff --git a/radiant/mainframe.h b/radiant/mainframe.h index 944c7b8b..9bf53f68 100644 --- a/radiant/mainframe.h +++ b/radiant/mainframe.h @@ -205,6 +205,10 @@ void EnginePath_verify(); const char* EnginePath_get(); const char* QERApp_GetGamePath(); +const int g_pakPathCount = 5; +extern CopiedString g_strPakPath[g_pakPathCount]; +const char* PakPath_get( int num ); + extern CopiedString g_strAppPath; const char* AppPath_get(); diff --git a/radiant/map.cpp b/radiant/map.cpp index 30364b27..3f61f2ce 100644 --- a/radiant/map.cpp +++ b/radiant/map.cpp @@ -1540,7 +1540,18 @@ tryDecompile: output.push_string( EnginePath_get() ); output.push_string( "\" -fs_homepath \"" ); output.push_string( g_qeglobals.m_userEnginePath.c_str() ); - output.push_string( "\" -fs_game " ); + output.push_string( "\"" ); + + // extra pakpaths + for ( int i = 0; i < g_pakPathCount; i++ ) { + if ( g_strcmp0( g_strPakPath[i].c_str(), "") ) { + output.push_string( " -fs_pakpath \"" ); + output.push_string( g_strPakPath[i].c_str() ); + output.push_string( "\"" ); + } + } + + output.push_string( " -fs_game " ); output.push_string( gamename_get() ); output.push_string( " -convert -format " ); output.push_string( Brush::m_type == eBrushTypeQuake3BP ? "map_bp" : "map" ); diff --git a/radiant/qe3.cpp b/radiant/qe3.cpp index 7d39afe6..5360a0ab 100644 --- a/radiant/qe3.cpp +++ b/radiant/qe3.cpp @@ -113,6 +113,13 @@ void QE_InitVFS(){ globalBasePath << globalRoot << basegame << '/'; GlobalFileSystem().initDirectory( globalBasePath.c_str() ); } + + // extra pakpaths + for ( int i = 0; i < g_pakPathCount; i++ ) { + if (g_strcmp0( g_strPakPath[i].c_str(), "")) { + GlobalFileSystem().initDirectory( g_strPakPath[i].c_str() ); + } + } } int g_numbrushes = 0; @@ -167,6 +174,17 @@ void bsp_init(){ build_set_variable( "MonitorAddress", ( g_WatchBSP_Enabled ) ? "127.0.0.1:39000" : "" ); build_set_variable( "GameName", gamename_get() ); + StringBuffer ExtraQ3map2Args; + // extra pakpaths + for ( int i = 0; i < g_pakPathCount; i++ ) { + if ( g_strcmp0( g_strPakPath[i].c_str(), "") ) { + ExtraQ3map2Args.push_string( " -fs_pakpath \"" ); + ExtraQ3map2Args.push_string( g_strPakPath[i].c_str() ); + ExtraQ3map2Args.push_string( "\"" ); + } + } + build_set_variable( "ExtraQ3map2Args", ExtraQ3map2Args.c_str() ); + const char* mapname = Map_Name( g_map ); StringOutputStream name( 256 ); name << StringRange( mapname, path_get_filename_base_end( mapname ) ) << ".bsp"; -- 2.39.2