载入中...
搜索中...
未找到
eve::voxel::VoxelWorld类 参考

Sparse chunk map + visibility selection (frustum + distance + face orientation). Meshing is neighbor-aware (cross-chunk seam culling), parallel-capable and script-friendly via getVisible getters and raycast helpers. 更多...

#include <VoxelWorld.h>

Public 成员函数

 VoxelWorld ()=default
 
 ~VoxelWorld ()
 
 VoxelWorld (const CubeTypeRegistry &types)
 
ChunkgetOrCreateChunk (int cx, int cy, int cz)
 
ChunkgetChunk (int cx, int cy, int cz)
 
const ChunkgetChunk (int cx, int cy, int cz) const
 
bool hasChunk (int cx, int cy, int cz) const
 
void removeChunk (int cx, int cy, int cz)
 
void clear ()
 
int getChunkCount () const
 
int unloadChunksOutside (int centerX, int centerY, int centerZ, int radiusChunks)
 Streaming eviction: drop chunks whose center is farther than radiusChunks chunk units from (centerX, centerY, centerZ). Radius < 0 is a no-op. Returns the number of chunks evicted.
 
StreamStats streamAround (int centerX, int centerY, int centerZ, int radiusChunks, const std::function< void(Chunk &, int, int, int)> &generator={})
 Player-centered streaming: evict chunks outside radiusChunks, then allocate + fill + mesh missing chunks inside it (sphere, chunk coords). generator is called for each new chunk (chunk, cx, cy, cz); when null the stored terrain sampler (procgen::TerrainSampler) is used if enabled, otherwise chunks stay empty. Radius < 0 is a no-op.
 
void setTerrainParams (uint32_t seed, uint8_t top, uint8_t sub, uint8_t stone, float baseHeight, float amplitude, float scale)
 Configure the built-in terrain generator used by streamAround(). The sampling itself lives in procgen::TerrainSampler (deterministic Perlin fBm); voxel only adapts it to 32³ chunk filling.
 
void disableTerrain ()
 
bool terrainEnabled () const
 
int terrainHeightAt (int wx, int wz) const
 Terrain height (world blocks) at a column for the configured seed.
 
void serializeWorld (std::vector< uint8_t > &out) const
 Persistence: serialize every chunk (coords + raw voxels) into out. Format is portable little-endian: "EVVX" + version + count + per-chunk (cx, cy, cz, 32³ voxels). Meshes are rebuilt on demand after loading.
 
bool deserializeWorld (const uint8_t *data, size_t size)
 
data::ByteDatasaveWorld () const
 Script-facing wrappers around serialize/deserialize.
 
bool loadWorld (data::ByteData *bytes)
 
int remeshDirty (int maxThreads=0)
 Remesh every dirty chunk. Returns number remeshed.
 
void selectVisible (const float *viewProj16, float eyeX, float eyeY, float eyeZ, float viewRange, bool faceCull=true)
 Select chunks/faces to draw.
 
int getVisibleBatchCount () const
 
const DrawBatchgetVisibleBatch (int index) const
 
int getVisibleChunkCount () const
 Script accessors for the last selectVisible result.
 
void getVisibleChunkCoord (int index, int &cx, int &cy, int &cz) const
 
int getVisibleRectCount () const
 
void drawVisible (graphics::IGraphics3D *gfx, graphics::Texture *atlas, int tilesPerRow=16)
 Issue Graphics::drawVoxelFaceInstances for every visible batch. Requires begin3DFrame + setMesh3DViewProj already done.
 
uint8_t getVoxel (int wx, int wy, int wz) const
 World-space voxel get/set. Air (0) never allocates a chunk; a border edit also invalidates the adjacent chunk's mesh.
 
void setVoxel (int wx, int wy, int wz, uint8_t texId)
 
bool raycast (float ox, float oy, float oz, float dx, float dy, float dz, float maxDist, int &hitX, int &hitY, int &hitZ, int &prevX, int &prevY, int &prevZ, int &faceX, int &faceY, int &faceZ) const
 Voxel raycast (Amanatides & Woo DDA). Returns true when a solid voxel is found within maxDist world units along the ray; fills hit/prev coords and the face normal of the surface the ray entered. prev is the last air voxel before the hit (equals hit when the ray starts inside solid).
 
