diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index 2e3be81..b681a42 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -4429,7 +4429,7 @@ std::string Core::getTextureLoadName(const std::string &texture) return loadName; } -std::pair, TextureLoadResult> Core::doTextureAdd(const std::string &texture, const std::string &loadName, std::string internalTextureName) +CountedPtr Core::doTextureAdd(const std::string &texture, const std::string &loadName, std::string internalTextureName) { if (texture.empty() || !ISPATHROOT(texture)) { @@ -4448,35 +4448,28 @@ std::pair, TextureLoadResult> Core::doTextureAdd(const std:: stringToLowerUserData(internalTextureName); CountedPtr t = core->findTexture(internalTextureName); if (t) - return std::make_pair(t, TEX_SUCCESS); + return t; t = new Texture; t->name = internalTextureName; - unsigned res = TEX_FAILED; - if(t->load(loadName)) - res |= (TEX_LOADED | TEX_SUCCESS); - else + if(!t->load(loadName)) { t->width = 64; t->height = 64; } - return std::make_pair(t, (TextureLoadResult)res); + return t; } -CountedPtr Core::addTexture(const std::string &textureName, TextureLoadResult *pLoadResult /* = 0 */) +CountedPtr Core::addTexture(const std::string &textureName) { BBGE_PROF(Core_addTexture); if (textureName.empty()) - { - if(pLoadResult) - *pLoadResult = TEX_FAILED; return NULL; - } - std::pair, TextureLoadResult> texResult; + CountedPtr ptex; std::string texture = textureName; stringToLowerUserData(texture); std::string internalTextureName = texture; @@ -4493,33 +4486,31 @@ CountedPtr Core::addTexture(const std::string &textureName, TextureLoad std::string ln = loadName; texture = secondaryTexturePath + texture; loadName = texture; - texResult = doTextureAdd(texture, loadName, internalTextureName); - if (!texResult.second) - texResult = doTextureAdd(t, ln, internalTextureName); + ptex = doTextureAdd(texture, loadName, internalTextureName); + if (!ptex || ptex->getLoadResult() == TEX_FAILED) + ptex = doTextureAdd(t, ln, internalTextureName); } else - texResult = doTextureAdd(texture, loadName, internalTextureName); + ptex = doTextureAdd(texture, loadName, internalTextureName); - addTexture(texResult.first.content()); + addTexture(ptex.content()); if(debugLogTextures) { - if (texResult.second & TEX_LOADED) + if (ptex) { std::ostringstream os; os << "LOADED TEXTURE FROM DISK: [" << internalTextureName << "] idx: " << resources.size()-1; debugLog(os.str()); } - else if(!(texResult.second & TEX_SUCCESS)) + else if(ptex->getLoadResult() != TEX_SUCCESS) { std::ostringstream os; os << "FAILED TO LOAD TEXTURE: [" << internalTextureName << "] idx: " << resources.size()-1; debugLog(os.str()); } } - if(pLoadResult) - *pLoadResult = texResult.second; - return texResult.first; + return ptex; } void Core::addRenderObject(RenderObject *o, int layer) diff --git a/BBGE/Core.h b/BBGE/Core.h index 34799d8..2892ea2 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -1023,7 +1023,7 @@ public: void removeTexture(Texture *res); void clearResources(); - CountedPtr addTexture(const std::string &texture, TextureLoadResult *pLoadResult = 0); + CountedPtr addTexture(const std::string &texture); PostProcessingFX postProcessingFx; @@ -1328,7 +1328,7 @@ protected: virtual void onReloadResources(); - std::pair, TextureLoadResult> doTextureAdd(const std::string &texture, const std::string &name, std::string internalTextureName); + CountedPtr doTextureAdd(const std::string &texture, const std::string &name, std::string internalTextureName); void deleteRenderObjectMemory(RenderObject *r); bool _hasFocus; diff --git a/BBGE/RenderObject.cpp b/BBGE/RenderObject.cpp index 6e79b4d..faa0f7d 100644 --- a/BBGE/RenderObject.cpp +++ b/BBGE/RenderObject.cpp @@ -1365,13 +1365,12 @@ bool RenderObject::setTexture(const std::string &n) if (name.empty()) return false; - if(texture && name == texture->name) + if(texture && texture->getLoadResult() == TEX_SUCCESS && name == texture->name) return true; // no texture change - TextureLoadResult res = TEX_FAILED; - CountedPtr tex = core->addTexture(name, &res); + CountedPtr tex = core->addTexture(name); setTexturePointer(tex); - return !!tex && res != TEX_FAILED; + return tex && tex->getLoadResult() == TEX_SUCCESS; } float RenderObject::getSortDepth() diff --git a/BBGE/Texture.cpp b/BBGE/Texture.cpp index f9b898c..ba68b80 100644 --- a/BBGE/Texture.cpp +++ b/BBGE/Texture.cpp @@ -69,6 +69,7 @@ Texture::Texture() repeating = false; pngSetStandardOrientation(0); ow = oh = -1; + loadResult = TEX_FAILED; } Texture::~Texture() @@ -262,6 +263,7 @@ void Texture::reload() bool Texture::load(std::string file) { + loadResult = TEX_FAILED; if (file.size()<4) { errorLog("Texture Name is Empty or Too Short"); @@ -430,6 +432,7 @@ bool Texture::loadPNG(const std::string &file) width = info.Width; height = info.Height; good = true; + loadResult = TEX_SUCCESS; } else { @@ -486,6 +489,7 @@ bool Texture::loadTGA(ImageTGA *imageTGA) delete[] (imageTGA->data); free (imageTGA); + loadResult = TEX_SUCCESS; return true; } diff --git a/BBGE/Texture.h b/BBGE/Texture.h index a32a5ee..643a54a 100644 --- a/BBGE/Texture.h +++ b/BBGE/Texture.h @@ -23,11 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Base.h" + enum TextureLoadResult { - TEX_FAILED = 0x00, - TEX_SUCCESS = 0x01, - TEX_LOADED = 0x02, + TEX_FAILED, + TEX_SUCCESS }; struct ImageTGA @@ -81,6 +81,8 @@ public: std::string name; + TextureLoadResult getLoadResult() const { return loadResult; } + protected: std::string loadName; @@ -91,6 +93,7 @@ protected: bool loadTGA(ImageTGA *tga); int ow, oh; + TextureLoadResult loadResult; };