From 04f747b00b95ebbd32457eae8a397695dc6981af Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sun, 12 May 2013 14:55:41 +0200 Subject: Added simple texturepack support (#208) --- src/app/app.cpp | 17 +++++++++++++++-- src/app/app.h | 3 +++ src/graphics/engine/engine.cpp | 35 +++++++++++++++++++++++++++++------ src/graphics/engine/engine.h | 9 ++++++++- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 190f667..87b9e39 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -149,6 +149,8 @@ CApplication::CApplication() m_language = LANGUAGE_ENV; + m_texPack = ""; + m_lowCPU = true; for (int i = 0; i < DIR_MAX; ++i) @@ -219,7 +221,8 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) OPT_LOGLEVEL, OPT_LANGUAGE, OPT_LANGDIR, - OPT_VBO + OPT_VBO, + OPT_TEXPACK }; option options[] = @@ -230,7 +233,8 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { "loglevel", required_argument, nullptr, OPT_LOGLEVEL }, { "language", required_argument, nullptr, OPT_LANGUAGE }, { "langdir", required_argument, nullptr, OPT_LANGDIR }, - { "vbo", required_argument, nullptr, OPT_VBO } + { "vbo", required_argument, nullptr, OPT_VBO }, + { "texpack", required_argument, nullptr, OPT_TEXPACK } }; opterr = 0; @@ -267,6 +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"); return PARSE_ARGS_HELP; } case OPT_DEBUG: @@ -330,6 +335,12 @@ 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 } @@ -484,6 +495,8 @@ 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; diff --git a/src/app/app.h b/src/app/app.h index 07f1b90..073ac97 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -467,6 +467,9 @@ protected: //! Application language Language m_language; + //! Texture pack + std::string m_texPack; + //! Low cpu mode bool m_lowCPU; }; diff --git a/src/graphics/engine/engine.cpp b/src/graphics/engine/engine.cpp index 806cb5f..5bd51fe 100644 --- a/src/graphics/engine/engine.cpp +++ b/src/graphics/engine/engine.cpp @@ -62,6 +62,8 @@ CEngine::CEngine(CApplication *app) m_sound = nullptr; m_terrain = nullptr; + m_texPack = ""; + m_showStats = false; m_focus = 0.75f; @@ -236,6 +238,11 @@ void CEngine::SetTerrain(CTerrain* terrain) m_terrain = terrain; } +void CEngine::SetTexturePack(const std::string& texpackName) +{ + m_texPack = texpackName; +} + bool CEngine::Create() { @@ -2109,7 +2116,7 @@ void CEngine::SetViewParams(const Math::Vector& eyePt, const Math::Vector& looka m_sound->SetListener(eyePt, lookatPt); } -Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params, CImage* image) +Texture CEngine::CreateTexture(const std::string& texName, const TextureCreateParams& params, CImage* image, std::string orginalName) { if (texName.empty()) return Texture(); // invalid texture @@ -2125,7 +2132,7 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa if (! img.Load(m_app->GetDataFilePath(DIR_TEXTURE, texName))) { std::string error = img.GetError(); - GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); + if(orginalName == "") GetLogger()->Error("Couldn't load texture '%s': %s, blacklisting\n", texName.c_str(), error.c_str()); m_texBlacklist.insert(texName); return Texture(); // invalid texture } @@ -2139,13 +2146,18 @@ Texture CEngine::CreateTexture(const std::string& texName, const TextureCreatePa if (! tex.Valid()) { - GetLogger()->Error("Couldn't load texture '%s', blacklisting\n", texName.c_str()); + if(orginalName == "") GetLogger()->Error("Couldn't load texture '%s', blacklisting\n", texName.c_str()); m_texBlacklist.insert(texName); return tex; } - m_texNameMap[texName] = tex; - m_revTexNameMap[tex] = texName; + if(orginalName == "") { + m_texNameMap[texName] = tex; + m_revTexNameMap[tex] = texName; + } else { + m_texNameMap[orginalName] = tex; + m_revTexNameMap[tex] = orginalName; + } return tex; } @@ -2170,7 +2182,18 @@ Texture CEngine::LoadTexture(const std::string& name, const TextureCreateParams& if (it != m_texNameMap.end()) return (*it).second; - Texture tex = CreateTexture(name, params); + Texture tex; + if (m_texPack != "") { + std::string name_texpack = m_texPack + "/" + name; + + if (m_texBlacklist.find(name_texpack) == m_texBlacklist.end()) { + tex = CreateTexture(name_texpack, params, nullptr, name); + if (tex.Valid()) + return tex; + } + } + + tex = CreateTexture(name, params); return tex; } diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index 16fb4e6..8df912e 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -726,6 +726,10 @@ public: //! Writes a screenshot containing the current frame bool WriteScreenShot(const std::string& fileName, int width, int height); + //! Set texture pack + void SetTexturePack(const std::string& texpackName); + + //@{ //! Management of game pause mode void SetPause(bool pause); @@ -1229,7 +1233,7 @@ protected: const Material& mat, int state); //! Create texture and add it to cache - Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms, CImage* image = nullptr); + Texture CreateTexture(const std::string &texName, const TextureCreateParams ¶ms, CImage* image = nullptr, std::string orginalName = ""); //! Tests whether the given object is visible bool IsVisible(int objRank); @@ -1403,6 +1407,9 @@ protected: * so are disabled for subsequent load calls. */ std::set m_texBlacklist; + //! Texture pack + std::string m_texPack; + //! Mouse cursor definitions EngineMouse m_mice[ENG_MOUSE_COUNT]; //! Texture with mouse cursors -- cgit v1.2.3-1-g7c22