networking progress
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user