From 64cc39eba1bd4b195c9c559ac13b860c1f7dd396 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 20 Jan 2022 15:58:08 -0500 Subject: [PATCH] Simplify main function by extracting game state setup code --- src/main.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index f7f49dd..4daa2bb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,12 +50,7 @@ macro_rules! register { } } -fn main() -> ::rltk::BError { - let context = ::rltk::RltkBuilder::simple(80, 60) - .unwrap() - .with_title("Roguelike Tutorial") - .build()?; - +fn init_state() -> State { let mut state = State::new(); register!( @@ -144,5 +139,14 @@ fn main() -> ::rltk::BError { state.generate_world_map(1, 0); - ::rltk::main_loop(context, state) + state +} + +fn main() -> ::rltk::BError { + let context = ::rltk::RltkBuilder::simple(80, 60) + .unwrap() + .with_title("Roguelike Tutorial") + .build()?; + + ::rltk::main_loop(context, init_state()) }