bool raycastScript (float ox, float oy, float oz, float dx, float dy, float dz, float maxDist)
 Script-facing raycast: stores the last result, returns hit/miss.
 
bool lastRaycastHit () const
 
int lastRaycastHitX () const
 
int lastRaycastHitY () const
 
int lastRaycastHitZ () const
 
int lastRaycastPrevX () const
 
int lastRaycastPrevY () const
 
int lastRaycastPrevZ () const
 
int lastRaycastFaceX () const
 
int lastRaycastFaceY () const
 
int lastRaycastFaceZ () const
 
void setVoxelByName (int wx, int wy, int wz, const std::string &name, int orientation=0)
 按方块名 + orientation(0..3) 设置体素;内部解析为具体类型 id 后写 Chunk。 未注册的名字按空气(0)处理。
 
std::string getCubeTypeName (int wx, int wy, int wz) const
 该体素所属方块类型名(未注册或空气返回空串)。
 
uint8_t getCubeTypeTex (int wx, int wy, int wz, const std::string &faceDir) const
 该体素在某面方向上的纹理 id(faceDir 如 "posX"/"+y"/"negZ")。
 
const CubeTypeRegistrycubeTypes () const
 本世界持有的方块类型注册表(副本)。
 

详细描述

Sparse chunk map + visibility selection (frustum + distance + face orientation). Meshing is neighbor-aware (cross-chunk seam culling), parallel-capable and script-friendly via getVisible getters and raycast helpers.

在文件 VoxelWorld.h52 行定义.

构造及析构函数说明

◆ VoxelWorld() [1/2]

eve::voxel::VoxelWorld::VoxelWorld ( )
default

◆ ~VoxelWorld()

eve::voxel::VoxelWorld::~VoxelWorld ( )
default

◆ VoxelWorld() [2/2]

eve::voxel::VoxelWorld::VoxelWorld ( const CubeTypeRegistry types)
inlineexplicit

在文件 VoxelWorld.h56 行定义.

成员函数说明

◆ clear()

void eve::voxel::VoxelWorld::clear ( )

在文件 VoxelWorld.cpp73 行定义.

被这些函数引用 deserializeWorld().

◆ cubeTypes()

const CubeTypeRegistry & eve::voxel::VoxelWorld::cubeTypes ( ) const
inline

本世界持有的方块类型注册表(副本)。

在文件 VoxelWorld.h182 行定义.

◆ deserializeWorld()

bool eve::voxel::VoxelWorld::deserializeWorld ( const uint8_t *  data,
size_t  size 
)

在文件 VoxelWorld.cpp200 行定义.

引用了 c, clear(), cx, cy, data, getOrCreateChunk(), eve::voxel::kChunkSize , 以及 p.

被这些函数引用 loadWorld().

◆ disableTerrain()

void eve::voxel::VoxelWorld::disableTerrain ( )
inline

在文件 VoxelWorld.h92 行定义.

◆ drawVisible()

void eve::voxel::VoxelWorld::drawVisible ( graphics::IGraphics3D gfx,
graphics::Texture atlas,
int  tilesPerRow = 16 
)

Issue Graphics::drawVoxelFaceInstances for every visible batch. Requires begin3DFrame + setMesh3DViewProj already done.

在文件 VoxelWorld.cpp353 行定义.

引用了 b, eve::graphics::IGraphics3D::drawVoxelFaceInstances() , 以及 eve::voxel::faceDirName().

◆ getChunk() [1/2]

Chunk * eve::voxel::VoxelWorld::getChunk ( int  cx,
int  cy,
int  cz 
)

在文件 VoxelWorld.cpp57 行定义.

引用了 cx , 以及 cy.

被这些函数引用 getVoxel() , 以及 setVoxel().

◆ getChunk() [2/2]

const Chunk * eve::voxel::VoxelWorld::getChunk ( int  cx,
int  cy,
int  cz 
) const

在文件 VoxelWorld.cpp62 行定义.

