Skip to content

Commit

Permalink
-Moved full scan to queued action
Browse files Browse the repository at this point in the history
-Cleaned up warp engine removal
-Updated API libraries
  • Loading branch information
chessmaster42 committed Jul 17, 2014
1 parent 0e0a5be commit 0ac8458
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
Binary file modified Libraries/SEModAPIExtensions.dll
Binary file not shown.
Binary file modified Libraries/SEModAPIInternal.dll
Binary file not shown.
67 changes: 49 additions & 18 deletions WarpDrivePlugin/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,27 @@ public override void Update()
TimeSpan timeSinceLastFullScan = DateTime.Now - m_lastFullScan;
if (timeSinceLastFullScan.TotalMilliseconds > 30000)
{
LogManager.APILog.WriteLine("Scanning all entities for valid warp drives ...");
m_lastFullScan = DateTime.Now;
LogManager.APILog.WriteLine("WarpDrivePlugin - Initializing full scan ...");

//Run cleanup
CleanUpEngineMap();

//Run full scan
FullScan();
//Queue up a full scan
Action action = FullScan;
SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action);
}
}

public override void Shutdown()
{
foreach (WarpEngine warpEngine in m_warpEngineMap.Values)
{
warpEngine.Dispose();
}
m_warpEngineMap.Clear();
}

public void OnCubeBlockCreated(CubeBlockEntity cubeBlock)
{
CubeGridEntity cubeGrid = cubeBlock.Parent;
Expand Down Expand Up @@ -267,31 +278,43 @@ public void OnCubeBlockCreated(CubeBlockEntity cubeBlock)

public void OnCubeBlockDeleted(CubeBlockEntity cubeBlock)
{
if (cubeBlock.Parent.GridSizeEnum != MyCubeSize.Large)
if (cubeBlock == null)
return;

CubeGridEntity cubeGrid = cubeBlock.Parent;

if (cubeGrid == null || !m_warpEngineMap.ContainsKey(cubeGrid))
//Check for invalid cube grid
if (cubeGrid == null)
return;
if (cubeGrid.GridSizeEnum != MyCubeSize.Large)
return;
if (!m_warpEngineMap.ContainsKey(cubeGrid))
return;
if (cubeGrid.IsDisposed)
{
RemoveWarpEngine(cubeGrid);
return;
}

//Check for invalid warp engine
WarpEngine warpEngine = m_warpEngineMap[cubeGrid];
bool shouldRemove = false;
if (warpEngine == null)
return;
if (warpEngine.IsDisposed)
{
RemoveWarpEngine(cubeGrid);
return;
}

//Check for invalid blocks
foreach (CubeBlockEntity block in warpEngine.Blocks)
{
if (block == null || block == cubeBlock || block.IsDisposed)
{
shouldRemove = true;
RemoveWarpEngine(cubeGrid);
break;
}
}
if (cubeGrid.IsDisposed)
shouldRemove = true;

if (shouldRemove)
{
RemoveWarpEngine(cubeGrid);
}
}

#endregion
Expand Down Expand Up @@ -339,18 +362,26 @@ protected bool CheckEngineForRemoval(WarpEngine engine)

protected void CleanUpEngineMap()
{
foreach (WarpEngine engine in m_warpEngineMap.Values)
try
{
if (CheckEngineForRemoval(engine))
foreach (WarpEngine engine in m_warpEngineMap.Values)
{
RemoveWarpEngine(engine.Parent);
if (CheckEngineForRemoval(engine))
{
RemoveWarpEngine(engine.Parent);
}
}
}
catch (Exception ex)
{
LogManager.GameLog.WriteLine(ex);
}
}

protected void FullScan()
{
m_lastFullScan = DateTime.Now;
LogManager.APILog.WriteLine("WarpDrivePlugin - Scanning all entities for valid warp drives ...");

foreach (BaseEntity entity in SectorObjectManager.Instance.GetTypedInternalData<BaseEntity>())
{
try
Expand Down
4 changes: 2 additions & 2 deletions WarpDrivePlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.1.4.0")]
[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: AssemblyVersion("0.1.4.1")]
[assembly: AssemblyFileVersion("0.1.4.1")]

0 comments on commit 0ac8458

Please sign in to comment.