Skip to content

Commit

Permalink
Merge pull request #76 from JCog/consolidate-procs
Browse files Browse the repository at this point in the history
Consolidate procs, don't use bitfields for settings, more
  • Loading branch information
JCog authored Mar 16, 2024
2 parents a0ad22e + 29d4436 commit 3348bf0
Show file tree
Hide file tree
Showing 20 changed files with 266 additions and 518 deletions.
14 changes: 7 additions & 7 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ void fpLog(const char *fmt, ...) {

va_list va;
va_start(va, fmt);
s32 l = vsnprintf(NULL, 0, fmt, va);
s32 msgSize = vsnprintf(NULL, 0, fmt, va) + 1;
va_end(va);

ent = &fp.log[0];
ent->msg = malloc(l + 1);
ent->msg = malloc(msgSize);
if (!ent->msg) {
return;
}
va_start(va, fmt);
vsprintf(ent->msg, fmt, va);
vsnprintf(ent->msg, msgSize, fmt, va);
va_end(va);
ent->age = 0;
}
Expand Down Expand Up @@ -213,8 +213,8 @@ void commandReloadLastWarpProc(void) {
}

void commandToggleWatchesProc(void) {
settings->bits.watchesVisible = !settings->bits.watchesVisible;
if (settings->bits.watchesVisible) {
settings->watchesVisible = !settings->watchesVisible;
if (settings->watchesVisible) {
watchlistShow(fp.menuWatchlist);
} else {
watchlistHide(fp.menuWatchlist);
Expand Down Expand Up @@ -242,7 +242,7 @@ void commandResetTimerProc(void) {
}

void commandShowHideTimerProc(void) {
settings->bits.timerShow = !settings->bits.timerShow;
settings->timerShow = !settings->timerShow;
}

void commandLoadGameProc(void) {
Expand Down Expand Up @@ -271,7 +271,7 @@ void commandBreakFreeProc(void) {
}

void commandToggleInpDispProc(void) {
settings->bits.inputDisplay ^= 1;
settings->inputDisplay ^= 1;
}

void commandClippyProc(void) {
Expand Down
22 changes: 11 additions & 11 deletions src/fp.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void fpDrawInputDisplay(struct GfxFont *font, s32 cellWidth, s32 cellHeight, u8
}

void fpDrawTimer(struct GfxFont *font, s32 cellWidth, s32 cellHeight, u8 menuAlpha) {
s32 hundredths = timerGetTimerCount() * 100 / fp.cpuCounterFreq;
s32 hundredths = timerCount * 100 / fp.cpuCounterFreq;
s32 seconds = hundredths / 100;
s32 minutes = seconds / 60;
s32 hours = minutes / 60;
Expand All @@ -288,9 +288,9 @@ void fpDrawTimer(struct GfxFont *font, s32 cellWidth, s32 cellHeight, u8 menuAlp
gfxPrintf(font, x, y, "%d.%02d", seconds, hundredths);
}

gfxPrintf(font, x, y + cellHeight, "%d", timerGetLagFrames());
if (timerGetMode() != TIMER_MANUAL) {
gfxPrintf(font, x, y + cellHeight * 2, "%d/%d", timerGetCutsceneCount(), timerGetCutsceneTarget());
gfxPrintf(font, x, y + cellHeight, "%d", timerLagFrames);
if (timerMode != TIMER_MANUAL) {
gfxPrintf(font, x, y + cellHeight * 2, "%d/%d", timerCutsceneCount, timerCutsceneTarget);
}
}

Expand Down Expand Up @@ -320,6 +320,9 @@ void fpUpdateCheats(void) {
pm_gActionCommandStatus.barFillLevel = 10000;
}
}
if (CHEAT_ACTIVE(CHEAT_AUTO_ACTION_CMD)) {
pm_gActionCommandStatus.autoSucceed = 1;
}
if (CHEAT_ACTIVE(CHEAT_BRIGHTEN_ROOM)) {
pm_set_screen_overlay_alpha(1, 0);
}
Expand All @@ -330,9 +333,7 @@ void fpUpdateCheats(void) {
// the game is constantly trying to raise this by 1 every frame, so 0 would just make it quiet instead of muted
pm_musicCurrentVolume = -1;
}
if (CHEAT_ACTIVE(CHEAT_AUTO_ACTION_CMD)) {
pm_gActionCommandStatus.autoSucceed = 1;
}
pm_gGameStatus.debugQuizmo = CHEAT_ACTIVE(CHEAT_QUIZMO) != 0;
}

void fpUpdateWarps(void) {
Expand Down Expand Up @@ -366,7 +367,7 @@ void fpDrawLog(struct GfxFont *font, s32 cellWidth, s32 cellHeight, u8 menuAlpha
free(ent->msg);
ent->msg = NULL;
continue;
} else if (!settings->bits.log) {
} else if (!settings->log) {
continue;
} else if (ent->age > fadeBegin) {
msgAlpha = 0xFF - (ent->age - fadeBegin) * 0xFF / fadeDuration;
Expand Down Expand Up @@ -501,13 +502,12 @@ void fpDraw(void) {
fpDrawVersion(font, cellWidth, cellHeight, menuAlpha);
}

if (settings->bits.inputDisplay) {
if (settings->inputDisplay) {
fpDrawInputDisplay(font, cellWidth, cellHeight, menuAlpha);
}

enum TimerState timerState = timerGetState();
if (fp.timerMoving || (timerState == TIMER_STOPPED && !fp.menuActive) ||
(settings->bits.timerShow && !fp.menuActive && timerState != TIMER_INACTIVE)) {
(settings->timerShow && !fp.menuActive && timerState != TIMER_INACTIVE)) {
fpDrawTimer(font, cellWidth, cellHeight, menuAlpha);
}

Expand Down
2 changes: 1 addition & 1 deletion src/fp/debug/flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void addEvent(s32 recordIndex, s32 flagIndex, bool value) {
e->recordIndex = recordIndex;
e->flagIndex = flagIndex;
e->value = value;
sprintf(e->description, "%s[0x%0*lx] := %i", r->name, r->indexLength, flagIndex, value);
snprintf(e->description, sizeof(e->description), "%s[0x%0*lx] := %i", r->name, r->indexLength, flagIndex, value);
}

static u32 getFlagWord(void *data, size_t wordSize, s32 index) {
Expand Down
2 changes: 1 addition & 1 deletion src/fp/debug/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static s32 dataTypeProc(struct MenuItem *item, enum MenuCallbackReason reason, v
break;
case 3:
viewDataSize = 4;
viewFloat = FALSE;
viewFloat = TRUE;
break;
}
makeCells(item->owner);
Expand Down
2 changes: 1 addition & 1 deletion src/fp/file/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static void returnPath(const char *name) {
strcpy(&path[dl + 1 + nl], gfSuffix);
if ((gfMode == GETFILE_SAVE || gfMode == GETFILE_SAVE_PREFIX_INC) && stat(path, NULL) == 0) {
char prompt[48];
sprintf(prompt, "'%.31s' exists", name);
snprintf(prompt, sizeof(prompt), "'%.31s' exists", name);
menuPrompt(&gfMenu, prompt,
"overwrite\0"
"cancel\0",
Expand Down
54 changes: 12 additions & 42 deletions src/fp/file/fp_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,6 @@ static void saveSlotIncProc(struct MenuItem *item, void *data) {
pm_gGameStatus.saveSlot %= 4;
}

static void saveProc(struct MenuItem *item, void *data) {
commandSaveGameProc();
}

static void loadProc(struct MenuItem *item, void *data) {
commandLoadGameProc();
}

static s32 byteModProc(struct MenuItem *item, enum MenuCallbackReason reason, void *data) {
s8 *p = data;
if (reason == MENU_CALLBACK_THINK_INACTIVE) {
if (menuIntinputGet(item) != *p) {
menuIntinputSet(item, *p);
}
} else if (reason == MENU_CALLBACK_CHANGED) {
*p = menuIntinputGet(item);
}
return 0;
}

static s32 byteOptionmodProc(struct MenuItem *item, enum MenuCallbackReason reason, void *data) {
u8 *p = data;
if (reason == MENU_CALLBACK_THINK_INACTIVE) {
if (menuOptionGet(item) != *p) {
menuOptionSet(item, *p);
}
} else if (reason == MENU_CALLBACK_DEACTIVATE) {
*p = menuOptionGet(item);
}
return 0;
}

static s32 storyProgressDrawProc(struct MenuItem *item, struct MenuDrawParams *drawParams) {
gfxModeSet(GFX_MODE_COLOR, GPACK_RGB24A8(drawParams->color, drawParams->alpha));
struct GfxFont *font = drawParams->font;
Expand All @@ -74,11 +42,11 @@ static s32 storyProgressDrawProc(struct MenuItem *item, struct MenuDrawParams *d

char buffer[24];
if (chapter == 0) {
sprintf(buffer, "pro. (%d/%d) -", chapterProgress, chapterMax);
snprintf(buffer, sizeof(buffer), "pro. (%d/%d) -", chapterProgress, chapterMax);
} else if (chapter > 8) {
sprintf(buffer, "invalid -");
snprintf(buffer, sizeof(buffer), "invalid -");
} else {
sprintf(buffer, "ch%d (%d/%d) -", chapter, chapterProgress, chapterMax);
snprintf(buffer, sizeof(buffer), "ch%d (%d/%d) -", chapter, chapterProgress, chapterMax);
}
gfxPrintf(font, x, y, buffer);
return 1;
Expand Down Expand Up @@ -212,9 +180,11 @@ struct Menu *createFileMenu(void) {

menu.selector = menuAddSubmenu(&menu, 0, y++, NULL, "return");
y++;
struct MenuItem *saveButton = menuAddButtonIcon(&menu, 0, y, tSave, 3, 0, 0xFFFFFF, 1.0f, saveProc, NULL);
struct MenuItem *saveButton =
menuAddButtonIcon(&menu, 0, y, tSave, 3, 0, 0xFFFFFF, 1.0f, menuFuncProc, commandSaveGameProc);
saveButton->tooltip = "save";
struct MenuItem *loadButton = menuAddButtonIcon(&menu, 3, y, tSave, 2, 0, 0xFFFFFF, 1.0f, loadProc, NULL);
struct MenuItem *loadButton =
menuAddButtonIcon(&menu, 3, y, tSave, 2, 0, 0xFFFFFF, 1.0f, menuFuncProc, commandLoadGameProc);
loadButton->tooltip = "load";
struct MenuItem *exportButton = menuAddButtonIcon(&menu, 6, y, tSave, 1, 0, 0xFFFFFF, 1.0f, exportFileProc, NULL);
exportButton->tooltip = "export";
Expand All @@ -241,33 +211,33 @@ struct Menu *createFileMenu(void) {

menuAddStatic(&menu, 0, y++, "story progress", 0xC0C0C0);
menuAddStaticCustom(&menu, 0, y, storyProgressDrawProc, NULL, 0xC0C0C0);
struct MenuItem *progressInput = menuAddIntinput(&menu, 14, y++, 16, 2, byteModProc, &STORY_PROGRESS);
struct MenuItem *progressInput = menuAddIntinput(&menu, 14, y++, 16, 2, menuByteModProc, &STORY_PROGRESS);
menuItemAddChainLink(minusButton, progressInput, MENU_NAVIGATE_DOWN);
menuItemAddChainLink(plusButton, progressInput, MENU_NAVIGATE_DOWN);
y++;

menuAddStatic(&menu, 0, y, "quizmo", 0xC0C0C0);
struct MenuItem *quizmoInput =
menuAddIntinput(&menu, menuX, y++, 10, 2, byteModProc, &pm_gCurrentSaveFile.globalBytes[0x161]);
menuAddIntinput(&menu, menuX, y++, 10, 2, menuByteModProc, &pm_gCurrentSaveFile.globalBytes[0x161]);
menuItemAddChainLink(quizmoInput, progressInput, MENU_NAVIGATE_UP);
menuAddStatic(&menu, 0, y, "toy box 1", 0xC0C0C0);
menuAddOption(&menu, menuX, y++,
"goomba\0"
"clubba\0"
"mushroom\0",
byteOptionmodProc, &pm_gCurrentSaveFile.globalBytes[0xD8]);
menuByteOptionmodProc, &pm_gCurrentSaveFile.globalBytes[0xD8]);
menuAddStatic(&menu, 0, y, "toy box 2", 0xC0C0C0);
menuAddOption(&menu, menuX, y++,
"fuzzy\0"
"hammer bros.\0"
"thunder rage\0",
byteOptionmodProc, &pm_gCurrentSaveFile.globalBytes[0xD9]);
menuByteOptionmodProc, &pm_gCurrentSaveFile.globalBytes[0xD9]);
menuAddStatic(&menu, 0, y, "toy box 3", 0xC0C0C0);
struct MenuItem *toyboxItem3Option = menuAddOption(&menu, menuX, y++,
"pokey\0"
"koopatrol\0"
"super soda\0",
byteOptionmodProc, &pm_gCurrentSaveFile.globalBytes[0xDA]);
menuByteOptionmodProc, &pm_gCurrentSaveFile.globalBytes[0xDA]);
y++;

struct MenuItem *enemiesButton = menuAddButton(&menu, 0, y++, "restore enemies", restoreEnemiesProc, NULL);
Expand Down
31 changes: 2 additions & 29 deletions src/fp/fp_cheats.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,9 @@
static const char *labels[] = {
"hp", "fp", "coins", "star power", "star pieces",
"peril", "auto mash", "action commands", "peekaboo", "brighten room",
"hide hud", "mute music",
"hide hud", "mute music", "quizmo spawns",
};

static s32 byteOptionmodProc(struct MenuItem *item, enum MenuCallbackReason reason, void *data) {
u8 *p = data;
if (reason == MENU_CALLBACK_THINK_INACTIVE) {
if (menuOptionGet(item) != *p) {
menuOptionSet(item, *p);
}
} else if (reason == MENU_CALLBACK_DEACTIVATE) {
*p = menuOptionGet(item);
}
return 0;
}

static s32 quizmoProc(struct MenuItem *item, enum MenuCallbackReason reason, void *data) {
if (reason == MENU_CALLBACK_SWITCH_ON) {
pm_gGameStatus.debugQuizmo = 1;
settings->bits.quizmoDebug = 1;
} else if (reason == MENU_CALLBACK_SWITCH_OFF) {
pm_gGameStatus.debugQuizmo = 0;
settings->bits.quizmoDebug = 0;
} else if (reason == MENU_CALLBACK_THINK) {
menuCheckboxSet(item, pm_gGameStatus.debugQuizmo);
}
return 0;
}

static s32 cheatProc(struct MenuItem *item, enum MenuCallbackReason reason, void *data) {
s32 cheatIndex = (s32)data;
if (reason == MENU_CALLBACK_SWITCH_ON) {
Expand Down Expand Up @@ -61,7 +36,7 @@ struct Menu *createCheatsMenu(void) {
"defeat on contact\0"
"auto-win\0"
"auto-runaway\0",
byteOptionmodProc, &settings->cheatEnemyContact);
menuByteOptionmodProc, &settings->cheatEnemyContact);
y++;
menuItemAddChainLink(menu.selector, encountersOption, MENU_NAVIGATE_DOWN);
for (s32 i = 0; i < CHEAT_MAX; i++) {
Expand All @@ -71,8 +46,6 @@ struct Menu *createCheatsMenu(void) {
menuItemAddChainLink(option, encountersOption, MENU_NAVIGATE_UP);
}
}
menuAddCheckbox(&menu, 0, y, quizmoProc, NULL);
menuAddStatic(&menu, 2, y++, "quizmo spawns", 0xC0C0C0);
y++;
menuAddButton(&menu, 0, y++, "save settings", fpSaveSettingsProc, NULL);

Expand Down
Loading

0 comments on commit 3348bf0

Please sign in to comment.