Skip to content

Commit

Permalink
More docs
Browse files Browse the repository at this point in the history
  • Loading branch information
warent committed Jun 10, 2024
1 parent 583999c commit a06cce4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions addons/HLNC/Serialization/HLBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace HLNC.Serialization
{
/// <summary>
/// Standard object used to package data that will be transferred across the network.
/// Used extensively by <see cref="HLBytes"/>.
/// </summary>
/// <param name="bytes"></param>
public class HLBuffer(byte[] bytes = null)
{
public byte[] bytes = bytes ?? [];
Expand Down
13 changes: 13 additions & 0 deletions addons/HLNC/Serialization/HLBytes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@

namespace HLNC.Serialization
{
/// <summary>
/// Converts variables and <see cref="Godot.Variant">Godot variants</see> into binary and vice-versa. <see cref="HLBuffer"/> is the medium of storage.
/// </summary>
public class HLBytes
{
/// <summary>
/// GZip bytes for smaller network packages.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static byte[] Compress(byte[] data)
{
using (var compressedStream = new MemoryStream())
Expand All @@ -20,6 +28,11 @@ public static byte[] Compress(byte[] data)
}
}

/// <summary>
/// Unzip GZipped bytes.
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static byte[] Decompress(byte[] data)
{
using (var compressedStream = new MemoryStream(data))
Expand Down
22 changes: 22 additions & 0 deletions addons/HLNC/Serialization/Serializers/IStateSerializable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,33 @@
namespace HLNC.Serialization.Serializers
{
public interface IDeserializedData { };

/// <summary>
/// Defines an object which the server utilizes to serialize and send data to the client, and the client can then receive and deserialize from the server.
/// </summary>
public interface IStateSerailizer
{
/// <summary>
/// Client-side only. Receive and deserialize binary received from the server.
/// </summary>
/// <param name="networkState"></param>
/// <param name="data"></param>
/// <param name="nodeOut"></param>
public void Import(IPeerController networkState, HLBuffer data, out NetworkNode3D nodeOut);

/// <summary>
/// Server-side only. Serialize and send data to the client.
/// </summary>
/// <param name="networkState"></param>
/// <param name="peer"></param>
/// <returns></returns>
public HLBuffer Export(IPeerController networkState, PeerId peer);
public void Acknowledge(IPeerController networkState, PeerId peer, Tick tick);

/// <summary>
/// Client-side only. Useful for data interpolation.
/// </summary>
/// <param name="delta"></param>
public void PhysicsProcess(double delta);
public void Cleanup();
}
Expand Down

0 comments on commit a06cce4

Please sign in to comment.