Expand description

Contains the code for the loading of all assets and ResourceId

In order for bottomless-pit to run on both desktop and web enviorments file reading has to be done asynchronously. When you call Texture::new, Shader::new, Font::new, or Engine::create_resource you are given a handle to the resource and not the resoruce directly. Since resources are loaded asynchronously it will not be imeaditly availble. In order to have the resource be available to use as soon as possible the engine halts while waiting for the resource. Game::update will not be called and Game::render will not be called either.

fn main() {
    let engine = mut EngineBuilder::new().build();
     
    let texture: ResourceId<Texture> = Texture::new(&mut engine, "path.png");
    // 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");
            // 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§

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