From 0a39ccd0b0c5b855fa7b5dea2082ced774923a62 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 19 Mar 2022 09:57:04 -0400 Subject: load line lag is better --- src/game.cpp | 37 +++++++++++++++++++++++++++++++++---- src/game.h | 4 ++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index 8e4dac5..31c682c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -15,6 +15,9 @@ Game::Game(std::mt19937& rng, Muxer& muxer, Renderer& renderer) : losePopLampTimer.accumulate(losePopLampTimer.getDt()); loadMap(); + tick(); + tick(); + tick(); for (int y = -1; y <= 1; y++) { @@ -105,6 +108,27 @@ void Game::tickDirty(bool onlyDark) { std::swap(map.tiles(), mapDoubleBuffer); } +void Game::tickOuter(bool onlyDark) { + mapDoubleBuffer = map.tiles(); + map.resetDirty(); + + for (int y = 0; y < CHUNK_HEIGHT + 2; y++) { + for (int x = map.getLeft(); x < map.getRight(); x++) { + tickIndividual(*this, mapDoubleBuffer, x, map.getTop() + y, onlyDark); + tickIndividual(*this, mapDoubleBuffer, x, map.getBottom() - 1 - y, onlyDark); + } + } + + for (int x = 0; x < CHUNK_WIDTH + 2; x++) { + for (int y = map.getTop() + CHUNK_HEIGHT + 2; y < map.getBottom() - CHUNK_HEIGHT - 2; y++) { + tickIndividual(*this, mapDoubleBuffer, map.getLeft() + x, y, onlyDark); + tickIndividual(*this, mapDoubleBuffer, map.getRight() - 1 - x, y, onlyDark); + } + } + + std::swap(map.tiles(), mapDoubleBuffer); +} + void Game::tick( int x1, int y1, @@ -577,10 +601,7 @@ void Game::loadMap() { newChunksVert, rng); - tick(); - tick(); - tick(); - + ticksNeeded = 3; dirtyLighting = true; dirtyRender = true; } @@ -909,6 +930,14 @@ void Game::updatePlaying(size_t frameTime) { } } + if (ticksNeeded > 0) { + gradualTickTimer.accumulate(frameTime); + if (gradualTickTimer.step()) { + ticksNeeded--; + tickOuter(); + } + } + if (dirtyLighting) { recalculateLighting(); diff --git a/src/game.h b/src/game.h index 6e676ae..0c4c89f 100644 --- a/src/game.h +++ b/src/game.h @@ -72,6 +72,8 @@ public: size_t numLamps = 0; size_t numDust = 0; std::vector mapDoubleBuffer; + int ticksNeeded = 0; + Timer gradualTickTimer = {100}; int player_x = 0; int player_y = 0; @@ -115,6 +117,8 @@ private: void tickDirty(bool onlyDark); + void tickOuter(bool onlyDark = false); + void tick( int x1, int y1, -- cgit 1.4.1