Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 4cf0299

Browse files
authored
Merge pull request #490 from cortex-command-community/move_to_data
Sort mods and core game modules into dedicated directories
2 parents 39d769d + 83c018d commit 4cf0299

28 files changed

+415
-214
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ compile_commands.json
2222
MemCleanupInfo.txt
2323
RTEA.vcxproj.user
2424
.DS_Store
25-
.vscode
25+
.vscode

Activities/GAScripted.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ int GAScripted::ReadProperty(const std::string_view &propName, Reader &reader) {
136136
int GAScripted::Save(Writer &writer) const {
137137
// Call the script OnSave() function, if it exists
138138
g_LuaMan.RunScriptString("if " + m_LuaClassName + " and " + m_LuaClassName + ".OnSave then " + m_LuaClassName + ":OnSave(); end");
139-
139+
140140
GameActivity::Save(writer);
141141

142142
writer.NewPropertyWithValue("ScriptPath", m_ScriptPath);
@@ -510,7 +510,7 @@ void GAScripted::Draw(BITMAP *pTargetBitmap, const Vector &targetPos) {
510510

511511
void GAScripted::CollectRequiredAreas() {
512512
// Open the script file so we can check it out
513-
std::ifstream *pScriptFile = new std::ifstream(m_ScriptPath.c_str());
513+
std::ifstream *pScriptFile = new std::ifstream(g_PresetMan.GetFullModulePath(m_ScriptPath.c_str()));
514514
if (!pScriptFile->good()) {
515515
return;
516516
}

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ This can be accessed via the new Lua (R/W) `SettingsMan` property `AIUpdateInter
625625

626626
- Swapped to SDL2 for window management and input handling.
627627

628+
- `Settings.ini` and player loadouts (BuyMenu presets) are now stored in the `Userdata` directory instead of `Base.rte`.
629+
628630
- Lua scripts are now run in a more efficient way. As part of this change, `PieSlice` scripts need to be reloaded like `MovableObject` scripts (i.e. using `pieSlice:ReloadScripts()`, in order for their changes to be reflected in-game.
629631
`PresetMan:ReloadAllScripts()` will reload `PieSlice` preset scripts, like it does for `MovableObject`s.
630632

Entities/MovableObject.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ int MovableObject::ReadProperty(const std::string_view &propName, Reader &reader
334334
else if (propName == "HUDVisible")
335335
reader >> m_HUDVisible;
336336
else if (propName == "ScriptPath") {
337-
std::string scriptPath = CorrectBackslashesInPath(reader.ReadPropValue());
337+
std::string scriptPath = g_PresetMan.GetFullModulePath(reader.ReadPropValue());
338338
switch (LoadScript(scriptPath)) {
339339
case 0:
340340
break;
@@ -490,7 +490,7 @@ int MovableObject::Save(Writer &writer) const
490490
writer << m_IgnoreTerrain;
491491
writer.NewProperty("SimUpdatesBetweenScriptedUpdates");
492492
writer << m_SimUpdatesBetweenScriptedUpdates;
493-
493+
494494
return 0;
495495
}
496496

@@ -687,7 +687,7 @@ MovableObject::MovableObject(const MovableObject &reference):
687687
m_AgeTimer(reference.GetAge()),
688688
m_Lifetime(reference.GetLifetime())
689689
{
690-
690+
691691
}
692692
*/
693693

@@ -866,7 +866,7 @@ void MovableObject::PreTravel()
866866

867867
void MovableObject::Travel()
868868
{
869-
869+
870870
}
871871

872872

@@ -946,7 +946,7 @@ void MovableObject::Draw(BITMAP* targetBitmap, const Vector& targetPos, DrawMode
946946
if (mode == g_DrawMOID && m_MOID == g_NoMOID) {
947947
return;
948948
}
949-
949+
950950
g_SceneMan.RegisterDrawing(targetBitmap, mode == g_DrawNoMOID ? g_NoMOID : m_MOID, m_Pos - targetPos, 1.0F);
951951
}
952952

Entities/Scene.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,14 +1029,15 @@ int Scene::ExpandAIPlanAssemblySchemes()
10291029

10301030
int Scene::SaveData(std::string pathBase)
10311031
{
1032-
if (pathBase.empty())
1032+
const std::string fullPathBase = g_PresetMan.GetFullModulePath(pathBase);
1033+
if (fullPathBase.empty())
10331034
return -1;
10341035

10351036
if (!m_pTerrain)
10361037
return 0;
10371038

10381039
// Save Terrain's data
1039-
if (m_pTerrain->SaveData(pathBase) < 0)
1040+
if (m_pTerrain->SaveData(fullPathBase) < 0)
10401041
{
10411042
RTEAbort("Saving Terrain " + m_pTerrain->GetPresetName() + "\'s data failed!");
10421043
return -1;
@@ -1052,7 +1053,7 @@ int Scene::SaveData(std::string pathBase)
10521053
{
10531054
std::snprintf(str, sizeof(str), "T%d", team);
10541055
// Save unseen layer data to disk
1055-
if (m_apUnseenLayer[team]->SaveData(pathBase + " US" + str + ".png") < 0)
1056+
if (m_apUnseenLayer[team]->SaveData(fullPathBase + " US" + str + ".png") < 0)
10561057
{
10571058
g_ConsoleMan.PrintString("ERROR: Saving unseen layer " + m_apUnseenLayer[team]->GetPresetName() + "\'s data failed!");
10581059
return -1;

GUI/GUIControlManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "GUI.h"
2+
#include "PresetMan.h"
23

34
using namespace RTE;
45

@@ -404,7 +405,8 @@ bool GUIControlManager::Save(GUIWriter *W) {
404405

405406
bool GUIControlManager::Load(const std::string &Filename, bool keepOld) {
406407
GUIReader reader;
407-
if (reader.Create(Filename.c_str()) != 0) {
408+
const std::string pathFile = g_PresetMan.GetFullModulePath(Filename);
409+
if (reader.Create(pathFile.c_str()) != 0) {
408410
return false;
409411
}
410412

GUI/GUISkin.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "GUI.h"
22
#include "GUIReader.h"
3+
#include "PresetMan.h"
34

45
using namespace RTE;
56

@@ -37,7 +38,13 @@ bool GUISkin::Load(const std::string &directory, const std::string &fileName) {
3738
// Destroy any previous instances
3839
Destroy();
3940

40-
m_Directory = !directory.empty() ? (directory + "/") : "";
41+
if (!directory.empty()) {
42+
m_Directory = g_PresetMan.GetFullModulePath(directory) + "/";
43+
} else {
44+
// Empty directory means file can be loaded from anywhere in the working directory so need to figure out in what data directory the file actually is from fileName.
45+
std::string fileFullPath = g_PresetMan.GetFullModulePath(fileName);
46+
m_Directory = fileFullPath.substr(0, fileFullPath.find_first_of("/\\") + 1);
47+
}
4148

4249
GUIReader skinFile;
4350
if (skinFile.Create(m_Directory + fileName) == -1) {

Lua/LuaBindingsManagers.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ namespace RTE {
201201
.def("ReadReflectedPreset", &PresetMan::ReadReflectedPreset)
202202
.def("ReloadEntityPreset", &LuaAdaptersPresetMan::ReloadEntityPreset1)
203203
.def("ReloadEntityPreset", &LuaAdaptersPresetMan::ReloadEntityPreset2)
204-
.def("ReloadAllScripts", &PresetMan::ReloadAllScripts);
204+
.def("ReloadAllScripts", &PresetMan::ReloadAllScripts)
205+
.def("IsModuleOfficial", &PresetMan::IsModuleOfficial)
206+
.def("IsModuleUserdata", &PresetMan::IsModuleUserdata)
207+
.def("GetFullModulePath", &PresetMan::GetFullModulePath);
205208
}
206209

207210
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Managers/ActivityMan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ namespace RTE {
103103
modifiableScene->GetTerrain()->MigrateToModule(g_PresetMan.GetModuleID(c_UserScriptedSavesModuleName));
104104

105105
// Block the main thread for a bit to let the Writer access the relevant data.
106-
std::unique_ptr<Writer> writer(std::make_unique<Writer>(c_UserScriptedSavesModuleName + "/" + fileName + ".ini"));
106+
std::unique_ptr<Writer> writer(std::make_unique<Writer>(g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/" + fileName + ".ini"));
107107
writer->NewPropertyWithValue("Activity", activity);
108108

109109
// Pull all stuff from MovableMan into the Scene for saving, so existing Actors/ADoors are saved, without transferring ownership, so the game can continue.
@@ -144,7 +144,7 @@ namespace RTE {
144144
std::unique_ptr<Scene> scene(std::make_unique<Scene>());
145145
std::unique_ptr<GAScripted> activity(std::make_unique<GAScripted>());
146146

147-
Reader reader(c_UserScriptedSavesModuleName + "/" + fileName + ".ini", true, nullptr, false);
147+
Reader reader(g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/" + fileName + ".ini", true, nullptr, false);
148148
if (!reader.ReaderOK()) {
149149
g_ConsoleMan.PrintString("ERROR: Game loading failed! Make sure you have a saved game called \"" + fileName + "\"");
150150
return false;

Managers/AudioMan.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "ActivityMan.h"
99
#include "SoundContainer.h"
1010
#include "GUISound.h"
11+
#include "PresetMan.h"
1112

1213
namespace RTE {
1314

@@ -285,13 +286,16 @@ namespace RTE {
285286

286287
void AudioMan::PlayMusic(const char *filePath, int loops, float volumeOverrideIfNotMuted) {
287288
if (m_AudioEnabled) {
288-
if (m_IsInMultiplayerMode) { RegisterMusicEvent(-1, MUSIC_PLAY, filePath, loops); }
289+
const std::string fullFilePath = g_PresetMan.GetFullModulePath(filePath);
290+
if (m_IsInMultiplayerMode) {
291+
RegisterMusicEvent(-1, NetworkMusicState::MUSIC_PLAY, fullFilePath.c_str(), loops);
292+
}
289293

290294
bool musicIsPlaying;
291295
FMOD_RESULT result = m_MusicChannelGroup->isPlaying(&musicIsPlaying);
292296
if (result == FMOD_OK && musicIsPlaying) {
293297
bool doNotPlayNextStream = true;
294-
FMOD_RESULT result = m_MusicChannelGroup->setUserData(&doNotPlayNextStream);
298+
result = m_MusicChannelGroup->setUserData(&doNotPlayNextStream);
295299
result = (result == FMOD_OK) ? m_MusicChannelGroup->stop() : result;
296300
result = (result == FMOD_OK) ? m_MusicChannelGroup->setUserData(nullptr) : result;
297301
}
@@ -302,22 +306,23 @@ namespace RTE {
302306

303307
FMOD::Sound *musicStream;
304308

305-
result = m_AudioSystem->createStream(filePath, ((loops == 0 || loops == 1) ? FMOD_LOOP_OFF : FMOD_LOOP_NORMAL), nullptr, &musicStream);
309+
result = m_AudioSystem->createStream(fullFilePath.c_str(), ((loops == 0 || loops == 1) ? FMOD_LOOP_OFF : FMOD_LOOP_NORMAL), nullptr, &musicStream);
310+
306311
if (result != FMOD_OK) {
307-
g_ConsoleMan.PrintString("ERROR: Could not open music file " + std::string(filePath) + ": " + std::string(FMOD_ErrorString(result)));
312+
g_ConsoleMan.PrintString("ERROR: Could not open music file " + fullFilePath + ": " + std::string(FMOD_ErrorString(result)));
308313
return;
309314
}
310315

311316
result = musicStream->setLoopCount(loops);
312317
if (result != FMOD_OK && (loops != 0 && loops != 1)) {
313-
g_ConsoleMan.PrintString("ERROR: Failed to set looping for music file: " + std::string(filePath) + ". This means it will only play 1 time, instead of " + (loops == 0 ? "looping endlessly." : loops + " times.") + std::string(FMOD_ErrorString(result)));
318+
g_ConsoleMan.PrintString("ERROR: Failed to set looping for music file: " + fullFilePath + ". This means it will only play 1 time, instead of " + (loops == 0 ? "looping endlessly." : loops + " times.") + std::string(FMOD_ErrorString(result)));
314319
}
315320

316321
FMOD::Channel *musicChannel;
317322
result = musicStream->set3DMinMaxDistance(c_SoundMaxAudibleDistance, c_SoundMaxAudibleDistance);
318323
result = (result == FMOD_OK) ? m_AudioSystem->playSound(musicStream, m_MusicChannelGroup, true, &musicChannel) : result;
319324
if (result != FMOD_OK) {
320-
g_ConsoleMan.PrintString("ERROR: Could not play music file: " + std::string(filePath) + ": " + std::string(FMOD_ErrorString(result)));
325+
g_ConsoleMan.PrintString("ERROR: Could not play music file: " + fullFilePath + ": " + std::string(FMOD_ErrorString(result)));
321326
return;
322327
}
323328
result = musicChannel->setPriority(PRIORITY_HIGH);
@@ -327,11 +332,11 @@ namespace RTE {
327332
volumeOverrideIfNotMuted = std::clamp((volumeOverrideIfNotMuted > 1.0F ? volumeOverrideIfNotMuted / 100.0F : volumeOverrideIfNotMuted), 0.0F, 1.0F);
328333
result = musicChannel->setVolume(volumeOverrideIfNotMuted);
329334
if (result != FMOD_OK && (loops != 0 && loops != 1)) {
330-
g_ConsoleMan.PrintString("ERROR: Failed to set volume override for music file: " + std::string(filePath) + ". This means it will stay at " + std::to_string(m_MusicVolume) + ": " + std::string(FMOD_ErrorString(result)));
335+
g_ConsoleMan.PrintString("ERROR: Failed to set volume override for music file: " + fullFilePath + ". This means it will stay at " + std::to_string(m_MusicVolume) + ": " + std::string(FMOD_ErrorString(result)));
331336
}
332337
}
333338

334-
m_MusicPath = filePath;
339+
m_MusicPath = fullFilePath;
335340

336341
result = musicChannel->setCallback(MusicChannelEndedCallback);
337342
if (result != FMOD_OK) {

0 commit comments

Comments
 (0)