Project Structure
The source code is organized into distinct modules:Main Game Loop
The game follows a classic render loop pattern defined insource/main.c:52-283:
Game State
The global game state is defined insource/game/game_state.h:41-84:
Platform Abstraction
The platform layer (source/platform/) provides a consistent API across Wii and PC:
- Graphics:
gfx.hprovides rendering primitives, matrix operations, blending modes, and fog control - Input:
input.hhandles controller/keyboard input mapping - Threading:
thread.hprovides thread creation and channels for chunk mesher communication - Timing:
time.hoffers platform-independent time measurement - Textures:
texture.hhandles texture loading and management - Display Lists:
displaylist.hmanages GPU command buffers for efficient rendering
Threading Architecture
fCavEX uses a single background thread for chunk meshing to avoid blocking the main render loop:Memory Management
The codebase uses reference counting for chunks:Data Flow
- World Loading: Network layer reads region files → World creates chunks → Chunks added to world sections
- Block Modification: User input → Server logic →
world_set_block()→ Lighting update queued → Chunk marked for rebuild - Rendering: Camera frustum culling → BFS visibility test → Chunk mesher builds geometry → GPU renders display lists
- Entity Updates: Fixed 50ms tick → Physics integration → Collision detection → Rendering with interpolation
Key Dependencies
- cglm: OpenGL mathematics library for vectors and matrices
- M-lib: Generic container library (dictionaries, lists)
- cNBT: NBT format parsing for world data
- lodepng: PNG encoding for screenshots
Build System
The project uses CMake with platform-specific configurations:- Wii builds use DevkitPPC toolchain
- PC builds support both OpenGL and software rendering
- Makefile wrapper provides convenience commands