using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using FlaxEditor.Content.Settings; using FlaxEngine; using FlaxEngine.Networking; namespace Game; public static class WorldConsoleCommands { [ConsoleCommand("playdemo")] public static void PlayDemoCommand(string[] text) { string demoName; if (text.Length < 1) demoName = "638201307621505588_v2";//return; else demoName = text[0]; if (!demoName.EndsWith(".gdem")) demoName += ".gdem"; string demoPath = Path.Combine(AssetManager.DemoPath, demoName); NetworkManager.PlayDemo(demoPath); #if false PlayerActor playerActor = Level.GetActors().First(/*x => x.GetScript().PlayerId == NetworkManager.LocalPlayerClientId*/); string demoPath = Path.Combine(AssetManager.DemoPath, demoName); if (File.Exists(demoPath)) playerActor.GetScript().SetInput(demoPath); #endif } private static Action timeDemoUpdate = null; private static void TimeDemoOnUpdate() { if (timeDemoUpdate != null) timeDemoUpdate(); } [ConsoleCommand("timedemo")] public static void TimeDemoCommand(string[] text) { string demoName; if (text.Length < 1) demoName = "638201307621505588_v2";//return; else demoName = text[0]; if (!demoName.EndsWith(".gdem")) demoName += ".gdem"; string demoPath = Path.Combine(AssetManager.DemoPath, demoName); NetworkManager.PlayDemo(demoPath); float oldPhysicsFps = Time.PhysicsFPS; float oldFps = Time.UpdateFPS; Time.PhysicsFPS = 0f; Time.UpdateFPS = 0f; Time.DrawFPS = 0f; float accumTime = 0f; int accumTimes = 0; timeDemoUpdate = () => { if (!NetworkManager.IsDemoPlaying) { Console.Print($"timedemo ended, time: {accumTimes} frames, avg: {(accumTime / (float)accumTimes) * 1000.0f}"); timeDemoUpdate = null; Time.PhysicsFPS = oldPhysicsFps; Time.UpdateFPS = oldFps; Time.DrawFPS = oldFps; return; } if (accumTimes == 0) Console.Print($"timedemo started"); accumTime += Time.DeltaTime; accumTimes++; }; Scripting.Update -= TimeDemoOnUpdate; Scripting.Update += TimeDemoOnUpdate; } [ConsoleCommand("timedemo2")] public static void TimeDemo2Command(string[] text) { string demoName; if (text.Length < 1) demoName = "638201307621505588_v2";//return; else demoName = text[0]; if (!demoName.EndsWith(".gdem")) demoName += ".gdem"; string demoPath = Path.Combine(AssetManager.DemoPath, demoName); NetworkManager.PlayDemo(demoPath); float oldPhysicsFps = Time.PhysicsFPS; float oldFps = Time.UpdateFPS; Time.PhysicsFPS = 0f; Time.UpdateFPS = 5f; Time.DrawFPS = 5f; float accumTime = 0f; int accumTimes = 0; timeDemoUpdate = () => { if (!NetworkManager.IsDemoPlaying) { Console.Print($"timedemo ended, time: {accumTimes} frames, avg: {(accumTime / (float)accumTimes) * 1000.0f}"); timeDemoUpdate = null; Time.PhysicsFPS = oldPhysicsFps; Time.UpdateFPS = oldFps; Time.DrawFPS = oldFps; return; } if (accumTimes == 0) Console.Print($"timedemo started"); accumTime += Time.DeltaTime; accumTimes++; }; Scripting.FixedUpdate -= TimeDemoOnUpdate; Scripting.FixedUpdate += TimeDemoOnUpdate; } [ConsoleVariable("net_fakelag")] public static string NetFakeLag { get { var driver = NetworkManager.server != null ? (NetworkManager.ServerNetworkDriver as NetworkLagDriver) : (NetworkManager.ClientNetworkDriver as NetworkLagDriver); if (driver == null) return 0.ToString(); return ((int)driver.Lag).ToString(); } set { var driver = NetworkManager.server != null ? (NetworkManager.ServerNetworkDriver as NetworkLagDriver) : (NetworkManager.ClientNetworkDriver as NetworkLagDriver); if (driver == null) return; int intValue = 0; if (int.TryParse(value, out intValue)) { } else if (float.TryParse(value, out float valueFloat)) intValue = (int)valueFloat; intValue = Math.Clamp(intValue, 0, 2000); driver.Lag = intValue; } } [ConsoleCommand("map")] public static void MapCommand() { //NetworkManager.StartServer(true); NetworkManager.StartServer(); } [ConsoleCommand("connect")] public static void ConnectCommand() { //GameMode.Connect(); NetworkManager.ConnectServer(); } }