引用了 cx , 以及 cy.

◆ getChunkCount()

int eve::voxel::VoxelWorld::getChunkCount ( ) const
inline

在文件 VoxelWorld.h65 行定义.

◆ getCubeTypeName()

std::string eve::voxel::VoxelWorld::getCubeTypeName ( int  wx,
int  wy,
int  wz 
) const

该体素所属方块类型名(未注册或空气返回空串)。

在文件 VoxelWorld.cpp505 行定义.

引用了 eve::voxel::CubeTypeRegistry::find(), getVoxel() , 以及 eve::voxel::CubeType::name.

◆ getCubeTypeTex()

uint8_t eve::voxel::VoxelWorld::getCubeTypeTex ( int  wx,
int  wy,
int  wz,
const std::string &  faceDir 
) const

该体素在某面方向上的纹理 id(faceDir 如 "posX"/"+y"/"negZ")。

在文件 VoxelWorld.cpp510 行定义.

引用了 d, eve::voxel::faceDirFromName(), getVoxel() , 以及 eve::voxel::resolveFaceTex().

◆ getOrCreateChunk()

Chunk * eve::voxel::VoxelWorld::getOrCreateChunk ( int  cx,
int  cy,
int  cz 
)

在文件 VoxelWorld.cpp47 行定义.

引用了 cx, cy , 以及 eve::voxel::Chunk::get().

被这些函数引用 deserializeWorld(), setVoxel() , 以及 streamAround().

◆ getVisibleBatch()

const DrawBatch & eve::voxel::VoxelWorld::getVisibleBatch ( int  index) const
inline

在文件 VoxelWorld.h129 行定义.

◆ getVisibleBatchCount()

int eve::voxel::VoxelWorld::getVisibleBatchCount ( ) const
inline

在文件 VoxelWorld.h128 行定义.

◆ getVisibleChunkCoord()

void eve::voxel::VoxelWorld::getVisibleChunkCoord ( int  index,
int &  cx,
int &  cy,
int &  cz 
) const

在文件 VoxelWorld.cpp339 行定义.

引用了 cx , 以及 cy.

◆ getVisibleChunkCount()

int eve::voxel::VoxelWorld::getVisibleChunkCount ( ) const
inline

Script accessors for the last selectVisible result.

在文件 VoxelWorld.h132 行定义.

◆ getVisibleRectCount()

int eve::voxel::VoxelWorld::getVisibleRectCount ( ) const

在文件 VoxelWorld.cpp347 行定义.

引用了 b , 以及 n.

◆ getVoxel()

uint8_t eve::voxel::VoxelWorld::getVoxel ( int  wx,
int  wy,
int  wz 
) const

World-space voxel get/set. Air (0) never allocates a chunk; a border edit also invalidates the adjacent chunk's mesh.

在文件 VoxelWorld.cpp363 行定义.

引用了 c, cx, cy, getChunk() , 以及 eve::voxel::kChunkSize.

被这些函数引用 getCubeTypeName(), getCubeTypeTex() , 以及 raycast().

◆ hasChunk()

bool eve::voxel::VoxelWorld::hasChunk ( int  cx,
int  cy,
int  cz 
) const

在文件 VoxelWorld.cpp67 行定义.

引用了 cx , 以及 cy.

被这些函数引用 streamAround().

◆ lastRaycastFaceX()

int eve::voxel::VoxelWorld::lastRaycastFaceX ( ) const
inline

在文件 VoxelWorld.h166 行定义.

◆ lastRaycastFaceY()

int eve::voxel::VoxelWorld::lastRaycastFaceY ( ) const
inline

在文件 VoxelWorld.h167 行定义.

◆ lastRaycastFaceZ()

int eve::voxel::VoxelWorld::lastRaycastFaceZ ( ) const
inline

在文件 VoxelWorld.h168 行定义.

◆ lastRaycastHit()

bool eve::voxel::VoxelWorld::lastRaycastHit ( ) const
inline

在文件 VoxelWorld.h159 行定义.

◆ lastRaycastHitX()

int eve::voxel::VoxelWorld::lastRaycastHitX ( ) const
inline

