Skip to content

Commit

Permalink
Merge pull request #309 from lhearachel/math
Browse files Browse the repository at this point in the history
Document math.c
  • Loading branch information
lhearachel authored Nov 22, 2024
2 parents 63e7e00 + 5cb7907 commit 13fe3e1
Show file tree
Hide file tree
Showing 140 changed files with 651 additions and 649 deletions.
4 changes: 1 addition & 3 deletions include/inlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
#include "heap.h"
#include "location.h"
#include "map_header.h"
#include "math.h"
#include "narc.h"
#include "palette.h"
#include "script_manager.h"
#include "sys_task.h"
#include "sys_task_manager.h"
#include "system_flags.h"
#include "unk_0201D15C.h"
#include "vars_flags.h"

static inline void inline_ov61_0222C3B0_sub_1(UnkStruct_ov61_0222C3B0 *);
static inline void inline_ov61_0222C3B0_sub(SysTask *, void *);
Expand Down
41 changes: 41 additions & 0 deletions include/math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef POKEPLATINUM_MATH_H
#define POKEPLATINUM_MATH_H

#include <nitro/fx/fx.h>

#include "constants/heap.h"

enum AffineTransformationMatrixMode {
AFFINE_MODE_NORMAL = 0,
AFFINE_MODE_MAX_256,
AFFINE_MODE_MAX_360,
};

fx32 CalcSineDegrees(u16 degrees);
fx32 CalcCosineDegrees(u16 degrees);
fx32 CalcSineDegrees_Wraparound(u16 degrees);
fx32 CalcCosineDegrees_Wraparound(u16 degrees);
u16 CalcAngleRotationIdx(u16 degrees);
u16 CalcAngleRotationIdx_Wraparound(u16 degrees);
fx32 CalcSineDegrees_FX32(fx32 degrees);
fx32 CalcCosineDegrees_FX32(fx32 degrees);

u32 LCRNG_GetSeed(void);
void LCRNG_SetSeed(u32 seed);
u16 LCRNG_Next(void);
u32 ARNG_Next(u32 seed);
void MTRNG_SetSeed(u32 seed);
u32 MTRNG_Next(void);

void CreateAffineTransformationMatrix(MtxFx22 *matrix, u16 degrees, fx32 xScale, fx32 yScale, u8 mode);

s32 CalcDotProduct2D(s32 x0, s32 y0, s32 x1, s32 y1, u32 unused);
s32 CalcRadialAngle(u16 radius, s32 distance);

u32 SumBytes(const void *data, u32 size);
void EncodeData(void *data, u32 size, u32 seed);
void DecodeData(void *data, u32 size, u32 seed);
u16 CalcCRC16Checksum(const void *data, u32 dataLen);
void InitCRC16Table(enum HeapId heapID);

#endif // POKEPLATINUM_MATH_H
29 changes: 0 additions & 29 deletions include/unk_0201D15C.h

This file was deleted.

2 changes: 1 addition & 1 deletion platinum.us/main.lsf
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Static main
Object main.nef.p/src_sys_task_manager.c.o
Object main.nef.p/src_unk_0201CED8.c.o
Object main.nef.p/src_charcode.c.o
Object main.nef.p/src_unk_0201D15C.c.o
Object main.nef.p/src_math.c.o
Object main.nef.p/src_text.c.o
Object main.nef.p/src_unk_0201DBEC.c.o
Object main.nef.p/src_unk_0201DD00.c.o
Expand Down
4 changes: 2 additions & 2 deletions src/battle/healthbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "bg_window.h"
#include "cell_actor.h"
#include "heap.h"
#include "math.h"
#include "message.h"
#include "narc.h"
#include "palette.h"
Expand All @@ -30,7 +31,6 @@
#include "text.h"
#include "unk_0200C440.h"
#include "unk_0200C6E4.h"
#include "unk_0201D15C.h"
#include "unk_0208C098.h"

#define HEALTHBAR_SCROLL_SPEED 24
Expand Down Expand Up @@ -1855,6 +1855,6 @@ static void ov16_022684BC(SysTask *param0, void *param1)
v0->unk_54 -= 360;
}

v1 = FX_Mul(sub_0201D15C(v0->unk_54), 0x1800) / FX32_ONE;
v1 = FX_Mul(CalcSineDegrees(v0->unk_54), 0x1800) / FX32_ONE;
Healthbar_OffsetPositionXY(v0, 0, v1);
}
2 changes: 1 addition & 1 deletion src/battle/ov16_0223B140.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "gx_layers.h"
#include "hardware_palette.h"
#include "heap.h"
#include "math.h"
#include "message.h"
#include "narc.h"
#include "overlay_manager.h"
Expand All @@ -75,7 +76,6 @@
#include "unk_0201567C.h"
#include "unk_02015F84.h"
#include "unk_02017728.h"
#include "unk_0201D15C.h"
#include "unk_0201DBEC.h"
#include "unk_0201E3D8.h"
#include "unk_0202419C.h"
Expand Down
4 changes: 2 additions & 2 deletions src/battle/ov16_02264798.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include "battle/struct_ov16_0225BFFC_decl.h"
#include "battle/struct_ov16_0225BFFC_t.h"

