Skip to content

Commit

Permalink
* support multiple Extra Resource Paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Garux committed Aug 22, 2023
1 parent c9d8265 commit 158b724
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
6 changes: 3 additions & 3 deletions radiant/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ class ToolXMLConstructor final : public XMLElementParser
void flush(){
if ( !m_buffer.empty() ) {
m_tool.push_back( new VariableString( m_buffer.c_str() ) );
// q3map2 ExtraResoucePath hack
// q3map2 ExtraResourcePaths hack
if( strstr( m_buffer.c_str(), "[RadiantPath]q3map2.[ExecutableType]" ) != nullptr // is q3map2
&& strstr( m_buffer.c_str(), "[ExtraResoucePath]" ) == nullptr ){ // has no extra path right away (could have been added by this before)
m_tool.push_back( new VariableString( "[ExtraResoucePath]" ) );
&& strstr( m_buffer.c_str(), "[ExtraResourcePaths]" ) == nullptr ){ // has no extra path right away (could have been added by this before)
m_tool.push_back( new VariableString( "[ExtraResourcePaths]" ) );
}
m_buffer.clear();
}
Expand Down
32 changes: 18 additions & 14 deletions radiant/mainframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ void EnginePath_Unrealise(){

static CopiedString g_installedDevFilesPath; // track last engine path, where dev files installation occured, to prompt again when changed

static void installDevFiles( const CopiedString& enginePath ){
if( !path_equal( enginePath.c_str(), g_installedDevFilesPath.c_str() ) ){
static void installDevFiles(){
if( !path_equal( g_strEnginePath.c_str(), g_installedDevFilesPath.c_str() ) ){
ASSERT_MESSAGE( g_enginepath_unrealised != 0, "installDevFiles: engine path realised" );
DoInstallDevFilesDlg( enginePath.c_str() );
g_installedDevFilesPath = enginePath;
DoInstallDevFilesDlg( g_strEnginePath.c_str() );
g_installedDevFilesPath = g_strEnginePath;
}
}

Expand All @@ -352,7 +352,7 @@ void setEnginePath( CopiedString& self, const char* value ){

self = buffer.c_str();

installDevFiles( self );
installDevFiles();

EnginePath_Realise();
}
Expand All @@ -362,10 +362,10 @@ typedef ReferenceCaller1<CopiedString, const char*, setEnginePath> EnginePathImp

// Extra Resource Path

CopiedString g_strExtraResourcePath;
std::array<CopiedString, 5> g_strExtraResourcePaths;

const char* ExtraResourcePath_get(){
return g_strExtraResourcePath.c_str();
const std::array<CopiedString, 5>& ExtraResourcePaths_get(){
return g_strExtraResourcePaths;
}


Expand Down Expand Up @@ -421,10 +421,11 @@ void Paths_constructPreferences( PreferencesPage& page ){
void Paths_constructPage( PreferenceGroup& group ){
PreferencesPage page( group.createPage( "Paths", "Path Settings" ) );
Paths_constructPreferences( page );
page.appendPathEntry( "Extra Resource Path", true,
StringImportCallback( EnginePathImportCaller( g_strExtraResourcePath ) ),
StringExportCallback( StringExportCaller( g_strExtraResourcePath ) )
);
for( auto& extraPath : g_strExtraResourcePaths )
page.appendPathEntry( "Extra Resource Path", true,
StringImportCallback( EnginePathImportCaller( extraPath ) ),
StringExportCallback( StringExportCaller( extraPath ) )
);

}
void Paths_registerPreferencesPage(){
Expand Down Expand Up @@ -486,7 +487,7 @@ void EnginePath_verify(){
g_PathsDialog.DoModal();
g_PathsDialog.Destroy();
}
installDevFiles( g_strEnginePath ); // try this anytime, as engine path may be set via command line or -gamedetect
installDevFiles(); // try this anytime, as engine path may be set via command line or -gamedetect
}

namespace
Expand Down Expand Up @@ -2096,7 +2097,10 @@ void MainFrame_Construct(){
GlobalPreferenceSystem().registerPreference( "OpenGLFont", CopiedStringImportStringCaller( g_OpenGLFont ), CopiedStringExportStringCaller( g_OpenGLFont ) );
GlobalPreferenceSystem().registerPreference( "OpenGLFontSize", IntImportStringCaller( g_OpenGLFontSize ), IntExportStringCaller( g_OpenGLFontSize ) );

GlobalPreferenceSystem().registerPreference( "ExtraResoucePath", CopiedStringImportStringCaller( g_strExtraResourcePath ), CopiedStringExportStringCaller( g_strExtraResourcePath ) );
for( size_t i = 0; i < g_strExtraResourcePaths.size(); ++i )
GlobalPreferenceSystem().registerPreference( StringOutputStream( 32 )( "ExtraResourcePath", i ),
CopiedStringImportStringCaller( g_strExtraResourcePaths[i] ), CopiedStringExportStringCaller( g_strExtraResourcePaths[i] ) );

GlobalPreferenceSystem().registerPreference( "EnginePath", CopiedStringImportStringCaller( g_strEnginePath ), CopiedStringExportStringCaller( g_strEnginePath ) );
GlobalPreferenceSystem().registerPreference( "InstalledDevFilesPath", CopiedStringImportStringCaller( g_installedDevFilesPath ), CopiedStringExportStringCaller( g_installedDevFilesPath ) );
if ( g_strEnginePath.empty() )
Expand Down
3 changes: 1 addition & 2 deletions radiant/mainframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ void Radiant_detachGameToolsPathObserver( ModuleObserver& observer );
void EnginePath_verify();
const char* EnginePath_get();

extern CopiedString g_strExtraResourcePath;
const char* ExtraResourcePath_get();
const std::array<CopiedString, 5>& ExtraResourcePaths_get();

extern CopiedString g_strAppPath;
const char* AppPath_get();
Expand Down
49 changes: 24 additions & 25 deletions radiant/qe3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,29 @@ void QE_InitVFS(){
const char* userRoot = g_qeglobals.m_userEnginePath.c_str();
const char* globalRoot = EnginePath_get();

const char* extrapath = ExtraResourcePath_get();
if( !string_empty( extrapath ) )
GlobalFileSystem().initDirectory( extrapath );
std::vector<CopiedString> paths;
const auto paths_push = [&paths]( const char* newPath ){ // collects unique paths
if( !string_empty( newPath )
&& std::none_of( paths.cbegin(), paths.cend(), [newPath]( const CopiedString& path ){ return path_equal( path.c_str(), newPath ); } ) )
paths.emplace_back( newPath );
};

StringOutputStream str( 256 );
// if we have a mod dir
if ( !path_equal( gamename, basegame ) ) {
// ~/.<gameprefix>/<fs_game>
if ( !path_equal( globalRoot, userRoot ) ) {
GlobalFileSystem().initDirectory( str( userRoot, gamename, '/' ) ); // userGamePath
}

// <fs_basepath>/<fs_game>
{
GlobalFileSystem().initDirectory( str( globalRoot, gamename, '/' ) ); // globalGamePath
}
}
for( const auto& path : ExtraResourcePaths_get() )
paths_push( path.c_str() );

StringOutputStream str( 256 );
// ~/.<gameprefix>/<fs_game>
paths_push( str( userRoot, gamename, '/' ) ); // userGamePath
// <fs_basepath>/<fs_game>
paths_push( str( globalRoot, gamename, '/' ) ); // globalGamePath
// ~/.<gameprefix>/<fs_main>
if ( !path_equal( globalRoot, userRoot ) ) {
GlobalFileSystem().initDirectory( str( userRoot, basegame, '/' ) ); // userBasePath
}

paths_push( str( userRoot, basegame, '/' ) ); // userBasePath
// <fs_basepath>/<fs_main>
{
GlobalFileSystem().initDirectory( str( globalRoot, basegame, '/' ) ); // globalBasePath
}
paths_push( str( globalRoot, basegame, '/' ) ); // globalBasePath

for( const auto& path : paths )
GlobalFileSystem().initDirectory( path.c_str() );
}


Expand Down Expand Up @@ -163,17 +159,20 @@ bool ConfirmModified( const char* title ){
}

void bsp_init(){
StringOutputStream stream( 256 );

build_set_variable( "RadiantPath", AppPath_get() );
build_set_variable( "ExecutableType", RADIANT_EXECUTABLE );
build_set_variable( "EnginePath", EnginePath_get() );
build_set_variable( "UserEnginePath", g_qeglobals.m_userEnginePath.c_str() );
build_set_variable( "ExtraResoucePath", string_empty( ExtraResourcePath_get() )? ""
: StringOutputStream()( " -fs_pakpath ", makeQuoted( ExtraResourcePath_get() ) ) );
for( const auto& path : ExtraResourcePaths_get() )
if( !string_empty( path.c_str() ) )
stream << " -fs_pakpath " << makeQuoted( path );
build_set_variable( "ExtraResourcePaths", stream );
build_set_variable( "MonitorAddress", ( g_WatchBSP_Enabled ) ? RADIANT_MONITOR_ADDRESS : "" );
build_set_variable( "GameName", gamename_get() );

const char* mapname = Map_Name( g_map );
StringOutputStream stream( 256 );
{
build_set_variable( "BspFile", stream( PathExtensionless( mapname ), ".bsp" ) );
}
Expand Down

0 comments on commit 158b724

Please sign in to comment.