World
Fixed-size 100×100×100 voxel world with save/load API. Engine-agnostic; shared by Simple3D and CNA.
Overview
World (namespace GalaxyEggbert::Worlds) is a pure C++ class with no
engine dependency. It organizes blocks into a chunksPerAxis³ grid of
Chunk objects (default 10, giving 1000 chunks / 100³ = 1,000,000 blocks).
Header: include/GalaxyEggbert/Worlds/World.hpp. Implementation: src/GalaxyEggbert/Worlds/World.cpp.
API
namespace GalaxyEggbert::Worlds {
class World final {
public:
explicit World(uint8_t chunksPerAxis = VoxelConfig::WorldChunksPerAxis);
uint8_t chunksPerAxis() const noexcept; // default 10
uint16_t blocksPerAxis() const noexcept; // default 100
size_t chunkCount() const noexcept; // default 1000
Block getBlock(uint16_t x, uint16_t y, uint16_t z) const;
void setBlock(uint16_t x, uint16_t y, uint16_t z, Block block);
const Chunk& chunk(uint8_t cx, uint8_t cy, uint8_t cz) const;
Chunk& chunk(uint8_t cx, uint8_t cy, uint8_t cz);
void saveToFile(const std::filesystem::path& path) const;
static World loadFromFile(const std::filesystem::path& path);
};
Usage Example
#include "GalaxyEggbert/Worlds/World.hpp"
using namespace GalaxyEggbert::Worlds;
World world;
world.setBlock(10, 0, 10, Block::make(BlockTypes::Ground));
world.setBlock(10, 1, 10, Block::make(BlockTypes::Wall));
world.saveToFile("level.vwr");
World loaded = World::loadFromFile("level.vwr");
Block b = loaded.getBlock(10, 0, 10);
assert(!b.isAir());
Used By
- GEWorldRuntime (CNA) — loads
.vwrand mobile-eggbert.txtdata into aWorld - GETerrainRenderer (CNA) — iterates every block to build terrain meshes
- GEBlupiController (CNA) — reads blocks for collision
- The equivalent Simple3D-side classes with the same names
Error Handling
getBlock/setBlock: throwstd::out_of_rangefor invalid coordinates.chunk(): throwsstd::out_of_rangefor invalid chunk coordinates.loadFromFile(): throwsstd::runtime_erroron file read failure or format mismatch.saveToFile(): throwsstd::runtime_erroron write failure.
Internal Storage
private:
uint8_t chunksPerAxis_;
std::vector<Chunk> chunks_; // size = chunksPerAxis³
Chunk grid is row-major: index = cx + cy*n + cz*n² where n = chunksPerAxis.
Block coordinates partition into chunk and local indices: chunkX = worldX / 10; localX = worldX % 10.
File Format
The .vwr binary format is fully documented in VWR Format.
Tests
Covered by tests/GalaxyEggbert/Worlds/WorldTests.cpp: get/set round-trips,
save/load round-trips, empty chunk skipping, boundary conditions.