From f4f8bbce0b8213b05a5d359c79b22701c73eb53d Mon Sep 17 00:00:00 2001 From: Sergey Lapin Date: Thu, 10 Oct 2024 12:25:32 +0300 Subject: [PATCH] Started mesh merging implementation --- godot/astream/blayout.conf | 1149 +++++++++++++++-- godot/main/building_layout_editor.tscn | 150 ++- .../buildings/building_layout_editor.cpp | 160 ++- .../stream/buildings/building_layout_editor.h | 4 + src/modules/stream/buildings/element_data.cpp | 424 +++++- src/modules/stream/buildings/element_data.h | 402 +----- src/modules/stream/buildings_editor.cpp | 94 +- src/modules/stream/buildings_editor.h | 7 +- src/modules/stream/editor_event.cpp | 3 +- src/modules/stream/editor_event.h | 27 +- src/modules/stream/line_metadata_editor.cpp | 6 +- src/modules/stream/line_metadata_editor.h | 2 +- src/modules/stream/nav_panel.cpp | 4 +- src/modules/stream/road_lines_data.cpp | 12 +- src/modules/stream/road_lines_editor.cpp | 120 +- src/modules/stream/road_lines_editor.h | 6 +- src/modules/stream/stream.cpp | 3 +- src/modules/stream/stream.h | 2 +- src/modules/stream/world_editor.cpp | 45 +- src/modules/stream/world_editor.h | 8 +- 20 files changed, 1923 insertions(+), 705 deletions(-) diff --git a/godot/astream/blayout.conf b/godot/astream/blayout.conf index 450710c..0ed5e72 100644 --- a/godot/astream/blayout.conf +++ b/godot/astream/blayout.conf @@ -140,217 +140,217 @@ grid_layouts={ "index": 17, "rotation": 0 }, { -"element": "empty", +"element": "corner", "index": 18, -"rotation": 0 +"rotation": 3 }, { -"element": "empty", +"element": "side_wall", "index": 19, -"rotation": 0 +"rotation": 2 }, { -"element": "empty", +"element": "side_wall", "index": 20, -"rotation": 0 +"rotation": 2 }, { -"element": "empty", +"element": "side_wall", "index": 21, -"rotation": 0 +"rotation": 2 }, { -"element": "empty", +"element": "side_wall", "index": 22, -"rotation": 0 +"rotation": 2 }, { -"element": "empty", +"element": "side_wall", "index": 23, -"rotation": 0 +"rotation": 2 }, { -"element": "empty", +"element": "side_wall", "index": 24, -"rotation": 0 +"rotation": 2 }, { -"element": "empty", +"element": "corner", "index": 25, -"rotation": 0 +"rotation": 2 }, { "element": "empty", "index": 26, "rotation": 0 }, { -"element": "empty", +"element": "side_wall", "index": 27, -"rotation": 0 +"rotation": 3 }, { -"element": "empty", +"element": "normal_floor", "index": 28, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 29, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 30, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 31, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 32, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 33, "rotation": 0 }, { -"element": "empty", +"element": "side_wall", "index": 34, -"rotation": 0 +"rotation": 1 }, { "element": "empty", "index": 35, "rotation": 0 }, { -"element": "empty", +"element": "side_wall", "index": 36, -"rotation": 0 +"rotation": 3 }, { -"element": "empty", +"element": "normal_floor", "index": 37, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 38, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 39, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 40, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 41, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 42, "rotation": 0 }, { -"element": "empty", +"element": "side_wall", "index": 43, -"rotation": 0 +"rotation": 1 }, { "element": "empty", "index": 44, "rotation": 0 }, { -"element": "empty", +"element": "side_wall", "index": 45, -"rotation": 0 +"rotation": 3 }, { -"element": "empty", +"element": "normal_floor", "index": 46, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 47, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 48, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 49, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 50, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 51, "rotation": 0 }, { -"element": "empty", +"element": "side_wall", "index": 52, -"rotation": 0 +"rotation": 1 }, { "element": "empty", "index": 53, "rotation": 0 }, { -"element": "empty", +"element": "side_wall", "index": 54, -"rotation": 0 +"rotation": 3 }, { -"element": "empty", +"element": "normal_floor", "index": 55, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 56, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 57, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 58, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 59, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 60, "rotation": 0 }, { -"element": "empty", +"element": "side_wall", "index": 61, -"rotation": 0 +"rotation": 1 }, { "element": "empty", "index": 62, "rotation": 0 }, { -"element": "empty", +"element": "side_wall", "index": 63, -"rotation": 0 +"rotation": 3 }, { -"element": "empty", +"element": "normal_floor", "index": 64, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 65, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 66, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 67, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 68, "rotation": 0 }, { -"element": "empty", +"element": "normal_floor", "index": 69, "rotation": 0 }, { -"element": "empty", +"element": "side_wall", "index": 70, -"rotation": 0 +"rotation": 1 }, { "element": "empty", "index": 71, @@ -1042,7 +1042,7 @@ grid_layouts={ "index": 80, "rotation": 0 } ], -"floor_0": [ { +"floor_-4": [ { "element": "empty", "index": 0, "rotation": 0 @@ -1159,11 +1159,11 @@ grid_layouts={ "index": 28, "rotation": 0 }, { -"element": "normal_floor", +"element": "empty", "index": 29, "rotation": 0 }, { -"element": "normal_floor", +"element": "empty", "index": 30, "rotation": 0 }, { @@ -1331,43 +1331,43 @@ grid_layouts={ "index": 71, "rotation": 0 }, { -"element": "corner", +"element": "empty", "index": 72, "rotation": 0 }, { -"element": "side_window", +"element": "empty", "index": 73, "rotation": 0 }, { -"element": "side_wall", +"element": "empty", "index": 74, "rotation": 0 }, { -"element": "side_door", +"element": "empty", "index": 75, "rotation": 0 }, { -"element": "side_wall", +"element": "empty", "index": 76, "rotation": 0 }, { -"element": "side_window", +"element": "empty", "index": 77, "rotation": 0 }, { -"element": "side_wall", +"element": "empty", "index": 78, "rotation": 0 }, { -"element": "corner", +"element": "empty", "index": 79, -"rotation": 1 +"rotation": 0 }, { "element": "empty", "index": 80, "rotation": 0 } ], -"floor_1": [ { +"floor_-5": [ { "element": "empty", "index": 0, "rotation": 0 @@ -1432,13 +1432,13 @@ grid_layouts={ "index": 15, "rotation": 0 }, { -"element": "side_wall", +"element": "empty", "index": 16, -"rotation": 2 +"rotation": 0 }, { -"element": "corner", +"element": "empty", "index": 17, -"rotation": 2 +"rotation": 0 }, { "element": "empty", "index": 18, @@ -1504,9 +1504,9 @@ grid_layouts={ "index": 33, "rotation": 0 }, { -"element": "normal_floor", +"element": "empty", "index": 34, -"rotation": 2 +"rotation": 0 }, { "element": "empty", "index": 35, @@ -1612,9 +1612,9 @@ grid_layouts={ "index": 60, "rotation": 0 }, { -"element": "side_wall", +"element": "empty", "index": 61, -"rotation": 1 +"rotation": 0 }, { "element": "empty", "index": 62, @@ -1646,8 +1646,658 @@ grid_layouts={ }, { "element": "empty", "index": 69, +"rotation": 0 +}, { +"element": "empty", +"index": 70, +"rotation": 0 +}, { +"element": "empty", +"index": 71, +"rotation": 0 +}, { +"element": "empty", +"index": 72, +"rotation": 0 +}, { +"element": "empty", +"index": 73, +"rotation": 0 +}, { +"element": "empty", +"index": 74, +"rotation": 0 +}, { +"element": "empty", +"index": 75, +"rotation": 0 +}, { +"element": "empty", +"index": 76, +"rotation": 0 +}, { +"element": "empty", +"index": 77, +"rotation": 0 +}, { +"element": "empty", +"index": 78, +"rotation": 0 +}, { +"element": "empty", +"index": 79, +"rotation": 0 +}, { +"element": "empty", +"index": 80, +"rotation": 0 +} ], +"floor_0": [ { +"element": "empty", +"index": 0, +"rotation": 0 +}, { +"element": "empty", +"index": 1, +"rotation": 0 +}, { +"element": "empty", +"index": 2, +"rotation": 0 +}, { +"element": "empty", +"index": 3, +"rotation": 0 +}, { +"element": "empty", +"index": 4, +"rotation": 0 +}, { +"element": "empty", +"index": 5, +"rotation": 0 +}, { +"element": "empty", +"index": 6, +"rotation": 0 +}, { +"element": "empty", +"index": 7, +"rotation": 0 +}, { +"element": "empty", +"index": 8, +"rotation": 0 +}, { +"element": "empty", +"index": 9, +"rotation": 0 +}, { +"element": "empty", +"index": 10, +"rotation": 0 +}, { +"element": "empty", +"index": 11, +"rotation": 0 +}, { +"element": "empty", +"index": 12, +"rotation": 0 +}, { +"element": "empty", +"index": 13, +"rotation": 0 +}, { +"element": "empty", +"index": 14, +"rotation": 0 +}, { +"element": "empty", +"index": 15, +"rotation": 0 +}, { +"element": "empty", +"index": 16, +"rotation": 0 +}, { +"element": "empty", +"index": 17, +"rotation": 0 +}, { +"element": "corner", +"index": 18, +"rotation": 3 +}, { +"element": "side_window", +"index": 19, +"rotation": 2 +}, { +"element": "side_wall", +"index": 20, +"rotation": 2 +}, { +"element": "side_window", +"index": 21, +"rotation": 2 +}, { +"element": "side_wall", +"index": 22, +"rotation": 2 +}, { +"element": "side_window", +"index": 23, +"rotation": 2 +}, { +"element": "side_wall", +"index": 24, +"rotation": 2 +}, { +"element": "corner", +"index": 25, +"rotation": 2 +}, { +"element": "empty", +"index": 26, +"rotation": 0 +}, { +"element": "side_wall", +"index": 27, +"rotation": 3 +}, { +"element": "normal_floor", +"index": 28, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 29, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 30, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 31, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 32, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 33, +"rotation": 0 +}, { +"element": "side_wall", +"index": 34, "rotation": 1 }, { +"element": "empty", +"index": 35, +"rotation": 0 +}, { +"element": "side_wall", +"index": 36, +"rotation": 3 +}, { +"element": "normal_floor", +"index": 37, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 38, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 39, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 40, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 41, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 42, +"rotation": 0 +}, { +"element": "side_wall", +"index": 43, +"rotation": 1 +}, { +"element": "empty", +"index": 44, +"rotation": 0 +}, { +"element": "side_wall", +"index": 45, +"rotation": 3 +}, { +"element": "normal_floor", +"index": 46, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 47, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 48, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 49, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 50, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 51, +"rotation": 0 +}, { +"element": "side_wall", +"index": 52, +"rotation": 1 +}, { +"element": "empty", +"index": 53, +"rotation": 0 +}, { +"element": "side_wall", +"index": 54, +"rotation": 3 +}, { +"element": "normal_floor", +"index": 55, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 56, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 57, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 58, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 59, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 60, +"rotation": 0 +}, { +"element": "side_wall", +"index": 61, +"rotation": 1 +}, { +"element": "empty", +"index": 62, +"rotation": 0 +}, { +"element": "side_wall", +"index": 63, +"rotation": 3 +}, { +"element": "normal_floor", +"index": 64, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 65, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 66, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 67, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 68, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 69, +"rotation": 0 +}, { +"element": "side_wall", +"index": 70, +"rotation": 1 +}, { +"element": "empty", +"index": 71, +"rotation": 0 +}, { +"element": "corner", +"index": 72, +"rotation": 0 +}, { +"element": "side_window", +"index": 73, +"rotation": 0 +}, { +"element": "side_wall", +"index": 74, +"rotation": 0 +}, { +"element": "side_door", +"index": 75, +"rotation": 0 +}, { +"element": "side_wall", +"index": 76, +"rotation": 0 +}, { +"element": "side_window", +"index": 77, +"rotation": 0 +}, { +"element": "side_wall", +"index": 78, +"rotation": 0 +}, { +"element": "corner", +"index": 79, +"rotation": 1 +}, { +"element": "empty", +"index": 80, +"rotation": 0 +} ], +"floor_1": [ { +"element": "empty", +"index": 0, +"rotation": 0 +}, { +"element": "empty", +"index": 1, +"rotation": 0 +}, { +"element": "empty", +"index": 2, +"rotation": 0 +}, { +"element": "empty", +"index": 3, +"rotation": 0 +}, { +"element": "empty", +"index": 4, +"rotation": 0 +}, { +"element": "empty", +"index": 5, +"rotation": 0 +}, { +"element": "empty", +"index": 6, +"rotation": 2 +}, { +"element": "empty", +"index": 7, +"rotation": 2 +}, { +"element": "empty", +"index": 8, +"rotation": 2 +}, { +"element": "empty", +"index": 9, +"rotation": 0 +}, { +"element": "empty", +"index": 10, +"rotation": 0 +}, { +"element": "empty", +"index": 11, +"rotation": 0 +}, { +"element": "empty", +"index": 12, +"rotation": 0 +}, { +"element": "empty", +"index": 13, +"rotation": 0 +}, { +"element": "empty", +"index": 14, +"rotation": 0 +}, { +"element": "empty", +"index": 15, +"rotation": 2 +}, { +"element": "empty", +"index": 16, +"rotation": 2 +}, { +"element": "empty", +"index": 17, +"rotation": 2 +}, { +"element": "corner", +"index": 18, +"rotation": 3 +}, { +"element": "side_wall", +"index": 19, +"rotation": 2 +}, { +"element": "side_wall", +"index": 20, +"rotation": 2 +}, { +"element": "side_wall", +"index": 21, +"rotation": 2 +}, { +"element": "side_wall", +"index": 22, +"rotation": 2 +}, { +"element": "side_wall", +"index": 23, +"rotation": 2 +}, { +"element": "side_wall", +"index": 24, +"rotation": 2 +}, { +"element": "corner", +"index": 25, +"rotation": 2 +}, { +"element": "empty", +"index": 26, +"rotation": 2 +}, { +"element": "side_wall", +"index": 27, +"rotation": 3 +}, { +"element": "normal_floor", +"index": 28, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 29, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 30, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 31, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 32, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 33, +"rotation": 0 +}, { +"element": "side_wall", +"index": 34, +"rotation": 1 +}, { +"element": "empty", +"index": 35, +"rotation": 0 +}, { +"element": "side_wall", +"index": 36, +"rotation": 3 +}, { +"element": "normal_floor", +"index": 37, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 38, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 39, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 40, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 41, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 42, +"rotation": 0 +}, { +"element": "side_wall", +"index": 43, +"rotation": 1 +}, { +"element": "empty", +"index": 44, +"rotation": 0 +}, { +"element": "side_wall", +"index": 45, +"rotation": 3 +}, { +"element": "normal_floor", +"index": 46, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 47, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 48, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 49, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 50, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 51, +"rotation": 0 +}, { +"element": "side_wall", +"index": 52, +"rotation": 1 +}, { +"element": "empty", +"index": 53, +"rotation": 0 +}, { +"element": "side_wall", +"index": 54, +"rotation": 3 +}, { +"element": "normal_floor", +"index": 55, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 56, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 57, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 58, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 59, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 60, +"rotation": 0 +}, { +"element": "side_wall", +"index": 61, +"rotation": 1 +}, { +"element": "empty", +"index": 62, +"rotation": 0 +}, { +"element": "side_wall", +"index": 63, +"rotation": 3 +}, { +"element": "normal_floor", +"index": 64, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 65, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 66, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 67, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 68, +"rotation": 0 +}, { +"element": "normal_floor", +"index": 69, +"rotation": 0 +}, { "element": "side_window", "index": 70, "rotation": 1 @@ -2016,6 +2666,331 @@ grid_layouts={ "element": "empty", "index": 80, "rotation": 0 +} ], +"floor_3": [ { +"element": "empty", +"index": 0, +"rotation": 0 +}, { +"element": "empty", +"index": 1, +"rotation": 0 +}, { +"element": "empty", +"index": 2, +"rotation": 0 +}, { +"element": "empty", +"index": 3, +"rotation": 0 +}, { +"element": "empty", +"index": 4, +"rotation": 0 +}, { +"element": "empty", +"index": 5, +"rotation": 0 +}, { +"element": "empty", +"index": 6, +"rotation": 0 +}, { +"element": "empty", +"index": 7, +"rotation": 0 +}, { +"element": "empty", +"index": 8, +"rotation": 0 +}, { +"element": "empty", +"index": 9, +"rotation": 0 +}, { +"element": "empty", +"index": 10, +"rotation": 0 +}, { +"element": "empty", +"index": 11, +"rotation": 0 +}, { +"element": "empty", +"index": 12, +"rotation": 0 +}, { +"element": "empty", +"index": 13, +"rotation": 0 +}, { +"element": "empty", +"index": 14, +"rotation": 0 +}, { +"element": "empty", +"index": 15, +"rotation": 0 +}, { +"element": "empty", +"index": 16, +"rotation": 0 +}, { +"element": "empty", +"index": 17, +"rotation": 0 +}, { +"element": "empty", +"index": 18, +"rotation": 0 +}, { +"element": "empty", +"index": 19, +"rotation": 0 +}, { +"element": "empty", +"index": 20, +"rotation": 0 +}, { +"element": "empty", +"index": 21, +"rotation": 0 +}, { +"element": "empty", +"index": 22, +"rotation": 0 +}, { +"element": "empty", +"index": 23, +"rotation": 0 +}, { +"element": "empty", +"index": 24, +"rotation": 0 +}, { +"element": "empty", +"index": 25, +"rotation": 0 +}, { +"element": "empty", +"index": 26, +"rotation": 0 +}, { +"element": "empty", +"index": 27, +"rotation": 0 +}, { +"element": "empty", +"index": 28, +"rotation": 0 +}, { +"element": "empty", +"index": 29, +"rotation": 0 +}, { +"element": "empty", +"index": 30, +"rotation": 0 +}, { +"element": "empty", +"index": 31, +"rotation": 0 +}, { +"element": "empty", +"index": 32, +"rotation": 0 +}, { +"element": "empty", +"index": 33, +"rotation": 0 +}, { +"element": "empty", +"index": 34, +"rotation": 0 +}, { +"element": "empty", +"index": 35, +"rotation": 0 +}, { +"element": "empty", +"index": 36, +"rotation": 0 +}, { +"element": "empty", +"index": 37, +"rotation": 0 +}, { +"element": "empty", +"index": 38, +"rotation": 0 +}, { +"element": "empty", +"index": 39, +"rotation": 0 +}, { +"element": "empty", +"index": 40, +"rotation": 0 +}, { +"element": "empty", +"index": 41, +"rotation": 0 +}, { +"element": "empty", +"index": 42, +"rotation": 0 +}, { +"element": "empty", +"index": 43, +"rotation": 0 +}, { +"element": "empty", +"index": 44, +"rotation": 0 +}, { +"element": "empty", +"index": 45, +"rotation": 0 +}, { +"element": "empty", +"index": 46, +"rotation": 0 +}, { +"element": "empty", +"index": 47, +"rotation": 0 +}, { +"element": "empty", +"index": 48, +"rotation": 0 +}, { +"element": "empty", +"index": 49, +"rotation": 0 +}, { +"element": "empty", +"index": 50, +"rotation": 0 +}, { +"element": "empty", +"index": 51, +"rotation": 0 +}, { +"element": "empty", +"index": 52, +"rotation": 0 +}, { +"element": "empty", +"index": 53, +"rotation": 0 +}, { +"element": "empty", +"index": 54, +"rotation": 0 +}, { +"element": "empty", +"index": 55, +"rotation": 0 +}, { +"element": "empty", +"index": 56, +"rotation": 0 +}, { +"element": "empty", +"index": 57, +"rotation": 0 +}, { +"element": "empty", +"index": 58, +"rotation": 0 +}, { +"element": "empty", +"index": 59, +"rotation": 0 +}, { +"element": "empty", +"index": 60, +"rotation": 0 +}, { +"element": "empty", +"index": 61, +"rotation": 0 +}, { +"element": "empty", +"index": 62, +"rotation": 0 +}, { +"element": "empty", +"index": 63, +"rotation": 0 +}, { +"element": "empty", +"index": 64, +"rotation": 0 +}, { +"element": "empty", +"index": 65, +"rotation": 0 +}, { +"element": "empty", +"index": 66, +"rotation": 0 +}, { +"element": "empty", +"index": 67, +"rotation": 0 +}, { +"element": "empty", +"index": 68, +"rotation": 0 +}, { +"element": "empty", +"index": 69, +"rotation": 0 +}, { +"element": "empty", +"index": 70, +"rotation": 0 +}, { +"element": "empty", +"index": 71, +"rotation": 0 +}, { +"element": "empty", +"index": 72, +"rotation": 0 +}, { +"element": "empty", +"index": 73, +"rotation": 0 +}, { +"element": "empty", +"index": 74, +"rotation": 0 +}, { +"element": "empty", +"index": 75, +"rotation": 0 +}, { +"element": "empty", +"index": 76, +"rotation": 0 +}, { +"element": "empty", +"index": 77, +"rotation": 0 +}, { +"element": "empty", +"index": 78, +"rotation": 0 +}, { +"element": "empty", +"index": 79, +"rotation": 0 +}, { +"element": "empty", +"index": 80, +"rotation": 0 } ] }, "interior": { diff --git a/godot/main/building_layout_editor.tscn b/godot/main/building_layout_editor.tscn index 36eff6d..b8b9b52 100644 --- a/godot/main/building_layout_editor.tscn +++ b/godot/main/building_layout_editor.tscn @@ -330,23 +330,42 @@ columns = 2 unique_name_in_owner = true margin_top = 719.0 margin_right = 314.0 -margin_bottom = 999.0 +margin_bottom = 1055.0 [node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/layout_editor"] margin_left = 7.0 margin_top = 7.0 margin_right = 307.0 -margin_bottom = 273.0 +margin_bottom = 329.0 -[node name="grid_elements" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"] -unique_name_in_owner = true +[node name="GridContainer" type="GridContainer" parent="VBoxContainer/layout_editor/VBoxContainer"] margin_right = 300.0 +margin_bottom = 44.0 +columns = 2 + +[node name="Label" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/GridContainer"] +margin_top = 3.0 +margin_right = 54.0 +margin_bottom = 17.0 +text = "element" + +[node name="grid_elements" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/GridContainer"] +unique_name_in_owner = true +margin_left = 58.0 +margin_right = 95.0 margin_bottom = 20.0 -[node name="select_rotation" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"] +[node name="Label2" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/GridContainer"] +margin_top = 27.0 +margin_right = 54.0 +margin_bottom = 41.0 +text = "rotation" + +[node name="select_rotation" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/GridContainer"] unique_name_in_owner = true +margin_left = 58.0 margin_top = 24.0 -margin_right = 300.0 +margin_right = 95.0 margin_bottom = 44.0 text = "0" items = [ "0", null, false, 0, null, "90", null, false, 1, null, "180", null, false, 2, null, "270", null, false, 3, null ] @@ -359,60 +378,129 @@ margin_right = 300.0 margin_bottom = 68.0 text = "Clear cell" -[node name="grow_cell_button" type="Button" parent="VBoxContainer/layout_editor/VBoxContainer"] -unique_name_in_owner = true +[node name="growth" type="HBoxContainer" parent="VBoxContainer/layout_editor/VBoxContainer"] margin_top = 72.0 margin_right = 300.0 margin_bottom = 92.0 + +[node name="grow_cell_button" type="Button" parent="VBoxContainer/layout_editor/VBoxContainer/growth"] +unique_name_in_owner = true +margin_right = 45.0 +margin_bottom = 20.0 text = "Grow" +[node name="grow_cell_style" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/growth"] +unique_name_in_owner = true +margin_left = 49.0 +margin_right = 123.0 +margin_bottom = 20.0 +text = "normal" +items = [ "normal", null, false, 0, null, "side", null, false, 1, null ] +selected = 0 + [node name="HSeparator" type="HSeparator" parent="VBoxContainer/layout_editor/VBoxContainer"] margin_top = 96.0 margin_right = 300.0 margin_bottom = 100.0 -[node name="grid_elements_corner" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"] -unique_name_in_owner = true +[node name="make_room" type="GridContainer" parent="VBoxContainer/layout_editor/VBoxContainer"] margin_top = 104.0 margin_right = 300.0 -margin_bottom = 124.0 +margin_bottom = 252.0 +columns = 2 -[node name="grid_elements_side" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"] +[node name="Label" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"] +margin_top = 3.0 +margin_right = 87.0 +margin_bottom = 17.0 +text = "corner" + +[node name="grid_elements_corner" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"] +unique_name_in_owner = true +margin_left = 91.0 +margin_right = 165.0 +margin_bottom = 20.0 + +[node name="Label2" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"] +margin_top = 27.0 +margin_right = 87.0 +margin_bottom = 41.0 +text = "side" + +[node name="grid_elements_side" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"] +unique_name_in_owner = true +margin_left = 91.0 +margin_top = 24.0 +margin_right = 165.0 +margin_bottom = 44.0 + +[node name="Label3" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"] +margin_top = 51.0 +margin_right = 87.0 +margin_bottom = 65.0 +text = "floor" + +[node name="grid_elements_floor" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"] +unique_name_in_owner = true +margin_left = 91.0 +margin_top = 48.0 +margin_right = 165.0 +margin_bottom = 68.0 + +[node name="Label4" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"] +margin_top = 77.0 +margin_right = 87.0 +margin_bottom = 91.0 +text = "width" + +[node name="make_room_width" type="SpinBox" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"] +unique_name_in_owner = true +margin_left = 91.0 +margin_top = 72.0 +margin_right = 165.0 +margin_bottom = 96.0 +min_value = 1.0 +value = 1.0 + +[node name="Label5" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"] +margin_top = 105.0 +margin_right = 87.0 +margin_bottom = 119.0 +text = "depth" + +[node name="make_room_depth" type="SpinBox" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"] +unique_name_in_owner = true +margin_left = 91.0 +margin_top = 100.0 +margin_right = 165.0 +margin_bottom = 124.0 +min_value = 1.0 +value = 1.0 + +[node name="make_room_button" type="Button" parent="VBoxContainer/layout_editor/VBoxContainer/make_room"] unique_name_in_owner = true margin_top = 128.0 -margin_right = 300.0 +margin_right = 87.0 margin_bottom = 148.0 - -[node name="grid_elements_floor" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"] -unique_name_in_owner = true -margin_top = 152.0 -margin_right = 300.0 -margin_bottom = 172.0 - -[node name="make_room_button" type="Button" parent="VBoxContainer/layout_editor/VBoxContainer"] -unique_name_in_owner = true -margin_top = 176.0 -margin_right = 300.0 -margin_bottom = 196.0 text = "Make Room" [node name="Label" type="Label" parent="VBoxContainer/layout_editor/VBoxContainer"] -margin_top = 200.0 +margin_top = 256.0 margin_right = 300.0 -margin_bottom = 214.0 +margin_bottom = 270.0 text = "Level" [node name="level_value" type="SpinBox" parent="VBoxContainer/layout_editor/VBoxContainer"] unique_name_in_owner = true -margin_top = 218.0 +margin_top = 274.0 margin_right = 300.0 -margin_bottom = 242.0 +margin_bottom = 298.0 [node name="layout_selector" type="OptionButton" parent="VBoxContainer/layout_editor/VBoxContainer"] unique_name_in_owner = true -margin_top = 246.0 +margin_top = 302.0 margin_right = 300.0 -margin_bottom = 266.0 +margin_bottom = 322.0 [node name="BuildingLayoutEditor" type="BuildingLayoutEditor" parent="."] source = ExtResource( 2 ) diff --git a/src/modules/stream/buildings/building_layout_editor.cpp b/src/modules/stream/buildings/building_layout_editor.cpp index 9a6d2b4..11c2a01 100644 --- a/src/modules/stream/buildings/building_layout_editor.cpp +++ b/src/modules/stream/buildings/building_layout_editor.cpp @@ -4,6 +4,7 @@ #include
#include #include +#include #include #include #include @@ -71,34 +72,7 @@ public: ->get_child(i) ->queue_delete(); } - List layout_keys; - int grid_size = - ElementData::get_singleton()->get_grid_size(); - assert(grid_size > 0); - int fl; - for (fl = -7; fl < 7; fl++) { - if (!ElementData::get_singleton()->has_floor( - current_layout, is_exterior, fl)) - continue; - for (i = 0; i < grid_size * grid_size; i++) { - Spatial *node = - ElementData::get_singleton() - ->get_grid_node( - current_layout, - is_exterior, fl, - i); - String element = - ElementData::get_singleton() - ->get_grid_element( - current_layout, - is_exterior, fl, - i); - editor->visualize_element_at(element, - node); - - print_line("element: " + element); - } - } + visualize_whole(current_layout, is_exterior); } editor->get_viewport()->get_camera()->set_global_translation( Vector3(-14, 23, 32)); @@ -123,7 +97,8 @@ public: EditorEvent::get_singleton()->event.remove_listener( this, &LayoutEditor::event_signal_handler); } - void event_signal_handler(const String &event, const Array &args) + void event_signal_handler(const String &event, + const Vector &args) { print_line("event: " + event); if (event == "mouse_press") { @@ -214,6 +189,8 @@ public: ->set_global_transform(base); ElementData::get_singleton()->ensure_floor( current_layout, is_exterior, current_floor); + print_line("visualize: " + itos(current_floor)); + visualize_below_and_current(current_layout, is_exterior); } void select_grid_element(int index) { @@ -248,7 +225,9 @@ public: void grow_cell() { int i; - ElementData::get_singleton()->grow_cell(current_layout, + int type = get_as_node("%grow_cell_style") + ->get_selected(); + ElementData::get_singleton()->grow_cell(type, current_layout, is_exterior, current_floor, current_cell); @@ -278,6 +257,91 @@ public: ClassDB::bind_method(D_METHOD("grow_cell"), &LayoutEditor::grow_cell); } + void clear_vis(const String &key, bool exterior) + { + int i, j; + int grid_size = ElementData::get_singleton()->get_grid_size(); + assert(grid_size > 0); + int fl; + for (fl = -7; fl < 7; fl++) { + if (!ElementData::get_singleton()->has_floor( + key, exterior, fl)) + continue; + for (i = 0; i < grid_size * grid_size; i++) { + Spatial *node = + ElementData::get_singleton() + ->get_grid_node(key, exterior, + fl, i); + for (j = 0; j < node->get_child_count(); j++) + node->get_child(j)->queue_delete(); + } + } + } + void clear_all_vis() + { + List layouts; + List::Element *e; + ElementData::get_singleton()->get_grid_layouts_key_list( + &layouts); + e = layouts.front(); + while (e) { + clear_vis(e->get(), false); + clear_vis(e->get(), true); + e = e->next(); + } + } + void visualize_whole(const String &key, bool exterior) + { + int i; + int grid_size = ElementData::get_singleton()->get_grid_size(); + assert(grid_size > 0); + int fl; + clear_all_vis(); + for (fl = -7; fl < 7; fl++) { + if (!ElementData::get_singleton()->has_floor( + key, exterior, fl)) + continue; + for (i = 0; i < grid_size * grid_size; i++) { + Spatial *node = + ElementData::get_singleton() + ->get_grid_node(key, exterior, + fl, i); + String element = + ElementData::get_singleton() + ->get_grid_element( + key, exterior, fl, i); + editor->visualize_element_at(element, node); + + print_line("element: " + element); + } + } + } + void visualize_below_and_current(const String &key, bool exterior) + { + int i; + int grid_size = ElementData::get_singleton()->get_grid_size(); + assert(grid_size > 0); + int fl; + clear_all_vis(); + for (fl = -7; fl <= current_floor; fl++) { + if (!ElementData::get_singleton()->has_floor( + key, exterior, fl)) + continue; + for (i = 0; i < grid_size * grid_size; i++) { + Spatial *node = + ElementData::get_singleton() + ->get_grid_node(key, exterior, + fl, i); + String element = + ElementData::get_singleton() + ->get_grid_element( + key, exterior, fl, i); + editor->visualize_element_at(element, node); + + print_line("element: " + element); + } + } + } }; class ElementEditor : public Object { @@ -994,6 +1058,37 @@ void BuildingLayoutEditor::visualize_element_at(const String &element, } } +Ref BuildingLayoutEditor::get_element_mesh(const String &element) const +{ + Ref ret; + int i; + for (i = 0; i < ELEMENT_SOCKETS; i++) { + SurfaceTool sf; + const String &mesh_name = + ElementData::get_singleton()->get_element_mesh_name( + element, i); + const String &element_type = + ElementData::get_singleton()->get_element_type(element); + const Transform &xform = + ElementData::get_singleton()->get_element_type_socket( + element_type, i); + Ref mesh = meshes[mesh_name].mesh; + } + return ret; +} +void BuildingLayoutEditor::update_element_meshes() +{ + List keys; + List::Element *e; + ElementData::get_singleton()->get_element_key_list(&keys); + e = keys.front(); + while (e) { + Ref mesh = get_element_mesh(e->get()); + ElementData::get_singleton()->set_element_mesh(e->get(), mesh); + e = e->next(); + } +} + static ElementTypeEditor *etype_editor; static ElementEditor *element_editor; static LayoutEditor *layout_editor; @@ -1211,10 +1306,9 @@ void BuildingLayoutEditor::_unhandled_input(const Ref &event) bool input_handled = false; if (event->is_action_pressed("mouse1")) { // if (Input::get_singleton()->is_action_just_pressed("mouse1")) { - Array args; Vector2 position = get_viewport()->get_mouse_position(); - args.push_back(position); - EditorEvent::get_singleton()->event.emit("mouse_press", args); + EditorEvent::get_singleton()->event.emit("mouse_press", + varray(position)); // } input_handled = true; } diff --git a/src/modules/stream/buildings/building_layout_editor.h b/src/modules/stream/buildings/building_layout_editor.h index 7b527e8..484e151 100644 --- a/src/modules/stream/buildings/building_layout_editor.h +++ b/src/modules/stream/buildings/building_layout_editor.h @@ -28,6 +28,10 @@ public: void visualize_element_type(const String &key, const String &test_element); void visualize_element_at(const String &element, Spatial *node); + void visualize_below_level(); + Ref get_element_mesh(const String &element) const; + + void update_element_meshes(); protected: void _notification(int which); diff --git a/src/modules/stream/buildings/element_data.cpp b/src/modules/stream/buildings/element_data.cpp index 3cad611..dd150f2 100644 --- a/src/modules/stream/buildings/element_data.cpp +++ b/src/modules/stream/buildings/element_data.cpp @@ -1,8 +1,66 @@ #undef NDEBUG #include "element_data.h" ElementData *ElementData::singleton = nullptr; -List ElementData::get_grow_cells(const String &key, bool exterior, int fl, - int cell) const +List ElementData::get_grow_cells_side(const String &key, bool exterior, + int fl, int cell) const +{ + List grow_cells; + int x = cell % grid_size; + int z = cell / grid_size; + bool grow_west = true, grow_south = true, grow_east = true, + grow_north = true; + int rotation = get_grid_rotation(key, exterior, fl, cell); + if (x == 0) + grow_west = false; + else if (x >= grid_size - 1) + grow_east = false; + if (z == 0) + grow_south = false; + else if (z >= grid_size - 1) + grow_north = false; + if (rotation == 0 || rotation == 2) { + grow_south = false; + grow_north = false; + } else if (rotation == 1 || rotation == 3) { + grow_west = false; + grow_east = false; + } + if (grow_west) { + int cell_ = (x - 1) + z * grid_size; + grow_cells.push_back(cell_); + } + if (grow_west && grow_south) { + int cell_ = (x - 1) + (z - 1) * grid_size; + grow_cells.push_back(cell_); + } + if (grow_south) { + int cell_ = x + (z - 1) * grid_size; + grow_cells.push_back(cell_); + } + if (grow_south && grow_east) { + int cell_ = (x + 1) + (z - 1) * grid_size; + grow_cells.push_back(cell_); + } + if (grow_east) { + int cell_ = (x + 1) + z * grid_size; + grow_cells.push_back(cell_); + } + if (grow_east && grow_north) { + int cell_ = (x + 1) + (z + 1) * grid_size; + grow_cells.push_back(cell_); + } + if (grow_north) { + int cell_ = x + (z + 1) * grid_size; + grow_cells.push_back(cell_); + } + if (grow_north && grow_west) { + int cell_ = (x - 1) + (z + 1) * grid_size; + grow_cells.push_back(cell_); + } + return grow_cells; +} +List ElementData::get_grow_cells_normal(const String &key, bool exterior, + int fl, int cell) const { List grow_cells; int x = cell % grid_size; @@ -51,7 +109,23 @@ List ElementData::get_grow_cells(const String &key, bool exterior, int fl, } return grow_cells; } -void ElementData::grow_cell(const String &key, bool exterior, int fl, int cell) +List ElementData::get_grow_cells(int type, const String &key, + bool exterior, int fl, int cell) const +{ + switch (type) { + case 0: + return get_grow_cells_normal(key, exterior, fl, cell); + break; + case 1: + return get_grow_cells_side(key, exterior, fl, cell); + break; + default: + return List(); + break; + } +} +void ElementData::grow_cell(int type, const String &key, bool exterior, int fl, + int cell) { List queue; List input_cells; @@ -73,7 +147,8 @@ void ElementData::grow_cell(const String &key, bool exterior, int fl, int cell) // do not place original cell in inputs if (input_cells.find(c) == nullptr) input_cells.push_back(c); - List cells = get_grow_cells(key, exterior, fl, c); + List cells = + get_grow_cells(type, key, exterior, fl, c); while (!cells.empty()) { int item = cells.front()->get(); cells.pop_front(); @@ -91,7 +166,8 @@ void ElementData::grow_cell(const String &key, bool exterior, int fl, int cell) queue.pop_front(); const String &el = get_grid_element(key, exterior, fl, c); if (el == element) { - List cells = get_grow_cells(key, exterior, fl, c); + List cells = + get_grow_cells(type, key, exterior, fl, c); while (!cells.empty()) { int g = cells.front()->get(); cells.pop_front(); @@ -120,4 +196,342 @@ void ElementData::grow_cell(const String &key, bool exterior, int fl, int cell) print_line("initial cell: " + itos(cell)); print_line("input_cells: " + itos(input_cells.size())); print_line("output_cells: " + itos(output_cells.size())); +} +void ElementData::create_new_layout(const String &key) +{ + flecs::entity top = ecs.lookup("grid_layouts"); + assert(top.is_valid()); + flecs::entity layout = ecs.entity(key.ascii().ptr()).child_of(top); + // one floor by default + layout.add(); + flecs::entity extr = ecs.entity("exterior").child_of(layout); + extr.add(); + flecs::entity intr = ecs.entity("interior").child_of(layout); + intr.add(); + intr.set({ 0 }); + extr.set({ 0 }); +} +void ElementData::create_new_exterior_floor(const String &key) +{ + int i; + flecs::entity ext = get_base(key, true); + assert(ext.is_valid()); + struct grid_layout_base *l = ext.get_mut(); + int floor = l->floor_count; + flecs::entity fl = + ecs.entity(("floor_" + itos(floor)).ascii().ptr()).child_of(ext); + assert(fl.is_valid()); + + for (i = 0; i < grid_size * grid_size; i++) { + flecs::entity item = + ecs.entity(("item_" + itos(i)).ascii().ptr()) + .child_of(fl); + item.set({ i, "empty", 0 }); + } + l->floor_count++; +} +void ElementData::create_new_interior_floor(const String &key) +{ + int i; + flecs::entity intr = get_base(key, false); + assert(intr.is_valid()); + struct grid_layout_base *l = intr.get_mut(); + int floor = l->floor_count; + flecs::entity fl = ecs.entity(("floor_" + itos(floor)).ascii().ptr()) + .child_of(intr); + assert(fl.is_valid()); + + for (i = 0; i < grid_size * grid_size; i++) { + flecs::entity item = + ecs.entity(("item_" + itos(i)).ascii().ptr()) + .child_of(fl); + item.set({ i, "empty", 0 }); + } + l->floor_count++; +} +void ElementData::serialize_layouts(Dictionary &store) +{ + flecs::entity top = ecs.lookup("grid_layouts"); + assert(top.is_valid()); + top.children([this, &store](flecs::entity l) { + Dictionary layout, exterior_layout, interior_layout; + if (l.has()) { + flecs::entity intr = l.lookup("interior"); + assert(intr.is_valid()); + flecs::entity extr = l.lookup("exterior"); + assert(extr.is_valid()); + intr.children([this, &interior_layout]( + flecs::entity intr_fl) { + if (intr_fl.has()) { + Array items; + intr_fl.children([&items]( + flecs::entity + floor_item) { + if (floor_item.has< + struct grid_floor_item>()) { + const struct grid_floor_item *item = + floor_item.get< + struct grid_floor_item>(); + Dictionary sitem; + sitem["index"] = + item->index; + sitem["element"] = + item->element; + sitem["rotation"] = + item->rotation; + items.push_back(sitem); + } + }); + String floor_key(intr_fl.name()); + interior_layout[floor_key] = items; + } + }); + extr.children([this, &exterior_layout]( + flecs::entity extr_fl) { + Array items; + extr_fl.children([&items](flecs::entity + floor_item) { + if (floor_item.has< + struct grid_floor_item>()) { + const struct grid_floor_item + *item = floor_item.get< + struct grid_floor_item>(); + Dictionary sitem; + sitem["index"] = item->index; + sitem["element"] = + item->element; + sitem["rotation"] = + item->rotation; + items.push_back(sitem); + } + }); + String floor_key(extr_fl.name()); + exterior_layout[floor_key] = items; + }); + layout["interior"] = interior_layout; + layout["exterior"] = exterior_layout; + } + String layout_name(l.name()); + store[layout_name] = layout; + }); +} +void ElementData::unserialize_layouts(const Dictionary &store) +{ + int i; + flecs::entity top = ecs.lookup("grid_layouts"); + assert(top.is_valid()); + // delete all layouts + top.children([this](flecs::entity l) { l.destruct(); }); + List layout_keys; + store.get_key_list(&layout_keys); + List::Element *e; + e = layout_keys.front(); + while (e) { + String layout_name = e->get(); + flecs::entity layout = + ecs.entity(layout_name.ascii().ptr()).child_of(top); + layout.add(); + flecs::entity extr = ecs.entity("exterior").child_of(layout); + extr.add(); + extr.set({ 0 }); + flecs::entity intr = ecs.entity("interior").child_of(layout); + intr.add(); + intr.set({ 0 }); + Dictionary store_layout = store[e->get()]; + Dictionary store_interior = store_layout["interior"]; + Dictionary store_exterior = store_layout["exterior"]; + List::Element *ve; + List interior_keys; + List exterior_keys; + store_interior.get_key_list(&interior_keys); + store_exterior.get_key_list(&exterior_keys); + for (ve = interior_keys.front(); ve; ve = ve->next()) { + String floor_key = ve->get(); + if (floor_key.begins_with("floor_")) { + flecs::entity floor_e = + ecs.entity(floor_key.ascii().ptr()) + .child_of(intr); + assert(floor_e.is_valid()); + floor_e.add(); + const Array &floor_interior = + store_interior[floor_key]; + for (i = 0; i < floor_interior.size(); i++) { + const Dictionary &item = + floor_interior[i]; + int index = item["index"]; + String element = item["element"]; + int rotation = item["rotation"]; + String item_key = "item_" + itos(index); + flecs::entity item_e = + ecs.entity(item_key.ascii() + .ptr()) + .child_of(floor_e); + item_e.set( + { index, element, rotation }); + } + struct grid_layout_base *l = + intr.get_mut(); + l->floor_count++; + } + } + for (ve = exterior_keys.front(); ve; ve = ve->next()) { + String floor_key = ve->get(); + if (floor_key.begins_with("floor_")) { + flecs::entity floor_e = + ecs.entity(floor_key.ascii().ptr()) + .child_of(extr); + assert(floor_e.is_valid()); + floor_e.add(); + const Array &floor_exterior = + store_exterior[floor_key]; + for (i = 0; i < floor_exterior.size(); i++) { + const Dictionary &item = + floor_exterior[i]; + int index = item["index"]; + String element = item["element"]; + int rotation = item["rotation"]; + String item_key = "item_" + itos(index); + flecs::entity item_e = + ecs.entity(item_key.ascii() + .ptr()) + .child_of(floor_e); + item_e.set( + { index, element, rotation }); + } + struct grid_layout_base *l = + extr.get_mut(); + l->floor_count++; + } + } + e = e->next(); + } +} +void ElementData::ensure_floor(const String &key, bool exterior, int fl) +{ + int i; + if (has_floor(key, exterior, fl)) + return; + flecs::entity base = get_base(key, exterior); + flecs::entity floor_e = + ecs.entity(("floor_" + itos(fl)).ascii().ptr()).child_of(base); + assert(floor_e.is_valid()); + for (i = 0; i < grid_size * grid_size; i++) { + flecs::entity item = + ecs.entity(("item_" + itos(i)).ascii().ptr()) + .child_of(floor_e); + item.set({ i, "empty", 0 }); + } + assert(has_floor(key, exterior, fl)); + print_line("ensured floor: " + itos(fl)); +} +void ElementData::load_data() +{ + int i; + ConfigFile config; + Dictionary conf_element_types; + Dictionary conf_elements; + Dictionary conf_grid_layouts; + List keys; + List::Element *e; + elements.clear(); + element_type.clear(); + config.load("res://astream/blayout.conf"); + conf_element_types = config.get_value("buildings_layout", + "element_types", Dictionary()); + conf_elements = + config.get_value("buildings_layout", "elements", Dictionary()); + conf_grid_layouts = config.get_value("buildings_layout", "grid_layouts", + Dictionary()); + conf_element_types.get_key_list(&keys); + e = keys.front(); + while (e) { + String key = e->get(); + Dictionary item = conf_element_types[key]; + assert(item.has("sockets")); + create_element_type(key); + Array sockets = item["sockets"]; + for (i = 0; i < sockets.size(); i++) + set_element_type_socket(key, i, sockets[i]); + e = e->next(); + } + keys.clear(); + conf_elements.get_key_list(&keys); + e = keys.front(); + while (e) { + String key = e->get(); + Dictionary item = conf_elements[key]; + assert(item.has("type")); + assert(item.has("mesh_names")); + String type = item["type"]; + print_line("loading element: " + key + " type: " + type); + if (key == "empty") { + e = e->next(); + continue; + } + create_element(key, type); + Array mesh_names = item["mesh_names"]; + for (i = 0; i < mesh_names.size(); i++) + set_element_mesh_name(key, i, mesh_names[i]); + e = e->next(); + } + unserialize_layouts(conf_grid_layouts); +} +void ElementData::save_data() +{ + int i; + ConfigFile config; + Dictionary conf_element_types; + Dictionary conf_elements; + Dictionary conf_exterior_grid; + List keys; + List::Element *e; + element_type.get_key_list(&keys); + e = keys.front(); + while (e) { + Dictionary item; + const struct grid_element_type &g = element_type[e->get()]; + if (e->get() == "empty") { + e = e->next(); + continue; + } + item["name"] = e->get(); + Array sockets; + sockets.resize(ELEMENT_SOCKETS); + for (i = 0; i < ELEMENT_SOCKETS; i++) + sockets[i] = g.sockets[i]; + item["sockets"] = sockets; + + conf_element_types[e->get()] = item; + e = e->next(); + } + keys.clear(); + elements.get_key_list(&keys); + e = keys.front(); + while (e) { + Dictionary item; + const struct grid_element &g = elements[e->get()]; + if (e->get() == "empty") { + e = e->next(); + continue; + } + item["name"] = e->get(); + item["type"] = g.type; + Array mesh_names; + mesh_names.resize(ELEMENT_SOCKETS); + for (i = 0; i < ELEMENT_SOCKETS; i++) + mesh_names[i] = g.mesh_names[i]; + item["mesh_names"] = mesh_names; + + conf_elements[e->get()] = item; + e = e->next(); + } + // TODO: support multiple layouts; + serialize_layouts(conf_exterior_grid); + + config.set_value("buildings_layout", "element_types", + conf_element_types); + config.set_value("buildings_layout", "elements", conf_elements); + config.set_value("buildings_layout", "grid_layouts", + conf_exterior_grid); + config.save("res://astream/blayout.conf"); } \ No newline at end of file diff --git a/src/modules/stream/buildings/element_data.h b/src/modules/stream/buildings/element_data.h index 52af0c1..fc32e8b 100644 --- a/src/modules/stream/buildings/element_data.h +++ b/src/modules/stream/buildings/element_data.h @@ -6,6 +6,7 @@ #include #include #include +#include "editor_event.h" template T *get_as_node(const String &path) { Node *scene; @@ -80,6 +81,7 @@ public: String name; String type; String mesh_names[ELEMENT_SOCKETS]; + Ref element_mesh; }; int grid_step{ 4 }; int grid_size{ 9 }; @@ -140,69 +142,22 @@ protected: HashMap elements; public: - List get_grow_cells(const String &key, bool exterior, int fl, - int cell) const; - void grow_cell(const String &key, bool exterior, int fl, int cell); - void create_new_layout(const String &key) - { - flecs::entity top = ecs.lookup("grid_layouts"); - assert(top.is_valid()); - flecs::entity layout = - ecs.entity(key.ascii().ptr()).child_of(top); - // one floor by default - layout.add(); - flecs::entity extr = ecs.entity("exterior").child_of(layout); - extr.add(); - flecs::entity intr = ecs.entity("interior").child_of(layout); - intr.add(); - intr.set({ 0 }); - extr.set({ 0 }); - } - void create_new_exterior_floor(const String &key) - { - int i; - flecs::entity ext = get_base(key, true); - assert(ext.is_valid()); - struct grid_layout_base *l = ext.get_mut(); - int floor = l->floor_count; - flecs::entity fl = - ecs.entity(("floor_" + itos(floor)).ascii().ptr()) - .child_of(ext); - assert(fl.is_valid()); - - for (i = 0; i < grid_size * grid_size; i++) { - flecs::entity item = - ecs.entity(("item_" + itos(i)).ascii().ptr()) - .child_of(fl); - item.set({ i, "empty", 0 }); - } - l->floor_count++; - } - void create_new_interior_floor(const String &key) - { - int i; - flecs::entity intr = get_base(key, false); - assert(intr.is_valid()); - struct grid_layout_base *l = intr.get_mut(); - int floor = l->floor_count; - flecs::entity fl = - ecs.entity(("floor_" + itos(floor)).ascii().ptr()) - .child_of(intr); - assert(fl.is_valid()); - - for (i = 0; i < grid_size * grid_size; i++) { - flecs::entity item = - ecs.entity(("item_" + itos(i)).ascii().ptr()) - .child_of(fl); - item.set({ i, "empty", 0 }); - } - l->floor_count++; - } + List get_grow_cells_side(const String &key, bool exterior, int fl, + int cell) const; + List get_grow_cells_normal(const String &key, bool exterior, + int fl, int cell) const; + List get_grow_cells(int type, const String &key, bool exterior, + int fl, int cell) const; + void grow_cell(int type, const String &key, bool exterior, int fl, + int cell); + void create_new_layout(const String &key); + void create_new_exterior_floor(const String &key); + void create_new_interior_floor(const String &key); inline int constexpr get_grid_size() { return grid_size; } - flecs::entity get_base(const String &key, bool exterior) const + inline flecs::entity get_base(const String &key, bool exterior) const { flecs::entity top = ecs.lookup("grid_layouts"); assert(top.is_valid()); @@ -215,7 +170,8 @@ public: base = layout.lookup("interior"); return base; } - flecs::entity get_floor(const String &key, bool exterior, int fl) const + inline flecs::entity get_floor(const String &key, bool exterior, + int fl) const { flecs::entity base = get_base(key, exterior); assert(base.is_valid()); @@ -223,7 +179,7 @@ public: flecs::entity floor_e = base.lookup(floor_key.ascii().ptr()); return floor_e; } - bool has_floor(const String &key, bool exterior, int fl) const + inline bool has_floor(const String &key, bool exterior, int fl) const { flecs::entity floor_e = get_floor(key, exterior, fl); if (!floor_e.is_valid()) @@ -231,25 +187,7 @@ public: flecs::entity item_e = floor_e.lookup("item_0"); return item_e.is_valid(); } - void ensure_floor(const String &key, bool exterior, int fl) - { - int i; - if (has_floor(key, exterior, fl)) - return; - flecs::entity base = get_base(key, exterior); - flecs::entity floor_e = - ecs.entity(("floor_" + itos(fl)).ascii().ptr()) - .child_of(base); - assert(floor_e.is_valid()); - for (i = 0; i < grid_size * grid_size; i++) { - flecs::entity item = - ecs.entity(("item_" + itos(i)).ascii().ptr()) - .child_of(floor_e); - item.set({ i, "empty", 0 }); - } - assert(has_floor(key, exterior, fl)); - print_line("ensured floor: " + itos(fl)); - } + void ensure_floor(const String &key, bool exterior, int fl); inline flecs::entity get_grid_entity(const String &key, bool exterior, int fl, int i) const { @@ -352,183 +290,8 @@ public: keys->push_back(String(e.name())); }); } - void serialize_layouts(Dictionary &store) - { - flecs::entity top = ecs.lookup("grid_layouts"); - assert(top.is_valid()); - top.children([this, &store](flecs::entity l) { - Dictionary layout, exterior_layout, interior_layout; - if (l.has()) { - flecs::entity intr = l.lookup("interior"); - assert(intr.is_valid()); - flecs::entity extr = l.lookup("exterior"); - assert(extr.is_valid()); - intr.children([this, &interior_layout]( - flecs::entity intr_fl) { - if (intr_fl.has()) { - Array items; - intr_fl.children([&items]( - flecs::entity - floor_item) { - if (floor_item.has< - struct grid_floor_item>()) { - const struct grid_floor_item *item = - floor_item - .get(); - Dictionary sitem; - sitem["index"] = - item->index; - sitem["element"] = - item->element; - sitem["rotation"] = - item->rotation; - items.push_back( - sitem); - } - }); - String floor_key( - intr_fl.name()); - interior_layout[floor_key] = - items; - } - }); - extr.children([this, &exterior_layout]( - flecs::entity extr_fl) { - Array items; - extr_fl.children([&items]( - flecs::entity - floor_item) { - if (floor_item.has< - struct grid_floor_item>()) { - const struct grid_floor_item *item = - floor_item.get< - struct grid_floor_item>(); - Dictionary sitem; - sitem["index"] = - item->index; - sitem["element"] = - item->element; - sitem["rotation"] = - item->rotation; - items.push_back(sitem); - } - }); - String floor_key(extr_fl.name()); - exterior_layout[floor_key] = items; - }); - layout["interior"] = interior_layout; - layout["exterior"] = exterior_layout; - } - String layout_name(l.name()); - store[layout_name] = layout; - }); - } - void unserialize_layouts(const Dictionary &store) - { - int i; - flecs::entity top = ecs.lookup("grid_layouts"); - assert(top.is_valid()); - // delete all layouts - top.children([this](flecs::entity l) { l.destruct(); }); - List layout_keys; - store.get_key_list(&layout_keys); - List::Element *e; - e = layout_keys.front(); - while (e) { - String layout_name = e->get(); - flecs::entity layout = - ecs.entity(layout_name.ascii().ptr()) - .child_of(top); - layout.add(); - flecs::entity extr = - ecs.entity("exterior").child_of(layout); - extr.add(); - extr.set({ 0 }); - flecs::entity intr = - ecs.entity("interior").child_of(layout); - intr.add(); - intr.set({ 0 }); - Dictionary store_layout = store[e->get()]; - Dictionary store_interior = store_layout["interior"]; - Dictionary store_exterior = store_layout["exterior"]; - List::Element *ve; - List interior_keys; - List exterior_keys; - store_interior.get_key_list(&interior_keys); - store_exterior.get_key_list(&exterior_keys); - for (ve = interior_keys.front(); ve; ve = ve->next()) { - String floor_key = ve->get(); - if (floor_key.begins_with("floor_")) { - flecs::entity floor_e = - ecs.entity(floor_key.ascii() - .ptr()) - .child_of(intr); - assert(floor_e.is_valid()); - floor_e.add(); - const Array &floor_interior = - store_interior[floor_key]; - for (i = 0; i < floor_interior.size(); - i++) { - const Dictionary &item = - floor_interior[i]; - int index = item["index"]; - String element = - item["element"]; - int rotation = item["rotation"]; - String item_key = - "item_" + itos(index); - flecs::entity item_e = - ecs.entity(item_key.ascii() - .ptr()) - .child_of( - floor_e); - item_e.set( - { index, element, - rotation }); - } - struct grid_layout_base *l = intr.get_mut< - struct grid_layout_base>(); - l->floor_count++; - } - } - for (ve = exterior_keys.front(); ve; ve = ve->next()) { - String floor_key = ve->get(); - if (floor_key.begins_with("floor_")) { - flecs::entity floor_e = - ecs.entity(floor_key.ascii() - .ptr()) - .child_of(extr); - assert(floor_e.is_valid()); - floor_e.add(); - const Array &floor_exterior = - store_exterior[floor_key]; - for (i = 0; i < floor_exterior.size(); - i++) { - const Dictionary &item = - floor_exterior[i]; - int index = item["index"]; - String element = - item["element"]; - int rotation = item["rotation"]; - String item_key = - "item_" + itos(index); - flecs::entity item_e = - ecs.entity(item_key.ascii() - .ptr()) - .child_of( - floor_e); - item_e.set( - { index, element, - rotation }); - } - struct grid_layout_base *l = extr.get_mut< - struct grid_layout_base>(); - l->floor_count++; - } - } - e = e->next(); - } - } + void serialize_layouts(Dictionary &store); + void unserialize_layouts(const Dictionary &store); void get_element_type_key_list(List *keys) { element_type.get_key_list(keys); @@ -574,12 +337,16 @@ public: g.name = key; g.type = type; elements[key] = g; + EditorEvent::get_singleton()->event.emit("elements_update", + varray(key)); } void set_element_type(const String &key, const String &type) { assert(elements.has(key)); assert(element_type.has(type)); elements[key].type = type; + EditorEvent::get_singleton()->event.emit("elements_update", + varray(key)); } const String &get_element_type(const String &key) const { @@ -592,6 +359,8 @@ public: assert(elements.has(key)); assert(socket >= 0 && socket < ELEMENT_SOCKETS); elements[key].mesh_names[socket] = mesh_name; + EditorEvent::get_singleton()->event.emit("elements_update", + varray(key)); } const String &get_element_mesh_name(const String &key, int socket) { @@ -599,7 +368,7 @@ public: assert(socket >= 0 && socket < ELEMENT_SOCKETS); return elements[key].mesh_names[socket]; } - int get_element_size() + inline int get_element_size() const { return elements.size(); } @@ -607,123 +376,20 @@ public: { elements.get_key_list(keys); } - bool has_element(const String &key) + inline bool has_element(const String &key) const { return elements.has(key); } - void save_data() + Ref get_element_mesh(const String &element) const { - int i; - ConfigFile config; - Dictionary conf_element_types; - Dictionary conf_elements; - Dictionary conf_exterior_grid; - List keys; - List::Element *e; - element_type.get_key_list(&keys); - e = keys.front(); - while (e) { - Dictionary item; - const struct grid_element_type &g = - element_type[e->get()]; - if (e->get() == "empty") { - e = e->next(); - continue; - } - item["name"] = e->get(); - Array sockets; - sockets.resize(ELEMENT_SOCKETS); - for (i = 0; i < ELEMENT_SOCKETS; i++) - sockets[i] = g.sockets[i]; - item["sockets"] = sockets; - - conf_element_types[e->get()] = item; - e = e->next(); - } - keys.clear(); - elements.get_key_list(&keys); - e = keys.front(); - while (e) { - Dictionary item; - const struct grid_element &g = elements[e->get()]; - if (e->get() == "empty") { - e = e->next(); - continue; - } - item["name"] = e->get(); - item["type"] = g.type; - Array mesh_names; - mesh_names.resize(ELEMENT_SOCKETS); - for (i = 0; i < ELEMENT_SOCKETS; i++) - mesh_names[i] = g.mesh_names[i]; - item["mesh_names"] = mesh_names; - - conf_elements[e->get()] = item; - e = e->next(); - } - // TODO: support multiple layouts; - serialize_layouts(conf_exterior_grid); - - config.set_value("buildings_layout", "element_types", - conf_element_types); - config.set_value("buildings_layout", "elements", conf_elements); - config.set_value("buildings_layout", "grid_layouts", - conf_exterior_grid); - config.save("res://astream/blayout.conf"); + return elements[element].element_mesh; } - void load_data() + void set_element_mesh(const String &element, const Ref &mesh) { - int i; - ConfigFile config; - Dictionary conf_element_types; - Dictionary conf_elements; - Dictionary conf_grid_layouts; - List keys; - List::Element *e; - elements.clear(); - element_type.clear(); - config.load("res://astream/blayout.conf"); - conf_element_types = config.get_value( - "buildings_layout", "element_types", Dictionary()); - conf_elements = config.get_value("buildings_layout", "elements", - Dictionary()); - conf_grid_layouts = config.get_value( - "buildings_layout", "grid_layouts", Dictionary()); - conf_element_types.get_key_list(&keys); - e = keys.front(); - while (e) { - String key = e->get(); - Dictionary item = conf_element_types[key]; - assert(item.has("sockets")); - create_element_type(key); - Array sockets = item["sockets"]; - for (i = 0; i < sockets.size(); i++) - set_element_type_socket(key, i, sockets[i]); - e = e->next(); - } - keys.clear(); - conf_elements.get_key_list(&keys); - e = keys.front(); - while (e) { - String key = e->get(); - Dictionary item = conf_elements[key]; - assert(item.has("type")); - assert(item.has("mesh_names")); - String type = item["type"]; - print_line("loading element: " + key + - " type: " + type); - if (key == "empty") { - e = e->next(); - continue; - } - create_element(key, type); - Array mesh_names = item["mesh_names"]; - for (i = 0; i < mesh_names.size(); i++) - set_element_mesh_name(key, i, mesh_names[i]); - e = e->next(); - } - unserialize_layouts(conf_grid_layouts); + elements[element].element_mesh = mesh; } + void save_data(); + void load_data(); }; #endif \ No newline at end of file diff --git a/src/modules/stream/buildings_editor.cpp b/src/modules/stream/buildings_editor.cpp index e9f6b53..6683f74 100644 --- a/src/modules/stream/buildings_editor.cpp +++ b/src/modules/stream/buildings_editor.cpp @@ -74,7 +74,7 @@ protected: } private: - void handle_event(const String &event, const Array &args) + void handle_event(const String &event, const Vector &args) { if (event == "buildings_building_cursor_moved") { Vector3 position = args[0]; @@ -143,13 +143,11 @@ private: xform.origin.y = position_y->get_text().to_float(); xform.origin.z = position_z->get_text().to_float(); String key = editor->get_selected_building(); - Array args; - args.push_back(key); - args.push_back(xform); int mode = editor->get_buildings_editor_mode(); if (mode == 1 || mode == 2) editor->set_cursor_position(xform.origin); - editor->emit("run_update_building_transform", args); + editor->emit("run_update_building_transform", + varray(key, xform)); } void handle_update() { @@ -269,7 +267,7 @@ class HandleButton : public Object { BuildingsEditor *editor; String button_path; String event_string; - Array event_args; + Vector event_args; Button *get_button() { Button *button = editor->get_as_node