Skip to content

Commit

Permalink
Refactor projectile infos
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas committed Feb 19, 2024
1 parent aa24705 commit d28b6c9
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public override void LoadData()
CriticalHandle.ThrowCriticalException(ex, typeof(HeartLoad));
}

HeartData.I.Log.Log("Small: " + MyAPIGateway.Utilities.SerializeToBinary(new n_SerializableProjectileInfo(1, Vector3.One, Vector3.Forward, 3, 235345645)).Length);
HeartData.I.Log.Log("Large: " + MyAPIGateway.Utilities.SerializeToBinary(new n_SerializableProjectileInfo(1, Vector3.One, Vector3.Forward, 3, 235345645, 345345, 3453454, 124334)).Length);
HeartData.I.Log.Log("Event: " + MyAPIGateway.Utilities.SerializeToBinary(new n_SerializableFireEvent(1, 234, Vector3.One, 12434)).Length);
HeartData.I.Log.Log("Small: " + MyAPIGateway.Utilities.SerializeToBinary(new n_SerializableProjectileInfos(1, Vector3.One, Vector3.Forward, 3, 235345645)).Length);
HeartData.I.Log.Log("Large: " + MyAPIGateway.Utilities.SerializeToBinary(new n_SerializableProjectileInfos(1, Vector3.One, Vector3.Forward, 3, 235345645, 345345, 3453454, 124334)).Length);
HeartData.I.Log.Log("Event: " + MyAPIGateway.Utilities.SerializeToBinary(new n_SerializableFireEvents(1, 234, Vector3.One, 12434)).Length);
}

public override void UpdateAfterSimulation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ public ProjectileGuidance(Projectile projectile)
projectile.Velocity = projectile.Definition.PhysicalProjectile.Velocity;
}

public IMyEntity GetTarget()
{
return targetEntity;
}

public void SetTarget(IMyEntity target)
{
targetEntity = target;
if (IsTargetAllowed(target, stages.First.Value))
targetEntity = target;
}

public void RunGuidance(float delta)
Expand Down Expand Up @@ -189,9 +195,12 @@ internal void PreformRaycast(Guidance currentstage)
}
}

internal bool IsTargetAllowed(IMyEntity target, Guidance currentStage)
internal bool IsTargetAllowed(IMyEntity target, Guidance? currentStage)
{
if (projectile.Firer == 0) return true;
if (currentStage == null)
return false;
if (projectile.Firer == 0)
return true;
IMyEntity firer = MyAPIGateway.Entities.GetEntityById(projectile.Firer);
if (firer == null || !(firer is IMyCubeBlock))
return true;
Expand All @@ -206,16 +215,16 @@ internal bool IsTargetAllowed(IMyEntity target, Guidance currentStage)
return true;

if ((relations == MyRelationsBetweenPlayerAndBlock.NoOwnership || relations == MyRelationsBetweenPlayerAndBlock.Neutral) &&
(currentStage.IFF & IFF_Enum.TargetNeutrals) == IFF_Enum.TargetNeutrals)
(currentStage?.IFF & IFF_Enum.TargetNeutrals) == IFF_Enum.TargetNeutrals)
return true;
if ((relations == MyRelationsBetweenPlayerAndBlock.Owner) &&
(currentStage.IFF & IFF_Enum.TargetSelf) == IFF_Enum.TargetSelf)
(currentStage?.IFF & IFF_Enum.TargetSelf) == IFF_Enum.TargetSelf)
return true;
if ((relations == MyRelationsBetweenPlayerAndBlock.Friends) &&
(currentStage.IFF & IFF_Enum.TargetFriendlies) == IFF_Enum.TargetFriendlies)
(currentStage?.IFF & IFF_Enum.TargetFriendlies) == IFF_Enum.TargetFriendlies)
return true;
if ((relations == MyRelationsBetweenPlayerAndBlock.Enemies) &&
(currentStage.IFF & IFF_Enum.TargetEnemies) == IFF_Enum.TargetEnemies)
(currentStage?.IFF & IFF_Enum.TargetEnemies) == IFF_Enum.TargetEnemies)
return true;

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class ProjectileNetworking
const int ProjectilesPerPacket = 50;
const int TicksPerPacket = 4;

private Dictionary<ulong, Queue<n_SerializableProjectileInfo>> SyncStream_PP = new Dictionary<ulong, Queue<n_SerializableProjectileInfo>>();
private Dictionary<ulong, Queue<n_SerializableFireEvent>> SyncStream_FireEvent = new Dictionary<ulong, Queue<n_SerializableFireEvent>>();
private Dictionary<ulong, Queue<n_SerializableProjectileInfos>> SyncStream_PP = new Dictionary<ulong, Queue<n_SerializableProjectileInfos>>();
private Dictionary<ulong, Queue<n_SerializableFireEvents>> SyncStream_FireEvent = new Dictionary<ulong, Queue<n_SerializableFireEvents>>();

