Skip to content

Commit

Permalink
Merge pull request #1876 from Lymia/file_loading_rework
Browse files Browse the repository at this point in the history
Refactor file loading to use an unified code path.
  • Loading branch information
Robosturm authored Jan 30, 2025
2 parents e727b5a + 55ef6a7 commit 4743e4d
Show file tree
Hide file tree
Showing 39 changed files with 824 additions and 1,347 deletions.
10 changes: 4 additions & 6 deletions 3rd_party/oxygine-framework/oxygine/res/ResAtlasGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "coreengine/gameconsole.h"
#include "coreengine/settings.h"
#include "coreengine/virtualpaths.h"

namespace oxygine
{
Expand Down Expand Up @@ -65,13 +66,10 @@ namespace oxygine
qint32 columns = 0;
qint32 rows = 0;
QImage img;
if (QFile::exists(Settings::getInstance()->getUserPath() + walker.getPath("file")))
QString imgFilePath = VirtualPaths::find(walker.getPath("file"));
if (QFile::exists(imgFilePath))
{
img = QImage(Settings::getInstance()->getUserPath() + walker.getPath("file"));
}
else if (QFile::exists(RCC_PREFIX_PATH + walker.getPath("file")))
{
img = QImage(RCC_PREFIX_PATH + walker.getPath("file"));
img = QImage(imgFilePath);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion 3rd_party/oxygine-framework/oxygine/res/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace oxygine
if (!file.exists() || file.size() == 0)
{
CONSOLE_PRINT_MODULE("can't load xml file: '" + xmlFile + "'", GameConsole::eDEBUG, GameConsole::eResources);
oxygine::handleErrorPolicy(oxygine::ep_show_error, "Resources::loadXML can't find xml file");
oxygine::handleErrorPolicy(oxygine::ep_show_error, "Resources::loadXML can't find xml file: " + xmlFile);
return false;
}
file.open(QIODevice::ReadOnly);
Expand Down
21 changes: 18 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ set(${PROJECT_NAME}_SRCS
coreengine/gameversion.h coreengine/gameversion.cpp
coreengine/refobject.h
coreengine/jsthis.h coreengine/jsthis.cpp
coreengine/virtualpaths.h coreengine/virtualpaths.cpp

# network engine
network/smtpmailsender.h network/smtpmailsender.cpp
Expand Down Expand Up @@ -955,7 +956,8 @@ if (NOT DEPLOY_RESOURCES_AS_FOLDER)
)
endif()
else()
message("Deploying resources")
message("Deploying resources as folder")
add_definitions(-DDEPLOY_RESOURCES_AS_FOLDER)
endif()

qt_add_resources(${PROJECT_NAME}_Resource_SRCS "core.qrc") # These files are always deployed using QRCs.
Expand Down Expand Up @@ -1045,6 +1047,7 @@ set(AppHeadersCxx
coreengine/scriptvariables.h
coreengine/settings.h
coreengine/userdata.h
coreengine/virtualpaths.h
game/building.h
game/co.h
game/gameaction.h
Expand Down Expand Up @@ -1345,7 +1348,8 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION "."
BUNDLE DESTINATION "."
LIBRARY DESTINATION ".")
LIBRARY DESTINATION "."
)

install(DIRECTORY templates DESTINATION "/")
if (DEPLOY_RESOURCES_AS_FOLDER)
Expand Down Expand Up @@ -1375,7 +1379,18 @@ elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION "bin"
BUNDLE DESTINATION "bin"
LIBRARY DESTINATION "bin")
LIBRARY DESTINATION "bin"
)

if (DEPLOY_RESOURCES_AS_FOLDER)
message("Installing resources as folder")
install(DIRECTORY resources DESTINATION "share/commander_wars")
install(DIRECTORY maps DESTINATION "share/commander_wars")
install(DIRECTORY customTerrainImages DESTINATION "share/commander_wars")
install(DIRECTORY mods DESTINATION "share/commander_wars")
install(DIRECTORY savegames DESTINATION "share/commander_wars")
install(DIRECTORY data DESTINATION "share/commander_wars")
endif()
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/android-build/build/outputs/apk/debug/android-build-debug.apk"
Expand Down
32 changes: 13 additions & 19 deletions ai/coreai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "coreengine/gameconsole.h"
#include "coreengine/globalutils.h"
#include "coreengine/virtualpaths.h"

