Upgrade cellular client to v10 with readable play and assisted steering
This commit is contained in:
+167
-1
@@ -2,8 +2,10 @@
|
||||
// software renderer, pinned toolkit). Notices fit their fixed-width window with a
|
||||
// visible close button; clicking it (move + press + release in one batch, no settling
|
||||
// frame) dismisses exactly that notice and never reaches the world.
|
||||
#include "cellular_scene.hpp"
|
||||
#include "controls_flow.hpp"
|
||||
#include "evo/client/application.hpp"
|
||||
#include "evo/render/organism.hpp"
|
||||
#include "panels.hpp"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <array>
|
||||
@@ -25,6 +27,11 @@ void check(bool ok, std::source_location at = std::source_location::current()) {
|
||||
throw std::runtime_error("client panels line " + std::to_string(at.line()));
|
||||
}
|
||||
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
|
||||
template <class T> const T& required(const std::optional<T>& value) {
|
||||
if (!value)
|
||||
throw std::runtime_error("missing panel test value");
|
||||
return *value;
|
||||
}
|
||||
SDL_Window* window() {
|
||||
int count{};
|
||||
SDL_Window** windows = SDL_GetWindows(&count);
|
||||
@@ -349,12 +356,171 @@ void apply_save_restart() {
|
||||
CHECK(intention && intention->move_x == -1000);
|
||||
std::filesystem::remove_all(dir);
|
||||
}
|
||||
void cellular_panels(const std::filesystem::path& review) {
|
||||
for (const auto size : {std::pair{960, 640}, std::pair{1280, 800}, std::pair{640, 480}}) {
|
||||
const auto [width, height] = size;
|
||||
auto opened = Application::open({width, height, false, "software"});
|
||||
CHECK(opened);
|
||||
auto app = std::move(*opened);
|
||||
const auto id = SDL_GetWindowID(window());
|
||||
SDL_Event focus{};
|
||||
focus.type = SDL_EVENT_WINDOW_FOCUS_GAINED;
|
||||
focus.window.windowID = id;
|
||||
CHECK(SDL_PushEvent(&focus) && app->poll_events());
|
||||
std::vector<render::Rectangle> boxes{
|
||||
{0, 0, static_cast<float>(width), static_cast<float>(height), {8, 19, 25, 255}}};
|
||||
const auto camera =
|
||||
Camera::create({width, height, width, height}, {width < 880 ? 0.29 : 2.1, 3.29}, 100);
|
||||
CHECK(camera);
|
||||
for (int x = 0; x < 5; ++x)
|
||||
for (int y = 0; y < 6; ++y) {
|
||||
const auto low =
|
||||
camera->world_to_screen({static_cast<double>(x), static_cast<double>(y)});
|
||||
const auto high = camera->world_to_screen({x + 1.0, y + 1.0});
|
||||
CHECK(low && high);
|
||||
patch_box(boxes, *low, *high, (x + y) % 4 != 0, x == 2 && y == 3, width, height);
|
||||
}
|
||||
OrganismCell organism;
|
||||
organism.id = 901;
|
||||
organism.x = {2200};
|
||||
organism.y = {3200};
|
||||
organism.phenotype.extent = 300;
|
||||
organism.phenotype.total_mass = 10000;
|
||||
organism.phenotype.structural_mass = 9000;
|
||||
organism.phenotype.membrane_mass = 1000;
|
||||
organism.phenotype.conversion_per_thousand = 650;
|
||||
organism.phenotype.movement_speed = 500;
|
||||
organism.phenotype.ingestion_rate = 400;
|
||||
organism.growth.realized_per_thousand = 1000;
|
||||
const auto population =
|
||||
OrganismPresentation::create({{100, 1}, 102, 1}, 0, std::array{organism});
|
||||
CHECK(population);
|
||||
CHECK(render::append_organisms(boxes, 100, &*population, Freshness::current, *camera));
|
||||
const auto frame = render::Frame::create(boxes);
|
||||
CHECK(frame);
|
||||
UiState ui;
|
||||
Launcher launch;
|
||||
Selection selection;
|
||||
EnvironmentLayer environment;
|
||||
OrganismLayer organisms;
|
||||
CellularPlay play;
|
||||
play.initialize(100);
|
||||
play.connected();
|
||||
network::CellularLifeDiagnostics diagnostics;
|
||||
diagnostics.reserve_energy_pj = 248000;
|
||||
diagnostics.reserve_matter_fg = {15000, 2400, 800, 6000};
|
||||
diagnostics.has_tick_effects = true;
|
||||
diagnostics.maintenance_cost_pj = 80;
|
||||
diagnostics.movement_cost_pj = 20;
|
||||
diagnostics.movement = network::CellularMovementResult::moved;
|
||||
diagnostics.intake = network::CellularIntakeResult::acquired;
|
||||
diagnostics.engulf = network::CellularEngulfResult::membrane_too_thick;
|
||||
network::CellularPerception perception{
|
||||
102, 901, {{1000, 2000, 50000, {100, 20, 10, 40}}}, diagnostics};
|
||||
play.observe(perception);
|
||||
play.observe_offer(network::CellularMutationOffer{
|
||||
102,
|
||||
901,
|
||||
1,
|
||||
100,
|
||||
{{3, 2, 0, 500, 1600, 22000, 1200, {100, 20, 10, 40}},
|
||||
{5, 1, 0, 2, 2000, 26000, 5000, {500, 80, 20, 120}},
|
||||
{8, 3, 0, 400, 1800, 24000, 300000, {400, 60, 20, 100}}}});
|
||||
FormBuffers form;
|
||||
render::EnvironmentDisplay display;
|
||||
PanelView view;
|
||||
view.mode = Mode::remote;
|
||||
view.launcher = &launch;
|
||||
view.environment = &environment;
|
||||
view.organisms = &organisms;
|
||||
view.selection = &selection;
|
||||
view.ui = &ui;
|
||||
view.bindings = &app->bindings();
|
||||
view.cellular_perception = &perception;
|
||||
view.cellular_play = &play;
|
||||
view.remote.emplace();
|
||||
view.remote->phase = "connected";
|
||||
view.remote->cellular_trial = true;
|
||||
view.remote->server_tick = 102;
|
||||
view.remote->region = 4;
|
||||
PanelActions action;
|
||||
app->set_overlay([&] { action = draw_panels(view, form, display); });
|
||||
const auto draw = [&] {
|
||||
CHECK(app->poll_events() && app->present(*frame) == Step::rendered);
|
||||
};
|
||||
for (int i = 0; i < 3; ++i)
|
||||
draw();
|
||||
const auto* journal = ImGui::FindWindowByName("Cellular field journal");
|
||||
CHECK(journal && journal->Active && journal->ScrollMax.x == 0);
|
||||
CHECK(journal->Pos.x >= 0 && journal->Pos.y >= 0 &&
|
||||
journal->Pos.x + journal->Size.x <= static_cast<float>(width) &&
|
||||
journal->Pos.y + journal->Size.y <= static_cast<float>(height));
|
||||
if (!review.empty()) {
|
||||
std::filesystem::create_directories(review);
|
||||
CHECK(app->request_screenshot(
|
||||
(review / ("cellular-" + std::to_string(width) + ".bmp")).string()));
|
||||
draw();
|
||||
}
|
||||
if (width != 960)
|
||||
continue;
|
||||
const auto* evolution = ImGui::FindWindowByName("Evolution");
|
||||
CHECK(evolution && evolution->Active && evolution->ScrollMax.x == 0);
|
||||
CHECK(evolution->Pos.x >= journal->Pos.x + journal->Size.x &&
|
||||
evolution->Pos.x + evolution->Size.x <= static_cast<float>(width));
|
||||
// Click the first production choice. Pointer ownership prevents world selection.
|
||||
const auto probe = [&](const ImGuiWindow* panel, float x_fraction, const auto& done) {
|
||||
const float x = panel->Pos.x + panel->Size.x * x_fraction;
|
||||
for (int offset = 90; static_cast<float>(offset) < panel->Size.y - 10; offset += 5) {
|
||||
const float y = panel->Pos.y + static_cast<float>(offset);
|
||||
mouse(id, SDL_EVENT_MOUSE_MOTION, x, y);
|
||||
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, x, y);
|
||||
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, x, y);
|
||||
CHECK(app->poll_events() && !app->take_navigation().click);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
CHECK(app->present(*frame) == Step::rendered && app->poll_events());
|
||||
if (done())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
auto depleted = diagnostics;
|
||||
depleted.reserve_energy_pj = 0;
|
||||
perception.diagnostics = depleted;
|
||||
draw();
|
||||
CHECK(!probe(evolution, 0.5F, [&] { return action.mutation.has_value(); }));
|
||||
perception.diagnostics = diagnostics;
|
||||
draw();
|
||||
CHECK(probe(evolution, 0.5F, [&] { return action.mutation.has_value(); }));
|
||||
CHECK(action.mutation == MutationChoice{901, 1, 100, 3});
|
||||
CHECK(play.queue(CellAction::mutation, 102, required(action.mutation)));
|
||||
const auto mutation_id = required(play.pending()).id;
|
||||
draw();
|
||||
CHECK(!probe(evolution, 0.5F, [&] { return action.mutation.has_value(); }));
|
||||
play.outcome({mutation_id, network::ActionResult::committed, 103, 5});
|
||||
draw();
|
||||
CHECK(probe(journal, 0.75F, [&] { return action.cell_action == CellAction::bud; }));
|
||||
play.observe_end({104, 901, network::CellularDeathReason::engulfed});
|
||||
perception = {104, 0, {}, {}};
|
||||
play.observe(perception);
|
||||
draw();
|
||||
if (!review.empty()) {
|
||||
CHECK(app->request_screenshot((review / "cellular-death.bmp").string()));
|
||||
draw();
|
||||
}
|
||||
CHECK(probe(evolution, 0.5F, [&] { return action.restart_life; }));
|
||||
CHECK(play.restart());
|
||||
draw();
|
||||
CHECK(!probe(evolution, 0.5F, [&] { return action.restart_life; }));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() try {
|
||||
int main(int argc, char** argv) try {
|
||||
notices();
|
||||
controls_panel();
|
||||
apply_save_restart();
|
||||
cellular_panels(argc == 2 ? std::filesystem::path{argv[1]} : std::filesystem::path{});
|
||||
std::puts("client panel tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
|
||||
Reference in New Issue
Block a user