`comfy_game!` papercuts
aochagavia opened this issue · comments
On v0.12, I would expect the following code to compile, but it doesn't:
use comfy::{comfy_game, EngineContext};
comfy_game!("Test", MyContext, MyGameState, make_context, setup, update);
fn make_context(state: &mut MyGameState, engine: &mut EngineContext<'_>) -> MyContext { MyContext }
fn setup(_: &mut MyContext) {}
fn update(_: &mut MyContext) {}
struct MyContext;
struct MyGameState;
Causes and possible solutions
The program fails to compile because:
- The
comfy_game!
macro assumes that some functions fromcomfy
have been imported (if the user addsuse comfy::*
to the source file, this problem goes away). IMO it would be cleaner to use absolute paths in the macro, so the user doesn't have to care about imports. - The
comfy_game!
macro still has a hardcoded reference toGameState
(this seems to have been resolved on master)
I believe both of these problems have been resolved with #7; can you retry with a version that includes it? I tried to catch all of the unqualified imports so let me know if I missed any.
Whoops, identified a few more sites where this is still broken:
Line 169 in 5a3c893
Line 133 in 5a3c893
Line 140 in 5a3c893
Line 149 in 5a3c893
Line 164 in 5a3c893
Line 145 in 5a3c893
Line 130 in 5a3c893
I'm about to get on a plane so I don't have time to fix these now, but all of these should be fixable by prefixing the import with $crate::
.
This should be now fixed on master, including a bunch more of these missing.
Note that the example needs a MyGameState::new(...)
, so a small change to make it compile
use comfy::{comfy_game, EngineContext};
comfy_game!("Test", MyContext, MyGameState, make_context, setup, update);
fn make_context(state: &mut MyGameState, engine: &mut EngineContext<'_>) -> MyContext { MyContext }
fn setup(_: &mut MyContext) {}
fn update(_: &mut MyContext) {}
struct MyContext;
struct MyGameState;
impl MyGameState {
fn new(_c: &EngineContext) -> Self { Self }
}
But that is independent of the reported issues, feel free to reopen if there are more problems, but as the example is it compiles for me on master :)