Performance optimization.

Check if this chunk has any random tick tiles before running random tile tick on it.

When at normal zoom level this has little impact, But when you zoom out really far it's helpful.
This commit is contained in:
2025-02-27 18:56:21 -05:00
parent 7707d6d3a6
commit 7ae6003e23
4 changed files with 17 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
# Build Options
set(CLIENT_BUILD_WITH_STEAM false)
cmake_policy(SET CMP0169 OLD)
#cmake_policy(SET CMP0169 OLD)
cmake_minimum_required(VERSION 3.18..3.29)
project(ReCaveGame

View File

@@ -130,6 +130,7 @@ namespace CaveGame::Core
bool touched;
// For to the rendertarget!!
float time_since_refresh = 0.f;
int tiles_with_random_tick_count = 0;
protected:
Vector2i cell;
TileID tiles[ChunkSize][ChunkSize];
@@ -139,9 +140,6 @@ namespace CaveGame::Core
bool first_pass_complete = false;
bool second_pass_complete = false;
bool has_update = false;
};
constexpr std::size_t Chunk::BufferSizeBytes()

View File

@@ -10,15 +10,19 @@ namespace CaveGame::Core
if (!(0 <= x && x < ChunkSize && 0 <= y && y < ChunkSize))
assert("Out of bounds!");
if (tiles[x][y] != t)
{
if (tiles[x][y] != t) {
Tile* old_tile = GetByNumeric(tiles[x][y]);
Tile* new_tile = GetByNumeric(t);
if (old_tile->DoesRandomTicc())
tiles_with_random_tick_count--;
if (new_tile->DoesRandomTicc())
tiles_with_random_tick_count++;
tiles[x][y] = t;
touched = true;
if (trigger_tile_updates)
{
SetTileUpdateFlag(x, y);
}
}
}

View File

@@ -447,11 +447,13 @@ namespace CaveGame::Core
Logs::Info("Saving successful!");
}
// TODO
/* This is what's taking all our CPU time now because we don't know if we have a tile in
* our chunk that does random tile ticks *before* having to observe it right here. If that
* were the case, We could just skip the whole thing. - Redacted. */
void World::DoRandomTileTick(const Vector2i& coords, Chunk* chunk) {
// TODO make sure this value is restored when the chunks load from disk.
if (chunk->tiles_with_random_tick_count == 0)
return;
if (chunk->tiles_with_random_tick_count < 0)
std::cout << "The number of tiles with random tick in the chunk is negative?" << std::endl;
Tile* tile = nullptr;
int max_tries = RandomTileTickCoefficient*5;