Refactored out the main_loop so that it's not tightly coupled inside builder, and in the process found I was accidentally copying GUI and GameEngine because Builder wasn't using a &ref for them. Now they don't have a copy constructor to catch that.
This commit is contained in:
parent
a7c5de6ac3
commit
fff182b457
7 changed files with 27 additions and 34 deletions
13
gui.cpp
13
gui.cpp
|
@ -9,6 +9,7 @@
|
|||
#include <nlohmann/json.hpp>
|
||||
#include <fstream>
|
||||
#include "sfmlgui.hpp"
|
||||
#include "builder.hpp"
|
||||
|
||||
using std::string, std::vector;
|
||||
|
||||
|
@ -46,22 +47,24 @@ GUI::GUI() {
|
|||
building_sound.load(data, "building");
|
||||
}
|
||||
|
||||
void GUI::output(const string &msg) {
|
||||
lines.push_back(msg);
|
||||
void GUI::output(const string msg) {
|
||||
_lines.push_back(msg);
|
||||
}
|
||||
|
||||
int GUI::main_loop(GameEngine &game, std::function<bool()> runner) {
|
||||
int GUI::main_loop(GameEngine &game, Builder &builder) {
|
||||
auto gui = SFMLGui(game);
|
||||
|
||||
gui.startup();
|
||||
|
||||
while(gui.is_open()) {
|
||||
bool result = runner();
|
||||
builder.event(BuildEvent::GO);
|
||||
gui.handle_events();
|
||||
gui.update_entities();
|
||||
gui.update_log(lines);
|
||||
gui.update_log(_lines);
|
||||
}
|
||||
|
||||
builder.event(BuildEvent::QUIT);
|
||||
|
||||
gui.shutdown();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue