1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-25 09:44:02 +00:00

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
This commit is contained in:
fgenesis 2024-11-15 05:09:57 +01:00
parent 08c42f0d52
commit 9d142bbd0c
4 changed files with 33 additions and 17 deletions

View file

@ -10,6 +10,7 @@
#include "SimpleIStringStream.h"
#define MAPVIS_SUBDIV 64
#define WORLDMAP_REVEALED_BUT_UNEXPLORED_ALPHA 0x60
class Quad;

View file

@ -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()

View file

@ -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);

View file

@ -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<unsigned char> 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;
}