22using System . Collections . Concurrent ;
33using System . Collections . Generic ;
44using System . Diagnostics ;
5+ using System . IO ;
56using System . Linq ;
67using System . Threading ;
78using System . Threading . Tasks ;
89using System . Windows . Controls ;
910using Havok ;
1011using NLog ;
12+ using Sandbox . Definitions ;
1113using Sandbox . Engine . Multiplayer ;
1214using Sandbox . Game . Entities ;
1315using Sandbox . Game . EntityComponents ;
2022using Torch . Managers ;
2123using VRage . Game ;
2224using VRage . Game . Components ;
25+ using VRage . Game . Definitions ;
2326using VRage . Game . Entity ;
2427using VRage . Game . ModAPI ;
28+ using VRage . Game . ObjectBuilders . ComponentSystem ;
2529using VRage . ModAPI ;
30+ using VRage . ObjectBuilders ;
31+ using VRage . Utils ;
2632using VRageMath ;
2733
2834namespace Concealment
2935{
3036 [ Plugin ( "Concealment" , "1.1" , "17f44521-b77a-4e85-810f-ee73311cf75d" ) ]
3137 public class ConcealmentPlugin : TorchPluginBase , IWpfPlugin
3238 {
33- public Persistent < Settings > Settings { get ; }
39+ public Persistent < Settings > Settings { get ; private set ; }
3440 public MTObservableCollection < ConcealGroup > ConcealGroups { get ; } = new MTObservableCollection < ConcealGroup > ( ) ;
3541
3642 private static readonly Logger Log = LogManager . GetLogger ( "Concealment" ) ;
@@ -44,7 +50,6 @@ public class ConcealmentPlugin : TorchPluginBase, IWpfPlugin
4450 public ConcealmentPlugin ( )
4551 {
4652 _intersectGroups = new List < ConcealGroup > ( ) ;
47- Settings = Persistent < Settings > . Load ( "Concealment.cfg" ) ;
4853 }
4954
5055 public UserControl GetControl ( )
@@ -55,8 +60,18 @@ public UserControl GetControl()
5560 public override void Init ( ITorchBase torch )
5661 {
5762 base . Init ( torch ) ;
63+ Settings = Persistent < Settings > . Load ( Path . Combine ( StoragePath , "Concealment.cfg" ) ) ;
5864 _concealedAabbTree = new MyDynamicAABBTreeD ( MyConstants . GAME_PRUNING_STRUCTURE_AABB_EXTENSION ) ;
5965 torch . SessionUnloading += Torch_SessionUnloading ;
66+
67+ //Init storage component.
68+ var comp = new MyModStorageComponentDefinition
69+ {
70+ Id = new MyDefinitionId ( typeof ( MyObjectBuilder_ModStorageComponent ) , "Concealment" ) ,
71+ RegisteredStorageGuids = new [ ] { Id }
72+ } ;
73+ MyDefinitionManager . Static . Definitions . AddDefinition ( comp ) ;
74+
6075 }
6176
6277 private void Torch_SessionUnloading ( )
@@ -224,6 +239,7 @@ public int RevealGroup(ConcealGroup group)
224239
225240 public int RevealGridsInSphere ( BoundingSphereD sphere )
226241 {
242+ Log . Debug ( $ "reveal in sphere { sphere . Center } | { sphere . Radius } ") ;
227243 var revealed = 0 ;
228244#if ! NOPHYS
229245 _concealedAabbTree . OverlapAllBoundingSphere ( ref sphere , _intersectGroups ) ;
@@ -244,10 +260,10 @@ public int RevealGridsInSphere(BoundingSphereD sphere)
244260
245261 public int RevealNearbyGrids ( double distanceFromPlayers )
246262 {
247- //annoying log spam
248- //Log.Debug("Revealing nearby grids");
263+ Log . Debug ( "Revealing nearby grids" ) ;
249264 var revealed = 0 ;
250265 var playerSpheres = GetPlayerBoundingSpheres ( distanceFromPlayers ) ;
266+ Log . Debug ( playerSpheres . Count ) ;
251267 foreach ( var sphere in playerSpheres )
252268 revealed += RevealGridsInSphere ( sphere ) ;
253269
@@ -263,19 +279,20 @@ public int ConcealDistantGrids(double distanceFromPlayers)
263279 var playerSpheres = GetPlayerBoundingSpheres ( distanceFromPlayers ) ;
264280
265281 ConcurrentBag < ConcealGroup > groups = new ConcurrentBag < ConcealGroup > ( ) ;
266- Parallel . ForEach ( MyCubeGridGroups . Static . Physical . Groups , group =>
282+ //Parallel.ForEach(MyCubeGridGroups.Static.Physical.Groups, group =>
283+ foreach ( var group in MyCubeGridGroups . Static . Physical . Groups )
267284 {
268285 var concealGroup = new ConcealGroup ( group ) ;
269286
270287 var volume = group . GetWorldAABB ( ) ;
271288 if ( playerSpheres . Any ( s => s . Contains ( volume ) != ContainmentType . Disjoint ) )
272- return ;
289+ continue ;
273290
274291 //if (IsExcluded(concealGroup))
275292 // return;
276293
277294 groups . Add ( concealGroup ) ;
278- } ) ;
295+ }
279296 foreach ( var group in groups )
280297 {
281298 concealed += ConcealGroup ( group ) ;
0 commit comments