]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
radiant: add optional pakpath support
authorThomas Debesse <dev@illwieckz.net>
Sun, 31 Dec 2017 16:21:00 +0000 (17:21 +0100)
committerThomas Debesse <dev@illwieckz.net>
Wed, 3 Jan 2018 20:50:40 +0000 (21:50 +0100)
- 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
radiant/mainframe.h
radiant/map.cpp
radiant/qe3.cpp

index 0baee4873e703dd6e5abd6ba448a65f9fdfdaba2..662f6332cef5e83f1868c042a048ebca1dafac0b 100644 (file)
@@ -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<void(const char*)> &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<void(const char*)> &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<void(const char*)> &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<void(const char*)> &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<void(const char*)> &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<EnginePath>(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<PakPath0>( g_strPakPath[i] ) );
+                       break;
+                       case 1:
+                       page.appendPathEntry( label.c_str(), true, make_property<PakPath1>( g_strPakPath[i] ) );
+                       break;
+                       case 2:
+                       page.appendPathEntry( label.c_str(), true, make_property<PakPath2>( g_strPakPath[i] ) );
+                       break;
+                       case 3:
+                       page.appendPathEntry( label.c_str(), true, make_property<PakPath3>( g_strPakPath[i] ) );
+                       break;
+                       case 4:
+                       page.appendPathEntry( label.c_str(), true, make_property<PakPath4>( 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();
index 944c7b8bbceb513001396163566b3ccf6075fee2..9bf53f6897a0ec323c131ab7788cc22be9e80308 100644 (file)
@@ -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();
 
index 30364b273390df4b601beed3ffa0d2a5f206bad5..3f61f2ce7a59d7649611892c63611e4731726c56 100644 (file)
@@ -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" );
index 7d39afe628a1c55d7d59d48f7e9f46bc55cd6cbf..5360a0ab28368b41b0661d2b303c2198a053c148 100644 (file)
@@ -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";