在文件 VoxelWorld.h160 行定义.

◆ lastRaycastHitY()

int eve::voxel::VoxelWorld::lastRaycastHitY ( ) const
inline

在文件 VoxelWorld.h161 行定义.

◆ lastRaycastHitZ()

int eve::voxel::VoxelWorld::lastRaycastHitZ ( ) const
inline

在文件 VoxelWorld.h162 行定义.

◆ lastRaycastPrevX()

int eve::voxel::VoxelWorld::lastRaycastPrevX ( ) const
inline

在文件 VoxelWorld.h163 行定义.

◆ lastRaycastPrevY()

int eve::voxel::VoxelWorld::lastRaycastPrevY ( ) const
inline

在文件 VoxelWorld.h164 行定义.

◆ lastRaycastPrevZ()

int eve::voxel::VoxelWorld::lastRaycastPrevZ ( ) const
inline

在文件 VoxelWorld.h165 行定义.

◆ loadWorld()

bool eve::voxel::VoxelWorld::loadWorld ( data::ByteData bytes)

◆ raycast()

bool eve::voxel::VoxelWorld::raycast ( float  ox,
float  oy,
float  oz,
float  dx,
float  dy,
float  dz,
float  maxDist,
int &  hitX,
int &  hitY,
int &  hitZ,
int &  prevX,
int &  prevY,
int &  prevZ,
int &  faceX,
int &  faceY,
int &  faceZ 
) const

Voxel raycast (Amanatides & Woo DDA). Returns true when a solid voxel is found within maxDist world units along the ray; fills hit/prev coords and the face normal of the surface the ray entered. prev is the last air voxel before the hit (equals hit when the ray starts inside solid).

在文件 VoxelWorld.cpp413 行定义.

引用了 getVoxel().

被这些函数引用 raycastScript().

◆ raycastScript()

bool eve::voxel::VoxelWorld::raycastScript ( float  ox,
float  oy,
float  oz,
float  dx,
float  dy,
float  dz,
float  maxDist 
)

Script-facing raycast: stores the last result, returns hit/miss.

在文件 VoxelWorld.cpp490 行定义.

引用了 raycast().

◆ remeshDirty()

int eve::voxel::VoxelWorld::remeshDirty ( int  maxThreads = 0)

Remesh every dirty chunk. Returns number remeshed.

参数
maxThreads0 = auto (parallel up to an internal cap on desktop), 1 = serial, >1 = that many workers. Falls back to serial when threads are unavailable.

在文件 VoxelWorld.cpp233 行定义.

引用了 c, dirty , 以及 eve::thread::Job::wait().

被这些函数引用 streamAround().

◆ removeChunk()

void eve::voxel::VoxelWorld::removeChunk ( int  cx,
int  cy,
int  cz 
)

在文件 VoxelWorld.cpp71 行定义.

引用了 cx , 以及 cy.

◆ saveWorld()

data::ByteData * eve::voxel::VoxelWorld::saveWorld ( ) const

Script-facing wrappers around serialize/deserialize.

在文件 VoxelWorld.cpp222 行定义.

引用了 serializeWorld().

◆ selectVisible()

void eve::voxel::VoxelWorld::selectVisible ( const float *  viewProj16,
float  eyeX,
float  eyeY,
float  eyeZ,
float  viewRange,
bool  faceCull = true 
)

Select chunks/faces to draw.

参数
viewProj16column-major 4x4 RH+ZO view-projection (16 floats)
eyeX/Y/Zcamera eye world position
viewRangemax distance from eye to chunk center (world units; ≤0 disables)
faceCullwhen true, drop face buffers whose outward normal points away

在文件 VoxelWorld.cpp281 行定义.

引用了 eve::voxel::DrawBatch::ao, eve::voxel::DrawBatch::chunk, eve::voxel::DrawBatch::count, cx, cy, dir, eve::voxel::DrawBatch::dir, eve::voxel::Chunk::ensureMeshed(), eve::voxel::Chunk::faceAOPackedData(), eve::voxel::faceDirCount(), eve::voxel::faceNormal(), eve::voxel::Chunk::facePackedData(), eve::voxel::Chunk::faceRectCount(), eve::voxel::Frustum::fromViewProjColumnMajor(), frustum, eve::voxel::Chunk::get(), eve::voxel::DrawBatch::packed , 以及 eve::voxel::Chunk::worldAABB().

