The UI is _finally_ responsive while the builder runs.

master
Zed A. Shaw 3 months ago
parent 5ae24d9b0a
commit 7c9bea81b2
  1. 2
      Makefile
  2. 42
      builder.cpp
  3. 7
      builder.hpp
  4. 19
      game_engine.hpp

@ -16,7 +16,7 @@ test:
meson test -C builddir --suite turings_tarpit
# make an install for real maybe copy dll and .exe to dir and zip?
install: build test
install: build
powershell "cp ./builddir/subprojects/libgit2-1.8.1/liblibgit2package.dll ."
powershell "cp ./builddir/subprojects/efsw/libefsw.dll ."
powershell "cp builddir/escape_turings_tarpit.exe ."

@ -120,27 +120,45 @@ void Builder::waiting(BuildEvent ev) {
game.start_round();
gui.building();
gui.output(format("CHANGES! Running build {}", build_cmd));
build_fut = std::async([&]() {
return start_command(build_cmd);
});
state(STARTING);
state(FORKING);
}
}
void Builder::starting(BuildEvent ev) {
std::future_status status = build_fut.wait_for(0ms);
void Builder::forking(BuildEvent ev) {
if(build_fut.valid()) {
std::future_status status = build_fut.wait_for(0ms);
if(status == std::future_status::ready) {
build_out = build_fut.get();
state(READING);
if(status == std::future_status::ready) {
build_out = build_fut.get();
state(READING);
} else {
state(FORKING);
}
} else {
state(STARTING);
build_fut = std::async([&]() {
return start_command(build_cmd);
});
state(FORKING);
}
}
void Builder::reading(BuildEvent ev) {
line = read_line(build_out, build_done);
state(BUILDING);
// BUG: too much copy-pasta so turn this into a class?
if(read_fut.valid()) {
std::future_status status = read_fut.wait_for(0ms);
if(status == std::future_status::ready) {
line = read_fut.get();
state(BUILDING);
} else {
state(READING);
}
} else {
read_fut = std::async([&]() {
return read_line(build_out, build_done);
});
}
}
void Builder::done(BuildEvent ev) {

@ -20,7 +20,7 @@ struct MatchResult {
};
enum BuildState {
START, WAITING, BUILDING, DONE, STARTING, READING,
START, WAITING, BUILDING, DONE, FORKING, READING,
EXIT, ERROR
};
@ -41,6 +41,7 @@ class Builder : DeadSimpleFSM<BuildState, BuildEvent> {
bool build_done = false;
string line = "";
std::future<FILE *> build_fut;
std::future<string> read_fut;
git_repository* repo = nullptr;
public:
@ -60,7 +61,7 @@ class Builder : DeadSimpleFSM<BuildState, BuildEvent> {
FSM_STATE(START, start, ev);
FSM_STATE(WAITING, waiting, ev);
FSM_STATE(DONE, done, ev);
FSM_STATE(STARTING, starting, ev);
FSM_STATE(FORKING, forking, ev);
FSM_STATE(READING, reading, ev);
FSM_STATE(EXIT, exit, ev);
FSM_STATE(ERROR, exit, ev);
@ -74,7 +75,7 @@ class Builder : DeadSimpleFSM<BuildState, BuildEvent> {
void start(BuildEvent ev);
void waiting(BuildEvent ev);
void done(BuildEvent ev);
void starting(BuildEvent ev);
void forking(BuildEvent ev);
void reading(BuildEvent ev);
void error(BuildEvent ev);
void exit(BuildEvent ev);

@ -40,22 +40,3 @@ class GameEngine {
void reset();
};
class Brainfucker {
public:
size_t dp = 0;
size_t ip = 0;
std::stringstream out;
std::array<int, 100> data = {};
string code = {};
Brainfucker();
void run(int count);
void set_code(string &code);
void reset();
void jump_backward();
void jump_forward();
string to_string();
};

Loading…
Cancel
Save