Skip to content

Commit

Permalink
Merge pull request UnclePunch#28 from AlexanderHarrison/add-timer-to-…
Browse files Browse the repository at this point in the history
…savestates

Hold to activate save/load states
  • Loading branch information
AlexanderHarrison authored Sep 26, 2024
2 parents 320bb55 + 3b9c5b2 commit 9b0e4f2
Showing 1 changed file with 29 additions and 44 deletions.
73 changes: 29 additions & 44 deletions src/lab.c
Original file line number Diff line number Diff line change
Expand Up @@ -3738,76 +3738,61 @@ void Savestates_Update()
*/

// timer variables
static int save_timer = 0;
static int load_timer = 0;
static int save_timer[4] = {0}; // Array to track save timer for each fighter
static int lockout_timer = 0;
const int SAVE_THRESHOLD = 20;
const int LOAD_THRESHOLD = 20;
const int LOCKOUT_DURATION = 30;

// not when pause menu is showing
if (Pause_CheckStatus(1) != 2)
{
// check if fighter exists
GOBJ *fighter = Fighter_GetGObj(0);
if (fighter != 0)
if (lockout_timer > 0)
{
// get fighter data
FighterData *fighter_data = fighter->userdata;
HSD_Pad *pad = PadGet(fighter_data->ply, PADGET_MASTER);

// check for savestate
int blacklist = (HSD_BUTTON_DPAD_DOWN | HSD_BUTTON_DPAD_UP | HSD_TRIGGER_Z | HSD_TRIGGER_R | HSD_BUTTON_A | HSD_BUTTON_B | HSD_BUTTON_X | HSD_BUTTON_Y | HSD_BUTTON_START);

if (lockout_timer > 0)
{
lockout_timer--;
}
else
lockout_timer--;
}
else
{
// loop through all controller ports
for (int port = 0; port < 4; port++)
{
HSD_Pad *pad = PadGet(port, PADGET_MASTER);
if (pad == NULL) continue; // Skip if no controller in this port

// check for savestate
int blacklist = (HSD_BUTTON_DPAD_DOWN | HSD_BUTTON_DPAD_UP | HSD_TRIGGER_Z | HSD_TRIGGER_R | HSD_BUTTON_A | HSD_BUTTON_B | HSD_BUTTON_X | HSD_BUTTON_Y | HSD_BUTTON_START);

// Save state (D-pad right)
if ((pad->held & HSD_BUTTON_DPAD_RIGHT) && !(pad->held & blacklist))
{
save_timer++;
if (save_timer == SAVE_THRESHOLD)
save_timer[port]++;
if (save_timer[port] == SAVE_THRESHOLD)
{
// save state
event_vars->Savestate_Save(event_vars->savestate);
save_timer = 0; // Reset timer after saving
save_timer[port] = 0; // Reset timer after saving
lockout_timer = LOCKOUT_DURATION;
}
}
else
{
save_timer = 0; // Reset timer if button is released
save_timer[port] = 0; // Reset timer if button is released
}

// Load state (D-pad left)
if ((pad->held & HSD_BUTTON_DPAD_LEFT) && !(pad->held & blacklist))
if ((pad->down & HSD_BUTTON_DPAD_LEFT) && !(pad->held & blacklist))
{
load_timer++;
if (load_timer == LOAD_THRESHOLD)
{
// load state
event_vars->Savestate_Load(event_vars->savestate);
// load state
event_vars->Savestate_Load(event_vars->savestate);

// re-roll random slot
if (LabOptions_Record[OPTREC_HMNSLOT].option_val == 0)
{
rec_data.hmn_rndm_slot = Record_GetRandomSlot(&rec_data.hmn_inputs);
}
if (LabOptions_Record[OPTREC_CPUSLOT].option_val == 0)
{
rec_data.cpu_rndm_slot = Record_GetRandomSlot(&rec_data.cpu_inputs);
}

load_timer = 0; // Reset timer after loading
lockout_timer = LOCKOUT_DURATION;
// re-roll random slot
if (LabOptions_Record[OPTREC_HMNSLOT].option_val == 0)
{
rec_data.hmn_rndm_slot = Record_GetRandomSlot(&rec_data.hmn_inputs);
}
if (LabOptions_Record[OPTREC_CPUSLOT].option_val == 0)
{
rec_data.cpu_rndm_slot = Record_GetRandomSlot(&rec_data.cpu_inputs);
}
}
else
{
load_timer = 0; // Reset timer if button is released
}
}
}
Expand Down

0 comments on commit 9b0e4f2

Please sign in to comment.