From 3d6241f53ab00e809e1426cf20f101a2fb48e053 Mon Sep 17 00:00:00 2001 From: feos Date: Sun, 23 Feb 2025 14:59:55 +0300 Subject: [PATCH] dsda: handle movement speeds in IEmulator allows to factor in syncsettings and savestates (for turnheld) --- .../Computers/Doom/DSDA.IEmulator.cs | 30 +++++++++---- .../Computers/Doom/DSDA.cs | 26 ++++++------ .../Computers/Doom/DSDAControllers.cs | 42 ------------------- 3 files changed, 34 insertions(+), 64 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IEmulator.cs b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IEmulator.cs index 23bebc570c..c22524cf88 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IEmulator.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.IEmulator.cs @@ -1,4 +1,5 @@ -using BizHawk.Emulation.Common; +using BizHawk.Common.NumberExtensions; +using BizHawk.Emulation.Common; using static BizHawk.Emulation.Cores.Computers.Doom.CInterface; namespace BizHawk.Emulation.Cores.Computers.Doom @@ -47,28 +48,39 @@ namespace BizHawk.Emulation.Cores.Computers.Doom { if ((playersPresent & (1 << i)) is not 0) { + int speedIndex = Convert.ToInt32(controller.IsPressed($"P{i+1} Run")); // todo: xor depending on autorun + + // initial axis read players[i]._RunSpeed = potReaders[i](controller, 0); players[i]._StrafingSpeed = potReaders[i](controller, 1); players[i]._TurningSpeed = potReaders[i](controller, 2); players[i]._WeaponSelect = potReaders[i](controller, 3); - var actionsBitfield = portReaders[i](controller); - players[i]._Fire = actionsBitfield & 0b00001; - players[i]._Action = (actionsBitfield & 0b00010) >> 1; - players[i]._AltWeapon = (actionsBitfield & 0b00100) >> 2; + // override axis based on movement buttons + if (controller.IsPressed($"P{i+1} Forward")) players[i]._RunSpeed = _runSpeeds[speedIndex]; + if (controller.IsPressed($"P{i+1} Backward")) players[i]._RunSpeed = -_runSpeeds[speedIndex]; + if (controller.IsPressed($"P{i+1} Strafe Right")) players[i]._StrafingSpeed = _strafeSpeeds[speedIndex]; + if (controller.IsPressed($"P{i+1} Strafe Left")) players[i]._StrafingSpeed = -_strafeSpeeds[speedIndex]; + if (controller.IsPressed($"P{i+1} Turn Right")) players[i]._TurningSpeed = -_turnSpeeds[speedIndex]; + if (controller.IsPressed($"P{i+1} Turn Left")) players[i]._TurningSpeed = _turnSpeeds[speedIndex]; - // Handling mouse-driven running + // mouse-driven running players[i]._RunSpeed -= (int)((float)potReaders[i](controller, 4) * (float)_syncSettings.MouseRunSensitivity / 6.0); - if (players[i]._RunSpeed > 50) players[i]._RunSpeed = 50; - if (players[i]._RunSpeed < -50) players[i]._RunSpeed = -50; + players[i]._RunSpeed = players[i]._RunSpeed.Clamp(-_runSpeeds[1], _runSpeeds[1]); - // Handling mouse-driven turning + // mouse-driven turning players[i]._TurningSpeed -= (int)((float)potReaders[i](controller, 5) * (float)_syncSettings.MouseTurnSensitivity / 300.0); if (_syncSettings.TurningResolution == TurningResolution.Shorttics) { players[i]._TurningSpeed >>= 8; } + // bool buttons + var actionsBitfield = portReaders[i](controller); + players[i]._Fire = actionsBitfield & 0b00001; + players[i]._Action = (actionsBitfield & 0b00010) >> 1; + players[i]._AltWeapon = (actionsBitfield & 0b00100) >> 2; + // Raven Games if (_syncSettings.InputFormat is DoomControllerTypes.Heretic or DoomControllerTypes.Hexen) { diff --git a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.cs b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.cs index 27499b7c2a..32ccdbb5c6 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDA.cs @@ -156,26 +156,20 @@ namespace BizHawk.Emulation.Cores.Computers.Doom } } - private int[] _turnHeld = [ 0, 0, 0, 0 ]; - private List _args; - - // IRegionable - public DisplayType Region { get; } - - // IRomInfo - public string RomDetails { get; } - // ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable private readonly CInterface.load_archive_cb _loadCallback; - private readonly string _dsdaWadFileName = "dsda-doom.wad"; private readonly byte[] _dsdaWadFileData; - private List _wadFiles; - private readonly CInterface Core; private readonly WaterboxHost _elf; - private readonly DoomControllerDeck _controllerDeck; + private readonly int[] _runSpeeds = [ 25, 50 ]; + private readonly int[] _strafeSpeeds = [ 24, 40 ]; + private readonly int[] _turnSpeeds = [ 640, 1280, 320 ]; + + private int[] _turnHeld = [ 0, 0, 0, 0 ]; + private List _args; + private List _wadFiles; /// /// core callback for file loading @@ -237,5 +231,11 @@ namespace BizHawk.Emulation.Cores.Computers.Doom throw new InvalidOperationException($"Unknown error processing file '{filename}'"); } } + + // IRegionable + public DisplayType Region { get; } + + // IRomInfo + public string RomDetails { get; } } } diff --git a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDAControllers.cs b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDAControllers.cs index 65a68421e7..b029ecab9a 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Doom/DSDAControllers.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Doom/DSDAControllers.cs @@ -82,48 +82,6 @@ namespace BizHawk.Emulation.Cores.Computers.Doom { int x = c.AxisValue(Definition.Axes[pot]); - // Handling running keys overriding axes values - if (Definition.Axes[pot] == $"P{PortNum} Run Speed") - { - if (c.IsPressed($"P{PortNum} Forward")) - { - x = c.IsPressed($"P{PortNum} Run") ? 50 : 25; - } - - if (c.IsPressed($"P{PortNum} Backward")) - { - x = c.IsPressed($"P{PortNum} Run") ? -50 : -25; - } - } - - // Handling strafing keys overriding axes values - if (Definition.Axes[pot] == $"P{PortNum} Strafing Speed") - { - if (c.IsPressed($"P{PortNum} Strafe Right")) - { - x = c.IsPressed($"P{PortNum} Run") ? 40 : 24; - } - - if (c.IsPressed($"P{PortNum} Strafe Left")) - { - x = c.IsPressed($"P{PortNum} Run") ? -40 : -24; - } - } - - // Handling turning keys overriding axes values - if (Definition.Axes[pot] == $"P{PortNum} Turning Speed") - { - if (c.IsPressed($"P{PortNum} Turn Left")) - { - x = c.IsPressed($"P{PortNum} Run") ? 1280 : 320; - } - - if (c.IsPressed($"P{PortNum} Turn Right")) - { - x = c.IsPressed($"P{PortNum} Run") ? -1280 : -320; - } - } - // Handling weapon select keys overriding axes values if (Definition.Axes[pot] == $"P{PortNum} Weapon Select") {