From 36f95a2087c482cb79576d8b9d2e82a6cfaf6d99 Mon Sep 17 00:00:00 2001 From: Viperio19 Date: Mon, 9 Dec 2024 11:18:35 +0100 Subject: [PATCH] Making `journal.h` structs named, making small changes to function names, mirroring param names in include files, removing unnecessary comments, using heap ids, and returning `BOOL`s instead of `int`s --- asm/macros/scrcmd.inc | 12 ++--- include/journal.h | 16 +++--- src/encounter.c | 4 +- src/journal.c | 8 +-- src/journal_display/journal_controller.c | 68 ++++++++++++------------ 5 files changed, 54 insertions(+), 54 deletions(-) diff --git a/asm/macros/scrcmd.inc b/asm/macros/scrcmd.inc index 6bfab0e251..0f8105f43f 100644 --- a/asm/macros/scrcmd.inc +++ b/asm/macros/scrcmd.inc @@ -2464,13 +2464,13 @@ .short 460 .endm - .macro ScrCmd_CreateJournalEvent arg0, arg1, arg2, arg3, arg4 + .macro ScrCmd_CreateJournalEvent eventType, eventParam, unused1, unused2, unused3 .short 461 - .short \arg0 - .short \arg1 - .short \arg2 - .short \arg3 - .short \arg4 + .short \eventType + .short \eventParam + .short \unused1 + .short \unused2 + .short \unused3 .endm .macro ScrCmd_1CE diff --git a/include/journal.h b/include/journal.h index 693223d52b..19e8afbdd7 100644 --- a/include/journal.h +++ b/include/journal.h @@ -109,7 +109,7 @@ enum JournalOnlineEventType { ONLINE_EVENT_WIFI_CLUB, }; -typedef struct { +typedef struct JournalEntryTitle { u32 year : 7; u32 month : 4; u32 week : 3; @@ -117,7 +117,7 @@ typedef struct { u32 mapID : 13; } JournalEntryTitle; -typedef struct { +typedef struct JournalEntryLocationEvent { u8 eventType; u8 padding_01; u16 locationID; // can be a mapID, a mapLabelTextID, or an index refering to a gym @@ -125,7 +125,7 @@ typedef struct { u16 item; } JournalEntryLocationEvent; -typedef struct { +typedef struct JournalEntryMon { u8 battleResult; u8 stringVariant : 2; u8 timeOfDay : 4; @@ -133,13 +133,13 @@ typedef struct { u16 species; } JournalEntryMon; -typedef struct { +typedef struct JournalEntryTrainer { u16 standard : 1; u16 trainerID : 15; u16 mapID; } JournalEntryTrainer; -typedef struct { +typedef struct JournalEntryOnlineEvent { u8 eventType; u8 result : 4; // can be a battle result, the placement in a contest, or an index refering to a plaza minigame u8 unused1 : 1; @@ -150,7 +150,7 @@ typedef struct { u16 pokemonName[12]; } JournalEntryOnlineEvent; -typedef struct { +typedef struct JournalEntry { JournalEntryTitle title; u32 locationEvents[MAX_JOURNAL_LOCATION_EVENTS]; JournalEntryMon mon; @@ -187,8 +187,8 @@ void *JournalEntry_CreateEventUsedMove(u8 moveIndex, u16 mapID, u32 heapID); void *JournalEntry_CreateEventDugUnderground(u32 heapID); void *JournalEntry_CreateEventBuiltSecretBase(u32 heapID); void *JournalEntry_CreateEventBattleFacility(u32 heapID, u32 eventType); -void *JournalEntry_CreateMonCaught(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID); -void *JournalEntry_CreateMonDefeated(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID); +void *JournalEntry_CreateEventMonCaught(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID); +void *JournalEntry_CreateEventMonDefeated(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID); void *JournalEntry_CreateEventStandardTrainer(u16 mapID, u16 trainerID, u32 heapID); void *JournalEntry_CreateEventSingleBattle(u16 *opponentName, u8 opponentGender, u8 battleResult, u32 heapID); void *JournalEntry_CreateEventDoubleBattle(u16 *opponentName, u8 opponentGender, u8 battleResult, u32 heapID); diff --git a/src/encounter.c b/src/encounter.c index 3c841e3117..a69f082a1f 100644 --- a/src/encounter.c +++ b/src/encounter.c @@ -954,13 +954,13 @@ static void UpdateJournal(FieldSystem *fieldSystem, FieldBattleDTO *dto) if (fieldSystem->unk_78.unk_02 >= 5) { caughtMon = Party_GetPokemonBySlotIndex(dto->parties[1], 0); - journalEntryMon = JournalEntry_CreateMonDefeated(SaveData_GetPlayTime(fieldSystem->saveData), Pokemon_GetValue(caughtMon, MON_DATA_SPECIES, 0), Pokemon_GetValue(caughtMon, MON_DATA_GENDER, 0), dto->timeOfDay, HEAP_ID_FIELDMAP); + journalEntryMon = JournalEntry_CreateEventMonDefeated(SaveData_GetPlayTime(fieldSystem->saveData), Pokemon_GetValue(caughtMon, MON_DATA_SPECIES, 0), Pokemon_GetValue(caughtMon, MON_DATA_GENDER, 0), dto->timeOfDay, HEAP_ID_FIELDMAP); JournalEntry_SaveData(fieldSystem->journalEntry, journalEntryMon, JOURNAL_MON); } } else if (resultMask == BATTLE_RESULT_CAPTURED_MON) { int caughtBattlerIdx = dto->caughtBattlerIdx; caughtMon = Party_GetPokemonBySlotIndex(dto->parties[caughtBattlerIdx], 0); - journalEntryMon = JournalEntry_CreateMonCaught(SaveData_GetPlayTime(fieldSystem->saveData), Pokemon_GetValue(caughtMon, MON_DATA_SPECIES, 0), Pokemon_GetValue(caughtMon, MON_DATA_GENDER, 0), dto->timeOfDay, HEAP_ID_FIELDMAP); + journalEntryMon = JournalEntry_CreateEventMonCaught(SaveData_GetPlayTime(fieldSystem->saveData), Pokemon_GetValue(caughtMon, MON_DATA_SPECIES, 0), Pokemon_GetValue(caughtMon, MON_DATA_GENDER, 0), dto->timeOfDay, HEAP_ID_FIELDMAP); JournalEntry_SaveData(fieldSystem->journalEntry, journalEntryMon, JOURNAL_MON); } diff --git a/src/journal.c b/src/journal.c index 376b92a72a..04e3d062ef 100644 --- a/src/journal.c +++ b/src/journal.c @@ -780,7 +780,7 @@ static JournalEntryMon *JournalEntry_CreateMon(u32 heapID) return journalEntryMon; } -void *JournalEntry_CreateMonCaught(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID) +void *JournalEntry_CreateEventMonCaught(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID) { JournalEntryMon *journalEntryMon = JournalEntry_CreateMon(heapID); u8 v1; @@ -796,14 +796,14 @@ void *JournalEntry_CreateMonCaught(const PlayTime *playTime, u16 species, u8 gen journalEntryMon->stringVariant = 0; } else if (v1 == 1 || v1 == 3) { journalEntryMon->stringVariant = 1; - } else { // v1 == 5 + } else { journalEntryMon->stringVariant = 2; } return journalEntryMon; } -void *JournalEntry_CreateMonDefeated(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID) +void *JournalEntry_CreateEventMonDefeated(const PlayTime *playTime, u16 species, u8 gender, u8 timeOfDay, u32 heapID) { JournalEntryMon *journalEntryMon = JournalEntry_CreateMon(heapID); u8 v1; @@ -819,7 +819,7 @@ void *JournalEntry_CreateMonDefeated(const PlayTime *playTime, u16 species, u8 g journalEntryMon->stringVariant = 0; } else if (v1 == 2 || v1 == 4) { journalEntryMon->stringVariant = 1; - } else { // v1 == 0 + } else { journalEntryMon->stringVariant = 2; } diff --git a/src/journal_display/journal_controller.c b/src/journal_display/journal_controller.c index 7730b3bcab..e2012ec49c 100644 --- a/src/journal_display/journal_controller.c +++ b/src/journal_display/journal_controller.c @@ -79,19 +79,19 @@ int JournalController_Init(OverlayManager *ovyManager, int *state) G2S_BlendNone(); SetAutorepeat(4, 8); - Heap_Create(3, 42, 0x20000); + Heap_Create(HEAP_ID_APPLICATION, HEAP_ID_JOURNAL, 0x20000); v1 = OverlayManager_Args(ovyManager); - v0 = OverlayManager_NewData(ovyManager, sizeof(UnkStruct_ov81_021D1610), 42); + v0 = OverlayManager_NewData(ovyManager, sizeof(UnkStruct_ov81_021D1610), HEAP_ID_JOURNAL); memset(v0, 0, sizeof(UnkStruct_ov81_021D1610)); - v0->bgConfig = BgConfig_New(42); + v0->bgConfig = BgConfig_New(HEAP_ID_JOURNAL); v0->saveData = v1; v0->journalEntry = SaveData_GetJournal(v1); v0->trainerInfo = SaveData_GetTrainerInfo(v1); - sub_0208C120(0, 42); - Font_UseImmediateGlyphAccess(FONT_SYSTEM, 42); + sub_0208C120(0, HEAP_ID_JOURNAL); + Font_UseImmediateGlyphAccess(FONT_SYSTEM, HEAP_ID_JOURNAL); JournalController_SetVRAMBanks(); JournalController_SetupBgs(v0->bgConfig); @@ -107,7 +107,7 @@ int JournalController_Init(OverlayManager *ovyManager, int *state) GXLayers_EngineAToggleLayers(GX_PLANEMASK_OBJ, 1); sub_02004550(67, 0, 0); - return 1; + return TRUE; } int JournalController_Main(OverlayManager *ovyManager, int *state) @@ -129,11 +129,11 @@ int JournalController_Main(OverlayManager *ovyManager, int *state) break; case JOURNAL_STATE_CLOSE: if (JournalController_IsClosingTransitionDone(v0) == 1) { - return 1; + return TRUE; } } - return 0; + return FALSE; } int JournalController_Exit(OverlayManager *ovyManager, int *state) @@ -148,9 +148,9 @@ int JournalController_Exit(OverlayManager *ovyManager, int *state) Font_UseLazyGlyphAccess(FONT_SYSTEM); OverlayManager_FreeData(ovyManager); - Heap_Destroy(42); + Heap_Destroy(HEAP_ID_JOURNAL); - return 1; + return TRUE; } static void JournalController_MainCallback(void *data) @@ -264,8 +264,8 @@ static void JournalController_SetupBgs(BgConfig *bgConfig) Bg_InitFromTemplate(bgConfig, 3, &v4, 0); - Bg_ClearTilesRange(0, 32, 0, 42); - Bg_ClearTilesRange(1, 32, 0, 42); + Bg_ClearTilesRange(0, 32, 0, HEAP_ID_JOURNAL); + Bg_ClearTilesRange(1, 32, 0, HEAP_ID_JOURNAL); } static void JournalController_TeardownBgs(BgConfig *bgConfig) @@ -281,16 +281,16 @@ static void JournalController_TeardownBgs(BgConfig *bgConfig) static void ov81_021D1050(UnkStruct_ov81_021D1610 *param0) { u16 *v0; - NARC *v1 = NARC_ctor(NARC_INDEX_GRAPHIC__F_NOTE_GRA, 42); + NARC *v1 = NARC_ctor(NARC_INDEX_GRAPHIC__F_NOTE_GRA, HEAP_ID_JOURNAL); if (TrainerInfo_Gender(param0->trainerInfo) == 0) { - Graphics_LoadTilesToBgLayerFromOpenNARC(v1, 2, param0->bgConfig, 2, 0, 0, 0, 42); - Graphics_LoadTilemapToBgLayerFromOpenNARC(v1, 0, param0->bgConfig, 2, 0, 0, 0, 42); - Graphics_LoadPaletteFromOpenNARC(v1, 4, 0, 0, 0, 42); + Graphics_LoadTilesToBgLayerFromOpenNARC(v1, 2, param0->bgConfig, 2, 0, 0, 0, HEAP_ID_JOURNAL); + Graphics_LoadTilemapToBgLayerFromOpenNARC(v1, 0, param0->bgConfig, 2, 0, 0, 0, HEAP_ID_JOURNAL); + Graphics_LoadPaletteFromOpenNARC(v1, 4, 0, 0, 0, HEAP_ID_JOURNAL); } else { - Graphics_LoadTilesToBgLayerFromOpenNARC(v1, 3, param0->bgConfig, 2, 0, 0, 0, 42); - Graphics_LoadTilemapToBgLayerFromOpenNARC(v1, 1, param0->bgConfig, 2, 0, 0, 0, 42); - Graphics_LoadPaletteFromOpenNARC(v1, 5, 0, 0, 0, 42); + Graphics_LoadTilesToBgLayerFromOpenNARC(v1, 3, param0->bgConfig, 2, 0, 0, 0, HEAP_ID_JOURNAL); + Graphics_LoadTilemapToBgLayerFromOpenNARC(v1, 1, param0->bgConfig, 2, 0, 0, 0, HEAP_ID_JOURNAL); + Graphics_LoadPaletteFromOpenNARC(v1, 5, 0, 0, 0, HEAP_ID_JOURNAL); } NARC_dtor(v1); @@ -299,15 +299,15 @@ static void ov81_021D1050(UnkStruct_ov81_021D1610 *param0) MI_CpuCopy16(v0, param0->unk_5C, 0x800); Bg_LoadTilemapBuffer(param0->bgConfig, 3, param0->unk_5C, 0x800); - Font_LoadTextPalette(0, 15 * 32, 42); + Font_LoadTextPalette(0, 15 * 32, HEAP_ID_JOURNAL); Bg_MaskPalette(4, 0); } static void ov81_021D1130(UnkStruct_ov81_021D1610 *param0) { - param0->loader = MessageLoader_Init(0, 26, 366, 42); - param0->template = StringTemplate_Default(42); - param0->strbuf = Strbuf_Init(128, 42); + param0->loader = MessageLoader_Init(0, 26, 366, HEAP_ID_JOURNAL); + param0->template = StringTemplate_Default(HEAP_ID_JOURNAL); + param0->strbuf = Strbuf_Init(128, HEAP_ID_JOURNAL); } static void ov81_021D115C(UnkStruct_ov81_021D1610 *param0) @@ -350,13 +350,13 @@ static int JournalController_HandleInput(UnkStruct_ov81_021D1610 *param0) return JOURNAL_STATE_TURN_LEFT; } } else { - sub_0208C120(1, 42); + sub_0208C120(1, HEAP_ID_JOURNAL); return JOURNAL_STATE_CLOSE; } } if (gCoreSys.pressedKeys & PAD_BUTTON_START) { - sub_0208C120(1, 42); + sub_0208C120(1, HEAP_ID_JOURNAL); return JOURNAL_STATE_CLOSE; } @@ -442,23 +442,23 @@ static u8 JournalController_PageExists(UnkStruct_ov81_021D1610 *param0, u8 param JournalEntry_GetData(param0->journalEntry, &journalEntryTitle, JOURNAL_TITLE, param1); if (journalEntryTitle.year == 0 && journalEntryTitle.month == 0 && journalEntryTitle.day == 0) { - return 0; + return FALSE; } - return 1; + return TRUE; } static u8 JournalController_NewDirectionPageExists(UnkStruct_ov81_021D1610 *param0, s8 pageChange) { if (pageChange == 1) { if (param0->page != 9 && JournalController_PageExists(param0, param0->page + 1) == 1) { - return 1; + return TRUE; } } else if (param0->page != 0 && JournalController_PageExists(param0, param0->page - 1) == 1) { - return 1; + return TRUE; } - return 0; + return FALSE; } static void ov81_021D140C(UnkStruct_ov81_021D1610 *param0, u8 bgLayer, u8 palette) @@ -505,10 +505,10 @@ static u8 ov81_021D14E0(UnkStruct_ov81_021D1610 *param0) Bg_SetPriority(param0->bgLayer3, 1); Bg_SetPriority(param0->bgLayer2, 2); Bg_SetPriority(param0->bgLayer1, 3); - return 1; + return TRUE; } - return 0; + return FALSE; } static u8 ov81_021D156C(UnkStruct_ov81_021D1610 *param0) @@ -527,8 +527,8 @@ static u8 ov81_021D156C(UnkStruct_ov81_021D1610 *param0) param0->unk_105F++; if (param0->unk_105F == 9) { - return 1; + return TRUE; } - return 0; + return FALSE; }