dsda: handle movement speeds in IEmulator

allows to factor in syncsettings and savestates (for turnheld)
This commit is contained in:
feos 2025-02-23 14:59:55 +03:00
parent 9ad6eb8971
commit 3d6241f53a
3 changed files with 34 additions and 64 deletions

View File

@ -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<int>(-_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)
{

View File

@ -156,26 +156,20 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
}
}
private int[] _turnHeld = [ 0, 0, 0, 0 ];
private List<string> _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<IRomAsset> _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<string> _args;
private List<IRomAsset> _wadFiles;
/// <summary>
/// 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; }
}
}

View File

@ -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")
{