245 lines
8.2 KiB
C#
245 lines
8.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using FidelityFX;
|
|
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
|
|
{
|
|
PostFxVolume postFx = Level.FindActor<PostFxVolume>();
|
|
if (postFx != null)
|
|
return postFx.CameraArtifacts.VignetteIntensity.ToString();
|
|
return "";
|
|
}
|
|
set
|
|
{
|
|
if (float.TryParse(value, out float valueFloat))
|
|
{
|
|
PostFxVolume postFx = Level.FindActor<PostFxVolume>();
|
|
if (postFx != null)
|
|
{
|
|
valueFloat = Mathf.Clamp(valueFloat, 0.0f, 2.0f);
|
|
|
|
CameraArtifactsSettings cameraArtifacts = postFx.CameraArtifacts;
|
|
cameraArtifacts.VignetteIntensity = valueFloat;
|
|
postFx.CameraArtifacts = cameraArtifacts;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[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
|
|
{
|
|
string workDir = Directory.GetCurrentDirectory();
|
|
string matBasePath = Path.Combine(workDir, "Content");
|
|
string assetPath = Path.Combine(matBasePath, "GameplayGlobals.flax");
|
|
|
|
GameplayGlobals globals = Content.Load<GameplayGlobals>(assetPath);
|
|
|
|
return ((bool)globals.GetValue("Scene Lighting") ? "1" : "0");
|
|
}
|
|
set
|
|
{
|
|
string workDir = Directory.GetCurrentDirectory();
|
|
string matBasePath = Path.Combine(workDir, "Content");
|
|
string assetPath = Path.Combine(matBasePath, "GameplayGlobals.flax");
|
|
|
|
GameplayGlobals globals = Content.Load<GameplayGlobals>(assetPath);
|
|
|
|
bool boolValue = false;
|
|
if (int.TryParse(value, out int intValue))
|
|
boolValue = intValue != 0;
|
|
else if (float.TryParse(value, out float valueFloat))
|
|
boolValue = valueFloat != 0f;
|
|
|
|
globals.SetValue("Scene Lighting", boolValue);
|
|
|
|
Light[] lights = Level.GetActors<Light>();
|
|
foreach (Light light in lights)
|
|
light.IsActive = boolValue;
|
|
}
|
|
}
|
|
|
|
[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));
|
|
}
|
|
}
|
|
} |