Implement M9.2 native client lifecycle and immutable render boundary
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#include "evo/client/application.hpp"
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <exception>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
|
||||
int main(int argc, char** argv) try {
|
||||
evo::client::Config config;
|
||||
unsigned frames = 0;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
const std::string_view arg{argv[i]};
|
||||
if (arg == "--hidden")
|
||||
config.hidden = true;
|
||||
else if (arg == "--renderer" && i + 1 < argc)
|
||||
config.renderer = argv[++i];
|
||||
else if (arg == "--frames" && i + 1 < argc) {
|
||||
const std::string_view value{argv[++i]};
|
||||
const auto [end, error] =
|
||||
std::from_chars(value.data(), value.data() + value.size(), frames);
|
||||
if (error != std::errc{} || end != value.data() + value.size() || frames == 0 ||
|
||||
frames > 100000)
|
||||
return 2;
|
||||
} else {
|
||||
std::fputs("usage: evo-client [--renderer NAME] [--hidden] [--frames 1..100000]\n",
|
||||
stderr);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
auto app = evo::client::Application::open(config);
|
||||
if (!app) {
|
||||
std::fprintf(stderr, "client initialization error=%d\n", static_cast<int>(app.error()));
|
||||
return 1;
|
||||
}
|
||||
// Presentation fixture only. No simulated organisms or world state.
|
||||
const std::array<evo::render::Rectangle, 1> boxes{{{24, 24, 160, 96, {64, 180, 140, 255}}}};
|
||||
const auto frame = evo::render::Frame::create(boxes, {16, 20, 28, 255});
|
||||
if (!frame)
|
||||
return 1;
|
||||
unsigned count = 0;
|
||||
while (frames == 0 || count < frames) {
|
||||
const auto result = (*app)->step(*frame);
|
||||
if (!result) {
|
||||
std::fprintf(stderr, "client frame error=%d\n", static_cast<int>(result.error()));
|
||||
return 1;
|
||||
}
|
||||
if (*result == evo::client::Step::closed)
|
||||
break;
|
||||
++count;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{16});
|
||||
}
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::fprintf(stderr, "client exception: %.200s\n", e.what());
|
||||
return 1;
|
||||
} catch (...) {
|
||||
std::fputs("client exception\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user