summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2022-03-19 09:57:04 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2022-03-19 09:57:04 -0400
commit0a39ccd0b0c5b855fa7b5dea2082ced774923a62 (patch)
tree266127270f4a706ed6a378c0c58116022b6fa3f1 /src
parentd1ec962c788286d0eca331ac33b3dd1867618ddb (diff)
downloadether-0a39ccd0b0c5b855fa7b5dea2082ced774923a62.tar.gz
ether-0a39ccd0b0c5b855fa7b5dea2082ced774923a62.tar.bz2
ether-0a39ccd0b0c5b855fa7b5dea2082ced774923a62.zip
load line lag is better
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp37
-rw-r--r--src/game.h4
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) :
15 losePopLampTimer.accumulate(losePopLampTimer.getDt()); 15 losePopLampTimer.accumulate(losePopLampTimer.getDt());
16 16
17 loadMap(); 17 loadMap();
18 tick();
19 tick();
20 tick();
18 21
19 for (int y = -1; y <= 1; y++) 22 for (int y = -1; y <= 1; y++)
20 { 23 {
@@ -105,6 +108,27 @@ void Game::tickDirty(bool onlyDark) {
105 std::swap(map.tiles(), mapDoubleBuffer); 108 std::swap(map.tiles(), mapDoubleBuffer);
106} 109}
107 110
111void Game::tickOuter(bool onlyDark) {
112 mapDoubleBuffer = map.tiles();
113 map.resetDirty();
114
115 for (int y = 0; y < CHUNK_HEIGHT + 2; y++) {
116 for (int x = map.getLeft(); x < map.getRight(); x++) {
117 tickIndividual(*this, mapDoubleBuffer, x, map.getTop() + y, onlyDark);
118 tickIndividual(*this, mapDoubleBuffer, x, map.getBottom() - 1 - y, onlyDark);
119 }
120 }
121
122 for (int x = 0; x < CHUNK_WIDTH + 2; x++) {
123 for (int y = map.getTop() + CHUNK_HEIGHT + 2; y < map.getBottom() - CHUNK_HEIGHT - 2; y++) {
124 tickIndividual(*this, mapDoubleBuffer, map.getLeft() + x, y, onlyDark);
125 tickIndividual(*this, mapDoubleBuffer, map.getRight() - 1 - x, y, onlyDark);
126 }
127 }
128
129 std::swap(map.tiles(), mapDoubleBuffer);
130}
131
108void Game::tick( 132void Game::tick(
109 int x1, 133 int x1,
110 int y1, 134 int y1,
@@ -577,10 +601,7 @@ void Game::loadMap() {
577 newChunksVert, 601 newChunksVert,
578 rng); 602 rng);
579 603
580 tick(); 604 ticksNeeded = 3;
581 tick();
582 tick();
583
584 dirtyLighting = true; 605 dirtyLighting = true;
585 dirtyRender = true; 606 dirtyRender = true;
586} 607}
@@ -909,6 +930,14 @@ void Game::updatePlaying(size_t frameTime) {
909 } 930 }
910 } 931 }
911 932
933 if (ticksNeeded > 0) {
934 gradualTickTimer.accumulate(frameTime);
935 if (gradualTickTimer.step()) {
936 ticksNeeded--;
937 tickOuter();
938 }
939 }
940
912 if (dirtyLighting) 941 if (dirtyLighting)
913 { 942 {
914 recalculateLighting(); 943 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:
72 size_t numLamps = 0; 72 size_t numLamps = 0;
73 size_t numDust = 0; 73 size_t numDust = 0;
74 std::vector<Tile> mapDoubleBuffer; 74 std::vector<Tile> mapDoubleBuffer;
75 int ticksNeeded = 0;
76 Timer gradualTickTimer = {100};
75 77
76 int player_x = 0; 78 int player_x = 0;
77 int player_y = 0; 79 int player_y = 0;
@@ -115,6 +117,8 @@ private:
115 117
116 void tickDirty(bool onlyDark); 118 void tickDirty(bool onlyDark);
117 119
120 void tickOuter(bool onlyDark = false);
121
118 void tick( 122 void tick(
119 int x1, 123 int x1,
120 int y1, 124 int y1,