Get/SetMonData optimisation (#7313)

This commit is contained in:
Nephrite 2025-07-28 13:42:28 +03:00 committed by GitHub
parent b12fcd8c7e
commit 7c6cff1fb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 326 additions and 306 deletions

View File

@ -26,6 +26,7 @@
#define ALIGNED(n) __attribute__((aligned(n)))
#define PACKED __attribute__((packed))
#define TRANSPARENT __attribute__ ((__transparent_union__))
#define ALWAYS_INLINE inline __attribute__((always_inline))
#define NONNULL __attribute__((__nonnull__))
#define SOUND_INFO_PTR (*(struct SoundInfo **)0x3007FF0)

View File

@ -16,7 +16,7 @@
#define FORM_SPECIES_END (0xffff)
// Property labels for Get(Box)MonData / Set(Box)MonData
enum {
enum MonData {
MON_DATA_PERSONALITY,
MON_DATA_STATUS,
MON_DATA_OT_ID,
@ -232,6 +232,14 @@ struct PokemonSubstruct3
max(sizeof(struct PokemonSubstruct2), \
sizeof(struct PokemonSubstruct3)))))
enum SubstructType
{
SUBSTRUCT_TYPE_0,
SUBSTRUCT_TYPE_1,
SUBSTRUCT_TYPE_2,
SUBSTRUCT_TYPE_3,
};
union PokemonSubstruct
{
struct PokemonSubstruct0 type0;

File diff suppressed because it is too large Load Diff

View File

@ -450,3 +450,28 @@ TEST("Pokémon level up learnsets fit within MAX_LEVEL_UP_MOVES and MAX_RELEARNE
EXPECT_LT(count, MAX_LEVEL_UP_MOVES);
EXPECT_LT(count, MAX_RELEARNER_MOVES - 1); // - 1 because at least one move is already known
}
TEST("Optimised GetMonData")
{
CreateMon(&gPlayerParty[0], SPECIES_WOBBUFFET, 5, 0, FALSE, 0, OT_ID_PRESET, 0x12345678);
u32 exp = 0x123456;
SetMonData(&gPlayerParty[0], MON_DATA_EXP, &exp);
struct Benchmark optimised,
vanilla = (struct Benchmark) { .ticks = 137 }; // From prior testing
u32 expGet = 0;
BENCHMARK(&optimised) { expGet = GetMonData(&gPlayerParty[0], MON_DATA_EXP); }
EXPECT_EQ(exp, expGet);
EXPECT_FASTER(optimised, vanilla);
}
TEST("Optimised SetMonData")
{
CreateMon(&gPlayerParty[0], SPECIES_WOBBUFFET, 5, 0, FALSE, 0, OT_ID_PRESET, 0x12345678);
u32 exp = 0x123456;
struct Benchmark optimised,
vanilla = (struct Benchmark) { .ticks = 205 }; // From prior testing
BENCHMARK(&optimised) { SetMonData(&gPlayerParty[0], MON_DATA_EXP, &exp); }
EXPECT_EQ(GetMonData(&gPlayerParty[0], MON_DATA_SANITY_IS_BAD_EGG), FALSE);
EXPECT_EQ(GetMonData(&gPlayerParty[0], MON_DATA_EXP), exp);
EXPECT_FASTER(optimised, vanilla);
}