gzip demos, add playdemo and timedemo commands
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FidelityFX;
|
||||
using FlaxEngine;
|
||||
|
||||
@@ -239,6 +240,73 @@ namespace Game
|
||||
}
|
||||
}
|
||||
|
||||
[ConsoleCommand("playdemo")]
|
||||
public static void PlayDemoCommand(string[] text)
|
||||
{
|
||||
if (text.Length < 1)
|
||||
return;
|
||||
string demoName = text[0];
|
||||
|
||||
if (!demoName.EndsWith(".gdem"))
|
||||
demoName += ".gdem";
|
||||
|
||||
PlayerActor playerActor = Level.GetActors<PlayerActor>().First(x =>
|
||||
x.GetScript<PlayerMovement>().PlayerId == NetworkManager.LocalPlayerClientId);
|
||||
|
||||
string demoPath = Path.Combine(AssetManager.DemoPath, demoName);
|
||||
if (File.Exists(demoPath))
|
||||
playerActor.GetScript<PlayerMovement>().SetInput(demoPath);
|
||||
}
|
||||
|
||||
[ConsoleCommand("timedemo")]
|
||||
public static void TimeDemoCommand(string[] text)
|
||||
{
|
||||
if (text.Length < 1)
|
||||
return;
|
||||
string demoName = text[0];
|
||||
|
||||
if (!demoName.EndsWith(".gdem"))
|
||||
demoName += ".gdem";
|
||||
|
||||
PlayerActor playerActor = Level.GetActors<PlayerActor>().First(x =>
|
||||
x.GetScript<PlayerMovement>().PlayerId == NetworkManager.LocalPlayerClientId);
|
||||
|
||||
var playerMovement = playerActor.GetScript<PlayerMovement>();
|
||||
string demoPath = Path.Combine(AssetManager.DemoPath, demoName);
|
||||
if (File.Exists(demoPath))
|
||||
playerMovement.SetInput(demoPath);
|
||||
|
||||
Action onUpdate = () => {};
|
||||
//bool lastPlaying = true;
|
||||
float accumTime = 0f;
|
||||
int accumTimes = 0;
|
||||
onUpdate = () =>
|
||||
{
|
||||
if (playerMovement)
|
||||
{
|
||||
var input = playerMovement.input as PlayerInputDemo;
|
||||
if (input != null)
|
||||
{
|
||||
if (!input.IsPlaying)
|
||||
{
|
||||
Console.Print($"demo ended, time: {accumTimes} frames, avg: {(accumTime/(float)accumTimes)*1000.0f}");
|
||||
Scripting.Update -= onUpdate;
|
||||
return;
|
||||
}
|
||||
|
||||
if (accumTimes == 0)
|
||||
Console.Print($"timedemo started");
|
||||
|
||||
accumTime += Time.DeltaTime;
|
||||
accumTimes++;
|
||||
//input.IsPlaying
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Scripting.Update += onUpdate;
|
||||
}
|
||||
|
||||
[ConsoleSubsystemInitializer]
|
||||
public static void Initialize()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user