394 lines
13 KiB
C#
394 lines
13 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using FidelityFX;
|
|
using FlaxEditor.Content.Settings;
|
|
using FlaxEngine;
|
|
|
|
namespace Game
|
|
{
|
|
// Holds Console variables and commands to control engine behaviour
|
|
public static class EngineSubsystem
|
|
{
|
|
private static FSR _fsrPlugin;
|
|
|
|
// TODO: this should manually set all postprocessing values to 0 or disabled
|
|
/*[ConsoleVariable("r_postprocessing")]
|
|
public static string PostProcessing
|
|
{
|
|
get
|
|
{
|
|
PostFxVolume postFx = Level.FindActor<PostFxVolume>();
|
|
if (postFx != null)
|
|
return postFx.CameraArtifacts.OverrideFlags.ToString();
|
|
return "";
|
|
}
|
|
set
|
|
{
|
|
bool valueBoolean = false;
|
|
if (int.TryParse(value, out int valueInt))
|
|
valueBoolean = valueInt != 0;
|
|
else
|
|
return;
|
|
|
|
PostFxVolume postFx = Level.FindActor<PostFxVolume>();
|
|
if (postFx != null)
|
|
{
|
|
var cameraArtifacts = postFx.CameraArtifacts;
|
|
cameraArtifacts.OverrideFlags = valueBoolean ? CameraArtifactsSettingsOverride.None : CameraArtifactsSettingsOverride.All;
|
|
postFx.CameraArtifacts = cameraArtifacts;
|
|
}
|
|
}
|
|
}*/
|
|
|
|
[ConsoleVariable("r_vignette")]
|
|
public static string Vignette
|
|
{
|
|
get
|
|
{
|
|
return Graphics.PostProcessSettings.CameraArtifacts.VignetteIntensity.ToString();
|
|
}
|
|
set
|
|
{
|
|
if (float.TryParse(value, out float valueFloat))
|
|
{
|
|
valueFloat = Mathf.Clamp(valueFloat, 0.0f, 2.0f);
|
|
|
|
PostProcessSettings postProcessSettings = Graphics.PostProcessSettings;
|
|
CameraArtifactsSettings cameraArtifacts = postProcessSettings.CameraArtifacts;
|
|
cameraArtifacts.VignetteIntensity = valueFloat;
|
|
postProcessSettings.CameraArtifacts = cameraArtifacts;
|
|
Graphics.PostProcessSettings = postProcessSettings;
|
|
}
|
|
}
|
|
}
|
|
|
|
[ConsoleVariable("cl_maxfps")]
|
|
public static string MaxFps
|
|
{
|
|
get => Time.UpdateFPS.ToString();
|
|
set
|
|
{
|
|
if (float.TryParse(value, out float valueFloat))
|
|
{
|
|
if (valueFloat <= 0.0f)
|
|
valueFloat = 0.0f;
|
|
else
|
|
valueFloat = Mathf.Clamp(valueFloat, 10f, 99999999999.0f);
|
|
|
|
if (Time.UpdateFPS != valueFloat)
|
|
Time.UpdateFPS = valueFloat;
|
|
if (Time.DrawFPS != valueFloat)
|
|
Time.DrawFPS = valueFloat;
|
|
}
|
|
}
|
|
}
|
|
|
|
[ConsoleVariable("r_renderscale")]
|
|
public static string RenderScale
|
|
{
|
|
get => MainRenderTask.Instance.RenderingPercentage.ToString();
|
|
set
|
|
{
|
|
if (float.TryParse(value, out float valueFloat))
|
|
{
|
|
valueFloat = Mathf.Clamp(valueFloat, 0.00001f, 4.0f);
|
|
MainRenderTask.Instance.RenderingPercentage = valueFloat;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static FSR FsrPlugin
|
|
{
|
|
get
|
|
{
|
|
if (_fsrPlugin == null)
|
|
_fsrPlugin = PluginManager.GetPlugin<FSR>();
|
|
return _fsrPlugin;
|
|
}
|
|
}
|
|
|
|
// TODO: r_upscaling
|
|
[ConsoleVariable("r_fsr_enabled")]
|
|
public static string FsrEnabled
|
|
{
|
|
get => FsrPlugin.PostFx.Enabled ? "1" : "0";
|
|
set
|
|
{
|
|
bool boolValue = false;
|
|
if (int.TryParse(value, out int intValue))
|
|
boolValue = intValue != 0;
|
|
else if (float.TryParse(value, out float valueFloat))
|
|
boolValue = valueFloat != 0f;
|
|
|
|
FsrPlugin.PostFx.Enabled = boolValue;
|
|
}
|
|
}
|
|
|
|
[ConsoleVariable("r_fsr_sharpness")]
|
|
public static string FsrSharpness
|
|
{
|
|
get
|
|
{
|
|
// In shader, the value of 0 is the max sharpness...
|
|
float sharpness = 2.0f - FsrPlugin.PostFx.Sharpness;
|
|
return sharpness.ToString();
|
|
}
|
|
set
|
|
{
|
|
if (float.TryParse(value, out float valueFloat))
|
|
{
|
|
valueFloat = Mathf.Clamp(valueFloat, 0f, 2.0f);
|
|
FsrPlugin.PostFx.Sharpness = 2.0f - valueFloat;
|
|
}
|
|
}
|
|
}
|
|
|
|
[ConsoleVariable("cl_showweapon")]
|
|
public static string ShowWeapon
|
|
{
|
|
get => Level.FindActor("ViewModelCamera").IsActive ? "1" : "0";
|
|
set
|
|
{
|
|
bool boolValue = false;
|
|
if (int.TryParse(value, out int intValue))
|
|
boolValue = intValue != 0;
|
|
else if (float.TryParse(value, out float valueFloat))
|
|
boolValue = valueFloat != 0f;
|
|
|
|
Level.FindActor("ViewModelCamera").IsActive = boolValue;
|
|
}
|
|
}
|
|
|
|
|
|
// Horizontal field of view of the Camera
|
|
[ConsoleVariable("fov")]
|
|
public static string CameraFov
|
|
{
|
|
get
|
|
{
|
|
float valueFloat = Level.FindActor("PlayerCamera").As<Camera>().FieldOfView;
|
|
float horizontalFov = (float)(180.0f / Math.PI *
|
|
(2 * Math.Atan(4f / 3f *
|
|
Math.Tan(Math.PI / 180.0f * valueFloat / 2.0f))));
|
|
return horizontalFov.ToString();
|
|
}
|
|
set
|
|
{
|
|
if (float.TryParse(value, out float valueFloat))
|
|
{
|
|
valueFloat = Mathf.Clamp(valueFloat, 0.01f, 360.0f);
|
|
|
|
float verticalFov = (float)(180.0f / Math.PI *
|
|
(2 * Math.Atan(3f / 4f *
|
|
Math.Tan(Math.PI / 180.0f * valueFloat / 2.0f))));
|
|
Level.FindActor("PlayerCamera").As<Camera>().FieldOfView = verticalFov;
|
|
}
|
|
}
|
|
}
|
|
|
|
[ConsoleVariable("r_lighting")]
|
|
public static string SceneLighting
|
|
{
|
|
get
|
|
{
|
|
return ((bool)AssetManager.Globals.GetValue("Scene Lighting") ? "1" : "0");
|
|
}
|
|
set
|
|
{
|
|
bool boolValue = false;
|
|
if (int.TryParse(value, out int intValue))
|
|
boolValue = intValue != 0;
|
|
else if (float.TryParse(value, out float valueFloat))
|
|
boolValue = valueFloat != 0f;
|
|
|
|
AssetManager.Globals.SetValue("Scene Lighting", boolValue);
|
|
AmbientOcclusion = value;
|
|
GlobalIllumination = value;
|
|
}
|
|
}
|
|
|
|
[ConsoleVariable("r_ambientocclusion")]
|
|
public static string AmbientOcclusion
|
|
{
|
|
get
|
|
{
|
|
return Graphics.PostProcessSettings.AmbientOcclusion.Enabled ? "1" : "0";
|
|
}
|
|
set
|
|
{
|
|
bool boolValue = false;
|
|
if (int.TryParse(value, out int intValue))
|
|
boolValue = intValue != 0;
|
|
else if (float.TryParse(value, out float valueFloat))
|
|
boolValue = valueFloat != 0f;
|
|
|
|
PostProcessSettings postProcessSettings = Graphics.PostProcessSettings;
|
|
AmbientOcclusionSettings aoSettings = postProcessSettings.AmbientOcclusion;
|
|
/*aoSettings.OverrideFlags = (aoSettings.OverrideFlags & ~AmbientOcclusionSettingsOverride.Enabled) |
|
|
(boolValue
|
|
? AmbientOcclusionSettingsOverride.Enabled
|
|
: 0 & AmbientOcclusionSettingsOverride.Enabled);
|
|
*/
|
|
|
|
aoSettings.Enabled = boolValue;
|
|
postProcessSettings.AmbientOcclusion = aoSettings;
|
|
}
|
|
}
|
|
|
|
[ConsoleVariable("r_vsync")]
|
|
public static string Vsync
|
|
{
|
|
get
|
|
{
|
|
return Graphics.UseVSync ? "1" : "0";
|
|
}
|
|
set
|
|
{
|
|
bool boolValue = false;
|
|
if (int.TryParse(value, out int intValue))
|
|
boolValue = intValue != 0;
|
|
else if (float.TryParse(value, out float valueFloat))
|
|
boolValue = valueFloat != 0f;
|
|
|
|
Graphics.UseVSync = boolValue;
|
|
}
|
|
}
|
|
|
|
[ConsoleVariable("r_gi")]
|
|
public static string GlobalIllumination
|
|
{
|
|
get
|
|
{
|
|
return Graphics.PostProcessSettings.GlobalIllumination.Mode == GlobalIlluminationMode.DDGI ? "1" : "0";
|
|
}
|
|
set
|
|
{
|
|
bool boolValue = false;
|
|
if (int.TryParse(value, out int intValue))
|
|
boolValue = intValue != 0;
|
|
else if (float.TryParse(value, out float valueFloat))
|
|
boolValue = valueFloat != 0f;
|
|
|
|
PostProcessSettings postProcessSettings = Graphics.PostProcessSettings;
|
|
|
|
GlobalIlluminationSettings giSettings = postProcessSettings.GlobalIllumination;
|
|
giSettings.Mode = boolValue ? GlobalIlluminationMode.DDGI : GlobalIlluminationMode.None;
|
|
postProcessSettings.GlobalIllumination = giSettings;
|
|
|
|
Graphics.PostProcessSettings = postProcessSettings;
|
|
|
|
Graphics.EnableGlobalSDF = boolValue;
|
|
}
|
|
}
|
|
|
|
[ConsoleVariable("r_shadows")]
|
|
public static string SceneShadows
|
|
{
|
|
get
|
|
{
|
|
return ((bool)AssetManager.Globals.GetValue("Scene Shadows") ? "1" : "0");
|
|
}
|
|
set
|
|
{
|
|
bool boolValue = false;
|
|
if (int.TryParse(value, out int intValue))
|
|
boolValue = intValue != 0;
|
|
else if (float.TryParse(value, out float valueFloat))
|
|
boolValue = valueFloat != 0f;
|
|
|
|
AssetManager.Globals.SetValue("Scene Shadows", boolValue);
|
|
}
|
|
}
|
|
|
|
[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);
|
|
}
|
|
|
|
private static Action timeDemoUpdate = null;
|
|
private static void TimeDemoOnUpdate()
|
|
{
|
|
if (timeDemoUpdate != null)
|
|
timeDemoUpdate();
|
|
}
|
|
|
|
[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);
|
|
|
|
float accumTime = 0f;
|
|
int accumTimes = 0;
|
|
timeDemoUpdate = () =>
|
|
{
|
|
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}");
|
|
timeDemoUpdate = null;
|
|
return;
|
|
}
|
|
|
|
if (accumTimes == 0)
|
|
Console.Print($"timedemo started");
|
|
|
|
accumTime += Time.DeltaTime;
|
|
accumTimes++;
|
|
}
|
|
}
|
|
};
|
|
|
|
Scripting.Update -= TimeDemoOnUpdate;
|
|
Scripting.Update += TimeDemoOnUpdate;
|
|
}
|
|
|
|
[ConsoleSubsystemInitializer]
|
|
public static void Initialize()
|
|
{
|
|
}
|
|
|
|
[ConsoleCommand("quit", "exit")]
|
|
public static void ExitCommand()
|
|
{
|
|
Engine.RequestExit();
|
|
}
|
|
|
|
[ConsoleCommand("debuglog")]
|
|
public static void DebugLogCommand(string[] text)
|
|
{
|
|
Debug.Log(string.Join(" ", text));
|
|
}
|
|
}
|
|
} |