From f0d97bfdb91a2c0a17d1697b145d4df930280dbb Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 18 May 2014 12:12:47 +0200 Subject: Better datadir mod support --- src/CMakeLists.txt | 3 +- src/app/app.cpp | 114 +++++--------------------------- src/app/app.h | 22 ++----- src/app/gamedata.cpp | 123 +++++++++++++++++++++++++++++++++++ src/app/gamedata.h | 66 +++++++++++++++++++ src/common/global.h | 19 ------ src/graphics/engine/engine.cpp | 34 ++-------- src/graphics/engine/modelmanager.cpp | 20 +++++- src/graphics/engine/modelmanager.h | 17 +++++ src/graphics/engine/terrain.cpp | 5 +- src/graphics/engine/text.cpp | 3 +- src/object/robotmain.cpp | 11 ++-- src/script/script.cpp | 7 +- src/sound/oalsound/alsound.cpp | 15 ++--- src/sound/sound.cpp | 7 +- src/sound/sound.h | 7 +- src/ui/edit.cpp | 3 +- src/ui/maindialog.cpp | 3 +- 18 files changed, 286 insertions(+), 193 deletions(-) create mode 100644 src/app/gamedata.cpp create mode 100644 src/app/gamedata.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8d6b14c..12171f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,11 +61,12 @@ endif() # Source files set(SOURCES app/app.cpp +app/gamedata.cpp app/main.cpp +app/pausemanager.cpp app/system.cpp app/${SYSTEM_CPP_MODULE} app/system_other.cpp -app/pausemanager.cpp common/event.cpp common/image.cpp common/iman.cpp diff --git a/src/app/app.cpp b/src/app/app.cpp index 51f1e42..549317a 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -19,6 +19,7 @@ #include "app/app.h" +#include "app/gamedata.h" #include "app/system.h" #include "common/logger.h" @@ -100,6 +101,7 @@ CApplication::CApplication() m_objMan = new CObjectManager(); m_eventQueue = new CEventQueue(); m_profile = new CProfile(); + m_gameData = new CGameData(); m_engine = nullptr; m_device = nullptr; @@ -149,7 +151,6 @@ CApplication::CApplication() m_dataPath = GetSystemUtils()->GetDataPath(); m_langPath = GetSystemUtils()->GetLangPath(); - m_texPackPath = ""; m_runSceneName = ""; m_runSceneRank = 0; @@ -161,19 +162,6 @@ CApplication::CApplication() m_lowCPU = true; m_protoMode = false; - - for (int i = 0; i < DIR_MAX; ++i) - m_standardDataDirs[i] = nullptr; - - m_standardDataDirs[DIR_AI] = "ai"; - m_standardDataDirs[DIR_FONT] = "fonts"; - m_standardDataDirs[DIR_HELP] = "help"; - m_standardDataDirs[DIR_ICON] = "icons"; - m_standardDataDirs[DIR_LEVEL] = "levels"; - m_standardDataDirs[DIR_MODEL] = "models"; - m_standardDataDirs[DIR_MUSIC] = "music"; - m_standardDataDirs[DIR_SOUND] = "sounds"; - m_standardDataDirs[DIR_TEXTURE] = "textures"; } CApplication::~CApplication() @@ -231,8 +219,8 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) OPT_LOGLEVEL, OPT_LANGUAGE, OPT_DATADIR, + OPT_MOD, OPT_LANGDIR, - OPT_TEXPACK, OPT_VBO }; @@ -245,9 +233,8 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { "loglevel", required_argument, nullptr, OPT_LOGLEVEL }, { "language", required_argument, nullptr, OPT_LANGUAGE }, { "datadir", required_argument, nullptr, OPT_DATADIR }, - { "game", required_argument, nullptr, OPT_DATADIR }, + { "mod", required_argument, nullptr, OPT_MOD }, { "langdir", required_argument, nullptr, OPT_LANGDIR }, - { "texpack", required_argument, nullptr, OPT_TEXPACK }, { "vbo", required_argument, nullptr, OPT_VBO }, { nullptr, 0, nullptr, 0} }; @@ -286,9 +273,8 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n"); GetLogger()->Message(" -language lang set language (one of: en, de, fr, pl, ru)\n"); GetLogger()->Message(" -datadir path set custom data directory path\n"); - GetLogger()->Message(" -game modid run mod\n"); + GetLogger()->Message(" -mod path run mod\n"); GetLogger()->Message(" -langdir path set custom language directory path\n"); - GetLogger()->Message(" -texpack path set path to custom texture pack\n"); GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n"); return PARSE_ARGS_HELP; } @@ -355,19 +341,19 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { m_dataPath = optarg; m_customDataPath = true; - GetLogger()->Info("Using custom datadir or running mod: '%s'\n", m_dataPath.c_str()); + GetLogger()->Info("Using datadir: '%s'\n", optarg); break; } - case OPT_LANGDIR: + case OPT_MOD: { - m_langPath = optarg; - GetLogger()->Info("Using custom language dir: '%s'\n", m_langPath.c_str()); + m_gameData->AddMod(std::string(optarg)); + GetLogger()->Info("Running mod from path: '%s'\n", optarg); break; } - case OPT_TEXPACK: + case OPT_LANGDIR: { - m_texPackPath = optarg; - GetLogger()->Info("Using texturepack: '%s'\n", m_texPackPath.c_str()); + m_langPath = optarg; + GetLogger()->Info("Using language dir: '%s'\n", m_langPath.c_str()); break; } case OPT_VBO: @@ -424,6 +410,9 @@ bool CApplication::Create() m_exitCode = 1; return false; } + + m_gameData->SetDataDir(std::string(m_dataPath)); + m_gameData->Init(); if (GetProfile().GetLocalProfileString("Language", "Lang", path)) { Language language; @@ -446,24 +435,8 @@ bool CApplication::Create() #endif m_sound->Create(); - - if (!m_customDataPath && GetProfile().GetLocalProfileString("Resources", "Sound", path)) - { - m_sound->CacheAll(path); - } - else - { - m_sound->CacheAll(GetDataSubdirPath(DIR_SOUND)); - } - - if (!m_customDataPath && GetProfile().GetLocalProfileString("Resources", "Music", path)) - { - m_sound->AddMusicFiles(path); - } - else - { - m_sound->AddMusicFiles(GetDataSubdirPath(DIR_MUSIC)); - } + m_sound->CacheAll(); + m_sound->AddMusicFiles(); GetLogger()->Info("CApplication created successfully\n"); @@ -1606,59 +1579,6 @@ bool CApplication::GetJoystickEnabled() const return m_joystickEnabled; } -std::string CApplication::GetDataDirPath() const -{ - return m_dataPath; -} - -std::string CApplication::GetDataSubdirPath(DataDir stdDir) const -{ - int index = static_cast(stdDir); - assert(index >= 0 && index < DIR_MAX); - std::stringstream str; - str << m_dataPath; - str << "/"; - str << m_standardDataDirs[index]; - return str.str(); -} - -std::string CApplication::GetDataFilePath(DataDir stdDir, const std::string& subpath) const -{ - int index = static_cast(stdDir); - assert(index >= 0 && index < DIR_MAX); - std::stringstream str; - str << m_dataPath; - str << "/"; - str << m_standardDataDirs[index]; - if (stdDir == DIR_HELP) - { - str << "/"; - str << GetLanguageChar(); - } - str << "/"; - str << subpath; - return str.str(); -} - -std::string CApplication::GetTexPackFilePath(const std::string& textureName) const -{ - std::stringstream str; - - if (! m_texPackPath.empty()) - { - str << m_texPackPath; - str << "/"; - str << textureName; - if (! boost::filesystem::exists(str.str())) - { - GetLogger()->Trace("Texture '%s' not in texpack\n", textureName.c_str()); - str.str(""); - } - } - - return str.str(); -} - Language CApplication::GetLanguage() const { return m_language; diff --git a/src/app/app.h b/src/app/app.h index 3d61081..86a757f 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -42,6 +42,7 @@ class CInstanceManager; class CEventQueue; class CRobotMain; class CSoundInterface; +class CGameData; namespace Gfx { class CModelManager; @@ -328,18 +329,6 @@ public: static bool ParseDebugModes(const std::string& str, int& debugModes); //@} - //! Returns the full path to data directory - std::string GetDataDirPath() const; - - //! Returns the full path to a standard dir in data directory - std::string GetDataSubdirPath(DataDir stdDir) const; - - //! Returns the full path to a file in data directory given standard dir and subpath - std::string GetDataFilePath(DataDir stdDir, const std::string &subpath) const; - - //! Returns the full path to a file in texture pack directory - std::string GetTexPackFilePath(const std::string& textureName) const; - //! Management of language //@{ Language GetLanguage() const; @@ -413,6 +402,8 @@ protected: CRobotMain* m_robotMain; //! Profile (INI) reader/writer CProfile* m_profile; + //! Game data + CGameData* m_gameData; //! Code to return at exit int m_exitCode; @@ -485,10 +476,7 @@ protected: //! Path to directory with language files std::string m_langPath; - - //! Path to directory with user texture pack - std::string m_texPackPath; - + //@{ //! Scene to run on startup std::string m_runSceneName; @@ -498,8 +486,6 @@ protected: //! Scene test mode bool m_sceneTest; - const char* m_standardDataDirs[DIR_MAX]; - //! Application language Language m_language; diff --git a/src/app/gamedata.cpp b/src/app/gamedata.cpp new file mode 100644 index 0000000..1bf3f36 --- /dev/null +++ b/src/app/gamedata.cpp @@ -0,0 +1,123 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2014, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +#include "app/gamedata.h" + + +#include "app/app.h" + +#include + +template<> CGameData* CSingleton::m_instance = nullptr; + +CGameData::CGameData() +{ + m_dataDirSet = false; + + for (int i = 0; i < DIR_MAX; ++i) + m_standardDataDirs[i] = nullptr; + + m_standardDataDirs[DIR_AI] = "ai"; + m_standardDataDirs[DIR_FONT] = "fonts"; + m_standardDataDirs[DIR_HELP] = "help"; + m_standardDataDirs[DIR_ICON] = "icons"; + m_standardDataDirs[DIR_LEVEL] = "levels"; + m_standardDataDirs[DIR_MODEL] = "models"; + m_standardDataDirs[DIR_MUSIC] = "music"; + m_standardDataDirs[DIR_SOUND] = "sounds"; + m_standardDataDirs[DIR_TEXTURE] = "textures"; +} + +CGameData::~CGameData() +{ +} + +void CGameData::SetDataDir(std::string path) +{ + assert(!m_dataDirSet); + m_dataDirSet = true; + + m_dataDirs.insert(m_dataDirs.begin(), path); +} + +void CGameData::AddMod(std::string path) +{ + m_dataDirs.push_back(path); +} + +void CGameData::Init() +{ + std::string out = "Using datadirs: "; + bool first = true; + for(std::vector::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) { + if(!first) out += ", "; + first = false; + out += *rit; + } + out += "\n"; + CLogger::GetInstancePointer()->Info(out.c_str()); +} + +std::string CGameData::GetFilePath(DataDir dir, const std::string& subpath) +{ + int index = static_cast(dir); + assert(index >= 0 && index < DIR_MAX); + + for(std::vector::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) { + std::stringstream str; + str << *rit; + str << "/"; + str << m_standardDataDirs[index]; + if (dir == DIR_HELP) + { + str << "/"; + str << CApplication::GetInstancePointer()->GetLanguageChar(); + } + str << "/"; + str << subpath; + boost::filesystem::path path(str.str()); + if(boost::filesystem::exists(path)) + { + return str.str(); + } + } + + std::stringstream str; + str << m_dataDirs[0]; + str << "/"; + str << m_standardDataDirs[index]; + if (dir == DIR_HELP) + { + str << "/"; + str << CApplication::GetInstancePointer()->GetLanguageChar(); + } + str << "/"; + str << subpath; + return str.str(); +} + +std::string CGameData::GetDataPath(const std::string &subpath) +{ + for(std::vector::reverse_iterator rit = m_dataDirs.rbegin(); rit != m_dataDirs.rend(); ++rit) { + std::string path = *rit + "/" + subpath; + boost::filesystem::path boostPath(path); + if(boost::filesystem::exists(boostPath)) + { + return path; + } + } + return m_dataDirs[0] + "/" + subpath; +} diff --git a/src/app/gamedata.h b/src/app/gamedata.h new file mode 100644 index 0000000..b7536a2 --- /dev/null +++ b/src/app/gamedata.h @@ -0,0 +1,66 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2014, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + +/** + * \file app/gamedata.h + * \brief Game data + */ + +#pragma once + +#include "common/singleton.h" + +#include +#include + +/** + * \enum DataDir + * \brief Directories in data directory + */ +enum DataDir +{ + DIR_AI, //! < ai scripts + DIR_FONT, //! < fonts + DIR_HELP, //! < help files + DIR_ICON, //! < icons & images + DIR_LEVEL, //! < levels + DIR_MODEL, //! < models + DIR_MUSIC, //! < music + DIR_SOUND, //! < sounds + DIR_TEXTURE, //! < textures + + DIR_MAX //! < number of dirs +}; + +class CGameData : public CSingleton +{ +public: + CGameData(); + ~CGameData(); + + void Init(); + void SetDataDir(std::string path); + void AddMod(std::string path); + + std::string GetFilePath(DataDir dir, const std::string &subpath); + std::string GetDataPath(const std::string &subpath); + +private: + bool m_dataDirSet; + std::vector m_dataDirs; + const char* m_standardDataDirs[DIR_MAX]; +}; + diff --git a/src/common/global.h b/src/common/global.h index 79206af..4049bdc 100644 --- a/src/common/global.h +++ b/src/common/global.h @@ -178,25 +178,6 @@ enum Language LANGUAGE_RUSSIAN = 4 }; -/** - * \enum DataDir - * \brief Directories in data directory - */ -enum DataDir -{ - DIR_AI, //! < ai scripts - DIR_FONT, //! < fonts - DIR_HELP, //! < help files - DIR_ICON, //! < icons & images - DIR_LEVEL, //! < levels - DIR_MODEL, //! < models - DIR_MUSIC, //! < music - DIR_SOUND, //! < sounds - DIR_TEXTURE, //! < textures - - DIR_MAX //! < number of dirs -}; - /** * \enum BuildType diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 0ee7715..d6e4415 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/engine.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/key.h" @@ -2246,33 +2247,12 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa if (image == nullptr) { - bool loadedFromTexPack = false; - - std::string texPackName = m_app->GetTexPackFilePath(texName); - if (! texPackName.empty()) + if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) { - if (img.Load(texPackName)) - { - loadedFromTexPack = true; - } - else - { - std::string error = img.GetError(); - GetLogger()->Error("Couldn't load texture '%s' from texpack: %s, blacklisting the texpack path\n", - texName.c_str(), error.c_str()); - m_texBlacklist.insert(texPackName); - } - } - - if (!loadedFromTexPack) - { - if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) - { - std::string error = img.GetError(); - GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); - m_texBlacklist.insert(texName); - return Texture(); // invalid texture - } + std::string error = img.GetError(); + GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); + m_texBlacklist.insert(texName); + return Texture(); // invalid texture } image = &img; @@ -2435,7 +2415,7 @@ bool CEngine::ChangeTextureColor(const std::string& texName, CImage img; - if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) + if (! img.Load(CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, texName))) { std::string error = img.GetError(); GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); diff --git a/src/graphics/engine/modelmanager.cpp b/src/graphics/engine/modelmanager.cpp index abc8c6c..0c0fb98 100644 --- a/src/graphics/engine/modelmanager.cpp +++ b/src/graphics/engine/modelmanager.cpp @@ -1,6 +1,24 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012-2014, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + #include "graphics/engine/modelmanager.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/logger.h" @@ -30,7 +48,7 @@ bool CModelManager::LoadModel(const std::string& fileName, bool mirrored) if (CApplication::GetInstance().IsDebugModeActive(DEBUG_MODELS)) modelFile.SetPrintDebugInfo(true); - std::string filePath = CApplication::GetInstance().GetDataFilePath(DIR_MODEL, fileName); + std::string filePath = CGameData::GetInstancePointer()->GetFilePath(DIR_MODEL, fileName); if (!modelFile.ReadModel(filePath)) { diff --git a/src/graphics/engine/modelmanager.h b/src/graphics/engine/modelmanager.h index 9d50b97..ee5fc27 100644 --- a/src/graphics/engine/modelmanager.h +++ b/src/graphics/engine/modelmanager.h @@ -1,3 +1,20 @@ +// * This file is part of the COLOBOT source code +// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch +// * Copyright (C) 2012-2014, Polish Portal of Colobot (PPC) +// * +// * This program is free software: you can redistribute it and/or modify +// * it under the terms of the GNU General Public License as published by +// * the Free Software Foundation, either version 3 of the License, or +// * (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have received a copy of the GNU General Public License +// * along with this program. If not, see http://www.gnu.org/licenses/. + #pragma once #include "common/singleton.h" diff --git a/src/graphics/engine/terrain.cpp b/src/graphics/engine/terrain.cpp index e6ca824..5f37cd8 100644 --- a/src/graphics/engine/terrain.cpp +++ b/src/graphics/engine/terrain.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/terrain.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" @@ -189,7 +190,7 @@ void CTerrain::AddMaterial(int id, const std::string& texName, const Math::Point bool CTerrain::LoadResources(const std::string& fileName) { CImage img; - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); if (! img.Load(path)) { GetLogger()->Error("Cannot load resource file: '%s'\n", path.c_str()); @@ -286,7 +287,7 @@ bool CTerrain::LoadRelief(const std::string &fileName, float scaleRelief, m_scaleRelief = scaleRelief; CImage img; - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_TEXTURE, fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_TEXTURE, fileName); if (! img.Load(path)) { GetLogger()->Error("Could not load relief file: '%s'!\n", path.c_str()); diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp index d0c9cc8..8fd01b7 100644 --- a/src/graphics/engine/text.cpp +++ b/src/graphics/engine/text.cpp @@ -19,6 +19,7 @@ #include "graphics/engine/text.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/image.h" #include "common/logger.h" @@ -865,7 +866,7 @@ CachedFont* CText::GetOrOpenFont(FontType font, float size) return m_lastCachedFont; } - std::string path = CApplication::GetInstance().GetDataFilePath(DIR_FONT, mf->fileName); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_FONT, mf->fileName); m_lastCachedFont = new CachedFont(); m_lastCachedFont->font = TTF_OpenFont(path.c_str(), pointSize); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index 256c362..2424938 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -20,6 +20,7 @@ #include "CBot/CBotDll.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/event.h" #include "common/global.h" @@ -4081,7 +4082,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "Instructions") && !resetObject) { OpString(line, "name", name); - std::string path = m_app->GetDataFilePath(DIR_HELP, name); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_HUSTON], path.c_str()); m_immediatSatCom = OpInt(line, "immediat", 0); @@ -4093,7 +4094,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "Satellite") && !resetObject) { OpString(line, "name", name); - std::string path = m_app->GetDataFilePath(DIR_HELP, name); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_SAT], path.c_str()); continue; } @@ -4101,7 +4102,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "Loading") && !resetObject) { OpString(line, "name", name); - std::string path = m_app->GetDataFilePath(DIR_HELP, name); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_LOADING], path.c_str()); continue; } @@ -4109,14 +4110,14 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) if (Cmd(line, "HelpFile") && !resetObject) { OpString(line, "name", name); - std::string path = m_app->GetDataFilePath(DIR_HELP, name); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_PROG], path.c_str()); continue; } if (Cmd(line, "SoluceFile") && !resetObject) { OpString(line, "name", name); - std::string path = m_app->GetDataFilePath(DIR_HELP, name); + std::string path = CGameData::GetInstancePointer()->GetFilePath(DIR_HELP, name); strcpy(m_infoFilename[SATCOM_SOLUCE], path.c_str()); continue; } diff --git a/src/script/script.cpp b/src/script/script.cpp index dd6b942..f97ed08 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -18,6 +18,7 @@ #include "script/script.h" #include "app/app.h" +#include "app/gamedata.h" #include "common/global.h" #include "common/iman.h" @@ -4406,7 +4407,7 @@ void CScript::New(Ui::CEdit* edit, const char* name) sf = m_main->GetScriptFile(); if ( sf[0] != 0 ) // Load an empty program specific? { - std::string filename = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, sf); + std::string filename = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, sf); file = fopen(filename.c_str(), "rb"); if ( file != NULL ) { @@ -4500,7 +4501,7 @@ bool CScript::ReadScript(const char* filename) if ( strchr(filename, '/') == 0 ) //we're reading non user script { - name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename); + name = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, filename); } else { @@ -4534,7 +4535,7 @@ bool CScript::WriteScript(const char* filename) if ( strchr(filename, '/') == 0 ) //we're writing non user script { - name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename); + name = CGameData::GetInstancePointer()->GetFilePath(DIR_AI, filename); } else { diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp index 23476d4..8afbdd2 100644 --- a/src/sound/oalsound/alsound.cpp +++ b/src/sound/oalsound/alsound.cpp @@ -18,6 +18,8 @@ #include "sound/oalsound/alsound.h" +#include "app/gamedata.h" + #include #include @@ -163,7 +165,7 @@ int ALSound::GetMusicVolume() bool ALSound::Cache(Sound sound, const std::string &filename) { Buffer *buffer = new Buffer(); - if (buffer->LoadFromFile(filename, sound)) + if (buffer->LoadFromFile(CGameData::GetInstancePointer()->GetFilePath(DIR_SOUND, filename), sound)) { m_sounds[sound] = buffer; return true; @@ -176,9 +178,7 @@ bool ALSound::CacheMusic(const std::string &filename) if (m_music.find(filename) == m_music.end()) { Buffer *buffer = new Buffer(); - std::stringstream file; - file << m_soundPath << "/" << filename; - if (buffer->LoadFromFile(file.str(), static_cast(-1))) + if (buffer->LoadFromFile(CGameData::GetInstancePointer()->GetFilePath(DIR_MUSIC, filename), static_cast(-1))) { m_music[filename] = buffer; return true; @@ -635,22 +635,21 @@ bool ALSound::PlayMusic(const std::string &filename, bool bRepeat, float fadeTim return false; } - std::stringstream file; - file << m_soundPath << "/" << filename; + std::string file = CGameData::GetInstancePointer()->GetFilePath(DIR_MUSIC, filename); Buffer *buffer; // check if we have music in cache if (m_music.find(filename) == m_music.end()) { GetLogger()->Debug("Music %s was not cached!\n", filename.c_str()); - if (!boost::filesystem::exists(file.str())) + if (!boost::filesystem::exists(file)) { GetLogger()->Debug("Requested music %s was not found.\n", filename.c_str()); return false; } buffer = new Buffer(); - if (!buffer->LoadFromFile(file.str(), static_cast(-1))) + if (!buffer->LoadFromFile(file, static_cast(-1))) { return false; } diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp index c4b30b5..9cae1fd 100644 --- a/src/sound/sound.cpp +++ b/src/sound/sound.cpp @@ -41,20 +41,19 @@ bool CSoundInterface::Create() return true; } -void CSoundInterface::CacheAll(const std::string &path) +void CSoundInterface::CacheAll() { for ( int i = 1; i < SOUND_MAX; i++ ) { std::stringstream filename; - filename << path << "/sound" << std::setfill('0') << std::setw(3) << i << ".wav"; + filename << "sound" << std::setfill('0') << std::setw(3) << i << ".wav"; if ( !Cache(static_cast(i), filename.str()) ) GetLogger()->Warn("Unable to load audio: %s\n", filename.str().c_str()); } } -void CSoundInterface::AddMusicFiles(const std::string &path) +void CSoundInterface::AddMusicFiles() { - m_soundPath = path; CacheMusic("Intro1.ogg"); CacheMusic("Intro2.ogg"); CacheMusic("music010.ogg"); diff --git a/src/sound/sound.h b/src/sound/sound.h index e86da2b..22a5ee2 100644 --- a/src/sound/sound.h +++ b/src/sound/sound.h @@ -159,10 +159,10 @@ public: /** Function called to cache all sound effect files. * Function calls \link CSoundInterface::Cache() \endlink for each file */ - void CacheAll(const std::string &path); + void CacheAll(); /** Function called to add all music files to list */ - void AddMusicFiles(const std::string &path); + void AddMusicFiles(); /** Function called to cache sound effect file. * This function is called by plugin interface for each file. @@ -327,8 +327,5 @@ public: * \return nothing */ virtual void StopPauseMusic(); - -protected: - std::string m_soundPath; }; diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index ff06161..6602651 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -19,6 +19,7 @@ #include "ui/edit.h" #include "app/app.h" +#include "app/gamedata.h" #include "clipboard/clipboard.h" @@ -1462,7 +1463,7 @@ bool CEdit::ReadText(std::string filename, int addSize) std::string path = filename; if (!fs::exists(path)) { - path = CApplication::GetInstancePointer()->GetDataDirPath() + "/" + filename; + path = CGameData::GetInstancePointer()->GetDataPath(filename); } file = fopen(fs::path(path).make_preferred().string().c_str(), "rb"); diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index b954c71..1964531 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -18,6 +18,7 @@ #include "ui/maindialog.h" #include "app/app.h" +#include "app/gamedata.h" #include "app/system.h" #include "common/config.h" @@ -3588,7 +3589,7 @@ void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank) { rankStream << std::setfill('0') << std::setw(3) << rank; filename = base + rankStream.str() + ".txt"; - filename = CApplication::GetInstance().GetDataFilePath(DIR_LEVEL, filename); + filename = CGameData::GetInstancePointer()->GetFilePath(DIR_LEVEL, filename); } } -- cgit v1.2.3-1-g7c22