public void QueueSync_PP(Projectile projectile)
{
Expand All @@ -36,6 +36,16 @@ public void QueueSync_FireEvent(IMyPlayer player, SorterWeaponLogic weapon, Proj

}

public void Recieve_PP()
{

}

public void Recieve_FireEvent()
{

}


int ticks = 0;
public void Update1()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using Heart_Module.Data.Scripts.HeartModule.Network;
using ProtoBuf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using VRage.Game.ModAPI;
using VRageMath;

namespace Heart_Module.Data.Scripts.HeartModule.Projectiles.ProjectileNetworking
{
// TODO: Make these implement packetbase stuff

[ProtoContract]
internal class n_SerializableProjectileInfos : PacketBase
{
public n_SerializableProjectileInfos() { }

public n_SerializableProjectileInfos(uint uniqueProjectileId, Vector3 positionRelativeToPlayer, Vector3 direction, int definitionId, int msFromMidnight, long? firerEntityId = null, long? targetEntityId = null, uint? projectileAge = null)
{
UniqueProjectileId = uniqueProjectileId;
playerRelativeX = positionRelativeToPlayer.X;
playerRelativeY = positionRelativeToPlayer.Y;
playerRelativeZ = positionRelativeToPlayer.Z;
directionX = direction.X;
directionY = direction.Y;
directionZ = direction.Z;
DefinitionId = definitionId;
MillisecondsFromMidnight = msFromMidnight;
FirerEntityId = firerEntityId;
TargetEntityId = targetEntityId;
ProjectileAge = projectileAge;
}

public n_SerializableProjectileInfos(Projectile projectile, IMyCharacter character, ProjectileDetailLevel detailLevel = ProjectileDetailLevel.Full)
{
UniqueProjectileId = projectile.Id;
playerRelativeX = (float) (projectile.Position.X - character.GetPosition().X);
playerRelativeY = (float) (projectile.Position.Y - character.GetPosition().Y);
playerRelativeZ = (float) (projectile.Position.Z - character.GetPosition().Z);
directionX = (float) projectile.Direction.X;
directionY = (float) projectile.Direction.Y;
directionZ = (float) projectile.Direction.Z;
MillisecondsFromMidnight = (int)DateTime.Now.TimeOfDay.TotalMilliseconds;

if (detailLevel != ProjectileDetailLevel.Minimal)
{
DefinitionId = projectile.DefinitionId;
FirerEntityId = projectile.Firer;
if (detailLevel != ProjectileDetailLevel.NoGuidance)
{
TargetEntityId = projectile.Guidance?.GetTarget()?.EntityId;
ProjectileAge = (uint)(projectile.Age * 60);
}
}
}


[ProtoMember(21)] public uint UniqueProjectileId;

[ProtoMember(22)] private float playerRelativeX;
[ProtoMember(23)] private float playerRelativeY;
[ProtoMember(24)] private float playerRelativeZ;
public Vector3 PlayerRelativePosition => new Vector3(playerRelativeX, playerRelativeY, playerRelativeZ); // just using a Vector3 adds 2 extra bytes (!!!)

[ProtoMember(25)] private float directionX;
[ProtoMember(26)] private float directionY;
[ProtoMember(27)] private float directionZ;
public Vector3 Direction => new Vector3(directionX, directionY, directionZ); // just using a Vector3 adds 2 extra bytes (!!!)

[ProtoMember(28)] public int? DefinitionId;
[ProtoMember(29)] public int MillisecondsFromMidnight;
[ProtoMember(30)] public long? FirerEntityId;

[ProtoMember(31)] public long? TargetEntityId;
[ProtoMember(32)] public uint? ProjectileAge;

public override void Received(ulong SenderSteamId)
{

}

public enum ProjectileDetailLevel
{
Full = 0,
NoGuidance = 1,
Minimal = 2,
}
}

[ProtoContract]
internal class n_SerializableFireEvents : PacketBase
{
public n_SerializableFireEvents() { }

public n_SerializableFireEvents(long firerWeaponId, uint uniqueProjectileId, Vector3 direction, int millisecondsFromMidnight)
{
FirerWeaponId = firerWeaponId;
UniqueProjectileId = uniqueProjectileId;
directionX = direction.X;
directionY = direction.Y;
directionZ = direction.Z;
MillisecondsFromMidnight = millisecondsFromMidnight;
}

[ProtoMember(21)] public long FirerWeaponId;
[ProtoMember(22)] public uint UniqueProjectileId;

[ProtoMember(23)] private float directionX;
[ProtoMember(24)] private float directionY;
[ProtoMember(25)] private float directionZ;
public Vector3 Direction => new Vector3(directionX, directionY, directionZ); // just using a Vector3 adds 2 extra bytes (!!!)


[ProtoMember(26)] public int MillisecondsFromMidnight;

public override void Received(ulong SenderSteamId)
{

}
}
}

0 comments on commit d28b6c9

Please sign in to comment.