GameEngine is now a state machine so I can push its design further and keep it solid.

This commit is contained in:
Zed A. Shaw 2024-09-12 00:34:41 -04:00
parent 1c89afaee2
commit 9e6c05eccd
5 changed files with 56 additions and 56 deletions

View file

@ -76,20 +76,22 @@ void Builder::building(BuildEvent ev) {
int rc = pclose(build_out);
if(rc == 0) {
game.event(GameEvent::BUILD_SUCCESS);
gui.build_works();
} else {
// BUG: make it not play two sounds
game.event(GameEvent::BUILD_FAILED);
gui.build_failed(true, build_cmd);
}
build_out = NULL;
game.event(GameEvent::BUILD_DONE);
state(DONE);
} else {
auto m = parse_line(line);
if(m.match) {
gui.output(format("HIT WITH {} @ {}:{}:{} {}", m.type, m.file_name, m.lnumber, m.col, m.message));
game.hit(m.type);
game.event(GameEvent::HIT);
}
state(READING);
}
@ -117,7 +119,7 @@ void Builder::start(BuildEvent ev) {
void Builder::waiting(BuildEvent ev) {
if(listener->changes) {
game.start_round();
game.event(GameEvent::BUILD_START);
gui.building();
gui.output(format("CHANGES! Running build {}", build_cmd));
state(FORKING);
@ -162,11 +164,8 @@ void Builder::reading(BuildEvent ev) {
}
void Builder::done(BuildEvent ev) {
game.end_round();
if(game.is_dead()) {
gui.you_died();
game.reset();
}
listener->reset_state();