Building skeleton generation done

This commit is contained in:
2024-11-04 04:26:43 +03:00
parent f474ada828
commit bfa2621dee
6 changed files with 891 additions and 490 deletions

View File

@@ -27,6 +27,8 @@ commands = [
[2, "Attach2"], [2, "Attach2"],
[3, "Left90"], [3, "Left90"],
[4, "Right90"], [4, "Right90"],
[5, "Forward", {"amount": "float"}] [5, "Motion", {"amount": "float"}],
[6, "PushPosition"],
[7, "PopPosition"]
] ]

View File

@@ -1,149 +1,128 @@
[layouts] [layouts]
entries=[ { entries=[ {
"children": [ 3 ], "children": [ 3, 4 ],
"commands": [ [ 1, [ ] ], [ 2, [ ] ], [ 1, [ ] ], [ 2, [ ] ] ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"floor_index": 0,
"index": 0, "index": 0,
"name": "v2", "name": "v2",
"order": 0, "order": 0,
"type": "layout" "type": "layout"
}, { }, {
"children": [ 4, 5, 6 ], "children": [ 5, 6, 7 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"floor_index": 0, "floor_index": 0,
"index": 1, "index": 1,
"name": "v1", "name": "v1",
"order": 0, "order": 0,
"type": "layout" "type": "layout"
}, { }, {
"children": [ 7, 8, 9, 10, 11 ], "children": [ 8, 9, 10, 11, 12 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"floor_index": 0, "floor_index": 0,
"index": 2, "index": 2,
"name": "v3", "name": "v3",
"order": 0, "order": 0,
"type": "layout" "type": "layout"
}, { }, {
"children": [ 12 ], "children": [ 13, 14 ],
"commands": [ [ 1, [ ] ], [ 2, [ ] ], [ 1, [ ] ], [ 2, [ ] ] ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 3, "index": 3,
"name": "zone_0", "name": "zone_0",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
"zone_type": 1 "zone_type": 1
}, { }, {
"children": [ 13, 14, 15, 16 ], "children": [ 15, 16, 17 ],
"commands": [ ], "commands": [ [ 4, [ ] ] ],
"index": 4, "index": 4,
"name": "zone_1", "name": "zone_1",
"order": 1,
"type": "zone",
"zone_type": 0
}, {
"children": [ 18, 19, 20, 21 ],
"commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 5,
"name": "zone_1",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
"zone_type": 1 "zone_type": 1
}, { }, {
"children": [ 17, 18, 19 ], "children": [ 22, 23, 24 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 5, "index": 6,
"name": "zone_0", "name": "zone_0",
"order": 1, "order": 1,
"type": "zone", "type": "zone",
"zone_type": 0 "zone_type": 0
}, { }, {
"children": [ 20, 21 ], "children": [ 25, 26 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 6, "index": 7,
"name": "unit_0", "name": "unit_0",
"order": 3, "order": 3,
"type": "unit" "type": "unit"
}, { }, {
"children": [ 22, 23 ], "children": [ 27, 28 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 7, "index": 8,
"name": "zone_0", "name": "zone_0",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
"zone_type": 1 "zone_type": 1
}, { }, {
"children": [ 24, 25 ], "children": [ 29, 30 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 8, "index": 9,
"name": "unit_0", "name": "unit_0",
"order": 0, "order": 0,
"type": "unit" "type": "unit"
}, { }, {
"children": [ 26, 27 ], "children": [ 31, 32 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 9, "index": 10,
"name": "unit_1", "name": "unit_1",
"order": 0, "order": 0,
"type": "unit" "type": "unit"
}, { }, {
"children": [ 28, 29 ], "children": [ 33, 34 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 10, "index": 11,
"name": "unit_2", "name": "unit_2",
"order": 0, "order": 0,
"type": "unit" "type": "unit"
}, { }, {
"children": [ 30, 31 ], "children": [ 35, 36 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 11, "index": 12,
"name": "unit_3", "name": "unit_3",
"order": 0, "order": 0,
"type": "unit" "type": "unit"
}, { }, {
"children": [ 32 ],
"commands": [ [ 1, [ ] ], [ 2, [ ] ], [ 1, [ ] ] ],
"index": 12,
"name": "stair_0",
"order": 0,
"room_area": 0.0,
"room_type": 305,
"type": "room",
"window": true
}, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 13, "index": 13,
"name": "living_room_0", "name": "living_room_0",
"order": 0, "order": 1,
"room_area": 144.0, "room_area": 144.0,
"room_type": 300, "room_type": 300,
"type": "room", "type": "room",
"window": true "window": true
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 14, "index": 14,
"name": "kitchen_0", "name": "kitchen_0",
"order": 1, "order": 2,
"room_area": 64.0, "room_area": 16.0,
"room_type": 302, "room_type": 302,
"type": "room", "type": "room",
"window": true "window": true
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 15, "index": 15,
"name": "storage_room_0",
"order": 2,
"room_area": 16.0,
"room_type": 307,
"type": "room",
"window": true
}, {
"children": [ ],
"commands": [ ],
"index": 16,
"name": "enterance_0",
"order": 3,
"room_area": 16.0,
"room_type": 304,
"type": "room",
"window": true
}, {
"children": [ ],
"commands": [ ],
"index": 17,
"name": "wc_0", "name": "wc_0",
"order": 0, "order": 0,
"room_area": 16.0, "room_area": 16.0,
@@ -152,8 +131,8 @@ entries=[ {
"window": false "window": false
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ], [ 3, [ ] ] ],
"index": 18, "index": 16,
"name": "bathroom_0", "name": "bathroom_0",
"order": 1, "order": 1,
"room_area": 16.0, "room_area": 16.0,
@@ -162,8 +141,8 @@ entries=[ {
"window": false "window": false
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 19, "index": 17,
"name": "bedroom_0", "name": "bedroom_0",
"order": 2, "order": 2,
"room_area": 64.0, "room_area": 64.0,
@@ -171,25 +150,95 @@ entries=[ {
"type": "room", "type": "room",
"window": true "window": true
}, { }, {
"children": [ 33, 34, 35 ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 18,
"name": "living_room_0",
"order": 0,
"room_area": 144.0,
"room_type": 300,
"type": "room",
"window": true
}, {
"children": [ ],
"commands": [ [ 5, [ ] ] ],
"index": 19,
"name": "kitchen_0",
"order": 1,
"room_area": 64.0,
"room_type": 302,
"type": "room",
"window": true
}, {
"children": [ ],
"commands": [ [ 5, [ ] ] ],
"index": 20, "index": 20,
"name": "storage_room_0",
"order": 2,
"room_area": 16.0,
"room_type": 307,
"type": "room",
"window": true
}, {
"children": [ ],
"commands": [ [ 5, [ ] ], [ 4, [ ] ] ],
"index": 21,
"name": "enterance_0",
"order": 3,
"room_area": 16.0,
"room_type": 304,
"type": "room",
"window": true
}, {
"children": [ ],
"commands": [ [ 5, [ ] ] ],
"index": 22,
"name": "wc_0",
"order": 0,
"room_area": 16.0,
"room_type": 200,
"type": "room",
"window": false
}, {
"children": [ ],
"commands": [ [ 5, [ ] ] ],
"index": 23,
"name": "bathroom_0",
"order": 1,
"room_area": 16.0,
"room_type": 201,
"type": "room",
"window": false
}, {
"children": [ ],
"commands": [ [ 5, [ ] ] ],
"index": 24,
"name": "bedroom_0",
"order": 2,
"room_area": 64.0,
"room_type": 202,
"type": "room",
"window": true
}, {
"children": [ 37, 38, 39 ],
"commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 25,
"name": "zone_0", "name": "zone_0",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
"zone_type": 0 "zone_type": 0
}, { }, {
"children": [ 36, 37 ], "children": [ 40, 41 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 21, "index": 26,
"name": "zone_1", "name": "zone_1",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
"zone_type": 1 "zone_type": 1
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 22, "index": 27,
"name": "enterance_0", "name": "enterance_0",
"order": 0, "order": 0,
"room_area": 64.0, "room_area": 64.0,
@@ -197,9 +246,9 @@ entries=[ {
"type": "room", "type": "room",
"window": true "window": true
}, { }, {
"children": [ 38 ], "children": [ 42 ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 23, "index": 28,
"name": "stair_0", "name": "stair_0",
"order": 0, "order": 0,
"room_area": 16.0, "room_area": 16.0,
@@ -207,81 +256,73 @@ entries=[ {
"type": "room", "type": "room",
"window": true "window": true
}, { }, {
"children": [ 39, 40, 41 ], "children": [ 43, 44, 45 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 24, "index": 29,
"name": "zone_0", "name": "zone_0",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
"zone_type": 0 "zone_type": 0
}, { }, {
"children": [ 42, 43 ], "children": [ 46, 47 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 25, "index": 30,
"name": "zone_1", "name": "zone_1",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
"zone_type": 1 "zone_type": 1
}, { }, {
"children": [ 44 ],
"commands": [ ],
"index": 26,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 0
}, {
"children": [ 45, 46 ],
"commands": [ ],
"index": 27,
"name": "zone_1",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ 47 ],
"commands": [ ],
"index": 28,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 0
}, {
"children": [ 48 ], "children": [ 48 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 29, "index": 31,
"name": "zone_1",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ 49 ],
"commands": [ ],
"index": 30,
"name": "zone_0", "name": "zone_0",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
"zone_type": 0 "zone_type": 0
}, { }, {
"children": [ 50 ], "children": [ 49, 50 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 31, "index": 32,
"name": "zone_1", "name": "zone_1",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
"zone_type": 1 "zone_type": 1
}, { }, {
"children": [ 51 ], "children": [ 51 ],
"commands": [ ], "commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"floor_index": 0, "index": 33,
"index": 32, "name": "zone_0",
"name": "floor_0",
"order": 0, "order": 0,
"type": "floor" "type": "zone",
"zone_type": 0
}, {
"children": [ 52 ],
"commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 34,
"name": "zone_1",
"order": 1,
"type": "zone",
"zone_type": 1
}, {
"children": [ 53 ],
"commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 35,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 0
}, {
"children": [ 54 ],
"commands": [ [ 3, [ ] ], [ 4, [ ] ] ],
"index": 36,
"name": "zone_1",
"order": 1,
"type": "zone",
"zone_type": 1
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 33, "index": 37,
"name": "bathroom_0", "name": "bathroom_0",
"order": 0, "order": 0,
"room_area": 16.0, "room_area": 16.0,
@@ -290,18 +331,18 @@ entries=[ {
"window": false "window": false
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 34, "index": 38,
"name": "wc_0", "name": "wc_0",
"order": 1, "order": 1,
"room_area": 4.0, "room_area": 16.0,
"room_type": 200, "room_type": 200,
"type": "room", "type": "room",
"window": false "window": false
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 35, "index": 39,
"name": "bedroom_0", "name": "bedroom_0",
"order": 2, "order": 2,
"room_area": 36.0, "room_area": 36.0,
@@ -310,8 +351,8 @@ entries=[ {
"window": true "window": true
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 36, "index": 40,
"name": "living_room_0", "name": "living_room_0",
"order": 0, "order": 0,
"room_area": 36.0, "room_area": 36.0,
@@ -320,8 +361,8 @@ entries=[ {
"window": true "window": true
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 37, "index": 41,
"name": "kitchen_0", "name": "kitchen_0",
"order": 1, "order": 1,
"room_area": 16.0, "room_area": 16.0,
@@ -329,47 +370,47 @@ entries=[ {
"type": "room", "type": "room",
"window": true "window": true
}, { }, {
"children": [ 52, 53 ], "children": [ 55, 56 ],
"commands": [ ], "commands": [ ],
"floor_index": 1, "floor_index": 1,
"index": 38, "index": 42,
"name": "floor_0", "name": "floor_0",
"order": 0, "order": 0,
"type": "floor" "type": "floor"
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 39, "index": 43,
"name": "bathroom_0", "name": "wc_0",
"order": 0, "order": 0,
"room_area": 16.0, "room_area": 16.0,
"room_type": 200,
"type": "room",
"window": false
}, {
"children": [ ],
"commands": [ [ 5, [ ] ] ],
"index": 44,
"name": "bathroom_0",
"order": 1,
"room_area": 16.0,
"room_type": 201, "room_type": 201,
"type": "room", "type": "room",
"window": false "window": false
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 40, "index": 45,
"name": "bedroom_0", "name": "bedroom_0",
"order": 0, "order": 2,
"room_area": 64.0, "room_area": 64.0,
"room_type": 202, "room_type": 202,
"type": "room", "type": "room",
"window": true "window": true
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 41, "index": 46,
"name": "wc_0",
"order": 0,
"room_area": 16.0,
"room_type": 200,
"type": "room",
"window": false
}, {
"children": [ ],
"commands": [ ],
"index": 42,
"name": "kitchen_0", "name": "kitchen_0",
"order": 0, "order": 0,
"room_area": 16.0, "room_area": 16.0,
@@ -378,18 +419,18 @@ entries=[ {
"window": true "window": true
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 43, "index": 47,
"name": "living_room_0", "name": "living_room_0",
"order": 0, "order": 1,
"room_area": 144.0, "room_area": 144.0,
"room_type": 300, "room_type": 300,
"type": "room", "type": "room",
"window": true "window": true
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 44, "index": 48,
"name": "bathroom_0", "name": "bathroom_0",
"order": 0, "order": 0,
"room_area": 16.0, "room_area": 16.0,
@@ -398,8 +439,8 @@ entries=[ {
"window": false "window": false
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 45, "index": 49,
"name": "kitchen_0", "name": "kitchen_0",
"order": 0, "order": 0,
"room_area": 64.0, "room_area": 64.0,
@@ -408,18 +449,18 @@ entries=[ {
"window": true "window": true
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 46, "index": 50,
"name": "living_room_0", "name": "living_room_0",
"order": 0, "order": 1,
"room_area": 64.0, "room_area": 64.0,
"room_type": 300, "room_type": 300,
"type": "room", "type": "room",
"window": true "window": true
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 47, "index": 51,
"name": "wc_0", "name": "wc_0",
"order": 0, "order": 0,
"room_area": 16.0, "room_area": 16.0,
@@ -428,8 +469,8 @@ entries=[ {
"window": false "window": false
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 48, "index": 52,
"name": "living_room_0", "name": "living_room_0",
"order": 0, "order": 0,
"room_area": 64.0, "room_area": 64.0,
@@ -438,8 +479,8 @@ entries=[ {
"window": true "window": true
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 49, "index": 53,
"name": "bathroom_0", "name": "bathroom_0",
"order": 0, "order": 0,
"room_area": 16.0, "room_area": 16.0,
@@ -448,8 +489,8 @@ entries=[ {
"window": false "window": false
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ [ 5, [ ] ] ],
"index": 50, "index": 54,
"name": "living_room_0", "name": "living_room_0",
"order": 0, "order": 0,
"room_area": 64.0, "room_area": 64.0,
@@ -457,47 +498,24 @@ entries=[ {
"type": "room", "type": "room",
"window": true "window": true
}, { }, {
"children": [ 54, 55 ], "children": [ 57 ],
"commands": [ ],
"index": 51,
"name": "unit_0",
"order": 0,
"type": "unit"
}, {
"children": [ 56 ],
"commands": [ ],
"index": 52,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ 57, 58 ],
"commands": [ ],
"index": 53,
"name": "unit_0",
"order": 0,
"type": "unit"
}, {
"children": [ ],
"commands": [ ],
"index": 54,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 0
}, {
"children": [ ],
"commands": [ ], "commands": [ ],
"index": 55, "index": 55,
"name": "zone_1", "name": "zone_0",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
"zone_type": 1 "zone_type": 1
}, { }, {
"children": [ ], "children": [ 58, 59 ],
"commands": [ ], "commands": [ ],
"index": 56, "index": 56,
"name": "unit_0",
"order": 0,
"type": "unit"
}, {
"children": [ ],
"commands": [ ],
"index": 57,
"name": "storage_room_0", "name": "storage_room_0",
"order": 0, "order": 0,
"room_area": 64.0, "room_area": 64.0,
@@ -505,17 +523,17 @@ entries=[ {
"type": "room", "type": "room",
"window": true "window": true
}, { }, {
"children": [ 59 ], "children": [ 60 ],
"commands": [ ], "commands": [ ],
"index": 57, "index": 58,
"name": "zone_0", "name": "zone_0",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
"zone_type": 0 "zone_type": 0
}, { }, {
"children": [ 60 ], "children": [ 61 ],
"commands": [ ], "commands": [ ],
"index": 58, "index": 59,
"name": "zone_1", "name": "zone_1",
"order": 0, "order": 0,
"type": "zone", "type": "zone",
@@ -523,20 +541,20 @@ entries=[ {
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ ],
"index": 59, "index": 60,
"name": "wc_0", "name": "wc_0",
"order": 0, "order": 0,
"room_area": 0.0, "room_area": 16.0,
"room_type": 200, "room_type": 200,
"type": "room", "type": "room",
"window": false "window": false
}, { }, {
"children": [ ], "children": [ ],
"commands": [ ], "commands": [ ],
"index": 60, "index": 61,
"name": "living_room_0", "name": "living_room_0",
"order": 0, "order": 0,
"room_area": 0.0, "room_area": 16.0,
"room_type": 300, "room_type": 300,
"type": "room", "type": "room",
"window": true "window": true

View File

@@ -440,7 +440,9 @@ void BuildingLayoutGraphUI::order_entered(float value, Control *item,
e.modified<WorldEditor::components::buildings_layout_order>(); e.modified<WorldEditor::components::buildings_layout_order>();
print_line("data set order"); print_line("data set order");
} }
static void *__PPP_ptr1 = nullptr;
static PopupPanel *command_editor = nullptr; static PopupPanel *command_editor = nullptr;
static void *__PPP_ptr2 = nullptr;
void BuildingLayoutGraphUI::command_entered(int index, Control *item, void BuildingLayoutGraphUI::command_entered(int index, Control *item,
const String &path) const String &path)
{ {
@@ -465,6 +467,34 @@ void BuildingLayoutGraphUI::command_entered(int index, Control *item,
} }
e.modified<WorldEditor::components::buildings_layout_commands>(); e.modified<WorldEditor::components::buildings_layout_commands>();
print_line("data set command"); print_line("data set command");
assert(__PPP_ptr1 == nullptr);
assert(__PPP_ptr2 == nullptr);
assert(Object::cast_to<Node>(command_editor) != nullptr);
assert(Object::cast_to<Control>(command_editor) != nullptr);
assert(Object::cast_to<PopupPanel>(command_editor) != nullptr);
command_editor->hide();
command_editor->queue_delete();
command_editor = nullptr;
update_graph();
}
void BuildingLayoutGraphUI::delete_command(Control *item, const String &path)
{
flecs::world ecs = BaseData::get_singleton()->get();
flecs::entity e = ecs.lookup(path.ascii().ptr());
assert(e.is_valid());
int cmd = item->get_meta("cmd");
if (cmd >= 0) {
WorldEditor::components::buildings_layout_commands *c = e.get_mut<
WorldEditor::components::buildings_layout_commands>();
c->commands.remove(cmd);
e.modified<WorldEditor::components::buildings_layout_commands>();
print_line("data delete command");
}
assert(__PPP_ptr1 == nullptr);
assert(__PPP_ptr2 == nullptr);
assert(Object::cast_to<Node>(command_editor) != nullptr);
assert(Object::cast_to<Control>(command_editor) != nullptr);
assert(Object::cast_to<PopupPanel>(command_editor) != nullptr);
command_editor->hide(); command_editor->hide();
command_editor->queue_delete(); command_editor->queue_delete();
command_editor = nullptr; command_editor = nullptr;
@@ -473,10 +503,33 @@ void BuildingLayoutGraphUI::command_entered(int index, Control *item,
void BuildingLayoutGraphUI::show_command_editor(Control *item, void BuildingLayoutGraphUI::show_command_editor(Control *item,
const String &path) const String &path)
{ {
/* TODO: command arguments */
ConfigFile config;
config.load("res://astream/building_layout.conf");
Array menu_array = config.get_value("commands", "commands", Array());
std::vector<Variant> menu_data;
int menu_count = 0;
int i;
std::vector<Dictionary> command_arguments;
for (i = 0; i < menu_array.size(); i++) {
Array entry = menu_array[i];
menu_data.push_back(entry[0]);
menu_data.push_back(entry[1]);
if (entry.size() == 2)
command_arguments.push_back(Dictionary());
else if (entry.size() == 3)
command_arguments.push_back(entry[2]);
menu_count++;
}
if (!command_editor) { if (!command_editor) {
command_editor = memnew(PopupPanel); command_editor = memnew(PopupPanel);
item->add_child(command_editor); item->add_child(command_editor);
} else { } else {
assert(__PPP_ptr1 == nullptr);
assert(__PPP_ptr2 == nullptr);
assert(Object::cast_to<Node>(command_editor) != nullptr);
assert(Object::cast_to<Control>(command_editor) != nullptr);
assert(Object::cast_to<PopupPanel>(command_editor) != nullptr);
command_editor->queue_delete(); command_editor->queue_delete();
command_editor = memnew(PopupPanel); command_editor = memnew(PopupPanel);
item->add_child(command_editor); item->add_child(command_editor);
@@ -498,17 +551,21 @@ void BuildingLayoutGraphUI::show_command_editor(Control *item,
std::vector<Variant> args = { std::vector<Variant> args = {
/* clang-format off */ /* clang-format off */
"Command:", "Command:",
"None", 3, "None", menu_count,
-1, "None",
1, "Arrach1",
2, "Attach2",
"command",
"Delete"
/* clang-format on */ /* clang-format on */
}; };
std::vector<Variant> args_append = {
/* clang-format off */
"command",
"Delete", "delete_button"
/* clang-format on */
};
args.insert(args.end(), menu_data.begin(), menu_data.end());
args.insert(args.end(), args_append.begin(), args_append.end());
HashMap<String, Object *> save_data; HashMap<String, Object *> save_data;
ui_field::ui_field_builder(item, vb, "p{h{lo#$b}}", args.data(), ui_field::ui_field_builder(item, vb, "p{h{lo#$b#$}}",
args.size(), &save_data); args.data(), args.size(),
&save_data);
assert(!save_data.empty()); assert(!save_data.empty());
List<String> keys; List<String> keys;
save_data.get_key_list(&keys); save_data.get_key_list(&keys);
@@ -527,19 +584,26 @@ void BuildingLayoutGraphUI::show_command_editor(Control *item,
ob->select(selected); ob->select(selected);
ob->connect("item_selected", this, "command_entered", ob->connect("item_selected", this, "command_entered",
varray(save_data["command"], String(e.path()))); varray(save_data["command"], String(e.path())));
Button *delete_button =
Object::cast_to<Button>(save_data["delete_button"]);
assert(delete_button);
delete_button->set_meta("cmd", cmd);
delete_button->connect("pressed", this, "delete_command",
varray(delete_button, String(e.path())));
} }
{ {
std::vector<Variant> args = { std::vector<Variant> args = {
/* clang-format off */ /* clang-format off */
"Command:", "Command:",
"None", 3, "None", menu_count,
-1, "None", };
1, "Arrach1", std::vector<Variant> args_append = {
2, "Attach2",
"command", "command",
"New" "New"
/* clang-format on */ /* clang-format on */
}; };
args.insert(args.end(), menu_data.begin(), menu_data.end());
args.insert(args.end(), args_append.begin(), args_append.end());
HashMap<String, Object *> save_data; HashMap<String, Object *> save_data;
ui_field::ui_field_builder(item, vb, "p{h{lo#$b}}", args.data(), ui_field::ui_field_builder(item, vb, "p{h{lo#$b}}", args.data(),
args.size(), &save_data); args.size(), &save_data);
@@ -556,8 +620,112 @@ void BuildingLayoutGraphUI::show_command_editor(Control *item,
ob->connect("item_selected", this, "command_entered", ob->connect("item_selected", this, "command_entered",
varray(save_data["command"], String(e.path()))); varray(save_data["command"], String(e.path())));
} }
assert(__PPP_ptr1 == nullptr);
assert(__PPP_ptr2 == nullptr);
command_editor->popup_centered(); command_editor->popup_centered();
} }
static List<Control *> update_controls;
void BuildingLayoutGraphUI::handle_event(const String &event,
const Vector<Variant> &args)
{
int i;
if (event == "button:building_layouts_create_new") {
LineEdit *line_edit = gui->get_as_node<LineEdit>(
"%building_layouts_create_text");
ItemList *item_list =
gui->get_as_node<ItemList>("%building_layout_list");
if (item_list->is_connected("item_selected", this,
"select_layout"))
item_list->disconnect("item_selected", this,
"select_layout");
String new_name = line_edit->get_text().strip_edges();
BuildingLayoutGraph::get_singleton()->create_new_layout(
new_name);
update_layout_item_list();
int selected = -1;
for (i = 0; i < item_list->get_item_count(); i++)
if (item_list->get_item_text(i) == new_name) {
selected = i;
break;
}
if (selected >= 0) {
item_list->select(selected);
select_layout(selected);
update_graph();
}
if (!item_list->is_connected("item_selected", this,
"select_layout"))
item_list->connect("item_selected", this,
"select_layout");
} else if (event == "button:building_layouts_save")
BuildingLayoutGraph::get_singleton()->save_layouts();
else if (event == "button:building_layouts_create_grid")
BuildingLayoutGraph::get_singleton()->create_interior_tilemap(
current_layout);
else if (event == "update_layout_view" ||
event == "building_layouts_layout_selected") {
update_graph();
dlg->update();
List<Control *>::Element *e = update_controls.front();
while (e) {
e->get()->update();
e = e->next();
}
}
}
void BuildingLayoutGraphUI::setup_layout_tab(Control *tab, const String &header)
{
assert(gui);
assert(tab);
std::vector<Variant> args_data = {
/* clang-format off */
header,
"Layouts:",
0, Vector2(0, 80), "building_layout_list",
"Create new layout",
"", "building_layouts_create_text", Control::SIZE_EXPAND_FILL,
"Create", "building_layouts_create_button",
"building_layouts_create_new", varray(),
"Save", "building_layouts_save_button",
"building_layouts_save", varray(),
"Build", "building_layouts_create_grid",
"building_layouts_create_grid", varray(),
Color(0.6f, 0.8f, 1.0f, 1.0f), "building_gen_display", Vector2(120, 180),
/* clang-format on */
};
HashMap<String, Object *> save_data;
ui_field::ui_field_builder(gui, tab,
"l_p{v{li.#!lh{e#+!b#!Q}b#!Qb#!Qc#.$}}",
args_data.data(), args_data.size(),
&save_data);
ColorRect *r =
Object::cast_to<ColorRect>(save_data["building_gen_display"]);
r->connect("draw", this, "draw_building_gen_display", varray(r));
update_controls.push_back(r);
}
void BuildingLayoutGraphUI::draw_building_gen_display(Control *draw)
{
print_line("draw gen display");
flecs::entity e = get_current_layout();
if (!e.is_valid())
return;
if (e.has<WorldEditor::components::buildings_layout_skeleton>()) {
const List<Pair<Vector2i, Vector2i> > &edges =
e.get<WorldEditor::components::buildings_layout_skeleton>()
->edges;
const List<Pair<Vector2i, Vector2i> >::Element *e =
edges.front();
Vector2i p(10, 10);
while (e) {
Pair<Vector2i, Vector2i> edge = e->get();
draw->draw_line(edge.first + p, edge.second + p,
Color(0, 0, 0, 1));
print_line((e->get().first.operator String()) + "->" +
(e->get().second.operator String()));
e = e->next();
}
}
}
void BuildingLayoutGraphUI::_bind_methods() void BuildingLayoutGraphUI::_bind_methods()
{ {
ClassDB::bind_method(D_METHOD("menu_pressed", "id", "button", "path"), ClassDB::bind_method(D_METHOD("menu_pressed", "id", "button", "path"),
@@ -584,6 +752,11 @@ void BuildingLayoutGraphUI::_bind_methods()
"item" "item"
"path"), "path"),
&BuildingLayoutGraphUI::command_entered); &BuildingLayoutGraphUI::command_entered);
ClassDB::bind_method(D_METHOD("delete_command", "item"
"path"),
&BuildingLayoutGraphUI::delete_command);
ClassDB::bind_method(D_METHOD("show_command_editor", "item", "path"), ClassDB::bind_method(D_METHOD("show_command_editor", "item", "path"),
&BuildingLayoutGraphUI::show_command_editor); &BuildingLayoutGraphUI::show_command_editor);
ClassDB::bind_method(D_METHOD("draw_building_gen_display", "draw"),
&BuildingLayoutGraphUI::draw_building_gen_display);
} }

View File

@@ -65,50 +65,7 @@ public:
varray(current_layout)); varray(current_layout));
print_line("select_layout: " + itos(id)); print_line("select_layout: " + itos(id));
} }
void handle_event(const String &event, const Vector<Variant> &args) void handle_event(const String &event, const Vector<Variant> &args);
{
int i;
if (event == "button:building_layouts_create_new") {
LineEdit *line_edit = gui->get_as_node<LineEdit>(
"%building_layouts_create_text");
ItemList *item_list = gui->get_as_node<ItemList>(
"%building_layout_list");
if (item_list->is_connected("item_selected", this,
"select_layout"))
item_list->disconnect("item_selected", this,
"select_layout");
String new_name = line_edit->get_text().strip_edges();
BuildingLayoutGraph::get_singleton()->create_new_layout(
new_name);
update_layout_item_list();
int selected = -1;
for (i = 0; i < item_list->get_item_count(); i++)
if (item_list->get_item_text(i) == new_name) {
selected = i;
break;
}
if (selected >= 0) {
item_list->select(selected);
select_layout(selected);
update_graph();
}
if (!item_list->is_connected("item_selected", this,
"select_layout"))
item_list->connect("item_selected", this,
"select_layout");
} else if (event == "button:building_layouts_save")
BuildingLayoutGraph::get_singleton()->save_layouts();
else if (event == "button:building_layouts_create_grid")
BuildingLayoutGraph::get_singleton()
->create_interior_tilemap(current_layout);
else if (event == "building_layouts_layout_selected") {
update_graph();
dlg->update();
} else if (event == "update_layout_view") {
update_graph();
dlg->update();
}
}
void tree_entered() void tree_entered()
{ {
if (!Engine::get_singleton()->is_editor_hint()) { if (!Engine::get_singleton()->is_editor_hint()) {
@@ -165,6 +122,7 @@ public:
const String &path); const String &path);
void order_entered(float value, Control *item, const String &path); void order_entered(float value, Control *item, const String &path);
void command_entered(int index, Control *item, const String &path); void command_entered(int index, Control *item, const String &path);
void delete_command(Control *item, const String &path);
void show_command_editor(Control *item, const String &path); void show_command_editor(Control *item, const String &path);
Vector<Vector2> buttons; Vector<Vector2> buttons;
#define DEPTH_MUL 160 #define DEPTH_MUL 160
@@ -237,30 +195,8 @@ public:
}); });
} }
} }
void setup_layout_tab(Control *tab, const String &header) void setup_layout_tab(Control *tab, const String &header);
{ void draw_building_gen_display(Control *draw);
assert(gui);
assert(tab);
std::vector<Variant> args_data = {
/* clang-format off */
header,
"Layouts:",
0, Vector2(0, 80), "building_layout_list",
"Create new layout",
"", "building_layouts_create_text", Control::SIZE_EXPAND_FILL,
"Create", "building_layouts_create_button",
"building_layouts_create_new", varray(),
"Save", "building_layouts_save_button",
"building_layouts_save", varray(),
"Build", "building_layouts_create_grid",
"building_layouts_create_grid", varray(),
Color(0.6f, 0.8f, 1.0f, 1.0f), "building_gen_display", Vector2(120, 180),
/* clang-format on */
};
ui_field::ui_field_builder(
gui, tab, "l_p{v{li.#!lh{e#+!b#!Q}b#!Qb#!Qc#.}}",
args_data.data(), args_data.size());
}
static void _bind_methods(); static void _bind_methods();
}; };

View File

@@ -7,59 +7,92 @@
#define MIN_ROOM_SIZE 16 /* 4 * 4 tiles */ #define MIN_ROOM_SIZE 16 /* 4 * 4 tiles */
struct state { struct state {
Rect2i main_rect; Vector2i start_position;
Rect2i last_rect; Vector2i current_position;
bool first; List<Pair<Vector2i, Vector2i> > edges;
int direction;
std::vector<Vector2i> directions;
List<Vector2i> positions_stack;
int count; int count;
List<Rect2i> rectangles; void left()
List<bool> windows;
struct room_data {
float area;
bool wall;
};
List<struct room_data> rooms;
Vector2i get_new_position(int way)
{ {
Vector2i ret; direction =
if (way == 0) { (direction - 1 + directions.size()) % directions.size();
ret.x = last_rect.position.x + last_rect.size.x; }
ret.y = last_rect.position.y; void right()
} else { {
ret.x = last_rect.position.x; direction = (direction + 1) % directions.size();
ret.y = last_rect.position.y + last_rect.size.y; }
void left90()
{
left();
left();
}
void right90()
{
right();
right();
}
void push_position()
{
positions_stack.push_back(current_position);
}
void pop_position()
{
if (!positions_stack.empty()) {
current_position = positions_stack.back()->get();
positions_stack.pop_back();
} }
return ret;
} }
Vector2i get_new_size(int way, float area) void motion(int amount)
{ {
Vector2i ret; assert(amount > 0);
if (way == 0) { Vector2i p1 = current_position;
ret.y = last_rect.size.y; Vector2i p2 = p1 + directions[direction] * amount;
ret.x = area / last_rect.size.y; assert(p1 != p2);
} else { edges.push_back(Pair<Vector2i, Vector2i>(p1, p2));
ret.x = last_rect.size.x; current_position = p2;
ret.y = area / last_rect.size.x; }
void run_command(int command, Vector<Variant> args)
{
switch (command) {
case 3:
left90();
break;
case 4:
right90();
break;
case 5: {
assert(args.size() > 0);
int amount = args[0];
assert(amount > 0);
motion(amount);
} break;
default:
print_error("unknown command: " + itos(command));
break;
} }
return ret; count++;
} }
void add_rect(const Rect2i &rect, bool window) state(const Vector2i &start)
: start_position(start)
, current_position(start)
, direction(0)
, count(0)
{ {
rectangles.push_back(rect); directions = {
windows.push_back(window); Vector2i(0, 1), Vector2i(1, 1), Vector2i(1, 0),
} Vector2i(1, -1), Vector2i(0, -1), Vector2i(-1, -1),
void pack_room(float area, bool wall) Vector2i(-1, 0), Vector2i(-1, 1),
{ };
rooms.push_back({ area, wall });
}
void next()
{
last_rect = main_rect;
} }
void dump() void dump()
{ {
List<Rect2i>::Element *e = rectangles.front(); List<Pair<Vector2i, Vector2i> >::Element *e = edges.front();
while (e) { while (e) {
print_line(e->get().operator String()); print_line(
"edge: " + (e->get().first.operator String()) +
" -> " + (e->get().second.operator String()));
e = e->next(); e = e->next();
} }
} }
@@ -77,11 +110,33 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
ecs.component<WorldEditor::components::buildings_layout_floor>(); ecs.component<WorldEditor::components::buildings_layout_floor>();
ecs.component<WorldEditor::components::buildings_layout_floor_index>(); ecs.component<WorldEditor::components::buildings_layout_floor_index>();
const String &module_name = "::BuildingLayoutGraph::graph_module"; const String &module_name = "::BuildingLayoutGraph::graph_module";
flecs::entity GraphSolveZones = ecs.entity("GraphSolveZones")
.add(flecs::Phase)
.depends_on(flecs::OnUpdate);
GraphSolveZones.disable();
flecs::entity GraphSolveUnits = ecs.entity("GraphSolveUnits")
.add(flecs::Phase)
.depends_on(GraphSolveZones);
flecs::entity GraphSolveFloors = ecs.entity("GraphSolveFloors")
.add(flecs::Phase)
.depends_on(GraphSolveUnits);
flecs::entity GraphSolve = ecs.entity("GraphSolve")
.add(flecs::Phase)
.depends_on(GraphSolveFloors);
flecs::entity GraphPostSolve = ecs.entity("GraphPostSolve")
.add(flecs::Phase)
.depends_on(flecs::PostUpdate);
GraphPostSolve.disable();
ecs.system("ZonesStart")
.kind(GraphSolveZones)
.run([module_name](flecs::iter &it) {
print_line("Processing zones...");
});
ecs.system<WorldEditor::components::buildings_layout_floor_index, ecs.system<WorldEditor::components::buildings_layout_floor_index,
const WorldEditor::components::buildings_layout_floor>( const WorldEditor::components::buildings_layout_floor>(
"FloorIndex") "FloorIndex")
.kind(0) .kind(GraphSolveZones)
.write<WorldEditor::components::buildings_layout_floor_index>() .write<WorldEditor::components::buildings_layout_floor_index>()
.each([](flecs::iter &it, size_t count, .each([](flecs::iter &it, size_t count,
WorldEditor::components::buildings_layout_floor_index WorldEditor::components::buildings_layout_floor_index
@@ -103,57 +158,43 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
qe.set<WorldEditor::components:: qe.set<WorldEditor::components::
buildings_layout_floor_index>( buildings_layout_floor_index>(
{ index.index }); { index.index });
print_line(String(qe.path()) +
" index set");
qe.children([&queue](flecs::entity ec) { qe.children([&queue](flecs::entity ec) {
queue.push_back(ec); queue.push_back(ec);
}); });
} }
} }
print_line("floor index done");
}); });
ecs.system<WorldEditor::components::buildings_layout_room>("RoomArea") ecs.system<WorldEditor::components::buildings_layout_room>("RoomArea")
.kind(0) .kind(GraphSolveZones)
.without<WorldEditor::components::buildings_layout_area>() .without<WorldEditor::components::buildings_layout_area>()
.write<WorldEditor::components::buildings_layout_area>() .write<WorldEditor::components::buildings_layout_area>()
.each([](flecs::iter &it, size_t count, .each([](flecs::iter &it, size_t count,
WorldEditor::components::buildings_layout_room &f) { WorldEditor::components::buildings_layout_room &f) {
flecs::entity floor_e = it.entity(count); flecs::entity room_e = it.entity(count);
floor_e.set< room_e.set<
WorldEditor::components::buildings_layout_area>( WorldEditor::components::buildings_layout_area>(
{ MIN_ROOM_SIZE }); { MIN_ROOM_SIZE });
}); });
ecs.system<const WorldEditor::components::buildings_layout_room,
WorldEditor::components::buildings_layout_area>("RoomArea2")
.kind(GraphSolveZones)
.write<WorldEditor::components::buildings_layout_area>()
.each([](flecs::iter &it, size_t count,
const WorldEditor::components::buildings_layout_room &f,
WorldEditor::components::buildings_layout_area &area) {
flecs::entity room_e = it.entity(count);
if (area.area < MIN_ROOM_SIZE)
area.area = MIN_ROOM_SIZE;
});
ecs.system<WorldEditor::components::buildings_layout_zone>("ZoneArea") ecs.system<WorldEditor::components::buildings_layout_zone>("ZoneArea")
.kind(0) .kind(GraphSolveZones)
.without<WorldEditor::components::buildings_layout_area>() .without<WorldEditor::components::buildings_layout_area>()
.write<WorldEditor::components::buildings_layout_area>() .write<WorldEditor::components::buildings_layout_area>()
.each([](flecs::iter &it, size_t count, .each([](flecs::iter &it, size_t count,
WorldEditor::components::buildings_layout_zone &f) { WorldEditor::components::buildings_layout_zone &f) {
flecs::entity floor_e = it.entity(count); flecs::entity zone_e = it.entity(count);
floor_e.set< zone_e.set<
WorldEditor::components::buildings_layout_area>(
{ 0.0f });
});
ecs.system<WorldEditor::components::buildings_layout_unit>("UnitArea")
.kind(0)
.without<WorldEditor::components::buildings_layout_area>()
.write<WorldEditor::components::buildings_layout_area>()
.each([](flecs::iter &it, size_t count,
WorldEditor::components::buildings_layout_unit &f) {
flecs::entity floor_e = it.entity(count);
floor_e.set<
WorldEditor::components::buildings_layout_area>(
{ 0.0f });
});
ecs.system<WorldEditor::components::buildings_layout_floor>("FloorArea")
.kind(0)
.without<WorldEditor::components::buildings_layout_area>()
.write<WorldEditor::components::buildings_layout_area>()
.each([](flecs::iter &it, size_t count,
WorldEditor::components::buildings_layout_floor &f) {
flecs::entity floor_e = it.entity(count);
floor_e.set<
WorldEditor::components::buildings_layout_area>( WorldEditor::components::buildings_layout_area>(
{ 0.0f }); { 0.0f });
}); });
@@ -161,7 +202,7 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
WorldEditor::components::buildings_layout_area, WorldEditor::components::buildings_layout_area,
WorldEditor::components::buildings_layout_floor_index>( WorldEditor::components::buildings_layout_floor_index>(
"ZoneAreaSum") "ZoneAreaSum")
.kind(0) .kind(GraphSolveZones)
.write<WorldEditor::components::buildings_layout_area>() .write<WorldEditor::components::buildings_layout_area>()
.each([](flecs::iter &it, size_t count, .each([](flecs::iter &it, size_t count,
WorldEditor::components::buildings_layout_zone &f, WorldEditor::components::buildings_layout_zone &f,
@@ -186,8 +227,9 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
.with(flecs::ChildOf, zone_e) .with(flecs::ChildOf, zone_e)
.build(); .build();
float sum = 0.0f; float sum = 0.0f;
q.each([&sum, int count_rooms = 0;
index](flecs::entity e, q.each([&sum, index, &count_rooms](
flecs::entity e,
WorldEditor::components:: WorldEditor::components::
buildings_layout_room &r, buildings_layout_room &r,
const WorldEditor::components:: const WorldEditor::components::
@@ -195,20 +237,86 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
const WorldEditor::components:: const WorldEditor::components::
buildings_layout_floor_index buildings_layout_floor_index
&rindex) { &rindex) {
if (index.index == rindex.index) if (index.index == rindex.index) {
sum += MAX(rarea.area, MIN_ROOM_SIZE); sum += MAX(rarea.area, MIN_ROOM_SIZE);
assert(sum >= 0.0f);
count_rooms++;
}
}); });
// because all room sizes > 0.0f
assert(count_rooms == 0 || sum >= 0.0f);
zone_e.set< zone_e.set<
WorldEditor::components::buildings_layout_area>( WorldEditor::components::buildings_layout_area>(
{ sum }); { sum });
print_line("area: " + String(zone_e.path()) + ": " + });
ecs.system<WorldEditor::components::buildings_layout_zone,
WorldEditor::components::buildings_layout_area,
WorldEditor::components::buildings_layout_floor_index>(
"ZoneAreaDisplay")
.kind(GraphSolveZones)
.each([](flecs::iter &it, size_t count,
WorldEditor::components::buildings_layout_zone &f,
WorldEditor::components::buildings_layout_area &area,
WorldEditor::components::buildings_layout_floor_index
&index) {
flecs::entity zone_e = it.entity(count);
float sum = area.area;
print_line("area: " + itos(count) + " " +
itos(it.field_count()) + " " +
String(zone_e.path()) + ": " +
String::num(sum)); String::num(sum));
if (count + 1 == (size_t)it.count())
print_line("end");
});
ecs.system("ZonesCheckpoint")
.kind(GraphSolveZones)
.run([module_name](flecs::iter &it) {
flecs::query<const WorldEditor::components::
buildings_layout_zone,
const WorldEditor::components::
buildings_layout_area>
q = it.world()
.query_builder<
const WorldEditor::components::
buildings_layout_zone,
const WorldEditor::components::
buildings_layout_area>()
.build();
int badness = 0;
q.each([&badness](flecs::entity e,
const WorldEditor::components::
buildings_layout_zone &zone,
const WorldEditor::components::
buildings_layout_area &area) {
if (area.area < MIN_ROOM_SIZE) {
badness++;
assert(false);
}
});
print_line("Zones processing done...");
});
ecs.system("UnitsStart")
.kind(GraphSolveZones)
.run([module_name](flecs::iter &it) {
print_line("Processing units...");
});
ecs.system<WorldEditor::components::buildings_layout_unit>("UnitArea")
.kind(GraphSolveUnits)
.without<WorldEditor::components::buildings_layout_area>()
.write<WorldEditor::components::buildings_layout_area>()
.each([](flecs::iter &it, size_t count,
WorldEditor::components::buildings_layout_unit &f) {
flecs::entity floor_e = it.entity(count);
floor_e.set<
WorldEditor::components::buildings_layout_area>(
{ 0.0f });
}); });
ecs.system<const WorldEditor::components::buildings_layout_unit, ecs.system<const WorldEditor::components::buildings_layout_unit,
WorldEditor::components::buildings_layout_area, WorldEditor::components::buildings_layout_area,
WorldEditor::components::buildings_layout_floor_index>( WorldEditor::components::buildings_layout_floor_index>(
"UnitAreaSum") "UnitAreaSum")
.kind(0) .kind(GraphSolveUnits)
.write<WorldEditor::components::buildings_layout_area>() .write<WorldEditor::components::buildings_layout_area>()
.each([](flecs::iter &it, size_t count, .each([](flecs::iter &it, size_t count,
const WorldEditor::components::buildings_layout_unit &f, const WorldEditor::components::buildings_layout_unit &f,
@@ -251,11 +359,73 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
print_line("area: " + String(unit_e.path()) + ": " + print_line("area: " + String(unit_e.path()) + ": " +
String::num(sum)); String::num(sum));
}); });
ecs.system<WorldEditor::components::buildings_layout_unit,
WorldEditor::components::buildings_layout_area,
WorldEditor::components::buildings_layout_floor_index>(
"UnitAreaDisplay")
.kind(GraphSolveUnits)
.each([](flecs::iter &it, size_t count,
WorldEditor::components::buildings_layout_unit &f,
WorldEditor::components::buildings_layout_area &area,
WorldEditor::components::buildings_layout_floor_index
&index) {
flecs::entity zone_e = it.entity(count);
float sum = area.area;
print_line("area: " + itos(count) + " " +
itos(it.field_count()) + " " +
String(zone_e.path()) + ": " +
String::num(sum));
if (count + 1 == (size_t)it.count())
print_line("end");
});
ecs.system("UnitCheckpoint")
.kind(GraphSolveUnits)
.run([module_name](flecs::iter &it) {
flecs::query<const WorldEditor::components::
buildings_layout_unit,
const WorldEditor::components::
buildings_layout_area>
q = it.world()
.query_builder<
const WorldEditor::components::
buildings_layout_unit,
const WorldEditor::components::
buildings_layout_area>()
.build();
int badness = 0;
q.each([&badness](flecs::entity e,
const WorldEditor::components::
buildings_layout_unit &zone,
const WorldEditor::components::
buildings_layout_area &area) {
if (area.area < MIN_ROOM_SIZE) {
badness++;
assert(false);
}
});
});
ecs.system("FloorsStart")
.kind(GraphSolveFloors)
.run([module_name](flecs::iter &it) {
print_line("Processing floors...");
});
ecs.system<WorldEditor::components::buildings_layout_floor>("FloorArea")
.kind(GraphSolveFloors)
.without<WorldEditor::components::buildings_layout_area>()
.write<WorldEditor::components::buildings_layout_area>()
.each([](flecs::iter &it, size_t count,
WorldEditor::components::buildings_layout_floor &f) {
flecs::entity floor_e = it.entity(count);
floor_e.set<
WorldEditor::components::buildings_layout_area>(
{ 0.0f });
});
ecs.system<const WorldEditor::components::buildings_layout_floor, ecs.system<const WorldEditor::components::buildings_layout_floor,
WorldEditor::components::buildings_layout_area, WorldEditor::components::buildings_layout_area,
WorldEditor::components::buildings_layout_floor_index>( WorldEditor::components::buildings_layout_floor_index>(
"FloorAreaSum") "FloorAreaSum")
.kind(0) .kind(GraphSolveFloors)
.write<WorldEditor::components::buildings_layout_area>() .write<WorldEditor::components::buildings_layout_area>()
.each([](flecs::iter &it, size_t count, .each([](flecs::iter &it, size_t count,
const WorldEditor::components::buildings_layout_floor const WorldEditor::components::buildings_layout_floor
@@ -297,9 +467,54 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
floor_e.set< floor_e.set<
WorldEditor::components::buildings_layout_area>( WorldEditor::components::buildings_layout_area>(
{ sum }); { sum });
print_line("area: " + String(floor_e.path()) + ": " +
String::num(sum));
}); });
ecs.system<WorldEditor::components::buildings_layout_floor,
WorldEditor::components::buildings_layout_area,
WorldEditor::components::buildings_layout_floor_index>(
"FloorAreaDisplay")
.kind(GraphSolveFloors)
.each([](flecs::iter &it, size_t count,
WorldEditor::components::buildings_layout_floor &f,
WorldEditor::components::buildings_layout_area &area,
WorldEditor::components::buildings_layout_floor_index
&index) {
flecs::entity zone_e = it.entity(count);
float sum = area.area;
print_line("area: " + itos(count) + " " +
itos(it.field_count()) + " " +
String(zone_e.path()) + ": " +
String::num(sum));
if (count + 1 == (size_t)it.count())
print_line("end");
});
ecs.system("FloorCheckpoint")
.kind(GraphSolveFloors)
.run([module_name](flecs::iter &it) {
flecs::query<const WorldEditor::components::
buildings_layout_floor,
const WorldEditor::components::
buildings_layout_area>
q = it.world()
.query_builder<
const WorldEditor::components::
buildings_layout_floor,
const WorldEditor::components::
buildings_layout_area>()
.build();
int badness = 0;
q.each([&badness](flecs::entity e,
const WorldEditor::components::
buildings_layout_floor &fl,
const WorldEditor::components::
buildings_layout_area &area) {
if (area.area < MIN_ROOM_SIZE) {
badness++;
assert(false);
}
});
print_line("Floor processing done...");
});
#if 0
ecs.system<const WorldEditor::components::buildings_layout_graph, ecs.system<const WorldEditor::components::buildings_layout_graph,
const WorldEditor::components::buildings_layout_floor_index, const WorldEditor::components::buildings_layout_floor_index,
const WorldEditor::components::buildings_layout_area>( const WorldEditor::components::buildings_layout_area>(
@@ -338,94 +553,149 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
print_line("grid size: " + print_line("grid size: " +
itos((int)Math::ceil(grid_size))); itos((int)Math::ceil(grid_size)));
}); });
ecs.system<WorldEditor::components::buildings_layout_zone>( #endif
"AssembleZones") ecs.system("AssembleSkeletonStart")
.kind(0) .kind(GraphSolve)
.each([module_name]( .run([module_name](flecs::iter &it) {
flecs::iter &it, size_t count, print_line("Assembling skeleton...");
WorldEditor::components::buildings_layout_zone &f) {
flecs::entity zone_e = it.entity(count);
flecs::query<const WorldEditor::components::
buildings_layout_order,
const WorldEditor::components::
buildings_layout_room,
const WorldEditor::components::
buildings_layout_area,
const WorldEditor::components::
buildings_layout_commands>
q = zone_e.world()
.query_builder<
const WorldEditor::components::
buildings_layout_order,
const WorldEditor::components::
buildings_layout_room,
const WorldEditor::components::
buildings_layout_area,
const WorldEditor::components::
buildings_layout_commands>()
.with(flecs::ChildOf, zone_e)
.order_by<
WorldEditor::components::
buildings_layout_order>(
[](flecs::entity_t e1,
const WorldEditor::components::
buildings_layout_order
*d1,
flecs::entity_t e2,
const WorldEditor::components::
buildings_layout_order
*d2) {
return (d1->index >
d2->index) -
(d1->index <
d2->index);
})
.build();
int c = 0;
struct state state;
state.first = true;
state.count = 0;
q.each([&c, &state](
flecs::entity e,
const WorldEditor::components::
buildings_layout_order &order,
const WorldEditor::components::
buildings_layout_room &r,
const WorldEditor::components::
buildings_layout_area &area,
const WorldEditor::components::
buildings_layout_commands &cmd) {
int i, j;
String output = String(e.path()) + "\n";
output +=
"\torder: " + itos(order.index) + "\n";
output += "\troom_type: " + itos(r.room_type) +
"\n";
output += "\twindow: " + itos(r.window) + "\n";
output += "\tarea: " + String::num(area.area) +
"\n";
output += "\tcommands: " +
itos(cmd.commands.size()) + "\n";
for (i = 0; i < cmd.commands.size(); i++) {
output +=
"\t\t" +
itos(cmd.commands[i].command) +
"\n";
for (j = 0;
j < cmd.commands[i].args.size();
j++)
output +=
"\t\t\t" +
(cmd.commands[i].args[j].
operator String()) +
"\n";
}
print_line(output);
state.pack_room(area.area, r.window);
c++;
});
state.dump();
}); });
ecs.system<const WorldEditor::components::buildings_layout_graph>(
"AssembleSkeleton")
.kind(GraphSolve)
.read<WorldEditor::components::buildings_layout_order>()
.read<WorldEditor::components::buildings_layout_area>()
.read<WorldEditor::components::buildings_layout_commands>()
.read<WorldEditor::components::buildings_layout_zone>()
.read<WorldEditor::components::buildings_layout_unit>()
.write<WorldEditor::components::buildings_layout_skeleton>()
.each([module_name](flecs::iter &it, size_t count,
const WorldEditor::components::
buildings_layout_graph &f) {
flecs::entity graph_e = it.entity(count);
List<flecs::entity> queue;
queue.push_back(graph_e);
struct state state(Vector2i(0, 0));
int badness = 0;
while (!queue.empty()) {
flecs::entity e = queue.front()->get();
queue.pop_front();
flecs::query<const WorldEditor::components::
buildings_layout_order,
const WorldEditor::components::
buildings_layout_area,
const WorldEditor::components::
buildings_layout_commands>
q = e.world()
.query_builder<
const WorldEditor::components::
buildings_layout_order,
const WorldEditor::components::
buildings_layout_area,
const WorldEditor::components::
buildings_layout_commands>()
.with(flecs::ChildOf, e)
.order_by<
WorldEditor::components::
buildings_layout_order>(
[](flecs::entity_t
e1,
const WorldEditor::
components::buildings_layout_order
*d1,
flecs::entity_t
e2,
const WorldEditor::
components::buildings_layout_order
*d2) {
return (d1->index >
d2->index) -
(d1->index <
d2->index);
})
.build();
q.each([&state, &queue, &badness](
flecs::entity ec,
const WorldEditor::components::
buildings_layout_order
&order,
const WorldEditor::components::
buildings_layout_area
&area,
const WorldEditor::components::
buildings_layout_commands
&cmd) {
int m;
for (m = 0; m < cmd.commands.size();
m++) {
int command =
cmd.commands[m].command;
switch (command) {
case 5:
if (area.area > 0) {
Vector<Variant>
args;
int motion = (int)Math::
ceil(Math::sqrt(
area.area));
print_line(
"motion command: " +
itos(motion));
args.push_back(
motion);
state.run_command(
command,
args);
} else {
print_error(
"motion command requires amount > 0 area = " +
String::num(
area.area) +
" " +
String(ec.path()));
badness++;
}
break;
default:
state.run_command(
cmd.commands[m]
.command,
cmd.commands[m]
.args);
break;
}
}
if (ec.has<WorldEditor::components::
buildings_layout_zone>() ||
ec.has<WorldEditor::components::
buildings_layout_unit>())
queue.push_back(ec);
});
if (badness > 0)
break;
}
if (badness == 0)
graph_e.set<WorldEditor::components::
buildings_layout_skeleton>(
{ state.edges });
print_line(String(graph_e.path()));
state.dump();
if (badness > 0)
print_line("BAD!");
});
ecs.system("AssembleSkeletonEnd")
.kind(GraphSolve)
.run([module_name](flecs::iter &it) {
print_line("Assembling skeleton done...");
it.world()
.lookup((module_name + "::GraphSolveZones")
.ascii()
.ptr())
.disable();
EditorEvent::get_singleton()->event.emit(
"update_layout_view", varray());
});
ecs.system<WorldEditor::components::buildings_layout_floor>( ecs.system<WorldEditor::components::buildings_layout_floor>(
"FloorCompleteArea") "FloorCompleteArea")
.kind(0) .kind(0)
@@ -440,7 +710,6 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
"UnitArea", "FloorArea", "UnitArea", "FloorArea",
"ZoneAreaSum", "UnitAreaSum", "ZoneAreaSum", "UnitAreaSum",
"FloorAreaSum", "CreateFloorData", "FloorAreaSum", "CreateFloorData",
"AssembleZones"
}; };
int i; int i;
for (i = 0; i < (int)systems.size(); i++) { for (i = 0; i < (int)systems.size(); i++) {
@@ -1052,16 +1321,16 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
&r) { &r) {
flecs::world w = e.world(); flecs::world w = e.world();
// create indices // create indices
w.system(w.lookup((module_name + "::FloorIndex") w.lookup((module_name + "::GraphSolveZones")
.ascii() .ascii()
.ptr())) .ptr())
.run(); .enable();
w.system(w.lookup((module_name + "::FloorCompleteArea") w.lookup((module_name + "::GraphSolve").ascii().ptr())
.ascii() .enable();
.ptr())) w.lookup((module_name + "::GraphPostSolve")
.run(); .ascii()
EditorEvent::get_singleton()->event.emit( .ptr())
"update_layout_view", varray()); .enable();
#if 0 #if 0
/* if set for room make zone dirty */ /* if set for room make zone dirty */
flecs::entity parent_e = e.parent(); flecs::entity parent_e = e.parent();
@@ -1105,16 +1374,16 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
buildings_layout_floor_index &r) { buildings_layout_floor_index &r) {
flecs::world w = e.world(); flecs::world w = e.world();
// create indices // create indices
w.system(w.lookup((module_name + "::FloorIndex") w.lookup((module_name + "::GraphSolveZones")
.ascii() .ascii()
.ptr())) .ptr())
.run(); .enable();
w.system(w.lookup((module_name + "::FloorCompleteArea") w.lookup((module_name + "::GraphSolve").ascii().ptr())
.ascii() .enable();
.ptr())) w.lookup((module_name + "::GraphPostSolve")
.run(); .ascii()
EditorEvent::get_singleton()->event.emit( .ptr())
"update_layout_view", varray()); .enable();
print_line(String(e.path()) + ": set floor"); print_line(String(e.path()) + ": set floor");
#if 0 #if 0
List<flecs::entity> queue; List<flecs::entity> queue;

View File

@@ -104,6 +104,9 @@ public:
struct buildings_layout_order { struct buildings_layout_order {
int index; int index;
}; };
struct buildings_layout_skeleton {
List<Pair<Vector2i, Vector2i> > edges;
};
struct buildings_layout_commands { struct buildings_layout_commands {
struct command { struct command {
int command; int command;