-
Notifications
You must be signed in to change notification settings - Fork 0
Engine Core
Core engine systems providing foundational functionality: window management, timing, logging, and multithreaded job processing.
File: src/engine/core/window.zig
Manages the application window lifecycle using SDL3 with Vulkan support and HiDPI awareness.
| Field | Type | Description |
|---|---|---|
window |
*c.SDL_Window |
SDL window handle |
is_vulkan |
bool |
Vulkan rendering mode (default: true) |
| Function | Description |
|---|---|
init(allocator, use_vulkan, width, height) |
Initialize SDL, create resizable Vulkan window |
setSize(width, height) |
Resize window (handles maximized/fullscreen states) |
deinit() |
Destroy window and quit SDL |
File: src/engine/core/time.zig
Provides frame timing, delta time calculation, fixed timestep for physics, and FPS tracking.
| Field | Type | Description |
|---|---|---|
delta_time |
f32 |
Seconds since last frame |
fixed_delta_time |
f32 |
Fixed timestep (default: 1/60s) |
accumulator |
f32 |
Accumulated time for fixed updates |
elapsed |
f32 |
Total elapsed seconds |
frame_count |
u64 |
Total frames rendered |
fps |
f32 |
Current FPS (updated per second) |
| Function | Description |
|---|---|
init() |
Initialize with current performance counter |
update() |
Calculate delta, update FPS (clamps to 0.25s max) |
shouldFixedUpdate() |
Returns true if fixed update should run |
getAlpha() |
Interpolation factor for smooth rendering |
time.update();
while (time.shouldFixedUpdate()) {
physics.fixedUpdate(time.fixed_delta_time);
}
render(time.getAlpha()); // Interpolate for smoothnessFile: src/engine/core/log.zig
Engine-wide logging with configurable severity levels.
pub const LogLevel = enum { trace, debug, info, warn, err, fatal };const log = @import("log.zig");
log.log.info("Player spawned at ({}, {})", .{x, z});
log.log.err("Failed to load chunk: {}", .{error});pub var log = Logger.init(.debug); // Default minimum levelFile: src/engine/core/job_system.zig
Thread-safe priority queue and worker pool for offloading expensive operations (world generation, mesh building).
pub const JobType = enum { generation, meshing };| Field | Type | Description |
|---|---|---|
type |
JobType |
Generation or meshing |
chunk_x, chunk_z
|
i32 |
Chunk coordinates |
job_token |
u32 |
Unique token for validation |
dist_sq |
i32 |
Priority (squared distance to player) |
Priority queue with distance-based ordering (closer chunks processed first).
| Method | Description |
|---|---|
init(allocator) |
Create queue |
push(job) |
Add job to queue |
pop() |
Blocking pop of highest priority job |
updatePlayerPos(cx, cz) |
Update priority calculations |
setPaused(paused) |
Pause/resume processing |
stop() |
Signal shutdown |
Spawns threads that consume from a JobQueue.
const pool = try WorkerPool.init(
allocator,
4, // Thread count
&job_queue,
context, // User context
processJobFn, // Callback
);
defer pool.deinit();When player moves significantly, jobs are re-sorted:
- Threshold: 64 pending jobs minimum
- Prevents constant re-sorting overhead
File: src/engine/core/ring_buffer.zig
Generic single-producer single-consumer FIFO queue with O(1) operations and auto-growth.
| Field | Type | Description |
|---|---|---|
buffer |
[]T |
Backing storage |
head |
usize |
Read position |
tail |
usize |
Write position |
len |
usize |
Current item count |
| Function | Description |
|---|---|
init(allocator, capacity) |
Create with initial capacity (min 64) |
push(item) |
Add to back (auto-grows if full) |
pop() |
Remove and return front (null if empty) |
peek() |
View front without removing |
clear() |
Clear without deallocation |
var queue = try RingBuffer(*ChunkData).init(allocator, 256);
defer queue.deinit();
queue.push(chunk_data);
while (queue.pop()) |data| {
uploadToGPU(data);
}File: src/engine/core/interfaces.zig
VTable-based interfaces for polymorphic behavior following SOLID principles.
| Interface | Methods | Purpose |
|---|---|---|
IUpdatable |
update(dt) |
Frame updates |
IRenderable |
render(view_proj) |
Rendering |
IInputHandler |
handleInput(event) |
Input processing |
IWidget |
draw(), handleInput(), getBounds()
|
UI widgets |
IChunkProvider |
generateChunk(x, z, blocks) |
World gen abstraction |
IMeshBuilder |
buildMesh(blocks, verts, indices) |
Mesh strategies |
pub const InputEvent = union(enum) {
key: KeyEvent,
mouse_motion: MouseMotionEvent,
mouse_button: MouseButtonEvent,
mouse_scroll: MouseScrollEvent,
window_resize: WindowResizeEvent,
quit: void,
};Comprehensive key definitions including:
- Letters:
athroughz - Numbers:
n0throughn9 - Arrows:
up,down,left,right - Modifiers:
shift,ctrl,alt - Function keys:
f1throughf12 - Special:
escape,space,tab,backspace,enter
βββββββββββββββ
β std lib β
ββββββββ¬βββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββ ββββββββββββ βββββββββββββββ
β log.zig β β time.zig β β ring_buffer β
ββββββ¬βββββ β (SDL3) β βββββββββββββββ
β ββββββββββββ
βΌ
ββββββββββββ βββββββββββββββ
βwindow.zigββββββββ c.zig β
β (SDL3) β β (SDL3/VK) β
ββββββββββββ βββββββββββββββ
β
βΌ
ββββββββββββββββ
β job_system β
β (chunk.zig) β
ββββββββββββββββ
- Architecture - System overview
- Rendering - Graphics systems
- World System - Chunk management
Source: src/engine/core/ | Last updated: January 2026