netcode progress, improved handling of missing frames

This commit is contained in:
2025-09-07 18:45:24 +03:00
parent 0d324c0ff0
commit 95de571eb5
9 changed files with 259 additions and 46 deletions

View File

@@ -1,15 +1,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using FlaxEngine;
namespace Game;
[StructLayout(LayoutKind.Sequential)]
public struct PlayerInputState2
public struct PlayerInputState2 : IEquatable<PlayerInputState2>
{
public ulong Frame;
public Float2 ViewDelta;
@@ -17,6 +19,22 @@ public struct PlayerInputState2
public float MoveRight;
public bool Attack;
public bool Jump;
/*public override bool Equals([NotNullWhen(true)] object obj)
{
if (obj is not PlayerInputState2 other)
return false;
return Frame == other.Frame && ViewDelta == other.ViewDelta && MoveForward == other.MoveForward && MoveRight == other.MoveRight && Attack == other.Attack && Jump == other.Jump;
}*/
public bool Equals(PlayerInputState2 other)
{
return Frame == other.Frame && ViewDelta == other.ViewDelta && MoveForward == other.MoveForward && MoveRight == other.MoveRight && Attack == other.Attack && Jump == other.Jump;
}
public static bool operator ==(PlayerInputState2 left, PlayerInputState2 right) => left.Equals(right);
public static bool operator !=(PlayerInputState2 left, PlayerInputState2 right) => !left.Equals(right);
}
public interface IPlayerInput
@@ -80,6 +98,9 @@ public class PlayerInput2 : IPlayerInput
_recordState.Attack |= Input.GetAction("Attack");
_recordState.Jump |= Input.GetAction("Jump");
_recordState.Frame = _frame;
if (Input.GetKeyDown(KeyboardKeys.F))
Thread.Sleep(20);
}
public PlayerInputState2 GetState() => _recordState;