Moved the main event loop out of GUI so it's not so tightly coupled to everything else.
This commit is contained in:
parent
c0ad0c8d23
commit
5ae24d9b0a
4 changed files with 22 additions and 23 deletions
|
@ -4,11 +4,19 @@
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
GUI gui;
|
GUI gui;
|
||||||
GameEngine game{100};
|
GameEngine game{100};
|
||||||
|
auto backend = SFMLBackend(game);
|
||||||
|
auto builder = Builder(gui, game);
|
||||||
|
|
||||||
auto builder = Builder(gui, game);
|
backend.startup();
|
||||||
gui.main_loop(game, builder);
|
|
||||||
|
|
||||||
return 1;
|
while(backend.is_open()) {
|
||||||
|
builder.event(BuildEvent::GO);
|
||||||
|
gui.main_loop(backend);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.event(BuildEvent::QUIT);
|
||||||
|
backend.shutdown();
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
20
gui.cpp
20
gui.cpp
|
@ -31,22 +31,10 @@ void GUI::output(const string msg) {
|
||||||
_lines.push_back(msg);
|
_lines.push_back(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GUI::main_loop(GameEngine &game, Builder &builder) {
|
void GUI::main_loop(SFMLBackend &gui) {
|
||||||
auto gui = SFMLBackend(game);
|
gui.handle_events();
|
||||||
|
gui.update_entities();
|
||||||
gui.startup();
|
gui.update_log(_lines);
|
||||||
|
|
||||||
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::build_works() {
|
void GUI::build_works() {
|
||||||
|
|
4
gui.hpp
4
gui.hpp
|
@ -20,12 +20,12 @@ class GUI {
|
||||||
|
|
||||||
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;
|
GUI(GUI &g) = delete;
|
||||||
|
|
||||||
void output(const string msg);
|
void output(const string msg);
|
||||||
|
|
||||||
int main_loop(GameEngine &game, Builder &builder);
|
void main_loop(SFMLBackend &backend);
|
||||||
|
|
||||||
void build_works();
|
void build_works();
|
||||||
void build_failed(bool play_sound, const string &command);
|
void build_failed(bool play_sound, const string &command);
|
||||||
|
|
|
@ -47,6 +47,9 @@ class SFMLBackend {
|
||||||
public:
|
public:
|
||||||
SFMLBackend(GameEngine &g);
|
SFMLBackend(GameEngine &g);
|
||||||
|
|
||||||
|
// prevent copy
|
||||||
|
SFMLBackend(SFMLBackend &g) = delete;
|
||||||
|
|
||||||
void startup();
|
void startup();
|
||||||
|
|
||||||
bool is_open();
|
bool is_open();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue