diff --git a/escape_turings_tarpit.cpp b/escape_turings_tarpit.cpp index a281b0c..54afc50 100644 --- a/escape_turings_tarpit.cpp +++ b/escape_turings_tarpit.cpp @@ -4,11 +4,19 @@ int main(int argc, char *argv[]) { - GUI gui; - GameEngine game{100}; + GUI gui; + GameEngine game{100}; + auto backend = SFMLBackend(game); + auto builder = Builder(gui, game); - auto builder = Builder(gui, game); - gui.main_loop(game, builder); + backend.startup(); - return 1; + while(backend.is_open()) { + builder.event(BuildEvent::GO); + gui.main_loop(backend); + } + + builder.event(BuildEvent::QUIT); + backend.shutdown(); + return 1; } diff --git a/gui.cpp b/gui.cpp index 0da84eb..6f8388f 100644 --- a/gui.cpp +++ b/gui.cpp @@ -31,22 +31,10 @@ void GUI::output(const string msg) { _lines.push_back(msg); } -int GUI::main_loop(GameEngine &game, Builder &builder) { - auto gui = SFMLBackend(game); - - gui.startup(); - - while(gui.is_open()) { - builder.event(BuildEvent::GO); - gui.handle_events(); - gui.update_entities(); - gui.update_log(_lines); - } - - builder.event(BuildEvent::QUIT); - - gui.shutdown(); - return EXIT_SUCCESS; +void GUI::main_loop(SFMLBackend &gui) { + gui.handle_events(); + gui.update_entities(); + gui.update_log(_lines); } void GUI::build_works() { diff --git a/gui.hpp b/gui.hpp index b54b558..acf4e24 100644 --- a/gui.hpp +++ b/gui.hpp @@ -20,12 +20,12 @@ class GUI { GUI(); - // FOUND BUG: adding this found that I was accidentally copying the gui, really it shouldn't be copyable + // prevent copy GUI(GUI &g) = delete; void output(const string msg); - int main_loop(GameEngine &game, Builder &builder); + void main_loop(SFMLBackend &backend); void build_works(); void build_failed(bool play_sound, const string &command); diff --git a/sfmlbackend.hpp b/sfmlbackend.hpp index 8c1496d..7ddbb3c 100644 --- a/sfmlbackend.hpp +++ b/sfmlbackend.hpp @@ -47,6 +47,9 @@ class SFMLBackend { public: SFMLBackend(GameEngine &g); + // prevent copy + SFMLBackend(SFMLBackend &g) = delete; + void startup(); bool is_open();