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

Investigate how Context could be broken up #209

Open
17cupsofcoffee opened this issue Nov 2, 2020 · 2 comments
Open

Investigate how Context could be broken up #209

17cupsofcoffee opened this issue Nov 2, 2020 · 2 comments
Labels
API: Breaking Indicates that resolving the issue would be a breaking change. Area: Game Loop Issues relating to the main game loop. Type: Investigation Ongoing investigations and unanswered questions.

Comments

@17cupsofcoffee
Copy link
Owner

Summary:
Tetra using a giant Context struct for all of its internal state is a bit of a pain - it makes it impossible for the internals of the renderer to use the public graphics API (because you can't pass ctx and something stored in ctx into the same method), and it's tricky to break it up into something that people can use in a custom game loop.

For me, the main constraints on making a change like this would be:

  • No implicit state - I do not want to simply hide Context away in a static and pretend it's not there.
  • No added API complexity - functions should not take any more arguments than they already do, just more specific ones
  • No added boilerplate - users shouldn't have to write their own game loop from scratch/initialize individual chunks of the engine unless they specifically want/need to do so

I'm not sure if there's an API that meets those criteria! But it's worth thinking about.

@17cupsofcoffee 17cupsofcoffee added Type: Feature Request Improvements that could be made to the code/documentation. Area: Game Loop Issues relating to the main game loop. Type: Discussion API: Breaking Indicates that resolving the issue would be a breaking change. labels Nov 2, 2020
@17cupsofcoffee 17cupsofcoffee added Type: Investigation Ongoing investigations and unanswered questions. and removed Type: Discussion Type: Feature Request Improvements that could be made to the code/documentation. labels Dec 24, 2020
@17cupsofcoffee
Copy link
Owner Author

Been thinking about this some more, and I think I can articulate what's bugged me about my previous attempts at splitting up Context:

Say we broke up Context into Graphics/Window/Input structs. Cool, that feels more decoupled. But big chunks of a game are going to need access to more than one of those - heck, update could need all of them! So either Tetra or the end user has to pack them up in a struct to pass them around (in which case we're back to having a big Context object) or people have to pass down three arguments where they used to only pass one. I don't think that actually improves anything for end users; in fact if anything it makes their life harder...

@rghartmann
Copy link
Contributor

rghartmann commented Jun 10, 2021

Have you thought about attribute-based access? If an update() call needs the delta time, the user can request it by:

fn update(#[time] delta: Duration) -> tetra::Result {}

Otherwise, the function would have no parameters at all, and be called as is by Tetra as part of the loop.

I'm not sure if it'd complicate working with the State trait in any way, though (somewhat new to Rust myself). But I am taking inspiration from how Legion handles systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: Breaking Indicates that resolving the issue would be a breaking change. Area: Game Loop Issues relating to the main game loop. Type: Investigation Ongoing investigations and unanswered questions.
Projects
None yet
Development

No branches or pull requests

2 participants