Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Resources

A resource is global state attached to the world, not to any entity. Delta time. The input snapshot for this frame. The list of loaded materials. The active camera. Each resource type exists exactly once in the world and lives on world.resources.

Systems read and write resources directly. There are no accessor functions, no per-resource fan-out. The freecs macro generates the Resources struct from the declaration block and gives every field public access.

#![allow(unused)]
fn main() {
fn run_systems(&mut self, world: &mut World) {
    let dt = world.resources.window.timing.delta_time;

    if world.resources.input.keyboard.is_key_pressed(KeyCode::Space) {
        self.jump();
    }

    world.resources.graphics.bloom_enabled = true;
}
}

Resource catalogue

Time and window

ResourceTypeDescription
windowWindowWindow handle, timing data, and display info
secondary_windowsSecondaryWindowsState for additional windows
window.timingWindowTimingdelta_time, frames_per_second, uptime_milliseconds

Input

ResourceTypeDescription
inputInputAggregated keyboard, mouse, and gamepad state
input.keyboardKeyboardPer-key state, is_key_pressed, just_pressed
input.mouseMousePosition, delta, button state, scroll

Graphics

ResourceTypeDescription
graphicsGraphicsAll rendering settings
graphics.atmosphereAtmosphereSky mode (None, Color, Sky)
graphics.bloom_enabledboolBloom toggle
graphics.ssao_enabledboolSSAO toggle
graphics.color_gradingColorGradingTonemapping, gamma, saturation, brightness, contrast

Caches

ResourceTypeDescription
mesh_cacheMeshCacheLoaded mesh data by name
material_registryMaterialRegistryRegistered materials
texture_cacheTextureCacheGPU textures
animation_cacheAnimationCacheAnimation clip data
prefab_cachePrefabCacheLoaded prefab templates
text_cacheTextCacheFont atlas and glyph data

Scene

ResourceTypeDescription
active_cameraOption<Entity>The camera the renderer pulls from
children_cacheHashMap<Entity, Vec<Entity>>Parent-to-children mapping
entity_namesHashMap<String, Entity>Name-to-entity lookup
transform_dirty_entitiesVec<Entity>Entities that need transform propagation

Simulation

ResourceTypeFeature
physicsPhysicsWorldphysics
audioAudioEngineaudio
navmeshNavMeshWorldalways

Communication

ResourceTypeDescription
event_busEventBusCross-system message queue
command_queueVec<WorldCommand>Deferred GPU and scene operations
frame_scheduleFrameScheduleOrdered list of engine systems dispatched each frame

Platform

ResourceTypeFeature
steamSteamResourcessteam

Feature-gated resources

Resources whose subsystems are optional only exist when the relevant feature flag is on. Guard access with cfg.

#![allow(unused)]
fn main() {
#[cfg(feature = "physics")]
{
    world.resources.physics.gravity = Vec3::new(0.0, -9.81, 0.0);
}

#[cfg(feature = "audio")]
{
    world.resources.audio.master_volume = 0.8;
}
}

World commands

Operations that need GPU access, or that have to happen at a defined point in the frame, go through world.queue_command. The command queue is a Vec<WorldCommand> that the renderer drains at frame setup.

#![allow(unused)]
fn main() {
world.queue_command(WorldCommand::LoadTexture {
    name: "my_texture".to_string(),
    rgba_data: texture_bytes,
    width: 256,
    height: 256,
});

world.queue_command(WorldCommand::DespawnRecursive { entity });
world.queue_command(WorldCommand::LoadHdrSkybox { hdr_data });
world.queue_command(WorldCommand::CaptureScreenshot { path: None });
}

The render-time commands are GPU uploads and screenshot captures. The ECS-time commands (DespawnRecursive, ReloadMaterial) are drained by the process_commands_system in the frame schedule. The full breakdown of immediate-versus-deferred operations is in Tags, Events, and Commands.