MinecraftConsoles/Minecraft.Client/Chunk.h
Racc 68efba88bd optimisation
Chunk.cpp/h:
- thread_local occluder table via std::array<bool,256> IIFE; queries
  isSolidRender() for all 255 tile types instead of only stone/dirt/bedrock
- Null-check getChunkAt() early-out with correct COMPILED/NOTSKYLIT/EMPTY flags
- Defer Region + TileRenderer construction past empty-check to skip 9 chunk
  lookups and 128KB memset for empty chunks (common post-teleport)
- Replace Win32 TLS API (TlsAlloc/TlsSetValue/TlsGetValue) + new/delete
  with static thread_local array for per-thread tileIds storage

LevelRenderer.cpp:
- Rewrite updateDirtyChunks nearest-chunk search as linear ClipChunk scan;
  dirty-flag checked before any distance work, batch-clear empty dirty chunks
  upfront via isRenderChunkEmpty to shrink dirty set across frames
- const on all distance/flag locals

Region.h/cpp:
- Stack buffer flatChunks_stack[16] for common render-chunk regions (4x4),
  std::unique_ptr<LevelChunk*[]> heap fallback for large pathfinding regions;
  eliminates per-rebuild heap alloc/free on the hot path
- Deleted copy/move ops; std::fill_n for null-init; static constexpr constant

TileRenderer.h/cpp:
- static thread_local cache array replaces per-instance new/delete
- Remove dead getLightColorCount, cacheOwned, conditional delete[]
- static constexpr cache size; defaulted destructor

Level.cpp: Region constructed directly on stack (no copy)
stdafx.h: added <array>
2026-03-09 17:57:01 +00:00

87 lines
1.8 KiB
C++

#pragma once
#include "AllowAllCuller.h"
#include "Tesselator.h"
#include "..\Minecraft.World\ArrayWithLength.h"
#include "LevelRenderer.h"
class Level;
class TileEntity;
class Entity;
using namespace std;
class ClipChunk
{
public:
Chunk *chunk;
int globalIdx;
bool visible;
float aabb[6];
int xm, ym, zm;
};
class Chunk
{
private:
static const int XZSIZE = LevelRenderer::CHUNK_XZSIZE;
static const int SIZE = LevelRenderer::CHUNK_SIZE;
public:
Level *level;
static LevelRenderer *levelRenderer;
private:
#ifndef _LARGE_WORLDS
static Tesselator *t;
#else
public:
static void CreateNewThreadStorage();
static void ReleaseThreadStorage();
static unsigned char *GetTileIdsStorage();
#endif
public:
static int updates;
int x, y, z;
int xRender, yRender, zRender;
int xRenderOffs, yRenderOffs, zRenderOffs;
int xm, ym, zm;
shared_ptr<AABB> bb;
ClipChunk *clipChunk;
int id;
//public:
// vector<shared_ptr<TileEntity> > renderableTileEntities; // 4J - removed
private:
LevelRenderer::rteMap *globalRenderableTileEntities;
CRITICAL_SECTION *globalRenderableTileEntities_cs;
bool assigned;
public:
Chunk(Level *level, LevelRenderer::rteMap &globalRenderableTileEntities, CRITICAL_SECTION &globalRenderableTileEntities_cs, int x, int y, int z, ClipChunk *clipChunk);
Chunk();
void setPos(int x, int y, int z);
private:
void translateToPos();
public:
void makeCopyForRebuild(Chunk *source);
void rebuild();
#ifdef __PS3__
void rebuild_SPU();
#endif // __PS3__
float distanceToSqr(shared_ptr<Entity> player) const;
float squishedDistanceToSqr(shared_ptr<Entity> player);
void reset();
void _delete();
int getList(int layer);
void cull(Culler *culler);
void renderBB() ;
bool isEmpty();
void setDirty();
void clearDirty(); // 4J added
bool emptyFlagSet(int layer);
~Chunk();
};