Module resource

Module resource 

Source
Expand description

Contains the code for the loading of all assets and ResourceId

All Resources have two types of loading a Blocking method and a Background method. On native platforms (Mac, Windows, Linux) The blocking method will just read from the file system and your resource will be available immediately. Background loads resources on a diffrent thread and it will be done when its done. On Wasm all things are loaded asynchronously so the Blocking method is faked by not updating or redrawing the game untill all blocking resources are loaded. There are no platform diffrences for background loading.

fn main() {
    let engine = mut EngineBuilder::new().build();
     
    let texture: ResourceId<Texture> = Texture::new(&mut engine, "path.png", LoadingOp::Blocking);
    // anything loaded in main will be ready on the first frame of the game
    let material = MaterialBuilder::new().add_texture(texture).build();

    let game = YourGame {
        textured_material: material,
    }
}

struct YourGame {
    textured_material: Material,
}

impl Game for YourGame {
    fn update(&mut self, engine: &mut Engine) {
        if engine.is_key_pressed(Key::A) {
            let texutre = Texture::new(engine, "path2.png", LoadingOp::Blocking);
            // render and update wont be called until after the texture finishes loading
        }
    }

    fn render<'pass, 'others>(&'others mut self, renderer: RenderInformation<'pass, 'others>) where 'others: 'pass {
        // do stuff
    }
}

Because of this stalling behavior it is recomended you do all your loading of assests in as large of chunks as possible.

Structs§

ResourceId
An Id for a specific type of resource used interally in the engine

Enums§

LoadingOp
This enum is used to control how resources are loaded. Background loading will load the resource on another thread and the resource will be ready when its ready. Blocking Loads on native platforms will read directly from the filesystem and the resource will be availble immediately. However on WASM the blocking behavoir is faked by pausing the game loop untill all blocking resources are done loading.