Skip to content

Commit

Permalink
implements optional pausing
Browse files Browse the repository at this point in the history
- implements "Enable Pausing" option in `Extended -> Video". It takes effect immediately.
- input-related gameplay checks use `g_Vars.currentplayer->pausemode` instead of `lvIsPaused()`
- input-related fixes when disabling pausing in solo
- allocate extra memory for `invmenu`, `gunmenu` just for inventory models
  • Loading branch information
cylonicboom committed Jan 20, 2024
1 parent 474a6df commit 4a232db
Show file tree
Hide file tree
Showing 20 changed files with 245 additions and 93 deletions.
1 change: 1 addition & 0 deletions port/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ PD_CONSTRUCTOR static void gameConfigInit(void)
configRegisterInt("Game.MemorySize", &g_OsMemSizeMb, 4, 2048);
configRegisterInt("Game.CenterHUD", &g_HudCenter, 0, 2);
configRegisterFloat("Game.ScreenShakeIntensity", &g_ViShakeIntensityMult, 0.f, 10.f);
configRegisterInt("Game.PausingEnabled", &g_PausingEnabled, 0, 1);
configRegisterInt("Game.TickRateDivisor", &g_TickRateDiv, 0, 10);
configRegisterInt("Game.SkipIntro", &g_SkipIntro, 0, 1);
configRegisterInt("Game.DisableMpDeathMusic", &g_MusicDisableMpDeath, 0, 1);
Expand Down
22 changes: 22 additions & 0 deletions port/src/optionsmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,20 @@ static MenuItemHandlerResult menuhandlerCenterHUD(s32 operation, struct menuitem
return 0;
}

static MenuItemHandlerResult menuhandlerSetPausingEnabled(s32 operation, struct menuitem *item, union handlerdata *data)
{
switch (operation) {
case MENUOP_GET:
return g_PausingEnabled;
break;
case MENUOP_SET:
g_PausingEnabled = data->checkbox.value;
break;
}

return 0;
}

static MenuItemHandlerResult menuhandlerScreenShake(s32 operation, struct menuitem *item, union handlerdata *data)
{
switch (operation) {
Expand Down Expand Up @@ -809,6 +823,14 @@ struct menuitem g_ExtendedVideoMenuItems[] = {
20,
menuhandlerScreenShake,
},
{
MENUITEMTYPE_CHECKBOX,
0,
MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SLIDER_WIDE,
(uintptr_t)"Enable Pausing",
20,
menuhandlerSetPausingEnabled,
},
{
MENUITEMTYPE_SEPARATOR,
0,
Expand Down
8 changes: 5 additions & 3 deletions src/game/bondbike.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void bbikeApplyMoveData(struct movedata *data)
|| contmode == CONTROLMODE_13
|| contmode == CONTROLMODE_11
|| contmode == CONTROLMODE_PC)
&& !lvIsPaused()) {
&& !g_Vars.currentplayer->pausemode) {
u32 lmask, rmask;
if (contmode == CONTROLMODE_PC) {
lmask = L_CBUTTONS;
Expand All @@ -218,8 +218,10 @@ void bbikeApplyMoveData(struct movedata *data)
lmask = L_JPAD | L_CBUTTONS;
rmask = R_JPAD | R_CBUTTONS;
}
data->digitalstepleft = joyCountButtonsOnSpecificSamples(0, contnum, lmask);
data->digitalstepright = joyCountButtonsOnSpecificSamples(0, contnum, rmask);
if (g_Vars.currentplayer->pausemode == PAUSEMODE_UNPAUSED) {
data->digitalstepleft = joyCountButtonsOnSpecificSamples(0, contnum, lmask);
data->digitalstepright = joyCountButtonsOnSpecificSamples(0, contnum, rmask);
}
}

// Forward/back
Expand Down
83 changes: 53 additions & 30 deletions src/game/bondeyespy.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "game/player.h"
#include "game/hudmsg.h"
#include "game/inv.h"
#include "game/lv.h"
#include "game/mplayer/ingame.h"
#include "game/playermgr.h"
#include "game/stagetable.h"
Expand Down Expand Up @@ -702,7 +703,9 @@ void eyespyProcessInput(bool allowbuttons)
s8 c1sticky = joyGetStickY(contpad1);
s8 c2sticky;
u32 c1buttons = allowbuttons ? joyGetButtons(contpad1, 0xffffffff) : 0;
u32 c1buttonsthisframe = allowbuttons ? joyGetButtonsPressedThisFrame(contpad1, 0xffffffff): 0;
u32 c2buttons;
u32 c2buttonsthisframe;
bool domovecentre = true;
s32 controlmode = optionsGetControlMode(g_Vars.currentplayerstats->mpindex);

Expand All @@ -722,6 +725,7 @@ void eyespyProcessInput(bool allowbuttons)
f32 tmp;
u32 umask, dmask, lmask, rmask;

bool pausepressed;
if (controlmode == CONTROLMODE_PC) {
umask = U_CBUTTONS;
dmask = D_CBUTTONS;
Expand All @@ -740,6 +744,7 @@ void eyespyProcessInput(bool allowbuttons)
c2sticky = joyGetStickY(contpad2);

c2buttons = allowbuttons ? joyGetButtons(contpad2, 0xffffffff) : 0;
c2buttonsthisframe = allowbuttons ? joyGetButtonsPressedThisFrame(contpad2, 0xffffffff) : 0;
} else {
#ifndef PLATFORM_N64
if (controlmode == CONTROLMODE_PC) {
Expand All @@ -753,25 +758,27 @@ void eyespyProcessInput(bool allowbuttons)
}
#endif
c2buttons = c1buttons;
c2buttonsthisframe = c1buttonsthisframe;
}

pausepressed = c1buttonsthisframe & START_BUTTON;
if (controlmode == CONTROLMODE_13 || controlmode == CONTROLMODE_14) {
aimpressed = c1buttons & Z_TRIG;
shootpressed = c1buttons & A_BUTTON;
exitpressed = c1buttons & R_TRIG;
activatepressed = c1buttons & B_BUTTON;
exitpressed = c1buttonsthisframe & R_TRIG;
activatepressed = c1buttonsthisframe & B_BUTTON;
} else if (controlmode <= CONTROLMODE_14 || controlmode == CONTROLMODE_PC) {
aimpressed = c1buttons & (R_TRIG);
shootpressed = c1buttons & Z_TRIG;
#ifndef PLATFORM_N64
if (controlmode == CONTROLMODE_PC) {
exitpressed = c1buttons & (BUTTON_WPNBACK | BUTTON_RADIAL);
activatepressed = c1buttons & (BUTTON_CANCEL_USE | BUTTON_ACCEPT_USE);
exitpressed = c1buttonsthisframe & (BUTTON_WPNBACK | BUTTON_RADIAL);
activatepressed = c1buttonsthisframe & (BUTTON_CANCEL_USE | BUTTON_ACCEPT_USE);
} else
#endif
{
exitpressed = (c1buttons | c2buttons) & A_BUTTON;
activatepressed = (c1buttons | c2buttons) & B_BUTTON;
exitpressed = (c1buttonsthisframe | c2buttonsthisframe) & A_BUTTON;
activatepressed = (c1buttonsthisframe | c2buttonsthisframe) & B_BUTTON;
}
} else {
if (controlmode >= CONTROLMODE_23) {
Expand All @@ -782,8 +789,8 @@ void eyespyProcessInput(bool allowbuttons)
shootpressed = c1buttons & Z_TRIG;
}

exitpressed = (c1buttons | c2buttons) & A_BUTTON;
activatepressed = (c1buttons | c2buttons) & B_BUTTON;
exitpressed = (c1buttonsthisframe | c2buttonsthisframe) & A_BUTTON;
activatepressed = (c1buttonsthisframe | c2buttonsthisframe) & B_BUTTON;
}

// Apply safe zone for c1stickx
Expand Down Expand Up @@ -932,7 +939,7 @@ void eyespyProcessInput(bool allowbuttons)
&& g_Vars.currentplayer->pausemode == PAUSEMODE_UNPAUSED
&& (c1buttons & START_BUTTON)) {
if (!g_Vars.mplayerisrunning) {
playerPause(MENUROOT_MAINMENU);
playerStartPause(MENUROOT_MAINMENU);
} else {
mpPushPauseDialog();
}
Expand Down Expand Up @@ -1187,33 +1194,49 @@ void eyespyProcessInput(bool allowbuttons)
return;
}

// Handle trigger
if (g_Vars.currentplayer->eyespy->camerashuttertime <= 0 && shootpressed && g_Vars.currentplayer->eyespy->active) {
if (g_Vars.currentplayer->eyespy->camerabuttonheld == false) {
g_Vars.currentplayer->eyespy->camerabuttonheld = true;
g_Vars.currentplayer->eyespy->camerashuttertime = TICKS(24);
// handle pause menu
if (!g_Vars.currentplayer->pausemode) {
if (g_Vars.currentplayer->eyespy->active && !g_Vars.currentplayer->isdead) {
if (!( g_Vars.currentplayer->pausemode & (PAUSEMODE_PAUSED | PAUSEMODE_PAUSING) ) && (pausepressed)) {
if (g_Vars.mplayerisrunning == false) {
if (g_Vars.lvframenum > 15) {
playerStartPause(MENUROOT_MAINMENU);
}
} else {
mpPushPauseDialog();
}
}

}
// Handle trigger
if (g_Vars.currentplayer->eyespy->camerashuttertime <= 0 && shootpressed && g_Vars.currentplayer->eyespy->active) {
if (g_Vars.currentplayer->eyespy->camerabuttonheld == false) {
g_Vars.currentplayer->eyespy->camerabuttonheld = true;
g_Vars.currentplayer->eyespy->camerashuttertime = TICKS(24);
}
} else {
g_Vars.currentplayer->eyespy->camerabuttonheld = false;
}
} else {
g_Vars.currentplayer->eyespy->camerabuttonheld = false;
}

// Handle exit
if (exitpressed && g_Vars.currentplayer->eyespy->active) {
g_Vars.currentplayer->eyespy->active = false;
g_Vars.currentplayer->devicesactive &= ~DEVICE_EYESPY;
}
// Handle exit
if (exitpressed && g_Vars.currentplayer->eyespy->active) {
g_Vars.currentplayer->eyespy->active = false;
g_Vars.currentplayer->devicesactive &= ~DEVICE_EYESPY;
}

// Handle B button activation
if (activatepressed && g_Vars.currentplayer->eyespy->active) {
if (g_Vars.currentplayer->eyespy->buttonheld == false) {
g_Vars.currentplayer->eyespy->buttonheld = true;
g_Vars.currentplayer->eyespy->opendoor = true;
// Handle B button activation
// but only if not in a pause-like state
if (activatepressed && g_Vars.currentplayer->eyespy->active) {
if (g_Vars.currentplayer->eyespy->buttonheld == false) {
g_Vars.currentplayer->eyespy->buttonheld = true;
g_Vars.currentplayer->eyespy->opendoor = true;
} else {
g_Vars.currentplayer->eyespy->opendoor = false;
}
} else {
g_Vars.currentplayer->eyespy->opendoor = false;
g_Vars.currentplayer->eyespy->buttonheld = false;
}
} else {
g_Vars.currentplayer->eyespy->opendoor = false;
g_Vars.currentplayer->eyespy->buttonheld = false;
}

g_Vars.currentplayer->eyespy->hit = g_EyespyHit;
Expand Down
10 changes: 9 additions & 1 deletion src/game/bondgun.c
Original file line number Diff line number Diff line change
Expand Up @@ -3637,6 +3637,13 @@ u8 *bgunGetGunMem(void)
return g_Vars.currentplayer->gunctrl.gunmem;
}

#ifndef PLATFORM_N64
u8 *bgunGetInvMem(void)
{
return g_Vars.currentplayer->gunctrl.invmem;
}
#endif

u32 bgunCalculateGunMemCapacity(void)
{
if (IS4MB() && PLAYERCOUNT() == 2) {
Expand All @@ -3654,7 +3661,8 @@ u32 bgunCalculateGunMemCapacity(void)
return g_BgunGunMemBaseSizeDefault + 25 * 1024;
}
#else
return g_BgunGunMemBaseSizeDefault + stageGetCurrent()->extragunmem;
// extra space to store invmen
return (g_BgunGunMemBaseSizeDefault * 2) + stageGetCurrent()->extragunmem;
#endif
}

Expand Down
1 change: 1 addition & 0 deletions src/game/bondgunreset.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void bgunReset(void)
}

g_Vars.currentplayer->gunctrl.gunmem = mempAlloc(i, MEMPOOL_STAGE);
g_Vars.currentplayer->gunctrl.invmem = mempAlloc(i, MEMPOOL_STAGE);
g_Vars.currentplayer->gunctrl.handfilenum = 0;
g_Vars.currentplayer->gunctrl.handmemloadptr = 0;
g_Vars.currentplayer->gunctrl.handmemloadremaining = 0;
Expand Down
10 changes: 6 additions & 4 deletions src/game/bondmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,10 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i

// Pausing
if (g_Vars.currentplayer->isdead == false) {
if (g_Vars.currentplayer->pausemode == PAUSEMODE_UNPAUSED && (c1buttonsthisframe & START_BUTTON)) {
if (g_Vars.currentplayer->pausemode == PAUSEMODE_UNPAUSED && (c1buttonsthisframe & (START_BUTTON))) {
if (g_Vars.mplayerisrunning == false) {
if (g_Vars.lvframenum > 15) {
playerPause(MENUROOT_MAINMENU);
playerStartPause(MENUROOT_MAINMENU);
}
} else {
mpPushPauseDialog();
Expand Down Expand Up @@ -904,7 +904,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i
g_Vars.currentplayer->insightaimmode = aimonhist[numsamples - 1];
}

if (!lvIsPaused()) {
if (!g_Vars.currentplayer->pausemode) {
// Handle aiming
if (optionsGetAimControl(g_Vars.currentplayerstats->mpindex) != AIMCONTROL_HOLD) {
for (i = 0; i < numsamples; i++) {
Expand Down Expand Up @@ -1235,7 +1235,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i
g_Vars.currentplayer->insightaimmode = aimonhist[numsamples - 1];
}

if (!lvIsPaused()) {
if (!g_Vars.currentplayer->pausemode) {
// Handle aiming
if (optionsGetAimControl(g_Vars.currentplayerstats->mpindex) != AIMCONTROL_HOLD) {
for (i = 0; i < numsamples; i++) {
Expand Down Expand Up @@ -2053,6 +2053,8 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i

g_Vars.currentplayer->vv_verta += g_Vars.currentplayer->speedverta * g_Vars.lvupdate60freal * 3.5f;
}
} else {
g_Vars.currentplayer->speedthetacontrol = 0;
}

if (movedata.cannaturalturn) {
Expand Down
2 changes: 1 addition & 1 deletion src/game/credits.c
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ void creditsTickSlide(void)
g_CreditsData->unk4208 = 0;

musicEndMenu();
musicStartPrimary(0);
musicStartPrimaryWithReason(0,1);
}
} while (credit && credit->more && g_CreditsData->numthisslide < 4);

Expand Down
9 changes: 5 additions & 4 deletions src/game/lv.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ struct sndstate *g_MiscSfxAudioHandles[3];
u32 var800aa5bc;
s32 g_MiscSfxActiveTypes[3];

bool g_PausingEnabled = 1;
u32 var80084010 = 0;
bool var80084014 = false;
bool g_LvPaused = false;
f32 var80084018 = 1;
u32 var8008401c = 0x00000001;

Expand Down Expand Up @@ -237,7 +238,7 @@ void lvReset(s32 stagenum)
{
lvFadeReset();

var80084014 = false;
g_LvPaused = false;
var80084010 = 0;

#if VERSION >= VERSION_NTSC_1_0
Expand Down Expand Up @@ -2458,12 +2459,12 @@ void lvSetPaused(bool paused)
pakEnableRumbleForAllPlayers();
}

var80084014 = paused;
g_LvPaused = paused;
}

bool lvIsPaused(void)
{
return var80084014;
return g_LvPaused;
}

s32 lvGetDifficulty(void)
Expand Down
Loading

0 comments on commit 4a232db

Please sign in to comment.