working replay system

This commit is contained in:
2022-03-21 19:01:28 +02:00
parent 99637255da
commit 4997077978
17 changed files with 243 additions and 108 deletions

View File

@@ -4,6 +4,7 @@ using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using FlaxEngine;
using Console = Cabrito.Console;
namespace Game
{
@@ -14,10 +15,6 @@ namespace Game
public bool IsRecording { get { return demoFileStream != null; } }
public PlayerInputLocal()
{
}
public PlayerInputLocal(string demoPath)
{
demoFileStream = File.Open(demoPath, FileMode.Create, FileAccess.Write);
@@ -29,32 +26,55 @@ namespace Game
public override void OnUpdate()
{
lastState = currentState;
// Collect anything framerate independent here like camera movement
// All axis values here should be accumulated, and binary actions OR'ed
currentState.input.viewDeltaX += InputManager.GetAxisRaw("Mouse X");
currentState.input.viewDeltaY += InputManager.GetAxisRaw("Mouse Y");
// Record camera angles here?
currentState.input.viewDeltaX = InputManager.GetAxisRaw("Mouse X");
currentState.input.viewDeltaY = InputManager.GetAxisRaw("Mouse Y");
}
public override void OnFixedUpdate()
{
// Record intent here
currentState.input.moveForward = InputManager.GetAxis("Vertical");
currentState.input.moveRight = InputManager.GetAxis("Horizontal");
currentState.input.attacking = InputManager.GetAction("Attack");
currentState.input.jumping = InputManager.GetAction("Jump");
}
public override void OnFixedUpdate()
{
// Collect all input here
/*currentState.input.moveForward = InputManager.GetAxis("Vertical");
currentState.input.moveRight = InputManager.GetAxis("Horizontal");
currentState.input.attacking = InputManager.GetAction("Attack");
currentState.input.jumping = InputManager.GetAction("Jump");*/
}
public override void OnEndFrame()
{
if (IsRecording)
{
currentState.input.verificationPosition = currentState.actor.position;
currentState.input.verificationOrientation = currentState.actor.orientation;
currentState.input.verificationVelocity = currentState.actor.velocity;
currentState.input.frame = frame;
buffer.Add(currentState.input);
}
// Reset anything accumulatable here
currentState.input.viewDeltaX = 0;
currentState.input.viewDeltaY = 0;
frame++;
}
public override void RecordCurrentActorState(PlayerActorState actorState)
{
if (!IsRecording)
return;
if (actorState.position.Length <= 0.01)
Console.Print("wrong recorded position?");
currentState.actor = actorState;
}
public void FlushDemo()
{
if (!IsRecording)