104 | function PlaceableTipOcclusionAreas:loadTipOcclusionArea(xmlFile, key, area) |
105 | local startNode = xmlFile:getValue(key .. "#startNode", nil, self.components, self.i3dMappings) |
106 | local endNode = xmlFile:getValue(key .. "#endNode", nil, self.components, self.i3dMappings) |
107 | |
108 | if startNode == nil then |
109 | Logging.xmlWarning(xmlFile, "Missing tip occlusion update area start node for '%s'", key) |
110 | return false |
111 | end |
112 | |
113 | if endNode == nil then |
114 | Logging.xmlWarning(xmlFile, "Missing tip occlusion update area end node for '%s'", key) |
115 | return false |
116 | end |
117 | |
118 | |
119 | local startX, _, startZ = localToLocal(startNode, self.rootNode, 0, 0, 0) |
120 | local endX, _, endZ = localToLocal(endNode, self.rootNode, 0, 0, 0) |
121 | |
122 | local sizeX = math.abs(endX - startX) |
123 | local sizeZ = math.abs(endZ - startZ) |
124 | |
125 | area.center = {} |
126 | area.center.x = (endX + startX) * 0.5 |
127 | area.center.z = (endZ + startZ) * 0.5 |
128 | |
129 | area.size = {} |
130 | area.size.x = sizeX |
131 | area.size.z = sizeZ |
132 | |
133 | area.startNode = startNode |
134 | area.endNode = endNode |
135 | |
136 | return true |
137 | end |
53 | function PlaceableTipOcclusionAreas:onLoad(savegame) |
54 | local spec = self.spec_tipOcclusionAreas |
55 | local xmlFile = self.xmlFile |
56 | |
57 | spec.updateTipOcclusionAreasOnDelete = false |
58 | spec.areas = {} |
59 | xmlFile:iterate("placeable.tipOcclusionUpdateAreas.tipOcclusionUpdateArea", function(_, key) |
60 | local area = {} |
61 | if self:loadTipOcclusionArea(xmlFile, key, area) then |
62 | table.insert(spec.areas, area) |
63 | end |
64 | end) |
65 | |
66 | if xmlFile:hasProperty("placeable.tipOcclusionUpdateArea") then |
67 | local sizeX = xmlFile:getValue("placeable.tipOcclusionUpdateArea#sizeX") |
68 | local sizeZ = xmlFile:getValue("placeable.tipOcclusionUpdateArea#sizeZ") |
69 | |
70 | if sizeX ~= nil and sizeZ ~= nil then |
71 | local centerX = xmlFile:getValue("placeable.tipOcclusionUpdateArea#centerX", 0) |
72 | local centerZ = xmlFile:getValue("placeable.tipOcclusionUpdateArea#centerZ", 0) |
73 | |
74 | local area = {} |
75 | area.center = {} |
76 | area.center.x = centerX |
77 | area.center.z = centerZ |
78 | |
79 | area.size = {} |
80 | area.size.x = sizeX |
81 | area.size.z = sizeZ |
82 | |
83 | table.insert(spec.areas, area) |
84 | end |
85 | end |
86 | end |
39 | function PlaceableTipOcclusionAreas.registerXMLPaths(schema, basePath) |
40 | schema:setXMLSpecializationType("TipOcclusionAreas") |
41 | schema:register(XMLValueType.FLOAT, basePath .. ".tipOcclusionUpdateArea#sizeX", "Size X") |
42 | schema:register(XMLValueType.FLOAT, basePath .. ".tipOcclusionUpdateArea#sizeZ", "Size Z") |
43 | schema:register(XMLValueType.FLOAT, basePath .. ".tipOcclusionUpdateArea#centerX", "Center position X", 0) |
44 | schema:register(XMLValueType.FLOAT, basePath .. ".tipOcclusionUpdateArea#centerZ", "Center position Z", 0) |
45 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".tipOcclusionUpdateAreas.tipOcclusionUpdateArea(?)#startNode", "Start node of tipOcclusion update area") |
46 | schema:register(XMLValueType.NODE_INDEX, basePath .. ".tipOcclusionUpdateAreas.tipOcclusionUpdateArea(?)#endNode", "End node of tipOcclusion update area") |
47 | schema:setXMLSpecializationType() |
48 | end |
155 | function PlaceableTipOcclusionAreas:updateTipOcclusionAreas() |
156 | if self.isServer then |
157 | local spec = self.spec_tipOcclusionAreas |
158 | for _, area in pairs(spec.areas) do |
159 | local x, z = area.center.x, area.center.z |
160 | local sizeX, sizeZ = area.size.x, area.size.z |
161 | |
162 | local x1, _, z1 = localToWorld(self.rootNode, x + sizeX * 0.5, 0, z + sizeZ * 0.5) |
163 | local x2, _, z2 = localToWorld(self.rootNode, x - sizeX * 0.5, 0, z + sizeZ * 0.5) |
164 | local x3, _, z3 = localToWorld(self.rootNode, x + sizeX * 0.5, 0, z - sizeZ * 0.5) |
165 | local x4, _, z4 = localToWorld(self.rootNode, x - sizeX * 0.5, 0, z - sizeZ * 0.5) |
166 | |
167 | local minX = math.min(x1, x2, x3, x4) |
168 | local maxX = math.max(x1, x2, x3, x4) |
169 | local minZ = math.min(z1, z2, z3, z4) |
170 | local maxZ = math.max(z1, z2, z3, z4) |
171 | g_densityMapHeightManager:setCollisionMapAreaDirty(minX, minZ, maxX, maxZ, true) |
172 | end |
173 | end |
174 | end |