mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
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>
63 lines
2.2 KiB
C++
63 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include "LevelSource.h"
|
|
|
|
class Material;
|
|
class TileEntity;
|
|
class BiomeSource;
|
|
|
|
class Region : public LevelSource
|
|
{
|
|
private:
|
|
static constexpr int MAX_STACK_CHUNKS = 16; // 4x4 covers the common render-chunk case (r=1)
|
|
int xc1, zc1;
|
|
LevelChunk *flatChunks_stack[MAX_STACK_CHUNKS];
|
|
LevelChunk **flatChunks; // non-owning: points to flatChunks_stack or flatChunksHeap's buffer
|
|
std::unique_ptr<LevelChunk*[]> flatChunksHeap; // owns heap allocation for large regions
|
|
int chunksDimX, chunksDimZ;
|
|
Level *level;
|
|
bool allEmpty;
|
|
|
|
// AP - added a caching system for Chunk::rebuild to take advantage of
|
|
int xcCached, zcCached;
|
|
unsigned char *CachedTiles;
|
|
|
|
public:
|
|
Region(Level *level, int x1, int y1, int z1, int x2, int y2, int z2, int r);
|
|
virtual ~Region();
|
|
|
|
// Non-copyable/movable: flatChunks may point to internal stack buffer
|
|
Region(const Region&) = delete;
|
|
Region& operator=(const Region&) = delete;
|
|
Region(Region&&) = delete;
|
|
Region& operator=(Region&&) = delete;
|
|
|
|
bool isAllEmpty();
|
|
int getTile(int x, int y, int z);
|
|
shared_ptr<TileEntity> getTileEntity(int x, int y, int z);
|
|
float getBrightness(int x, int y, int z, int emitt);
|
|
float getBrightness(int x, int y, int z);
|
|
int getLightColor(int x, int y, int z, int emitt, int tileId = -1); // 4J - change brought forward from 1.8.2
|
|
int getRawBrightness(int x, int y, int z);
|
|
int getRawBrightness(int x, int y, int z, bool propagate);
|
|
int getData(int x, int y, int z);
|
|
Material *getMaterial(int x, int y, int z);
|
|
BiomeSource *getBiomeSource();
|
|
Biome *getBiome(int x, int z);
|
|
bool isSolidRenderTile(int x, int y, int z);
|
|
bool isSolidBlockingTile(int x, int y, int z);
|
|
bool isTopSolidBlocking(int x, int y, int z);
|
|
bool isEmptyTile(int x, int y, int z);
|
|
|
|
// 4J - changes brought forward from 1.8.2
|
|
int getBrightnessPropagate(LightLayer::variety layer, int x, int y, int z, int tileId); // 4J added tileId
|
|
int getBrightness(LightLayer::variety layer, int x, int y, int z);
|
|
|
|
int getMaxBuildHeight();
|
|
int getDirectSignal(int x, int y, int z, int dir);
|
|
|
|
LevelChunk* getLevelChunk(int x, int y, int z);
|
|
|
|
// AP - added a caching system for Chunk::rebuild to take advantage of
|
|
void setCachedTiles(unsigned char *tiles, int xc, int zc);
|
|
}; |