#include "math.h"
#include "sys_task.h"
#include "sys_task_manager.h"
#include "unk_0200762C.h"
#include "unk_0201D15C.h"

static void ov16_02264800(SysTask *param0, void *param1);

Expand Down Expand Up @@ -55,6 +55,6 @@ static void ov16_02264800(SysTask *param0, void *param1)
v0->unk_198 -= 360;
}

v1 = FX_Mul(sub_0201D15C(v0->unk_198), 0x1800) / FX32_ONE;
v1 = FX_Mul(CalcSineDegrees(v0->unk_198), 0x1800) / FX32_ONE;
sub_02007DEC(v0->unk_20, 4, v1);
}
2 changes: 1 addition & 1 deletion src/battle/ov16_0226871C.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "graphics.h"
#include "heap.h"
#include "inlines.h"
#include "math.h"
#include "message.h"
#include "message_util.h"
#include "move_table.h"
Expand All @@ -56,7 +57,6 @@
#include "unk_0200C6E4.h"
#include "unk_02012744.h"
#include "unk_02017728.h"
#include "unk_0201D15C.h"
#include "unk_0201E86C.h"
#include "unk_0207C908.h"
#include "unk_0208C098.h"
Expand Down
4 changes: 2 additions & 2 deletions src/battle/ov16_0226DE44.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#include "struct_defs/struct_0200D0F4.h"

#include "heap.h"
#include "math.h"
#include "narc.h"
#include "palette.h"
#include "sys_task.h"
#include "sys_task_manager.h"
#include "unk_0200C6E4.h"
#include "unk_0201D15C.h"

typedef struct UnkStruct_ov16_0226DEEC_t {
CellActorData *unk_00;
Expand Down Expand Up @@ -173,7 +173,7 @@ static void ov16_0226DFD8(SysTask *param0, void *param1)
}

