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

Resources are global singletons stored in world.resources. Unlike components (which are per-entity), each resource type exists exactly once in the world.

Accessing Resources

All resources are accessed through world.resources:

#![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 Catalog

Time & Window

ResourceTypeDescription
windowWindowWindow handle, timing, and display info
secondary_windowsSecondaryWindowsMulti-window state
window.timingWindowTimingFrame timing: delta_time, frames_per_second, uptime_milliseconds

Input

ResourceTypeDescription
inputInputKeyboard, mouse, and gamepad state
input.keyboardKeyboardKey states, is_key_pressed(), just_pressed()
input.mouseMousePosition, delta, button state, scroll

Graphics

ResourceTypeDescription
graphicsGraphicsAll rendering settings
graphics.atmosphereAtmosphereSky type (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>Currently rendering camera
children_cacheHashMap<Entity, Vec<Entity>>Parent-to-children mapping
entity_namesHashMap<String, Entity>Name-to-entity lookup
transform_dirty_entitiesVec<Entity>Entities needing transform propagation

Simulation

ResourceTypeFeature
physicsPhysicsWorldphysics
audioAudioEngineaudio
navmeshNavMeshWorldalways

Communication

ResourceTypeDescription
event_busEventBusMessage passing between systems
command_queueVec<WorldCommand>Deferred GPU/scene operations
frame_scheduleFrameScheduleOrdered list of engine systems dispatched each frame

Platform

ResourceTypeFeature
xrXrResourcesopenxr
steamSteamResourcessteam
script_runtimeScriptRuntimescripting
sdf_worldSdfWorldsdf_sculpt

Conditional Resources

Some resources are only available when their feature flag is enabled:

#![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 require GPU access or must be deferred are queued as commands:

#![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 });
}

Commands are processed during the render phase when GPU access is available.