diff options
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/app.cpp | 154 | ||||
-rw-r--r-- | src/app/app.h | 71 |
2 files changed, 126 insertions, 99 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp index ed76c69..932e61e 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -146,25 +146,24 @@ CApplication::CApplication() m_dataPath = COLOBOT_DEFAULT_DATADIR; m_langPath = COLOBOT_I18N_DIR; + m_texPackPath = ""; m_language = LANGUAGE_ENV; - m_texPack = ""; - m_lowCPU = true; 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() @@ -272,7 +271,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) 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(" -texpack name set texture pack\n"); + GetLogger()->Message(" -texpack path set path to custom texture pack\n"); return PARSE_ARGS_HELP; } case OPT_DEBUG: @@ -286,6 +285,18 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) 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_LOGLEVEL: { LogLevel logLevel; @@ -312,12 +323,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) m_language = language; break; } - case OPT_LANGDIR: - { - m_langPath = optarg; - GetLogger()->Info("Using custom language dir: '%s'\n", m_langPath.c_str()); - break; - } case OPT_VBO: { std::string vbo; @@ -336,12 +341,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) break; } - case OPT_TEXPACK: - { - m_texPack = optarg; - GetLogger()->Info("Using texturepack: '%s'\n", m_texPack.c_str()); - break; - } default: assert(false); // should never get here } @@ -394,20 +393,27 @@ bool CApplication::Create() m_sound->Create(true); // Cache sound files - if (defaultValues) { + if (defaultValues) + { GetProfile().SetLocalProfileString("Resources", "Sound", GetDataSubdirPath(DIR_SOUND)); GetProfile().SetLocalProfileString("Resources", "Music", GetDataSubdirPath(DIR_MUSIC)); } - if (GetProfile().GetLocalProfileString("Resources", "Sound", path)) { + if (GetProfile().GetLocalProfileString("Resources", "Sound", path)) + { m_sound->CacheAll(path); - } else { + } + else + { m_sound->CacheAll(GetDataSubdirPath(DIR_SOUND)); } - if (GetProfile().GetLocalProfileString("Resources", "Music", path)) { + if (GetProfile().GetLocalProfileString("Resources", "Music", path)) + { m_sound->AddMusicFiles(path); - } else { + } + else + { m_sound->AddMusicFiles(GetDataSubdirPath(DIR_MUSIC)); } @@ -496,8 +502,6 @@ bool CApplication::Create() m_engine->SetDevice(m_device); - m_engine->SetTexturePack(m_texPack); - if (! m_engine->Create() ) { m_errorMessage = std::string("Error in CEngine::Init()\n") + standardInfoMessage; @@ -970,12 +974,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; } @@ -1269,7 +1273,7 @@ void CApplication::ResumeSimulation() GetLogger()->Info("Resume simulation\n"); } -bool CApplication::GetSimulationSuspended() +bool CApplication::GetSimulationSuspended() const { return m_simulationSuspended; } @@ -1327,48 +1331,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(); @@ -1415,27 +1419,27 @@ void CApplication::SetDebugMode(bool mode) m_debugMode = mode; } -bool CApplication::GetDebugMode() +bool CApplication::GetDebugMode() const { return m_debugMode; } -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; } @@ -1453,7 +1457,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; @@ -1468,12 +1472,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; } @@ -1486,7 +1490,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; @@ -1503,7 +1507,7 @@ std::vector<JoystickDevice> CApplication::GetJoystickList() return result; } -JoystickDevice CApplication::GetJoystick() +JoystickDevice CApplication::GetJoystick() const { return m_joystick; } @@ -1525,36 +1529,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(); } @@ -1563,12 +1568,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) @@ -1703,7 +1727,7 @@ void CApplication::SetLowCPU(bool low) m_lowCPU = low; } -bool CApplication::GetLowCPU() +bool CApplication::GetLowCPU() const { return m_lowCPU; } @@ -1718,7 +1742,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]; } diff --git a/src/app/app.h b/src/app/app.h index 073ac97..34028c7 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -209,20 +209,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); @@ -232,35 +232,35 @@ public: //! Resumes animation void ResumeSimulation(); //! Returns whether simulation is suspended - bool GetSimulationSuspended(); + bool GetSimulationSuspended() const; //@{ //! 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); @@ -268,7 +268,7 @@ public: //! Management of joystick enable state //@{ void SetJoystickEnabled(bool enable); - bool GetJoystickEnabled(); + bool GetJoystickEnabled() const; //@} //! Polls the state of joystick axes and buttons @@ -278,15 +278,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(); @@ -294,17 +294,17 @@ 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); @@ -312,22 +312,25 @@ public: //! Management of debug mode (prints more info in logger) //@{ void SetDebugMode(bool mode); - bool GetDebugMode(); + bool GetDebugMode() const; //@} //! 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); //@} @@ -335,14 +338,14 @@ 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; //@} protected: @@ -462,14 +465,14 @@ 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; + + const char* m_standardDataDirs[DIR_MAX]; //! Application language Language m_language; - //! Texture pack - std::string m_texPack; - //! Low cpu mode bool m_lowCPU; }; |