networking progress

This commit is contained in:
2023-04-06 21:12:04 +03:00
parent 59ef64fe3b
commit 7228c51dd7
32 changed files with 1084 additions and 261 deletions

View File

@@ -87,6 +87,11 @@ namespace Game
public const byte DemoVer = 1;
public PlayerState currentState;
public ulong frame;
//public ulong oldestFrame;
private PlayerState[] states = new PlayerState[120];
public virtual bool Predict => false;
public virtual void OnUpdate()
{
@@ -98,12 +103,43 @@ namespace Game
public virtual void OnEndFrame()
{
states[frame % 120] = currentState;
/*ulong oldest = ulong.MaxValue;
for (int i = 0; i < 120; i++)
oldest = states[i].input.frame < oldest ? states[i].input.frame : oldest;
oldestFrame = oldest;*/
frame++;
}
public virtual void RecordCurrentActorState(PlayerActorState actorState)
{
}
public bool GetState(ulong frame, out PlayerInputState inputState, out PlayerActorState actorState)
{
int frameIndex = (int)frame % 120;
if (states[frameIndex].input.frame != frame)
{
inputState = default;
actorState = default;
return false;
}
inputState = states[frameIndex].input;
actorState = states[frameIndex].actor;
return true;
}
public void SetState(ulong frame, ref PlayerInputState inputState, ref PlayerActorState actorState)
{
int frameIndex = (int)frame % 120;
states[frameIndex].input = inputState;
states[frameIndex].input.frame = frame;
states[frameIndex].actor = actorState;
}
public PlayerInputState GetCurrentInputState()
{
return currentState.input;