-
-
Notifications
You must be signed in to change notification settings - Fork 55
Description
So this may be a dumb question as it is very similar to #130 (I copied the title and tweaked it slightly even).
I'm having some trouble understanding Tasks, so this may just be stemming from that.
I have this code that does not work because Game::load receives an immutable window ref.
fn load(_window: &Window) -> Task<MyGame> {
let player = Image::load("assets/sara-atlas.png")
.map(|image| SpriteSheet::new(image, 5, 5))
.run(_window.gpu())
.expect("Error loading image.");
let world = World::new();
Task::succeed(|| MyGame {
player,
world,
})
}
The issue is, I want to load this image now then pass it into the MyGame object at the end of the load function. But Task::run function needs gpu and the Window::gpu function wants a mutable Window which load doesn't get.
In #103 you said it is by design that Game::update doesn't get a mutable window because only game logic should happen there and you don't want it to be changing the window itself, but I assume the same doesn't apply to Game::load, or am I wrong?
This is likely me just being confused about Tasks. When do Tasks actually get run? From the looks of it, it seems whatever calls Game::load runs the task(s), but if I have 100 images to load and I'm only supposed to return a Task<Game> from load how am I supposed to load all those images?
Also, down the road I want to have an AssetDatabase struct that holds lookup tables for all loaded assets (sprite sheets, dialogue trees, etc). And I want to load those assets after the main menu when the player selects one of the campaigns to play. That means it won't be happening in Game::load. But I also don't want some 'if' statement stuck in my Game::draw function being checked every tick. Should it go in Game::interact? (i've yet to mess with interact and input so I'm not sure)
Finally, thanks for making and maintaining this project. It's been very nice to work with so far.