if (v0->unk_1C == 0) {
v1 = FX_Mul(sub_0201D15C(v0->unk_10 / 100), 14 << FX32_SHIFT) / FX32_ONE;
v1 = FX_Mul(CalcSineDegrees(v0->unk_10 / 100), 14 << FX32_SHIFT) / FX32_ONE;
sub_0200D500(v0->unk_00, v0->unk_08, v0->unk_0C - v1, v0->unk_14);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/bg_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "gx_layers.h"
#include "heap.h"
#include "unk_0201D15C.h"
#include "math.h"

static u8 ConvertToGxBgScreenSize(u8 bgScreenSize, u8 bgType);
static void GetBgScreenTileDimensions(u8 bgScreenSize, u8 *outXTiles, u8 *outYTiles);
Expand Down Expand Up @@ -747,7 +747,7 @@ void Bg_SetAffineParams(BgConfig *bgConfig, u8 bgLayer, const MtxFx22 *mtx, int
static void ResetBgAffineTransforms(BgConfig *bgConfig, u8 bgLayer)
{
MtxFx22 mtx;
sub_0201D470(&mtx, 0, FX32_ONE, FX32_ONE, 0);
CreateAffineTransformationMatrix(&mtx, 0, FX32_ONE, FX32_ONE, AFFINE_MODE_NORMAL);
Bg_SetAffineParams(bgConfig, bgLayer, &mtx, 0, 0);
}

Expand Down Expand Up @@ -2460,7 +2460,7 @@ static void RunScheduledScrolls(BgConfig *bgConfig)
G2_SetBG2Offset(bgConfig->bgs[BG_LAYER_MAIN_2].xOffset, bgConfig->bgs[BG_LAYER_MAIN_2].yOffset);
} else {
MtxFx22 mtx;
sub_0201D470(&mtx, bgConfig->bgs[BG_LAYER_MAIN_2].rotation, bgConfig->bgs[BG_LAYER_MAIN_2].xScale, bgConfig->bgs[BG_LAYER_MAIN_2].yScale, 2);
CreateAffineTransformationMatrix(&mtx, bgConfig->bgs[BG_LAYER_MAIN_2].rotation, bgConfig->bgs[BG_LAYER_MAIN_2].xScale, bgConfig->bgs[BG_LAYER_MAIN_2].yScale, AFFINE_MODE_MAX_360);
G2_SetBG2Affine(&mtx, bgConfig->bgs[BG_LAYER_MAIN_2].xCenter, bgConfig->bgs[BG_LAYER_MAIN_2].yCenter, bgConfig->bgs[BG_LAYER_MAIN_2].xOffset, bgConfig->bgs[BG_LAYER_MAIN_2].yOffset);
}
}
Expand All @@ -2470,7 +2470,7 @@ static void RunScheduledScrolls(BgConfig *bgConfig)
G2_SetBG3Offset(bgConfig->bgs[BG_LAYER_MAIN_3].xOffset, bgConfig->bgs[BG_LAYER_MAIN_3].yOffset);
} else {
MtxFx22 mtx;
sub_0201D470(&mtx, bgConfig->bgs[BG_LAYER_MAIN_3].rotation, bgConfig->bgs[BG_LAYER_MAIN_3].xScale, bgConfig->bgs[BG_LAYER_MAIN_3].yScale, 2);
CreateAffineTransformationMatrix(&mtx, bgConfig->bgs[BG_LAYER_MAIN_3].rotation, bgConfig->bgs[BG_LAYER_MAIN_3].xScale, bgConfig->bgs[BG_LAYER_MAIN_3].yScale, AFFINE_MODE_MAX_360);
G2_SetBG3Affine(&mtx, bgConfig->bgs[BG_LAYER_MAIN_3].xCenter, bgConfig->bgs[BG_LAYER_MAIN_3].yCenter, bgConfig->bgs[BG_LAYER_MAIN_3].xOffset, bgConfig->bgs[BG_LAYER_MAIN_3].yOffset);
}
}
Expand All @@ -2488,7 +2488,7 @@ static void RunScheduledScrolls(BgConfig *bgConfig)
G2S_SetBG2Offset(bgConfig->bgs[BG_LAYER_SUB_2].xOffset, bgConfig->bgs[BG_LAYER_SUB_2].yOffset);
} else {
MtxFx22 mtx;
sub_0201D470(&mtx, bgConfig->bgs[BG_LAYER_SUB_2].rotation, bgConfig->bgs[BG_LAYER_SUB_2].xScale, bgConfig->bgs[BG_LAYER_SUB_2].yScale, 2);
CreateAffineTransformationMatrix(&mtx, bgConfig->bgs[BG_LAYER_SUB_2].rotation, bgConfig->bgs[BG_LAYER_SUB_2].xScale, bgConfig->bgs[BG_LAYER_SUB_2].yScale, AFFINE_MODE_MAX_360);
G2S_SetBG2Affine(&mtx, bgConfig->bgs[BG_LAYER_SUB_2].xCenter, bgConfig->bgs[BG_LAYER_SUB_2].yCenter, bgConfig->bgs[BG_LAYER_SUB_2].xOffset, bgConfig->bgs[BG_LAYER_SUB_2].yOffset);
}
}
Expand All @@ -2498,7 +2498,7 @@ static void RunScheduledScrolls(BgConfig *bgConfig)
G2S_SetBG3Offset(bgConfig->bgs[BG_LAYER_SUB_3].xOffset, bgConfig->bgs[BG_LAYER_SUB_3].yOffset);
} else {
MtxFx22 mtx;
sub_0201D470(&mtx, bgConfig->bgs[BG_LAYER_SUB_3].rotation, bgConfig->bgs[BG_LAYER_SUB_3].xScale, bgConfig->bgs[BG_LAYER_SUB_3].yScale, 2);
CreateAffineTransformationMatrix(&mtx, bgConfig->bgs[BG_LAYER_SUB_3].rotation, bgConfig->bgs[BG_LAYER_SUB_3].xScale, bgConfig->bgs[BG_LAYER_SUB_3].yScale, AFFINE_MODE_MAX_360);
G2S_SetBG3Affine(&mtx, bgConfig->bgs[BG_LAYER_SUB_3].xCenter, bgConfig->bgs[BG_LAYER_SUB_3].yCenter, bgConfig->bgs[BG_LAYER_SUB_3].xOffset, bgConfig->bgs[BG_LAYER_SUB_3].yOffset);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game_records.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <nitro.h>

#include "game_records.h"
#include "unk_0201D15C.h"
#include "math.h"
#include "unk_0202631C.h"

#define START_ENCODED_RECORDS RECORD_TRAINER_SCORE
Expand Down
2 changes: 1 addition & 1 deletion src/game_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "heap.h"
#include "location.h"
#include "main.h"
#include "math.h"
#include "overlay_manager.h"
#include "party.h"
#include "pokemon.h"
Expand All @@ -19,7 +20,6 @@
#include "system_flags.h"
#include "trainer_info.h"
#include "unk_02017428.h"
#include "unk_0201D15C.h"
#include "unk_0205C980.h"
#include "unk_0206B9D8.h"
#include "vars_flags.h"
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "game_overlay.h"
#include "game_start.h"
#include "main.h"
#include "math.h"
#include "overlay_manager.h"
#include "rtc.h"
#include "save_player.h"
Expand All @@ -26,7 +27,6 @@
#include "unk_0200F174.h"
#include "unk_02017428.h"
#include "unk_02017728.h"
#include "unk_0201D15C.h"
#include "unk_0201E3D8.h"
#include "unk_02022844.h"
#include "unk_0202419C.h"
Expand Down
Loading

0 comments on commit 13fe3e1

Please sign in to comment.