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) | |
| Chunk * | getOrCreateChunk (int cx, int cy, int cz) |
| Chunk * | getChunk (int cx, int cy, int cz) |
| const Chunk * | getChunk (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::ByteData * | saveWorld () 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 DrawBatch & | getVisibleBatch (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 CubeTypeRegistry & | cubeTypes () 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.h 第 52 行定义.
构造及析构函数说明
◆ VoxelWorld() [1/2]
|
default |
◆ ~VoxelWorld()
|
default |
◆ VoxelWorld() [2/2]
|
inlineexplicit |
在文件 VoxelWorld.h 第 56 行定义.
成员函数说明
◆ clear()
| void eve::voxel::VoxelWorld::clear | ( | ) |
在文件 VoxelWorld.cpp 第 73 行定义.
被这些函数引用 deserializeWorld().
◆ cubeTypes()
|
inline |
本世界持有的方块类型注册表(副本)。
在文件 VoxelWorld.h 第 182 行定义.
◆ deserializeWorld()
| bool eve::voxel::VoxelWorld::deserializeWorld | ( | const uint8_t * | data, |
| size_t | size | ||
| ) |
在文件 VoxelWorld.cpp 第 200 行定义.
引用了 c, clear(), cx, cy, data, getOrCreateChunk(), eve::voxel::kChunkSize , 以及 p.
被这些函数引用 loadWorld().
◆ disableTerrain()
|
inline |
在文件 VoxelWorld.h 第 92 行定义.
◆ 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.cpp 第 353 行定义.
引用了 b, eve::graphics::IGraphics3D::drawVoxelFaceInstances() , 以及 eve::voxel::faceDirName().
◆ getChunk() [1/2]
| Chunk * eve::voxel::VoxelWorld::getChunk | ( | int | cx, |
| int | cy, | ||
| int | cz | ||
| ) |
◆ getChunk() [2/2]
| const Chunk * eve::voxel::VoxelWorld::getChunk | ( | int | cx, |
| int | cy, | ||
| int | cz | ||
| ) | const |
在文件 VoxelWorld.cpp 第 62 行定义.
◆ getChunkCount()
|
inline |
在文件 VoxelWorld.h 第 65 行定义.
◆ getCubeTypeName()
| std::string eve::voxel::VoxelWorld::getCubeTypeName | ( | int | wx, |
| int | wy, | ||
| int | wz | ||
| ) | const |
该体素所属方块类型名(未注册或空气返回空串)。
在文件 VoxelWorld.cpp 第 505 行定义.
引用了 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.cpp 第 510 行定义.
引用了 d, eve::voxel::faceDirFromName(), getVoxel() , 以及 eve::voxel::resolveFaceTex().
◆ getOrCreateChunk()
| Chunk * eve::voxel::VoxelWorld::getOrCreateChunk | ( | int | cx, |
| int | cy, | ||
| int | cz | ||
| ) |
在文件 VoxelWorld.cpp 第 47 行定义.
引用了 cx, cy , 以及 eve::voxel::Chunk::get().
被这些函数引用 deserializeWorld(), setVoxel() , 以及 streamAround().
◆ getVisibleBatch()
|
inline |
在文件 VoxelWorld.h 第 129 行定义.
◆ getVisibleBatchCount()
|
inline |
在文件 VoxelWorld.h 第 128 行定义.
◆ getVisibleChunkCoord()
| void eve::voxel::VoxelWorld::getVisibleChunkCoord | ( | int | index, |
| int & | cx, | ||
| int & | cy, | ||
| int & | cz | ||
| ) | const |
在文件 VoxelWorld.cpp 第 339 行定义.
◆ getVisibleChunkCount()
|
inline |
Script accessors for the last selectVisible result.
在文件 VoxelWorld.h 第 132 行定义.
◆ getVisibleRectCount()
| int eve::voxel::VoxelWorld::getVisibleRectCount | ( | ) | const |
在文件 VoxelWorld.cpp 第 347 行定义.
◆ 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.cpp 第 363 行定义.
引用了 c, cx, cy, getChunk() , 以及 eve::voxel::kChunkSize.
被这些函数引用 getCubeTypeName(), getCubeTypeTex() , 以及 raycast().
◆ hasChunk()
| bool eve::voxel::VoxelWorld::hasChunk | ( | int | cx, |
| int | cy, | ||
| int | cz | ||
| ) | const |
◆ lastRaycastFaceX()
|
inline |
在文件 VoxelWorld.h 第 166 行定义.
◆ lastRaycastFaceY()
|
inline |
在文件 VoxelWorld.h 第 167 行定义.
◆ lastRaycastFaceZ()
|
inline |
在文件 VoxelWorld.h 第 168 行定义.
◆ lastRaycastHit()
|
inline |
在文件 VoxelWorld.h 第 159 行定义.
◆ lastRaycastHitX()
|
inline |
在文件 VoxelWorld.h 第 160 行定义.
◆ lastRaycastHitY()
|
inline |
在文件 VoxelWorld.h 第 161 行定义.
◆ lastRaycastHitZ()
|
inline |
在文件 VoxelWorld.h 第 162 行定义.
◆ lastRaycastPrevX()
|
inline |
在文件 VoxelWorld.h 第 163 行定义.
◆ lastRaycastPrevY()
|
inline |
在文件 VoxelWorld.h 第 164 行定义.
◆ lastRaycastPrevZ()
|
inline |
在文件 VoxelWorld.h 第 165 行定义.
◆ loadWorld()
| bool eve::voxel::VoxelWorld::loadWorld | ( | data::ByteData * | bytes | ) |
在文件 VoxelWorld.cpp 第 228 行定义.
引用了 deserializeWorld(), eve::data::ByteData::getData() , 以及 eve::data::ByteData::getSize().
◆ 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.cpp 第 413 行定义.
引用了 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.cpp 第 490 行定义.
引用了 raycast().
◆ remeshDirty()
| int eve::voxel::VoxelWorld::remeshDirty | ( | int | maxThreads = 0 | ) |
Remesh every dirty chunk. Returns number remeshed.
- 参数
-
maxThreads 0 = auto (parallel up to an internal cap on desktop), 1 = serial, >1 = that many workers. Falls back to serial when threads are unavailable.
在文件 VoxelWorld.cpp 第 233 行定义.
引用了 c, dirty , 以及 eve::thread::Job::wait().
被这些函数引用 streamAround().
◆ removeChunk()
| void eve::voxel::VoxelWorld::removeChunk | ( | int | cx, |
| int | cy, | ||
| int | cz | ||
| ) |
在文件 VoxelWorld.cpp 第 71 行定义.
◆ saveWorld()
| data::ByteData * eve::voxel::VoxelWorld::saveWorld | ( | ) | const |
Script-facing wrappers around serialize/deserialize.
在文件 VoxelWorld.cpp 第 222 行定义.
引用了 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.
- 参数
-
viewProj16 column-major 4x4 RH+ZO view-projection (16 floats) eyeX/Y/Z camera eye world position viewRange max distance from eye to chunk center (world units; ≤0 disables) faceCull when true, drop face buffers whose outward normal points away
在文件 VoxelWorld.cpp 第 281 行定义.
引用了 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.cpp 第 176 行定义.
引用了 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.cpp 第 19 行定义.
◆ setVoxel()
| void eve::voxel::VoxelWorld::setVoxel | ( | int | wx, |
| int | wy, | ||
| int | wz, | ||
| uint8_t | texId | ||
| ) |
在文件 VoxelWorld.cpp 第 372 行定义.
引用了 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.cpp 第 498 行定义.
引用了 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.cpp 第 101 行定义.
引用了 c, eve::voxel::StreamStats::created, eve::voxel::StreamStats::evicted, getOrCreateChunk(), h, hasChunk(), eve::voxel::kChunkSize, remeshDirty(), terrainHeightAt() , 以及 unloadChunksOutside().
◆ terrainEnabled()
|
inline |
在文件 VoxelWorld.h 第 93 行定义.
◆ terrainHeightAt()
| int eve::voxel::VoxelWorld::terrainHeightAt | ( | int | wx, |
| int | wz | ||
| ) | const |
Terrain height (world blocks) at a column for the configured seed.
在文件 VoxelWorld.cpp 第 35 行定义.
被这些函数引用 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.cpp 第 79 行定义.
被这些函数引用 streamAround().
该类的文档由以下文件生成:
- src/modules/voxel/VoxelWorld.h
- src/modules/voxel/VoxelWorld.cpp