From c8628e74b8978f087e733e0221ed8d776c778d81 Mon Sep 17 00:00:00 2001 From: Aristeas <94058548+Jnick-24@users.noreply.github.com> Date: Tue, 12 Mar 2024 18:58:53 -0500 Subject: [PATCH] Basic changes that should probably be in a separate branch Parallel projectile update Null check on weapon's projectile targeting Removed "no PID" message --- .../Projectiles/ProjectileManager.cs | 60 ++++++++++--------- .../Weapons/SorterTurretLogic_Targeting.cs | 3 + .../OrreryFrameworkDemo/ExampleAmmos.cs | 11 ++-- 3 files changed, 42 insertions(+), 32 deletions(-) diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/ProjectileManager.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/ProjectileManager.cs index 95f86f75..c1ad90cc 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/ProjectileManager.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Projectiles/ProjectileManager.cs @@ -1,7 +1,9 @@ using Heart_Module.Data.Scripts.HeartModule.ErrorHandler; +using Heart_Module.Data.Scripts.HeartModule.ExceptionHandler; using Heart_Module.Data.Scripts.HeartModule.Projectiles.ProjectileNetworking; using Heart_Module.Data.Scripts.HeartModule.Projectiles.StandardClasses; using Heart_Module.Data.Scripts.HeartModule.Weapons; +using Sandbox.Game.GUI.DebugInputComponents; using Sandbox.ModAPI; using System; using System.Collections.Generic; @@ -49,39 +51,43 @@ public override void UpdateAfterSimulation() { if (HeartData.I.IsSuspended) return; - // Tick projectiles - foreach (var projectile in ActiveProjectiles.Values.ToArray()) // This can be modified by ModApi calls during run + try { - projectile.TickUpdate(deltaTick); - if (projectile.QueuedDispose) - QueuedCloseProjectiles.Add(projectile); - } + MyAPIGateway.Parallel.ForEach(ActiveProjectiles.Values.ToArray(), UpdateSingleProjectile); + + foreach (var projectile in QueuedCloseProjectiles) + { + 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 + Network.Update1(); - // Queued removal of projectiles - foreach (var projectile in QueuedCloseProjectiles) + DamageHandler.Update(); + + clockTick.Restart(); + } + catch (Exception ex) { - //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 + ""); + SoftHandle.RaiseException(ex, typeof(ProjectileManager)); } - QueuedCloseProjectiles.Clear(); - - // Sync stuff - Network.Update1(); + } - DamageHandler.Update(); + private void UpdateSingleProjectile(Projectile projectile) + { + projectile.TickUpdate(deltaTick); - clockTick.Restart(); + if (projectile.QueuedDispose) + QueuedCloseProjectiles.Add(projectile); } public override void UpdatingStopped() diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic_Targeting.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic_Targeting.cs index 5ebe4005..0230b345 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic_Targeting.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/SorterTurretLogic_Targeting.cs @@ -25,6 +25,9 @@ public void UpdateTargeting() SorterWep.CubeGrid.LinearVelocity, TargetProjectile, 0) ?? Vector3D.MaxValue; UpdateTargetState(AimPoint); + + if (TargetProjectile.QueuedDispose) + TargetProjectile = null; } else if (TargetEntity != null) { diff --git a/OrreryFrameworkDemo/Data/Scripts/OrreryFrameworkDemo/ExampleAmmos.cs b/OrreryFrameworkDemo/Data/Scripts/OrreryFrameworkDemo/ExampleAmmos.cs index 9a6701c5..4e0d4095 100644 --- a/OrreryFrameworkDemo/Data/Scripts/OrreryFrameworkDemo/ExampleAmmos.cs +++ b/OrreryFrameworkDemo/Data/Scripts/OrreryFrameworkDemo/ExampleAmmos.cs @@ -39,7 +39,7 @@ partial class HeartDefinitions AreaDamage = 0, AreaRadius = 0, MaxImpacts = 1, - DamageToProjectiles = 0.2f, + DamageToProjectiles = 0.4f, DamageToProjectilesRadius = 0.2f, }, PhysicalProjectile = new PhysicalProjectile() @@ -47,11 +47,12 @@ partial class HeartDefinitions Velocity = 800, VelocityVariance = 0, Acceleration = 0, - Health = 1, + Health = 0, MaxTrajectory = 4000, MaxLifetime = -1, IsHitscan = false, GravityInfluenceMultiplier = 0.01f, + ProjectileSize = 0.5f, }, Visual = new Visual() { @@ -162,9 +163,9 @@ partial class HeartDefinitions LiveMethods = new LiveMethods() { - OnSpawn = (ProjectileId, Firer) => { - MyVisualScriptLogicProvider.SendChatMessage(ExampleAmmoMissile.Name + "WARNING: SOMEONE HAS FIRED A MISSILE WITHOUT A PID! LAUGH AT HIM!"); - }, + //OnSpawn = (ProjectileId, Firer) => { + // MyVisualScriptLogicProvider.SendChatMessage(ExampleAmmoMissile.Name + "WARNING: SOMEONE HAS FIRED A MISSILE WITHOUT A PID! LAUGH AT HIM!"); + //}, //OnSpawn = (ProjectileId, Firer) => { // HeartApi.LogWriteLine("OnSpawn " + ProjectileId + " | " + HeartApi.BlockHasWeapon(Firer));