Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should Task::new expect a result? #61

Closed
DanCardin opened this issue Jul 1, 2019 · 1 comment · Fixed by #66
Closed

Should Task::new expect a result? #61

DanCardin opened this issue Jul 1, 2019 · 1 comment · Fixed by #66
Labels
feature New feature or request
Milestone

Comments

@DanCardin
Copy link

DanCardin commented Jul 1, 2019

Task::new doesn't expect a Result, but Task::from_gpu does. I'm loading a non-image data file using serde_json; which I figured made sense to put inside a Task.

I'd initially started with Task::new because i don't need a Gpu but it doesn't expect a Result, and neither does Game.load, so I found myself needing to unwrap the Result<(), MyError> during the .map portion of task loading.

I eventually ended up using Task::using_gpu like so

Task::using_gpu(|_gpu| load_data().map_err(|e| coffee::Error::from(e)))

with a custom Error enum providing the Froms for i.e. io::Error, serde_json::Error, and coffee::Error (converting everything into a coffee::Error::IO variant because that seemed like the only potentially relevant category of error.


On a somewhat related note, I have a config file that I'm currently loading twice because it specifies the WindowSettings size, which it's not clear to me how to only load this file during the load Task process. Maybe this doesn't make sense, given that you need an initial display size to display e.g. the progress bar. but at the same time I didn't see a way to programmatically resize the display after load either.

@hecrj
Copy link
Owner

hecrj commented Jul 2, 2019

Yes. I think we should rename the current Task::new to Task::succeed and make it take a Clone type directly. We should probably add a Task::fail too. Elm does it this way.

Thank you for sharing your use case! It helps a lot to improve the engine :D And related to your use case, we will probably have a File::read or a FileSystem abstraction in the near future (maybe with serde integration through a feature?). Now that web support is coming (#63), it will help folks to keep files decoupled from the game environment.


On a somewhat related note, I have a config file that I'm currently loading twice because it specifies the WindowSettings size, which it's not clear to me how to only load this file during the load Task process.

I would personally store the video settings on its own file, separated from the rest of the game settings. However, we probably need a way to pass attributes to Game::load from Game::run. I think it would be a nice addition.

Maybe this doesn't make sense, given that you need an initial display size to display e.g. the progress bar. but at the same time I didn't see a way to programmatically resize the display after load either.

You are right, there is no way to resize the Window programmatically currently. I would like to know some use cases before implementing it! In this particular case, I think initializing the window with the correct size is the way to go.

@hecrj hecrj added the feature New feature or request label Jul 2, 2019
@hecrj hecrj closed this as completed in #66 Jul 3, 2019
@hecrj hecrj added this to the 0.4.0 milestone Jul 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants