dsda: reduce copypaste
This commit is contained in:
parent
f444d6b0a5
commit
72070a63de
|
@ -9,202 +9,88 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
|
|||
|
||||
public ControllerDefinition ControllerDefinition => _controllerDeck.Definition;
|
||||
|
||||
private delegate int ReadPot(IController c, int pot);
|
||||
private delegate byte ReadPort(IController c);
|
||||
|
||||
public bool FrameAdvance(IController controller, bool renderVideo, bool renderAudio)
|
||||
{
|
||||
// Declaring inputs
|
||||
PackedPlayerInput player1Inputs = new PackedPlayerInput();
|
||||
PackedPlayerInput player2Inputs = new PackedPlayerInput();
|
||||
PackedPlayerInput player3Inputs = new PackedPlayerInput();
|
||||
PackedPlayerInput player4Inputs = new PackedPlayerInput();
|
||||
PackedPlayerInput[] players = [
|
||||
new PackedPlayerInput(),
|
||||
new PackedPlayerInput(),
|
||||
new PackedPlayerInput(),
|
||||
new PackedPlayerInput()
|
||||
];
|
||||
|
||||
if (_syncSettings.Player1Present)
|
||||
ReadPot[] potReaders =
|
||||
[
|
||||
_controllerDeck.ReadPot1,
|
||||
_controllerDeck.ReadPot2,
|
||||
_controllerDeck.ReadPot3,
|
||||
_controllerDeck.ReadPot4,
|
||||
];
|
||||
|
||||
ReadPort[] portReaders =
|
||||
[
|
||||
_controllerDeck.ReadPort1,
|
||||
_controllerDeck.ReadPort2,
|
||||
_controllerDeck.ReadPort3,
|
||||
_controllerDeck.ReadPort4,
|
||||
];
|
||||
|
||||
int playersPresent = Convert.ToInt32(_syncSettings.Player1Present)
|
||||
| Convert.ToInt32(_syncSettings.Player2Present) << 1
|
||||
| Convert.ToInt32(_syncSettings.Player3Present) << 2
|
||||
| Convert.ToInt32(_syncSettings.Player4Present) << 3;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
player1Inputs._RunSpeed = _controllerDeck.ReadPot1(controller, 0);
|
||||
player1Inputs._StrafingSpeed = _controllerDeck.ReadPot1(controller, 1);
|
||||
player1Inputs._TurningSpeed = _controllerDeck.ReadPot1(controller, 2);
|
||||
player1Inputs._WeaponSelect = _controllerDeck.ReadPot1(controller, 3);
|
||||
var actionsBitfield = _controllerDeck.ReadPort1(controller);
|
||||
player1Inputs._Fire = actionsBitfield & 0b00001;
|
||||
player1Inputs._Action = (actionsBitfield & 0b00010) >> 1;
|
||||
player1Inputs._AltWeapon = (actionsBitfield & 0b00100) >> 2;
|
||||
|
||||
// Handling mouse-driven running
|
||||
int mouseRunningSpeed = _controllerDeck.ReadPot1(controller, 4);
|
||||
if (_player1LastMouseRunningValue > MOUSE_NO_INPUT)
|
||||
if ((playersPresent & (1 << i)) is not 0)
|
||||
{
|
||||
int mouseRunningDelta = _player1LastMouseRunningValue - mouseRunningSpeed;
|
||||
player1Inputs._RunSpeed += mouseRunningDelta * _syncSettings.MouseRunSensitivity;
|
||||
if (player1Inputs._RunSpeed > 50) player1Inputs._RunSpeed = 50;
|
||||
if (player1Inputs._RunSpeed < -50) player1Inputs._RunSpeed = -50;
|
||||
}
|
||||
_player1LastMouseRunningValue = mouseRunningSpeed;
|
||||
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);
|
||||
|
||||
// Handling mouse-driven turning
|
||||
int mouseTurningSpeed = _controllerDeck.ReadPot1(controller, 5);
|
||||
if (_player1LastMouseTurningValue > MOUSE_NO_INPUT)
|
||||
{
|
||||
int mouseTurningDelta = _player1LastMouseTurningValue - mouseTurningSpeed;
|
||||
player1Inputs._TurningSpeed += mouseTurningDelta * _syncSettings.MouseTurnSensitivity;
|
||||
if (_syncSettings.TurningResolution == TurningResolution.Shorttics)
|
||||
var actionsBitfield = portReaders[i](controller);
|
||||
players[i]._Fire = actionsBitfield & 0b00001;
|
||||
players[i]._Action = (actionsBitfield & 0b00010) >> 1;
|
||||
players[i]._AltWeapon = (actionsBitfield & 0b00100) >> 2;
|
||||
|
||||
// Handling mouse-driven running
|
||||
int mouseRunningSpeed = potReaders[i](controller, 4);
|
||||
if (_lastMouseRunningValues[i] > MOUSE_NO_INPUT)
|
||||
{
|
||||
player1Inputs._TurningSpeed >>= 8;
|
||||
int mouseRunningDelta = _lastMouseRunningValues[i] - mouseRunningSpeed;
|
||||
players[i]._RunSpeed += mouseRunningDelta * _syncSettings.MouseRunSensitivity;
|
||||
if (players[i]._RunSpeed > 50) players[i]._RunSpeed = 50;
|
||||
if (players[i]._RunSpeed < -50) players[i]._RunSpeed = -50;
|
||||
}
|
||||
}
|
||||
_player1LastMouseTurningValue = mouseTurningSpeed;
|
||||
_lastMouseRunningValues[i] = mouseRunningSpeed;
|
||||
|
||||
// Raven Games
|
||||
if (_syncSettings.InputFormat is DoomControllerTypes.Heretic or DoomControllerTypes.Hexen)
|
||||
{
|
||||
player1Inputs._FlyLook = _controllerDeck.ReadPot1(controller, 6);
|
||||
player1Inputs._ArtifactUse = _controllerDeck.ReadPot1(controller, 7);
|
||||
if (_syncSettings.InputFormat is DoomControllerTypes.Hexen)
|
||||
// Handling mouse-driven turning
|
||||
int mouseTurningSpeed = potReaders[i](controller, 5);
|
||||
if (_lastMouseTurningValues[i] > MOUSE_NO_INPUT)
|
||||
{
|
||||
player1Inputs._Jump = (actionsBitfield & 0b01000) >> 3;
|
||||
player1Inputs._EndPlayer = (actionsBitfield & 0b10000) >> 4;
|
||||
int mouseTurningDelta = _lastMouseTurningValues[i] - mouseTurningSpeed;
|
||||
players[i]._TurningSpeed += mouseTurningDelta * _syncSettings.MouseTurnSensitivity;
|
||||
if (_syncSettings.TurningResolution == TurningResolution.Shorttics)
|
||||
{
|
||||
players[i]._TurningSpeed >>= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_lastMouseTurningValues[i] = mouseTurningSpeed;
|
||||
|
||||
if (_syncSettings.Player2Present)
|
||||
{
|
||||
player2Inputs._RunSpeed = _controllerDeck.ReadPot2(controller, 0);
|
||||
player2Inputs._StrafingSpeed = _controllerDeck.ReadPot2(controller, 1);
|
||||
player2Inputs._TurningSpeed = _controllerDeck.ReadPot2(controller, 2);
|
||||
player2Inputs._WeaponSelect = _controllerDeck.ReadPot2(controller, 3);
|
||||
var actionsBitfield = _controllerDeck.ReadPort2(controller);
|
||||
player2Inputs._Fire = actionsBitfield & 0b00001;
|
||||
player2Inputs._Action = (actionsBitfield & 0b00010) >> 1;
|
||||
player2Inputs._AltWeapon = (actionsBitfield & 0b00100) >> 2;
|
||||
|
||||
// Handling mouse-driven running
|
||||
int mouseRunningSpeed = _controllerDeck.ReadPot2(controller, 4);
|
||||
if (_player2LastMouseRunningValue > MOUSE_NO_INPUT)
|
||||
{
|
||||
int mouseRunningDelta = _player2LastMouseRunningValue - mouseRunningSpeed;
|
||||
player2Inputs._RunSpeed += mouseRunningDelta * _syncSettings.MouseRunSensitivity;
|
||||
if (player2Inputs._RunSpeed > 50) player2Inputs._RunSpeed = 50;
|
||||
if (player2Inputs._RunSpeed < -50) player2Inputs._RunSpeed = -50;
|
||||
}
|
||||
_player2LastMouseRunningValue = mouseRunningSpeed;
|
||||
|
||||
// Handling mouse-driven turning
|
||||
int mouseTurningSpeed = _controllerDeck.ReadPot2(controller, 5);
|
||||
if (_player2LastMouseTurningValue > MOUSE_NO_INPUT)
|
||||
{
|
||||
int mouseTurningDelta = _player2LastMouseTurningValue - mouseTurningSpeed;
|
||||
player2Inputs._TurningSpeed += mouseTurningDelta * _syncSettings.MouseTurnSensitivity;
|
||||
if (_syncSettings.TurningResolution == TurningResolution.Shorttics)
|
||||
// Raven Games
|
||||
if (_syncSettings.InputFormat is DoomControllerTypes.Heretic or DoomControllerTypes.Hexen)
|
||||
{
|
||||
player2Inputs._TurningSpeed >>= 8;
|
||||
}
|
||||
}
|
||||
_player2LastMouseTurningValue = mouseTurningSpeed;
|
||||
|
||||
// Raven Games
|
||||
if (_syncSettings.InputFormat is DoomControllerTypes.Heretic or DoomControllerTypes.Hexen)
|
||||
{
|
||||
player2Inputs._FlyLook = _controllerDeck.ReadPot2(controller, 4);
|
||||
player2Inputs._ArtifactUse = _controllerDeck.ReadPot2(controller, 5);
|
||||
if (_syncSettings.InputFormat is DoomControllerTypes.Hexen)
|
||||
{
|
||||
player2Inputs._Jump = (actionsBitfield & 0b01000) >> 3;
|
||||
player2Inputs._EndPlayer = (actionsBitfield & 0b10000) >> 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_syncSettings.Player3Present)
|
||||
{
|
||||
player3Inputs._RunSpeed = _controllerDeck.ReadPot3(controller, 0);
|
||||
player3Inputs._StrafingSpeed = _controllerDeck.ReadPot3(controller, 1);
|
||||
player3Inputs._TurningSpeed = _controllerDeck.ReadPot3(controller, 2);
|
||||
player3Inputs._WeaponSelect = _controllerDeck.ReadPot3(controller, 3);
|
||||
var actionsBitfield = _controllerDeck.ReadPort3(controller);
|
||||
player3Inputs._Fire = actionsBitfield & 0b00001;
|
||||
player3Inputs._Action = (actionsBitfield & 0b00010) >> 1;
|
||||
player3Inputs._AltWeapon = (actionsBitfield & 0b00100) >> 2;
|
||||
|
||||
// Handling mouse-driven running
|
||||
int mouseRunningSpeed = _controllerDeck.ReadPot3(controller, 4);
|
||||
if (_player3LastMouseRunningValue > MOUSE_NO_INPUT)
|
||||
{
|
||||
int mouseRunningDelta = _player3LastMouseRunningValue - mouseRunningSpeed;
|
||||
player3Inputs._RunSpeed += mouseRunningDelta * _syncSettings.MouseRunSensitivity;
|
||||
if (player3Inputs._RunSpeed > 50) player3Inputs._RunSpeed = 50;
|
||||
if (player3Inputs._RunSpeed < -50) player3Inputs._RunSpeed = -50;
|
||||
}
|
||||
_player3LastMouseRunningValue = mouseRunningSpeed;
|
||||
|
||||
// Handling mouse-driven turning
|
||||
int mouseTurningSpeed = _controllerDeck.ReadPot3(controller, 5);
|
||||
if (_player3LastMouseTurningValue > MOUSE_NO_INPUT)
|
||||
{
|
||||
int mouseTurningDelta = _player3LastMouseTurningValue - mouseTurningSpeed;
|
||||
player3Inputs._TurningSpeed += mouseTurningDelta * _syncSettings.MouseTurnSensitivity;
|
||||
if (_syncSettings.TurningResolution == TurningResolution.Shorttics)
|
||||
{
|
||||
player3Inputs._TurningSpeed >>= 8;
|
||||
}
|
||||
}
|
||||
_player3LastMouseTurningValue = mouseTurningSpeed;
|
||||
|
||||
// Raven Games
|
||||
if (_syncSettings.InputFormat is DoomControllerTypes.Heretic or DoomControllerTypes.Hexen)
|
||||
{
|
||||
player3Inputs._FlyLook = _controllerDeck.ReadPot3(controller, 6);
|
||||
player3Inputs._ArtifactUse = _controllerDeck.ReadPot3(controller, 7);
|
||||
if (_syncSettings.InputFormat is DoomControllerTypes.Hexen)
|
||||
{
|
||||
player3Inputs._Jump = (actionsBitfield & 0b01000) >> 3;
|
||||
player3Inputs._EndPlayer = (actionsBitfield & 0b10000) >> 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_syncSettings.Player4Present)
|
||||
{
|
||||
player4Inputs._RunSpeed = _controllerDeck.ReadPot4(controller, 0);
|
||||
player4Inputs._StrafingSpeed = _controllerDeck.ReadPot4(controller, 1);
|
||||
player4Inputs._TurningSpeed = _controllerDeck.ReadPot4(controller, 2);
|
||||
player4Inputs._WeaponSelect = _controllerDeck.ReadPot4(controller, 3);
|
||||
var actionsBitfield = _controllerDeck.ReadPort4(controller);
|
||||
player4Inputs._Fire = actionsBitfield & 0b00001;
|
||||
player4Inputs._Action = (actionsBitfield & 0b00010) >> 1;
|
||||
player4Inputs._AltWeapon = (actionsBitfield & 0b00100) >> 2;
|
||||
|
||||
// Handling mouse-driven running
|
||||
int mouseRunningSpeed = _controllerDeck.ReadPot4(controller, 4);
|
||||
if (_player4LastMouseRunningValue > MOUSE_NO_INPUT)
|
||||
{
|
||||
int mouseRunningDelta = _player4LastMouseRunningValue - mouseRunningSpeed;
|
||||
player4Inputs._RunSpeed += mouseRunningDelta * _syncSettings.MouseRunSensitivity;
|
||||
if (player4Inputs._RunSpeed > 50) player4Inputs._RunSpeed = 50;
|
||||
if (player4Inputs._RunSpeed < -50) player4Inputs._RunSpeed = -50;
|
||||
}
|
||||
_player4LastMouseRunningValue = mouseRunningSpeed;
|
||||
|
||||
// Handling mouse-driven turning
|
||||
int mouseTurningSpeed = _controllerDeck.ReadPot4(controller, 5);
|
||||
if (_player4LastMouseTurningValue > MOUSE_NO_INPUT)
|
||||
{
|
||||
int mouseTurningDelta = _player4LastMouseTurningValue - mouseTurningSpeed;
|
||||
player4Inputs._TurningSpeed += mouseTurningDelta * _syncSettings.MouseTurnSensitivity;
|
||||
if (_syncSettings.TurningResolution == TurningResolution.Shorttics)
|
||||
{
|
||||
player4Inputs._TurningSpeed >>= 8;
|
||||
}
|
||||
}
|
||||
_player4LastMouseTurningValue = mouseTurningSpeed;
|
||||
|
||||
// Raven Games
|
||||
if (_syncSettings.InputFormat is DoomControllerTypes.Heretic or DoomControllerTypes.Hexen)
|
||||
{
|
||||
player4Inputs._FlyLook = _controllerDeck.ReadPot4(controller, 4);
|
||||
player4Inputs._ArtifactUse = _controllerDeck.ReadPot4(controller, 5);
|
||||
if (_syncSettings.InputFormat is DoomControllerTypes.Hexen)
|
||||
{
|
||||
player4Inputs._Jump = (actionsBitfield & 0b01000) >> 3;
|
||||
player4Inputs._EndPlayer = (actionsBitfield & 0b10000) >> 4;
|
||||
players[i]._FlyLook = potReaders[i](controller, 6);
|
||||
players[i]._ArtifactUse = potReaders[i](controller, 7);
|
||||
if (_syncSettings.InputFormat is DoomControllerTypes.Hexen)
|
||||
{
|
||||
players[i]._Jump = (actionsBitfield & 0b01000) >> 3;
|
||||
players[i]._EndPlayer = (actionsBitfield & 0b10000) >> 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,10 +101,10 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
|
|||
renderInfo._PlayerPointOfView = _settings.DisplayPlayer - 1;
|
||||
|
||||
Core.dsda_frame_advance(
|
||||
ref player1Inputs,
|
||||
ref player2Inputs,
|
||||
ref player3Inputs,
|
||||
ref player4Inputs,
|
||||
ref players[0],
|
||||
ref players[1],
|
||||
ref players[2],
|
||||
ref players[3],
|
||||
ref renderInfo);
|
||||
|
||||
if (renderVideo)
|
||||
|
|
|
@ -13,14 +13,14 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
|
|||
_elf.LoadStateBinary(reader);
|
||||
|
||||
// Getting last mouse positions
|
||||
_player1LastMouseRunningValue = reader.ReadInt32();
|
||||
_player1LastMouseTurningValue = reader.ReadInt32();
|
||||
_player2LastMouseRunningValue = reader.ReadInt32();
|
||||
_player2LastMouseTurningValue = reader.ReadInt32();
|
||||
_player3LastMouseRunningValue = reader.ReadInt32();
|
||||
_player3LastMouseTurningValue = reader.ReadInt32();
|
||||
_player4LastMouseRunningValue = reader.ReadInt32();
|
||||
_player4LastMouseTurningValue = reader.ReadInt32();
|
||||
_lastMouseRunningValues[0] = reader.ReadInt32();
|
||||
_lastMouseTurningValues[0] = reader.ReadInt32();
|
||||
_lastMouseRunningValues[1] = reader.ReadInt32();
|
||||
_lastMouseTurningValues[1] = reader.ReadInt32();
|
||||
_lastMouseRunningValues[2] = reader.ReadInt32();
|
||||
_lastMouseTurningValues[2] = reader.ReadInt32();
|
||||
_lastMouseRunningValues[3] = reader.ReadInt32();
|
||||
_lastMouseTurningValues[3] = reader.ReadInt32();
|
||||
|
||||
Frame = reader.ReadInt32();
|
||||
// any managed pointers that we sent to the core need to be resent now!
|
||||
|
@ -33,14 +33,14 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
|
|||
_elf.SaveStateBinary(writer);
|
||||
|
||||
// Writing last mouse positions
|
||||
writer.Write(_player1LastMouseRunningValue);
|
||||
writer.Write(_player1LastMouseTurningValue);
|
||||
writer.Write(_player2LastMouseRunningValue);
|
||||
writer.Write(_player2LastMouseTurningValue);
|
||||
writer.Write(_player3LastMouseRunningValue);
|
||||
writer.Write(_player3LastMouseTurningValue);
|
||||
writer.Write(_player4LastMouseRunningValue);
|
||||
writer.Write(_player4LastMouseTurningValue);
|
||||
writer.Write(_lastMouseRunningValues[0]);
|
||||
writer.Write(_lastMouseTurningValues[0]);
|
||||
writer.Write(_lastMouseRunningValues[1]);
|
||||
writer.Write(_lastMouseTurningValues[1]);
|
||||
writer.Write(_lastMouseRunningValues[2]);
|
||||
writer.Write(_lastMouseTurningValues[2]);
|
||||
writer.Write(_lastMouseRunningValues[3]);
|
||||
writer.Write(_lastMouseTurningValues[3]);
|
||||
|
||||
writer.Write(Frame);
|
||||
}
|
||||
|
|
|
@ -158,14 +158,18 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
|
|||
|
||||
// Remembering mouse position
|
||||
private const int MOUSE_NO_INPUT = -65535;
|
||||
private int _player1LastMouseRunningValue = MOUSE_NO_INPUT;
|
||||
private int _player1LastMouseTurningValue = MOUSE_NO_INPUT;
|
||||
private int _player2LastMouseRunningValue = MOUSE_NO_INPUT;
|
||||
private int _player2LastMouseTurningValue = MOUSE_NO_INPUT;
|
||||
private int _player3LastMouseRunningValue = MOUSE_NO_INPUT;
|
||||
private int _player3LastMouseTurningValue = MOUSE_NO_INPUT;
|
||||
private int _player4LastMouseRunningValue = MOUSE_NO_INPUT;
|
||||
private int _player4LastMouseTurningValue = MOUSE_NO_INPUT;
|
||||
private int[] _lastMouseRunningValues = [
|
||||
MOUSE_NO_INPUT,
|
||||
MOUSE_NO_INPUT,
|
||||
MOUSE_NO_INPUT,
|
||||
MOUSE_NO_INPUT
|
||||
];
|
||||
private int[] _lastMouseTurningValues = [
|
||||
MOUSE_NO_INPUT,
|
||||
MOUSE_NO_INPUT,
|
||||
MOUSE_NO_INPUT,
|
||||
MOUSE_NO_INPUT
|
||||
];
|
||||
private List<string> _args;
|
||||
|
||||
// IRegionable
|
||||
|
|
Loading…
Reference in New Issue