summaryrefslogtreecommitdiffstats
path: root/src/app/app.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/app.cpp')
-rw-r--r--src/app/app.cpp120
1 files changed, 74 insertions, 46 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 77930ed..06e3f01 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -21,7 +21,6 @@
#include "app/app.h"
-#include "app/gamedata.h"
#include "app/system.h"
#include "common/logger.h"
@@ -29,6 +28,7 @@
#include "common/image.h"
#include "common/key.h"
#include "common/stringutils.h"
+#include "common/resources/resourcemanager.h"
#include "graphics/engine/modelmanager.h"
#include "graphics/opengl/gldevice.h"
@@ -103,7 +103,6 @@ CApplication::CApplication()
m_objMan = new CObjectManager();
m_eventQueue = new CEventQueue();
m_profile = new CProfile();
- m_gameData = new CGameData();
m_engine = nullptr;
m_device = nullptr;
@@ -114,7 +113,6 @@ CApplication::CApplication()
m_exitCode = 0;
m_active = false;
m_debugModes = 0;
- m_customDataPath = false;
m_windowTitle = "COLOBOT: Gold Edition";
@@ -157,11 +155,17 @@ CApplication::CApplication()
#else
m_dataPath = GetSystemUtils()->GetDataPath();
m_langPath = GetSystemUtils()->GetLangPath();
+ #endif
+
+ #ifdef DEV_BUILD
+ m_savePath = "./saves";
+ #else
+ m_savePath = GetSystemUtils()->GetSaveDir();
#endif
m_runSceneName = "";
m_runSceneRank = 0;
-
+
m_sceneTest = false;
m_language = LANGUAGE_ENV;
@@ -187,9 +191,6 @@ CApplication::~CApplication()
delete m_iMan;
m_iMan = nullptr;
-
- delete m_gameData;
- m_gameData = nullptr;
GetSystemUtils()->DestroyTimeStamp(m_baseTimeStamp);
GetSystemUtils()->DestroyTimeStamp(m_curTimeStamp);
@@ -222,9 +223,10 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
OPT_SCENETEST,
OPT_LOGLEVEL,
OPT_LANGUAGE,
+ OPT_LANGDIR,
OPT_DATADIR,
+ OPT_SAVEDIR,
OPT_MOD,
- OPT_LANGDIR,
OPT_VBO
};
@@ -236,9 +238,10 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
{ "scenetest", no_argument, nullptr, OPT_SCENETEST },
{ "loglevel", required_argument, nullptr, OPT_LOGLEVEL },
{ "language", required_argument, nullptr, OPT_LANGUAGE },
+ { "langdir", required_argument, nullptr, OPT_LANGDIR },
{ "datadir", required_argument, nullptr, OPT_DATADIR },
+ { "savedir", required_argument, nullptr, OPT_SAVEDIR },
{ "mod", required_argument, nullptr, OPT_MOD },
- { "langdir", required_argument, nullptr, OPT_LANGDIR },
{ "vbo", required_argument, nullptr, OPT_VBO },
{ nullptr, 0, nullptr, 0}
};
@@ -276,9 +279,10 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
GetLogger()->Message(" -scenetest win every mission right after it's loaded\n");
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(" -mod path run mod\n");
GetLogger()->Message(" -langdir path set custom language directory path\n");
+ GetLogger()->Message(" -datadir path set custom data directory path\n");
+ GetLogger()->Message(" -savedir path set custom save directory path (must be writable)\n");
+ GetLogger()->Message(" -mod path load datadir mod from given path\n");
GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n");
return PARSE_ARGS_HELP;
}
@@ -341,25 +345,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
m_language = language;
break;
}
- case OPT_DATADIR:
- {
- m_dataPath = optarg;
- m_customDataPath = true;
- GetLogger()->Info("Using datadir: '%s'\n", optarg);
- break;
- }
- case OPT_MOD:
- {
- m_gameData->AddMod(std::string(optarg));
- GetLogger()->Info("Running mod from path: '%s'\n", optarg);
- break;
- }
- case OPT_LANGDIR:
- {
- m_langPath = optarg;
- GetLogger()->Info("Using language dir: '%s'\n", m_langPath.c_str());
- break;
- }
case OPT_VBO:
{
std::string vbo;
@@ -378,6 +363,30 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
break;
}
+ case OPT_DATADIR:
+ {
+ m_dataPath = optarg;
+ GetLogger()->Info("Using data dir: '%s'\n", optarg);
+ break;
+ }
+ case OPT_LANGDIR:
+ {
+ m_langPath = optarg;
+ GetLogger()->Info("Using language dir: '%s'\n", optarg);
+ break;
+ }
+ case OPT_SAVEDIR:
+ {
+ m_savePath = optarg;
+ GetLogger()->Info("Using save dir: '%s'\n", optarg);
+ break;
+ }
+ case OPT_MOD:
+ {
+ GetLogger()->Info("Loading mod: '%s'\n", optarg);
+ CResourceManager::AddLocation(optarg, true);
+ break;
+ }
default:
assert(false); // should never get here
}
@@ -393,30 +402,32 @@ bool CApplication::Create()
GetLogger()->Info("Creating CApplication\n");
- if (!GetProfile().Init())
- {
- GetLogger()->Warn("Config not found. Default values will be used!\n");
- defaultValues = true;
- }
- else
- {
- if (!m_customDataPath && GetProfile().GetStringProperty("Resources", "Data", path))
- m_dataPath = path;
- }
-
boost::filesystem::path dataPath(m_dataPath);
if (! (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) )
{
GetLogger()->Error("Data directory '%s' doesn't exist or is not a directory\n", m_dataPath.c_str());
m_errorMessage = std::string("Could not read from data directory:\n") +
- std::string("'") + m_dataPath + std::string("'\n") +
- std::string("Please check your installation, or supply a valid data directory by -datadir option.");
+ std::string("'") + m_dataPath + std::string("'\n") +
+ std::string("Please check your installation, or supply a valid data directory by -datadir option.");
m_exitCode = 1;
return false;
}
-
- m_gameData->SetDataDir(std::string(m_dataPath));
- m_gameData->Init();
+
+ boost::filesystem::create_directories(m_savePath);
+ boost::filesystem::create_directories(m_savePath+"/mods");
+
+ LoadModsFromDir(m_dataPath+"/mods");
+ LoadModsFromDir(m_savePath+"/mods");
+
+ CResourceManager::AddLocation(m_dataPath, false);
+ CResourceManager::SetSaveLocation(m_savePath);
+ CResourceManager::AddLocation(m_savePath, true);
+
+ if (!GetProfile().Init())
+ {
+ GetLogger()->Warn("Config not found. Default values will be used!\n");
+ defaultValues = true;
+ }
if (GetProfile().GetStringProperty("Language", "Lang", path)) {
Language language;
@@ -601,6 +612,23 @@ bool CApplication::CreateVideoSurface()
return true;
}
+void CApplication::LoadModsFromDir(const std::string &dir)
+{
+ try {
+ boost::filesystem::directory_iterator iterator(dir);
+ for(; iterator != boost::filesystem::directory_iterator(); ++iterator)
+ {
+ std::string fn = iterator->path().string();
+ CLogger::GetInstancePointer()->Info("Loading mod: '%s'\n", fn.c_str());
+ CResourceManager::AddLocation(fn, false);
+ }
+ }
+ catch(std::exception &e)
+ {
+ CLogger::GetInstancePointer()->Warn("Unable to load mods from directory '%s': %s\n", dir.c_str(), e.what());
+ }
+}
+
void CApplication::Destroy()
{
m_joystickEnabled = false;