Skip to content

Commit

Permalink
an
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas committed Feb 19, 2024
1 parent d28b6c9 commit a2758cb
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Heart_Module.Data.Scripts.HeartModule.ErrorHandler;
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.ModAPI;
Expand All @@ -15,6 +16,7 @@ namespace Heart_Module.Data.Scripts.HeartModule.Projectiles
public partial class ProjectileManager : MySessionComponentBase
{
public static ProjectileManager I = new ProjectileManager();
public ProjectileNetwork Network = new ProjectileNetwork();

private Dictionary<uint, Projectile> ActiveProjectiles = new Dictionary<uint, Projectile>();
private HashSet<Projectile> ProjectilesWithHealth = new HashSet<Projectile>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Heart_Module.Data.Scripts.HeartModule.Projectiles.StandardClasses;
using Sandbox.ModAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -8,7 +10,7 @@

namespace Heart_Module.Data.Scripts.HeartModule.Projectiles.ProjectileNetworking
{
public class ProjectileNetworking
public class ProjectileNetwork
{
const int ProjectilesPerPacket = 50;
const int TicksPerPacket = 4;
Expand Down Expand Up @@ -36,12 +38,23 @@ public void QueueSync_FireEvent(IMyPlayer player, SorterWeaponLogic weapon, Proj

}

public void Recieve_PP()
internal void Recieve_PP(n_SerializableProjectileInfos projectileInfos)
{
if (MyAPIGateway.Session.IsServer)
return;

for (int i = 0; i < projectileInfos.UniqueProjectileId.Length; i++)
{
n_SerializableProjectile projectile = new n_SerializableProjectile()
{

};

ProjectileManager.I.UpdateProjectileSync(projectile);
}
}

public void Recieve_FireEvent()
internal void Recieve_FireEvent(n_SerializableFireEvents fireEvents)
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,128 @@ 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)
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;

playerRelativeX = new float[positionRelativeToPlayer.Length];
playerRelativeY = new float[positionRelativeToPlayer.Length];
playerRelativeZ = new float[positionRelativeToPlayer.Length];
for (int i = 0; i < positionRelativeToPlayer.Length; i++)
{
playerRelativeX[i] = positionRelativeToPlayer[i].X;
playerRelativeY[i] = positionRelativeToPlayer[i].Y;
playerRelativeZ[i] = positionRelativeToPlayer[i].Z;
}

directionX = new float[direction.Length];
directionY = new float[direction.Length];
directionZ = new float[direction.Length];
for (int i = 0; i < direction.Length; i++)
{
directionX[i] = direction[i].X;
directionY[i] = direction[i].Y;
directionZ[i] = direction[i].Z;
}

DefinitionId = definitionId;
MillisecondsFromMidnight = msFromMidnight;
FirerEntityId = firerEntityId;
TargetEntityId = targetEntityId;
ProjectileAge = projectileAge;
}

public n_SerializableProjectileInfos(Projectile projectile, IMyCharacter character, ProjectileDetailLevel detailLevel = ProjectileDetailLevel.Full)
public n_SerializableProjectileInfos(List<Projectile> projectiles, 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;
UniqueProjectileId = new uint[projectiles.Count];
playerRelativeX = new float[projectiles.Count];
playerRelativeY = new float[projectiles.Count];
playerRelativeZ = new float[projectiles.Count];
directionX = new float[projectiles.Count];
directionY = new float[projectiles.Count];
directionZ = new float[projectiles.Count];
MillisecondsFromMidnight = new int[projectiles.Count];

if (detailLevel != ProjectileDetailLevel.Minimal)
{
DefinitionId = projectile.DefinitionId;
FirerEntityId = projectile.Firer;
DefinitionId = new int[projectiles.Count];
FirerEntityId = new long[projectiles.Count];
if (detailLevel != ProjectileDetailLevel.NoGuidance)
{
TargetEntityId = projectile.Guidance?.GetTarget()?.EntityId;
ProjectileAge = (uint)(projectile.Age * 60);
TargetEntityId = new long?[projectiles.Count];
ProjectileAge = new uint[projectiles.Count];
}
}


Vector3D characterPos = character.GetPosition();

for (int i = 0; i < projectiles.Count; i++)
{
UniqueProjectileId[i] = projectiles[i].Id;
playerRelativeX[i] = (float)(projectiles[i].Position.X - characterPos.X);
playerRelativeY[i] = (float)(projectiles[i].Position.Y - characterPos.Y);
playerRelativeZ[i] = (float)(projectiles[i].Position.Z - characterPos.Z);
directionX[i] = (float)projectiles[i].Direction.X;
directionY[i] = (float)projectiles[i].Direction.Y;
directionZ[i] = (float)projectiles[i].Direction.Z;

MillisecondsFromMidnight[i] = (int)DateTime.Now.TimeOfDay.TotalMilliseconds;

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


[ProtoMember(21)] public uint UniqueProjectileId;
[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(22)] private float[] playerRelativeX;
[ProtoMember(23)] private float[] playerRelativeY;
[ProtoMember(24)] private float[] playerRelativeZ;

[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 (!!!)
public Vector3[] PlayerRelativePosition() // just using a Vector3 adds 2 extra bytes (!!!)
{
Vector3[] array = new Vector3[playerRelativeX.Length];

for (int i = 0; i < array.Length; i++)
array[i] = new Vector3(playerRelativeX[i], playerRelativeY[i], playerRelativeZ[i]);

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

[ProtoMember(31)] public long? TargetEntityId;
[ProtoMember(32)] public uint? ProjectileAge;
[ProtoMember(25)] private float[] directionX;
[ProtoMember(26)] private float[] directionY;
[ProtoMember(27)] private float[] directionZ;

public Vector3[] Direction() // just using a Vector3 adds 2 extra bytes (!!!)
{
Vector3[] array = new Vector3[directionX.Length];

for (int i = 0; i < array.Length; i++)
array[i] = new Vector3(directionX[i], directionY[i], directionZ[i]);

return array;
}

[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)
{

ProjectileManager.I.Network.Recieve_PP(this);
}

public enum ProjectileDetailLevel
Expand All @@ -95,30 +155,46 @@ internal class n_SerializableFireEvents : PacketBase
{
public n_SerializableFireEvents() { }

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

directionX = new float[direction.Length];
directionY = new float[direction.Length];
directionZ = new float[direction.Length];
for (int i = 0; i < direction.Length; i++)
{
directionX[i] = direction[i].X;
directionY[i] = direction[i].Y;
directionZ[i] = direction[i].Z;
}

MillisecondsFromMidnight = millisecondsFromMidnight;
}

[ProtoMember(21)] public long FirerWeaponId;
[ProtoMember(22)] public uint UniqueProjectileId;
[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(23)] private float[] directionX;
[ProtoMember(24)] private float[] directionY;
[ProtoMember(25)] private float[] directionZ;

public Vector3[] Direction() // just using a Vector3 adds 2 extra bytes (!!!)
{
Vector3[] array = new Vector3[directionX.Length];

[ProtoMember(26)] public int MillisecondsFromMidnight;
for (int i = 0; i < array.Length; i++)
array[i] = new Vector3(directionX[i], directionY[i], directionZ[i]);

return array;
}

[ProtoMember(26)] public int[] MillisecondsFromMidnight;

public override void Received(ulong SenderSteamId)
{

ProjectileManager.I.Network.Recieve_FireEvent(this);
}
}
}

0 comments on commit a2758cb

Please sign in to comment.