Builder is now using the FSM I wrote. Still not as clean as I like but big improvement.

This commit is contained in:
Zed A. Shaw 2024-09-10 01:56:22 -04:00
parent dcf1a4020d
commit a7c5de6ac3
4 changed files with 176 additions and 129 deletions

View file

@ -2,6 +2,11 @@
#include "gui.hpp"
#include "game_engine.hpp"
#include <stdio.h>
#include "fsm.hpp"
#include <efsw/efsw.hpp>
#include <future>
#include <stdio.h>
#include "watcher.hpp"
using std::string;
@ -14,11 +19,28 @@ struct MatchResult {
string message = "";
};
class Builder {
enum BuildState {
START, WAITING, BUILDING, DONE, STARTING, READING,
EXIT, ERROR
};
enum BuildEvent {
GO, QUIT, CRASH
};
class Builder : DeadSimpleFSM<BuildState, BuildEvent> {
GUI gui;
GameEngine game;
string git_path = "NOT SET";
string build_cmd = "NOT SET";
efsw::FileWatcher* fileWatcher = NULL;
UpdateListener* listener = NULL;
efsw::WatchID wid;
FILE *build_out = NULL;
bool build_done = false;
string line = "";
std::future<FILE *> build_fut;
git_repository* repo = nullptr;
public:
@ -27,4 +49,34 @@ class Builder {
MatchResult parse_line(const string &line);
void run();
void event(BuildEvent ev) override {
try {
if(ev == QUIT) {
exit(ev);
}
switch(_state) {
FSM_STATE(BUILDING, building, ev);
FSM_STATE(START, start, ev);
FSM_STATE(WAITING, waiting, ev);
FSM_STATE(DONE, done, ev);
FSM_STATE(STARTING, starting, ev);
FSM_STATE(READING, reading, ev);
FSM_STATE(EXIT, exit, ev);
FSM_STATE(ERROR, exit, ev);
}
} catch(...) {
error(ev);
}
}
void building(BuildEvent ev);
void start(BuildEvent ev);
void waiting(BuildEvent ev);
void done(BuildEvent ev);
void starting(BuildEvent ev);
void reading(BuildEvent ev);
void error(BuildEvent ev);
void exit(BuildEvent ev);
};