Skip to content

Commit

Permalink
Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into…
Browse files Browse the repository at this point in the history
… port-debugger
  • Loading branch information
fgsfdsfgs committed Nov 25, 2023
2 parents aa6ac4b + 45a44cd commit 0cf6021
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ src/assets/*/sequences/*.seq
src/assets/*/textures/*.bin
src/generated
tools/mkrom/mkrom
/.vs
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ There are minor graphics- and gameplay-related issues, and possibly occasional c
* 60 FPS support, including fixes for some framerate-related issues;
* fixes for a couple original bugs and crashes;
* basic mod support, currently enough to load a few custom levels;
* slightly expanded memory heap size.
* slightly expanded memory heap size;
* experimental uncapped framerate support:
* set `Game.TickRateDivisor` to `0` in `pd.ini` to activate;
* in practice the game will have issues running faster than ~150 FPS, so use VSync or `Video.FramerateLimit` to cap it.

Currently only 32-bit platforms are supported, namely x86 Windows and Linux.
Note that 32-bit binaries will still work on 64-bit versions of those platforms,
Expand Down
2 changes: 2 additions & 0 deletions port/fast3d/gfx_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,8 @@ void gfx_opengl_copy_framebuffer(int fb_dst, int fb_src, int left, int top, bool

glBindFramebuffer(GL_FRAMEBUFFER, framebuffers[current_framebuffer].fbo);

glReadBuffer(GL_BACK);

glEnable(GL_SCISSOR_TEST);
}

Expand Down
7 changes: 6 additions & 1 deletion port/fast3d/gfx_pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,17 @@ static void import_texture(int i, int tile, bool importReplacement) {

if (rdp.tex_lod || !loaded_texture.addr) {
// set up miplevel 0; also acts as a catch-all for when .addr is NULL because my texture loader sucks
loaded_texture.addr = rdp.texture_to_load.addr;
loaded_texture.line_size_bytes = rdp.texture_tile[tile].line_size_bytes;
loaded_texture.full_image_line_size_bytes = rdp.texture_tile[tile].line_size_bytes;
loaded_texture.full_size_bytes = loaded_texture.full_image_line_size_bytes * rdp.texture_tile[tile].height;
loaded_texture.size_bytes = loaded_texture.line_size_bytes * rdp.texture_tile[tile].height;
if (siz == G_IM_SIZ_32b) {
// HACK: fixup 32-bit LODed texture height
loaded_texture.size_bytes <<= 1;
loaded_texture.full_size_bytes <<= 1;
}
loaded_texture.orig_size_bytes = loaded_texture.size_bytes;
loaded_texture.addr = rdp.texture_to_load.addr;
}

const RawTexMetadata* metadata = &loaded_texture.raw_tex_metadata;
Expand Down
15 changes: 14 additions & 1 deletion port/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ u8 g_VmShowStats = 0;

s32 g_TickRateDiv = 1;

s32 g_SkipIntro = false;

extern s32 g_StageNum;

s32 bootGetMemSize(void)
Expand Down Expand Up @@ -123,7 +125,17 @@ int main(int argc, const char **argv)
sysLogPrintf(LOG_NOTE, "rom file at %p - %p", g_RomFile, g_RomFile + g_RomFileSize);

g_SndDisabled = sysArgCheck("--no-sound");

g_StageNum = sysArgGetInt("--boot-stage", STAGE_TITLE);

if (g_StageNum == STAGE_TITLE && (sysArgCheck("--skip-intro") || g_SkipIntro)) {
// shorthand for --boot-stage 0x26
g_StageNum = STAGE_CITRAINING;
} else if (g_StageNum < 0x01 || g_StageNum > 0x5d) {
// stage num out of range
g_StageNum = STAGE_TITLE;
}

if (g_StageNum != STAGE_TITLE) {
sysLogPrintf(LOG_NOTE, "boot stage set to 0x%02x", g_StageNum);
}
Expand All @@ -139,6 +151,7 @@ PD_CONSTRUCTOR static void gameConfigInit(void)
configRegisterInt("Game.CenterHUD", &g_HudCenter, 0, 1);
configRegisterFloat("Game.ScreenShakeIntensity", &g_ViShakeIntensityMult, 0.f, 10.f);
configRegisterInt("Game.TickRateDivisor", &g_TickRateDiv, 0, 10);
configRegisterInt("Game.SkipIntro", &g_SkipIntro, 0, 1);
for (s32 j = 0; j < MAX_PLAYERS; ++j) {
const s32 i = j + 1;
configRegisterFloat(strFmt("Game.Player%d.FovY", i), &g_PlayerExtCfg[j].fovy, 5.f, 175.f);
Expand All @@ -148,6 +161,6 @@ PD_CONSTRUCTOR static void gameConfigInit(void)
configRegisterFloat(strFmt("Game.Player%d.MouseAimSpeedY", i), &g_PlayerExtCfg[j].mouseaimspeedy, 0.f, 10.f);
configRegisterFloat(strFmt("Game.Player%d.RadialMenuSpeed", i), &g_PlayerExtCfg[j].radialmenuspeed, 0.f, 10.f);
configRegisterFloat(strFmt("Game.Player%d.CrosshairSway", i), &g_PlayerExtCfg[j].crosshairsway, 0.f, 10.f);
configRegisterInt(strFmt("Game.Player%d.ClassicCrouch", i), &g_PlayerExtCfg[j].classiccrouch, 0, 1);
configRegisterInt(strFmt("Game.Player%d.CrouchMode", i), &g_PlayerExtCfg[j].crouchmode, 0, CROUCHMODE_TOGGLE_ANALOG);
}
}
45 changes: 29 additions & 16 deletions port/src/optionsmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "types.h"
#include "game/mainmenu.h"
#include "game/menu.h"
#include "game/gamefile.h"
#include "video.h"
#include "input.h"
#include "config.h"
Expand Down Expand Up @@ -723,32 +724,44 @@ struct menudialogdef g_ExtendedVideoMenuDialog = {
NULL,
};

static MenuItemHandlerResult menuhandlerFieldOfView(s32 operation, struct menuitem *item, union handlerdata *data)
static MenuItemHandlerResult menuhandlerCrouchMode(s32 operation, struct menuitem *item, union handlerdata *data)
{
static const char *opts[] = {
"Hold",
"Analog",
"Toggle",
"Toggle + Analog"
};

switch (operation) {
case MENUOP_GETSLIDER:
data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].fovy + 0.5f;
case MENUOP_GETOPTIONCOUNT:
data->dropdown.value = ARRAYCOUNT(opts);
break;
case MENUOP_GETOPTIONTEXT:
return (intptr_t)opts[data->dropdown.value];
case MENUOP_SET:
if (data->slider.value >= 15) {
g_PlayerExtCfg[g_ExtMenuPlayer].fovy = data->slider.value;
if (g_PlayerExtCfg[g_ExtMenuPlayer].fovzoom) {
g_PlayerExtCfg[g_ExtMenuPlayer].fovzoommult = g_PlayerExtCfg[g_ExtMenuPlayer].fovy / 60.f;
}
}
g_PlayerExtCfg[g_ExtMenuPlayer].crouchmode = data->dropdown.value;
break;
case MENUOP_GETSELECTEDINDEX:
data->dropdown.value = g_PlayerExtCfg[g_ExtMenuPlayer].crouchmode;
}

return 0;
}

static MenuItemHandlerResult menuhandlerClassicCrouch(s32 operation, struct menuitem *item, union handlerdata *data)
static MenuItemHandlerResult menuhandlerFieldOfView(s32 operation, struct menuitem *item, union handlerdata *data)
{
switch (operation) {
case MENUOP_GET:
return g_PlayerExtCfg[g_ExtMenuPlayer].classiccrouch;
case MENUOP_GETSLIDER:
data->slider.value = g_PlayerExtCfg[g_ExtMenuPlayer].fovy + 0.5f;
break;
case MENUOP_SET:
g_PlayerExtCfg[g_ExtMenuPlayer].classiccrouch = data->checkbox.value;
if (data->slider.value >= 15) {
g_PlayerExtCfg[g_ExtMenuPlayer].fovy = data->slider.value;
if (g_PlayerExtCfg[g_ExtMenuPlayer].fovzoom) {
g_PlayerExtCfg[g_ExtMenuPlayer].fovzoommult = g_PlayerExtCfg[g_ExtMenuPlayer].fovy / 60.f;
}
}
break;
}

Expand All @@ -771,12 +784,12 @@ static MenuItemHandlerResult menuhandlerCrosshairSway(s32 operation, struct menu

struct menuitem g_ExtendedGameMenuItems[] = {
{
MENUITEMTYPE_CHECKBOX,
MENUITEMTYPE_DROPDOWN,
0,
MENUITEMFLAG_LITERAL_TEXT,
(uintptr_t)"Allow Classic Crouch",
(uintptr_t)"Crouch Mode",
0,
menuhandlerClassicCrouch,
menuhandlerCrouchMode,
},
{
MENUITEMTYPE_SLIDER,
Expand Down
56 changes: 34 additions & 22 deletions src/game/bondmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -1565,31 +1565,43 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i

// Handle xbla-style crouch cycling
for (i = 0; i < numsamples; i++) {
s32 crouchsample = joyGetButtonsPressedOnSample(i, contpad1, 0xffffffff) & BUTTON_CROUCH_CYCLE;
if (crouchsample) {
if (g_Vars.currentplayer->crouchpos <= 0) {
g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND;
} else {
g_Vars.currentplayer->crouchpos--;
}
}

// handle 1964GEPD style crouch setting
crouchsample = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons) & BUTTON_HALF_CROUCH;
if (crouchsample) {
if (g_Vars.currentplayer->crouchpos == CROUCHPOS_DUCK) {
g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND;
} else {
g_Vars.currentplayer->crouchpos = CROUCHPOS_DUCK;
s32 crouchsample;
if (PLAYER_EXTCFG().crouchmode & CROUCHMODE_TOGGLE) {
// press to toggle crouch position
crouchsample = joyGetButtonsPressedOnSample(i, contpad1, 0xffffffff) & BUTTON_CROUCH_CYCLE;
if (crouchsample) {
if (g_Vars.currentplayer->crouchpos <= 0) {
g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND;
} else {
g_Vars.currentplayer->crouchpos--;
}
}
}

crouchsample = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons) & BUTTON_FULL_CROUCH;
if (crouchsample) {
if (g_Vars.currentplayer->crouchpos == CROUCHPOS_SQUAT) {
crouchsample = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons) & BUTTON_HALF_CROUCH;
if (crouchsample) {
if (g_Vars.currentplayer->crouchpos == CROUCHPOS_DUCK) {
g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND;
} else {
g_Vars.currentplayer->crouchpos = CROUCHPOS_DUCK;
}
}
crouchsample = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons) & BUTTON_FULL_CROUCH;
if (crouchsample) {
if (g_Vars.currentplayer->crouchpos == CROUCHPOS_SQUAT) {
g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND;
} else {
g_Vars.currentplayer->crouchpos = CROUCHPOS_SQUAT;
}
}
} else if (PLAYER_EXTCFG().crouchmode == CROUCHMODE_HOLD) {
// hold to crouch
crouchsample = joyGetButtonsOnSample(i, contpad1, c1allowedbuttons) & (BUTTON_FULL_CROUCH | BUTTON_HALF_CROUCH);
if (!crouchsample) {
g_Vars.currentplayer->crouchpos = CROUCHPOS_STAND;
} else {
} else if (crouchsample & BUTTON_FULL_CROUCH) {
g_Vars.currentplayer->crouchpos = CROUCHPOS_SQUAT;
} else if (crouchsample & BUTTON_HALF_CROUCH) {
g_Vars.currentplayer->crouchpos = CROUCHPOS_DUCK;
}
}
}
Expand Down Expand Up @@ -1657,7 +1669,7 @@ void bmoveProcessInput(bool allowc1x, bool allowc1y, bool allowc1buttons, bool i
#endif

// Handle C-button and analog crouch and uncrouch, if enabled
if (PLAYER_EXTCFG().classiccrouch && allowc1buttons) {
if ((PLAYER_EXTCFG().crouchmode & CROUCHMODE_ANALOG) && allowc1buttons) {
for (i = 0; i < numsamples; i++) {
if (!canmanualzoom && aimonhist[i]) {
bool goUp = joyGetButtonsPressedOnSample(i, contpad1, c1allowedbuttons & (U_CBUTTONS));
Expand Down
83 changes: 83 additions & 0 deletions src/game/cheats.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,79 @@ char *cheatGetName(s32 cheat_id)
}
#endif

#ifndef PLATFORM_N64

static MenuItemHandlerResult menuhandlerUnlockEverything(s32 operation, struct menuitem *item, union handlerdata *data)
{
if (operation == MENUOP_SET) {
gamefileUnlockEverything();
}
return 0;
}

struct menuitem g_CheatsConfirmUnlockMenuItems[] = {
{
MENUITEMTYPE_LABEL,
0,
MENUITEMFLAG_LITERAL_TEXT,
(uintptr_t)"Are you sure?\n\nThis will overwrite any progress\nsaved to the current profile.\n",
0,
NULL,
},
{
MENUITEMTYPE_SEPARATOR,
0,
0,
0x00000082,
0,
NULL,
},
{
MENUITEMTYPE_MARQUEE,
0,
MENUITEMFLAG_SMALLFONT | MENUITEMFLAG_MARQUEE_FADEBOTHSIDES | MENUITEMFLAG_LITERAL_TEXT,
(uintptr_t)"Unlocks all cheats, weapons, missions, challenges and combat simulator items.\n",
0,
NULL,
},
{
MENUITEMTYPE_SEPARATOR,
0,
0,
0x00000082,
0,
NULL,
},
{
MENUITEMTYPE_SELECTABLE,
0,
MENUITEMFLAG_SELECTABLE_CENTRE | MENUITEMFLAG_SELECTABLE_CLOSESDIALOG,
L_OPTIONS_191, // "No"
0,
NULL,
},
{
MENUITEMTYPE_SELECTABLE,
0,
MENUITEMFLAG_SELECTABLE_CENTRE | MENUITEMFLAG_SELECTABLE_CLOSESDIALOG,
L_OPTIONS_190, // "Yes"
0,
menuhandlerUnlockEverything,
},
{ MENUITEMTYPE_END },
};

struct menudialogdef g_CheatsConfirmUnlockMenuDialog = {
MENUDIALOGTYPE_DANGER,
L_OPTIONS_188, // "Warning"
g_CheatsConfirmUnlockMenuItems,
NULL,
0,
NULL,
};

#endif

struct menuitem g_CheatsFunMenuItems[] = {
{
MENUITEMTYPE_CHECKBOX,
Expand Down Expand Up @@ -1538,6 +1611,16 @@ struct menuitem g_CheatsMenuItems[] = {
0,
cheatMenuHandleTurnOffAllCheats,
},
#ifndef PLATFORM_N64
{
MENUITEMTYPE_SELECTABLE,
0,
MENUITEMFLAG_LITERAL_TEXT | MENUITEMFLAG_SELECTABLE_OPENSDIALOG,
(uintptr_t)"Unlock Everything\n",
0,
(void *)&g_CheatsConfirmUnlockMenuDialog,
},
#endif
{
MENUITEMTYPE_SEPARATOR,
0,
Expand Down
Loading

0 comments on commit 0cf6021

Please sign in to comment.