Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 54e3688

Browse files
committed
Concealment stuff
1 parent aaa4263 commit 54e3688

File tree

4 files changed

+75
-73
lines changed

4 files changed

+75
-73
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//21
1+
//26
22
//
33
// This code was generated by a tool. Any changes made manually will be lost
44
// the next time this code is regenerated.
55
//
66

77
using System.Reflection;
88

9-
[assembly: AssemblyFileVersion("1.13.7.21")]
10-
[assembly: AssemblyVersion("1.13.7.21")]
9+
[assembly: AssemblyFileVersion("1.13.7.26")]
10+
[assembly: AssemblyVersion("1.13.7.26")]

EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminConceal.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ public override bool HandleCommand(ulong userId, string[] words)
7070

7171
if (showConcealed)
7272
{
73-
HashSet<IMyEntity> entities = new HashSet<IMyEntity>();
73+
HashSet<MyEntity> entities = new HashSet<MyEntity>();
7474
Wrapper.GameAction(() =>
7575
{
76-
MyAPIGateway.Entities.GetEntities(entities);
76+
entities=MyEntities.GetEntities();
7777
});
7878

7979
Communication.SendPrivateInformation(userId, "==== Concealed Entities ===");
8080
int count = 0;
81-
foreach (MyEntity entity in EntityManagement.UnregisteredEntities)
81+
foreach (MyEntity entity in entities)
8282
{
83-
if (!(entity is MyCubeGrid))
83+
if (!EntityManagement.RemovedGrids.Contains( entity.EntityId ))
8484
continue;
8585

8686
MyCubeGrid grid = (MyCubeGrid)entity;

EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminReveal.cs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
namespace EssentialsPlugin.ChatHandlers.AdminConceal
22
{
3-
using System.Collections.Generic;
43
using System.Linq;
54
using EntityManagers;
65
using EssentialsPlugin.Utility;
7-
using Sandbox.Common.ObjectBuilders;
8-
using Sandbox.Engine.Multiplayer;
9-
using Sandbox.Game.Entities;
10-
using Sandbox.Game.Replication;
11-
using Sandbox.ModAPI;
12-
using SEModAPIInternal.API.Common;
13-
using SEModAPIInternal.API.Entity;
14-
using VRage.Game;
15-
using VRage.Game.Entity;
16-
using VRage.Game.ModAPI;
17-
using VRage.ModAPI;
18-
using VRage.ObjectBuilders;
19-
using VRageMath;
206

217
public class HandleAdminReveal : ChatHandlerBase
228
{
@@ -32,14 +18,15 @@ public override string GetCommandText()
3218

3319
public override Communication.ServerDialogItem GetHelpDialog( )
3420
{
35-
Communication.ServerDialogItem DialogItem = new Communication.ServerDialogItem( );
36-
DialogItem.title = "Help";
37-
DialogItem.header = "Admin Reveal";
38-
DialogItem.content =
39-
" This command allows you to reveal concealed grids.|" +
40-
"Usage: /admin reveal (force) - this command without 'force' only show you how many grids would be revealed.||" +
41-
"This command will run when concealment is disabled, and respects the update time setting.";
42-
DialogItem.buttonText = "close";
21+
Communication.ServerDialogItem DialogItem = new Communication.ServerDialogItem
22+
{
23+
title = "Help",
24+
header = "Admin Reveal",
25+
content = " This command allows you to reveal concealed grids.|" +
26+
"Usage: /admin reveal (force) - this command without 'force' only show you how many grids would be revealed.||" +
27+
"This command will run when concealment is disabled, and respects the update time setting.",
28+
buttonText = "close"
29+
};
4330
return DialogItem;
4431
}
4532

@@ -63,7 +50,7 @@ public override bool HandleCommand(ulong userId, string[] words)
6350
else
6451
{
6552
Communication.SendPrivateInformation( userId,
66-
$"Command would reveal {EntityManagement.UnregisteredEntities.Count} grids. Type /admin reveal force to reveal them." );
53+
$"Command would reveal {EntityManagement.RemovedGrids.Count} grids. Type /admin reveal force to reveal them." );
6754
}
6855
return true;
6956
}

EssentialsPlugin/EntityManagers/EntityManagement.cs

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6-
using System.Runtime.Remoting;
76
using System.Threading;
87
using EssentialsPlugin.ProcessHandlers;
98
using EssentialsPlugin.Utility;
109
using Sandbox.ModAPI;
11-
using Sandbox.ModAPI.Ingame;
1210
using SEModAPIInternal.API.Common;
1311
using VRage.ModAPI;
1412
using VRage.ObjectBuilders;
1513
using VRageMath;
16-
using IMyProductionBlock = Sandbox.ModAPI.Ingame.IMyProductionBlock;
1714
using Sandbox.Game.Entities;
1815
using Sandbox.Game.World;
1916
using Sandbox.Game.Entities.Blocks;
2017
using Sandbox.Game.Entities.Cube;
18+
using Sandbox.ModAPI.Ingame;
19+
using SpaceEngineers.Game.ModAPI;
2120
using SpaceEngineers.Game.ModAPI.Ingame;
2221
using VRage.Game;
2322
using VRage.Game.Entity;
2423
using VRage.Game.ModAPI;
25-
24+
using IMyProductionBlock = Sandbox.ModAPI.IMyProductionBlock;
25+
2626
public class EntityManagement
2727
{
2828
private static volatile bool _checkReveal;
2929
private static volatile bool _checkConceal;
3030
private static bool _oldInit;
31-
private static readonly List<long> RemovedGrids = new List<long>( );
31+
public static readonly HashSet<long> RemovedGrids = new HashSet<long>( );
3232
private static readonly List<ulong> Online = new List<ulong>( );
3333

34-
public static HashSet<MyEntity> UnregisteredEntities = new HashSet<MyEntity>();
34+
//public static HashSet<MyEntity> UnregisteredEntities = new HashSet<MyEntity>();
3535

3636

3737
public static void CheckAndConcealEntities( )
@@ -71,7 +71,10 @@ public static void CheckAndConcealEntities( )
7171
if ( grid.Physics == null ) //projection
7272
continue;
7373

74-
if ( UnregisteredEntities.Contains( grid ) )
74+
//if ( UnregisteredEntities.Contains( (MyEntity)grid ) )
75+
// continue;
76+
77+
if ( RemovedGrids.Contains( grid.EntityId ) )
7578
continue;
7679

7780
if ( grid.GridSizeEnum != MyCubeSize.Small )
@@ -222,8 +225,8 @@ private static void ConcealEntity( MyEntity entity )
222225
pos = 4;
223226
//else
224227
//{
225-
UnregisteredEntities.Add( entity );
226-
Wrapper.GameAction( () => UnregisterHierarchy( entity ) );
228+
//UnregisteredEntities.Add( entity );
229+
Wrapper.GameAction( () => UnregisterHierarchy( entity.GetTopMostParent( ) ) );
227230
if ( PluginSettings.Instance.DynamicShowMessages )
228231
Essentials.Log.Info( $"Concealed - Id: {entity.EntityId} -> Display: {entity.DisplayName} OwnerId: {ownerId} OwnerName: {ownerName}" );
229232

@@ -311,9 +314,11 @@ public static void CheckAndRevealEntities( )
311314
_checkReveal = true;
312315
try
313316
{
314-
foreach ( MyEntity entity in UnregisteredEntities)
317+
HashSet<MyEntity> entities = new HashSet<MyEntity>();
318+
MyAPIGateway.Utilities.InvokeOnGameThread( () => entities=MyEntities.GetEntities());
319+
foreach ( MyEntity entity in entities.ToArray())
315320
{
316-
if ( entity.Closed || entity.MarkedForClose )
321+
if ( entity.Closed || entity.MarkedForClose || !RemovedGrids.Contains( entity.EntityId ))
317322
continue;
318323

319324
if ( !( entity is MyCubeGrid ) )
@@ -345,7 +350,7 @@ public static void CheckAndRevealEntities( )
345350

346351
if ( found )
347352
{
348-
Wrapper.GameAction( () => ReregisterHierarchy( entity ) );
353+
Wrapper.GameAction( () => ReregisterHierarchy( entity.GetTopMostParent( ) ) );
349354

350355
if (PluginSettings.Instance.DynamicShowMessages)
351356
Essentials.Log.Info("Revealed - Id: {0} -> Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}",
@@ -563,35 +568,31 @@ public static void RevealEntityObsolete( KeyValuePair<IMyEntity, string> item )
563568

564569
static public void RevealAll( )
565570
{
566-
while ( _checkReveal )
567-
{
568-
}
569-
570571
_checkReveal = true;
571572

572573
CheckAndRevealEntitiesObsolete();
573574

574575
HashSet<MyEntity> entities = new HashSet<MyEntity>();
575576
Wrapper.GameAction( ()=>entities = MyEntities.GetEntities() );
576577

577-
foreach ( var entity in entities )
578+
foreach ( var entity in entities.ToArray() )
578579
{
579580
var grid = entity as MyCubeGrid;
580581
if ( grid == null )
581582
continue;
582583

583-
if (PluginSettings.Instance.DynamicShowMessages && UnregisteredEntities.Contains( entity ))
584+
if (PluginSettings.Instance.DynamicShowMessages && RemovedGrids.Contains( entity.EntityId ))
584585
Essentials.Log.Info("Revealed - Id: {0} -> Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}",
585586
entity.EntityId,
586587
entity.DisplayName.Replace("\r", "").Replace("\n", ""),
587588
((MyCubeGrid)entity).BigOwners.FirstOrDefault(),
588589
PlayerMap.Instance.GetPlayerNameFromPlayerId(((MyCubeGrid)entity).BigOwners.FirstOrDefault()),
589590
"Force reveal");
590591

591-
Wrapper.GameAction( () => ReregisterHierarchy( entity ) );
592+
Wrapper.GameAction( () => ReregisterHierarchy( entity.GetTopMostParent( ) ) );
592593
}
593594

594-
UnregisteredEntities.Clear();
595+
RemovedGrids.Clear();
595596
_checkReveal = false;
596597
}
597598

@@ -617,55 +618,69 @@ public static void SetOnline( ulong steamId, bool online )
617618
}
618619
}
619620

620-
private static void UnregisterHierarchy( MyEntity entity )
621+
private static void UnregisterHierarchy( MyEntity entity, bool top = true )
621622
{
622623
if ( entity.Hierarchy == null )
623624
return;
624625

625-
//if ( UnregisteredEntities.Contains( entity ) )
626-
// return;
626+
if (RemovedGrids.Contains(entity.EntityId))
627+
return;
627628

628629
foreach ( var child in entity.Hierarchy.Children )
629630
{
630631
MyEntity childEntity = (MyEntity)child.Container.Entity;
631-
UnregisterHierarchy( childEntity );
632+
UnregisterHierarchy( childEntity, false );
632633
MyEntities.UnregisterForUpdate( childEntity );
633-
childEntity.RemoveFromGamePruningStructure();
634+
//childEntity.RemoveFromGamePruningStructure();
634635

635636
//child.Container.Entity.InScene = false;
636637

637-
if ( !PluginSettings.Instance.DynamicConcealPhysics )
638-
continue;
639-
640-
if (child.Container.Entity.Physics != null)
641-
child.Container.Entity.Physics.Enabled = false;
642638
}
643639

644-
UnregisteredEntities.Add( entity );
640+
if ( !top )
641+
return;
642+
643+
RemovedGrids.Add( entity.EntityId );
644+
645+
MyEntities.UnregisterForUpdate( entity );
646+
entity.RemoveFromGamePruningStructure();
647+
if ( !PluginSettings.Instance.DynamicConcealPhysics )
648+
return;
649+
650+
if ( entity.Physics != null )
651+
entity.Physics.Enabled = false;
652+
645653
}
646654

647-
private static void ReregisterHierarchy( MyEntity entity )
655+
private static void ReregisterHierarchy( MyEntity entity, bool top = true )
648656
{
649657
if ( entity.Hierarchy == null )
650658
return;
651-
652-
foreach (var child in entity.Hierarchy.Children)
659+
660+
RemovedGrids.Remove( entity.EntityId );
661+
662+
foreach ( var child in entity.Hierarchy.Children )
653663
{
654664
MyEntity childEntity = (MyEntity)child.Container.Entity;
655-
ReregisterHierarchy(childEntity);
656-
MyEntities.RegisterForUpdate(childEntity);
657-
childEntity.AddToGamePruningStructure();
665+
ReregisterHierarchy( childEntity, false );
666+
MyEntities.RegisterForUpdate( childEntity );
667+
//childEntity.AddToGamePruningStructure();
658668

659669
//child.Container.Entity.InScene = true;
660670

661-
if (!PluginSettings.Instance.DynamicConcealPhysics)
662-
continue;
663-
664-
if (child.Container.Entity.Physics != null)
665-
child.Container.Entity.Physics.Enabled = true;
666671
}
672+
if ( !top )
673+
return;
674+
675+
MyEntities.RegisterForUpdate( entity );
676+
entity.AddToGamePruningStructure();
677+
678+
if ( !PluginSettings.Instance.DynamicConcealPhysics )
679+
return;
667680

668-
UnregisteredEntities.Remove( entity );
681+
if ( entity.Physics != null )
682+
entity.Physics.Enabled = true;
683+
//UnregisteredEntities.Remove( entity );
669684
}
670685
}
671686
}

0 commit comments

Comments
 (0)