From c8dfb45973de7fdfd9eca1e8397e0a423329ebbc Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 13 Apr 2024 23:09:55 +1000 Subject: [PATCH] Make initial block face visibility calculation much faster by avoiding redundant work for most blocks Reduces initial calculation time from ~11 ms to ~2 ms on my PC, and from ~1300 ms to ~130 ms on the DS --- src/Block.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Block.c b/src/Block.c index 3508e4145..fd2551efe 100644 --- a/src/Block.c +++ b/src/Block.c @@ -345,7 +345,13 @@ static void Block_CalcCulling(BlockID block, BlockID other) { cc_bool occludedX, occludedY, occludedZ, bothLiquid; int f; - /* Some blocks may not cull 'other' block, in which case just skip per-face check */ + /* Fast path: Full opaque neighbouring blocks will always have all shared faces hidden */ + if (Blocks.FullOpaque[block] && Blocks.FullOpaque[other]) { + Blocks.Hidden[(block * BLOCK_COUNT) + other] = 0x3F; + return; + } + + /* Some blocks may not cull 'other' block, in which case just skip detailed check */ /* e.g. sprite blocks, default leaves, will not cull any other blocks */ if (!Block_MightCull(block, other)) { Blocks.Hidden[(block * BLOCK_COUNT) + other] = 0; @@ -380,6 +386,7 @@ static void Block_CalcCulling(BlockID block, BlockID other) { /* Updates culling data of all blocks */ static void Block_UpdateAllCulling(void) { int block, neighbour; + for (block = BLOCK_AIR; block < BLOCK_COUNT; block++) { Block_CalcStretch((BlockID)block); for (neighbour = BLOCK_AIR; neighbour < BLOCK_COUNT; neighbour++) {