From 4ad11af5353f2dea65d748ab5e67acc9b694a017 Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Tue, 18 Jul 2023 18:07:58 +0900 Subject: [PATCH] mapfs shape data (#1087) * script * fix prologue printing * added type hints for return types * model docs * more models * pretty print for sprite xmls on earlier python ver * 1x oops * sprite xml labels * cod cleanup * type cleanup * fixes, script erroring * script fixes * objcopy * link, objcopy, etc * map_shape.ld * discard * kpa_117 match * move stuff into /geom * fix some shapes * 253 * 221 * opaque lights * 488 * all clear * fixies * RDP_MATRIX macro * more explicit property 5F --------- Co-authored-by: HailSanta --- .gitignore | 1 + include/common_structs.h | 2 +- include/enums.h | 253 +++--- include/functions.h | 8 +- include/macros.h | 39 + include/model.h | 59 +- src/17D6A0.c | 2 +- src/8800.c | 2 +- src/B4580.c | 6 +- src/audio/e0b30_len_b80.c | 2 +- .../area/trd_part_2/actor/fake_bowser.c | 58 +- src/battle/common/stage/area_omo/omo_01.inc.c | 6 +- src/collision.c | 16 +- src/common/FoliageTransform.inc.c | 16 +- src/draw_box.c | 26 +- src/entity/Chest.c | 4 +- src/entity/model/ArrowSign.c | 18 +- src/entity/model/BlueSwitch.c | 36 +- src/entity/model/BlueWarpPipe.c | 18 +- src/entity/model/Chest.c | 18 +- src/entity/model/CymbalPlant_gfx.c | 52 +- src/entity/model/GreenStompSwitch.c | 18 +- src/entity/model/Padlock.c | 18 +- src/entity/model/PadlockBlueFace.c | 18 +- src/entity/model/PadlockRedFace.c | 18 +- src/entity/model/PadlockRedFrame.c | 18 +- src/entity/model/PinkFlower_gfx.c | 18 +- src/entity/model/PowBlock.c | 18 +- src/entity/model/PushBlock.c | 18 +- src/entity/model/RedSwitch.c | 37 +- src/entity/model/SaveBlock.c | 18 +- src/entity/model/SpinningFlower.c | 18 +- src/entity/model/StarBoxLauncher.c | 18 +- src/entity/model/SuperBlock.c | 18 +- src/entity/model/Tweester.c | 36 +- src/entity/model/UltraBlock.c | 18 +- src/entity/model/UnusedBlock.c | 18 +- src/evt/map_api.c | 83 +- src/imgfx.c | 22 +- src/main_loop.c | 22 +- src/map_shape.ld | 14 + src/model.c | 799 ++++++++++-------- src/npc.c | 16 +- src/state_battle.c | 2 +- src/state_file_select.c | 2 +- src/state_pause.c | 2 +- .../area_end/end_01/end_01_4_opera_float.c | 6 +- src/world/area_flo/flo_14/flo_14_3_bubbles.c | 4 +- src/world/area_hos/hos_03/hos_03_3_model_fx.c | 2 +- src/world/area_jan/common/MoveBush.inc.c | 8 +- src/world/area_jan/jan_00/jan_00_4_whale.c | 4 +- src/world/area_kgr/kgr_01/kgr_01_2_wiggle.c | 2 +- src/world/area_kkj/common/Searchlights.inc.c | 6 +- src/world/area_kmr/kmr_02/kmr_02_3_npc.c | 2 +- .../area_kmr/kmr_20/kmr_20_11_npc_intro.c | 2 +- .../area_kmr/kmr_20/kmr_20_12_npc_epilogue.c | 2 +- src/world/area_kmr/kmr_30/kmr_30_3_the_end.c | 2 +- .../area_mac/mac_00/mac_00_9_water_gfx.c | 2 +- .../area_mac/mac_00/npc/dojo_members.inc.c | 2 +- .../mac_01/mac_01_6_crystal_ball_gfx.c | 2 +- src/world/area_mac/mac_01/mac_01_9_npc.c | 4 +- .../area_mac/mac_01/npc/rowf_and_rhuff.inc.c | 10 +- src/world/area_mac/mac_02/mac_02_3_rooms.c | 2 +- src/world/area_mac/mac_04/mac_04_3_rooms.c | 2 +- src/world/area_mac/mac_05/mac_05_5_whale.c | 4 +- .../area_mac/mac_05/mac_05_7_club64_sign.c | 2 +- src/world/area_mac/mac_06/mac_06_2_whale.c | 4 +- src/world/area_mac/mac_06/mac_06_3_npc.c | 8 +- src/world/area_mgm/mgm_02/mgm_02_2_npc.c | 24 +- src/world/area_mim/mim_04/mim_04_4_hint.c | 2 +- src/world/area_mim/mim_07/mim_07_4_hint.c | 2 +- src/world/area_nok/nok_04/nok_04_4_npc.c | 2 +- src/world/area_obk/common/RockingChair.inc.c | 18 +- .../area_obk/obk_01/obk_01_3_chandelier.c | 16 +- src/world/area_omo/common/RockingHorse.inc.c | 6 +- .../area_omo/omo_02/omo_02_5_barricade.c | 8 +- src/world/area_omo/omo_11/omo_11_3_gizmos.c | 20 +- src/world/area_sam/sam_06/sam_06_4_npc.c | 4 +- .../area_sam/sam_07/sam_07_4_frozen_pit.c | 8 +- .../area_tst/tst_04/tst_04_3_reflection.c | 2 +- src/world/area_tst/tst_13/tst_13_1_main.c | 2 +- src/world/common/atomic/UnkFunc27.inc.c | 2 +- .../dead/area_flo/flo_14/flo_14_3_bubbles.c | 4 +- src/world/script_api/rooms.c | 4 +- src/world/script_api/shops.c | 15 +- tools/build/configure.py | 108 ++- tools/build/mapfs/shape.py | 715 ++++++++++++++++ tools/compare_shapes.py | 28 + tools/splat_ext/pm_map_data.py | 14 +- tools/splat_ext/pm_sprites.py | 54 +- tools/splat_ext/sprite_common.py | 166 +++- ver/ique/asm/bss3.s | 18 +- ver/jp/symbol_addrs.txt | 4 +- ver/jp/undefined_syms.txt | 78 +- ver/us/asm/bss3.s | 18 +- ver/us/symbol_addrs.txt | 36 +- 96 files changed, 2116 insertions(+), 1273 deletions(-) create mode 100644 src/map_shape.ld create mode 100755 tools/build/mapfs/shape.py create mode 100755 tools/compare_shapes.py diff --git a/.gitignore b/.gitignore index c4cb503b00..71107f1c99 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ ctx.c.m2c build.ninja .ninja* *.ld +!src/map_shape.ld *.elf *.z64 *.v64 diff --git a/include/common_structs.h b/include/common_structs.h index 90c72c7e9a..e8dba3950e 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -264,7 +264,7 @@ typedef struct Npc { /* 0x0AA */ s8 renderMode; /* 0x0AB */ s8 verticalRenderOffset; /* 0x0AC */ u8 alpha; - /* 0x0AD */ u8 alpha2; ///< Multiplied with Npc::alpha + /* 0x0AD */ u8 hideAlpha; ///< Used when hiding NPCs; Multiplied with Npc::alpha /* 0x0AE */ char unk_AE[2]; /* 0x0B0 */ AnimID* extraAnimList; /* 0x0B4 */ s8 palSwapType; // 0..4 inclusive diff --git a/include/enums.h b/include/enums.h index 2c52c4466b..77319f88b1 100644 --- a/include/enums.h +++ b/include/enums.h @@ -3538,6 +3538,71 @@ enum WindowPriority { WINDOW_PRIORITY_64 = 64, }; +enum RenderModeIndex { + RENDER_MODE_IDX_00 = 0x00, + RENDER_MODE_IDX_01 = 0x01, + RENDER_MODE_IDX_02 = 0x02, + RENDER_MODE_IDX_03 = 0x03, + RENDER_MODE_IDX_04 = 0x04, + RENDER_MODE_IDX_05 = 0x05, + RENDER_MODE_IDX_06 = 0x06, + RENDER_MODE_IDX_07 = 0x07, + RENDER_MODE_IDX_08 = 0x08, + RENDER_MODE_IDX_09 = 0x09, + RENDER_MODE_IDX_0A = 0x0A, + RENDER_MODE_IDX_0B = 0x0B, + RENDER_MODE_IDX_0C = 0x0C, + RENDER_MODE_IDX_0D = 0x0D, + RENDER_MODE_IDX_0E = 0x0E, + RENDER_MODE_IDX_0F = 0x0F, + RENDER_MODE_IDX_10 = 0x10, + RENDER_MODE_IDX_11 = 0x11, + RENDER_MODE_IDX_12 = 0x12, + RENDER_MODE_IDX_13 = 0x13, + RENDER_MODE_IDX_14 = 0x14, + RENDER_MODE_IDX_15 = 0x15, + RENDER_MODE_IDX_16 = 0x16, + RENDER_MODE_IDX_17 = 0x17, + RENDER_MODE_IDX_18 = 0x18, + RENDER_MODE_IDX_19 = 0x19, + RENDER_MODE_IDX_1A = 0x1A, + RENDER_MODE_IDX_1B = 0x1B, + RENDER_MODE_IDX_1C = 0x1C, + RENDER_MODE_IDX_1D = 0x1D, + RENDER_MODE_IDX_1E = 0x1E, + RENDER_MODE_IDX_1F = 0x1F, + RENDER_MODE_IDX_20 = 0x20, + RENDER_MODE_IDX_21 = 0x21, + RENDER_MODE_IDX_22 = 0x22, + RENDER_MODE_IDX_23 = 0x23, + RENDER_MODE_IDX_24 = 0x24, + RENDER_MODE_IDX_25 = 0x25, + RENDER_MODE_IDX_26 = 0x26, + RENDER_MODE_IDX_27 = 0x27, + RENDER_MODE_IDX_28 = 0x28, + RENDER_MODE_IDX_29 = 0x29, + RENDER_MODE_IDX_2A = 0x2A, + RENDER_MODE_IDX_2B = 0x2B, + RENDER_MODE_IDX_2C = 0x2C, + RENDER_MODE_IDX_2D = 0x2D, + RENDER_MODE_IDX_2E = 0x2E, + RENDER_MODE_IDX_2F = 0x2F, + RENDER_MODE_IDX_30 = 0x30, + RENDER_MODE_IDX_31 = 0x31, + RENDER_MODE_IDX_32 = 0x32, + RENDER_MODE_IDX_33 = 0x33, + RENDER_MODE_IDX_34 = 0x34, + RENDER_MODE_IDX_35 = 0x35, + RENDER_MODE_IDX_36 = 0x36, + RENDER_MODE_IDX_37 = 0x37, + RENDER_MODE_IDX_38 = 0x38, + RENDER_MODE_IDX_39 = 0x39, + RENDER_MODE_IDX_3A = 0x3A, + RENDER_MODE_IDX_3B = 0x3B, + RENDER_MODE_IDX_3C = 0x3C, + RENDER_MODE_IDX_3D = 0x3D, +}; + /// not really enum RenderMode { RENDER_MODE_SURF_SOLID_AA_ZB_LAYER0 = 0x00000000, @@ -4786,25 +4851,37 @@ enum GlobalOverrides { GLOBAL_OVERRIDES_CANT_PICK_UP_ITEMS = 0x00200000, }; -#define MODEL_FLAGS_MASK_FFF0 (MODEL_FLAG_USES_CUSTOM_GFX | MODEL_FLAG_FLAG_20 | MODEL_FLAG_FLAG_40 | MODEL_FLAG_HAS_LOCAL_VERTEX_COPY | MODEL_FLAG_USE_CAMERA_UNK_MATRIX | MODEL_FLAG_FLAG_200 | MODEL_FLAG_HAS_TRANSFORM_APPLIED | MODEL_FLAG_HAS_TEX_PANNER | MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_FLAG_2000 | MODEL_FLAG_FLAG_4000 | MODEL_FLAG_FLAG_8000) +#define MODEL_FLAGS_MASK_FFF0 (\ + MODEL_FLAG_USES_CUSTOM_GFX \ + | MODEL_FLAG_20 \ + | MODEL_FLAG_40 \ + | MODEL_FLAG_HAS_LOCAL_VERTEX_COPY \ + | MODEL_FLAG_USE_CAMERA_UNK_MATRIX \ + | MODEL_FLAG_DO_BOUNDS_CULLING \ + | MODEL_FLAG_HAS_TRANSFORM \ + | MODEL_FLAG_HAS_TEX_PANNER \ + | MODEL_FLAG_MATRIX_DIRTY \ + | MODEL_FLAG_IGNORE_MATRIX \ + | MODEL_FLAG_4000 \ + | MODEL_FLAG_8000) enum ModelFlags { - MODEL_FLAG_FLAG_1 = 0x0001, - MODEL_FLAG_HIDDEN = 0x0002, - MODEL_FLAG_FLAG_4 = 0x0004, - MODEL_FLAG_TRANSFORM_GROUP_MEMBER = 0x0008, - MODEL_FLAG_USES_CUSTOM_GFX = 0x0010, - MODEL_FLAG_FLAG_20 = 0x0020, - MODEL_FLAG_FLAG_40 = 0x0040, - MODEL_FLAG_HAS_LOCAL_VERTEX_COPY = 0x0080, - MODEL_FLAG_USE_CAMERA_UNK_MATRIX = 0x0100, - MODEL_FLAG_FLAG_200 = 0x0200, - MODEL_FLAG_HAS_TRANSFORM_APPLIED = 0x0400, - MODEL_FLAG_HAS_TEX_PANNER = 0x0800, - MODEL_FLAG_USES_TRANSFORM_MATRIX = 0x1000, - MODEL_FLAG_FLAG_2000 = 0x2000, - MODEL_FLAG_FLAG_4000 = 0x4000, - MODEL_FLAG_FLAG_8000 = 0x8000, + MODEL_FLAG_VALID = 0x0001, + MODEL_FLAG_HIDDEN = 0x0002, + MODEL_FLAG_INACTIVE = 0x0004, + MODEL_FLAG_TRANSFORM_GROUP_MEMBER = 0x0008, + MODEL_FLAG_USES_CUSTOM_GFX = 0x0010, + MODEL_FLAG_20 = 0x0020, + MODEL_FLAG_40 = 0x0040, + MODEL_FLAG_HAS_LOCAL_VERTEX_COPY = 0x0080, + MODEL_FLAG_USE_CAMERA_UNK_MATRIX = 0x0100, + MODEL_FLAG_DO_BOUNDS_CULLING = 0x0200, + MODEL_FLAG_HAS_TRANSFORM = 0x0400, + MODEL_FLAG_HAS_TEX_PANNER = 0x0800, + MODEL_FLAG_MATRIX_DIRTY = 0x1000, // transform matrix changed and combined matrix needs to be recalculated + MODEL_FLAG_IGNORE_MATRIX = 0x2000, // set until dirty combined matrix has been recalculated + MODEL_FLAG_4000 = 0x4000, + MODEL_FLAG_8000 = 0x8000, }; enum ModelGroupVisibility { @@ -5081,10 +5158,9 @@ enum MusicSettingsFlags { MUSIC_SETTINGS_FLAG_20 = 0x00000020, }; -// the lower byte of Collider::flags +// the lower byte of ColliderFlags enum SurfaceType { SURFACE_TYPE_DEFAULT = 0, - /* SURFACE_TYPE_WATER = 1, SURFACE_TYPE_SPIKES = 2, SURFACE_TYPE_LAVA = 3, @@ -5094,7 +5170,7 @@ enum SurfaceType { SURFACE_TYPE_CLOUD = 7, ///< used with clouds in flo_19 and flo_21 SURFACE_TYPE_SNOW = 8, SURFACE_TYPE_HEDGES = 9, ///< used within hedge maze in flo_11 - */ + SURFACE_TYPE_INVALID = -1, }; typedef enum SurfaceInteractMode { @@ -5103,31 +5179,16 @@ typedef enum SurfaceInteractMode { SURFACE_INTERACT_LAND = 2, } SurfaceInteractMode; -//TODO -- temporarily combined with SurfaceType for map data dumper enum ColliderFlags { - COLLIDER_FLAGS_UPPER_MASK = 0x7FFFFE00, // map data dumper needs this to be first - COLLIDER_FLAGS_SURFACE_TYPE_MASK = 0x000000FF, - -// SURFACE_TYPE_DEFAULT = 0, - SURFACE_TYPE_HEDGES = 9, ///< used within hedge maze in flo_11 - SURFACE_TYPE_SNOW = 8, - SURFACE_TYPE_CLOUD = 7, ///< used with clouds in flo_19 and flo_21 - SURFACE_TYPE_FLOWERS = 6, - SURFACE_TYPE_SLIDE = 5, - SURFACE_TYPE_DOCK_WALL = 4, - SURFACE_TYPE_LAVA = 3, - SURFACE_TYPE_SPIKES = 2, - SURFACE_TYPE_WATER = 1, - SURFACE_TYPE_INVALID = -1, - - COLLIDER_FLAG_SAFE_FLOOR = 0x00000100, - COLLIDER_FLAG_IGNORE_SHELL = 0x00008000, - COLLIDER_FLAG_IGNORE_PLAYER = 0x00010000, - COLLIDER_FLAG_80000 = 0x00080000, // test version of DOCK walls? - COLLIDER_FLAG_HAS_MODEL_PARENT = 0x80000000 + COLLIDER_FLAGS_UPPER_MASK = 0x7FFFFE00, // map data dumper needs this to be first + COLLIDER_FLAGS_SURFACE_TYPE_MASK = 0x000000FF, + COLLIDER_FLAG_SAFE_FLOOR = 0x00000100, + COLLIDER_FLAG_IGNORE_SHELL = 0x00008000, + COLLIDER_FLAG_IGNORE_PLAYER = 0x00010000, + COLLIDER_FLAG_80000 = 0x00080000, // test version of DOCK walls? + COLLIDER_FLAG_HAS_MODEL_PARENT = 0x80000000 }; - //TODO reversed for map dumper with 0 separated enum ColliderFlagsModifyMode { MODIFY_COLLIDER_FLAGS_SET_SURFACE = 3, @@ -5147,41 +5208,6 @@ enum CollisionChannels { COLLISION_ONLY_ENTITIES = 0x00100000, }; -enum CameraInitDataFlags { - CAMERA_INIT_DATA_FLAG_1 = 0x00000001, - CAMERA_INIT_DATA_FLAG_2 = 0x00000002, - CAMERA_INIT_DATA_FLAG_4 = 0x00000004, - CAMERA_INIT_DATA_FLAG_8 = 0x00000008, - CAMERA_INIT_DATA_FLAG_10 = 0x00000010, - CAMERA_INIT_DATA_FLAG_20 = 0x00000020, - CAMERA_INIT_DATA_FLAG_40 = 0x00000040, - CAMERA_INIT_DATA_FLAG_80 = 0x00000080, - CAMERA_INIT_DATA_FLAG_100 = 0x00000100, - CAMERA_INIT_DATA_FLAG_200 = 0x00000200, - CAMERA_INIT_DATA_FLAG_400 = 0x00000400, - CAMERA_INIT_DATA_FLAG_800 = 0x00000800, - CAMERA_INIT_DATA_FLAG_1000 = 0x00001000, - CAMERA_INIT_DATA_FLAG_2000 = 0x00002000, - CAMERA_INIT_DATA_FLAG_4000 = 0x00004000, - CAMERA_INIT_DATA_FLAG_8000 = 0x00008000, - CAMERA_INIT_DATA_FLAG_10000 = 0x00010000, - CAMERA_INIT_DATA_FLAG_20000 = 0x00020000, - CAMERA_INIT_DATA_FLAG_40000 = 0x00040000, - CAMERA_INIT_DATA_FLAG_80000 = 0x00080000, - CAMERA_INIT_DATA_FLAG_100000 = 0x00100000, - CAMERA_INIT_DATA_FLAG_200000 = 0x00200000, - CAMERA_INIT_DATA_FLAG_400000 = 0x00400000, - CAMERA_INIT_DATA_FLAG_800000 = 0x00800000, - CAMERA_INIT_DATA_FLAG_1000000 = 0x01000000, - CAMERA_INIT_DATA_FLAG_2000000 = 0x02000000, - CAMERA_INIT_DATA_FLAG_4000000 = 0x04000000, - CAMERA_INIT_DATA_FLAG_8000000 = 0x08000000, - CAMERA_INIT_DATA_FLAG_10000000 = 0x10000000, - CAMERA_INIT_DATA_FLAG_20000000 = 0x20000000, - CAMERA_INIT_DATA_FLAG_40000000 = 0x40000000, - CAMERA_INIT_DATA_FLAG_80000000 = 0x80000000, -}; - enum CameraFlags { CAMERA_FLAG_1 = 0x00000001, CAMERA_FLAG_DISABLED = 0x00000002, @@ -5238,7 +5264,7 @@ enum CameraControlType { // Uses: A/B as 2D points // Yaw is defined by the line segment AB // flag 0 = free forward movement (follow player) - // flag 1 = lock forward movement (must intersect B) + // flag 1 = lock forward movement (must intersect B) CAM_CONTROL_FIXED_ORIENTATION = 0, // Camera faces toward or away from a point with the player in the center of the frame. @@ -5420,39 +5446,8 @@ enum ModelAnimatorFlags { }; enum ShopFlags { - SHOP_FLAG_0 = 0x00000000, SHOP_FLAG_1 = 0x00000001, - SHOP_FLAG_2 = 0x00000002, - SHOP_FLAG_4 = 0x00000004, SHOP_FLAG_8 = 0x00000008, - SHOP_FLAG_10 = 0x00000010, - SHOP_FLAG_20 = 0x00000020, - SHOP_FLAG_40 = 0x00000040, - SHOP_FLAG_80 = 0x00000080, - SHOP_FLAG_100 = 0x00000100, - SHOP_FLAG_200 = 0x00000200, - SHOP_FLAG_400 = 0x00000400, - SHOP_FLAG_800 = 0x00000800, - SHOP_FLAG_1000 = 0x00001000, - SHOP_FLAG_2000 = 0x00002000, - SHOP_FLAG_4000 = 0x00004000, - SHOP_FLAG_8000 = 0x00008000, - SHOP_FLAG_10000 = 0x00010000, - SHOP_FLAG_20000 = 0x00020000, - SHOP_FLAG_40000 = 0x00040000, - SHOP_FLAG_80000 = 0x00080000, - SHOP_FLAG_100000 = 0x00100000, - SHOP_FLAG_200000 = 0x00200000, - SHOP_FLAG_400000 = 0x00400000, - SHOP_FLAG_800000 = 0x00800000, - SHOP_FLAG_1000000 = 0x01000000, - SHOP_FLAG_2000000 = 0x02000000, - SHOP_FLAG_4000000 = 0x04000000, - SHOP_FLAG_8000000 = 0x08000000, - SHOP_FLAG_10000000 = 0x10000000, - SHOP_FLAG_20000000 = 0x20000000, - SHOP_FLAG_40000000 = 0x40000000, - SHOP_FLAG_80000000 = 0x80000000, }; enum { @@ -5614,38 +5609,12 @@ enum TempSetZoneEnabledFlags { }; enum ModelTransformGroupFlags { - MODEL_TRANSFORM_GROUP_FLAG_1 = 0x00000001, - MODEL_TRANSFORM_GROUP_FLAG_2 = 0x00000002, - MODEL_TRANSFORM_GROUP_FLAG_4 = 0x00000004, - MODEL_TRANSFORM_GROUP_FLAG_8 = 0x00000008, - MODEL_TRANSFORM_GROUP_FLAG_10 = 0x00000010, - MODEL_TRANSFORM_GROUP_FLAG_20 = 0x00000020, - MODEL_TRANSFORM_GROUP_FLAG_40 = 0x00000040, - MODEL_TRANSFORM_GROUP_FLAG_80 = 0x00000080, - MODEL_TRANSFORM_GROUP_FLAG_100 = 0x00000100, - MODEL_TRANSFORM_GROUP_FLAG_200 = 0x00000200, - MODEL_TRANSFORM_GROUP_FLAG_400 = 0x00000400, - MODEL_TRANSFORM_GROUP_FLAG_800 = 0x00000800, - MODEL_TRANSFORM_GROUP_FLAG_1000 = 0x00001000, - MODEL_TRANSFORM_GROUP_FLAG_2000 = 0x00002000, - MODEL_TRANSFORM_GROUP_FLAG_4000 = 0x00004000, - MODEL_TRANSFORM_GROUP_FLAG_8000 = 0x00008000, - MODEL_TRANSFORM_GROUP_FLAG_10000 = 0x00010000, - MODEL_TRANSFORM_GROUP_FLAG_20000 = 0x00020000, - MODEL_TRANSFORM_GROUP_FLAG_40000 = 0x00040000, - MODEL_TRANSFORM_GROUP_FLAG_80000 = 0x00080000, - MODEL_TRANSFORM_GROUP_FLAG_100000 = 0x00100000, - MODEL_TRANSFORM_GROUP_FLAG_200000 = 0x00200000, - MODEL_TRANSFORM_GROUP_FLAG_400000 = 0x00400000, - MODEL_TRANSFORM_GROUP_FLAG_800000 = 0x00800000, - MODEL_TRANSFORM_GROUP_FLAG_1000000 = 0x01000000, - MODEL_TRANSFORM_GROUP_FLAG_2000000 = 0x02000000, - MODEL_TRANSFORM_GROUP_FLAG_4000000 = 0x04000000, - MODEL_TRANSFORM_GROUP_FLAG_8000000 = 0x08000000, - MODEL_TRANSFORM_GROUP_FLAG_10000000 = 0x10000000, - MODEL_TRANSFORM_GROUP_FLAG_20000000 = 0x20000000, - MODEL_TRANSFORM_GROUP_FLAG_40000000 = 0x40000000, - MODEL_TRANSFORM_GROUP_FLAG_80000000 = 0x80000000, + TRANSFORM_GROUP_FLAG_VALID = 0x00000001, + TRANSFORM_GROUP_FLAG_HIDDEN = 0x00000002, // update, but do not render + TRANSFORM_GROUP_FLAG_INACTIVE = 0x00000004, + TRANSFORM_GROUP_FLAG_HAS_TRANSFORM = 0x00000400, + TRANSFORM_GROUP_FLAG_MATRIX_DIRTY = 0x00001000, + TRANSFORM_GROUP_FLAG_IGNORE_MATRIX = 0x00002000, // set until dirty matrix has been recalculated }; enum NpcDropFlags { @@ -5660,7 +5629,7 @@ enum NpcDropFlags { }; enum ImgFXStateFlags { - IMGFX_FLAG_IN_USE = 0x00000001, + IMGFX_FLAG_VALID = 0x00000001, IMGFX_FLAG_G_CULL_BACK = 0x00000002, IMGFX_FLAG_G_CULL_FRONT = 0x00000004, IMGFX_FLAG_8 = 0x00000008, diff --git a/include/functions.h b/include/functions.h index c93ee6c9da..bae23ec096 100644 --- a/include/functions.h +++ b/include/functions.h @@ -479,7 +479,7 @@ void set_entity_fog_dist(s32 start, s32 end); void set_entity_fog_color(s32 r, s32 g, s32 b, s32 a); struct ModelTransformGroup* get_transform_group(s32 index); -void make_transform_group(u16 modelID); +void mdl_make_transform_group(u16 modelID); void enable_transform_group(u16 modelID); void disable_transform_group(u16 modelID); void set_map_transition_effect(ScreenTransition); @@ -579,7 +579,7 @@ void start_bounce_b(void); void update_input(void); void update_max_rumble_duration(void); -void func_8011BAE8(void); +void mdl_reset_transform_flags(void); void update_workers(void); void update_triggers(void); void update_scripts(void); @@ -1086,7 +1086,7 @@ f32 get_player_normal_pitch(void); void partner_kill_ability_script(void); void func_800EF3D4(s32); -void func_80116698(void); +void mdl_update_transform_matrices(void); void func_8011B950(u16, s32, s32, s32); void backup_map_collision_data(void); @@ -1098,6 +1098,6 @@ void update_item_entities(void); void iterate_models(void); void restore_map_collision_data(void); void mdl_load_all_textures(struct ModelNode* model, s32 romOffset, s32 size); -void calculate_model_sizes(void); +void mdl_calculate_model_sizes(void); #endif diff --git a/include/macros.h b/include/macros.h index ac30f1988a..e325ba23e8 100644 --- a/include/macros.h +++ b/include/macros.h @@ -218,6 +218,45 @@ #define DMG_STATUS_ALWAYS(typeFlag, duration) (STATUS_FLAG_80000000 | STATUS_FLAG_RIGHT_ON | typeFlag | (duration << 8)) #define DMG_STATUS_IGNORE_RES(typeFlag, duration) (STATUS_KEY_IGNORE_RES | typeFlag | (duration << 8)) +#define _RDP_WHOLE(x) (((s32)(x * 65536.0) >> 16) & 0xFFFF) +#define _RDP_FRAC(x) ((s32)(x * 65536.0) & 0xFFFF) +#define _RDP_PACK_WHOLE(a, b) (_RDP_WHOLE(a) << 16) | _RDP_WHOLE(b) +#define _RDP_PACK_FRAC(a, b) (_RDP_FRAC(a) << 16) | _RDP_FRAC(b) + +#define RDP_MATRIX( \ + Ax, Bx, Cx, Dx, \ + Ay, By, Cy, Dy, \ + Az, Bz, Cz, Dz, \ + Aw, Bw, Cw, Dw ) \ +{ \ + .m = { \ + { \ + _RDP_PACK_WHOLE(Ax, Ay), \ + _RDP_PACK_WHOLE(Az, Aw), \ + _RDP_PACK_WHOLE(Bx, By), \ + _RDP_PACK_WHOLE(Bz, Bw), \ + }, \ + { \ + _RDP_PACK_WHOLE(Cx, Cy), \ + _RDP_PACK_WHOLE(Cz, Cw), \ + _RDP_PACK_WHOLE(Dx, Dy), \ + _RDP_PACK_WHOLE(Dz, Dw), \ + }, \ + { \ + _RDP_PACK_FRAC(Ax, Ay), \ + _RDP_PACK_FRAC(Az, Aw), \ + _RDP_PACK_FRAC(Bx, By), \ + _RDP_PACK_FRAC(Bz, Bw), \ + }, \ + { \ + _RDP_PACK_FRAC(Cx, Cy), \ + _RDP_PACK_FRAC(Cz, Cw), \ + _RDP_PACK_FRAC(Dx, Dy), \ + _RDP_PACK_FRAC(Dz, Dw), \ + } \ + } \ +}; + #define PM_CC_01 0, 0, 0, TEXEL0, PRIMITIVE, 0, TEXEL0, 0 #define PM_CC_02 0, 0, 0, TEXEL0, TEXEL0, 0, PRIMITIVE, 0 #define PM_CC_03 TEXEL0, 0, SHADE, 0, PRIMITIVE, 0, SHADE, 0 diff --git a/include/model.h b/include/model.h index cddc812121..599023f561 100644 --- a/include/model.h +++ b/include/model.h @@ -46,18 +46,18 @@ typedef struct ModelNode { typedef struct Model { /* 0x00 */ u16 flags; /* 0x02 */ u16 modelID; - /* 0x04 */ Mtx* currentMatrix; + /* 0x04 */ Mtx* bakedMtx; // pointer to stack-allocated copy of matrix supplied by the shape file for this model /* 0x08 */ ModelNode* modelNode; /* 0x0C */ ModelGroupData* groupData; - /* 0x10 */ Mtx* currentSpecialMatrix; + /* 0x10 */ Mtx* finalMtx; // the matrix actually used while building the display list /* 0x14 */ char unk_14[4]; - /* 0x18 */ Mtx specialMatrix; - /* 0x58 */ Matrix4f transformMatrix; + /* 0x18 */ Mtx savedMtx; + /* 0x58 */ Matrix4f userTransformMtx; // provided for user code to apply an additional multiplicative transformation /* 0x98 */ Vec3f center; /* 0xA4 */ u8 texPannerID; /* 0xA5 */ u8 customGfxIndex; /* 0xA6 */ s8 renderMode; - /* 0xA7 */ u8 matrixMode; + /* 0xA7 */ u8 matrixFreshness; /* 0xA8 */ u8 textureID; /* 0xA9 */ s8 textureVariation; /* 0xAA */ char unk_AA[6]; @@ -66,16 +66,16 @@ typedef struct Model { typedef struct ModelTransformGroup { /* 0x00 */ u16 flags; /* 0x02 */ u16 groupModelID; - /* 0x04 */ Mtx* matrixRDP_N; - /* 0x08 */ ModelNode* modelNode; - /* 0x0C */ Mtx* transformMtx; - /* 0x10 */ Mtx matrixA; - /* 0x50 */ Matrix4f matrixB; + /* 0x04 */ Mtx* bakedMtx; // would point to copy of matrix from shape file, but seems to always be NULL. + /* 0x08 */ ModelNode* baseModelNode; + /* 0x0C */ Mtx* finalMtx; // the matrix actually used while building the display list + /* 0x10 */ Mtx savedMtx; + /* 0x50 */ Matrix4f userTransformMtx; // provided for user code to apply an additional multiplicative transformation /* 0x90 */ Vec3f center; /* 0x9C */ u8 minChildModelIndex; /* 0x9D */ u8 maxChildModelIndex; /* 0x9E */ u8 renderMode; - /* 0x9F */ u8 matrixMode; + /* 0x9F */ u8 matrixFreshness; } ModelTransformGroup; // size = 0xA0 typedef Model* ModelList[MAX_MODELS]; @@ -126,28 +126,33 @@ typedef Gfx* ModelCustomGfxList[32]; typedef ModelCustomGfxBuilderFunc ModelCustomGfxBuilderList[32]; typedef enum ModelPropertyKeys { - MODEL_PROP_KEY_RENDER_MODE = 0x5C, - MODEL_PROP_KEY_CAMERA_DATA = 0x5D, - MODEL_PROP_KEY_TEXTURE_NAME = 0x5E, - MODEL_PROP_KEY_SPECIAL = 0x5F, - MODEL_PROP_KEY_GROUP_TYPE = 0x60, - MODEL_PROP_KEY_BOUNDING_BOX = 0x61, - MODEL_PROP_KEY_62 = 0x62, + MODEL_PROP_KEY_RENDER_MODE = 0x5C, + MODEL_PROP_KEY_CAMERA_DATA = 0x5D, + MODEL_PROP_KEY_TEXTURE_NAME = 0x5E, + MODEL_PROP_KEY_SPECIAL = 0x5F, + MODEL_PROP_KEY_GROUP_INFO = 0x60, + MODEL_PROP_KEY_BOUNDING_BOX = 0x61, + MODEL_PROP_KEY_62 = 0x62, } ModelPropertyKeys; typedef enum ShapeTypes { - SHAPE_TYPE_MODEL = 2, - SHAPE_TYPE_GROUP = 5, - SHAPE_TYPE_ROOT = 7, - SHAPE_TYPE_SPECIAL_GROUP = 10, + SHAPE_TYPE_MODEL = 2, + SHAPE_TYPE_GROUP = 5, + SHAPE_TYPE_ROOT = 7, + SHAPE_TYPE_SPECIAL_GROUP = 10, } ShapeTypes; +typedef enum GroupTypes { + GROUP_TYPE_0 = 0, + GROUP_TYPE_1 = 1, +} GroupTypes; + typedef enum ExtraTileTypes { - EXTRA_TILE_NONE = 0, - EXTRA_TILE_MIPMAPS = 1, - EXTRA_TILE_AUX_SAME_AS_MAIN = 2, - EXTRA_TILE_AUX_INDEPENDENT = 3, - EXTRA_TILE_4 = 4, + EXTRA_TILE_NONE = 0, + EXTRA_TILE_MIPMAPS = 1, + EXTRA_TILE_AUX_SAME_AS_MAIN = 2, + EXTRA_TILE_AUX_INDEPENDENT = 3, + EXTRA_TILE_4 = 4, } ExtraTileTypes; #define SHAPE_SIZE_LIMIT 0x8000 diff --git a/src/17D6A0.c b/src/17D6A0.c index 8757de1d3e..e3efe3bf9f 100644 --- a/src/17D6A0.c +++ b/src/17D6A0.c @@ -2899,7 +2899,7 @@ void btl_bonk_update(void* data) { if (message->unk_24 != 0) { message->unk_24--; if (message->unk_24 == 0) { - clear_entity_model_flags(modelIdx, MODEL_FLAG_FLAG_20); + clear_entity_model_flags(modelIdx, MODEL_FLAG_20); } exec_entity_model_commandlist(modelIdx); break; diff --git a/src/8800.c b/src/8800.c index 6e8d2afcc2..7e2471d3c8 100644 --- a/src/8800.c +++ b/src/8800.c @@ -89,7 +89,7 @@ void render_frame(s32 isSecondPass) { if (!isSecondPass) { gCurrentCamID = CAM_DEFAULT; - func_80116698(); + mdl_update_transform_matrices(); } if (isSecondPass) { diff --git a/src/B4580.c b/src/B4580.c index cd9e312dac..4093d0b649 100644 --- a/src/B4580.c +++ b/src/B4580.c @@ -683,10 +683,10 @@ void animator_node_update_model_transform(ModelAnimator* animator, f32 (*flipMtx if (node->flags & MODEL_ANIMATOR_FLAG_HAS_MODEL) { Model* model = get_model_from_list_index(get_model_list_index_from_tree_index(node->fcData.modelID)); - copy_matrix(sp10, model->transformMatrix); + copy_matrix(sp10, model->userTransformMtx); guMtxL2F(sp10, rootTransform); - guMtxCatF(model->transformMatrix, sp10, model->transformMatrix); - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX; + guMtxCatF(model->userTransformMtx, sp10, model->userTransformMtx); + model->flags |= MODEL_FLAG_MATRIX_DIRTY; } for (i = 0; i < ARRAY_COUNT(node->children); i++) { diff --git a/src/audio/e0b30_len_b80.c b/src/audio/e0b30_len_b80.c index 39e85d0d38..6f9a8b1219 100644 --- a/src/audio/e0b30_len_b80.c +++ b/src/audio/e0b30_len_b80.c @@ -121,7 +121,7 @@ void bgm_update_music_settings(void) { case 2: flags = music->flags; music->flags &= ~flag4; - if (flags & 1) { + if (flags & MUSIC_SETTINGS_FLAG_1) { if (au_song_is_playing(music->songName) == AU_RESULT_OK) { music->flags &= ~MUSIC_SETTINGS_FLAG_1; music->state = 3; diff --git a/src/battle/area/trd_part_2/actor/fake_bowser.c b/src/battle/area/trd_part_2/actor/fake_bowser.c index d6515852c5..bacb240649 100644 --- a/src/battle/area/trd_part_2/actor/fake_bowser.c +++ b/src/battle/area/trd_part_2/actor/fake_bowser.c @@ -1217,51 +1217,51 @@ EvtScript N(EVS_FakeBowser_Idle) = { EVT_CALL(RotateGroup, MODEL_atama, LVar0, 1, 0, 0) EVT_CALL(RotateGroup, MODEL_atama, LVar1, 0, 1, 0) EVT_CALL(RotateGroup, MODEL_atama, LVar2, 0, 0, 1) - EVT_CALL(SetModelFlags, MODEL_k1, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_k2, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_k3, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_k4, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_k5, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_k6, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_k7, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_k8, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_k9, MODEL_FLAG_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_k1, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_k2, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_k3, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_k4, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_k5, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_k6, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_k7, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_k8, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_k9, MODEL_FLAG_40, TRUE) EVT_CALL(GetPartPos, ACTOR_SELF, PRT_BODY, LVar0, LVar1, LVar2) EVT_CALL(TranslateGroup, MODEL_dou, LVar0, LVar1, LVar2) EVT_CALL(GetPartRotation, ACTOR_SELF, PRT_BODY, LVar0, LVar1, LVar2) EVT_CALL(RotateGroup, MODEL_dou, LVar0, 1, 0, 0) EVT_CALL(RotateGroup, MODEL_dou, LVar1, 0, 1, 0) EVT_CALL(RotateGroup, MODEL_dou, LVar2, 0, 0, 1) - EVT_CALL(SetModelFlags, MODEL_d1, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_d2, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_d3, MODEL_FLAG_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_d1, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_d2, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_d3, MODEL_FLAG_40, TRUE) EVT_CALL(GetPartPos, ACTOR_SELF, PRT_SHELL, LVar0, LVar1, LVar2) EVT_CALL(TranslateGroup, MODEL_koura, LVar0, LVar1, LVar2) EVT_CALL(GetPartRotation, ACTOR_SELF, PRT_SHELL, LVar0, LVar1, LVar2) EVT_CALL(RotateGroup, MODEL_koura, LVar0, 1, 0, 0) EVT_CALL(RotateGroup, MODEL_koura, LVar1, 0, 1, 0) EVT_CALL(RotateGroup, MODEL_koura, LVar2, 0, 0, 1) - EVT_CALL(SetModelFlags, MODEL_s1, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_s2, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_s3, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_s4, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_s5, MODEL_FLAG_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_s1, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_s2, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_s3, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_s4, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_s5, MODEL_FLAG_40, TRUE) EVT_CALL(GetPartPos, ACTOR_SELF, PRT_LEFT_ARM, LVar0, LVar1, LVar2) EVT_CALL(TranslateGroup, MODEL_left_arm, LVar0, LVar1, LVar2) EVT_CALL(GetPartRotation, ACTOR_SELF, PRT_LEFT_ARM, LVar0, LVar1, LVar2) EVT_CALL(RotateGroup, MODEL_left_arm, LVar0, 1, 0, 0) EVT_CALL(RotateGroup, MODEL_left_arm, LVar1, 0, 1, 0) EVT_CALL(RotateGroup, MODEL_left_arm, LVar2, 0, 0, 1) - EVT_CALL(SetModelFlags, MODEL_u1, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_u2, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_u3, MODEL_FLAG_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_u1, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_u2, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_u3, MODEL_FLAG_40, TRUE) EVT_CALL(GetPartPos, ACTOR_SELF, PRT_TAIL, LVar0, LVar1, LVar2) EVT_CALL(TranslateGroup, MODEL_shippo, LVar0, LVar1, LVar2) EVT_CALL(GetPartRotation, ACTOR_SELF, PRT_TAIL, LVar0, LVar1, LVar2) EVT_CALL(RotateGroup, MODEL_shippo, LVar0, 1, 0, 0) EVT_CALL(RotateGroup, MODEL_shippo, LVar1, 0, 1, 0) EVT_CALL(RotateGroup, MODEL_shippo, LVar2, 0, 0, 1) - EVT_CALL(SetModelFlags, MODEL_p1, MODEL_FLAG_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_p1, MODEL_FLAG_40, TRUE) EVT_SET(LVar0, ArrayVar(0)) EVT_IF_EQ(LVar0, ANIM_DOING_DEATH) EVT_CALL(GetPartPos, ACTOR_SELF, PRT_FRONT_WHEELS, LVar0, LVar1, LVar2) @@ -1275,7 +1275,7 @@ EvtScript N(EVS_FakeBowser_Idle) = { EVT_CALL(RotateGroup, MODEL_koma1, LVar0, 1, 0, 0) EVT_CALL(RotateGroup, MODEL_koma1, LVar1, 0, 1, 0) EVT_CALL(RotateGroup, MODEL_koma1, LVar2, 0, 0, 1) - EVT_CALL(SetModelFlags, MODEL_km1, MODEL_FLAG_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_km1, MODEL_FLAG_40, TRUE) EVT_SET(LVar0, ArrayVar(0)) EVT_IF_EQ(LVar0, ANIM_DOING_DEATH) EVT_CALL(GetPartPos, ACTOR_SELF, PRT_BACK_WHEELS, LVar0, LVar1, LVar2) @@ -1289,25 +1289,25 @@ EvtScript N(EVS_FakeBowser_Idle) = { EVT_CALL(RotateGroup, MODEL_koma2, LVar0, 1, 0, 0) EVT_CALL(RotateGroup, MODEL_koma2, LVar1, 0, 1, 0) EVT_CALL(RotateGroup, MODEL_koma2, LVar2, 0, 0, 1) - EVT_CALL(SetModelFlags, MODEL_km2, MODEL_FLAG_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_km2, MODEL_FLAG_40, TRUE) EVT_CALL(GetPartPos, ACTOR_SELF, PRT_RIGHT_ARM, LVar0, LVar1, LVar2) EVT_CALL(TranslateGroup, MODEL_right_arm, LVar0, LVar1, LVar2) EVT_CALL(GetPartRotation, ACTOR_SELF, PRT_RIGHT_ARM, LVar0, LVar1, LVar2) EVT_CALL(RotateGroup, MODEL_right_arm, LVar0, 1, 0, 0) EVT_CALL(RotateGroup, MODEL_right_arm, LVar1, 0, 1, 0) EVT_CALL(RotateGroup, MODEL_right_arm, LVar2, 0, 0, 1) - EVT_CALL(SetModelFlags, MODEL_o171, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_o172, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_o183, MODEL_FLAG_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_o171, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_o172, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_o183, MODEL_FLAG_40, TRUE) EVT_CALL(GetPartPos, ACTOR_SELF, PRT_FEET, LVar0, LVar1, LVar2) EVT_CALL(TranslateGroup, MODEL_ashi, LVar0, LVar1, LVar2) EVT_CALL(GetPartRotation, ACTOR_SELF, PRT_FEET, LVar0, LVar1, LVar2) EVT_CALL(RotateGroup, MODEL_ashi, LVar0, 1, 0, 0) EVT_CALL(RotateGroup, MODEL_ashi, LVar1, 0, 1, 0) EVT_CALL(RotateGroup, MODEL_ashi, LVar2, 0, 0, 1) - EVT_CALL(SetModelFlags, MODEL_o118, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_o120, MODEL_FLAG_FLAG_40, TRUE) - EVT_CALL(SetModelFlags, MODEL_o165, MODEL_FLAG_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_o118, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_o120, MODEL_FLAG_40, TRUE) + EVT_CALL(SetModelFlags, MODEL_o165, MODEL_FLAG_40, TRUE) // spawn puffs of smoke if health is low enough // written to have different effects at every quintile, but every case in the final // version just executes the same script diff --git a/src/battle/common/stage/area_omo/omo_01.inc.c b/src/battle/common/stage/area_omo/omo_01.inc.c index 1593449703..8fff81cfa1 100644 --- a/src/battle/common/stage/area_omo/omo_01.inc.c +++ b/src/battle/common/stage/area_omo/omo_01.inc.c @@ -53,12 +53,12 @@ API_CALLABLE(N(UpdateRockingHorse)) { offsetY = SQ(rotZ) / 90.0f; model = get_model_from_list_index(get_model_list_index_from_tree_index(horse->modelID)); - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + model->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; guTranslateF(mtxPivot, -horse->offsetX, 0.0f, -horse->offsetZ); guRotateF(mtxRotate, rotZ, 0.0f, 0.0f, 1.0f); - guMtxCatF(mtxPivot, mtxRotate, model->transformMatrix); + guMtxCatF(mtxPivot, mtxRotate, model->userTransformMtx); guTranslateF(mtxPivot, horse->offsetX, offsetY, horse->offsetZ); - guMtxCatF(model->transformMatrix, mtxPivot, model->transformMatrix); + guMtxCatF(model->userTransformMtx, mtxPivot, model->userTransformMtx); } return ApiStatus_BLOCK; } diff --git a/src/collision.c b/src/collision.c index abe4e70024..1a6c95c7f6 100644 --- a/src/collision.c +++ b/src/collision.c @@ -9,18 +9,18 @@ typedef struct HitFile { typedef struct ColliderBackupEntry { /* 0x00 */ s32 flags; /* 0x04 */ s16 parentModelIndex; - /* 0x06 */ s16 unk_06; + /* 0x06 */ char pad_06[2]; } ColliderBackupEntry; // size = 0x08 typedef struct HitFileHeader { /* 0x00 */ s16 numColliders; - /* 0x02 */ s16 unk_02; + /* 0x02 */ char pad_02[2]; /* 0x04 */ s32 collidersOffset; /* 0x08 */ s16 numVertices; - /* 0x0A */ s16 unk_0a; + /* 0x0A */ char pad_0A[2]; /* 0x0C */ s32 verticesOffset; /* 0x10 */ s16 boundingBoxesDataSize; - /* 0x12 */ s16 unk_12; + /* 0x12 */ char pad_12[2]; /* 0x14 */ s32 boundingBoxesOffset; } HitFileHeader; // size = 0x18 @@ -382,11 +382,11 @@ void update_collider_transform(s16 colliderID) { collider = &gCollisionData.colliderList[colliderID]; model = get_model_from_list_index(collider->parentModelIndex); - if (!model->currentMatrix) { - copy_matrix(model->transformMatrix, matrix); + if (model->bakedMtx == NULL) { + copy_matrix(model->userTransformMtx, matrix); } else { - guMtxL2F(matrix, (Mtx*)model->currentMatrix); - guMtxCatF(model->transformMatrix, matrix, matrix); + guMtxL2F(matrix, (Mtx*)model->bakedMtx); + guMtxCatF(model->userTransformMtx, matrix, matrix); } triangle = collider->triangleTable; diff --git a/src/common/FoliageTransform.inc.c b/src/common/FoliageTransform.inc.c index 70071793b6..28e7f06072 100644 --- a/src/common/FoliageTransform.inc.c +++ b/src/common/FoliageTransform.inc.c @@ -60,20 +60,20 @@ API_CALLABLE(N(TransformFoliage)) { Model* model = get_model_from_list_index(modelListIndex); Matrix4f mtx; - if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM_APPLIED)) { - guTranslateF(model->transformMatrix, 0.0f, dy, 0.0f); + if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM)) { + guTranslateF(model->userTransformMtx, 0.0f, dy, 0.0f); N(foliage_setup_shear_mtx)(mtx, scale, dx, dz); - guMtxCatF(mtx, model->transformMatrix, model->transformMatrix); + guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx); guTranslateF(mtx, 0.0f, -dy, 0.0f); - guMtxCatF(mtx, model->transformMatrix, model->transformMatrix); - model->flags |= (MODEL_FLAG_HAS_TRANSFORM_APPLIED | MODEL_FLAG_USES_TRANSFORM_MATRIX); + guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx); + model->flags |= (MODEL_FLAG_HAS_TRANSFORM | MODEL_FLAG_MATRIX_DIRTY); } else { guTranslateF(mtx, 0.0f, dy, 0.0f); - guMtxCatF(mtx, model->transformMatrix, model->transformMatrix); + guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx); N(foliage_setup_shear_mtx)(mtx, scale, dx, dz); - guMtxCatF(mtx, model->transformMatrix, model->transformMatrix); + guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx); guTranslateF(mtx, 0.0f, -dy, 0.0f); - guMtxCatF(mtx, model->transformMatrix, model->transformMatrix); + guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx); } return ApiStatus_DONE2; diff --git a/src/draw_box.c b/src/draw_box.c index e8f808dc4d..f3c6c9e35e 100644 --- a/src/draw_box.c +++ b/src/draw_box.c @@ -322,26 +322,12 @@ Vp gBoxViewport = { #include "vtx/drawbox1.vtx.inc.c" -/* -| 0.0 0.0 0.0 0.0| -| 0.0 0.0 0.0 0.0| -| 0.0 0.0 0.0 0.0| -|-6.0 0.0 0.0 0.0| -*/ -Mtx gBoxMatrix = { - .m = { - // integer portion - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0xFFFA0000, 0x00000000 }, - // fractional portion - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx gBoxMatrix = RDP_MATRIX( + 0.000000, 0.000000, 0.000000, -6.000000, + 0.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 0.000000 +); s32 draw_box(s32 flags, WindowStyle windowStyle, s32 posX, s32 posY, s32 posZ, s32 width, s32 height, u8 opacity, u8 darkening, f32 scaleX, f32 scaleY, f32 rotX, f32 rotY, f32 rotZ, void (*fpDrawContents)(s32, s32, s32, s32, s32, s32, s32), diff --git a/src/entity/Chest.c b/src/entity/Chest.c index ed6545a36d..4ec4e50d8d 100644 --- a/src/entity/Chest.c +++ b/src/entity/Chest.c @@ -8,7 +8,7 @@ extern EntityScript Entity_Chest_ScriptOpened; extern Gfx Entity_Chest_RenderBox[]; extern Gfx Entity_Chest_RenderLid[]; -extern Mtx Entity_Chest_lidMtx; +extern Mtx Entity_Chest_LidMtx; EvtScript Entity_Chest_AdjustCam_ISK = { EVT_THREAD @@ -98,7 +98,7 @@ void entity_Chest_setupGfx(s32 entityIndex) { Gfx* gfx; guRotateF(sp58, data->lidAngle, 1.0f, 0.0f, 0.0f); - guMtxL2F(sp18, ENTITY_ADDR(entity, Mtx*, &Entity_Chest_lidMtx)); + guMtxL2F(sp18, ENTITY_ADDR(entity, Mtx*, &Entity_Chest_LidMtx)); guMtxCatF(sp58, sp18, sp18); guMtxF2L(sp18, &gDisplayContext->matrixStack[gMatrixListPos]); gSPMatrix(gfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW); diff --git a/src/entity/model/ArrowSign.c b/src/entity/model/ArrowSign.c index f5dcedc643..5678839b86 100644 --- a/src/entity/model/ArrowSign.c +++ b/src/entity/model/ArrowSign.c @@ -28,18 +28,12 @@ Gfx Entity_ArrowSign_LoadTexture[] = { gsSPEndDisplayList(), }; -Mtx Entity_ArrowSign_mtxSign = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0xFFFF0014, 0x00010001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0xD1B40000, 0x00000000 } - } -}; +Mtx Entity_ArrowSign_mtxSign = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, -0.180848, + 0.000000, 1.000000, 0.000000, 20.000000, + 0.000000, 0.000000, 1.000000, 1.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_ArrowSign_RenderPole[] = { gsDPPipeSync(), diff --git a/src/entity/model/BlueSwitch.c b/src/entity/model/BlueSwitch.c index 458191dc95..8b976f96e9 100644 --- a/src/entity/model/BlueSwitch.c +++ b/src/entity/model/BlueSwitch.c @@ -33,31 +33,19 @@ Gfx Entity_BlueSwitch_LoadExclMark[] = { gsSPEndDisplayList(), }; -Mtx Entity_BlueSwitch_mtxExclMark = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000006, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_BlueSwitch_mtxExclMark = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 6.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); -Mtx Entity_BlueSwitch_mtxBlueBubble = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0xFFFF0005, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0xF9310000, 0x9BEF0000 } - } -}; +Mtx Entity_BlueSwitch_mtxBlueBubble = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, -0.026597, + 0.000000, 1.000000, 0.000000, 5.000000, + 0.000000, 0.000000, 1.000000, 0.609116, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_BlueSwitch_RenderBlueBubble[] = { gsDPPipeSync(), diff --git a/src/entity/model/BlueWarpPipe.c b/src/entity/model/BlueWarpPipe.c index 492a1644eb..09edf47136 100644 --- a/src/entity/model/BlueWarpPipe.c +++ b/src/entity/model/BlueWarpPipe.c @@ -36,18 +36,12 @@ Gfx Entity_BlueWarpPipe_LoadTexturePipe[] = { gsSPEndDisplayList(), }; -Mtx Entity_BlueWarpPipe_mtx = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x0000FFC9, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_BlueWarpPipe_mtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, -55.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_BlueWarpPipe_RenderBase[] = { gsDPPipeSync(), diff --git a/src/entity/model/Chest.c b/src/entity/model/Chest.c index 14d5f92e9e..8527e7dc29 100644 --- a/src/entity/model/Chest.c +++ b/src/entity/model/Chest.c @@ -54,18 +54,12 @@ Gfx Entity_Chest_LoadTextureLock[] = { gsSPEndDisplayList(), }; -Mtx Entity_Chest_lidMtx = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x0000001D, 0xFFE90001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_Chest_LidMtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 29.000000, + 0.000000, 0.000000, 1.000000, -23.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_Chest_RenderLidLock[] = { gsDPPipeSync(), diff --git a/src/entity/model/CymbalPlant_gfx.c b/src/entity/model/CymbalPlant_gfx.c index 86a31664cd..cd158418ee 100644 --- a/src/entity/model/CymbalPlant_gfx.c +++ b/src/entity/model/CymbalPlant_gfx.c @@ -24,35 +24,23 @@ Gfx Entity_CymbalPlant_LoadTexture[] = { #include "entity/model/CymbalPlant_7.vtx.inc.c" #include "entity/model/CymbalPlant_8.vtx.inc.c" -Mtx D_0A001078_E9A368 = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x0002001A, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0xAB15AB15, 0x00000000 } - } -}; +Mtx Entity_CymbalPlant_RightMtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 2.668290, + 0.000000, 1.000000, 0.000000, 26.668290, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); -Mtx D_0A0010B8_E9A3A8 = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0xFFFD001A, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0xAB15AB15, 0x00000000 } - } -}; +Mtx Entity_CymbalPlant_LeftMtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, -2.331711, + 0.000000, 1.000000, 0.000000, 26.668290, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_CymbalPlant_RenderNode3[] = { gsDPPipeSync(), - gsSPMatrix(&D_0A0010B8_E9A3A8, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), + gsSPMatrix(&Entity_CymbalPlant_LeftMtx, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), gsDPSetCycleType(G_CYC_1CYCLE), gsDPSetRenderMode(G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2), gsSPDisplayList(Entity_CymbalPlant_LoadTexture), @@ -80,7 +68,7 @@ Gfx Entity_CymbalPlant_RenderNode3[] = { Gfx Entity_CymbalPlant_RenderNode4[] = { gsDPPipeSync(), - gsSPMatrix(&D_0A0010B8_E9A3A8, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), + gsSPMatrix(&Entity_CymbalPlant_LeftMtx, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), gsDPSetCycleType(G_CYC_1CYCLE), gsDPSetRenderMode(G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2), gsSPDisplayList(Entity_CymbalPlant_LoadTexture), @@ -108,7 +96,7 @@ Gfx Entity_CymbalPlant_RenderNode4[] = { Gfx Entity_CymbalPlant_RenderNode5[] = { gsDPPipeSync(), - gsSPMatrix(&D_0A0010B8_E9A3A8, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), + gsSPMatrix(&Entity_CymbalPlant_LeftMtx, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), gsDPSetCycleType(G_CYC_1CYCLE), gsDPSetRenderMode(G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2), gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), @@ -126,7 +114,7 @@ Gfx Entity_CymbalPlant_RenderNode5[] = { }; Gfx D_0A001308_E9A5F8[] = { - gsSPMatrix(&D_0A0010B8_E9A3A8, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), + gsSPMatrix(&Entity_CymbalPlant_LeftMtx, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), gsSPDisplayList(Entity_CymbalPlant_RenderNode5), gsSPDisplayList(Entity_CymbalPlant_RenderNode4), gsSPDisplayList(Entity_CymbalPlant_RenderNode3), @@ -136,7 +124,7 @@ Gfx D_0A001308_E9A5F8[] = { Gfx Entity_CymbalPlant_RenderNode7[] = { gsDPPipeSync(), - gsSPMatrix(&D_0A001078_E9A368, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), + gsSPMatrix(&Entity_CymbalPlant_RightMtx, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), gsDPSetCycleType(G_CYC_1CYCLE), gsDPSetRenderMode(G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2), gsSPDisplayList(Entity_CymbalPlant_LoadTexture), @@ -164,7 +152,7 @@ Gfx Entity_CymbalPlant_RenderNode7[] = { Gfx Entity_CymbalPlant_RenderNode9[] = { gsDPPipeSync(), - gsSPMatrix(&D_0A001078_E9A368, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), + gsSPMatrix(&Entity_CymbalPlant_RightMtx, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), gsDPSetCycleType(G_CYC_1CYCLE), gsDPSetRenderMode(G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2), gsSPDisplayList(Entity_CymbalPlant_LoadTexture), @@ -192,7 +180,7 @@ Gfx Entity_CymbalPlant_RenderNode9[] = { Gfx Entity_CymbalPlant_RenderNode8[] = { gsDPPipeSync(), - gsSPMatrix(&D_0A001078_E9A368, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), + gsSPMatrix(&Entity_CymbalPlant_RightMtx, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), gsDPSetCycleType(G_CYC_1CYCLE), gsDPSetRenderMode(G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2), gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), @@ -209,7 +197,7 @@ Gfx Entity_CymbalPlant_RenderNode8[] = { }; Gfx D_0A001540_E9A830[] = { - gsSPMatrix(&D_0A001078_E9A368, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), + gsSPMatrix(&Entity_CymbalPlant_RightMtx, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW), gsSPDisplayList(Entity_CymbalPlant_RenderNode8), gsSPDisplayList(Entity_CymbalPlant_RenderNode9), gsSPDisplayList(Entity_CymbalPlant_RenderNode7), diff --git a/src/entity/model/GreenStompSwitch.c b/src/entity/model/GreenStompSwitch.c index 26b21e01b6..55d769b6a7 100644 --- a/src/entity/model/GreenStompSwitch.c +++ b/src/entity/model/GreenStompSwitch.c @@ -37,18 +37,12 @@ Gfx Entity_GreenStompSwitch_LoadExclMark[] = { gsSPEndDisplayList(), }; -Mtx Entity_GreenStompSwitch_mtx = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000000, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_GreenStompSwitch_mtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_GreenStompSwitch_RenderBase[] = { gsDPPipeSync(), diff --git a/src/entity/model/Padlock.c b/src/entity/model/Padlock.c index 4b8d9a6693..9c23685ea5 100644 --- a/src/entity/model/Padlock.c +++ b/src/entity/model/Padlock.c @@ -50,18 +50,12 @@ Gfx Entity_Padlock_LoadTextureBody[] = { gsSPEndDisplayList(), }; -Mtx Entity_Padlock_mtxShackle = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000016, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00008000, 0x00000000 } - } -}; +Mtx Entity_Padlock_mtxShackle = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 22.500000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_Padlock_RenderShackleMain[] = { gsDPPipeSync(), diff --git a/src/entity/model/PadlockBlueFace.c b/src/entity/model/PadlockBlueFace.c index f7d78a6497..3959bc40ed 100644 --- a/src/entity/model/PadlockBlueFace.c +++ b/src/entity/model/PadlockBlueFace.c @@ -48,18 +48,12 @@ Gfx Entity_PadlockBlueFace_LoadTextureBody[] = { gsSPEndDisplayList(), }; -Mtx Entity_PadlockBlueFace_mtxShackle = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000016, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00008000, 0x00000000 } - } -}; +Mtx Entity_PadlockBlueFace_mtxShackle = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 22.500000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_PadlockBlueFace_RenderShackleMain[] = { gsDPPipeSync(), diff --git a/src/entity/model/PadlockRedFace.c b/src/entity/model/PadlockRedFace.c index e8d5369ca0..78f12dac25 100644 --- a/src/entity/model/PadlockRedFace.c +++ b/src/entity/model/PadlockRedFace.c @@ -48,18 +48,12 @@ Gfx Entity_PadlockRedFace_LoadTextureBody[] = { gsSPEndDisplayList(), }; -Mtx Entity_PadlockRedFace_mtxShackle = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000016, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00008000, 0x00000000 } - } -}; +Mtx Entity_PadlockRedFace_mtxShackle = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 22.500000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_PadlockRedFace_RenderShackleMain[] = { gsDPPipeSync(), diff --git a/src/entity/model/PadlockRedFrame.c b/src/entity/model/PadlockRedFrame.c index e743d65649..45d81fe921 100644 --- a/src/entity/model/PadlockRedFrame.c +++ b/src/entity/model/PadlockRedFrame.c @@ -35,18 +35,12 @@ Gfx Entity_PadlockRedFrame_LoadTextureFace[] = { gsSPEndDisplayList(), }; -Mtx Entity_PadlockRedFrame_mtxShackle = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000000, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_PadlockRedFrame_mtxShackle = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_PadlockRedFrame_RenderShackleMain[] = { gsDPPipeSync(), diff --git a/src/entity/model/PinkFlower_gfx.c b/src/entity/model/PinkFlower_gfx.c index c3f1ef3277..bbeaae4d34 100644 --- a/src/entity/model/PinkFlower_gfx.c +++ b/src/entity/model/PinkFlower_gfx.c @@ -31,18 +31,12 @@ Gfx D_0A001020_E9C520[] = { gsSPEndDisplayList(), }; -Mtx D_0A001098_E9C598 = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0xFFF60019, 0x000D0001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx D_0A001098_E9C598 = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, -10.000000, + 0.000000, 1.000000, 0.000000, 25.000000, + 0.000000, 0.000000, 1.000000, 13.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_PinkFlower_RenderNode3[] = { gsDPPipeSync(), diff --git a/src/entity/model/PowBlock.c b/src/entity/model/PowBlock.c index e69a40ead3..8bbd487468 100644 --- a/src/entity/model/PowBlock.c +++ b/src/entity/model/PowBlock.c @@ -17,18 +17,12 @@ Gfx Entity_PowBlock_LoadTexture[] = { gsSPEndDisplayList(), }; -Mtx Entity_PowBlock_mtx = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000000, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_PowBlock_mtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_PowBlock_RenderTopBottom[] = { gsDPPipeSync(), diff --git a/src/entity/model/PushBlock.c b/src/entity/model/PushBlock.c index a3b792a27d..4e6e315a30 100644 --- a/src/entity/model/PushBlock.c +++ b/src/entity/model/PushBlock.c @@ -17,18 +17,12 @@ Gfx Entity_PushBlock_LoadTexture[] = { gsSPEndDisplayList(), }; -Mtx Entity_PushBlock_mtx = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000000, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_PushBlock_mtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_PushBlock_RenderFaces[] = { gsDPPipeSync(), diff --git a/src/entity/model/RedSwitch.c b/src/entity/model/RedSwitch.c index e59776c0e1..51c68d573d 100644 --- a/src/entity/model/RedSwitch.c +++ b/src/entity/model/RedSwitch.c @@ -32,31 +32,20 @@ Gfx Entity_RedSwitch_LoadExclMark[] = { gsSPEndDisplayList(), }; -Mtx Entity_RedSwitch_mtxExclMark = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000006, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_RedSwitch_mtxExclMark = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 6.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); + +Mtx Entity_RedSwitch_mtxRedBubble = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, -0.026600, + 0.000000, 1.000000, 0.000000, 5.000000, + 0.000000, 0.000000, 1.000000, 0.609116, + 0.000000, 0.000000, 0.000000, 1.000000 +); -Mtx Entity_RedSwitch_mtxRedBubble = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0xFFFF0005, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0xF9310000, 0x9BEF0000 } - } -}; Gfx Entity_RedSwitch_RenderRedBubble[] = { gsDPPipeSync(), diff --git a/src/entity/model/SaveBlock.c b/src/entity/model/SaveBlock.c index f2681ac501..995de26d76 100644 --- a/src/entity/model/SaveBlock.c +++ b/src/entity/model/SaveBlock.c @@ -42,18 +42,12 @@ Gfx Entity_SaveBlock_LoadTextureLetterS[] = { gsSPEndDisplayList(), }; -Mtx Entity_SaveBlock_Mtx = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000000, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_SaveBlock_Mtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_SaveBlock_RenderLetterS[] = { gsDPPipeSync(), diff --git a/src/entity/model/SpinningFlower.c b/src/entity/model/SpinningFlower.c index e7c4c3e971..a7d1d72f92 100644 --- a/src/entity/model/SpinningFlower.c +++ b/src/entity/model/SpinningFlower.c @@ -31,18 +31,12 @@ Gfx D_0A000AF8_E9D3F8[] = { gsSPEndDisplayList(), }; -Mtx D_0A000B70_E9D470 = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000014, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx D_0A000B70_E9D470 = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 20.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx D_0A000BB0_E9D4B0[] = { gsDPPipeSync(), diff --git a/src/entity/model/StarBoxLauncher.c b/src/entity/model/StarBoxLauncher.c index 89cc41c314..ef50d8bcb1 100644 --- a/src/entity/model/StarBoxLauncher.c +++ b/src/entity/model/StarBoxLauncher.c @@ -48,18 +48,12 @@ Gfx Entity_StarBoxLauncher_LoadTextureBox[] = { gsSPEndDisplayList(), }; -Mtx Entity_StarBoxLauncher_mtx = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000000, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_StarBoxLauncher_mtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_StarBoxLauncher_RenderChain[] = { gsDPPipeSync(), diff --git a/src/entity/model/SuperBlock.c b/src/entity/model/SuperBlock.c index 7d89d79e04..13e814501d 100644 --- a/src/entity/model/SuperBlock.c +++ b/src/entity/model/SuperBlock.c @@ -17,18 +17,12 @@ Gfx Entity_SuperBlock_LoadTexture[] = { gsSPEndDisplayList(), }; -Mtx Entity_SuperBlock_mtx = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000000, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_SuperBlock_mtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_SuperBlock_RenderTop[] = { gsDPPipeSync(), diff --git a/src/entity/model/Tweester.c b/src/entity/model/Tweester.c index b9a574497f..41d00dafc3 100644 --- a/src/entity/model/Tweester.c +++ b/src/entity/model/Tweester.c @@ -47,31 +47,19 @@ Gfx Entity_Tweester_LoadTextureFace[] = { gsSPEndDisplayList(), }; -Mtx Entity_Tweester_mtxInnerWhirl = { - .m = { - { 0x0000FFFF, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000000, 0x00000001 }, - { 0xFFF6FB88, 0x00000000, - 0x0478FFF6, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_Tweester_mtxInnerWhirl = RDP_MATRIX( + 0.999848, 0.017457, 0.000000, 0.000000, + -0.01746, 0.999848, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); -Mtx Entity_Tweester_mtxOuterWhirl = { - .m = { - { 0x00010000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000000, 0x00000001 }, - { 0x33330000, 0x00000000, - 0x0000E666, 0x00000000 }, - { 0x00000000, 0x33330000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_Tweester_mtxOuterWhirl = RDP_MATRIX( + 1.199997, 0.000000, 0.000000, 0.000000, + 0.000000, 0.899994, 0.000000, 0.000000, + 0.000000, 0.000000, 1.199997, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx D_0A0019E8_E58848[] = { gsDPPipeSync(), diff --git a/src/entity/model/UltraBlock.c b/src/entity/model/UltraBlock.c index 9a051a542c..b4bab0e053 100644 --- a/src/entity/model/UltraBlock.c +++ b/src/entity/model/UltraBlock.c @@ -17,18 +17,12 @@ Gfx Entity_UltraBlock_LoadTexture[] = { gsSPEndDisplayList(), }; -Mtx Entity_UltraBlock_mtx = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000000, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx Entity_UltraBlock_mtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx Entity_UltraBlock_RenderTop[] = { gsDPPipeSync(), diff --git a/src/entity/model/UnusedBlock.c b/src/entity/model/UnusedBlock.c index b3d449b55a..dea2430165 100644 --- a/src/entity/model/UnusedBlock.c +++ b/src/entity/model/UnusedBlock.c @@ -34,18 +34,12 @@ Gfx D_0A000968_E3D738[] = { gsSPEndDisplayList(), }; -Mtx D_0A000A20_E3D7F0 = { - .m = { - { 0x00010000, 0x00000000, - 0x00000001, 0x00000000 }, - { 0x00000000, 0x00010000, - 0x00000000, 0x00000001 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, - 0x00000000, 0x00000000 } - } -}; +Mtx D_0A000A20_E3D7F0 = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); Gfx D_0A000A60_E3D830[] = { gsDPPipeSync(), diff --git a/src/evt/map_api.c b/src/evt/map_api.c index cd7703ab3a..8eb3f10af4 100644 --- a/src/evt/map_api.c +++ b/src/evt/map_api.c @@ -19,14 +19,14 @@ ApiStatus TranslateModel(Evt* script, s32 isInitialCall) { z = evt_get_float_variable(script, *args++); model = get_model_from_list_index(modelIndex); - if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM_APPLIED)) { - guTranslateF(model->transformMatrix, x, y, z); - model->flags |= (MODEL_FLAG_HAS_TRANSFORM_APPLIED | MODEL_FLAG_USES_TRANSFORM_MATRIX); + if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM)) { + guTranslateF(model->userTransformMtx, x, y, z); + model->flags |= (MODEL_FLAG_HAS_TRANSFORM | MODEL_FLAG_MATRIX_DIRTY); } else { Matrix4f mtx; guTranslateF(mtx, x, y, z); - guMtxCatF(mtx, model->transformMatrix, model->transformMatrix); + guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx); } return ApiStatus_DONE2; @@ -42,14 +42,14 @@ ApiStatus RotateModel(Evt* script, s32 isInitialCall) { f32 z = evt_get_float_variable(script, *args++); Model* model = get_model_from_list_index(modelListIndex); - if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM_APPLIED)) { - guRotateF(model->transformMatrix, a, x, y, z); - model->flags |= (MODEL_FLAG_HAS_TRANSFORM_APPLIED | MODEL_FLAG_USES_TRANSFORM_MATRIX); + if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM)) { + guRotateF(model->userTransformMtx, a, x, y, z); + model->flags |= (MODEL_FLAG_HAS_TRANSFORM | MODEL_FLAG_MATRIX_DIRTY); } else { Matrix4f mtx; guRotateF(mtx, a, x, y, z); - guMtxCatF(mtx, model->transformMatrix, model->transformMatrix); + guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx); } return ApiStatus_DONE2; @@ -69,14 +69,14 @@ ApiStatus ScaleModel(Evt* script, s32 isInitialCall) { z = evt_get_float_variable(script, *args++); model = get_model_from_list_index(modelIndex); - if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM_APPLIED)) { - guScaleF(model->transformMatrix, x, y, z); - model->flags |= (MODEL_FLAG_HAS_TRANSFORM_APPLIED | MODEL_FLAG_USES_TRANSFORM_MATRIX); + if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM)) { + guScaleF(model->userTransformMtx, x, y, z); + model->flags |= (MODEL_FLAG_HAS_TRANSFORM | MODEL_FLAG_MATRIX_DIRTY); } else { Matrix4f mtx; guScaleF(mtx, x, y, z); - guMtxCatF(mtx, model->transformMatrix, model->transformMatrix); + guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx); } return ApiStatus_DONE2; @@ -96,7 +96,7 @@ ApiStatus InvalidateModelTransform(Evt* script, s32 isInitialCall) { Bytecode modelID = evt_get_variable(script, *args++); Model* model = get_model_from_list_index(get_model_list_index_from_tree_index(modelID)); - model->flags &= ~MODEL_FLAG_HAS_TRANSFORM_APPLIED; + model->flags &= ~MODEL_FLAG_HAS_TRANSFORM; return ApiStatus_DONE2; } @@ -338,7 +338,7 @@ void apply_transform_to_children(ApiStatus (*apiFunc)(Evt*, s32), Evt* script) { } ApiStatus MakeTransformGroup(Evt* script, s32 isInitialCall) { - make_transform_group((u16)evt_get_variable(script, *script->ptrReadPos)); + mdl_make_transform_group((u16)evt_get_variable(script, *script->ptrReadPos)); return ApiStatus_DONE2; } @@ -357,8 +357,8 @@ ApiStatus SetTransformGroupEnabled(Evt* script, s32 isInitialCall) { ApiStatus TranslateGroup(Evt* script, s32 isInitialCall) { Bytecode* args = script->ptrReadPos; - s32 modelIndex = evt_get_variable(script, *args); - s32 index = get_transform_group_index(modelIndex); + s32 modelID = evt_get_variable(script, *args); + s32 index = get_transform_group_index(modelID); ModelTransformGroup* transformGroup; Matrix4f mtx; f32 x, y, z; @@ -376,13 +376,14 @@ ApiStatus TranslateGroup(Evt* script, s32 isInitialCall) { transformGroup = get_transform_group(index); - index = transformGroup->flags & MODEL_TRANSFORM_GROUP_FLAG_400; // TODO fix weird match + index = transformGroup->flags & TRANSFORM_GROUP_FLAG_HAS_TRANSFORM; // TODO fix weird match if (!index) { - guTranslateF(transformGroup->matrixB, x, y, z); - transformGroup->flags |= (MODEL_TRANSFORM_GROUP_FLAG_400 | MODEL_TRANSFORM_GROUP_FLAG_1000); + guTranslateF(transformGroup->userTransformMtx, x, y, z); + transformGroup->flags |= TRANSFORM_GROUP_FLAG_HAS_TRANSFORM; + transformGroup->flags |= TRANSFORM_GROUP_FLAG_MATRIX_DIRTY; } else { guTranslateF(mtx, x, y, z); - guMtxCatF(mtx, transformGroup->matrixB, transformGroup->matrixB); + guMtxCatF(mtx, transformGroup->userTransformMtx, transformGroup->userTransformMtx); } return ApiStatus_DONE2; @@ -390,8 +391,10 @@ ApiStatus TranslateGroup(Evt* script, s32 isInitialCall) { ApiStatus RotateGroup(Evt* script, s32 isInitialCall) { Bytecode* args = script->ptrReadPos; - s32 index = get_transform_group_index(evt_get_variable(script, *args)); + s32 modelID = evt_get_variable(script, *args); + s32 index = get_transform_group_index(modelID); ModelTransformGroup* transformGroup; + Matrix4f mtx; f32 a, x, y, z; if (index == -1) { @@ -408,14 +411,13 @@ ApiStatus RotateGroup(Evt* script, s32 isInitialCall) { transformGroup = get_transform_group(index); - if (!(transformGroup->flags & MODEL_TRANSFORM_GROUP_FLAG_400)) { - guRotateF(transformGroup->matrixB, a, x, y, z); - transformGroup->flags |= (MODEL_TRANSFORM_GROUP_FLAG_400 | MODEL_TRANSFORM_GROUP_FLAG_1000); + if (!(transformGroup->flags & TRANSFORM_GROUP_FLAG_HAS_TRANSFORM)) { + guRotateF(transformGroup->userTransformMtx, a, x, y, z); + transformGroup->flags |= TRANSFORM_GROUP_FLAG_HAS_TRANSFORM; + transformGroup->flags |= TRANSFORM_GROUP_FLAG_MATRIX_DIRTY; } else { - Matrix4f mtx; - guRotateF(mtx, a, x, y, z); - guMtxCatF(mtx, transformGroup->matrixB, transformGroup->matrixB); + guMtxCatF(mtx, transformGroup->userTransformMtx, transformGroup->userTransformMtx); } return ApiStatus_DONE2; @@ -426,6 +428,7 @@ ApiStatus ScaleGroup(Evt* script, s32 isInitialCall) { s32 modelID = evt_get_variable(script, *args); s32 transformIndex = get_transform_group_index(modelID); ModelTransformGroup* transformGroup; + Matrix4f mtx; f32 x, y, z; if (transformIndex == -1) { @@ -441,15 +444,14 @@ ApiStatus ScaleGroup(Evt* script, s32 isInitialCall) { transformGroup = get_transform_group(transformIndex); - transformIndex = transformGroup->flags & MODEL_TRANSFORM_GROUP_FLAG_400; // TODO fix weird match + transformIndex = transformGroup->flags & TRANSFORM_GROUP_FLAG_HAS_TRANSFORM; // TODO fix weird match if (!(transformIndex)) { - guScaleF(transformGroup->matrixB, x, y, z); - transformGroup->flags |= (MODEL_TRANSFORM_GROUP_FLAG_400 | MODEL_TRANSFORM_GROUP_FLAG_1000); + guScaleF(transformGroup->userTransformMtx, x, y, z); + transformGroup->flags |= TRANSFORM_GROUP_FLAG_HAS_TRANSFORM; + transformGroup->flags |= TRANSFORM_GROUP_FLAG_MATRIX_DIRTY; } else { - Matrix4f mtx; - guScaleF(mtx, x, y, z); - guMtxCatF(mtx, transformGroup->matrixB, transformGroup->matrixB); + guMtxCatF(mtx, transformGroup->userTransformMtx, transformGroup->userTransformMtx); } return ApiStatus_DONE2; @@ -457,16 +459,17 @@ ApiStatus ScaleGroup(Evt* script, s32 isInitialCall) { ApiStatus GetTransformGroup(Evt* script, s32 isInitialCall) { Bytecode* args = script->ptrReadPos; - s32 var1 = evt_get_variable(script, *args++); + s32 modelID = evt_get_variable(script, *args++); Bytecode var2 = *args++; - evt_set_variable(script, var2, get_transform_group_index(var1)); + evt_set_variable(script, var2, get_transform_group_index(modelID)); return ApiStatus_DONE2; } ApiStatus EnableGroup(Evt* script, s32 isInitialCall) { Bytecode* args = script->ptrReadPos; - s32 index = get_transform_group_index(evt_get_variable(script, *args)); + s32 modelID = evt_get_variable(script, *args); + s32 index = get_transform_group_index(modelID); s32 flagUnset; ModelTransformGroup* transformGroup; @@ -514,16 +517,16 @@ void modify_collider_family_flags(s32 index, s32 flags, s32 mode) { } switch (mode) { - case 0: + case MODIFY_COLLIDER_FLAGS_SET_BITS: collider->flags |= flags; break; - case 1: + case MODIFY_COLLIDER_FLAGS_CLEAR_BITS: collider->flags &= ~flags; break; - case 2: + case MODIFY_COLLIDER_FLAGS_SET_VALUE: collider->flags = flags; break; - case 3: + case MODIFY_COLLIDER_FLAGS_SET_SURFACE: collider->flags &= ~0xFF; collider->flags |= flags & 0xFF; break; diff --git a/src/imgfx.c b/src/imgfx.c index b770870189..dfd553b091 100644 --- a/src/imgfx.c +++ b/src/imgfx.c @@ -284,16 +284,16 @@ void func_8013A4D0(void) { imgfx_vtxCount = 0; imgfx_init_instance(&(*ImgFXInstances)[0]); - (*ImgFXInstances)[0].flags |= IMGFX_FLAG_IN_USE; + (*ImgFXInstances)[0].flags |= IMGFX_FLAG_VALID; for (i = 1; i < ARRAY_COUNT(*ImgFXInstances); i++) { - if (((*ImgFXInstances)[i].flags & IMGFX_FLAG_IN_USE) && (*ImgFXInstances)[i].lastAnimCmd != IMGFX_SET_ANIM) { + if (((*ImgFXInstances)[i].flags & IMGFX_FLAG_VALID) && (*ImgFXInstances)[i].lastAnimCmd != IMGFX_SET_ANIM) { imgfx_cache_instance_data(&(*ImgFXInstances)[i]); } } for (i = 1; i < ARRAY_COUNT(*ImgFXInstances); i++) { - if ((*ImgFXInstances)[i].flags & IMGFX_FLAG_IN_USE && (*ImgFXInstances)[i].colorBuf != NULL) { + if ((*ImgFXInstances)[i].flags & IMGFX_FLAG_VALID && (*ImgFXInstances)[i].colorBuf != NULL) { if ((*ImgFXInstances)[i].lastColorCmd == IMGFX_COLOR_BUF_SET_MULTIPLY) { continue; } @@ -357,7 +357,7 @@ s32 imgfx_get_free_instances(s32 count) { numAssigned = 0; for (i = 1; i < ARRAY_COUNT(*ImgFXInstances); i++) { - if (!((*ImgFXInstances)[i].flags & IMGFX_FLAG_IN_USE)) { + if (!((*ImgFXInstances)[i].flags & IMGFX_FLAG_VALID)) { numAssigned++; } } @@ -371,7 +371,7 @@ s32 imgfx_get_free_instances(s32 count) { numAssigned = 0; iPrev = -1; for (i = 1; i < ARRAY_COUNT(*ImgFXInstances); i++) { - if ((*ImgFXInstances)[i].flags & IMGFX_FLAG_IN_USE) { + if ((*ImgFXInstances)[i].flags & IMGFX_FLAG_VALID) { continue; } @@ -385,7 +385,7 @@ s32 imgfx_get_free_instances(s32 count) { (*ImgFXInstances)[i].arrayIdx = i; imgfx_init_instance(&(*ImgFXInstances)[i]); numAssigned++; - (*ImgFXInstances)[i].flags |= IMGFX_FLAG_IN_USE; + (*ImgFXInstances)[i].flags |= IMGFX_FLAG_VALID; iPrev = i; if (numAssigned == count) { (*ImgFXInstances)[i].nextIdx = -1; @@ -503,7 +503,7 @@ void imgfx_update(u32 idx, ImgFXType type, s32 imgfxArg1, s32 imgfxArg2, s32 img s32 t1; u8 r, g, b, a; - if (!(state->flags & IMGFX_FLAG_IN_USE) || (idx >= MAX_IMGFX_INSTANCES)) { + if (!(state->flags & IMGFX_FLAG_VALID) || (idx >= MAX_IMGFX_INSTANCES)) { return; } @@ -521,7 +521,7 @@ void imgfx_update(u32 idx, ImgFXType type, s32 imgfxArg1, s32 imgfxArg2, s32 img state->ints.raw[0][0] = -1; state->ints.raw[1][0] = -1; - state->flags &= IMGFX_FLAG_IN_USE; + state->flags &= IMGFX_FLAG_VALID; if (flags != 0) { state->flags |= flags; } else { @@ -592,7 +592,7 @@ void imgfx_update(u32 idx, ImgFXType type, s32 imgfxArg1, s32 imgfxArg2, s32 img state->ints.args.color[3] = imgfxArg4; } - state->flags &= IMGFX_FLAG_IN_USE; + state->flags &= IMGFX_FLAG_VALID; if (flags != 0) { state->flags |= flags; } @@ -704,7 +704,7 @@ void imgfx_update(u32 idx, ImgFXType type, s32 imgfxArg1, s32 imgfxArg2, s32 img } void imgfx_set_state_flags(s32 idx, u16 flagBits, s32 mode) { - if ((*ImgFXInstances)[idx].flags & IMGFX_FLAG_IN_USE) { + if ((*ImgFXInstances)[idx].flags & IMGFX_FLAG_VALID) { if (mode) { (*ImgFXInstances)[idx].flags |= flagBits; } else { @@ -762,7 +762,7 @@ s32 imgfx_appendGfx_component(s32 idx, ImgFXTexture* ifxImg, u32 flagBits, Matri state->renderType = IMGFX_RENDER_DEFAULT; state->ints.raw[0][0] = -1; state->ints.raw[1][0] = -1; - state->flags &= IMGFX_FLAG_IN_USE; + state->flags &= IMGFX_FLAG_VALID; ret = 1; } return ret; diff --git a/src/main_loop.c b/src/main_loop.c index f76318cff9..616ee78ba4 100644 --- a/src/main_loop.c +++ b/src/main_loop.c @@ -24,20 +24,12 @@ s16 D_800741A0 = 0; s16 D_800741A2 = 0; s32 D_800741A4 = 0; -Matrix4s MasterIdentityMtx = { - .whole = { - {1, 0, 0, 0}, - {0, 1, 0, 0}, - {0, 0, 1, 0}, - {0, 0, 0, 1} - }, - .frac = { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0} - } -}; +Mtx MasterIdentityMtx = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); s32 D_800741E8[2] = {0, 0}; // padding? u16 gMatrixListPos = 0; @@ -81,7 +73,7 @@ void step_game_loop(void) { } } - func_8011BAE8(); + mdl_reset_transform_flags(); npc_iter_no_op(); update_workers(); update_triggers(); diff --git a/src/map_shape.ld b/src/map_shape.ld new file mode 100644 index 0000000000..f7b28cc51b --- /dev/null +++ b/src/map_shape.ld @@ -0,0 +1,14 @@ +SECTIONS +{ + . = 0x80210000; + .data : { *(.data) } + .rodata : { + *(.rodata) + . = ALIGN(0x10); + } + + /DISCARD/ : + { + *(*); + } +} diff --git a/src/model.c b/src/model.c index 785343fec2..565a40d7b3 100644 --- a/src/model.c +++ b/src/model.c @@ -80,9 +80,72 @@ extern Gfx D_8014C110[]; extern Gfx D_8014C138[]; extern Gfx D_8014C160[]; -Gfx* D_8014AFC0[] = { D_8014B7F8, D_8014B910, D_8014B820, D_8014B938, D_8014B848, D_8014B960, D_8014B870, D_8014B988, D_8014B898, D_8014BA20, D_8014B9B0, D_8014BAC0, D_8014B8C0, D_8014B9D8, D_8014B8E8, D_8014BA00, D_8014BB60, D_8014BC78, D_8014BB88, D_8014BCA0, D_8014BBB0, D_8014BCC8, D_8014BBD8, D_8014BCF8, D_8014BC00, D_8014BD88, D_8014BD18, D_8014BC28, D_8014BD40, D_8014BC50, D_8014BD68, D_8014BE78, D_8014BF90, D_8014BEA0, D_8014BFB8, D_8014BEC8, D_8014BFE0, D_8014BEF0, D_8014C008, D_8014BF18, D_8014C098, D_8014C028, D_8014BF40, D_8014C050, D_8014BF68, D_8014C078, D_8014BA48, D_8014BA70, D_8014BA98, D_8014BDB0, D_8014BDD8, D_8014BE00, D_8014C0C0, D_8014C0E8, D_8014C110, D_8014BB10, D_8014BB38, D_8014BE28, D_8014BE50, D_8014C138, D_8014C160, NULL }; +Gfx* ModelRenderModes[] = { + [RENDER_MODE_IDX_00] D_8014B7F8, + [RENDER_MODE_IDX_01] D_8014B910, + [RENDER_MODE_IDX_02] D_8014B820, + [RENDER_MODE_IDX_03] D_8014B938, + [RENDER_MODE_IDX_04] D_8014B848, + [RENDER_MODE_IDX_05] D_8014B960, + [RENDER_MODE_IDX_06] D_8014B870, + [RENDER_MODE_IDX_07] D_8014B988, + [RENDER_MODE_IDX_08] D_8014B898, + [RENDER_MODE_IDX_09] D_8014BA20, + [RENDER_MODE_IDX_0A] D_8014B9B0, + [RENDER_MODE_IDX_0B] D_8014BAC0, + [RENDER_MODE_IDX_0C] D_8014B8C0, + [RENDER_MODE_IDX_0D] D_8014B9D8, + [RENDER_MODE_IDX_0E] D_8014B8E8, + [RENDER_MODE_IDX_0F] D_8014BA00, + [RENDER_MODE_IDX_10] D_8014BB60, + [RENDER_MODE_IDX_11] D_8014BC78, + [RENDER_MODE_IDX_12] D_8014BB88, + [RENDER_MODE_IDX_13] D_8014BCA0, + [RENDER_MODE_IDX_14] D_8014BBB0, + [RENDER_MODE_IDX_15] D_8014BCC8, + [RENDER_MODE_IDX_16] D_8014BBD8, + [RENDER_MODE_IDX_17] D_8014BCF8, + [RENDER_MODE_IDX_18] D_8014BC00, + [RENDER_MODE_IDX_19] D_8014BD88, + [RENDER_MODE_IDX_1A] D_8014BD18, + [RENDER_MODE_IDX_1B] D_8014BC28, + [RENDER_MODE_IDX_1C] D_8014BD40, + [RENDER_MODE_IDX_1D] D_8014BC50, + [RENDER_MODE_IDX_1E] D_8014BD68, + [RENDER_MODE_IDX_1F] D_8014BE78, + [RENDER_MODE_IDX_20] D_8014BF90, + [RENDER_MODE_IDX_21] D_8014BEA0, + [RENDER_MODE_IDX_22] D_8014BFB8, + [RENDER_MODE_IDX_23] D_8014BEC8, + [RENDER_MODE_IDX_24] D_8014BFE0, + [RENDER_MODE_IDX_25] D_8014BEF0, + [RENDER_MODE_IDX_26] D_8014C008, + [RENDER_MODE_IDX_27] D_8014BF18, + [RENDER_MODE_IDX_28] D_8014C098, + [RENDER_MODE_IDX_29] D_8014C028, + [RENDER_MODE_IDX_2A] D_8014BF40, + [RENDER_MODE_IDX_2B] D_8014C050, + [RENDER_MODE_IDX_2C] D_8014BF68, + [RENDER_MODE_IDX_2D] D_8014C078, + [RENDER_MODE_IDX_2E] D_8014BA48, + [RENDER_MODE_IDX_2F] D_8014BA70, + [RENDER_MODE_IDX_30] D_8014BA98, + [RENDER_MODE_IDX_31] D_8014BDB0, + [RENDER_MODE_IDX_32] D_8014BDD8, + [RENDER_MODE_IDX_33] D_8014BE00, + [RENDER_MODE_IDX_34] D_8014C0C0, + [RENDER_MODE_IDX_35] D_8014C0E8, + [RENDER_MODE_IDX_36] D_8014C110, + [RENDER_MODE_IDX_37] D_8014BB10, + [RENDER_MODE_IDX_38] D_8014BB38, + [RENDER_MODE_IDX_39] D_8014BE28, + [RENDER_MODE_IDX_3A] D_8014BE50, + [RENDER_MODE_IDX_3B] D_8014C138, + [RENDER_MODE_IDX_3C] D_8014C160, + [RENDER_MODE_IDX_3D] NULL +}; -Gfx D_8014B0B8[21][5] = { +Gfx ModelCombineModesA[21][5] = { { gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), gsDPSetCombineMode(G_CC_SHADE, G_CC_PASS2), @@ -230,7 +293,7 @@ Gfx D_8014B0B8[21][5] = { }, }; -Gfx D_8014B400[21][5] = { +Gfx ModelCombineModesB[21][5] = { { gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), gsDPSetCombineMode(G_CC_SHADE, G_CC_PASS2), @@ -406,23 +469,13 @@ s8 gRenderModelPrimB = 255; s8 gRenderModelEnvR = 0; s8 gRenderModelEnvG = 0; s8 gRenderModelEnvB = 0; -s8 D_8014B766 = 0; -s8 D_8014B767 = 0; -Matrix4s mdl_RDPIdentity = { - .whole = { - {1, 0, 0, 0}, - {0, 1, 0, 0}, - {0, 0, 1, 0}, - {0, 0, 0, 1} - }, - .frac = { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0} - } -}; +Mtx mdl_RDPIdentity = RDP_MATRIX( + 1.000000, 0.000000, 0.000000, 0.000000, + 0.000000, 1.000000, 0.000000, 0.000000, + 0.000000, 0.000000, 1.000000, 0.000000, + 0.000000, 0.000000, 0.000000, 1.000000 +); // The depth buffer contains values encoded in a custom 18-bit floating-point format. // There are 3 bits of exponent, 11 bits of mantissa, and 4 bits of "dz". @@ -1044,8 +1097,8 @@ extern ModelList bModelList; extern ModelTransformGroupList wTransformGroups; extern ModelTransformGroupList bTransformGroups; -extern ModelCustomGfxList wModelSpecialDls; -extern ModelCustomGfxList bModelSpecialDls; +extern ModelCustomGfxList wCustomModelGfx; +extern ModelCustomGfxList bCustomModelGfx; extern ModelCustomGfxBuilderList wCustomModelGfxBuilders; extern ModelCustomGfxBuilderList bCustomModelGfxBuilders; @@ -1053,8 +1106,8 @@ extern ModelLocalVertexCopyList wModelLocalVtxBuffers; extern ModelLocalVertexCopyList bModelLocalVtxBuffers; extern ModelLocalVertexCopyList* gCurrentModelLocalVtxBuffers; -extern ModelNode* D_80152214; -extern ModelNode* D_80152218; +extern ModelNode* wModelTreeRoot; +extern ModelNode* bModelTreeRoot; extern ModelTreeInfoList D_80152220; extern ModelTreeInfoList D_80152A20; @@ -1069,12 +1122,12 @@ extern s32 texPannerMainV[MAX_TEX_PANNERS]; extern s32 texPannerAuxU[MAX_TEX_PANNERS]; extern s32 texPannerAuxV[MAX_TEX_PANNERS]; extern void* TextureHeapPos; -extern u16 mdl_currentTransformGroupChildIndex; +extern u16 mtg_IterIdx; extern u16 D_80153226; -extern ModelNode* D_80153370; -extern u16 D_80153374; -extern u16 D_80153376; -extern u16 D_8015336E; +extern ModelNode* mtg_FoundModelNode; +extern u16 mtg_MinChild; +extern u16 mtg_MaxChild; +extern u16 mtg_SearchModelID; extern RenderTask* mdl_renderTaskLists[3]; extern s32 mdl_renderTaskQueueIdx; extern s32 mdl_renderTaskCount; @@ -1155,7 +1208,7 @@ void appendGfx_model(void* data) { } else { texturingMode = 1; } - if ((textureHeader != NULL || renderMode <= RENDER_MODE_ALPHATEST_NO_ZB) && gCurrentFogSettings->enabled && !(flags & MODEL_FLAG_FLAG_40)) { + if ((textureHeader != NULL || renderMode <= RENDER_MODE_ALPHATEST_NO_ZB) && gCurrentFogSettings->enabled && !(flags & MODEL_FLAG_40)) { texturingMode = 3; combineSubType = 1; } @@ -1269,9 +1322,9 @@ void appendGfx_model(void* data) { } if (renderMode != RENDER_MODE_ALPHATEST && renderMode != RENDER_MODE_ALPHATEST_ONESIDED) { - *(*gfxPos) = D_8014B0B8[v1][combineSubType]; + *(*gfxPos) = ModelCombineModesA[v1][combineSubType]; } else { - *(*gfxPos) = D_8014B400[v1][combineSubType]; + *(*gfxPos) = ModelCombineModesB[v1][combineSubType]; } (*gfxPos)++; } @@ -1280,198 +1333,198 @@ void appendGfx_model(void* data) { case 1: switch (renderMode) { case RENDER_MODE_SURFACE_OPA: - renderModeIdx = 0; + renderModeIdx = RENDER_MODE_IDX_00; break; case RENDER_MODE_SURFACE_OPA_NO_AA: - renderModeIdx = 1; + renderModeIdx = RENDER_MODE_IDX_01; break; case RENDER_MODE_DECAL_OPA: - renderModeIdx = 2; + renderModeIdx = RENDER_MODE_IDX_02; break; case RENDER_MODE_DECAL_OPA_NO_AA: - renderModeIdx = 3; + renderModeIdx = RENDER_MODE_IDX_03; break; case RENDER_MODE_INTERSECTING_OPA: - renderModeIdx = 4; + renderModeIdx = RENDER_MODE_IDX_04; break; case RENDER_MODE_ALPHATEST: - renderModeIdx = 6; + renderModeIdx = RENDER_MODE_IDX_06; break; case RENDER_MODE_ALPHATEST_ONESIDED: - renderModeIdx = 7; + renderModeIdx = RENDER_MODE_IDX_07; break; case RENDER_MODE_SURFXLU_AA_ZB_ZUPD: - renderModeIdx = 9; + renderModeIdx = RENDER_MODE_IDX_09; break; case RENDER_MODE_SURFACE_XLU_LAYER1: case RENDER_MODE_SURFACE_XLU_LAYER2: case RENDER_MODE_SURFACE_XLU_LAYER3: - renderModeIdx = 8; + renderModeIdx = RENDER_MODE_IDX_08; break; case RENDER_MODE_SURFACE_XLU_NO_AA: - renderModeIdx = 10; + renderModeIdx = RENDER_MODE_IDX_0A; break; case RENDER_MODE_SURFXLU_ZB_ZUPD: - renderModeIdx = 11; + renderModeIdx = RENDER_MODE_IDX_0B; break; case RENDER_MODE_DECAL_XLU: - renderModeIdx = 12; + renderModeIdx = RENDER_MODE_IDX_0C; break; case RENDER_MODE_DECAL_XLU_NOAA: - renderModeIdx = 13; + renderModeIdx = RENDER_MODE_IDX_0D; break; case RENDER_MODE_INTERSECTING_XLU: - renderModeIdx = 14; + renderModeIdx = RENDER_MODE_IDX_0E; break; case RENDER_MODE_SURFACE_OPA_NO_ZB: - renderModeIdx = 0x2E; + renderModeIdx = RENDER_MODE_IDX_2E; break; case RENDER_MODE_ALPHATEST_NO_ZB: - renderModeIdx = 0x2F; + renderModeIdx = RENDER_MODE_IDX_2F; break; case RENDER_MODE_SURFACE_XLU_NO_ZB: - renderModeIdx = 0x30; + renderModeIdx = RENDER_MODE_IDX_30; break; case RENDER_MODE_CLOUD: - renderModeIdx = 0x37; + renderModeIdx = RENDER_MODE_IDX_37; break; case RENDER_MODE_CLOUD_NO_ZB: - renderModeIdx = 0x38; + renderModeIdx = RENDER_MODE_IDX_38; break; default: - renderModeIdx = 0; + renderModeIdx = RENDER_MODE_IDX_00; break; } - gSPDisplayList((*gfxPos)++, D_8014AFC0[renderModeIdx]); + gSPDisplayList((*gfxPos)++, ModelRenderModes[renderModeIdx]); break; case 2: switch (renderMode) { case RENDER_MODE_SURFACE_OPA_NO_AA: - renderModeIdx = 0x11; + renderModeIdx = RENDER_MODE_IDX_11; break; case RENDER_MODE_DECAL_OPA: - renderModeIdx = 0x12; + renderModeIdx = RENDER_MODE_IDX_12; break; case RENDER_MODE_DECAL_OPA_NO_AA: - renderModeIdx = 0x13; + renderModeIdx = RENDER_MODE_IDX_13; break; case RENDER_MODE_INTERSECTING_OPA: - renderModeIdx = 0x14; + renderModeIdx = RENDER_MODE_IDX_14; break; case RENDER_MODE_ALPHATEST: - renderModeIdx = 0x16; + renderModeIdx = RENDER_MODE_IDX_16; break; case RENDER_MODE_ALPHATEST_ONESIDED: - renderModeIdx = 0x17; + renderModeIdx = RENDER_MODE_IDX_17; break; case RENDER_MODE_SURFACE_XLU_LAYER1: case RENDER_MODE_SURFACE_XLU_LAYER2: case RENDER_MODE_SURFACE_XLU_LAYER3: - renderModeIdx = 0x18; + renderModeIdx = RENDER_MODE_IDX_18; break; case RENDER_MODE_SURFXLU_AA_ZB_ZUPD: - renderModeIdx = 0x19; + renderModeIdx = RENDER_MODE_IDX_19; break; case RENDER_MODE_SURFACE_XLU_NO_AA: - renderModeIdx = 0x1A; + renderModeIdx = RENDER_MODE_IDX_1A; break; case RENDER_MODE_DECAL_XLU: - renderModeIdx = 0x1B; + renderModeIdx = RENDER_MODE_IDX_1B; break; case RENDER_MODE_DECAL_XLU_NOAA: - renderModeIdx = 0x1C; + renderModeIdx = RENDER_MODE_IDX_1C; break; case RENDER_MODE_INTERSECTING_XLU: - renderModeIdx = 0x1D; + renderModeIdx = RENDER_MODE_IDX_1D; break; case RENDER_MODE_SURFACE_OPA_NO_ZB: - renderModeIdx = 0x31; + renderModeIdx = RENDER_MODE_IDX_31; break; case RENDER_MODE_ALPHATEST_NO_ZB: - renderModeIdx = 0x32; + renderModeIdx = RENDER_MODE_IDX_32; break; case RENDER_MODE_SURFACE_XLU_NO_ZB: - renderModeIdx = 0x33; + renderModeIdx = RENDER_MODE_IDX_33; break; case RENDER_MODE_CLOUD: - renderModeIdx = 0x39; + renderModeIdx = RENDER_MODE_IDX_39; break; case RENDER_MODE_CLOUD_NO_ZB: - renderModeIdx = 0x3A; + renderModeIdx = RENDER_MODE_IDX_3A; break; case RENDER_MODE_SURFACE_OPA: - renderModeIdx = 0x10; + renderModeIdx = RENDER_MODE_IDX_10; break; default: - renderModeIdx = 0x10; + renderModeIdx = RENDER_MODE_IDX_10; break; } - gSPDisplayList((*gfxPos)++, D_8014AFC0[renderModeIdx]); + gSPDisplayList((*gfxPos)++, ModelRenderModes[renderModeIdx]); break; case 3: - temp = 0x25; // required to match + temp = RENDER_MODE_IDX_25; // required to match switch (renderMode) { case RENDER_MODE_SURFACE_OPA_NO_AA: - renderModeIdx = 0x20; + renderModeIdx = RENDER_MODE_IDX_20; break; case RENDER_MODE_DECAL_OPA: - renderModeIdx = 0x21; + renderModeIdx = RENDER_MODE_IDX_21; break; case RENDER_MODE_DECAL_OPA_NO_AA: - renderModeIdx = 0x22; + renderModeIdx = RENDER_MODE_IDX_22; break; case RENDER_MODE_INTERSECTING_OPA: - renderModeIdx = 0x23; + renderModeIdx = RENDER_MODE_IDX_23; break; case RENDER_MODE_ALPHATEST: renderModeIdx = temp; break; case RENDER_MODE_ALPHATEST_ONESIDED: - renderModeIdx = 0x26; + renderModeIdx = RENDER_MODE_IDX_26; break; case RENDER_MODE_SURFACE_XLU_LAYER1: case RENDER_MODE_SURFACE_XLU_LAYER2: case RENDER_MODE_SURFACE_XLU_LAYER3: - renderModeIdx = 0x27; + renderModeIdx = RENDER_MODE_IDX_27; break; case RENDER_MODE_SURFXLU_AA_ZB_ZUPD: - renderModeIdx = 0x28; + renderModeIdx = RENDER_MODE_IDX_28; break; case RENDER_MODE_SURFACE_XLU_NO_AA: - renderModeIdx = 0x29; + renderModeIdx = RENDER_MODE_IDX_29; break; case RENDER_MODE_DECAL_XLU: - renderModeIdx = 0x2A; + renderModeIdx = RENDER_MODE_IDX_2A; break; case RENDER_MODE_DECAL_XLU_NOAA: - renderModeIdx = 0x2B; + renderModeIdx = RENDER_MODE_IDX_2B; break; case RENDER_MODE_INTERSECTING_XLU: - renderModeIdx = 0x2C; + renderModeIdx = RENDER_MODE_IDX_2C; break; case RENDER_MODE_SURFACE_OPA_NO_ZB: - renderModeIdx = 0x34; + renderModeIdx = RENDER_MODE_IDX_34; break; case RENDER_MODE_ALPHATEST_NO_ZB: - renderModeIdx = 0x35; + renderModeIdx = RENDER_MODE_IDX_35; break; case RENDER_MODE_SURFACE_XLU_NO_ZB: - renderModeIdx = 0x36; + renderModeIdx = RENDER_MODE_IDX_36; break; case RENDER_MODE_CLOUD: - renderModeIdx = 0x3B; + renderModeIdx = RENDER_MODE_IDX_3B; break; case RENDER_MODE_CLOUD_NO_ZB: - renderModeIdx = 0x3C; + renderModeIdx = RENDER_MODE_IDX_3C; break; case RENDER_MODE_SURFACE_OPA: - renderModeIdx = 0x1F; + renderModeIdx = RENDER_MODE_IDX_1F; break; default: - renderModeIdx = 0x1F; + renderModeIdx = RENDER_MODE_IDX_1F; break; } - gSPDisplayList((*gfxPos)++, D_8014AFC0[renderModeIdx]); + gSPDisplayList((*gfxPos)++, ModelRenderModes[renderModeIdx]); gDPSetFogColor((*gfxPos)++, gCurrentFogSettings->color.r, gCurrentFogSettings->color.g, gCurrentFogSettings->color.b, @@ -1483,7 +1536,7 @@ void appendGfx_model(void* data) { if (mdl_bgMultiplyColorA == 255) { return; } - gSPDisplayList((*gfxPos)++, D_8014AFC0[0x10]); + gSPDisplayList((*gfxPos)++, ModelRenderModes[RENDER_MODE_IDX_10]); switch (renderMode) { case RENDER_MODE_SURFACE_OPA: gDPSetRenderMode(gMainGfxPos++, GBL_c1(G_BL_CLR_BL, G_BL_A_FOG, G_BL_CLR_IN, G_BL_1MA), G_RM_AA_ZB_OPA_SURF2); @@ -1556,66 +1609,66 @@ void appendGfx_model(void* data) { case 6: switch (renderMode) { case RENDER_MODE_SURFACE_OPA_NO_AA: - renderModeIdx = 0x20; + renderModeIdx = RENDER_MODE_IDX_20; break; case RENDER_MODE_DECAL_OPA: - renderModeIdx = 0x21; + renderModeIdx = RENDER_MODE_IDX_21; break; case RENDER_MODE_DECAL_OPA_NO_AA: - renderModeIdx = 0x22; + renderModeIdx = RENDER_MODE_IDX_22; break; case RENDER_MODE_INTERSECTING_OPA: - renderModeIdx = 0x23; + renderModeIdx = RENDER_MODE_IDX_23; break; case RENDER_MODE_ALPHATEST: - renderModeIdx = 0x25; + renderModeIdx = RENDER_MODE_IDX_25; break; case RENDER_MODE_ALPHATEST_ONESIDED: - renderModeIdx = 0x26; + renderModeIdx = RENDER_MODE_IDX_26; break; case RENDER_MODE_SURFACE_XLU_LAYER1: case RENDER_MODE_SURFACE_XLU_LAYER2: case RENDER_MODE_SURFACE_XLU_LAYER3: - renderModeIdx = 0x27; + renderModeIdx = RENDER_MODE_IDX_27; break; case RENDER_MODE_SURFXLU_AA_ZB_ZUPD: - renderModeIdx = 0x28; + renderModeIdx = RENDER_MODE_IDX_28; break; case RENDER_MODE_SURFACE_XLU_NO_AA: - renderModeIdx = 0x29; + renderModeIdx = RENDER_MODE_IDX_29; break; case RENDER_MODE_DECAL_XLU: - renderModeIdx = 0x2A; + renderModeIdx = RENDER_MODE_IDX_2A; break; case RENDER_MODE_DECAL_XLU_NOAA: - renderModeIdx = 0x2B; + renderModeIdx = RENDER_MODE_IDX_2B; break; case RENDER_MODE_INTERSECTING_XLU: - renderModeIdx = 0x2C; + renderModeIdx = RENDER_MODE_IDX_2C; break; case RENDER_MODE_SURFACE_OPA_NO_ZB: - renderModeIdx = 0x34; + renderModeIdx = RENDER_MODE_IDX_34; break; case RENDER_MODE_ALPHATEST_NO_ZB: - renderModeIdx = 0x35; + renderModeIdx = RENDER_MODE_IDX_35; break; case RENDER_MODE_SURFACE_XLU_NO_ZB: - renderModeIdx = 0x36; + renderModeIdx = RENDER_MODE_IDX_36; break; case RENDER_MODE_CLOUD: - renderModeIdx = 0x3B; + renderModeIdx = RENDER_MODE_IDX_3B; break; case RENDER_MODE_CLOUD_NO_ZB: - renderModeIdx = 0x3C; + renderModeIdx = RENDER_MODE_IDX_3C; break; case RENDER_MODE_SURFACE_OPA: - renderModeIdx = 0x1F; + renderModeIdx = RENDER_MODE_IDX_1F; break; default: - renderModeIdx = 0x1F; + renderModeIdx = RENDER_MODE_IDX_1F; break; } - gSPDisplayList((*gfxPos)++, D_8014AFC0[renderModeIdx]); + gSPDisplayList((*gfxPos)++, ModelRenderModes[renderModeIdx]); fogR = (gCurrentFogSettings->color.r * (255 - mdl_bgMultiplyColorA) + mdl_bgMultiplyColorR * mdl_bgMultiplyColorA) / 255; fogG = (gCurrentFogSettings->color.g * (255 - mdl_bgMultiplyColorA) + mdl_bgMultiplyColorG * mdl_bgMultiplyColorA) / 255; @@ -1631,32 +1684,32 @@ void appendGfx_model(void* data) { case 11: switch (renderMode) { case RENDER_MODE_DECAL_OPA: - renderModeIdx = 0x21; + renderModeIdx = RENDER_MODE_IDX_21; break; case RENDER_MODE_INTERSECTING_OPA: - renderModeIdx = 0x23; + renderModeIdx = RENDER_MODE_IDX_23; break; case RENDER_MODE_ALPHATEST: - renderModeIdx = 0x25; + renderModeIdx = RENDER_MODE_IDX_25; break; case RENDER_MODE_CLOUD: - renderModeIdx = 0x3B; + renderModeIdx = RENDER_MODE_IDX_3B; break; case RENDER_MODE_CLOUD_NO_ZB: - renderModeIdx = 0x3C; + renderModeIdx = RENDER_MODE_IDX_3C; break; case RENDER_MODE_SURFACE_OPA: default: - renderModeIdx = 0x1F; + renderModeIdx = RENDER_MODE_IDX_1F; break; } - gSPDisplayList((*gfxPos)++, D_8014AFC0[renderModeIdx]); + gSPDisplayList((*gfxPos)++, ModelRenderModes[renderModeIdx]); break; } if (!(flags & MODEL_FLAG_TRANSFORM_GROUP_MEMBER)) { - if (!(flags & MODEL_FLAG_FLAG_2000)) { - gSPMatrix((*gfxPos)++, model->currentSpecialMatrix, mtxLoadMode | mtxPushMode | G_MTX_MODELVIEW); + if (!(flags & MODEL_FLAG_IGNORE_MATRIX)) { + gSPMatrix((*gfxPos)++, model->finalMtx, mtxLoadMode | mtxPushMode | G_MTX_MODELVIEW); if (mtxPushMode != G_MTX_NOPUSH) { mtxPushMode = G_MTX_NOPUSH; } @@ -1666,14 +1719,15 @@ void appendGfx_model(void* data) { } } else { mtxLoadMode = G_MTX_MUL; - if (!(flags & MODEL_FLAG_FLAG_2000)) { - gSPMatrix((*gfxPos)++, model->currentSpecialMatrix, mtxLoadMode | mtxPushMode | G_MTX_MODELVIEW); + if (!(flags & MODEL_FLAG_IGNORE_MATRIX)) { + gSPMatrix((*gfxPos)++, model->finalMtx, mtxLoadMode | mtxPushMode | G_MTX_MODELVIEW); if (mtxPushMode != G_MTX_NOPUSH) { mtxPushMode = G_MTX_NOPUSH; } } } + // custom gfx 'pre' if (flags & MODEL_FLAG_USES_CUSTOM_GFX) { customGfxIndex = (model->customGfxIndex & 0xF) * 2; if ((*gCurrentCustomModelGfxPtr)[customGfxIndex] != NULL) { @@ -1681,6 +1735,7 @@ void appendGfx_model(void* data) { } } + // add tex panner gfx if (textureHeader != NULL) { if (flags & MODEL_FLAG_HAS_TEX_PANNER) { s32 panMainU = texPannerMainU[model->texPannerID] >> 8; @@ -1703,6 +1758,7 @@ void appendGfx_model(void* data) { } } } + if (flags & MODEL_FLAG_USE_CAMERA_UNK_MATRIX) { gSPMatrix((*gfxPos)++, gCameras[gCurrentCamID].unkMatrix, mtxLoadMode | mtxPushMode | G_MTX_MODELVIEW); if (mtxPushMode != G_MTX_NOPUSH) { @@ -1712,10 +1768,13 @@ void appendGfx_model(void* data) { mtxLoadMode = G_MTX_MUL; } } + + // render the model if (!(flags & MODEL_FLAG_HAS_LOCAL_VERTEX_COPY)) { gSPDisplayList((*gfxPos)++, modelNode->displayData->displayList); } + // custom gfx 'post' if (flags & MODEL_FLAG_USES_CUSTOM_GFX) { customGfxIndex++; if ((*gCurrentCustomModelGfxPtr)[customGfxIndex] != NULL) { @@ -1770,7 +1829,7 @@ void load_texture_impl(u32 romOffset, TextureHandle* handle, TextureHeader* head void load_texture_by_name(ModelNodeProperty* propertyName, s32 romOffset, s32 size) { char* textureName = (char*)propertyName->data.p; - u32 baseOffset = romOffset; + u32 startOffset = romOffset; s32 textureIdx = 0; u32 paletteSize; u32 rasterSize; @@ -1785,7 +1844,7 @@ void load_texture_by_name(ModelNodeProperty* propertyName, s32 romOffset, s32 si return; } - while (romOffset < baseOffset + size) { + while (romOffset < startOffset + size) { dma_copy((u8*)romOffset, (u8*)romOffset + sizeof(gCurrentTextureHeader), &gCurrentTextureHeader); header = &gCurrentTextureHeader; @@ -1876,7 +1935,7 @@ void load_texture_by_name(ModelNodeProperty* propertyName, s32 romOffset, s32 si romOffset += auxRasterSize + auxPaletteSize; } - if (romOffset >= baseOffset + 0x40000) { + if (romOffset >= startOffset + 0x40000) { // did not find the texture with `textureName` (*mdl_currentModelTreeNodeInfo)[mdl_treeIterPos].textureID = 0; return; @@ -1888,7 +1947,7 @@ void load_texture_by_name(ModelNodeProperty* propertyName, s32 romOffset, s32 si if (textureHandle->gfx == NULL) { load_texture_impl(romOffset, textureHandle, header, rasterSize, paletteSize, auxRasterSize, auxPaletteSize); - load_texture_variants(romOffset + rasterSize + paletteSize + auxRasterSize + auxPaletteSize, (*mdl_currentModelTreeNodeInfo)[mdl_treeIterPos].textureID, baseOffset, size); + load_texture_variants(romOffset + rasterSize + paletteSize + auxRasterSize + auxPaletteSize, (*mdl_currentModelTreeNodeInfo)[mdl_treeIterPos].textureID, startOffset, size); } } @@ -2002,7 +2061,6 @@ void load_texture_variants(u32 romOffset, s32 textureID, s32 baseOffset, s32 siz } } -// Goofy temps needed to match ModelNodeProperty* get_model_property(ModelNode* node, ModelPropertyKeys key) { s32 numProperties = node->numProperties; ModelNodeProperty* propertyList = node->propertyList; @@ -2088,9 +2146,9 @@ void clear_model_data(void) { if (!gGameStatusPtr->isBattle) { gCurrentModels = &wModelList; gCurrentTransformGroups = &wTransformGroups; - gCurrentCustomModelGfxPtr = &wModelSpecialDls; + gCurrentCustomModelGfxPtr = &wCustomModelGfx; gCurrentCustomModelGfxBuildersPtr = &wCustomModelGfxBuilders; - gCurrentModelTreeRoot = &D_80152214; + gCurrentModelTreeRoot = &wModelTreeRoot; gCurrentModelLocalVtxBuffers = &wModelLocalVtxBuffers; mdl_currentModelTreeNodeInfo = &D_80152220; gBackgroundFogModePtr = &wBackgroundFogMode; @@ -2102,9 +2160,9 @@ void clear_model_data(void) { } else { gCurrentModels = &bModelList; gCurrentTransformGroups = &bTransformGroups; - gCurrentCustomModelGfxPtr = &bModelSpecialDls; + gCurrentCustomModelGfxPtr = &bCustomModelGfx; gCurrentCustomModelGfxBuildersPtr = &bCustomModelGfxBuilders; - gCurrentModelTreeRoot = &D_80152218; + gCurrentModelTreeRoot = &bModelTreeRoot; gCurrentModelLocalVtxBuffers = &bModelLocalVtxBuffers; mdl_currentModelTreeNodeInfo = &D_80152A20; gBackgroundFogModePtr = &bBackgroundFogMode; @@ -2153,9 +2211,9 @@ void init_model_data(void) { if (!gGameStatusPtr->isBattle) { gCurrentModels = &wModelList; gCurrentTransformGroups = &wTransformGroups; - gCurrentCustomModelGfxPtr = &wModelSpecialDls; + gCurrentCustomModelGfxPtr = &wCustomModelGfx; gCurrentCustomModelGfxBuildersPtr = &wCustomModelGfxBuilders; - gCurrentModelTreeRoot = &D_80152214; + gCurrentModelTreeRoot = &wModelTreeRoot; gCurrentModelLocalVtxBuffers = &wModelLocalVtxBuffers; mdl_currentModelTreeNodeInfo = &D_80152220; gBackgroundFogModePtr = &wBackgroundFogMode; @@ -2163,9 +2221,9 @@ void init_model_data(void) { } else { gCurrentModels = &bModelList; gCurrentTransformGroups = &bTransformGroups; - gCurrentCustomModelGfxPtr = &bModelSpecialDls; + gCurrentCustomModelGfxPtr = &bCustomModelGfx; gCurrentCustomModelGfxBuildersPtr = &bCustomModelGfxBuilders; - gCurrentModelTreeRoot = &D_80152218; + gCurrentModelTreeRoot = &bModelTreeRoot; gCurrentModelLocalVtxBuffers = &bModelLocalVtxBuffers; mdl_currentModelTreeNodeInfo = &D_80152A20; gBackgroundFogModePtr = &bBackgroundFogMode; @@ -2173,7 +2231,7 @@ void init_model_data(void) { } } -void calculate_model_sizes(void) { +void mdl_calculate_model_sizes(void) { s32 i; for (i = 0; i < ARRAY_COUNT(*gCurrentModels); i++) { @@ -2185,13 +2243,12 @@ void calculate_model_sizes(void) { bb->halfSizeX = (bb->maxX - bb->minX) * 0.5; bb->halfSizeY = (bb->maxY - bb->minY) * 0.5; bb->halfSizeZ = (bb->maxZ - bb->minZ) * 0.5; - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX; + model->flags |= MODEL_FLAG_MATRIX_DIRTY; } } } -void mdl_create_model(ModelBlueprint* bp, s32 arg1) { - EffectInstance* effect; +void mdl_create_model(ModelBlueprint* bp, s32 unused) { ModelNode* node = bp->mdlNode; ModelNodeProperty* prop; ModelBoundingBox* bb; @@ -2208,10 +2265,14 @@ void mdl_create_model(ModelBlueprint* bp, s32 arg1) { prop = get_model_property(node, MODEL_PROP_KEY_BOUNDING_BOX); if (prop != NULL) { ModelBoundingBox* bb = (ModelBoundingBox*) prop; + EffectInstance* effect; - fx_flame( - replaceWithFlame - 1, (bb->minX + bb->maxX) * 0.5f, bb->minY, (bb->minZ + bb->maxZ) * 0.5f, 1.0f, &effect - ); + fx_flame(replaceWithFlame - 1, + (bb->minX + bb->maxX) * 0.5f, + bb->minY, + (bb->minZ + bb->maxZ) * 0.5f, + 1.0f, + &effect); return; } } @@ -2224,12 +2285,13 @@ void mdl_create_model(ModelBlueprint* bp, s32 arg1) { } (*gCurrentModels)[modelIdx] = model = heap_malloc(sizeof(*model)); - model->flags = bp->flags | MODEL_FLAG_FLAG_1; + model->flags = bp->flags | MODEL_FLAG_VALID; model->modelID = D_80153226; model->modelNode = bp->mdlNode; model->groupData = bp->groupData; - model->matrixMode = 0; + model->matrixFreshness = 0; node = model->modelNode; + prop = get_model_property(node, MODEL_PROP_KEY_SPECIAL); if (prop != NULL) { model->texPannerID = prop->data.s & 0xF; @@ -2241,9 +2303,10 @@ void mdl_create_model(ModelBlueprint* bp, s32 arg1) { if (node->type != SHAPE_TYPE_GROUP) { prop = get_model_property(node, MODEL_PROP_KEY_RENDER_MODE); } else { - prop = get_model_property(node, MODEL_PROP_KEY_GROUP_TYPE); + prop = get_model_property(node, MODEL_PROP_KEY_GROUP_INFO); if (prop != NULL) { + // GROUP_INFO properties always come in pairs, with the second giving the render mode prop++; } } @@ -2258,17 +2321,17 @@ void mdl_create_model(ModelBlueprint* bp, s32 arg1) { model->textureVariation = 0; if (!is_identity_fixed_mtx(bp->mtx)) { - model->currentMatrix = heap_malloc(sizeof(*model->currentMatrix)); - *model->currentMatrix = *bp->mtx; - model->specialMatrix = *model->currentMatrix; + model->bakedMtx = heap_malloc(sizeof(*model->bakedMtx)); + *model->bakedMtx = *bp->mtx; + model->savedMtx = *model->bakedMtx; } else { - model->currentMatrix = NULL; - guMtxIdent(&model->specialMatrix); - model->flags |= MODEL_FLAG_FLAG_2000; + model->bakedMtx = NULL; + guMtxIdent(&model->savedMtx); + model->flags |= MODEL_FLAG_IGNORE_MATRIX; } - guMtxIdentF(model->transformMatrix); - model->currentSpecialMatrix = NULL; + guMtxIdentF(model->userTransformMtx); + model->finalMtx = NULL; prop = get_model_property(node, MODEL_PROP_KEY_BOUNDING_BOX); if (prop != NULL) { ModelBoundingBox* bb = (ModelBoundingBox*) prop; @@ -2280,15 +2343,14 @@ void mdl_create_model(ModelBlueprint* bp, s32 arg1) { x = y = z = 0.0f; } - if (model->currentMatrix != NULL) { - guMtxXFML(model->currentMatrix, x, y, z, &x, &y, &z); + if (model->bakedMtx != NULL) { + guMtxXFML(model->bakedMtx, x, y, z, &x, &y, &z); } model->center.x = x; model->center.y = y; model->center.z = z; - bb = (ModelBoundingBox*) prop; x = bb->maxX - bb->minX; y = bb->maxY - bb->minY; @@ -2297,8 +2359,8 @@ void mdl_create_model(ModelBlueprint* bp, s32 arg1) { bb->halfSizeY = y * 0.5; bb->halfSizeZ = z * 0.5; - if (model->currentMatrix == NULL && x < 100.0f && y < 100.0f && z < 100.0f) { - model->flags |= MODEL_FLAG_FLAG_200; + if (model->bakedMtx == NULL && x < 100.0f && y < 100.0f && z < 100.0f) { + model->flags |= MODEL_FLAG_DO_BOUNDS_CULLING; } (*mdl_currentModelTreeNodeInfo)[mdl_treeIterPos].modelIndex = modelIdx; } @@ -2318,98 +2380,124 @@ void iterate_models(void) { mdl = last; } -void func_80116698(void) { - Matrix4f sp20; - Matrix4f sp60; +void mdl_update_transform_matrices(void) { + Matrix4f tempModelMtx; + Matrix4f tempGroupMtx; f32 mX, mY, mZ; f32 mtgX, mtgY, mtgZ; Model* model; - Mtx* mtx; + Mtx* curMtx; ModelBoundingBox* bb; ModelTransformGroup* mtg; s32 i; for (i = 0; i < ARRAY_COUNT(*gCurrentModels); i++) { model = (*gCurrentModels)[i]; - if (model != NULL && (model->flags != 0) && !(model->flags & MODEL_FLAG_FLAG_4)) { - if (!(model->flags & MODEL_FLAG_USES_TRANSFORM_MATRIX)) { - if (model->matrixMode != 0) { - model->matrixMode--; - if (model->matrixMode <= 0) { - model->specialMatrix = *model->currentSpecialMatrix; + if (model != NULL && (model->flags != 0) && !(model->flags & MODEL_FLAG_INACTIVE)) { + if (!(model->flags & MODEL_FLAG_MATRIX_DIRTY)) { + if (model->matrixFreshness != 0) { + // matrix was recalculated recently and stored on the matrix stack + // since DisplayContexts alternate, we can fetch the previous matrix from the other context + model->matrixFreshness--; + if (model->matrixFreshness == 0) { + // since it hasn't changed in a few frames, cache the matrix + model->savedMtx = *model->finalMtx; } - mtx = model->currentSpecialMatrix; - model->currentSpecialMatrix = &gDisplayContext->matrixStack[gMatrixListPos++]; - *model->currentSpecialMatrix = *mtx; + // copy matrix from previous DisplayContext stack to current one + curMtx = model->finalMtx; + model->finalMtx = &gDisplayContext->matrixStack[gMatrixListPos++]; + *model->finalMtx = *curMtx; } else { - model->currentSpecialMatrix = &model->specialMatrix; + // transform matrix is not changed, have gfx build with saved matrix + model->finalMtx = &model->savedMtx; } } else { - model->flags &= ~MODEL_FLAG_USES_TRANSFORM_MATRIX; - model->matrixMode = 2; - mtx = &gDisplayContext->matrixStack[gMatrixListPos++]; - if (model->currentMatrix == NULL || (model->flags & MODEL_FLAG_TRANSFORM_GROUP_MEMBER)) { - guMtxF2L(model->transformMatrix, mtx); + // first frame with dirty matrix, need to recalculate it + model->flags &= ~MODEL_FLAG_MATRIX_DIRTY; + model->matrixFreshness = 2; + + // write matrix to the matrix stack + curMtx = &gDisplayContext->matrixStack[gMatrixListPos++]; + if (model->bakedMtx == NULL || (model->flags & MODEL_FLAG_TRANSFORM_GROUP_MEMBER)) { + guMtxF2L(model->userTransformMtx, curMtx); } else { - guMtxL2F(sp20, model->currentMatrix); - guMtxCatF(model->transformMatrix, sp20, sp20); - guMtxF2L(sp20, mtx); + guMtxL2F(tempModelMtx, model->bakedMtx); + guMtxCatF(model->userTransformMtx, tempModelMtx, tempModelMtx); + guMtxF2L(tempModelMtx, curMtx); } - model->flags &= ~MODEL_FLAG_FLAG_2000; + model->flags &= ~MODEL_FLAG_IGNORE_MATRIX; + + // recalculate the center of the model with transformation applied bb = (ModelBoundingBox*) get_model_property(model->modelNode, MODEL_PROP_KEY_BOUNDING_BOX); mX = (bb->minX + bb->maxX) * 0.5f; mY = (bb->minY + bb->maxY) * 0.5f; mZ = (bb->minZ + bb->maxZ) * 0.5f; - guMtxXFML(mtx, mX, mY, mZ, &mX, &mY, &mZ); - model->currentSpecialMatrix = mtx; + guMtxXFML(curMtx, mX, mY, mZ, &mX, &mY, &mZ); model->center.x = mX; model->center.y = mY; model->center.z = mZ; - model->flags &= ~MODEL_FLAG_FLAG_200; + + // point matrix for gfx building to our matrix on the stack + model->finalMtx = curMtx; + + // disable bounds culling for models with dynamic transformations + model->flags &= ~MODEL_FLAG_DO_BOUNDS_CULLING; } } } for (i = 0; i < ARRAY_COUNT((*gCurrentTransformGroups)); i++) { mtg = (*gCurrentTransformGroups)[i]; - if (mtg != NULL && mtg->flags != 0 && !(mtg->flags & MODEL_TRANSFORM_GROUP_FLAG_4)) { - if (!(mtg->flags & MODEL_TRANSFORM_GROUP_FLAG_1000)) { - if (mtg->matrixMode != 0) { - mtg->matrixMode--; - if (mtg->matrixMode == 0) { - mtg->matrixA = *mtg->transformMtx; + if (mtg != NULL && mtg->flags != 0 && !(mtg->flags & TRANSFORM_GROUP_FLAG_INACTIVE)) { + if (!(mtg->flags & TRANSFORM_GROUP_FLAG_MATRIX_DIRTY)) { + if (mtg->matrixFreshness != 0) { + // matrix was recalculated recently and stored on the matrix stack + // since DisplayContexts alternate, we can fetch the previous matrix from the other context + mtg->matrixFreshness--; + if (mtg->matrixFreshness == 0) { + // since it hasn't changed in a few frames, cache the matrix + mtg->savedMtx = *mtg->finalMtx; } - // store transformMtx on stack - mtx = mtg->transformMtx; - mtg->transformMtx = &gDisplayContext->matrixStack[gMatrixListPos++]; - *mtg->transformMtx = *mtx; + // copy matrix from previous DisplayContext stack to current one + curMtx = mtg->finalMtx; + mtg->finalMtx = &gDisplayContext->matrixStack[gMatrixListPos++]; + *mtg->finalMtx = *curMtx; } else { - mtg->transformMtx = &mtg->matrixA; + // transform matrix is not changed, have gfx build with saved matrix + mtg->finalMtx = &mtg->savedMtx; } } else { - mtg->flags &= ~MODEL_TRANSFORM_GROUP_FLAG_1000; - mtg->matrixMode = 2; - mtx = &gDisplayContext->matrixStack[gMatrixListPos++]; - if (mtg->matrixRDP_N == NULL) { - guMtxF2L(mtg->matrixB, mtx); + // first frame with dirty matrix, need to recalculate it + mtg->flags &= ~TRANSFORM_GROUP_FLAG_MATRIX_DIRTY; + mtg->matrixFreshness = 2; + + // write matrix to the matrix stack + curMtx = &gDisplayContext->matrixStack[gMatrixListPos++]; + if (mtg->bakedMtx == NULL) { + guMtxF2L(mtg->userTransformMtx, curMtx); } else { - guMtxL2F(sp60, mtg->matrixRDP_N); - guMtxCatF(mtg->matrixB, sp60, sp60); - guMtxF2L(sp60, mtx); + guMtxL2F(tempGroupMtx, mtg->bakedMtx); + guMtxCatF(mtg->userTransformMtx, tempGroupMtx, tempGroupMtx); + guMtxF2L(tempGroupMtx, curMtx); } - mtg->flags &= ~MODEL_TRANSFORM_GROUP_FLAG_2000; - bb = (ModelBoundingBox*) get_model_property(mtg->modelNode, MODEL_PROP_KEY_BOUNDING_BOX); + mtg->flags &= ~TRANSFORM_GROUP_FLAG_IGNORE_MATRIX; + + // recalculate the center of the transform group with transformation applied + bb = (ModelBoundingBox*) get_model_property(mtg->baseModelNode, MODEL_PROP_KEY_BOUNDING_BOX); mtgX = (bb->minX + bb->maxX) * 0.5f; mtgY = (bb->minY + bb->maxY) * 0.5f; mtgZ = (bb->minZ + bb->maxZ) * 0.5f; - guMtxXFML(mtx, mtgX, mtgY, mtgZ, &mtgX, &mtgY, &mtgZ); - mtg->transformMtx = mtx; + guMtxXFML(curMtx, mtgX, mtgY, mtgZ, &mtgX, &mtgY, &mtgZ); mtg->center.x = mtgX; mtg->center.y = mtgY; mtg->center.z = mtgZ; + + // point matrix for gfx building to our matrix on the stack + mtg->finalMtx = curMtx; } } } + build_custom_gfx(); } @@ -2421,7 +2509,7 @@ void render_models(void) { f32 m10, m11, m12, m13; f32 m20, m21, m22, m23; f32 m30, m31, m32, m33; - f32 x, y, z; + f32 centerX, centerY, centerZ; f32 bbx, bby, bbz; Camera* camera = &gCameras[gCurrentCameraID]; @@ -2431,10 +2519,10 @@ void render_models(void) { f32 xComp, yComp, zComp; s32 distance; - s32 cond; + s32 notVisible; s32 i; -#define COMMON_RENDER_MODELS \ +#define TEST_POINT_VISIBILITY \ outX = (m00 * xComp) + (m10 * yComp) + (m20 * zComp) + m30; \ outY = (m01 * xComp) + (m11 * yComp) + (m21 * zComp) + m31; \ outZ = (m02 * xComp) + (m12 * yComp) + (m22 * zComp) + m32; \ @@ -2468,6 +2556,7 @@ void render_models(void) { m32 = camera->perspectiveMatrix[3][2]; m33 = camera->perspectiveMatrix[3][3]; + // enqueue all visible models not in transform groups for (i = 0; i < ARRAY_COUNT(*gCurrentModels); i++) { model = (*gCurrentModels)[i]; if (model == NULL) { @@ -2476,25 +2565,27 @@ void render_models(void) { if (model->flags == 0) { continue; } - if (model->flags & MODEL_FLAG_FLAG_4) { + if (model->flags & MODEL_FLAG_INACTIVE) { continue; } if (model->flags & MODEL_FLAG_HIDDEN) { continue; } - if (model->flags & MODEL_FLAG_FLAG_20) { + if (model->flags & MODEL_FLAG_20) { continue; } if (model->flags & MODEL_FLAG_TRANSFORM_GROUP_MEMBER) { continue; } - x = model->center.x; - y = model->center.y; - z = model->center.z; + centerX = model->center.x; + centerY = model->center.y; + centerZ = model->center.z; - if (model->flags & MODEL_FLAG_FLAG_200) { - cond = FALSE; + // for models that are small enough to do bounds culling, only render if at least one + // corner of its boundary box is visible + if (model->flags & MODEL_FLAG_DO_BOUNDS_CULLING) { + notVisible = FALSE; boundingBox = (ModelBoundingBox*) model->modelNode->propertyList; bbx = boundingBox->halfSizeX; bby = boundingBox->halfSizeY; @@ -2502,69 +2593,71 @@ void render_models(void) { while (TRUE) { if (TRUE) { - xComp = x - bbx; - yComp = y - bby; - zComp = z - bbz; - COMMON_RENDER_MODELS; + xComp = centerX - bbx; + yComp = centerY - bby; + zComp = centerZ - bbz; + TEST_POINT_VISIBILITY; } if (bbx != 0.0f) { - xComp = x + bbx; - yComp = y - bby; - zComp = z - bbz; - COMMON_RENDER_MODELS; + xComp = centerX + bbx; + yComp = centerY - bby; + zComp = centerZ - bbz; + TEST_POINT_VISIBILITY; } if (bby != 0.0f) { - xComp = x - bbx; - yComp = y + bby; - zComp = z - bbz; - COMMON_RENDER_MODELS; + xComp = centerX - bbx; + yComp = centerY + bby; + zComp = centerZ - bbz; + TEST_POINT_VISIBILITY; } if (bbx != 0.0f && bby != 0.0f) { - xComp = x + bbx; - yComp = y + bby; - zComp = z - bbz; - COMMON_RENDER_MODELS; + xComp = centerX + bbx; + yComp = centerY + bby; + zComp = centerZ - bbz; + TEST_POINT_VISIBILITY; } if (bbz != 0.0f) { - xComp = x - bbx; - yComp = y - bby; - zComp = z + bbz; - COMMON_RENDER_MODELS; + xComp = centerX - bbx; + yComp = centerY - bby; + zComp = centerZ + bbz; + TEST_POINT_VISIBILITY; } if (bbx != 0.0f && bbz != 0.0f) { - xComp = x + bbx; - yComp = y - bby; - zComp = z + bbz; - COMMON_RENDER_MODELS; + xComp = centerX + bbx; + yComp = centerY - bby; + zComp = centerZ + bbz; + TEST_POINT_VISIBILITY; } if (bby != 0.0f && bbz != 0.0f) { - xComp = x - bbx; - yComp = y + bby; - zComp = z + bbz; - COMMON_RENDER_MODELS; + xComp = centerX - bbx; + yComp = centerY + bby; + zComp = centerZ + bbz; + TEST_POINT_VISIBILITY; } if (bbx != 0.0f && bby != 0.0f && bbz != 0.0f) { - xComp = x + bbx; - yComp = y + bby; - zComp = z + bbz; - COMMON_RENDER_MODELS; + xComp = centerX + bbx; + yComp = centerY + bby; + zComp = centerZ + bbz; + TEST_POINT_VISIBILITY; } - cond = TRUE; + notVisible = TRUE; break; } - if (cond) { + // no points of the models bounding box were visible + if (notVisible) { continue; } } - transform_point(camera->perspectiveMatrix, x, y, z, 1.0f, &outX, &outY, &outZ, &outW); + // map all model depths to the interval [0, 10k] and submit render task + transform_point(camera->perspectiveMatrix, centerX, centerY, centerZ, 1.0f, &outX, &outY, &outZ, &outW); distance = outZ + 5000.0f; if (distance < 0) { distance = 0; @@ -2582,6 +2675,8 @@ void render_models(void) { queue_render_task(rtPtr); } + // enqueue models in transform groups + // only the center of the group is used for depth sorting for (i = 0; i < ARRAY_COUNT(*gCurrentTransformGroups); i++) { transformGroup = (*gCurrentTransformGroups)[i]; if (transformGroup == NULL) { @@ -2592,7 +2687,7 @@ void render_models(void) { continue; } - if (transformGroup->flags & 4) { + if (transformGroup->flags & TRANSFORM_GROUP_FLAG_INACTIVE) { continue; } @@ -2611,7 +2706,7 @@ void render_models(void) { distance = ((outZ / outW) * 10000.0f); - if (!(transformGroup->flags & 2)) { + if (!(transformGroup->flags & TRANSFORM_GROUP_FLAG_HIDDEN)) { rtPtr->appendGfx = render_transform_group; rtPtr->appendGfxArg = transformGroup; rtPtr->distance = -distance; @@ -2652,7 +2747,7 @@ void func_80117D00(Model* model) { ModelNodeProperty* prop; newModel.flags = mdl->flags; - newModel.currentSpecialMatrix = mdl->currentSpecialMatrix; + newModel.finalMtx = mdl->finalMtx; newModel.modelNode = modelNode->groupData->childList[i]; newModel.texPannerID = mdl->texPannerID; newModel.customGfxIndex = mdl->customGfxIndex; @@ -2687,14 +2782,14 @@ void render_transform_group_node(ModelNode* node) { if (node != NULL) { if (node->type == SHAPE_TYPE_GROUP) { - ModelNodeProperty* groupTypeProp = get_model_property(node, MODEL_PROP_KEY_GROUP_TYPE); + ModelNodeProperty* groupInfoProp = get_model_property(node, MODEL_PROP_KEY_GROUP_INFO); - if (groupTypeProp != NULL && groupTypeProp->data.s != 0) { - model = get_model_from_list_index(mdl_currentTransformGroupChildIndex); + if (groupInfoProp != NULL && groupInfoProp->data.s != 0) { + model = get_model_from_list_index(mtg_IterIdx); if (!(model->flags & MODEL_FLAG_HIDDEN)) { appendGfx_model_group(model); } - mdl_currentTransformGroupChildIndex++; + mtg_IterIdx++; return; } } @@ -2704,8 +2799,7 @@ void render_transform_group_node(ModelNode* node) { s32 i; if (node->groupData->transformMatrix != NULL) { - gSPMatrix((*gfx)++, node->groupData->transformMatrix, - G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW); + gSPMatrix((*gfx)++, node->groupData->transformMatrix, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW); } numChildren = node->groupData->numChildren; @@ -2722,28 +2816,28 @@ void render_transform_group_node(ModelNode* node) { return; } - model = get_model_from_list_index(mdl_currentTransformGroupChildIndex); + model = get_model_from_list_index(mtg_IterIdx); if (!(model->flags & MODEL_FLAG_HIDDEN)) { appendGfx_model(model); } - mdl_currentTransformGroupChildIndex++; + mtg_IterIdx++; } } - // gfx temps needed void render_transform_group(void* data) { ModelTransformGroup* group = data; Gfx** gfx = &gMainGfxPos; - if (!(group->flags & MODEL_TRANSFORM_GROUP_FLAG_4)) { - mdl_currentTransformGroupChildIndex = group->minChildModelIndex; - if (!(group->flags & MODEL_TRANSFORM_GROUP_FLAG_2000)) { - gSPMatrix((*gfx)++, group->transformMtx, (G_MTX_PUSH | G_MTX_LOAD) | G_MTX_MODELVIEW); + if (!(group->flags & TRANSFORM_GROUP_FLAG_INACTIVE)) { + mtg_IterIdx = group->minChildModelIndex; + if (!(group->flags & TRANSFORM_GROUP_FLAG_IGNORE_MATRIX)) { + gSPMatrix((*gfx)++, group->finalMtx, (G_MTX_PUSH | G_MTX_LOAD) | G_MTX_MODELVIEW); } - render_transform_group_node(group->modelNode); - if (!(group->flags & MODEL_TRANSFORM_GROUP_FLAG_2000)) { + render_transform_group_node(group->baseModelNode); + + if (!(group->flags & TRANSFORM_GROUP_FLAG_IGNORE_MATRIX)) { gSPPopMatrix((*gfx)++, G_MTX_MODELVIEW); } gDPPipeSync((*gfx)++); @@ -2837,7 +2931,7 @@ void make_texture_gfx(TextureHeader* header, Gfx** gfxPos, IMG_PTR raster, PAL_P renderType = header->extraTiles * 3 + 1 + header->colorCombineSubType; } - **gfxPos = D_8014B0B8[renderType][0]; + **gfxPos = ModelCombineModesA[renderType][0]; (*gfxPos)++; switch (extraTileType) { @@ -3026,11 +3120,11 @@ void load_data_for_models(ModelNode* rootModel, s32 texturesOffset, s32 size) { } void load_model_transforms(ModelNode* model, ModelNode* parent, Matrix4f mdlTransformMtx, s32 treeDepth) { - Matrix4f sp10; + Matrix4f combinedMtx; Mtx sp50; ModelBlueprint modelBP; ModelBlueprint* modelBPptr = &modelBP; - ModelNodeProperty* groupTypeProperty; + ModelNodeProperty* prop; ModelNode* modelTemp; s32 i; @@ -3038,23 +3132,24 @@ void load_model_transforms(ModelNode* model, ModelNode* parent, Matrix4f mdlTran s32 groupType; if (model->groupData->transformMatrix != NULL) { - Matrix4f spA0; + Matrix4f tempMtx; - guMtxL2F(spA0, model->groupData->transformMatrix); - guMtxCatF(spA0, mdlTransformMtx, sp10); + guMtxL2F(tempMtx, model->groupData->transformMatrix); + guMtxCatF(tempMtx, mdlTransformMtx, combinedMtx); } - groupTypeProperty = get_model_property(model, MODEL_PROP_KEY_GROUP_TYPE); - if (groupTypeProperty == NULL) { - groupType = 0; + prop = get_model_property(model, MODEL_PROP_KEY_GROUP_INFO); + if (prop == NULL) { + groupType = GROUP_TYPE_0; } else { - groupType = groupTypeProperty->data.s; + groupType = prop->data.s; } - if (model->type != SHAPE_TYPE_GROUP || groupType == 0) { + if (model->type != SHAPE_TYPE_GROUP || groupType == GROUP_TYPE_0) { for (i = 0; i < model->groupData->numChildren; i++) { load_model_transforms(model->groupData->childList[i], model, - model->groupData->transformMatrix != NULL ? sp10 : mdlTransformMtx, treeDepth + 1); + model->groupData->transformMatrix != NULL ? combinedMtx : mdlTransformMtx, + treeDepth + 1); } (*mdl_currentModelTreeNodeInfo)[mdl_treeIterPos].modelIndex = -1; @@ -3121,7 +3216,6 @@ s32 get_transform_group_index(s32 modelID) { return -1; } -// TODO this seems to be returning center for the model and center for the BB (not the size) void get_model_center_and_size(u16 modelID, f32* centerX, f32* centerY, f32* centerZ, f32* sizeX, f32* sizeY, f32* sizeZ) { Model* model = get_model_from_list_index(get_model_list_index_from_tree_index(modelID)); ModelNode* node = model->modelNode; @@ -3146,23 +3240,26 @@ ModelTransformGroup* get_transform_group(s32 index) { return (*gCurrentTransformGroups)[index]; } +// find group info? void func_8011B1D8(ModelNode* node) { - ModelNode* childNode; + ModelNode* currentNode; ModelNodeProperty* prop; s32 numChildren; s32 i; - u16 childCount; + u16 currentID; + // stop searching if node is a model if (node->type == SHAPE_TYPE_MODEL) { - D_80153376 = D_80153226; + mtg_MaxChild = D_80153226; return; } + // stop searching if node is a group with GROUP_TYPE_0 if (node->type == SHAPE_TYPE_GROUP) { - prop = get_model_property(node, MODEL_PROP_KEY_GROUP_TYPE); - if (prop != NULL && prop->data.s != 0) { + prop = get_model_property(node, MODEL_PROP_KEY_GROUP_INFO); + if (prop != NULL && prop->data.s != GROUP_TYPE_0) { mdl_treeIterPos += mdl_get_child_count(node); - D_80153376 = mdl_treeIterPos; + mtg_MaxChild = mdl_treeIterPos; return; } } @@ -3171,24 +3268,27 @@ void func_8011B1D8(ModelNode* node) { numChildren = node->groupData->numChildren; if (numChildren != 0) { for (i = 0; i < numChildren; i++) { - childNode = node->groupData->childList[i]; - childCount = mdl_treeIterPos; - if (childNode->type == SHAPE_TYPE_GROUP) { - prop = get_model_property(childNode, MODEL_PROP_KEY_GROUP_TYPE); - if (prop != NULL && prop->data.s != 0) { - childCount += mdl_get_child_count(childNode); + currentNode = node->groupData->childList[i]; + currentID = mdl_treeIterPos; + + if (currentNode->type == SHAPE_TYPE_GROUP) { + prop = get_model_property(currentNode, MODEL_PROP_KEY_GROUP_INFO); + if (prop != NULL && prop->data.s != GROUP_TYPE_0) { + currentID += mdl_get_child_count(currentNode); } } - func_8011B1D8(childNode); + func_8011B1D8(currentNode); - if (D_80153370 != NULL) { - break; + if (mtg_FoundModelNode != NULL) { + // not possible + return; } - if (D_8015336E == mdl_treeIterPos) { - D_80153370 = childNode; - D_80153374 = childCount; - break; + // the current model is the one we're looking for + if (mtg_SearchModelID == mdl_treeIterPos) { + mtg_FoundModelNode = currentNode; + mtg_MinChild = currentID; + return; } mdl_treeIterPos++; @@ -3197,15 +3297,15 @@ void func_8011B1D8(ModelNode* node) { } } -void make_transform_group(u16 modelID) { +void mdl_make_transform_group(u16 modelID) { mdl_treeIterPos = 0; - D_80153370 = NULL; - D_8015336E = modelID; - D_80153376 = 0; - D_80153374 = 0; + mtg_FoundModelNode = NULL; + mtg_SearchModelID = modelID; + mtg_MaxChild = 0; + mtg_MinChild = 0; func_8011B1D8(*gCurrentModelTreeRoot); - if (D_80153370 != 0) { + if (mtg_FoundModelNode != NULL) { ModelTransformGroup* newMtg; ModelNode* node; ModelNodeProperty* prop; @@ -3220,33 +3320,34 @@ void make_transform_group(u16 modelID) { } (*gCurrentTransformGroups)[i] = newMtg = heap_malloc(sizeof(*newMtg)); - newMtg->flags = MODEL_TRANSFORM_GROUP_FLAG_1; + newMtg->flags = TRANSFORM_GROUP_FLAG_VALID; newMtg->groupModelID = modelID; - newMtg->minChildModelIndex = get_model_list_index_from_tree_index(D_80153374); - newMtg->maxChildModelIndex = get_model_list_index_from_tree_index(D_80153376); - newMtg->matrixMode = 0; - newMtg->matrixRDP_N = NULL; - newMtg->modelNode = D_80153370; - guMtxIdent(&newMtg->matrixA); - newMtg->flags |= 0x2000; - guMtxIdentF(newMtg->matrixB); + newMtg->minChildModelIndex = get_model_list_index_from_tree_index(mtg_MinChild); + newMtg->maxChildModelIndex = get_model_list_index_from_tree_index(mtg_MaxChild); + newMtg->matrixFreshness = 0; + newMtg->bakedMtx = NULL; + newMtg->baseModelNode = mtg_FoundModelNode; + guMtxIdent(&newMtg->savedMtx); + newMtg->flags |= TRANSFORM_GROUP_FLAG_IGNORE_MATRIX; + guMtxIdentF(newMtg->userTransformMtx); - node = newMtg->modelNode; + node = newMtg->baseModelNode; if (node->type != SHAPE_TYPE_GROUP) { prop = get_model_property(node, MODEL_PROP_KEY_RENDER_MODE); } else { - prop = get_model_property(node, MODEL_PROP_KEY_GROUP_TYPE); + prop = get_model_property(node, MODEL_PROP_KEY_GROUP_INFO); if (prop != NULL) { - prop = &prop[1]; + // GROUP_INFO properties always come in pairs, with the second giving the render mode + prop++; } } if (prop != NULL) { newMtg->renderMode = prop->data.s; } else { - newMtg->renderMode = 1; + newMtg->renderMode = RENDER_MODE_SURFACE_OPA; } bb = (ModelBoundingBox*)get_model_property(node, MODEL_PROP_KEY_BOUNDING_BOX); @@ -3258,8 +3359,8 @@ void make_transform_group(u16 modelID) { x = y = z = 0.0f; } - if (newMtg->matrixRDP_N != NULL) { - guMtxXFML(newMtg->matrixRDP_N, x, y, z, &x, &y, &z); + if (newMtg->bakedMtx != NULL) { + guMtxXFML(newMtg->bakedMtx, x, y, z, &x, &y, &z); } newMtg->center.x = x; @@ -3273,15 +3374,15 @@ void enable_transform_group(u16 modelID) { ModelTransformGroup* group = get_transform_group(get_transform_group_index(modelID)); s32 i; - group->flags &= ~0x4; + group->flags &= ~TRANSFORM_GROUP_FLAG_INACTIVE; for (i = group->minChildModelIndex; i <= group->maxChildModelIndex; i++) { Model* model = get_model_from_list_index(i); model->flags |= MODEL_FLAG_TRANSFORM_GROUP_MEMBER; - if (model->currentMatrix != NULL) { - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX; + if (model->bakedMtx != NULL) { + model->flags |= MODEL_FLAG_MATRIX_DIRTY; } } } @@ -3290,15 +3391,15 @@ void disable_transform_group(u16 modelID) { ModelTransformGroup* group = get_transform_group(get_transform_group_index(modelID)); s32 i; - group->flags |= MODEL_TRANSFORM_GROUP_FLAG_4; + group->flags |= TRANSFORM_GROUP_FLAG_INACTIVE; for (i = group->minChildModelIndex; i <= group->maxChildModelIndex; i++) { Model* model = get_model_from_list_index(i); model->flags &= ~MODEL_FLAG_TRANSFORM_GROUP_MEMBER; - if (model->currentMatrix != NULL) { - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX; + if (model->bakedMtx != NULL) { + model->flags |= MODEL_FLAG_MATRIX_DIRTY; } } } @@ -3377,19 +3478,19 @@ void set_model_group_visibility(u16 treeIndex, s32 flags, s32 mode) { } } -void func_8011B950(u16 treeIndex, s32 customGfxIndex, s32 fogType, s32 arg3) { +void func_8011B950(u16 modelID, s32 customGfxIndex, s32 fogType, s32 arg3) { s32 maxGroupIndex = -1; s32 i; s32 minGroupIndex; - s32 modelIndex = (*mdl_currentModelTreeNodeInfo)[treeIndex].modelIndex; + s32 modelIndex = (*mdl_currentModelTreeNodeInfo)[modelID].modelIndex; s32 siblingIndex; - s32 maskLow, maskHigh, newIndex; + s32 maskLow, maskHigh, packedFogType; if (modelIndex < MAX_MODELS - 1) { minGroupIndex = maxGroupIndex = modelIndex; } else { - s32 treeDepth = (*mdl_currentModelTreeNodeInfo)[treeIndex].treeDepth; - for (i = treeIndex - 1; i >= 0; i--) { + s32 treeDepth = (*mdl_currentModelTreeNodeInfo)[modelID].treeDepth; + for (i = modelID - 1; i >= 0; i--) { if ((*mdl_currentModelTreeNodeInfo)[i].treeDepth <= treeDepth) { break; } @@ -3417,35 +3518,35 @@ void func_8011B950(u16 treeIndex, s32 customGfxIndex, s32 fogType, s32 arg3) { fogType = 0; } - newIndex = customGfxIndex + (fogType << 4); + packedFogType = customGfxIndex + (fogType << 4); if (arg3 == 0) { for (i = minGroupIndex; i <= maxGroupIndex; i++) { Model* model = (*gCurrentModels)[i]; - model->customGfxIndex = (model->customGfxIndex & (maskLow + maskHigh)) + newIndex; + model->customGfxIndex = (model->customGfxIndex & (maskLow + maskHigh)) + packedFogType; } } else { for (i = 0; i < minGroupIndex; i++) { Model* model = (*gCurrentModels)[i]; - model->customGfxIndex = (model->customGfxIndex & (maskLow + maskHigh)) + newIndex; + model->customGfxIndex = (model->customGfxIndex & (maskLow + maskHigh)) + packedFogType; } for (i = maxGroupIndex + 1; i < MAX_MODELS; i++) { Model* model = (*gCurrentModels)[i]; if (model != NULL) { - model->customGfxIndex = (model->customGfxIndex & (maskLow + maskHigh)) + newIndex; + model->customGfxIndex = (model->customGfxIndex & (maskLow + maskHigh)) + packedFogType; } } } } -void func_8011BAE8(void) { +void mdl_reset_transform_flags(void) { s32 i; for (i = 0; i < ARRAY_COUNT(*gCurrentModels); i++) { Model* model = (*gCurrentModels)[i]; if (model != NULL) { - model->flags &= ~MODEL_FLAG_HAS_TRANSFORM_APPLIED; + model->flags &= ~MODEL_FLAG_HAS_TRANSFORM; } } @@ -3453,7 +3554,7 @@ void func_8011BAE8(void) { ModelTransformGroup* transformGroup = (*gCurrentTransformGroups)[i]; if (transformGroup != NULL) { - transformGroup->flags &= ~MODEL_TRANSFORM_GROUP_FLAG_400; + transformGroup->flags &= ~TRANSFORM_GROUP_FLAG_HAS_TRANSFORM; } } } @@ -3658,8 +3759,8 @@ void mdl_get_vertex_count(Gfx* gfx, s32* numVertices, Vtx** baseVtx, s32* gfxCou maxVtx = 0; if (gfx == NULL) { - *numVertices = maxVtx; - *baseVtx = (Vtx*)minVtx; + *numVertices = 0; + *baseVtx = NULL; } else { Gfx* baseGfx = gfx; @@ -3692,7 +3793,7 @@ void mdl_get_vertex_count(Gfx* gfx, s32* numVertices, Vtx** baseVtx, s32* gfxCou *numVertices = (maxVtx - minVtx) >> 4; *baseVtx = (Vtx*)minVtx; *gfxCount = gfx - baseGfx; - w1 = gfx->words.w1; // TODO required to match + w1 = 64; // TODO required to match -- can be any operation that stores w1 } } @@ -3779,7 +3880,7 @@ Gfx* mdl_get_copied_gfx(s32 copyIndex) { return gfxCopy; } -void mdl_project_tex_coords(s32 modelID, Gfx* arg1, Matrix4f arg2, Vtx* arg3) { +void mdl_project_tex_coords(s32 modelID, Gfx* outGfx, Matrix4f arg2, Vtx* arg3) { s32 sp18; Vtx* baseVtx; s32 sp20; @@ -3913,7 +4014,7 @@ void mdl_project_tex_coords(s32 modelID, Gfx* arg1, Matrix4f arg2, Vtx* arg3) { var_f20 = v0tc1 - var_f24 * v0ob0 - var_f26 * v0ob2; // used later } - mdl_get_vertex_count(arg1, &sp18, &baseVtx, &sp20, arg3); + mdl_get_vertex_count(outGfx, &sp18, &baseVtx, &sp20, arg3); for (i = 0; i < sp18; i++) { ob0 = baseVtx->v.ob[0]; @@ -4179,7 +4280,7 @@ void mdl_draw_hidden_panel_surface(Gfx** arg0, u16 treeIndex) { oldGfxPos = gMainGfxPos; gMainGfxPos = *arg0; - copied.flags = MODEL_FLAG_HAS_LOCAL_VERTEX_COPY | MODEL_FLAG_FLAG_1; + copied.flags = MODEL_FLAG_HAS_LOCAL_VERTEX_COPY | MODEL_FLAG_VALID; appendGfx_model(&copied); *arg0 = gMainGfxPos; diff --git a/src/npc.c b/src/npc.c index f6ef1e7422..65f289dcd2 100644 --- a/src/npc.c +++ b/src/npc.c @@ -131,7 +131,7 @@ s32 create_npc_impl(NpcBlueprint* blueprint, AnimID* animList, s32 isPeachNpc) { npc->unk_96 = 0; // TODO: fix npc->verticalRenderOffset = 0; npc->alpha = 255; - npc->alpha2 = 255; + npc->hideAlpha = 255; npc->jumpScale = 1.0f; npc->moveSpeed = 4.0f; npc->scale.x = 1.0f; @@ -964,12 +964,12 @@ void render_npcs(void) { if (npc->flags & NPC_FLAG_HIDING) { u8 r, g, b, a; get_background_color_blend(&r, &g, &b, &a); - npc->alpha2 = 255 - a; + npc->hideAlpha = 255 - a; } else { - npc->alpha2 = 255; + npc->hideAlpha = 255; } - if (npc->alpha2 != 0) { + if (npc->hideAlpha != 0) { queue_render_task(renderTaskPtr); } @@ -1323,7 +1323,7 @@ void npc_draw_palswap_mode_0(Npc* npc, s32 arg1, Matrix4f mtx) { } if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) { - s32 alpha = (npc->alpha * npc->alpha2 / 255); + s32 alpha = (npc->alpha * npc->hideAlpha / 255); u32 mask; if (alpha < 255) { mask = DRAW_SPRITE_OVERRIDE_ALPHA; @@ -1419,7 +1419,7 @@ s32 npc_draw_palswap_mode_1(Npc* npc, s32 arg1, Matrix4f mtx) { } if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) { - s32 alpha = npc->alpha * npc->alpha2 / 255; + s32 alpha = npc->alpha * npc->hideAlpha / 255; u32 mask; if (alpha < 255) { mask = DRAW_SPRITE_OVERRIDE_ALPHA; @@ -1557,7 +1557,7 @@ s32 npc_draw_palswap_mode_2(Npc* npc, s32 arg1, s32 arg2, Matrix4f mtx) { if (npc->palSwapState >= 0) { if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) { u32 mask; - blendAlpha = npc->alpha * npc->alpha2 / 255; + blendAlpha = npc->alpha * npc->hideAlpha / 255; if (blendAlpha < 255) { mask = DRAW_SPRITE_OVERRIDE_ALPHA; } else { @@ -1701,7 +1701,7 @@ s32 npc_draw_palswap_mode_4(Npc* npc, s32 arg1, Matrix4f mtx) { s32 temp; u32 spriteInstanceMask; - blendAlpha = npc->alpha * npc->alpha2 / 255; + blendAlpha = npc->alpha * npc->hideAlpha / 255; temp = blendAlpha < 255; spriteInstanceMask = ((temp) << 31) | DRAW_SPRITE_OVERRIDE_PALETTES; spr_draw_npc_sprite(npc->spriteInstanceID | spriteInstanceMask, arg1, blendAlpha, npc->localPalettes, mtx); diff --git a/src/state_battle.c b/src/state_battle.c index be0ffe0ed2..bef0772e83 100644 --- a/src/state_battle.c +++ b/src/state_battle.c @@ -196,7 +196,7 @@ void state_step_end_battle(void) { } mdl_load_all_textures(mapSettings->modelTreeRoot, get_asset_offset(wMapTexName, &sizeTemp), sizeTemp); - calculate_model_sizes(); + mdl_calculate_model_sizes(); npc_reload_all(); playerStatus->animFlags = D_800A0904; diff --git a/src/state_file_select.c b/src/state_file_select.c index 877bd0b283..7a96ed02b7 100644 --- a/src/state_file_select.c +++ b/src/state_file_select.c @@ -323,7 +323,7 @@ void state_step_exit_language_select(void) { set_background_size(296, 200, 12, 20); } - calculate_model_sizes(); + mdl_calculate_model_sizes(); npc_reload_all(); status_bar_respond_to_changes(); set_time_freeze_mode(TIME_FREEZE_PARTIAL); diff --git a/src/state_pause.c b/src/state_pause.c index ebb7336c59..2d22d6ec7b 100644 --- a/src/state_pause.c +++ b/src/state_pause.c @@ -200,7 +200,7 @@ void state_step_unpause(void) { } gGameStatusPtr->backgroundDarkness = gGameStatusPtr->savedBackgroundDarkness; - calculate_model_sizes(); + mdl_calculate_model_sizes(); npc_reload_all(); set_windows_visible(WINDOW_GROUP_ALL); status_bar_respond_to_changes(); diff --git a/src/world/area_end/end_01/end_01_4_opera_float.c b/src/world/area_end/end_01/end_01_4_opera_float.c index 7ddf9f3838..54afad1a65 100644 --- a/src/world/area_end/end_01/end_01_4_opera_float.c +++ b/src/world/area_end/end_01/end_01_4_opera_float.c @@ -5,7 +5,7 @@ extern s32 N(SpotlightsAlpha); API_CALLABLE(N(SetWorldDark)) { - func_8011B950(MODEL_Root, -1, 1, 0); + func_8011B950(MODEL_Root, CUSTOM_GFX_NONE, FOG_MODE_1, 0); set_background_color_blend(0, 0, 0, 255); return ApiStatus_DONE2; } @@ -23,7 +23,7 @@ API_CALLABLE(N(FadeInWorld)) { set_background_color_blend(0, 0, 0, script->functionTemp[1]); if (script->functionTemp[1] == 0) { - func_8011B950(MODEL_Root, -1, 0, 0); + func_8011B950(MODEL_Root, CUSTOM_GFX_NONE, FOG_MODE_0, 0); return ApiStatus_DONE2; } else { return ApiStatus_BLOCK; @@ -265,7 +265,7 @@ EvtScript N(EVS_UpdateLightshow) = { EVT_CALL(EnableModel, MODEL_kino8, TRUE) EVT_CALL(EnableTexPanning, MODEL_kino8, TRUE) EVT_CALL(SetModelCustomGfx, MODEL_kino7, CUSTOM_GFX_1, -1) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_set_spotlight_alpha)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_set_spotlight_alpha)), NULL) EVT_CHILD_THREAD EVT_CALL(MakeLerp, 0, 255, 90, EASING_LINEAR) EVT_LOOP(0) diff --git a/src/world/area_flo/flo_14/flo_14_3_bubbles.c b/src/world/area_flo/flo_14/flo_14_3_bubbles.c index d5bd1b773a..1ed17d6693 100644 --- a/src/world/area_flo/flo_14/flo_14_3_bubbles.c +++ b/src/world/area_flo/flo_14/flo_14_3_bubbles.c @@ -387,7 +387,7 @@ EvtScript N(EVS_SetupBubbles) = { EVT_SET(LVar0, CLONED_MODEL(5)) EVT_EXEC(N(EVS_ManageBlownBubble)) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_0, MODEL_o167, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_big_bubble)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_big_bubble)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_o167, CUSTOM_GFX_1, -1) EVT_CALL(SetModelCustomGfx, CLONED_MODEL(1), 1, -1) EVT_CALL(SetModelCustomGfx, CLONED_MODEL(2), 1, -1) @@ -395,7 +395,7 @@ EvtScript N(EVS_SetupBubbles) = { EVT_CALL(SetModelCustomGfx, CLONED_MODEL(4), 1, -1) EVT_CALL(SetModelCustomGfx, CLONED_MODEL(5), 1, -1) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_1, MODEL_o57, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_2, EVT_PTR(N(gfx_build_bubble_flower)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_2, EVT_PTR(N(gfx_build_bubble_flower)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_o57, CUSTOM_GFX_2, -1) EVT_RETURN EVT_END diff --git a/src/world/area_hos/hos_03/hos_03_3_model_fx.c b/src/world/area_hos/hos_03/hos_03_3_model_fx.c index 8288010e86..0bd92a50a6 100644 --- a/src/world/area_hos/hos_03/hos_03_3_model_fx.c +++ b/src/world/area_hos/hos_03/hos_03_3_model_fx.c @@ -153,7 +153,7 @@ EvtScript N(EVS_SetupAurora) = { EVT_END_THREAD EVT_CALL(SetTexPanner, MODEL_o160, TEX_PANNER_7) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_0, MODEL_o76, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(build_gfx_aurora)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(build_gfx_aurora)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_o76, CUSTOM_GFX_1, FOG_MODE_UNCHANGED) EVT_RETURN EVT_END diff --git a/src/world/area_jan/common/MoveBush.inc.c b/src/world/area_jan/common/MoveBush.inc.c index d73a59e8b4..bc2f0917bc 100644 --- a/src/world/area_jan/common/MoveBush.inc.c +++ b/src/world/area_jan/common/MoveBush.inc.c @@ -16,12 +16,12 @@ ApiStatus N(MoveBush_AnimateShearing)(Evt* script) { Model* mdl = get_model_from_list_index(modelIndex); Matrix4f mtx; - if (!(mdl->flags & MODEL_FLAG_HAS_TRANSFORM_APPLIED)) { - N(MoveBush_apply_shear_mtx)(mdl->transformMatrix, f); - mdl->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + if (!(mdl->flags & MODEL_FLAG_HAS_TRANSFORM)) { + N(MoveBush_apply_shear_mtx)(mdl->userTransformMtx, f); + mdl->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; } else { N(MoveBush_apply_shear_mtx)(mtx, f); - guMtxCatF(mtx, mdl->transformMatrix, mdl->transformMatrix); + guMtxCatF(mtx, mdl->userTransformMtx, mdl->userTransformMtx); } return ApiStatus_DONE2; } diff --git a/src/world/area_jan/jan_00/jan_00_4_whale.c b/src/world/area_jan/jan_00/jan_00_4_whale.c index c220ef950d..e904ad5c01 100644 --- a/src/world/area_jan/jan_00/jan_00_4_whale.c +++ b/src/world/area_jan/jan_00/jan_00_4_whale.c @@ -218,10 +218,10 @@ EvtScript N(D_8024652C_B26A6C) = { EvtScript N(EVS_802467AC) = { EVT_SET_GROUP(EVT_GROUP_00) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_1, MODEL_karada, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(unkAngleFunc002)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(unkAngleFunc002)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_karada, CUSTOM_GFX_1, -1) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_2, MODEL_onaka, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_2, EVT_PTR(N(unkAngleFunc003)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_2, EVT_PTR(N(unkAngleFunc003)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_onaka, CUSTOM_GFX_2, -1) EVT_THREAD EVT_LABEL(0) diff --git a/src/world/area_kgr/kgr_01/kgr_01_2_wiggle.c b/src/world/area_kgr/kgr_01/kgr_01_2_wiggle.c index 5ffdef8515..9e0a870e63 100644 --- a/src/world/area_kgr/kgr_01/kgr_01_2_wiggle.c +++ b/src/world/area_kgr/kgr_01/kgr_01_2_wiggle.c @@ -107,7 +107,7 @@ EvtScript N(EVS_StartTongueWiggle) = { EVT_CALL(EnableModel, TONGUE_COPY_MODEL_ID, FALSE) EVT_EXEC(N(EVS_WiggleTongue)) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_1, MODEL_sita, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(make_tongue_gfx)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(make_tongue_gfx)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_sita, CUSTOM_GFX_1, -1) EVT_CALL(HidePlayerShadow, TRUE) EVT_RETURN diff --git a/src/world/area_kkj/common/Searchlights.inc.c b/src/world/area_kkj/common/Searchlights.inc.c index ade865e072..35d10b9200 100644 --- a/src/world/area_kkj/common/Searchlights.inc.c +++ b/src/world/area_kkj/common/Searchlights.inc.c @@ -59,10 +59,10 @@ void N(set_spotlight_pos_scale)(s32 modelID, f32 x, f32 y, f32 z, f32 scale) { Matrix4f mtxTemp; Model* model = get_model_from_list_index(get_model_list_index_from_tree_index(modelID)); - guTranslateF(model->transformMatrix, x, y, z); + guTranslateF(model->userTransformMtx, x, y, z); guScaleF(mtxTemp, scale, 1.0f, scale); - guMtxCatF(mtxTemp, model->transformMatrix, model->transformMatrix); - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + guMtxCatF(mtxTemp, model->userTransformMtx, model->userTransformMtx); + model->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; } API_CALLABLE(N(UpdateSearchlight)) { diff --git a/src/world/area_kmr/kmr_02/kmr_02_3_npc.c b/src/world/area_kmr/kmr_02/kmr_02_3_npc.c index 32dfa748da..a7ed502bff 100644 --- a/src/world/area_kmr/kmr_02/kmr_02_3_npc.c +++ b/src/world/area_kmr/kmr_02/kmr_02_3_npc.c @@ -1411,7 +1411,7 @@ API_CALLABLE(N(func_80242F08_8B2F78)) { } API_CALLABLE(N(func_80242F28_8B2F98)) { - func_8011B950(MODEL_kinopi, -1, 1, 1); + func_8011B950(MODEL_kinopi, CUSTOM_GFX_NONE, FOG_MODE_1, 1); set_background_color_blend(0, 0, 0, 255); gCameras[CAM_DEFAULT].bgColor[0] = 0; gCameras[CAM_DEFAULT].bgColor[1] = 0; diff --git a/src/world/area_kmr/kmr_20/kmr_20_11_npc_intro.c b/src/world/area_kmr/kmr_20/kmr_20_11_npc_intro.c index 1859157796..bd3b133402 100644 --- a/src/world/area_kmr/kmr_20/kmr_20_11_npc_intro.c +++ b/src/world/area_kmr/kmr_20/kmr_20_11_npc_intro.c @@ -8,7 +8,7 @@ #define NAME_SUFFIX API_CALLABLE(N(func_80241C9C_8EDABC)) { - func_8011B950(MODEL_g62, -1, 1, 1); + func_8011B950(MODEL_g62, CUSTOM_GFX_NONE, FOG_MODE_1, 1); set_background_color_blend(0, 0, 0, 255); gCameras[CAM_DEFAULT].bgColor[0] = 0; diff --git a/src/world/area_kmr/kmr_20/kmr_20_12_npc_epilogue.c b/src/world/area_kmr/kmr_20/kmr_20_12_npc_epilogue.c index b4e1ca49d6..c1515c0a6d 100644 --- a/src/world/area_kmr/kmr_20/kmr_20_12_npc_epilogue.c +++ b/src/world/area_kmr/kmr_20/kmr_20_12_npc_epilogue.c @@ -7,7 +7,7 @@ #define NAME_SUFFIX API_CALLABLE(N(func_80242030_8EDE50)) { - func_8011B950(MODEL_g62, -1, 0, 1); + func_8011B950(MODEL_g62, CUSTOM_GFX_NONE, FOG_MODE_0, 1); set_background_color_blend(0, 0, 0, 0); gCameras[CAM_DEFAULT].bgColor[0] = 0; diff --git a/src/world/area_kmr/kmr_30/kmr_30_3_the_end.c b/src/world/area_kmr/kmr_30/kmr_30_3_the_end.c index 1b1771a279..d95e667c4c 100644 --- a/src/world/area_kmr/kmr_30/kmr_30_3_the_end.c +++ b/src/world/area_kmr/kmr_30/kmr_30_3_the_end.c @@ -197,7 +197,7 @@ EvtScript N(EVS_Scene_TheEnd) = { EVT_CALL(SetModelCustomGfx, MODEL_e, CUSTOM_GFX_1, -1) EVT_CALL(SetModelCustomGfx, MODEL_d, CUSTOM_GFX_1, -1) EVT_CALL(SetModelCustomGfx, MODEL_n, CUSTOM_GFX_1, -1) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_the_end)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_the_end)), NULL) EVT_CALL(MakeLerp, 0, 255, 90, EASING_LINEAR) EVT_LOOP(0) EVT_CALL(UpdateLerp) diff --git a/src/world/area_mac/mac_00/mac_00_9_water_gfx.c b/src/world/area_mac/mac_00/mac_00_9_water_gfx.c index 6a3ad8f5a0..b715c1298d 100644 --- a/src/world/area_mac/mac_00/mac_00_9_water_gfx.c +++ b/src/world/area_mac/mac_00/mac_00_9_water_gfx.c @@ -27,7 +27,7 @@ void N(gfx_build_water)(void) { EvtScript N(EVS_SetupWaterCustomGfx) = { EVT_WAIT(1) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_0, EVT_PTR(N(gfx_build_water)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_0, EVT_PTR(N(gfx_build_water)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_water, CUSTOM_GFX_0, -1) EVT_RETURN EVT_END diff --git a/src/world/area_mac/mac_00/npc/dojo_members.inc.c b/src/world/area_mac/mac_00/npc/dojo_members.inc.c index 29016d3048..6e6fcbcb91 100644 --- a/src/world/area_mac/mac_00/npc/dojo_members.inc.c +++ b/src/world/area_mac/mac_00/npc/dojo_members.inc.c @@ -17,7 +17,7 @@ API_CALLABLE(N(SetDojoBattle)) { } API_CALLABLE(N(ResetBackgroundPostBattle)) { - func_8011B950(MODEL_minka_1, -1, FOG_MODE_1, 1); + func_8011B950(MODEL_minka_1, CUSTOM_GFX_NONE, FOG_MODE_1, 1); set_background_color_blend(0, 0, 0, 255); gCameras[CAM_DEFAULT].bgColor[0] = 0; gCameras[CAM_DEFAULT].bgColor[1] = 0; diff --git a/src/world/area_mac/mac_01/mac_01_6_crystal_ball_gfx.c b/src/world/area_mac/mac_01/mac_01_6_crystal_ball_gfx.c index aac28551a1..ca1674e532 100644 --- a/src/world/area_mac/mac_01/mac_01_6_crystal_ball_gfx.c +++ b/src/world/area_mac/mac_01/mac_01_6_crystal_ball_gfx.c @@ -128,7 +128,7 @@ EvtScript N(EVS_SetupCrystalBallGfx) = { EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_2, EVT_PTR(N(gfx_build_crystal_ball_pre)), EVT_PTR(N(gfx_build_crystal_ball_post))) EVT_CALL(SetModelCustomGfx, MODEL_mirrorball, CUSTOM_GFX_2, -1) EVT_CALL(EnableModel, MODEL_mirrorball, FALSE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_3, EVT_PTR(N(gfx_build_inside_crystal_ball)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_3, EVT_PTR(N(gfx_build_inside_crystal_ball)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_tama, CUSTOM_GFX_3, -1) EVT_CALL(SetModelFlags, MODEL_tama, MODEL_FLAG_USE_CAMERA_UNK_MATRIX, TRUE) EVT_CALL(SetModelFlags, MODEL_ohosi, MODEL_FLAG_USE_CAMERA_UNK_MATRIX, TRUE) diff --git a/src/world/area_mac/mac_01/mac_01_9_npc.c b/src/world/area_mac/mac_01/mac_01_9_npc.c index f9f0cfda04..17ef672568 100644 --- a/src/world/area_mac/mac_01/mac_01_9_npc.c +++ b/src/world/area_mac/mac_01/mac_01_9_npc.c @@ -256,7 +256,7 @@ API_CALLABLE(N(func_802448A0_805120)) { if (isInitialCall) { if (script->varTable[0] == 0) { - func_8011B950(script->varTable[15], -1, FOG_MODE_1, 1); + func_8011B950(script->varTable[15], CUSTOM_GFX_NONE, FOG_MODE_1, 1); } script->functionTemp[0] = 0; } @@ -279,7 +279,7 @@ API_CALLABLE(N(func_802448A0_805120)) { if (script->functionTemp[0] >= 255) { if (script->varTable[0] == 3) { - func_8011B950(script->varTable[15], -1, FOG_MODE_0, 1); + func_8011B950(script->varTable[15], CUSTOM_GFX_NONE, FOG_MODE_0, 1); } return ApiStatus_DONE2; } diff --git a/src/world/area_mac/mac_01/npc/rowf_and_rhuff.inc.c b/src/world/area_mac/mac_01/npc/rowf_and_rhuff.inc.c index b49aab2d26..447c4910de 100644 --- a/src/world/area_mac/mac_01/npc/rowf_and_rhuff.inc.c +++ b/src/world/area_mac/mac_01/npc/rowf_and_rhuff.inc.c @@ -621,7 +621,7 @@ EvtScript N(EVS_NpcInit_Rowf) = { EVT_END_IF EVT_END_SWITCH EVT_SET(AF_MAC_41, FALSE) - EVT_CALL(SetModelFlags, MODEL_ju_2, MODEL_FLAG_FLAG_200, FALSE) + EVT_CALL(SetModelFlags, MODEL_ju_2, MODEL_FLAG_DO_BOUNDS_CULLING, FALSE) EVT_CALL(EnableGroup, MODEL_jutan1, FALSE) EVT_CALL(ModifyColliderFlags, MODIFY_COLLIDER_FLAGS_SET_BITS, COLLIDER_b1, COLLIDER_FLAGS_UPPER_MASK) EVT_CALL(ModifyColliderFlags, MODIFY_COLLIDER_FLAGS_SET_BITS, COLLIDER_b2, COLLIDER_FLAGS_UPPER_MASK) @@ -631,7 +631,7 @@ EvtScript N(EVS_NpcInit_Rowf) = { EVT_CALL(ScaleGroup, MODEL_jutan2, EVT_FLOAT(1.3), 1, EVT_FLOAT(1.3)) EVT_SET(MV_RowfRugRotateAngle, 60) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_0, MODEL_ju_1, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_0, EVT_PTR(N(gfx_build_rowf_rug_with_ripples)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_0, EVT_PTR(N(gfx_build_rowf_rug_with_ripples)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_ju_1, CUSTOM_GFX_0, -1) EVT_IF_EQ(AF_MAC_40, TRUE) EVT_BIND_TRIGGER(EVT_PTR(N(EVS_EnterBadgeShop)), TRIGGER_FLOOR_TOUCH, COLLIDER_roten, 1, 0) @@ -640,9 +640,9 @@ EvtScript N(EVS_NpcInit_Rowf) = { EVT_END_IF EVT_THREAD EVT_WAIT(5) - EVT_CALL(SetModelFlags, MODEL_b1, MODEL_FLAG_FLAG_4, FALSE) - EVT_CALL(SetModelFlags, MODEL_b2, MODEL_FLAG_FLAG_4, FALSE) - EVT_CALL(SetModelFlags, MODEL_b3, MODEL_FLAG_FLAG_4, FALSE) + EVT_CALL(SetModelFlags, MODEL_b1, MODEL_FLAG_INACTIVE, FALSE) + EVT_CALL(SetModelFlags, MODEL_b2, MODEL_FLAG_INACTIVE, FALSE) + EVT_CALL(SetModelFlags, MODEL_b3, MODEL_FLAG_INACTIVE, FALSE) EVT_CALL(N(HideRowfBadges)) EVT_LABEL(0) EVT_IF_EQ(GF_MAC01_RowfBadgeAvailableA, FALSE) diff --git a/src/world/area_mac/mac_02/mac_02_3_rooms.c b/src/world/area_mac/mac_02/mac_02_3_rooms.c index 1ea54bc0a1..5a863e4c79 100644 --- a/src/world/area_mac/mac_02/mac_02_3_rooms.c +++ b/src/world/area_mac/mac_02/mac_02_3_rooms.c @@ -5,7 +5,7 @@ API_CALLABLE(N(InitEntryFromTunnels)) { Npc* npc; s32 i; - func_8011B950(MODEL_souko, -1, FOG_MODE_1, 1); + func_8011B950(MODEL_souko, CUSTOM_GFX_NONE, FOG_MODE_1, 1); set_background_color_blend(0, 0, 0, 255); gCameras[CAM_DEFAULT].bgColor[0] = 0; gCameras[CAM_DEFAULT].bgColor[1] = 0; diff --git a/src/world/area_mac/mac_04/mac_04_3_rooms.c b/src/world/area_mac/mac_04/mac_04_3_rooms.c index acd1288cbf..4c9e109090 100644 --- a/src/world/area_mac/mac_04/mac_04_3_rooms.c +++ b/src/world/area_mac/mac_04/mac_04_3_rooms.c @@ -3,7 +3,7 @@ s32 set_background_color_blend(s32, s32, s32, s32); API_CALLABLE(N(InitEntryFromToybox)) { - func_8011B950(MODEL_heiho_house, -1, FOG_MODE_1, 1); + func_8011B950(MODEL_heiho_house, CUSTOM_GFX_NONE, FOG_MODE_1, 1); set_background_color_blend(0, 0, 0, 255); gCameras[CAM_DEFAULT].bgColor[0] = 0; gCameras[CAM_DEFAULT].bgColor[1] = 0; diff --git a/src/world/area_mac/mac_05/mac_05_5_whale.c b/src/world/area_mac/mac_05/mac_05_5_whale.c index 4e966b11c3..326f7d9dfd 100644 --- a/src/world/area_mac/mac_05/mac_05_5_whale.c +++ b/src/world/area_mac/mac_05/mac_05_5_whale.c @@ -229,10 +229,10 @@ EvtScript N(D_802516CC_86383C) = { EvtScript N(EVS_8025194C) = { EVT_SET_GROUP(EVT_GROUP_00) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_1, MODEL_karada, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(unkAngleFunc002)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(unkAngleFunc002)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_karada, CUSTOM_GFX_1, -1) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_2, MODEL_onaka, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_2, EVT_PTR(N(unkAngleFunc003)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_2, EVT_PTR(N(unkAngleFunc003)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_onaka, CUSTOM_GFX_2, -1) EVT_THREAD EVT_LABEL(0) diff --git a/src/world/area_mac/mac_05/mac_05_7_club64_sign.c b/src/world/area_mac/mac_05/mac_05_7_club64_sign.c index 468e01c875..ce8cff8e5c 100644 --- a/src/world/area_mac/mac_05/mac_05_7_club64_sign.c +++ b/src/world/area_mac/mac_05/mac_05_7_club64_sign.c @@ -94,7 +94,7 @@ void N(gfx_build_club_64)(s32 index) { EvtScript N(EVS_AnimateClub64Sign) = { EVT_CALL(MakeLocalVertexCopy, VTX_COPY_3, MODEL_o187, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_3, EVT_PTR(N(gfx_build_club_64)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_3, EVT_PTR(N(gfx_build_club_64)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_o187, CUSTOM_GFX_3, -1) EVT_RETURN EVT_END diff --git a/src/world/area_mac/mac_06/mac_06_2_whale.c b/src/world/area_mac/mac_06/mac_06_2_whale.c index 7910346c1f..4e369625cb 100644 --- a/src/world/area_mac/mac_06/mac_06_2_whale.c +++ b/src/world/area_mac/mac_06/mac_06_2_whale.c @@ -225,10 +225,10 @@ EvtScript N(EVS_WhaleState_Walk) = { EvtScript N(EVS_WhaleMain) = { EVT_SET_GROUP(EVT_GROUP_00) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_1, MODEL_karada, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(unkAngleFunc002)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(unkAngleFunc002)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_karada, CUSTOM_GFX_1, -1) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_2, MODEL_onaka, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_2, EVT_PTR(N(unkAngleFunc003)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_2, EVT_PTR(N(unkAngleFunc003)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_onaka, CUSTOM_GFX_2, -1) EVT_CALL(SetNpcVar, NPC_Whale, 0, 0) EVT_THREAD diff --git a/src/world/area_mac/mac_06/mac_06_3_npc.c b/src/world/area_mac/mac_06/mac_06_3_npc.c index 47a8c27b8d..804f5040ad 100644 --- a/src/world/area_mac/mac_06/mac_06_3_npc.c +++ b/src/world/area_mac/mac_06/mac_06_3_npc.c @@ -164,11 +164,11 @@ API_CALLABLE(N(func_802412AC_865DEC)) { Model* model = get_model_from_list_index(modelIndex); f32 x, y, z; - if (model->flags & MODEL_FLAG_HAS_TRANSFORM_APPLIED) { + if (model->flags & MODEL_FLAG_HAS_TRANSFORM) { // get model translation from transform matrix - x = model->transformMatrix[3][0]; - y = model->transformMatrix[3][1]; - z = model->transformMatrix[3][2]; + x = model->userTransformMtx[3][0]; + y = model->userTransformMtx[3][1]; + z = model->userTransformMtx[3][2]; } else { z = 0.0f; y = 0.0f; diff --git a/src/world/area_mgm/mgm_02/mgm_02_2_npc.c b/src/world/area_mgm/mgm_02/mgm_02_2_npc.c index af0661af72..218dc1c10b 100644 --- a/src/world/area_mgm/mgm_02/mgm_02_2_npc.c +++ b/src/world/area_mgm/mgm_02/mgm_02_2_npc.c @@ -696,13 +696,13 @@ API_CALLABLE(N(RunMinigame)) { data->box[i].stateTimer = 0; model = get_model_from_list_index(get_model_list_index_from_tree_index(data->box[i].peachPanelModelID)); model->flags &= ~MODEL_FLAG_HIDDEN; - if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM_APPLIED)) { - guTranslateF(model->transformMatrix, npc->pos.x, npc->pos.y, npc->pos.z); - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM)) { + guTranslateF(model->userTransformMtx, npc->pos.x, npc->pos.y, npc->pos.z); + model->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; } else { guTranslateF(mtx, npc->pos.x, npc->pos.y, npc->pos.z); - guMtxCatF(mtx, model->transformMatrix, model->transformMatrix); + guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx); } } break; @@ -711,12 +711,12 @@ API_CALLABLE(N(RunMinigame)) { npc->pos.y += npc->jumpVelocity; npc->jumpVelocity -= npc->jumpScale; model = get_model_from_list_index(get_model_list_index_from_tree_index(data->box[i].peachPanelModelID)); - if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM_APPLIED)) { - guTranslateF(model->transformMatrix, npc->pos.x, npc->pos.y, npc->pos.z); - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM)) { + guTranslateF(model->userTransformMtx, npc->pos.x, npc->pos.y, npc->pos.z); + model->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; } else { guTranslateF(mtx, npc->pos.x, npc->pos.y, npc->pos.z); - guMtxCatF(mtx, model->transformMatrix, model->transformMatrix); + guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx); } if ((npc->moveToPos.y + 20.0f) < npc->pos.y) { enable_npc_shadow(npc); @@ -742,12 +742,12 @@ API_CALLABLE(N(RunMinigame)) { hittingPeachBlock = TRUE; model = get_model_from_list_index(get_model_list_index_from_tree_index(data->box[i].peachPanelModelID)); centerY = update_lerp(EASING_QUADRATIC_OUT, npc->moveToPos.y, npc->moveToPos.y + 30.0, npc->duration, 30); - if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM_APPLIED)) { - guTranslateF(model->transformMatrix, npc->pos.x, centerY, npc->pos.z); - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + if (!(model->flags & MODEL_FLAG_HAS_TRANSFORM)) { + guTranslateF(model->userTransformMtx, npc->pos.x, centerY, npc->pos.z); + model->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; } else { guTranslateF(mtx, npc->pos.x, centerY, npc->pos.z); - guMtxCatF(mtx, model->transformMatrix, model->transformMatrix); + guMtxCatF(mtx, model->userTransformMtx, model->userTransformMtx); } npc->duration++; if (npc->duration >= 30) { diff --git a/src/world/area_mim/mim_04/mim_04_4_hint.c b/src/world/area_mim/mim_04/mim_04_4_hint.c index 9856d6a808..40483f850a 100644 --- a/src/world/area_mim/mim_04/mim_04_4_hint.c +++ b/src/world/area_mim/mim_04/mim_04_4_hint.c @@ -67,7 +67,7 @@ EvtScript N(EVS_ManageEvilTree) = { }; EvtScript N(EVS_SetupExitHint) = { - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_evil_tree_face)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_evil_tree_face)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_kao, CUSTOM_GFX_1, -1) EVT_CALL(SetModelFlags, MODEL_kao, MODEL_FLAG_USES_CUSTOM_GFX, TRUE) EVT_WAIT(20) diff --git a/src/world/area_mim/mim_07/mim_07_4_hint.c b/src/world/area_mim/mim_07/mim_07_4_hint.c index bf5824ac81..3f41d6c9fb 100644 --- a/src/world/area_mim/mim_07/mim_07_4_hint.c +++ b/src/world/area_mim/mim_07/mim_07_4_hint.c @@ -111,7 +111,7 @@ EvtScript N(EVS_OnInspectEvilRock) = { }; EvtScript N(EVS_SetupExitHint) = { - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_evil_rock_face)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_evil_rock_face)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_o440, CUSTOM_GFX_1, -1) EVT_CALL(SetModelFlags, MODEL_o440, MODEL_FLAG_USES_CUSTOM_GFX, TRUE) EVT_BIND_TRIGGER(EVT_PTR(N(EVS_OnInspectEvilRock)), TRIGGER_WALL_PRESS_A, COLLIDER_o491, 1, 0) diff --git a/src/world/area_nok/nok_04/nok_04_4_npc.c b/src/world/area_nok/nok_04/nok_04_4_npc.c index 2890fefb6e..ab0cb73a33 100644 --- a/src/world/area_nok/nok_04/nok_04_4_npc.c +++ b/src/world/area_nok/nok_04/nok_04_4_npc.c @@ -1478,7 +1478,7 @@ EvtScript N(EVS_SetupMinigame) = { EVT_CALL(EnableNpcShadow, NPC_Fuzzy_01, FALSE) EVT_CALL(EnableNpcShadow, NPC_Fuzzy_02, FALSE) EVT_CALL(EnableNpcShadow, NPC_Fuzzy_03, FALSE) - EVT_CALL(SetModelFlags, MODEL_o177, MODEL_FLAG_FLAG_200, FALSE) + EVT_CALL(SetModelFlags, MODEL_o177, MODEL_FLAG_DO_BOUNDS_CULLING, FALSE) EVT_IF_GE(GB_StoryProgress, STORY_CH1_FUZZY_THIEF_HID_IN_TREE) EVT_CALL(N(GetTreeHidingSpotPos), LVar4, LVar0, LVar1, LVar2) EVT_CALL(SetNpcPos, NPC_BossFuzzy, LVar0, LVar1, LVar2) diff --git a/src/world/area_obk/common/RockingChair.inc.c b/src/world/area_obk/common/RockingChair.inc.c index 26cb8fec20..6daa6e753b 100644 --- a/src/world/area_obk/common/RockingChair.inc.c +++ b/src/world/area_obk/common/RockingChair.inc.c @@ -171,24 +171,24 @@ API_CALLABLE(N(UpdateRockingChair)) { physics->verticalOffset = SQ(physics->rotationAngle) / 90.0f; model = get_model_from_list_index(get_model_list_index_from_tree_index(MODEL_i3)); - model->flags |= (MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED); - guTranslateF(model->transformMatrix, 0.0f, physics->verticalOffset, 0.0f); + model->flags |= (MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM); + guTranslateF(model->userTransformMtx, 0.0f, physics->verticalOffset, 0.0f); guRotateF(tempMtx, physics->rotationAngle, 0.0f, 0.0f, 1.0f); - guMtxCatF(model->transformMatrix, tempMtx, model->transformMatrix); + guMtxCatF(model->userTransformMtx, tempMtx, model->userTransformMtx); update_collider_transform(COLLIDER_i3); update_collider_transform(COLLIDER_i2); model = get_model_from_list_index(get_model_list_index_from_tree_index(MODEL_i2)); - model->flags |= (MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED); - guTranslateF(model->transformMatrix, 0.0f, physics->verticalOffset, 0.0f); + model->flags |= (MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM); + guTranslateF(model->userTransformMtx, 0.0f, physics->verticalOffset, 0.0f); guRotateF(tempMtx, physics->rotationAngle, 0.0f, 0.0f, 1.0f); - guMtxCatF(model->transformMatrix, tempMtx, model->transformMatrix); + guMtxCatF(model->userTransformMtx, tempMtx, model->userTransformMtx); model = get_model_from_list_index(get_model_list_index_from_tree_index(MODEL_i1)); - model->flags |= (MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED); - guTranslateF(model->transformMatrix, 0.0f, physics->verticalOffset, 0.0f); + model->flags |= (MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM); + guTranslateF(model->userTransformMtx, 0.0f, physics->verticalOffset, 0.0f); guRotateF(tempMtx, physics->rotationAngle, 0.0f, 0.0f, 1.0f); - guMtxCatF(model->transformMatrix, tempMtx, model->transformMatrix); + guMtxCatF(model->userTransformMtx, tempMtx, model->userTransformMtx); update_collider_transform(COLLIDER_i1); return ApiStatus_BLOCK; diff --git a/src/world/area_obk/obk_01/obk_01_3_chandelier.c b/src/world/area_obk/obk_01/obk_01_3_chandelier.c index de32ea17b8..7b93fd9f0a 100644 --- a/src/world/area_obk/obk_01/obk_01_3_chandelier.c +++ b/src/world/area_obk/obk_01/obk_01_3_chandelier.c @@ -111,7 +111,7 @@ API_CALLABLE(N(UpdateChandelier)) { } model = chandelier->models[0]; - copy_matrix(model->transformMatrix, chandelier->transformMtx); + copy_matrix(model->userTransformMtx, chandelier->transformMtx); lastDropDistance = 0.0f; chandelier->dropDistance = 0.0f; @@ -247,17 +247,17 @@ API_CALLABLE(N(UpdateChandelier)) { } script->varTable[1] = cabinetPos; - guTranslateF(model->transformMatrix, 0.0f, chandelier->dropDistance - 300.0f, 0.0f); + guTranslateF(model->userTransformMtx, 0.0f, chandelier->dropDistance - 300.0f, 0.0f); guRotateF(tempMtx, chandelier->swingAngle, 0.0f, 0.0f, 1.0f); - guMtxCatF(model->transformMatrix, tempMtx, model->transformMatrix); + guMtxCatF(model->userTransformMtx, tempMtx, model->userTransformMtx); guTranslateF(tempMtx, 0.0f, 300.0f, 0.0f); - guMtxCatF(model->transformMatrix, tempMtx, model->transformMatrix); - guMtxCatF(chandelier->transformMtx, model->transformMatrix, model->transformMatrix); - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + guMtxCatF(model->userTransformMtx, tempMtx, model->userTransformMtx); + guMtxCatF(chandelier->transformMtx, model->userTransformMtx, model->userTransformMtx); + model->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; for (i = 1; i < ARRAY_COUNT(chandelier->models); i++) { - copy_matrix(model->transformMatrix, chandelier->models[i]->transformMatrix); - chandelier->models[i]->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + copy_matrix(model->userTransformMtx, chandelier->models[i]->userTransformMtx); + chandelier->models[i]->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; } if (chandelier->flags & CHANDELIER_FLAG_TETHER_PLAYER) { diff --git a/src/world/area_omo/common/RockingHorse.inc.c b/src/world/area_omo/common/RockingHorse.inc.c index 41c4675394..9d0331be3a 100644 --- a/src/world/area_omo/common/RockingHorse.inc.c +++ b/src/world/area_omo/common/RockingHorse.inc.c @@ -52,12 +52,12 @@ API_CALLABLE(N(UpdateRockingHorses)) { horse->lastRockAngle = rockAngle; } model = get_model_from_list_index(get_model_list_index_from_tree_index(horse->modelID)); - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + model->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; guTranslateF(mtxPivot, -horse->posX, 0.0f, -horse->posZ); guRotateF(mtxRotate, rockAngle, 0.0f, 0.0f, 1.0f); - guMtxCatF(mtxPivot, mtxRotate, model->transformMatrix); + guMtxCatF(mtxPivot, mtxRotate, model->userTransformMtx); guTranslateF(mtxPivot, horse->posX, offsetY, horse->posZ); - guMtxCatF(model->transformMatrix, mtxPivot, model->transformMatrix); + guMtxCatF(model->userTransformMtx, mtxPivot, model->userTransformMtx); } return ApiStatus_BLOCK; } diff --git a/src/world/area_omo/omo_02/omo_02_5_barricade.c b/src/world/area_omo/omo_02/omo_02_5_barricade.c index a01b79a863..bcd740fc45 100644 --- a/src/world/area_omo/omo_02/omo_02_5_barricade.c +++ b/src/world/area_omo/omo_02/omo_02_5_barricade.c @@ -111,7 +111,7 @@ API_CALLABLE(N(AnimateBarricadeParts)) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { - part->transformMatrix[j][k] = model->transformMatrix[j][k]; + part->transformMatrix[j][k] = model->userTransformMtx[j][k]; } } } @@ -150,11 +150,11 @@ API_CALLABLE(N(AnimateBarricadeParts)) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { - model->transformMatrix[j][k] = part->transformMatrix[j][k]; + model->userTransformMtx[j][k] = part->transformMatrix[j][k]; } } - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + model->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; guTranslateF(mtxTransform, part->pos.x - part->origin.x, part->pos.y - part->origin.y, part->pos.z - part->origin.z); part->rot.x += part->angularVelocity.x; part->rot.y += part->angularVelocity.y; @@ -168,7 +168,7 @@ API_CALLABLE(N(AnimateBarricadeParts)) { guMtxCatF(mtxRotZ, mtxRotX, mtxRotX); guMtxCatF(mtxRotX, mtxRotY, mtxRotY); guMtxCatF(mtxRotY, mtxTransform, mtxTransform); - guMtxCatF(model->transformMatrix, mtxTransform, model->transformMatrix); + guMtxCatF(model->userTransformMtx, mtxTransform, model->userTransformMtx); } if ((u32) script->functionTemp[1] >= ARRAY_COUNT(N(BarricadeModels))) { diff --git a/src/world/area_omo/omo_11/omo_11_3_gizmos.c b/src/world/area_omo/omo_11/omo_11_3_gizmos.c index dc755021fe..ea89e20ec1 100644 --- a/src/world/area_omo/omo_11/omo_11_3_gizmos.c +++ b/src/world/area_omo/omo_11/omo_11_3_gizmos.c @@ -142,7 +142,7 @@ API_CALLABLE(N(UpdateRotatingPlatforms)) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { - it->transformMatrix[j][k] = loopModel->transformMatrix[j][k]; + it->transformMatrix[j][k] = loopModel->userTransformMtx[j][k]; } } @@ -155,7 +155,7 @@ API_CALLABLE(N(UpdateRotatingPlatforms)) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { - it->transformMatrix[j][k] = loopModel->transformMatrix[j][k]; + it->transformMatrix[j][k] = loopModel->userTransformMtx[j][k]; } } } @@ -167,11 +167,11 @@ API_CALLABLE(N(UpdateRotatingPlatforms)) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { - loopModel->transformMatrix[j][k] = it->transformMatrix[j][k]; + loopModel->userTransformMtx[j][k] = it->transformMatrix[j][k]; } } - loopModel->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + loopModel->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; guTranslateF(sp20, it->relativePos.x, it->relativePos.y, it->relativePos.z); guRotateF(spA0, script->functionTemp[1], 0.0f, 0.0f, 1.0f); guTranslateF(sp60, -it->relativePos.x, -it->relativePos.y, -it->relativePos.z); @@ -179,9 +179,9 @@ API_CALLABLE(N(UpdateRotatingPlatforms)) { guMtxCatF(sp20, spA0, spA0); guMtxCatF(spA0, sp60, sp60); guMtxCatF(spE0, sp60, sp60); - guMtxCatF(loopModel->transformMatrix, sp60, loopModel->transformMatrix); + guMtxCatF(loopModel->userTransformMtx, sp60, loopModel->userTransformMtx); update_collider_transform(N(RotatingPlatformColliders)[i]); - guMtxXFMF(loopModel->transformMatrix, 0.0f, 0.0f, 0.0f, &ox, &oy, &oz); + guMtxXFMF(loopModel->userTransformMtx, 0.0f, 0.0f, 0.0f, &ox, &oy, &oz); if (gCollisionStatus.currentFloor == N(RotatingPlatformColliders)[i] || gCollisionStatus.lastTouchedFloor == N(RotatingPlatformColliders)[i]) { @@ -199,12 +199,12 @@ API_CALLABLE(N(UpdateRotatingPlatforms)) { it->lastRelativePos.z = oz; } - guRotateF(axisModel->transformMatrix, script->functionTemp[1], 0.0f, 0.0f, 1.0f); - axisModel->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + guRotateF(axisModel->userTransformMtx, script->functionTemp[1], 0.0f, 0.0f, 1.0f); + axisModel->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; update_collider_transform(COLLIDER_fl); - guRotateF(ringModel->transformMatrix, script->functionTemp[1], 0.0f, 0.0f, 1.0f); - ringModel->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + guRotateF(ringModel->userTransformMtx, script->functionTemp[1], 0.0f, 0.0f, 1.0f); + ringModel->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; update_collider_transform(COLLIDER_1_0); isPounding = FALSE; diff --git a/src/world/area_sam/sam_06/sam_06_4_npc.c b/src/world/area_sam/sam_06/sam_06_4_npc.c index 0f250fdadb..3d5c361577 100644 --- a/src/world/area_sam/sam_06/sam_06_4_npc.c +++ b/src/world/area_sam/sam_06/sam_06_4_npc.c @@ -286,7 +286,7 @@ API_CALLABLE(N(func_80242538_D223C8)) { if (isInitialCall) { if (script->varTable[0] == 0) { - func_8011B950(script->varTable[15], -1, FOG_MODE_1, 1); + func_8011B950(script->varTable[15], CUSTOM_GFX_NONE, FOG_MODE_1, 1); } script->functionTemp[0] = 0; } @@ -309,7 +309,7 @@ API_CALLABLE(N(func_80242538_D223C8)) { if (script->functionTemp[0] >= 255) { if (script->varTable[0] == 3) { - func_8011B950(script->varTable[15], -1, FOG_MODE_0, 1); + func_8011B950(script->varTable[15], CUSTOM_GFX_NONE, FOG_MODE_0, 1); } return ApiStatus_DONE2; } diff --git a/src/world/area_sam/sam_07/sam_07_4_frozen_pit.c b/src/world/area_sam/sam_07/sam_07_4_frozen_pit.c index f253358be3..72e4565d35 100644 --- a/src/world/area_sam/sam_07/sam_07_4_frozen_pit.c +++ b/src/world/area_sam/sam_07/sam_07_4_frozen_pit.c @@ -63,7 +63,7 @@ API_CALLABLE(N(AnimateIceShattering)) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { - it->transformMatrix[j][k] = model->transformMatrix[j][k]; + it->transformMatrix[j][k] = model->userTransformMtx[j][k]; } } } @@ -87,11 +87,11 @@ API_CALLABLE(N(AnimateIceShattering)) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { - model->transformMatrix[j][k] = it->transformMatrix[j][k]; + model->userTransformMtx[j][k] = it->transformMatrix[j][k]; } } - model->flags |= MODEL_FLAG_USES_TRANSFORM_MATRIX | MODEL_FLAG_HAS_TRANSFORM_APPLIED; + model->flags |= MODEL_FLAG_MATRIX_DIRTY | MODEL_FLAG_HAS_TRANSFORM; guTranslateF(mtxTransform, it->pos.x - it->initialPos.x, it->pos.y - it->initialPos.y, it->pos.z - it->initialPos.z); it->rot.x += it->rotVel.x; it->rot.y += it->rotVel.y; @@ -105,7 +105,7 @@ API_CALLABLE(N(AnimateIceShattering)) { guMtxCatF(mtxRotZ, mtxRotX, mtxRotX); guMtxCatF(mtxRotX, mtxRotY, mtxRotY); guMtxCatF(mtxRotY, mtxTransform, mtxTransform); - guMtxCatF(mtxTransform, model->transformMatrix, model->transformMatrix); + guMtxCatF(mtxTransform, model->userTransformMtx, model->userTransformMtx); } if ((u32) script->functionTemp[1] >= ARRAY_COUNT(N(IceShardModels))) { diff --git a/src/world/area_tst/tst_04/tst_04_3_reflection.c b/src/world/area_tst/tst_04/tst_04_3_reflection.c index 338a7a7ce0..0c24f09577 100644 --- a/src/world/area_tst/tst_04/tst_04_3_reflection.c +++ b/src/world/area_tst/tst_04/tst_04_3_reflection.c @@ -25,7 +25,7 @@ void N(worker_render_player_reflection)(void) { if (playerStatus->flags & PS_FLAG_HAS_REFLECTION) { entityModel = get_entity_model(get_shadow_by_index(playerStatus->shadowID)->entityModelID); - entityModel->flags |= MODEL_FLAG_FLAG_200; + entityModel->flags |= ENTITY_MODEL_FLAG_REFLECT; get_screen_coords(gCurrentCamID, playerStatus->position.x, playerStatus->position.y, -playerStatus->position.z, &screenX, &screenY, &screenZ); diff --git a/src/world/area_tst/tst_13/tst_13_1_main.c b/src/world/area_tst/tst_13/tst_13_1_main.c index 2e7146cd60..53d43eada6 100644 --- a/src/world/area_tst/tst_13/tst_13_1_main.c +++ b/src/world/area_tst/tst_13/tst_13_1_main.c @@ -296,7 +296,7 @@ void N(build_gfx_floor)(void) { guScaleF(sp50, x, y, z); guMtxCatF(sp50, sp10, sp10); guMtxF2L(sp10, &gDisplayContext->matrixStack[gMatrixListPos]); - mdl_project_tex_coords(1, N(shockwave_gfx), sp10, NULL); + mdl_project_tex_coords(MODEL_o152, N(shockwave_gfx), sp10, NULL); gDPPipeSync(gMainGfxPos++); gDPSetCycleType(gMainGfxPos++, G_CYC_1CYCLE); diff --git a/src/world/common/atomic/UnkFunc27.inc.c b/src/world/common/atomic/UnkFunc27.inc.c index 7708fb575e..d3a724da60 100644 --- a/src/world/common/atomic/UnkFunc27.inc.c +++ b/src/world/common/atomic/UnkFunc27.inc.c @@ -34,7 +34,7 @@ API_CALLABLE(N(UnkFunc27)) { if (*modelIDList == 0xFFFF) { break; } - func_8011B950(*modelIDList, -1, fogType, 0); + func_8011B950(*modelIDList, CUSTOM_GFX_NONE, fogType, 0); modelIDList++; }; break; diff --git a/src/world/dead/area_flo/flo_14/flo_14_3_bubbles.c b/src/world/dead/area_flo/flo_14/flo_14_3_bubbles.c index 1f3fe89979..3e693ecef6 100644 --- a/src/world/dead/area_flo/flo_14/flo_14_3_bubbles.c +++ b/src/world/dead/area_flo/flo_14/flo_14_3_bubbles.c @@ -387,7 +387,7 @@ EvtScript N(EVS_SetupBubbles) = { EVT_SET(LVar0, CLONED_MODEL(5)) EVT_EXEC(N(EVS_ManageBlownBubble)) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_0, MODEL_o167, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_big_bubble)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_1, EVT_PTR(N(gfx_build_big_bubble)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_o167, CUSTOM_GFX_1, -1) EVT_CALL(SetModelCustomGfx, CLONED_MODEL(1), CUSTOM_GFX_1, -1) EVT_CALL(SetModelCustomGfx, CLONED_MODEL(2), CUSTOM_GFX_1, -1) @@ -395,7 +395,7 @@ EvtScript N(EVS_SetupBubbles) = { EVT_CALL(SetModelCustomGfx, CLONED_MODEL(4), CUSTOM_GFX_1, -1) EVT_CALL(SetModelCustomGfx, CLONED_MODEL(5), CUSTOM_GFX_1, -1) EVT_CALL(MakeLocalVertexCopy, VTX_COPY_1, MODEL_o57, TRUE) - EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_2, EVT_PTR(N(gfx_build_bubble_flower)), 0) + EVT_CALL(SetCustomGfxBuilders, CUSTOM_GFX_2, EVT_PTR(N(gfx_build_bubble_flower)), NULL) EVT_CALL(SetModelCustomGfx, MODEL_o57, CUSTOM_GFX_2, -1) EVT_RETURN EVT_END diff --git a/src/world/script_api/rooms.c b/src/world/script_api/rooms.c index adce85f64a..57e34ecdad 100644 --- a/src/world/script_api/rooms.c +++ b/src/world/script_api/rooms.c @@ -257,7 +257,7 @@ API_CALLABLE(RoomVisibilityToggleImpl) { if (isInitialCall) { if (script->varTable[0] == ROOM_VISIBILITY_SHOW) { - func_8011B950(script->varTable[15], -1, FOG_MODE_1, 1); + func_8011B950(script->varTable[15], CUSTOM_GFX_NONE, FOG_MODE_1, 1); } script->functionTemp[1] = 0; } @@ -281,7 +281,7 @@ API_CALLABLE(RoomVisibilityToggleImpl) { if (script->functionTemp[1] >= 255) { if (script->varTable[0] == ROOM_VISIBILITY_HIDE) { // ROOM_DATA_MODEL_ID - func_8011B950(script->varTable[15], -1, FOG_MODE_0, 1); + func_8011B950(script->varTable[15], CUSTOM_GFX_NONE, FOG_MODE_0, 1); } return ApiStatus_DONE2; } else { diff --git a/src/world/script_api/shops.c b/src/world/script_api/shops.c index f7dacb3c5f..a4a1e83782 100644 --- a/src/world/script_api/shops.c +++ b/src/world/script_api/shops.c @@ -197,8 +197,8 @@ API_CALLABLE(func_802803C8) { } API_CALLABLE(func_80280410) { - static Evt* D_80286520; - static s32 D_80286524; + static Evt* ShopInteractScript; + static s32 ShopInteractScriptID; Shop* shop = gGameStatusPtr->mapShop; s32 currentItemSlot = evt_get_variable(script, *script->ptrReadPos); @@ -210,7 +210,6 @@ API_CALLABLE(func_80280410) { shop->unk_358 = 5; if (gGameStatusPtr->pressedButtons[0] & BUTTON_A) { - Evt* childScript; disable_player_input(); @@ -218,14 +217,14 @@ API_CALLABLE(func_80280410) { childScript = start_script(&BadgeShopInteract, EVT_PRIORITY_1, 0); childScript->varTable[0] = currentItemSlot; - D_80286520 = childScript; - D_80286524 = childScript->id; + ShopInteractScript = childScript; + ShopInteractScriptID = childScript->id; shop->flags |= SHOP_FLAG_8; return ApiStatus_BLOCK; } else { return ApiStatus_DONE2; } - } else if (does_script_exist(D_80286524)) { + } else if (does_script_exist(ShopInteractScriptID)) { return ApiStatus_BLOCK; } @@ -930,7 +929,7 @@ API_CALLABLE(MakeShop) { gGameStatusPtr->shopItemEntities[numShopItems].pos.y = centerY; gGameStatusPtr->shopItemEntities[numShopItems].pos.z = centerZ; model = get_model_from_list_index(get_model_list_index_from_tree_index(itemDataPositions->posModelID)); - model->flags |= MODEL_FLAG_FLAG_4; + model->flags |= MODEL_FLAG_INACTIVE; gGameStatusPtr->shopItemEntities[numShopItems].index = make_item_entity_nodelay(inventory->itemID | shop->inventoryItemFlags, centerX, centerY, centerZ, 1, 0); set_item_entity_flags(gGameStatusPtr->shopItemEntities[numShopItems].index, ITEM_ENTITY_RESIZABLE); @@ -951,7 +950,7 @@ API_CALLABLE(MakeShop) { gWindowStyles[11].defaultStyleID = WINDOW_STYLE_3; shop->currentItemSlot = 0; shop->selectedStoreItemSlot = 0; - shop->flags = SHOP_FLAG_0; + shop->flags = 0; shop->owner = NULL; return ApiStatus_DONE2; diff --git a/tools/build/configure.py b/tools/build/configure.py index f42f2d334e..ad9cff68af 100755 --- a/tools/build/configure.py +++ b/tools/build/configure.py @@ -101,19 +101,31 @@ def write_ninja_rules( command=f"{cross}ld {ld_args}", ) + ninja.rule( + "shape_ld", + description="link($version) shape $out", + command=f"{cross}ld -T src/map_shape.ld $in -o $out", + ) + + ninja.rule( + "shape_objcopy", + description="objcopy($version) shape $out", + command=f"{cross}objcopy $in $out -O binary", + ) + Z64_DEBUG = "" if debug: - Z64_DEBUG = "-gS -R .data -R .note -R .eh_frame -R .gnu.attributes -R .comment -R .options" + Z64_DEBUG = " -gS -R .data -R .note -R .eh_frame -R .gnu.attributes -R .comment -R .options" ninja.rule( "z64", description="rom $out", - command=f"{cross}objcopy $in $out -O binary {Z64_DEBUG} && {BUILD_TOOLS}/rom/n64crc $out", + command=f"{cross}objcopy $in $out -O binary{Z64_DEBUG} && {BUILD_TOOLS}/rom/n64crc $out", ) ninja.rule( "z64_ique", description="rom $out", - command=f"{cross}objcopy $in $out -O binary {Z64_DEBUG}", + command=f"{cross}objcopy $in $out -O binary{Z64_DEBUG}", ) ninja.rule( @@ -174,6 +186,12 @@ def write_ninja_rules( command=f"{cross}ld -r -b binary $in -o $out", ) + ninja.rule( + "cp", + description="cp $in $out", + command=f"cp $in $out", + ) + ninja.rule( "as", description="as $in", @@ -268,22 +286,24 @@ def write_ninja_rules( "map_header", command=f"$python {BUILD_TOOLS}/mapfs/map_header.py $in > $out" ) - ninja.rule("pm_charset", command=f"$python {BUILD_TOOLS}/pm_charset.py $out $in") + ninja.rule("charset", command=f"$python {BUILD_TOOLS}/pm_charset.py $out $in") ninja.rule( - "pm_charset_palettes", + "charset_palettes", command=f"$python {BUILD_TOOLS}/pm_charset_palettes.py $out $in", ) ninja.rule( - "pm_sprite_shading_profiles", + "sprite_shading_profiles", command=f"$python {BUILD_TOOLS}/sprite/sprite_shading_profiles.py $in $out $header_path", ) ninja.rule( - "pm_imgfx_data", command=f"$python {BUILD_TOOLS}/imgfx/imgfx_data.py $in $out" + "imgfx_data", command=f"$python {BUILD_TOOLS}/imgfx/imgfx_data.py $in $out" ) + ninja.rule("shape", command=f"$python {BUILD_TOOLS}/mapfs/shape.py $in $out") + with Path("tools/permuter_settings.toml").open("w") as f: f.write( f"compiler_command = \"{cc} {CPPFLAGS.replace('$version', 'pal')} {cflags} -DPERMUTER -fforce-addr\"\n" @@ -444,6 +464,7 @@ class Configure: skip_outputs: Set[str], non_matching: bool, modern_gcc: bool, + c_maps: bool = False, ): import segtypes import segtypes.common.c @@ -906,7 +927,6 @@ class Configure: build(bin_path, imgs, "pack_title_data") elif name.endswith("_bg"): compress = True - bin_path = self.build_path() / bin_path build( bin_path, [path], @@ -929,34 +949,39 @@ class Configure: }, asset_deps=[f"mapfs/tex/{name}"], ) - elif name.endswith("_shape"): - map_name = "_".join(name.split("_")[:-1]) - - # Handle map XML files, if they exist (TODO: have splat output these) - map_xml = self.resolve_asset_path( - Path(f"assets/{self.version}") - / seg.dir - / seg.name - / (map_name + ".xml") + elif name.endswith("_shape_built"): + base_name = name[:-6] + raw_bin_path = self.resolve_asset_path( + f"assets/x/mapfs/geom/{base_name}.bin" ) - if map_xml.exists(): - # Build a header file for this map - build( - self.build_path() - / "include" - / seg.dir - / seg.name - / (map_name + ".h"), - [map_xml], - "map_header", - ) + bin_path = bin_path.parent / "geom" / (base_name + ".bin") - # NOTE: we don't build the map xml into a _shape or _hit file (yet); the Star Rod Map Editor - # is able to build the xml nonmatchingly into assets/star_rod_build/mapfs/*.bin for people - # who want that (i.e. modders). 'star_rod_build' should be added to asset_stack also. + if c_maps: + # raw bin -> c -> o -> elf -> objcopy -> final bin file + c_file_path = ( + bin_path.parent / "geom" / base_name + ).with_suffix(".c") + o_path = bin_path.parent / "geom" / (base_name + ".o") + elf_path = bin_path.parent / "geom" / (base_name + ".elf") + + build(c_file_path, [raw_bin_path], "shape") + build( + o_path, + [c_file_path], + "cc" if not modern_gcc else "cc_modern", + variables={ + "cflags": "", + "cppflags": f"-DVERSION_{self.version.upper()}", + "encoding": "CP932", # similar to SHIFT-JIS, but includes backslash and tilde + }, + ) + build(elf_path, [o_path], "shape_ld") + build(bin_path, [elf_path], "shape_objcopy") + else: + build(bin_path, [raw_bin_path], "cp") compress = True - bin_path = path + out_dir = out_dir / "geom" else: compress = True bin_path = path @@ -994,7 +1019,7 @@ class Configure: ) rasters.append(out_path) - build(entry.object_path.with_suffix(""), rasters, "pm_charset") + build(entry.object_path.with_suffix(""), rasters, "charset") build(entry.object_path, [entry.object_path.with_suffix("")], "bin") elif seg.type == "pm_charset_palettes": palettes = [] @@ -1018,9 +1043,7 @@ class Configure: ) palettes.append(out_path) - build( - entry.object_path.with_suffix(""), palettes, "pm_charset_palettes" - ) + build(entry.object_path.with_suffix(""), palettes, "charset_palettes") build(entry.object_path, [entry.object_path.with_suffix("")], "bin") elif seg.type == "pm_sprite_shading_profiles": header_path = str( @@ -1029,7 +1052,7 @@ class Configure: build( entry.object_path.with_suffix(""), entry.src_paths, - "pm_sprite_shading_profiles", + "sprite_shading_profiles", implicit_outputs=[header_path], variables={ "header_path": header_path, @@ -1040,7 +1063,7 @@ class Configure: c_file_path = ( Path(f"assets/{self.version}") / "imgfx" / (seg.name + ".c") ) - build(c_file_path, entry.src_paths, "pm_imgfx_data") + build(c_file_path, entry.src_paths, "imgfx_data") build( entry.object_path, @@ -1163,6 +1186,11 @@ if __name__ == "__main__": help="Use modern GCC instead of the original compiler", ) parser.add_argument("--ccache", action="store_true", help="Use ccache") + parser.add_argument( + "--c-maps", + action="store_true", + help="Convert map binaries to C as part of the build process", + ) args = parser.parse_args() exec_shell(["make", "-C", str(ROOT / args.splat)]) @@ -1296,7 +1324,9 @@ if __name__ == "__main__": configure.split( not args.no_split_assets, args.split_code, args.shift, args.debug ) - configure.write_ninja(ninja, skip_files, non_matching, args.modern_gcc) + configure.write_ninja( + ninja, skip_files, non_matching, args.modern_gcc, args.c_maps + ) all_rom_oks.append(str(configure.rom_ok_path())) diff --git a/tools/build/mapfs/shape.py b/tools/build/mapfs/shape.py new file mode 100755 index 0000000000..2f85e85ebe --- /dev/null +++ b/tools/build/mapfs/shape.py @@ -0,0 +1,715 @@ +import argparse +from pathlib import Path +import struct +from abc import ABC +from collections import deque +from io import TextIOWrapper +from typing import List, Dict, Optional + +BASE_ADDR = 0x80210000 + +NODE_TYPE_ROOT = 7 +NODE_TYPE_MODEL = 2 +NODE_TYPE_GROUP = 5 +NODE_TYPE_SPECIAL_GROUP = 10 + +GFX_LOAD_VTX = 0x01 +GFX_DRAW_TRI = 0x05 +GFX_DRAW_TRIS = 0x06 +GFX_RDP_PIPE_SYNC = 0xE7 +GFX_POP_MATRIX = 0xD8 +GFX_GEOMETRYMODE = 0xD9 +GFX_LOAD_MATRIX = 0xDA +GFX_START_DL = 0xDE +GFX_END_DL = 0xDF + +ALIGN_16 = "__attribute__ ((aligned (16))) " + + +def read_ascii_string(bytes: bytearray, addr: int) -> str: + start = addr - BASE_ADDR + length = 0 + + for char in bytes[start:]: + if char == 0: + break + length += 1 + + return bytes[start : start + length].decode("ascii") + + +def get_shape_type_name(id: int) -> str: + if id == NODE_TYPE_ROOT: + return "SHAPE_TYPE_ROOT" + elif id == NODE_TYPE_MODEL: + return "SHAPE_TYPE_MODEL" + elif id == NODE_TYPE_GROUP: + return "SHAPE_TYPE_GROUP" + elif id == NODE_TYPE_SPECIAL_GROUP: + return "SHAPE_TYPE_SPECIAL_GROUP" + raise Exception(f"Unknown shape type {id}") + + +class Segment(ABC): + def __init__(self, addr: int, name: str): + self.addr = addr + self.name = name + self.count = 0 + self.model_name = "" + + def get_sym(self) -> str: + if self.model_name != "": + return f"N({self.name}_{self.model_name})" + else: + return f"N({self.name})" + + def __str__(self): + return str(self.__class__.__name__[:-7]) + " " + self.get_sym() + + def scan(self, shape): + pass + + def print(self, shape): + shape.print(hex(self.addr) + " : " + str(self)) + + +class HeaderSegment(Segment): + def __init__(self, addr: int, name: str): + super().__init__(addr, name) + + def scan(self, shape): + start = self.addr - BASE_ADDR + ( + self.ptr_root_node, + self.ptr_vtx_table, + self.ptr_model_names, + self.ptr_collider_names, + self.ptr_zone_names, + ) = struct.unpack(">IIIII", shape.file_bytes[start : start + 20]) + + # note: do not push model root yet + shape.root_node = NodeSegment(self.ptr_root_node, "Node") + + shape.vtx_table = shape.push( + VertexTableSegment(self.ptr_vtx_table, "VertexTable") + ) + shape.model_names = shape.push( + StringListSegment(self.ptr_model_names, "ModelNames") + ) + shape.collider_names = shape.push( + StringListSegment(self.ptr_collider_names, "ColliderNames") + ) + shape.zone_names = shape.push( + StringListSegment(self.ptr_zone_names, "ZoneNames") + ) + + def print(self, shape): + shape.print(f"ShapeFileHeader {self.get_sym()} = {{") + shape.print(f" .root = &{shape.get_symbol(self.ptr_root_node)},") + shape.print(f" .vertexTable = {shape.get_symbol(self.ptr_vtx_table)},") + shape.print(f" .modelNames = {shape.get_symbol(self.ptr_model_names)},") + shape.print( + f" .colliderNames = {shape.get_symbol(self.ptr_collider_names)}," + ) + if self.ptr_zone_names != 0: + shape.print(f" .zoneNames = {shape.get_symbol(self.ptr_zone_names)},") + shape.print("};") + + +class VertexTableSegment(Segment): + def __init__(self, addr: int, name: str): + super().__init__(addr, name) + + def print(self, shape): + pos = self.addr - BASE_ADDR + shape.print(f"Vtx_t {self.get_sym()}[] = {{") + + for idx in range(self.count): + ( + x, + y, + z, + flag, + u, + v, + r, + g, + b, + a, + ) = struct.unpack(">hhhhhhBBBB", shape.file_bytes[pos : pos + 16]) + pos += 16 + + shape.print( + f" {{{{ {x:4}, {y:4}, {z:4} }}, {flag}, {{ {u:6}, {v:6} }}, {{ {r:3}, {g:3}, {b:3}, {a:3} }}}}," + ) + + shape.print("};") + + +class VectorListSegment(Segment): + def __init__(self, addr: int, name: str): + super().__init__(addr, name) + + def print(self, shape): + next = shape.get_segment_after(self) + + pos = self.addr - BASE_ADDR + end = next.addr - BASE_ADDR + count = (end - pos) // 12 + + shape.print(f"Vec3f {self.get_sym()}[] = {{") + + for _ in range(count): + (x, y, z) = struct.unpack(">fff", shape.file_bytes[pos : pos + 12]) + pos += 12 + + shape.print(f" {{ {x}, {y}, {z} }},") + + shape.print("};") + + +class StringListSegment(Segment): + def __init__(self, addr: int, name: str): + super().__init__(addr, name) + self.list: deque + + def scan(self, shape): + self.list = deque() + pos = self.addr - BASE_ADDR + while True: + (ptr_str,) = struct.unpack(">I", shape.file_bytes[pos : pos + 4]) + pos += 4 + + string = read_ascii_string(shape.file_bytes, ptr_str) + + if string == "db": + break + + self.list.append(string) + + def print(self, shape): + align_attribute = "" + if self.name == "ModelNames": + align_attribute = ALIGN_16 + + shape.print(f"{align_attribute}char* {self.get_sym()}[] = {{") + + for name in self.list: + shape.print(f' "{name}",') + shape.print(' "db",') + shape.print("};") + + +class NodeSegment(Segment): + def __init__(self, addr: int, name: str): + super().__init__(addr, name) + + def scan(self, shape): + pos = self.addr - BASE_ADDR + ( + self.node_type, + self.ptr_display_data, + self.num_properties, + self.ptr_property_list, + self.ptr_group_data, + ) = struct.unpack(">IIIII", shape.file_bytes[pos : pos + 20]) + + self.model_name = shape.model_name_map[self.addr] + shape.push(GroupDataSegment(self.ptr_group_data, "GroupData", self.model_name)) + shape.push( + DisplayDataSegment(self.ptr_display_data, "DisplayData", self.model_name) + ) + shape.push( + PropertyListSegment( + self.ptr_property_list, + "Properties", + self.model_name, + self.num_properties, + ) + ) + + def print(self, shape): + shape.print(f"ModelNode {self.get_sym()} = {{") + shape.print(f" .type = {get_shape_type_name(self.node_type)},") + if self.ptr_group_data != 0: + shape.print(f" .groupData = &{shape.get_symbol(self.ptr_group_data)},") + shape.print(f" .displayData = &{shape.get_symbol(self.ptr_display_data)},") + shape.print(f" .propertyList = {shape.get_symbol(self.ptr_property_list)},") + shape.print(f" .numProperties = {self.num_properties},") + shape.print("};") + + +class NodeListSegment(Segment): + def __init__(self, addr: int, name: str, model_name: str, num_children: int): + super().__init__(addr, name) + self.model_name = model_name + self.count = num_children + self.children: List[NodeSegment] = [] + + def scan(self, shape): + pos = self.addr - BASE_ADDR + + for _ in range(self.count): + (ptr_child,) = struct.unpack(">I", shape.file_bytes[pos : pos + 4]) + pos += 4 + + self.children.append(ptr_child) + shape.push(NodeSegment(ptr_child, "Node")) + + def print(self, shape): + shape.print(f"ModelNode* {self.get_sym()}[] = {{") + + for addr in self.children: + shape.print(f" &{shape.get_symbol(addr)},") + shape.print("};") + + +class PropertyListSegment(Segment): + def __init__(self, addr: int, name: str, model_name: str, count: int): + super().__init__(addr, name) + self.model_name = model_name + self.count = count + + def print(self, shape): + pos = self.addr - BASE_ADDR + shape.print(f"ModelNodeProperty {self.get_sym()}[] = {{") + + for _ in range(self.count): + ( + key, + fmt, + value, + ) = struct.unpack(">III", shape.file_bytes[pos : pos + 12]) + pos += 12 + + if key == 0x5E: + if value == 0: + shape.print( + f" {{ .key = {hex(key)}, .dataType = {fmt}, .data = {{ .p = NULL }}}}," + ) + else: + tex_name = read_ascii_string(shape.file_bytes, value) + shape.print( + f' {{ .key = {hex(key)}, .dataType = {fmt}, .data = {{ .p = "{tex_name}" }}}},' + ) + elif key == 0x5F: + shape.print( + f" {{ .key = {hex(key)}, .dataType = {fmt}, .data = {{ .s = {hex(value)} }}}}," + ) + else: + if fmt == 0: # int + shape.print( + f" {{ .key = {hex(key)}, .dataType = {fmt}, .data = {{ .s = {hex(value)} }}}}," + ) + elif fmt == 1: # float + temp = struct.pack(">I", value) + (f,) = struct.unpack(">f", temp) + shape.print( + f" {{ .key = {hex(key)}, .dataType = {fmt}, .data = {{ .f = {f} }}}}," + ) + elif fmt == 2: # pointer + shape.print( + f' {{ .key = {hex(key)}, .dataType = {fmt}, .data = {{ .p = "{shape.get_symbol(value)}" }}}},' + ) + else: + raise Exception( + f"Invalid property: 0x{key:08X} 0x{fmt:08X} 0x{value:08X}" + ) + + shape.print("};") + + +class GroupDataSegment(Segment): + def __init__(self, addr: int, name: str, model_name: str): + super().__init__(addr, name) + self.model_name = model_name + + def scan(self, shape): + start = self.addr - BASE_ADDR + ( + self.ptr_transform_mtx, + self.ptr_lights, + self.num_lights, + self.num_children, + self.ptr_children, + ) = struct.unpack(">IIIII", shape.file_bytes[start : start + 20]) + + shape.push( + NodeListSegment( + self.ptr_children, "Children", self.model_name, self.num_children + ) + ) + shape.push( + LightSetSegment(self.ptr_lights, "Lights", self.model_name, self.num_lights) + ) + shape.push(MatrixSegment(self.ptr_transform_mtx, "Mtx", self.model_name)) + + def print(self, shape): + shape.print(f"ModelGroupData {self.get_sym()} = {{") + if self.ptr_transform_mtx != 0: + shape.print( + f" .transformMatrix = (Mtx*) &{shape.get_symbol(self.ptr_transform_mtx)}," + ) + shape.print( + f" .lightingGroup = (Lightsn*) &{shape.get_symbol(self.ptr_lights)}," + ) + shape.print(f" .numLights = {self.num_lights},") + shape.print(f" .childList = {shape.get_symbol(self.ptr_children)},") + shape.print(f" .numChildren = {self.num_children},") + shape.print("};") + + +class LightSetSegment(Segment): + def __init__(self, addr: int, name: str, model_name: str, count: int): + super().__init__(addr, name) + self.model_name = model_name + self.count = count + + def print(self, shape): + next = shape.get_segment_after(self) + pos = self.addr - BASE_ADDR + end = next.addr - BASE_ADDR + + shape.print(f"// num: {self.count}") + shape.print(f"s32 {self.get_sym()}[] = {{") + while pos < end: + (v,) = struct.unpack(">I", shape.file_bytes[pos : pos + 4]) + pos += 4 + shape.print(f" 0x{v:08X},") + shape.print("};") + + +class MatrixSegment(Segment): + def __init__(self, addr: int, name: str, model_name: str): + super().__init__(addr, name) + self.model_name = model_name + + def print(self, shape): + pos = self.addr - BASE_ADDR + shape.print(f"Matrix4s {self.get_sym()} = {{") + + shape.print(" .whole = {") + for i in range(4): + (a, b, c, d) = struct.unpack(">hhhh", shape.file_bytes[pos : pos + 8]) + pos += 8 + shape.print( + f" {{ {hex(a):4}, {hex(b):4}, {hex(c):4}, {hex(d):4} }}," + ) + shape.print(" },") + + shape.print(" .frac = {") + for i in range(4): + (a, b, c, d) = struct.unpack(">hhhh", shape.file_bytes[pos : pos + 8]) + pos += 8 + shape.print( + f" {{ {hex(a):4}, {hex(b):4}, {hex(c):4}, {hex(d):4} }}," + ) + shape.print(" },") + + shape.print("};") + + +class DisplayDataSegment(Segment): + def __init__(self, addr: int, name: str, model_name: str): + super().__init__(addr, name) + self.model_name = model_name + + def scan(self, shape): + start = self.addr - BASE_ADDR + (self.ptr_display_list,) = struct.unpack( + ">I", shape.file_bytes[start : start + 4] + ) + + gfx_segment = shape.push( + DisplayListSegment(self.ptr_display_list, "Gfx", self.model_name) + ) + # Gfx segments may have been already visited during root Gfx traversal + # so we will now force the associated model name to be the current model + gfx_segment.model_name = self.model_name + + def print(self, shape): + start = self.addr - BASE_ADDR + shape.print(f"ModelDisplayData {self.get_sym()} = {{") + shape.print(f" .displayList = {shape.get_symbol(self.ptr_display_list)},") + shape.print("};") + + +class DisplayListSegment(Segment): + def __init__(self, addr: int, name: str, model_name: str): + super().__init__(addr, name) + self.model_name = model_name + + def scan(self, shape): + pos = self.addr - BASE_ADDR + while True: + (w1, w2) = struct.unpack(">II", shape.file_bytes[pos : pos + 8]) + pos += 8 + + op = w1 >> 24 + if op == GFX_END_DL: + break + elif op == GFX_START_DL: + shape.push( + DisplayListSegment( + w2, f"Gfx_{hex(w2)[2:].upper()}", self.model_name + ) + ) + elif op == GFX_LOAD_MATRIX: + shape.push( + MatrixSegment(w2, f"Mtx_{hex(w2)[2:]}", model_name=self.model_name) + ) + elif op == GFX_LOAD_VTX: + num = (w1 >> 12) & 0xFFF + idx = (w2 - shape.vtx_table.addr) // 0x10 + if shape.vtx_table.count < idx + num: + shape.vtx_table.count = idx + num + + def get_geometry_flags(self, bits: int) -> str: + flags = [] + + if (bits & 0x00000400) != 0: + flags.append("G_CULL_BACK") + + if (bits & 0x00020000) != 0: + flags.append("G_LIGHTING") + + if (bits & 0x00200000) != 0: + flags.append("G_SHADING_SMOOTH") + + return " | ".join(flags) + + def print(self, shape): + pos = self.addr - BASE_ADDR + shape.print(f"Gfx {self.get_sym()}[] = {{") + while True: + (w1, w2) = struct.unpack(">II", shape.file_bytes[pos : pos + 8]) + pos += 8 + + op = w1 >> 24 + + if op == GFX_LOAD_VTX: + num = (w1 >> 12) & 0x00000FFF + end = (w1 & 0x00000FFF) // 2 + buf_pos = end - num + index = (w2 - shape.vtx_table.addr) // 0x10 + shape.print( + f" gsSPVertex(&{shape.vtx_table.get_sym()}[{index}], {num}, {buf_pos})," + ) + elif op == GFX_DRAW_TRI: + i = (w1 & 0x00FF0000) >> 16 + j = (w1 & 0x0000FF00) >> 8 + k = w1 & 0x000000FF + shape.print(f" gsSP1Triangle({i // 2}, {j // 2}, {k // 2}, 0),") + elif op == GFX_DRAW_TRIS: + a = (w1 & 0x00FF0000) >> 16 + b = (w1 & 0x0000FF00) >> 8 + c = w1 & 0x000000FF + d = (w2 & 0x00FF0000) >> 16 + e = (w2 & 0x0000FF00) >> 8 + f = w2 & 0x000000FF + shape.print( + f" gsSP2Triangles({a // 2}, {b // 2}, {c // 2}, 0, {d // 2}, {e // 2}, {f // 2}, 0)," + ) + elif op == GFX_RDP_PIPE_SYNC: + shape.print(" gsDPPipeSync(),") + elif op == GFX_POP_MATRIX: + shape.print(" gsSPPopMatrix(G_MTX_MODELVIEW),") + elif op == GFX_GEOMETRYMODE: + if w1 == 0xD9FFFFFF: + flags = self.get_geometry_flags(w2) + shape.print(f" gsSPSetGeometryMode({flags}),") + else: + flags = self.get_geometry_flags(~(w1 | 0xFF000000)) + shape.print(f" gsSPClearGeometryMode({flags}),") + elif op == GFX_LOAD_MATRIX: + shape.print( + f" gsSPMatrix(&{shape.get_symbol(w2)}, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW)," + ) + elif op == GFX_START_DL: + shape.print(f" gsSPDisplayList({shape.get_symbol(w2)}),") + elif op == GFX_END_DL: + shape.print(" gsSPEndDisplayList(),") + break + + shape.print("};") + + if self.model_name == "root": + next = shape.get_segment_after(self) + end = next.addr - BASE_ADDR + + shape.print(f"\ns32 N(PostGfxPad)[] = {{") + while pos < end: + (v,) = struct.unpack(">I", shape.file_bytes[pos : pos + 4]) + pos += 4 + shape.print(f" 0x{v:08X},") + shape.print("};") + + +class ShapeFile: + def __init__(self, map_name: str, file_bytes: bytes): + self.map_name = map_name + self.file_bytes = file_bytes + self.out_file: TextIOWrapper + self.pending: List[Segment] = [] + self.visited: Dict[int, Segment] = {} + self.model_name_map: Dict[int, str] = {} + self.root_node: Optional[Segment] = None + self.vtx_table: Optional[Segment] = None + self.model_names: Optional[StringListSegment] = None + self.collider_names: Optional[Segment] = None + self.zone_names: Optional[Segment] = None + + def push(self, segment: Segment): + if segment.addr == 0: + return None + + if segment.addr in self.visited: + return self.visited[segment.addr] + + self.pending.append(segment) + self.visited[segment.addr] = segment + return segment + + def get_symbol(self, addr) -> str: + if not addr in self.visited: + raise Exception(f"Encountered unknown pointer: {hex(addr)}") + + return self.visited[addr].get_sym() + + def print(self, string: str): + if self.out_file != None: + self.out_file.write(string + "\n") + else: + print(string) + + # traverse the model tree and create a mapping from addr -> name which we will use during the second scan pass + def build_model_name_map(self, node_addr: int, names: deque): + node_start = node_addr - BASE_ADDR + ( + node_type, + ptr_display_list, + num_properties, + ptr_property_list, + ptr_group_data, + ) = struct.unpack(">IIIII", self.file_bytes[node_start : node_start + 20]) + + if node_type == NODE_TYPE_MODEL: + # set name for this model node + self.model_name_map[node_addr] = names.pop() + return + + group_start = ptr_group_data - BASE_ADDR + ( + ptr_transform_mtx, + ptr_lights, + num_lights, + num_children, + ptr_children, + ) = struct.unpack(">IIIII", self.file_bytes[group_start : group_start + 20]) + + child_start = ptr_children - BASE_ADDR + + for i in range(num_children): + (ptr_child,) = struct.unpack( + ">I", self.file_bytes[child_start : child_start + 4] + ) + self.build_model_name_map(ptr_child, names) + child_start += 4 + + # set name for this group node + if node_type == NODE_TYPE_ROOT: + self.model_name_map[node_addr] = "root" + else: + self.model_name_map[node_addr] = names.pop() + + def print_prologue(self, segments): + assert self.root_node is not None + assert self.vtx_table is not None + assert self.model_names is not None + assert self.collider_names is not None + + self.print('#include "common.h"') + self.print('#include "model.h"') + self.print("") + self.print(f"#define NAMESPACE {self.map_name}_shape") + self.print("") + self.print(f"extern ModelNode {self.root_node.get_sym()};") + self.print(f"extern Vtx_t {self.vtx_table.get_sym()}[];") + self.print(f"extern char* {self.model_names.get_sym()}[];") + self.print(f"extern char* {self.collider_names.get_sym()}[];") + + if self.zone_names is not None: + self.print(f"extern char* {self.zone_names.get_sym()}[];") + for segment in segments: + if isinstance(segment, MatrixSegment): + self.print(f"extern Matrix4s {segment.get_sym()};") + self.print("") + + def digest(self): + # first pass just scans the header and string lists + self.push(HeaderSegment(BASE_ADDR, "Header")) + + while len(self.pending) > 0: + segment = self.pending.pop() + segment.scan(self) + + assert self.model_names is not None + assert self.root_node is not None + + # traverse the model tree to create initial name map + model_names = deque(self.model_names.list) + model_names.reverse() + self.build_model_name_map(self.root_node.addr, model_names) + + # second pass scans the model tree and subordinate data structures + self.push(self.root_node) + self.push(VectorListSegment(self.root_node.addr + 0x14, "UnknownVectors")) + + while len(self.pending) > 0: + segment = self.pending.pop() + segment.scan(self) + + # create a sorted segment map + segment_addrs = list(self.visited.keys()) + segment_addrs.sort() + self.sorted_segments = {i: self.visited[i] for i in segment_addrs} + + def get_segment_after(self, seg: Segment) -> Optional[Segment]: + keys = list(self.sorted_segments.keys()) + idx = keys.index(seg.addr) + if idx + 1 < len(keys): + next_addr = keys[idx + 1] + ret = self.sorted_segments[next_addr] + else: + ret = None + return ret + + def write_to_c(self, out_file): + self.out_file = out_file + self.print_prologue(self.sorted_segments.values()) + + for addr, seg in self.sorted_segments.items(): + self.print(f"// {hex(seg.addr - BASE_ADDR)}") + seg.print(self) + self.print("") + + +def run(in_bin: Path, out: Path) -> None: + map_name = "_".join(in_bin.stem.split("_")[:-1]) + + with open(in_bin, "rb") as f: + file_bytes = f.read() + shape = ShapeFile(map_name, file_bytes) + shape.digest() + + with open(out, "w") as out_file: + shape.write_to_c(out_file) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("in_bin", type=Path, help="input binary file") + parser.add_argument("out_c", type=Path, help="output text file") + args = parser.parse_args() + + run(args.in_bin, args.out_c) diff --git a/tools/compare_shapes.py b/tools/compare_shapes.py new file mode 100755 index 0000000000..00260f2788 --- /dev/null +++ b/tools/compare_shapes.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import filecmp +import os +from pathlib import Path + +total = 0 +matching = 0 + +for root, dirs, files in os.walk("assets/us/mapfs/geom"): + for file in files: + if file.endswith("_shape.bin"): + total += 1 + shape_file = os.path.join(root, file) + built_data_file = Path("ver/us/build") / shape_file.replace( + "_shape.bin", "_shape_data.bin" + ) + + if filecmp.cmp(shape_file, built_data_file, shallow=False): + matching += 1 + else: + if total - matching == 10: + print("...") + if total - matching < 10: + print(file, "X") + +print() +print(f"{matching} of {total} files match") diff --git a/tools/splat_ext/pm_map_data.py b/tools/splat_ext/pm_map_data.py index 9653002770..9fcc909831 100644 --- a/tools/splat_ext/pm_map_data.py +++ b/tools/splat_ext/pm_map_data.py @@ -50,13 +50,17 @@ def parse_palette(data): return palette -def add_file_ext(name: str) -> str: +def add_file_ext(name: str, linker: bool = False) -> str: if name.startswith("party_"): return "party/" + name + ".png" - elif name.endswith("_hit") or name.endswith("_shape"): - return "geom/" + name + ".bin" # TODO: xml + elif name.endswith("_hit"): + return "geom/" + name + ".bin" + elif name.endswith("_shape"): + if linker: + name += "_built" + return "geom/" + name + ".bin" elif name.endswith("_tex"): - return "tex/" + name + ".bin" # TODO: texture archive + return "tex/" + name + ".bin" elif name.endswith("_bg"): return "bg/" + name + ".png" else: @@ -228,7 +232,7 @@ class N64SegPm_map_data(N64Segment): return [ LinkerEntry( self, - [fs_dir / add_file_ext(name) for name in self.files], + [fs_dir / add_file_ext(name, linker=True) for name in self.files], fs_dir.with_suffix(".dat"), ".data", ), diff --git a/tools/splat_ext/pm_sprites.py b/tools/splat_ext/pm_sprites.py index 72d8aef2a3..c9708ea2ee 100644 --- a/tools/splat_ext/pm_sprites.py +++ b/tools/splat_ext/pm_sprites.py @@ -2,6 +2,7 @@ import struct import sys +import re import xml.etree.ElementTree as ET from dataclasses import dataclass, field from pathlib import Path @@ -99,6 +100,31 @@ SPECIAL_RASTER = 0x1F880 LIST_END_BYTES = b"\xFF\xFF\xFF\xFF" +def indent(elem, level=0): + i = "\n" + level*" " + if len(elem): + if not elem.text or not elem.text.strip(): + elem.text = i + " " + if not elem.tail or not elem.tail.strip(): + elem.tail = i + for elem in elem: + indent(elem, level+1) + if not elem.tail or not elem.tail.strip(): + elem.tail = i + else: + if level and (not elem.tail or not elem.tail.strip()): + elem.tail = i + + +def pretty_print_xml(tree : ET.ElementTree, path : Path): + root = tree.getroot() + indent(root) + xml_str = ET.tostring(root, encoding="unicode") + xml_str = re.sub(" />", "/>", xml_str) + with open(path, "w") as f: + f.write(xml_str) + + @dataclass class RasterTableEntry: offset: int @@ -319,12 +345,7 @@ def write_player_metadata( ) xml = ET.ElementTree(Names) - - # pretty print (Python 3.9+) - if hasattr(ET, "indent"): - ET.indent(xml, " ") - - xml.write(str(out_path / PLAYER_SPRITE_MEDADATA_XML_FILENAME), encoding="unicode") + pretty_print_xml(xml, out_path / PLAYER_SPRITE_MEDADATA_XML_FILENAME) def write_npc_metadata( @@ -342,12 +363,7 @@ def write_npc_metadata( ) xml = ET.ElementTree(Names) - - # pretty print (Python 3.9+) - if hasattr(ET, "indent"): - ET.indent(xml, " ") - - xml.write(str(out_path / NPC_SPRITE_MEDADATA_XML_FILENAME), encoding="unicode") + pretty_print_xml(xml, out_path / NPC_SPRITE_MEDADATA_XML_FILENAME) def write_player_xmls( @@ -472,12 +488,7 @@ def write_player_xmls( ) xml = ET.ElementTree(SpriteSheet) - - # pretty print (Python 3.9+) - if hasattr(ET, "indent"): - ET.indent(xml, " ") - - xml.write(str(out_path / f"{cur_sprite_name}.xml"), encoding="unicode") + pretty_print_xml(xml, out_path / f"{cur_sprite_name}.xml") if has_back: sprite_idx += 2 @@ -721,12 +732,7 @@ class NpcSprite: ) xml = ET.ElementTree(SpriteSheet) - - # pretty print (Python 3.9+) - if hasattr(ET, "indent"): - ET.indent(xml, " ") - - xml.write(str(path / "SpriteSheet.xml"), encoding="unicode") + pretty_print_xml(xml, path / "SpriteSheet.xml") class N64SegPm_sprites(N64Segment): diff --git a/tools/splat_ext/sprite_common.py b/tools/splat_ext/sprite_common.py index 74ad4aa0a3..1284e39e6b 100644 --- a/tools/splat_ext/sprite_common.py +++ b/tools/splat_ext/sprite_common.py @@ -3,6 +3,19 @@ from itertools import zip_longest import struct from typing import Dict, List import xml.etree.ElementTree as ET +from enum import IntEnum + + +class CMD(IntEnum): + WAIT = 0 + SET_IMG = 1 + GOTO = 2 + SET_POS = 3 + SET_ROT = 4 + SET_SCALE = 5 + SET_PAL = 6 + LOOP = 7 + SET_META = 8 def iter_in_groups(iterable, n, fillvalue=None): @@ -30,6 +43,16 @@ class Animation: raise NotImplementedError() +@dataclass +class Label(Animation): + lbl_name: str + + def get_attributes(self): + return { + "name": str(self.lbl_name), + } + + @dataclass class Wait(Animation): duration: int @@ -62,24 +85,37 @@ class SetPalette(Animation): @dataclass class Goto(Animation): + dest: str pos: int def get_attributes(self): - return { - "pos": str(self.pos), - } + if self.pos != 0: + return { + "pos": str(self.pos), + } + else: + return { + "dest": str(self.dest), + } @dataclass class Loop(Animation): count: int + dest: str pos: int def get_attributes(self): - return { - "count": str(self.count), - "pos": str(self.pos), - } + if self.pos != 0: + return { + "count": str(self.count), + "pos": str(self.pos), + } + else: + return { + "count": str(self.count), + "dest": str(self.dest), + } @dataclass @@ -181,62 +217,105 @@ class AnimComponent: def size(self): return len(self.commands) + @staticmethod def parse_commands(command_list: List[int]) -> List[Animation]: ret: List[Animation] = [] + labels = {} + boundaries = [] + labels[0] = "Start" + i = 0 + while i < len(command_list): + boundaries.append(i) + cmd_start = command_list[i] + cmd_op = cmd_start >> 12 + cmd_arg = cmd_start & 0xFFF + + if cmd_op == CMD.GOTO: + dest = cmd_arg + if dest in boundaries and dest not in labels: + labels[dest] = f"Pos_{dest}" + elif cmd_op == CMD.SET_POS: + i += 3 + elif cmd_op == CMD.SET_ROT: + i += 2 + elif cmd_op == CMD.SET_SCALE: + i += 1 + elif cmd_op == CMD.LOOP: + dest = command_list[i + 1] + if dest in boundaries and dest not in labels: + labels[dest] = f"Pos_{dest}" + i += 1 + i += 1 + def to_signed(value): return -(value & 0x8000) | (value & 0x7FFF) i = 0 while i < len(command_list): cmd_start = command_list[i] + cmd_op = cmd_start >> 12 + cmd_arg = cmd_start & 0xFFF - if cmd_start <= 0xFFF: + if i in labels: + ret.append(Label(labels[i])) + + if cmd_op == CMD.WAIT: ret.append(Wait(cmd_start)) - elif cmd_start <= 0x1FFF: - raster = cmd_start % 0x1000 + elif cmd_op == CMD.SET_IMG: + raster = cmd_arg if raster == 0xFFF: raster = -1 ret.append(SetRaster(raster)) - elif cmd_start <= 0x2FFF: - ret.append(Goto(cmd_start % 0x2000)) - elif cmd_start <= 0x3FFF: - flag = cmd_start % 0x3000 + elif cmd_op == CMD.GOTO: + dest = cmd_arg + if dest in labels: + lbl_name = labels[dest] + ret.append(Goto(lbl_name, 0)) + else: + ret.append(Goto(None, dest)) + elif cmd_op == CMD.SET_POS: + flag = cmd_arg x, y, z = command_list[i + 1 : i + 4] x = to_signed(x) y = to_signed(y) z = to_signed(z) i += 3 ret.append(SetPos(flag, x, y, z)) - elif cmd_start <= 0x4FFF: + elif cmd_op == CMD.SET_ROT: x, y, z = command_list[i : i + 3] - x = ((x % 0x4000) << 20) >> 20 + x = (cmd_arg << 20) >> 20 y = to_signed(y) z = to_signed(z) i += 2 ret.append(SetRot(x, y, z)) - elif cmd_start <= 0x5FFF: - mode = cmd_start % 0x5000 + elif cmd_op == CMD.SET_SCALE: + mode = cmd_arg percent = command_list[i + 1] i += 1 ret.append(SetScale(mode, percent)) - elif cmd_start <= 0x6FFF: - palette = cmd_start % 0x6000 + elif cmd_op == CMD.SET_PAL: + palette = cmd_arg if palette == 0xFFF: palette = -1 ret.append(SetPalette(palette)) - elif cmd_start <= 0x7FFF: - count = cmd_start % 0x7000 - pos = command_list[i + 1] + elif cmd_op == CMD.LOOP: + count = cmd_arg + dest = command_list[i + 1] + if dest in labels: + lbl_name = labels[dest] + ret.append(Loop(count, lbl_name, 0)) + else: + ret.append(Loop(count, None, dest)) i += 1 - ret.append(Loop(count, pos)) - elif cmd_start <= 0x80FF: - ret.append(Unknown(cmd_start % 0x8000)) - elif cmd_start <= 0x81FF: - ret.append(SetParent(cmd_start % 0x8100)) - elif cmd_start <= 0x82FF: - ret.append(SetNotify(cmd_start % 0x8200)) + elif cmd_op == CMD.SET_META: + if cmd_start <= 0x80FF: + ret.append(Unknown(cmd_arg & 0xFF)) + elif cmd_start <= 0x81FF: + ret.append(SetParent(cmd_arg & 0xFF)) + elif cmd_start <= 0x82FF: + ret.append(SetNotify(cmd_arg & 0xFF)) else: raise Exception("Unknown command") i += 1 @@ -263,8 +342,12 @@ class AnimComponent: @staticmethod def from_xml(xml: ET.Element): commands: List[int] = [] + labels = {} for cmd in xml: - if cmd.tag == "Wait": + if cmd.tag == "Label": + idx = len(commands) + labels[cmd.attrib["name"]] = idx + elif cmd.tag == "Wait": duration = int(cmd.attrib["duration"]) commands.append(duration) elif cmd.tag == "SetRaster": @@ -273,7 +356,16 @@ class AnimComponent: raster = 0xFFF commands.append(0x1000 + raster) elif cmd.tag == "Goto": - commands.append(0x2000 + int(cmd.attrib["pos"])) + if "pos" in cmd.attrib: + # support hardcoded positions for glitched animations + pos = int(cmd.attrib["pos"]) + else: + # properly formatted animations will have labels + lbl_name = cmd.attrib["dest"] + if not lbl_name in labels: + raise Exception("Label missing for Goto dest: " + lbl_name) + pos = labels[lbl_name] + commands.append(0x2000 + pos) elif cmd.tag == "SetPos": flag = int(cmd.attrib["flag"]) x, y, z = cmd.attrib["xyz"].split(",") @@ -298,7 +390,15 @@ class AnimComponent: commands.append(0x6000 + palette) elif cmd.tag == "Loop": count = int(cmd.attrib["count"]) - pos = int(cmd.attrib["pos"]) + if "pos" in cmd.attrib: + # support hardcoded positions for glitched animations + pos = int(cmd.attrib["pos"]) + else: + # properly formatted animations will have labels + lbl_name = cmd.attrib["dest"] + if not lbl_name in labels: + raise Exception("Label missing for Loop dest: " + lbl_name) + pos = labels[lbl_name] commands.append(0x7000 + count) commands.append(pos) elif cmd.tag == "Unknown": diff --git a/ver/ique/asm/bss3.s b/ver/ique/asm/bss3.s index f4ec03c395..f86fc624ac 100644 --- a/ver/ique/asm/bss3.s +++ b/ver/ique/asm/bss3.s @@ -193,10 +193,10 @@ dlabel wTransformGroups dlabel bTransformGroups .space 0x00000010 -dlabel wModelSpecialDls +dlabel wCustomModelGfx .space 0x00000080 -dlabel bModelSpecialDls +dlabel bCustomModelGfx .space 0x00000080 dlabel wCustomModelGfxBuilders @@ -214,10 +214,10 @@ dlabel bModelLocalVtxBuffers dlabel gCurrentModelLocalVtxBuffers .space 4 -dlabel D_80152214 +dlabel wModelTreeRoot .space 4 -dlabel D_80152218 +dlabel bModelTreeRoot .space 4 dlabel D_8015221C @@ -271,19 +271,19 @@ dlabel texPannerAuxV dlabel TextureHeapPos .space 4 -dlabel mdl_currentTransformGroupChildIndex +dlabel mtg_IterIdx .space 2 -dlabel D_8015336E +dlabel mtg_SearchModelID .space 2 -dlabel D_80153370 +dlabel mtg_FoundModelNode .space 4 -dlabel D_80153374 +dlabel mtg_MinChild .space 2 -dlabel D_80153376 +dlabel mtg_MaxChild .space 2 dlabel D_80153378 diff --git a/ver/jp/symbol_addrs.txt b/ver/jp/symbol_addrs.txt index 1c0e3d8796..fb26ee45f5 100644 --- a/ver/jp/symbol_addrs.txt +++ b/ver/jp/symbol_addrs.txt @@ -266,9 +266,9 @@ step_current_game_mode = 0x80118088; state_render_backUI = 0x80118168; state_render_frontUI = 0x801181D4; clear_model_data = 0x8011AF54; -func_80116698 = 0x8011B8A8; +mdl_update_transform_matrices = 0x8011B8A8; render_models = 0x8011BDA0; -func_8011BAE8 = 0x80120CF8; +mdl_reset_transform_flags = 0x80120CF8; clear_render_tasks = 0x80122AA0; execute_render_tasks = 0x80122BC8; clear_animator_list = 0x80123434; diff --git a/ver/jp/undefined_syms.txt b/ver/jp/undefined_syms.txt index 7c88d825a5..b5ad9853de 100644 --- a/ver/jp/undefined_syms.txt +++ b/ver/jp/undefined_syms.txt @@ -59,16 +59,16 @@ npc_test_move_taller_with_slipping = 0x800DDAC4; npc_test_move_simple_with_slipping = 0x800DDC24; npc_test_move_complex_with_slipping = 0x800DDD74; update_player = 0x800DF720; -clear_player_status = 0x800DFC30; +clear_player_status = 0x800DFC30; player_reset_data = 0x800DFC54; suggest_player_anim_allow_backward = 0x800DFEDC; -disable_player_input = 0x800E0158; +disable_player_input = 0x800E0158; enable_player_input = 0x800E0184; player_render_interact_prompts = 0x800E0240; render_player = 0x800E1118; set_action_state = 0x800E5D84; start_bounce_a = 0x800E6014; -clear_player_data = 0x800E7340; +clear_player_data = 0x800E7340; initialize_status_bar = 0x800E78D4; draw_status_ui = 0x800E96DC; close_status_bar = 0x800E9758; @@ -147,7 +147,7 @@ NpcHitQueryColliderID = 0x8010CB38; gPartnerStatus = 0x08010ED70; gPlayerStatus = 0x8010F188; gPlayerData = 0x8010F450; -spr_init_sprites = 0x80111448; +spr_init_sprites = 0x80111448; spr_render_init = 0x801115B0; spr_update_player_sprite = 0x801115DC; spr_draw_player_sprite = 0x80111790; @@ -160,57 +160,57 @@ spr_free_sprite = 0x80112138; set_npc_imgfx_all = 0x801123E4; spr_get_npc_palettes = 0x80112590; spr_get_npc_color_variations = 0x801125BC; -update_entities = 0x801148E0; +update_entities = 0x801148E0; render_entities = 0x801150C4; get_entity_by_index = 0x801157F8; get_shadow_by_index = 0x80115814; -clear_entity_data = 0x80115EC8; +clear_entity_data = 0x80115EC8; init_entity_data = 0x80116068; create_shadow_type = 0x80117470; delete_shadow = 0x80117538; entity_raycast_down = 0x801177F8; set_npc_shadow_scale = 0x80117B10; -clear_game_modes = 0x80117DA8; +clear_game_modes = 0x80117DA8; set_game_mode_slot = 0x080117EB8; game_mode_set_fpDrawAuxUI = 0x80117F94; -step_current_game_mode = 0x80118088; +step_current_game_mode = 0x80118088; state_render_backUI = 0x80118168; state_render_frontUI = 0x801181D4; mdl_load_all_textures = 0x8011AE34; -clear_model_data = 0x8011AF54; +clear_model_data = 0x8011AF54; init_model_data = 0x8011B1F8; -calculate_model_sizes = 0x8011B33C; +mdl_calculate_model_sizes = 0x8011B33C; iterate_models = 0x8011B884; -func_80116698 = 0x8011B8A8; +mdl_update_transform_matrices = 0x8011B8A8; render_models = 0x8011BDA0; get_model_from_list_index = 0x8011FF40; load_data_for_models = 0x8011FF58; -func_8011BAE8 = 0x80120CF8; +mdl_reset_transform_flags = 0x80120CF8; set_background_color_blend = 0x8012106C; get_background_color_blend = 0x80121090; mdl_set_all_fog_mode = 0x80122A3C; -clear_render_tasks = 0x80122AA0; +clear_render_tasks = 0x80122AA0; queue_render_task = 0x80122B20; execute_render_tasks = 0x80122BC8; -clear_animator_list = 0x80123434; +clear_animator_list = 0x80123434; reset_animator_list = 0x80123520; -clear_entity_models = 0x80125DC0; +clear_entity_models = 0x80125DC0; init_entity_models = 0x80125E68; get_entity_model = 0x80127FEC; -clear_worker_list = 0x801282C8; +clear_worker_list = 0x801282C8; init_worker_list = 0x80128324; create_worker_world = 0x80128368; -update_workers = 0x80128614; +update_workers = 0x80128614; render_workers_world = 0x80128680; render_workers_frontUI = 0x801286F0; render_workers_backUI = 0x80128760; -clear_character_set = 0x80128870; -clear_printers = 0x80128884; -update_messages = 0x80128A60; +clear_character_set = 0x80128870; +clear_printers = 0x80128884; +update_messages = 0x80128A60; render_messages = 0x8012948C; get_msg_width = 0x8012B6D4; draw_msg = 0x8012B710; -clear_item_entity_data = 0x80136170; +clear_item_entity_data = 0x80136170; init_item_entity_list = 0x80136244; make_item_entity = 0x80136564; make_item_entity_delayed = 0x80136C38; @@ -223,19 +223,19 @@ set_screen_overlay_params_back = 0x8013CE54; set_screen_overlay_color = 0x8013CEC0; set_screen_overlay_center = 0x8013CEFC; set_screen_overlay_alpha = 0x8013D184; -clear_screen_overlays = 0x8013D1B8; +clear_screen_overlays = 0x8013D1B8; func_80138188 = 0x8013D238; -func_80138198 = 0x8013D248; +func_80138198 = 0x8013D248; render_screen_overlay_frontUI = 0x8013D250; render_screen_overlay_backUI = 0x8013D2D0; set_map_transition_effect = 0x8013D350; update_exit_map_screen_overlay = 0x8013D35C; update_enter_map_screen_overlay = 0x8013D684; imgfx_update_cache = 0x8013F798; -hud_element_clear_cache = 0x801461B0; +hud_element_clear_cache = 0x801461B0; init_hud_element_list = 0x801463B0; hud_element_create = 0x80146554; -update_hud_elements = 0x801466C0; +update_hud_elements = 0x801466C0; render_hud_elements_backUI = 0x801472C0; render_hud_elements_frontUI = 0x801477CC; render_hud_elements_world = 0x80148764; @@ -247,30 +247,30 @@ hud_element_set_render_pos = 0x80149A34; hud_element_set_flags = 0x80149AB0; hud_element_clear_flags = 0x80149ADC; hud_element_set_aux_cache = 0x8014A398; -clear_saved_variables = 0x8014A3D0; +clear_saved_variables = 0x8014A3D0; clear_area_flags = 0x8014A440; set_global_flag = 0x8014A500; get_global_flag = 0x8014A56C; -clear_trigger_data = 0x8014A730; +clear_trigger_data = 0x8014A730; init_trigger_list = 0x8014A7D8; -update_triggers = 0x8014A910; +update_triggers = 0x8014A910; load_map_bg = 0x8014AE20; -reset_background_settings = 0x8014AEA8; +reset_background_settings = 0x8014AEA8; read_background_size = 0x8014AED8; set_background_size = 0x8014AF20; appendGfx_background_texture = 0x8014AF70; -reset_ambient_sounds = 0x8014C2E0; -update_ambient_sounds = 0x8014C314; -clear_windows = 0x8014C4A0; -update_windows = 0x8014C4C4; +reset_ambient_sounds = 0x8014C2E0; +update_ambient_sounds = 0x8014C314; +clear_windows = 0x8014C4A0; +update_windows = 0x8014C4C4; render_window_root = 0x8014CB74; set_window_properties = 0x8014CD78; set_window_update = 0x8014CF2C; set_windows_visible = 0x8014CF74; -clear_sprite_shading_data = 0x8014D0F0; +clear_sprite_shading_data = 0x8014D0F0; init_sprite_shading_data = 0x8014D1A0; sfx_reset_door_sounds = 0x8014E6B0; -sfx_clear_sounds = 0x8014E6C8; +sfx_clear_sounds = 0x8014E6C8; sfx_clear_env_sounds = 0x8014E720; sfx_update_env_sound_params = 0x8014E7E4; sfx_set_reverb_mode = 0x8014E8AC; @@ -279,9 +279,9 @@ sfx_stop_env_sounds = 0x8014E8E8; sfx_stop_sound = 0x8014ED1C; sfx_play_sound = 0x8014ED64; sfx_play_sound_at_position = 0x8014EE0C; -bgm_reset_sequence_players = 0x8014F548; +bgm_reset_sequence_players = 0x8014F548; bgm_reset_volume = 0x8014F5DC; -bgm_update_music_settings = 0x8014F5F8; +bgm_update_music_settings = 0x8014F5F8; bgm_set_song = 0x8014F9C8; bgm_init_music_players = 0x8014FCB8; bgm_quiet_max_volume = 0x8014FD0C; @@ -318,11 +318,11 @@ shim_create_audio_system_obfuscated = 0x802B2000; shim_load_engine_data_obfuscated = 0x802B203C; shim_general_heap_create_obfuscated = 0x802B2078; shim_battle_heap_create_obfuscated = 0x802B20B4; -clear_script_list = 0x802C31DC; +clear_script_list = 0x802C31DC; init_script_list = 0x802C32EC; start_script = 0x802C33E0; start_script_in_group = 0x802C35D0; -update_scripts = 0x802C3D74; +update_scripts = 0x802C3D74; func_802C3EE4 = 0x802C3EE4; kill_script = 0x802C3F3C; kill_script_by_ID = 0x802C40AC; diff --git a/ver/us/asm/bss3.s b/ver/us/asm/bss3.s index 50ec1bebc0..0e8901a278 100644 --- a/ver/us/asm/bss3.s +++ b/ver/us/asm/bss3.s @@ -193,10 +193,10 @@ dlabel wTransformGroups dlabel bTransformGroups .space 0x00000010 -dlabel wModelSpecialDls +dlabel wCustomModelGfx .space 0x00000080 -dlabel bModelSpecialDls +dlabel bCustomModelGfx .space 0x00000080 dlabel wCustomModelGfxBuilders @@ -214,10 +214,10 @@ dlabel bModelLocalVtxBuffers dlabel gCurrentModelLocalVtxBuffers .space 4 -dlabel D_80152214 +dlabel wModelTreeRoot .space 4 -dlabel D_80152218 +dlabel bModelTreeRoot .space 4 dlabel D_8015221C @@ -271,19 +271,19 @@ dlabel texPannerAuxV dlabel TextureHeapPos .space 4 -dlabel mdl_currentTransformGroupChildIndex +dlabel mtg_IterIdx .space 2 -dlabel D_8015336E +dlabel mtg_SearchModelID .space 2 -dlabel D_80153370 +dlabel mtg_FoundModelNode .space 4 -dlabel D_80153374 +dlabel mtg_MinChild .space 2 -dlabel D_80153376 +dlabel mtg_MaxChild .space 2 dlabel D_80153378 diff --git a/ver/us/symbol_addrs.txt b/ver/us/symbol_addrs.txt index 07203759f2..f22f106512 100644 --- a/ver/us/symbol_addrs.txt +++ b/ver/us/symbol_addrs.txt @@ -4007,10 +4007,10 @@ mdl_load_all_textures = 0x80115C24; // type:func rom:0xAC324 mdl_get_child_count = 0x80115CA8; // type:func rom:0xAC3A8 clear_model_data = 0x80115D44; // type:func rom:0xAC444 init_model_data = 0x80115FE8; // type:func rom:0xAC6E8 -calculate_model_sizes = 0x8011612C; // type:func rom:0xAC82C +mdl_calculate_model_sizes = 0x8011612C; // type:func rom:0xAC82C mdl_create_model = 0x8011620C; // type:func rom:0xAC90C iterate_models = 0x80116674; // type:func rom:0xACD74 -func_80116698 = 0x80116698; // type:func rom:0xACD98 +mdl_update_transform_matrices = 0x80116698; // type:func rom:0xACD98 render_models = 0x80116B90; // type:func rom:0xAD290 appendGfx_model_group = 0x80117C94; // type:func rom:0xAE394 func_80117D00 = 0x80117D00; // type:func rom:0xAE400 @@ -4025,13 +4025,13 @@ get_transform_group_index = 0x8011B090; // type:func rom:0xB1790 get_model_center_and_size = 0x8011B0EC; // type:func rom:0xB17EC get_transform_group = 0x8011B1C0; // type:func rom:0xB18C0 func_8011B1D8 = 0x8011B1D8; // type:func rom:0xB18D8 -make_transform_group = 0x8011B37C; // type:func rom:0xB1A7C +mdl_make_transform_group = 0x8011B37C; // type:func rom:0xB1A7C enable_transform_group = 0x8011B5D0; // type:func rom:0xB1CD0 disable_transform_group = 0x8011B660; // type:func rom:0xB1D60 clone_model = 0x8011B6F0; // type:func rom:0xB1DF0 set_model_group_visibility = 0x8011B7C0; // type:func rom:0xB1EC0 func_8011B950 = 0x8011B950; // type:func rom:0xB2050 -func_8011BAE8 = 0x8011BAE8; // type:func rom:0xB21E8 +mdl_reset_transform_flags = 0x8011BAE8; // type:func rom:0xB21E8 enable_world_fog = 0x8011BB50; // type:func rom:0xB2250 disable_world_fog = 0x8011BB64; // type:func rom:0xB2264 set_world_fog_dist = 0x8011BB74; // type:func rom:0xB2274 @@ -4488,10 +4488,10 @@ bgm_set_battle_song = 0x8014AF8C; // type:func rom:0xE168C func_8014AFA0 = 0x8014AFA0; // type:func rom:0xE16A0 D_8014AFB0 = 0x8014AFB0; // rom:0xE16B0 D_8014AFB4 = 0x8014AFB4; // rom:0xE16B4 -D_8014AFC0 = 0x8014AFC0; // rom:0xE16C0 -D_8014B0B8 = 0x8014B0B8; // rom:0xE17B8 +ModelRenderModes = 0x8014AFC0; // rom:0xE16C0 +ModelCombineModesA = 0x8014B0B8; // rom:0xE17B8 D_8014B0BC = 0x8014B0BC; // rom:0xE17BC -D_8014B400 = 0x8014B400; // rom:0xE1B00 +ModelCombineModesB = 0x8014B400; // rom:0xE1B00 D_8014B404 = 0x8014B404; // rom:0xE1B04 TextureHeapBase = 0x8014B748; // rom:0xE1E48 mdl_bgMultiplyColorA = 0x8014B74C; // rom:0xE1E4C @@ -4870,9 +4870,9 @@ func_802C39F8 = 0x802C39F8; // type:func rom:0xE83A8 func_802C3C10 = 0x802C3C10; // type:func rom:0xE85C0 wTransformGroups = 0x80151F70; // rom:0xE8670 bTransformGroups = 0x80151F80; // rom:0xE8680 -wModelSpecialDls = 0x80151F90; // rom:0xE8690 +wCustomModelGfx = 0x80151F90; // rom:0xE8690 restart_script = 0x802C3D04; // type:func rom:0xE86B4 -bModelSpecialDls = 0x80152010; // rom:0xE8710 +bCustomModelGfx = 0x80152010; // rom:0xE8710 update_scripts = 0x802C3D74; // type:func rom:0xE8724 wCustomModelGfxBuilders = 0x80152090; // rom:0xE8790 bCustomModelGfxBuilders = 0x80152110; // rom:0xE8810 @@ -4881,8 +4881,8 @@ func_802C3EE4 = 0x802C3EE4; // type:func rom:0xE8894 bModelLocalVtxBuffers = 0x801521D0; // rom:0xE88D0 kill_script = 0x802C3F3C; // type:func rom:0xE88EC gCurrentModelLocalVtxBuffers = 0x80152210; // rom:0xE8910 -D_80152214 = 0x80152214; // rom:0xE8914 -D_80152218 = 0x80152218; // rom:0xE8918 +wModelTreeRoot = 0x80152214; // rom:0xE8914 +bModelTreeRoot = 0x80152218; // rom:0xE8918 D_8015221C = 0x8015221C; // rom:0xE891C D_80152220 = 0x80152220; // rom:0xE8920 kill_script_by_ID = 0x802C40AC; // type:func rom:0xE8A5C @@ -4948,10 +4948,10 @@ texPannerAuxU = 0x801532E8; // rom:0xE99E8 texPannerAuxV = 0x80153328; // rom:0xE9A28 mdl_nextTextureAddress = 0x80153368; // rom:0xE9A68 evt_handle_case_not_equal = 0x802C50BC; // type:func rom:0xE9A6C -D_8015336E = 0x8015336E; // rom:0xE9A6E -D_80153370 = 0x80153370; // rom:0xE9A70 -D_80153374 = 0x80153374; // rom:0xE9A74 -D_80153376 = 0x80153376; // rom:0xE9A76 +mtg_SearchModelID = 0x8015336E; // rom:0xE9A6E +mtg_FoundModelNode = 0x80153370; // rom:0xE9A70 +mtg_MinChild = 0x80153374; // rom:0xE9A74 +mtg_MaxChild = 0x80153376; // rom:0xE9A76 D_80153378 = 0x80153378; // rom:0xE9A78 depthCopyBuffer = 0x80153380; // rom:0xE9A80 mdl_renderTaskLists = 0x801533A0; // rom:0xE9AA0 @@ -26031,7 +26031,7 @@ D_801512E8 = 0x801512E8; // B_801512F0 = 0x801512F0; // gBattleEntityList = 0x801513F8; // mdl_treeIterPos = 0x80153224; // -mdl_currentTransformGroupChildIndex = 0x8015336C; // +mtg_IterIdx = 0x8015336C; // gCurrentAnimMeshListPtr = 0x80153A40; // gAnimRotMtx = 0x80153A68; // gMessageDrawStatePtr = 0x80155D74; // @@ -26770,8 +26770,8 @@ ExitSingleDoor = 0x80285DAC; // EnterSingleDoor = 0x80285DD4; // ExitDoubleDoor = 0x80285E4C; // EnterDoubleDoor = 0x80285E74; // -D_80286520 = 0x80286520; // -D_80286524 = 0x80286524; // +ShopInteractScript = 0x80286520; // +ShopInteractScriptID = 0x80286524; // D_80286528 = 0x80286528; // wShopBuyCallbackScript = 0x8028652C; // wShopSelectedItem = 0x80286530; //