diff --git a/.vimrc_proj b/.vimrc_proj index 2b745b4..d58d328 100644 --- a/.vimrc_proj +++ b/.vimrc_proj @@ -1 +1 @@ -set makeprg=meson\ compile\ -C\ . +set makeprg=meson\ compile\ -j\ 4\ -C\ . diff --git a/Makefile b/Makefile index 834f879..67e7ffe 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ all: build test build: - meson compile -C builddir + meson compile -j 4 -C builddir test: meson test -C builddir --suite turings_tarpit diff --git a/builder.cpp b/builder.cpp index 835afde..e2390b0 100644 --- a/builder.cpp +++ b/builder.cpp @@ -56,6 +56,8 @@ void Builder::run_build() { while(fgets(buffer, BUF_MAX, build_out) != nullptr) { string line(buffer); // yeah, that's probably a problem + cerr << buffer; + smatch err; bool match = regex_match(line, err, err_re); diff --git a/corotest.cpp b/corotest.cpp new file mode 100644 index 0000000..f1c294a --- /dev/null +++ b/corotest.cpp @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace std::chrono; + +template +struct Task { + struct promise_type; + + using handle_type = std::coroutine_handle; + + struct promise_type { + T value_; + std::exception_ptr exception_; + + Task get_return_object() { + return Task(handle_type::from_promise(*this)); + } + + std::suspend_always initial_suspend() { + return {}; + } + + std::suspend_always final_suspend() noexcept { + return {}; + } + + void unhandled_exception() { + exception_ = std::current_exception(); + } + + template From> // C++20 concept + void return_value(From &&from) { + value_ = std::forward(from); + } + + template From> // C++20 concept + std::suspend_always yield_value(From &&from) { + value_ = std::forward(from); + return {}; + } + + void return_void() {} + }; + + handle_type h_; + + Task() { + } + + Task(handle_type h) : h_(h) { + } + + Task(const Task &t) : h_(t.h_) { + } + + void destroy() { + h_.destroy(); + } + + T operator()() { + assert(!h_.done()); + call(); + return std::move(h_.promise().value_); + } + + bool done() { + return h_.done(); + } + + private: + + void call() { + h_(); + + if (h_.promise().exception_) + std::rethrow_exception(h_.promise().exception_); + } +}; + +#define pass() co_await std::suspend_always{} + +Task task_test() +{ + pass(); + + for (unsigned i = 0; i < 3; ++i) + co_yield i; + + co_return 1000; +} + +int main() +{ + + const int task_count = 4; + vector> tasks; + + for(int i = 0; i < task_count; i++) { + auto t = task_test(); + tasks.push_back(std::move(t)); + } + + int done_count = 0; + while(done_count < task_count) { + for(int i = 0; i < task_count; i++) { + Task &t = tasks[i]; + + if(t.done()) { + t.destroy(); + done_count++; + } else { + auto res = t(); + cout << "T# " << i << " result " + << res << endl; + } + } + } +} diff --git a/game_engine.cpp b/game_engine.cpp index 0fdd573..cf18ed9 100644 --- a/game_engine.cpp +++ b/game_engine.cpp @@ -19,7 +19,7 @@ int GameEngine::determine_damage(string &type) { return damage_types.at(type); } catch(std::out_of_range &err) { print(ERROR, "BAD DAMAGE TYPE {}\n", type); - return 1000; + return 0; } } diff --git a/meson.build b/meson.build index f75414d..790ae5e 100644 --- a/meson.build +++ b/meson.build @@ -15,9 +15,6 @@ libgit2package_dep = libgit2_proj.dependency('libgit2package') efsw_dep = dependency('efsw') fmt = dependency('fmt') -ftxui_screen = dependency('ftxui-screen') -ftxui_dom = dependency('ftxui-dom') -ftxui_component = dependency('ftxui-component') catch2 = dependency('catch2-with-main') sfml = dependency('sfml') json = dependency('nlohmann_json') @@ -25,7 +22,6 @@ imgui = dependency('imgui-sfml') dependencies = [ fmt, libgit2package_dep, efsw_dep, - ftxui_screen, ftxui_dom, ftxui_component, sfml, imgui, json ] @@ -36,18 +32,11 @@ executable('escape_turings_tarpit', 'builder.cpp', 'sfmlgui.cpp', 'escape_turings_tarpit.cpp'], - win_subsystem: 'windows', dependencies: dependencies) executable('regtest', 'regtest.cpp', dependencies: [fmt]) -executable('ftxtest', 'ftxtest.cpp', - dependencies: dependencies) - -executable('ftx_thread_test', 'ftx_thread_test.cpp', - dependencies: dependencies) - executable('audiotest', 'audiotest.cpp', dependencies: dependencies) @@ -57,6 +46,10 @@ executable('jsontest', 'jsontest.cpp', executable('threadtest', 'threadtest.cpp', dependencies: dependencies) +executable('corotest', 'corotest.cpp', + dependencies: dependencies, + cpp_args: '-fcoroutines') + runtests = executable('runtests', [ 'game_engine.cpp', 'tests/game_engine.cpp', diff --git a/scripts/reset_build.ps1 b/scripts/reset_build.ps1 index 8d7b4b0..da9e1b7 100644 --- a/scripts/reset_build.ps1 +++ b/scripts/reset_build.ps1 @@ -7,7 +7,6 @@ mkdir builddir meson wrap install fmt meson wrap install sqlite3 meson wrap install sqlitecpp -meson wrap install ftxui meson wrap install catch2 meson wrap install libpng meson wrap install vorbis diff --git a/scripts/reset_build.sh b/scripts/reset_build.sh index 471b622..d197853 100644 --- a/scripts/reset_build.sh +++ b/scripts/reset_build.sh @@ -10,7 +10,6 @@ cp *.wrap subprojects meson wrap install fmt meson wrap install sqlite3 meson wrap install sqlitecpp -meson wrap install ftxui meson wrap install catch2 meson wrap install libpng meson wrap install vorbis