How stcollier/samcraft works
Project Type and Overall Purpose
• Samcraft is a voxel engine built with OpenGL and C.
• It focuses on real-time 3D rendering (with HDR, shadows, etc.), efficient world generation (including infinite procedural worlds), physics, meshing algorithms, and a customizable client layer.
• The README and file structure show that the project covers both low-level engine functionality (graphics, physics, chunk/world management) and high-level client customization (via Lua configuration files in the client folder).
Main Components
a. Engine Core:
• Located in src/engine/core, this is responsible for setting up the window, camera, global engine states, shader management, and resource loading.
b. Engine Functionality / Modules:
• Engine Functionalities in src/engine/func include modules for frustum culling, meshing (greedy meshing), physics, player management, and raycasting.
• As “Game Logic / Physics” modules connected to the core.
c. Graphics (GFX) System:
• Found in src/engine/gfx, this part manages rendering pipelines: drawing block overlays, images, lights, skyboxes, sprites, text, UI elements, and postprocessing effects like HDR.
• As the Graphics Pipeline, linking the shader components (backed by the shaders in res/shaders) with textures (from res/textures) and fonts (from res/fonts).
d. Utility Modules:
• Under src/engine/util there are common utilities, thread pooling, timer functions, and other helper modules.
e. World and World Generation:
• In src/world, you have modules for block manipulation, chunk creation, world maintenance, and procedural world generation.
• This as the “World Module” that integrates with both the engine core and the physics/meshing systems to generate and render worlds dynamically.
f. Client Customization:
• The client folder contains Lua scripts and configuration files defining custom blocks such as cobblestone, dirt, grass, etc.
• This should be depicted as an external or configurable layer feeding into the engine’s block/world systems, enabling runtime customization.
g. External Libraries and Dependencies:
• The lib folder contains numerous libraries:
• cglm for vector/matrix math, used across core and graphics.
• glad – for OpenGL function loading.
• Shader dependencies, noise (osnoise) for procedural aspects, stb for image loading, and uthash for data management.
h. Resources:
• The res folder holds shaders, textures, and fonts needed for rendering.
• This as a resource pool that interacts with the graphics subsystem to load and manage visual assets.
Relationships and Data Flow
• That the main entry point (src/main.c) initializes the Engine Core, which in turn sets up the Game Loop.
• Interaction between the World Module and Client Customization: client-specified blocks inform the world generation and rendering modules.
• That resource files (shaders and textures) load into the Graphics Pipeline.
Architectural Patterns/Design Principles
• The project is modular with clearly separated concerns:
– Core initialization and management.
– Modular engine functionalities for specific tasks (physics, rendering, meshing).
– A decoupled resource pipeline.
– A client customization layer that permits extensions via Lua configurations.
• This modular design can be loosely compared to an MVC pattern where the “model” relates to the world data, “view” is the graphics/subsystems, and “controller” is provided by engine functionalities and game loop logic.
• Separation of concerns and a tight coupling between low-level systems (window, camera, shaders) and high-level gameplay systems (world, physics, custom blocks).
• Integration point for client configurations (Lua scripts and client/config.lua) and indicate how these drive customizable behavior in the engine.
• Don’t shy away from detailing inner dependencies (e.g., resources -> shaders and textures -> graphics module; engine core -> physics, frustum, and mesher modules).