diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp index 0b1b635..b36c8c2 100644 --- a/Aquaria/Game.cpp +++ b/Aquaria/Game.cpp @@ -227,6 +227,7 @@ Game::Game() : StateObject() cookingScript = 0; doScreenTrans = false; noSceneTransitionFadeout = false; + fullTilesetReload = false; } Game::~Game() @@ -1725,7 +1726,7 @@ bool Game::loadSceneXML(std::string scene) struct ElementDef { ElementDef(int lr) - : layer(lr), idx(0), x(0), y(0), rot(0), fh(0), fv(0), flags(0), efxIdx(0), repeat(0) + : layer(lr), idx(0), x(0), y(0), rot(0), fh(0), fv(0), flags(0), efxIdx(-1), repeat(0) , tag(0), sx(1), sy(1), rsx(1), rsy(1) {} @@ -1838,7 +1839,7 @@ bool Game::loadSceneXML(std::string scene) ElementDef& d = elemsDefs[i]; if(d.repeat) { - if(!(is >> d.rsx >> d.rsx)) + if(!(is >> d.rsx >> d.rsy)) break; } } @@ -1856,6 +1857,14 @@ bool Game::loadSceneXML(std::string scene) simpleElements = simpleElements->NextSiblingElement("SE"); } + if(fullTilesetReload) + { + fullTilesetReload = false; + // used by SceneEditor + // no elements exist right now -> textures will be cleared and reloaded + dsq->texmgr.clearUnused(); + } + // figure out which textures in the tileset are used and preload those that are actually used { unsigned char usedIdx[1024] = {0}; @@ -1904,8 +1913,7 @@ bool Game::loadSceneXML(std::string scene) e->rotation.z = d.rot; e->repeatToFillScale.x = d.rsx; e->repeatToFillScale.y = d.rsy; - if(d.efxIdx) - e->setElementEffectByIndex(d.efxIdx); + e->setElementEffectByIndex(d.efxIdx); if (d.repeat) e->repeatTextureToFill(true); // also applies repeatToFillScale e->setTag(d.tag); diff --git a/Aquaria/Game.h b/Aquaria/Game.h index 01c20cd..42cb8f0 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -350,6 +350,7 @@ public: bool loadingScene; bool doScreenTrans; bool noSceneTransitionFadeout; + bool fullTilesetReload; WaterSurfaceRender *waterSurfaceRender; diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index 9edc88a..00c8228 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -1817,6 +1817,7 @@ void SceneEditor::loadSceneByName() if (!s.empty()) { game->noSceneTransitionFadeout = true; + game->fullTilesetReload = true; game->transitionToScene(s); } } @@ -1825,6 +1826,7 @@ void SceneEditor::reloadScene() { debugLog("reloadScene"); game->noSceneTransitionFadeout = true; + game->fullTilesetReload = true; game->positionToAvatar = game->avatar->position; game->transitionToScene(game->sceneName); } diff --git a/BBGE/TextureMgr.cpp b/BBGE/TextureMgr.cpp index af7314e..7676868 100644 --- a/BBGE/TextureMgr.cpp +++ b/BBGE/TextureMgr.cpp @@ -8,13 +8,14 @@ struct TexLoadTmp { - TexLoadTmp() : loadmode(TextureMgr::KEEP), curTex(NULL), success(false) { img.pixels = NULL; } + TexLoadTmp() : loadmode(TextureMgr::KEEP), curTex(NULL), success(false), arrayidx(0) { img.pixels = NULL; } std::string name, filename; ImageData img; TextureMgr::LoadMode loadmode; Texture *curTex; // immutable bool success; // if this is true and img.pixels is NULL, don't change anything //bool mipmap; + size_t arrayidx; }; typedef ImageData (*ImageLoadFunc)(const char *fn); @@ -289,6 +290,7 @@ void TextureMgr::loadBatch(Texture * pdst[], const std::string texnames[], size_ for(size_t i = 0; i < n; ++i) { TexLoadTmp& tt = tmp[i]; + tt.arrayidx = i; tt.name = texnames[i]; stringToLower(tt.name); TexCache::iterator it = cache.find(tt.name); @@ -315,7 +317,7 @@ void TextureMgr::loadBatch(Texture * pdst[], const std::string texnames[], size_ TexLoadTmp& tt = *(TexLoadTmp*)p; Texture *tex = finalize(tt); if(pdst) - pdst[i] = tex; + pdst[tt.arrayidx] = tex; if(cb) cb(++doneCB, cbUD); }