Zith has native support for data-oriented programming through components (POD data), entities (component containers), and scenes (memory regions / arenas).
Components are plain-data component structs (see Type System). They are copy-by-default, C-compatible, and may contain pure transformation functions.
component Position { [x, y]: f32 }
component Velocity { dx: f32, dy: f32 }
component Health {
hp: u32,
max_hp: u32,
fn takeDamage(self: lend, damage: u32) {
self.hp = if (self.hp > damage) { self.hp - damage } else { 0 };
}
}
Component constraints (all must hold):
implement ComponentName as Trait).?unique Self, ?belong Self).A Scene is a memory region (arena / zone allocator). Entering a new scene replaces the previous one — resetting memory rather than stacking. A scene may specify a custom Allocator.
// Default allocator
scene GameLevel {
let terrain = @allocate(Terrain, levelData);
let entities = @allocate([_]Entity, entityList);
runLevel(terrain, entities);
// all memory freed here
}
// Custom bump allocator
scene GameFrame: BumpAllocator {
let scratch = @allocate([4096]u8);
renderFrame(scratch);
}
scene MainMenu {
entity MenuButton { /* ... */ }
entity TextDisplay { /* ... */ }
}
scene GameLevel {
entity Player { /* ... */ }
entity Enemy { /* ... */ }
entity Item { /* ... */ }
}
// Transition between scenes
transition(MainMenu, GameLevel); // old scene dies, new scene allocates
Use a scene per logical region for cache-friendly simulation logic and lifecycle-scoped allocation.
scene MainLevel { /* all main level entities and resources */ }
scene BossRoom { /* boss-specific entities */ }
// Memory is automatically reclaimed when exiting a scene
@ — compiler intrinsics / reflection: @allocate, @struct, @members, etc.# — variable/field attributes: #volatile, #thread_local, #wontRemain, etc.Related: Type System | Memory Management