Skip to content

Commit

Permalink
billions must multithread???
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas committed Feb 9, 2024
1 parent 007f0c3 commit d15fd41
Showing 1 changed file with 61 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Heart_Module.Data.Scripts.HeartModule.ErrorHandler;
using Heart_Module.Data.Scripts.HeartModule.Projectiles.StandardClasses;
using Heart_Module.Data.Scripts.HeartModule.Weapons;
using ParallelTasks;
using Sandbox.Game.Entities;
using Sandbox.ModAPI;
using System;
Expand Down Expand Up @@ -46,52 +47,74 @@ protected override void UnloadData()
DamageHandler.Unload();
}

public override void UpdateAfterSimulation()
private void ProjectileTick(Projectile projectile)
{
if (HeartData.I.IsSuspended) return;
projectile?.UpdateBoundingBoxCheck(allValidEntities);
}

HashSet<BoundingSphere> allValidEntities = new HashSet<BoundingSphere>();
MyAPIGateway.Entities.GetEntities(null, (ent) => {
if (ent is IMyCubeGrid || ent is IMyCharacter)
allValidEntities.Add(ent.WorldVolume);
return false;
}
);
HashSet<BoundingSphere> allValidEntities = new HashSet<BoundingSphere>();

// Tick projectiles
foreach (var projectile in ActiveProjectiles.Values.ToArray()) // This can be modified by ModApi calls during run
public override void UpdateAfterSimulation()
{
try
{
projectile.UpdateBoundingBoxCheck(allValidEntities);
projectile.TickUpdate(deltaTick);
if (projectile.QueuedDispose)
QueuedCloseProjectiles.Add(projectile);
}
if (HeartData.I.IsSuspended) return;

// Queued removal of projectiles
foreach (var projectile in QueuedCloseProjectiles)
{
//MyAPIGateway.Utilities.ShowMessage("Heart", $"Closing projectile {projectile.Id}. Age: {projectile.Age} ");
if (MyAPIGateway.Session.IsServer)
QueueSync(projectile, 2);

if (!MyAPIGateway.Utilities.IsDedicated)
projectile.CloseDrawing();

ActiveProjectiles.Remove(projectile.Id);
if (ProjectilesWithHealth.Contains(projectile))
ProjectilesWithHealth.Remove(projectile);
projectile.OnClose.Invoke(projectile);
if (projectile.Health < 0)
MyAPIGateway.Utilities.ShowNotification(projectile.Id + "");
}
QueuedCloseProjectiles.Clear();
allValidEntities.Clear();
MyAPIGateway.Entities.GetEntities(null, (ent) =>
{
if (ent is IMyCubeGrid || ent is IMyCharacter)
allValidEntities.Add(ent.WorldVolume);
return false;
}
);

// Tick projectiles
MyAPIGateway.Parallel.ForEach(ActiveProjectiles.Values.ToArray(), ProjectileTick);
foreach (var projectile in ActiveProjectiles.Values.ToArray()) // This can be modified by ModApi calls during run
{
projectile.TickUpdate(deltaTick);
if (projectile.QueuedDispose)
QueuedCloseProjectiles.Add(projectile);
}
//foreach (var projectile in ActiveProjectiles.Values.ToArray()) // This can be modified by ModApi calls during run
//{
// projectile.UpdateBoundingBoxCheck(allValidEntities);
// projectile.TickUpdate(deltaTick);
// if (projectile.QueuedDispose)
// QueuedCloseProjectiles.Add(projectile);
//}

// Queued removal of projectiles
foreach (var projectile in QueuedCloseProjectiles)
{
//MyAPIGateway.Utilities.ShowMessage("Heart", $"Closing projectile {projectile.Id}. Age: {projectile.Age} ");
if (MyAPIGateway.Session.IsServer)
QueueSync(projectile, 2);

if (!MyAPIGateway.Utilities.IsDedicated)
projectile.CloseDrawing();

ActiveProjectiles.Remove(projectile.Id);
if (ProjectilesWithHealth.Contains(projectile))
ProjectilesWithHealth.Remove(projectile);
projectile.OnClose.Invoke(projectile);
if (projectile.Health < 0)
MyAPIGateway.Utilities.ShowNotification(projectile.Id + "");
}
QueuedCloseProjectiles.Clear();

// Sync stuff
UpdateSync();
// Sync stuff
UpdateSync();

DamageHandler.Update();
DamageHandler.Update();

clockTick.Restart();
clockTick.Restart();
}
catch (Exception ex)
{
SoftHandle.RaiseException(ex, typeof(ProjectileManager));
}
}

public override void UpdatingStopped()
Expand Down

0 comments on commit d15fd41

Please sign in to comment.