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

Commit

Permalink
Fixed a threading error in GridGroups. Fixes #90
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxar-tc committed Apr 27, 2016
1 parent 6fd4a25 commit 2f666f9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
6 changes: 3 additions & 3 deletions EssentialsPlugin/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//83
//96
//
// 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.6.83")]
[assembly: AssemblyVersion("1.13.6.83")]
[assembly: AssemblyFileVersion("1.13.6.96")]
[assembly: AssemblyVersion("1.13.6.96")]
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ public override bool HandleCommand(ulong userId, string[] words)

try
{
string command = $"excludesblocksubtype:beacon{linkType} quiet";
string command = $"excludesblocksubtype:beacon quiet{linkType}";
HashSet<GridGroup> groups = CubeGrids.ScanGrids(0, CommandParser.GetCommandParts(command).ToArray());
int groupsCount = 0;
int groupsCount = groups.Count;
int gridsCount = 0;

foreach ( var group in groups )
{
if ( group.GetFatBlocks( ).Any( x => x is IMyBeacon ) )
continue;
//if ( group.GetFatBlocks( ).Any( x => x is IMyBeacon ) )
// continue;

groupsCount++;
//groupsCount++;
gridsCount += group.Grids.Count;
Communication.SendPrivateInformation( userId, $"Found group with parent {group.Parent.DisplayName} ({group.Parent.EntityId}) at {group.Parent.PositionComp.GetPosition( )} with no beacon." );
}
Expand Down
2 changes: 1 addition & 1 deletion EssentialsPlugin/Utility/CubeGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ public static HashSet<GridGroup> ScanGrids( ulong userId, string[] words )
//if (!quiet)
Communication.SendPrivateInformation( userId, $"Found {gridCount} grids in {groupCount} groups" );

return groupsToConfirm;
return groupsFound;
}

public static bool IsFullOwner( MyCubeGrid grid, long ownerId, IMyPlayer factionPlayer = null )
Expand Down
25 changes: 17 additions & 8 deletions EssentialsPlugin/Utility/GridGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Sandbox.Game.Entities;
using Sandbox.Game.Entities.Cube;
using VRage.Game.Entity;
using VRage.ModAPI;
using VRageMath;

public class GridGroup
Expand Down Expand Up @@ -69,20 +70,28 @@ public MyCubeGrid Parent

public GridGroup( MyCubeGrid grid, GridLinkTypeEnum linkType = GridLinkTypeEnum.Logical )
{
//HACK: Manually create a group for out of scene grids because pulling them from the server crashes
if ( grid.InScene )
{
List<MyCubeGrid> tmpList = new List<MyCubeGrid>( );

//find the group containing this grid with the given link type
Wrapper.GameAction( ( ) => tmpList = MyCubeGridGroups.Static.GetGroups( linkType ).GetGroupNodes( grid ) );

foreach ( MyCubeGrid node in tmpList )
_grids.Add( node );

_grids.UnionWith( tmpList );
}
//HACK: Manually create a group for out of scene grids because pulling them from the server crashes
else
{
_grids.Add( grid );
//use the old method to filter out grids with pisons or rotors, for safety
HashSet<IMyEntity> thisEntity = new HashSet<IMyEntity>();
HashSet<IMyEntity> returnSet = new HashSet<IMyEntity>();
thisEntity.Add( grid );
CubeGrids.GetGridsUnconnected( thisEntity, returnSet );

if ( returnSet.Count != 0 )
_grids.Add( (MyCubeGrid)returnSet.First( ) );
else
return;
}

//populate our internal lists
Expand Down Expand Up @@ -114,12 +123,12 @@ public static HashSet<GridGroup> GetGroups( HashSet<MyEntity> entities, GridLink
//on large servers this can run into the tens of seconds, so parallelize it
groupTasks.Add( Task.Run( ( ) =>
{
if ( result.Any( x => x.Grids.Contains( grid ) ) )
return;
var newGroup = new GridGroup( grid, linkType );
lock ( result )
{
result.Add( new GridGroup( grid, linkType ) );
if ( !result.Any( x => x.Grids.Contains( grid ) ) )
result.Add( newGroup );
}
} ) );
}
Expand Down

0 comments on commit 2f666f9

Please sign in to comment.