From fbee8b6c35e3bf55ad02c30f354bd42b2c245a1b Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 15 Mar 2022 12:13:45 -0400 Subject: lit tiles in unloaded chunk should count toward total lit tiles for zooming --- src/game.cpp | 7 ++----- src/map.h | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index e9a9fbe..7c67daa 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -119,11 +119,7 @@ void Game::tick(bool onlyDark) bool Game::movePlayer(int x, int y) { - if (/*x >= curBoundX && - y >= curBoundY && - x < curBoundX + curZoom * ZOOM_X_FACTOR && - y < curBoundY + curZoom * ZOOM_Y_FACTOR &&*/ - map.at(x,y).tile == Tile::Floor) + if (map.at(x,y).tile == Tile::Floor) { if (map.at(player_x, player_y).tile == Tile::Floor) { @@ -249,6 +245,7 @@ void Game::recalculateLighting() } } + litSpots += map.getUnloadedLitTiles(); dirtyLighting = false; } diff --git a/src/map.h b/src/map.h index 13b2b32..2faac85 100644 --- a/src/map.h +++ b/src/map.h @@ -120,6 +120,8 @@ public: return loaded_; } + inline int getUnloadedLitTiles() const { return unloadedLitTiles_; } + void load(int newLeftChunk, int newTopChunk, int newWidthChunks, int newHeightChunks, std::mt19937& rng) { // Flush the currently loaded data as long as there is any (this isn't the first load). if (!loaded_.empty()) { @@ -143,6 +145,8 @@ public: } } } + + unloadedLitTiles_ += chunk.litTiles; } } @@ -183,6 +187,7 @@ public: Chunk& chunk = chunks_[chunkIndex]; chunk.x = leftmostChunk_ + chunkX; chunk.y = topmostChunk_ + chunkY; + chunk.litTiles = 0; for (MapData& md : chunk.data) { @@ -205,6 +210,8 @@ public: std::next(std::begin(chunk.data), (y+1)*CHUNK_WIDTH), std::next(std::begin(loaded_), (chunkY*CHUNK_HEIGHT + y)*width_ + chunkX*CHUNK_WIDTH)); } + + unloadedLitTiles_ -= chunk.litTiles; } } @@ -225,6 +232,8 @@ private: std::vector chunks_; std::list freeList_; std::map> chunkByPos_; // chunkByPos_[X][Y] + + int unloadedLitTiles_ = 0; }; #endif /* end of include guard: MAP_H_3AB00D12 */ -- cgit 1.4.1