darthdeus / comfy

Comfy is a fun 2D game engine built in Rust. It's designed to be opinionated, productive, and easy to use.

Home Page:https://comfyengine.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`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 from comfy have been imported (if the user adds use 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 to GameState (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:

fn engine(&mut self) -> &mut EngineState {

pub engine: EngineState,

pub fn new(engine: EngineState) -> Self {

run_early_update_stages(&mut c);

run_late_update_stages(&mut c);

impl GameLoop for ComfyGame {

define_main!($name, ComfyGame);

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 :)