summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/app')
-rw-r--r--src/app/README.txt1
-rw-r--r--src/app/app.cpp580
-rw-r--r--src/app/app.h111
-rw-r--r--src/app/main.cpp5
-rw-r--r--src/app/system.cpp9
-rw-r--r--src/app/system.h5
-rw-r--r--src/app/system_linux.cpp31
-rw-r--r--src/app/system_linux.h5
-rw-r--r--src/app/system_other.cpp1
-rw-r--r--src/app/system_other.h1
-rw-r--r--src/app/system_windows.cpp27
-rw-r--r--src/app/system_windows.h5
12 files changed, 481 insertions, 300 deletions
diff --git a/src/app/README.txt b/src/app/README.txt
index 92be8a6..57a2785 100644
--- a/src/app/README.txt
+++ b/src/app/README.txt
@@ -2,3 +2,4 @@
* \dir src/app
* Main class of the application and system functions
*/
+
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 59a04f4..f98e0fc 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -25,13 +25,19 @@
#include "common/iman.h"
#include "common/image.h"
#include "common/key.h"
+#include "common/stringutils.h"
#include "graphics/engine/modelmanager.h"
#include "graphics/opengl/gldevice.h"
#include "object/robotmain.h"
+#ifdef OPENAL_SOUND
+ #include "sound/oalsound/alsound.h"
+#endif
+
#include <boost/filesystem.hpp>
+#include <boost/tokenizer.hpp>
#include <SDL.h>
#include <SDL_image.h>
@@ -40,11 +46,7 @@
#include <libintl.h>
#include <unistd.h>
#include <getopt.h>
-
-
-#ifdef OPENAL_SOUND
- #include "sound/oalsound/alsound.h"
-#endif
+#include <localename.h>
template<> CApplication* CSingleton<CApplication>::m_instance = nullptr;
@@ -95,6 +97,7 @@ CApplication::CApplication()
{
m_private = new ApplicationPrivate();
m_iMan = new CInstanceManager();
+ m_objMan = new CObjectManager();
m_eventQueue = new CEventQueue();
m_profile = new CProfile();
@@ -106,7 +109,7 @@ CApplication::CApplication()
m_exitCode = 0;
m_active = false;
- m_debugMode = false;
+ m_debugModes = 0;
m_windowTitle = "COLOBOT";
@@ -145,23 +148,29 @@ CApplication::CApplication()
m_dataPath = COLOBOT_DEFAULT_DATADIR;
m_langPath = COLOBOT_I18N_DIR;
+ m_texPackPath = "";
+
+ m_runSceneName = "";
+ m_runSceneRank = 0;
m_language = LANGUAGE_ENV;
m_lowCPU = true;
+ m_protoMode = false;
+
for (int i = 0; i < DIR_MAX; ++i)
- m_dataDirs[i] = nullptr;
+ m_standardDataDirs[i] = nullptr;
- m_dataDirs[DIR_AI] = "ai";
- m_dataDirs[DIR_FONT] = "fonts";
- m_dataDirs[DIR_HELP] = "help";
- m_dataDirs[DIR_ICON] = "icons";
- m_dataDirs[DIR_LEVEL] = "levels";
- m_dataDirs[DIR_MODEL] = "models";
- m_dataDirs[DIR_MUSIC] = "music";
- m_dataDirs[DIR_SOUND] = "sounds";
- m_dataDirs[DIR_TEXTURE] = "textures";
+ 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()
@@ -169,6 +178,9 @@ CApplication::~CApplication()
delete m_private;
m_private = nullptr;
+ delete m_objMan;
+ m_objMan = nullptr;
+
delete m_eventQueue;
m_eventQueue = nullptr;
@@ -211,22 +223,29 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
{
OPT_HELP = 1,
OPT_DEBUG,
- OPT_DATADIR,
+ OPT_RUNSCENE,
OPT_LOGLEVEL,
OPT_LANGUAGE,
+ OPT_DATADIR,
OPT_LANGDIR,
- OPT_VBO
+ OPT_TEXPACK,
+ OPT_VBO,
+ OPT_PROTO
};
option options[] =
{
{ "help", no_argument, nullptr, OPT_HELP },
- { "debug", no_argument, nullptr, OPT_DEBUG },
- { "datadir", required_argument, nullptr, OPT_DATADIR },
+ { "debug", required_argument, nullptr, OPT_DEBUG },
+ { "runscene", required_argument, nullptr, OPT_RUNSCENE },
{ "loglevel", required_argument, nullptr, OPT_LOGLEVEL },
{ "language", required_argument, nullptr, OPT_LANGUAGE },
+ { "datadir", required_argument, nullptr, OPT_DATADIR },
{ "langdir", required_argument, nullptr, OPT_LANGDIR },
- { "vbo", required_argument, nullptr, OPT_VBO }
+ { "texpack", required_argument, nullptr, OPT_TEXPACK },
+ { "vbo", required_argument, nullptr, OPT_VBO },
+ { "proto", no_argument, nullptr, OPT_PROTO },
+ { nullptr, 0, nullptr, 0}
};
opterr = 0;
@@ -256,24 +275,44 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
GetLogger()->Message("Colobot %s (%s)\n", COLOBOT_CODENAME, COLOBOT_VERSION);
GetLogger()->Message("\n");
GetLogger()->Message("List of available options:\n");
- GetLogger()->Message(" -help this help\n");
- GetLogger()->Message(" -debug enable debug mode (more info printed in logs)\n");
- GetLogger()->Message(" -datadir path set custom data directory path\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)\n");
- GetLogger()->Message(" -langdir path set custom language directory path\n");
- GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n");
+ GetLogger()->Message(" -help this help\n");
+ GetLogger()->Message(" -debug modes enable debug modes (more info printed in logs; see code for reference of modes)\n");
+ GetLogger()->Message(" -runscene sceneNNN run given scene on start\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)\n");
+ GetLogger()->Message(" -datadir path set custom data directory path\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");
+ GetLogger()->Message(" -proto show prototype levels\n");
return PARSE_ARGS_HELP;
}
case OPT_DEBUG:
{
- SetDebugMode(true);
+ if (optarg == nullptr)
+ {
+ m_debugModes = DEBUG_ALL;
+ GetLogger()->Info("All debug modes active\n");
+ }
+ else
+ {
+ int debugModes;
+ if (! ParseDebugModes(optarg, debugModes))
+ {
+ return PARSE_ARGS_FAIL;
+ }
+
+ m_debugModes = debugModes;
+ GetLogger()->Info("Active debug modes: %s\n", optarg);
+ }
break;
}
- case OPT_DATADIR:
+ case OPT_RUNSCENE:
{
- m_dataPath = optarg;
- GetLogger()->Info("Using custom data dir: '%s'\n", m_dataPath.c_str());
+ std::string file = optarg;
+ m_runSceneName = file.substr(0, file.size()-3);
+ m_runSceneRank = StrUtils::FromString<int>(file.substr(file.size()-3, 3));
+ GetLogger()->Info("Running scene '%s%d' on start\n", m_runSceneName.c_str(), m_runSceneRank);
break;
}
case OPT_LOGLEVEL:
@@ -281,7 +320,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
LogLevel logLevel;
if (! CLogger::ParseLogLevel(optarg, logLevel))
{
- GetLogger()->Error("Invalid log level: \"%s\"\n", optarg);
+ GetLogger()->Error("Invalid log level: '%s'\n", optarg);
return PARSE_ARGS_FAIL;
}
@@ -294,7 +333,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
Language language;
if (! ParseLanguage(optarg, language))
{
- GetLogger()->Error("Invalid language: \"%s\"\n", optarg);
+ GetLogger()->Error("Invalid language: '%s'\n", optarg);
return PARSE_ARGS_FAIL;
}
@@ -302,12 +341,24 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
m_language = language;
break;
}
+ case OPT_DATADIR:
+ {
+ m_dataPath = optarg;
+ GetLogger()->Info("Using custom data dir: '%s'\n", m_dataPath.c_str());
+ break;
+ }
case OPT_LANGDIR:
{
m_langPath = optarg;
GetLogger()->Info("Using custom language dir: '%s'\n", m_langPath.c_str());
break;
}
+ case OPT_TEXPACK:
+ {
+ m_texPackPath = optarg;
+ GetLogger()->Info("Using texturepack: '%s'\n", m_texPackPath.c_str());
+ break;
+ }
case OPT_VBO:
{
std::string vbo;
@@ -320,12 +371,17 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
m_deviceConfig.vboMode = Gfx::VBO_MODE_DISABLE;
else
{
- GetLogger()->Error("Invalid vbo mode: \"%s\"\n", optarg);
+ GetLogger()->Error("Invalid vbo mode: '%s'\n", optarg);
return PARSE_ARGS_FAIL;
}
break;
}
+ case OPT_PROTO:
+ {
+ m_protoMode = true;
+ break;
+ }
default:
assert(false); // should never get here
}
@@ -336,8 +392,22 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
bool CApplication::Create()
{
+ std::string path;
+ bool defaultValues = false;
+
GetLogger()->Info("Creating CApplication\n");
+ if (!GetProfile().InitCurrentDirectory())
+ {
+ GetLogger()->Warn("Config not found. Default values will be used!\n");
+ defaultValues = true;
+ }
+ else
+ {
+ if (GetProfile().GetLocalProfileString("Resources", "Data", path))
+ m_dataPath = path;
+ }
+
boost::filesystem::path dataPath(m_dataPath);
if (! (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) )
{
@@ -349,41 +419,47 @@ bool CApplication::Create()
return false;
}
+ GetProfile().SetLocalProfileString("Resources", "Data", m_dataPath);
+
SetLanguage(m_language);
//Create the sound instance.
- if (!GetProfile().InitCurrentDirectory())
+ #ifdef OPENAL_SOUND
+ m_sound = static_cast<CSoundInterface *>(new ALSound());
+ #else
+ GetLogger()->Info("No sound support.\n");
+ m_sound = new CSoundInterface();
+ #endif
+
+ m_sound->Create(true);
+
+ // Cache sound files
+ if (defaultValues)
{
- GetLogger()->Warn("Config not found. Default values will be used!\n");
- m_sound = new CSoundInterface();
+ GetProfile().SetLocalProfileString("Resources", "Sound", GetDataSubdirPath(DIR_SOUND));
+ GetProfile().SetLocalProfileString("Resources", "Music", GetDataSubdirPath(DIR_MUSIC));
+ }
+
+ if (GetProfile().GetLocalProfileString("Resources", "Sound", path))
+ {
+ m_sound->CacheAll(path);
}
else
{
- std::string path;
- if (GetProfile().GetLocalProfileString("Resources", "Data", path))
- m_dataPath = path;
-
- #ifdef OPENAL_SOUND
- m_sound = static_cast<CSoundInterface *>(new ALSound());
- #else
- GetLogger()->Info("No sound support.\n");
- m_sound = new CSoundInterface();
- #endif
-
- m_sound->Create(true);
- if (GetProfile().GetLocalProfileString("Resources", "Sound", path)) {
- m_sound->CacheAll(path);
- } else {
- m_sound->CacheAll(GetDataSubdirPath(DIR_SOUND));
- }
+ m_sound->CacheAll(GetDataSubdirPath(DIR_SOUND));
+ }
- if (GetProfile().GetLocalProfileString("Resources", "Music", path)) {
- m_sound->AddMusicFiles(path);
- } else {
- m_sound->AddMusicFiles(GetDataSubdirPath(DIR_MUSIC));
- }
+ if (GetProfile().GetLocalProfileString("Resources", "Music", path))
+ {
+ m_sound->AddMusicFiles(path);
+ }
+ else
+ {
+ m_sound->AddMusicFiles(GetDataSubdirPath(DIR_MUSIC));
}
+ GetLogger()->Info("CApplication created successfully\n");
+
std::string standardInfoMessage =
"\nPlease see the console output or log file\n"
"to get more information on the source of error";
@@ -448,6 +524,7 @@ bool CApplication::Create()
// Enable translating key codes of key press events to unicode chars
SDL_EnableUNICODE(1);
+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
// Don't generate joystick events
SDL_JoystickEventState(SDL_IGNORE);
@@ -477,11 +554,14 @@ bool CApplication::Create()
m_modelManager = new Gfx::CModelManager(m_engine);
// Create the robot application.
- m_robotMain = new CRobotMain(this);
+ m_robotMain = new CRobotMain(this, !defaultValues);
- m_robotMain->ChangePhase(PHASE_WELCOME1);
+ if (defaultValues) m_robotMain->CreateIni();
- GetLogger()->Info("CApplication created successfully\n");
+ if (! m_runSceneName.empty())
+ m_robotMain->LoadSceneOnStart(m_runSceneName, m_runSceneRank);
+ else
+ m_robotMain->ChangePhase(PHASE_WELCOME1);
return true;
}
@@ -605,7 +685,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig)
if (! CreateVideoSurface())
{
// Fatal error, so post the quit event
- m_eventQueue->AddEvent(Event(EVENT_QUIT));
+ m_eventQueue->AddEvent(Event(EVENT_SYS_QUIT));
return false;
}
@@ -634,7 +714,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig)
// Fatal error, so post the quit event
- m_eventQueue->AddEvent(Event(EVENT_QUIT));
+ m_eventQueue->AddEvent(Event(EVENT_SYS_QUIT));
return false;
}
}
@@ -818,31 +898,15 @@ int CApplication::Run()
Event event = ProcessSystemEvent();
- if (event.type == EVENT_QUIT)
+ if (event.type == EVENT_SYS_QUIT)
goto end; // exit the loop
if (event.type != EVENT_NULL)
- {
- bool passOn = ProcessEvent(event);
-
- if (m_engine != nullptr && passOn)
- passOn = m_engine->ProcessEvent(event);
-
- if (passOn)
- m_eventQueue->AddEvent(event);
- }
+ m_eventQueue->AddEvent(event);
Event virtualEvent = CreateVirtualEvent(event);
if (virtualEvent.type != EVENT_NULL)
- {
- bool passOn = ProcessEvent(virtualEvent);
-
- if (m_engine != nullptr && passOn)
- passOn = m_engine->ProcessEvent(virtualEvent);
-
- if (passOn)
- m_eventQueue->AddEvent(virtualEvent);
- }
+ m_eventQueue->AddEvent(virtualEvent);
}
}
@@ -853,19 +917,11 @@ int CApplication::Run()
Event event = ProcessSystemEvent();
- if (event.type == EVENT_QUIT)
+ if (event.type == EVENT_SYS_QUIT)
goto end; // exit the loop
if (event.type != EVENT_NULL)
- {
- bool passOn = ProcessEvent(event);
-
- if (m_engine != nullptr && passOn)
- passOn = m_engine->ProcessEvent(event);
-
- if (passOn)
- m_eventQueue->AddEvent(event);
- }
+ m_eventQueue->AddEvent(event);
}
// Enter game update & frame rendering only if active
@@ -874,22 +930,17 @@ int CApplication::Run()
Event event;
while (m_eventQueue->GetEvent(event))
{
- if (event.type == EVENT_QUIT)
+ if (event.type == EVENT_SYS_QUIT || event.type == EVENT_QUIT)
goto end; // exit both loops
- bool passOn = true;
-
- // Skip system events (they have been processed earlier)
- if (! event.systemEvent)
- {
- passOn = ProcessEvent(event);
+ LogEvent(event);
- if (passOn && m_engine != nullptr)
- passOn = m_engine->ProcessEvent(event);
- }
+ bool passOn = true;
+ if (m_engine != nullptr)
+ passOn = m_engine->ProcessEvent(event);
if (passOn && m_robotMain != nullptr)
- m_robotMain->EventProcess(event);
+ m_robotMain->ProcessEvent(event);
}
StopPerformanceCounter(PCNT_EVENT_PROCESSING);
@@ -900,6 +951,8 @@ int CApplication::Run()
event = CreateUpdateEvent();
if (event.type != EVENT_NULL && m_robotMain != nullptr)
{
+ LogEvent(event);
+
StartPerformanceCounter(PCNT_UPDATE_ENGINE);
m_engine->FrameUpdate();
StopPerformanceCounter(PCNT_UPDATE_ENGINE);
@@ -907,7 +960,7 @@ int CApplication::Run()
m_sound->FrameMove(m_relTime);
StartPerformanceCounter(PCNT_UPDATE_GAME);
- m_robotMain->EventProcess(event);
+ m_robotMain->ProcessEvent(event);
StopPerformanceCounter(PCNT_UPDATE_GAME);
}
@@ -938,12 +991,12 @@ end:
return m_exitCode;
}
-int CApplication::GetExitCode()
+int CApplication::GetExitCode() const
{
return m_exitCode;
}
-const std::string& CApplication::GetErrorMessage()
+const std::string& CApplication::GetErrorMessage() const
{
return m_errorMessage;
}
@@ -953,11 +1006,10 @@ const std::string& CApplication::GetErrorMessage()
Event CApplication::ProcessSystemEvent()
{
Event event;
- event.systemEvent = true;
if (m_private->currentEvent.type == SDL_QUIT)
{
- event.type = EVENT_QUIT;
+ event.type = EVENT_SYS_QUIT;
}
else if (m_private->currentEvent.type == SDL_VIDEORESIZE)
{
@@ -1103,76 +1155,74 @@ Event CApplication::ProcessSystemEvent()
return event;
}
-/**
- * Processes incoming events. It is the first function called after an event is captured.
- * Event is modified, updating its tracked keys state and mouse position to current values.
- * Function returns \c true if the event is to be passed on to other processing functions
- * or \c false if not. */
-bool CApplication::ProcessEvent(const Event &event)
+void CApplication::LogEvent(const Event &event)
{
CLogger *l = GetLogger();
- // Print the events in debug mode to test the code
- if (m_debugMode)
+ auto PrintEventDetails = [&]()
{
- switch (event.type)
- {
- case EVENT_KEY_DOWN:
- case EVENT_KEY_UP:
- l->Trace("EVENT_KEY_%s:\n", (event.type == EVENT_KEY_DOWN) ? "DOWN" : "UP");
- l->Trace(" virt = %s\n", (event.key.virt) ? "true" : "false");
- l->Trace(" key = %d\n", event.key.key);
- l->Trace(" unicode = 0x%04x\n", event.key.unicode);
- break;
- case EVENT_MOUSE_MOVE:
- l->Trace("EVENT_MOUSE_MOVE:\n");
- break;
- case EVENT_MOUSE_BUTTON_DOWN:
- case EVENT_MOUSE_BUTTON_UP:
- l->Trace("EVENT_MOUSE_BUTTON_%s:\n", (event.type == EVENT_MOUSE_BUTTON_DOWN) ? "DOWN" : "UP");
- l->Trace(" button = %d\n", event.mouseButton.button);
- break;
- case EVENT_MOUSE_WHEEL:
- l->Trace("EVENT_MOUSE_WHEEL:\n");
- l->Trace(" dir = %s\n", (event.mouseWheel.dir == WHEEL_DOWN) ? "WHEEL_DOWN" : "WHEEL_UP");
- break;
- case EVENT_JOY_AXIS:
- l->Trace("EVENT_JOY_AXIS:\n");
- l->Trace(" axis = %d\n", event.joyAxis.axis);
- l->Trace(" value = %d\n", event.joyAxis.value);
- break;
- case EVENT_JOY_BUTTON_DOWN:
- case EVENT_JOY_BUTTON_UP:
- l->Trace("EVENT_JOY_BUTTON_%s:\n", (event.type == EVENT_JOY_BUTTON_DOWN) ? "DOWN" : "UP");
- l->Trace(" button = %d\n", event.joyButton.button);
- break;
- case EVENT_ACTIVE:
- l->Trace("EVENT_ACTIVE:\n");
- l->Trace(" flags = 0x%x\n", event.active.flags);
- l->Trace(" gain = %s\n", event.active.gain ? "true" : "false");
- break;
- default:
- l->Trace("Event type = %d:\n", static_cast<int>(event.type));
- break;
- }
-
- l->Trace(" systemEvent = %s\n", event.systemEvent ? "true" : "false");
l->Trace(" rTime = %f\n", event.rTime);
l->Trace(" kmodState = %04x\n", event.kmodState);
l->Trace(" trackedKeysState = %04x\n", event.trackedKeysState);
l->Trace(" mousePos = %f, %f\n", event.mousePos.x, event.mousePos.y);
l->Trace(" mouseButtonsState = %02x\n", event.mouseButtonsState);
- }
+ l->Trace(" customParam = %d\n", event.customParam);
+ };
- // By default, pass on all events
- return true;
+ // Print the events in debug mode to test the code
+ if (IsDebugModeActive(DEBUG_SYS_EVENTS) || IsDebugModeActive(DEBUG_APP_EVENTS))
+ {
+ std::string eventType = ParseEventType(event.type);
+
+ if (IsDebugModeActive(DEBUG_SYS_EVENTS) && event.type <= EVENT_SYS_MAX)
+ {
+ l->Trace("System event %s:\n", eventType.c_str());
+ switch (event.type)
+ {
+ case EVENT_KEY_DOWN:
+ case EVENT_KEY_UP:
+ l->Trace(" virt = %s\n", (event.key.virt) ? "true" : "false");
+ l->Trace(" key = %d\n", event.key.key);
+ l->Trace(" unicode = 0x%04x\n", event.key.unicode);
+ break;
+ case EVENT_MOUSE_BUTTON_DOWN:
+ case EVENT_MOUSE_BUTTON_UP:
+ l->Trace(" button = %d\n", event.mouseButton.button);
+ break;
+ case EVENT_MOUSE_WHEEL:
+ l->Trace(" dir = %s\n", (event.mouseWheel.dir == WHEEL_DOWN) ? "WHEEL_DOWN" : "WHEEL_UP");
+ break;
+ case EVENT_JOY_AXIS:
+ l->Trace(" axis = %d\n", event.joyAxis.axis);
+ l->Trace(" value = %d\n", event.joyAxis.value);
+ break;
+ case EVENT_JOY_BUTTON_DOWN:
+ case EVENT_JOY_BUTTON_UP:
+ l->Trace(" button = %d\n", event.joyButton.button);
+ break;
+ case EVENT_ACTIVE:
+ l->Trace(" flags = 0x%x\n", event.active.flags);
+ l->Trace(" gain = %s\n", event.active.gain ? "true" : "false");
+ break;
+ default:
+ break;
+ }
+
+ PrintEventDetails();
+ }
+
+ if (IsDebugModeActive(DEBUG_APP_EVENTS) && event.type > EVENT_SYS_MAX)
+ {
+ l->Trace("App event %s:\n", eventType.c_str());
+ PrintEventDetails();
+ }
+ }
}
Event CApplication::CreateVirtualEvent(const Event& sourceEvent)
{
Event virtualEvent;
- virtualEvent.systemEvent = true;
if ((sourceEvent.type == EVENT_KEY_DOWN) || (sourceEvent.type == EVENT_KEY_UP))
{
@@ -1228,16 +1278,27 @@ void CApplication::SuspendSimulation()
void CApplication::ResumeSimulation()
{
m_simulationSuspended = false;
+ InternalResumeSimulation();
+ GetLogger()->Info("Resume simulation\n");
+}
+
+void CApplication::ResetTimeAfterLoading()
+{
+ InternalResumeSimulation();
+
+ GetLogger()->Trace("Resume simulation on loading\n");
+}
+
+void CApplication::InternalResumeSimulation()
+{
GetSystemUtils()->GetCurrentTimeStamp(m_baseTimeStamp);
GetSystemUtils()->CopyTimeStamp(m_curTimeStamp, m_baseTimeStamp);
m_realAbsTimeBase = m_realAbsTime;
m_absTimeBase = m_exactAbsTime;
-
- GetLogger()->Info("Resume simulation\n");
}
-bool CApplication::GetSimulationSuspended()
+bool CApplication::GetSimulationSuspended() const
{
return m_simulationSuspended;
}
@@ -1269,7 +1330,7 @@ Event CApplication::CreateUpdateEvent()
{
GetLogger()->Error("Fatal error: got negative system counter difference!\n");
GetLogger()->Error("This should never happen. Please report this error.\n");
- m_eventQueue->AddEvent(Event(EVENT_QUIT));
+ m_eventQueue->AddEvent(Event(EVENT_SYS_QUIT));
return Event(EVENT_NULL);
}
else
@@ -1285,7 +1346,6 @@ Event CApplication::CreateUpdateEvent()
}
Event frameEvent(EVENT_FRAME);
- frameEvent.systemEvent = true;
frameEvent.trackedKeysState = m_trackedKeys;
frameEvent.kmodState = m_kmodState;
frameEvent.mousePos = m_mousePos;
@@ -1295,48 +1355,48 @@ Event CApplication::CreateUpdateEvent()
return frameEvent;
}
-float CApplication::GetSimulationSpeed()
+float CApplication::GetSimulationSpeed() const
{
return m_simulationSpeed;
}
-float CApplication::GetAbsTime()
+float CApplication::GetAbsTime() const
{
return m_absTime;
}
-long long CApplication::GetExactAbsTime()
+long long CApplication::GetExactAbsTime() const
{
return m_exactAbsTime;
}
-long long CApplication::GetRealAbsTime()
+long long CApplication::GetRealAbsTime() const
{
return m_realAbsTime;
}
-float CApplication::GetRelTime()
+float CApplication::GetRelTime() const
{
return m_relTime;
}
-long long CApplication::GetExactRelTime()
+long long CApplication::GetExactRelTime() const
{
return m_exactRelTime;
}
-long long CApplication::GetRealRelTime()
+long long CApplication::GetRealRelTime() const
{
return m_realRelTime;
}
-Gfx::GLDeviceConfig CApplication::GetVideoConfig()
+Gfx::GLDeviceConfig CApplication::GetVideoConfig() const
{
return m_deviceConfig;
}
VideoQueryResult CApplication::GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions,
- bool fullScreen, bool resizeable)
+ bool fullScreen, bool resizeable) const
{
resolutions.clear();
@@ -1378,39 +1438,80 @@ VideoQueryResult CApplication::GetVideoResolutionList(std::vector<Math::IntPoint
return VIDEO_QUERY_OK;
}
-void CApplication::SetDebugMode(bool mode)
+void CApplication::SetDebugModeActive(DebugMode mode, bool active)
+{
+ if (active)
+ m_debugModes |= mode;
+ else
+ m_debugModes &= (~mode);
+}
+
+bool CApplication::IsDebugModeActive(DebugMode mode) const
{
- m_debugMode = mode;
+ return (m_debugModes & mode) != 0;
}
-bool CApplication::GetDebugMode()
+bool CApplication::ParseDebugModes(const std::string& str, int& debugModes)
{
- return m_debugMode;
+ debugModes = 0;
+
+ boost::char_separator<char> sep(",");
+ boost::tokenizer<boost::char_separator<char>> tokens(str, sep);
+ for (const auto& modeToken : tokens)
+ {
+ if (modeToken == "sys_events")
+ {
+ debugModes |= DEBUG_SYS_EVENTS;
+ }
+ else if (modeToken == "app_events")
+ {
+ debugModes |= DEBUG_APP_EVENTS;
+ }
+ else if (modeToken == "events")
+ {
+ debugModes |= DEBUG_EVENTS;
+ }
+ else if (modeToken == "models")
+ {
+ debugModes |= DEBUG_MODELS;
+ }
+ else if (modeToken == "all")
+ {
+ debugModes = DEBUG_ALL;
+ }
+ else
+ {
+ GetLogger()->Error("Invalid debug mode: '%s'\n", modeToken.c_str());
+ return false;
+ }
+ }
+
+ return true;
}
-int CApplication::GetKmods()
+int CApplication::GetKmods() const
{
return m_kmodState;
}
-bool CApplication::GetKmodState(int kmod)
+bool CApplication::GetKmodState(int kmod) const
{
return (m_kmodState & kmod) != 0;
}
-bool CApplication::GetTrackedKeyState(TrackedKey key)
+bool CApplication::GetTrackedKeyState(TrackedKey key) const
{
return (m_trackedKeys & key) != 0;
}
-bool CApplication::GetMouseButtonState(int index)
+bool CApplication::GetMouseButtonState(int index) const
{
return (m_mouseButtonsState & (1<<index)) != 0;
}
void CApplication::ResetKeyStates()
{
- GetLogger()->Info("Reset key states\n");
+ GetLogger()->Trace("Reset key states\n");
m_trackedKeys = 0;
m_kmodState = 0;
m_robotMain->ResetKeyStates();
@@ -1421,7 +1522,7 @@ void CApplication::SetGrabInput(bool grab)
SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF);
}
-bool CApplication::GetGrabInput()
+bool CApplication::GetGrabInput() const
{
int result = SDL_WM_GrabInput(SDL_GRAB_QUERY);
return result == SDL_GRAB_ON;
@@ -1436,12 +1537,12 @@ void CApplication::SetMouseMode(MouseMode mode)
SDL_ShowCursor(SDL_DISABLE);
}
-MouseMode CApplication::GetMouseMode()
+MouseMode CApplication::GetMouseMode() const
{
return m_mouseMode;
}
-Math::Point CApplication::GetMousePos()
+Math::Point CApplication::GetMousePos() const
{
return m_mousePos;
}
@@ -1454,7 +1555,7 @@ void CApplication::MoveMouse(Math::Point pos)
SDL_WarpMouse(windowPos.x, windowPos.y);
}
-std::vector<JoystickDevice> CApplication::GetJoystickList()
+std::vector<JoystickDevice> CApplication::GetJoystickList() const
{
std::vector<JoystickDevice> result;
@@ -1471,7 +1572,7 @@ std::vector<JoystickDevice> CApplication::GetJoystickList()
return result;
}
-JoystickDevice CApplication::GetJoystick()
+JoystickDevice CApplication::GetJoystick() const
{
return m_joystick;
}
@@ -1493,36 +1594,37 @@ void CApplication::SetJoystickEnabled(bool enable)
}
}
-bool CApplication::GetJoystickEnabled()
+bool CApplication::GetJoystickEnabled() const
{
return m_joystickEnabled;
}
-std::string CApplication::GetDataDirPath()
+std::string CApplication::GetDataDirPath() const
{
return m_dataPath;
}
-std::string CApplication::GetDataSubdirPath(DataDir stdDir)
+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_dataDirs[index];
+ str << m_standardDataDirs[index];
return str.str();
}
-std::string CApplication::GetDataFilePath(DataDir stdDir, const std::string& subpath)
+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_dataDirs[index];
- if (stdDir == DIR_HELP) {
+ str << m_standardDataDirs[index];
+ if (stdDir == DIR_HELP)
+ {
str << "/";
str << GetLanguageChar();
}
@@ -1531,12 +1633,31 @@ std::string CApplication::GetDataFilePath(DataDir stdDir, const std::string& sub
return str.str();
}
-Language CApplication::GetLanguage()
+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;
}
-char CApplication::GetLanguageChar()
+char CApplication::GetLanguageChar() const
{
char langChar = 'E';
switch (m_language)
@@ -1621,33 +1742,38 @@ void CApplication::SetLanguage(Language language)
if (locale.empty())
{
- char *envLang = getenv("LANGUAGE");
- if (envLang == NULL)
- {
- envLang = getenv("LANG");
- }
+ const char* envLang = gl_locale_name(LC_MESSAGES, "LC_MESSAGES");
if (envLang == NULL)
{
- GetLogger()->Error("Failed to get language from environment, setting default language");
+ GetLogger()->Error("Failed to get language from environment, setting default language\n");
m_language = LANGUAGE_ENGLISH;
}
- else if (strncmp(envLang,"en",2) == 0)
- {
- m_language = LANGUAGE_ENGLISH;
- }
- else if (strncmp(envLang,"de",2) == 0)
- {
- m_language = LANGUAGE_GERMAN;
- }
- else if (strncmp(envLang,"fr",2) == 0)
- {
- m_language = LANGUAGE_FRENCH;
- }
- else if (strncmp(envLang,"pl",2) == 0)
+ else
{
- m_language = LANGUAGE_POLISH;
+ GetLogger()->Trace("gl_locale_name: '%s'\n", envLang);
+
+ if (strncmp(envLang,"en",2) == 0)
+ {
+ m_language = LANGUAGE_ENGLISH;
+ }
+ else if (strncmp(envLang,"de",2) == 0)
+ {
+ m_language = LANGUAGE_GERMAN;
+ }
+ else if (strncmp(envLang,"fr",2) == 0)
+ {
+ m_language = LANGUAGE_FRENCH;
+ }
+ else if (strncmp(envLang,"pl",2) == 0)
+ {
+ m_language = LANGUAGE_POLISH;
+ }
+ else
+ {
+ GetLogger()->Warn("Enviromnent locale ('%s') is not supported, setting default language\n", envLang);
+ m_language = LANGUAGE_ENGLISH;
+ }
}
- GetLogger()->Trace("SetLanguage: Inherit LANGUAGE=%s from environment\n", envLang);
}
else
{
@@ -1657,6 +1783,7 @@ void CApplication::SetLanguage(Language language)
putenv(S_LANGUAGE);
GetLogger()->Trace("SetLanguage: Set LANGUAGE=%s in environment\n", locale.c_str());
}
+
setlocale(LC_ALL, "");
bindtextdomain("colobot", m_langPath.c_str());
@@ -1671,7 +1798,7 @@ void CApplication::SetLowCPU(bool low)
m_lowCPU = low;
}
-bool CApplication::GetLowCPU()
+bool CApplication::GetLowCPU() const
{
return m_lowCPU;
}
@@ -1686,7 +1813,7 @@ void CApplication::StopPerformanceCounter(PerformanceCounter counter)
GetSystemUtils()->GetCurrentTimeStamp(m_performanceCounters[counter][1]);
}
-float CApplication::GetPerformanceCounterData(PerformanceCounter counter)
+float CApplication::GetPerformanceCounterData(PerformanceCounter counter) const
{
return m_performanceCountersData[counter];
}
@@ -1715,3 +1842,8 @@ void CApplication::UpdatePerformanceCountersData()
}
}
+bool CApplication::GetProtoMode() const
+{
+ return m_protoMode;
+}
+
diff --git a/src/app/app.h b/src/app/app.h
index dcc90e0..269fa9b 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -31,6 +31,8 @@
#include "graphics/engine/engine.h"
#include "graphics/opengl/gldevice.h"
+#include "object/objman.h"
+
#include <string>
#include <vector>
@@ -141,6 +143,15 @@ enum PerformanceCounter
PCNT_MAX
};
+enum DebugMode
+{
+ DEBUG_SYS_EVENTS = 1 << 0,
+ DEBUG_APP_EVENTS = 1 << 1,
+ DEBUG_EVENTS = DEBUG_SYS_EVENTS | DEBUG_APP_EVENTS,
+ DEBUG_MODELS = 1 << 2,
+ DEBUG_ALL = DEBUG_SYS_EVENTS | DEBUG_APP_EVENTS | DEBUG_MODELS
+};
+
struct ApplicationPrivate;
/**
@@ -207,20 +218,20 @@ public:
//! Main event loop
int Run();
//! Returns the code to be returned at main() exit
- int GetExitCode();
+ int GetExitCode() const;
//! Returns the message of error (set to something if exit code is not 0)
- const std::string& GetErrorMessage();
+ const std::string& GetErrorMessage() const;
//! Cleans up before exit
void Destroy();
//! Returns a list of possible video modes
VideoQueryResult GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions,
- bool fullScreen, bool resizeable);
+ bool fullScreen, bool resizeable) const;
//! Returns the current video mode
- Gfx::GLDeviceConfig GetVideoConfig();
+ Gfx::GLDeviceConfig GetVideoConfig() const;
//! Change the video mode to given mode
bool ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig);
@@ -230,35 +241,38 @@ public:
//! Resumes animation
void ResumeSimulation();
//! Returns whether simulation is suspended
- bool GetSimulationSuspended();
+ bool GetSimulationSuspended() const;
+
+ //! Resets time counters to account for time spent loading game
+ void ResetTimeAfterLoading();
//@{
//! Management of simulation speed
void SetSimulationSpeed(float speed);
- float GetSimulationSpeed();
+ float GetSimulationSpeed() const;
//@}
//! Returns the absolute time counter [seconds]
- float GetAbsTime();
+ float GetAbsTime() const;
//! Returns the exact absolute time counter [nanoseconds]
- long long GetExactAbsTime();
+ long long GetExactAbsTime() const;
//! Returns the exact absolute time counter disregarding speed setting [nanoseconds]
- long long GetRealAbsTime();
+ long long GetRealAbsTime() const;
//! Returns the relative time since last update [seconds]
- float GetRelTime();
+ float GetRelTime() const;
//! Returns the exact realative time since last update [nanoseconds]
- long long GetExactRelTime();
+ long long GetExactRelTime() const;
//! Returns the exact relative time since last update disregarding speed setting [nanoseconds]
- long long GetRealRelTime();
+ long long GetRealRelTime() const;
//! Returns a list of available joystick devices
- std::vector<JoystickDevice> GetJoystickList();
+ std::vector<JoystickDevice> GetJoystickList() const;
//! Returns info about the current joystick
- JoystickDevice GetJoystick();
+ JoystickDevice GetJoystick() const;
//! Change the current joystick device
bool ChangeJoystick(const JoystickDevice &newJoystick);
@@ -266,7 +280,7 @@ public:
//! Management of joystick enable state
//@{
void SetJoystickEnabled(bool enable);
- bool GetJoystickEnabled();
+ bool GetJoystickEnabled() const;
//@}
//! Polls the state of joystick axes and buttons
@@ -276,15 +290,15 @@ public:
void UpdateMouse();
//! Returns the current key modifiers
- int GetKmods();
+ int GetKmods() const;
//! Returns whether the given kmod is active
- bool GetKmodState(int kmod);
+ bool GetKmodState(int kmod) const;
//! Returns whether the tracked key is pressed
- bool GetTrackedKeyState(TrackedKey key);
+ bool GetTrackedKeyState(TrackedKey key) const;
//! Returns whether the mouse button is pressed
- bool GetMouseButtonState(int index);
+ bool GetMouseButtonState(int index) const;
//! Resets tracked key states and modifiers
void ResetKeyStates();
@@ -292,40 +306,44 @@ public:
//! Management of the grab mode for input (keyboard & mouse)
//@{
void SetGrabInput(bool grab);
- bool GetGrabInput();
+ bool GetGrabInput() const;
//@}
//! Management of mouse mode
//@{
void SetMouseMode(MouseMode mode);
- MouseMode GetMouseMode();
+ MouseMode GetMouseMode() const;
//@}
//! Returns the position of mouse cursor (in interface coords)
- Math::Point GetMousePos();
+ Math::Point GetMousePos() const;
//! Moves (warps) the mouse cursor to the specified position (in interface coords)
void MoveMouse(Math::Point pos);
- //! Management of debug mode (prints more info in logger)
+ //! Management of debug modes (printing more info in logger)
//@{
- void SetDebugMode(bool mode);
- bool GetDebugMode();
+ void SetDebugModeActive(DebugMode mode, bool active);
+ bool IsDebugModeActive(DebugMode mode) const;
+ static bool ParseDebugModes(const std::string& str, int& debugModes);
//@}
//! Returns the full path to data directory
- std::string GetDataDirPath();
+ std::string GetDataDirPath() const;
//! Returns the full path to a standard dir in data directory
- std::string GetDataSubdirPath(DataDir stdDir);
+ 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);
+ 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();
- char GetLanguageChar();
+ Language GetLanguage() const;
+ char GetLanguageChar() const;
void SetLanguage(Language language);
static bool ParseLanguage(const std::string& str, Language& language);
//@}
@@ -333,16 +351,18 @@ public:
//! Management of sleep in main loop (lowers CPU usage)
//@{
void SetLowCPU(bool low);
- bool GetLowCPU();
+ bool GetLowCPU() const;
//@}
//! Management of performance counters
//@{
void StartPerformanceCounter(PerformanceCounter counter);
void StopPerformanceCounter(PerformanceCounter counter);
- float GetPerformanceCounterData(PerformanceCounter counter);
+ float GetPerformanceCounterData(PerformanceCounter counter) const;
//@}
+ bool GetProtoMode() const;
+
protected:
//! Creates the window's SDL_Surface
bool CreateVideoSurface();
@@ -353,8 +373,8 @@ protected:
Event CreateVirtualEvent(const Event& sourceEvent);
//! Prepares a simulation update event
TEST_VIRTUAL Event CreateUpdateEvent();
- //! Handles some incoming events
- bool ProcessEvent(const Event& event);
+ //! Logs debug data for event
+ void LogEvent(const Event& event);
//! Renders the image in window
void Render();
@@ -363,6 +383,9 @@ protected:
//! Closes the joystick device
void CloseJoystick();
+ //! Internal procedure to reset time counters
+ void InternalResumeSimulation();
+
//! Resets all performance counters to zero
void ResetPerformanceCounters();
//! Updates performance counters from gathered timer data
@@ -374,6 +397,8 @@ protected:
//! Instance manager
// TODO: to be removed
CInstanceManager* m_iMan;
+ //! Object manager
+ CObjectManager* m_objMan;
//! Global event queue
CEventQueue* m_eventQueue;
//! Graphics engine
@@ -393,8 +418,8 @@ protected:
int m_exitCode;
//! Whether application window is active
bool m_active;
- //! Whether debug mode is enabled
- bool m_debugMode;
+ //! Bit array of active debug modes
+ long m_debugModes;
//! Message to be displayed as error to the user
std::string m_errorMessage;
@@ -458,12 +483,24 @@ protected:
//! Path to directory with language files
std::string m_langPath;
- const char* m_dataDirs[DIR_MAX];
+ //! Path to directory with user texture pack
+ std::string m_texPackPath;
+
+ //@{
+ //! Scene to run on startup
+ std::string m_runSceneName;
+ int m_runSceneRank;
+ //@}
+
+ const char* m_standardDataDirs[DIR_MAX];
//! Application language
Language m_language;
//! Low cpu mode
bool m_lowCPU;
+
+ //! Show prototype levels
+ bool m_protoMode;
};
diff --git a/src/app/main.cpp b/src/app/main.cpp
index edb5828..5c0afd3 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -78,7 +78,9 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
{
CLogger logger; // single istance of logger
- InitializeRestext(); // init static translation strings
+ // Initialize static string arrays
+ InitializeRestext();
+ InitializeEventTypeTexts();
CSystemUtils* systemUtils = CSystemUtils::Create(); // platform-specific utils
systemUtils->Init();
@@ -122,3 +124,4 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
}
} // extern "C"
+
diff --git a/src/app/system.cpp b/src/app/system.cpp
index 743ed96..2eb68ba 100644
--- a/src/app/system.cpp
+++ b/src/app/system.cpp
@@ -188,12 +188,13 @@ float CSystemUtils::TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *afte
return result;
}
-std::string CSystemUtils::profileFileLocation()
+std::string CSystemUtils::GetProfileFileLocation()
{
- return std::string("colobot.ini");
+ return std::string("colobot.ini");
}
-std::string CSystemUtils::savegameDirectoryLocation()
+std::string CSystemUtils::GetSavegameDirectoryLocation()
{
- return std::string("savegame");
+ return std::string("savegame");
}
+
diff --git a/src/app/system.h b/src/app/system.h
index 6ae05d6..d22a519 100644
--- a/src/app/system.h
+++ b/src/app/system.h
@@ -131,10 +131,10 @@ public:
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) = 0;
//! Returns the profile (colobot.ini) file location
- virtual std::string profileFileLocation();
+ virtual std::string GetProfileFileLocation();
//! Returns the savegame directory location
- virtual std::string savegameDirectoryLocation();
+ virtual std::string GetSavegameDirectoryLocation();
};
//! Global function to get CSystemUtils instance
@@ -142,3 +142,4 @@ inline CSystemUtils* GetSystemUtils()
{
return CSystemUtils::GetInstancePointer();
}
+
diff --git a/src/app/system_linux.cpp b/src/app/system_linux.cpp
index 01dd850..492af7d 100644
--- a/src/app/system_linux.cpp
+++ b/src/app/system_linux.cpp
@@ -95,9 +95,9 @@ long long CSystemUtilsLinux::TimeStampExactDiff(SystemTimeStamp *before, SystemT
(after->clockTime.tv_sec - before->clockTime.tv_sec) * 1000000000ll;
}
-std::string CSystemUtilsLinux::profileFileLocation()
+std::string CSystemUtilsLinux::GetProfileFileLocation()
{
- std::string m_profileFile;
+ std::string profileFile;
// Determine profileFile according to XDG Base Directory Specification
char* envXDG_CONFIG_HOME = getenv("XDG_CONFIG_HOME");
@@ -106,25 +106,25 @@ std::string CSystemUtilsLinux::profileFileLocation()
char *envHOME = getenv("HOME");
if (envHOME == NULL)
{
- m_profileFile = "colobot.ini";
+ profileFile = "colobot.ini";
}
else
{
- m_profileFile = std::string(envHOME) + "/.config/colobot.ini";
+ profileFile = std::string(envHOME) + "/.config/colobot.ini";
}
}
else
{
- m_profileFile = std::string(envXDG_CONFIG_HOME) + "/colobot.ini";
+ profileFile = std::string(envXDG_CONFIG_HOME) + "/colobot.ini";
}
- GetLogger()->Trace("Profile configuration is %s\n", m_profileFile.c_str());
+ GetLogger()->Trace("Profile configuration is %s\n", profileFile.c_str());
- return m_profileFile;
+ return profileFile;
}
-std::string CSystemUtilsLinux::savegameDirectoryLocation()
+std::string CSystemUtilsLinux::GetSavegameDirectoryLocation()
{
- std::string m_savegameDir;
+ std::string savegameDir;
// Determine savegame dir according to XDG Base Directory Specification
char *envXDG_DATA_HOME = getenv("XDG_CONFIG_DATA");
@@ -133,18 +133,19 @@ std::string CSystemUtilsLinux::savegameDirectoryLocation()
char *envHOME = getenv("HOME");
if (envHOME == NULL)
{
- m_savegameDir = "/tmp/colobot-savegame";
+ savegameDir = "/tmp/colobot-savegame";
}
else
- {
- m_savegameDir = std::string(envHOME) + "/.local/share/colobot";
+ {
+ savegameDir = std::string(envHOME) + "/.local/share/colobot";
}
}
else
{
- m_savegameDir = std::string(envXDG_DATA_HOME) + "/colobot";
+ savegameDir = std::string(envXDG_DATA_HOME) + "/colobot";
}
- GetLogger()->Trace("Saved game files are going to %s\n", m_savegameDir.c_str());
+ GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
- return m_savegameDir;
+ return savegameDir;
}
+
diff --git a/src/app/system_linux.h b/src/app/system_linux.h
index a9a5a52..212d840 100644
--- a/src/app/system_linux.h
+++ b/src/app/system_linux.h
@@ -46,9 +46,10 @@ public:
virtual long long GetTimeStampExactResolution() override;
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override;
- virtual std::string profileFileLocation() override;
- virtual std::string savegameDirectoryLocation() override;
+ virtual std::string GetProfileFileLocation() override;
+ virtual std::string GetSavegameDirectoryLocation() override;
private:
bool m_zenityAvailable;
};
+
diff --git a/src/app/system_other.cpp b/src/app/system_other.cpp
index 9fc1f95..da81a6d 100644
--- a/src/app/system_other.cpp
+++ b/src/app/system_other.cpp
@@ -37,3 +37,4 @@ long long int CSystemUtilsOther::TimeStampExactDiff(SystemTimeStamp* before, Sys
{
return (after->sdlTicks - before->sdlTicks) * 1000000ll;
}
+
diff --git a/src/app/system_other.h b/src/app/system_other.h
index bf16c80..b10a326 100644
--- a/src/app/system_other.h
+++ b/src/app/system_other.h
@@ -46,3 +46,4 @@ public:
virtual long long GetTimeStampExactResolution() override;
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override;
};
+
diff --git a/src/app/system_windows.cpp b/src/app/system_windows.cpp
index 870683f..f48d4e0 100644
--- a/src/app/system_windows.cpp
+++ b/src/app/system_windows.cpp
@@ -111,38 +111,39 @@ std::wstring CSystemUtilsWindows::UTF8_Decode(const std::string& str)
}
-std::string CSystemUtilsWindows::profileFileLocation()
+std::string CSystemUtilsWindows::GetProfileFileLocation()
{
- std::string m_profileFile;
+ std::string profileFile;
char* envUSERPROFILE = getenv("USERPROFILE");
if (envUSERPROFILE == NULL)
{
- m_profileFile = "colobot.ini";
+ profileFile = "colobot.ini";
}
else
{
- m_profileFile = std::string(envUSERPROFILE) + "\\colobot\\colobot.ini";
+ profileFile = std::string(envUSERPROFILE) + "\\colobot\\colobot.ini";
}
- GetLogger()->Trace("Profile configuration is %s\n", m_profileFile.c_str());
+ GetLogger()->Trace("Profile configuration is %s\n", profileFile.c_str());
- return m_profileFile;
+ return profileFile;
}
-std::string CSystemUtilsWindows::savegameDirectoryLocation()
+std::string CSystemUtilsWindows::GetSavegameDirectoryLocation()
{
- std::string m_savegameDir;
+ std::string savegameDir;
char* envUSERPROFILE = getenv("USERPROFILE");
if (envUSERPROFILE == NULL)
{
- m_savegameDir = "savegame";
+ savegameDir = "savegame";
}
else
{
- m_savegameDir = std::string(envUSERPROFILE) + "\\colobot\\savegame";
+ savegameDir = std::string(envUSERPROFILE) + "\\colobot\\savegame";
}
- GetLogger()->Trace("Saved game files are going to %s\n", m_savegameDir.c_str());
+ GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
+
+ return savegameDir;
+}
- return m_savegameDir;
-} \ No newline at end of file
diff --git a/src/app/system_windows.h b/src/app/system_windows.h
index 88e7507..fbc71a1 100644
--- a/src/app/system_windows.h
+++ b/src/app/system_windows.h
@@ -44,8 +44,8 @@ public:
virtual long long GetTimeStampExactResolution() override;
virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) override;
- virtual std::string profileFileLocation() override;
- virtual std::string savegameDirectoryLocation() override;
+ virtual std::string GetProfileFileLocation() override;
+ virtual std::string GetSavegameDirectoryLocation() override;
private:
std::string UTF8_Encode(const std::wstring &wstr);
@@ -54,3 +54,4 @@ private:
protected:
long long m_counterFrequency;
};
+