|
|
|
#pragma once
|
|
|
|
#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;
|
|
|
|
|
|
|
|
struct MatchResult {
|
|
|
|
bool match = false;
|
|
|
|
string file_name = "";
|
|
|
|
string lnumber = "";
|
|
|
|
string col = "";
|
|
|
|
string type = "";
|
|
|
|
string message = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
enum BuildState {
|
|
|
|
START, WAITING, BUILDING, DONE, FORKING, READING,
|
|
|
|
EXIT, ERROR
|
|
|
|
};
|
|
|
|
|
|
|
|
enum BuildEvent {
|
|
|
|
GO, QUIT, CRASH
|
|
|
|
};
|
|
|
|
|
|
|
|
class Builder : DeadSimpleFSM<BuildState, BuildEvent> {
|
|
|
|
// FOUND BUG: this was interesting, it got copied but the gui kept working until the refactor
|
|
|
|
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;
|
|
|
|
std::future<string> read_fut;
|
|
|
|
std::mutex fsm_mutex;
|
|
|
|
git_repository* repo = nullptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Builder(GUI &g, GameEngine &engine);
|
|
|
|
|
|
|
|
MatchResult parse_line(const string &line);
|
|
|
|
string read_line(FILE *build_out, bool &done_out);
|
|
|
|
FILE *start_command(string &build_cmd);
|
|
|
|
|
|
|
|
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(FORKING, forking, 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 forking(BuildEvent ev);
|
|
|
|
void reading(BuildEvent ev);
|
|
|
|
void error(BuildEvent ev);
|
|
|
|
void exit(BuildEvent ev);
|
|
|
|
};
|