◆ serializeWorld()

void eve::voxel::VoxelWorld::serializeWorld ( std::vector< uint8_t > &  out) const

Persistence: serialize every chunk (coords + raw voxels) into out. Format is portable little-endian: "EVVX" + version + count + per-chunk (cx, cy, cz, 32³ voxels). Meshes are rebuilt on demand after loading.

在文件 VoxelWorld.cpp176 行定义.

引用了 cx, cy , 以及 eve::voxel::kChunkSize.

被这些函数引用 saveWorld().

◆ setTerrainParams()

void eve::voxel::VoxelWorld::setTerrainParams ( uint32_t  seed,
uint8_t  top,
uint8_t  sub,
uint8_t  stone,
float  baseHeight,
float  amplitude,
float  scale 
)

Configure the built-in terrain generator used by streamAround(). The sampling itself lives in procgen::TerrainSampler (deterministic Perlin fBm); voxel only adapts it to 32³ chunk filling.

在文件 VoxelWorld.cpp19 行定义.

引用了 scale , 以及 seed.

◆ setVoxel()

void eve::voxel::VoxelWorld::setVoxel ( int  wx,
int  wy,
int  wz,
uint8_t  texId 
)

在文件 VoxelWorld.cpp372 行定义.

引用了 c, cx, cy, getChunk(), getOrCreateChunk() , 以及 eve::voxel::kChunkSize.

被这些函数引用 setVoxelByName().

◆ setVoxelByName()

void eve::voxel::VoxelWorld::setVoxelByName ( int  wx,
int  wy,
int  wz,
const std::string &  name,
int  orientation = 0 
)

按方块名 + orientation(0..3) 设置体素;内部解析为具体类型 id 后写 Chunk。 未注册的名字按空气(0)处理。

在文件 VoxelWorld.cpp498 行定义.

引用了 eve::voxel::CubeTypeRegistry::find(), name, setVoxel() , 以及 eve::voxel::CubeTypeRegistry::variantId().

◆ streamAround()

StreamStats eve::voxel::VoxelWorld::streamAround ( int  centerX,
int  centerY,
int  centerZ,
int  radiusChunks,
const std::function< void(Chunk &, int, int, int)> &  generator = {} 
)

Player-centered streaming: evict chunks outside radiusChunks, then allocate + fill + mesh missing chunks inside it (sphere, chunk coords). generator is called for each new chunk (chunk, cx, cy, cz); when null the stored terrain sampler (procgen::TerrainSampler) is used if enabled, otherwise chunks stay empty. Radius < 0 is a no-op.

在文件 VoxelWorld.cpp101 行定义.

引用了 c, eve::voxel::StreamStats::created, eve::voxel::StreamStats::evicted, getOrCreateChunk(), h, hasChunk(), eve::voxel::kChunkSize, remeshDirty(), terrainHeightAt() , 以及 unloadChunksOutside().

◆ terrainEnabled()

bool eve::voxel::VoxelWorld::terrainEnabled ( ) const
inline

在文件 VoxelWorld.h93 行定义.

◆ terrainHeightAt()

int eve::voxel::VoxelWorld::terrainHeightAt ( int  wx,
int  wz 
) const

Terrain height (world blocks) at a column for the configured seed.

在文件 VoxelWorld.cpp35 行定义.

被这些函数引用 streamAround().

◆ unloadChunksOutside()

int eve::voxel::VoxelWorld::unloadChunksOutside ( int  centerX,
int  centerY,
int  centerZ,
int  radiusChunks 
)

Streaming eviction: drop chunks whose center is farther than radiusChunks chunk units from (centerX, centerY, centerZ). Radius < 0 is a no-op. Returns the number of chunks evicted.

在文件 VoxelWorld.cpp79 行定义.

引用了 cx , 以及 cy.

被这些函数引用 streamAround().


该类的文档由以下文件生成: