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

Commit

Permalink
Concealment stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxar-tc committed Jun 24, 2016
1 parent aaa4263 commit 54e3688
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 73 deletions.
6 changes: 3 additions & 3 deletions EssentialsPlugin/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//21
//26
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//

using System.Reflection;

[assembly: AssemblyFileVersion("1.13.7.21")]
[assembly: AssemblyVersion("1.13.7.21")]
[assembly: AssemblyFileVersion("1.13.7.26")]
[assembly: AssemblyVersion("1.13.7.26")]
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ public override bool HandleCommand(ulong userId, string[] words)

if (showConcealed)
{
HashSet<IMyEntity> entities = new HashSet<IMyEntity>();
HashSet<MyEntity> entities = new HashSet<MyEntity>();
Wrapper.GameAction(() =>
{
MyAPIGateway.Entities.GetEntities(entities);
entities=MyEntities.GetEntities();
});

Communication.SendPrivateInformation(userId, "==== Concealed Entities ===");
int count = 0;
foreach (MyEntity entity in EntityManagement.UnregisteredEntities)
foreach (MyEntity entity in entities)
{
if (!(entity is MyCubeGrid))
if (!EntityManagement.RemovedGrids.Contains( entity.EntityId ))
continue;

MyCubeGrid grid = (MyCubeGrid)entity;
Expand Down
33 changes: 10 additions & 23 deletions EssentialsPlugin/ChatHandlers/AdminConceal/HandleAdminReveal.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
namespace EssentialsPlugin.ChatHandlers.AdminConceal
{
using System.Collections.Generic;
using System.Linq;
using EntityManagers;
using EssentialsPlugin.Utility;
using Sandbox.Common.ObjectBuilders;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.Entities;
using Sandbox.Game.Replication;
using Sandbox.ModAPI;
using SEModAPIInternal.API.Common;
using SEModAPIInternal.API.Entity;
using VRage.Game;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRage.ModAPI;
using VRage.ObjectBuilders;
using VRageMath;

public class HandleAdminReveal : ChatHandlerBase
{
Expand All @@ -32,14 +18,15 @@ public override string GetCommandText()

public override Communication.ServerDialogItem GetHelpDialog( )
{
Communication.ServerDialogItem DialogItem = new Communication.ServerDialogItem( );
DialogItem.title = "Help";
DialogItem.header = "Admin Reveal";
DialogItem.content =
" This command allows you to reveal concealed grids.|" +
"Usage: /admin reveal (force) - this command without 'force' only show you how many grids would be revealed.||" +
"This command will run when concealment is disabled, and respects the update time setting.";
DialogItem.buttonText = "close";
Communication.ServerDialogItem DialogItem = new Communication.ServerDialogItem
{
title = "Help",
header = "Admin Reveal",
content = " This command allows you to reveal concealed grids.|" +
"Usage: /admin reveal (force) - this command without 'force' only show you how many grids would be revealed.||" +
"This command will run when concealment is disabled, and respects the update time setting.",
buttonText = "close"
};
return DialogItem;
}

Expand All @@ -63,7 +50,7 @@ public override bool HandleCommand(ulong userId, string[] words)
else
{
Communication.SendPrivateInformation( userId,
$"Command would reveal {EntityManagement.UnregisteredEntities.Count} grids. Type /admin reveal force to reveal them." );
$"Command would reveal {EntityManagement.RemovedGrids.Count} grids. Type /admin reveal force to reveal them." );
}
return true;
}
Expand Down
101 changes: 58 additions & 43 deletions EssentialsPlugin/EntityManagers/EntityManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting;
using System.Threading;
using EssentialsPlugin.ProcessHandlers;
using EssentialsPlugin.Utility;
using Sandbox.ModAPI;
using Sandbox.ModAPI.Ingame;
using SEModAPIInternal.API.Common;
using VRage.ModAPI;
using VRage.ObjectBuilders;
using VRageMath;
using IMyProductionBlock = Sandbox.ModAPI.Ingame.IMyProductionBlock;
using Sandbox.Game.Entities;
using Sandbox.Game.World;
using Sandbox.Game.Entities.Blocks;
using Sandbox.Game.Entities.Cube;
using Sandbox.ModAPI.Ingame;
using SpaceEngineers.Game.ModAPI;
using SpaceEngineers.Game.ModAPI.Ingame;
using VRage.Game;
using VRage.Game.Entity;
using VRage.Game.ModAPI;

using IMyProductionBlock = Sandbox.ModAPI.IMyProductionBlock;

public class EntityManagement
{
private static volatile bool _checkReveal;
private static volatile bool _checkConceal;
private static bool _oldInit;
private static readonly List<long> RemovedGrids = new List<long>( );
public static readonly HashSet<long> RemovedGrids = new HashSet<long>( );
private static readonly List<ulong> Online = new List<ulong>( );

public static HashSet<MyEntity> UnregisteredEntities = new HashSet<MyEntity>();
//public static HashSet<MyEntity> UnregisteredEntities = new HashSet<MyEntity>();


public static void CheckAndConcealEntities( )
Expand Down Expand Up @@ -71,7 +71,10 @@ public static void CheckAndConcealEntities( )
if ( grid.Physics == null ) //projection
continue;

if ( UnregisteredEntities.Contains( grid ) )
//if ( UnregisteredEntities.Contains( (MyEntity)grid ) )
// continue;

if ( RemovedGrids.Contains( grid.EntityId ) )
continue;

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

Expand Down Expand Up @@ -311,9 +314,11 @@ public static void CheckAndRevealEntities( )
_checkReveal = true;
try
{
foreach ( MyEntity entity in UnregisteredEntities)
HashSet<MyEntity> entities = new HashSet<MyEntity>();
MyAPIGateway.Utilities.InvokeOnGameThread( () => entities=MyEntities.GetEntities());
foreach ( MyEntity entity in entities.ToArray())
{
if ( entity.Closed || entity.MarkedForClose )
if ( entity.Closed || entity.MarkedForClose || !RemovedGrids.Contains( entity.EntityId ))
continue;

if ( !( entity is MyCubeGrid ) )
Expand Down Expand Up @@ -345,7 +350,7 @@ public static void CheckAndRevealEntities( )

if ( found )
{
Wrapper.GameAction( () => ReregisterHierarchy( entity ) );
Wrapper.GameAction( () => ReregisterHierarchy( entity.GetTopMostParent( ) ) );

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

static public void RevealAll( )
{
while ( _checkReveal )
{
}

_checkReveal = true;

CheckAndRevealEntitiesObsolete();

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

foreach ( var entity in entities )
foreach ( var entity in entities.ToArray() )
{
var grid = entity as MyCubeGrid;
if ( grid == null )
continue;

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

Wrapper.GameAction( () => ReregisterHierarchy( entity ) );
Wrapper.GameAction( () => ReregisterHierarchy( entity.GetTopMostParent( ) ) );
}

UnregisteredEntities.Clear();
RemovedGrids.Clear();
_checkReveal = false;
}

Expand All @@ -617,55 +618,69 @@ public static void SetOnline( ulong steamId, bool online )
}
}

private static void UnregisterHierarchy( MyEntity entity )
private static void UnregisterHierarchy( MyEntity entity, bool top = true )
{
if ( entity.Hierarchy == null )
return;

//if ( UnregisteredEntities.Contains( entity ) )
// return;
if (RemovedGrids.Contains(entity.EntityId))
return;

foreach ( var child in entity.Hierarchy.Children )
{
MyEntity childEntity = (MyEntity)child.Container.Entity;
UnregisterHierarchy( childEntity );
UnregisterHierarchy( childEntity, false );
MyEntities.UnregisterForUpdate( childEntity );
childEntity.RemoveFromGamePruningStructure();
//childEntity.RemoveFromGamePruningStructure();

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

if ( !PluginSettings.Instance.DynamicConcealPhysics )
continue;

if (child.Container.Entity.Physics != null)
child.Container.Entity.Physics.Enabled = false;
}

UnregisteredEntities.Add( entity );
if ( !top )
return;

RemovedGrids.Add( entity.EntityId );

MyEntities.UnregisterForUpdate( entity );
entity.RemoveFromGamePruningStructure();
if ( !PluginSettings.Instance.DynamicConcealPhysics )
return;

if ( entity.Physics != null )
entity.Physics.Enabled = false;

}

private static void ReregisterHierarchy( MyEntity entity )
private static void ReregisterHierarchy( MyEntity entity, bool top = true )
{
if ( entity.Hierarchy == null )
return;

foreach (var child in entity.Hierarchy.Children)

RemovedGrids.Remove( entity.EntityId );

foreach ( var child in entity.Hierarchy.Children )
{
MyEntity childEntity = (MyEntity)child.Container.Entity;
ReregisterHierarchy(childEntity);
MyEntities.RegisterForUpdate(childEntity);
childEntity.AddToGamePruningStructure();
ReregisterHierarchy( childEntity, false );
MyEntities.RegisterForUpdate( childEntity );
//childEntity.AddToGamePruningStructure();

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

if (!PluginSettings.Instance.DynamicConcealPhysics)
continue;

if (child.Container.Entity.Physics != null)
child.Container.Entity.Physics.Enabled = true;
}
if ( !top )
return;

MyEntities.RegisterForUpdate( entity );
entity.AddToGamePruningStructure();

if ( !PluginSettings.Instance.DynamicConcealPhysics )
return;

UnregisteredEntities.Remove( entity );
if ( entity.Physics != null )
entity.Physics.Enabled = true;
//UnregisteredEntities.Remove( entity );
}
}
}

0 comments on commit 54e3688

Please sign in to comment.