Did a small refactoring

This commit is contained in:
2024-11-12 07:51:34 +03:00
parent 124a080840
commit d1bcf3af7b
5 changed files with 744 additions and 340 deletions

View File

@@ -69,7 +69,8 @@
"variant": "cpp", "variant": "cpp",
"format": "cpp", "format": "cpp",
"future": "cpp", "future": "cpp",
"cassert": "cpp" "cassert": "cpp",
"bitset": "cpp"
}, },
"cmake.ignoreCMakeListsMissing": true "cmake.ignoreCMakeListsMissing": true
} }

View File

@@ -46,7 +46,21 @@ public:
int get_layout_count() const; int get_layout_count() const;
int get_children_count(flecs::entity base_e) const; int get_children_count(flecs::entity base_e) const;
struct graph_module { struct graph_module {
flecs::entity GraphSolve;
flecs::entity get_layout_grid_base(); flecs::entity get_layout_grid_base();
flecs::entity get_layout_base();
flecs::entity create_cell(flecs::entity floor_e,
flecs::entity region_e, int id);
bool have_cell(flecs::entity floor_e, int id);
void grow_cell(flecs::entity seed_e, int id);
void queue_grow_cell(flecs::entity seed_e, int id);
void growth_module(flecs::world &ecs,
const String &module_name);
void create_floor_components(
flecs::entity floor_e, flecs::entity base_floor_e,
const WorldEditor::components::buildings_layout_grid_size
&size);
graph_module(flecs::world &ecs); graph_module(flecs::world &ecs);
}; };
}; };

View File

@@ -801,7 +801,8 @@ void BuildingLayoutGraphUI::draw_2d_grid_view(Control *draw)
->grid_size; ->grid_size;
float disp_size = MIN(size.x, size.y); float disp_size = MIN(size.x, size.y);
float multiplier = disp_size / (float)grid_size; float multiplier = disp_size / (float)grid_size;
print_line(String::num(disp_size) + " " + itos(grid_size)); print_line("drawing: " + String::num(disp_size) + " " +
itos(grid_size));
flecs::entity grid_e = get_current_grid_layout(); flecs::entity grid_e = get_current_grid_layout();
if (!grid_e.is_valid()) if (!grid_e.is_valid())
return; return;
@@ -835,6 +836,7 @@ void BuildingLayoutGraphUI::draw_2d_grid_view(Control *draw)
print_line(String(fe.path())); print_line(String(fe.path()));
if (String(fe.name()) == cur_floor || if (String(fe.name()) == cur_floor ||
(cur_floor == "" && pos == 0)) { (cur_floor == "" && pos == 0)) {
print_line("draw floor: " + String(fe.name()));
draw->draw_rect(Rect2(0, 0, disp_size, disp_size), draw->draw_rect(Rect2(0, 0, disp_size, disp_size),
Color(0, 1, 1, 1), false); Color(0, 1, 1, 1), false);
// TODO: display children cells // TODO: display children cells
@@ -858,6 +860,8 @@ void BuildingLayoutGraphUI::draw_2d_grid_view(Control *draw)
float dx = x * disp_size / grid_size; float dx = x * disp_size / grid_size;
float dy = y * disp_size / grid_size; float dy = y * disp_size / grid_size;
float dsize = disp_size / grid_size; float dsize = disp_size / grid_size;
print_line("draw cell: " + String(fc.name()) +
" " + itos(index));
if (!colors.has(cell.type)) if (!colors.has(cell.type))
colors[cell.type] = Color(Math::randf(), colors[cell.type] = Color(Math::randf(),
Math::randf(), Math::randf(),
@@ -865,6 +869,12 @@ void BuildingLayoutGraphUI::draw_2d_grid_view(Control *draw)
1); 1);
draw->draw_rect(Rect2(dx, dy, dsize, dsize), draw->draw_rect(Rect2(dx, dy, dsize, dsize),
colors[cell.type]); colors[cell.type]);
print_line(
"draw cell: (" + itos(x) + ", " +
itos(y) + ") (" + String::num(dx) +
", " + String::num(dy) + ") " +
String::num(dsize) + " " +
(colors[cell.type].operator String()));
}); });
} }
pos++; pos++;

File diff suppressed because it is too large Load Diff

View File

@@ -75,6 +75,7 @@ public:
String type; String type;
int index; int index;
}; };
struct final_cell {};
struct buildings_layout_graph {}; struct buildings_layout_graph {};
struct buildings_layout_graph_node { struct buildings_layout_graph_node {
int depth; int depth;
@@ -116,9 +117,17 @@ public:
struct buildings_layout_grid_size { struct buildings_layout_grid_size {
int grid_size; int grid_size;
List<Pair<int, flecs::entity_t> > floors; List<Pair<int, flecs::entity_t> > floors;
int growth_size;
}; };
struct belongs {}; struct belongs {};
struct buildings_layout_grid_floor {}; struct buildings_layout_grid_floor {
Set<int> cells;
int grid_size;
int size_left;
};
struct buildings_layout_grid_queue {
List<Pair<flecs::entity_t, int> > queue;
};
struct buildings_layout_commands { struct buildings_layout_commands {
struct command { struct command {
int command; int command;