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 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'src/game.cpp') 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(); -- cgit 1.4.1