From 54a9b6f9ad2072bd82fc0c4fa58d9ccc822d41e3 Mon Sep 17 00:00:00 2001 From: Sergey Lapin Date: Mon, 9 Dec 2024 00:52:04 +0300 Subject: [PATCH] Rewritten grid matching in more declarative way --- src/modules/stream/ui/growth_module.cpp | 6 ++ src/modules/stream/ui/setup_3d_viewport.h | 71 ++++++++++++----------- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/modules/stream/ui/growth_module.cpp b/src/modules/stream/ui/growth_module.cpp index dd6ef50..d8e7752 100644 --- a/src/modules/stream/ui/growth_module.cpp +++ b/src/modules/stream/ui/growth_module.cpp @@ -5,6 +5,7 @@ #include "queries.h" #include "building_layout_graph.h" #include "growth_module.h" +// TODO: make sure Enterance is at outside wall, can do this on region level or on cell level growth_module::growth_module(flecs::world &ecs) { @@ -15,6 +16,10 @@ growth_module::growth_module(flecs::world &ecs) ecs.component(); ecs.component(); ecs.component(); + ecs.component(); + ecs.component(); + ecs.component(); + ecs.component(); ecs.component(); ecs.component(); ecs.component(); @@ -30,6 +35,7 @@ growth_module::growth_module(flecs::world &ecs) flecs::entity GraphSolve = ecs.lookup("::graph_module::GraphSolve"); assert(GraphSolve.is_valid()); GraphFilter.disable(); + assert(ecs.lookup("::growth_module::window_east").is_valid()); ecs.system("RunGrow") .immediate() diff --git a/src/modules/stream/ui/setup_3d_viewport.h b/src/modules/stream/ui/setup_3d_viewport.h index 9193729..7b6105a 100644 --- a/src/modules/stream/ui/setup_3d_viewport.h +++ b/src/modules/stream/ui/setup_3d_viewport.h @@ -127,7 +127,7 @@ protected: int y = 0; int z = cell.index / grid_size; Transform base_transform(Basis(), - Vector3(x * 4, 0, z * 4)); + Vector3(x * 4, y, z * 4)); int matches = 0; struct pmatch { int check; @@ -243,38 +243,43 @@ protected: -Math_PI / 2), Vector3(2, 0, 0), false }, }; - if (e.has()) - matches |= 1; - if (e.has()) - matches |= 2; - if (e.has()) - matches |= 4; - if (e.has()) - matches |= 8; - if (e.has()) - matches |= 16; - if (e.has()) - matches |= 32; - if (e.has()) - matches |= 64; - if (e.has()) - matches |= 128; - if (e.has()) - matches |= 256; - if (e.has()) - matches |= 512; - if (e.has()) - matches |= 1024; - if (e.has()) - matches |= 2048; - if (e.has()) - matches |= 4096; - if (e.has()) - matches |= 8192; - if (e.has()) - matches |= 16384; - if (e.has()) - matches |= 32768; + struct match_window { + const char *cmp_name; + int match; + }; + struct match_window cmp_matches[] = { + { "::growth_module::outside_wall_north", 1 }, + { "::growth_module::outside_wall_south", 2 }, + { "::growth_module::outside_wall_west", 4 }, + { "::growth_module::outside_wall_east", 8 }, + { "::growth_module::internal_wall_north", 16 }, + { "::growth_module::internal_wall_south", 32 }, + { "::growth_module::internal_wall_west", 64 }, + { "::growth_module::internal_wall_east", 128 }, + { "::growth_module::window_north", 256 }, + { "::growth_module::window_south", 512 }, + { "::growth_module::window_west", 1024 }, + { "::growth_module::window_east", 2048 }, + { "::growth_module::internal_door_north", + 4096 }, + { "::growth_module::internal_door_south", + 8192 }, + { "::growth_module::internal_door_west", + 16384 }, + { "::growth_module::internal_door_east", + 32768 }, + }; + for (i = 0; i < (int)sizeof(cmp_matches) / + (int)sizeof(cmp_matches[0]); + i++) { + flecs::entity cmp = e.world().lookup( + cmp_matches[i].cmp_name); + flecs::log::dbg("component: %s", + cmp_matches[i].cmp_name); + assert(cmp.is_valid()); + if (e.has(cmp)) + matches |= cmp_matches[i].match; + } for (i = 0; i < 2; i++) item_data[i].items.clear(); for (i = 0; i < (int)sizeof(match_data) /