Skip to content

Commit

Permalink
Basic changes that should probably be in a separate branch
Browse files Browse the repository at this point in the history
Parallel projectile update
Null check on weapon's projectile targeting
Removed "no PID" message
  • Loading branch information
ari-steas committed Mar 12, 2024
1 parent 0b4ee24 commit c8628e7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ partial class HeartDefinitions
AreaDamage = 0,
AreaRadius = 0,
MaxImpacts = 1,
DamageToProjectiles = 0.2f,
DamageToProjectiles = 0.4f,
DamageToProjectilesRadius = 0.2f,
},
PhysicalProjectile = new PhysicalProjectile()
{
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()
{
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit c8628e7

Please sign in to comment.