66using System . Threading ;
77using System . Threading . Tasks ;
88using System . Windows . Controls ;
9+ using Havok ;
910using NLog ;
1011using Sandbox . Engine . Multiplayer ;
1112using Sandbox . Game . Entities ;
13+ using Sandbox . Game . EntityComponents ;
1214using Sandbox . Game . Multiplayer ;
1315using Sandbox . Game . World ;
1416using Sandbox . ModAPI ;
1719using Torch . API . Plugins ;
1820using Torch . Managers ;
1921using VRage . Game ;
22+ using VRage . Game . Components ;
2023using VRage . Game . Entity ;
2124using VRage . Game . ModAPI ;
2225using VRage . ModAPI ;
@@ -42,7 +45,6 @@ public ConcealmentPlugin()
4245 {
4346 _intersectGroups = new List < ConcealGroup > ( ) ;
4447 Settings = Persistent < Settings > . Load ( "Concealment.cfg" ) ;
45- Settings . Data . RevealNeeded += ( ) => RevealNearbyGrids ( Settings . Data . RevealDistance ) ;
4648 }
4749
4850 public UserControl GetControl ( )
@@ -135,14 +137,12 @@ private void ConcealEntity(IMyEntity entity)
135137 if ( entity != entity . GetTopMostParent ( ) )
136138 return ;
137139
138- if ( Settings . Data . ManagePhysics )
139- {
140- MyGamePruningStructure . Remove ( ( MyEntity ) entity ) ;
141- entity . Physics ? . Deactivate ( ) ;
142- }
143-
144- if ( Settings . Data . ManageGamelogic )
145- UnregisterRecursive ( entity ) ;
140+ entity . GetStorage ( ) . SetValue ( Id , "True" ) ;
141+ #if ! NOPHYS
142+ MyGamePruningStructure . Remove ( ( MyEntity ) entity ) ;
143+ entity . Physics ? . Deactivate ( ) ;
144+ #endif
145+ UnregisterRecursive ( entity ) ;
146146
147147 void UnregisterRecursive ( IMyEntity e )
148148 {
@@ -160,14 +160,12 @@ private void RevealEntity(IMyEntity entity)
160160 if ( entity != entity . GetTopMostParent ( ) )
161161 return ;
162162
163- if ( Settings . Data . ManagePhysics )
164- {
165- MyGamePruningStructure . Add ( ( MyEntity ) entity ) ;
166- entity . Physics ? . Activate ( ) ;
167- }
168-
169- if ( Settings . Data . ManageGamelogic )
170- RegisterRecursive ( entity ) ;
163+ entity . GetStorage ( ) . SetValue ( Id , "False" ) ;
164+ #if ! NOPHYS
165+ MyGamePruningStructure . Add ( ( MyEntity ) entity ) ;
166+ entity . Physics ? . Activate ( ) ;
167+ #endif
168+ RegisterRecursive ( entity ) ;
171169
172170 void RegisterRecursive ( IMyEntity e )
173171 {
@@ -185,10 +183,12 @@ private int ConcealGroup(ConcealGroup group)
185183 if ( _concealGroups . Any ( g => g . Id == group . Id ) )
186184 return 0 ;
187185
188- Log . Info ( $ "Concealing grids: { group . GridNames } ") ;
186+ Log . Debug ( $ "Concealing grids: { group . GridNames } ") ;
189187 group . Grids . ForEach ( ConcealEntity ) ;
188+ #if ! NOPHYS
190189 var aabb = group . WorldAABB ;
191190 group . ProxyId = _concealedAabbTree . AddProxy ( ref aabb , group , 0 ) ;
191+ #endif
192192 group . Closing += Group_Closing ;
193193 Task . Run ( ( ) =>
194194 {
@@ -215,15 +215,26 @@ public int RevealGroup(ConcealGroup group)
215215 }
216216 Log . Debug ( $ "Revealing grids: { group . GridNames } ") ;
217217 group . Grids . ForEach ( RevealEntity ) ;
218+ #if ! NOPHYS
218219 _concealGroups . Remove ( group ) ;
219220 _concealedAabbTree . RemoveProxy ( group . ProxyId ) ;
221+ #endif
220222 return group . Grids . Count ;
221223 }
222224
223225 public int RevealGridsInSphere ( BoundingSphereD sphere )
224226 {
225227 var revealed = 0 ;
228+ #if ! NOPHYS
226229 _concealedAabbTree . OverlapAllBoundingSphere ( ref sphere , _intersectGroups ) ;
230+ #else
231+ foreach ( var group in ConcealGroups )
232+ {
233+ group . UpdateAABB ( ) ;
234+ if ( sphere . Contains ( group . WorldAABB ) != ContainmentType . Disjoint )
235+ _intersectGroups . Add ( group ) ;
236+ }
237+ #endif
227238 foreach ( var group in _intersectGroups )
228239 revealed += RevealGroup ( group ) ;
229240
@@ -305,4 +316,12 @@ private List<BoundingSphereD> GetPlayerBoundingSpheres(double distance)
305316 return ( ( MyPlayerCollection ) MyAPIGateway . Multiplayer . Players ) . GetOnlinePlayers ( ) . Where ( p => p . Controller ? . ControlledEntity != null ) . Select ( p => new BoundingSphereD ( p . Controller . ControlledEntity . Entity . PositionComp . GetPosition ( ) , distance ) ) . ToList ( ) ;
306317 }
307318 }
319+
320+ public static class Extensions
321+ {
322+ public static MyModStorageComponentBase GetStorage ( this IMyEntity entity )
323+ {
324+ return entity . Storage = entity . Storage ?? new MyModStorageComponent ( ) ;
325+ }
326+ }
308327}
0 commit comments