#include "resource_management/cospritemanager.h"
#include "resource_management/weaponmanager.h"
Expand Down Expand Up @@ -163,27 +164,20 @@ TargetedUnitPathFindingSystem* CoreAI::createTargetedPfs(Unit* pUnit, const QVec

void CoreAI::loadIni(QString file)
{
AI_CONSOLE_PRINT("CoreAI::loadIni " + file, GameConsole::eDEBUG);
m_iniFiles.append(file);
QStringList searchFiles;
if (!file.isEmpty())
{
searchFiles.append(QString(oxygine::Resource::RCC_PREFIX_PATH) + "resources/aidata/" + file);
searchFiles.append(Settings::getInstance()->getUserPath() + "resources/aidata/" + file);
// make sure to overwrite existing js stuff
for (qint32 i = 0; i < Settings::getInstance()->getMods().size(); i++)
{
searchFiles.append(QString(oxygine::Resource::RCC_PREFIX_PATH) + Settings::getInstance()->getMods().at(i) + "/aidata/" + file);
searchFiles.append(Settings::getInstance()->getUserPath() + Settings::getInstance()->getMods().at(i) + "/aidata/" + file);
}
}
for (auto & file : searchFiles)
AI_CONSOLE_PRINT("CoreAI::loadIni " + file, GameConsole::eDEBUG);
m_iniFiles.append(file);
if (file.isEmpty())
{
return;
}
QStringList searchFiles = VirtualPaths::findAll("resources/aidata/" + file);
for (auto & file : searchFiles)
{
if (QFile::exists(file))
{
if (QFile::exists(file))
{
readIni(file);
}
readIni(file);
}
}
}

void CoreAI::readIni(QString name)
Expand Down
4 changes: 3 additions & 1 deletion awbwReplayReader/awbwreplaydownloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>

#include "coreengine/settings.h"

class AwbwReplayDownloader : public QObject
{
Q_OBJECT
public:
explicit AwbwReplayDownloader(const QString & downloadPath = "data/records/", QObject *parent = nullptr);
explicit AwbwReplayDownloader(const QString & downloadPath = Settings::getInstance()->getUserPath() + "data/records/", QObject *parent = nullptr);

void login(const QString & userName, const QString & password);
void downLoadReplay(const QString & userName, const QString & password, const QString replay);
Expand Down
1 change: 1 addition & 0 deletions core.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<file>system/frac_table_shader.glsl</file>
<file>system/frac_matrix_shader.glsl</file>
<file>system/vertex_shader.glsl</file>
<file>system/startup_messages.txt</file>
</qresource>
</RCC>
37 changes: 7 additions & 30 deletions coreengine/audiomanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "coreengine/gameconsole.h"
#include "coreengine/interpreter.h"
#include "coreengine/globalutils.h"
#include "coreengine/virtualpaths.h"

#include <QFile>
#include <QFileInfo>
Expand Down Expand Up @@ -133,17 +134,9 @@ void AudioManager::createSoundCache()
{
if (Mainapp::getInstance()->isAudioThread())
{
QStringList searchFolders;
searchFolders.append(Settings::getInstance()->getUserPath() + "resources/sounds/");
searchFolders.append(QString(oxygine::Resource::RCC_PREFIX_PATH) + "resources/sounds/");
QStringList mods = Settings::getInstance()->getMods();
for (const auto & mod : std::as_const(mods))
auto searchPath = VirtualPaths::createSearchPathRev("resources/sounds/");
for (auto & folder : searchPath)
{
searchFolders.append(Settings::getInstance()->getUserPath() + mod + "/sounds/");
}
for (qint32 i = searchFolders.size() - 1; i >= 0; --i)
{
QString folder = searchFolders[i];
if (QFile::exists(folder + "res.xml"))
{
readSoundCacheFromXml(folder);
Expand All @@ -165,7 +158,6 @@ void AudioManager::createSoundCache()
else
{
emit sigCreateSoundCache();

}
}
#endif
Expand Down Expand Up @@ -560,17 +552,7 @@ bool AudioManager::tryAddMusic(QString file, qint64 startPointMs, qint64 endPoin
#ifdef AUDIOSUPPORT
if (!m_noAudio)
{
QString currentPath = file;
currentPath = file;
if (!QFile::exists(currentPath))
{
currentPath = Settings::getInstance()->getUserPath() + file;
if (!QFile::exists(currentPath))
{
CONSOLE_PRINT_MODULE("Unable to locate music file: " + currentPath + " using compiled path.", GameConsole::eDEBUG, GameConsole::eAudio);
currentPath = oxygine::Resource::RCC_PREFIX_PATH + file;
}
}
QString currentPath = VirtualPaths::find(file);
if (QFile::exists(currentPath))
{
m_player->m_player.stop();
Expand Down Expand Up @@ -651,15 +633,10 @@ void AudioManager::SlotLoadFolder(QString folder)
{
#ifdef AUDIOSUPPORT
QStringList loadedSounds;
for (qint32 i = 0; i < Settings::getInstance()->getMods().size(); i++)
{
loadMusicFolder(Settings::getInstance()->getUserPath() + "/" + Settings::getInstance()->getMods().at(i) + "/" + folder, loadedSounds);
loadMusicFolder(QString(oxygine::Resource::RCC_PREFIX_PATH) + "/" + Settings::getInstance()->getMods().at(i) + "/" + folder, loadedSounds);
}
if (m_loadBaseGameFolders)
QStringList searchPath = VirtualPaths::createSearchPathRev(folder);
for (QString folder : searchPath)
{
loadMusicFolder(Settings::getInstance()->getUserPath() + folder, loadedSounds);
loadMusicFolder(oxygine::Resource::RCC_PREFIX_PATH + folder, loadedSounds);
loadMusicFolder(folder, loadedSounds);
}
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion coreengine/filesupport.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef FILESUPPORT_H
#define FILESUPPORT_H

#include <QFile>
#include <QObject>
#include <QDataStream>
#include <QCryptographicHash>
Expand Down Expand Up @@ -134,4 +135,4 @@ class Filesupport final
}
};

#endif // HASHING_H
#endif // FILESUPPORT_H
Loading

0 comments on commit 4743e4d

Please sign in to comment.