summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorkrzys-h <krzys_h@interia.pl>2014-05-18 12:12:47 +0200
committerkrzys-h <krzys_h@interia.pl>2014-05-18 12:12:47 +0200
commitf0d97bfdb91a2c0a17d1697b145d4df930280dbb (patch)
tree2d529428006e145b624108cce636b07867f566af /src/app
parentf71658e38dbcfc5635a6b2a9c6c4168582728bb5 (diff)
downloadcolobot-f0d97bfdb91a2c0a17d1697b145d4df930280dbb.tar.gz
colobot-f0d97bfdb91a2c0a17d1697b145d4df930280dbb.tar.bz2
colobot-f0d97bfdb91a2c0a17d1697b145d4df930280dbb.zip
Better datadir mod support
Diffstat (limited to 'src/app')
-rw-r--r--src/app/app.cpp114
-rw-r--r--src/app/app.h22
-rw-r--r--src/app/gamedata.cpp123
-rw-r--r--src/app/gamedata.h66
4 files changed, 210 insertions, 115 deletions
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<int>(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<int>(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 <boost/filesystem.hpp>
+
+template<> CGameData* CSingleton<CGameData>::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<std::string>::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<int>(dir);
+ assert(index >= 0 && index < DIR_MAX);
+
+ for(std::vector<std::string>::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<std::string>::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 <string>
+#include <vector>
+
+/**
+ * \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<CGameData>
+{
+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<std::string> m_dataDirs;
+ const char* m_standardDataDirs[DIR_MAX];
+};
+