dsda: automap controls (and live gamma toggle)

limited to vanilla functionality
currently only works for doom, will require refactoring to work universally
This commit is contained in:
feos 2025-04-03 23:33:51 +03:00
parent a74100ff9f
commit ba48066748
10 changed files with 216 additions and 42 deletions

Binary file not shown.

View File

@ -820,8 +820,20 @@ namespace BizHawk.Emulation.Common
},
[VSystemID.Raw.Doom] = new()
{
["Automap"] = 'A',
["Automap Toggle"] = 'a',
["Automap +"] = '+',
["Automap -"] = '-',
["Automap Full/Zoom"] = 'z',
["Automap Follow"] = 'f',
["Automap Up"] = 'u',
["Automap Down"] = 'd',
["Automap Right"] = 'r',
["Automap Left"] = 'l',
["Automap Grid"] = 'g',
["Automap Mark"] = 'm',
["Automap Clear Marks"] = 'c',
["Backward"] = 'v',
["Change Gamma"] = 'G',
["End Player"] = 'E',
["Fire"] = 'F',
["Forward"] = '^',
@ -829,8 +841,8 @@ namespace BizHawk.Emulation.Common
["Run"] = 'R',
["Strafe Left"] = '<',
["Strafe Right"] = '>',
["Turn Left"] = 'l',
["Turn Right"] = 'r',
["Turn Left"] = '{',
["Turn Right"] = '}',
["Use"] = 'U',
["Weapon Select 1"] = '1',
["Weapon Select 2"] = '2',

View File

@ -35,10 +35,10 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
private readonly IPort _port4;
private static IReadOnlyDictionary<DoomControllerTypes, Func<int, bool, IPort>> _controllerCtors;
public ControllerDefinition Definition { get; }
public byte ReadButtons1(IController c) => _port1.ReadButtons(c);
public byte ReadButtons2(IController c) => _port2.ReadButtons(c);
public byte ReadButtons3(IController c) => _port3.ReadButtons(c);
public byte ReadButtons4(IController c) => _port4.ReadButtons(c);
public int ReadButtons1(IController c) => _port1.ReadButtons(c);
public int ReadButtons2(IController c) => _port2.ReadButtons(c);
public int ReadButtons3(IController c) => _port3.ReadButtons(c);
public int ReadButtons4(IController c) => _port4.ReadButtons(c);
public int ReadAxis1(IController c, int axis) => _port1.ReadAxis(c, axis);
public int ReadAxis2(IController c, int axis) => _port2.ReadAxis(c, axis);
public int ReadAxis3(IController c, int axis) => _port3.ReadAxis(c, axis);

View File

@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
public string SystemId => VSystemID.Raw.Doom;
public bool DeterministicEmulation => true;
private delegate int ReadAxis(IController c, int axis);
private delegate byte ReadPort(IController c);
private delegate int ReadPort(IController c);
public bool FrameAdvance(IController controller, bool renderVideo, bool renderAudio)
{
@ -100,9 +100,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
// bool buttons
var actionsBitfield = buttonsReaders[i](controller);
players[i].Fire = actionsBitfield & 0b00001;
players[i].Action = (actionsBitfield & 0b00010) >> 1;
players[i].Automap = (actionsBitfield & 0b00100) >> 2;
players[i].Buttons = actionsBitfield;
// Raven Games
if (_syncSettings.InputFormat is DoomControllerTypes.Heretic or DoomControllerTypes.Hexen)

View File

@ -27,7 +27,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
public interface IPort
{
byte ReadButtons(IController c);
int ReadButtons(IController c);
int ReadAxis(IController c, int axis);
ControllerDefinition Definition { get; }
int PortNum { get; }
@ -69,6 +69,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
"Strafe Right",
"Run",
"Strafe",
"Change Gamma",
"Weapon Select 1",
"Weapon Select 2",
"Weapon Select 3",
@ -90,13 +91,25 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
"Automap Clear Marks",
];
public byte ReadButtons(IController c)
public int ReadButtons(IController c)
{
byte result = 0;
int result = 0;
if (c.IsPressed($"P{PortNum} Fire")) { result |= 0b0001; }
if (c.IsPressed($"P{PortNum} Use")) { result |= 0b0010; }
if (c.IsPressed($"P{PortNum} Automap")) { result |= 0b0100; }
if (c.IsPressed($"P{PortNum} Fire")) result |= (1 << 0);
if (c.IsPressed($"P{PortNum} Use")) result |= (1 << 1);
if (c.IsPressed($"P{PortNum} Change Gamma")) result |= (1 << 2);
if (c.IsPressed($"P{PortNum} Automap Toggle")) result |= (1 << 3);
if (c.IsPressed($"P{PortNum} Automap +")) result |= (1 << 4);
if (c.IsPressed($"P{PortNum} Automap -")) result |= (1 << 5);
if (c.IsPressed($"P{PortNum} Automap Full/Zoom")) result |= (1 << 6);
if (c.IsPressed($"P{PortNum} Automap Follow")) result |= (1 << 7);
if (c.IsPressed($"P{PortNum} Automap Up")) result |= (1 << 8);
if (c.IsPressed($"P{PortNum} Automap Down")) result |= (1 << 9);
if (c.IsPressed($"P{PortNum} Automap Right")) result |= (1 << 10);
if (c.IsPressed($"P{PortNum} Automap Left")) result |= (1 << 11);
if (c.IsPressed($"P{PortNum} Automap Grid")) result |= (1 << 12);
if (c.IsPressed($"P{PortNum} Automap Mark")) result |= (1 << 13);
if (c.IsPressed($"P{PortNum} Automap Clear Marks")) result |= (1 << 14);
return result;
}
@ -165,9 +178,9 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
"Weapon Select 7",
];
public byte ReadButtons(IController c)
public int ReadButtons(IController c)
{
byte result = 0;
int result = 0;
if (c.IsPressed($"P{PortNum} Fire")) { result |= 0b0001; }
if (c.IsPressed($"P{PortNum} Use")) { result |= 0b0010; }
@ -281,9 +294,9 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
"Weapon Select 4"
];
public byte ReadButtons(IController c)
public int ReadButtons(IController c)
{
byte result = 0;
int result = 0;
if (c.IsPressed($"P{PortNum} Fire")) { result |= 0b00001; }
if (c.IsPressed($"P{PortNum} Use")) { result |= 0b00010; }

View File

@ -45,9 +45,7 @@ namespace BizHawk.Emulation.Cores.Computers.Doom
public int StrafingSpeed;
public int TurningSpeed;
public int WeaponSelect;
public int Fire;
public int Action;
public int Automap;
public int Buttons;
// Hexen + Heretic (Raven Games)
public int FlyLook;

14
waterbox/dsda/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
"editor.tabSize": 2,
"files.associations": {
"f_wipe.h": "c",
"bizhawkinterface.h": "c",
"emulibc.h": "c",
"d_main.h": "c",
"m_fixed.h": "c",
"d_event.h": "c",
"doomtype.h": "c",
"g_game.h": "c",
"d_player.h": "c"
}
}

View File

@ -2,7 +2,91 @@
bool foundIWAD = false;
bool wipeDone = true;
int last_automap_input[4] = { 0 };
AllButtons last_buttons[4] = { 0 };
void handle_automap_input(AllButtons buttons, int playerId)
{
static int bigstate = 0;
if (buttons.AutomapToggle && !last_buttons[playerId].AutomapToggle)
{
if (automap_active)
{
AM_Stop(true);
bigstate = 0;
}
else
AM_Start(true);
}
if (buttons.AutomapFollow && !last_buttons[playerId].AutomapFollow)
{
dsda_ToggleConfig(dsda_config_automap_follow, true);
dsda_AddMessage(automap_follow ? AMSTR_FOLLOWON : AMSTR_FOLLOWOFF);
}
if (buttons.AutomapGrid && !last_buttons[playerId].AutomapGrid)
{
dsda_ToggleConfig(dsda_config_automap_grid, true);
dsda_AddMessage(automap_grid ? AMSTR_GRIDON : AMSTR_GRIDOFF);
}
if (buttons.AutomapMark && !last_buttons[playerId].AutomapMark)
{
if (!raven)
{
AM_addMark();
doom_printf("%s %d", AMSTR_MARKEDSPOT, markpointnum - 1);
}
}
if (buttons.AutomapClearMarks && !last_buttons[playerId].AutomapClearMarks)
{
AM_clearMarks();
dsda_AddMessage(AMSTR_MARKSCLEARED);
}
if (buttons.AutomapFullZoom && !last_buttons[playerId].AutomapFullZoom)
{
bigstate = !bigstate;
if (bigstate)
{
AM_saveScaleAndLoc();
AM_minOutWindowScale();
}
else
AM_restoreScaleAndLoc();
}
if (buttons.AutomapZoomOut)
{
mtof_zoommul = M_ZOOMOUT;
ftom_zoommul = M_ZOOMIN;
curr_mtof_zoommul = mtof_zoommul;
zoom_leveltime = leveltime;
}
else if (buttons.AutomapZoomIn)
{
mtof_zoommul = M_ZOOMIN;
ftom_zoommul = M_ZOOMOUT;
curr_mtof_zoommul = mtof_zoommul;
zoom_leveltime = leveltime;
}
else
{
stop_zooming = true;
if (leveltime != zoom_leveltime)
AM_StopZooming();
}
if (!automap_follow)
{
if (buttons.AutomapUp) m_paninc.y += FTOM(map_pan_speed);
if (buttons.AutomapDown) m_paninc.y -= FTOM(map_pan_speed);
if (buttons.AutomapRight) m_paninc.x += FTOM(map_pan_speed);
if (buttons.AutomapLeft) m_paninc.x -= FTOM(map_pan_speed);
}
}
void send_input(struct PackedPlayerInput *inputs, int playerId)
{
@ -11,11 +95,11 @@ void send_input(struct PackedPlayerInput *inputs, int playerId)
local_cmds[playerId].lookfly = inputs->FlyLook;
local_cmds[playerId].arti = inputs->ArtifactUse;
local_cmds[playerId].angleturn = inputs->TurningSpeed;
if (inputs->Fire) local_cmds[playerId].buttons |= 0b00000001;
if (inputs->Action) local_cmds[playerId].buttons |= 0b00000010;
if (inputs->EndPlayer) local_cmds[playerId].arti |= 0b01000000;
if (inputs->Jump) local_cmds[playerId].arti |= 0b10000000;
if (inputs->Buttons.Fire) local_cmds[playerId].buttons |= 0b00000001;
if (inputs->Buttons.Use) local_cmds[playerId].buttons |= 0b00000010;
if (inputs->EndPlayer) local_cmds[playerId].arti |= 0b01000000;
if (inputs->Jump) local_cmds[playerId].arti |= 0b10000000;
if (inputs->WeaponSelect)
{
@ -23,14 +107,18 @@ void send_input(struct PackedPlayerInput *inputs, int playerId)
local_cmds[playerId].buttons |= (inputs->WeaponSelect - 1) << BT_WEAPONSHIFT;
}
if (inputs->Automap && !last_automap_input[playerId])
if (inputs->Buttons.ChangeGamma && !last_buttons[playerId].ChangeGamma)
{
if (automap_input)
AM_Stop(true);
else
AM_Start(true);
dsda_CycleConfig(dsda_config_usegamma, true);
dsda_AddMessage(usegamma == 0 ? GAMMALVL0 :
usegamma == 1 ? GAMMALVL1 :
usegamma == 2 ? GAMMALVL2 :
usegamma == 3 ? GAMMALVL3 :
GAMMALVL4);
}
last_automap_input[playerId] = inputs->Automap;
handle_automap_input(inputs->Buttons, playerId);
last_buttons[playerId] = inputs->Buttons;
}
ECL_EXPORT void dsda_get_audio(int *n, void **buffer)
@ -73,6 +161,9 @@ ECL_EXPORT bool dsda_frame_advance(struct PackedPlayerInput *player1Inputs, stru
// Setting inputs
headlessClearTickCommand();
m_paninc.y = 0;
m_paninc.x = 0;
// Setting Players inputs
send_input(player1Inputs, 0);
send_input(player2Inputs, 1);

View File

@ -4,9 +4,11 @@
#include "emulibc.h"
#include "am_map.h"
#include "d_englsh.h"
#include "d_main.h"
#include "d_player.h"
#include "doomstat.h"
#include "doomtype.h"
#include "f_wipe.h"
#include "g_game.h"
#include "i_sound.h"
@ -14,6 +16,7 @@
#include "p_mobj.h"
#include "dsda/args.h"
#include "dsda/messenger.h"
#include "dsda/settings.h"
extern int headlessMain(int argc, char **argv);
@ -25,7 +28,7 @@ extern void headlessSetSaveStatePointer(void *savePtr, int saveStateSize);
extern size_t headlessGetEffectiveSaveSize();
// Video
extern void headlessUpdateVideo(void);
extern void headlessUpdateVideo();
extern void* headlessGetVideoBuffer();
extern int headlessGetVideoPitch();
extern int headlessGetVideoWidth();
@ -35,7 +38,7 @@ extern void headlessDisableVideoRendering();
extern uint32_t* headlessGetPallette();
// Audio
extern void headlessUpdateSounds(void);
extern void headlessUpdateSounds();
extern void headlessEnableAudioRendering();
extern void headlessDisableAudioRendering();
extern uint8_t *I_CaptureAudio (int *nsamples);
@ -50,6 +53,30 @@ extern int numthings;
extern mobj_t **mobj_ptrs;
extern dsda_arg_t arg_value[dsda_arg_count];
// Automap
extern void AM_addMark();
extern void AM_StopZooming();
extern void AM_saveScaleAndLoc();
extern int AM_minOutWindowScale();
extern int AM_restoreScaleAndLoc();
extern int automap_active;
extern int automap_follow;
extern int automap_grid;
extern int markpointnum;
extern int zoom_leveltime;
extern dboolean stop_zooming;
extern mpoint_t m_paninc;
extern fixed_t mtof_zoommul;
extern fixed_t ftom_zoommul;
extern fixed_t curr_mtof_zoommul;
extern int map_pan_speed;
extern int map_scroll_speed;
extern fixed_t scale_mtof;
extern fixed_t scale_ftom;
#define FTOM(x) FixedMul(((x)<<16),scale_ftom)
#define M_ZOOMIN ((int) ((float)FRACUNIT * (1.00f + map_scroll_speed / 200.0f)))
#define M_ZOOMOUT ((int) ((float)FRACUNIT / (1.00f + map_scroll_speed / 200.0f)))
#ifdef PALETTE_SIZE
#undef PALETTE_SIZE
#endif
@ -63,6 +90,29 @@ enum MemoryArrayType
ARRAY_SECTORS = 2
};
typedef union
{
struct
{
bool Fire:1;
bool Use:1;
bool ChangeGamma:1;
bool AutomapToggle:1;
bool AutomapZoomIn:1;
bool AutomapZoomOut:1;
bool AutomapFullZoom:1;
bool AutomapFollow:1;
bool AutomapUp:1;
bool AutomapDown:1;
bool AutomapRight:1;
bool AutomapLeft:1;
bool AutomapGrid:1;
bool AutomapMark:1;
bool AutomapClearMarks:1;
};
uint32_t data;
} AllButtons;
struct InitSettings
{
int Player1Present;
@ -83,9 +133,7 @@ struct PackedPlayerInput
int StrafingSpeed;
int TurningSpeed;
int WeaponSelect;
int Fire;
int Action;
int Automap;
AllButtons Buttons;
int FlyLook;
int ArtifactUse;
int Jump;

@ -1 +1 @@
Subproject commit 256a718b96a0fb68faae5f0530e1018d19a1d770
Subproject commit c28f4220943ecee4551dbfb5003969c8dfafdc98