From 7c9bea81b23fdb21a98e07035997b3256fcc6bd5 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Tue, 10 Sep 2024 23:41:50 -0400 Subject: [PATCH] The UI is _finally_ responsive while the builder runs. --- Makefile | 2 +- builder.cpp | 42 ++++++++++++++++++++++++++++++------------ builder.hpp | 7 ++++--- game_engine.hpp | 19 ------------------- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 1040bdd..eeea2eb 100644 --- a/Makefile +++ b/Makefile @@ -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 ." diff --git a/builder.cpp b/builder.cpp index 94cdd2f..14da6fb 100644 --- a/builder.cpp +++ b/builder.cpp @@ -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) { diff --git a/builder.hpp b/builder.hpp index 482f460..7b3ae5c 100644 --- a/builder.hpp +++ b/builder.hpp @@ -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 { bool build_done = false; string line = ""; std::future build_fut; + std::future read_fut; git_repository* repo = nullptr; public: @@ -60,7 +61,7 @@ class Builder : DeadSimpleFSM { 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 { 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); diff --git a/game_engine.hpp b/game_engine.hpp index 6b63428..4fd04f6 100644 --- a/game_engine.hpp +++ b/game_engine.hpp @@ -40,22 +40,3 @@ class GameEngine { void reset(); }; - -class Brainfucker { - - public: - size_t dp = 0; - size_t ip = 0; - std::stringstream out; - std::array data = {}; - string code = {}; - - Brainfucker(); - - void run(int count); - void set_code(string &code); - void reset(); - void jump_backward(); - void jump_forward(); - string to_string(); -};