Created
March 1, 2014 07:03
-
-
Save lilyball/9286311 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct RenderWindow; | |
pub struct Engine<'a> { | |
priv caption: &'static str, | |
priv window: RenderWindow, | |
priv key_actions: 'a|| | |
} | |
pub struct EngineLoop<'a> { | |
priv game_loop: 'a|&mut Engine|, | |
priv event_loop: 'a|&mut Engine| | |
} | |
pub struct GameEngine<'a> { | |
priv engine: Engine<'a>, | |
priv loops: EngineLoop<'a> | |
} | |
impl<'a> GameEngine<'a> { | |
pub fn new() -> GameEngine { | |
GameEngine { | |
engine: Engine { caption: "test", window: RenderWindow, key_actions: ||{}}, | |
loops: EngineLoop { game_loop: |_|{}, event_loop: |_|{}} | |
} | |
} | |
pub fn start(&mut self) { | |
let GameEngine{ ref mut engine, ref mut loops } = *self; | |
loops.event_loop = |engine| { | |
loop { | |
// access window via engine.window, or somesuch | |
match "placeholder" { | |
"placeholder" => (engine.key_actions)(), | |
_ => {} | |
} | |
} | |
}; | |
loop { //another placeholder | |
(loops.event_loop)(&mut *engine); | |
(loops.game_loop)(&mut *engine); | |
} | |
} | |
pub fn set_key_actions(&mut self, key_actions: 'a||) { | |
self.engine.key_actions = key_actions | |
} | |
} | |
fn main() { | |
let mut engine = GameEngine::new(); | |
engine.set_key_actions(|| println!("foo")); | |
engine.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment