99using Sandbox . Game . Entities . Blocks ;
1010using Sandbox . Game . World ;
1111using SpaceEngineers . Game . Entities . Blocks ;
12+ using VRage . Audio ;
1213using VRage . Game . Entity ;
1314using VRage . Game . Entity . EntityComponents . Interfaces ;
1415using VRage . Groups ;
@@ -19,6 +20,7 @@ namespace Concealment
1920{
2021 public class ConcealGroup
2122 {
23+ private static readonly Logger _log = LogManager . GetCurrentClassLogger ( ) ;
2224 /// <summary>
2325 /// Entity ID of the first grid in the group.
2426 /// </summary>
@@ -70,9 +72,10 @@ private void UnhookOnClosing()
7072 grid . OnMarkForClose -= Grid_OnMarkForClose ;
7173 }
7274
73- private void Grid_OnMarkForClose ( VRage . Game . Entity . MyEntity obj )
75+ private void Grid_OnMarkForClose ( MyEntity obj )
7476 {
75- LogManager . GetLogger ( nameof ( ConcealGroup ) ) . Info ( $ "Grid group '{ GridNames } ' was marked for close.") ;
77+ _log . Debug ( $ "Grid group '{ GridNames } ' was marked for close.") ;
78+ EnableProjectors ( ) ;
7679 UnhookOnClosing ( ) ;
7780 Closing ? . Invoke ( this ) ;
7881 }
@@ -127,36 +130,54 @@ public bool IsCryoOccupied(ulong steamId)
127130 return false ;
128131 }
129132
133+ private readonly HashSet < long > _projectors = new HashSet < long > ( ) ;
134+ private void DisableProjectors ( MyCubeGrid grid )
135+ {
136+ foreach ( var projector in grid . GetFatBlocks < MyProjectorBase > ( ) )
137+ {
138+ if ( projector . ProjectedGrid == null )
139+ continue ;
140+
141+ projector . Enabled = false ;
142+ _projectors . Add ( projector . EntityId ) ;
143+ }
144+ }
145+
146+ public void EnableProjectors ( )
147+ {
148+ foreach ( var projector in _projectors . Select ( x => ( MyProjectorBase ) MyEntities . GetEntityById ( x ) ) )
149+ {
150+ projector . Enabled = true ;
151+ }
152+ _projectors . Clear ( ) ;
153+ }
154+
130155 /// <summary>
131156 /// Conceals this group from game and physics logic.
132157 /// </summary>
133158 public void Conceal ( )
134159 {
135- //TODO: find good way to disable grid movement/physics
136- //_unstatic.Clear();
137160 foreach ( var grid in Grids )
138161 {
139- //_unstatic[grid.EntityId] = !grid.IsStatic;
140- //grid.ConvertToStatic();
162+ DisableProjectors ( grid ) ;
141163
142164 if ( grid . Parent == null )
143165 UnregisterRecursive ( grid ) ;
144166 }
145167
146- //foreach (var entity in Grids)
147- // if (entity.Parent == null)
148- // MyGamePruningStructure.Remove(entity);
149-
150- void UnregisterRecursive ( IMyEntity e )
168+ void UnregisterRecursive ( MyEntity e )
151169 {
152- MyEntities . UnregisterForUpdate ( ( MyEntity ) e ) ;
170+ if ( e . IsPreview )
171+ return ;
172+
173+ MyEntities . UnregisterForUpdate ( e ) ;
153174 ( e . GameLogic as IMyGameLogicComponent ) ? . UnregisterForUpdate ( ) ;
154175 e . Flags |= ( EntityFlags ) 4 ;
155176 if ( e . Hierarchy == null )
156177 return ;
157178
158179 foreach ( var child in e . Hierarchy . Children )
159- UnregisterRecursive ( child . Container . Entity ) ;
180+ UnregisterRecursive ( ( MyEntity ) child . Container . Entity ) ;
160181 }
161182 }
162183
@@ -165,32 +186,29 @@ void UnregisterRecursive(IMyEntity e)
165186 /// </summary>
166187 public void Reveal ( )
167188 {
168- // foreach (var entity in Grids)
169- // if (entity.Parent == null)
170- // MyGamePruningStructure.Add(entity);
171-
172189 foreach ( var grid in Grids )
173190 {
174- //if (_unstatic[grid.EntityId])
175- // grid.OnConvertToDynamic();
176-
177191 if ( grid . Parent == null )
178192 RegisterRecursive ( grid ) ;
179193 }
194+
195+ EnableProjectors ( ) ;
180196
181- void RegisterRecursive ( IMyEntity e )
197+ void RegisterRecursive ( MyEntity e )
182198 {
183- MyEntities . RegisterForUpdate ( ( MyEntity ) e ) ;
199+ if ( e . IsPreview )
200+ return ;
201+
202+ MyEntities . RegisterForUpdate ( e ) ;
184203 ( e . GameLogic as IMyGameLogicComponent ) ? . RegisterForUpdate ( ) ;
185204 e . Flags &= ~ ( EntityFlags ) 4 ;
186205 if ( e . Hierarchy == null )
187206 return ;
188207
189208 foreach ( var child in e . Hierarchy . Children )
190- RegisterRecursive ( child . Container . Entity ) ;
209+ RegisterRecursive ( ( MyEntity ) child . Container . Entity ) ;
191210 }
192211 }
193-
194212 }
195213
196214}
0 commit comments