Added simple texturepack support (#208)
parent
06cf93f466
commit
04f747b00b
|
@ -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;
|
||||
|
|
|
@ -467,6 +467,9 @@ protected:
|
|||
//! Application language
|
||||
Language m_language;
|
||||
|
||||
//! Texture pack
|
||||
std::string m_texPack;
|
||||
|
||||
//! Low cpu mode
|
||||
bool m_lowCPU;
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<std::string> m_texBlacklist;
|
||||
|
||||
//! Texture pack
|
||||
std::string m_texPack;
|
||||
|
||||
//! Mouse cursor definitions
|
||||
EngineMouse m_mice[ENG_MOUSE_COUNT];
|
||||
//! Texture with mouse cursors
|
||||
|
|
Loading…
Reference in New Issue