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

Commit

Permalink
General performance increases with scan, delete, stop chat commands. …
Browse files Browse the repository at this point in the history
…Remove docking. Tweaks to concealment. Crash fix in player block enforcement. New commands: /admin scan insideplanet /admin delete insideplanet
  • Loading branch information
rexxar-tc committed Sep 28, 2016
1 parent e47b14f commit 0722e34
Show file tree
Hide file tree
Showing 20 changed files with 335 additions and 311 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,10 @@ $RECYCLE.BIN/
ClientEntityManagement.cs
ProcessClientConceal.cs
packages/*/*
.vs/Supercharger/EssentialsPlugin/code_marker.dat
.vs/Supercharger/EssentialsPlugin/codemap.dat
.vs/Supercharger/EssentialsPlugin/codemap.sync-conflict-20160901-211216.dat
.vs/Supercharger/EssentialsPlugin/global_history.dat
.vs/Supercharger/EssentialsPlugin/global_history.sync-conflict-20160901-211216.dat
.vs/Supercharger/EssentialsPlugin/rich_code_format.dat
.vs/Supercharger/EssentialsPlugin/workbench.dat
Binary file modified .vs/EssentialsPlugin/Supercharger.dat
Binary file not shown.
6 changes: 3 additions & 3 deletions EssentialsPlugin/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//243
//257
//
// 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.243")]
[assembly: AssemblyVersion("1.13.7.243")]
[assembly: AssemblyFileVersion("1.13.7.257")]
[assembly: AssemblyVersion("1.13.7.257")]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class HandleAdminOwnershipChange : ChatHandlerBase
{
public override string GetHelp( )
{
return "This command allows you to change the ownership of a ship. Usage: /admin ownership change <entityId> <PlayerName>";
return "This command allows you to change the ownership of a ship. Usage: /admin ownership change <entityId/entityName> <PlayerName>";
}
public override string GetCommandText( )
{
Expand Down
28 changes: 13 additions & 15 deletions EssentialsPlugin/ChatHandlers/Admin/HandleAdminStop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using VRageMath;
using Sandbox.Game.Entities;
using Sandbox.Game.Entities.Cube;
using VRage.Game.Entity;
using VRage.Game.ModAPI;

public class HandleAdminStop : ChatHandlerBase
Expand Down Expand Up @@ -77,25 +78,23 @@ public override bool HandleCommand( ulong userId, string[ ] words )
// arg_ships = true;
// arg_piloted = true;
//}
HashSet<IMyEntity> entities = new HashSet<IMyEntity>( );
HashSet<MyEntity> entities = new HashSet<MyEntity>( );
Wrapper.GameAction( ( ) =>
{
MyAPIGateway.Entities.GetEntities( entities );
} );
{
entities = MyEntities.GetEntities( );
} );

foreach ( IMyEntity entity in entities )
foreach ( MyEntity entity in entities )
{
bool found = false;
if ( entity == null )
continue;

if ( entity.Physics == null )
if ( entity?.Physics == null )
continue;

//if ( !(entity is IMyCubeGrid) || !(entity is IMyFloatingObject) || !(entity is MyInventoryBagEntity) )
// continue;

if ( arg_ships && entity is IMyCubeGrid )
if ( arg_ships && entity is MyCubeGrid )
{
//TODO: find a way to stop piloted ships
//even if we try to stop the grid entity, it won't work if there's a pilot
Expand All @@ -119,10 +118,10 @@ public override bool HandleCommand( ulong userId, string[ ] words )
*/
Stop( entity.GetTopMostParent( ) );
}
else if ( arg_floating && (entity is IMyFloatingObject || entity is MyInventoryBagEntity) )
else if ( arg_floating && (entity is MyFloatingObject || entity is MyInventoryBagEntity) )
Stop( entity );
}
Communication.SendPrivateInformation( userId, count.ToString( ) + " entities have been stopped." );
Communication.SendPrivateInformation( userId, count + " entities have been stopped." );
count = 0;
return true;
}
Expand All @@ -133,11 +132,10 @@ private static void Stop( IMyEntity entity )
if ( entity.Physics.LinearVelocity == Vector3D.Zero && entity.Physics.AngularVelocity == Vector3D.Zero )
return;

