Hello, I'm developing a fast-paced arena FPS with Unity & Photon Server. I was just curious about our performance:
Since it's a fast-paced game (Max 16 players - 8v8) with compact maps so some kind of action happens every second, which means that lots of operations must be sent.
For example: We have a specific operation for damage register event which is sent everytime a hit detection system returns a possible hit to another player. It first serializes a custom type to a byte array and then passes it over for the server to handle.
The custom type looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ExitGames.Client.Photon;
using System.IO;
[System.Serializable]
public class ServerWeaponDamageEvent {
public int ActorID;
public byte ActorCurrentWeaponID;
public byte Critical;
public float TimeSent;
public Vector3 Direction;
///
/// Serializes this custom type into a byte array.
///
/// The binary data.
///
public static void Serialize(Stream stream, ServerWeaponDamageEvent instance)
{
int num = 0;
using (MemoryStream memoryStream = new MemoryStream())
{
IntProxy.Serialize(memoryStream, instance.ActorID);
ByteProxy.Serialize(memoryStream, instance.ActorCurrentWeaponID);
ByteProxy.Serialize(memoryStream, instance.Critical);
SingleProxy.Serialize(memoryStream, instance.TimeSent);
Vector3Proxy.Serialize(memoryStream, instance.Direction);
IntProxy.Serialize(stream, ~num);
memoryStream.WriteTo(stream);
}
}
///
/// Deserializes this custom type from a byte array.
///
/// The custom type object.
///
public static ServerWeaponDamageEvent Deserialize(Stream bytes)
{
int num = IntProxy.Deserialize(bytes);
ServerWeaponDamageEvent damageEvent = new ServerWeaponDamageEvent();
damageEvent.ActorID = ByteProxy.Deserialize(bytes);
damageEvent.ActorCurrentWeaponID = ByteProxy.Deserialize(bytes);
damageEvent.Critical = ByteProxy.Deserialize(bytes);
damageEvent.TimeSent = SingleProxy.Deserialize(bytes);
damageEvent.Direction = Vector3Proxy.Deserialize(bytes);
return damageEvent;
}
}
After that has been sent and server has processed it; a DamageInfo class will be serialized as well and sent back to the client as an event.
The DamageInfo looks like this:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
[System.Serializable]
public class ServerDamageInfo
{
public int DamageAmount;
public PlayerHitboxType BodyPart;
//This is not handled currently by the server.
public float UpwardsForceMultiplier = 150f;
public Vector3 Force;
public bool IsExplosion;
///
/// Serializes this custom type.
///
/// The binary data.
///
public static void Serialize(Stream stream, ServerDamageInfo instance)
{
int num = 0;
using (MemoryStream memoryStream = new MemoryStream())
{
IntProxy.Serialize(memoryStream, instance.DamageAmount);
ByteProxy.Serialize(memoryStream, (byte)instance.BodyPart);
Vector3Proxy.Serialize(memoryStream, instance.Force);
BooleanProxy.Serialize(memoryStream, instance.IsExplosion);
IntProxy.Serialize(stream, ~num);
memoryStream.WriteTo(stream);
}
}
///
/// Deserializes this custom type.
///
/// The custom type object.
///
public static ServerDamageInfo Deserialize(Stream bytes)
{
int num = IntProxy.Deserialize(bytes);
ServerDamageInfo damageEvent = new ServerDamageInfo();
damageEvent.DamageAmount = ByteProxy.Deserialize(bytes);
damageEvent.BodyPart = (PlayerHitboxType)ByteProxy.Deserialize(bytes);
damageEvent.Force = Vector3Proxy.Deserialize(bytes);
damageEvent.IsExplosion = BooleanProxy.Deserialize(bytes);
return damageEvent;
}
}
I was just wondering since it's a fast-paced game and many players, for example could be registering hits to another player with rapid-fire machine guns. How much would these kinds of actions cost performance wise (mostly network-traffic)?
Here are some specifications of our server:
OS: Microsoft Windows Server 2016 Standard 64bit
CPU: Intel Xeon CPU E3-1246 v3 @ 3.50GHz, 4 cores
RAM: 32gb 1600Mhz
Network: 1gbps
Thanks in advance,
Samuel