Completely purge the coroutine stuff from the project.
This commit is contained in:
parent
453c50c563
commit
b0c9fefa9b
3 changed files with 13 additions and 28 deletions
35
builder.cpp
35
builder.cpp
|
@ -2,7 +2,6 @@
|
||||||
#include "dbc.hpp"
|
#include "dbc.hpp"
|
||||||
#include "watcher.hpp"
|
#include "watcher.hpp"
|
||||||
#include "game_engine.hpp"
|
#include "game_engine.hpp"
|
||||||
#include "coro.hpp"
|
|
||||||
#include <chrono> // for milliseconds
|
#include <chrono> // for milliseconds
|
||||||
#include <efsw/efsw.hpp>
|
#include <efsw/efsw.hpp>
|
||||||
#include <fmt/chrono.h>
|
#include <fmt/chrono.h>
|
||||||
|
@ -27,7 +26,9 @@ using namespace nlohmann;
|
||||||
|
|
||||||
#define BUF_MAX 1024
|
#define BUF_MAX 1024
|
||||||
|
|
||||||
Builder::Builder(GUI &g, GameEngine &engine) : gui(g), game(engine) {
|
Builder::Builder(GUI &g, GameEngine &engine)
|
||||||
|
: gui(g), game(engine)
|
||||||
|
{
|
||||||
std::ifstream infile(".tarpit.json");
|
std::ifstream infile(".tarpit.json");
|
||||||
json config = json::parse(infile);
|
json config = json::parse(infile);
|
||||||
|
|
||||||
|
@ -35,13 +36,12 @@ Builder::Builder(GUI &g, GameEngine &engine) : gui(g), game(engine) {
|
||||||
config["build_cmd"].template get_to<string>(build_cmd);
|
config["build_cmd"].template get_to<string>(build_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
Task<unsigned> Builder::run_build() {
|
void Builder::run_build() {
|
||||||
std::regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*");
|
std::regex err_re("(.*?):([0-9]+):([0-9]+):\\s*(.*?):\\s*(.*)\n*");
|
||||||
|
|
||||||
char buffer[BUF_MAX]; // BUF_MAX is a define already?
|
char buffer[BUF_MAX]; // BUF_MAX is a define already?
|
||||||
std::ofstream stats_out;
|
std::ofstream stats_out;
|
||||||
|
|
||||||
co_await Pass{};
|
|
||||||
|
|
||||||
stats_out.open("stats.csv", std::ios::out | std::ios::app);
|
stats_out.open("stats.csv", std::ios::out | std::ios::app);
|
||||||
std::time_t tstamp = std::time(nullptr);
|
std::time_t tstamp = std::time(nullptr);
|
||||||
|
@ -49,18 +49,15 @@ Task<unsigned> Builder::run_build() {
|
||||||
dbc::check(stats_out.good(), "Error opening stats.csv file.");
|
dbc::check(stats_out.good(), "Error opening stats.csv file.");
|
||||||
dbc::pre("simple test", [&]() { return stats_out.good(); });
|
dbc::pre("simple test", [&]() { return stats_out.good(); });
|
||||||
|
|
||||||
co_yield 1;
|
|
||||||
|
|
||||||
// need to catch the error message when the command is bad
|
// need to catch the error message when the command is bad
|
||||||
FILE *build_out = popen(build_cmd.c_str(), "r");
|
FILE *build_out = popen(build_cmd.c_str(), "r");
|
||||||
dbc::check(build_out != nullptr, "Failed to run command.");
|
dbc::check(build_out != nullptr, "Failed to run command.");
|
||||||
|
|
||||||
co_yield 2;
|
|
||||||
|
|
||||||
game.start_round();
|
game.start_round();
|
||||||
|
|
||||||
while(fgets(buffer, BUF_MAX, build_out) != nullptr) {
|
while(fgets(buffer, BUF_MAX, build_out) != nullptr) {
|
||||||
co_yield 3;
|
|
||||||
string line(buffer); // yeah, that's probably a problem
|
string line(buffer); // yeah, that's probably a problem
|
||||||
|
|
||||||
std::smatch err;
|
std::smatch err;
|
||||||
|
@ -87,10 +84,8 @@ Task<unsigned> Builder::run_build() {
|
||||||
gui.you_died();
|
gui.you_died();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
co_yield 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
co_yield 3;
|
|
||||||
|
|
||||||
game.end_round();
|
game.end_round();
|
||||||
|
|
||||||
|
@ -104,8 +99,6 @@ Task<unsigned> Builder::run_build() {
|
||||||
|
|
||||||
stats_out.close();
|
stats_out.close();
|
||||||
dbc::post("a post test", [&]() { return !stats_out.is_open(); });
|
dbc::post("a post test", [&]() { return !stats_out.is_open(); });
|
||||||
|
|
||||||
co_return 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Builder::run() {
|
void Builder::run() {
|
||||||
|
@ -127,8 +120,6 @@ void Builder::run() {
|
||||||
gui.output(format("Watching directory {} for changes...", git_path));
|
gui.output(format("Watching directory {} for changes...", git_path));
|
||||||
efsw::WatchID wid = fileWatcher->addWatch(git_path, listener, true);
|
efsw::WatchID wid = fileWatcher->addWatch(git_path, listener, true);
|
||||||
|
|
||||||
auto build_task = run_build();
|
|
||||||
|
|
||||||
int rc = gui.main_loop(game, [&] {
|
int rc = gui.main_loop(game, [&] {
|
||||||
fileWatcher->watch();
|
fileWatcher->watch();
|
||||||
|
|
||||||
|
@ -136,19 +127,15 @@ void Builder::run() {
|
||||||
gui.building();
|
gui.building();
|
||||||
gui.output(format("CHANGES! Running build {}", build_cmd));
|
gui.output(format("CHANGES! Running build {}", build_cmd));
|
||||||
|
|
||||||
if(!build_task.done()) {
|
run_build();
|
||||||
unsigned point = build_task();
|
|
||||||
} else {
|
|
||||||
if(game.is_dead()) {
|
|
||||||
gui.output("!!!! YOU DIED! !!!! Learn to code luser.");
|
|
||||||
game.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
listener->reset_state();
|
if(game.is_dead()) {
|
||||||
gui.output("^^^^^^^^^^^ END ^^^^^^^^^^^");
|
gui.output("!!!! YOU DIED! !!!! Learn to code luser.");
|
||||||
build_task.destroy();
|
game.reset();
|
||||||
build_task = run_build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listener->reset_state();
|
||||||
|
gui.output("^^^^^^^^^^^ END ^^^^^^^^^^^");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "gui.hpp"
|
#include "gui.hpp"
|
||||||
#include "game_engine.hpp"
|
#include "game_engine.hpp"
|
||||||
#include "coro.hpp"
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
@ -15,7 +14,7 @@ class Builder {
|
||||||
|
|
||||||
Builder(GUI &g, GameEngine &engine);
|
Builder(GUI &g, GameEngine &engine);
|
||||||
|
|
||||||
Task<unsigned> run_build();
|
void run_build();
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,8 +32,7 @@ executable('escape_turings_tarpit',
|
||||||
'builder.cpp',
|
'builder.cpp',
|
||||||
'sfmlgui.cpp',
|
'sfmlgui.cpp',
|
||||||
'escape_turings_tarpit.cpp'],
|
'escape_turings_tarpit.cpp'],
|
||||||
dependencies: dependencies,
|
dependencies: dependencies)
|
||||||
cpp_args: '-fcoroutines')
|
|
||||||
|
|
||||||
executable('regtest', 'regtest.cpp',
|
executable('regtest', 'regtest.cpp',
|
||||||
dependencies: [fmt])
|
dependencies: [fmt])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue