|
7 | 7 | using System.Threading; |
8 | 8 | using System.Threading.Tasks; |
9 | 9 | using System.Windows.Controls; |
10 | | -using Havok; |
11 | 10 | using NLog; |
12 | 11 | using Sandbox.Definitions; |
13 | 12 | using Sandbox.Engine.Multiplayer; |
|
23 | 22 | using VRage.Game; |
24 | 23 | using VRage.Game.Components; |
25 | 24 | using VRage.Game.Definitions; |
26 | | -using VRage.Game.Entity; |
27 | 25 | using VRage.Game.ModAPI; |
28 | 26 | using VRage.Game.ObjectBuilders.ComponentSystem; |
29 | 27 | using VRage.ModAPI; |
@@ -54,7 +52,7 @@ public ConcealmentPlugin() |
54 | 52 |
|
55 | 53 | UserControl IWpfPlugin.GetControl() |
56 | 54 | { |
57 | | - return _control ?? (_control = new ConcealmentControl {DataContext = this}); |
| 55 | + return _control ?? (_control = new ConcealmentControl { DataContext = this }); |
58 | 56 | } |
59 | 57 |
|
60 | 58 | public override void Init(ITorchBase torch) |
@@ -198,55 +196,17 @@ private void RevealSpawns(PlayerRequestArgs args) |
198 | 196 | }); |
199 | 197 | } |
200 | 198 |
|
201 | | - private void ConcealEntity(IMyEntity entity) |
202 | | - { |
203 | | - if (entity != entity.GetTopMostParent()) |
204 | | - return; |
205 | | - |
206 | | - entity.GetStorage().SetValue(Id, "True"); |
207 | | - MyGamePruningStructure.Remove((MyEntity)entity); |
208 | | - entity.Physics?.Deactivate(); |
209 | | - UnregisterRecursive(entity); |
210 | | - |
211 | | - void UnregisterRecursive(IMyEntity e) |
212 | | - { |
213 | | - MyEntities.UnregisterForUpdate((MyEntity)e); |
214 | | - if (e.Hierarchy == null) |
215 | | - return; |
216 | | - |
217 | | - foreach (var child in e.Hierarchy.Children) |
218 | | - UnregisterRecursive(child.Container.Entity); |
219 | | - } |
220 | | - } |
221 | | - |
222 | | - private void RevealEntity(IMyEntity entity) |
223 | | - { |
224 | | - if (entity != entity.GetTopMostParent()) |
225 | | - return; |
226 | | - |
227 | | - entity.GetStorage().SetValue(Id, "False"); |
228 | | - MyGamePruningStructure.Add((MyEntity)entity); |
229 | | - entity.Physics?.Activate(); |
230 | | - RegisterRecursive(entity); |
231 | | - |
232 | | - void RegisterRecursive(IMyEntity e) |
233 | | - { |
234 | | - MyEntities.RegisterForUpdate((MyEntity)e); |
235 | | - if (e.Hierarchy == null) |
236 | | - return; |
237 | | - |
238 | | - foreach (var child in e.Hierarchy.Children) |
239 | | - RegisterRecursive(child.Container.Entity); |
240 | | - } |
241 | | - } |
242 | 199 |
|
243 | 200 | private int ConcealGroup(ConcealGroup group) |
244 | 201 | { |
245 | 202 | if (ConcealedGroups.Any(g => g.Id == group.Id)) |
246 | 203 | return 0; |
247 | 204 |
|
248 | 205 | Log.Debug($"Concealing grids: {group.GridNames}"); |
249 | | - group.Grids.ForEach(ConcealEntity); |
| 206 | + group.Conceal(); |
| 207 | + foreach (var entity in group.Grids) |
| 208 | + entity.GetStorage().SetValue(Id, "True"); |
| 209 | + |
250 | 210 | group.UpdateAABB(); |
251 | 211 | var aabb = group.WorldAABB; |
252 | 212 | group.ProxyId = _concealedAabbTree.AddProxy(ref aabb, group, 0); |
@@ -277,7 +237,10 @@ public int RevealGroup(ConcealGroup group) |
277 | 237 |
|
278 | 238 | var count = group.Grids.Count; |
279 | 239 | Log.Debug($"Revealing grids: {group.GridNames}"); |
280 | | - group.Grids.ForEach(RevealEntity); |
| 240 | + group.Reveal(); |
| 241 | + foreach (var entity in group.Grids) |
| 242 | + entity.GetStorage().SetValue(Id, "False"); |
| 243 | + |
281 | 244 | ConcealedGroups.Remove(group); |
282 | 245 | _concealedAabbTree.RemoveProxy(group.ProxyId); |
283 | 246 | group.UpdatePostReveal(); |
|
0 commit comments