From 8f6fd2a1316432970f1d86515819e7bbe15ddab3 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 26 May 2013 14:50:23 +0200 Subject: Changes in texture code & refactoring * refactored and altered slightly the texture pack code * added flushing of texture cache * some refactoring and const-correctness in CApplication methods --- src/app/app.cpp | 154 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 89 insertions(+), 65 deletions(-) (limited to 'src/app/app.cpp') 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 &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< CApplication::GetJoystickList() +std::vector CApplication::GetJoystickList() const { std::vector result; @@ -1503,7 +1507,7 @@ std::vector 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(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(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]; } -- cgit v1.2.3-1-g7c22