Wrapper.GameAction( ( ) =>
Wrapper.BeginGameAction( ( ) =>
{
entity.Physics.LinearVelocity = Vector3D.Zero;
entity.Physics.AngularVelocity = Vector3D.Zero;
} );
entity.Physics.SetSpeeds( Vector3.Zero, Vector3.Zero );
}, null, null );
++count;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using SEModAPIInternal.API.Entity.Sector.SectorObject;
using SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid;
using SEModAPIInternal.API.Entity.Sector.SectorObject.CubeGrid.CubeBlock;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRage.ModAPI;
public class HandleAdminDeleteFloating : ChatHandlerBase
Expand Down Expand Up @@ -47,26 +48,19 @@ public override bool AllowedInConsole( )
public override bool HandleCommand( ulong userId, string[ ] words )
{
int count = 0;
HashSet<IMyEntity> entities = new HashSet<IMyEntity>( );
HashSet<MyEntity> entities = new HashSet<MyEntity>( );

Wrapper.GameAction( ( ) =>
{
MyAPIGateway.Entities.GetEntities( entities );
} );
Wrapper.GameAction( ( ) => entities = MyEntities.GetEntities( ) );

foreach ( IMyEntity entity in entities )
foreach ( MyEntity entity in entities )
{
if ( entity == null )
continue;

if ( entity is IMyFloatingObject || entity is MyInventoryBagEntity || entity is IMyMeteor )
if ( entity is MyFloatingObject || entity is MyInventoryBagEntity || entity is MyMeteor )
{
count++;
Wrapper.GameAction(()=>
{
entity.Close( );
} );
//MyMultiplayer.ReplicateImmediatelly( MyExternalReplicable.FindByObject( entity ) );
Wrapper.BeginGameAction( entity.Close, null, null );
}
}
Communication.SendPrivateInformation( userId, count.ToString( ) + " floating objects deleted." );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
namespace EssentialsPlugin.ChatHandlers
{
using System.Collections.Generic;
using System.Linq;
using EssentialsPlugin.Utility;
using Sandbox.Game.Entities;
using Sandbox.Game.Entities.Character;
using VRageMath;

public class HandleAdminDeleteInsidePlanet : ChatHandlerBase
{
public override string GetHelp()
{
return "This command allows you to delete entities that are trapped inside planets. Usage /admin delete insideplanet";
}
public override string GetCommandText()
{
return "/admin delete insideplanet";
}

public override bool IsAdminCommand()
{
return true;
}

public override bool AllowedInConsole()
{
return true;
}

public override bool HandleCommand(ulong userId, string[] words)
{
var entities = MyEntities.GetEntities( ).ToArray( );
var planets = new HashSet<MyPlanet>( );
int count = 0;
foreach (var entity in entities)
{
MyPlanet item = entity as MyPlanet;
if (item != null)
planets.Add( item );
}

foreach (var planet in planets)
{
var sphere25 = new BoundingSphereD(planet.PositionComp.GetPosition(), planet.MinimumRadius * 0.25);
var sphere75 = new BoundingSphereD(planet.PositionComp.GetPosition(), planet.MinimumRadius * 0.75);
foreach (var entity in entities)
{
if (entity.MarkedForClose || entity.Physics == null || entity is MyCharacter)
continue;

if (sphere25.Contains(entity.PositionComp.GetPosition()) != ContainmentType.Disjoint)
{
count++;
Wrapper.BeginGameAction( entity.Close, null, null );
continue;
}

if (Vector3.IsZero(entity.Physics.LinearVelocity))
continue;

if (sphere75.Contains(entity.PositionComp.GetPosition()) == ContainmentType.Disjoint)
continue;

count++;
Wrapper.BeginGameAction(entity.Close, null, null);
}
}

Communication.SendPrivateInformation( userId, $"Deleted {count} entities trapped in planets." );
return true;
}
}
}
26 changes: 15 additions & 11 deletions EssentialsPlugin/ChatHandlers/AdminScan/HandleAdminScanAreaAt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using System.Linq;
using EssentialsPlugin.Utility;
using Sandbox.Common.ObjectBuilders;
using Sandbox.Game.Entities;
using Sandbox.ModAPI;
using VRage.Game;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRage.ModAPI;
using VRageMath;
Expand Down Expand Up @@ -71,19 +73,21 @@ public override bool HandleCommand(ulong userId, string[] words)
List<MyObjectBuilder_CubeGrid> gridsToMove = new List<MyObjectBuilder_CubeGrid>();
BoundingSphereD sphere = new BoundingSphereD(startPosition, radius);
List<IMyEntity> entitiesToMove = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
int count = 0;
List<MyEntity> entities;
int count = 0;
Wrapper.GameAction( ( ) =>
{
entities = MyEntities.GetTopMostEntitiesInSphere( ref sphere );

Wrapper.GameAction(() =>
{
foreach (IMyEntity entity in entitiesToMove)
{
if (!(entity is IMyCubeGrid))
continue;
foreach (MyEntity entity in entities)
{
if (!( entity is MyCubeGrid ))
continue;

Communication.SendPrivateInformation(userId, string.Format("Found ship '{0}' ({1}) at {2}", entity.DisplayName, entity.EntityId, General.Vector3DToString(entity.GetPosition())));
count++;
}
});
Communication.SendPrivateInformation( userId, string.Format( "Found ship '{0}' ({1}) at {2}", entity.DisplayName, entity.EntityId, General.Vector3DToString( entity.PositionComp.GetPosition( ) ) ) );
count++;
}
} );

Communication.SendPrivateInformation(userId, string.Format("Total ships found: {0}", count));
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
namespace EssentialsPlugin.ChatHandlers
{
using System.Collections.Generic;
using System.Linq;
using EssentialsPlugin.Utility;
using Sandbox.Game.Entities;
using Sandbox.Game.Entities.Character;
using VRageMath;

public class HandleAdminScanInsidePlanet : ChatHandlerBase
{
public override string GetHelp()
{
return "This command allows you to scan for entities that are trapped inside planets. Usage /admin scan insideplanet";
}
public override string GetCommandText()
{
return "/admin scan insideplanet";
}

public override bool IsAdminCommand()
{
return true;
}

public override bool AllowedInConsole()
{
return true;
}

public override bool HandleCommand(ulong userId, string[] words)
{
var entities = MyEntities.GetEntities( ).ToArray( );
var planets = new HashSet<MyPlanet>( );
int count = 0;
foreach (var entity in entities)
{
MyPlanet item = entity as MyPlanet;
if (item != null)
planets.Add( item );
}

foreach (var planet in planets)
{
var sphere25 = new BoundingSphereD( planet.PositionComp.GetPosition( ), planet.MinimumRadius * 0.25 );
var sphere75 = new BoundingSphereD( planet.PositionComp.GetPosition( ), planet.MinimumRadius * 0.75 );
foreach (var entity in entities)
{
if (entity.MarkedForClose || entity.Physics == null || entity is MyCharacter)
continue;

if (sphere25.Contains( entity.PositionComp.GetPosition( ) ) != ContainmentType.Disjoint)
{
count++;
continue;
}

if (Vector3.IsZero( entity.Physics.LinearVelocity ))
continue;

if (sphere75.Contains( entity.PositionComp.GetPosition( ) ) == ContainmentType.Disjoint)
continue;

count++;
}
}

Communication.SendPrivateInformation( userId, $"Found {count} entities trapped in planets." );
return true;
}
}
}
7 changes: 4 additions & 3 deletions EssentialsPlugin/ChatHandlers/ChatHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ public abstract class ChatHandlerBase
protected static readonly Logger Log = LogManager.GetLogger( "PluginLog" );
public ChatHandlerBase( )
{
if ( ExtenderOptions.IsDebugging )
Log.Debug( $"Added chat handler: {GetCommandText()}" );
}
#if DEBUG
Log.Debug( $"Added chat handler: {GetCommandText()}" );
#endif
}

public virtual Boolean CanHandle(ulong steamId, String[] words, ref int commandCount)
{
Expand Down
Loading

0 comments on commit 0722e34

Please sign in to comment.