Add mouse sensitivity cvar, devconfig.cfg

This commit is contained in:
2025-03-20 22:09:08 +02:00
parent e6270ff541
commit 28b73be6c1
6 changed files with 74 additions and 12 deletions

View File

@@ -12,6 +12,9 @@ public class CameraMovement : Script
[Tooltip("Camera speed")]
public float MoveSpeed { get; set; } = 400;
[ConsoleVariable("sensitivity")]
public static float Sensitivity;
public override void OnStart()
{
Float3 initialEulerAngles = Actor.Orientation.EulerAngles;
@@ -26,8 +29,8 @@ public class CameraMovement : Script
Actor rootActor = Actor.GetChild(0);
Camera camera = rootActor.GetChild<Camera>();
float xAxis = Input.GetAxisRaw("Mouse X");
float yAxis = Input.GetAxisRaw("Mouse Y");
float xAxis = Input.GetAxisRaw("Mouse X") * Sensitivity;
float yAxis = Input.GetAxisRaw("Mouse Y") * Sensitivity;
if (xAxis != 0.0f || yAxis != 0.0f)
{
viewPitch += yAxis;

View File

@@ -27,4 +27,22 @@ public class Config
return lines;
}
public void Merge(Config config)
{
if (config.dictionary.Count == 0)
return;
foreach (var kvp in config.dictionary)
{
if (dictionary.TryGetValue(kvp.Key, out string oldValue))
{
if (oldValue == kvp.Value)
continue;
dictionary[kvp.Key] = kvp.Value;
}
else
dictionary.Add(kvp.Key, kvp.Value);
}
}
}

View File

@@ -68,8 +68,9 @@ public class ConsolePlugin : GamePlugin
private void LoadConfig()
{
Console.Print("Loading config file (GamePlugin)");
//Console.Print("Loading config file (GamePlugin)");
AssetManager.Globals.ResetValues();
AssetManager.LoadConfigurationFiles();
foreach (var line in AssetManager.Config.GetLines())
Console.Execute(line, false, true);
@@ -171,9 +172,10 @@ public class ConsoleEditorPlugin : EditorPlugin
private void LoadConfig()
{
Console.Print("Loading config file (EditorPlugin)");
//Console.Print("Loading config file (EditorPlugin)");
AssetManager.Globals.ResetValues();
AssetManager.LoadConfigurationFiles();
foreach (var line in AssetManager.Config.GetLines())
Console.Execute(line, false, true);

View File

@@ -45,13 +45,18 @@ internal struct ConsoleVariable
{
if (field != null)
return (string)field.GetValue(null);
if (setter != null)
if (getter != null)
return (string)getter.Invoke(null, null);
}
else if (type == typeof(float))
{
if (field != null)
return field.GetValue(null).ToString();
if (getter != null)
return (string)getter.Invoke(null, null);
}
else
{
throw new Exception("cvar is not type of string");
}
throw new Exception($"Unsupported console variable type '{type.FullName}'");
throw new Exception("GetValueString no field or getter specified");
}
@@ -66,6 +71,15 @@ internal struct ConsoleVariable
else if (setter != null)
setter.Invoke(null, new object[] { value });
}
else if (type == typeof(float))
{
if (!float.TryParse(value, out var floatValue))
return;
if (field != null)
field.SetValue(null, floatValue);
else if (setter != null)
setter.Invoke(null, new object[] { floatValue });
}
else
{
throw new Exception("Unsupported type for SetValue: " + type.Name);

View File

@@ -50,6 +50,9 @@ public class PlayerInput2 : IPlayerInput
/// </summary>
private PlayerInputState2 _recordState;
[ConsoleVariable("sensitivity")]
public static float Sensitivity;
public void SetFrame(ulong frame)
{
}
@@ -60,11 +63,11 @@ public class PlayerInput2 : IPlayerInput
// or taken with the peak values (axis direction),
// binary values should be OR'ed so triggered action is not lost if button debounces mid-frame.
float sensitivity = 1.0f / 8.0f;
sensitivity = 1.0f;
//float sensitivity = 1.0f / 8.0f;
//sensitivity = 1.0f;
float turnSpeed = 100.0f;
_recordState.ViewDelta += new Float2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")) * sensitivity;
_recordState.ViewDelta += new Float2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")) * Sensitivity;
_recordState.ViewDelta += new Float2(Input.GetAxisRaw("LookRight"), Input.GetAxisRaw("LookUp")) * Time.DeltaTime * turnSpeed;
_recordState.MoveForward = MathF.MaxMagnitude(_recordState.MoveForward, Input.GetAxis("Vertical"));

View File

@@ -14,6 +14,14 @@ public static class AssetManager
public static string CachePath { get; private set; } =
Path.Combine(Directory.GetCurrentDirectory(), "Cache");
public static string ConfigFilePath { get; private set; } =
Path.Combine(ContentPath, "config.cfg");
#if FLAX_EDITOR
public static string ConfigDevFilePath { get; private set; } =
Path.Combine(ContentPath, "devconfig.cfg");
#endif
public static GameplayGlobals Globals { get; private set; }
public static Config Config { get; private set; }
@@ -21,6 +29,20 @@ public static class AssetManager
static AssetManager()
{
Globals = Content.Load<GameplayGlobals>(Path.Combine(ContentPath, "Settings", "GameSettings", "GameplayGlobals.flax"));
Config = ConfigParser.ParseFile(Path.Combine(ContentPath, "config.cfg"));
}
public static void LoadConfigurationFiles()
{
Config = ConfigParser.ParseFile(ConfigFilePath);
#if FLAX_EDITOR
if (!File.Exists(ConfigDevFilePath))
{
File.WriteAllText(ConfigDevFilePath,
$"""
// Personal configuration file used during development, do not commit this file.
""");
}
Config.Merge(ConfigParser.ParseFile(ConfigDevFilePath));
#endif
}
}