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

Commit 6dfa856

Browse files
committed
Set full datapath during ContentFile::SetDataPath to not have to do it all over the place and make life more difficult than it needs to be
1 parent 1cf3ca7 commit 6dfa856

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

System/ContentFile.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace RTE {
8989
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
9090

9191
void ContentFile::SetDataPath(const std::string &newDataPath) {
92-
m_DataPath = CorrectBackslashesInPath(newDataPath);
92+
m_DataPath = g_PresetMan.GetFullModulePath(newDataPath);
9393
m_DataPathExtension = std::filesystem::path(m_DataPath).extension().string();
9494

9595
RTEAssert(!m_DataPathExtension.empty(), "Failed to find file extension when trying to find file with path and name:\n" + m_DataPath + "\n" + GetFormattedReaderPosition());
@@ -126,8 +126,7 @@ namespace RTE {
126126
}
127127
}
128128
if (fetchFileInfo) {
129-
std::string altDataPath = g_PresetMan.GetFullModulePath(m_DataPath);
130-
FILE *imageFile = fopen(altDataPath.c_str(), "rb");
129+
FILE *imageFile = fopen(m_DataPath.c_str(), "rb");
131130
RTEAssert(imageFile, "Failed to open file prior to reading info of image file with following path and name:\n\n" + m_DataPath + "\n\nThe file may not exist or be corrupt.");
132131

133132
if (m_DataPathExtension == ".png") {
@@ -223,7 +222,6 @@ namespace RTE {
223222
BITMAP *returnBitmap = nullptr;
224223
const int bitDepth = conversionMode == COLORCONV_8_TO_32 ? BitDepths::ThirtyTwo : BitDepths::Eight;
225224
std::string dataPathToLoad = dataPathToSpecificFrame.empty() ? m_DataPath : dataPathToSpecificFrame;
226-
dataPathToLoad = g_PresetMan.GetFullModulePath(dataPathToLoad);
227225

228226
if (g_PresetMan.GetReloadEntityPresetCalledThisUpdate()) {
229227
ReloadBitmap(dataPathToLoad, conversionMode);
@@ -260,20 +258,18 @@ namespace RTE {
260258
if (m_DataPath.empty() || frameCount < 1) {
261259
return;
262260
}
263-
const std::string dataPathToLoad = g_PresetMan.GetFullModulePath(m_DataPath);
264-
const std::string dataPathWithoutExtensionToLoad = g_PresetMan.GetFullModulePath(m_DataPathWithoutExtension);
265261
vectorToFill.reserve(frameCount);
266262

267263
if (frameCount == 1) {
268264
// Check for 000 in the file name in case it is part of an animation but the FrameCount was set to 1. Do not warn about this because it's normal operation, but warn about incorrect extension.
269-
if (!System::PathExistsCaseSensitive(dataPathToLoad)) {
265+
if (!System::PathExistsCaseSensitive(m_DataPath)) {
270266
const std::string altFileExtension = (m_DataPathExtension == ".png") ? ".bmp" : ".png";
271267

272-
if (System::PathExistsCaseSensitive(dataPathWithoutExtensionToLoad + "000" + m_DataPathExtension)) {
273-
SetDataPath(dataPathWithoutExtensionToLoad + "000" + m_DataPathExtension);
274-
} else if (System::PathExistsCaseSensitive(dataPathWithoutExtensionToLoad + "000" + altFileExtension)) {
268+
if (System::PathExistsCaseSensitive(m_DataPathWithoutExtension + "000" + m_DataPathExtension)) {
269+
SetDataPath(m_DataPathWithoutExtension + "000" + m_DataPathExtension);
270+
} else if (System::PathExistsCaseSensitive(m_DataPathWithoutExtension + "000" + altFileExtension)) {
275271
g_ConsoleMan.AddLoadWarningLogExtensionMismatchEntry(m_DataPath, m_FormattedReaderPosition, altFileExtension);
276-
SetDataPath(dataPathWithoutExtensionToLoad + "000" + altFileExtension);
272+
SetDataPath(m_DataPathWithoutExtension + "000" + altFileExtension);
277273
}
278274
}
279275
vectorToFill.emplace_back(GetAsBitmap(conversionMode));
@@ -312,18 +308,16 @@ namespace RTE {
312308
if (m_DataPath.empty() || !g_AudioMan.IsAudioEnabled()) {
313309
return nullptr;
314310
}
315-
const std::string dataPathToLoad = g_PresetMan.GetFullModulePath(m_DataPath);
316-
317311
FMOD::Sound *returnSample = nullptr;
318312

319-
std::unordered_map<std::string, FMOD::Sound *>::iterator foundSound = s_LoadedSamples.find(dataPathToLoad);
313+
std::unordered_map<std::string, FMOD::Sound *>::iterator foundSound = s_LoadedSamples.find(m_DataPath);
320314
if (foundSound != s_LoadedSamples.end()) {
321315
returnSample = (*foundSound).second;
322316
} else {
323317
returnSample = LoadAndReleaseSound(abortGameForInvalidSound, asyncLoading); //NOTE: This takes ownership of the sample file
324318

325319
// Insert the Sound object into the map, PASSING OVER OWNERSHIP OF THE LOADED FILE
326-
s_LoadedSamples.try_emplace(dataPathToLoad, returnSample);
320+
s_LoadedSamples.try_emplace(m_DataPath, returnSample);
327321
}
328322
return returnSample;
329323
}
@@ -334,11 +328,10 @@ namespace RTE {
334328
if (m_DataPath.empty() || !g_AudioMan.IsAudioEnabled()) {
335329
return nullptr;
336330
}
337-
const std::string dataPathToLoad = g_PresetMan.GetFullModulePath(m_DataPath);
338-
if (!System::PathExistsCaseSensitive(dataPathToLoad)) {
331+
if (!System::PathExistsCaseSensitive(m_DataPath)) {
339332
bool foundAltExtension = false;
340333
for (const std::string &altFileExtension : c_SupportedAudioFormats) {
341-
const std::string altDataPathToLoad = g_PresetMan.GetFullModulePath(m_DataPathWithoutExtension + altFileExtension);
334+
const std::string altDataPathToLoad = m_DataPathWithoutExtension + altFileExtension;
342335
if (System::PathExistsCaseSensitive(altDataPathToLoad)) {
343336
g_ConsoleMan.AddLoadWarningLogExtensionMismatchEntry(m_DataPath, m_FormattedReaderPosition, altFileExtension);
344337
SetDataPath(altDataPathToLoad);
@@ -353,7 +346,7 @@ namespace RTE {
353346
return nullptr;
354347
}
355348
}
356-
if (std::filesystem::file_size(dataPathToLoad) == 0) {
349+
if (std::filesystem::file_size(m_DataPath) == 0) {
357350
const std::string errorMessage = "Failed to create sound because the file was empty. The path and name were: ";
358351
RTEAssert(!abortGameForInvalidSound, errorMessage + "\n\n" + m_DataPathAndReaderPosition);
359352
g_ConsoleMan.PrintString("ERROR: " + errorMessage + m_DataPath);
@@ -362,7 +355,7 @@ namespace RTE {
362355
FMOD::Sound *returnSample = nullptr;
363356

364357
FMOD_MODE fmodFlags = FMOD_CREATESAMPLE | FMOD_3D | (asyncLoading ? FMOD_NONBLOCKING : FMOD_DEFAULT);
365-
FMOD_RESULT result = g_AudioMan.GetAudioSystem()->createSound(dataPathToLoad.c_str(), fmodFlags, nullptr, &returnSample);
358+
FMOD_RESULT result = g_AudioMan.GetAudioSystem()->createSound(m_DataPath.c_str(), fmodFlags, nullptr, &returnSample);
366359

367360
if (result != FMOD_OK) {
368361
const std::string errorMessage = "Failed to create sound because of FMOD error:\n" + std::string(FMOD_ErrorString(result)) + "\nThe path and name were: ";

0 commit comments

Comments
 (0)