From 9d142bbd0c39264e71ec6996ffc01b480d73ea2e Mon Sep 17 00:00:00 2001 From: fgenesis Date: Fri, 15 Nov 2024 05:09:57 +0100 Subject: [PATCH] show exploration progress on prerevealed maps, too also clean up map tile dirty/refresh handling a bit; it's less error prone and a bit more efficient now --- Aquaria/WorldMap.h | 1 + Aquaria/WorldMapRender.cpp | 33 +++++++++++++++++++++------------ Aquaria/WorldMapRender.h | 2 +- Aquaria/WorldMapTiles.cpp | 14 ++++++++++---- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Aquaria/WorldMap.h b/Aquaria/WorldMap.h index f35a2ae..b59bf0c 100644 --- a/Aquaria/WorldMap.h +++ b/Aquaria/WorldMap.h @@ -10,6 +10,7 @@ #include "SimpleIStringStream.h" #define MAPVIS_SUBDIV 64 +#define WORLDMAP_REVEALED_BUT_UNEXPLORED_ALPHA 0x60 class Quad; diff --git a/Aquaria/WorldMapRender.cpp b/Aquaria/WorldMapRender.cpp index 7bd3ec3..dd2c5c3 100644 --- a/Aquaria/WorldMapRender.cpp +++ b/Aquaria/WorldMapRender.cpp @@ -410,11 +410,15 @@ void WorldMapRender::setProperTileColor(WorldMapTileContainer& wt) const WorldMapTile& t = wt.tile; if(selectedTile != &wt) { - wt.q.alphaMod = (t.revealed || t.prerevealed) ? 0.5f : 0.0f; + float amod = (t.revealed || t.prerevealed) ? 0.5f : 0.0f; + + if(!t.revealed) + amod *= float(WORLDMAP_REVEALED_BUT_UNEXPLORED_ALPHA) / float(0xff); if (selectedTile && t.layer != selectedTile->tile.layer) - wt.q.alphaMod *= 0.5f; + amod *= 0.5f; + wt.q.alphaMod = amod; wt.q.color = Vector(0.7f, 0.8f, 1); } else @@ -564,9 +568,9 @@ void WorldMapRender::init() tc.position = t.gridPos; t.originalTex = texs[i]; + tc.setTexturePointer(texs[i]); // to init width, height - t.dirty = true; // force refresh to init texture, width, height - tc.refresh(); + tc.refreshMapTile(); // may or may not set texture to the generated one setProperTileColor(tc); } @@ -1136,8 +1140,9 @@ void WorldMapRender::toggle(bool turnON) scale = Vector(1,1); } + // Opening the map. Some tiles may need refreshing in case some new visited areas were uncovered in the meantime for(size_t i = 0; i < tiles.size(); ++i) - tiles[i]->refresh(); + tiles[i]->refreshMapTile(); xMin = xMax = -internalOffset.x; yMin = yMax = -internalOffset.y; @@ -1324,22 +1329,26 @@ WorldMapTileContainer::WorldMapTileContainer(WorldMapTile& tile) addChild(&q, PM_STATIC); q.borderAlpha = 0.7f; q.renderBorderColor = Vector(1, 0.5f, 0.5f); - assert(tile.generatedTex); - q.setTexturePointer(tile.generatedTex); } WorldMapTileContainer::~WorldMapTileContainer() { } -void WorldMapTileContainer::refresh() +void WorldMapTileContainer::refreshMapTile() { - if(tile.dirty) + Texture *usetex = tile.originalTex.content(); + if(tile.revealed) { - bool usegen = !tile.prerevealed && tile.updateDiscoveredTex(); - q.setTexturePointer(usegen ? tile.generatedTex : tile.originalTex); // updates width, height - tile.dirty = false; + if(tile.dirty) + { + tile.updateDiscoveredTex(); + tile.dirty = false; // keep it dirty when undiscovered + } + if(tile.generatedTex) + usetex = tile.generatedTex.content(); } + q.setTexturePointer(usetex); // updates width, height } void WorldMapTileContainer::removeGems() diff --git a/Aquaria/WorldMapRender.h b/Aquaria/WorldMapRender.h index 350fd4c..e911ddb 100644 --- a/Aquaria/WorldMapRender.h +++ b/Aquaria/WorldMapRender.h @@ -25,7 +25,7 @@ public: virtual void onUpdate(float dt) OVERRIDE; - void refresh(); // Called whenever we need to prepare for rendering + void refreshMapTile(); // Called whenever we need to prepare for rendering void removeGems(); void addGem(GemMover *gem); diff --git a/Aquaria/WorldMapTiles.cpp b/Aquaria/WorldMapTiles.cpp index a6ba209..4839fda 100644 --- a/Aquaria/WorldMapTiles.cpp +++ b/Aquaria/WorldMapTiles.cpp @@ -42,7 +42,6 @@ WorldMapTile::WorldMapTile() index = -1; stringIndex = 0; dirty = true; - generatedTex = new Texture; } WorldMapTile::~WorldMapTile() @@ -256,7 +255,10 @@ ImageData WorldMapTile::generateAlphaImage(size_t w, size_t h) if(visited.empty()) return ret; - // stbir can't deal with 1-bit images, so let's make a 1-channel black or white image first + const unsigned char exploredAlpha = 0xff; + const unsigned char unexploredAlpha = prerevealed ? WORLDMAP_REVEALED_BUT_UNEXPLORED_ALPHA : 0; + + // convert visited data to a proper 1-channel image Array2d tmp(MAPVIS_SUBDIV, MAPVIS_SUBDIV); unsigned char *dst = tmp.data(); for(size_t y = 0; y < MAPVIS_SUBDIV; ++y) @@ -266,7 +268,7 @@ ImageData WorldMapTile::generateAlphaImage(size_t w, size_t h) { unsigned c = src[x/8]; for(size_t bit = 0; bit < 8; ++bit) - *dst++ = (c & (1 << bit)) ? 0xff : 0; + *dst++ = (c & (1 << bit)) ? exploredAlpha : unexploredAlpha; } } @@ -322,7 +324,11 @@ bool WorldMapTile::updateDiscoveredTex() up.w = w; up.h = h; - generatedTex->upload(up, true); + Texture *tex = generatedTex.content(); + if(!tex) + generatedTex = tex = new Texture(); + + tex->upload(up, true); return true; }