From c2be079943f4a7aa9455e4a80e1c0306fc9c244f Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 7 Jun 2024 13:17:09 +1000 Subject: [PATCH] Save a few instructions for chunk updating checks --- src/MapRenderer.c | 32 +++++++++++++++++++------------- src/MapRenderer.h | 11 ++++++----- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/MapRenderer.c b/src/MapRenderer.c index 9a029048a..9815474a4 100644 --- a/src/MapRenderer.c +++ b/src/MapRenderer.c @@ -54,8 +54,12 @@ static void ChunkInfo_Reset(struct ChunkInfo* chunk, int x, int y, int z) { chunk->vb = 0; #endif - chunk->visible = true; chunk->empty = false; - chunk->pendingDelete = false; chunk->allAir = false; + chunk->visible = true; + chunk->empty = false; + chunk->dirty = false; + chunk->allAir = false; + chunk->noData = true; + chunk->drawXMin = false; chunk->drawXMax = false; chunk->drawZMin = false; chunk->drawZMax = false; chunk->drawYMin = false; chunk->drawYMax = false; @@ -313,7 +317,9 @@ static void DeleteChunk(struct ChunkInfo* info) { Gfx_DeleteVb(&info->vb); #endif - info->empty = false; info->allAir = false; + info->empty = false; + info->allAir = false; + info->noData = true; #ifdef OCCLUSION info.OcclusionFlags = 0; info.OccludedFlags = 0; @@ -351,12 +357,12 @@ static void BuildChunk(struct ChunkInfo* info, int* chunkUpdates) { Game.ChunkUpdates++; (*chunkUpdates)++; - info->pendingDelete = false; Builder_MakeChunk(info); - if (!info->normalParts && !info->translucentParts) { - info->empty = true; return; - } + info->dirty = false; + info->noData = !info->normalParts && !info->translucentParts; + info->empty = info->noData; + if (info->empty) return; if (info->normalParts) { ptr = info->normalParts; @@ -545,13 +551,13 @@ static int UpdateChunksAndVisibility(int* chunkUpdates) { if (info->empty) continue; distSqr = distances[i]; - noData = !info->normalParts && !info->translucentParts; + noData = info->noData; /* Auto unload chunks far away chunks */ if (!noData && distSqr >= buildDistSqr + 32 * 16) { DeleteChunk(info); continue; } - noData |= info->pendingDelete; + noData |= info->dirty; if (noData && distSqr <= buildDistSqr && *chunkUpdates < chunksTarget) { DeleteChunk(info); @@ -578,13 +584,13 @@ static int UpdateChunksStill(int* chunkUpdates) { if (info->empty) continue; distSqr = distances[i]; - noData = !info->normalParts && !info->translucentParts; + noData = info->noData; /* Auto unload chunks far away chunks */ if (!noData && distSqr >= buildDistSqr + 32 * 16) { DeleteChunk(info); continue; } - noData |= info->pendingDelete; + noData |= info->dirty; if (noData && distSqr <= buildDistSqr && *chunkUpdates < chunksTarget) { DeleteChunk(info); @@ -700,8 +706,8 @@ void MapRenderer_RefreshChunk(int cx, int cy, int cz) { info = &mapChunks[World_ChunkPack(cx, cy, cz)]; if (info->allAir) return; /* do not recreate chunks completely air */ - info->empty = false; - info->pendingDelete = true; + info->empty = false; + info->dirty = true; } void MapRenderer_OnBlockChanged(int x, int y, int z, BlockID block) { diff --git a/src/MapRenderer.h b/src/MapRenderer.h index f37865675..9af6528b1 100644 --- a/src/MapRenderer.h +++ b/src/MapRenderer.h @@ -34,11 +34,12 @@ struct ChunkPartInfo { struct ChunkInfo { cc_uint16 centreX, centreY, centreZ; /* Centre coordinates of the chunk */ - cc_uint8 visible : 1; /* Whether chunk is visible to the player */ - cc_uint8 empty : 1; /* Whether the chunk is empty of data */ - cc_uint8 pendingDelete : 1; /* Whether chunk is pending deletion */ - cc_uint8 allAir : 1; /* Whether chunk is completely air */ - cc_uint8 : 0; /* pad to next byte*/ + cc_uint8 visible : 1; /* Whether chunk is visible to the player */ + cc_uint8 empty : 1; /* Whether the chunk is empty of data and is known to have no data */ + cc_uint8 dirty : 1; /* Whether chunk is pending being rebuilt */ + cc_uint8 allAir : 1; /* Whether chunk is completely air */ + cc_uint8 noData : 1; /* Whether the chunk is currently empty of data, but may have data if built */ + cc_uint8 : 0; /* pad to next byte*/ cc_uint8 drawXMin : 1; cc_uint8 drawXMax : 1;