diff --git a/CHANGES b/CHANGES index 67053301..7b81e757 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,59 @@ +Refresh 15 (mostly a hotfix for RSP microcode selection) + +1.) Renamed frame_buffer funcs and _ZBUFFER (#1184) +2.) RSP Microcode Hotfix (#1183) +3.) Label osSetTimer.c (#1182) +4.) Fix styling (#1177) +5.) Rename all `FrameBuffer` variants to `Framebuffer` (#1176) +6.) Remove (WIP) from sh. +7.) Allow both archives and ELF objects to be patched (#1127) + +Refresh 14 + +1.) Label whomp and some object fields (#1174) +2.) Generate MIO0 object files using binutils `ld` instead of `as` (#1173) +3.) Bowser documentation (#1166) +4.) Fix comment syntax in 00_sound_player.0 (#1172) +5.) Rename in-game menu variables (#1163) +6.) Document double red coin sound and JP sound glitch (#1170) +7.) Document different bug in external.c (#1168) +8.) updated names/types of octagonal platform data (#1164) +9.) Label a number of unnamed variables. (#1169) +10.) Document JP PU sound glitch (#1167) +11.) Set model ids to spawn_triangle_break_particles (#1165) +12.) Fix borders in clear_frame_buffer (#1162) +13.) Fix seq header files for 64-bit (#1161) +14.) Game_init.c remaining doc (#1158) +15.) Label a couple static variables in sound_init.c (#1159) +16.) Properly define dialog values (status, flags, cutscenes) (#1153) +17.) Label all of amp's assets. (#1018) +18.) Split audio/synthesis.c into Shindou/non-Shindou files (#1144) +19.) Avoid CC_CHECK warnings when using gcc (#1157) +20.) level_select_menu.c => title_screen.c (#1152) +21.) Use C preprocessor on assembly files (#1126) +22.) Replace output_level_headers.py with sed equivalent (#1109) +23.) Fix CC_CHECK warnings related to unused symbols and UB (#1155) +24.) Define remaining floor lower limit values (#1147) +25.) use r+b mode for libultra.a patch tool (#1148) +26.) Use proper values for gPrevFrameObjectCount ifs (#1146) +27.) Some minor bowser.inc.c labelling. (#1150) +28.) fix king bob-omb texture pointers (#1145) +29.) Split audio/load.c into Shindou/non-Shindou files (#1143) +30.) Small Shindou audio cleanups (#1142) +31.) Fix endians in ALSeqData (#1141) +32.) Document S8 decoder rsp operation and some more (#1139) +33.) Fix Shindou synthesis_process_note fake match (#1140) +34.) More audio documentation, for the new rsp code and other fixes (#1138) +35.) Build fixes for macOS: cpp, clang, recomp, aiff_extract_codebook (#1135) +36.) Add ENABLE_RUMBLE to config.h (#1122) +37.) Reduce recomp memory consumption by using smaller disassembly blocks (#1128) +38.) Makefile fixes (#1123) +39.) Update README.md +40.) Update README.md +41.) Reflect current decompilation status +42.) Allow both archives and ELF objects to be patched (#1127) +43.) Remove WIP mention in README for sh version. + Refresh 13 2 - No more nonmatchings remain for all builds including Shindou. diff --git a/Makefile b/Makefile index af094b8f..40aac673 100644 --- a/Makefile +++ b/Makefile @@ -261,7 +261,6 @@ GENERATED_C_FILES := $(BUILD_DIR)/assets/mario_anim_data.c $(BUILD_DIR)/assets/d $(addprefix $(BUILD_DIR)/bin/,$(addsuffix _skybox.c,$(notdir $(basename $(wildcard textures/skyboxes/*.png))))) ifeq ($(TARGET_NDS),1) - C_FILES := $(filter-out src/game/main.c,$(C_FILES)) ULTRA_C_FILES := \ alBnkfNew.c \ guLookAtRef.c \ @@ -367,12 +366,6 @@ else COPT := $(IDO_ROOT)/copt endif endif -# Prefer gcc's cpp if installed on the system -ifneq (,$(call find-command,cpp-10)) - CPP := cpp-10 -else - CPP := cpp -endif LD := $(CROSS)ld AR := $(CROSS)ar OBJDUMP := $(CROSS)objdump @@ -393,6 +386,15 @@ endif C_DEFINES := $(foreach d,$(DEFINES),-D$(d)) DEF_INC_CFLAGS := $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(C_DEFINES) +# Prefer clang as C preprocessor if installed on the system +ifneq (,$(call find-command,clang)) + CPP := clang + CPPFLAGS := -E -P -x c -Wno-trigraphs $(DEF_INC_CFLAGS) +else + CPP := cpp + CPPFLAGS := -P -Wno-trigraphs $(DEF_INC_CFLAGS) +endif + ifeq ($(TARGET_NDS),1) LIBDIRS := $(DEVKITPRO)/libnds @@ -427,9 +429,6 @@ endif ASFLAGS := -march=vr4300 -mabi=32 $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(foreach d,$(DEFINES),--defsym $(d)) RSPASMFLAGS := $(foreach d,$(DEFINES),-definelabel $(subst =, ,$(d))) -# C preprocessor flags -CPPFLAGS := -P -Wno-trigraphs $(DEF_INC_CFLAGS) - ifeq ($(shell getconf LONG_BIT), 32) # Work around memory allocation bug in QEMU export QEMU_GUEST_BASE := 1 @@ -524,7 +523,7 @@ $(SOUND_BIN_DIR)/sound_data.o: $(SOUND_BIN_DIR)/sound_data.ctl.inc.c $(SO $(BUILD_DIR)/levels/scripts.o: $(BUILD_DIR)/include/level_headers.h ifeq ($(VERSION),sh) - $(BUILD_DIR)/src/audio/load.o: $(SOUND_BIN_DIR)/bank_sets.inc.c $(SOUND_BIN_DIR)/sequences_header.inc.c $(SOUND_BIN_DIR)/ctl_header.inc.c $(SOUND_BIN_DIR)/tbl_header.inc.c + $(BUILD_DIR)/src/audio/load_sh.o: $(SOUND_BIN_DIR)/bank_sets.inc.c $(SOUND_BIN_DIR)/sequences_header.inc.c $(SOUND_BIN_DIR)/ctl_header.inc.c $(SOUND_BIN_DIR)/tbl_header.inc.c endif $(CRASH_TEXTURE_C_FILES): TEXTURE_ENCODING := u32 @@ -617,11 +616,11 @@ $(BUILD_DIR)/levels/%/leveldata.elf: $(BUILD_DIR)/levels/%/leveldata.o $(BUILD_D $(V)$(LD) -e 0 -Ttext=$(SEGMENT_ADDRESS) -Map $@.map --just-symbols=$(BUILD_DIR)/bin/$(TEXTURE_BIN).elf -o $@ $< $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf - $(call print,Extracting compressionable data from:,$<,$@) + $(call print,Extracting compressible data from:,$<,$@) $(V)$(EXTRACT_DATA_FOR_MIO) $< $@ $(BUILD_DIR)/levels/%/leveldata.bin: $(BUILD_DIR)/levels/%/leveldata.elf - $(call print,Extracting compressionable data from:,$<,$@) + $(call print,Extracting compressible data from:,$<,$@) $(V)$(EXTRACT_DATA_FOR_MIO) $< $@ # Compress binary file @@ -632,10 +631,9 @@ $(BUILD_DIR)/%.mio0: $(BUILD_DIR)/%.bin # convert binary mio0 to object file $(BUILD_DIR)/%.mio0.o: $(BUILD_DIR)/%.mio0 $(call print,Converting MIO0 to ELF:,$<,$@) - $(V)printf ".section .data\n\n.incbin \"$<\"\n" | $(AS) $(ASFLAGS) -o $@ + $(V)$(LD) -r -b binary $< -o $@ endif - #==============================================================================# # Sound File Generation # #==============================================================================# @@ -659,7 +657,7 @@ $(BUILD_DIR)/%.table: %.aiff $(V)$(AIFF_EXTRACT_CODEBOOK) $< >$@ $(BUILD_DIR)/%.aifc: $(BUILD_DIR)/%.table %.aiff - $(call print,Encoding VADPCM:,$<,$@) + $(call print,Encoding ADPCM:,$(word 2,$^),$@) $(V)$(VADPCM_ENC) -c $^ $@ endif @@ -668,8 +666,8 @@ $(ENDIAN_BITWIDTH): $(TOOLS_DIR)/determine-endian-bitwidth.c $(V)$(CC) -c $(CFLAGS) -o $@.dummy2 $< 2>$@.dummy1; true $(V)grep -o 'msgbegin --endian .* --bitwidth .* msgend' $@.dummy1 > $@.dummy2 $(V)head -n1 <$@.dummy2 | cut -d' ' -f2-5 > $@ - @$(RM) $@.dummy1 - @$(RM) $@.dummy2 + $(V)$(RM) $@.dummy1 + $(V)$(RM) $@.dummy2 $(SOUND_BIN_DIR)/sound_data.ctl: sound/sound_banks/ $(SOUND_BANK_FILES) $(SOUND_SAMPLE_AIFCS) $(ENDIAN_BITWIDTH) @$(PRINT) "$(GREEN)Generating: $(BLUE)$@ $(NO_COL)\n" @@ -705,7 +703,7 @@ $(SOUND_BIN_DIR)/%.m64: $(SOUND_BIN_DIR)/%.o # Convert binary file to a comma-separated list of byte values for inclusion in C code $(BUILD_DIR)/%.inc.c: $(BUILD_DIR)/% - $(call print,Piping:,$<,$@) + $(call print,Converting to C:,$<,$@) $(V)hexdump -v -e '1/1 "0x%X,"' $< > $@ $(V)echo >> $@ @@ -736,7 +734,7 @@ $(BUILD_DIR)/text/%/define_text.inc.c: text/define_text.inc.c text/%/courses.h t # Level headers $(BUILD_DIR)/include/level_headers.h: levels/level_headers.h.in $(call print,Preprocessing level headers:,$<,$@) - $(V)$(CPP) $(CPPFLAGS) -I . levels/level_headers.h.in | $(PYTHON) $(TOOLS_DIR)/output_level_headers.py > $(BUILD_DIR)/include/level_headers.h + $(V)$(CPP) $(CPPFLAGS) -I . $< | sed -E 's|(.+)|#include "\1"|' > $@ # Run asm_processor on files that have NON_MATCHING code ifeq ($(NON_MATCHING),0) @@ -786,46 +784,36 @@ ifeq ($(COMPILER),ido) $(BUILD_DIR)/lib/src/string.o: OPT_FLAGS := -O2 $(BUILD_DIR)/lib/src/gu%.o: OPT_FLAGS := -O3 $(BUILD_DIR)/lib/src/al%.o: OPT_FLAGS := -O3 - # For the asm-processor, since it doesn't support -O3. Probably not actually compiled with these flags. + ifeq ($(VERSION),sh) - $(BUILD_DIR)/lib/src/unk_shindou_file.o: OPT_FLAGS := -O1 - $(BUILD_DIR)/lib/src/func_sh_80304D20.o: OPT_FLAGS := -O1 - $(BUILD_DIR)/lib/src/_Printf.o: OPT_FLAGS := -O3 - $(BUILD_DIR)/lib/src/contramread.o: OPT_FLAGS := -O1 - $(BUILD_DIR)/lib/src/osPfsIsPlug.o: OPT_FLAGS := -O1 - $(BUILD_DIR)/lib/src/osAiSetFrequency.o: OPT_FLAGS := -O1 - $(BUILD_DIR)/lib/src/contramwrite.o: OPT_FLAGS := -O1 - $(BUILD_DIR)/lib/src/sprintf.o: OPT_FLAGS := -O3 - $(BUILD_DIR)/lib/src/_Litob.o: OPT_FLAGS := -O3 - $(BUILD_DIR)/lib/src/_Ldtob.o: OPT_FLAGS := -O3 + $(BUILD_DIR)/lib/src/_Ldtob.o: OPT_FLAGS := -O3 + $(BUILD_DIR)/lib/src/_Litob.o: OPT_FLAGS := -O3 + $(BUILD_DIR)/lib/src/_Printf.o: OPT_FLAGS := -O3 + $(BUILD_DIR)/lib/src/sprintf.o: OPT_FLAGS := -O3 $(BUILD_DIR)/lib/src/osDriveRomInit.o: OPT_FLAGS := -g endif ifeq ($(VERSION),eu) - $(BUILD_DIR)/lib/src/_Litob.o: OPT_FLAGS := -O3 $(BUILD_DIR)/lib/src/_Ldtob.o: OPT_FLAGS := -O3 + $(BUILD_DIR)/lib/src/_Litob.o: OPT_FLAGS := -O3 $(BUILD_DIR)/lib/src/_Printf.o: OPT_FLAGS := -O3 $(BUILD_DIR)/lib/src/sprintf.o: OPT_FLAGS := -O3 - # Enable loop unrolling except for external.c (external.c might also have used - # unrolling, but it makes one loop harder to match). # For all audio files other than external.c and port_eu.c, put string literals # in .data. (In Shindou, the port_eu.c string literals also moved to .data.) $(BUILD_DIR)/src/audio/%.o: OPT_FLAGS := -O2 -use_readwrite_const $(BUILD_DIR)/src/audio/port_eu.o: OPT_FLAGS := -O2 - $(BUILD_DIR)/src/audio/external.o: OPT_FLAGS := -O2 -Wo,-loopunroll,0 endif ifeq ($(VERSION_JP_US),true) $(BUILD_DIR)/src/audio/%.o: OPT_FLAGS := -O2 -Wo,-loopunroll,0 - $(BUILD_DIR)/src/audio/load.o: OPT_FLAGS := -O2 -framepointer -Wo,-loopunroll,0 - endif - ifeq ($(VERSION_JP_US),true) + $(BUILD_DIR)/src/audio/load.o: OPT_FLAGS := -O2 -Wo,-loopunroll,0 -framepointer # The source-to-source optimizer copt is enabled for audio. This makes it use # acpp, which needs -Wp,-+ to handle C++-style comments. # All other files than external.c should really use copt, but only a few have # been matched so far. $(BUILD_DIR)/src/audio/effects.o: OPT_FLAGS := -O2 -Wo,-loopunroll,0 -sopt,-inline=sequence_channel_process_sound,-scalaroptimize=1 -Wp,-+ - $(BUILD_DIR)/src/audio/synthesis.o: OPT_FLAGS := -O2 -sopt,-scalaroptimize=1 -Wp,-+ + $(BUILD_DIR)/src/audio/synthesis.o: OPT_FLAGS := -O2 -Wo,-loopunroll,0 -sopt,-scalaroptimize=1 -Wp,-+ endif + $(BUILD_DIR)/src/audio/external.o: OPT_FLAGS := -O2 -Wo,-loopunroll,0 # Add a target for build/eu/src/audio/*.copt to make it easier to see debug $(BUILD_DIR)/src/audio/%.acpp: src/audio/%.c @@ -839,7 +827,7 @@ endif # Assemble assembly code $(BUILD_DIR)/%.o: %.s $(call print,Assembling:,$<,$@) - $(V)$(AS) $(ASFLAGS) -MD $(BUILD_DIR)/$*.d -o $@ $< + $(V)$(CPP) $(CPPFLAGS) $< | $(AS) $(ASFLAGS) -MD $(BUILD_DIR)/$*.d -o $@ # Assemble RSP assembly code $(BUILD_DIR)/rsp/%.bin $(BUILD_DIR)/rsp/%_data.bin: rsp/%.s @@ -863,7 +851,7 @@ $(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT) $(BUILD_DIR)/libultra.a: $(ULTRA_O_FILES) @$(PRINT) "$(GREEN)Linking libultra: $(BLUE)$@ $(NO_COL)\n" $(V)$(AR) rcs -o $@ $(ULTRA_O_FILES) - $(V)$(TOOLS_DIR)/patch_libultra_math $@ + $(V)$(TOOLS_DIR)/patch_elf_32bit $@ # Link libgoddard $(BUILD_DIR)/libgoddard.a: $(GODDARD_O_FILES) diff --git a/Makefile.split b/Makefile.split index bb824aa5..d78c7429 100644 --- a/Makefile.split +++ b/Makefile.split @@ -161,8 +161,8 @@ endef ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),distclean) $(BUILD_DIR)/level_rules.mk: levels/level_rules.mk levels/level_defines.h - @$(PRINT) "$(GREEN)Preprocessing level make rules: $(BLUE)$@ $(NO_COL)\n" - @$(CPP) $(VERSION_CFLAGS) -I . -o $@ $< + $(call print,Preprocessing level make rules:,$<,$@) + $(V)$(CPP) $(CPPFLAGS) $(VERSION_CFLAGS) -I . -o $@ $< include $(BUILD_DIR)/level_rules.mk endif endif @@ -179,11 +179,11 @@ $(eval $(call level_rules,menu,generic)) # Menu (File Select) # Ending cake textures are generated in a special way $(BUILD_DIR)/levels/ending/cake_eu.inc.c: levels/ending/cake_eu.png - @$(PRINT) "$(GREEN)Splitting $(YELLOW)$< $(GREEN)to: $(BLUE)$@ $(NO_COL)\n" - @$(SKYCONV) --type cake-eu --split $^ $(BUILD_DIR)/levels/ending $(TEXTURE_OPTIONS) + $(call print,Splitting:,$<,$@) + $(V)$(SKYCONV) --type cake-eu --split $^ $(BUILD_DIR)/levels/ending $(TEXTURE_OPTIONS) $(BUILD_DIR)/levels/ending/cake.inc.c: levels/ending/cake.png - @$(PRINT) "$(GREEN)Splitting $(YELLOW)$< $(GREEN)to: $(BLUE)$@ $(NO_COL)\n" - @$(SKYCONV) --type cake --split $^ $(BUILD_DIR)/levels/ending $(TEXTURE_OPTIONS) + $(call print,Splitting:,$<,$@) + $(V)$(SKYCONV) --type cake --split $^ $(BUILD_DIR)/levels/ending $(TEXTURE_OPTIONS) # -------------------------------------- # Texture Bin Rules @@ -250,8 +250,8 @@ $(BUILD_DIR)/bin/eu/translation_fr.elf: SEGMENT_ADDRESS := 0x19000000 # -------------------------------------- $(BUILD_DIR)/bin/%_skybox.c: textures/skyboxes/%.png - @$(PRINT) "$(GREEN)Splitting $(YELLOW)$< $(GREEN)to: $(BLUE)$@ $(NO_COL)\n" - @$(SKYCONV) --type sky --split $^ $(BUILD_DIR)/bin $(TEXTURE_OPTIONS) + $(call print,Splitting:,$<,$@) + $(V)$(SKYCONV) --type sky --split $^ $(BUILD_DIR)/bin $(TEXTURE_OPTIONS) $(BUILD_DIR)/bin/%_skybox.elf: SEGMENT_ADDRESS := 0x0A000000 diff --git a/actors/amp/anims/anim_0800401C.inc.c b/actors/amp/anims/animation.inc.c similarity index 87% rename from actors/amp/anims/anim_0800401C.inc.c rename to actors/amp/anims/animation.inc.c index f114dcfc..2763f4dc 100644 --- a/actors/amp/anims/anim_0800401C.inc.c +++ b/actors/amp/anims/animation.inc.c @@ -1,5 +1,4 @@ -// 0x08003E30 -static const s16 amp_seg8_animvalue_08003E30[] = { +static const s16 dAmpAnimValue[] = { 0x0000, 0x0000, 0x0D79, 0x1AF2, 0x286B, 0x35E4, 0x435D, 0x50D6, 0x5E50, 0x6BC9, 0x7942, 0x86BE, 0x9437, 0xA1B0, 0xAF2A, 0xBCA3, 0xCA1C, 0xD795, 0xE50E, 0xF287, 0x1872, 0x0000, 0x1AF2, 0x35E4, @@ -23,8 +22,7 @@ static const s16 amp_seg8_animvalue_08003E30[] = { 0xC001, 0x3FFF, }; -// 0x08003F74 -static const u16 amp_seg8_animindex_08003F74[] = { +static const u16 dAmpAnimIndex[] = { 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x00A1, 0x0001, 0x0000, 0x0013, 0x008D, 0x0001, 0x00A0, @@ -40,15 +38,14 @@ static const u16 amp_seg8_animindex_08003F74[] = { 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x004E, }; -// 0x0800401C -static const struct Animation amp_seg8_anim_0800401C = { +static const struct Animation dAmpAnimation = { 0, 0, 0, 0, 0x13, - ANIMINDEX_NUMPARTS(amp_seg8_animindex_08003F74), - amp_seg8_animvalue_08003E30, - amp_seg8_animindex_08003F74, + ANIMINDEX_NUMPARTS(dAmpAnimIndex), + dAmpAnimValue, + dAmpAnimIndex, 0, }; diff --git a/actors/amp/anims/data.inc.c b/actors/amp/anims/data.inc.c index ad33202f..ed31deb4 100644 --- a/actors/amp/anims/data.inc.c +++ b/actors/amp/anims/data.inc.c @@ -1 +1 @@ -#include "anim_0800401C.inc.c" +#include "animation.inc.c" diff --git a/actors/amp/anims/table.inc.c b/actors/amp/anims/table.inc.c index 77485e89..33e67941 100644 --- a/actors/amp/anims/table.inc.c +++ b/actors/amp/anims/table.inc.c @@ -1,4 +1,3 @@ -// 0x08004034 -const struct Animation *const amp_seg8_anims_08004034[] = { - &_seg8_anim_0800401C, +const struct Animation *const dAmpAnimsList[] = { + &dAmpAnimation, }; diff --git a/actors/amp/geo.inc.c b/actors/amp/geo.inc.c index 378a84bb..9c9e1d69 100644 --- a/actors/amp/geo.inc.c +++ b/actors/amp/geo.inc.c @@ -1,19 +1,18 @@ -// 0x0F000028 -const GeoLayout amp_geo[] = { +const GeoLayout dAmpGeo[] = { GEO_SHADOW(SHADOW_CIRCLE_4_VERTS, 0xC8, 100), GEO_OPEN_NODE(), GEO_SCALE(0x00, 16384), GEO_OPEN_NODE(), GEO_ANIMATED_PART(LAYER_OPAQUE, 0, 0, 0, NULL), GEO_OPEN_NODE(), - GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, amp_seg8_dl_08002C88), + GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, dAmpEyeDl), GEO_OPEN_NODE(), GEO_ANIMATED_PART(LAYER_OPAQUE, 0, 0, 0, NULL), GEO_OPEN_NODE(), GEO_SWITCH_CASE(2, geo_switch_anim_state), GEO_OPEN_NODE(), GEO_ANIMATED_PART(LAYER_OPAQUE, 0, 0, 0, NULL), - GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, amp_seg8_dl_08002BA0), + GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, dAmpElectricityDl), GEO_CLOSE_NODE(), GEO_CLOSE_NODE(), GEO_ANIMATED_PART(LAYER_OPAQUE, 0, 0, 0, NULL), @@ -21,7 +20,7 @@ const GeoLayout amp_geo[] = { GEO_SWITCH_CASE(2, geo_switch_anim_state), GEO_OPEN_NODE(), GEO_ANIMATED_PART(LAYER_OPAQUE, 0, 0, 0, NULL), - GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, amp_seg8_dl_08002BA0), + GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, dAmpElectricityDl), GEO_CLOSE_NODE(), GEO_CLOSE_NODE(), GEO_ANIMATED_PART(LAYER_OPAQUE, 0, 0, 0, NULL), @@ -29,7 +28,7 @@ const GeoLayout amp_geo[] = { GEO_SWITCH_CASE(2, geo_switch_anim_state), GEO_OPEN_NODE(), GEO_ANIMATED_PART(LAYER_OPAQUE, 0, 0, 0, NULL), - GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, amp_seg8_dl_08002BA0), + GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, dAmpElectricityDl), GEO_CLOSE_NODE(), GEO_CLOSE_NODE(), GEO_ANIMATED_PART(LAYER_OPAQUE, 0, 0, 0, NULL), @@ -37,16 +36,16 @@ const GeoLayout amp_geo[] = { GEO_SWITCH_CASE(2, geo_switch_anim_state), GEO_OPEN_NODE(), GEO_ANIMATED_PART(LAYER_OPAQUE, 0, 0, 0, NULL), - GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, amp_seg8_dl_08002BA0), + GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, dAmpElectricityDl), GEO_CLOSE_NODE(), GEO_CLOSE_NODE(), GEO_CLOSE_NODE(), - GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, amp_seg8_dl_08002D70), + GEO_ANIMATED_PART(LAYER_ALPHA, 0, 0, 0, dAmpMouthDl), GEO_ANIMATED_PART(LAYER_OPAQUE, 0, 0, 0, NULL), GEO_OPEN_NODE(), GEO_BILLBOARD(), GEO_OPEN_NODE(), - GEO_DISPLAY_LIST(LAYER_ALPHA, amp_seg8_dl_08002E58), + GEO_DISPLAY_LIST(LAYER_ALPHA, dAmpBodyDl), GEO_CLOSE_NODE(), GEO_CLOSE_NODE(), GEO_CLOSE_NODE(), diff --git a/actors/amp/model.inc.c b/actors/amp/model.inc.c index 15745bd0..67185c8f 100644 --- a/actors/amp/model.inc.c +++ b/actors/amp/model.inc.c @@ -1,27 +1,22 @@ // Amp -// 0x08000F18 -ALIGNED8 static const Texture amp_seg8_texture_08000F18[] = { +ALIGNED8 static const Texture dAmpElectricityTexture[] = { #include "actors/amp/amp_electricity.rgba16.inc.c" }; -// 0x08001318 -ALIGNED8 static const Texture amp_seg8_texture_08001318[] = { +ALIGNED8 static const Texture dAmpEyesTexture[] = { #include "actors/amp/amp_eyes.rgba16.inc.c" }; -// 0x08001B18 -ALIGNED8 static const Texture amp_seg8_texture_08001B18[] = { +ALIGNED8 static const Texture dAmpBodyTexture[] = { #include "actors/amp/amp_body.rgba16.inc.c" }; -// 0x08002318 -ALIGNED8 static const Texture amp_seg8_texture_08002318[] = { +ALIGNED8 static const Texture dAmpMouthTexture[] = { #include "actors/amp/amp_mouth.rgba16.inc.c" }; -// 0x08002B18 -static const Vtx amp_seg8_vertex_08002B18[] = { +static const Vtx dAmpElectricityVertices[] = { {{{ 224, 0, -89}, 0, { 0, 480}, {0xff, 0xff, 0xff, 0xff}}}, {{{ 187, 149, 0}, 0, { 223, 1078}, {0xff, 0xff, 0xff, 0xff}}}, {{{ 224, 0, 90}, 0, { 479, 478}, {0xff, 0xff, 0xff, 0xff}}}, @@ -29,18 +24,16 @@ static const Vtx amp_seg8_vertex_08002B18[] = { {{{ 224, 0, -89}, 0, { 0, 478}, {0xff, 0xff, 0xff, 0xff}}}, }; -// 0x08002B68 - 0x08002BA0 -const Gfx amp_seg8_dl_08002B68[] = { - gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, amp_seg8_texture_08000F18), +const Gfx dAmpElectricitySubDl[] = { + gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dAmpElectricityTexture), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 16 * 32 - 1, CALC_DXT(16, G_IM_SIZ_16b_BYTES)), - gsSPVertex(amp_seg8_vertex_08002B18, 5, 0), + gsSPVertex(dAmpElectricityVertices, 5, 0), gsSP2Triangles( 0, 1, 2, 0x0, 2, 3, 4, 0x0), gsSPEndDisplayList(), }; -// 0x08002BA0 - 0x08002C10 -const Gfx amp_seg8_dl_08002BA0[] = { +const Gfx dAmpElectricityDl[] = { gsDPPipeSync(), gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA), gsSPClearGeometryMode(G_LIGHTING | G_CULL_BACK), @@ -49,7 +42,7 @@ const Gfx amp_seg8_dl_08002BA0[] = { gsDPTileSync(), gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 0, G_TX_RENDERTILE, 0, G_TX_CLAMP, 5, G_TX_NOLOD, G_TX_CLAMP, 4, G_TX_NOLOD), gsDPSetTileSize(0, 0, 0, (16 - 1) << G_TEXTURE_IMAGE_FRAC, (32 - 1) << G_TEXTURE_IMAGE_FRAC), - gsSPDisplayList(amp_seg8_dl_08002B68), + gsSPDisplayList(dAmpElectricitySubDl), gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF), gsDPPipeSync(), gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), @@ -57,26 +50,23 @@ const Gfx amp_seg8_dl_08002BA0[] = { gsSPEndDisplayList(), }; -// 0x08002C10 -static const Vtx amp_seg8_vertex_08002C10[] = { +static const Vtx dAmpEyeVertices[] = { {{{ 68, 72, 158}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, {{{ -27, -71, 164}, 0, { 990, 990}, {0xff, 0xff, 0xff, 0xff}}}, {{{ 68, -71, 158}, 0, { 990, 0}, {0xff, 0xff, 0xff, 0xff}}}, {{{ -27, 72, 164}, 0, { 0, 990}, {0xff, 0xff, 0xff, 0xff}}}, }; -// 0x08002C50 - 0x08002C88 -const Gfx amp_seg8_dl_08002C50[] = { - gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, amp_seg8_texture_08001318), +const Gfx dAmpEyeSubDl[] = { + gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dAmpEyesTexture), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 32 * 32 - 1, CALC_DXT(32, G_IM_SIZ_16b_BYTES)), - gsSPVertex(amp_seg8_vertex_08002C10, 4, 0), + gsSPVertex(dAmpEyeVertices, 4, 0), gsSP2Triangles( 0, 1, 2, 0x0, 0, 3, 1, 0x0), gsSPEndDisplayList(), }; -// 0x08002C88 - 0x08002CF8 -const Gfx amp_seg8_dl_08002C88[] = { +const Gfx dAmpEyeDl[] = { gsDPPipeSync(), gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA), gsSPClearGeometryMode(G_LIGHTING), @@ -85,7 +75,7 @@ const Gfx amp_seg8_dl_08002C88[] = { gsDPTileSync(), gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 0, G_TX_RENDERTILE, 0, G_TX_CLAMP, 5, G_TX_NOLOD, G_TX_CLAMP, 5, G_TX_NOLOD), gsDPSetTileSize(0, 0, 0, (32 - 1) << G_TEXTURE_IMAGE_FRAC, (32 - 1) << G_TEXTURE_IMAGE_FRAC), - gsSPDisplayList(amp_seg8_dl_08002C50), + gsSPDisplayList(dAmpEyeSubDl), gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF), gsDPPipeSync(), gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), @@ -93,26 +83,23 @@ const Gfx amp_seg8_dl_08002C88[] = { gsSPEndDisplayList(), }; -// 0x08002CF8 -static const Vtx amp_seg8_vertex_08002CF8[] = { +static const Vtx dAmpMouthVertices[] = { {{{ -29, 72, 164}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, {{{ -124, -71, 121}, 0, { 990, 990}, {0xff, 0xff, 0xff, 0xff}}}, {{{ -29, -71, 164}, 0, { 990, 0}, {0xff, 0xff, 0xff, 0xff}}}, {{{ -124, 72, 121}, 0, { 0, 990}, {0xff, 0xff, 0xff, 0xff}}}, }; -// 0x08002D38 - 0x08002D70 -const Gfx amp_seg8_dl_08002D38[] = { - gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, amp_seg8_texture_08002318), +const Gfx dAmpMouthSubDl[] = { + gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dAmpMouthTexture), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 32 * 32 - 1, CALC_DXT(32, G_IM_SIZ_16b_BYTES)), - gsSPVertex(amp_seg8_vertex_08002CF8, 4, 0), + gsSPVertex(dAmpMouthVertices, 4, 0), gsSP2Triangles( 0, 1, 2, 0x0, 0, 3, 1, 0x0), gsSPEndDisplayList(), }; -// 0x08002D70 - 0x08002DE0 -const Gfx amp_seg8_dl_08002D70[] = { +const Gfx dAmpMouthDl[] = { gsDPPipeSync(), gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA), gsSPClearGeometryMode(G_LIGHTING), @@ -121,7 +108,7 @@ const Gfx amp_seg8_dl_08002D70[] = { gsDPTileSync(), gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 0, G_TX_RENDERTILE, 0, G_TX_CLAMP, 5, G_TX_NOLOD, G_TX_CLAMP, 5, G_TX_NOLOD), gsDPSetTileSize(0, 0, 0, (32 - 1) << G_TEXTURE_IMAGE_FRAC, (32 - 1) << G_TEXTURE_IMAGE_FRAC), - gsSPDisplayList(amp_seg8_dl_08002D38), + gsSPDisplayList(dAmpMouthSubDl), gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF), gsDPPipeSync(), gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), @@ -129,26 +116,23 @@ const Gfx amp_seg8_dl_08002D70[] = { gsSPEndDisplayList(), }; -// 0x08002DE0 -static const Vtx amp_seg8_vertex_08002DE0[] = { +static const Vtx dAmpBodyVertices[] = { {{{ -39, -39, 0}, 0, { 0, 990}, {0xff, 0xff, 0xff, 0xff}}}, {{{ 40, 40, 0}, 0, { 990, 0}, {0xff, 0xff, 0xff, 0xff}}}, {{{ -39, 40, 0}, 0, { 0, 0}, {0xff, 0xff, 0xff, 0xff}}}, {{{ 40, -39, 0}, 0, { 990, 990}, {0xff, 0xff, 0xff, 0xff}}}, }; -// 0x08002E20 - 0x08002E58 -const Gfx amp_seg8_dl_08002E20[] = { - gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, amp_seg8_texture_08001B18), +const Gfx dAmpBodySubDl[] = { + gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, dAmpBodyTexture), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 32 * 32 - 1, CALC_DXT(32, G_IM_SIZ_16b_BYTES)), - gsSPVertex(amp_seg8_vertex_08002DE0, 4, 0), + gsSPVertex(dAmpBodyVertices, 4, 0), gsSP2Triangles( 0, 1, 2, 0x0, 0, 3, 1, 0x0), gsSPEndDisplayList(), }; -// 0x08002E58 - 0x08002EC8 -const Gfx amp_seg8_dl_08002E58[] = { +const Gfx dAmpBodyDl[] = { gsDPPipeSync(), gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA), gsSPClearGeometryMode(G_LIGHTING), @@ -157,7 +141,7 @@ const Gfx amp_seg8_dl_08002E58[] = { gsDPTileSync(), gsDPSetTile(G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 0, G_TX_RENDERTILE, 0, G_TX_CLAMP, 5, G_TX_NOLOD, G_TX_CLAMP, 5, G_TX_NOLOD), gsDPSetTileSize(0, 0, 0, (32 - 1) << G_TEXTURE_IMAGE_FRAC, (32 - 1) << G_TEXTURE_IMAGE_FRAC), - gsSPDisplayList(amp_seg8_dl_08002E20), + gsSPDisplayList(dAmpBodySubDl), gsSPTexture(0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF), gsDPPipeSync(), gsDPSetCombineMode(G_CC_SHADE, G_CC_SHADE), @@ -165,15 +149,18 @@ const Gfx amp_seg8_dl_08002E58[] = { gsSPEndDisplayList(), }; -// 0x08002EC8 -static const Lights1 amp_seg8_lights_08002EC8 = gdSPDefLights1( +/** + * Everything beyond this point is unused, and seems to be an attempt at a 3D modelled + * amp. The model and attempt are overall slightly buggy, with misread lights and a slightly + * broken model. + */ + +UNUSED static const Lights1 dAmpUnused3DLights = gdSPDefLights1( 0x33, 0x3f, 0x00, 0xcf, 0xff, 0x00, 0x28, 0x28, 0x28 ); -// //! Another malformed entry: Vertex interpreted as light -// 0x08002EE0 -static const Vtx amp_seg8_vertex_08002EE0[] = { +UNUSED static const Vtx dAmpUnused3DVtx01[] = { {{{ 280, 0, 35}, 0, { 0, 0}, {0x7b, 0xe2, 0x00, 0x00}}}, {{{ 240, -160, 0}, 0, { 0, 0}, {0x7b, 0xe2, 0x00, 0x00}}}, {{{ 280, 0, -35}, 0, { 0, 0}, {0x7b, 0xe2, 0x00, 0x00}}}, @@ -182,8 +169,7 @@ static const Vtx amp_seg8_vertex_08002EE0[] = { {{{ 280, 0, 35}, 0, { 0, 0}, {0x7b, 0x1e, 0x00, 0xff}}}, }; -// 0x08002F40 -static const Vtx amp_seg8_vertex_08002F40[] = { +UNUSED static const Vtx dAmpUnused3DVtx02[] = { {{{ 280, 0, 35}, 0, { 0, 0}, {0x7b, 0xe2, 0x00, 0x00}}}, {{{ 240, -160, 0}, 0, { 0, 0}, {0x7b, 0xe2, 0x00, 0x00}}}, {{{ 280, 0, -35}, 0, { 0, 0}, {0x7b, 0xe2, 0x00, 0x00}}}, @@ -192,8 +178,7 @@ static const Vtx amp_seg8_vertex_08002F40[] = { {{{ 280, 0, 35}, 0, { 0, 0}, {0x7b, 0x1e, 0x00, 0xff}}}, }; -// 0x08002FA0 -static const Vtx amp_seg8_vertex_08002FA0[] = { +UNUSED static const Vtx dAmpUnused3DVtx03[] = { {{{ 280, 0, 35}, 0, { 0, 0}, {0x7b, 0xe2, 0x00, 0x00}}}, {{{ 240, -160, 0}, 0, { 0, 0}, {0x7b, 0xe2, 0x00, 0x00}}}, {{{ 280, 0, -35}, 0, { 0, 0}, {0x7b, 0xe2, 0x00, 0x00}}}, @@ -202,8 +187,7 @@ static const Vtx amp_seg8_vertex_08002FA0[] = { {{{ 280, 0, 35}, 0, { 0, 0}, {0x7b, 0x1e, 0x00, 0xff}}}, }; -// 0x08003000 -static const Vtx amp_seg8_vertex_08003000[] = { +UNUSED static const Vtx dAmpUnused3DVtx04[] = { {{{ 280, 0, -35}, 0, { 0, 0}, {0x7b, 0x1e, 0x00, 0x00}}}, {{{ 240, 160, 0}, 0, { 0, 0}, {0x7b, 0x1e, 0x00, 0x00}}}, {{{ 280, 0, 35}, 0, { 0, 0}, {0x7b, 0x1e, 0x00, 0x00}}}, @@ -212,8 +196,7 @@ static const Vtx amp_seg8_vertex_08003000[] = { {{{ 280, 0, -35}, 0, { 0, 0}, {0x7b, 0xe2, 0x00, 0xff}}}, }; -// 0x08003060 -static const Vtx amp_seg8_vertex_08003060[] = { +UNUSED static const Vtx dAmpUnused3DVtx05[] = { {{{ -184, -54, -54}, 0, { 0, 0}, {0x8b, 0xde, 0xde, 0x00}}}, {{{ -184, -76, 0}, 0, { 0, 0}, {0x8b, 0xd0, 0x00, 0x00}}}, {{{ -200, 0, 0}, 0, { 0, 0}, {0x81, 0x00, 0x00, 0x00}}}, @@ -232,8 +215,7 @@ static const Vtx amp_seg8_vertex_08003060[] = { {{{ 200, 0, 0}, 0, { 0, 0}, {0x7f, 0x00, 0x00, 0xff}}}, }; -// 0x08003160 -static const Vtx amp_seg8_vertex_08003160[] = { +UNUSED static const Vtx dAmpUnused3DVtx06[] = { {{{ -184, 0, -76}, 0, { 0, 0}, {0x8b, 0x00, 0xd0, 0xff}}}, {{{ -184, -54, -54}, 0, { 0, 0}, {0x8b, 0xde, 0xde, 0x00}}}, {{{ -200, 0, 0}, 0, { 0, 0}, {0x81, 0x00, 0x00, 0x00}}}, @@ -252,8 +234,7 @@ static const Vtx amp_seg8_vertex_08003160[] = { {{{ 200, 0, 0}, 0, { 0, 0}, {0x7f, 0x00, 0x00, 0xff}}}, }; -// 0x08003260 -static const Vtx amp_seg8_vertex_08003260[] = { +UNUSED static const Vtx dAmpUnused3DVtx07[] = { {{{ -184, 54, -54}, 0, { 0, 0}, {0x8b, 0x22, 0xde, 0xff}}}, {{{ -184, 0, -76}, 0, { 0, 0}, {0x8b, 0x00, 0xd0, 0x00}}}, {{{ -200, 0, 0}, 0, { 0, 0}, {0x81, 0x00, 0x00, 0x00}}}, @@ -272,8 +253,7 @@ static const Vtx amp_seg8_vertex_08003260[] = { {{{ 200, 0, 0}, 0, { 0, 0}, {0x7f, 0x00, 0x00, 0xff}}}, }; -// 0x08003360 -static const Vtx amp_seg8_vertex_08003360[] = { +UNUSED static const Vtx dAmpUnused3DVtx08[] = { {{{ -184, 76, 0}, 0, { 0, 0}, {0x8b, 0x30, 0x00, 0xff}}}, {{{ -184, 54, -54}, 0, { 0, 0}, {0x8b, 0x22, 0xde, 0x00}}}, {{{ -200, 0, 0}, 0, { 0, 0}, {0x81, 0x00, 0x00, 0x00}}}, @@ -292,8 +272,7 @@ static const Vtx amp_seg8_vertex_08003360[] = { {{{ 200, 0, 0}, 0, { 0, 0}, {0x7f, 0x00, 0x00, 0xff}}}, }; -// 0x08003460 -static const Vtx amp_seg8_vertex_08003460[] = { +UNUSED static const Vtx dAmpUnused3DVtx09[] = { {{{ -184, 54, 54}, 0, { 0, 0}, {0x8b, 0x22, 0x22, 0xff}}}, {{{ -184, 76, 0}, 0, { 0, 0}, {0x8b, 0x30, 0x00, 0x00}}}, {{{ -200, 0, 0}, 0, { 0, 0}, {0x81, 0x00, 0x00, 0x00}}}, @@ -312,8 +291,7 @@ static const Vtx amp_seg8_vertex_08003460[] = { {{{ 200, 0, 0}, 0, { 0, 0}, {0x7f, 0x00, 0x00, 0xff}}}, }; -// 0x08003560 -static const Vtx amp_seg8_vertex_08003560[] = { +UNUSED static const Vtx dAmpUnused3DVtx10[] = { {{{ -184, 0, 76}, 0, { 0, 0}, {0x8b, 0x00, 0x30, 0xff}}}, {{{ -184, 54, 54}, 0, { 0, 0}, {0x8b, 0x22, 0x22, 0x00}}}, {{{ -200, 0, 0}, 0, { 0, 0}, {0x81, 0x00, 0x00, 0x00}}}, @@ -332,8 +310,7 @@ static const Vtx amp_seg8_vertex_08003560[] = { {{{ 200, 0, 0}, 0, { 0, 0}, {0x7f, 0x00, 0x00, 0xff}}}, }; -// 0x08003660 -static const Vtx amp_seg8_vertex_08003660[] = { +UNUSED static const Vtx dAmpUnused3DVtx11[] = { {{{ -184, -54, 54}, 0, { 0, 0}, {0x8b, 0xde, 0x22, 0xff}}}, {{{ -184, 0, 76}, 0, { 0, 0}, {0x8b, 0x00, 0x30, 0x00}}}, {{{ -200, 0, 0}, 0, { 0, 0}, {0x81, 0x00, 0x00, 0x00}}}, @@ -352,8 +329,7 @@ static const Vtx amp_seg8_vertex_08003660[] = { {{{ 200, 0, 0}, 0, { 0, 0}, {0x7f, 0x00, 0x00, 0xff}}}, }; -// 0x08003760 -static const Vtx amp_seg8_vertex_08003760[] = { +UNUSED static const Vtx dAmpUnused3DVtx12[] = { {{{ -184, -76, 0}, 0, { 0, 0}, {0x8b, 0xd0, 0x00, 0xff}}}, {{{ -184, -54, 54}, 0, { 0, 0}, {0x8b, 0xde, 0x22, 0x00}}}, {{{ -200, 0, 0}, 0, { 0, 0}, {0x81, 0x00, 0x00, 0x00}}}, @@ -372,70 +348,63 @@ static const Vtx amp_seg8_vertex_08003760[] = { {{{ 200, 0, 0}, 0, { 0, 0}, {0x7f, 0x00, 0x00, 0xff}}}, }; -// 0x08003860 -static const Vtx amp_seg8_vertex_08003860[] = { +UNUSED static const Vtx dAmpUnused3DVtx13[] = { {{{ -37, 90, 205}, 0, { 0, 0}, {0xcc, 0x00, 0x73, 0x00}}}, {{{ -129, 90, 163}, 0, { 0, 0}, {0xcc, 0x00, 0x73, 0x00}}}, {{{ -129, -90, 163}, 0, { 0, 0}, {0xcc, 0x00, 0x73, 0x00}}}, {{{ -37, -90, 205}, 0, { 0, 0}, {0xcc, 0x00, 0x73, 0xff}}}, }; -// 0x080038A0 -static const Vtx amp_seg8_vertex_080038A0[] = { +UNUSED static const Vtx dAmpUnused3DVtx14[] = { {{{ 112, -7, 182}, 0, { 0, 0}, {0x4c, 0xd8, 0x5c, 0x00}}}, {{{ 66, -139, 162}, 0, { 0, 0}, {0x4c, 0xd8, 0x5c, 0x00}}}, {{{ 175, -77, 98}, 0, { 0, 0}, {0x4c, 0xd8, 0x5c, 0x00}}}, }; -// 0x080038D0 -static const Vtx amp_seg8_vertex_080038D0[] = { +UNUSED static const Vtx dAmpUnused3DVtx15[] = { {{{ 63, 90, 198}, 0, { 0, 0}, {0x08, 0x00, 0x7e, 0x00}}}, {{{ -35, 90, 205}, 0, { 0, 0}, {0x08, 0x00, 0x7e, 0x00}}}, {{{ -35, -90, 205}, 0, { 0, 0}, {0x08, 0x00, 0x7e, 0x00}}}, {{{ 63, -90, 198}, 0, { 0, 0}, {0x08, 0x00, 0x7e, 0xff}}}, }; -// 0x08003910 - 0x08003940 -const Gfx amp_seg8_dl_08003910[] = { - gsSPLight(&_seg8_lights_08002EC8.l, 1), - gsSPLight(&_seg8_lights_08002EC8.a, 2), - gsSPVertex(amp_seg8_vertex_08002EE0, 6, 0), +UNUSED const Gfx dAmpUnused3DElectricDl1[] = { + gsSPLight(&dAmpUnused3DLights.l, 1), + gsSPLight(&dAmpUnused3DLights.a, 2), + gsSPVertex(dAmpUnused3DVtx01, 6, 0), gsSP2Triangles( 0, 1, 2, 0x0, 3, 4, 5, 0x0), gsSPEndDisplayList(), }; -// 0x08003940 - 0x08003970 -const Gfx amp_seg8_dl_08003940[] = { - gsSPLight(&_seg8_lights_08002EC8.l, 1), - gsSPLight(&_seg8_lights_08002EC8.a, 2), - gsSPVertex(amp_seg8_vertex_08002F40, 6, 0), +UNUSED const Gfx dAmpUnused3DElectricDl2[] = { + gsSPLight(&dAmpUnused3DLights.l, 1), + gsSPLight(&dAmpUnused3DLights.a, 2), + gsSPVertex(dAmpUnused3DVtx02, 6, 0), gsSP2Triangles( 0, 1, 2, 0x0, 3, 4, 5, 0x0), gsSPEndDisplayList(), }; -// 0x08003970 - 0x080039A0 -const Gfx amp_seg8_dl_08003970[] = { - gsSPLight(&_seg8_lights_08002EC8.l, 1), - gsSPLight(&_seg8_lights_08002EC8.a, 2), - gsSPVertex(amp_seg8_vertex_08002FA0, 6, 0), +UNUSED const Gfx dAmpUnused3DElectricDl3[] = { + gsSPLight(&dAmpUnused3DLights.l, 1), + gsSPLight(&dAmpUnused3DLights.a, 2), + gsSPVertex(dAmpUnused3DVtx03, 6, 0), gsSP2Triangles( 0, 1, 2, 0x0, 3, 4, 5, 0x0), gsSPEndDisplayList(), }; -// 0x080039A0 - 0x080039D0 -const Gfx amp_seg8_dl_080039A0[] = { - gsSPLight(&_seg8_lights_08002EC8.l, 1), - gsSPLight(&_seg8_lights_08002EC8.a, 2), - gsSPVertex(amp_seg8_vertex_08003000, 6, 0), +UNUSED const Gfx dAmpUnused3DElectricDl4[] = { + gsSPLight(&dAmpUnused3DLights.l, 1), + gsSPLight(&dAmpUnused3DLights.a, 2), + gsSPVertex(dAmpUnused3DVtx04, 6, 0), gsSP2Triangles( 0, 1, 2, 0x0, 3, 4, 5, 0x0), gsSPEndDisplayList(), }; -// 0x080039D0 - 0x08003DA8 -const Gfx amp_seg8_dl_080039D0[] = { - gsSPLight((const u8*)amp_seg8_vertex_08002EE0 + 0x8, 1), - gsSPLight((const u8*)amp_seg8_vertex_08002EE0, 2), - gsSPVertex(amp_seg8_vertex_08003060, 16, 0), +UNUSED const Gfx dAmpUnused3DModelDl[] = { + //! Vertex interpreted as light + gsSPLight((const u8*)dAmpUnused3DVtx01 + 0x8, 1), + gsSPLight((const u8*)dAmpUnused3DVtx01, 2), + gsSPVertex(dAmpUnused3DVtx05, 16, 0), gsSP2Triangles( 0, 1, 2, 0x0, 1, 0, 3, 0x0), gsSP2Triangles( 1, 3, 4, 0x0, 4, 3, 5, 0x0), gsSP2Triangles( 4, 5, 6, 0x0, 6, 5, 7, 0x0), @@ -443,7 +412,7 @@ const Gfx amp_seg8_dl_080039D0[] = { gsSP2Triangles( 8, 9, 10, 0x0, 10, 9, 11, 0x0), gsSP2Triangles(10, 11, 12, 0x0, 12, 11, 13, 0x0), gsSP2Triangles(12, 13, 14, 0x0, 14, 13, 15, 0x0), - gsSPVertex(amp_seg8_vertex_08003160, 16, 0), + gsSPVertex(dAmpUnused3DVtx06, 16, 0), gsSP2Triangles( 0, 1, 2, 0x0, 1, 0, 3, 0x0), gsSP2Triangles( 1, 3, 4, 0x0, 4, 3, 5, 0x0), gsSP2Triangles( 4, 5, 6, 0x0, 6, 5, 7, 0x0), @@ -451,7 +420,7 @@ const Gfx amp_seg8_dl_080039D0[] = { gsSP2Triangles( 8, 9, 10, 0x0, 10, 9, 11, 0x0), gsSP2Triangles(10, 11, 12, 0x0, 12, 11, 13, 0x0), gsSP2Triangles(12, 13, 14, 0x0, 14, 13, 15, 0x0), - gsSPVertex(amp_seg8_vertex_08003260, 16, 0), + gsSPVertex(dAmpUnused3DVtx07, 16, 0), gsSP2Triangles( 0, 1, 2, 0x0, 1, 0, 3, 0x0), gsSP2Triangles( 1, 3, 4, 0x0, 4, 3, 5, 0x0), gsSP2Triangles( 4, 5, 6, 0x0, 6, 5, 7, 0x0), @@ -459,7 +428,7 @@ const Gfx amp_seg8_dl_080039D0[] = { gsSP2Triangles( 8, 9, 10, 0x0, 10, 9, 11, 0x0), gsSP2Triangles(10, 11, 12, 0x0, 12, 11, 13, 0x0), gsSP2Triangles(12, 13, 14, 0x0, 14, 13, 15, 0x0), - gsSPVertex(amp_seg8_vertex_08003360, 16, 0), + gsSPVertex(dAmpUnused3DVtx08, 16, 0), gsSP2Triangles( 0, 1, 2, 0x0, 1, 0, 3, 0x0), gsSP2Triangles( 1, 3, 4, 0x0, 4, 3, 5, 0x0), gsSP2Triangles( 4, 5, 6, 0x0, 6, 5, 7, 0x0), @@ -467,7 +436,7 @@ const Gfx amp_seg8_dl_080039D0[] = { gsSP2Triangles( 8, 9, 10, 0x0, 10, 9, 11, 0x0), gsSP2Triangles(10, 11, 12, 0x0, 12, 11, 13, 0x0), gsSP2Triangles(12, 13, 14, 0x0, 14, 13, 15, 0x0), - gsSPVertex(amp_seg8_vertex_08003460, 16, 0), + gsSPVertex(dAmpUnused3DVtx09, 16, 0), gsSP2Triangles( 0, 1, 2, 0x0, 1, 0, 3, 0x0), gsSP2Triangles( 1, 3, 4, 0x0, 4, 3, 5, 0x0), gsSP2Triangles( 4, 5, 6, 0x0, 6, 5, 7, 0x0), @@ -475,7 +444,7 @@ const Gfx amp_seg8_dl_080039D0[] = { gsSP2Triangles( 8, 9, 10, 0x0, 10, 9, 11, 0x0), gsSP2Triangles(10, 11, 12, 0x0, 12, 11, 13, 0x0), gsSP2Triangles(12, 13, 14, 0x0, 14, 13, 15, 0x0), - gsSPVertex(amp_seg8_vertex_08003560, 16, 0), + gsSPVertex(dAmpUnused3DVtx10, 16, 0), gsSP2Triangles( 0, 1, 2, 0x0, 1, 0, 3, 0x0), gsSP2Triangles( 1, 3, 4, 0x0, 4, 3, 5, 0x0), gsSP2Triangles( 4, 5, 6, 0x0, 6, 5, 7, 0x0), @@ -483,7 +452,7 @@ const Gfx amp_seg8_dl_080039D0[] = { gsSP2Triangles( 8, 9, 10, 0x0, 10, 9, 11, 0x0), gsSP2Triangles(10, 11, 12, 0x0, 12, 11, 13, 0x0), gsSP2Triangles(12, 13, 14, 0x0, 14, 13, 15, 0x0), - gsSPVertex(amp_seg8_vertex_08003660, 16, 0), + gsSPVertex(dAmpUnused3DVtx11, 16, 0), gsSP2Triangles( 0, 1, 2, 0x0, 1, 0, 3, 0x0), gsSP2Triangles( 1, 3, 4, 0x0, 4, 3, 5, 0x0), gsSP2Triangles( 4, 5, 6, 0x0, 6, 5, 7, 0x0), @@ -491,7 +460,7 @@ const Gfx amp_seg8_dl_080039D0[] = { gsSP2Triangles( 8, 9, 10, 0x0, 10, 9, 11, 0x0), gsSP2Triangles(10, 11, 12, 0x0, 12, 11, 13, 0x0), gsSP2Triangles(12, 13, 14, 0x0, 14, 13, 15, 0x0), - gsSPVertex(amp_seg8_vertex_08003760, 16, 0), + gsSPVertex(dAmpUnused3DVtx12, 16, 0), gsSP2Triangles( 0, 1, 2, 0x0, 1, 0, 3, 0x0), gsSP2Triangles( 1, 3, 4, 0x0, 4, 3, 5, 0x0), gsSP2Triangles( 4, 5, 6, 0x0, 6, 5, 7, 0x0), @@ -502,29 +471,29 @@ const Gfx amp_seg8_dl_080039D0[] = { gsSPEndDisplayList(), }; -// 0x08003DA8 - 0x08003DD8 -const Gfx amp_seg8_dl_08003DA8[] = { - gsSPLight((const u8*)amp_seg8_vertex_08002EE0 + 0x8, 1), - gsSPLight((const u8*)amp_seg8_vertex_08002EE0, 2), - gsSPVertex(amp_seg8_vertex_08003860, 4, 0), +UNUSED const Gfx dAmpUnused3DElectricDl5[] = { + //! Vertex interpreted as light + gsSPLight((const u8*)dAmpUnused3DVtx01 + 0x8, 1), + gsSPLight((const u8*)dAmpUnused3DVtx01, 2), + gsSPVertex(dAmpUnused3DVtx13, 4, 0), gsSP2Triangles( 0, 1, 2, 0x0, 0, 2, 3, 0x0), gsSPEndDisplayList(), }; -// 0x08003DD8 - 0x08003E00 -const Gfx amp_seg8_dl_08003DD8[] = { - gsSPLight((const u8*)amp_seg8_vertex_08002EE0 + 0x8, 1), - gsSPLight((const u8*)amp_seg8_vertex_08002EE0, 2), - gsSPVertex(amp_seg8_vertex_080038A0, 3, 0), +UNUSED const Gfx dAmpUnused3DElectricDl6[] = { + //! Vertex interpreted as light + gsSPLight((const u8*)dAmpUnused3DVtx01 + 0x8, 1), + gsSPLight((const u8*)dAmpUnused3DVtx01, 2), + gsSPVertex(dAmpUnused3DVtx14, 3, 0), gsSP1Triangle( 0, 1, 2, 0x0), gsSPEndDisplayList(), }; -// 0x08003E00 - 0x08003E30 -const Gfx amp_seg8_dl_08003E00[] = { - gsSPLight((const u8*)amp_seg8_vertex_08002EE0 + 0x8, 1), - gsSPLight((const u8*)amp_seg8_vertex_08002EE0, 2), - gsSPVertex(amp_seg8_vertex_080038D0, 4, 0), +UNUSED const Gfx dAmpUnused3DElectricDl7[] = { + //! Vertex interpreted as light + gsSPLight((const u8*)dAmpUnused3DVtx01 + 0x8, 1), + gsSPLight((const u8*)dAmpUnused3DVtx01, 2), + gsSPVertex(dAmpUnused3DVtx15, 4, 0), gsSP2Triangles( 0, 1, 2, 0x0, 0, 2, 3, 0x0), gsSPEndDisplayList(), }; diff --git a/actors/bowser/flames_data.inc.c b/actors/bowser/flames_data.inc.c new file mode 100644 index 00000000..1ba334ab --- /dev/null +++ b/actors/bowser/flames_data.inc.c @@ -0,0 +1,98 @@ +// 0x060576FC + +const s16 dBowserFlamesOrientationValues[] = { +// posX, posY, posZ, rotY, rotX + 0, 280, 80, 0x00E9, 0x1A96, + 0, 278, 83, 0x00EC, 0x1C7F, + 0, 273, 92, 0x00F9, 0x20BF, + 0, 268, 102, 0x010F, 0x2519, + 0, 263, 109, 0x011D, 0x2751, + 0, 263, 110, 0x011C, 0x2714, + 0, 265, 106, 0x0112, 0x2601, + 0, 268, 102, 0x0109, 0x24C0, + 0, 271, 96, 0x00FF, 0x2358, + 0, 274, 90, 0x00F7, 0x21CB, + 0, 277, 84, 0x00EE, 0x201C, + 0, 280, 78, 0x00E7, 0x1E4E, + 0, 284, 71, 0x00DF, 0x1C64, + 0, 288, 63, 0x00D9, 0x1A61, + 0, 291, 56, 0x00D3, 0x184B, + 0, 295, 48, 0x00CF, 0x1622, + 0, 298, 40, 0x00CA, 0x13E9, + 0, 301, 32, 0x00C7, 0x11A5, + 0, 304, 23, 0x00C4, 0x0F59, + 0, 308, 15, 0x00C1, 0x0D08, + 0, 311, 7, 0x00C0, 0x0AB5, + 0, 313, 0, 0x00C0, 0x0863, + 0, 315, -8, 0x00BF, 0x0615, + 0, 317, -15, 0x00CE, 0x03A3, + 0, 319, -22, 0x00F8, 0x00ED, + 0, 320, -29, 0x0131, 0xFFFF, + 0, 322, -36, 0x0172, 0xFFFF, + 0, 322, -40, 0x01B5, 0xFFFF, + 0, 323, -45, 0x01ED, 0xFFFF, + 0, 323, -48, 0x0213, 0xFFFF, + 0, 323, -51, 0x0219, 0xFFFF, + 0, 323, -52, 0x01F2, 0xFFFF, + 0, 323, -51, 0x018F, 0xFFFF, + 0, 323, -49, 0x00E5, 0xFFFF, + 0, 322, -45, 0xFFFF, 0xFFFF, + 0, 320, -35, 0xFFFF, 0xFFFF, + 0, 317, -23, 0xFFFF, 0xFFFF, + 0, 312, -7, 0xFFFF, 0xFFFF, + 0, 306, 11, 0xFFFF, 0xFFFF, + 0, 299, 31, 0xFFFF, 0xFFFF, + 0, 288, 51, 0xFFFF, 0xFFFF, + 0, 278, 70, 0xFFFF, 0xFFFF, + 0, 267, 89, 0xFFFF, 0xFFFF, + 0, 256, 106, 0xFFFF, 0x023A, + 0, 244, 120, 0xFFFF, 0x04AA, + 0, 236, 132, 0xFFFF, 0x069F, + 0, 229, 139, 0xFFFF, 0x0803, + 0, 224, 144, 0xFFFF, 0x08C0, + 0, 222, 147, 0xFFFF, 0x0928, + 0, 221, 148, 0xFFFF, 0x099D, + 0, 221, 149, 0xFFFF, 0x0A16, + 0, 221, 150, 0xFFFF, 0x0A8D, + 0, 221, 150, 0xFFFF, 0x0AF6, + 0, 222, 150, 0xFFFF, 0x0B4A, + 0, 222, 150, 0xFFFF, 0x0B84, + 0, 222, 149, 0x020A, 0x0BA0, + 0, 223, 149, 0x0524, 0x0B9E, + 0, 225, 148, 0x07EC, 0x0B84, + 0, 226, 147, 0x0A3F, 0x0B57, + 0, 227, 145, 0x0BFB, 0x0B1F, + 0, 228, 144, 0x0D00, 0x0AE5, + 0, 230, 142, 0x0D6F, 0x0AA0, + 0, 232, 140, 0x0D8B, 0x0A48, + 0, 233, 138, 0x0D5D, 0x09DE, + 0, 236, 136, 0x0CED, 0x096A, + 0, 238, 134, 0x0C49, 0x08EA, + 0, 239, 132, 0x0B76, 0x0863, + 0, 241, 130, 0x0A80, 0x07D9, + 0, 244, 128, 0x0970, 0x074E, + 0, 246, 125, 0x084E, 0x06C7, + 0, 248, 122, 0x0723, 0x0649, + 0, 251, 120, 0x05F8, 0x05D7, + 0, 253, 117, 0x04D6, 0x0579, + 0, 254, 114, 0x03C3, 0x0532, + 0, 256, 111, 0x02C9, 0x0509, + 0, 259, 108, 0x01F0, 0x0504, + 0, 261, 105, 0x0141, 0x0525, + 0, 262, 103, 0x00C3, 0x0572, + 0, 264, 100, 0x006E, 0x0619, + 0, 267, 97, 0x0032, 0x0734, + 0, 268, 95, 0x000C, 0x08AF, + 0, 269, 93, 0xFFFF, 0x0A74, + 0, 272, 90, 0xFFFF, 0x0C70, + 0, 273, 88, 0xFFFF, 0x0E8E, + 0, 274, 86, 0x0014, 0x10B6, + 0, 275, 84, 0x0032, 0x12DA, + 0, 277, 82, 0x0056, 0x14E1, + 0, 277, 82, 0x007E, 0x16B9, + 0, 278, 80, 0x00A4, 0x184B, + 0, 278, 80, 0x00C6, 0x1983, + 0, 279, 80, 0x00DF, 0x1A4D, + 0, 280, 80, 0x00E9, 0x1A96, + 0, 0, 0, 0x0000, 0x0000, +}; diff --git a/actors/bowser/flames_pos.inc.c b/actors/bowser/flames_pos.inc.c deleted file mode 100644 index 25bddc3e..00000000 --- a/actors/bowser/flames_pos.inc.c +++ /dev/null @@ -1,96 +0,0 @@ -// 0x060576FC -const s16 bowser_seg6_unkmoveshorts_060576FC[] = { - 0x0000, 0x0118, 0x0050, 0x00E9, 0x1A96, - 0x0000, 0x0116, 0x0053, 0x00EC, 0x1C7F, - 0x0000, 0x0111, 0x005C, 0x00F9, 0x20BF, - 0x0000, 0x010C, 0x0066, 0x010F, 0x2519, - 0x0000, 0x0107, 0x006D, 0x011D, 0x2751, - 0x0000, 0x0107, 0x006E, 0x011C, 0x2714, - 0x0000, 0x0109, 0x006A, 0x0112, 0x2601, - 0x0000, 0x010C, 0x0066, 0x0109, 0x24C0, - 0x0000, 0x010F, 0x0060, 0x00FF, 0x2358, - 0x0000, 0x0112, 0x005A, 0x00F7, 0x21CB, - 0x0000, 0x0115, 0x0054, 0x00EE, 0x201C, - 0x0000, 0x0118, 0x004E, 0x00E7, 0x1E4E, - 0x0000, 0x011C, 0x0047, 0x00DF, 0x1C64, - 0x0000, 0x0120, 0x003F, 0x00D9, 0x1A61, - 0x0000, 0x0123, 0x0038, 0x00D3, 0x184B, - 0x0000, 0x0127, 0x0030, 0x00CF, 0x1622, - 0x0000, 0x012A, 0x0028, 0x00CA, 0x13E9, - 0x0000, 0x012D, 0x0020, 0x00C7, 0x11A5, - 0x0000, 0x0130, 0x0017, 0x00C4, 0x0F59, - 0x0000, 0x0134, 0x000F, 0x00C1, 0x0D08, - 0x0000, 0x0137, 0x0007, 0x00C0, 0x0AB5, - 0x0000, 0x0139, 0x0000, 0x00C0, 0x0863, - 0x0000, 0x013B, 0xFFF8, 0x00BF, 0x0615, - 0x0000, 0x013D, 0xFFF1, 0x00CE, 0x03A3, - 0x0000, 0x013F, 0xFFEA, 0x00F8, 0x00ED, - 0x0000, 0x0140, 0xFFE3, 0x0131, 0xFFFF, - 0x0000, 0x0142, 0xFFDC, 0x0172, 0xFFFF, - 0x0000, 0x0142, 0xFFD8, 0x01B5, 0xFFFF, - 0x0000, 0x0143, 0xFFD3, 0x01ED, 0xFFFF, - 0x0000, 0x0143, 0xFFD0, 0x0213, 0xFFFF, - 0x0000, 0x0143, 0xFFCD, 0x0219, 0xFFFF, - 0x0000, 0x0143, 0xFFCC, 0x01F2, 0xFFFF, - 0x0000, 0x0143, 0xFFCD, 0x018F, 0xFFFF, - 0x0000, 0x0143, 0xFFCF, 0x00E5, 0xFFFF, - 0x0000, 0x0142, 0xFFD3, 0xFFFF, 0xFFFF, - 0x0000, 0x0140, 0xFFDD, 0xFFFF, 0xFFFF, - 0x0000, 0x013D, 0xFFE9, 0xFFFF, 0xFFFF, - 0x0000, 0x0138, 0xFFF9, 0xFFFF, 0xFFFF, - 0x0000, 0x0132, 0x000B, 0xFFFF, 0xFFFF, - 0x0000, 0x012B, 0x001F, 0xFFFF, 0xFFFF, - 0x0000, 0x0120, 0x0033, 0xFFFF, 0xFFFF, - 0x0000, 0x0116, 0x0046, 0xFFFF, 0xFFFF, - 0x0000, 0x010B, 0x0059, 0xFFFF, 0xFFFF, - 0x0000, 0x0100, 0x006A, 0xFFFF, 0x023A, - 0x0000, 0x00F4, 0x0078, 0xFFFF, 0x04AA, - 0x0000, 0x00EC, 0x0084, 0xFFFF, 0x069F, - 0x0000, 0x00E5, 0x008B, 0xFFFF, 0x0803, - 0x0000, 0x00E0, 0x0090, 0xFFFF, 0x08C0, - 0x0000, 0x00DE, 0x0093, 0xFFFF, 0x0928, - 0x0000, 0x00DD, 0x0094, 0xFFFF, 0x099D, - 0x0000, 0x00DD, 0x0095, 0xFFFF, 0x0A16, - 0x0000, 0x00DD, 0x0096, 0xFFFF, 0x0A8D, - 0x0000, 0x00DD, 0x0096, 0xFFFF, 0x0AF6, - 0x0000, 0x00DE, 0x0096, 0xFFFF, 0x0B4A, - 0x0000, 0x00DE, 0x0096, 0xFFFF, 0x0B84, - 0x0000, 0x00DE, 0x0095, 0x020A, 0x0BA0, - 0x0000, 0x00DF, 0x0095, 0x0524, 0x0B9E, - 0x0000, 0x00E1, 0x0094, 0x07EC, 0x0B84, - 0x0000, 0x00E2, 0x0093, 0x0A3F, 0x0B57, - 0x0000, 0x00E3, 0x0091, 0x0BFB, 0x0B1F, - 0x0000, 0x00E4, 0x0090, 0x0D00, 0x0AE5, - 0x0000, 0x00E6, 0x008E, 0x0D6F, 0x0AA0, - 0x0000, 0x00E8, 0x008C, 0x0D8B, 0x0A48, - 0x0000, 0x00E9, 0x008A, 0x0D5D, 0x09DE, - 0x0000, 0x00EC, 0x0088, 0x0CED, 0x096A, - 0x0000, 0x00EE, 0x0086, 0x0C49, 0x08EA, - 0x0000, 0x00EF, 0x0084, 0x0B76, 0x0863, - 0x0000, 0x00F1, 0x0082, 0x0A80, 0x07D9, - 0x0000, 0x00F4, 0x0080, 0x0970, 0x074E, - 0x0000, 0x00F6, 0x007D, 0x084E, 0x06C7, - 0x0000, 0x00F8, 0x007A, 0x0723, 0x0649, - 0x0000, 0x00FB, 0x0078, 0x05F8, 0x05D7, - 0x0000, 0x00FD, 0x0075, 0x04D6, 0x0579, - 0x0000, 0x00FE, 0x0072, 0x03C3, 0x0532, - 0x0000, 0x0100, 0x006F, 0x02C9, 0x0509, - 0x0000, 0x0103, 0x006C, 0x01F0, 0x0504, - 0x0000, 0x0105, 0x0069, 0x0141, 0x0525, - 0x0000, 0x0106, 0x0067, 0x00C3, 0x0572, - 0x0000, 0x0108, 0x0064, 0x006E, 0x0619, - 0x0000, 0x010B, 0x0061, 0x0032, 0x0734, - 0x0000, 0x010C, 0x005F, 0x000C, 0x08AF, - 0x0000, 0x010D, 0x005D, 0xFFFF, 0x0A74, - 0x0000, 0x0110, 0x005A, 0xFFFF, 0x0C70, - 0x0000, 0x0111, 0x0058, 0xFFFF, 0x0E8E, - 0x0000, 0x0112, 0x0056, 0x0014, 0x10B6, - 0x0000, 0x0113, 0x0054, 0x0032, 0x12DA, - 0x0000, 0x0115, 0x0052, 0x0056, 0x14E1, - 0x0000, 0x0115, 0x0052, 0x007E, 0x16B9, - 0x0000, 0x0116, 0x0050, 0x00A4, 0x184B, - 0x0000, 0x0116, 0x0050, 0x00C6, 0x1983, - 0x0000, 0x0117, 0x0050, 0x00DF, 0x1A4D, - 0x0000, 0x0118, 0x0050, 0x00E9, 0x1A96, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, -}; diff --git a/actors/bowser/geo.inc.c b/actors/bowser/geo.inc.c index 06d2f13a..b59e23a6 100644 --- a/actors/bowser/geo.inc.c +++ b/actors/bowser/geo.inc.c @@ -110,10 +110,10 @@ const GeoLayout bowser_geo_0000D8[] = { const GeoLayout bowser_geo_000424[] = { GEO_SHADOW(SHADOW_CIRCLE_9_VERTS, 0x9B, 400), GEO_OPEN_NODE(), -#ifdef VERSION_JP - GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_06040210), -#else +#if BUGFIX_BOWSER_FADING_OUT GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_06040358), +#else + GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_06040210), #endif GEO_OPEN_NODE(), GEO_ANIMATED_PART(LAYER_TRANSPARENT, -89, -2, -18, NULL), @@ -200,10 +200,10 @@ const GeoLayout bowser_geo_000424[] = { GEO_OPEN_NODE(), GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_0603A4E8), GEO_CLOSE_NODE(), -#ifdef VERSION_JP - GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_0603B8D0), -#else +#if BUGFIX_BOWSER_FADING_OUT GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_0603B948), +#else + GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_0603B8D0), #endif GEO_CLOSE_NODE(), GEO_CLOSE_NODE(), @@ -226,10 +226,10 @@ const GeoLayout bowser_geo_000424[] = { const GeoLayout bowser_geo_000770[] = { GEO_NODE_START(), GEO_OPEN_NODE(), -#ifdef VERSION_JP - GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_06040210), -#else +#if BUGFIX_BOWSER_FADING_OUT GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_06040358), +#else + GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_06040210), #endif GEO_OPEN_NODE(), GEO_ANIMATED_PART(LAYER_TRANSPARENT, -89, -2, -18, NULL), @@ -316,10 +316,10 @@ const GeoLayout bowser_geo_000770[] = { GEO_OPEN_NODE(), GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_0603A4E8), GEO_CLOSE_NODE(), -#ifdef VERSION_JP - GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_0603B8D0), -#else +#if BUGFIX_BOWSER_FADING_OUT GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_0603B948), +#else + GEO_ANIMATED_PART(LAYER_TRANSPARENT, 0, 0, 0, bowser_seg6_dl_0603B8D0), #endif GEO_CLOSE_NODE(), GEO_CLOSE_NODE(), @@ -341,7 +341,7 @@ const GeoLayout bowser_geo_000770[] = { #ifndef VERSION_JP // 0x0D000AB8 const GeoLayout bowser_shadow_geo[] = { - GEO_SHADOW(0x00, 0x9B, 400), + GEO_SHADOW(SHADOW_CIRCLE_9_VERTS, 0x9B, 400), GEO_RETURN(), }; #endif @@ -351,11 +351,10 @@ const GeoLayout bowser_geo[] = { GEO_NODE_START(), GEO_OPEN_NODE(), GEO_ASM(0, geo_update_layer_transparency), -#ifdef VERSION_JP - GEO_SWITCH_CASE(2, geo_switch_anim_state), -#endif #ifndef VERSION_JP GEO_SWITCH_CASE(3, geo_switch_anim_state), +#else + GEO_SWITCH_CASE(2, geo_switch_anim_state), #endif GEO_OPEN_NODE(), GEO_NODE_START(), @@ -384,19 +383,16 @@ const GeoLayout bowser_geo[] = { }; // 0x0D000B18 / 0B40 -const GeoLayout bowser2_geo[] = { +const GeoLayout bowser_geo_no_shadow[] = { GEO_NODE_START(), GEO_OPEN_NODE(), GEO_ASM(0, geo_update_layer_transparency), - -#ifdef VERSION_JP - GEO_SWITCH_CASE(2, geo_switch_anim_state), -#endif #ifndef VERSION_JP GEO_SWITCH_CASE(3, geo_switch_anim_state), +#else + GEO_SWITCH_CASE(2, geo_switch_anim_state), #endif GEO_OPEN_NODE(), - GEO_NODE_START(), GEO_OPEN_NODE(), GEO_ASM(0, geo_bits_bowser_coloring), diff --git a/actors/bowser/model.inc.c b/actors/bowser/model.inc.c index 69a0b083..24ba7c59 100644 --- a/actors/bowser/model.inc.c +++ b/actors/bowser/model.inc.c @@ -1184,7 +1184,7 @@ const Gfx bowser_seg6_dl_0603B8D0[] = { gsSPEndDisplayList(), }; -#ifndef VERSION_JP +#if BUGFIX_BOWSER_FADING_OUT // 0x0603B948 - 0x0603B9C8 const Gfx bowser_seg6_dl_0603B948[] = { gsDPPipeSync(), @@ -2870,7 +2870,7 @@ const Gfx bowser_seg6_dl_06040210[] = { gsSPEndDisplayList(), }; -#ifndef VERSION_JP +#if BUGFIX_BOWSER_FADING_OUT // 0x06040358 - 0x06040428 const Gfx bowser_seg6_dl_06040358[] = { gsDPPipeSync(), diff --git a/actors/common0.h b/actors/common0.h index f4a791db..53c7f396 100644 --- a/actors/common0.h +++ b/actors/common0.h @@ -4,24 +4,12 @@ #include "types.h" // amp -extern const GeoLayout amp_geo[]; -extern const Gfx amp_seg8_dl_08002B68[]; -extern const Gfx amp_seg8_dl_08002BA0[]; -extern const Gfx amp_seg8_dl_08002C50[]; -extern const Gfx amp_seg8_dl_08002C88[]; -extern const Gfx amp_seg8_dl_08002D38[]; -extern const Gfx amp_seg8_dl_08002D70[]; -extern const Gfx amp_seg8_dl_08002E20[]; -extern const Gfx amp_seg8_dl_08002E58[]; -extern const Gfx amp_seg8_dl_08003910[]; -extern const Gfx amp_seg8_dl_08003940[]; -extern const Gfx amp_seg8_dl_08003970[]; -extern const Gfx amp_seg8_dl_080039A0[]; -extern const Gfx amp_seg8_dl_080039D0[]; -extern const Gfx amp_seg8_dl_08003DA8[]; -extern const Gfx amp_seg8_dl_08003DD8[]; -extern const Gfx amp_seg8_dl_08003E00[]; -extern const struct Animation *const amp_seg8_anims_08004034[]; +extern const GeoLayout dAmpGeo[]; +extern const Gfx dAmpElectricityDl[]; +extern const Gfx dAmpEyeDl[]; +extern const Gfx dAmpMouthDl[]; +extern const Gfx dAmpBodyDl[]; +extern const struct Animation *const dAmpAnimsList[]; // blue_coin_switch extern const GeoLayout blue_coin_switch_geo[]; diff --git a/actors/group0.h b/actors/group0.h index 44f8b05d..62387f20 100644 --- a/actors/group0.h +++ b/actors/group0.h @@ -236,7 +236,7 @@ extern const Gfx mario_right_hand_cap_bottom_dl[]; extern const Gfx mario_right_hand_cap_dl[]; extern const Gfx mario_right_hand_cap_wings_half_1_dl[]; extern const Gfx mario_right_hand_cap_wings_half_2_dl[]; -extern const Gfx mario_right_hand_cap_wings_intial_dl[]; +extern const Gfx mario_right_hand_cap_wings_initial_dl[]; extern const Gfx mario_right_hand_cap_wings_end_dl[]; extern const Gfx mario_right_hand_cap[]; extern const Gfx mario_right_hand_cap_wings[]; @@ -250,7 +250,7 @@ extern const Gfx mario_cap_unused_base_bottom_dl[]; extern const Gfx mario_cap_unused_base_dl[]; extern const Gfx mario_wings_half_1_unused_dl[]; extern const Gfx mario_wings_half_2_unused_dl[]; -extern const Gfx mario_cap_wings_unused_intial_dl[]; +extern const Gfx mario_cap_wings_unused_initial_dl[]; extern const Gfx mario_cap_wings_unused_end_dl[]; extern const Gfx mario_cap_unused_dl[]; extern const Gfx mario_metal_cap_unused_dl[]; diff --git a/actors/group12.c b/actors/group12.c index b6ed0af7..ece6a0bd 100644 --- a/actors/group12.c +++ b/actors/group12.c @@ -18,7 +18,7 @@ UNUSED static const u64 binid_2 = 2; #include "bowser/model.inc.c" #include "bowser/anims/data.inc.c" #include "bowser/anims/table.inc.c" -#include "bowser/flames_pos.inc.c" +#include "bowser/flames_data.inc.c" UNUSED static const u64 binid_3 = 3; #include "bomb/model.inc.c" diff --git a/actors/group12.h b/actors/group12.h index 2a73af21..02258c86 100644 --- a/actors/group12.h +++ b/actors/group12.h @@ -17,7 +17,7 @@ extern const GeoLayout bowser_geo_000424[]; extern const GeoLayout bowser_geo_000770[]; extern const GeoLayout bowser_shadow_geo[]; extern const GeoLayout bowser_geo[]; -extern const GeoLayout bowser2_geo[]; +extern const GeoLayout bowser_geo_no_shadow[]; extern const Gfx bowser_seg6_dl_06039110[]; extern const Gfx bowser_seg6_dl_060391C8[]; extern const Gfx bowser_seg6_dl_06039260[]; @@ -90,7 +90,7 @@ extern const Gfx bowser_seg6_dl_06043548[]; extern const Gfx bowser_seg6_dl_06043648[]; extern const Gfx bowser_seg6_dl_06043698[]; extern const struct Animation *const bowser_seg6_anims_06057690[]; -extern const s16 bowser_seg6_unkmoveshorts_060576FC[]; +extern const s16 dBowserFlamesOrientationValues[]; // bowser_flame extern const GeoLayout bowser_flames_geo[]; diff --git a/actors/king_bobomb/model.inc.c b/actors/king_bobomb/model.inc.c index 3065684c..fb933b86 100644 --- a/actors/king_bobomb/model.inc.c +++ b/actors/king_bobomb/model.inc.c @@ -55,6 +55,11 @@ ALIGNED8 static const Texture king_bobomb_seg5_texture_05004878[] = { #include "actors/king_bobomb/king_bob-omb_eyes.rgba16.inc.c" }; +// 0x05005078 - Unused +ALIGNED8 static const Texture king_bobomb_seg5_texture_05005078[] = { +#include "actors/king_bobomb/king_bob-omb_eyes_blink.rgba16.inc.c" +}; + // 0x05005878 ALIGNED8 static const Texture king_bobomb_seg5_texture_05005878[] = { #include "actors/king_bobomb/king_bob-omb_hand.rgba16.inc.c" diff --git a/actors/mario/model.inc.c b/actors/mario/model.inc.c index 191d5332..e5d632e1 100644 --- a/actors/mario/model.inc.c +++ b/actors/mario/model.inc.c @@ -6060,7 +6060,7 @@ const Gfx mario_right_hand_cap_wings_half_2_dl[] = { }; // 0x0401B0E0 - 0x0401B138 -const Gfx mario_right_hand_cap_wings_intial_dl[] = { +const Gfx mario_right_hand_cap_wings_initial_dl[] = { gsDPPipeSync(), gsDPSetCombineMode(G_CC_MODULATERGBFADEA, G_CC_MODULATERGBFADEA), gsSPClearGeometryMode(G_CULL_BACK | G_SHADING_SMOOTH), @@ -6104,7 +6104,7 @@ const Gfx mario_right_hand_cap[] = { // 0x0401B1D8 - 0x0401B230 const Gfx mario_right_hand_cap_wings[] = { - gsSPDisplayList(mario_right_hand_cap_wings_intial_dl), + gsSPDisplayList(mario_right_hand_cap_wings_initial_dl), gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, mario_texture_wings_half_1), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 32 * 64 - 1, CALC_DXT(32, G_IM_SIZ_16b_BYTES)), @@ -6132,7 +6132,7 @@ const Gfx mario_metal_right_hand_cap_shared_dl[] = { // 0x0401B278 - 0x0401B2D0 const Gfx mario_metal_right_hand_cap_shared_dl_wings[] = { - gsSPDisplayList(mario_right_hand_cap_wings_intial_dl), + gsSPDisplayList(mario_right_hand_cap_wings_initial_dl), gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, mario_texture_metal_wings_half_1), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 32 * 64 - 1, CALC_DXT(32, G_IM_SIZ_16b_BYTES)), @@ -6590,7 +6590,7 @@ const Gfx mario_wings_half_2_unused_dl[] = { }; // 0x0401C6D8 - 0x0401C730 -const Gfx mario_cap_wings_unused_intial_dl[] = { +const Gfx mario_cap_wings_unused_initial_dl[] = { gsDPPipeSync(), gsDPSetCombineMode(G_CC_MODULATERGBA, G_CC_MODULATERGBA), gsSPClearGeometryMode(G_CULL_BACK | G_SHADING_SMOOTH), @@ -6656,7 +6656,7 @@ const Gfx mario_metal_cap_unused_dl[] = { // 0x0401C890 - 0x0401C8E8 # Unreferenced, unused like the duplicated cap, same case const Gfx mario_cap_wings_unused[] = { - gsSPDisplayList(mario_cap_wings_unused_intial_dl), + gsSPDisplayList(mario_cap_wings_unused_initial_dl), gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, mario_texture_wings_half_1), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 32 * 64 - 1, CALC_DXT(32, G_IM_SIZ_16b_BYTES)), @@ -6671,7 +6671,7 @@ const Gfx mario_cap_wings_unused[] = { // 0x0401C8E8 - 0x0401C940 # Unreferenced, unused like the duplicated cap, same case const Gfx mario_metal_cap_wings_unused[] = { - gsSPDisplayList(mario_cap_wings_unused_intial_dl), + gsSPDisplayList(mario_cap_wings_unused_initial_dl), gsDPSetTextureImage(G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, mario_texture_metal_wings_half_1), gsDPLoadSync(), gsDPLoadBlock(G_TX_LOADTILE, 0, 0, 32 * 64 - 1, CALC_DXT(32, G_IM_SIZ_16b_BYTES)), diff --git a/asm/boot.s b/asm/boot.s index be12ff0a..17a0ace7 100644 --- a/asm/boot.s +++ b/asm/boot.s @@ -1,21 +1,21 @@ -# assembler directives -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +// assembler directives +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" -# 0xA0000000-0xBFFFFFFF: KSEG1 direct map non-cache mirror of 0x00000000 -# 0xA4000000-0xA4000FFF: RSP DMEM +// 0xA0000000-0xBFFFFFFF: KSEG1 direct map non-cache mirror of 0x00000000 +// 0xA4000000-0xA4000FFF: RSP DMEM -# 0xA4000000-0xA400003F: ROM header +// 0xA4000000-0xA400003F: ROM header .section .text, "ax" -# 0xA4000040-0xA4000B6F: IPL3 +// 0xA4000040-0xA4000B6F: IPL3 -# IPL3 entry point jumped to from IPL2 -glabel ipl3_entry # 0xA4000040 +// IPL3 entry point jumped to from IPL2 +glabel ipl3_entry // 0xA4000040 mtc0 $zero, $13 mtc0 $zero, $9 mtc0 $zero, $11 @@ -797,7 +797,7 @@ func_A4000AD0: nop nop -# 0xA4000B70-0xA4000FFF: IPL3 Font +// 0xA4000B70-0xA4000FFF: IPL3 Font glabel ipl3_font .incbin "textures/ipl3_raw/ipl3_font_00.ia1" .incbin "textures/ipl3_raw/ipl3_font_01.ia1" diff --git a/asm/decompress.s b/asm/decompress.s index 1399179d..4c1733e4 100644 --- a/asm/decompress.s +++ b/asm/decompress.s @@ -1,61 +1,17 @@ -# assembler directives -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +// assembler directives +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" -# This file is handwritten. +// This file is handwritten. glabel decompress -.if VERSION_SH == 1 - lw $a3, 8($a0) - lw $t9, 0xc($a0) - lw $t8, 4($a0) - add $a3, $a3, $a0 - add $t9, $t9, $a0 - move $a2, $zero - addi $a0, $a0, 0x10 - add $t8, $t8, $a1 -.L802772C0: - bnel $a2, $zero, .L802772D8 - slt $t1, $t0, $zero - lw $t0, ($a0) - li $a2, 32 - addi $a0, $a0, 4 - slt $t1, $t0, $zero -.L802772D8: - beql $t1, $zero, .L802772F8 - lhu $t2, ($a3) - lb $t2, ($t9) - addi $t9, $t9, 1 - addi $a1, $a1, 1 - b .L80277324 - sb $t2, -1($a1) - lhu $t2, ($a3) -.L802772F8: - addi $a3, $a3, 2 - srl $t3, $t2, 0xc - andi $t2, $t2, 0xfff - sub $t1, $a1, $t2 - addi $t3, $t3, 3 -.L8027730C: - lb $t2, -1($t1) - addi $t3, $t3, -1 - addi $t1, $t1, 1 - addi $a1, $a1, 1 - bnez $t3, .L8027730C - sb $t2, -1($a1) -.L80277324: - sll $t0, $t0, 1 - bne $a1, $t8, .L802772C0 - addi $a2, $a2, -1 - jr $ra - nop -.elseif VERSION_EU == 1 +#if defined(VERSION_EU) || defined(VERSION_SH) lw $a3, 8($a0) lw $t9, 0xc($a0) lw $t8, 4($a0) @@ -99,7 +55,7 @@ glabel decompress addi $a2, $a2, -1 jr $ra nop -.else +#else lw $t8, 4($a0) lw $a3, 8($a0) lw $t9, 0xc($a0) @@ -146,4 +102,4 @@ glabel decompress nop jr $ra nop -.endif +#endif diff --git a/asm/entry.s b/asm/entry.s index 755e1b4b..fa95d8e1 100644 --- a/asm/entry.s +++ b/asm/entry.s @@ -1,29 +1,29 @@ -# assembler directives -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +// assembler directives +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" glabel entry_point - lui $t0, %hi(_mainSegmentNoloadStart) # $t0, 0x8034 - lui $t1, %lo(_mainSegmentNoloadSizeHi) # lui $t1, 2 - addiu $t0, %lo(_mainSegmentNoloadStart) # addiu $t0, $t0, -0x6df0 - ori $t1, %lo(_mainSegmentNoloadSizeLo) # ori $t1, $t1, 0xcee0 + lui $t0, %hi(_mainSegmentNoloadStart) // $t0, 0x8034 + lui $t1, %lo(_mainSegmentNoloadSizeHi) // lui $t1, 2 + addiu $t0, %lo(_mainSegmentNoloadStart) // addiu $t0, $t0, -0x6df0 + ori $t1, %lo(_mainSegmentNoloadSizeLo) // ori $t1, $t1, 0xcee0 .L80246010: addi $t1, $t1, -8 sw $zero, ($t0) sw $zero, 4($t0) bnez $t1, .L80246010 addi $t0, $t0, 8 - lui $t2, %hi(main_func) # $t2, 0x8024 - lui $sp, %hi(gIdleThreadStack) # $sp, 0x8020 - addiu $t2, %lo(main_func) # addiu $t2, $t2, 0x6dc4 + lui $t2, %hi(main_func) // $t2, 0x8024 + lui $sp, %hi(gIdleThreadStack) // $sp, 0x8020 + addiu $t2, %lo(main_func) // addiu $t2, $t2, 0x6dc4 jr $t2 - addiu $sp, %lo(gIdleThreadStack) # addiu $sp, $sp, 0xa00 + addiu $sp, %lo(gIdleThreadStack) // addiu $sp, $sp, 0xa00 nop nop nop diff --git a/asm/rom_header.s b/asm/rom_header.s index c056acdb..af8b9afd 100644 --- a/asm/rom_header.s +++ b/asm/rom_header.s @@ -8,38 +8,39 @@ .word entry_point /* Entrypoint */ /* Revision */ -.if VERSION_SH == 1 +#ifdef VERSION_SH .word 0x00001448 -.elseif VERSION_EU == 1 +#elif defined(VERSION_EU) .word 0x00001446 -.else /* NTSC-U and NTSC-J 1.0 */ +#else /* NTSC-U and NTSC-J 1.0 */ .word 0x00001444 -.endif +#endif .word 0x4EAA3D0E /* Checksum 1 */ .word 0x74757C24 /* Checksum 2 */ .word 0x00000000 /* Unknown */ .word 0x00000000 /* Unknown */ -.if VERSION_SH == 1 +#ifdef VERSION_SH .ascii "SUPERMARIO64 " /* Internal ROM name */ -.else +#else .ascii "SUPER MARIO 64 " /* Internal ROM name */ -.endif +#endif .word 0x00000000 /* Unknown */ .word 0x0000004E /* Cartridge */ .ascii "SM" /* Cartridge ID */ /* Region */ -.if VERSION_US == 1 - .ascii "E" /* NTSC-U (North America) */ -.elseif (VERSION_JP == 1 || VERSION_SH == 1) - .ascii "J" /* NTSC-J (Japan) */ -.else +#ifdef VERSION_EU .ascii "P" /* PAL (Europe) */ -.endif +#elif defined(VERSION_US) + .ascii "E" /* NTSC-U (North America) */ +#else + .ascii "J" /* NTSC-J (Japan) */ +#endif -.if VERSION_SH == 1 + +#ifdef VERSION_SH .byte 0x03 /* Version (Shindou) */ -.else +#else .byte 0x00 /* Version */ -.endif +#endif diff --git a/assets.json b/assets.json index dd27f39f..691735f2 100644 --- a/assets.json +++ b/assets.json @@ -266,8 +266,9 @@ "actors/king_bobomb/king_bob-omb_arm.rgba16.png": [32,32,2048,{"jp":[1257760,8312],"us":[1264928,8312],"eu":[1136896,8312],"sh":[1113408,8312]}], "actors/king_bobomb/king_bob-omb_body_unused.rgba16.png": [64,64,8192,{"jp":[1257760,10360],"us":[1264928,10360],"eu":[1136896,10360],"sh":[1113408,10360]}], "actors/king_bobomb/king_bob-omb_crown_rim.rgba16.png": [32,16,1024,{"jp":[1257760,24696],"us":[1264928,24696],"eu":[1136896,24696],"sh":[1113408,24696]}], -"actors/king_bobomb/king_bob-omb_eyes.rgba16.png": [32,64,4096,{"jp":[1257760,18552],"us":[1264928,18552],"eu":[1136896,18552],"sh":[1113408,18552]}], -"actors/king_bobomb/king_bob-omb_hand.rgba16.png": [32,32,2048,{"jp":[1215456,64],"us":[1222624,64],"eu":[1094592,64],"sh":[1071104,64]}], +"actors/king_bobomb/king_bob-omb_eyes.rgba16.png": [32,32,2048,{"jp":[1257760,18552],"us":[1264928,18552],"eu":[1136896,18552],"sh":[1113408,18552]}], +"actors/king_bobomb/king_bob-omb_eyes_blink.rgba16.png": [32,32,2048,{"jp":[1257760,20600],"us":[1264928,20600],"eu":[1136896,20600],"sh":[1113408,20600]}], +"actors/king_bobomb/king_bob-omb_hand.rgba16.png": [32,32,2048,{"jp":[1257760,22648],"us":[1264928,22648],"eu":[1136896,22648],"sh":[1113408,22648]}], "actors/king_bobomb/king_bob-omb_left_side.rgba16.png": [32,64,4096,{"jp":[1257760,33912],"us":[1264928,33912],"eu":[1136896,33912],"sh":[1113408,33912]}], "actors/king_bobomb/king_bob-omb_right_side.rgba16.png": [32,64,4096,{"jp":[1257760,38008],"us":[1264928,38008],"eu":[1136896,38008],"sh":[1113408,38008]}], "actors/klepto/klepto_beak.rgba16.png": [32,64,4096,{"jp":[1327760,4104],"us":[1334928,4104],"eu":[1206896,4104],"sh":[1183408,4104]}], diff --git a/bin/segment2.c b/bin/segment2.c index eb2bdb3a..ea305277 100644 --- a/bin/segment2.c +++ b/bin/segment2.c @@ -2097,13 +2097,13 @@ const Gfx dl_hud_img_begin[] = { gsDPSetTexturePersp(G_TP_NONE), gsDPSetAlphaCompare(G_AC_THRESHOLD), gsDPSetBlendColor(255, 255, 255, 255), -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_JP) || defined(VERSION_US) + gsDPSetRenderMode(G_RM_AA_XLU_SURF, G_RM_AA_XLU_SURF2), +#else gsDPSetRenderMode(G_RM_NOOP, G_RM_NOOP2), #endif #ifdef VERSION_EU gsDPSetTextureFilter(G_TF_POINT), -#elif defined(VERSION_JP) || defined(VERSION_US) - gsDPSetRenderMode(G_RM_AA_XLU_SURF, G_RM_AA_XLU_SURF2), #endif gsSPEndDisplayList(), }; @@ -2498,7 +2498,7 @@ const Texture texture_waterbox_lava[] = { }; // Unreferenced light group -static const Lights1 segment2_lights_unused = gdSPDefLights1( +UNUSED static const Lights1 segment2_lights_unused = gdSPDefLights1( 0x40, 0x40, 0x40, 0xff, 0xff, 0xff, 0x28, 0x28, 0x28 ); diff --git a/data/behavior_data.c b/data/behavior_data.c index 9d11492b..e9234e53 100644 --- a/data/behavior_data.c +++ b/data/behavior_data.c @@ -874,7 +874,7 @@ const BehaviorScript bhvMrIBlueCoin[] = { OR_INT(oFlags, OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE), BILLBOARD(), SET_INT(oIntangibleTimer, 0), - SET_FLOAT(oMrIUnk110, 20), + SET_FLOAT(oCoinUnk110, 20), SET_INT(oAnimState, -1), SET_OBJ_PHYSICS(/*Wall hitbox radius*/ 30, /*Gravity*/ -400, /*Bounciness*/ -70, /*Drag strength*/ 1000, /*Friction*/ 1000, /*Buoyancy*/ 200, /*Unused*/ 0, 0), CALL_NATIVE(bhv_coin_init), @@ -1965,6 +1965,7 @@ const BehaviorScript bhvBowser[] = { SPAWN_CHILD(/*Model*/ MODEL_NONE, /*Behavior*/ bhvBowserBodyAnchor), SPAWN_CHILD(/*Model*/ MODEL_BOWSER_BOMB_CHILD_OBJ, /*Behavior*/ bhvBowserFlameSpawn), SPAWN_OBJ(/*Model*/ MODEL_NONE, /*Behavior*/ bhvBowserTailAnchor), + // Beta leftover that spawn 50 coins when Bowser is defeated SET_INT(oNumLootCoins, 50), SET_OBJ_PHYSICS(/*Wall hitbox radius*/ 0, /*Gravity*/ -400, /*Bounciness*/ -70, /*Drag strength*/ 1000, /*Friction*/ 1000, /*Buoyancy*/ 200, /*Unused*/ 0, 0), SET_HOME(), @@ -3023,7 +3024,7 @@ const BehaviorScript bhvHiddenStaircaseStep[] = { END_LOOP(), }; -const BehaviorScript bhvBooBossSpawnedBridge[] = { +const BehaviorScript bhvBooStaircase[] = { BEGIN(OBJ_LIST_SURFACE), OR_INT(oFlags, OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE), LOAD_COLLISION_DATA(bbh_seg7_collision_staircase_step), @@ -3031,7 +3032,7 @@ const BehaviorScript bhvBooBossSpawnedBridge[] = { SET_FLOAT(oCollisionDistance, 1000), SET_HOME(), BEGIN_LOOP(), - CALL_NATIVE(bhv_boo_boss_spawned_bridge_loop), + CALL_NATIVE(bhv_boo_staircase), CALL_NATIVE(load_object_collision_model), END_LOOP(), }; @@ -3141,7 +3142,7 @@ const BehaviorScript bhvUnusedFakeStar[] = { }; // What is this? -static const BehaviorScript unused_1[] = { +UNUSED static const BehaviorScript unused_1[] = { BREAK(), BREAK(), BREAK(), @@ -3851,7 +3852,7 @@ const BehaviorScript bhvSignOnWall[] = { const BehaviorScript bhvHomingAmp[] = { BEGIN(OBJ_LIST_GENACTOR), OR_INT(oFlags, (OBJ_FLAG_COMPUTE_ANGLE_TO_MARIO | OBJ_FLAG_COMPUTE_DIST_TO_MARIO | OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW | OBJ_FLAG_MOVE_XZ_USING_FVEL | OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE)), - LOAD_ANIMATIONS(oAnimations, amp_seg8_anims_08004034), + LOAD_ANIMATIONS(oAnimations, dAmpAnimsList), ANIMATE(0), SET_FLOAT(oGraphYOffset, 40), SET_INT(oIntangibleTimer, 0), @@ -3864,7 +3865,7 @@ const BehaviorScript bhvHomingAmp[] = { const BehaviorScript bhvCirclingAmp[] = { BEGIN(OBJ_LIST_GENACTOR), OR_INT(oFlags, (OBJ_FLAG_COMPUTE_ANGLE_TO_MARIO | OBJ_FLAG_COMPUTE_DIST_TO_MARIO | OBJ_FLAG_MOVE_XZ_USING_FVEL | OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE)), - LOAD_ANIMATIONS(oAnimations, amp_seg8_anims_08004034), + LOAD_ANIMATIONS(oAnimations, dAmpAnimsList), ANIMATE(0), SET_FLOAT(oGraphYOffset, 40), SET_INT(oIntangibleTimer, 0), diff --git a/enhancements/crash.patch b/enhancements/crash.patch index c3c8b537..87c5c8f9 100644 --- a/enhancements/crash.patch +++ b/enhancements/crash.patch @@ -1,13 +1,13 @@ diff --git a/asm/crash.s b/asm/crash.s new file mode 100644 -index 00000000..0b2a5574 +index 00000000..033bf952 --- /dev/null +++ b/asm/crash.s @@ -0,0 +1,153 @@ -+# SM64 Crash Handler -+# See Readme below. ++// SM64 Crash Handler ++// See Readme below. + -+.include "macros.inc" ++#include "macros.inc" + +/* --------------------------------------------------------------- + * IMPORTANT README: @@ -58,7 +58,7 @@ index 00000000..0b2a5574 + sw $a3, %lo(nAssertStopProgram)($at) + beqz $a3, .end_2 + nop -+ syscall # trigger crash screen ++ syscall // trigger crash screen +.end_2: + jr $ra + nop @@ -75,15 +75,15 @@ index 00000000..0b2a5574 + jr $ra + mfc0 $v0, COP0_BADVADDR + -+# If the error code field of cop0's cause register is non-zero, -+# draw crash details to the screen and hang -+# -+# If there wasn't an error, continue to the original handler ++// If the error code field of cop0's cause register is non-zero, ++// draw crash details to the screen and hang ++ ++// If there wasn't an error, continue to the original handler + +glabel __crash_handler_entry + mfc0 $k1, COP0_CAUSE + andi $k1, $k1, (0x1F << 2) -+ beqzl $k1, .end2 # exit if ExCode is 0 ++ beqzl $k1, .end2 // exit if ExCode is 0 + lui $k0, %hi(__osException) + la $k0, exceptionRegContext + sd $zero, 0x018 ($k0) @@ -116,7 +116,7 @@ index 00000000..0b2a5574 + sd $sp, 0x0F0 ($k0) + sd $fp, 0x0F8 ($k0) + sd $ra, 0x100 ($k0) -+ # cop unusable exception fired twice on startup so we'll ignore it for now ++ // cop unusable exception fired twice on startup so we'll ignore it for now + li $t0, (0x0B << 2) + beq $k1, $t0, .end + nop @@ -155,14 +155,14 @@ index 00000000..0b2a5574 + lui $k0, %hi(__osException) + .end2: + addiu $k0, $k0, %lo(__osException) -+ jr $k0 # run the original handler ++ jr $k0 // run the original handler + nop diff --git a/lib/asm/__osExceptionPreamble.s b/lib/asm/__osExceptionPreamble.s -index e14928ce..4d12129e 100644 +index c3b97993..c552a485 100644 --- a/lib/asm/__osExceptionPreamble.s +++ b/lib/asm/__osExceptionPreamble.s -@@ -18,8 +18,8 @@ - .endif +@@ -11,8 +11,8 @@ + #endif glabel __osExceptionPreamble - lui $k0, %hi(__osException) @@ -173,10 +173,10 @@ index e14928ce..4d12129e 100644 nop diff --git a/sm64.ld b/sm64.ld -index f80f5b4d..569344bc 100755 +index 7d9b5b4a..c7bb81b9 100755 --- a/sm64.ld +++ b/sm64.ld -@@ -116,6 +116,7 @@ SECTIONS +@@ -117,6 +117,7 @@ SECTIONS BUILD_DIR/src/game/rendering_graph_node.o(.text); BUILD_DIR/src/game/profiler.o(.text); BUILD_DIR/asm/decompress.o(.text); diff --git a/enhancements/debug_box.patch b/enhancements/debug_box.patch index f51cedfb..12623828 100644 --- a/enhancements/debug_box.patch +++ b/enhancements/debug_box.patch @@ -2,10 +2,10 @@ diff --git a/src/game/area.c b/src/game/area.c index af9d0156..c68a7f6e 100644 --- a/src/game/area.c +++ b/src/game/area.c -@@ -21,6 +21,7 @@ - #include "engine/geo_layout.h" +@@ -22,6 +22,7 @@ #include "save_file.h" #include "level_table.h" + #include "dialog_ids.h" +#include "debug_box.h" struct SpawnInfo gPlayerSpawnInfos[1]; diff --git a/enhancements/fps.patch b/enhancements/fps.patch index ad8bfaa0..e5e1acca 100644 --- a/enhancements/fps.patch +++ b/enhancements/fps.patch @@ -1,10 +1,10 @@ diff --git a/src/game/game_init.c b/src/game/game_init.c -index b6334688..62ed106c 100644 +index b961ca52..531231cf 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c -@@ -59,6 +59,47 @@ struct DemoInput *gCurrDemoInput = NULL; // demo input sequence - u16 gDemoInputListID = 0; - struct DemoInput gRecordedDemoInput = { 0 }; // possibly removed in EU. TODO: Check +@@ -82,6 +82,47 @@ struct DemoInput gRecordedDemoInput = { 0 }; + // Display + // ---------------------------------------------------------------------------------------------------- +// SDK states that 1 cycle takes about 21.33 nanoseconds +#define SECONDS_PER_CYCLE 0.00000002133f @@ -48,9 +48,9 @@ index b6334688..62ed106c 100644 +} + /** - * Initializes the Reality Display Processor (RDP). - * This function initializes settings such as texture filtering mode, -@@ -633,5 +674,7 @@ void thread5_game_loop(UNUSED void *arg) { + * Sets the initial RDP (Reality Display Processor) rendering settings. + */ +@@ -694,5 +735,7 @@ void thread5_game_loop(UNUSED void *arg) { // amount of free space remaining. print_text_fmt_int(180, 20, "BUF %d", gGfxPoolEnd - (u8 *) gDisplayListHead); } diff --git a/enhancements/ique_support.patch b/enhancements/ique_support.patch index ed2a508c..8487c48e 100644 --- a/enhancements/ique_support.patch +++ b/enhancements/ique_support.patch @@ -13,16 +13,16 @@ index 00000000..e60550ab +extern enum ConsoleType get_console_type(void); diff --git a/lib/asm/skGetId.s b/lib/asm/skGetId.s new file mode 100644 -index 00000000..8fb4c449 +index 00000000..58e7d4f9 --- /dev/null +++ b/lib/asm/skGetId.s @@ -0,0 +1,18 @@ -+# Code by stuckpixel ++// Code by stuckpixel + +.set noreorder +.set gp=64 + -+.include "macros.inc" ++#include "macros.inc" + +glabel skGetId + li $v0, 0 @@ -36,10 +36,10 @@ index 00000000..8fb4c449 + nop + nop diff --git a/lib/src/__osViSwapContext.c b/lib/src/__osViSwapContext.c -index b9d364b1..fa149b5d 100644 +index 990cb11f..22756e91 100644 --- a/lib/src/__osViSwapContext.c +++ b/lib/src/__osViSwapContext.c -@@ -52,7 +52,9 @@ void __osViSwapContext() { +@@ -54,7 +54,9 @@ void __osViSwapContext() { HW_REG(VI_INTR_REG, u32) = s0->fldRegs[field].vIntr; HW_REG(VI_X_SCALE_REG, u32) = s1->unk20; HW_REG(VI_Y_SCALE_REG, u32) = s1->unk2c; @@ -269,7 +269,7 @@ index 1a86477b..a94f8721 100644 return sp34; } diff --git a/lib/src/osInitialize.c b/lib/src/osInitialize.c -index ea247636..4adb45cb 100644 +index ba73024b..6deaf407 100644 --- a/lib/src/osInitialize.c +++ b/lib/src/osInitialize.c @@ -1,6 +1,7 @@ @@ -280,7 +280,7 @@ index ea247636..4adb45cb 100644 #define PIF_ADDR_START (void *) 0x1FC007FC -@@ -54,6 +55,7 @@ void osInitialize(void) { +@@ -51,6 +52,7 @@ void osInitialize(void) { UNUSED u32 eu_sp30; #endif UNUSED u32 sp2c; @@ -289,24 +289,24 @@ index ea247636..4adb45cb 100644 __osSetSR(__osGetSR() | 0x20000000); __osSetFpcCsr(0x01000800); diff --git a/sm64.ld b/sm64.ld -index f80f5b4d..e53d4e40 100755 +index 7d9b5b4a..be853a3b 100755 --- a/sm64.ld +++ b/sm64.ld -@@ -300,6 +300,8 @@ SECTIONS - #ifdef VERSION_SH - BUILD_DIR/libultra.a:unk_shindou_file_3.o(.text) +@@ -306,6 +306,8 @@ SECTIONS + #if ENABLE_RUMBLE + BUILD_DIR/libultra.a:unk_shindou_file_3.o(.text); #endif + BUILD_DIR/libultra.a:consoleType.o(.text) + BUILD_DIR/libultra.a:skGetId.o(.text) BUILD_DIR/lib/rsp.o(.text); #else BUILD_DIR/src/game*.o(.text); -@@ -410,6 +412,8 @@ SECTIONS - BUILD_DIR/libultra.a:__osGetCause.o(.text); - BUILD_DIR/libultra.a:__osAtomicDec.o(.text); - BUILD_DIR/libultra.a:guLookAtRef.o(.text); /* Fast3DEX2 only */ -+ BUILD_DIR/libultra.a:consoleType.o(.text); -+ BUILD_DIR/libultra.a:skGetId.o(.text); +@@ -428,6 +430,8 @@ SECTIONS + #if ENABLE_RUMBLE + BUILD_DIR/libultra.a:unk_shindou_file_3.o(.text); + #endif ++ BUILD_DIR/libultra.a:consoleType.o(.text) ++ BUILD_DIR/libultra.a:skGetId.o(.text) BUILD_DIR/lib/rsp.o(.text); #endif diff --git a/enhancements/mem_error_screen.patch b/enhancements/mem_error_screen.patch index b4a82e0b..3941e328 100644 --- a/enhancements/mem_error_screen.patch +++ b/enhancements/mem_error_screen.patch @@ -1,8 +1,8 @@ diff --git a/Makefile b/Makefile -index f81fd27b..318140f2 100644 +index f50b7622..124c7ec6 100644 --- a/Makefile +++ b/Makefile -@@ -419,6 +419,7 @@ $(BUILD_DIR)/include/text_strings.h: $(BUILD_DIR)/include/text_menu_strings.h +@@ -478,6 +478,7 @@ $(BUILD_DIR)/include/text_strings.h: $(BUILD_DIR)/include/text_menu_strings.h $(BUILD_DIR)/src/menu/file_select.o: $(BUILD_DIR)/include/text_strings.h $(BUILD_DIR)/src/menu/star_select.o: $(BUILD_DIR)/include/text_strings.h $(BUILD_DIR)/src/game/ingame_menu.o: $(BUILD_DIR)/include/text_strings.h @@ -11,12 +11,12 @@ index f81fd27b..318140f2 100644 #==============================================================================# diff --git a/include/segments.h b/include/segments.h -index a8c1bf97..84c3d7a4 100644 +index a97d6ee8..186c968e 100644 --- a/include/segments.h +++ b/include/segments.h -@@ -1,6 +1,9 @@ - #ifndef SEGMENTS_H - #define SEGMENTS_H +@@ -3,6 +3,9 @@ + + #include "config.h" +/* Use expansion pack RAM */ +#define USE_EXT_RAM 1 @@ -58,7 +58,7 @@ index 17c773ed..677a5ae9 100644 + JUMP(/*target*/ level_script_entry_error_screen), +}; diff --git a/levels/intro/geo.c b/levels/intro/geo.c -index 7a297fe7..71b16442 100644 +index 30a87806..6bf7b79a 100644 --- a/levels/intro/geo.c +++ b/levels/intro/geo.c @@ -15,6 +15,24 @@ @@ -100,7 +100,7 @@ index 99277e86..04797cd7 100644 + #endif diff --git a/levels/intro/script.c b/levels/intro/script.c -index a130cc04..926c0d09 100644 +index 04b8fc4c..ca9058c4 100644 --- a/levels/intro/script.c +++ b/levels/intro/script.c @@ -18,6 +18,21 @@ @@ -138,7 +138,7 @@ index d41a91c8..7d047236 100644 struct LevelCommand *level_script_execute(struct LevelCommand *cmd); diff --git a/src/game/main.c b/src/game/main.c -index 9615f25a..e2d7b3d4 100644 +index 1a9d9e7e..f4f7a9e5 100644 --- a/src/game/main.c +++ b/src/game/main.c @@ -11,6 +11,7 @@ @@ -149,7 +149,7 @@ index 9615f25a..e2d7b3d4 100644 // Message IDs #define MESG_SP_COMPLETE 100 -@@ -127,6 +128,10 @@ void alloc_pool(void) { +@@ -131,6 +132,10 @@ void alloc_pool(void) { void *start = (void *) SEG_POOL_START; void *end = (void *) SEG_POOL_END; @@ -160,7 +160,7 @@ index 9615f25a..e2d7b3d4 100644 main_pool_init(start, end); gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT); } -@@ -332,7 +337,10 @@ void thread3_main(UNUSED void *arg) { +@@ -336,7 +341,10 @@ void thread3_main(UNUSED void *arg) { create_thread(&gSoundThread, 4, thread4_sound, NULL, gThread4Stack + 0x2000, 20); osStartThread(&gSoundThread); @@ -174,7 +174,7 @@ index 9615f25a..e2d7b3d4 100644 while (TRUE) { diff --git a/src/game/mem_error_screen.c b/src/game/mem_error_screen.c new file mode 100644 -index 00000000..81efaf91 +index 00000000..f432927c --- /dev/null +++ b/src/game/mem_error_screen.c @@ -0,0 +1,104 @@ @@ -274,15 +274,14 @@ index 00000000..81efaf91 + + addr = segmented_to_virtual(level_script_entry_error_screen); + -+ rendering_init(); ++ render_init(); + + while (1) { -+ config_gfx_pool(); ++ select_gfx_pool(); + addr = level_script_execute(addr); + display_and_vsync(); + } +} -\ No newline at end of file diff --git a/src/game/mem_error_screen.h b/src/game/mem_error_screen.h new file mode 100644 index 00000000..9fbff34c diff --git a/enhancements/record_demo.patch b/enhancements/record_demo.patch index 5e90000c..a02b9f17 100644 --- a/enhancements/record_demo.patch +++ b/enhancements/record_demo.patch @@ -1,5 +1,5 @@ diff --git a/src/game/game_init.c b/src/game/game_init.c -index b6334688..9363074b 100644 +index b961ca52..adfde049 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -11,6 +11,7 @@ @@ -10,9 +10,9 @@ index b6334688..9363074b 100644 #include "profiler.h" #include "save_file.h" #include "seq_ids.h" -@@ -335,6 +336,45 @@ void display_and_vsync(void) { - gGlobalTimer++; - } +@@ -386,6 +387,45 @@ void display_and_vsync(void) { + // Controls + // ---------------------------------------------------------------------------------------------------- +/* + * This enhancement allows you to record gameplay demos for the mario head screen. @@ -24,7 +24,7 @@ index b6334688..9363074b 100644 + * +*/ + -+#include "../src/game/mario.h" ++#include "mario.h" + +#define DEMOREC_STATUS_NOT_RECORDING 0 +#define DEMOREC_STATUS_PREPARING 1 @@ -53,15 +53,15 @@ index b6334688..9363074b 100644 +struct DemoInput* gRecordedInputsPtr = (struct DemoInput*)gRecordedInputs; +struct DemoInput gRecordedDemoInputCopy; + - // this function records distinct inputs over a 255-frame interval to RAM locations and was likely - // used to record the demo sequences seen in the final game. This function is unused. - static void record_demo(void) { -@@ -368,6 +408,118 @@ static void record_demo(void) { + /** + * This function records distinct inputs over a 255-frame interval to RAM locations and was likely + * used to record the demo sequences seen in the final game. This function is unused. +@@ -420,6 +460,118 @@ UNUSED static void record_demo(void) { gRecordedDemoInput.timer++; } +void record_new_demo_input(void) { -+ if(gRecordedDemoInput.timer == 1 && gRecordedDemoInputCopy.timer > 0) { ++ if (gRecordedDemoInput.timer == 1 && gRecordedDemoInputCopy.timer > 0) { + gRecordedInputs[gNumOfRecordedInputs].timer = gRecordedDemoInputCopy.timer; + gRecordedInputs[gNumOfRecordedInputs + 1].timer = 0; + gRecordedInputs[gNumOfRecordedInputs].rawStickX = gRecordedDemoInputCopy.rawStickX; @@ -86,13 +86,13 @@ index b6334688..9363074b 100644 +void recording(void) { + + // Force-stop when someone makes too many inputs. -+ if(gNumOfRecordedInputs + 1 > DEMOREC_MAX_INPUTS) { ++ if (gNumOfRecordedInputs + 1 > DEMOREC_MAX_INPUTS) { + gRecordingStatus = DEMOREC_STATUS_STOPPING; + return; + } + + copy_gRecordedDemoInput(); -+ record_demo(); // Defined in game.c ++ record_demo(); + record_new_demo_input(); +} + @@ -112,10 +112,10 @@ index b6334688..9363074b 100644 + case DEMOREC_STATUS_NOT_RECORDING: + break; + case DEMOREC_STATUS_PREPARING: -+ if(gMarioObject != NULL && gCurrLevelNum >= 5) { // If the game is in an active level ++ if (gMarioObject != NULL && gCurrLevelNum != LEVEL_NONE) { // If the game is in an active level + gRecordingStatus = DEMOREC_STATUS_RECORDING; + -+ // A bit of a hack, but it works. ++ // First 4 values in demo inputs are used to define level ID + gNumOfRecordedInputs = 1; + gRecordedInputs[0].timer = gCurrLevelNum; + gRecordedInputs[0].rawStickX = 0; @@ -127,7 +127,7 @@ index b6334688..9363074b 100644 + recording(); + break; + case DEMOREC_STATUS_DONE: -+ if(gDoneDelay > DEMOREC_DONE_DELAY) ++ if (gDoneDelay > DEMOREC_DONE_DELAY) + gRecordingStatus = DEMOREC_STATUS_NOT_RECORDING; + else + gDoneDelay++; @@ -159,8 +159,8 @@ index b6334688..9363074b 100644 + // so the debug level select is used for that. + gDebugLevelSelect = TRUE; + -+ if(gPlayer1Controller->buttonPressed & L_TRIG) { -+ if(gRecordingStatus == DEMOREC_STATUS_NOT_RECORDING) { ++ if (gPlayer1Controller->buttonPressed & L_TRIG) { ++ if (gRecordingStatus == DEMOREC_STATUS_NOT_RECORDING) { + gRecordingStatus = DEMOREC_STATUS_PREPARING; + } else if (gRecordingStatus == DEMOREC_STATUS_RECORDING) { + gRecordingStatus = DEMOREC_STATUS_STOPPING; @@ -172,12 +172,12 @@ index b6334688..9363074b 100644 + print_status(); +} + - // take the updated controller struct and calculate - // the new x, y, and distance floats. - void adjust_analog_stick(struct Controller *controller) { -@@ -623,6 +775,7 @@ void thread5_game_loop(UNUSED void *arg) { + /** + * Take the updated controller struct and calculate the new x, y, and distance floats. + */ +@@ -684,6 +836,7 @@ void thread5_game_loop(UNUSED void *arg) { audio_game_loop_tick(); - config_gfx_pool(); + select_gfx_pool(); read_controller_inputs(); + recordingDemo(); addr = level_script_execute(addr); diff --git a/extract_assets.py b/extract_assets.py index 3b6427e3..bde5ef21 100755 --- a/extract_assets.py +++ b/extract_assets.py @@ -20,6 +20,8 @@ def read_local_asset_list(f): def asset_needs_update(asset, version): + if version <= 6 and asset in ["actors/king_bobomb/king_bob-omb_eyes.rgba16.png", "actors/king_bobomb/king_bob-omb_hand.rgba16.png"]: + return True if version <= 5 and asset == "textures/spooky/bbh_textures.00800.rgba16.png": return True if version <= 4 and asset in ["textures/mountain/ttm_textures.01800.rgba16.png", "textures/mountain/ttm_textures.05800.rgba16.png"]: @@ -59,7 +61,7 @@ def clean_assets(local_asset_file): def main(): # In case we ever need to change formats of generated files, we keep a # revision ID in the local asset file. - new_version = 6 + new_version = 7 try: local_asset_file = open(".assets-local.txt") diff --git a/include/PR/abi.h b/include/PR/abi.h index 2631214f..b73cb726 100644 --- a/include/PR/abi.h +++ b/include/PR/abi.h @@ -56,13 +56,14 @@ #define A_ADDMIXER 4 #define A_RESAMPLE_ZOH 6 -#define A_INTERL 17 +#define A_DMEMMOVE2 16 +#define A_DOWNSAMPLE_HALF 17 #define A_ENVSETUP1 18 #define A_ENVMIXER 19 #define A_LOADBUFF 20 #define A_SAVEBUFF 21 #define A_ENVSETUP2 22 -#define A_UNK_23 23 +#define A_S8DEC 23 #define A_HILOGAIN 24 #define A_UNK_25 25 #define A_DUPLICATE 26 @@ -306,6 +307,8 @@ typedef short ENVMIX_STATE[40]; * address is later used as parameter, the 8 high bits will be an index * to the segment table and the lower 24 bits are added to the base address * stored in the segment table for this entry. The result is the physical address. + * With the newer rsp audio code, this segment table is not used. The address is + * used directly instead. * * Transfers to/from DRAM are executed using DMA and hence follow these restrictions: * All DRAM addresses should be aligned by 8 bytes, or they will be @@ -349,14 +352,6 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = (uintptr_t)(s); \ } -#define aADPCM_23(pkt, f, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_UNK_23, 24, 8) | _SHIFTL(f, 16, 8); \ - _a->words.w1 = (uintptr_t)(s); \ -} - /* * Not used in SM64. */ @@ -570,15 +565,6 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ } -#define aInterl(pkt, f, i, o, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_INTERL, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(i, 0, 16)); \ - _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ -} - /* * Sets internal volume parameters. * See aEnvMixer for more info. @@ -663,12 +649,50 @@ typedef short ENVMIX_STATE[40]; #undef aEnvMixer #undef aInterleave +// New or modified operations in the new audio microcode below + +/** + * Decompresses S8 data. + * Possible flags: A_INIT and A_LOOP. + * + * First set up internal data in DMEM: + * aSetLoop(cmd++, physicalAddressOfLoopState) (if A_LOOP is set) + * + * Then before this command, call: + * aSetBuffer(cmd++, 0, in, out, count) + * + * Note: count will be rounded up to the nearest multiple of 32 bytes. + * + * S8 decompression works by expanding s8 bytes into s16 numbers, + * by performing a left shift of 8 steps. + * + * Before the algorithm starts, the previous 16 samples are loaded according to flag: + * A_INIT: all zeros + * A_LOOP: the address set by aSetLoop + * no flags: the DRAM address in the s parameter + * These 16 samples are immediately copied to the destination address. + * + * The result of "count" bytes will be written after these 16 initial samples. + * The last 16 samples written to the destination will also be written to + * the state address in DRAM. + */ +#define aS8Dec(pkt, f, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_S8DEC, 24, 8) | _SHIFTL(f, 16, 8); \ + _a->words.w1 = (uintptr_t)(s); \ +} + /* * Mix two tracks by simple clamped addition. * * s: DMEM source track 1 * d: DMEM source track 2 and destination - * c: number of bytes to write (rounded down to 16 byte alignment) + * c: number of bytes to write + * + * Note: count is first rounded down to the nearest multiple of 16 bytes + * and then rounded up to the nearest multiple of 64 bytes. */ #define aAddMixer(pkt, s, d, c) \ { \ @@ -726,6 +750,28 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = (_SHIFTL(d, 16, 16) | _SHIFTL(0x80, 0, 16)); \ } +/* + * Copies memory in DMEM, second version. + * + * Copies t * c bytes from address i to address o. + * + * Note: count is first rounded up to the nearest multiple of 32 bytes, + * before the multiplication by t. + * + * Note: This acts as memcpy where 32 bytes are moved at a time, therefore + * if input and output overlap, output address should be less than input address. + * + * Not used in SM64. + */ +#define aDMEMMove2(pkt, t, i, o, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_DMEMMOVE2, 24, 8) | \ + _SHIFTL(t, 16, 8) | _SHIFTL(i, 0, 16); \ + _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ +} + /* * Fast resample. * @@ -734,14 +780,37 @@ typedef short ENVMIX_STATE[40]; * * This works like the other resample command but just takes the "nearest" sample, * instead of a function of the four nearest samples. + * + * Initially the current position is calculated as (in << 16) + startFract. + * For every sample to create, the value is simply taken from the sample + * at address ((position >> 17) << 1). Then the current position is incremented + * by (pitch << 2). + * + * Note: count represents the number of output bytes to create, and is + * rounded up to the nearest multiple of 8 bytes. */ -#define aResampleZoh(pkt, pitch, start_fract) \ +#define aResampleZoh(pkt, pitch, startFract) \ { \ Acmd *_a = (Acmd *)pkt; \ \ _a->words.w0 = (_SHIFTL(A_RESAMPLE_ZOH, 24, 8) | \ _SHIFTL(pitch, 0, 16)); \ - _a->words.w1 = _SHIFTL(start_fract, 0, 16); \ + _a->words.w1 = _SHIFTL(startFract, 0, 16); \ +} + +/* + * Fast downsampling by taking every other sample, discarding others. + * + * Note: nSamples refers to the number of output samples to create, and + * is first rounded up to the nearest multiple of 8. + */ +#define aDownsampleHalf(pkt, nSamples, i, o) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_DOWNSAMPLE_HALF, 24, 8) | \ + _SHIFTL(nSamples, 0, 16)); \ + _a->words.w1 = _SHIFTL(i, 16, 16) | _SHIFTL(o, 0, 16); \ } /* @@ -764,39 +833,87 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = _SHIFTL(i, 16, 16) | _SHIFTL(o, 0, 16); \ } -#define aEnvSetup1(pkt, a, b, c, d) \ +/* + * See aEnvMixer for more info. + */ +#define aEnvSetup1(pkt, initialVolReverb, rampReverb, rampLeft, rampRight) \ { \ Acmd *_a = (Acmd *)pkt; \ \ _a->words.w0 = (_SHIFTL(A_ENVSETUP1, 24, 8) | \ - _SHIFTL(a, 16, 8) | _SHIFTL(b, 0, 16)); \ - _a->words.w1 = _SHIFTL(c, 16, 16) | _SHIFTL(d, 0, 16); \ + _SHIFTL(initialVolReverb, 16, 8) | \ + _SHIFTL(rampReverb, 0, 16)); \ + _a->words.w1 = _SHIFTL(rampLeft, 16, 16) | \ + _SHIFTL(rampRight, 0, 16); \ } -#define aEnvSetup2(pkt, volLeft, volRight) \ +/* + * See aEnvMixer for more info. + */ +#define aEnvSetup2(pkt, initialVolLeft, initialVolRight) \ { \ Acmd *_a = (Acmd *)pkt; \ \ _a->words.w0 = _SHIFTL(A_ENVSETUP2, 24, 8); \ - _a->words.w1 = _SHIFTL(volLeft, 16, 16) | \ - _SHIFTL(volRight, 0, 16); \ + _a->words.w1 = _SHIFTL(initialVolLeft, 16, 16) | \ + _SHIFTL(initialVolRight, 0, 16); \ } -#define aEnvMixer(pkt, inBuf, nSamples, bit1, bit2, bit3, dryLeft, dryRight, wetLeft, wetRight) \ +/* + * Mixes an envelope with mono sound into 4 channels. + * + * To allow for many parameters, a sequence of aEnvSetup1, aEnvSetup2, + * aEnvMixer shall always be called. + * + * The function works in blocks of 8 samples. + * However, nSamples is rounded up to the nearest multiple of 16 samples. + * + * For each sample in a block: + * 1. sampleLeft = in * volLeft * (negLeft ? -1 : 1) + * 2. sampleRight = in * volRight * (negRight ? -1 : 1) + * 3. dryLeft += sampleLeft + * 4. dryRight += sampleRight + * 5. if swapReverb: swap sampleLeft and sampleRight + * 6. wetLeft += sampleLeft * volReverb + * 7. wetRight += sampleRight * volReverb + * + * After each block, all vol variables are added by their corresponding + * ramp value. + * + * Each volume variable is treated as a UQ0.16 number. Make sure + * the ramp additions don't overflow, or wrapping will occur. + * The initialVolReverb parameter is only 8 bits, but will be left + * shifted 8 bits by the rsp. + */ +#define aEnvMixer(pkt, inBuf, nSamples, swapReverb, negLeft, negRight, \ + dryLeft, dryRight, wetLeft, wetRight) \ { \ Acmd *_a = (Acmd *)pkt; \ \ _a->words.w0 = (_SHIFTL(A_ENVMIXER, 24, 8) | \ _SHIFTL((inBuf) >> 4, 16, 8) | \ _SHIFTL(nSamples, 8, 8)) | \ - _SHIFTL(bit1, 2, 1) | _SHIFTL(bit2, 1, 1) | \ - _SHIFTL(bit3, 0, 1); \ + _SHIFTL(swapReverb, 2, 1) | _SHIFTL(negLeft, 1, 1) |\ + _SHIFTL(negRight, 0, 1); \ _a->words.w1 = _SHIFTL((dryLeft) >> 4, 24, 8) | \ _SHIFTL((dryRight) >> 4, 16, 8) | \ _SHIFTL((wetLeft) >> 4, 8, 8) | \ _SHIFTL((wetRight) >> 4, 0, 8); \ } +/* + * Interleaves two mono channels into stereo. + * + * The count refers to the size of each input. Hence 2 * count bytes + * will be written out. + * + * A left sample will be placed before the right sample. + * All addresses (output, left, right) are DMEM addresses. + * + * Note: count will be rounded up to the nearest multiple of 8 bytes. + * The previous version of this function rounded up to the nearest + * multiple of 16 bytes. + */ #define aInterleave(pkt, o, l, r, c) \ { \ Acmd *_a = (Acmd *)pkt; \ @@ -806,7 +923,26 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = _SHIFTL(l, 16, 16) | _SHIFTL(r, 0, 16); \ } -// countOrBuf meaning depends on flag +/* + * Linear filter function. + * + * Calculates out[i] = sum all elements in the vector in[i..i-7] * filter[0..7], + * where "*" represents dot multiplication. The input/output contains s16 + * samples and filter contains Q1.15 signed fixed point numbers. + * Every result sample is rounded and clamped. + * + * First initiate by calling with the flag f set to 2, countOrBuf contains + * the length in bytes that shall be processed in the next call. The addr + * parameter shall contain the DRAM address to the filter table (16 bytes). + * The count will be rounded up to the nearest multiple of 16 bytes. + * + * The aFilter function shall then be called in direct succession, with flag + * set to either 0 or 1. The countOrBuf parameter shall contain the DMEM + * address for the input/output. The addr parameter shall contain the DRAM + * address for the state, containing the last previous 8 input samples. + * The state is always written to upon exit, but is only read at entry if + * the flag is 0 (otherwise all-zero samples are used instead). + */ #define aFilter(pkt, f, countOrBuf, addr) \ { \ Acmd *_a = (Acmd *)pkt; \ @@ -816,22 +952,41 @@ typedef short ENVMIX_STATE[40]; _a->words.w1 = (uintptr_t)(addr); \ } -#define aHilogain(pkt, id, buflen, i) \ +/* + * Modifies the volume of samples using a simple UQ4.4 gain multiplier. + * + * Performs the following: + * + * 1. Count c is rounded up to 32 byte alignment + * 2. g is a u8 that contains a UQ4.4 number + * 3. Modify each sample s, so that s = clamp_s16(s * g >> 4) + */ +#define aHiLoGain(pkt, g, buflen, i) \ { \ Acmd *_a = (Acmd *)pkt; \ \ _a->words.w0 = _SHIFTL(A_HILOGAIN, 24, 8) | \ - _SHIFTL((id), 16, 8) | _SHIFTL((buflen), 0, 16); \ + _SHIFTL((g), 16, 8) | _SHIFTL((buflen), 0, 16); \ _a->words.w1 = _SHIFTL((i), 16, 16); \ } -#define aUnknown25(pkt, f, g, i, o) \ +/* + * Performs the following: + * + * 1. Count c is rounded up to 64 byte alignment + * 2. f is added to i + * 3. i and o are from now treated as s16 pointers + * 4. 32 s16 samples are loaded from i to tbl + * 5. for (u32 idx = 0; idx * sizeof(s16) < c; idx++) + * o[idx] = clamp_s16((s32)o[idx] * (s32)tbl[idx % 32]); + */ +#define aUnknown25(pkt, f, c, o, i) \ { \ Acmd *_a = (Acmd *)pkt; \ \ _a->words.w0 = (_SHIFTL(A_UNK_25, 24, 8) | \ - _SHIFTL((f), 16, 8) | _SHIFTL((g), 0, 16)); \ - _a->words.w1 = _SHIFTL((i), 16, 16) | _SHIFTL((o), 0, 16); \ + _SHIFTL((f), 16, 8) | _SHIFTL((c), 0, 16)); \ + _a->words.w1 = _SHIFTL((o), 16, 16) | _SHIFTL((i), 0, 16); \ } #endif diff --git a/include/PR/libaudio.h b/include/PR/libaudio.h index 3fffe9c0..cb7a5b19 100644 --- a/include/PR/libaudio.h +++ b/include/PR/libaudio.h @@ -8,7 +8,8 @@ typedef struct u8 *offset; s32 len; #ifdef VERSION_SH - s8 magic[2]; // tbl: 0x0204, otherwise: 0x0203 + s8 medium; + s8 magic; // tbl: 0x04, otherwise: 0x03 // for ctl (else zeros): union { @@ -38,7 +39,9 @@ typedef struct #ifdef VERSION_SH s16 unk2; u8 *data; +#if !IS_64_BIT s32 pad[2]; +#endif #endif ALSeqData seqArray[1]; } ALSeqFile; diff --git a/lib/src/os.h b/include/PR/os.h similarity index 100% rename from lib/src/os.h rename to include/PR/os.h diff --git a/include/behavior_data.h b/include/behavior_data.h index 7acb3309..66c410b7 100644 --- a/include/behavior_data.h +++ b/include/behavior_data.h @@ -261,7 +261,7 @@ extern const BehaviorScript bhvBoo[]; extern const BehaviorScript bhvMerryGoRoundBoo[]; extern const BehaviorScript bhvGhostHuntBoo[]; extern const BehaviorScript bhvHiddenStaircaseStep[]; -extern const BehaviorScript bhvBooBossSpawnedBridge[]; +extern const BehaviorScript bhvBooStaircase[]; extern const BehaviorScript bhvBbhTiltingTrapPlatform[]; extern const BehaviorScript bhvHauntedBookshelf[]; extern const BehaviorScript bhvMeshElevator[]; diff --git a/include/config.h b/include/config.h index 211a086a..044b0694 100644 --- a/include/config.h +++ b/include/config.h @@ -8,7 +8,7 @@ */ // Bug Fixes -// --| US Version Nintendo Bug Fixes +// --| Post-JP Version Nintendo Bug Fixes /// Fixes bug where obtaining over 999 coins sets the number of lives to 999 (or -25) #define BUGFIX_MAX_LIVES (0 || VERSION_US || VERSION_EU || VERSION_SH) /// Fixes bug where the Boss music won't fade out after defeating King Bob-omb @@ -22,6 +22,17 @@ #define BUGFIX_PIRANHA_PLANT_SLEEP_DAMAGE (0 || VERSION_US || VERSION_SH) /// Fixes bug where it shows a star when you grab a key in bowser battle stages #define BUGFIX_STAR_BOWSER_KEY (0 || VERSION_US || VERSION_EU || VERSION_SH) +/// Fixes bug that enables Mario in time stop even if is not ready to speak +#define BUGFIX_DIALOG_TIME_STOP (0 || VERSION_US || VERSION_EU || VERSION_SH) +/// Fixes bug that causes Mario to still collide with Bowser in BitS after his defeat +#define BUGFIX_BOWSER_COLLIDE_BITS_DEAD (0 || VERSION_US || VERSION_EU || VERSION_SH) +/// Fixes bug where Bowser wouldn't reset his speed when fallen off (and adds missing checks) +#define BUGFIX_BOWSER_FALLEN_OFF_STAGE (0 || VERSION_US || VERSION_EU || VERSION_SH) +/// Fixes bug where Bowser would look weird while fading out +#define BUGFIX_BOWSER_FADING_OUT (0 || VERSION_US || VERSION_EU || VERSION_SH) + +// Support Rumble Pak +#define ENABLE_RUMBLE (0 || VERSION_SH) // Screen Size Defines #define SCREEN_WIDTH 320 diff --git a/include/course_table.h b/include/course_table.h index ec2d4296..c8963274 100644 --- a/include/course_table.h +++ b/include/course_table.h @@ -12,8 +12,7 @@ #define DEFINE_BONUS_COURSE(courseenum, _1) courseenum, -enum CourseNum -{ +enum CourseNum { #include "levels/course_defines.h" COURSE_END, // To mark end + 1 for marking max and count. // TODO: clean this up. This is still bad. Which @@ -27,6 +26,7 @@ enum CourseNum #undef DEFINE_COURSES_END #undef DEFINE_BONUS_COURSE -#define COURSE_IS_MAIN_COURSE(cmd) (cmd >= COURSE_MIN && cmd <= COURSE_STAGES_MAX) +#define COURSE_IS_MAIN_COURSE(cmd) ((cmd) >= COURSE_MIN && (cmd) <= COURSE_STAGES_MAX) +#define COURSE_NUM_TO_INDEX(cmd) ((cmd) - 1) #endif // COURSE_TABLE_H diff --git a/include/dialog_ids.h b/include/dialog_ids.h index 6feadafb..2d9a2410 100644 --- a/include/dialog_ids.h +++ b/include/dialog_ids.h @@ -2,6 +2,7 @@ #define DIALOG_IDS_H enum DialogId { + DIALOG_NONE = -1, DIALOG_000, DIALOG_001, DIALOG_002, diff --git a/include/level_table.h b/include/level_table.h index e3062c49..b0c2c633 100644 --- a/include/level_table.h +++ b/include/level_table.h @@ -7,8 +7,7 @@ #define STUB_LEVEL(_0, levelenum, _2, _3, _4, _5, _6, _7, _8) levelenum, #define DEFINE_LEVEL(_0, levelenum, _2, _3, _4, _5, _6, _7, _8, _9, _10) levelenum, -enum LevelNum -{ +enum LevelNum { LEVEL_NONE, #include "levels/level_defines.h" LEVEL_COUNT, diff --git a/include/macro_presets.h b/include/macro_presets.h index e96c7b75..38b1eb69 100644 --- a/include/macro_presets.h +++ b/include/macro_presets.h @@ -5,8 +5,7 @@ #include "behavior_data.h" #include "model_ids.h" -struct MacroPreset -{ +struct MacroPreset { /*0x00*/ const BehaviorScript *behavior; /*0x04*/ s16 model; /*0x06*/ s16 param; diff --git a/include/macros.inc b/include/macros.inc index f642978a..3cb002a3 100644 --- a/include/macros.inc +++ b/include/macros.inc @@ -1,4 +1,4 @@ -# Assembly Macros +// Assembly Macros .set K0BASE, 0x80000000 .set K1BASE, 0xA0000000 diff --git a/include/mario_animation_ids.h b/include/mario_animation_ids.h index 1d22d3d1..954ddb04 100644 --- a/include/mario_animation_ids.h +++ b/include/mario_animation_ids.h @@ -3,8 +3,7 @@ /* Mario Animation IDs */ -enum MarioAnimID -{ +enum MarioAnimID { /* 0x00 */ MARIO_ANIM_SLOW_LEDGE_GRAB, /* 0x01 */ MARIO_ANIM_FALL_OVER_BACKWARDS, /* 0x02 */ MARIO_ANIM_BACKWARD_AIR_KB, @@ -196,7 +195,7 @@ enum MarioAnimID /* 0xBC */ MARIO_ANIM_TURNING_PART1, /* 0xBD */ MARIO_ANIM_TURNING_PART2, /* 0xBE */ MARIO_ANIM_SLIDEFLIP_LAND, - /* 0XBF */ MARIO_ANIM_SLIDEFLIP, + /* 0xBF */ MARIO_ANIM_SLIDEFLIP, /* 0xC0 */ MARIO_ANIM_TRIPLE_JUMP_LAND, /* 0xC1 */ MARIO_ANIM_TRIPLE_JUMP, /* 0xC2 */ MARIO_ANIM_FIRST_PERSON, diff --git a/include/mario_geo_switch_case_ids.h b/include/mario_geo_switch_case_ids.h index 007d23b0..d824e83d 100644 --- a/include/mario_geo_switch_case_ids.h +++ b/include/mario_geo_switch_case_ids.h @@ -3,8 +3,7 @@ /* Mario Geo-Switch-Case IDs */ -enum MarioEyesGSCId -{ +enum MarioEyesGSCId { /*0x00*/ MARIO_EYES_BLINK, /*0x01*/ MARIO_EYES_OPEN, /*0x02*/ MARIO_EYES_HALF_CLOSED, @@ -16,8 +15,7 @@ enum MarioEyesGSCId /*0x08*/ MARIO_EYES_DEAD }; -enum MarioHandGSCId -{ +enum MarioHandGSCId { /*0x00*/ MARIO_HAND_FISTS, /*0x01*/ MARIO_HAND_OPEN, /*0x02*/ MARIO_HAND_PEACE_SIGN, @@ -26,16 +24,14 @@ enum MarioHandGSCId /*0x05*/ MARIO_HAND_RIGHT_OPEN }; -enum MarioCapGSCId -{ +enum MarioCapGSCId { /*0x00*/ MARIO_HAS_DEFAULT_CAP_ON, /*0x01*/ MARIO_HAS_DEFAULT_CAP_OFF, /*0x02*/ MARIO_HAS_WING_CAP_ON, /*0x03*/ MARIO_HAS_WING_CAP_OFF // unused }; -enum MarioGrabPosGSCId -{ +enum MarioGrabPosGSCId { /*0x00*/ GRAB_POS_NULL, /*0x01*/ GRAB_POS_LIGHT_OBJ, /*0x02*/ GRAB_POS_HEAVY_OBJ, diff --git a/include/model_ids.h b/include/model_ids.h index 1cd0a253..c51b0b23 100644 --- a/include/model_ids.h +++ b/include/model_ids.h @@ -385,7 +385,7 @@ // group 9 #define MODEL_BOO 0x54 // boo_geo -#define MODEL_BETA_BOO_KEY 0x55 // small_key_geo +#define MODEL_BETA_BOO_KEY 0x55 // small_key_geo #define MODEL_HAUNTED_CHAIR 0x56 // haunted_chair_geo #define MODEL_MAD_PIANO 0x57 // mad_piano_geo #define MODEL_BOOKEND_PART 0x58 // bookend_part_geo @@ -410,12 +410,12 @@ // second set of actor bins, (0x64-0x73) // group 12 -#define MODEL_BOWSER 0x64 // bowser_geo - 2nd geo loaded is bowser_geo_000424, starts with shadow command +#define MODEL_BOWSER 0x64 // bowser_geo #define MODEL_BOWSER_BOMB_CHILD_OBJ 0x65 // bowser_bomb_geo - Spawns as a chill object in bowser's behavior command, causing an explosion if it touches a bomb #define MODEL_BOWSER_SMOKE 0x66 // bowser_impact_smoke_geo #define MODEL_BOWSER_FLAMES 0x67 // bowser_flames_geo #define MODEL_BOWSER_WAVE 0x68 // invisible_bowser_accessory_geo -#define MODEL_BOWSER2 0x69 // bowser2_geo - 2nd geo loaded is bowser_geo_000770, starts with node command, only difference +#define MODEL_BOWSER_NO_SHADOW 0x69 // bowser_geo_no_shadow // group 13 #define MODEL_BUB 0x64 // cheep_cheep_geo @@ -531,7 +531,7 @@ #define MODEL_KOOPA_WITHOUT_SHELL 0xBF // koopa_without_shell_geo #define MODEL_GOOMBA 0xC0 // goomba_geo #define MODEL_SEAWEED 0xC1 // seaweed_geo -#define MODEL_AMP 0xC2 // amp_geo +#define MODEL_AMP 0xC2 // dAmpGeo #define MODEL_BOBOMB_BUDDY 0xC3 // bobomb_buddy_geo // find me // find me @@ -562,7 +562,7 @@ #define MODEL_PEACH 0xDE // peach_geo #define MODEL_CHUCKYA 0xDF // chuckya_geo #define MODEL_WHITE_PUFF 0xE0 // white_puff_geo -#define MODEL_TRAJECTORY_MARKER_BALL 0xE1 // bowling_ball_track_geo - duplicate used in SSL Pyramid small sized and as a track ball +#define MODEL_TRAJECTORY_MARKER_BALL 0xE1 // bowling_ball_track_geo - duplicate used in SSL Pyramid small sized and as a track ball // Menu Models (overwrites Level Geometry IDs) #define MODEL_MAIN_MENU_MARIO_SAVE_BUTTON MODEL_LEVEL_GEOMETRY_03 // main_menu_geo_0001D0 diff --git a/include/object_constants.h b/include/object_constants.h index 95f5ce53..16dfe90c 100644 --- a/include/object_constants.h +++ b/include/object_constants.h @@ -47,29 +47,24 @@ #define OBJ_FLAG_30 (1 << 30) // 0x40000000 /* oHeldState */ -#define HELD_FREE 0 -#define HELD_HELD 1 -#define HELD_THROWN 2 +#define HELD_FREE 0 +#define HELD_HELD 1 +#define HELD_THROWN 2 #define HELD_DROPPED 3 /* oDialogState */ -#define DIALOG_UNK1_ENABLE_TIME_STOP 0 -#define DIALOG_UNK1_INTERRUPT_MARIO_ACTION 1 -#define DIALOG_UNK1_BEGIN_DIALOG 2 -#define DIALOG_UNK1_AWAIT_DIALOG 3 -#define DIALOG_UNK1_DISABLE_TIME_STOP 4 +#define DIALOG_STATUS_ENABLE_TIME_STOP 0 +#define DIALOG_STATUS_INTERRUPT 1 +#define DIALOG_STATUS_START_DIALOG 2 +#define DIALOG_STATUS_STOP_DIALOG 3 +#define DIALOG_STATUS_DISABLE_TIME_STOP 4 -#define DIALOG_UNK1_FLAG_DEFAULT (1 << 1) // 0x02 -#define DIALOG_UNK1_FLAG_RESPONSE (1 << 2) // 0x04 -#define DIALOG_UNK1_FLAG_4 (1 << 4) // 0x10 - -#define DIALOG_UNK2_ENABLE_TIME_STOP 0 -#define DIALOG_UNK2_TURN_AND_INTERRUPT_MARIO_ACTION 1 -#define DIALOG_UNK2_AWAIT_DIALOG 2 -#define DIALOG_UNK2_END_DIALOG 3 - -#define DIALOG_UNK2_FLAG_0 (1 << 0) // 0x01 -#define DIALOG_UNK2_LEAVE_TIME_STOP_ENABLED (1 << 4) // 0x10 +#define DIALOG_FLAG_NONE 0 +#define DIALOG_FLAG_TURN_TO_MARIO (1 << 0) // 0x01 // cutscene only +#define DIALOG_FLAG_TEXT_DEFAULT (1 << 1) // 0x02 +#define DIALOG_FLAG_TEXT_RESPONSE (1 << 2) // 0x04 // non-cutscene only +#define DIALOG_FLAG_UNK_CAPSWITCH (1 << 3) // 0x08 // not defined +#define DIALOG_FLAG_TIME_STOP_ENABLED (1 << 4) // 0x10 /* oMoveFlags */ #define OBJ_MOVE_LANDED (1 << 0) // 0x0001 @@ -120,12 +115,12 @@ #define ACTIVE_PARTICLE_TRIANGLE (1 << 19) // 0x00080000 /* oAction */ -#define OBJ_ACT_LAVA_DEATH 100 +#define OBJ_ACT_LAVA_DEATH 100 #define OBJ_ACT_DEATH_PLANE_DEATH 101 #define OBJ_ACT_HORIZONTAL_KNOCKBACK 100 -#define OBJ_ACT_VERTICAL_KNOCKBACK 101 -#define OBJ_ACT_SQUISHED 102 +#define OBJ_ACT_VERTICAL_KNOCKBACK 101 +#define OBJ_ACT_SQUISHED 102 /* gTTCSpeedSetting */ #define TTC_SPEED_SLOW 0 @@ -135,67 +130,186 @@ /* Bob-omb */ /* oBehParams2ndByte */ - #define BOBOMB_BP_STYPE_GENERIC 0 + #define BOBOMB_BP_STYPE_GENERIC 0 #define BOBOMB_BP_STYPE_STATIONARY 1 + /* oAction */ - #define BOBOMB_ACT_PATROL 0 - #define BOBOMB_ACT_LAUNCHED 1 - #define BOBOMB_ACT_CHASE_MARIO 2 - #define BOBOMB_ACT_EXPLODE 3 - #define BOBOMB_ACT_LAVA_DEATH 100 + #define BOBOMB_ACT_PATROL 0 + #define BOBOMB_ACT_LAUNCHED 1 + #define BOBOMB_ACT_CHASE_MARIO 2 + #define BOBOMB_ACT_EXPLODE 3 + #define BOBOMB_ACT_LAVA_DEATH 100 #define BOBOMB_ACT_DEATH_PLANE_DEATH 101 /* Hidden Blue Coin */ /* oAction */ #define HIDDEN_BLUE_COIN_ACT_INACTIVE 0 - #define HIDDEN_BLUE_COIN_ACT_WAITING 1 - #define HIDDEN_BLUE_COIN_ACT_ACTIVE 2 + #define HIDDEN_BLUE_COIN_ACT_WAITING 1 + #define HIDDEN_BLUE_COIN_ACT_ACTIVE 2 /* Blue Coin Switch */ /* oAction */ - #define BLUE_COIN_SWITCH_ACT_IDLE 0 + #define BLUE_COIN_SWITCH_ACT_IDLE 0 #define BLUE_COIN_SWITCH_ACT_RECEDING 1 - #define BLUE_COIN_SWITCH_ACT_TICKING 2 + #define BLUE_COIN_SWITCH_ACT_TICKING 2 /* Moving Blue Coin */ /* oAction */ - #define MOV_BCOIN_ACT_STILL 0 + #define MOV_BCOIN_ACT_STILL 0 #define MOV_BCOIN_ACT_MOVING 1 /* Moving Yellow Coin */ /* oAction */ - #define MOV_YCOIN_ACT_IDLE 0 - #define MOV_YCOIN_ACT_BLINKING 1 - #define MOV_YCOIN_ACT_LAVA_DEATH 100 + #define MOV_YCOIN_ACT_IDLE 0 + #define MOV_YCOIN_ACT_BLINKING 1 + #define MOV_YCOIN_ACT_LAVA_DEATH 100 #define MOV_YCOIN_ACT_DEATH_PLANE_DEATH 101 /* Bob-omb Buddy */ /* oBehParams2ndByte */ - #define BOBOMB_BUDDY_BP_STYPE_GENERIC 0 - #define BOBOMB_BUDDY_BP_STYPE_BOB_GRASS_KBB 1 + #define BOBOMB_BUDDY_BP_STYPE_GENERIC 0 + #define BOBOMB_BUDDY_BP_STYPE_BOB_GRASS_KBB 1 #define BOBOMB_BUDDY_BP_STYPE_BOB_CANNON_KBB 2 - #define BOBOMB_BUDDY_BP_STYPE_BOB_GRASS 3 + #define BOBOMB_BUDDY_BP_STYPE_BOB_GRASS 3 + /* oAction */ - #define BOBOMB_BUDDY_ACT_IDLE 0 + #define BOBOMB_BUDDY_ACT_IDLE 0 #define BOBOMB_BUDDY_ACT_TURN_TO_TALK 2 - #define BOBOMB_BUDDY_ACT_TALK 3 + #define BOBOMB_BUDDY_ACT_TALK 3 + /* oBobombBuddyRole */ #define BOBOMB_BUDDY_ROLE_ADVICE 0 #define BOBOMB_BUDDY_ROLE_CANNON 1 + /* oBobombBuddyCannonStatus */ - #define BOBOMB_BUDDY_CANNON_UNOPENED 0 - #define BOBOMB_BUDDY_CANNON_OPENING 1 - #define BOBOMB_BUDDY_CANNON_OPENED 2 + #define BOBOMB_BUDDY_CANNON_UNOPENED 0 + #define BOBOMB_BUDDY_CANNON_OPENING 1 + #define BOBOMB_BUDDY_CANNON_OPENED 2 #define BOBOMB_BUDDY_CANNON_STOP_TALKING 3 + /* oBobombBuddyHasTalkedToMario */ #define BOBOMB_BUDDY_HAS_NOT_TALKED 0 - #define BOBOMB_BUDDY_HAS_TALKED 2 + #define BOBOMB_BUDDY_HAS_TALKED 2 + +/* Bowser */ + /* Tail oAction */ + #define BOWSER_ACT_TAIL_DEFAULT 0 + #define BOWSER_ACT_TAIL_THROWN 1 + #define BOWSER_ACT_TAIL_TOUCHED_MARIO 2 + + /* oAction */ + #define BOWSER_ACT_DEFAULT 0 + #define BOWSER_ACT_THROWN 1 + #define BOWSER_ACT_JUMP_ONTO_STAGE 2 + #define BOWSER_ACT_DANCE 3 + #define BOWSER_ACT_DEAD 4 + #define BOWSER_ACT_WAIT 5 + #define BOWSER_ACT_INTRO_WALK 6 + #define BOWSER_ACT_CHARGE_MARIO 7 + #define BOWSER_ACT_SPIT_FIRE_INTO_SKY 8 + #define BOWSER_ACT_SPIT_FIRE_ONTO_FLOOR 9 + #define BOWSER_ACT_HIT_EDGE 10 + #define BOWSER_ACT_TURN_FROM_EDGE 11 + #define BOWSER_ACT_HIT_MINE 12 + #define BOWSER_ACT_BIG_JUMP 13 + #define BOWSER_ACT_WALK_TO_MARIO 14 + #define BOWSER_ACT_BREATH_FIRE 15 + #define BOWSER_ACT_TELEPORT 16 + #define BOWSER_ACT_QUICK_JUMP 17 + #define BOWSER_ACT_UNUSED_SLOW_WALK 18 + #define BOWSER_ACT_TILT_LAVA_PLATFORM 19 + + /* Animations */ + #define BOWSER_ANIM_STAND_UP 0 + #define BOWSER_ANIM_STAND_UP_UNUSED 1 // slightly different + #define BOWSER_ANIM_SHAKING 2 + #define BOWSER_ANIM_GRABBED 3 + #define BOWSER_ANIM_BROKEN 4 // broken animation + #define BOWSER_ANIM_FALL_DOWN 5 // unused + #define BOWSER_ANIM_BREATH 6 + #define BOWSER_ANIM_JUMP 7 // unused, short jump, replaced by start/stop + #define BOWSER_ANIM_JUMP_STOP 8 + #define BOWSER_ANIM_JUMP_START 9 + #define BOWSER_ANIM_DANCE 10 + #define BOWSER_ANIM_BREATH_UP 11 + #define BOWSER_ANIM_IDLE 12 + #define BOWSER_ANIM_SLOW_GAIT 13 + #define BOWSER_ANIM_LOOK_DOWN_STOP_WALK 14 + #define BOWSER_ANIM_LOOK_UP_START_WALK 15 + #define BOWSER_ANIM_FLIP_DOWN 16 + #define BOWSER_ANIM_LAY_DOWN 17 + #define BOWSER_ANIM_RUN_START 18 + #define BOWSER_ANIM_RUN 19 + #define BOWSER_ANIM_RUN_STOP 20 + #define BOWSER_ANIM_RUN_SLIP 21 + #define BOWSER_ANIM_BREATH_QUICK 22 + #define BOWSER_ANIM_EDGE_MOVE 23 + #define BOWSER_ANIM_EDGE_STOP 24 + #define BOWSER_ANIM_FLIP 25 + #define BOWSER_ANIM_STAND_UP_FROM_FLIP 26 + + /* oBehParams2ndByte */ + #define BOWSER_BP_BITDW 0 + #define BOWSER_BP_BITFS 1 + #define BOWSER_BP_BITS 2 + + /* oBowserCamAct */ + #define BOWSER_CAM_ACT_IDLE 0 + #define BOWSER_CAM_ACT_WALK 1 + #define BOWSER_CAM_ACT_END 2 + + /* oBowserStatus */ + #define BOWSER_STATUS_ANGLE_MARIO (1 << 1) // 0x00000002 + #define BOWSER_STATUS_ANGLE_CENTER (1 << 2) // 0x00000004 + #define BOWSER_STATUS_DIST_MARIO (1 << 3) // 0x00000008 + #define BOWSER_STATUS_DIST_CENTER (1 << 4) // 0x00000010 + #define BOWSER_STATUS_BIG_JUMP (1 << 16) // 0x00010000 + #define BOWSER_STATUS_FIRE_SKY (1 << 17) // 0x00020000 + + /* oBowserGrabbedStatus */ + #define BOWSER_GRAB_STATUS_NONE 0 + #define BOWSER_GRAB_STATUS_GRABBED 1 + #define BOWSER_GRAB_STATUS_HOLDING 2 + + /* oSubAction */ + #define BOWSER_SUB_ACT_DEAD_FLY_BACK 0 + #define BOWSER_SUB_ACT_DEAD_BOUNCE 1 + #define BOWSER_SUB_ACT_DEAD_WAIT 2 + #define BOWSER_SUB_ACT_DEAD_DEFAULT_END 3 + #define BOWSER_SUB_ACT_DEAD_DEFAULT_END_OVER 4 + #define BOWSER_SUB_ACT_DEAD_FINAL_END 10 + #define BOWSER_SUB_ACT_DEAD_FINAL_END_OVER 11 + + #define BOWSER_SUB_ACT_CHARGE_START 0 + #define BOWSER_SUB_ACT_CHARGE_RUN 1 + #define BOWSER_SUB_ACT_CHARGE_END 2 + #define BOWSER_SUB_ACT_CHARGE_SLIP 3 + + #define BOWSER_SUB_ACT_TELEPORT_START 0 + #define BOWSER_SUB_ACT_TELEPORT_MOVE 1 + #define BOWSER_SUB_ACT_TELEPORT_STOP 2 + + #define BOWSER_SUB_ACT_HIT_MINE_START 0 + #define BOWSER_SUB_ACT_HIT_MINE_FALL 1 + #define BOWSER_SUB_ACT_HIT_MINE_STOP 2 + + #define BOWSER_SUB_ACT_JUMP_ON_STAGE_IDLE 0 + #define BOWSER_SUB_ACT_JUMP_ON_STAGE_START 1 + #define BOWSER_SUB_ACT_JUMP_ON_STAGE_LAND 2 + #define BOWSER_SUB_ACT_JUMP_ON_STAGE_STOP 3 + +/* Bowser Bits Platform*/ + /* oAction */ + #define BOWSER_BITS_PLAT_ACT_START 0 + #define BOWSER_BITS_PLAT_ACT_CHECK 1 + #define BOWSER_BITS_PLAT_ACT_FALL 2 /* Fish Spawer */ /* oAction */ #define FISH_SPAWNER_ACT_SPAWN 0 #define FISH_SPAWNER_ACT_IDLE 1 #define FISH_SPAWNER_ACT_RESPAWN 2 + /* oBehParams2ndByte */ #define FISH_SPAWNER_BP_MANY_BLUE 0 #define FISH_SPAWNER_BP_FEW_BLUE 1 @@ -210,29 +324,29 @@ /* Blue_Fish */ /* oAction */ - #define BLUE_FISH_ACT_DIVE 0 - #define BLUE_FISH_ACT_TURN 1 - #define BLUE_FISH_ACT_ASCEND 2 + #define BLUE_FISH_ACT_DIVE 0 + #define BLUE_FISH_ACT_TURN 1 + #define BLUE_FISH_ACT_ASCEND 2 #define BLUE_FISH_ACT_TURN_BACK 3 /* oAction: bhv_blue_fish_spawn_loop */ - #define BLUE_FISH_ACT_SPAWN 0 - #define BLUE_FISH_ACT_ROOM 1 + #define BLUE_FISH_ACT_SPAWN 0 + #define BLUE_FISH_ACT_ROOM 1 #define BLUE_FISH_ACT_DUPLICATE 2 /* Cannon Trap Door */ /* oAction */ - #define CANNON_TRAP_DOOR_ACT_CLOSED 0 + #define CANNON_TRAP_DOOR_ACT_CLOSED 0 #define CANNON_TRAP_DOOR_ACT_CAM_ZOOM 1 - #define CANNON_TRAP_DOOR_ACT_OPENING 2 - #define CANNON_TRAP_DOOR_ACT_OPEN 3 + #define CANNON_TRAP_DOOR_ACT_OPENING 2 + #define CANNON_TRAP_DOOR_ACT_OPEN 3 /* Homing Amp */ /* oAction */ - #define HOMING_AMP_ACT_INACTIVE 0 - #define HOMING_AMP_ACT_APPEAR 1 - #define HOMING_AMP_ACT_CHASE 2 - #define HOMING_AMP_ACT_GIVE_UP 3 + #define HOMING_AMP_ACT_INACTIVE 0 + #define HOMING_AMP_ACT_APPEAR 1 + #define HOMING_AMP_ACT_CHASE 2 + #define HOMING_AMP_ACT_GIVE_UP 3 #define HOMING_AMP_ACT_ATTACK_COOLDOWN 4 /* Amp */ @@ -243,57 +357,60 @@ #define AMP_BP_ROT_RADIUS_0 3 /* oAction */ - #define AMP_ACT_IDLE 2 + #define AMP_ACT_IDLE 2 #define AMP_ACT_ATTACK_COOLDOWN 4 /* Butterfly */ /* oAction */ - #define BUTTERFLY_ACT_RESTING 0 + #define BUTTERFLY_ACT_RESTING 0 #define BUTTERFLY_ACT_FOLLOW_MARIO 1 - #define BUTTERFLY_ACT_RETURN_HOME 2 + #define BUTTERFLY_ACT_RETURN_HOME 2 /* Hoot */ /* oHootAvailability */ #define HOOT_AVAIL_ASLEEP_IN_TREE 0 - #define HOOT_AVAIL_WANTS_TO_TALK 1 - #define HOOT_AVAIL_READY_TO_FLY 2 + #define HOOT_AVAIL_WANTS_TO_TALK 1 + #define HOOT_AVAIL_READY_TO_FLY 2 + /* oAction */ #define HOOT_ACT_ASCENT 0 - #define HOOT_ACT_CARRY 1 - #define HOOT_ACT_TIRED 2 + #define HOOT_ACT_CARRY 1 + #define HOOT_ACT_TIRED 2 /* Bully (all variants) */ /* oBehParams2ndByte */ #define BULLY_BP_SIZE_SMALL 0 - #define BULLY_BP_SIZE_BIG 1 + #define BULLY_BP_SIZE_BIG 1 + /* oAction */ - #define BULLY_ACT_PATROL 0 - #define BULLY_ACT_CHASE_MARIO 1 - #define BULLY_ACT_KNOCKBACK 2 - #define BULLY_ACT_BACK_UP 3 - #define BULLY_ACT_INACTIVE 4 - #define BULLY_ACT_ACTIVATE_AND_FALL 5 - #define BULLY_ACT_LAVA_DEATH 100 + #define BULLY_ACT_PATROL 0 + #define BULLY_ACT_CHASE_MARIO 1 + #define BULLY_ACT_KNOCKBACK 2 + #define BULLY_ACT_BACK_UP 3 + #define BULLY_ACT_INACTIVE 4 + #define BULLY_ACT_ACTIVATE_AND_FALL 5 + #define BULLY_ACT_LAVA_DEATH 100 #define BULLY_ACT_DEATH_PLANE_DEATH 101 + /* oBullySubtype */ - #define BULLY_STYPE_GENERIC 0 - #define BULLY_STYPE_MINION 1 - #define BULLY_STYPE_CHILL 16 + #define BULLY_STYPE_GENERIC 0 + #define BULLY_STYPE_MINION 1 + #define BULLY_STYPE_CHILL 16 /* Water Ring (all variants) */ /* oAction */ #define WATER_RING_ACT_NOT_COLLECTED 0 - #define WATER_RING_ACT_COLLECTED 1 + #define WATER_RING_ACT_COLLECTED 1 /* Jet Stream Water Ring Spawner */ /* oAction */ - #define JS_RING_SPAWNER_ACT_ACTIVE 0 + #define JS_RING_SPAWNER_ACT_ACTIVE 0 #define JS_RING_SPAWNER_ACT_INACTIVE 1 /* Celebration Star */ /* oAction */ #define CELEB_STAR_ACT_SPIN_AROUND_MARIO 0 - #define CELEB_STAR_ACT_FACE_CAMERA 1 + #define CELEB_STAR_ACT_FACE_CAMERA 1 /* LLL Drawbridge */ /* oAction */ @@ -302,108 +419,110 @@ /* Bomp (both variants) */ /* oAction */ - #define BOMP_ACT_WAIT 0 + #define BOMP_ACT_WAIT 0 #define BOMP_ACT_POKE_OUT 1 - #define BOMP_ACT_EXTEND 2 - #define BOMP_ACT_RETRACT 3 + #define BOMP_ACT_EXTEND 2 + #define BOMP_ACT_RETRACT 3 /* WF Sliding Brick Platform */ /* oBehParams2ndByte */ #define WF_SLID_BRICK_PTFM_BP_MOV_VEL_10 1 #define WF_SLID_BRICK_PTFM_BP_MOV_VEL_15 2 #define WF_SLID_BRICK_PTFM_BP_MOV_VEL_20 3 + /* oAction */ - #define WF_SLID_BRICK_PTFM_ACT_WAIT 0 - #define WF_SLID_BRICK_PTFM_ACT_EXTEND 1 + #define WF_SLID_BRICK_PTFM_ACT_WAIT 0 + #define WF_SLID_BRICK_PTFM_ACT_EXTEND 1 #define WF_SLID_BRICK_PTFM_ACT_RETRACT 2 /* Fake Moneybag Coin */ /* oAction */ - #define FAKE_MONEYBAG_COIN_ACT_IDLE 0 + #define FAKE_MONEYBAG_COIN_ACT_IDLE 0 #define FAKE_MONEYBAG_COIN_ACT_TRANSFORM 1 /* Moneybag */ /* oAction */ - #define MONEYBAG_ACT_APPEAR 0 + #define MONEYBAG_ACT_APPEAR 0 #define MONEYBAG_ACT_UNUSED_APPEAR 1 - #define MONEYBAG_ACT_MOVE_AROUND 2 - #define MONEYBAG_ACT_RETURN_HOME 3 - #define MONEYBAG_ACT_DISAPPEAR 4 - #define MONEYBAG_ACT_DEATH 5 + #define MONEYBAG_ACT_MOVE_AROUND 2 + #define MONEYBAG_ACT_RETURN_HOME 3 + #define MONEYBAG_ACT_DISAPPEAR 4 + #define MONEYBAG_ACT_DEATH 5 + /* oMoneybagJumpState */ - #define MONEYBAG_JUMP_LANDING 0 - #define MONEYBAG_JUMP_PREPARE 1 - #define MONEYBAG_JUMP_JUMP 2 + #define MONEYBAG_JUMP_LANDING 0 + #define MONEYBAG_JUMP_PREPARE 1 + #define MONEYBAG_JUMP_JUMP 2 #define MONEYBAG_JUMP_JUMP_AND_BOUNCE 3 - #define MONEYBAG_JUMP_WALK_AROUND 4 - #define MONEYBAG_JUMP_WALK_HOME 5 + #define MONEYBAG_JUMP_WALK_AROUND 4 + #define MONEYBAG_JUMP_WALK_HOME 5 /* Bowling Ball */ /* oAction */ #define BBALL_ACT_INITIALIZE 0 - #define BBALL_ACT_ROLL 1 + #define BBALL_ACT_ROLL 1 /* Bowling Ball + Bowling Ball Spawner (all variants) */ /* oBehParams2ndByte */ #define BBALL_BP_STYPE_BOB_UPPER 0 - #define BBALL_BP_STYPE_TTM 1 + #define BBALL_BP_STYPE_TTM 1 #define BBALL_BP_STYPE_BOB_LOWER 2 #define BBALL_BP_STYPE_THI_LARGE 3 #define BBALL_BP_STYPE_THI_SMALL 4 /* Bowling Ball (Free) */ /* oAction */ - #define FREE_BBALL_ACT_IDLE 0 - #define FREE_BBALL_ACT_ROLL 1 + #define FREE_BBALL_ACT_IDLE 0 + #define FREE_BBALL_ACT_ROLL 1 #define FREE_BBALL_ACT_RESET 2 /* Beta Chest Lid */ /* oAction */ #define BETA_CHEST_ACT_IDLE_CLOSED 0 - #define BETA_CHEST_ACT_OPENING 1 - #define BETA_CHEST_ACT_IDLE_OPEN 2 + #define BETA_CHEST_ACT_OPENING 1 + #define BETA_CHEST_ACT_IDLE_OPEN 2 /* BBH Tilting Trap Platform */ /* oAction */ // Unused in original Japanese version - #define BBH_TILTING_TRAP_PLATFORM_ACT_MARIO_ON 0 + #define BBH_TILTING_TRAP_PLATFORM_ACT_MARIO_ON 0 #define BBH_TILTING_TRAP_PLATFORM_ACT_MARIO_OFF 1 /* Boo */ /* oBooDeathStatus */ #define BOO_DEATH_STATUS_ALIVE 0 #define BOO_DEATH_STATUS_DYING 1 - #define BOO_DEATH_STATUS_DEAD 2 + #define BOO_DEATH_STATUS_DEAD 2 /* attackStatus */ - #define BOO_NOT_ATTACKED 0 - #define BOO_ATTACKED 1 - #define BOO_BOUNCED_ON -1 + #define BOO_NOT_ATTACKED 0 + #define BOO_ATTACKED 1 + #define BOO_BOUNCED_ON -1 /* Beta Boo Key */ /* oAction */ - #define BETA_BOO_KEY_ACT_IN_BOO 0 + #define BETA_BOO_KEY_ACT_IN_BOO 0 #define BETA_BOO_KEY_ACT_DROPPING 1 - #define BETA_BOO_KEY_ACT_DROPPED 2 + #define BETA_BOO_KEY_ACT_DROPPED 2 /* Boo Cage */ /* oAction */ - #define BOO_CAGE_ACT_IN_BOO 0 - #define BOO_CAGE_ACT_FALLING 1 - #define BOO_CAGE_ACT_ON_GROUND 2 + #define BOO_CAGE_ACT_IN_BOO 0 + #define BOO_CAGE_ACT_FALLING 1 + #define BOO_CAGE_ACT_ON_GROUND 2 #define BOO_CAGE_ACT_MARIO_JUMPING_IN 3 - #define BOO_CAGE_ACT_USELESS 4 + #define BOO_CAGE_ACT_USELESS 4 /* BBH Haunted Bookshelf */ /* oAction */ - #define HAUNTED_BOOKSHELF_ACT_IDLE 0 + #define HAUNTED_BOOKSHELF_ACT_IDLE 0 #define HAUNTED_BOOKSHELF_ACT_RECEDE 1 /* BBH Merry-Go-Round */ /* gMarioCurrentRoom */ #define BBH_NEAR_MERRY_GO_ROUND_ROOM 10 - #define BBH_DYNAMIC_SURFACE_ROOM 0 - #define BBH_OUTSIDE_ROOM 13 + #define BBH_DYNAMIC_SURFACE_ROOM 0 + #define BBH_OUTSIDE_ROOM 13 /* Coffin Spawner */ /* oAction */ @@ -419,71 +538,71 @@ /* WDW Arrow Lift */ /* oAction */ - #define ARROW_LIFT_ACT_IDLE 0 + #define ARROW_LIFT_ACT_IDLE 0 #define ARROW_LIFT_ACT_MOVING_AWAY 1 #define ARROW_LIFT_ACT_MOVING_BACK 2 /* status */ #define ARROW_LIFT_NOT_DONE_MOVING 0 - #define ARROW_LIFT_DONE_MOVING 1 + #define ARROW_LIFT_DONE_MOVING 1 /* Yoshi */ /* oAction */ - #define YOSHI_ACT_IDLE 0 - #define YOSHI_ACT_WALK 1 - #define YOSHI_ACT_TALK 2 - #define YOSHI_ACT_WALK_JUMP_OFF_ROOF 3 - #define YOSHI_ACT_FINISH_JUMPING_AND_DESPAWN 4 - #define YOSHI_ACT_GIVE_PRESENT 5 - #define YOSHI_ACT_CREDITS 10 + #define YOSHI_ACT_IDLE 0 + #define YOSHI_ACT_WALK 1 + #define YOSHI_ACT_TALK 2 + #define YOSHI_ACT_WALK_JUMP_OFF_ROOF 3 + #define YOSHI_ACT_FINISH_JUMPING_AND_DESPAWN 4 + #define YOSHI_ACT_GIVE_PRESENT 5 + #define YOSHI_ACT_CREDITS 10 /* Koopa */ /* oAction */ - #define KOOPA_UNSHELLED_ACT_RUN 0 - #define KOOPA_UNSHELLED_ACT_DIVE 1 - #define KOOPA_UNSHELLED_ACT_LYING 2 + #define KOOPA_UNSHELLED_ACT_RUN 0 + #define KOOPA_UNSHELLED_ACT_DIVE 1 + #define KOOPA_UNSHELLED_ACT_LYING 2 #define KOOPA_UNSHELLED_ACT_UNUSED3 3 - #define KOOPA_SHELLED_ACT_STOPPED 0 - #define KOOPA_SHELLED_ACT_WALK 1 + #define KOOPA_SHELLED_ACT_STOPPED 0 + #define KOOPA_SHELLED_ACT_WALK 1 #define KOOPA_SHELLED_ACT_RUN_FROM_MARIO 2 - #define KOOPA_SHELLED_ACT_LYING 3 - #define KOOPA_SHELLED_ACT_DIE 4 + #define KOOPA_SHELLED_ACT_LYING 3 + #define KOOPA_SHELLED_ACT_DIE 4 #define KOOPA_THE_QUICK_ACT_WAIT_BEFORE_RACE 0 - #define KOOPA_THE_QUICK_ACT_UNUSED1 1 - #define KOOPA_THE_QUICK_ACT_SHOW_INIT_TEXT 2 - #define KOOPA_THE_QUICK_ACT_RACE 3 - #define KOOPA_THE_QUICK_ACT_DECELERATE 4 - #define KOOPA_THE_QUICK_ACT_STOP 5 - #define KOOPA_THE_QUICK_ACT_AFTER_RACE 6 + #define KOOPA_THE_QUICK_ACT_UNUSED1 1 + #define KOOPA_THE_QUICK_ACT_SHOW_INIT_TEXT 2 + #define KOOPA_THE_QUICK_ACT_RACE 3 + #define KOOPA_THE_QUICK_ACT_DECELERATE 4 + #define KOOPA_THE_QUICK_ACT_STOP 5 + #define KOOPA_THE_QUICK_ACT_AFTER_RACE 6 /* oSubAction */ #define KOOPA_SHELLED_SUB_ACT_START_WALK 0 - #define KOOPA_SHELLED_SUB_ACT_WALK 1 - #define KOOPA_SHELLED_SUB_ACT_STOP_WALK 2 + #define KOOPA_SHELLED_SUB_ACT_WALK 1 + #define KOOPA_SHELLED_SUB_ACT_STOP_WALK 2 #define KOOPA_THE_QUICK_SUB_ACT_START_RUN 0 - #define KOOPA_THE_QUICK_SUB_ACT_RUN 1 - #define KOOPA_THE_QUICK_SUB_ACT_JUMP 2 + #define KOOPA_THE_QUICK_SUB_ACT_RUN 1 + #define KOOPA_THE_QUICK_SUB_ACT_JUMP 2 /* oKoopaTheQuickRaceIndex */ #define KOOPA_THE_QUICK_BOB_INDEX 0 #define KOOPA_THE_QUICK_THI_INDEX 1 /* oBehParams2ndByte */ - #define KOOPA_BP_UNSHELLED 0 - #define KOOPA_BP_NORMAL 1 + #define KOOPA_BP_UNSHELLED 0 + #define KOOPA_BP_NORMAL 1 #define KOOPA_BP_KOOPA_THE_QUICK_BASE 2 - #define KOOPA_BP_KOOPA_THE_QUICK_BOB (KOOPA_BP_KOOPA_THE_QUICK_BASE + KOOPA_THE_QUICK_BOB_INDEX) - #define KOOPA_BP_KOOPA_THE_QUICK_THI (KOOPA_BP_KOOPA_THE_QUICK_BASE + KOOPA_THE_QUICK_THI_INDEX) - #define KOOPA_BP_TINY 4 + #define KOOPA_BP_KOOPA_THE_QUICK_BOB (KOOPA_BP_KOOPA_THE_QUICK_BASE + KOOPA_THE_QUICK_BOB_INDEX) + #define KOOPA_BP_KOOPA_THE_QUICK_THI (KOOPA_BP_KOOPA_THE_QUICK_BASE + KOOPA_THE_QUICK_THI_INDEX) + #define KOOPA_BP_TINY 4 /* Pokey */ /* oAction */ #define POKEY_ACT_UNINITIALIZED 0 - #define POKEY_ACT_WANDER 1 - #define POKEY_ACT_UNLOAD_PARTS 2 + #define POKEY_ACT_WANDER 1 + #define POKEY_ACT_UNLOAD_PARTS 2 /* Swoop */ /* oAction */ @@ -492,48 +611,49 @@ /* Fly guy */ /* oAction */ - #define FLY_GUY_ACT_IDLE 0 + #define FLY_GUY_ACT_IDLE 0 #define FLY_GUY_ACT_APPROACH_MARIO 1 - #define FLY_GUY_ACT_LUNGE 2 - #define FLY_GUY_ACT_SHOOT_FIRE 3 + #define FLY_GUY_ACT_LUNGE 2 + #define FLY_GUY_ACT_SHOOT_FIRE 3 /* Goomba triplet spawner */ /* oBehParams2ndByte */ - #define GOOMBA_TRIPLET_SPAWNER_BP_SIZE_MASK 0x00000003 + #define GOOMBA_TRIPLET_SPAWNER_BP_SIZE_MASK 0x00000003 #define GOOMBA_TRIPLET_SPAWNER_BP_EXTRA_GOOMBAS_MASK 0x000000FC + /* oAction */ #define GOOMBA_TRIPLET_SPAWNER_ACT_UNLOADED 0 - #define GOOMBA_TRIPLET_SPAWNER_ACT_LOADED 1 + #define GOOMBA_TRIPLET_SPAWNER_ACT_LOADED 1 /* Goomba */ /* oBehParams2ndByte */ - #define GOOMBA_BP_SIZE_MASK 0x00000003 - #define GOOMBA_SIZE_REGULAR 0 - #define GOOMBA_SIZE_HUGE 1 - #define GOOMBA_SIZE_TINY 2 + #define GOOMBA_BP_SIZE_MASK 0x00000003 + #define GOOMBA_SIZE_REGULAR 0 + #define GOOMBA_SIZE_HUGE 1 + #define GOOMBA_SIZE_TINY 2 #define GOOMBA_BP_TRIPLET_FLAG_MASK 0x000000FC /* oAction */ - #define GOOMBA_ACT_WALK 0 + #define GOOMBA_ACT_WALK 0 #define GOOMBA_ACT_ATTACKED_MARIO 1 - #define GOOMBA_ACT_JUMP 2 + #define GOOMBA_ACT_JUMP 2 /* Chain chomp */ /* oAction */ #define CHAIN_CHOMP_ACT_UNINITIALIZED 0 - #define CHAIN_CHOMP_ACT_MOVE 1 - #define CHAIN_CHOMP_ACT_UNLOAD_CHAIN 2 + #define CHAIN_CHOMP_ACT_MOVE 1 + #define CHAIN_CHOMP_ACT_UNLOAD_CHAIN 2 /* oSubAction */ - #define CHAIN_CHOMP_SUB_ACT_TURN 0 + #define CHAIN_CHOMP_SUB_ACT_TURN 0 #define CHAIN_CHOMP_SUB_ACT_LUNGE 1 /* oChainChompReleaseStatus */ - #define CHAIN_CHOMP_NOT_RELEASED 0 + #define CHAIN_CHOMP_NOT_RELEASED 0 #define CHAIN_CHOMP_RELEASED_TRIGGER_CUTSCENE 1 - #define CHAIN_CHOMP_RELEASED_LUNGE_AROUND 2 - #define CHAIN_CHOMP_RELEASED_BREAK_GATE 3 - #define CHAIN_CHOMP_RELEASED_JUMP_AWAY 4 - #define CHAIN_CHOMP_RELEASED_END_CUTSCENE 5 + #define CHAIN_CHOMP_RELEASED_LUNGE_AROUND 2 + #define CHAIN_CHOMP_RELEASED_BREAK_GATE 3 + #define CHAIN_CHOMP_RELEASED_JUMP_AWAY 4 + #define CHAIN_CHOMP_RELEASED_END_CUTSCENE 5 /* Chain chomp chain part */ /* oBehParams2ndByte */ @@ -545,55 +665,55 @@ /* Wiggler */ /* oAction */ - #define WIGGLER_ACT_UNINITIALIZED 0 - #define WIGGLER_ACT_WALK 1 - #define WIGGLER_ACT_KNOCKBACK 2 - #define WIGGLER_ACT_JUMPED_ON 3 - #define WIGGLER_ACT_SHRINK 4 + #define WIGGLER_ACT_UNINITIALIZED 0 + #define WIGGLER_ACT_WALK 1 + #define WIGGLER_ACT_KNOCKBACK 2 + #define WIGGLER_ACT_JUMPED_ON 3 + #define WIGGLER_ACT_SHRINK 4 #define WIGGLER_ACT_FALL_THROUGH_FLOOR 5 /* oWigglerTextStatus */ - #define WIGGLER_TEXT_STATUS_AWAIT_DIALOG 0 - #define WIGGLER_TEXT_STATUS_SHOWING_DIALOG 1 + #define WIGGLER_TEXT_STATUS_AWAIT_DIALOG 0 + #define WIGGLER_TEXT_STATUS_SHOWING_DIALOG 1 #define WIGGLER_TEXT_STATUS_COMPLETED_DIALOG 2 /* Spiny */ /* oAction */ - #define SPINY_ACT_WALK 0 - #define SPINY_ACT_HELD_BY_LAKITU 1 + #define SPINY_ACT_WALK 0 + #define SPINY_ACT_HELD_BY_LAKITU 1 #define SPINY_ACT_THROWN_BY_LAKITU 2 - #define SPINY_ACT_ATTACKED_MARIO 3 + #define SPINY_ACT_ATTACKED_MARIO 3 /* Evil lakitu */ /* oAction */ #define ENEMY_LAKITU_ACT_UNINITIALIZED 0 - #define ENEMY_LAKITU_ACT_MAIN 1 + #define ENEMY_LAKITU_ACT_MAIN 1 /* oSubAction */ - #define ENEMY_LAKITU_SUB_ACT_NO_SPINY 0 - #define ENEMY_LAKITU_SUB_ACT_HOLD_SPINY 1 + #define ENEMY_LAKITU_SUB_ACT_NO_SPINY 0 + #define ENEMY_LAKITU_SUB_ACT_HOLD_SPINY 1 #define ENEMY_LAKITU_SUB_ACT_THROW_SPINY 2 /* Cloud */ /* oAction */ - #define CLOUD_ACT_SPAWN_PARTS 0 - #define CLOUD_ACT_MAIN 1 - #define CLOUD_ACT_UNLOAD 2 + #define CLOUD_ACT_SPAWN_PARTS 0 + #define CLOUD_ACT_MAIN 1 + #define CLOUD_ACT_UNLOAD 2 #define CLOUD_ACT_FWOOSH_HIDDEN 3 /* oBehParams2ndByte */ - #define CLOUD_BP_FWOOSH 0 + #define CLOUD_BP_FWOOSH 0 #define CLOUD_BP_LAKITU_CLOUD 1 /* Camera lakitu */ /* oAction */ #define CAMERA_LAKITU_INTRO_ACT_TRIGGER_CUTSCENE 0 - #define CAMERA_LAKITU_INTRO_ACT_SPAWN_CLOUD 1 - #define CAMERA_LAKITU_INTRO_ACT_UNK2 2 + #define CAMERA_LAKITU_INTRO_ACT_SPAWN_CLOUD 1 + #define CAMERA_LAKITU_INTRO_ACT_UNK2 2 /* oBehParams2ndByte */ #define CAMERA_LAKITU_BP_FOLLOW_CAMERA 0 - #define CAMERA_LAKITU_BP_INTRO 1 + #define CAMERA_LAKITU_BP_INTRO 1 /* Manta Ray */ /* oAction */ @@ -602,14 +722,14 @@ /* Monty mole */ /* oAction */ - #define MONTY_MOLE_ACT_SELECT_HOLE 0 - #define MONTY_MOLE_ACT_RISE_FROM_HOLE 1 - #define MONTY_MOLE_ACT_SPAWN_ROCK 2 + #define MONTY_MOLE_ACT_SELECT_HOLE 0 + #define MONTY_MOLE_ACT_RISE_FROM_HOLE 1 + #define MONTY_MOLE_ACT_SPAWN_ROCK 2 #define MONTY_MOLE_ACT_BEGIN_JUMP_INTO_HOLE 3 - #define MONTY_MOLE_ACT_THROW_ROCK 4 - #define MONTY_MOLE_ACT_JUMP_INTO_HOLE 5 - #define MONTY_MOLE_ACT_HIDE 6 - #define MONTY_MOLE_ACT_JUMP_OUT_OF_HOLE 7 + #define MONTY_MOLE_ACT_THROW_ROCK 4 + #define MONTY_MOLE_ACT_JUMP_INTO_HOLE 5 + #define MONTY_MOLE_ACT_HIDE 6 + #define MONTY_MOLE_ACT_JUMP_OUT_OF_HOLE 7 /* oBehParams2ndByte */ #define MONTY_MOLE_BP_NO_ROCK 0 @@ -697,36 +817,39 @@ /* Piranha Plant */ /* oAction */ - #define PIRANHA_PLANT_ACT_IDLE 0 - #define PIRANHA_PLANT_ACT_SLEEPING 1 - #define PIRANHA_PLANT_ACT_BITING 2 - #define PIRANHA_PLANT_ACT_WOKEN_UP 3 - #define PIRANHA_PLANT_ACT_STOPPED_BITING 4 - #define PIRANHA_PLANT_ACT_ATTACKED 5 - #define PIRANHA_PLANT_ACT_SHRINK_AND_DIE 6 + #define PIRANHA_PLANT_ACT_IDLE 0 + #define PIRANHA_PLANT_ACT_SLEEPING 1 + #define PIRANHA_PLANT_ACT_BITING 2 + #define PIRANHA_PLANT_ACT_WOKEN_UP 3 + #define PIRANHA_PLANT_ACT_STOPPED_BITING 4 + #define PIRANHA_PLANT_ACT_ATTACKED 5 + #define PIRANHA_PLANT_ACT_SHRINK_AND_DIE 6 #define PIRANHA_PLANT_ACT_WAIT_TO_RESPAWN 7 - #define PIRANHA_PLANT_ACT_RESPAWN 8 + #define PIRANHA_PLANT_ACT_RESPAWN 8 + + /* oPiranhaPlantSleepMusicState */ + #define PIRANHA_PLANT_SLEEP_MUSIC_PLAYING 0 /* Piranha Plant bubble */ - #define PIRANHA_PLANT_BUBBLE_ACT_IDLE 0 + #define PIRANHA_PLANT_BUBBLE_ACT_IDLE 0 #define PIRANHA_PLANT_BUBBLE_ACT_GROW_SHRINK_LOOP 1 - #define PIRANHA_PLANT_BUBBLE_ACT_BURST 2 + #define PIRANHA_PLANT_BUBBLE_ACT_BURST 2 /* Platform on track */ /* oAction */ - #define PLATFORM_ON_TRACK_ACT_INIT 0 - #define PLATFORM_ON_TRACK_ACT_WAIT_FOR_MARIO 1 + #define PLATFORM_ON_TRACK_ACT_INIT 0 + #define PLATFORM_ON_TRACK_ACT_WAIT_FOR_MARIO 1 #define PLATFORM_ON_TRACK_ACT_MOVE_ALONG_TRACK 2 - #define PLATFORM_ON_TRACK_ACT_PAUSE_BRIEFLY 3 - #define PLATFORM_ON_TRACK_ACT_FALL 4 + #define PLATFORM_ON_TRACK_ACT_PAUSE_BRIEFLY 3 + #define PLATFORM_ON_TRACK_ACT_FALL 4 /* oBehParams >> 16 */ - #define PLATFORM_ON_TRACK_BP_MASK_PATH 0xF - #define PLATFORM_ON_TRACK_BP_MASK_TYPE (0x7 << 4) + #define PLATFORM_ON_TRACK_BP_MASK_PATH 0xF + #define PLATFORM_ON_TRACK_BP_MASK_TYPE (0x7 << 4) #define PLATFORM_ON_TRACK_BP_RETURN_TO_START (1 << 8) - #define PLATFORM_ON_TRACK_BP_DONT_DISAPPEAR (1 << 9) - #define PLATFORM_ON_TRACK_BP_DONT_TURN_YAW (1 << 10) - #define PLATFORM_ON_TRACK_BP_DONT_TURN_ROLL (1 << 11) + #define PLATFORM_ON_TRACK_BP_DONT_DISAPPEAR (1 << 9) + #define PLATFORM_ON_TRACK_BP_DONT_TURN_YAW (1 << 10) + #define PLATFORM_ON_TRACK_BP_DONT_TURN_ROLL (1 << 11) #define PLATFORM_ON_TRACK_TYPE_CARPET 0 #define PLATFORM_ON_TRACK_TYPE_SKI_LIFT 1 @@ -748,18 +871,18 @@ /* Pyramid top */ #define PYRAMID_TOP_ACT_CHECK_IF_SOLVED 0 - #define PYRAMID_TOP_ACT_SPINNING 1 - #define PYRAMID_TOP_ACT_EXPLODE 2 + #define PYRAMID_TOP_ACT_SPINNING 1 + #define PYRAMID_TOP_ACT_EXPLODE 2 /* Pyramid wall */ /* oAction */ #define PYRAMID_WALL_ACT_MOVING_DOWN 0 - #define PYRAMID_WALL_ACT_MOVING_UP 1 + #define PYRAMID_WALL_ACT_MOVING_UP 1 /* oBehParams2ndByte */ - #define PYRAMID_WALL_BP_POSITION_HIGH 0 + #define PYRAMID_WALL_BP_POSITION_HIGH 0 #define PYRAMID_WALL_BP_POSITION_MIDDLE 1 - #define PYRAMID_WALL_BP_POSITION_LOW 2 + #define PYRAMID_WALL_BP_POSITION_LOW 2 /* Penguins (general) */ /* Walking sounds */ @@ -772,58 +895,57 @@ /* Racing penguin */ /* oAction */ - #define RACING_PENGUIN_ACT_WAIT_FOR_MARIO 0 - #define RACING_PENGUIN_ACT_SHOW_INIT_TEXT 1 + #define RACING_PENGUIN_ACT_WAIT_FOR_MARIO 0 + #define RACING_PENGUIN_ACT_SHOW_INIT_TEXT 1 #define RACING_PENGUIN_ACT_PREPARE_FOR_RACE 2 - #define RACING_PENGUIN_ACT_RACE 3 - #define RACING_PENGUIN_ACT_FINISH_RACE 4 - #define RACING_PENGUIN_ACT_SHOW_FINAL_TEXT 5 + #define RACING_PENGUIN_ACT_RACE 3 + #define RACING_PENGUIN_ACT_FINISH_RACE 4 + #define RACING_PENGUIN_ACT_SHOW_FINAL_TEXT 5 /* SL walking penguin */ /* oAction */ - #define SL_WALKING_PENGUIN_ACT_MOVING_FORWARDS 0 - #define SL_WALKING_PENGUIN_ACT_TURNING_BACK 1 - #define SL_WALKING_PENGUIN_ACT_RETURNING 2 + #define SL_WALKING_PENGUIN_ACT_MOVING_FORWARDS 0 + #define SL_WALKING_PENGUIN_ACT_TURNING_BACK 1 + #define SL_WALKING_PENGUIN_ACT_RETURNING 2 #define SL_WALKING_PENGUIN_ACT_TURNING_FORWARDS 3 /* Snowman wind */ /* oSubAction */ - #define SL_SNOWMAN_WIND_ACT_IDLE 0 + #define SL_SNOWMAN_WIND_ACT_IDLE 0 #define SL_SNOWMAN_WIND_ACT_TALKING 1 #define SL_SNOWMAN_WIND_ACT_BLOWING 2 - /* Water bomb */ /* oAction */ #define WATER_BOMB_ACT_SHOT_FROM_CANNON 0 - #define WATER_BOMB_ACT_INIT 1 - #define WATER_BOMB_ACT_DROP 2 - #define WATER_BOMB_ACT_EXPLODE 3 + #define WATER_BOMB_ACT_INIT 1 + #define WATER_BOMB_ACT_DROP 2 + #define WATER_BOMB_ACT_EXPLODE 3 /* TTC rotating solid */ /* oBehParams2ndByte */ - #define TTC_ROTATING_SOLID_BP_CUBE 0 + #define TTC_ROTATING_SOLID_BP_CUBE 0 #define TTC_ROTATING_SOLID_BP_TRIANGULAR_PRISM 1 /* TTC moving bar */ /* oAction */ - #define TTC_MOVING_BAR_ACT_WAIT 0 + #define TTC_MOVING_BAR_ACT_WAIT 0 #define TTC_MOVING_BAR_ACT_PULL_BACK 1 - #define TTC_MOVING_BAR_ACT_EXTEND 2 - #define TTC_MOVING_BAR_ACT_RETRACT 3 + #define TTC_MOVING_BAR_ACT_EXTEND 2 + #define TTC_MOVING_BAR_ACT_RETRACT 3 /* TTC cog */ /* oBehParams2ndByte */ - #define TTC_COG_BP_SHAPE_MASK 0x00000002 - #define TTC_COG_BP_SHAPE_HEXAGON (0 << 1) + #define TTC_COG_BP_SHAPE_MASK 0x00000002 + #define TTC_COG_BP_SHAPE_HEXAGON (0 << 1) #define TTC_COG_BP_SHAPE_TRIANGLE (1 << 1) - #define TTC_COG_BP_DIR_MASK 0x00000001 - #define TTC_COG_BP_DIR_CCW (0 << 0) // TODO: Check these - #define TTC_COG_BP_DIR_CW (1 << 0) + #define TTC_COG_BP_DIR_MASK 0x00000001 + #define TTC_COG_BP_DIR_CCW (0 << 0) // TODO: Check these + #define TTC_COG_BP_DIR_CW (1 << 0) /* TTC 2D Rotator */ /* oBehParams2ndByte */ - #define TTC_2D_ROTATOR_BP_HAND 0 + #define TTC_2D_ROTATOR_BP_HAND 0 #define TTC_2D_ROTATOR_BP_2D_COG 1 /* Activated Back-and-Forth Platform */ @@ -834,13 +956,13 @@ /* Dorrie */ /* oAction */ - #define DORRIE_ACT_MOVE 0 + #define DORRIE_ACT_MOVE 0 #define DORRIE_ACT_LOWER_HEAD 1 #define DORRIE_ACT_RAISE_HEAD 2 /* Mad piano */ /* oAction */ - #define MAD_PIANO_ACT_WAIT 0 + #define MAD_PIANO_ACT_WAIT 0 #define MAD_PIANO_ACT_ATTACK 1 /* Fire piranha plant */ @@ -850,56 +972,56 @@ /* Fire spitter */ /* oAction */ - #define FIRE_SPITTER_ACT_IDLE 0 + #define FIRE_SPITTER_ACT_IDLE 0 #define FIRE_SPITTER_ACT_SPIT_FIRE 1 /* Eyerok boss */ /* oAction */ - #define EYEROK_BOSS_ACT_SLEEP 0 - #define EYEROK_BOSS_ACT_WAKE_UP 1 + #define EYEROK_BOSS_ACT_SLEEP 0 + #define EYEROK_BOSS_ACT_WAKE_UP 1 #define EYEROK_BOSS_ACT_SHOW_INTRO_TEXT 2 - #define EYEROK_BOSS_ACT_FIGHT 3 - #define EYEROK_BOSS_ACT_DIE 4 + #define EYEROK_BOSS_ACT_FIGHT 3 + #define EYEROK_BOSS_ACT_DIE 4 /* Eyerok hand */ /* oAction */ - #define EYEROK_HAND_ACT_SLEEP 0 - #define EYEROK_HAND_ACT_IDLE 1 - #define EYEROK_HAND_ACT_OPEN 2 - #define EYEROK_HAND_ACT_SHOW_EYE 3 - #define EYEROK_HAND_ACT_CLOSE 4 - #define EYEROK_HAND_ACT_RETREAT 5 - #define EYEROK_HAND_ACT_TARGET_MARIO 6 - #define EYEROK_HAND_ACT_SMASH 7 - #define EYEROK_HAND_ACT_FIST_PUSH 8 - #define EYEROK_HAND_ACT_FIST_SWEEP 9 + #define EYEROK_HAND_ACT_SLEEP 0 + #define EYEROK_HAND_ACT_IDLE 1 + #define EYEROK_HAND_ACT_OPEN 2 + #define EYEROK_HAND_ACT_SHOW_EYE 3 + #define EYEROK_HAND_ACT_CLOSE 4 + #define EYEROK_HAND_ACT_RETREAT 5 + #define EYEROK_HAND_ACT_TARGET_MARIO 6 + #define EYEROK_HAND_ACT_SMASH 7 + #define EYEROK_HAND_ACT_FIST_PUSH 8 + #define EYEROK_HAND_ACT_FIST_SWEEP 9 #define EYEROK_HAND_ACT_BEGIN_DOUBLE_POUND 10 // raising for double smash - #define EYEROK_HAND_ACT_DOUBLE_POUND 11 // double smashing - #define EYEROK_HAND_ACT_ATTACKED 12 - #define EYEROK_HAND_ACT_RECOVER 13 - #define EYEROK_HAND_ACT_BECOME_ACTIVE 14 - #define EYEROK_HAND_ACT_DIE 15 + #define EYEROK_HAND_ACT_DOUBLE_POUND 11 // double smashing + #define EYEROK_HAND_ACT_ATTACKED 12 + #define EYEROK_HAND_ACT_RECOVER 13 + #define EYEROK_HAND_ACT_BECOME_ACTIVE 14 + #define EYEROK_HAND_ACT_DIE 15 /* Klepto */ /* oAction */ - #define KLEPTO_ACT_CIRCLE_TARGET_HOLDING 0 + #define KLEPTO_ACT_CIRCLE_TARGET_HOLDING 0 #define KLEPTO_ACT_APPROACH_TARGET_HOLDING 1 - #define KLEPTO_ACT_WAIT_FOR_MARIO 2 - #define KLEPTO_ACT_TURN_TOWARD_MARIO 3 - #define KLEPTO_ACT_DIVE_AT_MARIO 4 - #define KLEPTO_ACT_RESET_POSITION 5 - #define KLEPTO_ACT_STRUCK_BY_MARIO 6 - #define KLEPTO_ACT_RETREAT 7 + #define KLEPTO_ACT_WAIT_FOR_MARIO 2 + #define KLEPTO_ACT_TURN_TOWARD_MARIO 3 + #define KLEPTO_ACT_DIVE_AT_MARIO 4 + #define KLEPTO_ACT_RESET_POSITION 5 + #define KLEPTO_ACT_STRUCK_BY_MARIO 6 + #define KLEPTO_ACT_RETREAT 7 /* oAnimState */ #define KLEPTO_ANIM_STATE_HOLDING_NOTHING 0 - #define KLEPTO_ANIM_STATE_HOLDING_CAP 1 - #define KLEPTO_ANIM_STATE_HOLDING_STAR 2 + #define KLEPTO_ANIM_STATE_HOLDING_CAP 1 + #define KLEPTO_ANIM_STATE_HOLDING_STAR 2 /* Bird */ /* oAction */ #define BIRD_ACT_INACTIVE 0 - #define BIRD_ACT_FLY 1 + #define BIRD_ACT_FLY 1 /* oBehParams2ndByte */ #define BIRD_BP_SPAWNED 0 @@ -907,9 +1029,9 @@ /* Skeeter */ /* oAction */ - #define SKEETER_ACT_IDLE 0 + #define SKEETER_ACT_IDLE 0 #define SKEETER_ACT_LUNGE 1 - #define SKEETER_ACT_WALK 2 + #define SKEETER_ACT_WALK 2 /* Snufit */ /* oAction */ @@ -929,68 +1051,69 @@ /* Triplet butterfly */ /* oAction */ - #define TRIPLET_BUTTERFLY_ACT_INIT 0 - #define TRIPLET_BUTTERFLY_ACT_WANDER 1 + #define TRIPLET_BUTTERFLY_ACT_INIT 0 + #define TRIPLET_BUTTERFLY_ACT_WANDER 1 #define TRIPLET_BUTTERFLY_ACT_ACTIVATE 2 - #define TRIPLET_BUTTERFLY_ACT_EXPLODE 3 + #define TRIPLET_BUTTERFLY_ACT_EXPLODE 3 /* oBehParams2ndByte */ #define TRIPLET_BUTTERFLY_BP_BUTTERFLY_NUM 0x00000003 - #define TRIPLET_BUTTERFLY_BP_NO_BOMBS 0x00000004 + #define TRIPLET_BUTTERFLY_BP_NO_BOMBS 0x00000004 /* oTripletButterflyType */ - #define TRIPLET_BUTTERFLY_TYPE_NORMAL -1 - #define TRIPLET_BUTTERFLY_TYPE_EXPLODES 0 - #define TRIPLET_BUTTERFLY_TYPE_SPAWN_1UP 1 + #define TRIPLET_BUTTERFLY_TYPE_NORMAL -1 + #define TRIPLET_BUTTERFLY_TYPE_EXPLODES 0 + #define TRIPLET_BUTTERFLY_TYPE_SPAWN_1UP 1 /* Water level diamond */ /* oAction */ // Loading - #define WATER_LEVEL_DIAMOND_ACT_INIT 0 + #define WATER_LEVEL_DIAMOND_ACT_INIT 0 // Idling when Mario isn't inside its hitbox - #define WATER_LEVEL_DIAMOND_ACT_IDLE 1 + #define WATER_LEVEL_DIAMOND_ACT_IDLE 1 // While the water level is changing #define WATER_LEVEL_DIAMOND_ACT_CHANGE_WATER_LEVEL 2 // After the water level has changed but Mario hasn't left its hitbox yet - #define WATER_LEVEL_DIAMOND_ACT_IDLE_SPINNING 3 + #define WATER_LEVEL_DIAMOND_ACT_IDLE_SPINNING 3 /* Mips */ /* oAction */ - #define MIPS_ACT_WAIT_FOR_NEARBY_MARIO 0 - #define MIPS_ACT_FOLLOW_PATH 1 + #define MIPS_ACT_WAIT_FOR_NEARBY_MARIO 0 + #define MIPS_ACT_FOLLOW_PATH 1 #define MIPS_ACT_WAIT_FOR_ANIMATION_DONE 2 - #define MIPS_ACT_FALL_DOWN 3 - #define MIPS_ACT_IDLE 4 + #define MIPS_ACT_FALL_DOWN 3 + #define MIPS_ACT_IDLE 4 /* oMipsStarStatus */ - #define MIPS_STAR_STATUS_HAVENT_SPAWNED_STAR 0 - #define MIPS_STAR_STATUS_SHOULD_SPAWN_STAR 1 + #define MIPS_STAR_STATUS_HAVENT_SPAWNED_STAR 0 + #define MIPS_STAR_STATUS_SHOULD_SPAWN_STAR 1 #define MIPS_STAR_STATUS_ALREADY_SPAWNED_STAR 2 /* Falling Pillar */ /* oAction */ - #define FALLING_PILLAR_ACT_IDLE 0 + #define FALLING_PILLAR_ACT_IDLE 0 #define FALLING_PILLAR_ACT_TURNING 1 #define FALLING_PILLAR_ACT_FALLING 2 /* Bowser Puzzle */ /* oAction */ - #define BOWSER_PUZZLE_ACT_SPAWN_PIECES 0 + #define BOWSER_PUZZLE_ACT_SPAWN_PIECES 0 #define BOWSER_PUZZLE_ACT_WAIT_FOR_COMPLETE 1 - #define BOWSER_PUZZLE_ACT_DONE 2 + #define BOWSER_PUZZLE_ACT_DONE 2 /* Mr Blizzard */ /* oAction */ - #define MR_BLIZZARD_ACT_SPAWN_SNOWBALL 0 - #define MR_BLIZZARD_ACT_HIDE_UNHIDE 1 + #define MR_BLIZZARD_ACT_SPAWN_SNOWBALL 0 + #define MR_BLIZZARD_ACT_HIDE_UNHIDE 1 #define MR_BLIZZARD_ACT_RISE_FROM_GROUND 2 - #define MR_BLIZZARD_ACT_ROTATE 3 - #define MR_BLIZZARD_ACT_THROW_SNOWBALL 4 - #define MR_BLIZZARD_ACT_BURROW 5 - #define MR_BLIZZARD_ACT_DEATH 6 - #define MR_BLIZZARD_ACT_JUMP 7 + #define MR_BLIZZARD_ACT_ROTATE 3 + #define MR_BLIZZARD_ACT_THROW_SNOWBALL 4 + #define MR_BLIZZARD_ACT_BURROW 5 + #define MR_BLIZZARD_ACT_DEATH 6 + #define MR_BLIZZARD_ACT_JUMP 7 + /* oBehParams2ndByte */ - #define MR_BLIZZARD_STYPE_NO_CAP 0 + #define MR_BLIZZARD_STYPE_NO_CAP 0 #define MR_BLIZZARD_STYPE_JUMPING 1 #endif // OBJECT_CONSTANTS_H diff --git a/include/object_fields.h b/include/object_fields.h index 89939cc2..8159f4aa 100644 --- a/include/object_fields.h +++ b/include/object_fields.h @@ -65,8 +65,8 @@ #define /*0x0B4*/ oVelZ OBJECT_FIELD_F32(0x0B) #define /*0x0B8*/ oForwardVel OBJECT_FIELD_F32(0x0C) #define /*0x0B8*/ oForwardVelS32 OBJECT_FIELD_S32(0x0C) -#define /*0x0BC*/ oUnkBC OBJECT_FIELD_F32(0x0D) -#define /*0x0C0*/ oUnkC0 OBJECT_FIELD_F32(0x0E) +#define /*0x0BC*/ oLeftVel OBJECT_FIELD_F32(0x0D) +#define /*0x0C0*/ oUpVel OBJECT_FIELD_F32(0x0E) #define /*0x0C4*/ O_MOVE_ANGLE_INDEX 0x0F #define /*0x0C4*/ O_MOVE_ANGLE_PITCH_INDEX (O_MOVE_ANGLE_INDEX + 0) #define /*0x0C4*/ O_MOVE_ANGLE_YAW_INDEX (O_MOVE_ANGLE_INDEX + 1) @@ -186,8 +186,8 @@ #define /*0x0FC*/ oHomingAmpAvgY OBJECT_FIELD_F32(0x1D) /* Arrow Lift */ -#define /*0x0F4*/ oArrowLiftDisplacement OBJECT_FIELD_F32(0x1B) -#define /*0x100*/ oArrowLiftUnk100 OBJECT_FIELD_S32(0x1E) +#define /*0x0F4*/ oArrowLiftDisplacement OBJECT_FIELD_F32(0x1B) +#define /*0x100*/ oArrowLiftUnk100 OBJECT_FIELD_S32(0x1E) /* Back-and-Forth Platform */ #define /*0x0F4*/ oBackAndForthPlatformDirection OBJECT_FIELD_F32(0x1B) @@ -274,24 +274,24 @@ #define /*0x0FC*/ oBBallSpawnerPeriodMinus1 OBJECT_FIELD_S32(0x1D) /* Bowser */ -#define /*0x088*/ oBowserUnk88 OBJECT_FIELD_S32(0x00) -#define /*0x0F4*/ oBowserUnkF4 OBJECT_FIELD_S32(0x1B) -#define /*0x0F8*/ oBowserUnkF8 OBJECT_FIELD_S32(0x1C) -#define /*0x0FC*/ oBowserDistToCentre OBJECT_FIELD_F32(0x1D) -#define /*0x106*/ oBowserUnk106 OBJECT_FIELD_S16(0x1F, 1) -#define /*0x108*/ oBowserUnk108 OBJECT_FIELD_S16(0x20, 0) +#define /*0x088*/ oBowserCamAct OBJECT_FIELD_S32(0x00) +#define /*0x0F4*/ oBowserStatus OBJECT_FIELD_S32(0x1B) +#define /*0x0F8*/ oBowserTimer OBJECT_FIELD_S32(0x1C) +#define /*0x0FC*/ oBowserDistToCenter OBJECT_FIELD_F32(0x1D) +#define /*0x106*/ oBowserBitsJustJump OBJECT_FIELD_S16(0x1F, 1) +#define /*0x108*/ oBowserRandSplitFloor OBJECT_FIELD_S16(0x20, 0) #define /*0x10A*/ oBowserHeldAnglePitch OBJECT_FIELD_S16(0x20, 1) #define /*0x10D*/ oBowserHeldAngleVelYaw OBJECT_FIELD_S16(0x21, 0) -#define /*0x10E*/ oBowserUnk10E OBJECT_FIELD_S16(0x21, 1) -#define /*0x110*/ oBowserUnk110 OBJECT_FIELD_S16(0x22, 0) -#define /*0x112*/ oBowserAngleToCentre OBJECT_FIELD_S16(0x22, 1) -#define /*0x1AC*/ oBowserUnk1AC OBJECT_FIELD_S16(0x49, 0) -#define /*0x1AE*/ oBowserUnk1AE OBJECT_FIELD_S16(0x49, 1) +#define /*0x10E*/ oBowserGrabbedStatus OBJECT_FIELD_S16(0x21, 1) +#define /*0x110*/ oBowserIsReacting OBJECT_FIELD_S16(0x22, 0) +#define /*0x112*/ oBowserAngleToCenter OBJECT_FIELD_S16(0x22, 1) +#define /*0x1AC*/ oBowserTargetOpacity OBJECT_FIELD_S16(0x49, 0) +#define /*0x1AE*/ oBowserEyesTimer OBJECT_FIELD_S16(0x49, 1) #define /*0x1B0*/ oBowserEyesShut OBJECT_FIELD_S16(0x4A, 0) -#define /*0x1B2*/ oBowserUnk1B2 OBJECT_FIELD_S16(0x4A, 1) +#define /*0x1B2*/ oBowserRainbowLight OBJECT_FIELD_S16(0x4A, 1) /* Bowser Shockwave */ -#define /*0x0F4*/ oBowserShockWaveUnkF4 OBJECT_FIELD_F32(0x1B) +#define /*0x0F4*/ oBowserShockWaveScale OBJECT_FIELD_F32(0x1B) /* Black Smoke Bowser */ #define /*0x0F4*/ oBlackSmokeBowserUnkF4 OBJECT_FIELD_F32(0x1B) @@ -319,9 +319,9 @@ #define /*0x108*/ oBubbaUnk108 OBJECT_FIELD_F32(0x20) #define /*0x10C*/ oBubbaUnk10C OBJECT_FIELD_F32(0x21) #define /*0x1AC*/ oBubbaUnk1AC OBJECT_FIELD_S16(0x49, 0) -#define /*0x1AE*/ oBubbaUnk1AE OBJECT_FIELD_S16(0x49, + 1) +#define /*0x1AE*/ oBubbaUnk1AE OBJECT_FIELD_S16(0x49, 1) #define /*0x1B0*/ oBubbaUnk1B0 OBJECT_FIELD_S16(0x4A, 0) -#define /*0x1B2*/ oBubbaUnk1B2 OBJECT_FIELD_S16(0x4A, + 1) +#define /*0x1B2*/ oBubbaUnk1B2 OBJECT_FIELD_S16(0x4A, 1) /* Bullet Bill */ #define /*0x0F8*/ oBulletBillInitialMoveYaw OBJECT_FIELD_S32(0x1C) @@ -406,7 +406,7 @@ #endif /* Collision Particle */ -#define /*0x0F4*/ oCollisionParticleUnkF4 OBJECT_FIELD_F32(0x1B) +#define /*0x0F4*/ oCollisionParticleUnkF4 OBJECT_FIELD_F32(0x1B) /* Controllable Platform */ #define /*0x0F8*/ oControllablePlatformUnkF8 OBJECT_FIELD_S32(0x1C) @@ -442,9 +442,9 @@ #define /*0x104*/ oDorrieYawVel OBJECT_FIELD_S32(0x1F) #define /*0x10C*/ oDorrieLiftingMario OBJECT_FIELD_S32(0x21) #define /*0x1AC*/ oDorrieGroundPounded OBJECT_FIELD_S16(0x49, 0) -#define /*0x1AE*/ oDorrieAngleToHome OBJECT_FIELD_S16(0x49, + 1) +#define /*0x1AE*/ oDorrieAngleToHome OBJECT_FIELD_S16(0x49, 1) #define /*0x1B0*/ oDorrieNeckAngle OBJECT_FIELD_S16(0x4A, 0) -#define /*0x1B2*/ oDorrieHeadRaiseSpeed OBJECT_FIELD_S16(0x4A, + 1) +#define /*0x1B2*/ oDorrieHeadRaiseSpeed OBJECT_FIELD_S16(0x4A, 1) /* Elevator */ #define /*0x0F4*/ oElevatorUnkF4 OBJECT_FIELD_F32(0x1B) @@ -497,7 +497,7 @@ /* Flame */ #define /*0x0F4*/ oFlameScale OBJECT_FIELD_F32(0x1B) #define /*0x0F8*/ oFlameSpeedTimerOffset OBJECT_FIELD_S32(0x1C) -#define /*0x0FC*/ oFlameUnkFC OBJECT_FIELD_F32(0x1D) +#define /*0x0FC*/ oFlameUnusedRand OBJECT_FIELD_F32(0x1D) #define /*0x100*/ oFlameBowser OBJECT_FIELD_OBJ(0x1E) /* Blue Flame */ @@ -523,7 +523,7 @@ #define /*0x0F4*/ oFloatingPlatformUnkF4 OBJECT_FIELD_S32(0x1B) #define /*0x0F8*/ oFloatingPlatformUnkF8 OBJECT_FIELD_F32(0x1C) #define /*0x0FC*/ oFloatingPlatformUnkFC OBJECT_FIELD_F32(0x1D) -#define /*0x100*/ oFloatingPlatformUnk100 OBJECT_FIELD_S32(0x1E) +#define /*0x100*/ oFloatingPlatformUnk100 OBJECT_FIELD_S32(0x1E) /* Floor Switch Press Animation */ #define /*0x0F4*/ oFloorSwitchPressAnimationUnkF4 OBJECT_FIELD_S32(0x1B) @@ -604,9 +604,9 @@ #define /*0x10C*/ oKleptoStartPosZ OBJECT_FIELD_F32(0x21) #define /*0x110*/ oKleptoTimeUntilTargetChange OBJECT_FIELD_S32(0x22) #define /*0x1AC*/ oKleptoTargetNumber OBJECT_FIELD_S16(0x49, 0) -#define /*0x1AE*/ oKleptoUnk1AE OBJECT_FIELD_S16(0x49, + 1) +#define /*0x1AE*/ oKleptoUnk1AE OBJECT_FIELD_S16(0x49, 1) #define /*0x1B0*/ oKleptoUnk1B0 OBJECT_FIELD_S16(0x4A, 0) -#define /*0x1B2*/ oKleptoYawToTarget OBJECT_FIELD_S16(0x4A, + 1) +#define /*0x1B2*/ oKleptoYawToTarget OBJECT_FIELD_S16(0x4A, 1) /* Koopa */ #define /*0x0F4*/ oKoopaAgility OBJECT_FIELD_F32(0x1B) @@ -626,12 +626,12 @@ #define /*0x0F4*/ oKoopaRaceEndpointRaceBegun OBJECT_FIELD_S32(0x1B) #define /*0x0F8*/ oKoopaRaceEndpointKoopaFinished OBJECT_FIELD_S32(0x1C) #define /*0x0FC*/ oKoopaRaceEndpointRaceStatus OBJECT_FIELD_S32(0x1D) -#define /*0x100*/ oKoopaRaceEndpointUnk100 OBJECT_FIELD_S32(0x1E) +#define /*0x100*/ oKoopaRaceEndpointDialog OBJECT_FIELD_S32(0x1E) #define /*0x104*/ oKoopaRaceEndpointRaceEnded OBJECT_FIELD_S32(0x1F) /* Koopa Shell Flame */ #define /*0x0F4*/ oKoopaShellFlameUnkF4 OBJECT_FIELD_F32(0x1B) -#define /*0x0F8*/ oKoopaShellFlameUnkF8 OBJECT_FIELD_F32(0x1C) +#define /*0x0F8*/ oKoopaShellFlameScale OBJECT_FIELD_F32(0x1C) /* Camera Lakitu */ #define /*0x0F4*/ oCameraLakituBlinkTimer OBJECT_FIELD_S32(0x1B) @@ -642,7 +642,7 @@ #define /*0x104*/ oCameraLakituUnk104 OBJECT_FIELD_S32(0x1F) #endif #define /*0x1AC*/ oCameraLakituPitchVel OBJECT_FIELD_S16(0x49, 0) -#define /*0x1AE*/ oCameraLakituYawVel OBJECT_FIELD_S16(0x49, + 1) +#define /*0x1AE*/ oCameraLakituYawVel OBJECT_FIELD_S16(0x49, 1) /* Evil Lakitu */ #define /*0x0F4*/ oEnemyLakituNumSpinies OBJECT_FIELD_S32(0x1B) @@ -651,14 +651,14 @@ #define /*0x100*/ oEnemyLakituFaceForwardCountdown OBJECT_FIELD_S32(0x1E) /* Intro Cutscene Lakitu */ -#define /*0x0F8*/ oIntroLakituSplineSegmentProgress OBJECT_FIELD_F32(0x1C) -#define /*0x0FC*/ oIntroLakituSplineSegment OBJECT_FIELD_F32(0x1D) -#define /*0x100*/ oIntroLakituUnk100 OBJECT_FIELD_F32(0x1E) -#define /*0x104*/ oIntroLakituUnk104 OBJECT_FIELD_F32(0x1F) -#define /*0x108*/ oIntroLakituUnk108 OBJECT_FIELD_F32(0x20) -#define /*0x10C*/ oIntroLakituUnk10C OBJECT_FIELD_F32(0x21) -#define /*0x110*/ oIntroLakituUnk110 OBJECT_FIELD_F32(0x22) -#define /*0x1AC*/ oIntroLakituCloud OBJECT_FIELD_OBJ(0x49) +#define /*0x0F8*/ oIntroLakituSplineSegmentProgress OBJECT_FIELD_F32(0x1C) +#define /*0x0FC*/ oIntroLakituSplineSegment OBJECT_FIELD_F32(0x1D) +#define /*0x100*/ oIntroLakituUnk100 OBJECT_FIELD_F32(0x1E) +#define /*0x104*/ oIntroLakituUnk104 OBJECT_FIELD_F32(0x1F) +#define /*0x108*/ oIntroLakituUnk108 OBJECT_FIELD_F32(0x20) +#define /*0x10C*/ oIntroLakituUnk10C OBJECT_FIELD_F32(0x21) +#define /*0x110*/ oIntroLakituUnk110 OBJECT_FIELD_F32(0x22) +#define /*0x1AC*/ oIntroLakituCloud OBJECT_FIELD_OBJ(0x49) /* Main Menu Button */ #define /*0x0F4*/ oMenuButtonState OBJECT_FIELD_S32(0x1B) @@ -715,7 +715,7 @@ #define /*0x100*/ oMrIUnk100 OBJECT_FIELD_S32(0x1E) #define /*0x104*/ oMrIUnk104 OBJECT_FIELD_S32(0x1F) #define /*0x108*/ oMrIUnk108 OBJECT_FIELD_S32(0x20) -#define /*0x10C*/ oMrISize OBJECT_FIELD_F32(0x21) +#define /*0x10C*/ oMrIScale OBJECT_FIELD_F32(0x21) #define /*0x110*/ oMrIUnk110 OBJECT_FIELD_S32(0x22) /* Object Respawner */ @@ -737,9 +737,9 @@ // 0x1D-0x21 reserved for pathing #define /*0x110*/ oRacingPenguinWeightedNewTargetSpeed OBJECT_FIELD_F32(0x22) #define /*0x1AC*/ oRacingPenguinFinalTextbox OBJECT_FIELD_S16(0x49, 0) -#define /*0x1AE*/ oRacingPenguinMarioWon OBJECT_FIELD_S16(0x49, + 1) +#define /*0x1AE*/ oRacingPenguinMarioWon OBJECT_FIELD_S16(0x49, 1) #define /*0x1B0*/ oRacingPenguinReachedBottom OBJECT_FIELD_S16(0x4A, 0) -#define /*0x1B2*/ oRacingPenguinMarioCheated OBJECT_FIELD_S16(0x4A, + 1) +#define /*0x1B2*/ oRacingPenguinMarioCheated OBJECT_FIELD_S16(0x4A, 1) /* Small Penguin */ #define /*0x088*/ oSmallPenguinUnk88 OBJECT_FIELD_S32(0x00) @@ -760,7 +760,7 @@ /* Fire Piranha Plant */ #define /*0x0F4*/ oFirePiranhaPlantNeutralScale OBJECT_FIELD_F32(0x1B) -#define /*0x0F8*/ oFirePiranhaPlantScale OBJECT_FIELD_F32(0x1C) //Shared with above obj? Coincidence? +#define /*0x0F8*/ oFirePiranhaPlantScale OBJECT_FIELD_F32(0x1C) // Shared with above obj? Coincidence? #define /*0x0FC*/ oFirePiranhaPlantActive OBJECT_FIELD_S32(0x1D) #define /*0x100*/ oFirePiranhaPlantDeathSpinTimer OBJECT_FIELD_S32(0x1E) #define /*0x104*/ oFirePiranhaPlantDeathSpinVel OBJECT_FIELD_F32(0x1F) @@ -770,10 +770,14 @@ #define /*0x0F8*/ oPitouneUnkF8 OBJECT_FIELD_F32(0x1C) #define /*0x0FC*/ oPitouneUnkFC OBJECT_FIELD_F32(0x1D) -/* Platform */ -#define /*0x0F4*/ oPlatformTimer OBJECT_FIELD_S32(0x1B) -#define /*0x0F8*/ oPlatformUnkF8 OBJECT_FIELD_OBJ(0x1C) -#define /*0x0FC*/ oPlatformUnkFC OBJECT_FIELD_S32(0x1D) +/* Falling Rising Bitfs Platform */ +#define /*0x0F4*/ oBitfsPlatformTimer OBJECT_FIELD_S32(0x1B) + +/* Falling Bowser Bits Platform */ +#define /*0x0F8*/ oBitsPlatformBowser OBJECT_FIELD_OBJ(0x1C) +#define /*0x0FC*/ oBitsPlatformTimer OBJECT_FIELD_S32(0x1D) + +/* WF Platform */ #define /*0x10C*/ oPlatformUnk10C OBJECT_FIELD_F32(0x21) #define /*0x110*/ oPlatformUnk110 OBJECT_FIELD_F32(0x22) @@ -788,9 +792,9 @@ #define /*0x10C*/ oPlatformOnTrackYaw OBJECT_FIELD_S32(0x21) #define /*0x110*/ oPlatformOnTrackOffsetY OBJECT_FIELD_F32(0x22) #define /*0x1AC*/ oPlatformOnTrackIsNotSkiLift OBJECT_FIELD_S16(0x49, 0) -#define /*0x1AE*/ oPlatformOnTrackIsNotHMC OBJECT_FIELD_S16(0x49, + 1) +#define /*0x1AE*/ oPlatformOnTrackIsNotHMC OBJECT_FIELD_S16(0x49, 1) #define /*0x1B0*/ oPlatformOnTrackType OBJECT_FIELD_S16(0x4A, 0) -#define /*0x1B2*/ oPlatformOnTrackWasStoodOn OBJECT_FIELD_S16(0x4A, + 1) +#define /*0x1B2*/ oPlatformOnTrackWasStoodOn OBJECT_FIELD_S16(0x4A, 1) /* Platform Spawner */ #define /*0x0F4*/ oPlatformSpawnerUnkF4 OBJECT_FIELD_S32(0x1B) @@ -853,11 +857,11 @@ #define /*0x108*/ oSinkWhenSteppedOnUnk108 OBJECT_FIELD_F32(0x20) /* Skeeter */ -#define /*0x0F4*/ oSkeeterTargetAngle OBJECT_FIELD_S32(0x1B) -#define /*0x0F8*/ oSkeeterUnkF8 OBJECT_FIELD_S32(0x1C) -#define /*0x0FC*/ oSkeeterUnkFC OBJECT_FIELD_F32(0x1D) -#define /*0x100*/ oSkeeterWaitTime OBJECT_FIELD_S32(0x1E) -#define /*0x1AC*/ oSkeeterUnk1AC OBJECT_FIELD_S16(0x49, 0) +#define /*0x0F4*/ oSkeeterTargetAngle OBJECT_FIELD_S32(0x1B) +#define /*0x0F8*/ oSkeeterTurningAwayFromWall OBJECT_FIELD_S32(0x1C) +#define /*0x0FC*/ oSkeeterUnkFC OBJECT_FIELD_F32(0x1D) +#define /*0x100*/ oSkeeterWaitTime OBJECT_FIELD_S32(0x1E) +#define /*0x1AC*/ oSkeeterUnk1AC OBJECT_FIELD_S16(0x49, 0) /* Jrb Sliding Box */ #define /*0x0F4*/ oJrbSlidingBoxUnkF4 OBJECT_FIELD_OBJ(0x1B) @@ -871,13 +875,13 @@ #define /*0x0F4*/ oSmokeTimer OBJECT_FIELD_S32(0x1B) /* Snowman's Bottom */ -#define /*0x0F4*/ oSnowmansBottomUnkF4 OBJECT_FIELD_F32(0x1B) +#define /*0x0F4*/ oSnowmansBottomScale OBJECT_FIELD_F32(0x1B) #define /*0x0F8*/ oSnowmansBottomUnkF8 OBJECT_FIELD_S32(0x1C) #define /*0x1AC*/ oSnowmansBottomUnk1AC OBJECT_FIELD_S32(0x49) // 0x1D-0x21 reserved for pathing /* Snowman's Head */ -#define /*0x0F4*/ oSnowmansHeadUnkF4 OBJECT_FIELD_S32(0x1B) +#define /*0x0F4*/ oSnowmansHeadDialogActive OBJECT_FIELD_S32(0x1B) /* Snowman Wind Blowing */ #define /*0x0F4*/ oSLSnowmanWindOriginalYaw OBJECT_FIELD_S32(0x1B) @@ -890,9 +894,9 @@ #define /*0x108*/ oSnufitBodyBaseScale OBJECT_FIELD_S32(0x20) #define /*0x10C*/ oSnufitBullets OBJECT_FIELD_S32(0x21) #define /*0x1AC*/ oSnufitXOffset OBJECT_FIELD_S16(0x49, 0) -#define /*0x1AE*/ oSnufitYOffset OBJECT_FIELD_S16(0x49, + 1) +#define /*0x1AE*/ oSnufitYOffset OBJECT_FIELD_S16(0x49, 1) #define /*0x1B0*/ oSnufitZOffset OBJECT_FIELD_S16(0x4A, 0) -#define /*0x1B2*/ oSnufitBodyScale OBJECT_FIELD_S16(0x4A, + 1) +#define /*0x1B2*/ oSnufitBodyScale OBJECT_FIELD_S16(0x4A, 1) /* Spindel */ #define /*0x0F4*/ oSpindelUnkF4 OBJECT_FIELD_S32(0x1B) @@ -1061,7 +1065,7 @@ #define /*0x110*/ oUnagiUnk110 OBJECT_FIELD_F32(0x22) #define /*0x1AC*/ oUnagiUnk1AC OBJECT_FIELD_F32(0x49) #define /*0x1B0*/ oUnagiUnk1B0 OBJECT_FIELD_S16(0x4A, 0) -#define /*0x1B2*/ oUnagiUnk1B2 OBJECT_FIELD_S16(0x4A, + 1) +#define /*0x1B2*/ oUnagiUnk1B2 OBJECT_FIELD_S16(0x4A, 1) /* Water Bomb */ #define /*0x0F8*/ oWaterBombVerticalStretch OBJECT_FIELD_F32(0x1C) @@ -1140,7 +1144,7 @@ #define /*0x10C*/ oWigglerTargetYaw OBJECT_FIELD_S32(0x21) #define /*0x110*/ oWigglerWalkAwayFromWallTimer OBJECT_FIELD_S32(0x22) #define /*0x1AC*/ oWigglerUnused OBJECT_FIELD_S16(0x49, 0) -#define /*0x1AE*/ oWigglerTextStatus OBJECT_FIELD_S16(0x49, + 1) +#define /*0x1AE*/ oWigglerTextStatus OBJECT_FIELD_S16(0x49, 1) /* Lll Wood Piece */ #define /*0x0F4*/ oLllWoodPieceOscillationTimer OBJECT_FIELD_S32(0x1B) diff --git a/include/segments.h b/include/segments.h index a8c1bf97..a97d6ee8 100644 --- a/include/segments.h +++ b/include/segments.h @@ -1,6 +1,8 @@ #ifndef SEGMENTS_H #define SEGMENTS_H +#include "config.h" + /* * Memory addresses for segments. Ideally, this header file would not be * needed, and the addresses would be defined in sm64.ld and linker-inserted @@ -20,10 +22,10 @@ #define SEG_BUFFERS 0x801C1000 -#ifdef VERSION_EU -#define SEG_MAIN 0x80241800 // TODO: Investigate why it's different? -#elif defined(VERSION_SH) +#if defined(VERSION_SH) || ENABLE_RUMBLE #define SEG_MAIN 0x80249000 +#elif defined(VERSION_EU) +#define SEG_MAIN 0x80241800 // TODO: Investigate why it's different? #else #define SEG_MAIN 0x80246000 #endif diff --git a/include/seq_ids.h b/include/seq_ids.h index 0aec73d1..8166de64 100644 --- a/include/seq_ids.h +++ b/include/seq_ids.h @@ -6,6 +6,8 @@ #define SEQ_BASE_ID 0x7f #define SEQ_VARIATION 0x80 +#define SEQ_MENU_GAME_OVER (SEQ_MENU_TITLE_SCREEN | SEQ_VARIATION) + enum SeqId { SEQ_SOUND_PLAYER, // 0x00 SEQ_EVENT_CUTSCENE_COLLECT_STAR, // 0x01 diff --git a/include/seq_macros.inc b/include/seq_macros.inc index e0633acb..d73d9923 100644 --- a/include/seq_macros.inc +++ b/include/seq_macros.inc @@ -1,7 +1,7 @@ -# Macros for disassembled sequence files. This file was automatically generated by seq_decoder.py. -# To regenerate it, run: ./tools/seq_decoder.py --emit-asm-macros >seq_macros.inc +// Macros for disassembled sequence files. This file was automatically generated by seq_decoder.py. +// To regenerate it, run: ./tools/seq_decoder.py --emit-asm-macros > include/seq_macros.inc -# seq commands +// seq commands .macro seq_testchdisabled a .byte 0x0 + \a @@ -155,7 +155,7 @@ .byte 0xff .endm -.ifdef VERSION_SH +#ifdef VERSION_SH .macro seq_unreservenotes .byte 0xf0 @@ -166,9 +166,9 @@ .byte \a .endm -.else +#else -.ifdef VERSION_EU +#ifdef VERSION_EU .macro seq_unreservenotes .byte 0xf0 @@ -179,7 +179,7 @@ .byte \a .endm -.else +#else .macro seq_unreservenotes .byte 0xf1 @@ -190,11 +190,11 @@ .byte \a .endm -.endif +#endif -.endif +#endif -# chan commands +// chan commands .macro chan_startchannel a, b .byte 0x10 + \a @@ -462,7 +462,7 @@ var_long \a .endm -.ifdef VERSION_SH +#ifdef VERSION_SH .macro chan_setnotepriority a .byte 0xe9 @@ -495,7 +495,7 @@ .byte 0x90 + \a .endm -.else +#else .macro chan_testlayerfinished a .byte 0x0 + \a @@ -514,7 +514,7 @@ .byte 0xa0 + \a .endm -.ifdef VERSION_EU +#ifdef VERSION_EU .macro chan_setnotepriority a .byte 0xe9 @@ -530,7 +530,7 @@ .byte \a .endm -.else +#else .macro chan_setnotepriority a .byte 0x60 + \a @@ -545,11 +545,11 @@ .byte \a .endm -.endif +#endif -.endif +#endif -# layer commands +// layer commands .macro layer_note0 a, b, c, d .byte 0x0 + \a @@ -659,7 +659,7 @@ .byte \c .endm -# envelope commands +// envelope commands .macro envelope_disable a .byte 0x0, 0x0 @@ -686,7 +686,7 @@ .byte \b >> 8, \b & 0xff .endm -# other commands +// other commands .macro var_long x .byte (0x80 | (\x & 0x7f00) >> 8), (\x & 0xff) diff --git a/include/sm64.h b/include/sm64.h index 34bfec22..88446c92 100644 --- a/include/sm64.h +++ b/include/sm64.h @@ -59,7 +59,7 @@ #define INPUT_A_DOWN 0x0080 #define INPUT_IN_POISON_GAS 0x0100 #define INPUT_IN_WATER 0x0200 -#define INPUT_UNKNOWN_10 0x0400 +#define INPUT_STOMPED 0x0400 #define INPUT_INTERACT_OBJ_GRABBABLE 0x0800 #define INPUT_UNKNOWN_12 0x1000 #define INPUT_B_PRESSED 0x2000 diff --git a/include/sounds.h b/include/sounds.h index a734a103..71709c90 100644 --- a/include/sounds.h +++ b/include/sounds.h @@ -291,18 +291,23 @@ #define SOUND_GENERAL_PLATFORM /* 0x302D8080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x2D, 0x80, SOUND_DISCRETE) // unverified #define SOUND_GENERAL_DONUT_PLATFORM_EXPLOSION /* 0x302E2080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x2E, 0x20, SOUND_DISCRETE) #define SOUND_GENERAL_BOWSER_BOMB_EXPLOSION /* 0x312F0080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x2F, 0x00, SOUND_NO_VOLUME_LOSS | SOUND_DISCRETE) +#if defined(VERSION_JP) #define SOUND_GENERAL_COIN_SPURT /* 0x30300080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x30, 0x00, SOUND_DISCRETE) // unverified -#define SOUND_GENERAL_COIN_SPURT_2 /* 0x38300080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x30, 0x00, SOUND_CONSTANT_FREQUENCY | SOUND_DISCRETE) // unverified -#define SOUND_GENERAL_COIN_SPURT_EU /* 0x38302080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x30, 0x20, SOUND_CONSTANT_FREQUENCY | SOUND_DISCRETE) // unverified - +#elif defined(VERSION_US) +#define SOUND_GENERAL_COIN_SPURT /* 0x38300080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x30, 0x00, SOUND_CONSTANT_FREQUENCY | SOUND_DISCRETE) // unverified +#else +#define SOUND_GENERAL_COIN_SPURT /* 0x38302080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x30, 0x20, SOUND_CONSTANT_FREQUENCY | SOUND_DISCRETE) // unverified +#endif #define SOUND_GENERAL_EXPLOSION6 /* 0x30310000 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x31, 0x00, 0) // unverified, unused #define SOUND_GENERAL_UNK32 /* 0x30320000 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x32, 0x00, 0) // unverified, unused #define SOUND_GENERAL_BOAT_TILT1 /* 0x30344080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x34, 0x40, SOUND_DISCRETE) // unverified #define SOUND_GENERAL_BOAT_TILT2 /* 0x30354080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x35, 0x40, SOUND_DISCRETE) // unverified #define SOUND_GENERAL_COIN_DROP /* 0x30364080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x36, 0x40, SOUND_DISCRETE) // unverified -#define SOUND_GENERAL_UNKNOWN3_LOWPRIO /* 0x30370080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x37, 0x00, SOUND_DISCRETE) // unverified -#define SOUND_GENERAL_UNKNOWN3 /* 0x30378080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x37, 0x80, SOUND_DISCRETE) // unverified -#define SOUND_GENERAL_UNKNOWN3_2 /* 0x38378080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x37, 0x80, SOUND_CONSTANT_FREQUENCY | SOUND_DISCRETE) // unverified +#ifdef VERSION_JP +#define SOUND_GENERAL_UNKNOWN3 /* 0x30370080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x37, 0x00, SOUND_DISCRETE) // unverified +#else +#define SOUND_GENERAL_UNKNOWN3 /* 0x38378080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x37, 0x80, SOUND_CONSTANT_FREQUENCY | SOUND_DISCRETE) // unverified +#endif #define SOUND_GENERAL_PENDULUM_SWING /* 0x30380080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x38, 0x00, SOUND_DISCRETE) #define SOUND_GENERAL_CHAIN_CHOMP1 /* 0x30390080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x39, 0x00, SOUND_DISCRETE) // unverified #define SOUND_GENERAL_CHAIN_CHOMP2 /* 0x303A0080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x3A, 0x00, SOUND_DISCRETE) // unverified @@ -319,8 +324,11 @@ #define SOUND_GENERAL_QUIET_POUND2 /* 0x30430080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x43, 0x00, SOUND_DISCRETE) // unverified #define SOUND_GENERAL_BIG_POUND /* 0x30440080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x44, 0x00, SOUND_DISCRETE) // unverified #define SOUND_GENERAL_UNK45 /* 0x30450080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x45, 0x00, SOUND_DISCRETE) // unverified -#define SOUND_GENERAL_UNK46_LOWPRIO /* 0x30460080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x46, 0x00, SOUND_DISCRETE) // unverified +#ifdef VERSION_JP +#define SOUND_GENERAL_UNK46 /* 0x30460080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x46, 0x00, SOUND_DISCRETE) // unverified +#else #define SOUND_GENERAL_UNK46 /* 0x30468080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x46, 0x80, SOUND_DISCRETE) // unverified +#endif #define SOUND_GENERAL_CANNON_UP /* 0x30478080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x47, 0x80, SOUND_DISCRETE) // unverified #define SOUND_GENERAL_GRINDEL_ROLL /* 0x30480080 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x48, 0x00, SOUND_DISCRETE) // unverified #define SOUND_GENERAL_EXPLOSION7 /* 0x30490000 */ SOUND_ARG_LOAD(SOUND_BANK_GENERAL, 0x49, 0x00, 0) // unverified, unused @@ -386,7 +394,7 @@ #define SOUND_ENV_UNK12 /* 0x40120000 */ SOUND_ARG_LOAD(SOUND_BANK_ENV, 0x12, 0x00, 0) // unverified, unused #define SOUND_ENV_SLIDING /* 0x40130000 */ SOUND_ARG_LOAD(SOUND_BANK_ENV, 0x13, 0x00, 0) // unverified #define SOUND_ENV_STAR /* 0x40140010 */ SOUND_ARG_LOAD(SOUND_BANK_ENV, 0x14, 0x00, SOUND_LOWER_BACKGROUND_MUSIC) // unverified -#define SOUND_ENV_UNKNOWN4 /* 0x41150000 */ SOUND_ARG_LOAD(SOUND_BANK_ENV, 0x15, 0x00, SOUND_NO_VOLUME_LOSS) // unverified +#define SOUND_ENV_MOVING_BIG_PLATFORM /* 0x41150000 */ SOUND_ARG_LOAD(SOUND_BANK_ENV, 0x15, 0x00, SOUND_NO_VOLUME_LOSS) // unverified #define SOUND_ENV_WATER_DRAIN /* 0x41160000 */ SOUND_ARG_LOAD(SOUND_BANK_ENV, 0x16, 0x00, SOUND_NO_VOLUME_LOSS) // unverified #define SOUND_ENV_METAL_BOX_PUSH /* 0x40178000 */ SOUND_ARG_LOAD(SOUND_BANK_ENV, 0x17, 0x80, 0) // unverified #define SOUND_ENV_SINK_QUICKSAND /* 0x40188000 */ SOUND_ARG_LOAD(SOUND_BANK_ENV, 0x18, 0x80, 0) // unverified @@ -412,7 +420,7 @@ #define SOUND_OBJ_MRI_DEATH /* 0x50140080 */ SOUND_ARG_LOAD(SOUND_BANK_OBJ, 0x14, 0x00, SOUND_DISCRETE) #define SOUND_OBJ_POUNDING1 /* 0x50155080 */ SOUND_ARG_LOAD(SOUND_BANK_OBJ, 0x15, 0x50, SOUND_DISCRETE) // unverified #define SOUND_OBJ_POUNDING1_HIGHPRIO /* 0x50158080 */ SOUND_ARG_LOAD(SOUND_BANK_OBJ, 0x15, 0x80, SOUND_DISCRETE) // unverified -#define SOUND_OBJ_WHOMP_LOWPRIO /* 0x50166080 */ SOUND_ARG_LOAD(SOUND_BANK_OBJ, 0x16, 0x60, SOUND_DISCRETE) +#define SOUND_OBJ_WHOMP /* 0x50166080 */ SOUND_ARG_LOAD(SOUND_BANK_OBJ, 0x16, 0x60, SOUND_DISCRETE) #define SOUND_OBJ_KING_BOBOMB /* 0x50168080 */ SOUND_ARG_LOAD(SOUND_BANK_OBJ, 0x16, 0x80, SOUND_DISCRETE) #define SOUND_OBJ_BULLY_METAL /* 0x50178080 */ SOUND_ARG_LOAD(SOUND_BANK_OBJ, 0x17, 0x80, SOUND_DISCRETE) // unverified #define SOUND_OBJ_BULLY_EXPLODE /* 0x5018A080 */ SOUND_ARG_LOAD(SOUND_BANK_OBJ, 0x18, 0xA0, SOUND_DISCRETE) // unverified @@ -516,8 +524,11 @@ /* Menu Sound Effects */ #define SOUND_MENU_CHANGE_SELECT /* 0x7000F880 */ SOUND_ARG_LOAD(SOUND_BANK_MENU, 0x00, 0xF8, SOUND_DISCRETE) #define SOUND_MENU_REVERSE_PAUSE /* 0x70010000 */ SOUND_ARG_LOAD(SOUND_BANK_MENU, 0x01, 0x00, 0) // unverified, unused +#ifdef VERSION_JP #define SOUND_MENU_PAUSE /* 0x7002F080 */ SOUND_ARG_LOAD(SOUND_BANK_MENU, 0x02, 0xF0, SOUND_DISCRETE) -#define SOUND_MENU_PAUSE_HIGHPRIO /* 0x7002FF80 */ SOUND_ARG_LOAD(SOUND_BANK_MENU, 0x02, 0xFF, SOUND_DISCRETE) +#else +#define SOUND_MENU_PAUSE /* 0x7002FF80 */ SOUND_ARG_LOAD(SOUND_BANK_MENU, 0x02, 0xFF, SOUND_DISCRETE) +#endif #define SOUND_MENU_PAUSE_2 /* 0x7003FF80 */ SOUND_ARG_LOAD(SOUND_BANK_MENU, 0x03, 0xFF, SOUND_DISCRETE) #define SOUND_MENU_MESSAGE_APPEAR /* 0x70040080 */ SOUND_ARG_LOAD(SOUND_BANK_MENU, 0x04, 0x00, SOUND_DISCRETE) #define SOUND_MENU_MESSAGE_DISAPPEAR /* 0x70050080 */ SOUND_ARG_LOAD(SOUND_BANK_MENU, 0x05, 0x00, SOUND_DISCRETE) diff --git a/include/special_presets.h b/include/special_presets.h index e16ac6a8..9e2e1853 100644 --- a/include/special_presets.h +++ b/include/special_presets.h @@ -12,8 +12,7 @@ #define SPTYPE_UNKNOWN 3 // object is 14-bytes long, has 3 extra shorts that get converted to floats. #define SPTYPE_DEF_PARAM_AND_YROT 4 // object is 10-bytes long, has y-rotation and uses the default param -struct SpecialPreset -{ +struct SpecialPreset { /*00*/ u8 preset_id; /*01*/ u8 type; // Determines whether object is 8, 10, 12 or 14 bytes long. /*02*/ u8 defParam; // Default parameter, only used when type is SPTYPE_DEF_PARAM_AND_YROT @@ -23,8 +22,7 @@ struct SpecialPreset // Some Models ID's are missing their names because they are probably unused -static struct SpecialPreset SpecialObjectPresets[] = -{ +static struct SpecialPreset SpecialObjectPresets[] = { {0x00, SPTYPE_YROT_NO_PARAMS , 0x00, MODEL_NONE, NULL}, {0x01, SPTYPE_NO_YROT_OR_PARAMS , 0x00, MODEL_YELLOW_COIN, bhvYellowCoin}, {0x02, SPTYPE_NO_YROT_OR_PARAMS , 0x00, MODEL_YELLOW_COIN, bhvYellowCoin}, diff --git a/include/surface_terrains.h b/include/surface_terrains.h index 669a0ac2..f555d5b1 100644 --- a/include/surface_terrains.h +++ b/include/surface_terrains.h @@ -43,13 +43,13 @@ #define SURFACE_HARD_VERY_SLIPPERY 0x0036 // Hard and very slippery (Always has fall damage) #define SURFACE_HARD_NOT_SLIPPERY 0x0037 // Hard and Non-slippery (Always has fall damage) #define SURFACE_VERTICAL_WIND 0x0038 // Death at bottom with vertical wind -#define SURFACE_BOSS_FIGHT_CAMERA 0x0065 // Wide camera for BOB and WF bosses +#define SURFACE_BOSS_FIGHT_CAMERA 0x0065 // Wide camera for BoB and WF bosses #define SURFACE_CAMERA_FREE_ROAM 0x0066 // Free roam camera for THI and TTC #define SURFACE_THI3_WALLKICK 0x0068 // Surface where there's a wall kick section in THI 3rd area, has no action defined #define SURFACE_CAMERA_8_DIR 0x0069 // Surface that enables far camera for platforms, used in THI #define SURFACE_CAMERA_MIDDLE 0x006E // Surface camera that returns to the middle, used on the 4 pillars of SSL #define SURFACE_CAMERA_ROTATE_RIGHT 0x006F // Surface camera that rotates to the right (Bowser 1 & THI) -#define SURFACE_CAMERA_ROTATE_LEFT 0x0070 // Surface camera that rotates to the left (BOB & TTM) +#define SURFACE_CAMERA_ROTATE_LEFT 0x0070 // Surface camera that rotates to the left (BoB & TTM) #define SURFACE_CAMERA_BOUNDARY 0x0072 // Intangible Area, only used to restrict camera movement #define SURFACE_NOISE_VERY_SLIPPERY_73 0x0073 // Very slippery floor with noise, unused #define SURFACE_NOISE_VERY_SLIPPERY_74 0x0074 // Very slippery floor with noise, unused @@ -60,9 +60,9 @@ #define SURFACE_NO_CAM_COL_SLIPPERY 0x0079 // Surface with no cam collision flag, slippery with noise (CCM, PSS and TTM slides) #define SURFACE_SWITCH 0x007A // Surface with no cam collision flag, non-slippery with noise, used by switches and Dorrie #define SURFACE_VANISH_CAP_WALLS 0x007B // Vanish cap walls, pass through them with Vanish Cap -#define SURFACE_PAINTING_WOBBLE_A6 0x00A6 // Painting wobble (BOB Left) -#define SURFACE_PAINTING_WOBBLE_A7 0x00A7 // Painting wobble (BOB Middle) -#define SURFACE_PAINTING_WOBBLE_A8 0x00A8 // Painting wobble (BOB Right) +#define SURFACE_PAINTING_WOBBLE_A6 0x00A6 // Painting wobble (BoB Left) +#define SURFACE_PAINTING_WOBBLE_A7 0x00A7 // Painting wobble (BoB Middle) +#define SURFACE_PAINTING_WOBBLE_A8 0x00A8 // Painting wobble (BoB Right) #define SURFACE_PAINTING_WOBBLE_A9 0x00A9 // Painting wobble (CCM Left) #define SURFACE_PAINTING_WOBBLE_AA 0x00AA // Painting wobble (CCM Middle) #define SURFACE_PAINTING_WOBBLE_AB 0x00AB // Painting wobble (CCM Right) @@ -105,9 +105,9 @@ #define SURFACE_PAINTING_WOBBLE_D0 0x00D0 // Painting wobble (HMC & COTMC - Left), makes the painting wobble if touched #define SURFACE_PAINTING_WOBBLE_D1 0x00D1 // Painting wobble (Unused, HMC & COTMC - Middle) #define SURFACE_PAINTING_WOBBLE_D2 0x00D2 // Painting wobble (Unused, HMC & COTMC - Right) -#define SURFACE_PAINTING_WARP_D3 0x00D3 // Painting warp (BOB Left) -#define SURFACE_PAINTING_WARP_D4 0x00D4 // Painting warp (BOB Middle) -#define SURFACE_PAINTING_WARP_D5 0x00D5 // Painting warp (BOB Right) +#define SURFACE_PAINTING_WARP_D3 0x00D3 // Painting warp (BoB Left) +#define SURFACE_PAINTING_WARP_D4 0x00D4 // Painting warp (BoB Middle) +#define SURFACE_PAINTING_WARP_D5 0x00D5 // Painting warp (BoB Right) #define SURFACE_PAINTING_WARP_D6 0x00D6 // Painting warp (CCM Left) #define SURFACE_PAINTING_WARP_D7 0x00D7 // Painting warp (CCM Middle) #define SURFACE_PAINTING_WARP_D8 0x00D8 // Painting warp (CCM Right) diff --git a/include/types.h b/include/types.h index c6e801e1..150de575 100644 --- a/include/types.h +++ b/include/types.h @@ -6,6 +6,7 @@ #include #include "macros.h" +#include "config.h" // Certain functions are marked as having return values, but do not @@ -19,8 +20,7 @@ #endif -struct Controller -{ +struct Controller { /*0x00*/ s16 rawStickX; // /*0x02*/ s16 rawStickY; // /*0x04*/ float stickX; // [-64, 64] positive is right @@ -30,8 +30,8 @@ struct Controller /*0x12*/ u16 buttonPressed; /*0x14*/ OSContStatus *statusData; /*0x18*/ OSContPad *controllerData; -#ifdef VERSION_SH - /*0x1C*/ int port; +#if ENABLE_RUMBLE + /*0x1C*/ s32 port; #endif }; @@ -62,16 +62,14 @@ enum SpTaskState { SPTASK_STATE_FINISHED_DP }; -struct SPTask -{ +struct SPTask { /*0x00*/ OSTask task; /*0x40*/ OSMesgQueue *msgqueue; /*0x44*/ OSMesg msg; /*0x48*/ enum SpTaskState state; }; // size = 0x4C, align = 0x8 -struct VblankHandler -{ +struct VblankHandler { OSMesgQueue *queue; OSMesg msg; }; @@ -99,8 +97,7 @@ struct Animation { #define ANIMINDEX_NUMPARTS(animindex) (sizeof(animindex) / sizeof(u16) / 6 - 1) -struct GraphNode -{ +struct GraphNode { /*0x00*/ s16 type; // structure type /*0x02*/ s16 flags; // hi = drawing layer, lo = rendering modes /*0x04*/ struct GraphNode *prev; @@ -109,8 +106,7 @@ struct GraphNode /*0x10*/ struct GraphNode *children; }; -struct AnimInfo -{ +struct AnimInfo { /*0x00 0x38*/ s16 animID; /*0x02 0x3A*/ s16 animYTrans; /*0x04 0x3C*/ struct Animation *curAnim; @@ -120,8 +116,7 @@ struct AnimInfo /*0x10 0x48*/ s32 animAccel; }; -struct GraphNodeObject -{ +struct GraphNodeObject { /*0x00*/ struct GraphNode node; /*0x14*/ struct GraphNode *sharedChild; /*0x18*/ s8 areaIndex; @@ -135,8 +130,7 @@ struct GraphNodeObject /*0x54*/ Vec3f cameraToObject; }; -struct ObjectNode -{ +struct ObjectNode { struct GraphNodeObject gfx; struct ObjectNode *next; struct ObjectNode *prev; @@ -145,8 +139,7 @@ struct ObjectNode // NOTE: Since ObjectNode is the first member of Object, it is difficult to determine // whether some of these pointers point to ObjectNode or Object. -struct Object -{ +struct Object { /*0x000*/ struct ObjectNode header; /*0x068*/ struct Object *parentObj; /*0x06C*/ struct Object *prevObj; @@ -155,8 +148,7 @@ struct Object /*0x076*/ s16 numCollidedObjs; /*0x078*/ struct Object *collidedObjs[4]; /*0x088*/ - union - { + union { // Object fields. See object_fields.h. u32 asU32[0x50]; s32 asS32[0x50]; @@ -206,8 +198,7 @@ struct Object /*0x25C*/ void *respawnInfo; }; -struct ObjectHitbox -{ +struct ObjectHitbox { /*0x00*/ u32 interactType; /*0x04*/ u8 downOffset; /*0x05*/ s8 damageOrCoinValue; @@ -219,14 +210,12 @@ struct ObjectHitbox /*0x0E*/ s16 hurtboxHeight; }; -struct Waypoint -{ +struct Waypoint { s16 flags; Vec3s pos; }; -struct Surface -{ +struct Surface { /*0x00*/ s16 type; /*0x02*/ s16 force; /*0x04*/ s8 flags; @@ -245,8 +234,7 @@ struct Surface /*0x2C*/ struct Object *object; }; -struct MarioBodyState -{ +struct MarioBodyState { /*0x00*/ u32 action; /*0x04*/ s8 capState; /// see MarioCapGSCId /*0x05*/ s8 eyeState; @@ -258,32 +246,10 @@ struct MarioBodyState /*0x0C*/ Vec3s torsoAngle; /*0x12*/ Vec3s headAngle; /*0x18*/ Vec3f heldObjLastPosition; /// also known as HOLP - u8 padding[4]; + u8 filler[4]; }; -struct OffsetSizePair -{ - u32 offset; - u32 size; -}; - -struct MarioAnimDmaRelatedThing -{ - u32 count; - u8 *srcAddr; - struct OffsetSizePair anim[1]; // dynamic size -}; - -struct MarioAnimation -{ - struct MarioAnimDmaRelatedThing *animDmaTable; - u8 *currentAnimAddr; - struct Animation *targetAnim; - u8 padding[4]; -}; - -struct MarioState -{ +struct MarioState { /*0x00*/ u16 unk00; /*0x02*/ u16 input; /*0x04*/ u32 flags; @@ -327,7 +293,7 @@ struct MarioState /*0x94*/ struct PlayerCameraState *statusForCamera; /*0x98*/ struct MarioBodyState *marioBodyState; /*0x9C*/ struct Controller *controller; - /*0xA0*/ struct MarioAnimation *animation; + /*0xA0*/ struct DmaHandlerList *animList; /*0xA4*/ u32 collidedObjInteractTypes; /*0xA8*/ s16 numCoins; /*0xAA*/ s16 numStars; diff --git a/levels/bbh/areas/1/collision.inc.c b/levels/bbh/areas/1/collision.inc.c index e17311a8..1abb9baf 100644 --- a/levels/bbh/areas/1/collision.inc.c +++ b/levels/bbh/areas/1/collision.inc.c @@ -3742,7 +3742,7 @@ const Collision bbh_seg7_collision_level[] = { COL_TRI(12, 14, 15), COL_TRI_STOP(), COL_SPECIAL_INIT(26), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 1434, -204, 4710, /*yaw*/ 128), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 1434, -204, 4710, /*yaw*/ 128), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_haunted_door, /*pos*/ 0, -2457, 2099, /*yaw*/ 128), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_haunted_door, /*pos*/ -1996, -2457, 205, /*yaw*/ 192), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_haunted_door, /*pos*/ 1587, -2457, 205, /*yaw*/ 64), diff --git a/levels/bitdw/areas/1/collision.inc.c b/levels/bitdw/areas/1/collision.inc.c index 21eb923f..1d4de531 100644 --- a/levels/bitdw/areas/1/collision.inc.c +++ b/levels/bitdw/areas/1/collision.inc.c @@ -1324,7 +1324,7 @@ const Collision bitdw_seg7_collision_level[] = { COL_TRI(485, 486, 489), COL_TRI_STOP(), COL_SPECIAL_INIT(23), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -7443, -3153, 3886, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -7443, -3153, 3886, /*yaw*/ 64), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ -6368, -3972, 3883, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_04, /*pos*/ -3245, -3358, 3893, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_05, /*pos*/ -2405, -1228, 1740, /*yaw*/ 0), diff --git a/levels/bitfs/areas/1/collision.inc.c b/levels/bitfs/areas/1/collision.inc.c index 0307e25c..e88d3d17 100644 --- a/levels/bitfs/areas/1/collision.inc.c +++ b/levels/bitfs/areas/1/collision.inc.c @@ -2053,7 +2053,7 @@ const Collision bitfs_seg7_collision_level[] = { COL_TRI(801, 802, 509), COL_TRI_STOP(), COL_SPECIAL_INIT(24), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -7577, -2764, 0, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -7577, -2764, 0, /*yaw*/ 64), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ -5938, -3071, 0, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_04, /*pos*/ -5488, -1535, 41, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_04, /*pos*/ 4342, 1741, 41, /*yaw*/ 0), diff --git a/levels/bits/areas/1/collision.inc.c b/levels/bits/areas/1/collision.inc.c index 130a24fe..af2e6c24 100644 --- a/levels/bits/areas/1/collision.inc.c +++ b/levels/bits/areas/1/collision.inc.c @@ -2400,7 +2400,7 @@ const Collision bits_seg7_collision_level[] = { COL_TRI(135, 216, 214), COL_TRI_STOP(), COL_SPECIAL_INIT(22), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -7039, -4812, 4, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -7039, -4812, 4, /*yaw*/ 64), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ -4505, -5119, 0, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_04, /*pos*/ -2291, -2073, -762, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_05, /*pos*/ 3891, -3276, -705, /*yaw*/ 0), diff --git a/levels/bowser_1/areas/1/collision.inc.c b/levels/bowser_1/areas/1/collision.inc.c index 7593a37b..e2a25a55 100644 --- a/levels/bowser_1/areas/1/collision.inc.c +++ b/levels/bowser_1/areas/1/collision.inc.c @@ -77,7 +77,7 @@ const Collision bowser_1_seg7_collision_level[] = { COL_TRI(25, 27, 28), COL_TRI_STOP(), COL_SPECIAL_INIT(22), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, 1843, 0, /*yaw*/ 1423), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, 1843, 0, /*yaw*/ 1423), // unused, probably an early way to set initial position SPECIAL_OBJECT(/*preset*/ special_mine, /*pos*/ 2949, 589, 0), SPECIAL_OBJECT(/*preset*/ special_mine, /*pos*/ 0, 589, -2949), SPECIAL_OBJECT(/*preset*/ special_mine, /*pos*/ 0, 589, 2949), diff --git a/levels/bowser_2/areas/1/collision.inc.c b/levels/bowser_2/areas/1/collision.inc.c index 6853832e..628b171e 100644 --- a/levels/bowser_2/areas/1/collision.inc.c +++ b/levels/bowser_2/areas/1/collision.inc.c @@ -19,7 +19,7 @@ const Collision bowser_2_seg7_collision_lava[] = { COL_TRI(0, 5, 7), COL_TRI_STOP(), COL_SPECIAL_INIT(2), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, 1229, 0, /*yaw*/ 128), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, 1229, 0, /*yaw*/ 128), // unused, probably an early way to set initial position SPECIAL_OBJECT(/*preset*/ special_bowser, /*pos*/ -8, 1229, -1418), COL_END(), }; diff --git a/levels/bowser_3/areas/1/collision.inc.c b/levels/bowser_3/areas/1/collision.inc.c index 20b0ef3a..68d64090 100644 --- a/levels/bowser_3/areas/1/collision.inc.c +++ b/levels/bowser_3/areas/1/collision.inc.c @@ -68,7 +68,7 @@ const Collision bowser_3_seg7_collision_level[] = { COL_TRI(0, 2, 3), COL_TRI_STOP(), COL_SPECIAL_INIT(7), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, 307, 0, /*yaw*/ 128), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, 307, 0, /*yaw*/ 128), // unused, probably an early way to set initial position SPECIAL_OBJECT(/*preset*/ special_bowser, /*pos*/ 13, 307, -1024), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ -3362, -204, 1121, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ 0, -204, 3584, /*yaw*/ 0), diff --git a/levels/castle_courtyard/areas/1/collision.inc.c b/levels/castle_courtyard/areas/1/collision.inc.c index 14ea0d13..8d1f2bd3 100644 --- a/levels/castle_courtyard/areas/1/collision.inc.c +++ b/levels/castle_courtyard/areas/1/collision.inc.c @@ -847,7 +847,7 @@ const Collision castle_courtyard_seg7_collision[] = { COL_TRI(136, 45, 133), COL_TRI_STOP(), COL_SPECIAL_INIT(19), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 15, 0, 202, /*yaw*/ 128), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 15, 0, 202, /*yaw*/ 128), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ 0, 2048, 2662, /*yaw*/ 0), SPECIAL_OBJECT(/*preset*/ special_spiky_tree, /*pos*/ 2272, -214, -1432), SPECIAL_OBJECT(/*preset*/ special_spiky_tree, /*pos*/ 818, 10, 203), diff --git a/levels/castle_inside/areas/1/collision.inc.c b/levels/castle_inside/areas/1/collision.inc.c index 57455efc..a081bccf 100644 --- a/levels/castle_inside/areas/1/collision.inc.c +++ b/levels/castle_inside/areas/1/collision.inc.c @@ -3741,7 +3741,7 @@ const Collision inside_castle_seg7_area_1_collision[] = { COL_TRI(77, 79, 80), COL_TRI_STOP(), COL_SPECIAL_INIT(11), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -1023, 0, 1152, /*yaw*/ 128), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -1023, 0, 1152, /*yaw*/ 128), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_wooden_door, /*pos*/ -271, 0, -824, /*yaw*/ 32), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_wooden_door, /*pos*/ -1775, 0, -824, /*yaw*/ 224), SPECIAL_OBJECT_WITH_YAW_AND_PARAM(/*preset*/ special_castle_door_warp, /*pos*/ -1100, 0, 2202, /*yaw*/ 0, /*behParam2*/ 0), diff --git a/levels/ccm/areas/1/collision.inc.c b/levels/ccm/areas/1/collision.inc.c index 33167b31..45068372 100644 --- a/levels/ccm/areas/1/collision.inc.c +++ b/levels/ccm/areas/1/collision.inc.c @@ -1747,7 +1747,7 @@ const Collision ccm_seg7_area_1_collision[] = { COL_TRI(336, 609, 616), COL_TRI_STOP(), COL_SPECIAL_INIT(21), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -1512, 2560, -2305, /*yaw*/ 100), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -1512, 2560, -2305, /*yaw*/ 100), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ -409, 2765, -1637, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_04, /*pos*/ 2355, -4095, 4096, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_05, /*pos*/ -4210, -1446, 1874, /*yaw*/ 0), diff --git a/levels/ccm/areas/2/collision.inc.c b/levels/ccm/areas/2/collision.inc.c index df408822..d75bdf58 100644 --- a/levels/ccm/areas/2/collision.inc.c +++ b/levels/ccm/areas/2/collision.inc.c @@ -1873,7 +1873,7 @@ const Collision ccm_seg7_area_2_collision[] = { COL_TRI(19, 23, 24), COL_TRI_STOP(), COL_SPECIAL_INIT(2), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -5836, 7465, -6143, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -5836, 7465, -6143, /*yaw*/ 64), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW_AND_PARAM(/*preset*/ special_wooden_door_warp, /*pos*/ -7628, -5836, -6988, /*yaw*/ 64, /*behParam2*/ 20), COL_END(), }; diff --git a/levels/cotmc/areas/1/collision.inc.c b/levels/cotmc/areas/1/collision.inc.c index c9c1c7ac..b4f27890 100644 --- a/levels/cotmc/areas/1/collision.inc.c +++ b/levels/cotmc/areas/1/collision.inc.c @@ -990,7 +990,7 @@ const Collision cotmc_seg7_collision_level[] = { COL_TRI(208, 206, 207), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -4185, 20, -47, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -4185, 20, -47, /*yaw*/ 64), // unused, probably an early way to set initial position COL_WATER_BOX_INIT(1), COL_WATER_BOX(0, -1535, -7679, 1536, 3389, 0), COL_END(), diff --git a/levels/hmc/areas/1/collision.inc.c b/levels/hmc/areas/1/collision.inc.c index 341486c1..4fe8d829 100644 --- a/levels/hmc/areas/1/collision.inc.c +++ b/levels/hmc/areas/1/collision.inc.c @@ -3599,7 +3599,7 @@ const Collision hmc_seg7_collision_level[] = { COL_TRI(55, 58, 56), COL_TRI_STOP(), COL_SPECIAL_INIT(13), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -7601, 2253, 7630, /*yaw*/ 96), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -7601, 2253, 7630, /*yaw*/ 96), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_wooden_door, /*pos*/ 922, -4689, 2330, /*yaw*/ 192), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_wooden_door, /*pos*/ -3586, 1536, 647, /*yaw*/ 19), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_wooden_door, /*pos*/ 5911, -204, 870, /*yaw*/ 0), diff --git a/levels/intro/script.c b/levels/intro/script.c index a130cc04..04b8fc4c 100644 --- a/levels/intro/script.c +++ b/levels/intro/script.c @@ -8,7 +8,7 @@ #include "game/area.h" #include "game/level_update.h" -#include "menu/level_select_menu.h" +#include "menu/title_screen.h" #include "levels/scripts.h" #include "levels/menu/header.h" @@ -33,7 +33,7 @@ const LevelScript level_intro_splash_screen[] = { // Start animation LOAD_AREA(/*area*/ 1), - CALL(/*arg*/ 0, /*func*/ lvl_intro_update), + CALL(/*arg*/ LVL_INTRO_PLAY_ITS_A_ME_MARIO, /*func*/ lvl_intro_update), SLEEP(/*frames*/ 75), TRANSITION(/*transType*/ WARP_TRANSITION_FADE_INTO_COLOR, /*time*/ 16, /*color*/ 0x00, 0x00, 0x00), SLEEP(/*frames*/ 16), @@ -59,10 +59,10 @@ const LevelScript level_intro_mario_head_regular[] = { SLEEP(/*frames*/ 2), BLACKOUT(/*active*/ FALSE), LOAD_AREA(/*area*/ 1), - SET_MENU_MUSIC(/*seq*/ 0x0002), + SET_MENU_MUSIC(/*seq*/ SEQ_MENU_TITLE_SCREEN), TRANSITION(/*transType*/ WARP_TRANSITION_FADE_FROM_STAR, /*time*/ 20, /*color*/ 0x00, 0x00, 0x00), SLEEP(/*frames*/ 20), - CALL_LOOP(/*arg*/ 1, /*func*/ lvl_intro_update), + CALL_LOOP(/*arg*/ LVL_INTRO_REGULAR, /*func*/ lvl_intro_update), JUMP_IF(/*op*/ OP_EQ, /*arg*/ 100, script_intro_L1), JUMP_IF(/*op*/ OP_EQ, /*arg*/ 101, script_intro_L2), JUMP(script_intro_L4), @@ -84,10 +84,10 @@ const LevelScript level_intro_mario_head_dizzy[] = { SLEEP(/*frames*/ 2), BLACKOUT(/*active*/ FALSE), LOAD_AREA(/*area*/ 1), - SET_MENU_MUSIC(/*seq*/ 0x0082), + SET_MENU_MUSIC(/*seq*/ SEQ_MENU_GAME_OVER), TRANSITION(/*transType*/ WARP_TRANSITION_FADE_FROM_STAR, /*time*/ 20, /*color*/ 0x00, 0x00, 0x00), SLEEP(/*frames*/ 20), - CALL_LOOP(/*arg*/ 2, /*func*/ lvl_intro_update), + CALL_LOOP(/*arg*/ LVL_INTRO_GAME_OVER, /*func*/ lvl_intro_update), JUMP_IF(/*op*/ OP_EQ, /*arg*/ 100, script_intro_L1), JUMP_IF(/*op*/ OP_EQ, /*arg*/ 101, script_intro_L2), JUMP(script_intro_L4), @@ -106,10 +106,10 @@ const LevelScript level_intro_entry_4[] = { FREE_LEVEL_POOL(), LOAD_AREA(/*area*/ 1), - SET_MENU_MUSIC(/*seq*/ 0x0002), + SET_MENU_MUSIC(/*seq*/ SEQ_MENU_TITLE_SCREEN), TRANSITION(/*transType*/ WARP_TRANSITION_FADE_FROM_COLOR, /*time*/ 16, /*color*/ 0xFF, 0xFF, 0xFF), SLEEP(/*frames*/ 16), - CALL_LOOP(/*arg*/ 3, /*func*/ lvl_intro_update), + CALL_LOOP(/*arg*/ LVL_INTRO_LEVEL_SELECT, /*func*/ lvl_intro_update), JUMP_IF(/*op*/ OP_EQ, /*arg*/ -1, script_intro_L5), JUMP(script_intro_L3), }; diff --git a/levels/jrb/areas/1/collision.inc.c b/levels/jrb/areas/1/collision.inc.c index f4a1c8a4..cb0eba6d 100644 --- a/levels/jrb/areas/1/collision.inc.c +++ b/levels/jrb/areas/1/collision.inc.c @@ -872,7 +872,7 @@ const Collision jrb_seg7_area_1_collision[] = { COL_TRI(7, 5, 0), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -6750, 1126, 1482, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -6750, 1126, 1482, /*yaw*/ 64), // unused, probably an early way to set initial position COL_WATER_BOX_INIT(3), COL_WATER_BOX(0, -6304, -669, 7992, 7814, 1024), COL_WATER_BOX(1, 4433, -4253, 5969, -669, -3016), diff --git a/levels/jrb/areas/1/movtext.inc.c b/levels/jrb/areas/1/movtext.inc.c index 12759f4f..8985f222 100644 --- a/levels/jrb/areas/1/movtext.inc.c +++ b/levels/jrb/areas/1/movtext.inc.c @@ -35,8 +35,8 @@ const struct MovtexQuadCollection jrb_movtex_water[] = { {-1, NULL}, }; -// 0x0700D2E4, appears if you enter the course the first time, then it disappears when you grab the first star -static Movtex jrb_movtex_intial_mist_data[] = { +// 0x0700D2E4, appears if you enter the course the first time, then it disappears when you collect the "Plunder in the Sunken Ship" star +static Movtex jrb_movtex_initial_mist_data[] = { MOV_TEX_INIT_LOAD( 1), MOV_TEX_ROT_SPEED( 20), MOV_TEX_ROT_SCALE( 10), @@ -51,7 +51,7 @@ static Movtex jrb_movtex_intial_mist_data[] = { }; // 0x0700D304 -const struct MovtexQuadCollection jrb_movtex_intial_mist[] = { - {51, jrb_movtex_intial_mist_data}, +const struct MovtexQuadCollection jrb_movtex_initial_mist[] = { + {51, jrb_movtex_initial_mist_data}, {-1, NULL}, }; diff --git a/levels/jrb/areas/2/collision.inc.c b/levels/jrb/areas/2/collision.inc.c index 31d002a0..f91b3e0c 100644 --- a/levels/jrb/areas/2/collision.inc.c +++ b/levels/jrb/areas/2/collision.inc.c @@ -584,7 +584,7 @@ const Collision jrb_seg7_area_2_collision[] = { COL_TRI(29, 79, 80), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 866, 798, -1248, /*yaw*/ 128), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 866, 798, -1248, /*yaw*/ 128), // unused, probably an early way to set initial position COL_WATER_BOX_INIT(1), COL_WATER_BOX(0, -4095, -4095, 4096, 4096, 2765), COL_END(), diff --git a/levels/jrb/areas/2/movtext.inc.c b/levels/jrb/areas/2/movtext.inc.c index 90e466a7..958f9844 100644 --- a/levels/jrb/areas/2/movtext.inc.c +++ b/levels/jrb/areas/2/movtext.inc.c @@ -1,5 +1,5 @@ // 0x0701137C -static Movtex jrb_movtex_sinked_boat_water_data[] = { +static Movtex jrb_movtex_sunken_ship_water_data[] = { MOV_TEX_INIT_LOAD( 1), MOV_TEX_ROT_SPEED( 20), MOV_TEX_ROT_SCALE( 6), @@ -14,7 +14,7 @@ static Movtex jrb_movtex_sinked_boat_water_data[] = { }; // 0x0701139C -const struct MovtexQuadCollection jrb_movtex_sinked_boat_water[] = { - {0, jrb_movtex_sinked_boat_water_data}, +const struct MovtexQuadCollection jrb_movtex_sunken_ship_water[] = { + {0, jrb_movtex_sunken_ship_water_data}, {-1, NULL}, }; diff --git a/levels/jrb/header.h b/levels/jrb/header.h index c6887382..f142c5c0 100644 --- a/levels/jrb/header.h +++ b/levels/jrb/header.h @@ -52,13 +52,13 @@ extern const Collision jrb_seg7_collision_0700D1DC[]; extern const Trajectory jrb_seg7_trajectory_unagi_1[]; extern const Trajectory jrb_seg7_trajectory_unagi_2[]; extern const struct MovtexQuadCollection jrb_movtex_water[]; -extern const struct MovtexQuadCollection jrb_movtex_intial_mist[]; +extern const struct MovtexQuadCollection jrb_movtex_initial_mist[]; extern const Gfx jrb_seg7_dl_0700EF00[]; extern const Gfx jrb_seg7_dl_0700FE48[]; extern const Gfx jrb_seg7_dl_07010548[]; extern const Collision jrb_seg7_area_2_collision[]; extern const MacroObject jrb_seg7_area_2_macro_objs[]; -extern const struct MovtexQuadCollection jrb_movtex_sinked_boat_water[]; +extern const struct MovtexQuadCollection jrb_movtex_sunken_ship_water[]; // script extern const LevelScript level_jrb_entry[]; diff --git a/levels/lll/areas/1/collision.inc.c b/levels/lll/areas/1/collision.inc.c index ce5e107d..10047658 100644 --- a/levels/lll/areas/1/collision.inc.c +++ b/levels/lll/areas/1/collision.inc.c @@ -1376,7 +1376,7 @@ const Collision lll_seg7_area_1_collision[] = { COL_TRI(10, 52, 3), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -3839, 154, 6272, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -3839, 154, 6272, /*yaw*/ 64), // unused, probably an early way to set initial position COL_END(), #else COL_INIT(), @@ -2730,7 +2730,7 @@ const Collision lll_seg7_area_1_collision[] = { COL_TRI(3, 52, 71), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -3839, 154, 6272, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -3839, 154, 6272, /*yaw*/ 64), // unused, probably an early way to set initial position COL_END(), #endif }; diff --git a/levels/lll/areas/2/collision.inc.c b/levels/lll/areas/2/collision.inc.c index 65d5b898..2e747d31 100644 --- a/levels/lll/areas/2/collision.inc.c +++ b/levels/lll/areas/2/collision.inc.c @@ -1549,7 +1549,7 @@ const Collision lll_seg7_area_2_collision[] = { COL_TRI(324, 451, 450), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -955, 103, -1029, /*yaw*/ 84), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -955, 103, -1029, /*yaw*/ 84), // unused, probably an early way to set initial position COL_WATER_BOX_INIT(1), COL_WATER_BOX(10, -3071, -3071, 3072, 3072, 20), COL_END(), diff --git a/levels/menu/script.c b/levels/menu/script.c index f6db65c9..25c31f00 100644 --- a/levels/menu/script.c +++ b/levels/menu/script.c @@ -43,7 +43,7 @@ const LevelScript level_main_menu_entry_1[] = { FREE_LEVEL_POOL(), LOAD_AREA(/*area*/ 1), - SET_MENU_MUSIC(/*seq*/ 0x0021), + SET_MENU_MUSIC(/*seq*/ SEQ_MENU_FILE_SELECT), TRANSITION(/*transType*/ WARP_TRANSITION_FADE_FROM_COLOR, /*time*/ 16, /*color*/ 0xFF, 0xFF, 0xFF), CALL(/*arg*/ 0, /*func*/ lvl_init_menu_values_and_cursor_pos), CALL_LOOP(/*arg*/ 0, /*func*/ lvl_update_obj_and_load_file_selected), diff --git a/levels/rr/areas/1/collision.inc.c b/levels/rr/areas/1/collision.inc.c index aa0a8487..ddd55ec0 100644 --- a/levels/rr/areas/1/collision.inc.c +++ b/levels/rr/areas/1/collision.inc.c @@ -2694,7 +2694,7 @@ const Collision rr_seg7_collision_level[] = { COL_TRI_SPECIAL(31, 46, 45, 0x140), COL_TRI_STOP(), COL_SPECIAL_INIT(23), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 2599, -1833, 2071, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 2599, -1833, 2071, /*yaw*/ 64), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ 1902, -1833, 1063, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_04, /*pos*/ 3803, -1833, 2036, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_05, /*pos*/ -4888, -2550, 5847, /*yaw*/ 0), @@ -5419,7 +5419,7 @@ const Collision rr_seg7_collision_level[] = { COL_TRI_SPECIAL(35, 46, 47, 0x100), COL_TRI_STOP(), COL_SPECIAL_INIT(23), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 2599, -1833, 2071, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 2599, -1833, 2071, /*yaw*/ 64), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ 1902, -1833, 1063, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_04, /*pos*/ 3803, -1833, 2036, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_05, /*pos*/ -4888, -2550, 5847, /*yaw*/ 0), diff --git a/levels/sa/areas/1/collision.inc.c b/levels/sa/areas/1/collision.inc.c index 6d823ab2..c4806fd1 100644 --- a/levels/sa/areas/1/collision.inc.c +++ b/levels/sa/areas/1/collision.inc.c @@ -105,7 +105,7 @@ const Collision sa_seg7_collision[] = { COL_TRI(30, 47, 12), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, -1535, 0, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, -1535, 0, /*yaw*/ 64), // unused, probably an early way to set initial position COL_WATER_BOX_INIT(1), COL_WATER_BOX(0, -3173, -3173, 3174, 3174, 102), COL_END(), diff --git a/levels/scripts.c b/levels/scripts.c index 3067162c..248fb83c 100644 --- a/levels/scripts.c +++ b/levels/scripts.c @@ -171,7 +171,7 @@ static const LevelScript script_exec_ ## folder [] = { \ const LevelScript script_func_global_1[] = { LOAD_MODEL_FROM_GEO(MODEL_BLUE_COIN_SWITCH, blue_coin_switch_geo), - LOAD_MODEL_FROM_GEO(MODEL_AMP, amp_geo), + LOAD_MODEL_FROM_GEO(MODEL_AMP, dAmpGeo), LOAD_MODEL_FROM_GEO(MODEL_PURPLE_SWITCH, purple_switch_geo), LOAD_MODEL_FROM_GEO(MODEL_CHECKERBOARD_PLATFORM, checkerboard_platform_geo), LOAD_MODEL_FROM_GEO(MODEL_BREAKABLE_BOX, breakable_box_geo), @@ -297,7 +297,7 @@ const LevelScript script_func_global_13[] = { LOAD_MODEL_FROM_GEO(MODEL_BOWSER_SMOKE, bowser_impact_smoke_geo), LOAD_MODEL_FROM_GEO(MODEL_BOWSER_FLAMES, bowser_flames_geo), LOAD_MODEL_FROM_GEO(MODEL_BOWSER_WAVE, invisible_bowser_accessory_geo), - LOAD_MODEL_FROM_GEO(MODEL_BOWSER2, bowser2_geo), + LOAD_MODEL_FROM_GEO(MODEL_BOWSER_NO_SHADOW, bowser_geo_no_shadow), RETURN(), }; diff --git a/levels/sl/areas/1/collision.inc.c b/levels/sl/areas/1/collision.inc.c index 8dab56df..b5579698 100644 --- a/levels/sl/areas/1/collision.inc.c +++ b/levels/sl/areas/1/collision.inc.c @@ -1423,7 +1423,7 @@ const Collision sl_seg7_area_1_collision[] = { COL_TRI(510, 327, 321), COL_TRI_STOP(), COL_SPECIAL_INIT(10), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 5541, 1024, 443, /*yaw*/ 192), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 5541, 1024, 443, /*yaw*/ 192), // unused, probably an early way to set initial position SPECIAL_OBJECT(/*preset*/ special_snow_tree, /*pos*/ 5395, 1054, -5443), SPECIAL_OBJECT(/*preset*/ special_snow_tree, /*pos*/ 0, 4864, 0), SPECIAL_OBJECT(/*preset*/ special_snow_tree, /*pos*/ 5666, 1024, -3341), diff --git a/levels/sl/areas/2/collision.inc.c b/levels/sl/areas/2/collision.inc.c index 7b1d55c4..6a0ce64f 100644 --- a/levels/sl/areas/2/collision.inc.c +++ b/levels/sl/areas/2/collision.inc.c @@ -407,7 +407,7 @@ const Collision sl_seg7_area_2_collision[] = { COL_TRI(146, 187, 145), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, 0, 2867, /*yaw*/ 128), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, 0, 2867, /*yaw*/ 128), // unused, probably an early way to set initial position COL_END(), }; diff --git a/levels/ssl/areas/1/collision.inc.c b/levels/ssl/areas/1/collision.inc.c index 80f9c40a..64e77cf6 100644 --- a/levels/ssl/areas/1/collision.inc.c +++ b/levels/ssl/areas/1/collision.inc.c @@ -1554,7 +1554,7 @@ const Collision ssl_seg7_area_1_collision[] = { COL_TRI(482, 483, 484), COL_TRI_STOP(), COL_SPECIAL_INIT(7), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 653, 38, 6566, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 653, 38, 6566, /*yaw*/ 64), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ 5760, 0, 5751, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ -3583, 0, 2935, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ -511, 0, 2935, /*yaw*/ 0), diff --git a/levels/ssl/areas/2/collision.inc.c b/levels/ssl/areas/2/collision.inc.c index a305da02..2a960a73 100644 --- a/levels/ssl/areas/2/collision.inc.c +++ b/levels/ssl/areas/2/collision.inc.c @@ -2655,7 +2655,7 @@ const Collision ssl_seg7_area_2_collision[] = { COL_TRI(359, 420, 419), COL_TRI_STOP(), COL_SPECIAL_INIT(4), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, 0, 6451, /*yaw*/ 128), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 0, 0, 6451, /*yaw*/ 128), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_04, /*pos*/ 1741, -101, 1843, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_04, /*pos*/ 0, -101, 528, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_04, /*pos*/ -1740, -101, 1843, /*yaw*/ 0), diff --git a/levels/thi/areas/1/collision.inc.c b/levels/thi/areas/1/collision.inc.c index 3e1f44f8..75e14627 100644 --- a/levels/thi/areas/1/collision.inc.c +++ b/levels/thi/areas/1/collision.inc.c @@ -1256,7 +1256,7 @@ const Collision thi_seg7_area_1_collision[] = { COL_TRI(412, 320, 319), COL_TRI_STOP(), COL_SPECIAL_INIT(2), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -7372, -2969, 7373, /*yaw*/ 106), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -7372, -2969, 7373, /*yaw*/ 106), // unused, probably an early way to set initial position SPECIAL_OBJECT(/*preset*/ special_bubble_tree, /*pos*/ 4813, -511, 2254), COL_WATER_BOX_INIT(3), COL_WATER_BOX(0, -8191, -8191, -5119, 6246, -3071), diff --git a/levels/thi/areas/2/collision.inc.c b/levels/thi/areas/2/collision.inc.c index e47fe1c1..dce7d94a 100644 --- a/levels/thi/areas/2/collision.inc.c +++ b/levels/thi/areas/2/collision.inc.c @@ -970,7 +970,7 @@ const Collision thi_seg7_area_2_collision[] = { COL_TRI(244, 25, 148), COL_TRI_STOP(), COL_SPECIAL_INIT(3), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -2211, -890, 2212, /*yaw*/ 106), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -2211, -890, 2212, /*yaw*/ 106), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ -40, -767, -4494, /*yaw*/ 0), SPECIAL_OBJECT(/*preset*/ special_bubble_tree, /*pos*/ 1444, -153, 676), COL_WATER_BOX_INIT(3), diff --git a/levels/totwc/areas/1/collision.inc.c b/levels/totwc/areas/1/collision.inc.c index 38ef427d..fb8816b1 100644 --- a/levels/totwc/areas/1/collision.inc.c +++ b/levels/totwc/areas/1/collision.inc.c @@ -587,7 +587,7 @@ const Collision totwc_seg7_collision[] = { COL_TRI(81, 97, 67), COL_TRI_STOP(), COL_SPECIAL_INIT(23), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -4095, 2935, 0, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -4095, 2935, 0, /*yaw*/ 64), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ 4608, -357, -511, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ -4095, 666, 512, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ -5631, -1893, 6144, /*yaw*/ 0), diff --git a/levels/ttc/areas/1/collision.inc.c b/levels/ttc/areas/1/collision.inc.c index 4eaba6ea..5fc0f7cb 100644 --- a/levels/ttc/areas/1/collision.inc.c +++ b/levels/ttc/areas/1/collision.inc.c @@ -1890,6 +1890,6 @@ const Collision ttc_seg7_collision_level[] = { COL_TRI(526, 625, 624), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 1046, -4822, -266, /*yaw*/ 192), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 1046, -4822, -266, /*yaw*/ 192), // unused, probably an early way to set initial position COL_END(), }; diff --git a/levels/ttm/areas/1/collision.inc.c b/levels/ttm/areas/1/collision.inc.c index f31d8ffb..dd923702 100644 --- a/levels/ttm/areas/1/collision.inc.c +++ b/levels/ttm/areas/1/collision.inc.c @@ -2293,7 +2293,7 @@ const Collision ttm_seg7_area_1_collision[] = { COL_TRI(516, 430, 819), COL_TRI_STOP(), COL_SPECIAL_INIT(29), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 102, -4332, 5734, /*yaw*/ 32), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 102, -4332, 5734, /*yaw*/ 32), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ -3276, -4423, -3685, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ 7293, -5056, 1429, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_03, /*pos*/ 4938, -5568, 5115, /*yaw*/ 0), diff --git a/levels/vcutm/areas/1/collision.inc.c b/levels/vcutm/areas/1/collision.inc.c index 99de3350..f0489e16 100644 --- a/levels/vcutm/areas/1/collision.inc.c +++ b/levels/vcutm/areas/1/collision.inc.c @@ -844,6 +844,6 @@ const Collision vcutm_seg7_collision[] = { COL_TRI(40, 27, 30), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -6143, 5734, -6143, /*yaw*/ 0), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -6143, 5734, -6143, /*yaw*/ 0), // unused, probably an early way to set initial position COL_END(), }; diff --git a/levels/wdw/areas/1/collision.inc.c b/levels/wdw/areas/1/collision.inc.c index 122c3d62..b4901bc7 100644 --- a/levels/wdw/areas/1/collision.inc.c +++ b/levels/wdw/areas/1/collision.inc.c @@ -1345,7 +1345,7 @@ const Collision wdw_seg7_area_1_collision[] = { COL_TRI(85, 159, 157), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 3395, 1280, 384, /*yaw*/ 128), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 3395, 1280, 384, /*yaw*/ 128), // unused, probably an early way to set initial position COL_WATER_BOX_INIT(1), COL_WATER_BOX(0, -3839, -3839, 4608, 4608, 31), COL_END(), diff --git a/levels/wf/areas/1/collision.inc.c b/levels/wf/areas/1/collision.inc.c index 19301158..3a13fd68 100644 --- a/levels/wf/areas/1/collision.inc.c +++ b/levels/wf/areas/1/collision.inc.c @@ -1075,7 +1075,7 @@ const Collision wf_seg7_collision_070102D8[] = { COL_TRI(4, 7, 5), COL_TRI_STOP(), COL_SPECIAL_INIT(6), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 2560, 256, 5120, /*yaw*/ 64), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ 2560, 256, 5120, /*yaw*/ 64), // unused, probably an early way to set initial position SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_0E, /*pos*/ 3584, 154, 4864, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_0F, /*pos*/ 4608, 256, 1792, /*yaw*/ 0), SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_level_geo_11, /*pos*/ -2499, 1792, -261, /*yaw*/ 0), diff --git a/levels/wmotr/areas/1/collision.inc.c b/levels/wmotr/areas/1/collision.inc.c index 82a8a7ce..1a3670fc 100644 --- a/levels/wmotr/areas/1/collision.inc.c +++ b/levels/wmotr/areas/1/collision.inc.c @@ -2055,6 +2055,6 @@ const Collision wmotr_seg7_collision[] = { COL_TRI(288, 286, 289), COL_TRI_STOP(), COL_SPECIAL_INIT(1), - SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -67, 1669, -16, /*yaw*/ 192), // unused, probably an early way to set intial position + SPECIAL_OBJECT_WITH_YAW(/*preset*/ special_null_start, /*pos*/ -67, 1669, -16, /*yaw*/ 192), // unused, probably an early way to set initial position COL_END(), }; diff --git a/lib/asm/__osDisableInt.s b/lib/asm/__osDisableInt.s index 4c759b4c..b19b8481 100644 --- a/lib/asm/__osDisableInt.s +++ b/lib/asm/__osDisableInt.s @@ -1,7 +1,7 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/__osExceptionPreamble.s b/lib/asm/__osExceptionPreamble.s index e14928ce..c3b97993 100644 --- a/lib/asm/__osExceptionPreamble.s +++ b/lib/asm/__osExceptionPreamble.s @@ -1,21 +1,14 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" - -.ifdef VERSION_EU -.set VERSION_EU_SH, 1 -.endif -.ifdef VERSION_SH -.set VERSION_EU_SH, 1 -.endif +#include "macros.inc" .section .text, "ax" -.ifdef AVOID_UB +#ifdef AVOID_UB .set D_80334890, D_80334890_fix -.endif +#endif glabel __osExceptionPreamble lui $k0, %hi(__osException) @@ -37,7 +30,7 @@ glabel __osException sd $t2, 0x68($k0) sw $zero, 0x18($k0) mfc0 $t0, $13 -.ifndef VERSION_EU_SH +#if !defined(VERSION_EU) && !defined(VERSION_SH) andi $t1, $t0, 0x7c li $t2, 0 bne $t1, $t2, .L80326750 @@ -62,11 +55,11 @@ glabel __osException lui $at, %hi(D_80334934) sw $zero, %lo(D_80334934)($at) lui $at, %hi(D_80334938) -.endif +#endif move $t0, $k0 -.ifndef VERSION_EU_SH +#if !defined(VERSION_EU) && !defined(VERSION_SH) sw $zero, %lo(D_80334938)($at) -.endif +#endif lui $k0, %hi(D_80334890 + 0x10) lw $k0, %lo(D_80334890 + 0x10)($k0) ld $t1, 0x20($t0) @@ -79,17 +72,17 @@ glabel __osException sd $t1, 0x60($k0) ld $t1, 0x68($t0) sd $t1, 0x68($k0) -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) lw $k1, 0x118($k0) -.else +#else .L80326794: -.endif +#endif mflo $t0 sd $t0, 0x108($k0) mfhi $t0 -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) andi $t1, $k1, 0xff00 -.endif +#endif sd $v0, 0x28($k0) sd $v1, 0x30($k0) sd $a0, 0x38($k0) @@ -115,31 +108,31 @@ glabel __osException sd $sp, 0xf0($k0) sd $fp, 0xf8($k0) sd $ra, 0x100($k0) -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) beqz $t1, .L802F3A18 sd $t0, 0x110($k0) lui $t0, %hi(__OSGlobalIntMask) addiu $t0, %lo(__OSGlobalIntMask) lw $t0, ($t0) li $at, -1 -.ifdef VERSION_EU +#ifdef VERSION_EU xor $t0, $t0, $at -.else +#else xor $t2, $t0, $at -.endif +#endif lui $at, (0xFFFF00FF >> 16) -.ifdef VERSION_EU +#ifdef VERSION_EU andi $t0, $t0, 0xFF00 -.else +#else andi $t2, $t2, 0xFF00 -.endif +#endif ori $at, (0xFFFF00FF & 0xFFFF) -.ifdef VERSION_EU +#ifdef VERSION_EU or $t1, $t1, $t0 and $k1, $k1, $at or $k1, $k1, $t1 sw $k1, 0x118($k0) -.else +#else or $t4, $t1, $t2 and $t3, $k1, $at andi $t0, $t0, 0xFF00 @@ -148,7 +141,7 @@ glabel __osException and $k1, $k1, $at sw $t3, 0x118($k0) or $k1, $k1, $t1 -.endif +#endif .L802F3A18: lui $t1, %hi(MI_INTR_MASK_REG) @@ -167,9 +160,9 @@ glabel __osException or $t1, $t1, $t0 .L802F3A50: sw $t1, 0x128($k0) -.else +#else sd $t0, 0x110($k0) -.endif +#endif mfc0 $t0, $14 sw $t0, 0x11c($k0) lw $t0, 0x18($k0) @@ -197,14 +190,14 @@ glabel __osException .L80326868: mfc0 $t0, $13 sw $t0, 0x120($k0) -.ifndef VERSION_EU_SH +#if !defined(VERSION_EU) && !defined(VERSION_SH) lui $t1, %hi(MI_INTR_MASK_REG) lw $t1, %lo(MI_INTR_MASK_REG)($t1) sw $t1, 0x128($k0) -.endif +#endif li $t1, 2 sh $t1, 0x10($k0) -.ifndef VERSION_EU_SH +#if !defined(VERSION_EU) && !defined(VERSION_SH) lui $t1, %hi(D_80334934) lw $t1, %lo(D_80334934)($t1) beqz $t1, .L803268B4 @@ -239,7 +232,7 @@ glabel __osException b .L80326E08 sw $t1, %lo(D_80334A44)($at) .L80326900: -.endif +#endif andi $t1, $t0, 0x7c li $t2, 36 beq $t1, $t2, .L80326B84 @@ -267,7 +260,7 @@ glabel __osException lw $t2, %lo(jtbl_80338630)($at) jr $t2 nop -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) glabel L802F3B28 li $at, -8193 b .L8032692C @@ -276,7 +269,7 @@ glabel L802F3B34 li $at, -16385 b .L8032692C and $s0, $s0, $at -.endif +#endif glabel L80326964 mfc0 $t1, $11 mtc0 $t1, $11 @@ -287,62 +280,62 @@ glabel L80326964 b .L8032692C and $s0, $s0, $at glabel L80326984 -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) li $at, -2049 and $s0, $s0, $at -.endif +#endif li $t2, 4 lui $at, %hi(D_80334920) addu $at, $at, $t2 lw $t2, %lo(D_80334920)($at) -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) lui $sp, %hi(leoDiskStack) addiu $sp, %lo(leoDiskStack) li $a0, 16 beqz $t2, .L803269A4 addiu $sp, $sp, 0xff0 -.else +#else beqz $t2, .L803269A4 nop -.endif +#endif jalr $t2 nop -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) beqz $v0, .L803269A4 -.ifdef VERSION_SH +#ifdef VERSION_SH li $a0, 0x10 -.else +#else nop -.endif +#endif b .L80326B9C nop -.endif +#endif .L803269A4: jal send_mesg -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) nop b .L8032692C nop -.else +#else li $a0, 16 li $at, -2049 b .L8032692C and $s0, $s0, $at -.endif +#endif glabel L803269B8 -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) lui $t0, %hi(__OSGlobalIntMask) addiu $t0, %lo(__OSGlobalIntMask) lw $t0, ($t0) -.endif +#endif lui $s1, %hi(MI_INTR_REG) lw $s1, %lo(MI_INTR_REG)($s1) -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) srl $t0, $t0, 0x10 and $s1, $s1, $t0 -.else +#else andi $s1, $s1, 0x3f -.endif +#endif andi $t1, $s1, 1 beqz $t1, .L80326A18 nop @@ -609,7 +602,7 @@ glabel __osEnqueueAndYield sw $k1, 0x12c($a1) .L80326D70: -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) lw $k1, 0x118($a1) andi $t1, $k1, 0xff00 beqz $t1, .L802F3FBC @@ -627,10 +620,10 @@ glabel __osEnqueueAndYield or $k1, $k1, $t1 sw $k1, 0x118($a1) .L802F3FBC: -.endif +#endif lui $k1, %hi(MI_INTR_MASK_REG) lw $k1, %lo(MI_INTR_MASK_REG)($k1) -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) beqz $k1, .L802F3FF4 nop lui $k0, %hi(__OSGlobalIntMask) @@ -644,7 +637,7 @@ glabel __osEnqueueAndYield and $k0, $k0, $t0 or $k1, $k1, $k0 .L802F3FF4: -.endif +#endif beqz $a0, .L80326D88 sw $k1, 0x128($a1) jal __osEnqueueThread @@ -653,7 +646,7 @@ glabel __osEnqueueAndYield j __osDispatchThread nop -#enqueue and pop look like compiled functions? but there's no easy way to extract them +// enqueue and pop look like compiled functions? but there's no easy way to extract them glabel __osEnqueueThread lw $t8, ($a0) lw $t7, 4($a1) @@ -691,7 +684,7 @@ glabel __osDispatchThread li $t0, 4 sh $t0, 0x10($v0) move $k0, $v0 -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) lui $t0, %hi(__OSGlobalIntMask) lw $k1, 0x118($k0) addiu $t0, %lo(__OSGlobalIntMask) @@ -704,7 +697,7 @@ glabel __osDispatchThread and $k1, $k1, $at or $k1, $k1, $t1 mtc0 $k1, $12 -.endif +#endif .L80326E08: ld $k1, 0x108($k0) ld $at, 0x20($k0) @@ -741,10 +734,10 @@ glabel __osDispatchThread ld $ra, 0x100($k0) lw $k1, 0x11c($k0) mtc0 $k1, $14 -.ifndef VERSION_EU_SH +#if !defined(VERSION_EU) && !defined(VERSION_SH) lw $k1, 0x118($k0) mtc0 $k1, $12 -.endif +#endif lw $k1, 0x18($k0) beqz $k1, .L80326EF0 nop @@ -768,13 +761,13 @@ glabel __osDispatchThread ldc1 $f30, 0x1a8($k0) .L80326EF0: lw $k1, 0x128($k0) -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) lui $k0, %hi(__OSGlobalIntMask) addiu $k0, %lo(__OSGlobalIntMask) lw $k0, ($k0) srl $k0, $k0, 0x10 and $k1, $k1, $k0 -.endif +#endif sll $k1, $k1, 1 lui $k0, %hi(D_803386D0) addiu $k0, %lo(D_803386D0) @@ -820,13 +813,13 @@ glabel jtbl_80338630 .word L803269B8 .word L80326984 .word L80326AE8 -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) .word L802F3B28 .word L802F3B34 -.else +#else .word L80326BE8 .word L80326BE8 -.endif +#endif .word L80326964 .word 0 .word 0 diff --git a/lib/asm/__osGetCause.s b/lib/asm/__osGetCause.s index 13fff167..56371707 100644 --- a/lib/asm/__osGetCause.s +++ b/lib/asm/__osGetCause.s @@ -1,7 +1,7 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/__osGetSR.s b/lib/asm/__osGetSR.s index e2f74c76..0ed57883 100644 --- a/lib/asm/__osGetSR.s +++ b/lib/asm/__osGetSR.s @@ -1,7 +1,7 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/__osProbeTLB.s b/lib/asm/__osProbeTLB.s index fe83ea16..5f955bc9 100644 --- a/lib/asm/__osProbeTLB.s +++ b/lib/asm/__osProbeTLB.s @@ -1,8 +1,8 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" @@ -44,8 +44,8 @@ glabel __osProbeTLB andi $t5, $v0, 2 beqz $t5, .L8032A0D8 nop - lui $at, (0x3FFFFFC0 >> 16) # lui $at, 0x3fff - ori $at, (0x3FFFFFC0 & 0xFFFF) # ori $at, $at, 0xffc0 + lui $at, (0x3FFFFFC0 >> 16) // lui $at, 0x3fff + ori $at, (0x3FFFFFC0 & 0xFFFF) // ori $at, $at, 0xffc0 and $v0, $v0, $at sll $v0, $v0, 6 and $t5, $a0, $t3 diff --git a/lib/asm/__osRestoreInt.s b/lib/asm/__osRestoreInt.s index f6ab98ef..9b2c80ff 100644 --- a/lib/asm/__osRestoreInt.s +++ b/lib/asm/__osRestoreInt.s @@ -1,7 +1,7 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/__osSetCompare.s b/lib/asm/__osSetCompare.s index a1dab931..2df90585 100644 --- a/lib/asm/__osSetCompare.s +++ b/lib/asm/__osSetCompare.s @@ -1,7 +1,7 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/__osSetFpcCsr.s b/lib/asm/__osSetFpcCsr.s index e644bc74..0d5e75bc 100644 --- a/lib/asm/__osSetFpcCsr.s +++ b/lib/asm/__osSetFpcCsr.s @@ -1,7 +1,7 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/__osSetSR.s b/lib/asm/__osSetSR.s index 3fba3e66..00544244 100644 --- a/lib/asm/__osSetSR.s +++ b/lib/asm/__osSetSR.s @@ -1,7 +1,7 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/__os_eu_802ef550.s b/lib/asm/__os_eu_802ef550.s index 99b328e2..4f723ddb 100644 --- a/lib/asm/__os_eu_802ef550.s +++ b/lib/asm/__os_eu_802ef550.s @@ -1,12 +1,12 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 .set noat -.include "macros.inc" +#include "macros.inc" .section .text, "ax" -# cache related +// cache related glabel __os_eu_802ef550 lui $t0,0x8000 li $t2,0x2000 diff --git a/lib/asm/bcopy.s b/lib/asm/bcopy.s index 953a3d3c..e4f26909 100644 --- a/lib/asm/bcopy.s +++ b/lib/asm/bcopy.s @@ -1,8 +1,8 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/bzero.s b/lib/asm/bzero.s index 37053b7e..1e073acb 100644 --- a/lib/asm/bzero.s +++ b/lib/asm/bzero.s @@ -1,9 +1,9 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" -#this file is probably handwritten +// this file is probably handwritten .section .text, "ax" diff --git a/lib/asm/llmuldiv_gcc.s b/lib/asm/llmuldiv_gcc.s index cf604929..1582f878 100644 --- a/lib/asm/llmuldiv_gcc.s +++ b/lib/asm/llmuldiv_gcc.s @@ -1,9 +1,9 @@ -# assembler directives -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +// assembler directives +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/osGetCount.s b/lib/asm/osGetCount.s index 58bd3629..b47b66ae 100644 --- a/lib/asm/osGetCount.s +++ b/lib/asm/osGetCount.s @@ -1,7 +1,7 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/osInvalDCache.s b/lib/asm/osInvalDCache.s index 452c4dd3..dca94af6 100644 --- a/lib/asm/osInvalDCache.s +++ b/lib/asm/osInvalDCache.s @@ -1,8 +1,8 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/osInvalICache.s b/lib/asm/osInvalICache.s index 8b8a03f0..fd9ea6a7 100644 --- a/lib/asm/osInvalICache.s +++ b/lib/asm/osInvalICache.s @@ -1,8 +1,8 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/osMapTLB.s b/lib/asm/osMapTLB.s index b9ee4364..1910cd9d 100644 --- a/lib/asm/osMapTLB.s +++ b/lib/asm/osMapTLB.s @@ -1,14 +1,14 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" -# This file is handwritten +// This file is handwritten -#void osMapTLB(s32 index, OSPageMask pm, void *vaddr, u32 evenpaddr, u32 oddpaddr, s32 asid); +// void osMapTLB(s32 index, OSPageMask pm, void *vaddr, u32 evenpaddr, u32 oddpaddr, s32 asid); glabel osMapTLB mfc0 $t0, $10 mtc0 $a0, $0 diff --git a/lib/asm/osMapTLBRdb.s b/lib/asm/osMapTLBRdb.s index 6753280d..4bcba1d1 100644 --- a/lib/asm/osMapTLBRdb.s +++ b/lib/asm/osMapTLBRdb.s @@ -1,8 +1,8 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/osSetIntMask.s b/lib/asm/osSetIntMask.s index ce1c884d..6ea380e5 100644 --- a/lib/asm/osSetIntMask.s +++ b/lib/asm/osSetIntMask.s @@ -1,38 +1,31 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .eqv MI_INTR_MASK_REG, 0xA430000C -.ifdef VERSION_EU -.set VERSION_EU_SH, 1 -.endif -.ifdef VERSION_SH -.set VERSION_EU_SH, 1 -.endif - .section .text, "ax" glabel osSetIntMask -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) mfc0 $t4, $12 andi $v0, $t4, 0xff01 - lui $t0, %hi(__OSGlobalIntMask) # $t0, 0x8030 - addiu $t0, %lo(__OSGlobalIntMask) # addiu $t0, $t0, 0x208c + lui $t0, %hi(__OSGlobalIntMask) // $t0, 0x8030 + addiu $t0, %lo(__OSGlobalIntMask) // addiu $t0, $t0, 0x208c lw $t3, ($t0) li $at, -1 xor $t0, $t3, $at andi $t0, $t0, 0xff00 or $v0, $v0, $t0 -.else +#else mfc0 $t1, $12 andi $v0, $t1, 0xff01 -.endif - lui $t2, %hi(MI_INTR_MASK_REG) # $t2, 0xa430 +#endif + lui $t2, %hi(MI_INTR_MASK_REG) // $t2, 0xa430 lw $t2, %lo(MI_INTR_MASK_REG)($t2) -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) beqz $t2, .L80200074 srl $t1, $t3, 0x10 li $at, -1 @@ -40,36 +33,36 @@ glabel osSetIntMask andi $t1, $t1, 0x3f or $t2, $t2, $t1 .L80200074: -.endif +#endif sll $t2, $t2, 0x10 or $v0, $v0, $t2 lui $at, 0x3f and $t0, $a0, $at -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) and $t0, $t0, $t3 -.endif +#endif srl $t0, $t0, 0xf lui $t2, %hi(D_803386D0) addu $t2, $t2, $t0 lhu $t2, %lo(D_803386D0)($t2) - lui $at, %hi(MI_INTR_MASK_REG) # $at, 0xa430 + lui $at, %hi(MI_INTR_MASK_REG) // $at, 0xa430 sw $t2, %lo(MI_INTR_MASK_REG)($at) andi $t0, $a0, 0xff01 -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) andi $t1, $t3, 0xff00 and $t0, $t0, $t1 -.endif - lui $at, (0xFFFF00FF >> 16) # lui $at, 0xffff - ori $at, (0xFFFF00FF & 0xFFFF) # ori $at, $at, 0xff -.ifdef VERSION_EU_SH +#endif + lui $at, (0xFFFF00FF >> 16) // lui $at, 0xffff + ori $at, (0xFFFF00FF & 0xFFFF) // ori $at, $at, 0xff +#if defined(VERSION_EU) || defined(VERSION_SH) and $t4, $t4, $at or $t4, $t4, $t0 mtc0 $t4, $12 -.else +#else and $t1, $t1, $at or $t1, $t1, $t0 mtc0 $t1, $12 -.endif +#endif nop nop jr $ra diff --git a/lib/asm/osUnmapTLBAll.s b/lib/asm/osUnmapTLBAll.s index 0bd9ad27..1548c162 100644 --- a/lib/asm/osUnmapTLBAll.s +++ b/lib/asm/osUnmapTLBAll.s @@ -1,7 +1,7 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/osWritebackDCache.s b/lib/asm/osWritebackDCache.s index 8e870168..e4a2ab0c 100644 --- a/lib/asm/osWritebackDCache.s +++ b/lib/asm/osWritebackDCache.s @@ -1,7 +1,7 @@ -.set noreorder # don't insert nops after branches +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" @@ -34,6 +34,6 @@ glabel osWritebackDCache .L80324E4C: cache 1, ($t0) bltu $t0, $t1, .L80324E4C - addiu $t0, 0x10 # addiu $t0, $t0, 0x10 + addiu $t0, 0x10 // addiu $t0, $t0, 0x10 jr $ra nop diff --git a/lib/asm/osWritebackDCacheAll.s b/lib/asm/osWritebackDCacheAll.s index 88707604..bb5fa41d 100644 --- a/lib/asm/osWritebackDCacheAll.s +++ b/lib/asm/osWritebackDCacheAll.s @@ -1,8 +1,8 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/asm/parameters.s b/lib/asm/parameters.s index 0314d41f..5b402250 100644 --- a/lib/asm/parameters.s +++ b/lib/asm/parameters.s @@ -1,10 +1,10 @@ .macro gsymbol sym addr .global \sym .set \sym, \addr -.ifndef VERSION_JP +#ifndef VERSION_JP nop nop -.endif +#endif .endm .text @@ -16,7 +16,7 @@ gsymbol osCiCId 0x80000310 gsymbol osVersion 0x80000314 gsymbol osMemSize 0x80000318 gsymbol osAppNmiBuffer 0x8000031C -.ifdef VERSION_SH +#ifdef VERSION_SH nop nop nop @@ -25,4 +25,4 @@ nop nop nop nop -.endif \ No newline at end of file +#endif diff --git a/lib/asm/sqrtf.s b/lib/asm/sqrtf.s index a3ce7756..70984e56 100644 --- a/lib/asm/sqrtf.s +++ b/lib/asm/sqrtf.s @@ -1,8 +1,8 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches +.set noat // allow manual use of $at +.set noreorder // don't insert nops after branches .set gp=64 -.include "macros.inc" +#include "macros.inc" .section .text, "ax" diff --git a/lib/rsp.s b/lib/rsp.s index bfc59875..42893f92 100644 --- a/lib/rsp.s +++ b/lib/rsp.s @@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" .set UCODE_SIZE, 0x800 .section .text @@ -10,22 +10,22 @@ glabel rspF3DBootStart glabel rspF3DBootEnd .balign 16 -.ifndef F3DEX_GBI_SHARED +#ifndef F3DEX_GBI_SHARED glabel rspF3DStart /* Use regular Fast3D bins (default) */ .incbin "rsp/fast3d.bin" glabel rspF3DEnd -.else /* Use one of the Fast3DEX series grucodes. */ +#else /* Use one of the Fast3DEX series grucodes. */ glabel rspF3DStart - .if F3DZEX_GBI_2 == 1 + #ifdef F3DZEX_GBI_2 .incbin "lib/PR/f3dex2/F3DZEX_NoN.bin" - .elseif F3DEX_GBI == 1 + #elif defined(F3DEX_GBI) .incbin "lib/PR/f3dex/F3DEX.bin" - .elseif F3DEX_GBI_2 == 1 + #elif defined(F3DEX_GBI_2) .incbin "lib/PR/f3dex2/F3DEX2.bin" - .endif + #endif glabel rspF3DEnd -.endif +#endif /* Audio Bins */ @@ -40,107 +40,107 @@ glabel rspAspMainEnd */ /* Fast3DEX NoN Text */ -.ifdef F3DEX_NON_GBI +#ifdef F3DEX_NON_GBI glabel rspF3DEXNoNStart .balign 16 .incbin "lib/PR/f3dex/F3DEX_NoN.bin" glabel rspF3DEXNoNEnd -.endif +#endif /* Fast3DLX Text */ -.ifdef F3DLX_GBI +#ifdef F3DLX_GBI glabel rspF3DLXStart .incbin "lib/PR/f3dex/F3DLX.bin" glabel rspF3DLXEnd -.endif +#endif /* Fast3DLX NoN Text */ -.ifdef F3DLX_NON_GBI +#ifdef F3DLX_NON_GBI glabel rspF3DLXNoNStart .balign 16 .incbin "lib/PR/f3dex/F3DLX_NoN.bin" glabel rspF3DLXNoNEnd -.endif +#endif /* Fast3DLX Rej Text */ -.ifdef F3DLX_REJ_GBI +#ifdef F3DLX_REJ_GBI glabel rspF3DLXRejStart .balign 16 .incbin "lib/PR/f3dex/F3DLX_Rej.bin" glabel rspF3DLXRejEnd -.endif +#endif /* Line3DEX Text */ -.ifdef L3DEX_GBI +#ifdef L3DEX_GBI glabel rspL3DEXStart .balign 16 .incbin "lib/PR/f3dex/L3DEX.bin" glabel rspL3DEXEnd -.endif +#endif /* S2DEX Text */ -.ifdef S2DEX_GBI +#ifdef S2DEX_GBI glabel rspS2DEXStart .balign 16 .incbin "lib/PR/s2dex/S2DEX.bin" glabel rspS2DEXEnd -.endif +#endif /* Fast3DEX2 series */ /* Fast3DEX2 NoN Text */ -.ifdef F3DEX2_NON_GBI +#ifdef F3DEX2_NON_GBI .balign 16 glabel rspF3DEX2NoNStart .incbin "lib/PR/f3dex2/F3DEX2_NoN.bin" glabel rspF3DEX2NoNEnd -.endif +#endif /* Fast3DEX2 Rej Text */ -.ifdef F3DEX2_REJ_GBI +#ifdef F3DEX2_REJ_GBI .balign 16 glabel rspF3DEX2RejStart .incbin "lib/PR/f3dex2/F3DEX2_Rej.bin" glabel rspF3DEX2RejEnd -.endif +#endif /* Line3DEX2 Text */ -.ifdef L3DEX2_GBI +#ifdef L3DEX2_GBI .balign 16 glabel rspL3DEX2Start .incbin "lib/PR/f3dex2/L3DEX2.bin" glabel rspL3DEX2End -.endif +#endif /* S2DEX2 Text */ -.ifdef S2DEX_GBI_2 +#ifdef S2DEX_GBI_2 .balign 16 glabel rspS2DEXStart .incbin "lib/PR/s2dex/S2DEX2.bin" glabel rspS2DEXEnd -.endif +#endif /* DATA SECTION START */ .section .rodata .balign 16 -.ifndef F3DEX_GBI_SHARED /* Use regular Fast3D data (default) */ +#ifndef F3DEX_GBI_SHARED /* Use regular Fast3D data (default) */ glabel rspF3DDataStart .incbin "rsp/fast3d_data.bin" glabel rspF3DDataEnd -.else /* Using one of the Fast3DEX series grucodes */ +#else /* Using one of the Fast3DEX series grucodes */ glabel rspF3DDataStart - .if F3DZEX_GBI_2 == 1 + #ifdef F3DZEX_GBI_2 .incbin "lib/PR/f3dex2/F3DZEX_NoN_data.bin" - .elseif F3DEX_GBI == 1 + #elif defined(F3DEX_GBI) .incbin "lib/PR/f3dex/F3DEX_data.bin" - .elseif F3DEX_GBI_2 == 1 + #elif defined(F3DEX_GBI_2) .incbin "lib/PR/f3dex2/F3DEX2_data.bin" - .endif + #endif glabel rspF3DDataEnd -.endif +#endif /* Audio Data */ @@ -154,83 +154,83 @@ glabel rspAspMainDataEnd /* Fast3DEX Series */ /* Fast3DEX NoN Data */ -.ifdef F3DEX_NON_GBI +#ifdef F3DEX_NON_GBI .balign 16 glabel rspF3DEXNoNDataStart .incbin "lib/PR/f3dex/F3DEX_NoN_data.bin" glabel rspF3DEXNoNDataEnd -.endif +#endif /* Fast3DLX Data */ -.ifdef F3DLX_GBI +#ifdef F3DLX_GBI .balign 16 glabel rspF3DLXDataStart .incbin "lib/PR/f3dex/F3DLX_data.bin" glabel rspF3DLXDataEnd -.endif +#endif /* Fast3DLX NoN Data */ -.ifdef F3DLX_NON_GBI +#ifdef F3DLX_NON_GBI .balign 16 glabel rspF3DLXNoNDataStart .incbin "lib/PR/f3dex/F3DLX_NoN_data.bin" glabel rspF3DLXNoNDataEnd -.endif +#endif /* Fast3DLX Rej Data */ -.ifdef F3DLX_REJ_GBI +#ifdef F3DLX_REJ_GBI .balign 16 glabel rspF3DLXRejDataStart .incbin "lib/PR/f3dex/F3DLX_Rej_data.bin" glabel rspF3DLXRejDataEnd -.endif +#endif /* Line3DEX Data */ -.ifdef L3DEX_GBI +#ifdef L3DEX_GBI .balign 16 glabel rspL3DEXDataStart .incbin "lib/PR/f3dex/L3DEX_data.bin" glabel rspL3DEXDataEnd -.endif +#endif /* S2DEX Data */ -.ifdef S2DEX_GBI +#ifdef S2DEX_GBI .balign 16 glabel rspS2DEXDataStart .incbin "lib/PR/s2dex/S2DEX_data.bin" glabel rspS2DEXDataEnd -.endif +#endif /* Fast3DEX2 Series */ /* Fast3DEX2 NoN Data */ -.ifdef F3DEX2_NON_GBI +#ifdef F3DEX2_NON_GBI .balign 16 glabel rspF3DEX2NoNStart .incbin "lib/PR/f3dex2/F3DEX2_NoN_data.bin" glabel rspF3DEX2NoNEnd -.endif +#endif /* Fast3DEX2 Rej Data */ -.ifdef F3DEX2_REJ_GBI +#ifdef F3DEX2_REJ_GBI .balign 16 glabel rspF3DEX2RejStart .incbin "lib/PR/f3dex2/F3DEX2_Rej_data.bin" glabel rspF3DEX2RejEnd -.endif +#endif /* Line3DEX2 Data */ -.ifdef L3DEX2_GBI +#ifdef L3DEX2_GBI .balign 16 glabel rspL3DEX2Start .incbin "lib/PR/f3dex2/L3DEX2_data.bin" glabel rspL3DEX2End -.endif +#endif /* S2DEX2 Data */ -.ifdef S2DEX_GBI_2 +#ifdef S2DEX_GBI_2 .balign 16 glabel rspS2DEXStart .incbin "lib/PR/s2dex/S2DEX2_data.bin" glabel rspS2DEXEnd -.endif +#endif diff --git a/lib/src/D_802F4380.c b/lib/src/D_802F4380.c index bc7fce24..7183ab1d 100644 --- a/lib/src/D_802F4380.c +++ b/lib/src/D_802F4380.c @@ -57,7 +57,7 @@ u32 D_802F4380() { return 1; } sp2c->dramAddr = (void *) ((u32) sp2c->dramAddr + sp2c->sectorSize); - sp30->sectorNum += 1; + sp30->sectorNum++; osEPiRawStartDma(__osDiskHandle, 1, 0x05000400, sp2c->dramAddr, sp2c->sectorSize); return 1; } @@ -77,8 +77,7 @@ u32 D_802F4380() { sp2c->dramAddr = (void *) ((u32) sp2c->dramAddr + sp2c->sectorSize); } sp34 = HW_REG(ASIC_BM_STATUS, u32); - if (((C1_SINGLE & sp34) && (C1_DOUBLE & sp34)) || (sp34 & MICRO_STATUS)) - { + if (((C1_SINGLE & sp34) && (C1_DOUBLE & sp34)) || (sp34 & MICRO_STATUS)) { if (sp2c->C1ErrNum > 3) { if (sp30->transferMode != 3 || sp30->sectorNum > 0x52) { sp30->errStatus = 17; @@ -89,7 +88,7 @@ u32 D_802F4380() { sp28 = sp2c->C1ErrNum; sp2c->C1ErrSector[sp28] = sp30->sectorNum + 1; } - sp2c->C1ErrNum += 1; + sp2c->C1ErrNum++; } if (sp3c & C2_TRANSFER) { if (sp30->sectorNum != 87) { @@ -123,7 +122,7 @@ u32 D_802F4380() { sp30->errStatus = 0; func_802F4B08(); } - sp30->sectorNum += 1; + sp30->sectorNum++; if (sp3c & DATA_REQUEST) { if (sp30->sectorNum > 0x54) { sp30->errStatus = 6; diff --git a/lib/src/__osDevMgrMain.c b/lib/src/__osDevMgrMain.c index 3f48e8fc..e31bdaa3 100644 --- a/lib/src/__osDevMgrMain.c +++ b/lib/src/__osDevMgrMain.c @@ -10,7 +10,7 @@ void __osDevMgrMain(void *args) { OSMesg dummy; s32 ret; OSMgrArgs *sp34; -#ifndef VERSION_SH +#ifdef VERSION_EU UNUSED u32 sp30; #endif u32 sp2c; @@ -19,7 +19,7 @@ void __osDevMgrMain(void *args) { #ifdef VERSION_SH u32 tmp; #endif -#ifndef VERSION_SH +#ifdef VERSION_EU sp30 = 0; #endif sp2c = 0; @@ -108,7 +108,7 @@ void __osDevMgrMain(void *args) { } if (ret == 0) { osRecvMesg(sp34->eventQueue, &em, OS_MESG_BLOCK); -#ifndef VERSION_SH +#ifdef VERSION_EU sp30 = #endif osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); diff --git a/lib/src/__osViInit.c b/lib/src/__osViInit.c index 980c7b89..9e0c9163 100644 --- a/lib/src/__osViInit.c +++ b/lib/src/__osViInit.c @@ -1,14 +1,6 @@ #include "libultra_internal.h" #include "hardware.h" -#ifdef VERSION_SH -extern s32 D_SH_80000300; // Potentially a TV type -#endif - -#ifndef VERSION_JP -extern u32 osTvType; -#endif - OSViContext sViContexts[2] = { 0 }; OSViContext *__osViCurr = &sViContexts[0]; OSViContext *__osViNext = &sViContexts[1]; @@ -80,6 +72,7 @@ void __osViInit(void) { osViClock = 0x02E6025C; #endif } + #endif __osViNext->unk00 = 0x20; diff --git a/lib/src/contramread.c b/lib/src/contramread.c index 3043f71a..cd74bb24 100644 --- a/lib/src/contramread.c +++ b/lib/src/contramread.c @@ -2,7 +2,6 @@ #include "PR/rcp.h" #include "controller.h" -#ifdef VERSION_SH extern s32 func_8030A5C0(OSMesgQueue *, s32); void __osPackRamReadData(int channel, u16 address); @@ -87,4 +86,3 @@ void __osPackRamReadData(int channel, u16 address) { ptr += sizeof(__OSContRamReadFormat); ptr[0] = CONT_CMD_END; } -#endif diff --git a/lib/src/contramwrite.c b/lib/src/contramwrite.c index 6b83dae3..f72d6ffd 100644 --- a/lib/src/contramwrite.c +++ b/lib/src/contramwrite.c @@ -2,7 +2,6 @@ #include "PR/rcp.h" #include "controller.h" -#ifdef VERSION_SH extern s32 func_8030A5C0(OSMesgQueue *, s32); void __osPackRamWriteData(int channel, u16 address, u8 *buffer); @@ -87,4 +86,3 @@ void __osPackRamWriteData(int channel, u16 address, u8 *buffer) { ptr += sizeof(__OSContRamReadFormat); ptr[0] = CONT_CMD_END; } -#endif diff --git a/lib/src/controller.h b/lib/src/controller.h index 67182b41..518b113e 100644 --- a/lib/src/controller.h +++ b/lib/src/controller.h @@ -1,7 +1,7 @@ #ifndef _CONTROLLER_H #define _CONTROLLER_H #include "PR/os_internal.h" -#include "os.h" +#include "PR/os.h" #include "PR/rcp.h" //should go somewhere else but diff --git a/lib/src/crc.c b/lib/src/crc.c index f18dc632..f7fd3f29 100644 --- a/lib/src/crc.c +++ b/lib/src/crc.c @@ -1,6 +1,5 @@ #include "libultra_internal.h" -#ifdef VERSION_SH u8 __osContAddressCrc(u16 addr) { u8 temp; u8 temp2; @@ -45,4 +44,3 @@ u8 __osContDataCrc(u8 *data) { } return temp; } -#endif diff --git a/lib/src/epidma.c b/lib/src/epidma.c index cc46a4d4..3aa76f17 100644 --- a/lib/src/epidma.c +++ b/lib/src/epidma.c @@ -1,4 +1,5 @@ #ifdef VERSION_SH + #include "PR/os_internal.h" #include "piint.h" @@ -21,4 +22,5 @@ s32 osEPiStartDma(OSPiHandle *pihandle, OSIoMesg *mb, s32 direction) { } return ret; } + #endif diff --git a/lib/src/func_802F4A20.c b/lib/src/func_802F4A20.c index c38c23a4..499697d8 100644 --- a/lib/src/func_802F4A20.c +++ b/lib/src/func_802F4A20.c @@ -32,7 +32,7 @@ void func_802F4B08(void) { } sp24 = (sp28->first + sp28->validCount) % sp28->msgCount; sp28->msg[sp24] = sp2c->msg; - sp28->validCount += 1; + sp28->validCount++; if (sp28->mtqueue->next != NULL) { s0 = __osPopThread(&sp28->mtqueue); __osEnqueueThread(&D_80334898, s0); diff --git a/lib/src/hardware.h b/lib/src/hardware.h index 14848ca8..564e814c 100644 --- a/lib/src/hardware.h +++ b/lib/src/hardware.h @@ -1,7 +1,7 @@ #ifndef _HARDWARE_H_ #define _HARDWARE_H_ -#define HW_REG(reg, type) *(volatile type *)(uintptr_t)(reg | 0xa0000000) +#define HW_REG(reg, type) *(volatile type *)(uintptr_t)((reg) | 0xa0000000) #define AI_DRAM_ADDR_REG 0x04500000 #define AI_LEN_REG 0x04500004 diff --git a/lib/src/kdebugserver_stack.c b/lib/src/kdebugserver_stack.c index 148e0d3f..62dd6151 100644 --- a/lib/src/kdebugserver_stack.c +++ b/lib/src/kdebugserver_stack.c @@ -1,5 +1,5 @@ #include "libultra_internal.h" -#if !defined(VERSION_SH) && !defined(VERSION_EU) +#if defined(VERSION_JP) || defined(VERSION_US) u8 D_80365E40[0x100]; #endif diff --git a/lib/src/leointerrupt.c b/lib/src/leointerrupt.c index 2aeea1e5..83a4f39e 100644 --- a/lib/src/leointerrupt.c +++ b/lib/src/leointerrupt.c @@ -4,9 +4,10 @@ #include "piint.h" #include "osint.h" -u8 leoDiskStack[OS_PIM_STACKSIZE]; //technically should have a OS_LEO_STACKSIZE or something.. +u8 leoDiskStack[OS_PIM_STACKSIZE]; // technically should have a OS_LEO_STACKSIZE or something.. #ifdef VERSION_SH + // TODO: so many magic constants :'( static void __osLeoResume(void); static void __osLeoAbnormalResume(void); @@ -92,7 +93,7 @@ s32 __osLeoInterrupt() { int errNum = blockInfo->C1ErrNum; blockInfo->C1ErrSector[errNum] = info->sectorNum + 1; } - blockInfo->C1ErrNum += 1; + blockInfo->C1ErrNum++; } if (stat & LEO_STATUS_C2_TRANSFER) { if (info->sectorNum != 87) { @@ -179,4 +180,5 @@ static void __osLeoResume(void) { __osEnqueueThread(&D_80334898, __osPopThread(&mq->mtqueue)); } } + #endif diff --git a/lib/src/osAiSetFrequency.c b/lib/src/osAiSetFrequency.c index 4b32658e..5cc8bc93 100644 --- a/lib/src/osAiSetFrequency.c +++ b/lib/src/osAiSetFrequency.c @@ -1,6 +1,7 @@ #include "libultra_internal.h" #include "osAi.h" #include "hardware.h" +#include "macros.h" extern s32 osViClock; @@ -29,9 +30,9 @@ s32 osAiSetFrequency(u32 freq) { #ifndef VERSION_SH // put some extra jr $ra's down there please -static void filler1(void) { +UNUSED static void filler1(void) { } -static void filler2(void) { +UNUSED static void filler2(void) { } #endif diff --git a/lib/src/osCartRomInit.c b/lib/src/osCartRomInit.c index 51602f69..84ea3b63 100644 --- a/lib/src/osCartRomInit.c +++ b/lib/src/osCartRomInit.c @@ -2,9 +2,9 @@ #include "PR/R4300.h" #include "PR/rcp.h" #include "PR/os_pi.h" -#include "os.h" +#include "PR/os.h" +#include "libultra_internal.h" -#ifdef VERSION_SH OSPiHandle CartRomHandle; OSPiHandle *osCartRomInit(void) { @@ -36,4 +36,3 @@ OSPiHandle *osCartRomInit(void) { return &CartRomHandle; } -#endif diff --git a/lib/src/osCreatePiManager.c b/lib/src/osCreatePiManager.c index 7e182b74..890cfe32 100644 --- a/lib/src/osCreatePiManager.c +++ b/lib/src/osCreatePiManager.c @@ -12,7 +12,7 @@ OSMgrArgs __osPiDevMgr = { 0 }; OSPiHandle *__osPiTable = NULL; #endif #ifdef VERSION_SH -OSPiHandle *__osCurrentHandle[2] = { &CartRomHandle, &LeoDiskHandle }; +OSPiHandle **__osCurrentHandle[2] = { &CartRomHandle, &LeoDiskHandle }; #endif OSThread piMgrThread; u32 piMgrStack[0x400]; // stack bottom diff --git a/lib/src/osCreateViManager.c b/lib/src/osCreateViManager.c index 7c971826..67776ed6 100644 --- a/lib/src/osCreateViManager.c +++ b/lib/src/osCreateViManager.c @@ -13,8 +13,8 @@ static OSIoMesg viEventCounterMesg; extern void __osTimerServicesInit(void); extern void __osTimerInterrupt(void); -extern OSTime _osCurrentTime; -extern u32 D_80365DA8; +extern OSTime __osCurrentTime; +extern u32 __osBaseCounter; extern u32 __osViIntrCount; void viMgrMain(void *); @@ -92,13 +92,13 @@ void viMgrMain(void *vargs) { __osViIntrCount++; if (sp28) { sp24 = osGetCount(); - _osCurrentTime = sp24; + __osCurrentTime = sp24; sp28 = 0; } - sp24 = D_80365DA8; - D_80365DA8 = osGetCount(); - sp24 = D_80365DA8 - sp24; - _osCurrentTime = _osCurrentTime + sp24; + sp24 = __osBaseCounter; + __osBaseCounter = osGetCount(); + sp24 = __osBaseCounter - sp24; + __osCurrentTime = __osCurrentTime + sp24; break; case 14: diff --git a/lib/src/osDriveRomInit.c b/lib/src/osDriveRomInit.c index 930e5613..9bfc1de4 100644 --- a/lib/src/osDriveRomInit.c +++ b/lib/src/osDriveRomInit.c @@ -7,7 +7,7 @@ extern OSPiHandle *__osPiTable; extern OSPiHandle DriveRomHandle; -OSPiHandle *osDriveRomInit() { // Why is this compiled with -g??? +OSPiHandle *osDriveRomInit(void) { // Why is this compiled with -g??? UNUSED s32 sp1c = 0; u32 saveMask; @@ -32,4 +32,3 @@ OSPiHandle *osDriveRomInit() { // Why is this compiled with -g??? return &DriveRomHandle; } - diff --git a/lib/src/osEepromLongRead.c b/lib/src/osEepromLongRead.c index b9884abf..3260d138 100644 --- a/lib/src/osEepromLongRead.c +++ b/lib/src/osEepromLongRead.c @@ -20,7 +20,7 @@ s32 osEepromLongRead(OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes) { } nbytes -= 8; - address += 1; + address++; buffer += 8; osSetTimer(&D_80365D28, 12000 * osClockRate / 1000000, 0, &_osContMesgQueue, _osContMesgBuff); osRecvMesg(&_osContMesgQueue, NULL, OS_MESG_BLOCK); diff --git a/lib/src/osEepromLongWrite.c b/lib/src/osEepromLongWrite.c index ef09fa92..69d367e3 100644 --- a/lib/src/osEepromLongWrite.c +++ b/lib/src/osEepromLongWrite.c @@ -21,7 +21,7 @@ s32 osEepromLongWrite(OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes) { } nbytes -= 8; - address += 1; + address++; buffer += 8; osSetTimer(&D_80365D28, 12000 * osClockRate / 1000000, 0, &_osContMesgQueue, _osContMesgBuff); osRecvMesg(&_osContMesgQueue, NULL, OS_MESG_BLOCK); diff --git a/lib/src/osEepromRead.c b/lib/src/osEepromRead.c index ea784b2c..7f3a0292 100644 --- a/lib/src/osEepromRead.c +++ b/lib/src/osEepromRead.c @@ -96,4 +96,7 @@ s32 __osPackEepReadData(u8 address) { *(unkStruct2 *) sp14 = sp8; sp14 += 0xc; *sp14 = 254; +#ifdef AVOID_UB + return 0; +#endif } diff --git a/lib/src/osEepromWrite.c b/lib/src/osEepromWrite.c index 1a86477b..67c42a59 100644 --- a/lib/src/osEepromWrite.c +++ b/lib/src/osEepromWrite.c @@ -108,6 +108,9 @@ s32 __osPackEepWriteData(u8 address, u8 *buffer) { *(unkStruct2 *) sp14 = sp8; sp14 += 0xc; *sp14 = 254; +#ifdef AVOID_UB + return 0; +#endif } s32 __osEepStatus(OSMesgQueue *a0, unkStruct *a1) { diff --git a/lib/src/osGetTime.c b/lib/src/osGetTime.c index 93dc8cbe..45cef5ca 100644 --- a/lib/src/osGetTime.c +++ b/lib/src/osGetTime.c @@ -1,17 +1,18 @@ #include "libultra_internal.h" -extern OSTime _osCurrentTime; -extern u32 D_80365DA8; +extern OSTime __osCurrentTime; +extern u32 __osBaseCounter; OSTime osGetTime() { - u32 sp34; - u32 sp30; - OSTime sp28; - register u32 int_disabled; - int_disabled = __osDisableInt(); - sp34 = osGetCount(); - sp30 = sp34 - D_80365DA8; - sp28 = _osCurrentTime; - __osRestoreInt(int_disabled); - return sp28 + sp30; + u32 tmpTime; + u32 elapseCount; + OSTime currentCount; + register u32 saveMask; + + saveMask = __osDisableInt(); + tmpTime = osGetCount(); + elapseCount = tmpTime - __osBaseCounter; + currentCount = __osCurrentTime; + __osRestoreInt(saveMask); + return currentCount + elapseCount; } diff --git a/lib/src/osLeoDiskInit.c b/lib/src/osLeoDiskInit.c index 0507de6a..066aab8a 100644 --- a/lib/src/osLeoDiskInit.c +++ b/lib/src/osLeoDiskInit.c @@ -9,7 +9,6 @@ extern OSPiHandle *__osPiTable; OSPiHandle LeoDiskHandle; OSPiHandle *__osDiskHandle; -// some kind of piHandle init function, maybe osDriveRomInit or osCartRomInit OSPiHandle *osLeoDiskInit(void) { s32 sp1c; LeoDiskHandle.type = 2; diff --git a/lib/src/osPfsIsPlug.c b/lib/src/osPfsIsPlug.c index 9611c977..6165e329 100644 --- a/lib/src/osPfsIsPlug.c +++ b/lib/src/osPfsIsPlug.c @@ -1,8 +1,7 @@ #include "PR/os_pi.h" +#include "libultra_internal.h" #include "controller.h" -//#include "siint.h" -#ifdef VERSION_SH OSPifRam __osPfsPifRam; s32 osPfsIsPlug(OSMesgQueue *queue, u8 *pattern) { @@ -94,4 +93,3 @@ void __osPfsGetInitData(u8 *pattern, OSContStatus *data) { } *pattern = bits; } -#endif diff --git a/lib/src/osSetTime.c b/lib/src/osSetTime.c index ba906b69..cad09ab2 100644 --- a/lib/src/osSetTime.c +++ b/lib/src/osSetTime.c @@ -1,7 +1,7 @@ #include "libultra_internal.h" -extern OSTime _osCurrentTime; +extern OSTime __osCurrentTime; void osSetTime(OSTime time) { - _osCurrentTime = time; + __osCurrentTime = time; } diff --git a/lib/src/osSetTimer.c b/lib/src/osSetTimer.c index f7003b67..fc1258cf 100644 --- a/lib/src/osSetTimer.c +++ b/lib/src/osSetTimer.c @@ -1,23 +1,23 @@ #include "libultra_internal.h" -extern OSTimer *D_80334830; +extern OSTimer *__osTimerList; extern u64 __osInsertTimer(OSTimer *); -u32 osSetTimer(OSTimer *a0, OSTime a1, u64 a2, OSMesgQueue *a3, OSMesg a4) { - u64 sp18; - a0->next = NULL; - a0->prev = NULL; - a0->interval = a2; - if (a1 != 0) { - a0->remaining = a1; +u32 osSetTimer(OSTimer *t, OSTime countdown, OSTime interval, OSMesgQueue *mq, OSMesg msg) { + OSTime time; + t->next = NULL; + t->prev = NULL; + t->interval = interval; + if (countdown != 0) { + t->remaining = countdown; } else { - a0->remaining = a2; + t->remaining = interval; } - a0->mq = a3; - a0->msg = a4; - sp18 = __osInsertTimer(a0); - if (D_80334830->next == a0) { - __osSetTimerIntr(sp18); + t->mq = mq; + t->msg = msg; + time = __osInsertTimer(t); + if (__osTimerList->next == t) { + __osSetTimerIntr(time); } return 0; } diff --git a/lib/src/osSpTaskLoadGo.c b/lib/src/osSpTaskLoadGo.c index 88392c0b..2843b442 100644 --- a/lib/src/osSpTaskLoadGo.c +++ b/lib/src/osSpTaskLoadGo.c @@ -31,7 +31,7 @@ void osSpTaskLoad(OSTask *task) { task->t.flags &= ~M_TASK_FLAG0; #ifdef VERSION_SH if (physicalTask->t.flags & M_TASK_FLAG2) { - physicalTask->t.ucode = HW_REG((uintptr_t)task->t.yield_data_ptr + 0xBFC, u64*); + physicalTask->t.ucode = (u64*)HW_REG((uintptr_t)task->t.yield_data_ptr + 0xBFC, u64*); } #endif } diff --git a/lib/src/osTimer.c b/lib/src/osTimer.c index ffd0255f..2c13925b 100644 --- a/lib/src/osTimer.c +++ b/lib/src/osTimer.c @@ -1,88 +1,90 @@ #include "libultra_internal.h" -// TODO: document -OSTimer D_80365D80; -OSTimer *D_80334830 = &D_80365D80; -OSTime _osCurrentTime; -u32 D_80365DA8; +OSTimer __osBaseTimer; +OSTimer *__osTimerList = &__osBaseTimer; +OSTime __osCurrentTime; +u32 __osBaseCounter; u32 __osViIntrCount; -u32 D_80365DB0; +u32 __osTimerCounter; void __osTimerServicesInit(void) { - _osCurrentTime = 0; - D_80365DA8 = 0; + __osCurrentTime = 0; + __osBaseCounter = 0; __osViIntrCount = 0; - D_80334830->prev = D_80334830; - D_80334830->next = D_80334830->prev; - D_80334830->remaining = 0; - D_80334830->interval = D_80334830->remaining; - D_80334830->mq = NULL; - D_80334830->msg = NULL; + __osTimerList->prev = __osTimerList; + __osTimerList->next = __osTimerList->prev; + __osTimerList->remaining = 0; + __osTimerList->interval = __osTimerList->remaining; + __osTimerList->mq = NULL; + __osTimerList->msg = NULL; } void __osTimerInterrupt(void) { - OSTimer *sp24; - u32 sp20; - u32 sp1c; - if (D_80334830->next == D_80334830) { + OSTimer *t; + u32 count; + u32 elapsedCycles; + + if (__osTimerList->next == __osTimerList) { return; } + while (TRUE) { - sp24 = D_80334830->next; - if (sp24 == D_80334830) { + t = __osTimerList->next; + if (t == __osTimerList) { __osSetCompare(0); - D_80365DB0 = 0; + __osTimerCounter = 0; break; } - sp20 = osGetCount(); - sp1c = sp20 - D_80365DB0; - D_80365DB0 = sp20; - if (sp1c < sp24->remaining) { - sp24->remaining -= sp1c; - __osSetTimerIntr(sp24->remaining); + count = osGetCount(); + elapsedCycles = count - __osTimerCounter; + __osTimerCounter = count; + if (elapsedCycles < t->remaining) { + t->remaining -= elapsedCycles; + __osSetTimerIntr(t->remaining); return; } else { - sp24->prev->next = sp24->next; - sp24->next->prev = sp24->prev; - sp24->next = NULL; - sp24->prev = NULL; - if (sp24->mq != NULL) { - osSendMesg(sp24->mq, sp24->msg, OS_MESG_NOBLOCK); + t->prev->next = t->next; + t->next->prev = t->prev; + t->next = NULL; + t->prev = NULL; + if (t->mq != NULL) { + osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); } - if (sp24->interval != 0) { - sp24->remaining = sp24->interval; - __osInsertTimer(sp24); + if (t->interval != 0) { + t->remaining = t->interval; + __osInsertTimer(t); } } } } -void __osSetTimerIntr(u64 a0) { - u64 tmp; - s32 intDisabled = __osDisableInt(); - D_80365DB0 = osGetCount(); - tmp = a0 + D_80365DB0; - __osSetCompare(tmp); - __osRestoreInt(intDisabled); +void __osSetTimerIntr(OSTime time) { + OSTime newTime; + s32 savedMask = __osDisableInt(); + __osTimerCounter = osGetCount(); + newTime = time + __osTimerCounter; + __osSetCompare(newTime); + __osRestoreInt(savedMask); } -u64 __osInsertTimer(OSTimer *a0) { - OSTimer *sp34; - u64 sp28; - s32 intDisabled; - intDisabled = __osDisableInt(); - for (sp34 = D_80334830->next, sp28 = a0->remaining; sp34 != D_80334830 && sp28 > sp34->remaining; - sp28 -= sp34->remaining, sp34 = sp34->next) { +OSTime __osInsertTimer(OSTimer *t) { + OSTimer *timep; + OSTime time; + s32 savedMask; + + savedMask = __osDisableInt(); + for (timep = __osTimerList->next, time = t->remaining; timep != __osTimerList && time > timep->remaining; + time -= timep->remaining, timep = timep->next) { ; } - a0->remaining = sp28; - if (sp34 != D_80334830) { - sp34->remaining -= sp28; + t->remaining = time; + if (timep != __osTimerList) { + timep->remaining -= time; } - a0->next = sp34; - a0->prev = sp34->prev; - sp34->prev->next = a0; - sp34->prev = a0; - __osRestoreInt(intDisabled); - return sp28; + t->next = timep; + t->prev = timep->prev; + timep->prev->next = t; + timep->prev = t; + __osRestoreInt(savedMask); + return time; } diff --git a/lib/src/piint.h b/lib/src/piint.h index b3fee34e..f2793962 100644 --- a/lib/src/piint.h +++ b/lib/src/piint.h @@ -3,7 +3,7 @@ #include "PR/os_internal.h" #include "PR/rcp.h" #include "PR/os_pi.h" -#include "os.h" +#include "PR/os.h" //https://github.com/LuigiBlood/64dd/wiki/Memory-Map diff --git a/lib/src/unk_shindou_file_3.c b/lib/src/unk_shindou_file_3.c index 318e4068..d18e7b3c 100644 --- a/lib/src/unk_shindou_file_3.c +++ b/lib/src/unk_shindou_file_3.c @@ -1,7 +1,6 @@ #include "libultra_internal.h" #include "controller.h" -#ifdef VERSION_SH s32 func_8030A5C0(OSMesgQueue *arg0, s32 arg1) { // TODO: This is almost certainly __osPfsGetStatus. s32 sp34 = 0; OSMesg sp30; @@ -25,4 +24,3 @@ s32 func_8030A5C0(OSMesgQueue *arg0, s32 arg1) { // TODO: This is almost certain return sp34; } -#endif diff --git a/rename_sym.sh b/rename_sym.sh index 326dcb2e..639105b6 100755 --- a/rename_sym.sh +++ b/rename_sym.sh @@ -10,4 +10,4 @@ fi #echo "Replace $1 with $2?" #read -grep -rl "$1" text/**/*.{c,h} assets/**/*.c enhancements/*.patch lib/**/*.{c,h,s} asm/**/*.s bin/**/*.c data/*.c levels/**/*.{c,h} actors/**/*.c src/**/*.{c,h} include/**/*.{h,in} undefined_syms.txt | xargs sed -i "s/\b$1\b/$2/g" +grep -rl "$1" text/**/*.{c,h} assets/**/*.c enhancements/*.patch lib/**/*.{c,h,s} asm/**/*.s bin/**/*.c data/*.c levels/**/*.{c,h} actors/**/*.{c,h} src/**/*.{c,h} include/**/*.{h,in} undefined_syms.txt | xargs sed -i "s/\b$1\b/$2/g" diff --git a/rsp/audio.s b/rsp/audio.s index b10e8dbd..901a7d0d 100644 --- a/rsp/audio.s +++ b/rsp/audio.s @@ -53,15 +53,15 @@ dispatchTable: jumpTableEntry cmd_SPNOOP jumpTableEntry cmd_SETLOOP - jumpTableEntry cmd_17e4 - jumpTableEntry cmd_INTERL + jumpTableEntry cmd_DMEMMOVE2 + jumpTableEntry cmd_DOWNSAMPLE_HALF jumpTableEntry cmd_ENVSETUP1 jumpTableEntry cmd_ENVMIXER jumpTableEntry cmd_LOADBUFF jumpTableEntry cmd_SAVEBUFF jumpTableEntry cmd_ENVSETUP2 - jumpTableEntry cmd_1b78 + jumpTableEntry cmd_S8DEC jumpTableEntry cmd_HILOGAIN jumpTableEntry cmd_1c7c @@ -938,12 +938,12 @@ cmd_RESAMPLE: .endif addi $8, $8, -8 .ifdef VERSION_SH - sdv $v16[0], 0x00($8) + sdv $v16[0], 0x00($8) .endif @@audio_c410c: lsv $v23[14], 0x08($23) // saved pitch_accumulator .ifdef VERSION_SH - ldv $v16[0], 0x00($8) + ldv $v16[0], 0x00($8) .else ldv $v16[0], 0x00($23) // saved next 4 unprocessed samples sdv $v16[0], 0x00($8) // store them before the input samples @@ -1100,8 +1100,8 @@ cmd_RESAMPLE: mtc0 $zero, SP_SEMAPHORE .ifdef VERSION_SH -cmd_17e4: - srl $t7, $k0, 16 +cmd_DMEMMOVE2: + srl $t7, $k0, 16 andi $t7, $t7, 0xff andi $t5, $k0, 0xffff srl $t6, $t9, 0x10 @@ -1150,7 +1150,7 @@ cmd_DUPLICATE: j cmd_SPNOOP nop -cmd_INTERL: +cmd_DOWNSAMPLE_HALF: andi $t4, $k0, 0xffff andi $t6, $t9, 0xffff srl $t5, $t9, 0x10 @@ -1606,24 +1606,24 @@ cmd_MIXER: j cmd_SPNOOP nop -cmd_1b78: - lhu $13, 0x0(r24) +cmd_S8DEC: + lhu $13, (audio_in_buf)(r24) vxor $v2, $v2, $v2 - lhu $14, 0x2(r24) + lhu $14, (audio_out_buf)(r24) vxor $v3, $v3, $v3 - lhu $12, 0x4(r24) + lhu $12, (audio_count)(r24) sll $17, $25, 8 - srl $17, $17, 8 - sqv $v2[0], 0x0(r14) + srl $17, $17, 8 // state addr + sqv $v2[0], 0x0(r14) // store 0 to first 16 samples if A_INIT sqv $v3[0], 0x10(r14) srl $1, $26, 16 andi $1, $1, 0x1 - bgtz $1, @audio_4001bd8 + bgtz $1, @audio_4001bd8 // A_INIT srl $1, $26, 16 andi $1, $1, 0x2 - beq $0, $1, @audio_4001bbc + beq $0, $1, @audio_4001bbc // A_LOOP addi $2, $17, 0x0 - lw $2, 0x10(r24) + lw $2, (audio_loop_value)(r24) @audio_4001bbc: addi $1, $14, 0x0 jal dma_read_start @@ -1635,10 +1635,10 @@ cmd_1b78: mtc0 $0, sp_semaphore @audio_4001bd8: addi $14, $14, 0x20 - beq $12, $0, @audio_4001c04 + beq $12, $0, @audio_4001c04 // this of very few ops allows count=0 nop @audio_4001be4: - lpv $v2[0], 0x0(r13) + lpv $v2[0], 0x0(r13) // load each byte to upper 8 bits per elem lpv $v3[0], 0x8(r13) addi $13, $13, 0x10 addi $12, $12, 0xffe0 @@ -1647,7 +1647,7 @@ cmd_1b78: bgtz $12, @audio_4001be4 addi $14, $14, 0x20 @audio_4001c04: - addi $1, $14, 0xffe0 + addi $1, $14, 0xffe0 // write last 16 samples to the state addi $2, $17, 0x0 jal dma_write_start addi $3, $0, 0x1f diff --git a/sm64.ld b/sm64.ld index f9d769db..250de7a5 100755 --- a/sm64.ld +++ b/sm64.ld @@ -3,6 +3,7 @@ OUTPUT_ARCH (mips) /* include/segments.h defines SEG_POOL_START, SEG_POOL_END, SEG_BUFFERS, * SEG_GODDARD, SEG_MAIN, SEG_ENGINE, SEG_FRAMEBUFFERS */ #include "segments.h" +#include "config.h" #define BEGIN_SEG(name, addr) \ _##name##SegmentStart = ADDR(.name); \ @@ -94,7 +95,7 @@ SECTIONS BUILD_DIR/src/game/main.o(.text); BUILD_DIR/src/game/game_init.o(.text); BUILD_DIR/src/game/sound_init.o(.text); -#ifdef VERSION_SH +#if ENABLE_RUMBLE BUILD_DIR/src/game/rumble_init.o(.text); #endif BUILD_DIR/src/game/level_update.o(.text); @@ -144,11 +145,16 @@ SECTIONS BUILD_DIR/src/game/hud.o(.text); BUILD_DIR/src/game/obj_behaviors.o(.text); BUILD_DIR/src/game/obj_behaviors_2.o(.text); +#ifdef VERSION_SH + BUILD_DIR/src/audio/synthesis_sh.o(.text); +#else BUILD_DIR/src/audio/synthesis.o(.text); +#endif BUILD_DIR/src/audio/heap.o(.text); BUILD_DIR/src/audio/load.o(.text); #ifdef VERSION_SH - BUILD_DIR/src/audio/unk_shindou_audio_file.o(.text); + BUILD_DIR/src/audio/load_sh.o(.text); + BUILD_DIR/src/audio/port_sh.o(.text); #endif BUILD_DIR/src/audio/playback.o(.text); BUILD_DIR/src/audio/effects.o(.text); @@ -194,114 +200,115 @@ SECTIONS BUILD_DIR/libultra.a:osContStartReadData.o(.text); BUILD_DIR/libultra.a:osContInit.o(.text); BUILD_DIR/libultra.a:osEepromProbe.o(.text); -#ifdef VERSION_SH +#if ENABLE_RUMBLE BUILD_DIR/libultra.a:motor.o(.text); #endif BUILD_DIR/libultra.a:osInvalDCache.o(.text); BUILD_DIR/libultra.a:osPiStartDma.o(.text); - BUILD_DIR/libultra.a:bzero.o(.text) - BUILD_DIR/libultra.a:osInvalICache.o(.text) - BUILD_DIR/libultra.a:osEepromLongRead.o(.text) - BUILD_DIR/libultra.a:osEepromLongWrite.o(.text) - BUILD_DIR/libultra.a:bcopy.o(.text) - BUILD_DIR/libultra.a:guOrthoF.o(.text) - BUILD_DIR/libultra.a:guPerspectiveF.o(.text) - BUILD_DIR/libultra.a:llconv.o(.text) - BUILD_DIR/libultra.a:cosf.o(.text) - BUILD_DIR/libultra.a:sinf.o(.text) - BUILD_DIR/libultra.a:guTranslateF.o(.text) - BUILD_DIR/libultra.a:guRotateF.o(.text) - BUILD_DIR/libultra.a:guScaleF.o(.text) - BUILD_DIR/libultra.a:osAiSetFrequency.o(.text) + BUILD_DIR/libultra.a:bzero.o(.text); + BUILD_DIR/libultra.a:osInvalICache.o(.text); + BUILD_DIR/libultra.a:osEepromLongRead.o(.text); + BUILD_DIR/libultra.a:osEepromLongWrite.o(.text); + BUILD_DIR/libultra.a:bcopy.o(.text); + BUILD_DIR/libultra.a:guOrthoF.o(.text); + BUILD_DIR/libultra.a:guPerspectiveF.o(.text); + BUILD_DIR/libultra.a:llconv.o(.text); + BUILD_DIR/libultra.a:cosf.o(.text); + BUILD_DIR/libultra.a:sinf.o(.text); + BUILD_DIR/libultra.a:guTranslateF.o(.text); + BUILD_DIR/libultra.a:guRotateF.o(.text); + BUILD_DIR/libultra.a:guScaleF.o(.text); + BUILD_DIR/libultra.a:osAiSetFrequency.o(.text); #ifdef VERSION_SH - BUILD_DIR/libultra.a:osCartRomInit.o(.text) - BUILD_DIR/libultra.a:epidma.o(.text) -#else - BUILD_DIR/libultra.a:alBnkfNew.o(.text) + BUILD_DIR/libultra.a:osCartRomInit.o(.text); + BUILD_DIR/libultra.a:epidma.o(.text); #endif - BUILD_DIR/libultra.a:osAiGetLength.o(.text) - BUILD_DIR/libultra.a:osAiSetNextBuffer.o(.text) -#ifdef VERSION_SH - BUILD_DIR/libultra.a:osGetCount.o(.text) - BUILD_DIR/libultra.a:__osDisableInt.o(.text) - BUILD_DIR/libultra.a:__osRestoreInt.o(.text) -#endif - BUILD_DIR/libultra.a:_Litob.o(.text) - BUILD_DIR/libultra.a:_Ldtob.o(.text) - BUILD_DIR/libultra.a:__osSetSR.o(.text) - BUILD_DIR/libultra.a:__osGetSR.o(.text) - BUILD_DIR/libultra.a:__osSetFpcCsr.o(.text) - BUILD_DIR/libultra.a:__osSiRawReadIo.o(.text) - BUILD_DIR/libultra.a:__osSiRawWriteIo.o(.text) - BUILD_DIR/libultra.a:__osExceptionPreamble.o(.text) - BUILD_DIR/libultra.a:osWritebackDCache.o(.text) - BUILD_DIR/libultra.a:osMapTLBRdb.o(.text) - BUILD_DIR/libultra.a:osPiRawReadIo.o(.text) - BUILD_DIR/libultra.a:EU_D_802f4330.o(.text) - BUILD_DIR/libultra.a:D_802F4380.o(.text) - BUILD_DIR/libultra.a:func_802F4A20.o(.text) - BUILD_DIR/libultra.a:osTimer.o(.text) #ifdef VERSION_EU - BUILD_DIR/libultra.a:__osDisableInt.o(.text) - BUILD_DIR/libultra.a:__osRestoreInt.o(.text) - BUILD_DIR/libultra.a:osGetCount.o(.text) + BUILD_DIR/libultra.a:alBnkfNew.o(.text); #endif - BUILD_DIR/libultra.a:__osViInit.o(.text) - BUILD_DIR/libultra.a:__osDequeueThread.o(.text) - BUILD_DIR/libultra.a:osVirtualToPhysical.o(.text) - BUILD_DIR/libultra.a:__osSpSetStatus.o(.text) - BUILD_DIR/libultra.a:__osSpSetPc.o(.text) - BUILD_DIR/libultra.a:__osSpRawStartDma.o(.text) - BUILD_DIR/libultra.a:__osSpDeviceBusy.o(.text) - BUILD_DIR/libultra.a:__osSpGetStatus.o(.text) - BUILD_DIR/libultra.a:osGetThreadPri.o(.text) + BUILD_DIR/libultra.a:osAiGetLength.o(.text); + BUILD_DIR/libultra.a:osAiSetNextBuffer.o(.text); +#ifdef VERSION_SH + BUILD_DIR/libultra.a:osGetCount.o(.text); + BUILD_DIR/libultra.a:__osDisableInt.o(.text); + BUILD_DIR/libultra.a:__osRestoreInt.o(.text); +#endif + BUILD_DIR/libultra.a:_Litob.o(.text); + BUILD_DIR/libultra.a:_Ldtob.o(.text); + BUILD_DIR/libultra.a:__osSetSR.o(.text); + BUILD_DIR/libultra.a:__osGetSR.o(.text); + BUILD_DIR/libultra.a:__osSetFpcCsr.o(.text); + BUILD_DIR/libultra.a:__osSiRawReadIo.o(.text); + BUILD_DIR/libultra.a:__osSiRawWriteIo.o(.text); + BUILD_DIR/libultra.a:__osExceptionPreamble.o(.text); + BUILD_DIR/libultra.a:osWritebackDCache.o(.text); + BUILD_DIR/libultra.a:osMapTLBRdb.o(.text); + BUILD_DIR/libultra.a:osPiRawReadIo.o(.text); + BUILD_DIR/libultra.a:EU_D_802f4330.o(.text); + BUILD_DIR/libultra.a:D_802F4380.o(.text); + BUILD_DIR/libultra.a:func_802F4A20.o(.text); + BUILD_DIR/libultra.a:osTimer.o(.text); +#ifdef VERSION_EU + BUILD_DIR/libultra.a:__osDisableInt.o(.text); + BUILD_DIR/libultra.a:__osRestoreInt.o(.text); + BUILD_DIR/libultra.a:osGetCount.o(.text); +#endif + BUILD_DIR/libultra.a:__osViInit.o(.text); + BUILD_DIR/libultra.a:__osDequeueThread.o(.text); + BUILD_DIR/libultra.a:osVirtualToPhysical.o(.text); + BUILD_DIR/libultra.a:__osSpSetStatus.o(.text); + BUILD_DIR/libultra.a:__osSpSetPc.o(.text); + BUILD_DIR/libultra.a:__osSpRawStartDma.o(.text); + BUILD_DIR/libultra.a:__osSpDeviceBusy.o(.text); + BUILD_DIR/libultra.a:__osSpGetStatus.o(.text); + BUILD_DIR/libultra.a:osGetThreadPri.o(.text); BUILD_DIR/libultra.a:__osViGetCurrentContext.o(.text); - BUILD_DIR/libultra.a:__osViSwapContext.o(.text) + BUILD_DIR/libultra.a:__osViSwapContext.o(.text); #ifdef VERSION_SH - BUILD_DIR/libultra.a:osLeoDiskInit.o(.text) + BUILD_DIR/libultra.a:osLeoDiskInit.o(.text); #endif - BUILD_DIR/libultra.a:__osPiCreateAccessQueue.o(.text) - BUILD_DIR/libultra.a:osPiRawStartDma.o(.text) - BUILD_DIR/libultra.a:osEPiRawStartDma.o(.text) - BUILD_DIR/libultra.a:__osDevMgrMain.o(.text) - BUILD_DIR/libultra.a:__osSiCreateAccessQueue.o(.text) - BUILD_DIR/libultra.a:__osSiRawStartDma.o(.text) - BUILD_DIR/libultra.a:osSetTimer.o(.text) - BUILD_DIR/libultra.a:osEepromWrite.o(.text) -#ifdef VERSION_SH - BUILD_DIR/libultra.a:osPfsIsPlug.o(.text) - BUILD_DIR/libultra.a:crc.o(.text) - BUILD_DIR/libultra.a:contramwrite.o(.text) - BUILD_DIR/libultra.a:contramread.o(.text) + BUILD_DIR/libultra.a:__osPiCreateAccessQueue.o(.text); + BUILD_DIR/libultra.a:osPiRawStartDma.o(.text); + BUILD_DIR/libultra.a:osEPiRawStartDma.o(.text); + BUILD_DIR/libultra.a:__osDevMgrMain.o(.text); + BUILD_DIR/libultra.a:__osSiCreateAccessQueue.o(.text); + BUILD_DIR/libultra.a:__osSiRawStartDma.o(.text); + BUILD_DIR/libultra.a:osSetTimer.o(.text); + BUILD_DIR/libultra.a:osEepromWrite.o(.text); +#if ENABLE_RUMBLE + BUILD_DIR/libultra.a:osPfsIsPlug.o(.text); + BUILD_DIR/libultra.a:crc.o(.text); + BUILD_DIR/libultra.a:contramwrite.o(.text); + BUILD_DIR/libultra.a:contramread.o(.text); #endif - BUILD_DIR/libultra.a:osJamMesg.o(.text) - BUILD_DIR/libultra.a:osPiGetCmdQueue.o(.text) - BUILD_DIR/libultra.a:osEepromRead.o(.text) - BUILD_DIR/libultra.a:guMtxF2L.o(.text) - BUILD_DIR/libultra.a:guNormalize.o(.text) + BUILD_DIR/libultra.a:osJamMesg.o(.text); + BUILD_DIR/libultra.a:osPiGetCmdQueue.o(.text); + BUILD_DIR/libultra.a:osEepromRead.o(.text); + BUILD_DIR/libultra.a:guMtxF2L.o(.text); + BUILD_DIR/libultra.a:guNormalize.o(.text); BUILD_DIR/libultra.a:__osAiDeviceBusy.o(.text); - BUILD_DIR/libultra.a:ldiv.o(.text) + BUILD_DIR/libultra.a:ldiv.o(.text); BUILD_DIR/libultra.a:__osSiDeviceBusy.o(.text); #ifdef VERSION_SH - BUILD_DIR/libultra.a:leointerrupt.o(.text) + BUILD_DIR/libultra.a:leointerrupt.o(.text); #endif - BUILD_DIR/libultra.a:osSetIntMask.o(.text) - BUILD_DIR/libultra.a:osDestroyThread.o(.text) -#ifndef VERSION_SH - BUILD_DIR/libultra.a:osLeoDiskInit.o(.text) + BUILD_DIR/libultra.a:osSetIntMask.o(.text); + BUILD_DIR/libultra.a:osDestroyThread.o(.text); +#ifdef VERSION_EU + BUILD_DIR/libultra.a:osLeoDiskInit.o(.text); #endif - BUILD_DIR/libultra.a:__osSetCompare.o(.text) - BUILD_DIR/libultra.a:__osDequeueThread.o(.text) - BUILD_DIR/libultra.a:__osProbeTLB.o(.text) - BUILD_DIR/libultra.a:__osResetGlobalIntMask.o(.text) - BUILD_DIR/libultra.a:__osEPiRawWriteIo.o(.text) + BUILD_DIR/libultra.a:__osSetCompare.o(.text); + BUILD_DIR/libultra.a:__osDequeueThread.o(.text); + BUILD_DIR/libultra.a:__osProbeTLB.o(.text); + BUILD_DIR/libultra.a:__osResetGlobalIntMask.o(.text); + BUILD_DIR/libultra.a:__osEPiRawWriteIo.o(.text); #ifdef VERSION_SH - BUILD_DIR/libultra.a:__osEPiRawReadIo.o(.text) - BUILD_DIR/libultra.a:__osSetGlobalIntMask.o(.text) + BUILD_DIR/libultra.a:__osEPiRawReadIo.o(.text); + BUILD_DIR/libultra.a:__osSetGlobalIntMask.o(.text); #endif - BUILD_DIR/libultra.a:func_802F71F0.o(.text) -#ifdef VERSION_SH - BUILD_DIR/libultra.a:unk_shindou_file_3.o(.text) + BUILD_DIR/libultra.a:func_802F71F0.o(.text); +#if ENABLE_RUMBLE + BUILD_DIR/libultra.a:unk_shindou_file_3.o(.text); #endif BUILD_DIR/lib/rsp.o(.text); #else @@ -335,6 +342,9 @@ SECTIONS BUILD_DIR/libultra.a:osContStartReadData.o(.text); BUILD_DIR/libultra.a:osContInit.o(.text); BUILD_DIR/libultra.a:osEepromProbe.o(.text); +#if ENABLE_RUMBLE + BUILD_DIR/libultra.a:motor.o(.text); +#endif BUILD_DIR/libultra.a:llmuldiv.o(.text); BUILD_DIR/libultra.a:llmuldiv_gcc.o(.text); BUILD_DIR/libultra.a:osInvalDCache.o(.text); @@ -393,6 +403,12 @@ SECTIONS BUILD_DIR/libultra.a:__osSiRawStartDma.o(.text); BUILD_DIR/libultra.a:osSetTimer.o(.text); BUILD_DIR/libultra.a:osEepromWrite.o(.text); +#if ENABLE_RUMBLE + BUILD_DIR/libultra.a:osPfsIsPlug.o(.text); + BUILD_DIR/libultra.a:crc.o(.text); + BUILD_DIR/libultra.a:contramwrite.o(.text); + BUILD_DIR/libultra.a:contramread.o(.text); +#endif BUILD_DIR/libultra.a:osJamMesg.o(.text); BUILD_DIR/libultra.a:osPiGetCmdQueue.o(.text); BUILD_DIR/libultra.a:osEepromRead.o(.text); @@ -413,6 +429,9 @@ SECTIONS BUILD_DIR/libultra.a:__osGetCause.o(.text); BUILD_DIR/libultra.a:__osAtomicDec.o(.text); BUILD_DIR/libultra.a:guLookAtRef.o(.text); /* Fast3DEX2 only */ +#if ENABLE_RUMBLE + BUILD_DIR/libultra.a:unk_shindou_file_3.o(.text); +#endif BUILD_DIR/lib/rsp.o(.text); #endif @@ -421,7 +440,7 @@ SECTIONS BUILD_DIR/src/game/main.o(.data*); BUILD_DIR/src/game/game_init.o(.data*); BUILD_DIR/src/game/sound_init.o(.data*); -#ifdef VERSION_SH +#if ENABLE_RUMBLE BUILD_DIR/src/game/rumble_init.o(.data*); #endif BUILD_DIR/src/game/level_update.o(.data*); @@ -465,18 +484,20 @@ SECTIONS /* wildcard doesn't match on EU due to files being moved to engine/ */ BUILD_DIR/src/game*.o(.data*); #endif +#ifdef VERSION_SH + BUILD_DIR/src/audio/synthesis_sh.o(.data*); +#else BUILD_DIR/src/audio/synthesis.o(.data*); - BUILD_DIR/src/audio/heap.o(.data*); -#ifndef VERSION_SH - BUILD_DIR/src/audio/load.o(.data*); #endif + BUILD_DIR/src/audio/heap.o(.data*); + BUILD_DIR/src/audio/load.o(.data*); BUILD_DIR/src/audio/playback.o(.data*); BUILD_DIR/src/audio/effects.o(.data*); BUILD_DIR/src/audio/seqplayer.o(.data*); #ifdef VERSION_SH BUILD_DIR/src/audio/data.o(.data*); BUILD_DIR/src/audio/shindou_debug_prints.o(.data*); - BUILD_DIR/src/audio/unk_shindou_audio_file.o(.data*); + BUILD_DIR/src/audio/port_sh.o(.data*); BUILD_DIR/src/audio/external.o(.data*); BUILD_DIR/src/audio/audio_session_presets_sh.o(.data*); #else @@ -492,7 +513,7 @@ SECTIONS BUILD_DIR/libultra.a:osViTable.o(.data*); BUILD_DIR/libultra.a:osCreatePiManager.o(.data*); BUILD_DIR/libultra.a:osContInit.o(.data*); -#ifdef VERSION_SH +#if ENABLE_RUMBLE BUILD_DIR/libultra.a:motor.o(.data*); #endif BUILD_DIR/libultra.a:osAiSetNextBuffer.o(.data*); @@ -510,6 +531,9 @@ SECTIONS BUILD_DIR/libultra.a:osCreatePiManager.o(.data*); BUILD_DIR/libultra.a:osInitialize.o(.data*); BUILD_DIR/libultra.a:osContInit.o(.data*); +#if ENABLE_RUMBLE + BUILD_DIR/libultra.a:motor.o(.data*); +#endif BUILD_DIR/libultra.a:osAiSetNextBuffer.o(.data*); BUILD_DIR/libultra.a:osTimer.o(.data*); BUILD_DIR/libultra.a:_Printf.o(.data*); @@ -556,8 +580,8 @@ SECTIONS BUILD_DIR/src/game/object_collision.o(.rodata*); BUILD_DIR/src/game/spawn_object.o(.rodata*); #endif - BUILD_DIR/libultra.a:__osDisableInt.o(.text) - BUILD_DIR/libultra.a:__osRestoreInt.o(.text) + BUILD_DIR/libultra.a:__osDisableInt.o(.text); + BUILD_DIR/libultra.a:__osRestoreInt.o(.text); BUILD_DIR/src/game/spawn_sound.o(.rodata*); BUILD_DIR/src/game/debug.o(.rodata*); BUILD_DIR/src/game/screen_transition.o(.rodata*); @@ -577,11 +601,15 @@ SECTIONS #if defined(VERSION_JP) || defined(VERSION_US) BUILD_DIR/src/game*.o(.rodata*); #endif +#ifdef VERSION_SH + BUILD_DIR/src/audio/synthesis_sh.o(.rodata*); + BUILD_DIR/src/audio/heap.o(.rodata*); + BUILD_DIR/src/audio/load_sh.o(.rodata*); + BUILD_DIR/src/audio/port_sh.o(.rodata*); +#else BUILD_DIR/src/audio/synthesis.o(.rodata*); BUILD_DIR/src/audio/heap.o(.rodata*); BUILD_DIR/src/audio/load.o(.rodata*); -#ifdef VERSION_SH - BUILD_DIR/src/audio/unk_shindou_audio_file.o(.rodata*); #endif BUILD_DIR/src/audio/playback.o(.rodata*); BUILD_DIR/src/audio/effects.o(.rodata*); @@ -619,8 +647,9 @@ SECTIONS #ifndef VERSION_EU BUILD_DIR/libultra.a:*.o(.rodata*); #endif + /* audio blobs, should really be moved into a separate file */ #ifdef VERSION_SH - BUILD_DIR/src/audio/load.o(.data*); + BUILD_DIR/src/audio/load_sh.o(.data*); #endif BUILD_DIR/lib/rsp.o(.rodata*); } @@ -631,7 +660,7 @@ SECTIONS BUILD_DIR/src/game/main.o(.bss*); BUILD_DIR/src/game/game_init.o(.bss*); BUILD_DIR/src/game/sound_init.o(.bss*); -#ifdef VERSION_SH +#if ENABLE_RUMBLE BUILD_DIR/src/game/rumble_init.o(.bss*); #endif BUILD_DIR/src/game/level_update.o(.bss*); @@ -662,7 +691,7 @@ SECTIONS BUILD_DIR/src/game/ingame_menu.o(.bss*); BUILD_DIR/src/game/envfx_snow.o(.bss*); BUILD_DIR/src/game/envfx_bubbles.o(.bss*); - BUILD_DIR/src/game/macro_special_objects.o(.bss*) + BUILD_DIR/src/game/macro_special_objects.o(.bss*); BUILD_DIR/src/game/hud.o(.bss*); BUILD_DIR/src/game/obj_behaviors.o(.bss*); BUILD_DIR/src/game/obj_behaviors_2.o(.bss*); @@ -675,9 +704,9 @@ SECTIONS #endif #ifdef VERSION_SH BUILD_DIR/src/audio/globals_start.o(.bss*); - BUILD_DIR/src/audio/synthesis.o(.bss*); + BUILD_DIR/src/audio/synthesis_sh.o(.bss*); BUILD_DIR/src/audio/heap.o(.bss*); - BUILD_DIR/src/audio/load.o(.bss*); + BUILD_DIR/src/audio/load_sh.o(.bss*); BUILD_DIR/src/audio/data.o(.bss*); #endif @@ -689,23 +718,23 @@ SECTIONS BUILD_DIR/libultra.a:osCreatePiManager.o(.bss*); BUILD_DIR/libultra.a:osContStartReadData.o(.bss*); BUILD_DIR/libultra.a:osContInit.o(.bss*); -#ifdef VERSION_SH +#if ENABLE_RUMBLE BUILD_DIR/libultra.a:motor.o(.bss*); #endif BUILD_DIR/libultra.a:guRotateF.o(.bss*); #ifdef VERSION_SH BUILD_DIR/libultra.a:osCartRomInit.o(.bss*); #endif -#ifndef VERSION_SH +#ifdef VERSION_EU BUILD_DIR/libultra.a:leointerrupt.o(.bss*); #endif BUILD_DIR/libultra.a:osTimer.o(.bss*); #ifdef VERSION_SH - BUILD_DIR/libultra.a:osLeoDiskInit.o(.bss*) + BUILD_DIR/libultra.a:osLeoDiskInit.o(.bss*); #endif BUILD_DIR/libultra.a:__osPiCreateAccessQueue.o(.bss*); BUILD_DIR/libultra.a:__osSiCreateAccessQueue.o(.bss*); -#ifdef VERSION_SH +#if ENABLE_RUMBLE BUILD_DIR/libultra.a:osPfsIsPlug.o(.bss*); #endif BUILD_DIR/libultra.a:osEepromWrite.o(.bss*); @@ -713,8 +742,8 @@ SECTIONS #ifdef VERSION_SH BUILD_DIR/libultra.a:leointerrupt.o(.bss*); #endif -#ifndef VERSION_SH - BUILD_DIR/libultra.a:osLeoDiskInit.o(.bss*) +#ifdef VERSION_EU + BUILD_DIR/libultra.a:osLeoDiskInit.o(.bss*); #endif BUILD_DIR/libultra.a:_Printf.o(.bss*); BUILD_DIR/libultra.a:osAiSetNextBuffer.o(.bss*); @@ -727,11 +756,17 @@ SECTIONS BUILD_DIR/libultra.a:osInitialize.o(.bss*); BUILD_DIR/libultra.a:osContStartReadData.o(.bss*); BUILD_DIR/libultra.a:osContInit.o(.bss*); +#if ENABLE_RUMBLE + BUILD_DIR/libultra.a:motor.o(.bss*); +#endif BUILD_DIR/libultra.a:guRotateF.o(.bss*); BUILD_DIR/libultra.a:osTimer.o(.bss*); BUILD_DIR/libultra.a:_Printf.o(.bss*); BUILD_DIR/libultra.a:__osPiCreateAccessQueue.o(.bss*); BUILD_DIR/libultra.a:__osSiCreateAccessQueue.o(.bss*); +#if ENABLE_RUMBLE + BUILD_DIR/libultra.a:osPfsIsPlug.o(.bss*); +#endif BUILD_DIR/libultra.a:osEepromWrite.o(.bss*); BUILD_DIR/libultra.a:kdebugserver_stack.o(.bss*); BUILD_DIR/libultra.a:kdebugserver.o(.bss*); @@ -816,7 +851,6 @@ SECTIONS __expansionRamStart = 0x80400000; ASSERT((. <= __expansionRamStart), "Error: RDRAM expanded into Expansion RAM, despite Expansion RAM not being defined.") - BEGIN_SEG(entry, 0x10000000) { BUILD_DIR/levels/entry.o(.data); @@ -867,7 +901,7 @@ SECTIONS /* 0x8016F000 21D7D0-255EC0 [386F0] */ BEGIN_SEG(goddard, SEG_GODDARD) { - BUILD_DIR/src/menu/level_select_menu.o(.text); + BUILD_DIR/src/menu/title_screen.o(.text); BUILD_DIR/src/menu/intro_geo.o(.text); BUILD_DIR/src/menu/file_select.o(.text); BUILD_DIR/src/menu/star_select.o(.text); @@ -889,8 +923,8 @@ SECTIONS BUILD_DIR/libgoddard.a:renderer.o(.text); BUILD_DIR/libgoddard.a:*.o(.text); /* data, rodata, per file */ - BUILD_DIR/src/menu/level_select_menu.o(.data*); - BUILD_DIR/src/menu/level_select_menu.o(.rodata*); + BUILD_DIR/src/menu/title_screen.o(.data*); + BUILD_DIR/src/menu/title_screen.o(.rodata*); BUILD_DIR/src/menu/intro_geo.o(.data*); BUILD_DIR/src/menu/file_select.o(.data*); BUILD_DIR/src/menu/file_select.o(.rodata*); @@ -956,14 +990,12 @@ SECTIONS { BUILD_DIR/src/buffers/buffers.o(.bss*); BUILD_DIR/src/audio/globals_start.o(.bss*); -#ifndef VERSION_SH +#ifdef VERSION_SH + BUILD_DIR/src/audio/port_sh.o(.bss*); +#else BUILD_DIR/src/audio/synthesis.o(.bss*); BUILD_DIR/src/audio/heap.o(.bss*); -#endif BUILD_DIR/src/audio/load.o(.bss*); -#ifdef VERSION_SH - BUILD_DIR/src/audio/unk_shindou_audio_file.o(.bss*); -#else BUILD_DIR/src/audio/data.o(.bss*); #endif BUILD_DIR/src/audio*.o(.bss*); @@ -974,15 +1006,14 @@ SECTIONS . = ALIGN(0x1000); #endif #ifdef VERSION_SH - . = . + 0xB000; + . += 0xB000; #endif BUILD_DIR/src/buffers/gfx_output_buffer.o(.bss*); } END_NOLOAD(buffers) -#ifndef VERSION_SH ASSERT((. <= SEG_MAIN), "Error: buffers segment extended into main") -#endif + /* 0x268020 0x268020-0 [0] */ BEGIN_SEG(intro, 0x14000000) { @@ -1094,5 +1125,3 @@ SECTIONS *(*); } } -EXTERN(osPfsIsPlug) -EXTERN(__osLeoInterrupt) diff --git a/sound/sequences/00_sound_player.s b/sound/sequences/00_sound_player.s index a5f6b91c..1d1e0173 100644 --- a/sound/sequences/00_sound_player.s +++ b/sound/sequences/00_sound_player.s @@ -1,22 +1,16 @@ -.include "seq_macros.inc" +#include "seq_macros.inc" + .section .rodata .align 0 + sequence_start: - -.ifdef VERSION_SH - .set VERSION_EU_SH, 1 -.endif -.ifdef VERSION_EU - .set VERSION_EU_SH, 1 -.endif - seq_setmutebhv 0x60 seq_setmutescale 0 -.ifdef VERSION_SH +#ifdef VERSION_SH seq_setvol 100 -.else +#else seq_setvol 127 -.endif +#endif seq_settempo 120 seq_initchannels 0x3ff seq_startchannel 0, .channel0 @@ -77,7 +71,7 @@ chan_stereoheadseteffects 1 chan_setdyntable .channel59_table chan_jump .main_loop_023589 -# Main loop for standard, non-continuous sound effects +// Main loop for standard, non-continuous sound effects .main_loop_023589: chan_delay1 chan_ioreadval 0 @@ -91,17 +85,17 @@ chan_iowriteval 5 chan_ioreadval 4 chan_dyncall -# keep looping until layer 0 finishes or we are told to stop or to play something else +// keep looping until layer 0 finishes or we are told to stop or to play something else .poll_023589: chan_delay1 chan_ioreadval 0 -chan_bltz .skip_023589 /* if we have a signal: */ - chan_beqz .force_stop_023589 /* told to stop */ - chan_jump .start_playing_023589 /* told to play something else */ +chan_bltz .skip_023589 // if we have a signal: + chan_beqz .force_stop_023589 // told to stop + chan_jump .start_playing_023589 // told to play something else .skip_023589: chan_testlayerfinished 0 -chan_beqz .poll_023589 /* if layer 0 hasn't finished, keep polling */ -chan_jump .main_loop_023589 /* otherwise go back to the main loop */ +chan_beqz .poll_023589 // if layer 0 hasn't finished, keep polling +chan_jump .main_loop_023589 // otherwise go back to the main loop .force_stop_023589: chan_freelayer 0 chan_freelayer 1 @@ -144,7 +138,7 @@ chan_stereoheadseteffects 1 chan_setdyntable .channel6_table chan_jump .main_loop_146 -# Main loop for moving, env and air sound effects, which play continuously +// Main loop for moving, env and air sound effects, which play continuously .main_loop_146: chan_delay1 chan_ioreadval 0 @@ -159,7 +153,7 @@ chan_iowriteval 5 chan_ioreadval 4 chan_dyncall -# keep looping until we are told to stop or to play something else +// keep looping until we are told to stop or to play something else .poll_146: chan_delay1 chan_ioreadval 0 @@ -181,7 +175,7 @@ chan_iowriteval 5 chan_stereoheadseteffects 1 chan_setdyntable .channel7_table -# Loop for menu sound effects +// Loop for menu sound effects .main_loop_7: chan_delay1 chan_ioreadval 0 @@ -198,19 +192,19 @@ chan_setpanmix 127 chan_ioreadval 4 chan_dyncall -# keep looping until layer 0 finishes or we are told to stop or to play something else +// keep looping until layer 0 finishes or we are told to stop or to play something else .poll_7: chan_delay1 chan_ioreadval 0 -chan_bltz .skip_7 /* if we have a signal: */ - chan_beqz .force_stop_7 /* told to stop */ +chan_bltz .skip_7 // if we have a signal: + chan_beqz .force_stop_7 // told to stop chan_unreservenotes - chan_jump .start_playing_7 /* told to play something else */ + chan_jump .start_playing_7 // told to play something else .skip_7: chan_testlayerfinished 0 -chan_beqz .poll_7 /* if layer 0 hasn't finished, keep polling */ +chan_beqz .poll_7 // if layer 0 hasn't finished, keep polling chan_unreservenotes -chan_jump .main_loop_7 /* otherwise go back to the main loop */ +chan_jump .main_loop_7 // otherwise go back to the main loop .force_stop_7: chan_freelayer 0 chan_freelayer 1 @@ -218,7 +212,7 @@ chan_freelayer 2 chan_unreservenotes chan_jump .main_loop_7 -# Delay for a number of ticks (1-255) in an interruptible manner. +// Delay for a number of ticks (1-255) in an interruptible manner. .delay: chan_writeseq_nextinstr 0, 1 chan_loop 20 @@ -233,15 +227,15 @@ chan_end chan_setpanmix 127 chan_setvolscale 127 chan_setvibratoextent 0 -chan_ioreadval 1 /* IO slots 0-3 are reset to -1 when read; restore the value */ +chan_ioreadval 1 // IO slots 0-3 are reset to -1 when read; restore the value chan_iowriteval 0 -chan_break /* break out of the loop */ -chan_break /* force the caller to return immediately */ +chan_break // break out of the loop +chan_break // force the caller to return immediately chan_end -# Set reverb in way that takes area echo level and volume into account. This -# is done by writing to IO slot 5 and letting get_sound_reverb in external.c -# do the necessary math. +// Set reverb in way that takes area echo level and volume into account. This +// is done by writing to IO slot 5 and letting get_sound_reverb in external.c +// do the necessary math. .set_reverb: chan_writeseq_nextinstr 0, 1 chan_setreverb 10 @@ -342,15 +336,15 @@ sound_ref .sound_action_bounce_off_object sound_ref .chan_7ED sound_ref .sound_action_read_sign sound_ref .chan_810 -.ifdef VERSION_JP +#ifdef VERSION_JP sound_ref .sound_action_jump_default sound_ref .sound_action_jump_default sound_ref .sound_action_jump_default -.else +#else sound_ref .chan_828 sound_ref .sound_action_intro_unk45e sound_ref .sound_action_intro_unk45f -.endif +#endif sound_ref .sound_action_heavy_landing_default sound_ref .sound_action_heavy_landing_grass sound_ref .sound_action_heavy_landing_water @@ -988,7 +982,7 @@ layer_portamento 0x81, 42, 255 layer_note1 37, 0x1e, 105 layer_end -.sound_action_climb_down_tree: # unused +.sound_action_climb_down_tree: // unused chan_setbank 0 chan_setinstr 1 chan_setlayer 0, .layer_579 @@ -999,7 +993,7 @@ layer_portamento 0x81, 44, 255 layer_note1 40, 0xb4, 100 layer_end -.chan_582: # unused +.chan_582: // unused chan_setbank 0 chan_setinstr 2 chan_setlayer 0, .layer_58A @@ -1418,8 +1412,8 @@ layer_note1 39, 0xa, 127 layer_note1 42, 0x8, 127 layer_end -.ifndef VERSION_JP - .chan_828: # unused +#ifndef VERSION_JP + .chan_828: // unused chan_setbank 7 chan_setinstr 3 chan_setlayer 0, .layer_83C @@ -1464,7 +1458,7 @@ layer_end .layer_871: layer_transpose 8 layer_jump .layer_776 -.endif +#endif .sound_action_heavy_landing_default: chan_call .heavy_landing_common @@ -2029,7 +2023,7 @@ sound_ref .sound_mario_punch_wah sound_ref .sound_mario_uh sound_ref .sound_mario_hrmm sound_ref .sound_mario_wah2 -.ifdef VERSION_JP +#ifdef VERSION_JP sound_ref .sound_mario_jump_hoo sound_ref .sound_mario_jump_hoo sound_ref .sound_mario_jump_hoo @@ -2046,7 +2040,7 @@ sound_ref .sound_mario_wah2 sound_ref .sound_mario_jump_hoo sound_ref .sound_mario_jump_hoo sound_ref .sound_mario_jump_hoo -.else +#else sound_ref .sound_peach_dear_mario sound_ref .sound_mario_jump_hoo sound_ref .sound_mario_jump_hoo @@ -2071,7 +2065,7 @@ sound_ref .sound_mario_wah2 sound_ref .sound_peach_bake_a_cake sound_ref .sound_peach_for_mario sound_ref .sound_peach_mario2 -.endif +#endif .sound_mario_jump_hoo: chan_setbank 8 @@ -2080,9 +2074,9 @@ chan_setlayer 0, .layer_C3C chan_end .layer_C3C: -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) layer_transpose 2 -.endif +#endif layer_portamento 0x82, 41, 127 layer_note1 37, 0x14, 127 layer_end @@ -2119,9 +2113,9 @@ chan_setlayer 0, .layer_C6C chan_end .layer_C6C: -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) layer_transpose 1 -.endif +#endif layer_portamento 0x82, 44, 200 layer_note1 39, 0x30, 127 layer_end @@ -2482,7 +2476,7 @@ chan_end layer_transpose -1 layer_jump .layer_C4E -.ifndef VERSION_JP +#ifndef VERSION_JP .sound_peach_dear_mario: chan_setbank 10 chan_setinstr 15 @@ -2697,9 +2691,9 @@ layer_jump .layer_C4E .layer_F8A: layer_note1 39, 0x50, 127 layer_end -.endif +#endif -.ifdef VERSION_EU_SH +#if defined(VERSION_EU) || defined(VERSION_SH) .chan_unused_F9A_eu: chan_setbank 8 chan_setinstr 0 @@ -2709,7 +2703,7 @@ layer_jump .layer_C4E .layer_FA2_eu: layer_delay 0x5 layer_end -.endif +#endif .channel38_table: sound_ref .sound_general_activate_cap_switch @@ -2830,7 +2824,7 @@ sound_ref .sound_general_boing3 sound_ref .sound_general_grand_star sound_ref .sound_general_grand_star_jump sound_ref .sound_general_boat_rock -.ifdef VERSION_JP +#ifdef VERSION_JP sound_ref .sound_menu_enter_hole sound_ref .sound_menu_enter_hole sound_ref .sound_menu_enter_hole @@ -2841,7 +2835,7 @@ sound_ref .sound_general_boat_rock sound_ref .sound_general_bubbles sound_ref .sound_menu_enter_hole sound_ref .sound_menu_enter_hole -.else +#else sound_ref .sound_general_vanish_sfx sound_ref .sound_menu_enter_hole sound_ref .sound_general_red_coin @@ -2852,7 +2846,7 @@ sound_ref .sound_general_boat_rock sound_ref .sound_general_boing2 sound_ref .sound_general_yoshi_walk sound_ref .sound_general_enemy_alert1 -.endif +#endif .sound_general_activate_cap_switch: chan_setbank 5 @@ -3408,17 +3402,17 @@ chan_setbank 9 chan_setinstr 3 chan_setval 40 chan_call .set_reverb -.ifdef VERSION_SH +#ifdef VERSION_SH chan_setreverb 40 -.endif +#endif chan_setlayer 0, .layer_141A chan_end .layer_141A: layer_transpose 24 -.ifdef VERSION_SH +#ifdef VERSION_SH layer_note1 51, 0xc, 90 -.endif +#endif layer_note1 39, 0x4, 90 layer_note1 51, 0xc, 90 layer_note1 39, 0x4, 50 @@ -3487,18 +3481,18 @@ layer_end .sound_general_chain_chomp2: chan_setbank 7 -.ifdef VERSION_JP +#ifdef VERSION_JP chan_setinstr 8 -.else +#else chan_setinstr 14 -.endif +#endif chan_setval 15 chan_call .set_reverb chan_setlayer 0, .layer_14C6 chan_setlayer 1, .layer_14E3 -.ifndef VERSION_JP +#ifndef VERSION_JP chan_setlayer 2, .layer_14E3 -.endif +#endif chan_setval 1 chan_call .delay chan_setenvelope .envelope_3368 @@ -3507,11 +3501,11 @@ chan_setinstr 7 chan_setval 13 chan_call .delay chan_setbank 7 -.ifdef VERSION_JP +#ifdef VERSION_JP chan_setinstr 8 -.else +#else chan_setinstr 14 -.endif +#endif chan_end .layer_14C6: @@ -3527,12 +3521,12 @@ layer_end .layer_14E3: layer_loop 2 -.ifdef VERSION_JP +#ifdef VERSION_JP layer_portamento 0x81, 36, 255 layer_note1 24, 0x18, 127 -.else +#else layer_note1 34, 0x19, 100 -.endif +#endif layer_loopend layer_end @@ -4154,24 +4148,27 @@ layer_note1 31, 0x14, 127 layer_end .sound_general_red_coin: -.ifdef VERSION_JP +#ifdef VERSION_JP chan_setbank 9 chan_setinstr 3 chan_setlayer 0, .layer_1909 chan_setlayer 1, .layer_1902 chan_setlayer 2, .layer_1907 -.else - .ifdef VERSION_EU_SH +#else + #if defined(VERSION_EU) || defined(VERSION_SH) chan_setbank 9 chan_setinstr 3 - .else + #else chan_setinstr 128 - .endif + #endif chan_setenvelope .envelope_3378 + // Small bugfix: .main_loop_023589 expects layer 0 to live the longest. + // I don't think this actually makes any audible difference given the + // silence at the end. chan_setlayer 0, .layer_1907 chan_setlayer 1, .layer_1902 chan_setlayer 2, .layer_1909 -.endif +#endif chan_end .layer_1902: @@ -4191,6 +4188,12 @@ layer_note0 58, 0x10, 100, 80 layer_note0 58, 0x10, 60, 80 layer_note0 58, 0x10, 40, 80 layer_note0 58, 0x10, 25, 80 +// This small delay should not have any effect, but decreases the probability of +// encountering double red coin glitch. Without it, layer 0 finishes in 1.04 +// seconds, and with some bad luck around scheduling/lag the sound spawner with +// a lifetime of 30 frames that creates the sound may deactivate on the same +// frame. That leads to double sound glitch on JP, see src/audio/external.c. +// With the delay, the same thing can still happen but requires more CPU lag. layer_delay 0xa layer_end @@ -4422,7 +4425,7 @@ layer_portamento 0x81, 36, 40 layer_note1 41, 0xc, 127 layer_end -.ifdef VERSION_JP +#ifdef VERSION_JP .sound_general_boat_rock: chan_setbank 9 chan_setinstr 0 @@ -4438,7 +4441,7 @@ layer_end layer_portamento 0x1, 32, 0x7f layer_note1 60, 0x28, 100 layer_end -.else +#else .sound_general_boat_rock: chan_setbank 4 chan_setinstr 2 @@ -4476,7 +4479,7 @@ layer_end layer_portamento 0x81, 19, 255 layer_note1 31, 0x32, 115 layer_end -.endif +#endif .channel4_table: sound_ref .sound_env_waterfall1 @@ -4525,21 +4528,21 @@ chan_setbank 5 chan_setinstr 1 chan_setval 25 chan_call .set_reverb -.ifdef VERSION_JP +#ifdef VERSION_JP chan_setenvelope .envelope_32E4 -.else +#else chan_setenvelope .envelope_32C4 -.endif +#endif chan_setlayer 0, .layer_1B53 chan_end .layer_1B53: layer_somethingon -.ifdef VERSION_JP +#ifdef VERSION_JP layer_delay 0x6 -.else +#else layer_delay 0x4 -.endif +#endif .layer_1B56: layer_note1 41, 0x12c, 95 layer_jump .layer_1B56 @@ -4694,11 +4697,11 @@ chan_end .layer_1C69: layer_portamento 0x81, 15, 255 -.ifdef VERSION_JP +#ifdef VERSION_JP layer_note1 11, 0x1f4, 100 -.else +#else layer_note1 11, 0x1f4, 127 -.endif +#endif layer_end .sound_env_elevator3: @@ -5374,11 +5377,11 @@ chan_end .layer_20D2: layer_portamento 0x81, 44, 255 -.ifdef VERSION_JP +#ifdef VERSION_JP layer_note1 36, 0x18, 90 -.else +#else layer_note1 36, 0x18, 115 -.endif +#endif layer_delay 0x32 layer_end @@ -5398,13 +5401,13 @@ layer_note1 31, 0x26, 127 layer_end .layer_20F4: -.ifdef VERSION_JP +#ifdef VERSION_JP layer_note1 38, 0x8, 120 layer_note1 33, 0x1e, 120 -.else +#else layer_note1 38, 0x8, 127 layer_note1 33, 0x1e, 127 -.endif +#endif layer_end .sound_obj_bully_metal: @@ -6989,7 +6992,7 @@ sound_ref .sound_menu_thank_you_playing_my_game sound_ref .sound_menu_read_a_sign sound_ref .sound_menu_exit_a_sign sound_ref .sound_menu_mario_castle_warp2 -.ifdef VERSION_JP +#ifdef VERSION_JP sound_ref .sound_menu_message_next_page sound_ref .sound_menu_coin_its_a_me_mario sound_ref .sound_menu_yoshi_gain_lives @@ -7003,7 +7006,7 @@ sound_ref .sound_menu_mario_castle_warp2 sound_ref .sound_menu_mario_castle_warp sound_ref .sound_menu_star_sound sound_ref .sound_menu_change_select -.else +#else sound_ref .sound_menu_star_sound_okey_dokey sound_ref .sound_menu_star_sound_lets_a_go sound_ref .sound_menu_yoshi_gain_lives @@ -7033,7 +7036,7 @@ sound_ref .sound_menu_mario_castle_warp2 sound_ref .sound_menu_power_meter sound_ref .sound_menu_camera_buzz sound_ref .sound_menu_camera_turn -.endif +#endif .sound_menu_change_select: chan_setbank 9 @@ -7506,13 +7509,13 @@ layer_end chan_reservenotes 4 chan_setbank 9 chan_setinstr 2 -.ifdef VERSION_SH +#ifdef VERSION_SH chan_setval 15 .set EXIT_PIPE_NOTE_VELOCITY, 106 -.else +#else chan_setval 30 .set EXIT_PIPE_NOTE_VELOCITY, 126 -.endif +#endif chan_call .set_reverb chan_setenvelope .envelope_3464 chan_setdecayrelease 220 @@ -7774,7 +7777,7 @@ chan_setlayer 0, .layer_3041 chan_setlayer 1, .layer_2FC9 chan_end -.ifndef VERSION_JP +#ifndef VERSION_JP .sound_menu_star_sound_okey_dokey: chan_setbank 4 chan_setinstr 14 @@ -7828,33 +7831,33 @@ chan_end .layer_3146: layer_delay 0x6 - .ifdef VERSION_SH + #ifdef VERSION_SH .set RED_COIN_NOTE_VELOCITY_SUB, 10 - .else + #else .set RED_COIN_NOTE_VELOCITY_SUB, 0 - .endif + #endif .layer_3148: layer_call .transpose_by_coin_index - layer_note0 46, 0xc, 75 - RED_COIN_NOTE_VELOCITY_SUB, 20 - layer_note0 45, 0xc, 75 - RED_COIN_NOTE_VELOCITY_SUB, 20 - layer_note0 46, 0xc, 75 - RED_COIN_NOTE_VELOCITY_SUB, 20 - layer_note0 58, 0x10, 80 - RED_COIN_NOTE_VELOCITY_SUB, 80 - layer_note0 58, 0x10, 45 - RED_COIN_NOTE_VELOCITY_SUB, 80 - layer_note0 58, 0x10, 20 - RED_COIN_NOTE_VELOCITY_SUB, 80 - layer_note0 58, 0x10, 15 - RED_COIN_NOTE_VELOCITY_SUB, 80 + layer_note0 46, 0xc, (75 - RED_COIN_NOTE_VELOCITY_SUB), 20 + layer_note0 45, 0xc, (75 - RED_COIN_NOTE_VELOCITY_SUB), 20 + layer_note0 46, 0xc, (75 - RED_COIN_NOTE_VELOCITY_SUB), 20 + layer_note0 58, 0x10, (80 - RED_COIN_NOTE_VELOCITY_SUB), 80 + layer_note0 58, 0x10, (45 - RED_COIN_NOTE_VELOCITY_SUB), 80 + layer_note0 58, 0x10, (20 - RED_COIN_NOTE_VELOCITY_SUB), 80 + layer_note0 58, 0x10, (15 - RED_COIN_NOTE_VELOCITY_SUB), 80 layer_end .layer_3168: layer_call .transpose_by_coin_index - layer_note0 41, 0xc, 75 - RED_COIN_NOTE_VELOCITY_SUB, 20 - layer_note0 40, 0xc, 75 - RED_COIN_NOTE_VELOCITY_SUB, 20 - layer_note0 41, 0xc, 75 - RED_COIN_NOTE_VELOCITY_SUB, 20 - layer_note0 53, 0x10, 80 - RED_COIN_NOTE_VELOCITY_SUB, 80 - layer_note0 53, 0x10, 45 - RED_COIN_NOTE_VELOCITY_SUB, 80 - layer_note0 53, 0x10, 20 - RED_COIN_NOTE_VELOCITY_SUB, 80 - layer_note0 53, 0x10, 15 - RED_COIN_NOTE_VELOCITY_SUB, 80 + layer_note0 41, 0xc, (75 - RED_COIN_NOTE_VELOCITY_SUB), 20 + layer_note0 40, 0xc, (75 - RED_COIN_NOTE_VELOCITY_SUB), 20 + layer_note0 41, 0xc, (75 - RED_COIN_NOTE_VELOCITY_SUB), 20 + layer_note0 53, 0x10, (80 - RED_COIN_NOTE_VELOCITY_SUB), 80 + layer_note0 53, 0x10, (45 - RED_COIN_NOTE_VELOCITY_SUB), 80 + layer_note0 53, 0x10, (20 - RED_COIN_NOTE_VELOCITY_SUB), 80 + layer_note0 53, 0x10, (15 - RED_COIN_NOTE_VELOCITY_SUB), 80 layer_end .transpose_by_coin_index: @@ -7877,7 +7880,7 @@ chan_end layer_transpose 0 layer_note1 32, 0x7f, 115 layer_end -.endif +#endif .sound_general_bird_chirp2: chan_setbank 5 @@ -8084,14 +8087,14 @@ envelope_line 1 32700 envelope_line 10 0 envelope_goto 2 -.ifndef VERSION_JP +#ifndef VERSION_JP .envelope_3378: envelope_line 3 32700 envelope_line 10 30000 envelope_line 10 10000 envelope_line 100 0 envelope_goto 3 -.endif +#endif .envelope_338C: envelope_line 1 32700 @@ -8150,11 +8153,11 @@ envelope_goto 2 .envelope_341C: envelope_line 25 32760 envelope_line 60 10000 -.ifdef VERSION_SH +#ifdef VERSION_SH envelope_hang -.else +#else envelope_goto 2 -.endif +#endif .envelope_3428: envelope_line 1 10000 diff --git a/src/audio/data.c b/src/audio/data.c index 3817c7ab..f8495bbb 100644 --- a/src/audio/data.c +++ b/src/audio/data.c @@ -877,12 +877,6 @@ u16 unk_sh_data_4[] = { 0x5FFF, 0x9001, 0x7FFF, 0x8001 }; - -char shindouDebugPrint1[] = "Terminate-Canceled Channel %d,Phase %d\n"; -char shindouDebugPrint2[] = "S->W\n"; -char shindouDebugPrint3[] = "W->S\n"; -char shindouDebugPrint4[] = "S-Resample Pitch %x (old %d -> delay %d)\n"; -// These debug prints are continued in shindou_debug_prints_1.c. #endif #ifndef VERSION_SH diff --git a/src/audio/external.c b/src/audio/external.c index aa0f6cf2..d797850d 100644 --- a/src/audio/external.c +++ b/src/audio/external.c @@ -484,15 +484,9 @@ void unused_8031E4F0(void) { stubbed_printf("\n"); stubbed_printf("BNK "); -#ifdef VERSION_SH -#define count 1 -#else -#define count 4 -#endif - for (i = 0; i < 40; i += count) { + for (i = 0; i < 40; i += 4) { stubbed_printf("%1x", 0); } -#undef count stubbed_printf("\n"); stubbed_printf("FIXHEAP "); @@ -1160,8 +1154,8 @@ static void select_current_sounds(u8 bank) { } /** - * Given an x and z coordinates, return the pan. This is a value between 0 and - * 1 that represents the audio direction. + * Given x and z coordinates, return the pan. This is a value nominally between + * 0 and 1 that represents the audio direction. * * Pan: * 0.0 - fully left @@ -1195,12 +1189,17 @@ static f32 get_sound_pan(f32 x, f32 z) { pan = US_FLOAT(0.5); } else if (x >= US_FLOAT(0.0) && absX >= absZ) { // far right pan - pan = US_FLOAT(1.0) - (US_FLOAT(44000.0) - absX) / (US_FLOAT(3.0) * (US_FLOAT(44000.0) - absZ)); + pan = US_FLOAT(1.0) - (2 * AUDIO_MAX_DISTANCE - absX) / (US_FLOAT(3.0) * (2 * AUDIO_MAX_DISTANCE - absZ)); } else if (x < 0 && absX > absZ) { // far left pan - pan = (US_FLOAT(44000.0) - absX) / (US_FLOAT(3.0) * (US_FLOAT(44000.0) - absZ)); + pan = (2 * AUDIO_MAX_DISTANCE - absX) / (US_FLOAT(3.0) * (2 * AUDIO_MAX_DISTANCE - absZ)); } else { // center pan + //! @bug (JP PU sound glitch) If |x|, |z| > AUDIO_MAX_DISTANCE, we'll + // end up in this case, and pan may be set to something outside of [0,1] + // since x is not clamped. On JP, this can lead to an out-of-bounds + // float read in note_set_vel_pan_reverb when x is highly negative, + // causing console crashes when that float is a nan or denormal. pan = 0.5 + x / (US_FLOAT(6.0) * absZ); } @@ -1246,6 +1245,8 @@ static f32 get_sound_volume(u8 bank, u8 soundIndex, f32 volumeRange) { if (sSoundBanks[bank][soundIndex].soundBits & SOUND_VIBRATO) { #ifdef VERSION_JP + //! @bug Intensity is 0 when the sound is far away. Due to the subtraction below, it is possible to end up with a negative intensity. + // When it is, objects with a volumeRange of 1 can still occasionally be lightly heard. if (intensity != 0.0) #else if (intensity >= 0.08f) @@ -1447,7 +1448,7 @@ void update_game_sound(void) { func_802ad770(0x05020000 | ((channelIndex & 0xff) << 8), get_sound_reverb(bank, soundIndex, channelIndex)); #else - gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverb = + gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol = get_sound_reverb(bank, soundIndex, channelIndex); #endif @@ -1488,7 +1489,7 @@ void update_game_sound(void) { *sSoundBanks[bank][soundIndex].z); gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale = get_sound_freq_scale(bank, soundIndex); - gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverb = + gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol = get_sound_reverb(bank, soundIndex, channelIndex); #endif break; @@ -1511,7 +1512,7 @@ void update_game_sound(void) { func_802ad728(0x04020000 | ((channelIndex & 0xff) << 8), get_sound_freq_scale(bank, soundIndex)); #else - gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverb = + gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol = get_sound_reverb(bank, soundIndex, channelIndex); gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume = get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK2); @@ -1527,6 +1528,13 @@ void update_game_sound(void) { #ifdef VERSION_JP // If the sound was marked for deletion (bits set to NO_SOUND), then stop playing it // and delete it + // @bug (JP double red coin sound) If the sound finished within the same frame as + // being marked for deletion, the signal to stop playing will be interpreted as a + // signal to *start* playing, as .main_loop_023589 in 00_sound_player does not check + // for soundScriptIO[0] being zero. This happens most commonly for red coin sounds + // whose sound spawners deactivate 30 frames after the sound starts to play, while + // the sound itself runs for 1.20 seconds. With enough lag these may coincide. + // Fixed on US by checking that layer0->finished is FALSE. else if (soundStatus == SOUND_STATUS_STOPPED) { update_background_music_after_sound(bank, soundIndex); gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[0] = 0; @@ -1538,17 +1546,19 @@ void update_game_sound(void) { sSoundBanks[bank][soundIndex].soundStatus = SOUND_STATUS_STOPPED; delete_sound_from_bank(bank, soundIndex); } else if (soundStatus == SOUND_STATUS_STOPPED - && gSequencePlayers[SEQ_PLAYER_SFX] - .channels[channelIndex] - ->layers[0] - ->finished - == FALSE) { + && gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex] + ->layers[0]->finished == FALSE) { update_background_music_after_sound(bank, soundIndex); gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[0] = 0; delete_sound_from_bank(bank, soundIndex); } #endif // If sound has finished playing, then delete it + // @bug (JP sound glitch) On JP, ...->layers[0] has not been checked for null, + // so this access can crash if an earlier layer allocation failed due to too + // many sounds playing at once. This crash is comparatively common; RTA + // speedrunners even have a setup for avoiding it within the SSL pyramid: + // https://www.youtube.com/watch?v=QetyTgbQxcw else if (gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->layers[0]->enabled == FALSE) { update_background_music_after_sound(bank, soundIndex); @@ -1622,7 +1632,7 @@ void update_game_sound(void) { func_802ad770(0x05020000 | ((channelIndex & 0xff) << 8), get_sound_reverb(bank, soundIndex, channelIndex)); #else - gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverb = + gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol = get_sound_reverb(bank, soundIndex, channelIndex); #endif @@ -1663,7 +1673,7 @@ void update_game_sound(void) { *sSoundBanks[bank][soundIndex].z); gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale = get_sound_freq_scale(bank, soundIndex); - gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverb = + gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol = get_sound_reverb(bank, soundIndex, channelIndex); #endif break; @@ -1686,7 +1696,7 @@ void update_game_sound(void) { func_802ad728(0x04020000 | ((channelIndex & 0xff) << 8), get_sound_freq_scale(bank, soundIndex)); #else - gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverb = + gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->reverbVol = get_sound_reverb(bank, soundIndex, channelIndex); gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume = get_sound_volume(bank, soundIndex, VOLUME_RANGE_UNK2); @@ -2103,10 +2113,11 @@ void set_audio_muted(u8 muted) { for (i = 0; i < SEQUENCE_PLAYERS; i++) { #if defined(VERSION_EU) || defined(VERSION_SH) - if (muted) + if (muted) { func_802ad74c(0xf1000000, 0); - else + } else { func_802ad74c(0xf2000000, 0); + } #else gSequencePlayers[i].muted = muted; #endif diff --git a/src/audio/external.h b/src/audio/external.h index a9edaedc..5efc6dfd 100644 --- a/src/audio/external.h +++ b/src/audio/external.h @@ -27,9 +27,6 @@ extern u32 gAudioRandom; extern u8 gAudioSPTaskYieldBuffer[]; // ucode yield data ptr; only used in JP struct SPTask *create_next_audio_frame_task(void); -#ifdef VERSION_SH -struct SPTask *func_sh_802f5a80(void); -#endif void play_sound(s32 soundBits, f32 *pos); void audio_signal_game_loop_tick(void); void update_game_sound(void); diff --git a/src/audio/heap.c b/src/audio/heap.c index 5e9ac322..4d7945a3 100644 --- a/src/audio/heap.c +++ b/src/audio/heap.c @@ -82,8 +82,7 @@ void unk_pools_init(u32 size1, u32 size2); * Assuming 'k' in [9, 24], * Computes a newton's method step for f(x) = x^k - d */ -f64 root_newton_step(f64 x, s32 k, f64 d) -{ +f64 root_newton_step(f64 x, s32 k, f64 d) { f64 deg2 = x * x; f64 deg4 = deg2 * deg2; f64 deg8 = deg4 * deg4; @@ -206,8 +205,6 @@ void discard_bank(s32 bankId) { #if defined(VERSION_EU) if (note->noteSubEu.bankId == bankId) { -#elif defined(VERSION_SH) - if (note->unkSH33 == bankId) { #else if (note->bankId == bankId) { #endif @@ -384,7 +381,7 @@ void temporary_pools_init(struct PoolSplit *a) { #undef SOUND_ALLOC_FUNC #if defined(VERSION_JP) || defined(VERSION_US) -static void unused_803163D4(void) { +UNUSED static void unused_803163D4(void) { } #endif @@ -512,7 +509,7 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg if (poolIdx == 1) { if (firstVal == SOUND_LOAD_STATUS_4) { for (i = 0; i < gMaxSimultaneousNotes; i++) { - if (gNotes[i].unkSH33 == tp->entries[0].id && gNotes[i].noteSubEu.enabled) { + if (gNotes[i].bankId == tp->entries[0].id && gNotes[i].noteSubEu.enabled) { break; } } @@ -525,7 +522,7 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg } if (secondVal == SOUND_LOAD_STATUS_4) { for (i = 0; i < gMaxSimultaneousNotes; i++) { - if (gNotes[i].unkSH33 == tp->entries[1].id && gNotes[i].noteSubEu.enabled) { + if (gNotes[i].bankId == tp->entries[1].id && gNotes[i].noteSubEu.enabled) { break; } } @@ -591,7 +588,7 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg } else if (poolIdx == 1) { if (firstVal == SOUND_LOAD_STATUS_COMPLETE) { for (i = 0; i < gMaxSimultaneousNotes; i++) { - if (gNotes[i].unkSH33 == tp->entries[0].id && gNotes[i].noteSubEu.enabled) { + if (gNotes[i].bankId == tp->entries[0].id && gNotes[i].noteSubEu.enabled) { break; } } @@ -602,7 +599,7 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg } if (secondVal == SOUND_LOAD_STATUS_COMPLETE) { for (i = 0; i < gMaxSimultaneousNotes; i++) { - if (gNotes[i].unkSH33 == tp->entries[1].id && gNotes[i].noteSubEu.enabled) { + if (gNotes[i].bankId == tp->entries[1].id && gNotes[i].noteSubEu.enabled) { break; } } @@ -1687,7 +1684,7 @@ void func_sh_802f23ec(void) { s32 i; s32 idx; s32 seqCount; - u32 bankId1; // non symmetric fake match? can also change 0xff to 0xffU for same effect + s32 bankId1; s32 bankId2; s32 instId; s32 drumId; @@ -1700,7 +1697,7 @@ void func_sh_802f23ec(void) { for (idx = 0; idx < seqCount; idx++) { bankId1 = gCtlEntries[idx].bankId1; bankId2 = gCtlEntries[idx].bankId2; - if ((bankId1 != 0xff && entry->bankId == bankId1) || (bankId2 != 0xff && entry->bankId == bankId2) || entry->bankId == 0) { + if ((bankId1 != 0xffu && entry->bankId == bankId1) || (bankId2 != 0xff && entry->bankId == bankId2) || entry->bankId == 0) { if (get_bank_or_seq(1, 3, idx) != NULL) { if (IS_BANK_LOAD_COMPLETE(idx) != FALSE) { for (i = 0; i < gUnkPool2.numEntries; i++) { diff --git a/src/audio/heap.h b/src/audio/heap.h index e01dc8d4..7f9632b5 100644 --- a/src/audio/heap.h +++ b/src/audio/heap.h @@ -15,8 +15,7 @@ #define IS_BANK_LOAD_COMPLETE(bankId) (gBankLoadStatus[bankId] >= SOUND_LOAD_STATUS_COMPLETE) #define IS_SEQ_LOAD_COMPLETE(seqId) (gSeqLoadStatus[seqId] >= SOUND_LOAD_STATUS_COMPLETE) -struct SoundAllocPool -{ +struct SoundAllocPool { u8 *start; u8 *cur; u32 size; @@ -34,15 +33,13 @@ struct SeqOrBankEntry { #endif }; // size = 0xC -struct PersistentPool -{ +struct PersistentPool { /*0x00*/ u32 numEntries; /*0x04*/ struct SoundAllocPool pool; /*0x14*/ struct SeqOrBankEntry entries[32]; }; // size = 0x194 -struct TemporaryPool -{ +struct TemporaryPool { /*EU, SH*/ /*0x00, 0x00*/ u32 nextSide; /*0x04, */ struct SoundAllocPool pool; @@ -59,21 +56,18 @@ struct TemporaryPool /*0x28, 0x2A entries[1].id */ }; // size = 0x2C -struct SoundMultiPool -{ +struct SoundMultiPool { /*0x000*/ struct PersistentPool persistent; /*0x194*/ struct TemporaryPool temporary; /* */ u32 pad2[4]; }; // size = 0x1D0 -struct Unk1Pool -{ +struct Unk1Pool { struct SoundAllocPool pool; struct SeqOrBankEntry entries[32]; }; -struct UnkEntry -{ +struct UnkEntry { s8 used; s8 medium; s8 bankId; @@ -83,8 +77,7 @@ struct UnkEntry u32 size; }; -struct UnkPool -{ +struct UnkPool { /*0x00*/ struct SoundAllocPool pool; /*0x10*/ struct UnkEntry entries[64]; /*0x510*/ s32 numEntries; @@ -131,12 +124,14 @@ void audio_reset_session(void); #else void audio_reset_session(struct AudioSessionSettings *preset); #endif +void discard_bank(s32 bankId); #ifdef VERSION_SH void fill_filter(s16 filter[8], s32 arg1, s32 arg2); u8 *func_sh_802f1d40(u32 size, s32 bank, u8 *arg2, s8 medium); u8 *func_sh_802f1d90(u32 size, s32 bank, u8 *arg2, s8 medium); void *unk_pool1_lookup(s32 poolIdx, s32 id); +void *unk_pool1_alloc(s32 poolIndex, s32 arg1, u32 size); #endif #endif // AUDIO_HEAP_H diff --git a/src/audio/internal.h b/src/audio/internal.h index a834532f..f91c3a2e 100644 --- a/src/audio/internal.h +++ b/src/audio/internal.h @@ -41,6 +41,11 @@ #define TATUMS_PER_BEAT 48 +// abi.h contains more details about the ADPCM and S8 codecs, "skip" skips codec processing +#define CODEC_ADPCM 0 +#define CODEC_S8 1 +#define CODEC_SKIP 2 + #ifdef VERSION_JP #define TEMPO_SCALE 1 #else @@ -88,8 +93,7 @@ struct NotePool; -struct AudioListItem -{ +struct AudioListItem { // A node in a circularly linked list. Each node is either a head or an item: // - Items can be either detached (prev = NULL), or attached to a list. // 'value' points to something of interest. @@ -106,8 +110,7 @@ struct AudioListItem struct NotePool *pool; }; // size = 0x10 -struct NotePool -{ +struct NotePool { struct AudioListItem disabled; struct AudioListItem decaying; struct AudioListItem releasing; @@ -149,8 +152,7 @@ struct AdsrEnvelope { s16 arg; }; // size = 0x4 -struct AdpcmLoop -{ +struct AdpcmLoop { u32 start; u32 end; u32 count; @@ -158,15 +160,13 @@ struct AdpcmLoop s16 state[16]; // only exists if count != 0. 8-byte aligned }; -struct AdpcmBook -{ +struct AdpcmBook { s32 order; s32 npredictors; s16 book[1]; // size 8 * order * npredictors. 8-byte aligned }; -struct AudioBankSample -{ +struct AudioBankSample { #ifdef VERSION_SH /* 0x00 */ u32 codec : 4; /* 0x00 */ u32 medium : 2; @@ -185,14 +185,12 @@ struct AudioBankSample #endif }; -struct AudioBankSound -{ +struct AudioBankSound { struct AudioBankSample *sample; f32 tuning; // frequency scale factor }; // size = 0x8 -struct Instrument -{ +struct Instrument { /*0x00*/ u8 loaded; /*0x01*/ u8 normalRangeLo; /*0x02*/ u8 normalRangeHi; @@ -203,8 +201,7 @@ struct Instrument /*0x18*/ struct AudioBankSound highNotesSound; }; // size = 0x20 -struct Drum -{ +struct Drum { u8 releaseRate; u8 pan; u8 loaded; @@ -212,14 +209,12 @@ struct Drum struct AdsrEnvelope *envelope; }; -struct AudioBank -{ +struct AudioBank { struct Drum **drums; struct Instrument *instruments[1]; }; // dynamic size -struct CtlEntry -{ +struct CtlEntry { #ifndef VERSION_SH u8 unused; #endif @@ -241,8 +236,7 @@ struct M64ScriptState { }; // size = 0x1C // Also known as a Group, according to debug strings. -struct SequencePlayer -{ +struct SequencePlayer { /*US/JP, EU, SH */ #if defined(VERSION_EU) || defined(VERSION_SH) /*0x000, 0x000, 0x000*/ u8 enabled : 1; @@ -320,8 +314,7 @@ struct SequencePlayer /*0x13C, 0x144*/ ssize_t bankDmaRemaining; }; // size = 0x140, 0x148 on EU, 0x14C on SH -struct AdsrSettings -{ +struct AdsrSettings { u8 releaseRate; #if defined(VERSION_EU) || defined(VERSION_SH) u8 sustain; @@ -373,8 +366,8 @@ union ReverbBits { /* 0x00 */ u8 asByte; }; struct ReverbInfo { - u8 reverb; - u8 bankId; + u8 reverbVol; + u8 synthesisVolume; // UQ4.4, although 0 <= x < 1 is rounded up to 1 u8 pan; union ReverbBits reverbBits; f32 freqScale; @@ -383,11 +376,10 @@ struct ReverbInfo { s16 *filter; }; -struct NoteAttributes -{ - u8 reverb; +struct NoteAttributes { + u8 reverbVol; #ifdef VERSION_SH - u8 unk1; + u8 synthesisVolume; // UQ4.4, although 0 <= x < 1 is rounded up to 1 #endif #if defined(VERSION_EU) || defined(VERSION_SH) u8 pan; @@ -407,8 +399,7 @@ struct NoteAttributes // Also known as a SubTrack, according to debug strings. // Confusingly, a SubTrack is a container of Tracks. -struct SequenceChannel -{ +struct SequenceChannel { /* U/J, EU, SH */ /*0x00, 0x00*/ u8 enabled : 1; /*0x00, 0x00*/ u8 finished : 1; @@ -430,7 +421,7 @@ struct SequenceChannel #endif /*0x01, 0x02*/ u8 noteAllocPolicy; /*0x02, 0x03, 0x03*/ u8 muteBehavior; - /*0x03, 0x04, 0x04*/ u8 reverb; // or dry/wet mix + /*0x03, 0x04, 0x04*/ u8 reverbVol; // until EU: Q1.7, after EU: UQ0.8 /*0x04, ????*/ u8 notePriority; // 0-3 #ifdef VERSION_SH u8 unkSH06; // some priority @@ -445,7 +436,7 @@ struct SequenceChannel /*0x06, */ u8 updatesPerFrameUnused; #endif #ifdef VERSION_SH - /* 0x0C*/ u8 unkSH0C; // bankId + /* 0x0C*/ u8 synthesisVolume; // UQ4.4, although 0 <= x < 1 is rounded up to 1 #endif /*0x08, 0x0C, 0x0E*/ u16 vibratoRateStart; // initially 0x800 /*0x0A, 0x0E, 0x10*/ u16 vibratoExtentStart; @@ -490,8 +481,7 @@ struct SequenceChannel }; // size = 0xC0, 0xC4 in EU, 0xD0 in SH // Also known as a Track, according to debug strings. -struct SequenceChannelLayer -{ +struct SequenceChannelLayer { /* U/J, EU, SH */ /*0x00, 0x00*/ u8 enabled : 1; /*0x00, 0x00*/ u8 finished : 1; @@ -521,7 +511,7 @@ struct SequenceChannelLayer // 0..0x3f; this makes 0x40..0x7f accessible as well) /*0x20, 0x24, 0x24*/ f32 freqScale; #ifdef VERSION_SH - /* 0x28*/ f32 unkSH28; + /* 0x28*/ f32 freqScaleMultiplier; #endif /*0x24, 0x28, 0x2C*/ f32 velocitySquare; #if defined(VERSION_JP) || defined(VERSION_US) @@ -549,8 +539,7 @@ struct SequenceChannelLayer }; // size = 0x80 #if defined(VERSION_EU) || defined(VERSION_SH) -struct NoteSynthesisState -{ +struct NoteSynthesisState { /*0x00*/ u8 restart; /*0x01*/ u8 sampleDmaIndex; /*0x02*/ u8 prevHeadsetPanRight; @@ -562,17 +551,16 @@ struct NoteSynthesisState /*0x04, 0x06*/ u16 samplePosFrac; /*0x08*/ s32 samplePosInt; /*0x0C*/ struct NoteSynthesisBuffers *synthesisBuffers; - /*0x10*/ s16 curVolLeft; - /*0x12*/ s16 curVolRight; + /*0x10*/ s16 curVolLeft; // UQ0.16 (EU Q1.15) + /*0x12*/ s16 curVolRight; // UQ0.16 (EU Q1.15) }; -struct NotePlaybackState -{ +struct NotePlaybackState { /* U/J, EU, SH */ /*0x04, 0x00, 0x00*/ u8 priority; /* 0x01, 0x01*/ u8 waveId; /* 0x02, 0x02*/ u8 sampleCountIndex; #ifdef VERSION_SH - /* 0x03*/ u8 unkSH33; // bankId? + /* 0x03*/ u8 bankId; /* 0x04*/ u8 unkSH34; #endif /*0x08, 0x04, 0x06*/ s16 adsrVolScale; @@ -586,8 +574,7 @@ struct NotePlaybackState /*0x74, 0x4C, */ struct Portamento portamento; /*0x84, 0x5C, */ struct VibratoState vibratoState; }; -struct NoteSubEu -{ +struct NoteSubEu { /*0x00*/ volatile u8 enabled : 1; /*0x00*/ u8 needsInit : 1; /*0x00*/ u8 finished : 1; @@ -600,12 +587,16 @@ struct NoteSubEu /*0x01*/ u8 bookOffset : 3; /*0x01*/ u8 isSyntheticWave : 1; /*0x01*/ u8 hasTwoAdpcmParts : 1; +#ifdef VERSION_EU /*0x02*/ u8 bankId; +#else + /*0x02*/ u8 synthesisVolume; // UQ4.4, although 0 <= x < 1 is rounded up to 1 +#endif /*0x03*/ u8 headsetPanRight; /*0x04*/ u8 headsetPanLeft; - /*0x05*/ u8 reverbVol; - /*0x06*/ u16 targetVolLeft; - /*0x08*/ u16 targetVolRight; + /*0x05*/ u8 reverbVol; // UQ0.7 (EU Q1.7) + /*0x06*/ u16 targetVolLeft; // UQ0.12 (EU UQ0.10) + /*0x08*/ u16 targetVolRight; // UQ0.12 (EU UQ0.10) /*0x0A*/ u16 resamplingRateFixedPoint; // stored as signed but loaded as u16 /*0x0C*/ union { s16 *samples; @@ -615,8 +606,7 @@ struct NoteSubEu /*0x10*/ s16 *filter; #endif }; -struct Note -{ +struct Note { /* U/J, EU, SH */ /*0xA4, 0x00, 0x00*/ struct AudioListItem listItem; /* 0x10, 0x10*/ struct NoteSynthesisState synthesisState; @@ -633,7 +623,7 @@ struct Note /* 0x31, 0x31*/ u8 waveId; /* 0x32, 0x32*/ u8 sampleCountIndex; #ifdef VERSION_SH - /* 0x33*/ u8 unkSH33; // bankId? + /* 0x33*/ u8 bankId; /* 0x34*/ u8 unkSH34; #endif /*0x08, 0x34, 0x36*/ s16 adsrVolScale; @@ -651,14 +641,12 @@ struct Note }; // size = 0xC0, known to be 0xC8 on SH #else // volatile Note, needed in synthesis_process_notes -struct vNote -{ +struct vNote { /* U/J, EU */ /*0x00*/ volatile u8 enabled : 1; long long int force_structure_alignment; }; // size = 0xC0 -struct Note -{ +struct Note { /* U/J, EU */ /*0x00*/ u8 enabled : 1; /*0x00*/ u8 needsInit : 1; @@ -691,25 +679,24 @@ struct Note /*0x30, 0x48*/ struct SequenceChannelLayer *wantedParentLayer; /*0x34*/ struct NoteSynthesisBuffers *synthesisBuffers; /*0x38*/ f32 frequency; - /*0x3C*/ u16 targetVolLeft; - /*0x3E*/ u16 targetVolRight; - /*0x40*/ u8 reverb; + /*0x3C*/ u16 targetVolLeft; // Q1.15, but will always be non-negative + /*0x3E*/ u16 targetVolRight; // Q1.15, but will always be non-negative + /*0x40*/ u8 reverbVol; // Q1.7 /*0x41*/ u8 unused1; // never read, set to 0x3f /*0x44*/ struct NoteAttributes attributes; /*0x54, 0x58*/ struct AdsrState adsr; /*0x74, 0x7C*/ struct Portamento portamento; /*0x84, 0x8C*/ struct VibratoState vibratoState; - /*0x9C*/ s16 curVolLeft; - /*0x9E*/ s16 curVolRight; - /*0xA0*/ s16 reverbVol; + /*0x9C*/ s16 curVolLeft; // Q1.15, but will always be non-negative + /*0x9E*/ s16 curVolRight; // Q1.15, but will always be non-negative + /*0xA0*/ s16 reverbVolShifted; // Q1.15 /*0xA2*/ s16 unused2; // never read, set to 0 /*0xA4, 0x00*/ struct AudioListItem listItem; /* */ u8 pad2[0xc]; }; // size = 0xC0 #endif -struct NoteSynthesisBuffers -{ +struct NoteSynthesisBuffers { s16 adpcmdecState[0x10]; s16 finalResampleState[0x10]; #ifdef VERSION_SH @@ -728,15 +715,13 @@ struct NoteSynthesisBuffers }; #ifdef VERSION_EU -struct ReverbSettingsEU -{ +struct ReverbSettingsEU { u8 downsampleRate; u8 windowSize; // To be multiplied by 64 u16 gain; }; #else -struct ReverbSettingsEU -{ +struct ReverbSettingsEU { u8 downsampleRate; // always 1 u8 windowSize; // To be multiplied by 16 u16 gain; @@ -749,8 +734,7 @@ struct ReverbSettingsEU }; #endif -struct AudioSessionSettingsEU -{ +struct AudioSessionSettingsEU { /* 0x00 */ u32 frequency; /* 0x04 */ u8 unk1; // always 1 /* 0x05 */ u8 maxSimultaneousNotes; @@ -773,8 +757,7 @@ struct AudioSessionSettingsEU #endif }; // 0x30 on shindou -struct AudioSessionSettings -{ +struct AudioSessionSettings { /*0x00*/ u32 frequency; /*0x04*/ u8 maxSimultaneousNotes; /*0x05*/ u8 reverbDownsampleRate; // always 1 diff --git a/src/audio/load.c b/src/audio/load.c index 24a2424f..896032dd 100644 --- a/src/audio/load.c +++ b/src/audio/load.c @@ -1,4 +1,6 @@ +#ifndef VERSION_SH #include +#include #include "data.h" #include "external.h" @@ -20,16 +22,11 @@ struct SharedDma { // EU only void port_eu_init(void); -// SH only -#if defined(VERSION_SH) -void func_sh_802f6a9c(void); -void func_sh_802f51d4(struct AudioBankSound *sound, struct AudioBank *memBase, struct PatchStruct *patchInfo); -#endif struct Note *gNotes; -#if defined(VERSION_EU) || defined(VERSION_SH) -static u8 pad[4]; +#if defined(VERSION_EU) +UNUSED static u8 pad[4]; #endif struct SequencePlayer gSequencePlayers[SEQUENCE_PLAYERS]; @@ -40,35 +37,6 @@ struct SequenceChannel gSequenceChannelNone; struct AudioListItem gLayerFreeList; struct NotePool gNoteFreeLists; -#ifdef VERSION_SH -struct AudioBankSample *D_SH_8034EA88[0x80]; -struct UnkStructSH8034EC88 D_SH_8034EC88[0x80]; -s32 D_SH_8034F688; // index into D_SH_8034EA88 -s32 D_SH_8034F68C; // index or size for D_SH_8034EC88 - -struct PendingDmaAudioBank { - s8 inProgress; - s8 timer; - s8 medium; - struct AudioBank *audioBank; - uintptr_t devAddr; - void *vAddr; - u32 remaining; - u32 transferSize; - u32 encodedInfo; - OSMesgQueue *retQueue; - OSMesgQueue dmaRetQueue; - OSMesg mesgs[1]; - OSIoMesg ioMesg; -}; -struct PendingDmaAudioBank D_SH_8034F690[16]; - -OSMesgQueue gUnkQueue1; -OSMesg gUnkMesgBufs1[0x10]; -OSMesgQueue gUnkQueue2; -OSMesg gUnkMesgBufs2[0x10]; -#endif - OSMesgQueue gCurrAudioFrameDmaQueue; OSMesg gCurrAudioFrameDmaMesgBufs[AUDIO_FRAME_DMA_QUEUE_SIZE]; OSIoMesg gCurrAudioFrameDmaIoMesgBufs[AUDIO_FRAME_DMA_QUEUE_SIZE]; @@ -77,11 +45,7 @@ OSMesgQueue gAudioDmaMesgQueue; OSMesg gAudioDmaMesg; OSIoMesg gAudioDmaIoMesg; -#ifdef VERSION_SH -struct SharedDma *sSampleDmas; // sh: 0x803503D0 -#else struct SharedDma sSampleDmas[0x60]; -#endif u32 gSampleDmaNumListItems; // sh: 0x803503D4 u32 sSampleDmaListSize1; // sh: 0x803503D8 u32 sUnused80226B40; // set to 0, never read, sh: 0x803503DC @@ -111,14 +75,11 @@ struct AudioBufferParametersEU gAudioBufferParameters; s32 gAiFrequency; #endif -#ifdef VERSION_SH -struct AudioBufferParametersEU gAudioBufferParameters; -#endif u32 sDmaBufSize; s32 gMaxAudioCmds; s32 gMaxSimultaneousNotes; -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) s16 gTempoInternalToExternal; #else s32 gSamplesPerFrameTarget; @@ -131,7 +92,7 @@ s8 gAudioUpdatesPerFrame; s8 gSoundMode; -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) s8 gAudioUpdatesPerFrame; #endif @@ -145,27 +106,9 @@ extern u8 gBankSetsData[]; // bank_sets.s ALSeqFile *get_audio_file_header(s32 arg0); -#ifdef VERSION_SH -void *func_sh_802f3688(s32 arg0); -void *get_bank_or_seq_wrapper(s32 arg0, s32 arg1); -void func_sh_802f3d78(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3); -void func_sh_802f3c38(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 medium); -void func_sh_802f4a4c(s32 audioResetStatus); -void func_sh_802f4bd8(struct PendingDmaSample *arg0, s32 len); -void func_sh_802f4c5c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3); -struct PendingDmaAudioBank *func_sh_802f4cb4(uintptr_t devAddr, void *vAddr, s32 size, s32 medium, s32 numChunks, OSMesgQueue *retQueue, s32 encodedInfo); -void func_sh_802f4dcc(s32 audioResetStatus); -void func_sh_802f4e50(struct PendingDmaAudioBank *audioBank, s32 audioResetStatus); -void func_sh_802f50ec(struct PendingDmaAudioBank *arg0, size_t len); -void func_sh_802f517c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3); -s32 func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo, s32 arg3); -void *func_sh_802F3564(s32 arg0); -#endif - /** * Performs an immediate DMA copy */ -#if !defined(VERSION_SH) void audio_dma_copy_immediate(uintptr_t devAddr, void *vAddr, size_t nbytes) { eu_stubbed_printf_3("Romcopy %x -> %x ,size %x\n", devAddr, vAddr, nbytes); osInvalDCache(vAddr, nbytes); @@ -174,7 +117,6 @@ void audio_dma_copy_immediate(uintptr_t devAddr, void *vAddr, size_t nbytes) { osRecvMesg(&gAudioDmaMesgQueue, NULL, OS_MESG_BLOCK); eu_stubbed_printf_0("Romcopyend\n"); } -#endif #ifdef VERSION_EU u8 audioString34[] = "CAUTION:WAVE CACHE FULL %d"; @@ -198,18 +140,15 @@ u8 audioString49[] = "BANK LOAD MISS! FOR %d\n"; /** * Performs an asynchronus (normal priority) DMA copy */ -#if !defined(VERSION_SH) void audio_dma_copy_async(uintptr_t devAddr, void *vAddr, size_t nbytes, OSMesgQueue *queue, OSIoMesg *mesg) { osInvalDCache(vAddr, nbytes); osPiStartDma(mesg, OS_MESG_PRI_NORMAL, OS_READ, devAddr, vAddr, nbytes, queue); } -#endif /** * Performs a partial asynchronous (normal priority) DMA copy. This is limited * to 0x1000 bytes transfer at once. */ -#ifndef VERSION_SH void audio_dma_partial_copy_async(uintptr_t *devAddr, u8 **vAddr, ssize_t *remaining, OSMesgQueue *queue, OSIoMesg *mesg) { #if defined(VERSION_EU) ssize_t transfer = (*remaining >= 0x1000 ? 0x1000 : *remaining); @@ -222,13 +161,12 @@ void audio_dma_partial_copy_async(uintptr_t *devAddr, u8 **vAddr, ssize_t *remai *devAddr += transfer; *vAddr += transfer; } -#endif void decrease_sample_dma_ttls() { u32 i; for (i = 0; i < sSampleDmaListSize1; i++) { -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) struct SharedDma *temp = &sSampleDmas[i]; #else struct SharedDma *temp = sSampleDmas + i; @@ -243,7 +181,7 @@ void decrease_sample_dma_ttls() { } for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) { -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) struct SharedDma *temp = &sSampleDmas[i]; #else struct SharedDma *temp = sSampleDmas + i; @@ -260,40 +198,19 @@ void decrease_sample_dma_ttls() { sUnused80226B40 = 0; } -extern char shindouDebugPrint62[]; -#ifdef VERSION_SH -void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef, s32 medium) { - UNUSED s32 sp60; -#else void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) { -#endif -#ifdef VERSION_SH - struct SharedDma *dma; - s32 hasDma = FALSE; -#else s32 hasDma = FALSE; struct SharedDma *dma; -#endif uintptr_t dmaDevAddr; -#ifdef VERSION_SH - UNUSED u32 pad; - u32 dmaIndex; - u32 transfer; -#else u32 transfer; u32 i; u32 dmaIndex; -#endif ssize_t bufferPos; -#ifdef VERSION_SH - u32 i; -#else UNUSED u32 pad; -#endif if (arg2 != 0 || *dmaIndexRef >= sSampleDmaListSize1) { for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) { -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) dma = &sSampleDmas[i]; #else dma = sSampleDmas + i; @@ -314,7 +231,7 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) { } dma->ttl = 60; *dmaIndexRef = (u8) i; -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) return &dma->buffer[(devAddr - dma->source)]; #else return (devAddr - dma->source) + dma->buffer; @@ -356,7 +273,7 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) { sSampleDmaReuseQueueTail1++; } dma->ttl = 2; -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) return dma->buffer + (devAddr - dma->source); #else return (devAddr - dma->source) + dma->buffer; @@ -365,9 +282,6 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) { } if (!hasDma) { -#ifdef VERSION_SH - if (1) {} -#endif // Allocate a DMA from reuse queue 1. This queue will hopefully never // be empty, since TTL 2 is so small. dmaIndex = sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1++]; @@ -388,11 +302,6 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) { OS_READ, dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue); *dmaIndexRef = dmaIndex; return (devAddr - dmaDevAddr) + dma->buffer; -#elif defined (VERSION_SH) - func_sh_802f3dd0(&gCurrAudioFrameDmaIoMesgBufs[gCurrAudioFrameDmaCount++], OS_MESG_PRI_NORMAL, OS_READ, - dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue, medium, shindouDebugPrint62); - *dmaIndexRef = dmaIndex; - return (devAddr - dmaDevAddr) + dma->buffer; #else gCurrAudioFrameDmaCount++; osPiStartDma(&gCurrAudioFrameDmaIoMesgBufs[gCurrAudioFrameDmaCount - 1], OS_MESG_PRI_NORMAL, @@ -405,7 +314,7 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) { void init_sample_dma_buffers(UNUSED s32 arg0) { s32 i; -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) #define j i #else s32 j; @@ -413,25 +322,16 @@ void init_sample_dma_buffers(UNUSED s32 arg0) { #if defined(VERSION_EU) sDmaBufSize = 0x400; -#elif defined(VERSION_SH) - sDmaBufSize = 0x2D0; - sSampleDmas = sound_alloc_uninitialized(&gNotesAndBuffersPool, - gMaxSimultaneousNotes * 4 * sizeof(struct SharedDma) * gAudioBufferParameters.presetUnk4); #else sDmaBufSize = 144 * 9; #endif -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++) #else for (i = 0; i < gMaxSimultaneousNotes * 3; i++) #endif { -#if defined(VERSION_SH) - if ((sSampleDmas[gSampleDmaNumListItems].buffer = sound_alloc_uninitialized(&gNotesAndBuffersPool, sDmaBufSize)) == NULL) { - break; - } -#else sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, sDmaBufSize); if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) { #if defined(VERSION_EU) @@ -440,7 +340,6 @@ void init_sample_dma_buffers(UNUSED s32 arg0) { goto out1; #endif } -#endif sSampleDmas[gSampleDmaNumListItems].bufSize = sDmaBufSize; sSampleDmas[gSampleDmaNumListItems].source = 0; sSampleDmas[gSampleDmaNumListItems].sizeUnused = 0; @@ -465,19 +364,12 @@ out1: sSampleDmaReuseQueueHead1 = (u8) gSampleDmaNumListItems; sSampleDmaListSize1 = gSampleDmaNumListItems; -#if defined(VERSION_SH) - sDmaBufSize = 0x2D0; -#elif defined(VERSION_EU) +#if defined(VERSION_EU) sDmaBufSize = 0x200; #else sDmaBufSize = 160 * 9; #endif for (i = 0; i < gMaxSimultaneousNotes; i++) { -#if defined(VERSION_SH) - if ((sSampleDmas[gSampleDmaNumListItems].buffer = sound_alloc_uninitialized(&gNotesAndBuffersPool, sDmaBufSize)) == NULL) { - break; - } -#else sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, sDmaBufSize); if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) { #if defined(VERSION_EU) @@ -486,17 +378,11 @@ out1: goto out2; #endif } -#endif -#if defined(VERSION_SH) sSampleDmas[gSampleDmaNumListItems].bufSize = sDmaBufSize; -#endif sSampleDmas[gSampleDmaNumListItems].source = 0; sSampleDmas[gSampleDmaNumListItems].sizeUnused = 0; sSampleDmas[gSampleDmaNumListItems].unused2 = 0; sSampleDmas[gSampleDmaNumListItems].ttl = 0; -#ifndef VERSION_SH - sSampleDmas[gSampleDmaNumListItems].bufSize = sDmaBufSize; -#endif gSampleDmaNumListItems++; } #if defined(VERSION_JP) || defined(VERSION_US) @@ -516,68 +402,15 @@ out2: sSampleDmaReuseQueueTail2 = 0; sSampleDmaReuseQueueHead2 = gSampleDmaNumListItems - sSampleDmaListSize1; -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) #undef j #endif } -#ifndef static -// Keep supporting the good old "#define static" hack. -#undef static -#endif - -#if defined(VERSION_SH) -void patch_seq_file(ALSeqFile *seqFile, u8 *data, u16 arg2) { - ALSeqFile *phi_a2; - s32 i; - - seqFile->unk2 = arg2; - seqFile->data = data; - for (i = 0; i < seqFile->seqCount; i++) { - if (seqFile->seqArray[i].len != 0 && seqFile->seqArray[i].magic[0] == 2) { - seqFile->seqArray[i].offset += (uintptr_t)data; - } - } -} - -void *func_sh_802f2e24(s32 arg0, s32 *arg1) { - s32 phi_s2; - s32 phi_s0; - s32 phi_s1; - void *sp28; - - phi_s0 = ((u16 *)gAlBankSets)[func_sh_802f39a0(0, arg0)]; - phi_s1 = gAlBankSets[phi_s0++]; - phi_s2 = 0xFF; - while (phi_s1 > 0) { - phi_s2 = gAlBankSets[phi_s0++]; - phi_s2 = (s32) phi_s2; - sp28 = func_sh_802f3688(phi_s2); - phi_s1--; - } - *arg1 = phi_s2; - return sp28; -} -#endif - #if defined(VERSION_JP) || defined(VERSION_US) // This function gets optimized out on US due to being static and never called -static +UNUSED static #endif -#if defined(VERSION_SH) -void preload_sequence(s32 arg0, s32 arg1) { - UNUSED s32 pad; - s32 sp18; - - arg0 = func_sh_802f39a0(0, arg0); - if (arg1 & PRELOAD_BANKS) { - func_sh_802f2e24(arg0, &sp18); - } - if (arg1 & PRELOAD_SEQUENCE) { - func_sh_802F3564(arg0); - } -} -#else void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED u8 *offsetBase) { struct AudioBankSample *sample; void *patched; @@ -613,9 +446,11 @@ void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED #undef PATCH } -#endif -#if defined(VERSION_JP) || defined(VERSION_US) +#ifdef VERSION_EU +#define PATCH_SOUND patch_sound +#else +// copt inline of the above #define PATCH_SOUND(_sound, mem, offset) \ { \ struct AudioBankSound *sound = _sound; \ @@ -640,457 +475,40 @@ void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED } #endif -#if defined(VERSION_SH) -s32 func_sh_802f2f38(struct AudioBankSample *sample, s32 bankId) { - u8 *sp24; - - if (sample->isPatched == TRUE && sample->medium != 0) { - sp24 = func_sh_802f1d90(sample->size, bankId, sample->sampleAddr, sample->medium); - if (sp24 == NULL) { - return -1; - } - if (sample->medium == 1) { - func_sh_802f3d78(sample->sampleAddr, sp24, sample->size, gAlTbl->unk2); - } else { - func_sh_802f3c38(sample->sampleAddr, sp24, sample->size, sample->medium); - } - sample->medium = 0; - sample->sampleAddr = sp24; - } -} - -s32 func_sh_802f3024(s32 bankId, s32 instId, s32 arg2) { - struct Instrument *instr; - struct Drum *drum; - - if (instId < 0x7F) { - instr = get_instrument_inner(bankId, instId); - if (instr == NULL) { - return -1; - } - if (instr->normalRangeLo != 0) { - func_sh_802f2f38(instr->lowNotesSound.sample, bankId); - } - func_sh_802f2f38(instr->normalNotesSound.sample, bankId); - if (instr->normalRangeHi != 0x7F) { - func_sh_802f2f38(instr->highNotesSound.sample, bankId); - } - //! missing return - } else if (instId == 0x7F) { - drum = get_drum(bankId, arg2); - if (drum == NULL) { - return -1; - } - func_sh_802f2f38(drum->sound.sample, bankId); - return 0; - } -} - -void func_sh_802f30f4(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue *arg3) { - if (func_802f3f08(2, func_sh_802f39a0(2, arg0), arg1, arg2, arg3) == 0) { - osSendMesg(arg3, 0, 0); - } -} - -void func_sh_802f3158(s32 index, s32 numChunks, s32 arg2, OSMesgQueue *retQueue) { - s32 val; - s32 v; - - val = ((u16 *) gAlBankSets)[func_sh_802f39a0(0, index)]; - v = gAlBankSets[val++]; - - while (v > 0) { - func_802f3f08(1, func_sh_802f39a0(1, gAlBankSets[val++]), numChunks, arg2, retQueue); - v--; - } -} - -u8 *func_sh_802f3220(u32 index, u32 *a1) { - s32 val; - - val = ((u16 *) gAlBankSets)[func_sh_802f39a0(0, index)]; - *a1 = gAlBankSets[val++]; - if (*a1 == 0) { - return NULL; - } - return &gAlBankSets[val]; -} - -void func_sh_802f3288(s32 idx) { - s32 s0; - s32 s2; - - idx = ((u16*)gAlBankSets)[func_sh_802f39a0(0, idx)]; - s2 = gAlBankSets[idx++]; - while (s2 > 0) { - s2--; - s0 = func_sh_802f39a0(1, gAlBankSets[idx++]); - - if (unk_pool1_lookup(1, s0) == 0) { - func_sh_802f3368(s0); - if (gBankLoadStatus[s0] != 5) { - gBankLoadStatus[s0] = 0; - } - - continue; - } - - } -} - -s32 func_sh_802f3368(s32 arg0) { - struct SoundMultiPool *pool = &gBankLoadedPool; - struct TemporaryPool *temporary = &pool->temporary; - struct PersistentPool *persistent; - u32 i; - - if (temporary->entries[0].id == arg0) { - temporary->entries[0].id = -1; - } else if (arg0 == temporary->entries[1].id) { - temporary->entries[1].id = -1; - } - - persistent = &pool->persistent; - for (i = 0; i < persistent->numEntries; i++) { - if (persistent->entries[i].id == arg0) { - persistent->entries[i].id = -1; - } - - } - - discard_bank(arg0); -} - - -void func_sh_802F3430(s32 arg0, s32 arg1, s32 arg2); -void func_sh_802F3410(s32 arg0, s32 arg1, s32 arg2) { - func_sh_802F3430(arg0, arg1, arg2); -} - -void func_sh_802F3430(s32 arg0, s32 arg1, s32 arg2) { - struct SequencePlayer *seqPlayer; - u8 *seqData; - u32 temp; - u32 s0; - s32 s1; - u8 bank; - u32 id; - - seqPlayer = &gSequencePlayers[arg0]; - - temp = func_sh_802f39a0(0, arg1); - sequence_player_disable(seqPlayer); - id = temp; - - s0 = ((u16 *) gAlBankSets)[id]; - s1 = gAlBankSets[s0++]; - bank = 0xff; - - while (s1 > 0) { - bank = gAlBankSets[s0++]; - func_sh_802f3688(bank); - s1--; - } - - seqData = func_sh_802F3564(id); - init_sequence_player(arg0); - seqPlayer->seqId = id; - seqPlayer->defaultBank[0] = bank; - seqPlayer->enabled = 1; - seqPlayer->seqData = seqData; - seqPlayer->scriptState.pc = seqData; - seqPlayer->scriptState.depth = 0; - seqPlayer->delay = 0; - seqPlayer->finished = 0; - - if (id) { - } - - for (id = 0; id < 0x10; id++) { - } - -} - -void *func_sh_802F3564(s32 arg0) { - void *a = func_sh_802f39a0(0, arg0); - s32 b; - return func_sh_802f3764(0, a, &b); -} - -extern u8 gUnkLoadStatus[0x40]; - -void *func_sh_802f3598(s32 idx, s32 *medium) { - void *ret; - ALSeqFile *f; - s32 temp; - s32 sp28; - - f = get_audio_file_header(2); - idx = func_sh_802f39a0(2, idx); - ret = get_bank_or_seq_wrapper(2, idx); - if (ret != NULL) { - if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5) { - gUnkLoadStatus[idx] = SOUND_LOAD_STATUS_COMPLETE; - } - - *medium = 0; - return ret; - } - - temp = f->seqArray[idx].magic[1]; - if (temp == 4) { - *medium = f->seqArray[idx].magic[0]; - return f->seqArray[idx].offset; - } else { - ret = func_sh_802f3764(2, idx, &sp28); - if (ret != 0) { - *medium = 0; - return ret; - } - - *medium = f->seqArray[idx].magic[0]; - } - return f->seqArray[idx].offset; - -} - -void *func_sh_802f3688(s32 idx) { - void *ret; - s32 bankId1; - s32 bankId2; - s32 sp38; - struct PatchStruct patchInfo; - - idx = func_sh_802f39a0(1, idx); - bankId1 = gCtlEntries[idx].bankId1; - bankId2 = gCtlEntries[idx].bankId2; - - patchInfo.bankId1 = bankId1; - patchInfo.bankId2 = bankId2; - - if (patchInfo.bankId1 != 0xFF) { - patchInfo.baseAddr1 = func_sh_802f3598(patchInfo.bankId1, &patchInfo.medium1); - } else { - patchInfo.baseAddr1 = NULL; - } - - if (bankId2 != 0xFF) { - patchInfo.baseAddr2 = func_sh_802f3598(bankId2, &patchInfo.medium2); - } else { - patchInfo.baseAddr2 = NULL; - } - - if ((ret = func_sh_802f3764(1, idx, &sp38)) == NULL) { - return NULL; - } - - if (sp38 == 1) { - func_sh_802f5310(idx, ret, &patchInfo, 0); - } - - return ret; -} - -void *func_sh_802f3764(s32 poolIdx, s32 idx, s32 *arg2) { - s32 size; - ALSeqFile *f; - void *vAddr; - s32 sp30; - UNUSED u32 pad2; - u8 *devAddr; - s8 loadStatus; - s32 sp18; - - vAddr = get_bank_or_seq_wrapper(poolIdx, idx); - if (vAddr != NULL) { - *arg2 = 0; - loadStatus = SOUND_LOAD_STATUS_COMPLETE; - } else { - f = get_audio_file_header(poolIdx); - size = f->seqArray[idx].len; - size = ALIGN16(size); - sp30 = f->seqArray[idx].magic[0]; - sp18 = f->seqArray[idx].magic[1]; - devAddr = f->seqArray[idx].offset; - - - switch (sp18) - { - case 0: - vAddr = unk_pool1_alloc(poolIdx, idx, size); - if (vAddr == NULL) { - return vAddr; - } - break; - case 1: - vAddr = alloc_bank_or_seq(poolIdx, size, 1, idx); - if (vAddr == NULL) { - return vAddr; - } - break; - case 2: - vAddr = alloc_bank_or_seq(poolIdx, size, 0, idx); - if (vAddr == NULL) { - return vAddr; - } - break; - - case 3: - case 4: - vAddr = alloc_bank_or_seq(poolIdx, size, 2, idx); - if (vAddr == NULL) { - return vAddr; - } - break; - } - - *arg2 = 1; - if (sp30 == 1) { - func_sh_802f3d78((uintptr_t) devAddr, vAddr, size, f->unk2); - } else { - func_sh_802f3c38((uintptr_t) devAddr, vAddr, size, sp30); - } - - switch (sp18) - { - case 0: - loadStatus = SOUND_LOAD_STATUS_5; - break; - - default: - loadStatus = SOUND_LOAD_STATUS_COMPLETE; - break; - } - } - - switch (poolIdx) - { - case 0: - if (gSeqLoadStatus[idx] != SOUND_LOAD_STATUS_5) { - gSeqLoadStatus[idx] = loadStatus; - } - break; - - case 1: - if (gBankLoadStatus[idx] != SOUND_LOAD_STATUS_5) { - gBankLoadStatus[idx] = loadStatus; - } - break; - - case 2: - if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5) { - gUnkLoadStatus[idx] = loadStatus; - } - break; - } - - return vAddr; -} - -s32 func_sh_802f39a0(s32 arg0, s32 idx) { - ALSeqFile *f; - - f = get_audio_file_header(arg0); - if (f->seqArray[idx].len == 0) { - idx = (s32) f->seqArray[idx].offset; // TODO: something doesn't seem right here... - } - return idx; -} - -void *get_bank_or_seq_wrapper(s32 poolIdx, s32 id) { - void *ret; - - ret = unk_pool1_lookup(poolIdx, id); - if (ret != NULL) { - return ret; - } - ret = get_bank_or_seq(poolIdx, 2, id); - if (ret != 0) { - return ret; - } - return NULL; -} - -ALSeqFile *get_audio_file_header(s32 index) { - ALSeqFile *ret; - switch(index) { - default: - ret = NULL; - break; - case 0: - ret = gSeqFileHeader; - break; - case 1: - ret = gAlCtlHeader; - break; - case 2: - ret = gAlTbl; - break; - } - return ret; -} -#endif - // on US/JP this inlines patch_sound, using some -sopt compiler flag -#if defined(VERSION_SH) -void patch_audio_bank(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo) { -#else void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32 numDrums) { -#endif struct Instrument *instrument; -#if defined(VERSION_SH) - void **itInstrs; -#else struct Instrument **itInstrs; -#endif struct Instrument **end; -#if defined(VERSION_SH) - s32 i; -#else - struct AudioBank *temp; // Maybe Shindou also has this; I'm not sure. + struct AudioBank *temp; u32 i; -#endif void *patched; struct Drum *drum; -#ifndef VERSION_SH struct Drum **drums; -#endif #if defined(VERSION_EU) u32 numDrums2; -#elif defined(VERSION_SH) - s32 numDrums2; - s32 numInstruments2; #endif -#define BASE_OFFSET(x, base) (void *)((uintptr_t) (x) + (uintptr_t) base) -#define PATCH(x, base) (patched = BASE_OFFSET(x, base)) +#define BASE_OFFSET_REAL(x, base) (void *)((uintptr_t) (x) + (uintptr_t) base) +#define PATCH(x, base) (patched = BASE_OFFSET_REAL(x, base)) #define PATCH_MEM(x) x = PATCH(x, mem) -#if defined(VERSION_SH) - numDrums2 = gCtlEntries[bankId].numDrums; - numInstruments2 = gCtlEntries[bankId].numInstruments; - itInstrs = mem->drums; - if (mem->drums) { - } +#if defined(VERSION_JP) || defined(VERSION_US) +#define BASE_OFFSET(x, base) BASE_OFFSET_REAL(x, base) #else - drums = mem->drums; +#define BASE_OFFSET(x, base) BASE_OFFSET_REAL(base, x) #endif + + drums = mem->drums; #if defined(VERSION_JP) || defined(VERSION_US) if (drums != NULL && numDrums > 0) { mem->drums = (void *)((uintptr_t) drums + (uintptr_t) mem); if (numDrums > 0) //! unneeded when -sopt is enabled for (i = 0; i < numDrums; i++) { #else -#if defined(VERSION_EU) numDrums2 = numDrums; if (drums != NULL && numDrums2 > 0) { mem->drums = PATCH(drums, mem); -#elif defined(VERSION_SH) - if (itInstrs != NULL && numDrums2 != 0) { - if (1) { - mem->drums = PATCH(itInstrs, mem); - } -#endif for (i = 0; i < numDrums2; i++) { #endif patched = mem->drums[i]; @@ -1102,16 +520,11 @@ void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32 //! copt replaces drum with 'patched' for these two lines PATCH_SOUND(&(*(struct Drum *)patched).sound, mem, offset); patched = (*(struct Drum *)patched).envelope; - drum->envelope = BASE_OFFSET(mem, patched); #else -#if defined(VERSION_EU) patch_sound(&drum->sound, (u8 *) mem, offset); -#elif defined(VERSION_SH) - func_sh_802f51d4(&drum->sound, mem, patchInfo); -#endif patched = drum->envelope; - drum->envelope = BASE_OFFSET(patched, mem); #endif + drum->envelope = BASE_OFFSET(mem, patched); drum->loaded = 1; } @@ -1119,25 +532,17 @@ void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32 } } -#ifndef VERSION_SH //! Doesn't affect EU, but required for US/JP temp = &*mem; -#endif #if defined(VERSION_JP) || defined(VERSION_US) if (numInstruments >= 1) #endif -#if defined(VERSION_SH) - if (numInstruments2 > 0) { - itInstrs = mem->instruments; - end = numInstruments2 + (struct Instrument **) itInstrs; -#else if (numInstruments > 0) { //! Doesn't affect EU, but required for US/JP struct Instrument **tempInst; itInstrs = temp->instruments; tempInst = temp->instruments; end = numInstruments + tempInst; -#endif #if defined(VERSION_JP) || defined(VERSION_US) l2: @@ -1145,144 +550,35 @@ l2: do { #endif if (*itInstrs != NULL) { -#ifdef VERSION_SH - *itInstrs = BASE_OFFSET(mem, *itInstrs); -#else *itInstrs = BASE_OFFSET(*itInstrs, mem); -#endif instrument = *itInstrs; if (instrument->loaded == 0) { -#if defined(VERSION_JP) || defined(VERSION_US) PATCH_SOUND(&instrument->lowNotesSound, (u8 *) mem, offset); PATCH_SOUND(&instrument->normalNotesSound, (u8 *) mem, offset); PATCH_SOUND(&instrument->highNotesSound, (u8 *) mem, offset); -#elif defined(VERSION_EU) - patch_sound(&instrument->lowNotesSound, (u8 *) mem, offset); - patch_sound(&instrument->normalNotesSound, (u8 *) mem, offset); - patch_sound(&instrument->highNotesSound, (u8 *) mem, offset); -#elif defined(VERSION_SH) - if (instrument->normalRangeLo != 0) { - func_sh_802f51d4(&instrument->lowNotesSound, mem, patchInfo); - } - func_sh_802f51d4(&instrument->normalNotesSound, mem, patchInfo); - if (instrument->normalRangeHi != 0x7F) { - func_sh_802f51d4(&instrument->highNotesSound, mem, patchInfo); - } -#endif patched = instrument->envelope; - -#if defined(VERSION_JP) || defined(VERSION_US) instrument->envelope = BASE_OFFSET(mem, patched); instrument->loaded = 1; -#else - instrument->envelope = BASE_OFFSET(patched, mem); - instrument->loaded = 1; -#endif } } -#ifndef VERSION_SH itInstrs++; -#else - itInstrs = ((struct Instrument **) itInstrs) + 1; -#endif #if defined(VERSION_JP) || defined(VERSION_US) //! goto generated by copt, required to match US/JP if (end != itInstrs) { goto l2; } #else -#ifdef VERSION_EU } while (end != itInstrs); -#else - } while ((struct Instrument **) itInstrs != (0, end)); //! This is definitely fake -#endif #endif } -#if defined(VERSION_SH) - gCtlEntries[bankId].drums = mem->drums; - gCtlEntries[bankId].instruments = mem->instruments; -#endif #undef PATCH_MEM #undef PATCH +#undef BASE_OFFSET_REAL #undef BASE_OFFSET #undef PATCH_SOUND } -#if defined(VERSION_SH) -void func_sh_802f3ed4(UNUSED s32 arg0, UNUSED s32 arg1, UNUSED void *vAddr, UNUSED size_t nbytes); - -extern char shindouDebugPrint81[]; -extern char shindouDebugPrint82[]; -void func_sh_802f3c38(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 medium) { - nbytes = ALIGN16(nbytes); - osInvalDCache(vAddr, nbytes); - -lock: - if (gAudioLoadLockSH != 0) { - goto lock; - } - - if (nbytes >= 0x400U) { - func_sh_802f3dd0(&gAudioDmaIoMesg, 1, 0, devAddr, vAddr, 0x400, &gAudioDmaMesgQueue, medium, shindouDebugPrint81); - osRecvMesg(&gAudioDmaMesgQueue, NULL, 1); - nbytes = nbytes - 0x400; - devAddr = devAddr + 0x400; - vAddr = (u8*)vAddr + 0x400; - goto lock; - } - - if (nbytes != 0) { - func_sh_802f3dd0(&gAudioDmaIoMesg, 1, 0, devAddr, vAddr, nbytes, &gAudioDmaMesgQueue, medium, shindouDebugPrint82); - osRecvMesg(&gAudioDmaMesgQueue, NULL, 1); - } -} - -void func_sh_802f3d78(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) { - uintptr_t sp1C; - - sp1C = devAddr; - osInvalDCache(vAddr, nbytes); - func_sh_802f3ed4(func_sh_802f3ec4(arg3, &sp1C), sp1C, vAddr, nbytes); -} - -s32 func_sh_802f3dd0(OSIoMesg *m, s32 pri, s32 direction, uintptr_t devAddr, void *dramAddr, s32 size, OSMesgQueue *retQueue, s32 medium, const char *arg8) { - OSPiHandle *handle; - if (gAudioLoadLockSH >= 0x11U) { - return -1; - } - switch (medium) { - case 2: - handle = osCartRomInit(); - break; - case 3: - handle = osDriveRomInit(); - break; - default: - return 0; - } - if ((size & 0xf) != 0) { - size = ALIGN16(size); - } - m->hdr.pri = pri; - m->hdr.retQueue = retQueue; - m->dramAddr = dramAddr; - m->devAddr = devAddr; - m->size = size; - handle->transferInfo.cmdType = 2; - osEPiStartDma(handle, m, direction); - return 0; -} - -s32 func_sh_802f3ec4(UNUSED s32 arg0, UNUSED uintptr_t *arg1) { - return 0; -} - -void func_sh_802f3ed4(UNUSED s32 arg0, UNUSED s32 arg1, UNUSED void *vAddr, UNUSED size_t nbytes) { -} -#endif - -#ifndef VERSION_SH struct AudioBank *bank_load_immediate(s32 bankId, s32 arg1) { UNUSED u32 pad1[4]; u32 buf[4]; @@ -1314,9 +610,7 @@ struct AudioBank *bank_load_immediate(s32 bankId, s32 arg1) { gBankLoadStatus[bankId] = SOUND_LOAD_STATUS_COMPLETE; return ret; } -#endif -#ifndef VERSION_SH struct AudioBank *bank_load_async(s32 bankId, s32 arg1, struct SequencePlayer *seqPlayer) { u32 numInstruments, numDrums; UNUSED u32 pad1[2]; @@ -1372,9 +666,7 @@ struct AudioBank *bank_load_async(s32 bankId, s32 arg1, struct SequencePlayer *s gBankLoadStatus[bankId] = SOUND_LOAD_STATUS_IN_PROGRESS; return ret; } -#endif -#ifndef VERSION_SH void *sequence_dma_immediate(s32 seqId, s32 arg1) { s32 seqLength; void *ptr; @@ -1392,9 +684,7 @@ void *sequence_dma_immediate(s32 seqId, s32 arg1) { gSeqLoadStatus[seqId] = SOUND_LOAD_STATUS_COMPLETE; return ptr; } -#endif -#ifndef VERSION_SH void *sequence_dma_async(s32 seqId, s32 arg1, struct SequencePlayer *seqPlayer) { s32 seqLength; void *ptr; @@ -1431,9 +721,7 @@ void *sequence_dma_async(s32 seqId, s32 arg1, struct SequencePlayer *seqPlayer) } return ptr; } -#endif -#ifndef VERSION_SH u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) { void *temp; u32 bankId; @@ -1443,7 +731,7 @@ u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) { *nullCount = 0; *nonNullCount = 0; -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) offset = ((u16 *) gAlBankSets)[seqId]; for (i = gAlBankSets[offset++], ret = 0; i != 0; i--) { bankId = gAlBankSets[offset++]; @@ -1455,12 +743,10 @@ u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) { #endif if (IS_BANK_LOAD_COMPLETE(bankId) == TRUE) { -#ifndef VERSION_SH -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) temp = get_bank_or_seq(&gBankLoadedPool, 2, bankId); #else temp = get_bank_or_seq(&gBankLoadedPool, 2, gAlBankSets[offset - 1]); -#endif #endif } else { temp = NULL; @@ -1476,10 +762,8 @@ u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) { return ret; } -#endif -#ifndef VERSION_SH -struct AudioBank *load_banks_immediate(s32 seqId, u8 *arg1) { +struct AudioBank *load_banks_immediate(s32 seqId, u8 *outDefaultBank) { void *ret; u32 bankId; u16 offset; @@ -1510,12 +794,10 @@ struct AudioBank *load_banks_immediate(s32 seqId, u8 *arg1) { ret = bank_load_immediate(bankId, 2); } } - *arg1 = bankId; + *outDefaultBank = bankId; return ret; } -#endif -#ifndef VERSION_SH void preload_sequence(u32 seqId, u8 preloadMask) { void *sequenceData; u8 temp; @@ -1545,9 +827,7 @@ void preload_sequence(u32 seqId, u8 preloadMask) { gAudioLoadLock = AUDIO_LOCK_NOT_LOADING; } -#endif -#ifndef VERSION_SH void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync); void load_sequence(u32 player, u32 seqId, s32 loadAsync) { @@ -1559,9 +839,7 @@ void load_sequence(u32 player, u32 seqId, s32 loadAsync) { gAudioLoadLock = AUDIO_LOCK_NOT_LOADING; } } -#endif -#ifndef VERSION_SH void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) { void *sequenceData; struct SequencePlayer *seqPlayer = &gSequencePlayers[player]; @@ -1575,26 +853,16 @@ void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) { if (loadAsync) { s32 numMissingBanks = 0; s32 dummy = 0; -#ifdef VERSION_SH - s32 bankId = 0xBA17; // dummy code to avoid problems -#else s32 bankId = get_missing_bank(seqId, &dummy, &numMissingBanks); -#endif if (numMissingBanks == 1) { -#ifndef VERSION_SH eu_stubbed_printf_0("Ok,one bank slow load Start \n"); if (bank_load_async(bankId, 2, seqPlayer) == NULL) { return; } -#endif // @bug This should set the last bank (i.e. the first in the JSON) // as default, not the missing one. This code path never gets // taken, though -- all sequence loading is synchronous. seqPlayer->defaultBank[0] = bankId; -#ifdef VERSION_SH - } - } -#else } else { eu_stubbed_printf_1("Sorry,too many %d bank is none.fast load Start \n", numMissingBanks); if (load_banks_immediate(seqId, &seqPlayer->defaultBank[0]) == NULL) { @@ -1604,29 +872,23 @@ void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) { } else if (load_banks_immediate(seqId, &seqPlayer->defaultBank[0]) == NULL) { return; } -#endif eu_stubbed_printf_2("Seq %d:Default Load Id is %d\n", seqId, seqPlayer->defaultBank[0]); eu_stubbed_printf_0("Seq Loading Start\n"); seqPlayer->seqId = seqId; -#ifndef VERSION_SH sequenceData = get_bank_or_seq(&gSeqLoadedPool, 2, seqId); -#endif if (sequenceData == NULL) { if (seqPlayer->seqDmaInProgress) { eu_stubbed_printf_0("Error:Before Sequence-SlowDma remain.\n"); eu_stubbed_printf_0(" Cancel Seq Start.\n"); return; } -#ifndef VERSION_SH if (loadAsync) { sequenceData = sequence_dma_async(seqId, 2, seqPlayer); } else { - sequenceData = sequence_dma_immediate(seqId, 2); } -#endif if (sequenceData == NULL) { return; @@ -1641,142 +903,11 @@ void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) { seqPlayer->seqData = sequenceData; seqPlayer->scriptState.pc = sequenceData; } -#endif -#if defined(VERSION_SH) -void *func_sh_802f3ee8(uintptr_t devAddr, void *vAddr) { - s32 b; - return func_sh_802f3764(devAddr, vAddr, &b); -} - -void *func_802f3f08(s32 poolIdx, s32 idx, s32 numChunks, s32 arg3, OSMesgQueue *retQueue) { - s32 size; - ALSeqFile *f; - void *vAddr; - s32 medium; - s32 sp18; - uintptr_t devAddr; - s32 loadStatus; - - switch (poolIdx) { - case 0: - if (gSeqLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) { - return 0; - } - break; - case 1: - if (gBankLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) { - return 0; - } - break; - case 2: - if (gUnkLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) { - return 0; - } - break; - - } - vAddr = get_bank_or_seq_wrapper(poolIdx, idx); - if (vAddr != NULL) { - loadStatus = 2; - osSendMesg(retQueue, (OSMesg) (arg3 << 0x18), 0); - } else { - f = get_audio_file_header(poolIdx); - size = f->seqArray[idx].len; - size = ALIGN16(size); - medium = f->seqArray[idx].magic[0]; - sp18 = f->seqArray[idx].magic[1]; - devAddr = (uintptr_t) f->seqArray[idx].offset; - loadStatus = 2; - - switch (sp18) { - case 0: - vAddr = unk_pool1_alloc(poolIdx, idx, size); - if (vAddr == NULL) { - return vAddr; - } - loadStatus = 5; - break; - case 1: - vAddr = alloc_bank_or_seq(poolIdx, size, 1, idx); - if (vAddr == NULL) { - return vAddr; - } - break; - case 2: - vAddr = alloc_bank_or_seq(poolIdx, size, 0, idx); - if (vAddr == NULL) { - return vAddr; - } - break; - - case 4: - case 3: - vAddr = alloc_bank_or_seq(poolIdx, size, 2, idx); - if (vAddr == NULL) { - return vAddr; - } - break; - } - - func_sh_802f4cb4(devAddr, vAddr, size, medium, numChunks, retQueue, (arg3 << 0x18) | (poolIdx << 0x10) | (idx << 8) | loadStatus); - loadStatus = SOUND_LOAD_STATUS_IN_PROGRESS; - } - - switch (poolIdx) { - case 0: - if (gSeqLoadStatus[idx] != 5) { - gSeqLoadStatus[idx] = loadStatus; - } - break; - - case 1: - if (gBankLoadStatus[idx] != 5) { - gBankLoadStatus[idx] = loadStatus; - } - break; - - case 2: - if (gUnkLoadStatus[idx] != 5) { - gUnkLoadStatus[idx] = loadStatus; - } - break; - } - - return vAddr; -} - -void func_802f41e4(s32 audioResetStatus) { - func_sh_802f4a4c(audioResetStatus); - func_sh_802f573c(audioResetStatus); - func_sh_802f4dcc(audioResetStatus); -} -#endif - -#if defined(VERSION_SH) -u8 gShindouSoundBanksHeader[] = { -#include "sound/ctl_header.inc.c" -}; - -u8 gBankSetsData[] = { -#include "sound/bank_sets.inc.c" -}; - -u8 gShindouSampleBanksHeader[] = { -#include "sound/tbl_header.inc.c" -}; - -u8 gShindouSequencesHeader[] = { -#include "sound/sequences_header.inc.c" -}; -#endif - -// (void) must be omitted from parameters +// (void) must be omitted from parameters to fix stack with -framepointer void audio_init() { #if defined(VERSION_EU) UNUSED s8 pad[16]; -#elif defined(VERSION_SH) - UNUSED s8 pad[24]; #else UNUSED s8 pad[32]; #endif @@ -1785,7 +916,7 @@ void audio_init() { #endif s32 i, j, k; UNUSED s32 lim1; // lim1 unused in EU -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) UNUSED u8 buf[0x10]; s32 UNUSED lim2, lim3; #else @@ -1795,15 +926,8 @@ void audio_init() { UNUSED u64 *ptr64; void *data; UNUSED s32 pad2; -#ifdef VERSION_SH - s32 seqCount; -#endif -#ifdef VERSION_SH - gAudioLoadLockSH = 0; -#else gAudioLoadLock = AUDIO_LOCK_UNINITIALIZED; -#endif #if defined(VERSION_JP) || defined(VERSION_US) lim1 = gUnusedCount80333EE8; @@ -1842,21 +966,16 @@ void audio_init() { } #endif -#ifdef VERSION_EU D_EU_802298D0 = 20.03042f; gRefreshRate = 50; port_eu_init(); if (k) { } -#else - D_EU_802298D0 = 16.713f; - gRefreshRate = 60; - func_sh_802f6a9c(); -#endif #endif #ifdef TARGET_N64 - eu_stubbed_printf_3("Clear Workarea %x -%x size %x \n", + eu_stubbed_printf_3( + "Clear Workarea %x -%x size %x \n", (uintptr_t) &gAudioGlobalsStartMarker, (uintptr_t) &gAudioGlobalsEndMarker, (uintptr_t) &gAudioGlobalsEndMarker - (uintptr_t) &gAudioGlobalsStartMarker @@ -1879,28 +998,20 @@ void audio_init() { osCreateMesgQueue(&gAudioDmaMesgQueue, &gAudioDmaMesg, 1); osCreateMesgQueue(&gCurrAudioFrameDmaQueue, gCurrAudioFrameDmaMesgBufs, ARRAY_COUNT(gCurrAudioFrameDmaMesgBufs)); -#ifdef VERSION_SH - osCreateMesgQueue(&gUnkQueue1, gUnkMesgBufs1, 0x10); - osCreateMesgQueue(&gUnkQueue2, gUnkMesgBufs2, 0x10); -#endif gCurrAudioFrameDmaCount = 0; gSampleDmaNumListItems = 0; sound_init_main_pools(gAudioInitPoolSize); for (i = 0; i < NUMAIBUFFERS; i++) { -#ifdef VERSION_SH - gAiBuffers[i] = sound_alloc_uninitialized(&gAudioInitPool, AIBUFFER_LEN); -#else gAiBuffers[i] = soundAlloc(&gAudioInitPool, AIBUFFER_LEN); -#endif for (j = 0; j < (s32) (AIBUFFER_LEN / sizeof(s16)); j++) { gAiBuffers[i][j] = 0; } } -#if defined(VERSION_EU) || defined(VERSION_SH) +#if defined(VERSION_EU) gAudioResetPresetIdToLoad = 0; gAudioResetStatus = 1; audio_shut_down_and_reset_step(); @@ -1913,31 +1024,7 @@ void audio_init() { eu_stubbed_printf_3("Heap %x %x %x\n", 0, 0, 0); eu_stubbed_printf_0("Main Heap Initialize.\n"); - // Load header for sequence data (assets/music_data.sbk.s) -#ifdef VERSION_SH - gSeqFileHeader = (ALSeqFile *) gShindouSequencesHeader; - gAlCtlHeader = (ALSeqFile *) gShindouSoundBanksHeader; - gAlTbl = (ALSeqFile *) gShindouSampleBanksHeader; - gAlBankSets = gBankSetsData; - gSequenceCount = (s16) gSeqFileHeader->seqCount; - patch_seq_file(gSeqFileHeader, gMusicData, D_SH_80315EF4); - patch_seq_file(gAlCtlHeader, gSoundDataADSR, D_SH_80315EF8); - patch_seq_file(gAlTbl, gSoundDataRaw, D_SH_80315EFC); - seqCount = gAlCtlHeader->seqCount; - gCtlEntries = sound_alloc_uninitialized(&gAudioInitPool, seqCount * sizeof(struct CtlEntry)); - for (i = 0; i < seqCount; i++) { - gCtlEntries[i].bankId1 = (u8) ((gAlCtlHeader->seqArray[i].ctl.as_s16.bankAndFf >> 8) & 0xff); - gCtlEntries[i].bankId2 = (u8) (gAlCtlHeader->seqArray[i].ctl.as_s16.bankAndFf & 0xff); - gCtlEntries[i].numInstruments = (u8) ((gAlCtlHeader->seqArray[i].ctl.as_s16.numInstrumentsAndDrums >> 8) & 0xff); - gCtlEntries[i].numDrums = (u8) (gAlCtlHeader->seqArray[i].ctl.as_s16.numInstrumentsAndDrums & 0xff); - } - data = sound_alloc_uninitialized(&gAudioInitPool, D_SH_80315EF0); - if (data == NULL) { - D_SH_80315EF0 = 0; - } - sound_alloc_pool_init(&gUnkPool1.pool, data, D_SH_80315EF0); - init_sequence_players(); -#else + // Load headers for sounds and sequences gSeqFileHeader = (ALSeqFile *) buf; data = gMusicData; audio_dma_copy_immediate((uintptr_t) data, gSeqFileHeader, 0x10); @@ -1952,7 +1039,7 @@ void audio_init() { audio_dma_copy_immediate((uintptr_t) data, gSeqFileHeader, size); alSeqFileNew(gSeqFileHeader, data); - // Load header for CTL (assets/sound_data.ctl.s, i.e. ADSR) + // Load header for CTL (instrument metadata) gAlCtlHeader = (ALSeqFile *) buf; data = gSoundDataADSR; audio_dma_copy_immediate((uintptr_t) data, gAlCtlHeader, 0x10); @@ -1963,7 +1050,7 @@ void audio_init() { audio_dma_copy_immediate((uintptr_t) data, gAlCtlHeader, size); alSeqFileNew(gAlCtlHeader, data); - // Load header for TBL (assets/sound_data.tbl.s, i.e. raw data) + // Load header for TBL (raw sound data) gAlTbl = (ALSeqFile *) buf; audio_dma_copy_immediate((uintptr_t) data, gAlTbl, 0x10); size = gAlTbl->seqCount * sizeof(ALSeqData) + 4; @@ -1972,7 +1059,7 @@ void audio_init() { audio_dma_copy_immediate((uintptr_t) gSoundDataRaw, gAlTbl, size); alSeqFileNew(gAlTbl, gSoundDataRaw); - // Load bank sets for each sequence (assets/bank_sets.s) + // Load bank sets for each sequence gAlBankSets = soundAlloc(&gAudioInitPool, 0x100); audio_dma_copy_immediate((uintptr_t) gBankSetsData, gAlBankSets, 0x100); @@ -1985,535 +1072,5 @@ void audio_init() { eu_stubbed_printf_1(" Seqdrv :[%6d]\n", 0); // gMusicData eu_stubbed_printf_1(" audiodata :[%6d]\n", 0); // gSoundDataRaw eu_stubbed_printf_0("---------------------------------------\n"); -#endif -} - -#if defined(VERSION_SH) -s32 func_802f47c8(s32 bankId, u8 idx, s8 *io) { - struct AudioBankSample *sample = func_sh_802f4978(bankId, idx); - struct PendingDmaSample *temp; - if (sample == NULL) { - *io = 0; - return -1; - } - if (sample->medium == 0) { - *io = 2; - return 0; - } - temp = &D_SH_80343D00.arr[D_SH_80343D00.someIndex]; - if (temp->state == 3) { - temp->state = 0; - } - temp->sample = *sample; - temp->io = io; - temp->vAddr = func_sh_802f1d40(sample->size, bankId, sample->sampleAddr, sample->medium); - if (temp->vAddr == NULL) { - if (sample->medium == 1 || sample->codec == 2) { - *io = 0; - return -1; - } else { - *io = 3; - return -1; - } - } - temp->state = 1; - temp->remaining = ALIGN16(sample->size); - temp->resultSampleAddr = (u8 *) temp->vAddr; - temp->devAddr = (uintptr_t) sample->sampleAddr; - temp->medium = sample->medium; - temp->bankId = bankId; - temp->idx = idx; - D_SH_80343D00.someIndex ^= 1; - return 0; -} - -struct AudioBankSample *func_sh_802f4978(s32 bankId, s32 idx) { - struct Drum *drum; - struct Instrument *inst; - struct AudioBankSample *ret; - - if (idx < 128) { - inst = get_instrument_inner(bankId, idx); - if (inst == 0) { - return NULL; - } - ret = inst->normalNotesSound.sample; - } else { - drum = get_drum(bankId, idx - 128); - if (drum == 0) { - return NULL; - } - ret = drum->sound.sample; - } - return ret; -} -void stub_sh_802f49dc(void) { - -} - -void func_sh_802f49e4(struct PendingDmaSample *arg0) { - struct AudioBankSample *sample = func_sh_802f4978(arg0->bankId, arg0->idx); - if (sample != NULL) { - arg0->sample = *sample; - sample->sampleAddr = arg0->resultSampleAddr; - sample->medium = 0; - } -} - -void func_sh_802f4a4c(s32 audioResetStatus) { - ALSeqFile *alTbl; - struct PendingDmaSample *entry; - - s32 i; - - alTbl = gAlTbl; - - for (i = 0; i < 2; i++) { - entry = &D_SH_80343D00.arr[i]; - switch (entry->state) { - case 2: - osRecvMesg(&entry->queue, NULL, 1); - if (audioResetStatus != 0) { - entry->state = 3; - break; - } - // fallthrough - case 1: - entry->state = 2; - if (entry->remaining == 0) { - func_sh_802f49e4(entry); - entry->state = 3; - *entry->io = 1; - } else if (entry->remaining < 0x1000) { - if (1 == entry->medium) { - func_sh_802f4c5c(entry->devAddr, entry->vAddr, entry->remaining, alTbl->unk2); - } else { - func_sh_802f4bd8(entry, entry->remaining); - } - entry->remaining = 0; - } else { - if (1 == entry->medium) { - func_sh_802f4c5c(entry->devAddr, entry->vAddr, 0x1000, alTbl->unk2); - } else { - func_sh_802f4bd8(entry, 0x1000); - } - entry->remaining = (s32) (entry->remaining - 0x1000); - entry->vAddr = (u8 *) entry->vAddr + 0x1000; - entry->devAddr = entry->devAddr + 0x1000; - } - break; - } - } -} - -extern char shindouDebugPrint102[]; -void func_sh_802f4bd8(struct PendingDmaSample *arg0, s32 len) { // len must be signed - osInvalDCache(arg0->vAddr, len); - osCreateMesgQueue(&arg0->queue, arg0->mesgs, 1); - func_sh_802f3dd0(&arg0->ioMesg, 0, 0, arg0->devAddr, arg0->vAddr, len, &arg0->queue, arg0->medium, shindouDebugPrint102); -} - -void func_sh_802f4c5c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) { - uintptr_t sp1C; - - sp1C = devAddr; - osInvalDCache(vAddr, nbytes); - func_sh_802f3ed4(func_sh_802f3ec4(arg3, &sp1C), sp1C, vAddr, nbytes); -} - -struct PendingDmaAudioBank *func_sh_802f4cb4(uintptr_t devAddr, void *vAddr, s32 size, s32 medium, s32 numChunks, OSMesgQueue *retQueue, s32 encodedInfo) { - struct PendingDmaAudioBank *item; - s32 i; - - for (i = 0; i < ARRAY_COUNT(D_SH_8034F690); i++) { - if (D_SH_8034F690[i].inProgress == 0) { - item = &D_SH_8034F690[i]; - break; - } - } - if (i == ARRAY_COUNT(D_SH_8034F690)) { - return NULL; - } - - item->inProgress = 1; - item->devAddr = devAddr; - item->audioBank = vAddr; - item->vAddr = vAddr; - item->remaining = size; - if (numChunks == 0) { - item->transferSize = 0x1000; - } else { - item->transferSize = ((size / numChunks) + 0xFF) & ~0xFF; - if (item->transferSize < 0x100) { - item->transferSize = 0x100; - } - } - item->retQueue = retQueue; - item->timer = 3; - item->medium = medium; - item->encodedInfo = encodedInfo; - osCreateMesgQueue(&item->dmaRetQueue, item->mesgs, 1); - return item; -} - -void func_sh_802f4dcc(s32 audioResetStatus) { - s32 i; - - if (gAudioLoadLockSH != 1) { - for (i = 0; i < ARRAY_COUNT(D_SH_8034F690); i++) { - if (D_SH_8034F690[i].inProgress == 1) { - func_sh_802f4e50(&D_SH_8034F690[i], audioResetStatus); - } - } - } -} - -void func_sh_802f4e50(struct PendingDmaAudioBank *audioBank, s32 audioResetStatus) { - ALSeqFile *alSeqFile; - u32 *encodedInfo; - OSMesg mesg; - u32 temp; - u32 seqId; - s32 bankId1; - s32 bankId2; - struct PatchStruct patchStruct; - alSeqFile = gAlTbl; - if (audioBank->timer >= 2) { - audioBank->timer--; - return; - } - if (audioBank->timer == 1) { - audioBank->timer = 0; - } else { - if (audioResetStatus != 0) { - osRecvMesg(&audioBank->dmaRetQueue, NULL, OS_MESG_BLOCK); - audioBank->inProgress = 0; - return; - } - if (osRecvMesg(&audioBank->dmaRetQueue, NULL, OS_MESG_NOBLOCK) == -1) { - return; - } - } - - encodedInfo = &audioBank->encodedInfo; - if (audioBank->remaining == 0) { - mesg = (OSMesg) audioBank->encodedInfo; - mesg = mesg; //! needs an extra read from mesg here to match... - temp = *encodedInfo; - seqId = (temp >> 8) & 0xFF; - switch ((u8) (temp >> 0x10)) { - case 0: - if (gSeqLoadStatus[seqId] != 5) { - gSeqLoadStatus[seqId] = (u8) (temp & 0xFF); - } - break; - case 2: - if (gUnkLoadStatus[seqId] != 5) { - gUnkLoadStatus[seqId] = (u8) (temp & 0xFF); - } - break; - case 1: - if (gBankLoadStatus[seqId] != 5) { - gBankLoadStatus[seqId] = (u8) (temp & 0xFF); - } - bankId1 = gCtlEntries[seqId].bankId1; - bankId2 = gCtlEntries[seqId].bankId2; - patchStruct.bankId1 = bankId1; - patchStruct.bankId2 = bankId2; - if (bankId1 != 0xFF) { - patchStruct.baseAddr1 = func_sh_802f3598(bankId1, &patchStruct.medium1); - } else { - patchStruct.baseAddr1 = NULL; - } - if (bankId2 != 0xFF) { - patchStruct.baseAddr2 = func_sh_802f3598(bankId2, &patchStruct.medium2); - } else { - patchStruct.baseAddr2 = NULL; - } - - func_sh_802f5310(seqId, audioBank->audioBank, &patchStruct, 1); - break; - } - mesg = (OSMesg) audioBank->encodedInfo; - audioBank->inProgress = 0; - osSendMesg(audioBank->retQueue, mesg, OS_MESG_NOBLOCK); - } else if (audioBank->remaining < audioBank->transferSize) { - if (audioBank->medium == 1) { - func_sh_802f517c(audioBank->devAddr, audioBank->vAddr, audioBank->remaining, alSeqFile->unk2); - } else { - func_sh_802f50ec(audioBank, audioBank->remaining); - } - - audioBank->remaining = 0; - } else { - if (audioBank->medium == 1) { - func_sh_802f517c(audioBank->devAddr, audioBank->vAddr, audioBank->transferSize, alSeqFile->unk2); - } else { - func_sh_802f50ec(audioBank, audioBank->transferSize); - } - - audioBank->remaining -= audioBank->transferSize; - audioBank->devAddr += audioBank->transferSize; - audioBank->vAddr = ((u8 *) audioBank->vAddr) + audioBank->transferSize; - } -} - -extern char shindouDebugPrint110[]; -void func_sh_802f50ec(struct PendingDmaAudioBank *arg0, size_t len) { - len += 0xf; - len &= ~0xf; - osInvalDCache(arg0->vAddr, len); - osCreateMesgQueue(&arg0->dmaRetQueue, arg0->mesgs, 1); - func_sh_802f3dd0(&arg0->ioMesg, 0, 0, arg0->devAddr, arg0->vAddr, len, &arg0->dmaRetQueue, arg0->medium, shindouDebugPrint110); -} - - -void func_sh_802f517c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) { - uintptr_t sp1C; - - sp1C = devAddr; - osInvalDCache(vAddr, nbytes); - func_sh_802f3ed4(func_sh_802f3ec4(arg3, &sp1C), sp1C, vAddr, nbytes); -} - -void func_sh_802f51d4(struct AudioBankSound *sound, struct AudioBank *memBase, struct PatchStruct *patchInfo) { - struct AudioBankSample *sample; - void *patched; - -#define PATCH(x, base) (patched = (void *)((uintptr_t) (x) + (uintptr_t) base)) - - if ((uintptr_t) sound->sample <= 0x80000000) { - sample = sound->sample = PATCH(sound->sample, memBase); - if (sample->size != 0 && sample->isPatched != TRUE) { - sample->loop = PATCH(sample->loop, memBase); - sample->book = PATCH(sample->book, memBase); - switch (sample->medium) { - case 0: - sample->sampleAddr = PATCH(sample->sampleAddr, patchInfo->baseAddr1); - sample->medium = patchInfo->medium1; - break; - case 1: - sample->sampleAddr = PATCH(sample->sampleAddr, patchInfo->baseAddr2); - sample->medium = patchInfo->medium2; - break; - - case 2: - case 3: - break; - } - sample->isPatched = TRUE; - if (sample->bit1 && sample->medium != 0) { - D_SH_8034EA88[D_SH_8034F688++] = sample; - } - } - } -#undef PATCH -} - -s32 func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo, s32 arg3) { - UNUSED u32 pad[2]; - u8 *addr; - UNUSED u32 pad1[3]; - s32 sp4C; - struct AudioBankSample *temp_s0; - s32 i; - s32 count; - s32 temp; - - sp4C = 0; - if (D_SH_8034F68C != 0) { - sp4C = 1; - } else { - D_SH_80343CF0 = 0; - } - D_SH_8034F688 = 0; - patch_audio_bank(bankId, mem, patchInfo); - - count = 0; - for (i = 0; i < D_SH_8034F688; i++) { - count += ALIGN16(D_SH_8034EA88[i]->size); - } - - for (i = 0; i < D_SH_8034F688; i++) { - if (D_SH_8034F68C != 0x78) { - temp_s0 = D_SH_8034EA88[i]; - switch (arg3) { - case 0: - temp = temp_s0->medium = patchInfo->medium1; - if (temp != 0) { - if (temp_s0->size) { - } - addr = func_sh_802f1d90(temp_s0->size, patchInfo->bankId1, temp_s0->sampleAddr, temp_s0->medium); - } else { - temp = temp_s0->medium = patchInfo->medium2; - if (temp != 0) { - addr = func_sh_802f1d90(temp_s0->size, patchInfo->bankId2, temp_s0->sampleAddr, temp_s0->medium); - } - } - break; - - case 1: - temp = temp_s0->medium = patchInfo->medium1; - if (temp != 0) { - addr = func_sh_802f1d40(temp_s0->size, patchInfo->bankId1, temp_s0->sampleAddr, temp_s0->medium); - } else { - temp = temp_s0->medium = patchInfo->medium2; - if (temp != 0) { - addr = func_sh_802f1d40(temp_s0->size, patchInfo->bankId2, temp_s0->sampleAddr, temp_s0->medium); - } - } - break; - } - switch ((uintptr_t) addr) { - case 0: - break; - default: - switch (arg3) { - case 0: - if (temp_s0->medium == 1) { - func_sh_802f3d78((uintptr_t) temp_s0->sampleAddr, addr, temp_s0->size, gAlTbl->unk2); - temp_s0->sampleAddr = addr; - temp_s0->medium = 0; - } else { - func_sh_802f3c38((uintptr_t) temp_s0->sampleAddr, addr, temp_s0->size, temp_s0->medium); - temp_s0->sampleAddr = addr; - temp_s0->medium = 0; - } - break; - - case 1: - D_SH_8034EC88[D_SH_8034F68C].sample = temp_s0; - D_SH_8034EC88[D_SH_8034F68C].ramAddr = addr; - D_SH_8034EC88[D_SH_8034F68C].encodedInfo = (D_SH_8034F68C << 24) | 0xffffff; - D_SH_8034EC88[D_SH_8034F68C].isFree = FALSE; - D_SH_8034EC88[D_SH_8034F68C].endAndMediumIdentification = temp_s0->sampleAddr + temp_s0->size + temp_s0->medium; - D_SH_8034F68C++; - break; - } - } - continue; - } - break; - } - - D_SH_8034F688 = 0; - if (D_SH_8034F68C != 0 && sp4C == 0) { - temp_s0 = D_SH_8034EC88[D_SH_8034F68C - 1].sample; - temp = (temp_s0->size >> 12); - temp += 1; - count = (uintptr_t) temp_s0->sampleAddr; - func_sh_802f4cb4( - count, - D_SH_8034EC88[D_SH_8034F68C - 1].ramAddr, - temp_s0->size, - temp_s0->medium, - temp, - &gUnkQueue2, - D_SH_8034EC88[D_SH_8034F68C - 1].encodedInfo); - } -} - -s32 func_sh_802f573c(s32 audioResetStatus) { - struct AudioBankSample *sample; - u32 idx; - u8 *sampleAddr; - u32 size; - s32 unk; - u8 *added; - - if (D_SH_8034F68C > 0) { - if (audioResetStatus != 0) { - if (osRecvMesg(&gUnkQueue2, (OSMesg *) &idx, OS_MESG_NOBLOCK)){ - } - D_SH_8034F68C = 0; - return 0; - } - if (osRecvMesg(&gUnkQueue2, (OSMesg *) &idx, OS_MESG_NOBLOCK) == -1) { - return 0; - } - idx >>= 0x18; - if (D_SH_8034EC88[idx].isFree == FALSE) { - sample = D_SH_8034EC88[idx].sample; - added = (sample->sampleAddr + sample->size + sample->medium); - if (added == D_SH_8034EC88[idx].endAndMediumIdentification) { - sample->sampleAddr = D_SH_8034EC88[idx].ramAddr; - sample->medium = 0; - } - D_SH_8034EC88[idx].isFree = TRUE; - } - - next: - if (D_SH_8034F68C > 0) { - if (D_SH_8034EC88[D_SH_8034F68C - 1].isFree == TRUE) { - D_SH_8034F68C--; - goto next; - } - sample = D_SH_8034EC88[D_SH_8034F68C - 1].sample; - sampleAddr = sample->sampleAddr; - size = sample->size; - unk = size >> 0xC; - unk += 1; - added = ((sampleAddr + size) + sample->medium); - if (added != D_SH_8034EC88[D_SH_8034F68C - 1].endAndMediumIdentification) { - D_SH_8034EC88[D_SH_8034F68C - 1].isFree = TRUE; - D_SH_8034F68C--; - goto next; - } - size = sample->size; - func_sh_802f4cb4(sampleAddr, D_SH_8034EC88[D_SH_8034F68C - 1].ramAddr, size, sample->medium, - unk, &gUnkQueue2, D_SH_8034EC88[D_SH_8034F68C - 1].encodedInfo); - } - } - return 1; -} - -s32 func_sh_802f5900(struct AudioBankSample *sample, s32 numLoaded, struct AudioBankSample *arg2[]) { - s32 i; - - for (i = 0; i < numLoaded; i++) { - if (sample->sampleAddr == arg2[i]->sampleAddr) { - break; - } - } - if (i == numLoaded) { - arg2[numLoaded++] = sample; - } - return numLoaded; -} - -s32 func_sh_802f5948(s32 bankId, struct AudioBankSample *list[]) { - s32 i; - struct Drum *drum; - struct Instrument *inst; - s32 numLoaded; - s32 numDrums; - s32 numInstruments; - - numLoaded = 0; - numDrums = gCtlEntries[bankId].numDrums; - numInstruments = gCtlEntries[bankId].numInstruments; - - for (i = 0; i < numDrums; i++) { - drum = get_drum(bankId, i); - if (drum == NULL) { - continue; - } - numLoaded = func_sh_802f5900(drum->sound.sample, numLoaded, list); - } - for (i = 0; i < numInstruments; i++) { - inst = get_instrument_inner(bankId, i); - if (inst == NULL) { - continue; - - } - if (inst->normalRangeLo != 0) { - numLoaded = func_sh_802f5900(inst->lowNotesSound.sample, numLoaded, list); - } - if (inst->normalRangeHi != 127) { - numLoaded = func_sh_802f5900(inst->highNotesSound.sample, numLoaded, list); - } - numLoaded = func_sh_802f5900(inst->normalNotesSound.sample, numLoaded, list); - } - return numLoaded; } #endif diff --git a/src/audio/load.h b/src/audio/load.h index d96f27b7..63379d21 100644 --- a/src/audio/load.h +++ b/src/audio/load.h @@ -89,18 +89,25 @@ void patch_audio_bank(s32 bankId, struct AudioBank *mem, struct PatchStruct *pat #else void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32 numDrums); #endif -#ifndef VERSION_SH +#ifdef VERSION_SH +void preload_sequence(u32 seqId, s32 preloadMask); +#else void preload_sequence(u32 seqId, u8 preloadMask); #endif void load_sequence(u32 player, u32 seqId, s32 loadAsync); #ifdef VERSION_SH -void func_sh_802f3158(s32 index, s32 arg1, s32 arg2, OSMesgQueue *retQueue); -u8 *func_sh_802f3220(u32 index, u32 *a1); +void func_sh_802f3158(s32 seqId, s32 arg1, s32 arg2, OSMesgQueue *retQueue); +u8 *func_sh_802f3220(u32 seqId, u32 *a1); struct AudioBankSample *func_sh_802f4978(s32 bankId, s32 idx); -void *func_802f3f08(s32 poolIdx, s32 arg1, s32 arg2, s32 arg3, OSMesgQueue *retQueue); -s32 func_sh_802f3368(s32 arg0); +s32 func_sh_802f47c8(s32 bankId, u8 idx, s8 *io); +void *func_sh_802f3f08(s32 poolIdx, s32 arg1, s32 arg2, s32 arg3, OSMesgQueue *retQueue); +void func_sh_802f41e4(s32 audioResetStatus); +BAD_RETURN(s32) func_sh_802f3368(s32 bankId); void *func_sh_802f3764(s32 arg0, s32 idx, s32 *arg2); +s32 func_sh_802f3024(s32 bankId, s32 instId, s32 arg2); +void func_sh_802f30f4(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue *arg3); +void func_sh_802f3288(s32 idx); #endif diff --git a/src/audio/load_sh.c b/src/audio/load_sh.c new file mode 100644 index 00000000..99593a28 --- /dev/null +++ b/src/audio/load_sh.c @@ -0,0 +1,1639 @@ +#ifdef VERSION_SH +#include +#include + +#include "data.h" +#include "external.h" +#include "heap.h" +#include "load.h" +#include "seqplayer.h" + +#define ALIGN16(val) (((val) + 0xF) & ~0xF) + +struct SharedDma { + /*0x0*/ u8 *buffer; // target, points to pre-allocated buffer + /*0x4*/ uintptr_t source; // device address + /*0x8*/ u16 sizeUnused; // set to bufSize, never read + /*0xA*/ u16 bufSize; // size of buffer + /*0xC*/ u8 unused2; // set to 0, never read + /*0xD*/ u8 reuseIndex; // position in sSampleDmaReuseQueue1/2, if ttl == 0 + /*0xE*/ u8 ttl; // duration after which the DMA can be discarded +}; // size = 0x10 + +void port_eu_init(void); +void patch_sound(struct AudioBankSound *sound, struct AudioBank *memBase, struct PatchStruct *patchInfo); +void *func_802f3f08(s32 poolIdx, s32 idx, s32 numChunks, s32 arg3, OSMesgQueue *retQueue); + +struct Note *gNotes; + +UNUSED static u32 pad; + +struct SequencePlayer gSequencePlayers[SEQUENCE_PLAYERS]; +struct SequenceChannel gSequenceChannels[SEQUENCE_CHANNELS]; +struct SequenceChannelLayer gSequenceLayers[SEQUENCE_LAYERS]; + +struct SequenceChannel gSequenceChannelNone; +struct AudioListItem gLayerFreeList; +struct NotePool gNoteFreeLists; + +struct AudioBankSample *D_SH_8034EA88[0x80]; +struct UnkStructSH8034EC88 D_SH_8034EC88[0x80]; +s32 D_SH_8034F688; // index into D_SH_8034EA88 +s32 D_SH_8034F68C; // index or size for D_SH_8034EC88 + +struct PendingDmaAudioBank { + s8 inProgress; + s8 timer; + s8 medium; + struct AudioBank *audioBank; + uintptr_t devAddr; + void *vAddr; + u32 remaining; + u32 transferSize; + u32 encodedInfo; + OSMesgQueue *retQueue; + OSMesgQueue dmaRetQueue; + OSMesg mesgs[1]; + OSIoMesg ioMesg; +}; +struct PendingDmaAudioBank sPendingDmaAudioBanks[16]; + +OSMesgQueue gUnkQueue1; +OSMesg gUnkMesgBufs1[0x10]; +OSMesgQueue gUnkQueue2; +OSMesg gUnkMesgBufs2[0x10]; + +OSMesgQueue gCurrAudioFrameDmaQueue; +OSMesg gCurrAudioFrameDmaMesgBufs[AUDIO_FRAME_DMA_QUEUE_SIZE]; +OSIoMesg gCurrAudioFrameDmaIoMesgBufs[AUDIO_FRAME_DMA_QUEUE_SIZE]; + +OSMesgQueue gAudioDmaMesgQueue; +OSMesg gAudioDmaMesg; +OSIoMesg gAudioDmaIoMesg; + +struct SharedDma *sSampleDmas; +u32 gSampleDmaNumListItems; +u32 sSampleDmaListSize1; +u32 sUnused80226B40; // set to 0, never read + +// Circular buffer of DMAs with ttl = 0. tail <= head, wrapping around mod 256. +u8 sSampleDmaReuseQueue1[256]; +u8 sSampleDmaReuseQueue2[256]; +u8 sSampleDmaReuseQueueTail1; +u8 sSampleDmaReuseQueueTail2; +u8 sSampleDmaReuseQueueHead1; +u8 sSampleDmaReuseQueueHead2; + +ALSeqFile *gSeqFileHeader; +ALSeqFile *gAlCtlHeader; +ALSeqFile *gAlTbl; +u8 *gAlBankSets; +u16 gSequenceCount; + +struct CtlEntry *gCtlEntries; + +struct AudioBufferParametersEU gAudioBufferParameters; +u32 sDmaBufSize; +s32 gMaxAudioCmds; +s32 gMaxSimultaneousNotes; + +s16 gTempoInternalToExternal; + +s8 gSoundMode; + +s8 gAudioUpdatesPerFrame; + +extern u64 gAudioGlobalsStartMarker; +extern u64 gAudioGlobalsEndMarker; + +extern u8 gSoundDataADSR[]; // ctl +extern u8 gSoundDataRaw[]; // tbl +extern u8 gMusicData[]; // sequences + +ALSeqFile *get_audio_file_header(s32 arg0); + +void *func_sh_802f3688(s32 bankId); +void *get_bank_or_seq_wrapper(s32 arg0, s32 arg1); +void func_sh_802f3d78(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3); +void func_sh_802f3c38(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 medium); +s32 func_sh_802f3dd0(OSIoMesg *m, s32 pri, s32 direction, uintptr_t devAddr, + void *dramAddr, s32 size, OSMesgQueue *retQueue, s32 medium, UNUSED const char *reason); +void func_sh_802f4a4c(s32 audioResetStatus); +void func_sh_802f4bd8(struct PendingDmaSample *arg0, s32 len); +void func_sh_802f4c5c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3); +struct PendingDmaAudioBank *func_sh_802f4cb4(uintptr_t devAddr, void *vAddr, s32 size, + s32 medium, s32 numChunks, OSMesgQueue *retQueue, s32 encodedInfo); +void func_sh_802f4dcc(s32 audioResetStatus); +void func_sh_802f4e50(struct PendingDmaAudioBank *audioBank, s32 audioResetStatus); +void func_sh_802f50ec(struct PendingDmaAudioBank *arg0, size_t len); +void func_sh_802f517c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3); +BAD_RETURN(s32) func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo, s32 arg3); +s32 func_sh_802f573c(s32 audioResetStatus); +void *func_sh_802f3564(s32 seqId); +s32 func_sh_802f3ec4(s32 arg0, uintptr_t *arg1); +void func_sh_802f3ed4(UNUSED s32 arg0, UNUSED s32 arg1, UNUSED void *vAddr, UNUSED size_t nbytes); + +s32 canonicalize_index(s32 poolIdx, s32 idx); + +void decrease_sample_dma_ttls() { + u32 i; + + for (i = 0; i < sSampleDmaListSize1; i++) { + struct SharedDma *temp = &sSampleDmas[i]; + if (temp->ttl != 0) { + temp->ttl--; + if (temp->ttl == 0) { + temp->reuseIndex = sSampleDmaReuseQueueHead1; + sSampleDmaReuseQueue1[sSampleDmaReuseQueueHead1++] = (u8) i; + } + } + } + + for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) { + struct SharedDma *temp = &sSampleDmas[i]; + if (temp->ttl != 0) { + temp->ttl--; + if (temp->ttl == 0) { + temp->reuseIndex = sSampleDmaReuseQueueHead2; + sSampleDmaReuseQueue2[sSampleDmaReuseQueueHead2++] = (u8) i; + } + } + } + + sUnused80226B40 = 0; +} + +extern char shindouDebugPrint62[]; // "SUPERDMA" +void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef, s32 medium) { + UNUSED s32 sp60; + struct SharedDma *dma; + s32 hasDma = FALSE; + uintptr_t dmaDevAddr; + UNUSED u32 pad; + u32 dmaIndex; + u32 transfer; + ssize_t bufferPos; + u32 i; + + if (arg2 != 0 || *dmaIndexRef >= sSampleDmaListSize1) { + for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) { + dma = &sSampleDmas[i]; + bufferPos = devAddr - dma->source; + if (0 <= bufferPos && (size_t) bufferPos <= dma->bufSize - size) { + // We already have a DMA request for this memory range. + if (dma->ttl == 0 && sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2) { + // Move the DMA out of the reuse queue, by swapping it with the + // tail, and then incrementing the tail. + if (dma->reuseIndex != sSampleDmaReuseQueueTail2) { + sSampleDmaReuseQueue2[dma->reuseIndex] = + sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2]; + sSampleDmas[sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2]].reuseIndex = + dma->reuseIndex; + } + sSampleDmaReuseQueueTail2++; + } + dma->ttl = 60; + *dmaIndexRef = (u8) i; + return &dma->buffer[(devAddr - dma->source)]; + } + } + + if (sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2 && arg2 != 0) { + // Allocate a DMA from reuse queue 2. This queue can be empty, since + // TTL 60 is pretty large. + dmaIndex = sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2]; + sSampleDmaReuseQueueTail2++; + dma = sSampleDmas + dmaIndex; + hasDma = TRUE; + } + } else { + dma = sSampleDmas + *dmaIndexRef; + bufferPos = devAddr - dma->source; + if (0 <= bufferPos && (size_t) bufferPos <= dma->bufSize - size) { + // We already have DMA for this memory range. + if (dma->ttl == 0) { + // Move the DMA out of the reuse queue, by swapping it with the + // tail, and then incrementing the tail. + if (dma->reuseIndex != sSampleDmaReuseQueueTail1) { + sSampleDmaReuseQueue1[dma->reuseIndex] = + sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1]; + sSampleDmas[sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1]].reuseIndex = + dma->reuseIndex; + } + sSampleDmaReuseQueueTail1++; + } + dma->ttl = 2; + return dma->buffer + (devAddr - dma->source); + } + } + + if (!hasDma) { + if (1) {} + // Allocate a DMA from reuse queue 1. This queue will hopefully never + // be empty, since TTL 2 is so small. + dmaIndex = sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1++]; + dma = sSampleDmas + dmaIndex; + hasDma = TRUE; + } + + transfer = dma->bufSize; + dmaDevAddr = devAddr & ~0xF; + dma->ttl = 2; + dma->source = dmaDevAddr; + dma->sizeUnused = transfer; + func_sh_802f3dd0(&gCurrAudioFrameDmaIoMesgBufs[gCurrAudioFrameDmaCount++], OS_MESG_PRI_NORMAL, OS_READ, + dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue, medium, shindouDebugPrint62); + *dmaIndexRef = dmaIndex; + return (devAddr - dmaDevAddr) + dma->buffer; +} + +void init_sample_dma_buffers(UNUSED s32 arg0) { + s32 i; + + sDmaBufSize = 0x2D0; + sSampleDmas = sound_alloc_uninitialized(&gNotesAndBuffersPool, + gMaxSimultaneousNotes * 4 * sizeof(struct SharedDma) * gAudioBufferParameters.presetUnk4); + + for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++) { + if ((sSampleDmas[gSampleDmaNumListItems].buffer = sound_alloc_uninitialized(&gNotesAndBuffersPool, sDmaBufSize)) == NULL) { + break; + } + sSampleDmas[gSampleDmaNumListItems].bufSize = sDmaBufSize; + sSampleDmas[gSampleDmaNumListItems].source = 0; + sSampleDmas[gSampleDmaNumListItems].sizeUnused = 0; + sSampleDmas[gSampleDmaNumListItems].unused2 = 0; + sSampleDmas[gSampleDmaNumListItems].ttl = 0; + gSampleDmaNumListItems++; + } + + for (i = 0; (u32) i < gSampleDmaNumListItems; i++) { + sSampleDmaReuseQueue1[i] = (u8) i; + sSampleDmas[i].reuseIndex = (u8) i; + } + + for (i = gSampleDmaNumListItems; i < 0x100; i++) { + sSampleDmaReuseQueue1[i] = 0; + } + + sSampleDmaReuseQueueTail1 = 0; + sSampleDmaReuseQueueHead1 = (u8) gSampleDmaNumListItems; + sSampleDmaListSize1 = gSampleDmaNumListItems; + + sDmaBufSize = 0x2D0; + for (i = 0; i < gMaxSimultaneousNotes; i++) { + if ((sSampleDmas[gSampleDmaNumListItems].buffer = sound_alloc_uninitialized(&gNotesAndBuffersPool, sDmaBufSize)) == NULL) { + break; + } + sSampleDmas[gSampleDmaNumListItems].bufSize = sDmaBufSize; + sSampleDmas[gSampleDmaNumListItems].source = 0; + sSampleDmas[gSampleDmaNumListItems].sizeUnused = 0; + sSampleDmas[gSampleDmaNumListItems].unused2 = 0; + sSampleDmas[gSampleDmaNumListItems].ttl = 0; + gSampleDmaNumListItems++; + } + + for (i = sSampleDmaListSize1; (u32) i < gSampleDmaNumListItems; i++) { + sSampleDmaReuseQueue2[i - sSampleDmaListSize1] = (u8) i; + sSampleDmas[i].reuseIndex = (u8)(i - sSampleDmaListSize1); + } + + // This probably meant to touch the range size1..size2 as well... but it + // doesn't matter, since these values are never read anyway. + for (i = gSampleDmaNumListItems; i < 0x100; i++) { + sSampleDmaReuseQueue2[i] = sSampleDmaListSize1; + } + + sSampleDmaReuseQueueTail2 = 0; + sSampleDmaReuseQueueHead2 = gSampleDmaNumListItems - sSampleDmaListSize1; +} + +void patch_seq_file(ALSeqFile *seqFile, u8 *data, u16 arg2) { + s32 i; + + seqFile->unk2 = arg2; + seqFile->data = data; + for (i = 0; i < seqFile->seqCount; i++) { + if (seqFile->seqArray[i].len != 0 && seqFile->seqArray[i].medium == 2) { + seqFile->seqArray[i].offset += (uintptr_t)data; + } + } +} + +struct AudioBank *load_banks_immediate(s32 seqId, s32 *outDefaultBank) { + u8 bank; + s32 offset; + s32 i; + void *ret; + + offset = ((u16 *)gAlBankSets)[canonicalize_index(0, seqId)]; + bank = 0xFF; + for (i = gAlBankSets[offset++]; i > 0; i--) { + bank = gAlBankSets[offset++]; + ret = func_sh_802f3688(bank); + } + *outDefaultBank = bank; + return ret; +} + +void preload_sequence(u32 seqId, s32 preloadMask) { + UNUSED s32 pad; + s32 temp; + + seqId = canonicalize_index(0, seqId); + if (preloadMask & PRELOAD_BANKS) { + load_banks_immediate(seqId, &temp); + } + if (preloadMask & PRELOAD_SEQUENCE) { + func_sh_802f3564(seqId); + } +} + +s32 func_sh_802f2f38(struct AudioBankSample *sample, s32 bankId) { + u8 *sp24; + + if (sample->isPatched == TRUE && sample->medium != 0) { + sp24 = func_sh_802f1d90(sample->size, bankId, sample->sampleAddr, sample->medium); + if (sp24 == NULL) { + return -1; + } + if (sample->medium == 1) { + func_sh_802f3d78((uintptr_t) sample->sampleAddr, sp24, sample->size, gAlTbl->unk2); + } else { + func_sh_802f3c38((uintptr_t) sample->sampleAddr, sp24, sample->size, sample->medium); + } + sample->medium = 0; + sample->sampleAddr = sp24; + } +#ifdef AVOID_UB + return 0; +#endif +} + +s32 func_sh_802f3024(s32 bankId, s32 instId, s32 arg2) { + struct Instrument *instr; + struct Drum *drum; + + if (instId < 0x7F) { + instr = get_instrument_inner(bankId, instId); + if (instr == NULL) { + return -1; + } + if (instr->normalRangeLo != 0) { + func_sh_802f2f38(instr->lowNotesSound.sample, bankId); + } + func_sh_802f2f38(instr->normalNotesSound.sample, bankId); + if (instr->normalRangeHi != 0x7F) { + func_sh_802f2f38(instr->highNotesSound.sample, bankId); + } + //! @bug missing return + } else if (instId == 0x7F) { + drum = get_drum(bankId, arg2); + if (drum == NULL) { + return -1; + } + func_sh_802f2f38(drum->sound.sample, bankId); + return 0; + } +#ifdef AVOID_UB + return 0; +#endif +} + +void func_sh_802f30f4(s32 arg0, s32 arg1, s32 arg2, OSMesgQueue *arg3) { + if (func_802f3f08(2, canonicalize_index(2, arg0), arg1, arg2, arg3) == 0) { + osSendMesg(arg3, 0, 0); + } +} + +void func_sh_802f3158(s32 seqId, s32 numChunks, s32 arg2, OSMesgQueue *retQueue) { + s32 val; + s32 v; + + val = ((u16 *) gAlBankSets)[canonicalize_index(0, seqId)]; + v = gAlBankSets[val++]; + + while (v > 0) { + func_802f3f08(1, canonicalize_index(1, gAlBankSets[val++]), numChunks, arg2, retQueue); + v--; + } +} + +u8 *func_sh_802f3220(u32 seqId, u32 *a1) { + s32 val; + + val = ((u16 *) gAlBankSets)[canonicalize_index(0, seqId)]; + *a1 = gAlBankSets[val++]; + if (*a1 == 0) { + return NULL; + } + return &gAlBankSets[val]; +} + +void func_sh_802f3288(s32 idx) { + s32 bankId; + s32 s2; + + idx = ((u16*)gAlBankSets)[canonicalize_index(0, idx)]; + s2 = gAlBankSets[idx++]; + while (s2 > 0) { + s2--; + bankId = canonicalize_index(1, gAlBankSets[idx++]); + + if (unk_pool1_lookup(1, bankId) == NULL) { + func_sh_802f3368(bankId); + if (gBankLoadStatus[bankId] != SOUND_LOAD_STATUS_5) { + gBankLoadStatus[bankId] = SOUND_LOAD_STATUS_NOT_LOADED; + } + + continue; + } + + } +} + +BAD_RETURN(s32) func_sh_802f3368(s32 bankId) { + struct SoundMultiPool *pool = &gBankLoadedPool; + struct TemporaryPool *temporary = &pool->temporary; + struct PersistentPool *persistent; + u32 i; + + if (temporary->entries[0].id == bankId) { + temporary->entries[0].id = -1; + } else if (temporary->entries[1].id == bankId) { + temporary->entries[1].id = -1; + } + + persistent = &pool->persistent; + for (i = 0; i < persistent->numEntries; i++) { + if (persistent->entries[i].id == bankId) { + persistent->entries[i].id = -1; + } + + } + + discard_bank(bankId); +} + + +void load_sequence_internal(s32 player, s32 seqId, s32 loadAsync); +void load_sequence(u32 player, u32 seqId, s32 loadAsync) { + load_sequence_internal(player, seqId, loadAsync); +} + +void load_sequence_internal(s32 player, s32 seqId, UNUSED s32 loadAsync) { + struct SequencePlayer *seqPlayer; + u8 *sequenceData; + u32 s0; + s32 count; + u8 bank; + s32 i; + + seqPlayer = &gSequencePlayers[player]; + + seqId = canonicalize_index(0, seqId); + sequence_player_disable(seqPlayer); + + s0 = ((u16 *) gAlBankSets)[seqId]; + count = gAlBankSets[s0++]; + bank = 0xff; + + while (count > 0) { + bank = gAlBankSets[s0++]; + func_sh_802f3688(bank); + count--; + } + + sequenceData = func_sh_802f3564(seqId); + init_sequence_player(player); + seqPlayer->seqId = seqId; + seqPlayer->defaultBank[0] = bank; + seqPlayer->enabled = 1; + seqPlayer->seqData = sequenceData; + seqPlayer->scriptState.pc = sequenceData; + seqPlayer->scriptState.depth = 0; + seqPlayer->delay = 0; + seqPlayer->finished = 0; + + for (i = 0; i < 0x10; i++) { + } +} + +void *func_sh_802f3564(s32 seqId) { + s32 seqId2 = canonicalize_index(0, seqId); + s32 temp; + return func_sh_802f3764(0, seqId2, &temp); +} + +extern u8 gUnkLoadStatus[0x40]; + +void *func_sh_802f3598(s32 idx, s32 *medium) { + void *ret; + ALSeqFile *f; + s32 temp; + s32 sp28; + + f = get_audio_file_header(2); + idx = canonicalize_index(2, idx); + ret = get_bank_or_seq_wrapper(2, idx); + if (ret != NULL) { + if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5) { + gUnkLoadStatus[idx] = SOUND_LOAD_STATUS_COMPLETE; + } + + *medium = 0; + return ret; + } + + temp = f->seqArray[idx].magic; + if (temp == 4) { + *medium = f->seqArray[idx].medium; + return f->seqArray[idx].offset; + } else { + ret = func_sh_802f3764(2, idx, &sp28); + if (ret != 0) { + *medium = 0; + return ret; + } + + *medium = f->seqArray[idx].medium; + } + return f->seqArray[idx].offset; + +} + +void *func_sh_802f3688(s32 bankId) { + void *ret; + s32 bankId1; + s32 bankId2; + s32 sp38; + struct PatchStruct patchInfo; + + bankId = canonicalize_index(1, bankId); + bankId1 = gCtlEntries[bankId].bankId1; + bankId2 = gCtlEntries[bankId].bankId2; + + patchInfo.bankId1 = bankId1; + patchInfo.bankId2 = bankId2; + + if (patchInfo.bankId1 != 0xFF) { + patchInfo.baseAddr1 = func_sh_802f3598(patchInfo.bankId1, &patchInfo.medium1); + } else { + patchInfo.baseAddr1 = NULL; + } + + if (bankId2 != 0xFF) { + patchInfo.baseAddr2 = func_sh_802f3598(bankId2, &patchInfo.medium2); + } else { + patchInfo.baseAddr2 = NULL; + } + + if ((ret = func_sh_802f3764(1, bankId, &sp38)) == NULL) { + return NULL; + } + + if (sp38 == 1) { + func_sh_802f5310(bankId, ret, &patchInfo, 0); + } + + return ret; +} + +void *func_sh_802f3764(s32 poolIdx, s32 idx, s32 *arg2) { + s32 size; + ALSeqFile *f; + void *vAddr; + s32 medium; + UNUSED u32 pad2; + u8 *devAddr; + s8 loadStatus; + s32 sp18; + + vAddr = get_bank_or_seq_wrapper(poolIdx, idx); + if (vAddr != NULL) { + *arg2 = 0; + loadStatus = SOUND_LOAD_STATUS_COMPLETE; + } else { + f = get_audio_file_header(poolIdx); + size = f->seqArray[idx].len; + size = ALIGN16(size); + medium = f->seqArray[idx].medium; + sp18 = f->seqArray[idx].magic; + devAddr = f->seqArray[idx].offset; + + + switch (sp18) { + case 0: + vAddr = unk_pool1_alloc(poolIdx, idx, size); + if (vAddr == NULL) { + return vAddr; + } + break; + case 1: + vAddr = alloc_bank_or_seq(poolIdx, size, 1, idx); + if (vAddr == NULL) { + return vAddr; + } + break; + case 2: + vAddr = alloc_bank_or_seq(poolIdx, size, 0, idx); + if (vAddr == NULL) { + return vAddr; + } + break; + + case 3: + case 4: + vAddr = alloc_bank_or_seq(poolIdx, size, 2, idx); + if (vAddr == NULL) { + return vAddr; + } + break; + } + + *arg2 = 1; + if (medium == 1) { + func_sh_802f3d78((uintptr_t) devAddr, vAddr, size, f->unk2); + } else { + func_sh_802f3c38((uintptr_t) devAddr, vAddr, size, medium); + } + + switch (sp18) { + case 0: + loadStatus = SOUND_LOAD_STATUS_5; + break; + + default: + loadStatus = SOUND_LOAD_STATUS_COMPLETE; + break; + } + } + + switch (poolIdx) { + case 0: + if (gSeqLoadStatus[idx] != SOUND_LOAD_STATUS_5) { + gSeqLoadStatus[idx] = loadStatus; + } + break; + + case 1: + if (gBankLoadStatus[idx] != SOUND_LOAD_STATUS_5) { + gBankLoadStatus[idx] = loadStatus; + } + break; + + case 2: + if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5) { + gUnkLoadStatus[idx] = loadStatus; + } + break; + } + + return vAddr; +} + +s32 canonicalize_index(s32 poolIdx, s32 idx) { + ALSeqFile *f; + + f = get_audio_file_header(poolIdx); + if (f->seqArray[idx].len == 0) { + idx = (s32) (uintptr_t) f->seqArray[idx].offset; + } + return idx; +} + +void *get_bank_or_seq_wrapper(s32 poolIdx, s32 id) { + void *ret; + + ret = unk_pool1_lookup(poolIdx, id); + if (ret != NULL) { + return ret; + } + ret = get_bank_or_seq(poolIdx, 2, id); + if (ret != 0) { + return ret; + } + return NULL; +} + +ALSeqFile *get_audio_file_header(s32 poolIdx) { + ALSeqFile *ret; + switch (poolIdx) { + default: + ret = NULL; + break; + case 0: + ret = gSeqFileHeader; + break; + case 1: + ret = gAlCtlHeader; + break; + case 2: + ret = gAlTbl; + break; + } + return ret; +} + +void patch_audio_bank(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo) { + struct Instrument *instrument; + void **itInstrs; + struct Instrument **end; + s32 i; + void *patched; + struct Drum *drum; + s32 numDrums; + s32 numInstruments; + +#define BASE_OFFSET(x, base) (void *)((uintptr_t) (x) + (uintptr_t) base) +#define PATCH(x, base) (patched = BASE_OFFSET(x, base)) +#define PATCH_MEM(x) x = PATCH(x, mem) + + numDrums = gCtlEntries[bankId].numDrums; + numInstruments = gCtlEntries[bankId].numInstruments; + itInstrs = (void **) mem->drums; + if (mem->drums) { + } + if (itInstrs != NULL && numDrums != 0) { + if (1) { + mem->drums = PATCH(itInstrs, mem); + } + for (i = 0; i < numDrums; i++) { + patched = mem->drums[i]; + if (patched != NULL) { + drum = PATCH(patched, mem); + mem->drums[i] = drum; + if (drum->loaded == 0) { + patch_sound(&drum->sound, mem, patchInfo); + patched = drum->envelope; + drum->envelope = BASE_OFFSET(patched, mem); + drum->loaded = 1; + } + + } + } + } + + if (numInstruments > 0) { + itInstrs = (void **) mem->instruments; + end = numInstruments + (struct Instrument **) itInstrs; + + do { + if (*itInstrs != NULL) { + *itInstrs = BASE_OFFSET(*itInstrs, mem); + instrument = *itInstrs; + + if (instrument->loaded == 0) { + if (instrument->normalRangeLo != 0) { + patch_sound(&instrument->lowNotesSound, mem, patchInfo); + } + patch_sound(&instrument->normalNotesSound, mem, patchInfo); + if (instrument->normalRangeHi != 0x7F) { + patch_sound(&instrument->highNotesSound, mem, patchInfo); + } + patched = instrument->envelope; + + instrument->envelope = BASE_OFFSET(patched, mem); + instrument->loaded = 1; + } + } + itInstrs = (void **) ((struct Instrument **) itInstrs) + 1; + } while ((struct Instrument **) itInstrs != ((void) 0, end)); //! This is definitely fake + } + gCtlEntries[bankId].drums = mem->drums; + gCtlEntries[bankId].instruments = mem->instruments; +#undef PATCH_MEM +#undef PATCH +#undef BASE_OFFSET +} + +extern char shindouDebugPrint81[]; // "FastCopy" +extern char shindouDebugPrint82[]; // "FastCopy" +void func_sh_802f3c38(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 medium) { + nbytes = ALIGN16(nbytes); + osInvalDCache(vAddr, nbytes); + +again: + if (gAudioLoadLockSH != 0) { + goto again; + } + + if (nbytes >= 0x400U) { + func_sh_802f3dd0(&gAudioDmaIoMesg, 1, 0, devAddr, vAddr, 0x400, &gAudioDmaMesgQueue, medium, shindouDebugPrint81); + osRecvMesg(&gAudioDmaMesgQueue, NULL, 1); + nbytes = nbytes - 0x400; + devAddr = devAddr + 0x400; + vAddr = (u8*)vAddr + 0x400; + goto again; + } + + if (nbytes != 0) { + func_sh_802f3dd0(&gAudioDmaIoMesg, 1, 0, devAddr, vAddr, nbytes, &gAudioDmaMesgQueue, medium, shindouDebugPrint82); + osRecvMesg(&gAudioDmaMesgQueue, NULL, 1); + } +} + +void func_sh_802f3d78(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) { + uintptr_t sp1C; + + sp1C = devAddr; + osInvalDCache(vAddr, nbytes); + func_sh_802f3ed4(func_sh_802f3ec4(arg3, &sp1C), sp1C, vAddr, nbytes); +} + +s32 func_sh_802f3dd0(OSIoMesg *m, s32 pri, s32 direction, uintptr_t devAddr, void *dramAddr, s32 size, OSMesgQueue *retQueue, s32 medium, UNUSED const char *reason) { + OSPiHandle *handle; + if (gAudioLoadLockSH >= 0x11U) { + return -1; + } + switch (medium) { + case 2: + handle = osCartRomInit(); + break; + case 3: + handle = osDriveRomInit(); + break; + default: + return 0; + } + if ((size & 0xf) != 0) { + size = ALIGN16(size); + } + m->hdr.pri = pri; + m->hdr.retQueue = retQueue; + m->dramAddr = dramAddr; + m->devAddr = devAddr; + m->size = size; + handle->transferInfo.cmdType = 2; + osEPiStartDma(handle, m, direction); + return 0; +} + +s32 func_sh_802f3ec4(UNUSED s32 arg0, UNUSED uintptr_t *arg1) { + return 0; +} + +void func_sh_802f3ed4(UNUSED s32 arg0, UNUSED s32 arg1, UNUSED void *vAddr, UNUSED size_t nbytes) { +} + +void *func_sh_802f3ee8(s32 poolIdx, s32 idx) { + s32 temp; + return func_sh_802f3764(poolIdx, idx, &temp); +} + +void *func_802f3f08(s32 poolIdx, s32 idx, s32 numChunks, s32 arg3, OSMesgQueue *retQueue) { + s32 size; + ALSeqFile *f; + void *vAddr; + s32 medium; + s32 sp18; + uintptr_t devAddr; + s32 loadStatus; + + switch (poolIdx) { + case 0: + if (gSeqLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) { + return 0; + } + break; + case 1: + if (gBankLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) { + return 0; + } + break; + case 2: + if (gUnkLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) { + return 0; + } + break; + + } + vAddr = get_bank_or_seq_wrapper(poolIdx, idx); + if (vAddr != NULL) { + loadStatus = 2; + osSendMesg(retQueue, (OSMesg) (arg3 << 0x18), 0); + } else { + f = get_audio_file_header(poolIdx); + size = f->seqArray[idx].len; + size = ALIGN16(size); + medium = f->seqArray[idx].medium; + sp18 = f->seqArray[idx].magic; + devAddr = (uintptr_t) f->seqArray[idx].offset; + loadStatus = 2; + + switch (sp18) { + case 0: + vAddr = unk_pool1_alloc(poolIdx, idx, size); + if (vAddr == NULL) { + return vAddr; + } + loadStatus = SOUND_LOAD_STATUS_5; + break; + case 1: + vAddr = alloc_bank_or_seq(poolIdx, size, 1, idx); + if (vAddr == NULL) { + return vAddr; + } + break; + case 2: + vAddr = alloc_bank_or_seq(poolIdx, size, 0, idx); + if (vAddr == NULL) { + return vAddr; + } + break; + + case 4: + case 3: + vAddr = alloc_bank_or_seq(poolIdx, size, 2, idx); + if (vAddr == NULL) { + return vAddr; + } + break; + } + + func_sh_802f4cb4(devAddr, vAddr, size, medium, numChunks, retQueue, (arg3 << 0x18) | (poolIdx << 0x10) | (idx << 8) | loadStatus); + loadStatus = SOUND_LOAD_STATUS_IN_PROGRESS; + } + + switch (poolIdx) { + case 0: + if (gSeqLoadStatus[idx] != SOUND_LOAD_STATUS_5) { + gSeqLoadStatus[idx] = loadStatus; + } + break; + + case 1: + if (gBankLoadStatus[idx] != SOUND_LOAD_STATUS_5) { + gBankLoadStatus[idx] = loadStatus; + } + break; + + case 2: + if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5) { + gUnkLoadStatus[idx] = loadStatus; + } + break; + } + + return vAddr; +} + +void func_sh_802f41e4(s32 audioResetStatus) { + func_sh_802f4a4c(audioResetStatus); + func_sh_802f573c(audioResetStatus); + func_sh_802f4dcc(audioResetStatus); +} + +#if defined(VERSION_SH) +u8 gShindouSoundBanksHeader[] = { +#include "sound/ctl_header.inc.c" +}; + +u8 gBankSetsData[] = { +#include "sound/bank_sets.inc.c" +}; + +u8 gShindouSampleBanksHeader[] = { +#include "sound/tbl_header.inc.c" +}; + +u8 gShindouSequencesHeader[] = { +#include "sound/sequences_header.inc.c" +}; +#endif + +// (void) must be omitted from parameters +void audio_init() { + UNUSED s8 pad[0x34]; + s32 i, j, k; + s32 lim; + u64 *ptr64; + void *data; + UNUSED u8 pad2[4]; + s32 seqCount; + + gAudioLoadLockSH = 0; + + for (i = 0; i < gAudioHeapSize / 8; i++) { + ((u64 *) gAudioHeap)[i] = 0; + } + +#ifdef TARGET_N64 + // It seems boot.s doesn't clear the .bss area for audio, so do it here. + lim = ((uintptr_t) &gAudioGlobalsEndMarker - (uintptr_t) &gAudioGlobalsStartMarker) / 8; + ptr64 = &gAudioGlobalsStartMarker; + for (k = lim; k >= 0; k--) { + *ptr64++ = 0; + } +#endif + + D_EU_802298D0 = 16.713f; + gRefreshRate = 60; + port_eu_init(); + +#ifdef TARGET_N64 + eu_stubbed_printf_3( + "Clear Workarea %x -%x size %x \n", + (uintptr_t) &gAudioGlobalsStartMarker, + (uintptr_t) &gAudioGlobalsEndMarker, + (uintptr_t) &gAudioGlobalsEndMarker - (uintptr_t) &gAudioGlobalsStartMarker + ); +#endif + + eu_stubbed_printf_1("AudioHeap is %x\n", gAudioHeapSize); + + for (i = 0; i < NUMAIBUFFERS; i++) { + gAiBufferLengths[i] = 0xa0; + } + + gAudioFrameCount = 0; + gAudioTaskIndex = 0; + gCurrAiBufferIndex = 0; + gSoundMode = 0; + gAudioTask = NULL; + gAudioTasks[0].task.t.data_size = 0; + gAudioTasks[1].task.t.data_size = 0; + osCreateMesgQueue(&gAudioDmaMesgQueue, &gAudioDmaMesg, 1); + osCreateMesgQueue(&gCurrAudioFrameDmaQueue, gCurrAudioFrameDmaMesgBufs, + ARRAY_COUNT(gCurrAudioFrameDmaMesgBufs)); + osCreateMesgQueue(&gUnkQueue1, gUnkMesgBufs1, 0x10); + osCreateMesgQueue(&gUnkQueue2, gUnkMesgBufs2, 0x10); + gCurrAudioFrameDmaCount = 0; + gSampleDmaNumListItems = 0; + + sound_init_main_pools(gAudioInitPoolSize); + + for (i = 0; i < NUMAIBUFFERS; i++) { + gAiBuffers[i] = sound_alloc_uninitialized(&gAudioInitPool, AIBUFFER_LEN); + + for (j = 0; j < (s32) (AIBUFFER_LEN / sizeof(s16)); j++) { + gAiBuffers[i][j] = 0; + } + } + + gAudioResetPresetIdToLoad = 0; + gAudioResetStatus = 1; + audio_shut_down_and_reset_step(); + + // Not sure about these prints + eu_stubbed_printf_1("Heap reset.Synth Change %x \n", 0); + eu_stubbed_printf_3("Heap %x %x %x\n", 0, 0, 0); + eu_stubbed_printf_0("Main Heap Initialize.\n"); + + // Load headers for sounds and sequences + gSeqFileHeader = (ALSeqFile *) gShindouSequencesHeader; + gAlCtlHeader = (ALSeqFile *) gShindouSoundBanksHeader; + gAlTbl = (ALSeqFile *) gShindouSampleBanksHeader; + gAlBankSets = gBankSetsData; + gSequenceCount = (s16) gSeqFileHeader->seqCount; + patch_seq_file(gSeqFileHeader, gMusicData, D_SH_80315EF4); + patch_seq_file(gAlCtlHeader, gSoundDataADSR, D_SH_80315EF8); + patch_seq_file(gAlTbl, gSoundDataRaw, D_SH_80315EFC); + seqCount = gAlCtlHeader->seqCount; + gCtlEntries = sound_alloc_uninitialized(&gAudioInitPool, seqCount * sizeof(struct CtlEntry)); + for (i = 0; i < seqCount; i++) { + gCtlEntries[i].bankId1 = (u8) ((gAlCtlHeader->seqArray[i].ctl.as_s16.bankAndFf >> 8) & 0xff); + gCtlEntries[i].bankId2 = (u8) (gAlCtlHeader->seqArray[i].ctl.as_s16.bankAndFf & 0xff); + gCtlEntries[i].numInstruments = (u8) ((gAlCtlHeader->seqArray[i].ctl.as_s16.numInstrumentsAndDrums >> 8) & 0xff); + gCtlEntries[i].numDrums = (u8) (gAlCtlHeader->seqArray[i].ctl.as_s16.numInstrumentsAndDrums & 0xff); + } + data = sound_alloc_uninitialized(&gAudioInitPool, D_SH_80315EF0); + if (data == NULL) { + D_SH_80315EF0 = 0; + } + sound_alloc_pool_init(&gUnkPool1.pool, data, D_SH_80315EF0); + init_sequence_players(); +} + +s32 func_sh_802f47c8(s32 bankId, u8 idx, s8 *io) { + struct AudioBankSample *sample = func_sh_802f4978(bankId, idx); + struct PendingDmaSample *temp; + if (sample == NULL) { + *io = 0; + return -1; + } + if (sample->medium == 0) { + *io = 2; + return 0; + } + temp = &D_SH_80343D00.arr[D_SH_80343D00.someIndex]; + if (temp->state == 3) { + temp->state = 0; + } + temp->sample = *sample; + temp->io = io; + temp->vAddr = func_sh_802f1d40(sample->size, bankId, sample->sampleAddr, sample->medium); + if (temp->vAddr == NULL) { + if (sample->medium == 1 || sample->codec == CODEC_SKIP) { + *io = 0; + return -1; + } else { + *io = 3; + return -1; + } + } + temp->state = 1; + temp->remaining = ALIGN16(sample->size); + temp->resultSampleAddr = (u8 *) temp->vAddr; + temp->devAddr = (uintptr_t) sample->sampleAddr; + temp->medium = sample->medium; + temp->bankId = bankId; + temp->idx = idx; + D_SH_80343D00.someIndex ^= 1; + return 0; +} + +struct AudioBankSample *func_sh_802f4978(s32 bankId, s32 idx) { + struct Drum *drum; + struct Instrument *inst; + struct AudioBankSample *ret; + + if (idx < 128) { + inst = get_instrument_inner(bankId, idx); + if (inst == 0) { + return NULL; + } + ret = inst->normalNotesSound.sample; + } else { + drum = get_drum(bankId, idx - 128); + if (drum == 0) { + return NULL; + } + ret = drum->sound.sample; + } + return ret; +} + +void stub_sh_802f49dc(void) { +} + +void func_sh_802f49e4(struct PendingDmaSample *arg0) { + struct AudioBankSample *sample = func_sh_802f4978(arg0->bankId, arg0->idx); + if (sample != NULL) { + arg0->sample = *sample; + sample->sampleAddr = arg0->resultSampleAddr; + sample->medium = 0; + } +} + +void func_sh_802f4a4c(s32 audioResetStatus) { + ALSeqFile *alTbl; + struct PendingDmaSample *entry; + + s32 i; + + alTbl = gAlTbl; + + for (i = 0; i < 2; i++) { + entry = &D_SH_80343D00.arr[i]; + switch (entry->state) { + case 2: + osRecvMesg(&entry->queue, NULL, 1); + if (audioResetStatus != 0) { + entry->state = 3; + break; + } + // fallthrough + case 1: + entry->state = 2; + if (entry->remaining == 0) { + func_sh_802f49e4(entry); + entry->state = 3; + *entry->io = 1; + } else if (entry->remaining < 0x1000) { + if (entry->medium == 1) { + func_sh_802f4c5c(entry->devAddr, entry->vAddr, entry->remaining, alTbl->unk2); + } else { + func_sh_802f4bd8(entry, entry->remaining); + } + entry->remaining = 0; + } else { + if (entry->medium == 1) { + func_sh_802f4c5c(entry->devAddr, entry->vAddr, 0x1000, alTbl->unk2); + } else { + func_sh_802f4bd8(entry, 0x1000); + } + entry->remaining = (s32) (entry->remaining - 0x1000); + entry->vAddr = (u8 *) entry->vAddr + 0x1000; + entry->devAddr = entry->devAddr + 0x1000; + } + break; + } + } +} + +extern char shindouDebugPrint102[]; // "SLOWCOPY" +void func_sh_802f4bd8(struct PendingDmaSample *arg0, s32 len) { // len must be signed + osInvalDCache(arg0->vAddr, len); + osCreateMesgQueue(&arg0->queue, arg0->mesgs, 1); + func_sh_802f3dd0(&arg0->ioMesg, 0, 0, arg0->devAddr, arg0->vAddr, len, &arg0->queue, arg0->medium, shindouDebugPrint102); +} + +void func_sh_802f4c5c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) { + uintptr_t sp1C; + + sp1C = devAddr; + osInvalDCache(vAddr, nbytes); + func_sh_802f3ed4(func_sh_802f3ec4(arg3, &sp1C), sp1C, vAddr, nbytes); +} + +struct PendingDmaAudioBank *func_sh_802f4cb4(uintptr_t devAddr, void *vAddr, s32 size, s32 medium, s32 numChunks, OSMesgQueue *retQueue, s32 encodedInfo) { + struct PendingDmaAudioBank *item; + s32 i; + + for (i = 0; i < ARRAY_COUNT(sPendingDmaAudioBanks); i++) { + if (sPendingDmaAudioBanks[i].inProgress == 0) { + item = &sPendingDmaAudioBanks[i]; + break; + } + } + if (i == ARRAY_COUNT(sPendingDmaAudioBanks)) { + return NULL; + } + + item->inProgress = 1; + item->devAddr = devAddr; + item->audioBank = vAddr; + item->vAddr = vAddr; + item->remaining = size; + if (numChunks == 0) { + item->transferSize = 0x1000; + } else { + item->transferSize = ((size / numChunks) + 0xFF) & ~0xFF; + if (item->transferSize < 0x100) { + item->transferSize = 0x100; + } + } + item->retQueue = retQueue; + item->timer = 3; + item->medium = medium; + item->encodedInfo = encodedInfo; + osCreateMesgQueue(&item->dmaRetQueue, item->mesgs, 1); + return item; +} + +void func_sh_802f4dcc(s32 audioResetStatus) { + s32 i; + + if (gAudioLoadLockSH != 1) { + for (i = 0; i < ARRAY_COUNT(sPendingDmaAudioBanks); i++) { + if (sPendingDmaAudioBanks[i].inProgress == 1) { + func_sh_802f4e50(&sPendingDmaAudioBanks[i], audioResetStatus); + } + } + } +} + +void func_sh_802f4e50(struct PendingDmaAudioBank *audioBank, s32 audioResetStatus) { + ALSeqFile *alSeqFile; + u32 *encodedInfo; + OSMesg mesg; + u32 temp; + u32 bankId; + s32 bankId1; + s32 bankId2; + struct PatchStruct patchStruct; + alSeqFile = gAlTbl; + if (audioBank->timer >= 2) { + audioBank->timer--; + return; + } + if (audioBank->timer == 1) { + audioBank->timer = 0; + } else { + if (audioResetStatus != 0) { + osRecvMesg(&audioBank->dmaRetQueue, NULL, OS_MESG_BLOCK); + audioBank->inProgress = 0; + return; + } + if (osRecvMesg(&audioBank->dmaRetQueue, NULL, OS_MESG_NOBLOCK) == -1) { + return; + } + } + + encodedInfo = &audioBank->encodedInfo; + if (audioBank->remaining == 0) { + mesg = (OSMesg) audioBank->encodedInfo; +#pragma GCC diagnostic push +#if defined(__clang__) +#pragma GCC diagnostic ignored "-Wself-assign" +#endif + mesg = mesg; //! needs an extra read from mesg here to match... +#pragma GCC diagnostic pop + temp = *encodedInfo; + bankId = (temp >> 8) & 0xFF; + switch ((u8) (temp >> 0x10)) { + case 0: + if (gSeqLoadStatus[bankId] != SOUND_LOAD_STATUS_5) { + gSeqLoadStatus[bankId] = (u8) (temp & 0xFF); + } + break; + case 2: + if (gUnkLoadStatus[bankId] != SOUND_LOAD_STATUS_5) { + gUnkLoadStatus[bankId] = (u8) (temp & 0xFF); + } + break; + case 1: + if (gBankLoadStatus[bankId] != SOUND_LOAD_STATUS_5) { + gBankLoadStatus[bankId] = (u8) (temp & 0xFF); + } + bankId1 = gCtlEntries[bankId].bankId1; + bankId2 = gCtlEntries[bankId].bankId2; + patchStruct.bankId1 = bankId1; + patchStruct.bankId2 = bankId2; + if (bankId1 != 0xFF) { + patchStruct.baseAddr1 = func_sh_802f3598(bankId1, &patchStruct.medium1); + } else { + patchStruct.baseAddr1 = NULL; + } + if (bankId2 != 0xFF) { + patchStruct.baseAddr2 = func_sh_802f3598(bankId2, &patchStruct.medium2); + } else { + patchStruct.baseAddr2 = NULL; + } + + func_sh_802f5310(bankId, audioBank->audioBank, &patchStruct, 1); + break; + } + mesg = (OSMesg) audioBank->encodedInfo; + audioBank->inProgress = 0; + osSendMesg(audioBank->retQueue, mesg, OS_MESG_NOBLOCK); + } else if (audioBank->remaining < audioBank->transferSize) { + if (audioBank->medium == 1) { + func_sh_802f517c(audioBank->devAddr, audioBank->vAddr, audioBank->remaining, alSeqFile->unk2); + } else { + func_sh_802f50ec(audioBank, audioBank->remaining); + } + + audioBank->remaining = 0; + } else { + if (audioBank->medium == 1) { + func_sh_802f517c(audioBank->devAddr, audioBank->vAddr, audioBank->transferSize, alSeqFile->unk2); + } else { + func_sh_802f50ec(audioBank, audioBank->transferSize); + } + + audioBank->remaining -= audioBank->transferSize; + audioBank->devAddr += audioBank->transferSize; + audioBank->vAddr = ((u8 *) audioBank->vAddr) + audioBank->transferSize; + } +} + +extern char shindouDebugPrint110[]; // "BGCOPY" +void func_sh_802f50ec(struct PendingDmaAudioBank *arg0, size_t len) { + len += 0xf; + len &= ~0xf; + osInvalDCache(arg0->vAddr, len); + osCreateMesgQueue(&arg0->dmaRetQueue, arg0->mesgs, 1); + func_sh_802f3dd0(&arg0->ioMesg, 0, 0, arg0->devAddr, arg0->vAddr, len, &arg0->dmaRetQueue, arg0->medium, shindouDebugPrint110); +} + + +void func_sh_802f517c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) { + uintptr_t sp1C; + + sp1C = devAddr; + osInvalDCache(vAddr, nbytes); + func_sh_802f3ed4(func_sh_802f3ec4(arg3, &sp1C), sp1C, vAddr, nbytes); +} + +void patch_sound(struct AudioBankSound *sound, struct AudioBank *memBase, struct PatchStruct *patchInfo) { + struct AudioBankSample *sample; + void *patched; + +#define PATCH(x, base) (patched = (void *)((uintptr_t) (x) + (uintptr_t) base)) + + if ((uintptr_t) sound->sample <= 0x80000000) { + sample = sound->sample = PATCH(sound->sample, memBase); + if (sample->size != 0 && sample->isPatched != TRUE) { + sample->loop = PATCH(sample->loop, memBase); + sample->book = PATCH(sample->book, memBase); + switch (sample->medium) { + case 0: + sample->sampleAddr = PATCH(sample->sampleAddr, patchInfo->baseAddr1); + sample->medium = patchInfo->medium1; + break; + case 1: + sample->sampleAddr = PATCH(sample->sampleAddr, patchInfo->baseAddr2); + sample->medium = patchInfo->medium2; + break; + + case 2: + case 3: + break; + } + sample->isPatched = TRUE; + if (sample->bit1 && sample->medium != 0) { + D_SH_8034EA88[D_SH_8034F688++] = sample; + } + } + } +#undef PATCH +} + +BAD_RETURN(s32) func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct PatchStruct *patchInfo, s32 arg3) { + UNUSED u32 pad[2]; + u8 *addr; + UNUSED u32 pad1[3]; + s32 sp4C; + struct AudioBankSample *temp_s0; + s32 i; + uintptr_t count; + s32 temp; + + sp4C = 0; + if (D_SH_8034F68C != 0) { + sp4C = 1; + } else { + D_SH_80343CF0 = 0; + } + D_SH_8034F688 = 0; + patch_audio_bank(bankId, mem, patchInfo); + + count = 0; + for (i = 0; i < D_SH_8034F688; i++) { + count += ALIGN16(D_SH_8034EA88[i]->size); + } + + for (i = 0; i < D_SH_8034F688; i++) { + if (D_SH_8034F68C != 0x78) { + temp_s0 = D_SH_8034EA88[i]; + switch (arg3) { + case 0: + temp = temp_s0->medium = patchInfo->medium1; + if (temp != 0) { + if (temp_s0->size) { + } + addr = func_sh_802f1d90(temp_s0->size, patchInfo->bankId1, temp_s0->sampleAddr, temp_s0->medium); + } else { + temp = temp_s0->medium = patchInfo->medium2; + if (temp != 0) { + addr = func_sh_802f1d90(temp_s0->size, patchInfo->bankId2, temp_s0->sampleAddr, temp_s0->medium); + } + } + break; + + case 1: + temp = temp_s0->medium = patchInfo->medium1; + if (temp != 0) { + addr = func_sh_802f1d40(temp_s0->size, patchInfo->bankId1, temp_s0->sampleAddr, temp_s0->medium); + } else { + temp = temp_s0->medium = patchInfo->medium2; + if (temp != 0) { + addr = func_sh_802f1d40(temp_s0->size, patchInfo->bankId2, temp_s0->sampleAddr, temp_s0->medium); + } + } + break; + } + switch ((uintptr_t) addr) { + case 0: + break; + default: + switch (arg3) { + case 0: + if (temp_s0->medium == 1) { + func_sh_802f3d78((uintptr_t) temp_s0->sampleAddr, addr, temp_s0->size, gAlTbl->unk2); + temp_s0->sampleAddr = addr; + temp_s0->medium = 0; + } else { + func_sh_802f3c38((uintptr_t) temp_s0->sampleAddr, addr, temp_s0->size, temp_s0->medium); + temp_s0->sampleAddr = addr; + temp_s0->medium = 0; + } + break; + + case 1: + D_SH_8034EC88[D_SH_8034F68C].sample = temp_s0; + D_SH_8034EC88[D_SH_8034F68C].ramAddr = addr; + D_SH_8034EC88[D_SH_8034F68C].encodedInfo = (D_SH_8034F68C << 24) | 0xffffff; + D_SH_8034EC88[D_SH_8034F68C].isFree = FALSE; + D_SH_8034EC88[D_SH_8034F68C].endAndMediumIdentification = temp_s0->sampleAddr + temp_s0->size + temp_s0->medium; + D_SH_8034F68C++; + break; + } + } + continue; + } + break; + } + + D_SH_8034F688 = 0; + if (D_SH_8034F68C != 0 && sp4C == 0) { + temp_s0 = D_SH_8034EC88[D_SH_8034F68C - 1].sample; + temp = (temp_s0->size >> 12); + temp += 1; + count = (uintptr_t) temp_s0->sampleAddr; + func_sh_802f4cb4( + count, + D_SH_8034EC88[D_SH_8034F68C - 1].ramAddr, + temp_s0->size, + temp_s0->medium, + temp, + &gUnkQueue2, + D_SH_8034EC88[D_SH_8034F68C - 1].encodedInfo); + } +} + +s32 func_sh_802f573c(s32 audioResetStatus) { + struct AudioBankSample *sample; + u32 idx; + u8 *sampleAddr; + u32 size; + s32 unk; + u8 *added; + + if (D_SH_8034F68C > 0) { + if (audioResetStatus != 0) { + if (osRecvMesg(&gUnkQueue2, (OSMesg *) &idx, OS_MESG_NOBLOCK)) { + } + D_SH_8034F68C = 0; + return 0; + } + if (osRecvMesg(&gUnkQueue2, (OSMesg *) &idx, OS_MESG_NOBLOCK) == -1) { + return 0; + } + idx >>= 0x18; + if (D_SH_8034EC88[idx].isFree == FALSE) { + sample = D_SH_8034EC88[idx].sample; + added = (sample->sampleAddr + sample->size + sample->medium); + if (added == D_SH_8034EC88[idx].endAndMediumIdentification) { + sample->sampleAddr = D_SH_8034EC88[idx].ramAddr; + sample->medium = 0; + } + D_SH_8034EC88[idx].isFree = TRUE; + } + +next: + if (D_SH_8034F68C > 0) { + if (D_SH_8034EC88[D_SH_8034F68C - 1].isFree == TRUE) { + D_SH_8034F68C--; + goto next; + } + sample = D_SH_8034EC88[D_SH_8034F68C - 1].sample; + sampleAddr = sample->sampleAddr; + size = sample->size; + unk = size >> 0xC; + unk += 1; + added = ((sampleAddr + size) + sample->medium); + if (added != D_SH_8034EC88[D_SH_8034F68C - 1].endAndMediumIdentification) { + D_SH_8034EC88[D_SH_8034F68C - 1].isFree = TRUE; + D_SH_8034F68C--; + goto next; + } + size = sample->size; + func_sh_802f4cb4((uintptr_t) sampleAddr, D_SH_8034EC88[D_SH_8034F68C - 1].ramAddr, size, sample->medium, + unk, &gUnkQueue2, D_SH_8034EC88[D_SH_8034F68C - 1].encodedInfo); + } + } + return 1; +} + +s32 func_sh_802f5900(struct AudioBankSample *sample, s32 numLoaded, struct AudioBankSample *arg2[]) { + s32 i; + + for (i = 0; i < numLoaded; i++) { + if (sample->sampleAddr == arg2[i]->sampleAddr) { + break; + } + } + if (i == numLoaded) { + arg2[numLoaded++] = sample; + } + return numLoaded; +} + +s32 func_sh_802f5948(s32 bankId, struct AudioBankSample *list[]) { + s32 i; + struct Drum *drum; + struct Instrument *inst; + s32 numLoaded; + s32 numDrums; + s32 numInstruments; + + numLoaded = 0; + numDrums = gCtlEntries[bankId].numDrums; + numInstruments = gCtlEntries[bankId].numInstruments; + + for (i = 0; i < numDrums; i++) { + drum = get_drum(bankId, i); + if (drum == NULL) { + continue; + } + numLoaded = func_sh_802f5900(drum->sound.sample, numLoaded, list); + } + for (i = 0; i < numInstruments; i++) { + inst = get_instrument_inner(bankId, i); + if (inst == NULL) { + continue; + + } + if (inst->normalRangeLo != 0) { + numLoaded = func_sh_802f5900(inst->lowNotesSound.sample, numLoaded, list); + } + if (inst->normalRangeHi != 127) { + numLoaded = func_sh_802f5900(inst->highNotesSound.sample, numLoaded, list); + } + numLoaded = func_sh_802f5900(inst->normalNotesSound.sample, numLoaded, list); + } + return numLoaded; +} +#endif diff --git a/src/audio/playback.c b/src/audio/playback.c index dc07fd78..ff42e765 100644 --- a/src/audio/playback.c +++ b/src/audio/playback.c @@ -15,7 +15,7 @@ void note_set_resampling_rate(struct Note *note, f32 resamplingRateInput); #ifdef VERSION_SH void note_set_vel_pan_reverb(struct Note *note, struct ReverbInfo *reverbInfo) #else -void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverb) +void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbVol) #endif { struct NoteSubEu *sub = ¬e->noteSubEu; @@ -30,7 +30,7 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverb) UNUSED u32 pad1; f32 velocity; u8 pan; - u8 reverb; + u8 reverbVol; struct ReverbBitsData reverbBits; #endif @@ -38,7 +38,7 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverb) note_set_resampling_rate(note, reverbInfo->freqScale); velocity = reverbInfo->velocity; pan = reverbInfo->pan; - reverb = reverbInfo->reverb; + reverbVol = reverbInfo->reverbVol; reverbBits = reverbInfo->reverbBits.s; pan &= 0x7f; #else @@ -119,7 +119,7 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverb) } #ifdef VERSION_SH -if (velocity < 0.0f) { + if (velocity < 0.0f) { velocity = 0.0f; } if (velocity > 1.0f) { @@ -128,7 +128,7 @@ if (velocity < 0.0f) { sub->targetVolLeft = ((s32) (velocity * volLeft * 4095.999f)); sub->targetVolRight = ((s32) (velocity * volRight * 4095.999f)); - sub->bankId = reverbInfo->bankId; + sub->synthesisVolume = reverbInfo->synthesisVolume; sub->filter = reverbInfo->filter; #else if (velocity < 0.0f) { @@ -144,11 +144,12 @@ if (velocity < 0.0f) { sub->targetVolRight = ((s32) (velocity * volRight) & 0xffff) >> 5; #endif - if (sub->reverbVol != reverb) { + //! @bug for the change to UQ0.7, the if statement should also have been changed accordingly + if (sub->reverbVol != reverbVol) { #ifdef VERSION_SH - sub->reverbVol = reverb >> 1; + sub->reverbVol = reverbVol >> 1; #else - sub->reverbVol = reverb; + sub->reverbVol = reverbVol; #endif sub->envMixerNeedsInit = TRUE; return; @@ -345,7 +346,7 @@ void process_notes(void) { #ifndef VERSION_SH f32 frequency; #if defined(VERSION_JP) || defined(VERSION_US) - u8 reverb; + u8 reverbVol; #endif f32 velocity; #if defined(VERSION_JP) || defined(VERSION_US) @@ -359,11 +360,11 @@ void process_notes(void) { struct NoteSubEu *noteSubEu; #ifndef VERSION_SH UNUSED u8 pad[12]; - u8 reverb; + u8 reverbVol; UNUSED u8 pad3; u8 pan; #else - u8 pad[8]; + UNUSED u8 pad[8]; struct ReverbInfo reverbInfo; #endif u8 bookOffset; @@ -508,9 +509,9 @@ void process_notes(void) { reverbInfo.freqScale = attributes->freqScale; reverbInfo.velocity = attributes->velocity; reverbInfo.pan = attributes->pan; - reverbInfo.reverb = attributes->reverb; + reverbInfo.reverbVol = attributes->reverbVol; reverbInfo.reverbBits = attributes->reverbBits; - reverbInfo.bankId = attributes->unk1; + reverbInfo.synthesisVolume = attributes->synthesisVolume; reverbInfo.filter = attributes->filter; bookOffset = noteSubEu->bookOffset; } else { @@ -518,8 +519,8 @@ void process_notes(void) { reverbInfo.velocity = playbackState->parentLayer->noteVelocity; reverbInfo.pan = playbackState->parentLayer->notePan; reverbInfo.reverbBits = playbackState->parentLayer->reverbBits; - reverbInfo.reverb = playbackState->parentLayer->seqChannel->reverb; - reverbInfo.bankId = playbackState->parentLayer->seqChannel->unkSH0C; + reverbInfo.reverbVol = playbackState->parentLayer->seqChannel->reverbVol; + reverbInfo.synthesisVolume = playbackState->parentLayer->seqChannel->synthesisVolume; reverbInfo.filter = playbackState->parentLayer->seqChannel->filter; bookOffset = playbackState->parentLayer->seqChannel->bookOffset & 0x7; if (playbackState->parentLayer->seqChannel->seqPlayer->muted @@ -538,7 +539,7 @@ void process_notes(void) { frequency = attributes->freqScale; velocity = attributes->velocity; pan = attributes->pan; - reverb = attributes->reverb; + reverbVol = attributes->reverbVol; if (1) { } bookOffset = noteSubEu->bookOffset; @@ -546,7 +547,7 @@ void process_notes(void) { frequency = playbackState->parentLayer->noteFreqScale; velocity = playbackState->parentLayer->noteVelocity; pan = playbackState->parentLayer->notePan; - reverb = playbackState->parentLayer->seqChannel->reverb; + reverbVol = playbackState->parentLayer->seqChannel->reverbVol; bookOffset = playbackState->parentLayer->seqChannel->bookOffset & 0x7; } @@ -554,7 +555,7 @@ void process_notes(void) { frequency *= gAudioBufferParameters.resampleRate; velocity = velocity * scale * scale; note_set_resampling_rate(note, frequency); - note_set_vel_pan_reverb(note, velocity, pan, reverb); + note_set_vel_pan_reverb(note, velocity, pan, reverbVol); #endif noteSubEu->bookOffset = bookOffset; skip:; @@ -603,12 +604,12 @@ void process_notes(void) { frequency = attributes->freqScale; velocity = attributes->velocity; pan = attributes->pan; - reverb = attributes->reverb; + reverbVol = attributes->reverbVol; } else { frequency = note->parentLayer->noteFreqScale; velocity = note->parentLayer->noteVelocity; pan = note->parentLayer->notePan; - reverb = note->parentLayer->seqChannel->reverb; + reverbVol = note->parentLayer->seqChannel->reverbVol; } scale = note->adsrVolScale; @@ -621,7 +622,7 @@ void process_notes(void) { scale *= 4.3498e-5f; // ~1 / 23000 velocity = velocity * scale * scale; note_set_frequency(note, frequency); - note_set_vel_pan_reverb(note, velocity, pan, reverb); + note_set_vel_pan_reverb(note, velocity, pan, reverbVol); continue; } #endif @@ -746,9 +747,9 @@ void seq_channel_layer_decay_release_internal(struct SequenceChannelLayer *seqLa attributes->reverbBits = seqLayer->reverbBits; #endif if (seqLayer->seqChannel != NULL) { - attributes->reverb = seqLayer->seqChannel->reverb; + attributes->reverbVol = seqLayer->seqChannel->reverbVol; #ifdef VERSION_SH - attributes->unk1 = seqLayer->seqChannel->unkSH0C; + attributes->synthesisVolume = seqLayer->seqChannel->synthesisVolume; attributes->filter = seqLayer->seqChannel->filter; if (seqLayer->seqChannel->seqPlayer->muted && (seqLayer->seqChannel->muteBehavior & 8) != 0) { note->noteSubEu.finished = TRUE; @@ -1159,7 +1160,7 @@ void note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLaye build_synthetic_wave(note, seqLayer, instId); } #ifdef VERSION_SH - note->unkSH33 = seqLayer->seqChannel->bankId; + note->bankId = seqLayer->seqChannel->bankId; #else sub->bankId = seqLayer->seqChannel->bankId; #endif @@ -1444,7 +1445,7 @@ void note_init_all(void) { #if defined(VERSION_EU) || defined(VERSION_SH) note->waveId = 0; #else - note->reverb = 0; + note->reverbVol = 0; note->usesHeadsetPanEffects = FALSE; note->sampleCount = 0; note->instOrWave = 0; diff --git a/src/audio/playback.h b/src/audio/playback.h index d0eaf2ba..e2e15bf9 100644 --- a/src/audio/playback.h +++ b/src/audio/playback.h @@ -33,7 +33,7 @@ void note_init_all(void); #if defined(VERSION_SH) void note_set_vel_pan_reverb(struct Note *note, struct ReverbInfo *reverbInfo); #elif defined(VERSION_EU) -void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverb); +void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbVol); #endif #if defined(VERSION_EU) || defined(VERSION_SH) diff --git a/src/audio/port_eu.c b/src/audio/port_eu.c index e9a2a6a3..ab4aa65a 100644 --- a/src/audio/port_eu.c +++ b/src/audio/port_eu.c @@ -29,7 +29,6 @@ extern struct EuAudioCmd sAudioCmd[0x100]; void func_8031D690(s32 player, FadeT fadeInTime); void seq_player_fade_to_zero_volume(s32 player, FadeT fadeOutTime); -void port_eu_init_queues(void); void decrease_sample_dma_ttls(void); s32 audio_shut_down_and_reset_step(void); void func_802ad7ec(u32); @@ -139,44 +138,44 @@ void eu_process_audio_cmd(struct EuAudioCmd *cmd) { s32 i; switch (cmd->u.s.op) { - case 0x81: - preload_sequence(cmd->u.s.arg2, 3); - break; + case 0x81: + preload_sequence(cmd->u.s.arg2, 3); + break; - case 0x82: - case 0x88: - load_sequence(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3); - func_8031D690(cmd->u.s.arg1, cmd->u2.as_s32); - break; + case 0x82: + case 0x88: + load_sequence(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3); + func_8031D690(cmd->u.s.arg1, cmd->u2.as_s32); + break; - case 0x83: - if (gSequencePlayers[cmd->u.s.arg1].enabled != FALSE) { - if (cmd->u2.as_s32 == 0) { - sequence_player_disable(&gSequencePlayers[cmd->u.s.arg1]); + case 0x83: + if (gSequencePlayers[cmd->u.s.arg1].enabled != FALSE) { + if (cmd->u2.as_s32 == 0) { + sequence_player_disable(&gSequencePlayers[cmd->u.s.arg1]); + } + else { + seq_player_fade_to_zero_volume(cmd->u.s.arg1, cmd->u2.as_s32); + } } - else { - seq_player_fade_to_zero_volume(cmd->u.s.arg1, cmd->u2.as_s32); + break; + + case 0xf0: + gSoundMode = cmd->u2.as_s32; + break; + + case 0xf1: + for (i = 0; i < 4; i++) { + gSequencePlayers[i].muted = TRUE; + gSequencePlayers[i].recalculateVolume = TRUE; } - } - break; + break; - case 0xf0: - gSoundMode = cmd->u2.as_s32; - break; - - case 0xf1: - for (i = 0; i < 4; i++) { - gSequencePlayers[i].muted = TRUE; - gSequencePlayers[i].recalculateVolume = TRUE; - } - break; - - case 0xf2: - for (i = 0; i < 4; i++) { - gSequencePlayers[i].muted = FALSE; - gSequencePlayers[i].recalculateVolume = TRUE; - } - break; + case 0xf2: + for (i = 0; i < 4; i++) { + gSequencePlayers[i].muted = FALSE; + gSequencePlayers[i].recalculateVolume = TRUE; + } + break; } } @@ -264,55 +263,54 @@ void func_802ad7ec(u32 arg0) { } else if ((cmd->u.s.op & 0x40) != 0) { switch (cmd->u.s.op) { - case 0x41: - seqPlayer->fadeVolumeScale = cmd->u2.as_f32; - seqPlayer->recalculateVolume = TRUE; - break; + case 0x41: + seqPlayer->fadeVolumeScale = cmd->u2.as_f32; + seqPlayer->recalculateVolume = TRUE; + break; - case 0x47: - seqPlayer->tempo = cmd->u2.as_s32 * TATUMS_PER_BEAT; - break; + case 0x47: + seqPlayer->tempo = cmd->u2.as_s32 * TATUMS_PER_BEAT; + break; - case 0x48: - seqPlayer->transposition = cmd->u2.as_s8; - break; + case 0x48: + seqPlayer->transposition = cmd->u2.as_s8; + break; - case 0x46: - seqPlayer->seqVariationEu[cmd->u.s.arg3] = cmd->u2.as_s8; - break; + case 0x46: + seqPlayer->seqVariationEu[cmd->u.s.arg3] = cmd->u2.as_s8; + break; } } else if (seqPlayer->enabled != FALSE && cmd->u.s.arg2 < 0x10) { chan = seqPlayer->channels[cmd->u.s.arg2]; - if (IS_SEQUENCE_CHANNEL_VALID(chan)) - { + if (IS_SEQUENCE_CHANNEL_VALID(chan)) { switch (cmd->u.s.op) { - case 1: - chan->volumeScale = cmd->u2.as_f32; - chan->changes.as_bitfields.volume = TRUE; - break; - case 2: - chan->volume = cmd->u2.as_f32; - chan->changes.as_bitfields.volume = TRUE; - break; - case 3: - chan->newPan = cmd->u2.as_s8; - chan->changes.as_bitfields.pan = TRUE; - break; - case 4: - chan->freqScale = cmd->u2.as_f32; - chan->changes.as_bitfields.freqScale = TRUE; - break; - case 5: - chan->reverb = cmd->u2.as_s8; - break; - case 6: - if (cmd->u.s.arg3 < 8) { - chan->soundScriptIO[cmd->u.s.arg3] = cmd->u2.as_s8; - } - break; - case 8: - chan->stopSomething2 = cmd->u2.as_s8; + case 1: + chan->volumeScale = cmd->u2.as_f32; + chan->changes.as_bitfields.volume = TRUE; + break; + case 2: + chan->volume = cmd->u2.as_f32; + chan->changes.as_bitfields.volume = TRUE; + break; + case 3: + chan->newPan = cmd->u2.as_s8; + chan->changes.as_bitfields.pan = TRUE; + break; + case 4: + chan->freqScale = cmd->u2.as_f32; + chan->changes.as_bitfields.freqScale = TRUE; + break; + case 5: + chan->reverbVol = cmd->u2.as_s8; + break; + case 6: + if (cmd->u.s.arg3 < 8) { + chan->soundScriptIO[cmd->u.s.arg3] = cmd->u2.as_s8; + } + break; + case 8: + chan->stopSomething2 = cmd->u2.as_s8; } } } diff --git a/src/audio/unk_shindou_audio_file.c b/src/audio/port_sh.c similarity index 65% rename from src/audio/unk_shindou_audio_file.c rename to src/audio/port_sh.c index c2ed3159..e7fae5b0 100644 --- a/src/audio/unk_shindou_audio_file.c +++ b/src/audio/port_sh.c @@ -1,4 +1,5 @@ #ifdef VERSION_SH +// TODO: merge this with port_eu.c? #include @@ -7,6 +8,7 @@ #include "load.h" #include "synthesis.h" #include "internal.h" +#include "seqplayer.h" #define EXTRA_BUFFERED_AI_SAMPLES_TARGET 0x80 #define SAMPLES_TO_OVERPRODUCE 0x10 @@ -15,12 +17,13 @@ extern s32 D_SH_80314FC8; extern struct SPTask *D_SH_80314FCC; extern u8 D_SH_80315098; extern u8 D_SH_8031509C; +extern OSMesgQueue *D_SH_80350F68; -void func_sh_802f62e0(s32 playerIndex, s32 numFrames); -void func_sh_802f6288(s32 arg0, s32 numFrames); -void func_sh_802f6554(u32 arg0); +void func_8031D690(s32 playerIndex, s32 numFrames); +void seq_player_fade_to_zero_volume(s32 arg0, s32 numFrames); +void func_802ad7ec(u32 arg0); -struct SPTask *func_sh_802f5a80(void) { +struct SPTask *create_next_audio_frame_task(void) { u32 samplesRemainingInAI; s32 writtenCmds; s32 index; @@ -59,7 +62,7 @@ struct SPTask *func_sh_802f5a80(void) { gCurrAudioFrameDmaCount = 0; decrease_sample_dma_ttls(); - func_802f41e4(gAudioResetStatus); + func_sh_802f41e4(gAudioResetStatus); if (osRecvMesg(D_SH_80350F88, (OSMesg *) &sp38, OS_MESG_NOBLOCK) != -1) { if (gAudioResetStatus == 0) { gAudioResetStatus = 5; @@ -99,7 +102,7 @@ struct SPTask *func_sh_802f5a80(void) { if (osRecvMesg(D_SH_80350F68, (OSMesg *) &sp34, 0) != -1) { do { - func_sh_802f6554(sp34); + func_802ad7ec(sp34); } while (osRecvMesg(D_SH_80350F68, (OSMesg *) &sp34, 0) != -1); } @@ -143,109 +146,109 @@ struct SPTask *func_sh_802f5a80(void) { } } -void func_sh_802f5fb8(struct EuAudioCmd *cmd) { +void eu_process_audio_cmd(struct EuAudioCmd *cmd) { s32 i; struct Note *note; struct NoteSubEu *sub; switch (cmd->u.s.op) { - case 0x81: - preload_sequence(cmd->u.s.arg2, 3); - break; + case 0x81: + preload_sequence(cmd->u.s.arg2, 3); + break; - case 0x82: - case 0x88: - func_sh_802F3410(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3); - func_sh_802f62e0(cmd->u.s.arg1, cmd->u2.as_s32); - break; + case 0x82: + case 0x88: + load_sequence(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3); + func_8031D690(cmd->u.s.arg1, cmd->u2.as_s32); + break; - case 0x83: - if (gSequencePlayers[cmd->u.s.arg1].enabled != FALSE) { - if (cmd->u2.as_s32 == 0) { - sequence_player_disable(&gSequencePlayers[cmd->u.s.arg1]); + case 0x83: + if (gSequencePlayers[cmd->u.s.arg1].enabled != FALSE) { + if (cmd->u2.as_s32 == 0) { + sequence_player_disable(&gSequencePlayers[cmd->u.s.arg1]); + } + else { + seq_player_fade_to_zero_volume(cmd->u.s.arg1, cmd->u2.as_s32); + } } - else { - func_sh_802f6288(cmd->u.s.arg1, cmd->u2.as_s32); + break; + + case 0x84: + break; + + case 0xf0: + gSoundMode = cmd->u2.as_s32; + break; + + case 0xf1: + for (i = 0; i < 4; i++) { + gSequencePlayers[i].muted = TRUE; + gSequencePlayers[i].recalculateVolume = TRUE; } - } - break; + break; - case 0x84: - break; - - case 0xf0: - gSoundMode = cmd->u2.as_s32; - break; - - case 0xf1: - for (i = 0; i < 4; i++) { - gSequencePlayers[i].muted = TRUE; - gSequencePlayers[i].recalculateVolume = TRUE; - } - break; - - case 0xf2: - if (cmd->u2.as_s32 == 1) { - for (i = 0; i < gMaxSimultaneousNotes; i++) { - note = &gNotes[i]; - sub = ¬e->noteSubEu; - if (note->noteSubEu.enabled && note->unkSH34 == 0) { - if ((note->parentLayer->seqChannel->muteBehavior & 8) != 0) { - sub->finished = TRUE; + case 0xf2: + if (cmd->u2.as_s32 == 1) { + for (i = 0; i < gMaxSimultaneousNotes; i++) { + note = &gNotes[i]; + sub = ¬e->noteSubEu; + if (note->noteSubEu.enabled && note->unkSH34 == 0) { + if ((note->parentLayer->seqChannel->muteBehavior & 8) != 0) { + sub->finished = TRUE; + } } } } - } - for (i = 0; i < 4; i++) { - gSequencePlayers[i].muted = FALSE; - gSequencePlayers[i].recalculateVolume = TRUE; - } - break; + for (i = 0; i < 4; i++) { + gSequencePlayers[i].muted = FALSE; + gSequencePlayers[i].recalculateVolume = TRUE; + } + break; - case 0xf3: - func_sh_802f3024(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3); - break; + case 0xf3: + func_sh_802f3024(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3); + break; - case 0xf4: - func_sh_802f30f4(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3, &gUnkQueue1); - break; + case 0xf4: + func_sh_802f30f4(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3, &gUnkQueue1); + break; - case 0xf5: - func_sh_802f3158(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3, &gUnkQueue1); - break; + case 0xf5: + func_sh_802f3158(cmd->u.s.arg1, cmd->u.s.arg2, cmd->u.s.arg3, &gUnkQueue1); + break; - case 0xf6: - func_sh_802f3288(cmd->u.s.arg2); - break; + case 0xf6: + func_sh_802f3288(cmd->u.s.arg2); + break; } } -void func_sh_802f6288(s32 arg0, s32 numFrames) { +void seq_player_fade_to_zero_volume(s32 arg0, s32 fadeOutTime) { struct SequencePlayer *player; - if (numFrames == 0) { - numFrames = 1; + if (fadeOutTime == 0) { + fadeOutTime = 1; } player = &gSequencePlayers[arg0]; player->state = 2; - player->fadeRemainingFrames = numFrames; - player->fadeVelocity = -(player->fadeVolume / (f32) numFrames); + player->fadeRemainingFrames = fadeOutTime; + player->fadeVelocity = -(player->fadeVolume / (f32) fadeOutTime); } -void func_sh_802f62e0(s32 playerIndex, s32 numFrames) { +void func_8031D690(s32 playerIndex, s32 fadeInTime) { struct SequencePlayer *player; - if (numFrames != 0) { + if (fadeInTime != 0) { player = &gSequencePlayers[playerIndex]; player->state = 1; - player->fadeTimerUnkEu = numFrames; - player->fadeRemainingFrames = numFrames; + player->fadeTimerUnkEu = fadeInTime; + player->fadeRemainingFrames = fadeInTime; player->fadeVolume = 0.0f; player->fadeVelocity = 0.0f; } } -void func_sh_802f6330(void) { +void port_eu_init_queues(void) { D_SH_80350F18 = 0; D_SH_80350F19 = 0; D_SH_80350F38 = &D_SH_80350F20; @@ -258,8 +261,8 @@ void func_sh_802f6330(void) { osCreateMesgQueue(D_SH_80350FA8, D_SH_80350F8C, 1); } -extern struct EuAudioCmd sAudioCmd[0x100]; // sAudioCmd, maybe? -void func_802ad6f0(s32 arg0, s32 *arg1) { // func_sh_802f63f8 +extern struct EuAudioCmd sAudioCmd[0x100]; +void func_802ad6f0(s32 arg0, s32 *arg1) { struct EuAudioCmd *cmd = &sAudioCmd[D_SH_80350F18 & 0xff]; cmd->u.first = arg0; cmd->u2.as_u32 = *arg1; @@ -269,34 +272,30 @@ void func_802ad6f0(s32 arg0, s32 *arg1) { // func_sh_802f63f8 } } -void func_802ad728(u32 arg0, f32 arg1) { // func_sh_802f6450 +void func_802ad728(u32 arg0, f32 arg1) { func_802ad6f0(arg0, (s32 *) &arg1); } -void func_802ad74c(u32 arg0, u32 arg1) { // func_sh_802f6474 +void func_802ad74c(u32 arg0, u32 arg1) { func_802ad6f0(arg0, (s32 *) &arg1); } -void func_802ad770(u32 arg0, s8 arg1) { // func_sh_802f6498 +void func_802ad770(u32 arg0, s8 arg1) { s32 sp1C = arg1 << 24; func_802ad6f0(arg0, &sp1C); } char shindouDebugPrint133[] = "AudioSend: %d -> %d (%d)\n"; -extern OSMesgQueue *D_SH_80350F68; void func_sh_802F64C8(void) { static s32 D_SH_8031503C = 0; - s32 a0 = (D_SH_80350F18 - D_SH_80350F19 + 0x100) & 0xff; - s32 a1; + s32 mesg; - if (D_SH_8031503C < a0) { - D_SH_8031503C = a0; + if (((D_SH_80350F18 - D_SH_80350F19 + 0x100) & 0xff) > D_SH_8031503C) { + D_SH_8031503C = (D_SH_80350F18 - D_SH_80350F19 + 0x100) & 0xff; } - a0 = ((D_SH_80350F19 & 0xff) << 8) | (D_SH_80350F18 & 0xFF); - a1 = a0; - a0 = D_SH_80350F68; - osSendMesg(a0, a1, 0); + mesg = ((D_SH_80350F19 & 0xff) << 8) | (D_SH_80350F18 & 0xff); + osSendMesg(D_SH_80350F68, (OSMesg)mesg, OS_MESG_NOBLOCK); D_SH_80350F19 = D_SH_80350F18; } @@ -304,16 +303,16 @@ void func_sh_802f6540(void) { D_SH_80350F19 = D_SH_80350F18; } -void func_sh_802f6554(u32 arg0) { +void func_802ad7ec(u32 arg0) { struct EuAudioCmd *cmd; struct SequencePlayer *seqPlayer; struct SequenceChannel *chan; - u8 a0; + u8 end; - static char shindouDebugPrint134[] = "Continue Port\n"; - static char shindouDebugPrint135[] = "%d -> %d\n"; - static char shindouDebugPrint136[] = "Sync-Frame Break. (Remain %d)\n"; - static char shindouDebugPrint137[] = "Undefined Port Command %d\n"; + UNUSED static char shindouDebugPrint134[] = "Continue Port\n"; + UNUSED static char shindouDebugPrint135[] = "%d -> %d\n"; + UNUSED static char shindouDebugPrint136[] = "Sync-Frame Break. (Remain %d)\n"; + UNUSED static char shindouDebugPrint137[] = "Undefined Port Command %d\n"; static u8 D_SH_80315098 = 0; static u8 D_SH_8031509C = 0; @@ -322,10 +321,10 @@ void func_sh_802f6554(u32 arg0) { D_SH_80315098 = (arg0 >> 8) & 0xff; } - a0 = arg0 & 0xff; + end = arg0 & 0xff; for (;;) { - if (D_SH_80315098 == a0) { + if (D_SH_80315098 == end) { D_SH_8031509C = 0; break; } @@ -336,83 +335,83 @@ void func_sh_802f6554(u32 arg0) { break; } else if ((cmd->u.s.op & 0xf0) == 0xf0) { - func_sh_802f5fb8(cmd); + eu_process_audio_cmd(cmd); } else if (cmd->u.s.arg1 < SEQUENCE_PLAYERS) { seqPlayer = &gSequencePlayers[cmd->u.s.arg1]; if ((cmd->u.s.op & 0x80) != 0) { - func_sh_802f5fb8(cmd); + eu_process_audio_cmd(cmd); } else if ((cmd->u.s.op & 0x40) != 0) { switch (cmd->u.s.op) { - case 0x41: - if (seqPlayer->fadeVolumeScale != cmd->u2.as_f32) { - seqPlayer->fadeVolumeScale = cmd->u2.as_f32; - seqPlayer->recalculateVolume = TRUE; - } - break; + case 0x41: + if (seqPlayer->fadeVolumeScale != cmd->u2.as_f32) { + seqPlayer->fadeVolumeScale = cmd->u2.as_f32; + seqPlayer->recalculateVolume = TRUE; + } + break; - case 0x47: - seqPlayer->tempo = cmd->u2.as_s32 * TATUMS_PER_BEAT; - break; + case 0x47: + seqPlayer->tempo = cmd->u2.as_s32 * TATUMS_PER_BEAT; + break; - case 0x49: - seqPlayer->tempoAdd = cmd->u2.as_s32 * TEMPO_SCALE; - break; + case 0x49: + seqPlayer->tempoAdd = cmd->u2.as_s32 * TEMPO_SCALE; + break; - case 0x48: - seqPlayer->transposition = cmd->u2.as_s8; - break; + case 0x48: + seqPlayer->transposition = cmd->u2.as_s8; + break; - case 0x46: - seqPlayer->seqVariationEu[cmd->u.s.arg3] = cmd->u2.as_s8; - break; + case 0x46: + seqPlayer->seqVariationEu[cmd->u.s.arg3] = cmd->u2.as_s8; + break; } } else if (seqPlayer->enabled != FALSE && cmd->u.s.arg2 < 0x10) { chan = seqPlayer->channels[cmd->u.s.arg2]; - if (IS_SEQUENCE_CHANNEL_VALID(chan)) - { + if (IS_SEQUENCE_CHANNEL_VALID(chan)) { switch (cmd->u.s.op) { - case 1: - if (chan->volumeScale != cmd->u2.as_f32) { - chan->volumeScale = cmd->u2.as_f32; - chan->changes.as_bitfields.volume = TRUE; - } - break; - case 2: - if (chan->volume != cmd->u2.as_f32) { - chan->volume = cmd->u2.as_f32; - chan->changes.as_bitfields.volume = TRUE; - } - break; - case 3: - if (chan->newPan != cmd->u2.as_s8) { - chan->newPan = cmd->u2.as_s8; - chan->changes.as_bitfields.pan = TRUE; - } - break; - case 4: - if (chan->freqScale != cmd->u2.as_f32) { - chan->freqScale = cmd->u2.as_f32; - chan->changes.as_bitfields.freqScale = TRUE; - } - break; - case 5: - if (chan->reverb != cmd->u2.as_s8) { - chan->reverb = cmd->u2.as_s8; - } - break; - case 6: - if (cmd->u.s.arg3 < 8) { - chan->soundScriptIO[cmd->u.s.arg3] = cmd->u2.as_s8; - } - break; - case 8: - chan->stopSomething2 = cmd->u2.as_s8; - break; - case 9: - chan->muteBehavior = cmd->u2.as_s8; + case 1: + if (chan->volumeScale != cmd->u2.as_f32) { + chan->volumeScale = cmd->u2.as_f32; + chan->changes.as_bitfields.volume = TRUE; + } + break; + case 2: + if (chan->volume != cmd->u2.as_f32) { + chan->volume = cmd->u2.as_f32; + chan->changes.as_bitfields.volume = TRUE; + } + break; + case 3: + if (chan->newPan != cmd->u2.as_s8) { + chan->newPan = cmd->u2.as_s8; + chan->changes.as_bitfields.pan = TRUE; + } + break; + case 4: + if (chan->freqScale != cmd->u2.as_f32) { + chan->freqScale = cmd->u2.as_f32; + chan->changes.as_bitfields.freqScale = TRUE; + } + break; + case 5: + //! @bug u8 s8 comparison (but harmless) + if (chan->reverbVol != cmd->u2.as_s8) { + chan->reverbVol = cmd->u2.as_s8; + } + break; + case 6: + if (cmd->u.s.arg3 < 8) { + chan->soundScriptIO[cmd->u.s.arg3] = cmd->u2.as_s8; + } + break; + case 8: + chan->stopSomething2 = cmd->u2.as_s8; + break; + case 9: + chan->muteBehavior = cmd->u2.as_s8; } } } @@ -489,9 +488,8 @@ s8 func_sh_802f6a6c(s32 playerIndex, s32 index) { return gSequencePlayers[playerIndex].seqVariationEu[index]; } -void func_sh_802f6a9c(void) { - // creates a bunch of os message queues - func_sh_802f6330(); +void port_eu_init(void) { + port_eu_init_queues(); } char shindouDebugPrint138[] = "specchg conjunction error (Msg:%d Cur:%d)\n"; @@ -525,9 +523,13 @@ char shindouDebugPrint164[] = "Audio: C-Alloc : lowerPrio is NULL\n"; char shindouDebugPrint165[] = "Intterupt UseStop %d (Kill %d)\n"; char shindouDebugPrint166[] = "Intterupt RelWait %d (Kill %d)\n"; char shindouDebugPrint167[] = "Drop Voice (Prio %x)\n"; -s32 D_SH_803154CC = 0; // Either an unused variable or a file boundary. +s32 D_SH_803154CC = 0; // file boundary + +// effects.c char shindouDebugPrint168[] = "Audio:Envp: overflow %f\n"; -s32 D_SH_803154EC = 0; // Either an unused variable or a file boundary. +s32 D_SH_803154EC = 0; // file boundary + +// seqplayer.c char shindouDebugPrint169[] = "Audio:Track:Warning: No Free Notetrack\n"; char shindouDebugPrint170[] = "SUBTRACK DIM\n"; char shindouDebugPrint171[] = "Audio:Track: Warning :SUBTRACK had been stolen by other Group.\n"; diff --git a/src/audio/seqplayer.c b/src/audio/seqplayer.c index cbf40e93..b37687ae 100644 --- a/src/audio/seqplayer.c +++ b/src/audio/seqplayer.c @@ -55,9 +55,9 @@ void sequence_channel_init(struct SequenceChannel *seqChannel) { seqChannel->panChannelWeight = 1.0f; seqChannel->noteUnused = NULL; #endif - seqChannel->reverb = 0; + seqChannel->reverbVol = 0; #ifdef VERSION_SH - seqChannel->unkSH0C = 0; + seqChannel->synthesisVolume = 0; #endif seqChannel->notePriority = NOTE_PRIORITY_DEFAULT; #ifdef VERSION_SH @@ -142,7 +142,7 @@ s32 seq_channel_set_layer(struct SequenceChannel *seqChannel, s32 layerIndex) { layer->freqScale = 1.0f; layer->velocitySquare = 0.0f; #ifdef VERSION_SH - layer->unkSH28 = 1.0f; + layer->freqScaleMultiplier = 1.0f; #endif layer->instOrWave = 0xff; #else @@ -989,7 +989,7 @@ void seq_channel_layer_process_script_part1(struct SequenceChannelLayer *layer) } s32 seq_channel_layer_process_script_part5(struct SequenceChannelLayer *layer, s32 cmd) { - if (!layer->stopSomething && layer->sound != NULL && layer->sound->sample->codec == 2 && + if (!layer->stopSomething && layer->sound != NULL && layer->sound->sample->codec == CODEC_SKIP && layer->sound->sample->medium != 0) { layer->stopSomething = TRUE; return -1; @@ -1176,7 +1176,7 @@ s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer) { case 0xce: cmd = m64_read_u8(state) + 0x80; - layer->unkSH28 = unk_sh_data_1[cmd]; + layer->freqScaleMultiplier = unk_sh_data_1[cmd]; // missing break :) default: @@ -1320,7 +1320,7 @@ s32 seq_channel_layer_process_script_part4(struct SequenceChannelLayer *layer, s } } layer->delayUnused = layer->delay; - layer->freqScale *= layer->unkSH28; + layer->freqScale *= layer->freqScaleMultiplier; return sameSound; } @@ -1390,8 +1390,7 @@ s32 seq_channel_layer_process_script_part3(struct SequenceChannelLayer *layer, s layer->delay = sp3A; layer->duration = layer->noteDuration * sp3A >> 8; if ((seqPlayer->muted && (seqChannel->muteBehavior & 0x50) != 0) - || seqChannel->stopSomething2) - { + || seqChannel->stopSomething2) { layer->stopSomething = TRUE; return -1; } @@ -1404,8 +1403,7 @@ u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrume struct Instrument *inst; #if defined(VERSION_EU) || defined(VERSION_SH) inst = get_instrument_inner(seqChannel->bankId, instId); - if (inst == NULL) - { + if (inst == NULL) { *instOut = NULL; return 0; } @@ -1524,25 +1522,21 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { for (;;) { cmd = m64_read_u8(state); #if !defined(VERSION_EU) && !defined(VERSION_SH) - if (cmd == 0xff) // chan_end - { + if (cmd == 0xff) { // chan_end if (state->depth == 0) { sequence_channel_disable(seqChannel); break; } state->depth--, state->pc = state->stack[state->depth]; } - if (cmd == 0xfe) // chan_delay1 - { + if (cmd == 0xfe) { // chan_delay1 break; } - if (cmd == 0xfd) // chan_delay - { + if (cmd == 0xfd) { // chan_delay seqChannel->delay = m64_read_compressed_u16(state); break; } - if (cmd == 0xf3) // chan_hang - { + if (cmd == 0xf3) { // chan_hang seqChannel->stopScript = TRUE; break; } @@ -1828,7 +1822,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { #endif case 0xd4: // chan_setreverb - seqChannel->reverb = m64_read_u8(state); + seqChannel->reverbVol = m64_read_u8(state); break; case 0xc6: // chan_setbank; switch bank within set @@ -1972,8 +1966,8 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { seqChannel->transposition = (s8) *seqData++; seqChannel->newPan = *seqData++; seqChannel->panChannelWeight = *seqData++; - seqChannel->reverb = *seqData++; - seqChannel->reverbIndex = *seqData++; // reverb index? + seqChannel->reverbVol = *seqData++; + seqChannel->reverbIndex = *seqData++; seqChannel->changes.as_bitfields.pan = TRUE; break; @@ -1984,7 +1978,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { seqChannel->transposition = (s8) m64_read_u8(state); seqChannel->newPan = m64_read_u8(state); seqChannel->panChannelWeight = m64_read_u8(state); - seqChannel->reverb = m64_read_u8(state); + seqChannel->reverbVol = m64_read_u8(state); seqChannel->reverbIndex = m64_read_u8(state); seqChannel->changes.as_bitfields.pan = TRUE; break; @@ -2016,7 +2010,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { #endif #ifdef VERSION_SH case 0xed: - seqChannel->unkSH0C = m64_read_u8(state); + seqChannel->synthesisVolume = m64_read_u8(state); break; case 0xef: @@ -2112,7 +2106,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) { case 0x10: seqChannel->soundScriptIO[loBits] = -1; - if (func_802f47c8(seqChannel->bankId, (u8)value, &seqChannel->soundScriptIO[loBits]) == -1) { + if (func_sh_802f47c8(seqChannel->bankId, (u8)value, &seqChannel->soundScriptIO[loBits]) == -1) { } break; #else @@ -2362,8 +2356,7 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) { #endif for (;;) { cmd = m64_read_u8(state); - if (cmd == 0xff) // seq_end - { + if (cmd == 0xff) { // seq_end if (state->depth == 0) { sequence_player_disable(seqPlayer); break; @@ -2375,14 +2368,12 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) { #endif } - if (cmd == 0xfd) // seq_delay - { + if (cmd == 0xfd) { // seq_delay seqPlayer->delay = m64_read_compressed_u16(state); break; } - if (cmd == 0xfe) // seq_delay1 - { + if (cmd == 0xfe) { // seq_delay1 seqPlayer->delay = 1; break; } @@ -2502,7 +2493,7 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) { seqPlayer->tempo = gTempoInternalToExternal; } - //if (cmd){} + //if (cmd) {} if ((s16) seqPlayer->tempo <= 0) { seqPlayer->tempo = 1; diff --git a/src/audio/shindou_debug_prints.c b/src/audio/shindou_debug_prints.c index 5f85e24a..261d4521 100644 --- a/src/audio/shindou_debug_prints.c +++ b/src/audio/shindou_debug_prints.c @@ -1,7 +1,14 @@ #include #ifdef VERSION_SH -// The first four debug prints are in data.c. +// synthesis.c +char shindouDebugPrint1[] = "Terminate-Canceled Channel %d,Phase %d\n"; +char shindouDebugPrint2[] = "S->W\n"; +char shindouDebugPrint3[] = "W->S\n"; +char shindouDebugPrint4[] = "S-Resample Pitch %x (old %d -> delay %d)\n"; +s32 shindouDebugPrintPadding1[] = {0,0,0}; + +// heap.c char shindouDebugPrint5[] = "Warning:Kill Note %x \n"; char shindouDebugPrint6[] = "Kill Voice %d (ID %d) %d\n"; char shindouDebugPrint7[] = "Warning: Running Sequence's data disappear!\n"; @@ -58,8 +65,9 @@ char shindouDebugPrint57[] = "Request--------Single-Stay, %d\n"; char shindouDebugPrint58[] = "Try Kill %d \n"; char shindouDebugPrint59[] = "Try Kill %x %x\n"; char shindouDebugPrint60[] = "Try Kill %x %x %x\n"; -// Zero padding here. These aren't used variables, so they could be either unused variables or a file boundary. s32 shindouDebugPrintPadding[] = {0, 0, 0}; + +// load.c char shindouDebugPrint61[] = "CAUTION:WAVE CACHE FULL %d"; char shindouDebugPrint62[] = "SUPERDMA"; char shindouDebugPrint63[] = "Bank Change... top %d lba %d\n"; @@ -124,6 +132,8 @@ char shindouDebugPrint121[] = "N start %d\n"; char shindouDebugPrint122[] = "============Error: Magic is Broken: %x\n"; char shindouDebugPrint123[] = "Error: No Handle.\n"; char shindouDebugPrint124[] = "Success: %x\n"; + +// port_eu.c char shindouDebugPrint125[] = "DAC:Lost 1 Frame.\n"; char shindouDebugPrint126[] = "DMA: Request queue over.( %d )\n"; char shindouDebugPrint127[] = "Spec Change Override. %d -> %d\n"; diff --git a/src/audio/synthesis.c b/src/audio/synthesis.c index b9f73753..224a0007 100644 --- a/src/audio/synthesis.c +++ b/src/audio/synthesis.c @@ -1,3 +1,4 @@ +#ifndef VERSION_SH #include #include "synthesis.h" @@ -9,7 +10,6 @@ #include "external.h" -#ifndef VERSION_SH #define DMEM_ADDR_TEMP 0x0 #define DMEM_ADDR_RESAMPLED 0x20 #define DMEM_ADDR_RESAMPLED2 0x160 @@ -22,18 +22,6 @@ #define DMEM_ADDR_RIGHT_CH 0x600 #define DMEM_ADDR_WET_LEFT_CH 0x740 #define DMEM_ADDR_WET_RIGHT_CH 0x880 -#else -#define DMEM_ADDR_TEMP 0x450 -#define DMEM_ADDR_RESAMPLED 0x470 -#define DMEM_ADDR_RESAMPLED2 0x5f0 -#define DMEM_ADDR_UNCOMPRESSED_NOTE 0x5f0 -#define DMEM_ADDR_NOTE_PAN_TEMP 0x650 -#define DMEM_ADDR_COMPRESSED_ADPCM_DATA 0x990 -#define DMEM_ADDR_LEFT_CH 0x990 -#define DMEM_ADDR_RIGHT_CH 0xb10 -#define DMEM_ADDR_WET_LEFT_CH 0xc90 -#define DMEM_ADDR_WET_RIGHT_CH 0xe10 -#endif #define aSetLoadBufferPair(pkt, c, off) \ aSetBuffer(pkt, 0, c + DMEM_ADDR_WET_LEFT_CH, 0, DEFAULT_LEN_1CH - c); \ @@ -57,12 +45,8 @@ struct VolumeChange { }; u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex); -#if defined(VERSION_EU) || defined(VERSION_SH) -#ifdef VERSION_SH -u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, u16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex); -#else -u64 *synthesis_process_note(struct Note *note, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, u16 *aiBuf, s32 bufLen, u64 *cmd); -#endif +#ifdef VERSION_EU +u64 *synthesis_process_note(struct Note *note, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s16 *aiBuf, s32 bufLen, u64 *cmd); u64 *load_wave_samples(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad); u64 *final_resample(u64 *cmd, struct NoteSynthesisState *synthesisState, s32 count, u16 pitch, u16 dmemIn, u32 flags); u64 *process_envelope(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, u32 flags); @@ -78,7 +62,7 @@ u64 *process_envelope_inner(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 flags, s32 leftRight); #endif -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU struct SynthesisReverb gSynthesisReverbs[4]; u8 sAudioSynthesisPad[0x10]; #else @@ -86,13 +70,10 @@ struct SynthesisReverb gSynthesisReverb; u8 sAudioSynthesisPad[0x20]; #endif -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU s16 gVolume; s8 gUseReverb; s8 gNumSynthesisReverbs; -#ifdef VERSION_SH -s16 D_SH_803479B4; // contains 4096 -#endif struct NoteSubEu *gNoteSubsEu; #endif @@ -106,7 +87,7 @@ u8 audioString1[] = "pitch %x: delaybytes %d : olddelay %d\n"; u8 audioString2[] = "cont %x: delaybytes %d : olddelay %d\n"; #endif -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU // Equivalent functionality as the US/JP version, // just that the reverb structure is chosen from an array with index void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex) { @@ -215,59 +196,31 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) { } #endif -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU u64 *synthesis_load_reverb_ring_buffer(u64 *cmd, u16 addr, u16 srcOffset, s32 len, s32 reverbIndex) { -#ifdef VERSION_SH - aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[srcOffset]), - addr, len); - aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[srcOffset]), - addr + DEFAULT_LEN_1CH, len); -#else aSetBuffer(cmd++, 0, addr, 0, len); aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[srcOffset])); aSetBuffer(cmd++, 0, addr + DEFAULT_LEN_1CH, 0, len); aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[srcOffset])); -#endif return cmd; } #endif -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU u64 *synthesis_save_reverb_ring_buffer(u64 *cmd, u16 addr, u16 destOffset, s32 len, s32 reverbIndex) { -#ifdef VERSION_SH - aSaveBuffer(cmd++, addr, - VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[destOffset]), len); - aSaveBuffer(cmd++, addr + DEFAULT_LEN_1CH, - VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[destOffset]), len); -#else aSetBuffer(cmd++, 0, 0, addr, len); aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[destOffset])); aSetBuffer(cmd++, 0, 0, addr + DEFAULT_LEN_1CH, len); aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[destOffset])); -#endif return cmd; } #endif -#if defined(VERSION_SH) -void func_sh_802ed644(s32 updateIndexStart, s32 noteIndex) { - s32 i; - - for (i = updateIndexStart + 1; i < gAudioBufferParameters.updatesPerFrame; i++) { - if (!gNoteSubsEu[gMaxSimultaneousNotes * i + noteIndex].needsInit) { - gNoteSubsEu[gMaxSimultaneousNotes * i + noteIndex].enabled = FALSE; - } else { - break; - } - } -} -#endif - -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU void synthesis_load_note_subs_eu(s32 updateIndex) { struct NoteSubEu *src; struct NoteSubEu *dest; @@ -286,7 +239,7 @@ void synthesis_load_note_subs_eu(s32 updateIndex) { } #endif -#if defined(VERSION_JP) || defined(VERSION_US) +#ifndef VERSION_EU s32 get_volume_ramping(u16 sourceVol, u16 targetVol, s32 arg2) { // This roughly computes 2^16 * (targetVol / sourceVol) ^ (8 / arg2), // but with discretizations of targetVol, sourceVol and arg2. @@ -309,46 +262,32 @@ s32 get_volume_ramping(u16 sourceVol, u16 targetVol, s32 arg2) { } #endif -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU // TODO: (Scrub C) pointless mask and whitespace u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) { s32 i, j; -#ifndef VERSION_SH f32 *leftVolRamp; f32 *rightVolRamp; -#endif u32 *aiBufPtr; u64 *cmd = cmdBuf; s32 chunkLen; -#ifndef VERSION_SH s32 nextVolRampTable; -#endif for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--) { process_sequences(i - 1); synthesis_load_note_subs_eu(gAudioBufferParameters.updatesPerFrame - i); } -#ifndef VERSION_SH aSegment(cmd++, 0, 0); -#endif aiBufPtr = (u32 *) aiBuf; for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--) { -#ifdef VERSION_SH - if (i == 1) { - chunkLen = bufLen; - } else { - if (bufLen / i >= gAudioBufferParameters.samplesPerUpdateMax) { - chunkLen = gAudioBufferParameters.samplesPerUpdateMax; - } else if (bufLen / i <= gAudioBufferParameters.samplesPerUpdateMin) { - chunkLen = gAudioBufferParameters.samplesPerUpdateMin; - } else { - chunkLen = gAudioBufferParameters.samplesPerUpdate; - } - } -#else if (i == 1) { +#pragma GCC diagnostic push +#if defined(__clang__) +#pragma GCC diagnostic ignored "-Wself-assign" +#endif // self-assignment has no affect when added here, could possibly simplify a macro definition chunkLen = bufLen; nextVolRampTable = nextVolRampTable; leftVolRamp = gLeftVolRampings[nextVolRampTable]; rightVolRamp = gRightVolRampings[nextVolRampTable & 0xFFFFFFFF]; +#pragma GCC diagnostic pop } else { if (bufLen / i >= gAudioBufferParameters.samplesPerUpdateMax) { chunkLen = gAudioBufferParameters.samplesPerUpdateMax; nextVolRampTable = 2; leftVolRamp = gLeftVolRampings[2]; rightVolRamp = gRightVolRampings[2]; @@ -360,7 +299,6 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) { } gCurrentLeftVolRamping = leftVolRamp; gCurrentRightVolRamping = rightVolRamp; -#endif for (j = 0; j < gNumSynthesisReverbs; j++) { if (gSynthesisReverbs[j].useReverb != 0) { prepare_reverb_ring_buffer(chunkLen, gAudioBufferParameters.updatesPerFrame - i, j); @@ -422,7 +360,7 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) { #endif -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s16 updateIndex) { struct ReverbRingBufferItem *item; s16 startPad; @@ -430,22 +368,15 @@ u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s1 item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex]; -#ifndef VERSION_SH aClearBuffer(cmd++, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH); -#endif if (gSynthesisReverbs[reverbIndex].downsampleRate == 1) { cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH, item->startPos, item->lengthA, reverbIndex); if (item->lengthB != 0) { cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH + item->lengthA, 0, item->lengthB, reverbIndex); } -#ifdef VERSION_SH - aAddMixer(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH); - aMix(cmd++, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH); -#else aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH); aMix(cmd++, 0, 0x7fff, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH); aMix(cmd++, 0, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_LEFT_CH); -#endif } else { startPad = (item->startPos % 8u) * 2; paddedLengthA = ALIGN(startPad + item->lengthA, 4); @@ -461,45 +392,13 @@ u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s1 aSetBuffer(cmd++, 0, DMEM_ADDR_RESAMPLED2 + startPad, DMEM_ADDR_WET_RIGHT_CH, bufLen * 2); aResample(cmd++, gSynthesisReverbs[reverbIndex].resampleFlags, gSynthesisReverbs[reverbIndex].resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].resampleStateRight)); -#ifdef VERSION_SH - aAddMixer(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH); - aMix(cmd++, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH); -#else aSetBuffer(cmd++, 0, 0, 0, DEFAULT_LEN_2CH); aMix(cmd++, 0, 0x7fff, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH); aMix(cmd++, 0, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_LEFT_CH); -#endif - } -#ifdef VERSION_SH - if (gSynthesisReverbs[reverbIndex].panRight != 0 || gSynthesisReverbs[reverbIndex].panLeft != 0) { - // Leak some audio from the left reverb channel into the right reverb channel and vice versa (pan) - aDMEMMove(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_RESAMPLED, DEFAULT_LEN_1CH); - aMix(cmd++, gSynthesisReverbs[reverbIndex].panRight, DMEM_ADDR_WET_RIGHT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_1CH); - aMix(cmd++, gSynthesisReverbs[reverbIndex].panLeft, DMEM_ADDR_RESAMPLED, DMEM_ADDR_WET_RIGHT_CH, DEFAULT_LEN_1CH); - } -#endif - return cmd; -} -#endif - -#if defined(VERSION_SH) -u64 *synthesis_load_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) { - struct ReverbRingBufferItem *item; - struct SynthesisReverb *reverb; - - reverb = &gSynthesisReverbs[reverbIndex]; - item = &reverb->items[reverb->curFrame][updateIndex]; - // Get the oldest samples in the ring buffer into the wet channels - cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED, item->startPos, item->lengthA, reverbIndex); - if (item->lengthB != 0) { - // Ring buffer wrapped - cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED + item->lengthA, 0, item->lengthB, reverbIndex); } return cmd; } -#endif -#if defined(VERSION_EU) u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) { struct ReverbRingBufferItem *item; @@ -516,8 +415,8 @@ u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) { break; default: - // Downsampling is done later by CPU when RSP is done, therefore we need to have double - // buffering. Left and right buffers are adjacent in memory. + // Downsampling is done later by CPU when RSP is done, therefore we need to have double + // buffering. Left and right buffers are adjacent in memory. aSetBuffer(cmd++, 0, 0, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH); aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex].toDownsampleLeft)); gSynthesisReverbs[reverbIndex].resampleFlags = 0; @@ -526,50 +425,9 @@ u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) { } return cmd; } -#elif defined(VERSION_SH) -u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) { - struct ReverbRingBufferItem *item; - - item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex]; - switch (gSynthesisReverbs[reverbIndex].downsampleRate) { - case 1: - // Put the oldest samples in the ring buffer into the wet channels - cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH, item->startPos, item->lengthA, reverbIndex); - if (item->lengthB != 0) { - // Ring buffer wrapped - cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH + item->lengthA, 0, item->lengthB, reverbIndex); - } - break; - - default: - // Downsampling is done later by CPU when RSP is done, therefore we need to have double - // buffering. Left and right buffers are adjacent in memory. - aSaveBuffer(cmd++, DMEM_ADDR_WET_LEFT_CH, - VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex].toDownsampleLeft), DEFAULT_LEN_2CH); - break; - } - gSynthesisReverbs[reverbIndex].resampleFlags = 0; - return cmd; -} - -u64 *func_sh_802EDF24(u64 *cmd, s16 reverbIndex, s16 updateIndex) { - struct ReverbRingBufferItem *item; - struct SynthesisReverb *reverb; - - reverb = &gSynthesisReverbs[reverbIndex]; - item = &reverb->items[reverb->curFrame][updateIndex]; - // Put the oldest samples in the ring buffer into the wet channels - cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED, item->startPos, item->lengthA, reverbIndex); - if (item->lengthB != 0) { - // Ring buffer wrapped - cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED + item->lengthA, 0, item->lengthB, reverbIndex); - } - return cmd; -} - #endif -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) { struct NoteSubEu *noteSubEu; u8 noteIndices[56]; @@ -611,53 +469,20 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI for (; i < notePos; i++) { temp = updateIndex * gMaxSimultaneousNotes; if (j == gNoteSubsEu[temp + noteIndices[i]].reverbIndex) { -#ifdef VERSION_SH - cmd = synthesis_process_note(noteIndices[i], - &gNoteSubsEu[temp + noteIndices[i]], - &gNotes[noteIndices[i]].synthesisState, - aiBuf, bufLen, cmd, updateIndex); -#else cmd = synthesis_process_note(&gNotes[noteIndices[i]], &gNoteSubsEu[temp + noteIndices[i]], &gNotes[noteIndices[i]].synthesisState, aiBuf, bufLen, cmd); -#endif continue; } else { break; } } if (gSynthesisReverbs[j].useReverb != 0) { -#ifdef VERSION_SH - if (gSynthesisReverbs[j].unk100 != NULL) { - aFilter(cmd++, 0x02, bufLen * 2, gSynthesisReverbs[j].unk100); - aFilter(cmd++, gSynthesisReverbs[j].resampleFlags, DMEM_ADDR_WET_LEFT_CH, gSynthesisReverbs[j].unk108); - } - if (gSynthesisReverbs[j].unk104 != NULL) { - aFilter(cmd++, 0x02, bufLen * 2, gSynthesisReverbs[j].unk104); - aFilter(cmd++, gSynthesisReverbs[j].resampleFlags, DMEM_ADDR_WET_RIGHT_CH, gSynthesisReverbs[j].unk10C); - } -#endif cmd = synthesis_save_reverb_samples(cmd, j, updateIndex); -#ifdef VERSION_SH - if (gSynthesisReverbs[j].unk5 != -1) { - if (gSynthesisReverbs[gSynthesisReverbs[j].unk5].downsampleRate == 1) { - cmd = synthesis_load_reverb_samples(cmd, gSynthesisReverbs[j].unk5, updateIndex); - aMix(cmd++, gSynthesisReverbs[j].unk08, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_RESAMPLED, DEFAULT_LEN_2CH); - cmd = func_sh_802EDF24(cmd++, gSynthesisReverbs[j].unk5, updateIndex); - } - } -#endif } } for (; i < notePos; i++) { -#ifdef VERSION_SH - struct NoteSubEu *noteSubEu2 = &gNoteSubsEu[updateIndex * gMaxSimultaneousNotes + noteIndices[i]]; - cmd = synthesis_process_note(noteIndices[i], - noteSubEu2, - &gNotes[noteIndices[i]].synthesisState, - aiBuf, bufLen, cmd, updateIndex); -#else temp = updateIndex * gMaxSimultaneousNotes; if (IS_BANK_LOAD_COMPLETE(gNoteSubsEu[temp + noteIndices[i]].bankId) == TRUE) { cmd = synthesis_process_note(&gNotes[noteIndices[i]], @@ -667,22 +492,16 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI } else { gAudioErrorFlags = (gNoteSubsEu[temp + noteIndices[i]].bankId + (i << 8)) + 0x10000000; } -#endif } temp = bufLen * 2; -#ifdef VERSION_SH - aInterleave(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_LEFT_CH, DMEM_ADDR_RIGHT_CH, temp); - aSaveBuffer(cmd++, DMEM_ADDR_TEMP, VIRTUAL_TO_PHYSICAL2(aiBuf), temp * 2); -#else aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, temp); aInterleave(cmd++, DMEM_ADDR_LEFT_CH, DMEM_ADDR_RIGHT_CH); aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, temp * 2); aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(aiBuf)); -#endif return cmd; } -#elif defined(VERSION_JP) || defined(VERSION_US) +#else u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) { UNUSED s32 pad1[1]; s16 ra; @@ -758,10 +577,9 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI } #endif -#ifndef VERSION_SH -#if defined(VERSION_EU) +#ifdef VERSION_EU // Processes just one note, not all -u64 *synthesis_process_note(struct Note *note, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, u16 *aiBuf, s32 bufLen, u64 *cmd) { +u64 *synthesis_process_note(struct Note *note, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, UNUSED s16 *aiBuf, s32 bufLen, u64 *cmd) { UNUSED s32 pad0[3]; #else u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { @@ -772,22 +590,22 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { struct AudioBankSample *audioBookSample; // sp164, sp138 struct AdpcmLoop *loopInfo; // sp160, sp134 s16 *curLoadedBook = NULL; // sp154, sp130 -#if defined(VERSION_EU) +#ifdef VERSION_EU UNUSED u8 padEU[0x04]; #endif UNUSED u8 pad8[0x04]; -#if defined(VERSION_JP) || defined(VERSION_US) +#ifndef VERSION_EU u16 resamplingRateFixedPoint; // sp5c, sp11A #endif s32 noteFinished; // 150 t2, sp124 s32 restart; // 14c t3, sp120 s32 flags; // sp148, sp11C -#if defined(VERSION_EU) +#ifdef VERSION_EU u16 resamplingRateFixedPoint; // sp5c, sp11A #endif UNUSED u8 pad7[0x0c]; // sp100 UNUSED s32 tempBufLen; -#if defined(VERSION_EU) +#ifdef VERSION_EU s32 sp130; //sp128, sp104 UNUSED u32 pad9; #else @@ -796,7 +614,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { #endif s32 nAdpcmSamplesProcessed; // signed required for US s32 t0; -#if defined(VERSION_EU) +#ifdef VERSION_EU u8 *sampleAddr; // sp120, spF4 s32 s6; #else @@ -804,7 +622,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { u8 *sampleAddr; // sp120, spF4 #endif -#if defined(VERSION_EU) +#ifdef VERSION_EU s32 samplesLenAdjusted; // 108, spEC // Might have been used to store (samplesLenFixedPoint >> 0x10), but doing so causes strange // behavior with the break near the end of the loop, causing US and JP to need a goto instead @@ -829,26 +647,26 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { u32 samplesLenFixedPoint; // v1_1 s32 nSamplesInThisIteration; // v1_2 u32 a3; -#if defined(VERSION_JP) || defined(VERSION_US) +#ifndef VERSION_EU s32 t9; #endif u8 *v0_2; s32 nParts; // spE8, spBC s32 curPart; // spE4, spB8 -#if defined(VERSION_JP) || defined(VERSION_US) +#ifndef VERSION_EU f32 resamplingRate; // f12 #endif s32 temp; -#if defined(VERSION_EU) +#ifdef VERSION_EU s32 s5Aligned; #endif s32 resampledTempLen; // spD8, spAC u16 noteSamplesDmemAddrBeforeResampling; // spD6, spAA -#if defined(VERSION_JP) || defined(VERSION_US) +#ifndef VERSION_EU for (noteIndex = 0; noteIndex < gMaxSimultaneousNotes; noteIndex++) { note = &gNotes[noteIndex]; #ifdef VERSION_US @@ -866,17 +684,17 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { } else { #endif flags = 0; -#if defined(VERSION_EU) +#ifdef VERSION_EU tempBufLen = bufLen; #endif -#if defined(VERSION_EU) +#ifdef VERSION_EU if (noteSubEu->needsInit == TRUE) { #else if (note->needsInit == TRUE) { #endif flags = A_INIT; -#if defined(VERSION_JP) || defined(VERSION_US) +#ifndef VERSION_EU note->samplePosInt = 0; note->samplePosFrac = 0; #else @@ -890,7 +708,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { #endif } -#if defined(VERSION_JP) || defined(VERSION_US) +#ifndef VERSION_EU if (note->frequency < US_FLOAT(2.0)) { nParts = 1; if (note->frequency > US_FLOAT(1.99996)) { @@ -916,7 +734,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { synthesisState->samplePosFrac = samplesLenFixedPoint & 0xFFFF; #endif -#if defined(VERSION_EU) +#ifdef VERSION_EU if (noteSubEu->isSyntheticWave) { cmd = load_wave_samples(cmd, noteSubEu, synthesisState, samplesLenFixedPoint >> 0x10); noteSamplesDmemAddrBeforeResampling = (synthesisState->samplePosInt * 2) + DMEM_ADDR_UNCOMPRESSED_NOTE; @@ -935,7 +753,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { else { // ADPCM note -#if defined(VERSION_EU) +#ifdef VERSION_EU audioBookSample = noteSubEu->sound.audioBankSound->sample; #else audioBookSample = note->sound->sample; @@ -961,7 +779,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { if (curLoadedBook != audioBookSample->book->book) { u32 nEntries; // v1 curLoadedBook = audioBookSample->book->book; -#if defined(VERSION_EU) +#ifdef VERSION_EU nEntries = 16 * audioBookSample->book->order * audioBookSample->book->npredictors; aLoadADPCM(cmd++, nEntries, VIRTUAL_TO_PHYSICAL2(curLoadedBook + noteSubEu->bookOffset)); #else @@ -970,7 +788,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { #endif } -#if defined(VERSION_EU) +#ifdef VERSION_EU if (noteSubEu->bookOffset) { curLoadedBook = euUnknownData_80301950; // what's this? never read } @@ -983,7 +801,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { noteFinished = FALSE; restart = FALSE; nSamplesToProcess = samplesLenAdjusted - nAdpcmSamplesProcessed; -#if defined(VERSION_EU) +#ifdef VERSION_EU s2 = synthesisState->samplePosInt & 0xf; samplesRemaining = endPos - synthesisState->samplePosInt; #else @@ -991,7 +809,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { samplesRemaining = endPos - note->samplePosInt; #endif -#if defined(VERSION_EU) +#ifdef VERSION_EU if (s2 == 0 && synthesisState->restart == FALSE) { s2 = 16; } @@ -1007,7 +825,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { s0 = t0 * 16; s3 = s6 + s0 - nSamplesToProcess; } else { -#if defined(VERSION_JP) || defined(VERSION_US) +#ifndef VERSION_EU s0 = samplesRemaining + s2 - 0x10; #else s0 = samplesRemaining - s6; @@ -1027,7 +845,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { } if (t0 != 0) { -#if defined(VERSION_EU) +#ifdef VERSION_EU temp = (synthesisState->samplePosInt - s2 + 0x10) / 16; if (audioBookSample->loaded == 0x81) { v0_2 = sampleAddr + temp * 9; @@ -1050,7 +868,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { a3 = 0; } -#if defined(VERSION_EU) +#ifdef VERSION_EU if (synthesisState->restart != FALSE) { aSetLoop(cmd++, VIRTUAL_TO_PHYSICAL2(audioBookSample->loop->state)); flags = A_LOOP; // = 2 @@ -1065,7 +883,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { #endif nSamplesInThisIteration = s0 + s6 - s3; -#if defined(VERSION_EU) +#ifdef VERSION_EU if (nAdpcmSamplesProcessed == 0) { aSetBuffer(cmd++, 0, DMEM_ADDR_COMPRESSED_ADPCM_DATA + a3, DMEM_ADDR_UNCOMPRESSED_NOTE, s0 * 2); @@ -1118,7 +936,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { if (noteFinished) { aClearBuffer(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5, (samplesLenAdjusted - nAdpcmSamplesProcessed) * 2); -#if defined(VERSION_EU) +#ifdef VERSION_EU noteSubEu->finished = 1; note->noteSubEu.finished = 1; note->noteSubEu.enabled = 0; @@ -1129,7 +947,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { #endif break; } -#if defined(VERSION_EU) +#ifdef VERSION_EU if (restart) { synthesisState->restart = TRUE; synthesisState->samplePosInt = loopInfo->start; @@ -1155,14 +973,14 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { switch (curPart) { case 0: aSetBuffer(cmd++, 0, DMEM_ADDR_UNCOMPRESSED_NOTE + sp130, DMEM_ADDR_RESAMPLED, samplesLenAdjusted + 4); -#if defined(VERSION_EU) +#ifdef VERSION_EU aResample(cmd++, A_INIT, 0xff60, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->dummyResampleState)); #else aResample(cmd++, A_INIT, 0xff60, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->dummyResampleState)); #endif resampledTempLen = samplesLenAdjusted + 4; noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_RESAMPLED + 4; -#if defined(VERSION_EU) +#ifdef VERSION_EU if (noteSubEu->finished != FALSE) { #else if (note->finished != FALSE) { @@ -1175,7 +993,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { aSetBuffer(cmd++, 0, DMEM_ADDR_UNCOMPRESSED_NOTE + sp130, DMEM_ADDR_RESAMPLED2, samplesLenAdjusted + 8); -#if defined(VERSION_EU) +#ifdef VERSION_EU aResample(cmd++, A_INIT, 0xff60, VIRTUAL_TO_PHYSICAL2( synthesisState->synthesisBuffers->dummyResampleState)); @@ -1191,7 +1009,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { } } -#if defined(VERSION_EU) +#ifdef VERSION_EU if (noteSubEu->finished != FALSE) { #else if (note->finished != FALSE) { @@ -1203,7 +1021,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { flags = 0; -#if defined(VERSION_EU) +#ifdef VERSION_EU if (noteSubEu->needsInit == TRUE) { flags = A_INIT; noteSubEu->needsInit = FALSE; @@ -1221,28 +1039,28 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { noteSamplesDmemAddrBeforeResampling, flags); #endif -#if defined(VERSION_JP) || defined(VERSION_US) - if (note->headsetPanRight != 0 || note->prevHeadsetPanRight != 0) { - leftRight = 1; - } else if (note->headsetPanLeft != 0 || note->prevHeadsetPanLeft != 0) { - leftRight = 2; -#else +#ifdef VERSION_EU if (noteSubEu->headsetPanRight != 0 || synthesisState->prevHeadsetPanRight != 0) { leftRight = 1; } else if (noteSubEu->headsetPanLeft != 0 || synthesisState->prevHeadsetPanLeft != 0) { leftRight = 2; +#else + if (note->headsetPanRight != 0 || note->prevHeadsetPanRight != 0) { + leftRight = 1; + } else if (note->headsetPanLeft != 0 || note->prevHeadsetPanLeft != 0) { + leftRight = 2; #endif } else { leftRight = 0; } -#if defined(VERSION_EU) +#ifdef VERSION_EU cmd = process_envelope(cmd, noteSubEu, synthesisState, bufLen, 0, leftRight, flags); #else cmd = process_envelope(cmd, note, bufLen, 0, leftRight, flags); #endif -#if defined(VERSION_EU) +#ifdef VERSION_EU if (noteSubEu->usesHeadsetPanEffects) { cmd = note_apply_headset_pan_effects(cmd, noteSubEu, synthesisState, bufLen * 2, flags, leftRight); } @@ -1252,7 +1070,7 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { } #endif } -#if defined(VERSION_JP) || defined(VERSION_US) +#ifndef VERSION_EU } t9 = bufLen * 2; @@ -1265,389 +1083,25 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) { return cmd; } -#else // VERSION_SH -u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, UNUSED u16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) { - UNUSED s32 pad0[3]; - struct AudioBankSample *audioBookSample; // sp164, sp138 - struct AdpcmLoop *loopInfo; // sp160, sp134 - s16 *curLoadedBook; // sp154, sp130 - UNUSED u8 padEU[0x04]; - UNUSED u8 pad8[0x04]; - s32 noteFinished; // 150 t2, sp124 - s32 restart; // 14c t3, sp120 - s32 flags; // sp148, sp11C, t8 - u16 resamplingRateFixedPoint; // sp5c, sp11A - s32 nSamplesToLoad; //s0, Ec - UNUSED u8 pad7[0x0c]; // sp100 - s32 sp130; //sp128, sp104 - UNUSED s32 tempBufLen; - UNUSED u32 pad9; - s32 t0; - u8 *sampleAddr; // sp120, spF4 - s32 s6; - s32 samplesLenAdjusted; // 108, spEC - s32 nAdpcmSamplesProcessed; // signed required for US // spc0 - s32 endPos; // sp110, spE4 - s32 nSamplesToProcess; // sp10c/a0, spE0 - // Might have been used to store (samplesLenFixedPoint >> 0x10), but doing so causes strange - // behavior with the break near the end of the loop, causing US and JP to need a goto instead - UNUSED s32 samplesLenInt; - s32 s2; - s32 leftRight; //s0 - s32 s5; //s4 - u32 samplesLenFixedPoint; // v1_1 - s32 s3; // spA0 - s32 nSamplesInThisIteration; // v1_2 - u32 a3; - u8 *v0_2; - s32 unk_s6; // sp90 - s32 s5Aligned; - s32 sp88; - s32 sp84; - u32 temp; - s32 nParts; // spE8, spBC - s32 curPart; // spE4, spB8 - s32 aligned; - UNUSED u32 padSH1; - s32 resampledTempLen; // spD8, spAC, sp6c - u16 noteSamplesDmemAddrBeforeResampling; // spD6, spAA, sp6a -- 6C - UNUSED u32 padSH2; - UNUSED u32 padSH3; - UNUSED u32 padSH4; - struct Note *note; // sp58 - u16 sp56; // sp56 - u16 addr; - u8 bankId; - curLoadedBook = NULL; - note = &gNotes[noteIndex]; - flags = 0; - if (noteSubEu->needsInit == TRUE) { - flags = A_INIT; - synthesisState->restart = 0; - synthesisState->samplePosInt = 0; - synthesisState->samplePosFrac = 0; - synthesisState->curVolLeft = 0; - synthesisState->curVolRight = 0; - synthesisState->prevHeadsetPanRight = 0; - synthesisState->prevHeadsetPanLeft = 0; - synthesisState->reverbVol = noteSubEu->reverbVol; - synthesisState->unk5 = 0; - note->noteSubEu.finished = 0; - } - - resamplingRateFixedPoint = noteSubEu->resamplingRateFixedPoint; - nParts = noteSubEu->hasTwoAdpcmParts + 1; - samplesLenFixedPoint = (resamplingRateFixedPoint * bufLen * 2) + synthesisState->samplePosFrac; - nSamplesToLoad = (samplesLenFixedPoint >> 0x10); - synthesisState->samplePosFrac = samplesLenFixedPoint & 0xFFFF; - - if ((synthesisState->unk5 == 1) && (nParts == 2)) { - nSamplesToLoad += 2; - sp56 = 2; - } else if ((synthesisState->unk5 == 2) && (nParts == 1)) { - nSamplesToLoad -= 4; - sp56 = 4; - } else { - sp56 = 0; - } - - - synthesisState->unk5 = nParts; - - if (noteSubEu->isSyntheticWave) { - cmd = load_wave_samples(cmd, noteSubEu, synthesisState, nSamplesToLoad); - noteSamplesDmemAddrBeforeResampling = (synthesisState->samplePosInt * 2) + DMEM_ADDR_UNCOMPRESSED_NOTE; - synthesisState->samplePosInt += nSamplesToLoad; - } else { - // ADPCM note - audioBookSample = noteSubEu->sound.audioBankSound->sample; - loopInfo = audioBookSample->loop; - endPos = loopInfo->end; - sampleAddr = audioBookSample->sampleAddr; - resampledTempLen = 0; - for (curPart = 0; curPart < nParts; curPart++) { - nAdpcmSamplesProcessed = 0; // s8 - s5 = 0; // s4 - - if (nParts == 1) { - samplesLenAdjusted = nSamplesToLoad; - } else if (nSamplesToLoad & 1) { - samplesLenAdjusted = (nSamplesToLoad & ~1) + (curPart * 2); - } else { - samplesLenAdjusted = nSamplesToLoad; - } - - if (audioBookSample->codec == 0) { - if (curLoadedBook != (*audioBookSample->book).book) { - u32 nEntries; - switch (noteSubEu->bookOffset) { - case 1: - curLoadedBook = euUnknownData_80301950 + 1; - break; - case 2: - curLoadedBook = euUnknownData_80301950 + 2; - break; - case 3: - default: - curLoadedBook = audioBookSample->book->book; - break; - } - nEntries = 16 * audioBookSample->book->order * audioBookSample->book->npredictors; - aLoadADPCM(cmd++, nEntries, VIRTUAL_TO_PHYSICAL2(curLoadedBook)); - } - } - - while (nAdpcmSamplesProcessed != samplesLenAdjusted) { - s32 samplesRemaining; // v1 - s32 s0; - - noteFinished = FALSE; - restart = FALSE; - s2 = synthesisState->samplePosInt & 0xf; - samplesRemaining = endPos - synthesisState->samplePosInt; - nSamplesToProcess = samplesLenAdjusted - nAdpcmSamplesProcessed; - - if (s2 == 0 && synthesisState->restart == FALSE) { - s2 = 16; - } - s6 = 16 - s2; // a1 - if (nSamplesToProcess < samplesRemaining) { - t0 = (nSamplesToProcess - s6 + 0xf) / 16; - s0 = t0 * 16; - s3 = s6 + s0 - nSamplesToProcess; - } else { - s0 = samplesRemaining - s6; - s3 = 0; - if (s0 <= 0) { - s0 = 0; - s6 = samplesRemaining; - } - t0 = (s0 + 0xf) / 16; - if (loopInfo->count != 0) { - // Loop around and restart - restart = 1; - } else { - noteFinished = 1; - } - } - switch (audioBookSample->codec) { - case 0: - unk_s6 = 9; - sp88 = 0x10; - sp84 = 0; - break; - case 1: - unk_s6 = 0x10; - sp88 = 0x10; - sp84 = 0; - break; - case 2: goto skip; - } - if (t0 != 0) { - temp = (synthesisState->samplePosInt + sp88 - s2) / 16; - if (audioBookSample->medium == 0) { - v0_2 = sp84 + (temp * unk_s6) + sampleAddr; - } else { - v0_2 = dma_sample_data((uintptr_t)(sp84 + (temp * unk_s6) + sampleAddr), - ALIGN(t0 * unk_s6 + 16, 4), flags, &synthesisState->sampleDmaIndex, audioBookSample->medium); - } - - a3 = ((uintptr_t)v0_2 & 0xf); - addr = DMEM_ADDR_COMPRESSED_ADPCM_DATA; - addr -= ALIGN(t0 * unk_s6 + 16, 4); - aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(v0_2 - a3), addr & 0xffff, ALIGN(t0 * unk_s6 + 16, 4)); - } else { - s0 = 0; - a3 = 0; - } - if (synthesisState->restart != FALSE) { - aSetLoop(cmd++, VIRTUAL_TO_PHYSICAL2(audioBookSample->loop->state)); - flags = A_LOOP; // = 2 - synthesisState->restart = FALSE; - } - nSamplesInThisIteration = s0 + s6 - s3; - if (nAdpcmSamplesProcessed == 0) { - switch (audioBookSample->codec) { - case 0: - aligned = ALIGN(t0 * unk_s6 + 16, 4); - //! I have no idea. - addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff; - addr += a3; - aSetBuffer(cmd++, 0, addr, DMEM_ADDR_UNCOMPRESSED_NOTE, s0 * 2); - aADPCMdec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState)); - break; - case 1: - aligned = ALIGN(t0 * unk_s6 + 16, 4); - addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff; - addr += a3; - aSetBuffer(cmd++, 0, addr, DMEM_ADDR_UNCOMPRESSED_NOTE, s0 * 2); - aADPCM_23(cmd++, flags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState)); - break; - } - sp130 = s2 * 2; - } else { - s5Aligned = ALIGN(s5 + 16, 4); - switch (audioBookSample->codec) { - case 0: - aligned = ALIGN(t0 * unk_s6 + 16, 4); - addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff; - addr += a3; - aSetBuffer(cmd++, 0, addr, DMEM_ADDR_UNCOMPRESSED_NOTE + s5Aligned, s0 * 2); - aADPCMdec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState)); - break; - case 1: - aligned = ALIGN(t0 * unk_s6 + 16, 4); - addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff & 0xffff; - addr += a3; - aSetBuffer(cmd++, 0, addr, DMEM_ADDR_UNCOMPRESSED_NOTE + s5Aligned, s0 * 2); - aADPCM_23(cmd++, flags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState)); - - break; - } - aDMEMMove(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5Aligned + (s2 * 2), DMEM_ADDR_UNCOMPRESSED_NOTE + s5, (nSamplesInThisIteration) * 2); - } - nAdpcmSamplesProcessed += nSamplesInThisIteration; - switch (flags) { - case A_INIT: // = 1 - sp130 = 0x20; - s5 = (s0 + 0x10) * 2; - break; - case A_LOOP: // = 2 - s5 = (nSamplesInThisIteration) * 2 + s5; - break; - default: - if (s5 != 0) { - s5 = (nSamplesInThisIteration) * 2 + s5; - } else { - s5 = (s2 + (nSamplesInThisIteration)) * 2; - } - break; - } - flags = 0; -skip: - if (noteFinished) { - aClearBuffer(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5, - (samplesLenAdjusted - nAdpcmSamplesProcessed) * 2); - noteSubEu->finished = 1; - note->noteSubEu.finished = 1; - func_sh_802ed644(updateIndex, noteIndex); - break; - } - if (restart != 0) { - synthesisState->restart = TRUE; - synthesisState->samplePosInt = loopInfo->start; - } else { - synthesisState->samplePosInt += nSamplesToProcess; - } - } - - switch (nParts) { - case 1: - noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_UNCOMPRESSED_NOTE + sp130; - break; - case 2: - switch (curPart) { - case 0: - aInterl(cmd++, 0, ALIGN(samplesLenAdjusted / 2, 3), DMEM_ADDR_UNCOMPRESSED_NOTE + sp130, DMEM_ADDR_RESAMPLED); - resampledTempLen = samplesLenAdjusted; - noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_RESAMPLED; - if (noteSubEu->finished != FALSE) { - aClearBuffer(cmd++, noteSamplesDmemAddrBeforeResampling + resampledTempLen, samplesLenAdjusted + 0x10); - } - break; - case 1: - aInterl(cmd++, 0, ALIGN(samplesLenAdjusted / 2, 3), DMEM_ADDR_UNCOMPRESSED_NOTE + sp130, resampledTempLen + DMEM_ADDR_RESAMPLED); - break; - } - } - if (noteSubEu->finished != FALSE) { - break; - } - } - } - flags = 0; - if (noteSubEu->needsInit == TRUE) { - flags = A_INIT; - noteSubEu->needsInit = FALSE; - } - flags = flags | sp56; - cmd = final_resample(cmd, synthesisState, bufLen * 2, resamplingRateFixedPoint, - noteSamplesDmemAddrBeforeResampling, flags); - if ((flags & 1) != 0) { - flags = 1; - } - - if (noteSubEu->filter) { - aFilter(cmd++, 0x02, bufLen * 2, noteSubEu->filter); - aFilter(cmd++, flags, DMEM_ADDR_TEMP, synthesisState->synthesisBuffers->filterBuffer); - - } - - if (noteSubEu->bookOffset == 3) { - aUnknown25(cmd++, 0, bufLen * 2, DMEM_ADDR_TEMP, DMEM_ADDR_TEMP); - } - - bankId = noteSubEu->bankId; - if (bankId != 0) { - if (bankId < 0x10) { - bankId = 0x10; - } - - aHilogain(cmd++, bankId, (bufLen + 0x10) * 2, DMEM_ADDR_TEMP); - } - - if (noteSubEu->headsetPanRight != 0 || synthesisState->prevHeadsetPanRight != 0) { - leftRight = 1; - } else if (noteSubEu->headsetPanLeft != 0 || synthesisState->prevHeadsetPanLeft != 0) { - leftRight = 2; - } else { - leftRight = 0; - } - cmd = process_envelope(cmd, noteSubEu, synthesisState, bufLen, 0x450, leftRight, flags); - if (noteSubEu->usesHeadsetPanEffects) { - if ((flags & 1) == 0) { - flags = 0; - } - cmd = note_apply_headset_pan_effects(cmd, noteSubEu, synthesisState, bufLen * 2, flags, leftRight); - } - - return cmd; -} -#endif - -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU u64 *load_wave_samples(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad) { s32 a3; s32 repeats; -#ifndef VERSION_SH s32 i; aSetBuffer(cmd++, /*flags*/ 0, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ 0, /*count*/ 128); aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(noteSubEu->sound.samples)); -#else - aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(noteSubEu->sound.samples), - DMEM_ADDR_UNCOMPRESSED_NOTE, 128); -#endif synthesisState->samplePosInt &= 0x3f; a3 = 64 - synthesisState->samplePosInt; if (a3 < nSamplesToLoad) { repeats = (nSamplesToLoad - a3 + 63) / 64; -#ifndef VERSION_SH for (i = 0; i < repeats; i++) { aDMEMMove(cmd++, /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, /*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + (1 + i) * 128, /*count*/ 128); } -#else - if (repeats != 0) { - aDuplicate(cmd++, - /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, - /*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + 128, - /*copies*/ repeats); - } -#endif } return cmd; } @@ -1669,18 +1123,10 @@ u64 *load_wave_samples(u64 *cmd, struct Note *note, s32 nSamplesToLoad) { } #endif -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU u64 *final_resample(u64 *cmd, struct NoteSynthesisState *synthesisState, s32 count, u16 pitch, u16 dmemIn, u32 flags) { -#ifdef VERSION_SH - if (pitch == 0) { - aClearBuffer(cmd++, DMEM_ADDR_TEMP, count); - } else { -#endif - aSetBuffer(cmd++, /*flags*/ 0, dmemIn, /*dmemout*/ DMEM_ADDR_TEMP, count); - aResample(cmd++, flags, pitch, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->finalResampleState)); -#ifdef VERSION_SH - } -#endif + aSetBuffer(cmd++, /*flags*/ 0, dmemIn, /*dmemout*/ DMEM_ADDR_TEMP, count); + aResample(cmd++, flags, pitch, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->finalResampleState)); return cmd; } #else @@ -1691,8 +1137,7 @@ u64 *final_resample(u64 *cmd, struct Note *note, s32 count, u16 pitch, u16 dmemI } #endif -#ifndef VERSION_SH -#if defined(VERSION_JP) || defined(VERSION_US) +#ifndef VERSION_EU u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, s32 headsetPanSettings, UNUSED u32 flags) { UNUSED u8 pad[16]; @@ -1782,7 +1227,7 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat } } -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU if (targetLeft == sourceLeft && targetRight == sourceRight && !note->envMixerNeedsInit) { #else if (vol->targetLeft == vol->sourceLeft && vol->targetRight == vol->sourceRight @@ -1792,7 +1237,7 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat } else { mixerFlags = A_INIT; -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU rampLeft = gCurrentLeftVolRamping[targetLeft >> 5] * gCurrentRightVolRamping[sourceLeft >> 5]; rampRight = gCurrentLeftVolRamping[targetRight >> 5] * gCurrentRightVolRamping[sourceRight >> 5]; #else @@ -1801,7 +1246,7 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat #endif // The operation's parameters change meanings depending on flags -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU aSetVolume(cmd++, A_VOL | A_LEFT, sourceLeft, 0, 0); aSetVolume(cmd++, A_VOL | A_RIGHT, sourceRight, 0, 0); aSetVolume32(cmd++, A_RATE | A_LEFT, targetLeft, rampLeft); @@ -1812,16 +1257,16 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat aSetVolume(cmd++, A_VOL | A_RIGHT, vol->sourceRight, 0, 0); aSetVolume32(cmd++, A_RATE | A_LEFT, vol->targetLeft, rampLeft); aSetVolume32(cmd++, A_RATE | A_RIGHT, vol->targetRight, rampRight); - aSetVolume(cmd++, A_AUX, gVolume, 0, note->reverbVol); + aSetVolume(cmd++, A_AUX, gVolume, 0, note->reverbVolShifted); #endif } -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU if (gUseReverb && note->reverbVol != 0) { aEnvMixer(cmd++, mixerFlags | A_AUX, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->mixEnvelopeState)); #else - if (gSynthesisReverb.useReverb && note->reverb) { + if (gSynthesisReverb.useReverb && note->reverbVol != 0) { aEnvMixer(cmd++, mixerFlags | A_AUX, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->mixEnvelopeState)); #endif @@ -1840,7 +1285,7 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat /*out*/ DMEM_ADDR_WET_RIGHT_CH); } } else { -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU aEnvMixer(cmd++, mixerFlags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->mixEnvelopeState)); #else aEnvMixer(cmd++, mixerFlags, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->mixEnvelopeState)); @@ -1858,123 +1303,29 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat return cmd; } -#elif defined(VERSION_SH) -u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, UNUSED u32 flags) { - u16 sourceRight; - u16 sourceLeft; - u16 targetLeft; - u16 targetRight; - s16 rampLeft; - s16 rampRight; - s32 sourceReverbVol; - s16 reverbVol; - s32 temp = 0; - - sourceLeft = synthesisState->curVolLeft; - sourceRight = synthesisState->curVolRight; - targetLeft = note->targetVolLeft; - targetRight = note->targetVolRight; - targetLeft <<= 4; - targetRight <<= 4; - - if (targetLeft != sourceLeft) { - rampLeft = (targetLeft - sourceLeft) / (nSamples >> 3); - } else { - rampLeft = 0; - } - if (targetRight != sourceRight) { - rampRight = (targetRight - sourceRight) / (nSamples >> 3); - } else { - rampRight = 0; - } - - sourceReverbVol = synthesisState->reverbVol; - if (note->reverbVol != sourceReverbVol) { - temp = ((note->reverbVol & 0x7f) - (sourceReverbVol & 0x7f)) << 9; - reverbVol = temp / (nSamples >> 3); - synthesisState->reverbVol = note->reverbVol; - } else { - reverbVol = 0; - } - synthesisState->curVolLeft = sourceLeft + rampLeft * (nSamples >> 3); - synthesisState->curVolRight = sourceRight + rampRight * (nSamples >> 3); - - if (note->usesHeadsetPanEffects) { - aClearBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DEFAULT_LEN_1CH); - aEnvSetup1(cmd++, (sourceReverbVol & 0x7f) * 2, reverbVol, rampLeft, rampRight); - aEnvSetup2(cmd++, sourceLeft, sourceRight); - - switch (headsetPanSettings) { - case 1: - aEnvMixer(cmd++, - inBuf, nSamples, - (sourceReverbVol & 0x80) >> 7, - note->stereoStrongRight, note->stereoStrongLeft, - DMEM_ADDR_NOTE_PAN_TEMP, - DMEM_ADDR_RIGHT_CH, - DMEM_ADDR_WET_LEFT_CH, - DMEM_ADDR_WET_RIGHT_CH); - break; - case 2: - aEnvMixer(cmd++, - inBuf, nSamples, - (sourceReverbVol & 0x80) >> 7, - note->stereoStrongRight, note->stereoStrongLeft, - DMEM_ADDR_LEFT_CH, - DMEM_ADDR_NOTE_PAN_TEMP, - DMEM_ADDR_WET_LEFT_CH, - DMEM_ADDR_WET_RIGHT_CH); - break; - default: - aEnvMixer(cmd++, - inBuf, nSamples, - (sourceReverbVol & 0x80) >> 7, - note->stereoStrongRight, note->stereoStrongLeft, - DMEM_ADDR_LEFT_CH, - DMEM_ADDR_RIGHT_CH, - DMEM_ADDR_WET_LEFT_CH, - DMEM_ADDR_WET_RIGHT_CH); - break; - } - } else { - aEnvSetup1(cmd++, (sourceReverbVol & 0x7f) * 2, reverbVol, rampLeft, rampRight); - aEnvSetup2(cmd++, sourceLeft, sourceRight); - aEnvMixer(cmd++, - inBuf, nSamples, - (sourceReverbVol & 0x80) >> 7, - note->stereoStrongRight, note->stereoStrongLeft, - DMEM_ADDR_LEFT_CH, - DMEM_ADDR_RIGHT_CH, - DMEM_ADDR_WET_LEFT_CH, - DMEM_ADDR_WET_RIGHT_CH); - } - return cmd; -} -#endif - -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight) { #else u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 flags, s32 leftRight) { #endif u16 dest; u16 pitch; -#if defined(VERSION_JP) || defined(VERSION_US) - u16 prevPanShift; - u16 panShift; -#else +#ifdef VERSION_EU u8 prevPanShift; u8 panShift; UNUSED u8 unkDebug; +#else + u16 prevPanShift; + u16 panShift; #endif switch (leftRight) { case 1: dest = DMEM_ADDR_LEFT_CH; -#if defined(VERSION_JP) || defined(VERSION_US) - panShift = note->headsetPanRight; -#else +#ifdef VERSION_EU panShift = noteSubEu->headsetPanRight; +#else + panShift = note->headsetPanRight; #endif note->prevHeadsetPanLeft = 0; prevPanShift = note->prevHeadsetPanRight; @@ -1982,10 +1333,10 @@ u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 break; case 2: dest = DMEM_ADDR_RIGHT_CH; -#if defined(VERSION_JP) || defined(VERSION_US) - panShift = note->headsetPanLeft; -#else +#ifdef VERSION_EU panShift = noteSubEu->headsetPanLeft; +#else + panShift = note->headsetPanLeft; #endif note->prevHeadsetPanRight = 0; @@ -1996,26 +1347,8 @@ u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 return cmd; } - if (flags != 1) // A_INIT? - { + if (flags != 1) { // A_INIT? // Slightly adjust the sample rate in order to fit a change in pan shift -#ifdef VERSION_SH - if (panShift != prevPanShift) { - pitch = (((bufLen << 0xf) / 2) - 1) / ((bufLen + panShift - prevPanShift - 2) / 2); - aSetBuffer(cmd++, 0, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, (bufLen + panShift) - prevPanShift); - aResampleZoh(cmd++, pitch, 0); - } else { - aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, bufLen); - } - - if (prevPanShift != 0) { - aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panSamplesBuffer), - DMEM_ADDR_NOTE_PAN_TEMP, ALIGN(prevPanShift, 4)); - aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP + prevPanShift, bufLen + panShift - prevPanShift); - } else { - aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP, bufLen + panShift); - } -#else if (prevPanShift == 0) { // Kind of a hack that moves the first samples into the resample state aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, 8); @@ -2026,7 +1359,7 @@ u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 aSetBuffer(cmd++, 0, 0, DMEM_ADDR_TEMP, 32); aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panResampleState)); -#if defined(VERSION_EU) +#ifdef VERSION_EU pitch = (bufLen << 0xf) / (bufLen + panShift - prevPanShift + 8); if (pitch) { } @@ -2057,58 +1390,48 @@ u64 *note_apply_headset_pan_effects(u64 *cmd, struct Note *note, s32 bufLen, s32 } else { aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP, panShift + bufLen - prevPanShift); } -#endif } else { // Just shift right aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, bufLen); -#ifdef VERSION_SH - aClearBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, panShift); - aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP + panShift, bufLen); -#else aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP + panShift, bufLen); aClearBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, panShift); -#endif } if (panShift) { // Save excessive samples for next iteration -#ifdef VERSION_SH - aSaveBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP + bufLen, - VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panSamplesBuffer), ALIGN(panShift, 4)); -#else aSetBuffer(cmd++, 0, 0, DMEM_ADDR_NOTE_PAN_TEMP + bufLen, panShift); aSaveBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panSamplesBuffer)); -#endif } -#ifdef VERSION_SH - aAddMixer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, dest, (bufLen + 0x3f) & 0xffc0); -#else aSetBuffer(cmd++, 0, 0, 0, bufLen); aMix(cmd++, 0, /*gain*/ 0x7fff, /*in*/ DMEM_ADDR_NOTE_PAN_TEMP, /*out*/ dest); -#endif return cmd; } -#if defined(VERSION_JP) || defined(VERSION_US) +#ifndef VERSION_EU // Moved to playback.c in EU void note_init_volume(struct Note *note) { note->targetVolLeft = 0; note->targetVolRight = 0; - note->reverb = 0; note->reverbVol = 0; + note->reverbVolShifted = 0; note->unused2 = 0; note->curVolLeft = 1; note->curVolRight = 1; note->frequency = 0.0f; } -void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb) { +void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverbVol) { s32 panIndex; f32 volLeft; f32 volRight; + // Anding with 127 avoids out-of-bounds reads when pan is outside of [0, 1]. + // This can occur during PU movement -- see the bug comment in get_sound_pan + // in external.c. An out-of-bounds read by itself doesn't crash, but if the + // resulting value is a nan or denormal, performing arithmetic on it crashes + // on console. #ifdef VERSION_JP panIndex = MIN((s32)(pan * 127.5), 127); #else @@ -2170,9 +1493,9 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb if (note->targetVolRight == 0) { note->targetVolRight++; } - if (note->reverb != reverb) { - note->reverb = reverb; - note->reverbVol = reverb << 8; + if (note->reverbVol != reverbVol) { + note->reverbVol = reverbVol; + note->reverbVolShifted = reverbVol << 8; note->envMixerNeedsInit = TRUE; return; } @@ -2215,3 +1538,4 @@ void note_disable(struct Note *note) { note->prevParentLayer = NO_LAYER; } #endif +#endif diff --git a/src/audio/synthesis.h b/src/audio/synthesis.h index 244fc4a8..b6465ac2 100644 --- a/src/audio/synthesis.h +++ b/src/audio/synthesis.h @@ -17,8 +17,7 @@ #define MAX_UPDATES_PER_FRAME 4 #endif -struct ReverbRingBufferItem -{ +struct ReverbRingBufferItem { s16 numSamplesAfterDownsampling; s16 chunkLen; // never read s16 *toDownsampleLeft; @@ -28,8 +27,7 @@ struct ReverbRingBufferItem s16 lengthB; // second length in ring buffer (from pos 0) }; // size = 0x14 -struct SynthesisReverb -{ +struct SynthesisReverb { /*0x00, 0x00, 0x00*/ u8 resampleFlags; /*0x01, 0x01, 0x01*/ u8 useReverb; /*0x02, 0x02, 0x02*/ u8 framesLeftToIgnore; @@ -53,8 +51,7 @@ struct SynthesisReverb /*0x08, 0x0C, 0x14*/ s32 nextRingBufferPos; /*0x0C, 0x10, 0x18*/ s32 unkC; // never read /*0x10, 0x14, 0x1C*/ s32 bufSizePerChannel; - struct - { + struct { s16 *left; s16 *right; } ringBuffer; @@ -90,7 +87,7 @@ extern s16 D_SH_803479B4; u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen); #if defined(VERSION_JP) || defined(VERSION_US) void note_init_volume(struct Note *note); -void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb); +void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverbVol); void note_set_frequency(struct Note *note, f32 frequency); void note_enable(struct Note *note); void note_disable(struct Note *note); diff --git a/src/audio/synthesis_sh.c b/src/audio/synthesis_sh.c new file mode 100644 index 00000000..d27df362 --- /dev/null +++ b/src/audio/synthesis_sh.c @@ -0,0 +1,910 @@ +#ifdef VERSION_SH +#include + +#include "synthesis.h" +#include "heap.h" +#include "data.h" +#include "load.h" +#include "seqplayer.h" +#include "internal.h" +#include "external.h" + + +#define DMEM_ADDR_TEMP 0x450 +#define DMEM_ADDR_RESAMPLED 0x470 +#define DMEM_ADDR_RESAMPLED2 0x5f0 +#define DMEM_ADDR_UNCOMPRESSED_NOTE 0x5f0 +#define DMEM_ADDR_NOTE_PAN_TEMP 0x650 +#define DMEM_ADDR_COMPRESSED_ADPCM_DATA 0x990 +#define DMEM_ADDR_LEFT_CH 0x990 +#define DMEM_ADDR_RIGHT_CH 0xb10 +#define DMEM_ADDR_WET_LEFT_CH 0xc90 +#define DMEM_ADDR_WET_RIGHT_CH 0xe10 + +#define aSetLoadBufferPair(pkt, c, off) \ + aSetBuffer(pkt, 0, c + DMEM_ADDR_WET_LEFT_CH, 0, DEFAULT_LEN_1CH - c); \ + aLoadBuffer(pkt, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.ringBuffer.left + (off))); \ + aSetBuffer(pkt, 0, c + DMEM_ADDR_WET_RIGHT_CH, 0, DEFAULT_LEN_1CH - c); \ + aLoadBuffer(pkt, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.ringBuffer.right + (off))) + +#define aSetSaveBufferPair(pkt, c, d, off) \ + aSetBuffer(pkt, 0, 0, c + DMEM_ADDR_WET_LEFT_CH, d); \ + aSaveBuffer(pkt, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.ringBuffer.left + (off))); \ + aSetBuffer(pkt, 0, 0, c + DMEM_ADDR_WET_RIGHT_CH, d); \ + aSaveBuffer(pkt, VIRTUAL_TO_PHYSICAL2(gSynthesisReverb.ringBuffer.right + (off))); + +#define ALIGN(val, amnt) (((val) + (1 << amnt) - 1) & ~((1 << amnt) - 1)) + +struct VolumeChange { + u16 sourceLeft; + u16 sourceRight; + u16 targetLeft; + u16 targetRight; +}; + +u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex); +u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex); +u64 *load_wave_samples(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad); +u64 *final_resample(u64 *cmd, struct NoteSynthesisState *synthesisState, s32 count, u16 pitch, u16 dmemIn, u32 flags); +u64 *process_envelope(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, u32 flags); +u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight); + +struct SynthesisReverb gSynthesisReverbs[4]; +u8 sAudioSynthesisPad[0x10]; + +s16 gVolume; +s8 gUseReverb; +s8 gNumSynthesisReverbs; +s16 D_SH_803479B4; // contains 4096 +struct NoteSubEu *gNoteSubsEu; + +// Equivalent functionality as the US/JP version, +// just that the reverb structure is chosen from an array with index +// Identical in EU. +void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex) { + struct ReverbRingBufferItem *item; + struct SynthesisReverb *reverb = &gSynthesisReverbs[reverbIndex]; + s32 srcPos; + s32 dstPos; + s32 nSamples; + s32 excessiveSamples; + s32 UNUSED pad[3]; + if (reverb->downsampleRate != 1) { + if (reverb->framesLeftToIgnore == 0) { + // Now that the RSP has finished, downsample the samples produced two frames ago by skipping + // samples. + item = &reverb->items[reverb->curFrame][updateIndex]; + + // Touches both left and right since they are adjacent in memory + osInvalDCache(item->toDownsampleLeft, DEFAULT_LEN_2CH); + + for (srcPos = 0, dstPos = 0; dstPos < item->lengthA / 2; + srcPos += reverb->downsampleRate, dstPos++) { + reverb->ringBuffer.left[item->startPos + dstPos] = + item->toDownsampleLeft[srcPos]; + reverb->ringBuffer.right[item->startPos + dstPos] = + item->toDownsampleRight[srcPos]; + } + for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += reverb->downsampleRate, dstPos++) { + reverb->ringBuffer.left[dstPos] = item->toDownsampleLeft[srcPos]; + reverb->ringBuffer.right[dstPos] = item->toDownsampleRight[srcPos]; + } + } + } + + item = &reverb->items[reverb->curFrame][updateIndex]; + nSamples = chunkLen / reverb->downsampleRate; + excessiveSamples = (nSamples + reverb->nextRingBufferPos) - reverb->bufSizePerChannel; + if (excessiveSamples < 0) { + // There is space in the ring buffer before it wraps around + item->lengthA = nSamples * 2; + item->lengthB = 0; + item->startPos = (s32) reverb->nextRingBufferPos; + reverb->nextRingBufferPos += nSamples; + } else { + // Ring buffer wrapped around + item->lengthA = (nSamples - excessiveSamples) * 2; + item->lengthB = excessiveSamples * 2; + item->startPos = reverb->nextRingBufferPos; + reverb->nextRingBufferPos = excessiveSamples; + } + // These fields are never read later + item->numSamplesAfterDownsampling = nSamples; + item->chunkLen = chunkLen; +} + +u64 *synthesis_load_reverb_ring_buffer(u64 *cmd, u16 addr, u16 srcOffset, s32 len, s32 reverbIndex) { + aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[srcOffset]), + addr, len); + aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[srcOffset]), + addr + DEFAULT_LEN_1CH, len); + return cmd; +} + +u64 *synthesis_save_reverb_ring_buffer(u64 *cmd, u16 addr, u16 destOffset, s32 len, s32 reverbIndex) { + aSaveBuffer(cmd++, addr, + VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.left[destOffset]), len); + aSaveBuffer(cmd++, addr + DEFAULT_LEN_1CH, + VIRTUAL_TO_PHYSICAL2(&gSynthesisReverbs[reverbIndex].ringBuffer.right[destOffset]), len); + return cmd; +} + +void func_sh_802ed644(s32 updateIndexStart, s32 noteIndex) { + s32 i; + + for (i = updateIndexStart + 1; i < gAudioBufferParameters.updatesPerFrame; i++) { + if (!gNoteSubsEu[gMaxSimultaneousNotes * i + noteIndex].needsInit) { + gNoteSubsEu[gMaxSimultaneousNotes * i + noteIndex].enabled = FALSE; + } else { + break; + } + } +} + +void synthesis_load_note_subs_eu(s32 updateIndex) { + struct NoteSubEu *src; + struct NoteSubEu *dest; + s32 i; + + for (i = 0; i < gMaxSimultaneousNotes; i++) { + src = &gNotes[i].noteSubEu; + dest = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i]; + if (src->enabled) { + *dest = *src; + src->needsInit = FALSE; + } else { + dest->enabled = FALSE; + } + } +} + +// TODO: (Scrub C) pointless mask and whitespace +u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) { + s32 i, j; + u32 *aiBufPtr; + u64 *cmd = cmdBuf; + s32 chunkLen; + + for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--) { + process_sequences(i - 1); + synthesis_load_note_subs_eu(gAudioBufferParameters.updatesPerFrame - i); + } + aiBufPtr = (u32 *) aiBuf; + for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--) { + if (i == 1) { + chunkLen = bufLen; + } else { + if (bufLen / i >= gAudioBufferParameters.samplesPerUpdateMax) { + chunkLen = gAudioBufferParameters.samplesPerUpdateMax; + } else if (bufLen / i <= gAudioBufferParameters.samplesPerUpdateMin) { + chunkLen = gAudioBufferParameters.samplesPerUpdateMin; + } else { + chunkLen = gAudioBufferParameters.samplesPerUpdate; + } + } + for (j = 0; j < gNumSynthesisReverbs; j++) { + if (gSynthesisReverbs[j].useReverb != 0) { + prepare_reverb_ring_buffer(chunkLen, gAudioBufferParameters.updatesPerFrame - i, j); + } + } + cmd = synthesis_do_one_audio_update((s16 *) aiBufPtr, chunkLen, cmd, gAudioBufferParameters.updatesPerFrame - i); + bufLen -= chunkLen; + aiBufPtr += chunkLen; + } + + for (j = 0; j < gNumSynthesisReverbs; j++) { + if (gSynthesisReverbs[j].framesLeftToIgnore != 0) { + gSynthesisReverbs[j].framesLeftToIgnore--; + } + gSynthesisReverbs[j].curFrame ^= 1; + } + *writtenCmds = cmd - cmdBuf; + return cmd; +} + +u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s16 updateIndex) { + struct ReverbRingBufferItem *item; + s16 startPad; + s16 paddedLengthA; + + item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex]; + + if (gSynthesisReverbs[reverbIndex].downsampleRate == 1) { + cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH, item->startPos, item->lengthA, reverbIndex); + if (item->lengthB != 0) { + cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH + item->lengthA, 0, item->lengthB, reverbIndex); + } + aAddMixer(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH); + aMix(cmd++, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH); + } else { + startPad = (item->startPos % 8u) * 2; + paddedLengthA = ALIGN(startPad + item->lengthA, 4); + + cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED, (item->startPos - startPad / 2), DEFAULT_LEN_1CH, reverbIndex); + if (item->lengthB != 0) { + cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED + paddedLengthA, 0, DEFAULT_LEN_1CH - paddedLengthA, reverbIndex); + } + + aSetBuffer(cmd++, 0, DMEM_ADDR_RESAMPLED + startPad, DMEM_ADDR_WET_LEFT_CH, bufLen * 2); + aResample(cmd++, gSynthesisReverbs[reverbIndex].resampleFlags, gSynthesisReverbs[reverbIndex].resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].resampleStateLeft)); + + aSetBuffer(cmd++, 0, DMEM_ADDR_RESAMPLED2 + startPad, DMEM_ADDR_WET_RIGHT_CH, bufLen * 2); + aResample(cmd++, gSynthesisReverbs[reverbIndex].resampleFlags, gSynthesisReverbs[reverbIndex].resampleRate, VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].resampleStateRight)); + + aAddMixer(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH); + aMix(cmd++, 0x8000 + gSynthesisReverbs[reverbIndex].reverbGain, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_2CH); + } + if (gSynthesisReverbs[reverbIndex].panRight != 0 || gSynthesisReverbs[reverbIndex].panLeft != 0) { + // Leak some audio from the left reverb channel into the right reverb channel and vice versa (pan) + aDMEMMove(cmd++, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_RESAMPLED, DEFAULT_LEN_1CH); + aMix(cmd++, gSynthesisReverbs[reverbIndex].panRight, DMEM_ADDR_WET_RIGHT_CH, DMEM_ADDR_WET_LEFT_CH, DEFAULT_LEN_1CH); + aMix(cmd++, gSynthesisReverbs[reverbIndex].panLeft, DMEM_ADDR_RESAMPLED, DMEM_ADDR_WET_RIGHT_CH, DEFAULT_LEN_1CH); + } + return cmd; +} + +u64 *synthesis_load_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) { + struct ReverbRingBufferItem *item; + struct SynthesisReverb *reverb; + + reverb = &gSynthesisReverbs[reverbIndex]; + item = &reverb->items[reverb->curFrame][updateIndex]; + // Get the oldest samples in the ring buffer into the wet channels + cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED, item->startPos, item->lengthA, reverbIndex); + if (item->lengthB != 0) { + // Ring buffer wrapped + cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED + item->lengthA, 0, item->lengthB, reverbIndex); + } + return cmd; +} + +u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) { + struct ReverbRingBufferItem *item; + + item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex]; + switch (gSynthesisReverbs[reverbIndex].downsampleRate) { + case 1: + // Put the oldest samples in the ring buffer into the wet channels + cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH, item->startPos, item->lengthA, reverbIndex); + if (item->lengthB != 0) { + // Ring buffer wrapped + cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_WET_LEFT_CH + item->lengthA, 0, item->lengthB, reverbIndex); + } + break; + + default: + // Downsampling is done later by CPU when RSP is done, therefore we need to have double + // buffering. Left and right buffers are adjacent in memory. + aSaveBuffer(cmd++, DMEM_ADDR_WET_LEFT_CH, + VIRTUAL_TO_PHYSICAL2(gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex].toDownsampleLeft), DEFAULT_LEN_2CH); + break; + } + gSynthesisReverbs[reverbIndex].resampleFlags = 0; + return cmd; +} + +u64 *func_sh_802EDF24(u64 *cmd, s16 reverbIndex, s16 updateIndex) { + struct ReverbRingBufferItem *item; + struct SynthesisReverb *reverb; + + reverb = &gSynthesisReverbs[reverbIndex]; + item = &reverb->items[reverb->curFrame][updateIndex]; + // Put the oldest samples in the ring buffer into the wet channels + cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED, item->startPos, item->lengthA, reverbIndex); + if (item->lengthB != 0) { + // Ring buffer wrapped + cmd = synthesis_save_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED + item->lengthA, 0, item->lengthB, reverbIndex); + } + return cmd; +} + +u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) { + struct NoteSubEu *noteSubEu; + u8 noteIndices[56]; + s32 temp; + s32 i; + s16 j; + s16 notePos = 0; + + if (gNumSynthesisReverbs == 0) { + for (i = 0; i < gMaxSimultaneousNotes; i++) { + if (gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i].enabled) { + noteIndices[notePos++] = i; + } + } + } else { + for (j = 0; j < gNumSynthesisReverbs; j++) { + for (i = 0; i < gMaxSimultaneousNotes; i++) { + noteSubEu = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i]; + if (noteSubEu->enabled && j == noteSubEu->reverbIndex) { + noteIndices[notePos++] = i; + } + } + } + + for (i = 0; i < gMaxSimultaneousNotes; i++) { + noteSubEu = &gNoteSubsEu[gMaxSimultaneousNotes * updateIndex + i]; + if (noteSubEu->enabled && noteSubEu->reverbIndex >= gNumSynthesisReverbs) { + noteIndices[notePos++] = i; + } + } + } + aClearBuffer(cmd++, DMEM_ADDR_LEFT_CH, DEFAULT_LEN_2CH); + i = 0; + for (j = 0; j < gNumSynthesisReverbs; j++) { + gUseReverb = gSynthesisReverbs[j].useReverb; + if (gUseReverb != 0) { + cmd = synthesis_resample_and_mix_reverb(cmd, bufLen, j, updateIndex); + } + for (; i < notePos; i++) { + temp = updateIndex * gMaxSimultaneousNotes; + if (j == gNoteSubsEu[temp + noteIndices[i]].reverbIndex) { + cmd = synthesis_process_note(noteIndices[i], + &gNoteSubsEu[temp + noteIndices[i]], + &gNotes[noteIndices[i]].synthesisState, + aiBuf, bufLen, cmd, updateIndex); + continue; + } else { + break; + } + } + if (gSynthesisReverbs[j].useReverb != 0) { + if (gSynthesisReverbs[j].unk100 != NULL) { + aFilter(cmd++, 0x02, bufLen * 2, gSynthesisReverbs[j].unk100); + aFilter(cmd++, gSynthesisReverbs[j].resampleFlags, DMEM_ADDR_WET_LEFT_CH, gSynthesisReverbs[j].unk108); + } + if (gSynthesisReverbs[j].unk104 != NULL) { + aFilter(cmd++, 0x02, bufLen * 2, gSynthesisReverbs[j].unk104); + aFilter(cmd++, gSynthesisReverbs[j].resampleFlags, DMEM_ADDR_WET_RIGHT_CH, gSynthesisReverbs[j].unk10C); + } + cmd = synthesis_save_reverb_samples(cmd, j, updateIndex); + if (gSynthesisReverbs[j].unk5 != -1) { + if (gSynthesisReverbs[gSynthesisReverbs[j].unk5].downsampleRate == 1) { + cmd = synthesis_load_reverb_samples(cmd, gSynthesisReverbs[j].unk5, updateIndex); + aMix(cmd++, gSynthesisReverbs[j].unk08, DMEM_ADDR_WET_LEFT_CH, DMEM_ADDR_RESAMPLED, DEFAULT_LEN_2CH); + cmd = func_sh_802EDF24(cmd++, gSynthesisReverbs[j].unk5, updateIndex); + } + } + } + } + for (; i < notePos; i++) { + struct NoteSubEu *noteSubEu2 = &gNoteSubsEu[updateIndex * gMaxSimultaneousNotes + noteIndices[i]]; + cmd = synthesis_process_note(noteIndices[i], + noteSubEu2, + &gNotes[noteIndices[i]].synthesisState, + aiBuf, bufLen, cmd, updateIndex); + } + + temp = bufLen * 2; + aInterleave(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_LEFT_CH, DMEM_ADDR_RIGHT_CH, temp); + aSaveBuffer(cmd++, DMEM_ADDR_TEMP, VIRTUAL_TO_PHYSICAL2(aiBuf), temp * 2); + return cmd; +} + +u64 *synthesis_process_note(s32 noteIndex, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, UNUSED s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateIndex) { + UNUSED s32 pad0[3]; + struct AudioBankSample *audioBookSample; // sp164, sp138 + struct AdpcmLoop *loopInfo; // sp160, sp134 + s16 *curLoadedBook; // sp154, sp130 + UNUSED u8 padEU[0x04]; + UNUSED u8 pad8[0x04]; + s32 noteFinished; // 150 t2, sp124 + s32 restart; // 14c t3, sp120 + s32 flags; // sp148, sp11C, t8 + u16 resamplingRateFixedPoint; // sp5c, sp11A + s32 nSamplesToLoad; //s0, Ec + UNUSED u8 pad7[0x0c]; // sp100 + s32 sp130; //sp128, sp104 + UNUSED s32 tempBufLen; + UNUSED u32 pad9; + s32 t0; + u8 *sampleAddr; // sp120, spF4 + s32 s6; + s32 samplesLenAdjusted; // 108, spEC + s32 nAdpcmSamplesProcessed; // signed required for US // spc0 + s32 endPos; // sp110, spE4 + s32 nSamplesToProcess; // sp10c/a0, spE0 + // Might have been used to store (samplesLenFixedPoint >> 0x10), but doing so causes strange + // behavior with the break near the end of the loop, causing US and JP to need a goto instead + UNUSED s32 samplesLenInt; + s32 s2; + s32 leftRight; //s0 + s32 s5; //s4 + u32 samplesLenFixedPoint; // v1_1 + s32 s3; // spA0 + s32 nSamplesInThisIteration; // v1_2 + u32 a3; + u8 *v0_2; + s32 unk_s6; // sp90 + s32 s5Aligned; + s32 sp88; + s32 sp84; + u32 temp; + s32 nParts; // spE8, spBC + s32 curPart; // spE4, spB8 + s32 aligned; + UNUSED u32 padSH1; + s32 resampledTempLen; // spD8, spAC, sp6c + u16 noteSamplesDmemAddrBeforeResampling; // spD6, spAA, sp6a -- 6C + UNUSED u32 padSH2; + UNUSED u32 padSH3; + UNUSED u32 padSH4; + struct Note *note; // sp58 + u16 sp56; // sp56 + u16 addr; + u8 synthesisVolume; + + curLoadedBook = NULL; + note = &gNotes[noteIndex]; + flags = 0; + if (noteSubEu->needsInit == TRUE) { + flags = A_INIT; + synthesisState->restart = 0; + synthesisState->samplePosInt = 0; + synthesisState->samplePosFrac = 0; + synthesisState->curVolLeft = 0; + synthesisState->curVolRight = 0; + synthesisState->prevHeadsetPanRight = 0; + synthesisState->prevHeadsetPanLeft = 0; + synthesisState->reverbVol = noteSubEu->reverbVol; + synthesisState->unk5 = 0; + note->noteSubEu.finished = 0; + } + + resamplingRateFixedPoint = noteSubEu->resamplingRateFixedPoint; + nParts = noteSubEu->hasTwoAdpcmParts + 1; + samplesLenFixedPoint = (resamplingRateFixedPoint * bufLen * 2) + synthesisState->samplePosFrac; + nSamplesToLoad = (samplesLenFixedPoint >> 0x10); + synthesisState->samplePosFrac = samplesLenFixedPoint & 0xFFFF; + + if ((synthesisState->unk5 == 1) && (nParts == 2)) { + nSamplesToLoad += 2; + sp56 = 2; + } else if ((synthesisState->unk5 == 2) && (nParts == 1)) { + nSamplesToLoad -= 4; + sp56 = 4; + } else { + sp56 = 0; + } + + + synthesisState->unk5 = nParts; + + if (noteSubEu->isSyntheticWave) { + cmd = load_wave_samples(cmd, noteSubEu, synthesisState, nSamplesToLoad); + noteSamplesDmemAddrBeforeResampling = (synthesisState->samplePosInt * 2) + DMEM_ADDR_UNCOMPRESSED_NOTE; + synthesisState->samplePosInt += nSamplesToLoad; + } else { + // ADPCM note + audioBookSample = noteSubEu->sound.audioBankSound->sample; + loopInfo = audioBookSample->loop; + endPos = loopInfo->end; + sampleAddr = audioBookSample->sampleAddr; + resampledTempLen = 0; + for (curPart = 0; curPart < nParts; curPart++) { + nAdpcmSamplesProcessed = 0; // s8 + s5 = 0; // s4 + + if (nParts == 1) { + samplesLenAdjusted = nSamplesToLoad; + } else if (nSamplesToLoad & 1) { + samplesLenAdjusted = (nSamplesToLoad & ~1) + (curPart * 2); + } else { + samplesLenAdjusted = nSamplesToLoad; + } + + if (audioBookSample->codec == CODEC_ADPCM) { + if (curLoadedBook != (*audioBookSample->book).book) { + u32 nEntries; + switch (noteSubEu->bookOffset) { + case 1: + curLoadedBook = euUnknownData_80301950 + 1; + break; + case 2: + curLoadedBook = euUnknownData_80301950 + 2; + break; + case 3: + default: + curLoadedBook = audioBookSample->book->book; + break; + } + nEntries = 16 * audioBookSample->book->order * audioBookSample->book->npredictors; + aLoadADPCM(cmd++, nEntries, VIRTUAL_TO_PHYSICAL2(curLoadedBook)); + } + } + + while (nAdpcmSamplesProcessed != samplesLenAdjusted) { + s32 samplesRemaining; // v1 + s32 s0; + + noteFinished = FALSE; + restart = FALSE; + s2 = synthesisState->samplePosInt & 0xf; + samplesRemaining = endPos - synthesisState->samplePosInt; + nSamplesToProcess = samplesLenAdjusted - nAdpcmSamplesProcessed; + + if (s2 == 0 && synthesisState->restart == FALSE) { + s2 = 16; + } + s6 = 16 - s2; // a1 + if (nSamplesToProcess < samplesRemaining) { + t0 = (nSamplesToProcess - s6 + 0xf) / 16; + s0 = t0 * 16; + s3 = s6 + s0 - nSamplesToProcess; + } else { + s0 = samplesRemaining - s6; + s3 = 0; + if (s0 <= 0) { + s0 = 0; + s6 = samplesRemaining; + } + t0 = (s0 + 0xf) / 16; + if (loopInfo->count != 0) { + // Loop around and restart + restart = 1; + } else { + noteFinished = 1; + } + } + switch (audioBookSample->codec) { + case CODEC_ADPCM: + unk_s6 = 9; + sp88 = 0x10; + sp84 = 0; + break; + case CODEC_S8: + unk_s6 = 0x10; + sp88 = 0x10; + sp84 = 0; + break; + case CODEC_SKIP: goto skip; + } + if (t0 != 0) { + temp = (synthesisState->samplePosInt + sp88 - s2) / 16; + if (audioBookSample->medium == 0) { + v0_2 = sp84 + (temp * unk_s6) + sampleAddr; + } else { + v0_2 = dma_sample_data((uintptr_t)(sp84 + (temp * unk_s6) + sampleAddr), + ALIGN(t0 * unk_s6 + 16, 4), flags, &synthesisState->sampleDmaIndex, audioBookSample->medium); + } + + a3 = ((uintptr_t)v0_2 & 0xf); + aligned = ALIGN(t0 * unk_s6 + 16, 4); + addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff; + aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(v0_2 - a3), addr, ALIGN(t0 * unk_s6 + 16, 4)); + } else { + s0 = 0; + a3 = 0; + } + if (synthesisState->restart != FALSE) { + aSetLoop(cmd++, VIRTUAL_TO_PHYSICAL2(audioBookSample->loop->state)); + flags = A_LOOP; // = 2 + synthesisState->restart = FALSE; + } + nSamplesInThisIteration = s0 + s6 - s3; + if (nAdpcmSamplesProcessed == 0) { + switch (audioBookSample->codec) { + case CODEC_ADPCM: + aligned = ALIGN(t0 * unk_s6 + 16, 4); + addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff; + aSetBuffer(cmd++, 0, addr + a3, DMEM_ADDR_UNCOMPRESSED_NOTE, s0 * 2); + aADPCMdec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState)); + break; + case CODEC_S8: + aligned = ALIGN(t0 * unk_s6 + 16, 4); + addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff; + aSetBuffer(cmd++, 0, addr + a3, DMEM_ADDR_UNCOMPRESSED_NOTE, s0 * 2); + aS8Dec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState)); + break; + } + sp130 = s2 * 2; + } else { + s5Aligned = ALIGN(s5 + 16, 4); + switch (audioBookSample->codec) { + case CODEC_ADPCM: + aligned = ALIGN(t0 * unk_s6 + 16, 4); + addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff; + aSetBuffer(cmd++, 0, addr + a3, DMEM_ADDR_UNCOMPRESSED_NOTE + s5Aligned, s0 * 2); + aADPCMdec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState)); + break; + case CODEC_S8: + aligned = ALIGN(t0 * unk_s6 + 16, 4); + addr = (DMEM_ADDR_COMPRESSED_ADPCM_DATA - aligned) & 0xffff; + aSetBuffer(cmd++, 0, addr + a3, DMEM_ADDR_UNCOMPRESSED_NOTE + s5Aligned, s0 * 2); + aS8Dec(cmd++, flags, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->adpcmdecState)); + break; + } + aDMEMMove(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5Aligned + (s2 * 2), DMEM_ADDR_UNCOMPRESSED_NOTE + s5, (nSamplesInThisIteration) * 2); + } + nAdpcmSamplesProcessed += nSamplesInThisIteration; + switch (flags) { + case A_INIT: // = 1 + sp130 = 0x20; + s5 = (s0 + 0x10) * 2; + break; + case A_LOOP: // = 2 + s5 = (nSamplesInThisIteration) * 2 + s5; + break; + default: + if (s5 != 0) { + s5 = (nSamplesInThisIteration) * 2 + s5; + } else { + s5 = (s2 + (nSamplesInThisIteration)) * 2; + } + break; + } + flags = 0; +skip: + if (noteFinished) { + aClearBuffer(cmd++, DMEM_ADDR_UNCOMPRESSED_NOTE + s5, + (samplesLenAdjusted - nAdpcmSamplesProcessed) * 2); + noteSubEu->finished = 1; + note->noteSubEu.finished = 1; + func_sh_802ed644(updateIndex, noteIndex); + break; + } + if (restart != 0) { + synthesisState->restart = TRUE; + synthesisState->samplePosInt = loopInfo->start; + } else { + synthesisState->samplePosInt += nSamplesToProcess; + } + } + + switch (nParts) { + case 1: + noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_UNCOMPRESSED_NOTE + sp130; + break; + case 2: + switch (curPart) { + case 0: + aDownsampleHalf(cmd++, ALIGN(samplesLenAdjusted / 2, 3), DMEM_ADDR_UNCOMPRESSED_NOTE + sp130, DMEM_ADDR_RESAMPLED); + resampledTempLen = samplesLenAdjusted; + noteSamplesDmemAddrBeforeResampling = DMEM_ADDR_RESAMPLED; + if (noteSubEu->finished != FALSE) { + aClearBuffer(cmd++, noteSamplesDmemAddrBeforeResampling + resampledTempLen, samplesLenAdjusted + 0x10); + } + break; + case 1: + aDownsampleHalf(cmd++, ALIGN(samplesLenAdjusted / 2, 3), DMEM_ADDR_UNCOMPRESSED_NOTE + sp130, resampledTempLen + DMEM_ADDR_RESAMPLED); + break; + } + } + if (noteSubEu->finished != FALSE) { + break; + } + } + } + flags = 0; + if (noteSubEu->needsInit == TRUE) { + flags = A_INIT; + noteSubEu->needsInit = FALSE; + } + flags = flags | sp56; + cmd = final_resample(cmd, synthesisState, bufLen * 2, resamplingRateFixedPoint, + noteSamplesDmemAddrBeforeResampling, flags); + if ((flags & 1) != 0) { + flags = 1; + } + + if (noteSubEu->filter) { + aFilter(cmd++, 0x02, bufLen * 2, noteSubEu->filter); + aFilter(cmd++, flags, DMEM_ADDR_TEMP, synthesisState->synthesisBuffers->filterBuffer); + + } + + if (noteSubEu->bookOffset == 3) { + aUnknown25(cmd++, 0, bufLen * 2, DMEM_ADDR_TEMP, DMEM_ADDR_TEMP); + } + + synthesisVolume = noteSubEu->synthesisVolume; + if (synthesisVolume != 0) { + if (synthesisVolume < 0x10) { + synthesisVolume = 0x10; + } + + aHiLoGain(cmd++, synthesisVolume, (bufLen + 0x10) * 2, DMEM_ADDR_TEMP); + } + + if (noteSubEu->headsetPanRight != 0 || synthesisState->prevHeadsetPanRight != 0) { + leftRight = 1; + } else if (noteSubEu->headsetPanLeft != 0 || synthesisState->prevHeadsetPanLeft != 0) { + leftRight = 2; + } else { + leftRight = 0; + } + cmd = process_envelope(cmd, noteSubEu, synthesisState, bufLen, DMEM_ADDR_TEMP, leftRight, flags); + if (noteSubEu->usesHeadsetPanEffects) { + if ((flags & 1) == 0) { + flags = 0; + } + cmd = note_apply_headset_pan_effects(cmd, noteSubEu, synthesisState, bufLen * 2, flags, leftRight); + } + + return cmd; +} + +u64 *load_wave_samples(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *synthesisState, s32 nSamplesToLoad) { + s32 a3; + s32 repeats; + aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(noteSubEu->sound.samples), + DMEM_ADDR_UNCOMPRESSED_NOTE, 128); + + synthesisState->samplePosInt &= 0x3f; + a3 = 64 - synthesisState->samplePosInt; + if (a3 < nSamplesToLoad) { + repeats = (nSamplesToLoad - a3 + 63) / 64; + if (repeats != 0) { + aDuplicate(cmd++, + /*dmemin*/ DMEM_ADDR_UNCOMPRESSED_NOTE, + /*dmemout*/ DMEM_ADDR_UNCOMPRESSED_NOTE + 128, + /*copies*/ repeats); + } + } + return cmd; +} + +u64 *final_resample(u64 *cmd, struct NoteSynthesisState *synthesisState, s32 count, u16 pitch, u16 dmemIn, u32 flags) { + if (pitch == 0) { + aClearBuffer(cmd++, DMEM_ADDR_TEMP, count); + } else { + aSetBuffer(cmd++, /*flags*/ 0, dmemIn, /*dmemout*/ DMEM_ADDR_TEMP, count); + aResample(cmd++, flags, pitch, VIRTUAL_TO_PHYSICAL2(synthesisState->synthesisBuffers->finalResampleState)); + } + return cmd; +} + +u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisState *synthesisState, s32 nSamples, u16 inBuf, s32 headsetPanSettings, UNUSED u32 flags) { + u16 sourceRight; + u16 sourceLeft; + u16 targetLeft; + u16 targetRight; + s16 rampLeft; + s16 rampRight; + s32 sourceReverbVol; + s16 rampReverb; + s32 reverbVolDiff = 0; + + sourceLeft = synthesisState->curVolLeft; + sourceRight = synthesisState->curVolRight; + targetLeft = note->targetVolLeft; + targetRight = note->targetVolRight; + targetLeft <<= 4; + targetRight <<= 4; + + if (targetLeft != sourceLeft) { + rampLeft = (targetLeft - sourceLeft) / (nSamples >> 3); + } else { + rampLeft = 0; + } + if (targetRight != sourceRight) { + rampRight = (targetRight - sourceRight) / (nSamples >> 3); + } else { + rampRight = 0; + } + + sourceReverbVol = synthesisState->reverbVol; + if (note->reverbVol != sourceReverbVol) { + reverbVolDiff = ((note->reverbVol & 0x7f) - (sourceReverbVol & 0x7f)) << 9; + rampReverb = reverbVolDiff / (nSamples >> 3); + synthesisState->reverbVol = note->reverbVol; + } else { + rampReverb = 0; + } + synthesisState->curVolLeft = sourceLeft + rampLeft * (nSamples >> 3); + synthesisState->curVolRight = sourceRight + rampRight * (nSamples >> 3); + + if (note->usesHeadsetPanEffects) { + aClearBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DEFAULT_LEN_1CH); + aEnvSetup1(cmd++, (sourceReverbVol & 0x7f) * 2, rampReverb, rampLeft, rampRight); + aEnvSetup2(cmd++, sourceLeft, sourceRight); + + switch (headsetPanSettings) { + case 1: + aEnvMixer(cmd++, + inBuf, nSamples, + (sourceReverbVol & 0x80) >> 7, + note->stereoStrongRight, note->stereoStrongLeft, + DMEM_ADDR_NOTE_PAN_TEMP, + DMEM_ADDR_RIGHT_CH, + DMEM_ADDR_WET_LEFT_CH, + DMEM_ADDR_WET_RIGHT_CH); + break; + case 2: + aEnvMixer(cmd++, + inBuf, nSamples, + (sourceReverbVol & 0x80) >> 7, + note->stereoStrongRight, note->stereoStrongLeft, + DMEM_ADDR_LEFT_CH, + DMEM_ADDR_NOTE_PAN_TEMP, + DMEM_ADDR_WET_LEFT_CH, + DMEM_ADDR_WET_RIGHT_CH); + break; + default: + aEnvMixer(cmd++, + inBuf, nSamples, + (sourceReverbVol & 0x80) >> 7, + note->stereoStrongRight, note->stereoStrongLeft, + DMEM_ADDR_LEFT_CH, + DMEM_ADDR_RIGHT_CH, + DMEM_ADDR_WET_LEFT_CH, + DMEM_ADDR_WET_RIGHT_CH); + break; + } + } else { + aEnvSetup1(cmd++, (sourceReverbVol & 0x7f) * 2, rampReverb, rampLeft, rampRight); + aEnvSetup2(cmd++, sourceLeft, sourceRight); + aEnvMixer(cmd++, + inBuf, nSamples, + (sourceReverbVol & 0x80) >> 7, + note->stereoStrongRight, note->stereoStrongLeft, + DMEM_ADDR_LEFT_CH, + DMEM_ADDR_RIGHT_CH, + DMEM_ADDR_WET_LEFT_CH, + DMEM_ADDR_WET_RIGHT_CH); + } + return cmd; +} + +u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struct NoteSynthesisState *note, s32 bufLen, s32 flags, s32 leftRight) { + u16 dest; + u16 pitch; + u8 prevPanShift; + u8 panShift; + UNUSED u8 unkDebug; + + switch (leftRight) { + case 1: + dest = DMEM_ADDR_LEFT_CH; + panShift = noteSubEu->headsetPanRight; + note->prevHeadsetPanLeft = 0; + prevPanShift = note->prevHeadsetPanRight; + note->prevHeadsetPanRight = panShift; + break; + case 2: + dest = DMEM_ADDR_RIGHT_CH; + panShift = noteSubEu->headsetPanLeft; + note->prevHeadsetPanRight = 0; + + prevPanShift = note->prevHeadsetPanLeft; + note->prevHeadsetPanLeft = panShift; + break; + default: + return cmd; + } + + if (flags != 1) { // A_INIT? + // Slightly adjust the sample rate in order to fit a change in pan shift + if (panShift != prevPanShift) { + pitch = (((bufLen << 0xf) / 2) - 1) / ((bufLen + panShift - prevPanShift - 2) / 2); + aSetBuffer(cmd++, 0, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, (bufLen + panShift) - prevPanShift); + aResampleZoh(cmd++, pitch, 0); + } else { + aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, bufLen); + } + + if (prevPanShift != 0) { + aLoadBuffer(cmd++, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panSamplesBuffer), + DMEM_ADDR_NOTE_PAN_TEMP, ALIGN(prevPanShift, 4)); + aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP + prevPanShift, bufLen + panShift - prevPanShift); + } else { + aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP, bufLen + panShift); + } + } else { + // Just shift right + aDMEMMove(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, DMEM_ADDR_TEMP, bufLen); + aClearBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, panShift); + aDMEMMove(cmd++, DMEM_ADDR_TEMP, DMEM_ADDR_NOTE_PAN_TEMP + panShift, bufLen); + } + + if (panShift) { + // Save excessive samples for next iteration + aSaveBuffer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP + bufLen, + VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panSamplesBuffer), ALIGN(panShift, 4)); + } + + aAddMixer(cmd++, DMEM_ADDR_NOTE_PAN_TEMP, dest, (bufLen + 0x3f) & 0xffc0); + + return cmd; +} +#endif diff --git a/src/buffers/buffers.c b/src/buffers/buffers.c index 72b031bc..0a7b6f7f 100644 --- a/src/buffers/buffers.c +++ b/src/buffers/buffers.c @@ -1,6 +1,7 @@ #include #include "buffers.h" +#include "config.h" ALIGNED8 u8 gDecompressionHeap[0xD000]; #if defined(VERSION_EU) @@ -15,7 +16,7 @@ ALIGNED8 u8 gIdleThreadStack[0x800]; ALIGNED8 u8 gThread3Stack[0x2000]; ALIGNED8 u8 gThread4Stack[0x2000]; ALIGNED8 u8 gThread5Stack[0x2000]; -#ifdef VERSION_SH +#if ENABLE_RUMBLE ALIGNED8 u8 gThread6Stack[0x2000]; #endif // 0x400 bytes @@ -39,8 +40,3 @@ ALIGNED8 u8 gAudioSPTaskYieldBuffer[OS_YIELD_AUDIO_SIZE]; #if !defined(F3DEX_GBI_SHARED) && !defined(VERSION_EU) ALIGNED8 u8 gUnusedThread2Stack[0x1400]; #endif - - - - - diff --git a/src/buffers/buffers.h b/src/buffers/buffers.h index b9abbf6b..92c97c93 100644 --- a/src/buffers/buffers.h +++ b/src/buffers/buffers.h @@ -5,6 +5,7 @@ #include "game/save_file.h" #include "game/game_init.h" +#include "config.h" extern u8 gDecompressionHeap[]; @@ -18,7 +19,7 @@ extern u8 gIdleThreadStack[]; extern u8 gThread3Stack[]; extern u8 gThread4Stack[]; extern u8 gThread5Stack[]; -#ifdef VERSION_SH +#if ENABLE_RUMBLE extern u8 gThread6Stack[]; #endif diff --git a/src/buffers/framebuffers.c b/src/buffers/framebuffers.c index bb3589d2..09a84782 100644 --- a/src/buffers/framebuffers.c +++ b/src/buffers/framebuffers.c @@ -4,9 +4,9 @@ // 0x70800 bytes #ifdef AVOID_UB -u16 gFrameBuffers[3][SCREEN_WIDTH * SCREEN_HEIGHT]; +u16 gFramebuffers[3][SCREEN_WIDTH * SCREEN_HEIGHT]; #else -u16 gFrameBuffer0[SCREEN_WIDTH * SCREEN_HEIGHT]; -u16 gFrameBuffer1[SCREEN_WIDTH * SCREEN_HEIGHT]; -u16 gFrameBuffer2[SCREEN_WIDTH * SCREEN_HEIGHT]; +u16 gFramebuffer0[SCREEN_WIDTH * SCREEN_HEIGHT]; +u16 gFramebuffer1[SCREEN_WIDTH * SCREEN_HEIGHT]; +u16 gFramebuffer2[SCREEN_WIDTH * SCREEN_HEIGHT]; #endif diff --git a/src/buffers/framebuffers.h b/src/buffers/framebuffers.h index d17f1fb7..70cee045 100644 --- a/src/buffers/framebuffers.h +++ b/src/buffers/framebuffers.h @@ -9,14 +9,14 @@ // -g codegen implies that they are separate variables. This is impossible to // reconcile without undefined behavior. Avoid that when possible. #ifdef AVOID_UB -extern u16 gFrameBuffers[3][SCREEN_WIDTH * SCREEN_HEIGHT]; -#define gFrameBuffer0 gFrameBuffers[0] -#define gFrameBuffer1 gFrameBuffers[1] -#define gFrameBuffer2 gFrameBuffers[2] +extern u16 gFramebuffers[3][SCREEN_WIDTH * SCREEN_HEIGHT]; +#define gFramebuffer0 gFramebuffers[0] +#define gFramebuffer1 gFramebuffers[1] +#define gFramebuffer2 gFramebuffers[2] #else -extern u16 gFrameBuffer0[SCREEN_WIDTH * SCREEN_HEIGHT]; -extern u16 gFrameBuffer1[SCREEN_WIDTH * SCREEN_HEIGHT]; -extern u16 gFrameBuffer2[SCREEN_WIDTH * SCREEN_HEIGHT]; +extern u16 gFramebuffer0[SCREEN_WIDTH * SCREEN_HEIGHT]; +extern u16 gFramebuffer1[SCREEN_WIDTH * SCREEN_HEIGHT]; +extern u16 gFramebuffer2[SCREEN_WIDTH * SCREEN_HEIGHT]; #endif #endif // FRAMEBUFFERS_H diff --git a/src/engine/behavior_script.c b/src/engine/behavior_script.c index cc39e5a2..64039c94 100644 --- a/src/engine/behavior_script.c +++ b/src/engine/behavior_script.c @@ -31,7 +31,7 @@ static u16 gRandomSeed16; // Unused function that directly jumps to a behavior command and resets the object's stack index. -static void goto_behavior_unused(const BehaviorScript *bhvAddr) { +UNUSED static void goto_behavior_unused(const BehaviorScript *bhvAddr) { gCurBhvCommand = segmented_to_virtual(bhvAddr); gCurrentObject->bhvStackIndex = 0; } @@ -107,7 +107,7 @@ static uintptr_t cur_obj_bhv_stack_pop(void) { return bhvAddr; } -static void stub_behavior_script_1(void) { +UNUSED static void stub_behavior_script_1(void) { for (;;) { ; } @@ -687,7 +687,7 @@ static s32 bhv_cmd_begin(void) { // It cannot be simply re-added to the table, as unlike all other bhv commands it takes a parameter. // Theoretically this command would have been of variable size. // Included below is a modified/repaired version of this function that would work properly. -static void bhv_cmd_set_int_random_from_table(s32 tableSize) { +UNUSED static void bhv_cmd_set_int_random_from_table(s32 tableSize) { u8 field = BHV_CMD_GET_2ND_U8(0); s32 table[16]; s32 i; @@ -904,7 +904,7 @@ static BhvCommandProc BehaviorCmdTable[] = { // Execute the behavior script of the current object, process the object flags, and other miscellaneous code for updating objects. void cur_obj_update(void) { - UNUSED u32 unused; + UNUSED u8 filler[4]; s16 objFlags = gCurrentObject->oFlags; f32 distanceFromMario; diff --git a/src/engine/geo_layout.c b/src/engine/geo_layout.c index d071d1a6..2fd4afac 100644 --- a/src/engine/geo_layout.c +++ b/src/engine/geo_layout.c @@ -293,7 +293,7 @@ void geo_layout_cmd_nop3(void) { } /* - 0x0C: Create zbuffer-toggling scene graph node + 0x0C: Create z-buffer-toggling scene graph node cmd+0x01: u8 enableZBuffer (1 = on, 0 = off) */ void geo_layout_cmd_node_master_list(void) { diff --git a/src/engine/graph_node.c b/src/engine/graph_node.c index 8edf7f8f..4b2447e7 100644 --- a/src/engine/graph_node.c +++ b/src/engine/graph_node.c @@ -719,7 +719,7 @@ void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo graphNode->areaIndex = spawn->areaIndex; graphNode->activeAreaIndex = spawn->activeAreaIndex; - graphNode->sharedChild = spawn->unk18; + graphNode->sharedChild = spawn->model; graphNode->unk4C = spawn; graphNode->throwMatrix = NULL; graphNode->animInfo.curAnim = 0; @@ -791,9 +791,7 @@ s32 retrieve_animation_index(s32 frame, u16 **attributes) { */ s16 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist) { s32 result; - struct Animation *anim; - - anim = obj->curAnim; + struct Animation *anim = obj->curAnim; if (obj->animTimer == gAreaUpdateCounter || anim->flags & ANIM_FLAG_2) { if (accelAssist != NULL) { @@ -804,7 +802,7 @@ s16 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist) { } if (anim->flags & ANIM_FLAG_FORWARD) { - if (obj->animAccel) { + if (obj->animAccel != 0) { result = obj->animFrameAccelAssist - obj->animAccel; } else { result = (obj->animFrame - 1) << 16; diff --git a/src/engine/graph_node.h b/src/engine/graph_node.h index e20064c3..08067e04 100644 --- a/src/engine/graph_node.h +++ b/src/engine/graph_node.h @@ -68,16 +68,14 @@ typedef Gfx *(*GraphNodeFunc)(s32 callContext, struct GraphNode *node, void *con * Many graph node types have an update function that gets called * when they are processed. */ -struct FnGraphNode -{ +struct FnGraphNode { /*0x00*/ struct GraphNode node; /*0x14*/ GraphNodeFunc func; }; /** The very root of the geo tree. Specifies the viewport. */ -struct GraphNodeRoot -{ +struct GraphNodeRoot { /*0x00*/ struct GraphNode node; /*0x14*/ u8 areaIndex; /*0x15*/ s8 unk15; // ? @@ -92,8 +90,7 @@ struct GraphNodeRoot /** A node that sets up an orthographic projection based on the global * root node. Used to draw the skybox image. */ -struct GraphNodeOrthoProjection -{ +struct GraphNodeOrthoProjection { /*0x00*/ struct GraphNode node; /*0x14*/ f32 scale; }; @@ -102,8 +99,7 @@ struct GraphNodeOrthoProjection * game world. It does not set up the camera position, that is done by * the child of this node, which has type GraphNodeCamera. */ -struct GraphNodePerspective -{ +struct GraphNodePerspective { /*0x00*/ struct FnGraphNode fnNode; /*0x18*/ s32 unused; /*0x1C*/ f32 fov; // horizontal field of view in degrees @@ -114,8 +110,7 @@ struct GraphNodePerspective /** An entry in the master list. It is a linked list of display lists * carrying a transformation matrix. */ -struct DisplayListNode -{ +struct DisplayListNode { Mtx *transform; void *displayList; struct DisplayListNode *next; @@ -126,8 +121,7 @@ struct DisplayListNode * different master list than opaque objects. * It also sets the z-buffer on before rendering and off after. */ -struct GraphNodeMasterList -{ +struct GraphNodeMasterList { /*0x00*/ struct GraphNode node; /*0x14*/ struct DisplayListNode *listHeads[GFX_NUM_MASTER_LISTS]; /*0x34*/ struct DisplayListNode *listTails[GFX_NUM_MASTER_LISTS]; @@ -136,8 +130,7 @@ struct GraphNodeMasterList /** Simply used as a parent to group multiple children. * Does not have any additional functionality. */ -struct GraphNodeStart -{ +struct GraphNodeStart { /*0x00*/ struct GraphNode node; }; @@ -147,8 +140,7 @@ struct GraphNodeStart * Usage examples: Mario has three level's of detail: Normal, low-poly arms only, and fully low-poly * The tower in Whomp's fortress has two levels of detail. */ -struct GraphNodeLevelOfDetail -{ +struct GraphNodeLevelOfDetail { /*0x00*/ struct GraphNode node; /*0x14*/ s16 minDistance; /*0x16*/ s16 maxDistance; @@ -159,8 +151,7 @@ struct GraphNodeLevelOfDetail * which is set in the node's function. * Usage examples: room visibility, coin animation, blinking, Mario's power-up / hand pose / cap */ -struct GraphNodeSwitchCase -{ +struct GraphNodeSwitchCase { /*0x00*/ struct FnGraphNode fnNode; /*0x18*/ s32 unused; /*0x1C*/ s16 numCases; @@ -171,8 +162,7 @@ struct GraphNodeSwitchCase * GraphNode that specifies the location and aim of the camera. * When the roll is 0, the up vector is (0, 1, 0). */ -struct GraphNodeCamera -{ +struct GraphNodeCamera { /*0x00*/ struct FnGraphNode fnNode; /*0x18*/ union { // When the node is created, a mode is assigned to the node. @@ -195,8 +185,7 @@ struct GraphNodeCamera * based on the ENEMYINFO array. * The display list can be null, in which case it won't draw anything itself. */ -struct GraphNodeTranslationRotation -{ +struct GraphNodeTranslationRotation { /*0x00*/ struct GraphNode node; /*0x14*/ void *displayList; /*0x18*/ Vec3s translation; @@ -207,12 +196,11 @@ struct GraphNodeTranslationRotation * Usage example: SUPER MARIO logo letters in debug level select. * The display list can be null, in which case it won't draw anything itself. */ -struct GraphNodeTranslation -{ +struct GraphNodeTranslation { /*0x00*/ struct GraphNode node; /*0x14*/ void *displayList; /*0x18*/ Vec3s translation; - u8 pad1E[2]; + u8 filler[2]; }; /** GraphNode that rotates itself and its children. @@ -220,12 +208,11 @@ struct GraphNodeTranslation * set by a parent script node in that case. * The display list can be null, in which case it won't draw anything itself. */ -struct GraphNodeRotation -{ +struct GraphNodeRotation { /*0x00*/ struct GraphNode node; /*0x14*/ void *displayList; /*0x18*/ Vec3s rotation; - u8 pad1E[2]; + u8 filler[2]; }; /** GraphNode part that transforms itself and its children based on animation @@ -235,8 +222,7 @@ struct GraphNodeRotation * Used for Mario, enemies and anything else with animation data. * The display list can be null, in which case it won't draw anything itself. */ -struct GraphNodeAnimatedPart -{ +struct GraphNodeAnimatedPart { /*0x00*/ struct GraphNode node; /*0x14*/ void *displayList; /*0x18*/ Vec3s translation; @@ -247,8 +233,7 @@ struct GraphNodeAnimatedPart * then it simply sets the billboard flag for the entire object, this node is * used for billboard parts (like a chuckya or goomba body). */ -struct GraphNodeBillboard -{ +struct GraphNodeBillboard { /*0x00*/ struct GraphNode node; /*0x14*/ void *displayList; /*0x18*/ Vec3s translation; @@ -257,8 +242,7 @@ struct GraphNodeBillboard /** A GraphNode that simply draws a display list without doing any * transformation beforehand. It does inherit the parent's transformation. */ -struct GraphNodeDisplayList -{ +struct GraphNodeDisplayList { /*0x00*/ struct GraphNode node; /*0x14*/ void *displayList; }; @@ -271,8 +255,7 @@ struct GraphNodeDisplayList * There is also a level command that scales the entire level, used for THI. * The display list can be null, in which case it won't draw anything itself. */ -struct GraphNodeScale -{ +struct GraphNodeScale { /*0x00*/ struct GraphNode node; /*0x14*/ void *displayList; /*0x18*/ f32 scale; @@ -283,8 +266,7 @@ struct GraphNodeScale * The shadow type determines the shape (round or rectangular), vertices (4 or 9) * and other features. */ -struct GraphNodeShadow -{ +struct GraphNodeShadow { /*0x00*/ struct GraphNode node; /*0x14*/ s16 shadowScale; // diameter (when a circle) or side (when a square) of shadow /*0x16*/ u8 shadowSolidity; // opacity of shadow, 255 = opaque @@ -294,8 +276,7 @@ struct GraphNodeShadow /** GraphNode that contains as its sharedChild a group node containing all * object nodes. */ -struct GraphNodeObjectParent -{ +struct GraphNodeObjectParent { /*0x00*/ struct GraphNode node; /*0x14*/ struct GraphNode *sharedChild; }; @@ -308,8 +289,7 @@ struct GraphNodeObjectParent * The parameter field gives extra context info. For shifting sand or paintings, * it can determine which texture to use. */ -struct GraphNodeGenerated -{ +struct GraphNodeGenerated { /*0x00*/ struct FnGraphNode fnNode; /*0x18*/ u32 parameter; // extra context for the function }; @@ -317,8 +297,7 @@ struct GraphNodeGenerated /** GraphNode that draws a background image or a rectangle of a color. * Drawn in an orthographic projection, used for skyboxes. */ -struct GraphNodeBackground -{ +struct GraphNodeBackground { /*0x00*/ struct FnGraphNode fnNode; /*0x18*/ s32 unused; /*0x1C*/ s32 background; // background ID, or rgba5551 color if fnNode.func is null @@ -326,8 +305,7 @@ struct GraphNodeBackground /** Renders the object that Mario is holding. */ -struct GraphNodeHeldObject -{ +struct GraphNodeHeldObject { /*0x00*/ struct FnGraphNode fnNode; /*0x18*/ s32 playerIndex; /*0x1C*/ struct Object *objNode; @@ -339,11 +317,10 @@ struct GraphNodeHeldObject * object node. Used for very large objects, such as shock wave rings that Bowser * creates, tornadoes, the big eel. */ -struct GraphNodeCullingRadius -{ +struct GraphNodeCullingRadius { /*0x00*/ struct GraphNode node; /*0x14*/ s16 cullingRadius; // specifies the 'sphere radius' for purposes of frustum culling - u8 pad1E[2]; + u8 filler[2]; }; extern struct GraphNodeMasterList *gCurGraphNodeMasterList; diff --git a/src/engine/level_script.c b/src/engine/level_script.c index 884e9b45..b0463393 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -286,7 +286,7 @@ static void level_cmd_load_mario_head(void) { if (addr != NULL) { gdm_init(addr, DOUBLE_SIZE_ON_64_BIT(0xE1000)); gd_add_to_heap(gZBuffer, sizeof(gZBuffer)); // 0x25800 - gd_add_to_heap(gFrameBuffer0, 3 * sizeof(gFrameBuffer0)); // 0x70800 + gd_add_to_heap(gFramebuffer0, 3 * sizeof(gFramebuffer0)); // 0x70800 gdm_setup(); gdm_maketestdl(CMD_GET(s16, 2)); } else { @@ -425,7 +425,7 @@ static void level_cmd_init_mario(void) { gMarioSpawnInfo->areaIndex = 0; gMarioSpawnInfo->behaviorArg = CMD_GET(u32, 4); gMarioSpawnInfo->behaviorScript = CMD_GET(void *, 8); - gMarioSpawnInfo->unk18 = gLoadedGraphNodes[CMD_GET(u8, 3)]; + gMarioSpawnInfo->model = gLoadedGraphNodes[CMD_GET(u8, 3)]; gMarioSpawnInfo->next = NULL; sCurrentCmd = CMD_NEXT; @@ -453,7 +453,7 @@ static void level_cmd_place_object(void) { spawnInfo->behaviorArg = CMD_GET(u32, 16); spawnInfo->behaviorScript = CMD_GET(void *, 20); - spawnInfo->unk18 = gLoadedGraphNodes[model]; + spawnInfo->model = gLoadedGraphNodes[model]; spawnInfo->next = gAreas[sCurrAreaIndex].objectSpawnInfos; gAreas[sCurrAreaIndex].objectSpawnInfos = spawnInfo; @@ -545,8 +545,8 @@ static void level_cmd_3A(void) { struct UnusedArea28 *val4; if (sCurrAreaIndex != -1) { - if ((val4 = gAreas[sCurrAreaIndex].unused28) == NULL) { - val4 = gAreas[sCurrAreaIndex].unused28 = + if ((val4 = gAreas[sCurrAreaIndex].unused) == NULL) { + val4 = gAreas[sCurrAreaIndex].unused = alloc_only_pool_alloc(sLevelPool, sizeof(struct UnusedArea28)); } @@ -827,7 +827,7 @@ struct LevelCommand *level_script_execute(struct LevelCommand *cmd) { } profiler_log_thread5_time(LEVEL_SCRIPT_EXECUTE); - init_render_image(); + init_rcp(); render_game(); end_master_display_list(); alloc_display_list(0); diff --git a/src/engine/math_util.c b/src/engine/math_util.c index e5d59d8b..72fa6259 100644 --- a/src/engine/math_util.c +++ b/src/engine/math_util.c @@ -15,7 +15,14 @@ int gSplineState; // These functions have bogus return values. // Disable the compiler warning. #pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wreturn-local-addr" + +#ifdef __GNUC__ +#if defined(__clang__) + #pragma GCC diagnostic ignored "-Wreturn-stack-address" +#else + #pragma GCC diagnostic ignored "-Wreturn-local-addr" +#endif +#endif /// Copy vector 'src' to 'dest' void *vec3f_copy(Vec3f dest, Vec3f src) { diff --git a/src/engine/surface_collision.c b/src/engine/surface_collision.c index 9a01f8bb..c59a1436 100644 --- a/src/engine/surface_collision.c +++ b/src/engine/surface_collision.c @@ -211,7 +211,7 @@ s32 find_wall_collisions(struct WallCollisionData *colData) { numCollisions += find_wall_collisions_from_list(node, colData); // Increment the debug tracker. - gNumCalls.wall += 1; + gNumCalls.wall++; return numCollisions; } @@ -305,18 +305,20 @@ static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, s32 */ f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct Surface **pceil) { s16 cellZ, cellX; + struct Surface *ceil, *dynamicCeil; struct SurfaceNode *surfaceList; + f32 height = CELL_HEIGHT_LIMIT; f32 dynamicHeight = CELL_HEIGHT_LIMIT; - s16 x, y, z; //! (Parallel Universes) Because position is casted to an s16, reaching higher - // float locations can return ceilings despite them not existing there. - //(Dynamic ceilings will unload due to the range.) - x = (s16) posX; - y = (s16) posY; - z = (s16) posZ; + // float locations can return ceilings despite them not existing there. + // (Dynamic ceilings will unload due to the range.) + s16 x = (s16) posX; + s16 y = (s16) posY; + s16 z = (s16) posZ; + *pceil = NULL; if (x <= -LEVEL_BOUNDARY_MAX || x >= LEVEL_BOUNDARY_MAX) { @@ -346,7 +348,7 @@ f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct Surface **pceil) { *pceil = ceil; // Increment the debug tracker. - gNumCalls.ceil += 1; + gNumCalls.ceil++; return height; } @@ -369,7 +371,7 @@ f32 unused_obj_find_floor_height(struct Object *obj) { */ struct FloorGeometry sFloorGeo; -static u8 unused8038BE50[0x40]; +UNUSED static u8 unused8038BE50[0x40]; /** * Return the floor height underneath (xPos, yPos, zPos) and populate `floorGeo` @@ -518,8 +520,8 @@ f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor) { f32 dynamicHeight = FLOOR_LOWER_LIMIT; //! (Parallel Universes) Because position is casted to an s16, reaching higher - // float locations can return floors despite them not existing there. - //(Dynamic floors will unload due to the range.) + // float locations can return floors despite them not existing there. + // (Dynamic floors will unload due to the range.) s16 x = (s16) xPos; s16 y = (s16) yPos; s16 z = (s16) zPos; @@ -563,7 +565,7 @@ f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor) { // If a floor was missed, increment the debug counter. if (floor == NULL) { - gNumFindFloorMisses += 1; + gNumFindFloorMisses++; } if (dynamicHeight > height) { @@ -574,7 +576,7 @@ f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor) { *pfloor = floor; // Increment the debug tracker. - gNumCalls.floor += 1; + gNumCalls.floor++; return height; } @@ -624,7 +626,7 @@ f32 find_water_level(f32 x, f32 z) { f32 find_poison_gas_level(f32 x, f32 z) { s32 i; s32 numRegions; - UNUSED s32 unused; + UNUSED u8 filler[4]; s16 val; f32 loX, hiX, loZ, hiZ; f32 gasLevel = FLOOR_LOWER_LIMIT; diff --git a/src/engine/surface_collision.h b/src/engine/surface_collision.h index ad5e6406..f4695081 100644 --- a/src/engine/surface_collision.h +++ b/src/engine/surface_collision.h @@ -17,19 +17,17 @@ // It doesn't match if ".0" is removed or ".f" is added #define FLOOR_LOWER_LIMIT_SHADOW (FLOOR_LOWER_LIMIT + 1000.0) -struct WallCollisionData -{ +struct WallCollisionData { /*0x00*/ f32 x, y, z; /*0x0C*/ f32 offsetY; /*0x10*/ f32 radius; - /*0x14*/ s16 unused; + /*0x14*/ u8 filler[2]; /*0x16*/ s16 numWalls; /*0x18*/ struct Surface *walls[4]; }; -struct FloorGeometry -{ - f32 unused[4]; // possibly position data? +struct FloorGeometry { + u8 filler[16]; // possibly position data? f32 normalX; f32 normalY; f32 normalZ; diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c index b5113901..399423f0 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c @@ -1,7 +1,5 @@ #include -#include "prevent_bss_reordering.h" - #include "sm64.h" #include "game/ingame_menu.h" #include "graph_node.h" @@ -213,7 +211,7 @@ static s16 lower_cell_index(s16 coord) { //! Some wall checks are larger than the buffer, meaning wall checks can // miss walls that are near a cell border. if (coord % CELL_SIZE < 50) { - index -= 1; + index--; } if (index < 0) { @@ -245,7 +243,7 @@ static s16 upper_cell_index(s16 coord) { //! Some wall checks are larger than the buffer, meaning wall checks can // miss walls that are near a cell border. if (coord % CELL_SIZE > CELL_SIZE - 50) { - index += 1; + index++; } if (index > NUM_CELLS_INDEX) { @@ -291,7 +289,7 @@ static void add_surface(struct Surface *surface, s32 dynamic) { } } -static void stub_surface_load_1(void) { +UNUSED static void stub_surface_load_1(void) { } /** @@ -442,12 +440,12 @@ static void load_static_surfaces(s16 **data, s16 *vertexData, s16 surfaceType, s s16 flags = surf_has_no_cam_collision(surfaceType); numSurfaces = *(*data); - *data += 1; + (*data)++; for (i = 0; i < numSurfaces; i++) { if (*surfaceRooms != NULL) { room = *(*surfaceRooms); - *surfaceRooms += 1; + (*surfaceRooms)++; } surface = read_surface_data(vertexData, data); @@ -467,7 +465,7 @@ static void load_static_surfaces(s16 **data, s16 *vertexData, s16 surfaceType, s *data += 3; if (hasForce) { - *data += 1; + (*data)++; } } } @@ -477,8 +475,7 @@ static void load_static_surfaces(s16 **data, s16 *vertexData, s16 surfaceType, s */ static s16 *read_vertex_data(s16 **data) { s32 numVertices; - UNUSED s16 unused1[3]; - UNUSED s16 unused2[3]; + UNUSED u8 filler[16]; s16 *vertexData; numVertices = *(*data); @@ -590,7 +587,7 @@ u32 get_area_terrain_size(s16 *data) { void load_area_terrain(s16 index, s16 *data, s8 *surfaceRooms, s16 *macroObjects) { s16 terrainLoadType; s16 *vertexData; - UNUSED s32 unused; + UNUSED u8 filler[4]; // Initialize the data for this. gEnvironmentRegions = NULL; @@ -653,7 +650,7 @@ void clear_dynamic_surfaces(void) { } } -static void unused_80383604(void) { +UNUSED static void unused_80383604(void) { } /** @@ -756,7 +753,7 @@ void load_object_surfaces(s16 **data, s16 *vertexData) { * Transform an object's vertices, reload them, and render the object. */ void load_object_collision_model(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; s16 vertexData[600]; s16 *collisionData = gCurrentObject->collisionData; diff --git a/src/engine/surface_load.h b/src/engine/surface_load.h index e41a04a4..e00e2bc0 100644 --- a/src/engine/surface_load.h +++ b/src/engine/surface_load.h @@ -9,14 +9,12 @@ #define NUM_CELLS (2 * LEVEL_BOUNDARY_MAX / CELL_SIZE) #define NUM_CELLS_INDEX (NUM_CELLS - 1) -struct SurfaceNode -{ +struct SurfaceNode { struct SurfaceNode *next; struct Surface *surface; }; -enum -{ +enum { SPATIAL_PARTITION_FLOORS, SPATIAL_PARTITION_CEILS, SPATIAL_PARTITION_WALLS diff --git a/src/game/area.c b/src/game/area.c index af9d0156..bca1ceaa 100644 --- a/src/game/area.c +++ b/src/game/area.c @@ -21,6 +21,7 @@ #include "engine/geo_layout.h" #include "save_file.h" #include "level_table.h" +#include "dialog_ids.h" struct SpawnInfo gPlayerSpawnInfos[1]; struct GraphNode *D_8033A160[0x100]; @@ -32,7 +33,7 @@ s16 gCurrCourseNum; s16 gCurrActNum; s16 gCurrAreaIndex; s16 gSavedCourseNum; -s16 gPauseScreenMode; +s16 gMenuOptSelectIndex; s16 gSaveOptSelectIndex; struct SpawnInfo *gMarioSpawnInfo = &gPlayerSpawnInfos[0]; @@ -108,7 +109,7 @@ void print_intro_text(void) { #ifdef VERSION_EU s32 language = eu_get_language(); #endif - if ((gGlobalTimer & 0x1F) < 20) { + if ((gGlobalTimer & 31) < 20) { if (gControllerBits == 0) { #ifdef VERSION_EU print_text_centered(SCREEN_WIDTH / 2, 20, gNoControllerMsg[language]); @@ -193,11 +194,11 @@ void clear_areas(void) { gAreaData[i].instantWarps = NULL; gAreaData[i].objectSpawnInfos = NULL; gAreaData[i].camera = NULL; - gAreaData[i].unused28 = NULL; + gAreaData[i].unused = NULL; gAreaData[i].whirlpools[0] = NULL; gAreaData[i].whirlpools[1] = NULL; - gAreaData[i].dialog[0] = 255; - gAreaData[i].dialog[1] = 255; + gAreaData[i].dialog[0] = DIALOG_NONE; + gAreaData[i].dialog[1] = DIALOG_NONE; gAreaData[i].musicParam = 0; gAreaData[i].musicParam2 = 0; } @@ -329,16 +330,14 @@ void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue) { gWarpTransition.data.texTimer = 0; - if (transType & 1) // Is the image fading in? - { + if (transType & 1) { // Is the image fading in? gWarpTransition.data.startTexRadius = GFX_DIMENSIONS_FULL_RADIUS; if (transType >= 0x0F) { gWarpTransition.data.endTexRadius = 16; } else { gWarpTransition.data.endTexRadius = 0; } - } else // The image is fading out. (Reverses start & end circles) - { + } else { // The image is fading out. (Reverses start & end circles) if (transType >= 0x0E) { gWarpTransition.data.startTexRadius = 16; } else { @@ -373,19 +372,20 @@ void render_game(void) { render_text_labels(); do_cutscene_handler(); print_displaying_credits_entry(); + gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 0, BORDER_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - BORDER_HEIGHT); - gPauseScreenMode = render_menus_and_dialogs(); - - if (gPauseScreenMode != 0) { - gSaveOptSelectIndex = gPauseScreenMode; + gMenuOptSelectIndex = render_menus_and_dialogs(); + if (gMenuOptSelectIndex != MENU_OPT_NONE) { + gSaveOptSelectIndex = gMenuOptSelectIndex; } if (D_8032CE78 != NULL) { make_viewport_clip_rect(D_8032CE78); - } else + } else { gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 0, BORDER_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - BORDER_HEIGHT); + } if (gWarpTransition.isActive) { if (gWarpTransDelay == 0) { @@ -407,7 +407,7 @@ void render_game(void) { if (D_8032CE78 != NULL) { clear_viewport(D_8032CE78, gWarpTransFBSetColor); } else { - clear_frame_buffer(gWarpTransFBSetColor); + clear_framebuffer(gWarpTransFBSetColor); } } diff --git a/src/game/area.h b/src/game/area.h index d746caa7..9141005b 100644 --- a/src/game/area.h +++ b/src/game/area.h @@ -7,16 +7,14 @@ #include "camera.h" #include "engine/graph_node.h" -struct WarpNode -{ +struct WarpNode { /*00*/ u8 id; /*01*/ u8 destLevel; /*02*/ u8 destArea; /*03*/ u8 destNode; }; -struct ObjectWarpNode -{ +struct ObjectWarpNode { /*0x00*/ struct WarpNode node; /*0x04*/ struct Object *object; /*0x08*/ struct ObjectWarpNode *next; @@ -26,27 +24,24 @@ struct ObjectWarpNode #define INSTANT_WARP_INDEX_START 0x00 // Equal and greater than Surface 0x1B #define INSTANT_WARP_INDEX_STOP 0x04 // Less than Surface 0x1F -struct InstantWarp -{ +struct InstantWarp { /*0x00*/ u8 id; // 0 = 0x1B / 1 = 0x1C / 2 = 0x1D / 3 = 0x1E /*0x01*/ u8 area; /*0x02*/ Vec3s displacement; }; -struct SpawnInfo -{ +struct SpawnInfo { /*0x00*/ Vec3s startPos; /*0x06*/ Vec3s startAngle; /*0x0C*/ s8 areaIndex; /*0x0D*/ s8 activeAreaIndex; /*0x10*/ u32 behaviorArg; /*0x14*/ void *behaviorScript; - /*0x18*/ struct GraphNode *unk18; + /*0x18*/ struct GraphNode *model; /*0x1C*/ struct SpawnInfo *next; }; -struct UnusedArea28 -{ +struct UnusedArea28 { /*0x00*/ s16 unk00; /*0x02*/ s16 unk02; /*0x04*/ s16 unk04; @@ -54,14 +49,12 @@ struct UnusedArea28 /*0x08*/ s16 unk08; }; -struct Whirlpool -{ +struct Whirlpool { /*0x00*/ Vec3s pos; /*0x03*/ s16 strength; }; -struct Area -{ +struct Area { /*0x00*/ s8 index; /*0x01*/ s8 flags; // Only has 1 flag: 0x01 = Is this the active area? /*0x02*/ u16 terrainType; // default terrain of the level (set from level script cmd 0x31) @@ -74,7 +67,7 @@ struct Area /*0x1C*/ struct InstantWarp *instantWarps; /*0x20*/ struct SpawnInfo *objectSpawnInfos; /*0x24*/ struct Camera *camera; - /*0x28*/ struct UnusedArea28 *unused28; // Filled by level script 0x3A, but is unused. + /*0x28*/ struct UnusedArea28 *unused; // Filled by level script 0x3A, but is unused. /*0x2C*/ struct Whirlpool *whirlpools[2]; /*0x34*/ u8 dialog[2]; // Level start dialog number (set by level script cmd 0x30) /*0x36*/ u16 musicParam; @@ -82,8 +75,7 @@ struct Area }; // All the transition data to be used in screen_transition.c -struct WarpTransitionData -{ +struct WarpTransitionData { /*0x00*/ u8 red; /*0x01*/ u8 green; /*0x02*/ u8 blue; @@ -109,8 +101,7 @@ struct WarpTransitionData #define WARP_TRANSITION_FADE_FROM_BOWSER 0x12 #define WARP_TRANSITION_FADE_INTO_BOWSER 0x13 -struct WarpTransition -{ +struct WarpTransition { /*0x00*/ u8 isActive; // Is the transition active. (either TRUE or FALSE) /*0x01*/ u8 type; // Determines the type of transition to use (circle, star, etc.) /*0x02*/ u8 time; // Amount of time to complete the transition (in frames) @@ -118,6 +109,24 @@ struct WarpTransition /*0x04*/ struct WarpTransitionData data; }; +enum MenuOption { + MENU_OPT_NONE, + MENU_OPT_1, + MENU_OPT_2, + MENU_OPT_3, + MENU_OPT_DEFAULT = MENU_OPT_1, + + // Course Pause Menu + MENU_OPT_CONTINUE = MENU_OPT_1, + MENU_OPT_EXIT_COURSE = MENU_OPT_2, + MENU_OPT_CAMERA_ANGLE_R = MENU_OPT_3, + + // Save Menu + MENU_OPT_SAVE_AND_CONTINUE = MENU_OPT_1, + MENU_OPT_SAVE_AND_QUIT = MENU_OPT_2, + MENU_OPT_CONTINUE_DONT_SAVE = MENU_OPT_3 +}; + extern struct GraphNode **gLoadedGraphNodes; extern struct SpawnInfo gPlayerSpawnInfos[]; extern struct GraphNode *D_8033A160[]; @@ -127,7 +136,7 @@ extern s16 gCurrCourseNum; extern s16 gCurrActNum; extern s16 gCurrAreaIndex; extern s16 gSavedCourseNum; -extern s16 gPauseScreenMode; +extern s16 gMenuOptSelectIndex; extern s16 gSaveOptSelectIndex; extern struct SpawnInfo *gMarioSpawnInfo; diff --git a/src/game/behavior_actions.c b/src/game/behavior_actions.c index 03dbaa1d..9800146f 100644 --- a/src/game/behavior_actions.c +++ b/src/game/behavior_actions.c @@ -23,6 +23,7 @@ #include "level_table.h" #include "level_update.h" #include "levels/bob/header.h" +#include "levels/bowser_3/header.h" #include "levels/castle_inside/header.h" #include "levels/hmc/header.h" #include "main.h" @@ -46,55 +47,18 @@ #define o gCurrentObject -struct WFRotatingPlatformData { - s16 pad; - s16 scale; - const Collision *collisionData; - s16 collisionDistance; +static s32 sCapSaveFlags[] = { + SAVE_FLAG_HAVE_WING_CAP, + SAVE_FLAG_HAVE_METAL_CAP, + SAVE_FLAG_HAVE_VANISH_CAP, }; -struct Struct8032F34C { - s16 numBridgeSections; - s16 bridgeRelativeStartingXorZ; - s16 platformWidth; - s16 model; - const void *segAddr; -}; - -struct Struct8032F698 { - void *unk0; - s16 unk1; - s16 unk2; - s16 unk3; - s16 unk4; -}; - -struct Struct802C0DF0 { - u8 unk0; - u8 unk1; - u8 unk2; - u8 model; - const BehaviorScript *behavior; -}; - -struct Struct8032F754 { - s32 unk0; - Vec3f unk1; - f32 unk2; -}; - -struct OpenableGrill { - s16 halfWidth; - s16 modelID; - const Collision *collision; -}; - -s32 D_8032F0C0[] = { SAVE_FLAG_HAVE_WING_CAP, SAVE_FLAG_HAVE_METAL_CAP, SAVE_FLAG_HAVE_VANISH_CAP }; - // Boo Roll -s16 D_8032F0CC[] = { 6047, 5664, 5292, 4934, 4587, 4254, 3933, 3624, 3329, 3046, 2775, - 2517, 2271, 2039, 1818, 1611, 1416, 1233, 1063, 906, 761, 629, - 509, 402, 308, 226, 157, 100, 56, 25, 4, 0 }; +static s16 sBooHitRotations[] = { + 6047, 5664, 5292, 4934, 4587, 4254, 3933, 3624, 3329, 3046, 2775, + 2517, 2271, 2039, 1818, 1611, 1416, 1233, 1063, 906, 761, 629, + 509, 402, 308, 226, 157, 100, 56, 25, 4, 0, +}; #include "behaviors/star_door.inc.c" #include "behaviors/mr_i.inc.c" @@ -115,21 +79,36 @@ s16 D_8032F0CC[] = { 6047, 5664, 5292, 4934, 4587, 4254, 3933, 3624, 3329, 3046, #include "behaviors/white_puff_explode.inc.c" // not in behavior file -struct SpawnParticlesInfo D_8032F270 = { 2, 20, MODEL_MIST, 0, 40, 5, 30, 20, 252, 30, 330.0f, 10.0f }; +static struct SpawnParticlesInfo sMistParticles = { + /* behParam: */ 2, + /* count: */ 20, + /* model: */ MODEL_MIST, + /* offsetY: */ 0, + /* forwardVelBase: */ 40, + /* forwardVelRange: */ 5, + /* velYBase: */ 30, + /* velYRange: */ 20, + /* gravity: */ 252, + /* dragStrength: */ 30, + /* sizeBase: */ 330.0f, + /* sizeRange: */ 10.0f, +}; // generate_wind_puffs/dust (something like that) void spawn_mist_particles_variable(s32 count, s32 offsetY, f32 size) { - D_8032F270.sizeBase = size; - D_8032F270.sizeRange = size / 20.0; - D_8032F270.offsetY = offsetY; + sMistParticles.sizeBase = size; + sMistParticles.sizeRange = size / 20.0; + sMistParticles.offsetY = offsetY; + if (count == 0) { - D_8032F270.count = 20; + sMistParticles.count = 20; } else if (count > 20) { - D_8032F270.count = count; + sMistParticles.count = count; } else { - D_8032F270.count = 4; + sMistParticles.count = 4; } - cur_obj_spawn_particles(&D_8032F270); + + cur_obj_spawn_particles(&sMistParticles); } #include "behaviors/sparkle_spawn_star.inc.c" @@ -166,16 +145,16 @@ void spawn_mist_particles_variable(s32 count, s32 offsetY, f32 size) { // not sure what this is doing here. not in a behavior file. Gfx *geo_move_mario_part_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx) { Mat4 sp20; - struct Object *sp1C; if (run == TRUE) { - sp1C = (struct Object *) gCurGraphNodeObject; + struct Object *sp1C = (struct Object *) gCurGraphNodeObject; if (sp1C == gMarioObject && sp1C->prevObj != NULL) { create_transformation_from_matrices(sp20, mtx, *gCurGraphNodeCamera->matrixPtr); obj_update_pos_from_parent_transformation(sp20, sp1C->prevObj); obj_set_gfx_pos_from_pos(sp1C->prevObj); } } + return NULL; } @@ -192,6 +171,7 @@ void spawn_sparkle_particles(s32 n, s32 a1, s32 a2, s32 r) { static s16 D_8035FF10; s32 i; s16 separation = 0x10000 / n; // Evenly spread around a circle + for (i = 0; i < n; i++) { spawn_object_relative(0, sins(D_8035FF10 + i * separation) * a1, (i + 1) * a2, coss(D_8035FF10 + i * separation) * a1, o, MODEL_NONE, bhvSparkleSpawn); @@ -205,6 +185,8 @@ void spawn_sparkle_particles(s32 n, s32 a1, s32 a2, s32 r) { #include "behaviors/bowser_key.inc.c" #include "behaviors/bullet_bill.inc.c" #include "behaviors/bowser.inc.c" +#include "behaviors/bowser_falling_platform.inc.c" +#include "behaviors/bowser_flame.inc.c" #include "behaviors/blue_fish.inc.c" // Not in behavior file, duplicate of vec3f_copy except without bad return. @@ -238,13 +220,17 @@ void vec3f_copy_2(Vec3f dest, Vec3f src) { s32 set_obj_anim_with_accel_and_sound(s16 a0, s16 a1, s32 a2) { f32 sp1C; - if ((sp1C = o->header.gfx.animInfo.animAccel / (f32) 0x10000) == 0) + + if ((sp1C = o->header.gfx.animInfo.animAccel / (f32) 0x10000) == 0) { sp1C = 1.0f; + } + if (cur_obj_check_anim_frame_in_range(a0, sp1C) || cur_obj_check_anim_frame_in_range(a1, sp1C)) { cur_obj_play_sound_2(a2); - return 1; + return TRUE; } - return 0; + + return FALSE; } #include "behaviors/tuxie.inc.c" diff --git a/src/game/behavior_actions.h b/src/game/behavior_actions.h index d068492e..97939170 100644 --- a/src/game/behavior_actions.h +++ b/src/game/behavior_actions.h @@ -231,7 +231,7 @@ void bhv_big_boo_loop(void); void bhv_courtyard_boo_triplet_init(void); void obj_set_secondary_camera_focus(void); void bhv_boo_loop(void); -void bhv_boo_boss_spawned_bridge_loop(void); +void bhv_boo_staircase(void); void bhv_bbh_tilting_trap_platform_loop(void); void bhv_haunted_bookshelf_loop(void); void bhv_merry_go_round_loop(void); diff --git a/src/game/behaviors/activated_bf_plat.inc.c b/src/game/behaviors/activated_bf_plat.inc.c index bb553c51..8b6399b7 100644 --- a/src/game/behaviors/activated_bf_plat.inc.c +++ b/src/game/behaviors/activated_bf_plat.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvActivatedBackAndForthPlatform. * There are only 2 of these in the game; the BitFS gray elevator @@ -16,7 +17,7 @@ * move off of it. To do this, they changed it to a bhvPlatformOnTrack, but * forgot to remove its entry in this table. */ -static void const *sActivatedBackAndForthPlatformCollisionModels[] = { +static Collision const *sActivatedBackAndForthPlatformCollisionModels[] = { /* ACTIVATED_BF_PLAT_TYPE_BITS_ARROW_PLAT */ bits_seg7_collision_0701AD54, /* ACTIVATED_BF_PLAT_TYPE_BITFS_MESH_PLAT */ bitfs_seg7_collision_070157E0, /* ACTIVATED_BF_PLAT_TYPE_BITFS_ELEVATOR */ bitfs_seg7_collision_07015124 @@ -61,7 +62,7 @@ void bhv_activated_back_and_forth_platform_init(void) { * Activated back-and-forth platform update function. */ void bhv_activated_back_and_forth_platform_update(void) { - UNUSED s32 unused[3]; + UNUSED u8 filler[12]; // oVelY is used for vertical platforms' movement and also for // horizontal platforms' dipping up/down when Mario gets on/off them @@ -78,7 +79,7 @@ void bhv_activated_back_and_forth_platform_update(void) { // and one more frame of "lag" after it finally reaches 0 here, // Mario actually has to wait 22 frames before the platform starts moving. if (o->oActivatedBackAndForthPlatformCountdown != 0) { - o->oActivatedBackAndForthPlatformCountdown -= 1; + o->oActivatedBackAndForthPlatformCountdown--; } else { // After the wait period is over, we start moving, by adding the velocity // to the positional offset. diff --git a/src/game/behaviors/amp.inc.c b/src/game/behaviors/amp.inc.c index 1a63bbb2..4fbdadb7 100644 --- a/src/game/behaviors/amp.inc.c +++ b/src/game/behaviors/amp.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvHomingAmp and bhvCirclingAmp. * These are distinct objects; one chases (homes in on) Mario, @@ -24,9 +25,9 @@ void bhv_homing_amp_init(void) { o->oHomeX = o->oPosX; o->oHomeY = o->oPosY; o->oHomeZ = o->oPosZ; - o->oGravity = 0; - o->oFriction = 1.0; - o->oBuoyancy = 1.0; + o->oGravity = 0.0f; + o->oFriction = 1.0f; + o->oBuoyancy = 1.0f; o->oHomingAmpAvgY = o->oHomeY; // Homing amps start at 1/10th their normal size. @@ -48,8 +49,9 @@ static void check_amp_attack(void) { if (o->oInteractStatus & INT_STATUS_INTERACTED) { // Unnecessary if statement, maybe caused by a macro for - // if (o->oInteractStatus & INT_STATUS_INTERACTED) + // if (o->oInteractStatus & INT_STATUS_INTERACTED) { // o->oAction = X; + // } // ? if (o->oInteractStatus & INT_STATUS_INTERACTED) { // This function is used for both normal amps and homing amps, @@ -88,7 +90,7 @@ static void homing_amp_appear_loop(void) { // Once the timer becomes greater than 90, i.e. 91 frames have passed, // reset the amp's size and start chasing Mario. - if (o->oTimer >= 91) { + if (o->oTimer > 90) { cur_obj_scale(1.0f); o->oAction = HOMING_AMP_ACT_CHASE; o->oAmpYPhase = 0; @@ -121,7 +123,7 @@ static void homing_amp_chase_loop(void) { o->oHomingAmpAvgY = gMarioObject->header.gfx.pos[1] + 150.0f; } - if (o->oTimer >= 31) { + if (o->oTimer > 30) { o->oHomingAmpLockedOn = FALSE; } } else { @@ -160,7 +162,7 @@ static void homing_amp_give_up_loop(void) { // Move forward for 152 frames o->oForwardVel = 15.0f; - if (o->oTimer >= 151) { + if (o->oTimer > 150) { // Hide the amp and reset it back to its inactive state o->oPosX = o->oHomeX; o->oPosY = o->oHomeY; @@ -168,7 +170,7 @@ static void homing_amp_give_up_loop(void) { o->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE; o->oAction = HOMING_AMP_ACT_INACTIVE; o->oAnimState = 0; - o->oForwardVel = 0; + o->oForwardVel = 0.0f; o->oHomingAmpAvgY = o->oHomeY; } } @@ -179,15 +181,15 @@ static void homing_amp_give_up_loop(void) { static void amp_attack_cooldown_loop(void) { // Turn intangible and wait for 90 frames before chasing Mario again after hitting him. o->header.gfx.animInfo.animFrame += 2; - o->oForwardVel = 0; + o->oForwardVel = 0.0f; cur_obj_become_intangible(); - if (o->oTimer >= 31) { + if (o->oTimer > 30) { o->oAnimState = 0; } - if (o->oTimer >= 91) { + if (o->oTimer > 90) { o->oAnimState = 1; cur_obj_become_tangible(); o->oAction = HOMING_AMP_ACT_CHASE; @@ -334,7 +336,6 @@ void bhv_circling_amp_loop(void) { } else { circling_amp_idle_loop(); } - break; case AMP_ACT_ATTACK_COOLDOWN: diff --git a/src/game/behaviors/animated_floor_switch.inc.c b/src/game/behaviors/animated_floor_switch.inc.c index 8f502310..e0e8471f 100644 --- a/src/game/behaviors/animated_floor_switch.inc.c +++ b/src/game/behaviors/animated_floor_switch.inc.c @@ -1,8 +1,8 @@ // animated_floor_switch.inc.c struct Struct80331A54 { - const void *unk00; - s16 unk04; + const Collision *collision; + s16 model; }; struct Struct80331A54 D_80331A54[][5] = { @@ -63,7 +63,7 @@ void bhv_animates_on_floor_switch_press_loop(void) { } if (o->oFloorSwitchPressAnimationUnkF8 < 9) { - o->oFloorSwitchPressAnimationUnkF8 += 1; + o->oFloorSwitchPressAnimationUnkF8++; } } else if ((o->oFloorSwitchPressAnimationUnkF8 -= 2) < 0) { o->oFloorSwitchPressAnimationUnkF8 = 0; @@ -71,7 +71,7 @@ void bhv_animates_on_floor_switch_press_loop(void) { } o->collisionData = segmented_to_virtual( - D_80331A54[o->oBehParams2ndByte][o->oFloorSwitchPressAnimationUnkF8 / 2].unk00); + D_80331A54[o->oBehParams2ndByte][o->oFloorSwitchPressAnimationUnkF8 / 2].collision); - cur_obj_set_model(D_80331A54[o->oBehParams2ndByte][o->oFloorSwitchPressAnimationUnkF8 / 2].unk04); + cur_obj_set_model(D_80331A54[o->oBehParams2ndByte][o->oFloorSwitchPressAnimationUnkF8 / 2].model); } diff --git a/src/game/behaviors/arrow_lift.inc.c b/src/game/behaviors/arrow_lift.inc.c index 127d3576..2dac2616 100644 --- a/src/game/behaviors/arrow_lift.inc.c +++ b/src/game/behaviors/arrow_lift.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for WDW arrow lifts. * When a player stands on an arrow lift, it starts moving between diff --git a/src/game/behaviors/bbh_haunted_bookshelf.inc.c b/src/game/behaviors/bbh_haunted_bookshelf.inc.c index 8a7eff1d..e6591217 100644 --- a/src/game/behaviors/bbh_haunted_bookshelf.inc.c +++ b/src/game/behaviors/bbh_haunted_bookshelf.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvHauntedBookshelf. * This is the bookshelf that recedes after solving the puzzle of the haunted books. @@ -29,6 +30,7 @@ void bhv_haunted_bookshelf_loop(void) { } break; + case HAUNTED_BOOKSHELF_ACT_RECEDE: // Move the bookshelf and play the sound o->oPosX += 5.0f; @@ -40,6 +42,7 @@ void bhv_haunted_bookshelf_loop(void) { } break; + default: break; } diff --git a/src/game/behaviors/bbh_merry_go_round.inc.c b/src/game/behaviors/bbh_merry_go_round.inc.c index 91640fde..5b634428 100644 --- a/src/game/behaviors/bbh_merry_go_round.inc.c +++ b/src/game/behaviors/bbh_merry_go_round.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvMerryGoRound. * This is the merry-go-round in BBH. diff --git a/src/game/behaviors/bbh_tilting_trap.inc.c b/src/game/behaviors/bbh_tilting_trap.inc.c index d18f33df..6f35cf06 100644 --- a/src/game/behaviors/bbh_tilting_trap.inc.c +++ b/src/game/behaviors/bbh_tilting_trap.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvBbhTiltingTrapPlatform. * This is the tilting platform trap in the upper floor of BBH @@ -8,9 +9,9 @@ * Update function for bhvBbhTiltingTrapPlatform. */ void bhv_bbh_tilting_trap_platform_loop(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; - // US (and probably later) versions use oAction for the + // Post-JP versions use oAction for the // if statement, while immediately setting it over here. // This was done so that Mario leaving or getting on the platform // resets oTimer to 0. @@ -29,14 +30,14 @@ void bhv_bbh_tilting_trap_platform_loop(void) { o->oFaceAnglePitch += o->oAngleVelPitch; } else #ifndef VERSION_JP - // In the US version, if the platform has tilted more than 3000 angle units + // In the post-JP versions, if the platform has tilted more than 3000 angle units // in less than 16 frames since Mario got on it, and he has stepped off, // this code will not run, so it will continue to rotate with the same // angular velocity for 16 more frames. This was probably done to make // the platform more dangerous. This code will not work correctly // without the oAction changes above, since oTimer will not ever // reset to 0 without them. - if ((absi(o->oFaceAnglePitch) < 3000) || (o->oTimer >= 16)) + if ((absi(o->oFaceAnglePitch) < 3000) || (o->oTimer > 15)) #endif { // Make the platform return to the horizontal at a speed of diff --git a/src/game/behaviors/beta_boo_key.inc.c b/src/game/behaviors/beta_boo_key.inc.c index 27a85dee..23249555 100644 --- a/src/game/behaviors/beta_boo_key.inc.c +++ b/src/game/behaviors/beta_boo_key.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvAlphaBooKey and bhvBetaBooKey. * They were apparently intended to be a key that would be contained in boos @@ -87,14 +88,14 @@ static void beta_boo_key_dropped_loop(void) { if (obj_check_if_collided_with_object(o, gMarioObject)) { // This interaction status is 0x01, the first interaction status flag. // It was only used for Hoot in the final game, but it seems it could've - // done something else or held some special meaning in beta. + // treated as a TRUE/FALSE statement or held some special meaning in beta. // Earlier, in beta_boo_key_drop (called when the parent boo is killed), // o->parentObj is set to the parent boo's parentObj. This means that // here, the parentObj is actually the parent of the old parent boo. // One theory about this code is that there was a boo spawner, which // spawned "false" boos and one "true" boo with the key, and the player // was intended to find the one with the key to progress. - o->parentObj->oInteractStatus = INT_STATUS_HOOT_GRABBED_BY_MARIO; + o->parentObj->oInteractStatus = TRUE; // Delete the object and spawn sparkles obj_mark_for_deletion(o); @@ -163,8 +164,11 @@ static void beta_boo_key_inside_boo_loop(void) { o->oFaceAngleYaw += 0x200; } -static void (*sBetaBooKeyActions[])(void) = { beta_boo_key_inside_boo_loop, beta_boo_key_drop, - beta_boo_key_dropped_loop }; +static void (*sBetaBooKeyActions[])(void) = { + beta_boo_key_inside_boo_loop, + beta_boo_key_drop, + beta_boo_key_dropped_loop, +}; /** * Update function for bhvBetaBooKey. diff --git a/src/game/behaviors/beta_bowser_anchor.inc.c b/src/game/behaviors/beta_bowser_anchor.inc.c index e12d204c..f0475840 100644 --- a/src/game/behaviors/beta_bowser_anchor.inc.c +++ b/src/game/behaviors/beta_bowser_anchor.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvBetaBowserAnchor. * This seems to be a beta bowser anchor object. It continuously updates to be @@ -9,15 +10,15 @@ * It continuously updates to be in front of Mario, * and attacks all non-Mario objects it touches. * It continuously sets its hitbox radius/height - * based on gDebugInfo[4]. + * based on gDebugInfo[DEBUG_PAGE_EFFECTINFO]. */ void bhv_beta_bowser_anchor_loop(void) { // Set the object's position to be 30 units above Mario's feet, // and 300 units in front of him. cur_obj_set_pos_relative(gMarioObject, 0, 30.0f, 300.0f); - o->hitboxRadius = gDebugInfo[4][0] + 100; - o->hitboxHeight = gDebugInfo[4][1] + 300; + o->hitboxRadius = gDebugInfo[DEBUG_PAGE_EFFECTINFO][0] + 100; + o->hitboxHeight = gDebugInfo[DEBUG_PAGE_EFFECTINFO][1] + 300; obj_attack_collided_from_other_object(o); } diff --git a/src/game/behaviors/beta_chest.inc.c b/src/game/behaviors/beta_chest.inc.c index 7a1a786d..53ac6149 100644 --- a/src/game/behaviors/beta_chest.inc.c +++ b/src/game/behaviors/beta_chest.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvBetaChestBottom and bhvBetaChestLid. * These are apparently the beta versions of chests. @@ -49,6 +50,7 @@ void bhv_beta_chest_lid_loop(void) { } break; + case BETA_CHEST_ACT_OPENING: if (o->oTimer == 0) { // Spawn the bubble 80 units in the -Y direction and 120 units in the +Z direction. @@ -63,7 +65,7 @@ void bhv_beta_chest_lid_loop(void) { o->oAction++; // Set to BETA_CHEST_ACT_IDLE_OPEN } - // Fall-through + // fallthrough case BETA_CHEST_ACT_IDLE_OPEN: break; } diff --git a/src/game/behaviors/beta_fish_splash_spawner.inc.c b/src/game/behaviors/beta_fish_splash_spawner.inc.c index 6daab4c6..93a2ee12 100644 --- a/src/game/behaviors/beta_fish_splash_spawner.inc.c +++ b/src/game/behaviors/beta_fish_splash_spawner.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvBetaFishSplashSpawner. * This is a now non-functional fish splash object found in WF @@ -12,6 +13,6 @@ * Update function for bhvBetaFishSplashSpawner. */ void bhv_beta_fish_splash_spawner_loop(void) { - UNUSED u8 pad[12]; - UNUSED f32 water_level = find_water_level(o->oPosX, o->oPosZ); + UNUSED u8 filler[12]; + UNUSED f32 waterLevel = find_water_level(o->oPosX, o->oPosZ); } diff --git a/src/game/behaviors/beta_holdable_object.inc.c b/src/game/behaviors/beta_holdable_object.inc.c index b4ec61f9..13af68e7 100644 --- a/src/game/behaviors/beta_holdable_object.inc.c +++ b/src/game/behaviors/beta_holdable_object.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvBetaHoldableObject. * This is a simple implementation of a holdable object, probably used @@ -11,9 +12,9 @@ * Just sets various physics constants for the object. */ void bhv_beta_holdable_object_init(void) { - o->oGravity = 2.5; - o->oFriction = 0.8; - o->oBuoyancy = 1.3; + o->oGravity = 2.5f; + o->oFriction = 0.8f; + o->oBuoyancy = 1.3f; } /** @@ -27,8 +28,8 @@ static void beta_holdable_object_drop(void) { o->oHeldState = HELD_FREE; - o->oForwardVel = 0; - o->oVelY = 0; + o->oForwardVel = 0.0f; + o->oVelY = 0.0f; } /** @@ -46,8 +47,8 @@ static void beta_holdable_object_throw(void) { o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; // Set initial velocity - o->oForwardVel = 40.0; - o->oVelY = 20.0; + o->oForwardVel = 40.0f; + o->oVelY = 20.0f; } /** diff --git a/src/game/behaviors/beta_trampoline.inc.c b/src/game/behaviors/beta_trampoline.inc.c index f9c248f5..100ebc23 100644 --- a/src/game/behaviors/beta_trampoline.inc.c +++ b/src/game/behaviors/beta_trampoline.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvBetaTrampolineTop and bhvBetaTrampolineSpring. * This was a trampoline that was never finished. The model and collision diff --git a/src/game/behaviors/bird.inc.c b/src/game/behaviors/bird.inc.c index e6d081a4..11d51058 100644 --- a/src/game/behaviors/bird.inc.c +++ b/src/game/behaviors/bird.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvBird. These are the birds in the castle grounds * that fly away and scatter when Mario comes near them. There are @@ -52,7 +53,7 @@ static void bird_act_inactive(void) { * and the parent spawner bird if it's a spawned bird. */ static void bird_act_fly(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; f32 distance; // Compute forward velocity and vertical velocity from oBirdSpeed and pitch diff --git a/src/game/behaviors/blue_coin.inc.c b/src/game/behaviors/blue_coin.inc.c index d10e3600..902a6739 100644 --- a/src/game/behaviors/blue_coin.inc.c +++ b/src/game/behaviors/blue_coin.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvHiddenBlueCoin and bhvBlueCoinSwitch. * bhvHiddenBlueCoin are the stationary blue coins that appear when @@ -24,6 +25,7 @@ void bhv_hidden_blue_coin_loop(void) { } break; + case HIDDEN_BLUE_COIN_ACT_WAITING: // Wait until the blue coin switch starts ticking to activate. blueCoinSwitch = o->oHiddenBlueCoinSwitch; @@ -33,6 +35,7 @@ void bhv_hidden_blue_coin_loop(void) { } break; + case HIDDEN_BLUE_COIN_ACT_ACTIVE: // Become tangible cur_obj_enable_rendering(); @@ -85,6 +88,7 @@ void bhv_blue_coin_switch_loop(void) { load_object_collision_model(); break; + case BLUE_COIN_SWITCH_ACT_RECEDING: // Recede for 6 frames before going invisible and ticking. // This is probably an off-by-one error, since the switch is 100 units tall @@ -108,6 +112,7 @@ void bhv_blue_coin_switch_loop(void) { } break; + case BLUE_COIN_SWITCH_ACT_TICKING: // Tick faster when the blue coins start blinking if (o->oTimer < 200) { diff --git a/src/game/behaviors/blue_fish.inc.c b/src/game/behaviors/blue_fish.inc.c index dcaa35b3..452748da 100644 --- a/src/game/behaviors/blue_fish.inc.c +++ b/src/game/behaviors/blue_fish.inc.c @@ -1,3 +1,4 @@ + /** * @file blue_fish.inc.c * Implements behaviour and spawning for bhvBlueFish located in the castle aquarium outside of SA. @@ -8,17 +9,18 @@ */ void bhv_blue_fish_movement_loop(void) { f32 randomSwitch; + switch (o->oAction) { // Initial dive phase after spawning case BLUE_FISH_ACT_DIVE: cur_obj_init_animation_with_accel_and_sound(0, 1.0f); - + // Assigns random values to variables that help determine natural motion. if (o->oTimer == 0) { - o->oBlueFishRandomAngle = random_sign() << 11; + o->oBlueFishRandomAngle = random_sign() * 0x800; o->oBlueFishRandomVel = random_float() * 2; o->oBlueFishRandomTime = (s32)(random_float() * 30) & 0xFE; - + // Adjusts pitch velocity or sets to zero dependant on outcome of randomSwitch. randomSwitch = random_float() * 5; if (randomSwitch < 2.0f) { @@ -27,23 +29,24 @@ void bhv_blue_fish_movement_loop(void) { o->oAngleVelPitch = 0; } } - + // Set forward velocity and progress oAction to BLUE_FISH_ACT_TURN. o->oForwardVel = o->oBlueFishRandomVel + 3.0f; if (o->oTimer >= o->oBlueFishRandomTime + 60) { o->oAction++; } - + // Set pitch velocity if (o->oTimer < (o->oBlueFishRandomTime + 60) / 2) { o->oFaceAnglePitch += o->oAngleVelPitch; } else { o->oFaceAnglePitch -= o->oAngleVelPitch; } - + // Calculate new Y velocity o->oVelY = -sins(o->oFaceAnglePitch) * o->oForwardVel; break; + // Animates and adjusts fish yaw angle. case BLUE_FISH_ACT_TURN: cur_obj_init_animation_with_accel_and_sound(0, 2.0f); @@ -51,39 +54,41 @@ void bhv_blue_fish_movement_loop(void) { if (o->oTimer == 15) { o->oAction++; } - break; + break; + // Animates and adjusts pitch to an upward direction. case BLUE_FISH_ACT_ASCEND: cur_obj_init_animation_with_accel_and_sound(0, 1.0f); - - // Progresses oAction to BLUE_FISH_ACT_TURN_BACK after elapsed time. + + // Progresses oAction to BLUE_FISH_ACT_TURN_BACK after elapsed time. if (o->oTimer >= o->oBlueFishRandomTime + 60) { o->oAction++; } - + // Adjusts pitch angle. Direction relies on time not passed. if (o->oTimer < (o->oBlueFishRandomTime + 60) / 2) { o->oFaceAnglePitch -= o->oAngleVelPitch; } else { o->oFaceAnglePitch += o->oAngleVelPitch; } - break; + break; + // Animates and turns fish around case BLUE_FISH_ACT_TURN_BACK: cur_obj_init_animation_with_accel_and_sound(0, 2.0f); o->oMoveAngleYaw = (s32)(o->oBlueFishRandomAngle + o->oMoveAngleYaw); - + // Sets the fish back to the BLUE_FISH_ACT_DIVE phase. if (o->oTimer == 15) { o->oAction = BLUE_FISH_ACT_DIVE; } break; } - + // Calculates Y velocity and calls physics engine. o->oVelY = -sins(o->oFaceAnglePitch) * o->oForwardVel; cur_obj_move_using_fvel_and_gravity(); - + // Deletes object if the parent has oAction set to BLUE_FISH_ACT_DUPLICATE. if (o->parentObj->oAction == BLUE_FISH_ACT_DUPLICATE) { obj_mark_for_deletion(o); @@ -97,28 +102,29 @@ void bhv_blue_fish_movement_loop(void) { void bhv_tank_fish_group_loop(void) { struct Object *fish; s32 i; + switch (o->oAction) { case BLUE_FISH_ACT_SPAWN: if (gMarioCurrentRoom == 15 || gMarioCurrentRoom == 7) { - + // spawns fifteen fish and moves them within 200.0f for (i = 0; i < 15; i++) { fish = spawn_object_relative(0, 300, 0, -200, o, MODEL_FISH, bhvBlueFish); obj_translate_xyz_random(fish, 200.0f); } - + // Proceed to BLUE_FISH_ACT_ROOM phase. o->oAction++; } break; - + // Sets next oAction phase if Mario is not in rooms fifteen and seven. case BLUE_FISH_ACT_ROOM: if (gMarioCurrentRoom != 15 && gMarioCurrentRoom != 7) { o->oAction++; } break; - + // Sets oAction to the BLUE_FISH_ACT_SPAWN phase. case BLUE_FISH_ACT_DUPLICATE: o->oAction = BLUE_FISH_ACT_SPAWN; diff --git a/src/game/behaviors/bobomb.inc.c b/src/game/behaviors/bobomb.inc.c index 2e3a314c..4db4137b 100644 --- a/src/game/behaviors/bobomb.inc.c +++ b/src/game/behaviors/bobomb.inc.c @@ -1,4 +1,4 @@ -// bobomb.c.inc +// bobomb.inc.c static struct ObjectHitbox sBobombHitbox = { /* interactType: */ INTERACT_GRABBABLE, @@ -13,14 +13,14 @@ static struct ObjectHitbox sBobombHitbox = { }; void bhv_bobomb_init(void) { - o->oGravity = 2.5; - o->oFriction = 0.8; - o->oBuoyancy = 1.3; + o->oGravity = 2.5f; + o->oFriction = 0.8f; + o->oBuoyancy = 1.3f; o->oInteractionSubtype = INT_SUBTYPE_KICKABLE; } void bobomb_spawn_coin(void) { - if (((o->oBehParams >> 8) & 0x1) == 0) { + if (!((o->oBehParams >> 8) & 0x01)) { obj_spawn_yellow_coins(o, 1); o->oBehParams = 0x100; set_object_respawn_info_bits(o, 1); @@ -28,70 +28,70 @@ void bobomb_spawn_coin(void) { } void bobomb_act_explode(void) { - struct Object *explosion; - if (o->oTimer < 5) + if (o->oTimer < 5) { cur_obj_scale(1.0 + (f32) o->oTimer / 5.0); - else { - explosion = spawn_object(o, MODEL_EXPLOSION, bhvExplosion); + } else { + struct Object *explosion = spawn_object(o, MODEL_EXPLOSION, bhvExplosion); explosion->oGraphYOffset += 100.0f; bobomb_spawn_coin(); create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000); + o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } } - void bobomb_check_interactions(void) { obj_set_hitbox(o, &sBobombHitbox); - if ((o->oInteractStatus & INT_STATUS_INTERACTED) != 0) - { - if ((o->oInteractStatus & INT_STATUS_MARIO_UNK1) != 0) - { + + if (o->oInteractStatus & INT_STATUS_INTERACTED) { + if (o->oInteractStatus & INT_STATUS_MARIO_KNOCKBACK_DMG) { o->oMoveAngleYaw = gMarioObject->header.gfx.angle[1]; - o->oForwardVel = 25.0; - o->oVelY = 30.0; + o->oForwardVel = 25.0f; + o->oVelY = 30.0f; o->oAction = BOBOMB_ACT_LAUNCHED; } - if ((o->oInteractStatus & INT_STATUS_TOUCHED_BOB_OMB) != 0) + if (o->oInteractStatus & INT_STATUS_TOUCHED_BOB_OMB) { o->oAction = BOBOMB_ACT_EXPLODE; + } o->oInteractStatus = 0; } - if (obj_attack_collided_from_other_object(o) == 1) + if (obj_attack_collided_from_other_object(o) == TRUE) { o->oAction = BOBOMB_ACT_EXPLODE; + } } void bobomb_act_patrol(void) { - UNUSED s8 filler[4]; - UNUSED s16 sp22; + UNUSED u8 filler[4]; + UNUSED s16 animFrame = o->header.gfx.animInfo.animFrame; s16 collisionFlags; - sp22 = o->header.gfx.animInfo.animFrame; - o->oForwardVel = 5.0; - + o->oForwardVel = 5.0f; collisionFlags = object_step(); - if ((obj_return_home_if_safe(o, o->oHomeX, o->oHomeY, o->oHomeZ, 400) == 1) + + if ((obj_return_home_if_safe(o, o->oHomeX, o->oHomeY, o->oHomeZ, 400) == TRUE) && (obj_check_if_facing_toward_angle(o->oMoveAngleYaw, o->oAngleToMario, 0x2000) == TRUE)) { o->oBobombFuseLit = 1; o->oAction = BOBOMB_ACT_CHASE_MARIO; } + obj_check_floor_death(collisionFlags, sObjFloor); } void bobomb_act_chase_mario(void) { UNUSED u8 filler[4]; - s16 sp1a, collisionFlags; - - sp1a = ++o->header.gfx.animInfo.animFrame; - o->oForwardVel = 20.0; + s16 animFrame = ++o->header.gfx.animInfo.animFrame; + s16 collisionFlags; + o->oForwardVel = 20.0f; collisionFlags = object_step(); - if (sp1a == 5 || sp1a == 16) + if (animFrame == 5 || animFrame == 16) { cur_obj_play_sound_2(SOUND_OBJ_BOBOMB_WALK); + } obj_turn_toward_object(o, gMarioObject, 16, 0x800); obj_check_floor_death(collisionFlags, sObjFloor); @@ -100,8 +100,9 @@ void bobomb_act_chase_mario(void) { void bobomb_act_launched(void) { s16 collisionFlags = 0; collisionFlags = object_step(); - if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) == OBJ_COL_FLAG_GROUNDED) - o->oAction = BOBOMB_ACT_EXPLODE; /* bit 0 */ + if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) == OBJ_COL_FLAG_GROUNDED) { + o->oAction = BOBOMB_ACT_EXPLODE; + } } void generic_bobomb_free_loop(void) { @@ -123,8 +124,9 @@ void generic_bobomb_free_loop(void) { break; case BOBOMB_ACT_LAVA_DEATH: - if (obj_lava_death() == 1) + if (obj_lava_death() == TRUE) { create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000); + } break; case BOBOMB_ACT_DEATH_PLANE_DEATH: @@ -135,8 +137,9 @@ void generic_bobomb_free_loop(void) { bobomb_check_interactions(); - if (o->oBobombFuseTimer >= 151) + if (o->oBobombFuseTimer > 150) { o->oAction = 3; + } } void stationary_bobomb_free_loop(void) { @@ -150,8 +153,9 @@ void stationary_bobomb_free_loop(void) { break; case BOBOMB_ACT_LAVA_DEATH: - if (obj_lava_death() == 1) + if (obj_lava_death() == TRUE) { create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000); + } break; case BOBOMB_ACT_DEATH_PLANE_DEATH: @@ -162,15 +166,17 @@ void stationary_bobomb_free_loop(void) { bobomb_check_interactions(); - if (o->oBobombFuseTimer >= 151) + if (o->oBobombFuseTimer > 150) { o->oAction = 3; + } } void bobomb_free_loop(void) { - if (o->oBehParams2ndByte == BOBOMB_BP_STYPE_GENERIC) + if (o->oBehParams2ndByte == BOBOMB_BP_STYPE_GENERIC) { generic_bobomb_free_loop(); - else + } else { stationary_bobomb_free_loop(); + } } void bobomb_held_loop(void) { @@ -179,7 +185,7 @@ void bobomb_held_loop(void) { cur_obj_set_pos_relative(gMarioObject, 0, 60.0f, 100.0); o->oBobombFuseLit = 1; - if (o->oBobombFuseTimer >= 151) { + if (o->oBobombFuseTimer > 150) { //! Although the Bob-omb's action is set to explode when the fuse timer expires, // bobomb_act_explode() will not execute until the bob-omb's held state changes. // This allows the Bob-omb to be regrabbed indefinitely. @@ -203,14 +209,12 @@ void bobomb_thrown_loop(void) { o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE; o->oHeldState = 0; - o->oFlags &= ~0x8; /* bit 3 */ - o->oForwardVel = 25.0; - o->oVelY = 20.0; + o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; + o->oForwardVel = 25.0f; + o->oVelY = 20.0f; o->oAction = BOBOMB_ACT_LAUNCHED; } -// sp18 = blinkTimer - void curr_obj_random_blink(s32 *blinkTimer) { if (*blinkTimer == 0) { if ((s16)(random_float() * 100.0f) == 0) { @@ -219,11 +223,16 @@ void curr_obj_random_blink(s32 *blinkTimer) { } } else { (*blinkTimer)++; - if (*blinkTimer >= 6) + + if (*blinkTimer > 5) { o->oAnimState = 0; - if (*blinkTimer >= 11) + } + + if (*blinkTimer > 10) { o->oAnimState = 1; - if (*blinkTimer >= 16) { + } + + if (*blinkTimer > 15) { o->oAnimState = 0; *blinkTimer = 0; } @@ -232,7 +241,8 @@ void curr_obj_random_blink(s32 *blinkTimer) { void bhv_bobomb_loop(void) { s8 dustPeriodMinus1; - if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 4000) != 0) { + + if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 4000)) { switch (o->oHeldState) { case HELD_FREE: bobomb_free_loop(); @@ -254,14 +264,16 @@ void bhv_bobomb_loop(void) { curr_obj_random_blink(&o->oBobombBlinkTimer); if (o->oBobombFuseLit == 1) { - if (o->oBobombFuseTimer >= 121) + if (o->oBobombFuseTimer > 120) { dustPeriodMinus1 = 1; - else + } else { dustPeriodMinus1 = 7; + } - if ((dustPeriodMinus1 & o->oBobombFuseTimer) - == 0) /* oBobombFuseTimer % 2 or oBobombFuseTimer % 8 */ + // oBobombFuseTimer % 2 or oBobombFuseTimer % 8 + if (!(dustPeriodMinus1 & o->oBobombFuseTimer)) { spawn_object(o, MODEL_SMOKE, bhvBobombFuseSmoke); + } cur_obj_play_sound_1(SOUND_AIR_BOBOMB_LIT_FUSE); @@ -278,15 +290,15 @@ void bhv_bobomb_fuse_smoke_init(void) { } void bhv_bobomb_buddy_init(void) { - o->oGravity = 2.5; - o->oFriction = 0.8; - o->oBuoyancy = 1.3; + o->oGravity = 2.5f; + o->oFriction = 0.8f; + o->oBuoyancy = 1.3f; o->oInteractionSubtype = INT_SUBTYPE_NPC; } void bobomb_buddy_act_idle(void) { UNUSED u8 filler[4]; - s16 sp1a = o->header.gfx.animInfo.animFrame; + s16 animFrame = o->header.gfx.animInfo.animFrame; UNUSED s16 collisionFlags = 0; o->oBobombBuddyPosXCopy = o->oPosX; @@ -295,14 +307,17 @@ void bobomb_buddy_act_idle(void) { collisionFlags = object_step(); - if ((sp1a == 5) || (sp1a == 16)) + if (animFrame == 5 || animFrame == 16) { cur_obj_play_sound_2(SOUND_OBJ_BOBOMB_WALK); + } - if (o->oDistanceToMario < 1000.0f) + if (o->oDistanceToMario < 1000.0f) { o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oAngleToMario, 0x140); + } - if (o->oInteractStatus == INT_STATUS_INTERACTED) + if (o->oInteractStatus == INT_STATUS_INTERACTED) { o->oAction = BOBOMB_BUDDY_ACT_TURN_TO_TALK; + } } /** @@ -320,31 +335,34 @@ void bobomb_buddy_cannon_dialog(s16 dialogFirstText, s16 dialogSecondText) { switch (o->oBobombBuddyCannonStatus) { case BOBOMB_BUDDY_CANNON_UNOPENED: buddyText = cutscene_object_with_dialog(CUTSCENE_DIALOG, o, dialogFirstText); - if (buddyText != 0) { + if (buddyText != DIALOG_RESPONSE_NONE) { save_file_set_cannon_unlocked(); cannonClosed = cur_obj_nearest_object_with_behavior(bhvCannonClosed); - if (cannonClosed != 0) + if (cannonClosed != NULL) { o->oBobombBuddyCannonStatus = BOBOMB_BUDDY_CANNON_OPENING; - else + } else { o->oBobombBuddyCannonStatus = BOBOMB_BUDDY_CANNON_STOP_TALKING; + } } break; case BOBOMB_BUDDY_CANNON_OPENING: cannonClosed = cur_obj_nearest_object_with_behavior(bhvCannonClosed); cutscene = cutscene_object(CUTSCENE_PREPARE_CANNON, cannonClosed); - if (cutscene == -1) + if (cutscene == -1) { o->oBobombBuddyCannonStatus = BOBOMB_BUDDY_CANNON_OPENED; + } break; case BOBOMB_BUDDY_CANNON_OPENED: buddyText = cutscene_object_with_dialog(CUTSCENE_DIALOG, o, dialogSecondText); - if (buddyText != 0) + if (buddyText != DIALOG_RESPONSE_NONE) { o->oBobombBuddyCannonStatus = BOBOMB_BUDDY_CANNON_STOP_TALKING; + } break; case BOBOMB_BUDDY_CANNON_STOP_TALKING: - set_mario_npc_dialog(0); + set_mario_npc_dialog(MARIO_DIALOG_STOP); o->activeFlags &= ~ACTIVE_FLAG_INITIATED_TIME_STOP; o->oBobombBuddyHasTalkedToMario = BOBOMB_BUDDY_HAS_TALKED; @@ -356,14 +374,14 @@ void bobomb_buddy_cannon_dialog(s16 dialogFirstText, s16 dialogSecondText) { } void bobomb_buddy_act_talk(void) { - if (set_mario_npc_dialog(1) == 2) { + if (set_mario_npc_dialog(MARIO_DIALOG_LOOK_FRONT) == MARIO_DIALOG_STATUS_SPEAK) { o->activeFlags |= ACTIVE_FLAG_INITIATED_TIME_STOP; switch (o->oBobombBuddyRole) { case BOBOMB_BUDDY_ROLE_ADVICE: if (cutscene_object_with_dialog(CUTSCENE_DIALOG, o, o->oBehParams2ndByte) != BOBOMB_BUDDY_BP_STYPE_GENERIC) { - set_mario_npc_dialog(0); + set_mario_npc_dialog(MARIO_DIALOG_STOP); o->activeFlags &= ~ACTIVE_FLAG_INITIATED_TIME_STOP; o->oBobombBuddyHasTalkedToMario = BOBOMB_BUDDY_HAS_TALKED; @@ -373,23 +391,28 @@ void bobomb_buddy_act_talk(void) { break; case BOBOMB_BUDDY_ROLE_CANNON: - if (gCurrCourseNum == COURSE_BOB) + if (gCurrCourseNum == COURSE_BOB) { bobomb_buddy_cannon_dialog(DIALOG_004, DIALOG_105); - else + } else { bobomb_buddy_cannon_dialog(DIALOG_047, DIALOG_106); + } break; } } } void bobomb_buddy_act_turn_to_talk(void) { - s16 sp1e = o->header.gfx.animInfo.animFrame; - if ((sp1e == 5) || (sp1e == 16)) + s16 animFrame = o->header.gfx.animInfo.animFrame; + + if (animFrame == 5 || animFrame == 16) { cur_obj_play_sound_2(SOUND_OBJ_BOBOMB_WALK); + } o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oAngleToMario, 0x1000); - if ((s16) o->oMoveAngleYaw == (s16) o->oAngleToMario) + + if ((s16) o->oMoveAngleYaw == (s16) o->oAngleToMario) { o->oAction = BOBOMB_BUDDY_ACT_TALK; + } cur_obj_play_sound_2(SOUND_ACTION_READ_SIGN); } diff --git a/src/game/behaviors/bomp.inc.c b/src/game/behaviors/bomp.inc.c index 26b38931..4109e2f9 100644 --- a/src/game/behaviors/bomp.inc.c +++ b/src/game/behaviors/bomp.inc.c @@ -1,4 +1,4 @@ -// bomp.c.inc +// bomp.inc.c void bhv_small_bomp_init(void) { o->oFaceAngleYaw -= 0x4000; @@ -9,7 +9,7 @@ void bhv_small_bomp_init(void) { void bhv_small_bomp_loop(void) { switch (o->oAction) { case BOMP_ACT_WAIT: - if (o->oTimer >= 101) { + if (o->oTimer > 100) { o->oAction = BOMP_ACT_POKE_OUT; o->oForwardVel = 30.0f; } @@ -18,7 +18,7 @@ void bhv_small_bomp_loop(void) { case BOMP_ACT_POKE_OUT: if (o->oPosX > 3450.0f) { o->oPosX = 3450.0f; - o->oForwardVel = 0; + o->oForwardVel = 0.0f; } if (o->oTimer == 15.0) { @@ -31,7 +31,7 @@ void bhv_small_bomp_loop(void) { case BOMP_ACT_EXTEND: if (o->oPosX > 3830.0f) { o->oPosX = 3830.0f; - o->oForwardVel = 0; + o->oForwardVel = 0.0f; } if (o->oTimer == 60) { @@ -45,7 +45,7 @@ void bhv_small_bomp_loop(void) { case BOMP_ACT_RETRACT: if (o->oPosX < 3330.0f) { o->oPosX = 3330.0f; - o->oForwardVel = 0; + o->oForwardVel = 0.0f; } if (o->oTimer == 90) { @@ -65,7 +65,7 @@ void bhv_large_bomp_init(void) { void bhv_large_bomp_loop(void) { switch (o->oAction) { case BOMP_ACT_WAIT: - if (o->oTimer >= 101) { + if (o->oTimer > 100) { o->oAction = BOMP_ACT_POKE_OUT; o->oForwardVel = 30.0f; } @@ -74,7 +74,7 @@ void bhv_large_bomp_loop(void) { case BOMP_ACT_POKE_OUT: if (o->oPosX > 3450.0f) { o->oPosX = 3450.0f; - o->oForwardVel = 0; + o->oForwardVel = 0.0f; } if (o->oTimer == 15.0) { @@ -87,7 +87,7 @@ void bhv_large_bomp_loop(void) { case BOMP_ACT_EXTEND: if (o->oPosX > 3830.0f) { o->oPosX = 3830.0f; - o->oForwardVel = 0; + o->oForwardVel = 0.0f; } if (o->oTimer == 60) { @@ -101,7 +101,7 @@ void bhv_large_bomp_loop(void) { case BOMP_ACT_RETRACT: if (o->oPosX < 3330.0f) { o->oPosX = 3330.0f; - o->oForwardVel = 0; + o->oForwardVel = 0.0f; } if (o->oTimer == 90) { diff --git a/src/game/behaviors/boo.inc.c b/src/game/behaviors/boo.inc.c index 32c01894..1f935acd 100644 --- a/src/game/behaviors/boo.inc.c +++ b/src/game/behaviors/boo.inc.c @@ -1,22 +1,24 @@ -// boo.c.inc +// boo.inc.c + +#define SPAWN_CASTLE_BOO_STAR_REQUIREMENT 12 static struct ObjectHitbox sBooGivingStarHitbox = { - /* interactType: */ 0, - /* downOffset: */ 0, + /* interactType: */ 0, + /* downOffset: */ 0, /* damageOrCoinValue: */ 3, - /* health: */ 3, - /* numLootCoins: */ 0, - /* radius: */ 140, - /* height: */ 80, - /* hurtboxRadius: */ 40, - /* hurtboxHeight: */ 60, + /* health: */ 3, + /* numLootCoins: */ 0, + /* radius: */ 140, + /* height: */ 80, + /* hurtboxRadius: */ 40, + /* hurtboxHeight: */ 60, }; // Relative positions static s16 sCourtyardBooTripletPositions[][3] = { - {0, 50, 0}, - {210, 110, 210}, - {-210, 70, -210} + { 0, 50, 0 }, + { 210, 110, 210 }, + { -210, 70, -210 }, }; static void boo_stop(void) { @@ -41,10 +43,8 @@ static s32 boo_should_be_stopped(void) { return TRUE; } - if (o->oRoom == 10) { - if (gTimeStopState & TIME_STOP_MARIO_OPENED_DOOR) { - return TRUE; - } + if (o->oRoom == 10 && (gTimeStopState & TIME_STOP_MARIO_OPENED_DOOR)) { + return TRUE; } } @@ -71,10 +71,8 @@ static s32 boo_should_be_active(void) { return TRUE; } } else if (!boo_should_be_stopped()) { - if ( - o->oDistanceToMario < activationRadius && - (o->oRoom == gMarioCurrentRoom || gMarioCurrentRoom == 0) - ) { + if (o->oDistanceToMario < activationRadius + && (o->oRoom == gMarioCurrentRoom || gMarioCurrentRoom == 0)) { return TRUE; } } @@ -84,21 +82,14 @@ static s32 boo_should_be_active(void) { void bhv_courtyard_boo_triplet_init(void) { s32 i; - struct Object *boo; - if (gHudDisplay.stars < 12) { + if (gHudDisplay.stars < SPAWN_CASTLE_BOO_STAR_REQUIREMENT) { obj_mark_for_deletion(o); } else { for (i = 0; i < 3; i++) { - boo = spawn_object_relative( - 0x01, - sCourtyardBooTripletPositions[i][0], - sCourtyardBooTripletPositions[i][1], - sCourtyardBooTripletPositions[i][2], - o, - MODEL_BOO, - bhvGhostHuntBoo - ); + struct Object *boo = spawn_object_relative( + 1, sCourtyardBooTripletPositions[i][0], sCourtyardBooTripletPositions[i][1], + sCourtyardBooTripletPositions[i][2], o, MODEL_BOO, bhvGhostHuntBoo); boo->oMoveAngleYaw = random_u16(); } @@ -124,14 +115,14 @@ static void boo_approach_target_opacity_and_update_scale(void) { } } - scale = (o->oOpacity/255.0f * 0.4 + 0.6) * o->oBooBaseScale; + scale = (o->oOpacity / 255.0f * 0.4 + 0.6) * o->oBooBaseScale; obj_scale(o, scale); // why no cur_obj_scale? was cur_obj_scale written later? } static void boo_oscillate(s32 ignoreOpacity) { o->oFaceAnglePitch = sins(o->oBooOscillationTimer) * 0x400; - if (o->oOpacity == 0xFF || ignoreOpacity == TRUE) { + if (o->oOpacity == 255 || ignoreOpacity == TRUE) { o->header.gfx.scale[0] = sins(o->oBooOscillationTimer) * 0.08 + o->oBooBaseScale; o->header.gfx.scale[1] = -sins(o->oBooOscillationTimer) * 0.08 + o->oBooBaseScale; o->header.gfx.scale[2] = o->header.gfx.scale[0]; @@ -145,15 +136,13 @@ static s32 boo_vanish_or_appear(void) { s16 relativeMarioFaceAngle = abs_angle_diff(o->oMoveAngleYaw, gMarioObject->oFaceAngleYaw); // magic? s16 relativeAngleToMarioThreshhold = 0x1568; - s16 relativeMarioFaceAngleThreshhold = 0x6b58; + s16 relativeMarioFaceAngleThreshhold = 0x6B58; s32 doneAppearing = FALSE; o->oVelY = 0.0f; - if ( - relativeAngleToMario > relativeAngleToMarioThreshhold || - relativeMarioFaceAngle < relativeMarioFaceAngleThreshhold - ) { + if (relativeAngleToMario > relativeAngleToMarioThreshhold + || relativeMarioFaceAngle < relativeMarioFaceAngleThreshhold) { if (o->oOpacity == 40) { o->oBooTargetOpacity = 255; cur_obj_play_sound_2(SOUND_OBJ_BOO_LAUGH_LONG); @@ -175,9 +164,9 @@ static void boo_set_move_yaw_for_during_hit(s32 hurt) { o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; o->oBooMoveYawBeforeHit = (f32) o->oMoveAngleYaw; - if (hurt != FALSE) { + if (hurt) { o->oBooMoveYawDuringHit = gMarioObject->oMoveAngleYaw; - } else if (coss((s16)o->oMoveAngleYaw - (s16)o->oAngleToMario) < 0.0f) { + } else if (coss((s16) o->oMoveAngleYaw - (s16) o->oAngleToMario) < 0.0f) { o->oBooMoveYawDuringHit = o->oMoveAngleYaw; } else { o->oBooMoveYawDuringHit = (s16)(o->oMoveAngleYaw + 0x8000); @@ -196,9 +185,9 @@ static void boo_move_during_hit(s32 roll, f32 fVel) { o->oVelY = coss(oscillationVel); o->oMoveAngleYaw = o->oBooMoveYawDuringHit; - if (roll != FALSE) { - o->oFaceAngleYaw += D_8032F0CC[o->oTimer]; - o->oFaceAngleRoll += D_8032F0CC[o->oTimer]; + if (roll) { + o->oFaceAngleYaw += sBooHitRotations[o->oTimer]; + o->oFaceAngleRoll += sBooHitRotations[o->oTimer]; } } @@ -223,11 +212,12 @@ static s32 boo_update_after_bounced_on(f32 a0) { } if (o->oTimer < 32) { - boo_move_during_hit(FALSE, D_8032F0CC[o->oTimer]/5000.0f * a0); + boo_move_during_hit(FALSE, sBooHitRotations[o->oTimer] / 5000.0f * a0); } else { cur_obj_become_tangible(); boo_reset_after_hit(); o->oAction = 1; + return TRUE; } @@ -243,13 +233,12 @@ static s32 big_boo_update_during_nonlethal_hit(f32 a0) { } if (o->oTimer < 32) { - boo_move_during_hit(TRUE, D_8032F0CC[o->oTimer]/5000.0f * a0); + boo_move_during_hit(TRUE, sBooHitRotations[o->oTimer] / 5000.0f * a0); } else if (o->oTimer < 48) { big_boo_shake_after_hit(); } else { cur_obj_become_tangible(); boo_reset_after_hit(); - o->oAction = 1; return TRUE; @@ -261,8 +250,6 @@ static s32 big_boo_update_during_nonlethal_hit(f32 a0) { // called every frame once mario lethally hits the boo until the boo is deleted, // returns whether death is complete static s32 boo_update_during_death(void) { - struct Object *parentBigBoo; - if (o->oTimer == 0) { o->oForwardVel = 40.0f; o->oMoveAngleYaw = gMarioObject->oMoveAngleYaw; @@ -278,14 +265,14 @@ static s32 boo_update_during_death(void) { o->oBooDeathStatus = BOO_DEATH_STATUS_DEAD; if (o->oBooParentBigBoo != NULL) { - parentBigBoo = o->oBooParentBigBoo; + struct Object *parentBigBoo = o->oBooParentBigBoo; #ifndef VERSION_JP if (!cur_obj_has_behavior(bhvBoo)) { +#endif parentBigBoo->oBigBooNumMinionBoosKilled++; +#ifndef VERSION_JP } -#else - parentBigBoo->oBigBooNumMinionBoosKilled++; #endif } @@ -312,7 +299,8 @@ static s32 boo_get_attack_status(void) { s32 attackStatus = BOO_NOT_ATTACKED; if (o->oInteractStatus & INT_STATUS_INTERACTED) { - if ((o->oInteractStatus & INT_STATUS_WAS_ATTACKED) && !obj_has_attack_type(ATTACK_FROM_ABOVE)) { + if ((o->oInteractStatus & INT_STATUS_WAS_ATTACKED) + && !obj_has_attack_type(ATTACK_FROM_ABOVE)) { cur_obj_become_intangible(); o->oInteractStatus = 0; @@ -338,7 +326,7 @@ static void boo_chase_mario(f32 a0, s16 a1, f32 a2) { s16 sp1A; if (boo_vanish_or_appear()) { - o->oInteractType = 0x8000; + o->oInteractType = INTERACT_BOUNCE_TOP; if (cur_obj_lateral_dist_from_mario_to_home() > 1500.0f) { sp1A = cur_obj_angle_to_home(); @@ -349,10 +337,11 @@ static void boo_chase_mario(f32 a0, s16 a1, f32 a2) { cur_obj_rotate_yaw_toward(sp1A, a1); o->oVelY = 0.0f; - if (mario_is_in_air_action() == 0) { + if (!mario_is_in_air_action()) { sp1C = o->oPosY - gMarioObject->oPosY; if (a0 < sp1C && sp1C < 500.0f) { - o->oVelY = increment_velocity_toward_range(o->oPosY, gMarioObject->oPosY + 50.0f, 10.f, 2.0f); + o->oVelY = increment_velocity_toward_range + (o->oPosY, gMarioObject->oPosY + 50.0f, 10.0f, 2.0f); } } @@ -383,7 +372,7 @@ static void boo_act_0(void) { o->oBooParentBigBoo = cur_obj_nearest_object_with_behavior(bhvGhostHuntBigBoo); o->oBooBaseScale = 1.0f; - o->oBooTargetOpacity = 0xFF; + o->oBooTargetOpacity = 255; if (boo_should_be_active()) { // Condition is met if the object is bhvBalconyBigBoo or bhvMerryGoRoundBoo @@ -417,6 +406,7 @@ static void boo_act_1(void) { } boo_chase_mario(-100.0f, o->oBooTurningSpeed + 0x180, 0.5f); + attackStatus = boo_get_attack_status(); if (boo_should_be_stopped()) { @@ -464,7 +454,7 @@ static void boo_act_4(void) { dialogID = DIALOG_107; } - if (cur_obj_update_dialog(2, 2, dialogID, 0)) { + if (cur_obj_update_dialog(MARIO_DIALOG_LOOK_UP, DIALOG_FLAG_TEXT_DEFAULT, dialogID, 0)) { create_sound_spawner(SOUND_OBJ_DYING_ENEMY1); obj_mark_for_deletion(o); @@ -480,7 +470,7 @@ static void (*sBooActions[])(void) = { boo_act_2, boo_act_3, boo_act_4, - boo_act_5 + boo_act_5, }; void bhv_boo_loop(void) { @@ -491,10 +481,9 @@ void bhv_boo_loop(void) { cur_obj_move_standard(78); boo_approach_target_opacity_and_update_scale(); - if (obj_has_behavior(o->parentObj, bhvMerryGoRoundBooManager)) { - if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) { - o->parentObj->oMerryGoRoundBooManagerNumBoosKilled++; - } + if (obj_has_behavior(o->parentObj, bhvMerryGoRoundBooManager) + && o->activeFlags == ACTIVE_FLAG_DEACTIVATED) { + o->parentObj->oMerryGoRoundBooManagerNumBoosKilled++; } o->oInteractStatus = 0; @@ -510,11 +499,13 @@ static void big_boo_act_0(void) { o->oBooParentBigBoo = NULL; + if (boo_should_be_active() #ifndef VERSION_JP - if (boo_should_be_active() && gDebugInfo[5][0] + 5 <= o->oBigBooNumMinionBoosKilled) { + && o->oBigBooNumMinionBoosKilled >= gDebugInfo[DEBUG_PAGE_ENEMYINFO][0] + 5 #else - if (boo_should_be_active() && o->oBigBooNumMinionBoosKilled >= 5) { + && o->oBigBooNumMinionBoosKilled >= 5 #endif + ) { o->oAction = 1; cur_obj_set_pos_to_home(); @@ -522,7 +513,7 @@ static void big_boo_act_0(void) { cur_obj_unhide(); - o->oBooTargetOpacity = 0xFF; + o->oBooTargetOpacity = 255; o->oBooBaseScale = 3.0f; o->oHealth = 3; @@ -569,7 +560,7 @@ static void big_boo_act_1(void) { o->oAction = 3; } - if (attackStatus == 1) { + if (attackStatus == BOO_ATTACKED) { create_sound_spawner(SOUND_OBJ_THWOMP); } } @@ -644,9 +635,9 @@ static void big_boo_act_4(void) { if (o->oTimer > 60 && o->oDistanceToMario < 600.0f) { obj_set_pos(o, 973, 0, 717); - spawn_object_relative(0, 0, 0, 0, o, MODEL_BBH_STAIRCASE_STEP, bhvBooBossSpawnedBridge); - spawn_object_relative(1, 0, 0, -200, o, MODEL_BBH_STAIRCASE_STEP, bhvBooBossSpawnedBridge); - spawn_object_relative(2, 0, 0, 200, o, MODEL_BBH_STAIRCASE_STEP, bhvBooBossSpawnedBridge); + spawn_object_relative(0, 0, 0, 0, o, MODEL_BBH_STAIRCASE_STEP, bhvBooStaircase); + spawn_object_relative(1, 0, 0, -200, o, MODEL_BBH_STAIRCASE_STEP, bhvBooStaircase); + spawn_object_relative(2, 0, 0, 200, o, MODEL_BBH_STAIRCASE_STEP, bhvBooStaircase); obj_mark_for_deletion(o); } @@ -660,7 +651,7 @@ static void (*sBooGivingStarActions[])(void) = { big_boo_act_1, big_boo_act_2, big_boo_act_3, - big_boo_act_4 + big_boo_act_4, }; void bhv_big_boo_loop(void) { @@ -675,12 +666,13 @@ void bhv_big_boo_loop(void) { cur_obj_move_standard(78); boo_approach_target_opacity_and_update_scale(); + o->oInteractStatus = 0; } static void boo_with_cage_act_0(void) { o->oBooParentBigBoo = NULL; - o->oBooTargetOpacity = 0xFF; + o->oBooTargetOpacity = 255; o->oBooBaseScale = 2.0f; cur_obj_scale(2.0f); @@ -724,12 +716,10 @@ static void boo_with_cage_act_3(void) { } void bhv_boo_with_cage_init(void) { - struct Object* cage; - - if (gHudDisplay.stars < 12) { + if (gHudDisplay.stars < SPAWN_CASTLE_BOO_STAR_REQUIREMENT) { obj_mark_for_deletion(o); } else { - cage = spawn_object(o, MODEL_HAUNTED_CAGE, bhvBooCage); + struct Object *cage = spawn_object(o, MODEL_HAUNTED_CAGE, bhvBooCage); cage->oBehParams = o->oBehParams; } } @@ -738,11 +728,10 @@ static void (*sBooWithCageActions[])(void) = { boo_with_cage_act_0, boo_with_cage_act_1, boo_with_cage_act_2, - boo_with_cage_act_3 + boo_with_cage_act_3, }; -void bhv_boo_with_cage_loop(void) -{ +void bhv_boo_with_cage_loop(void) { //PARTIAL_UPDATE cur_obj_update_floor_and_walls(); @@ -750,6 +739,7 @@ void bhv_boo_with_cage_loop(void) cur_obj_move_standard(78); boo_approach_target_opacity_and_update_scale(); + o->oInteractStatus = 0; } @@ -759,7 +749,8 @@ void bhv_merry_go_round_boo_manager_loop(void) { if (o->oDistanceToMario < 1000.0f) { if (o->oMerryGoRoundBooManagerNumBoosKilled < 5) { if (o->oMerryGoRoundBooManagerNumBoosSpawned != 5) { - if (o->oMerryGoRoundBooManagerNumBoosSpawned - o->oMerryGoRoundBooManagerNumBoosKilled < 2) { + if (o->oMerryGoRoundBooManagerNumBoosSpawned + - o->oMerryGoRoundBooManagerNumBoosKilled < 2) { spawn_object(o, MODEL_BOO, bhvMerryGoRoundBoo); o->oMerryGoRoundBooManagerNumBoosSpawned++; } @@ -768,7 +759,7 @@ void bhv_merry_go_round_boo_manager_loop(void) { o->oAction++; } - if (o->oMerryGoRoundBooManagerNumBoosKilled > 4) { + if (o->oMerryGoRoundBooManagerNumBoosKilled >= 5) { struct Object *boo = spawn_object(o, MODEL_BOO, bhvMerryGoRoundBigBoo); obj_copy_behavior_params(boo, o); @@ -783,12 +774,14 @@ void bhv_merry_go_round_boo_manager_loop(void) { } break; + case 1: if (o->oTimer > 60) { o->oAction = 0; } break; + case 2: break; } @@ -810,7 +803,7 @@ void bhv_boo_in_castle_loop(void) { if (o->oAction == 0) { cur_obj_hide(); - if (gHudDisplay.stars < 12) { + if (gHudDisplay.stars < SPAWN_CASTLE_BOO_STAR_REQUIREMENT) { obj_mark_for_deletion(o); } @@ -863,7 +856,7 @@ void bhv_boo_in_castle_loop(void) { cur_obj_move_using_fvel_and_gravity(); } -void bhv_boo_boss_spawned_bridge_loop(void) { +void bhv_boo_staircase(void) { f32 targetY; switch (o->oBehParams2ndByte) { @@ -878,7 +871,7 @@ void bhv_boo_boss_spawned_bridge_loop(void) { break; } - switch(o->oAction) { + switch (o->oAction) { case 0: o->oPosY = o->oHomeY - 620.0f; o->oAction++; @@ -893,16 +886,18 @@ void bhv_boo_boss_spawned_bridge_loop(void) { } break; + case 2: if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_GENERAL_UNKNOWN4_LOWPRIO); } - if (cur_obj_move_up_and_down(o->oTimer)) { + if (jiggle_bbh_stair(o->oTimer)) { o->oAction++; } break; + case 3: if (o->oTimer == 0 && o->oBehParams2ndByte == 1) { play_puzzle_jingle(); diff --git a/src/game/behaviors/boo_cage.inc.c b/src/game/behaviors/boo_cage.inc.c index 24e4e062..76f1f04e 100644 --- a/src/game/behaviors/boo_cage.inc.c +++ b/src/game/behaviors/boo_cage.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvBooCage. * This is the cage inside the big boo in the castle courtyard @@ -10,22 +11,22 @@ * Mario has to enter to enter BBH. */ static struct ObjectHitbox sBooCageHitbox = { - /* interactType: */ INTERACT_BBH_ENTRANCE, - /* downOffset: */ 0, + /* interactType: */ INTERACT_BBH_ENTRANCE, + /* downOffset: */ 0, /* damageOrCoinValue: */ 0, - /* health: */ 0, - /* numLootCoins: */ 0, - /* radius: */ 120, - /* height: */ 300, - /* hurtboxRadius: */ 0, - /* hurtboxHeight: */ 0, + /* health: */ 0, + /* numLootCoins: */ 0, + /* radius: */ 120, + /* height: */ 300, + /* hurtboxRadius: */ 0, + /* hurtboxHeight: */ 0, }; /** * Update function for bhvBooCage. */ void bhv_boo_cage_loop(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; obj_set_hitbox(o, &sBooCageHitbox); @@ -50,6 +51,7 @@ void bhv_boo_cage_loop(void) { } break; + case BOO_CAGE_ACT_FALLING: // Reset pitch and roll. This is useless, since the cage never rotates. // Was it meant to rotate inside the boo, like the beta boo key? @@ -78,6 +80,7 @@ void bhv_boo_cage_loop(void) { } break; + case BOO_CAGE_ACT_ON_GROUND: // Allow Mario to enter the cage once it's still on the ground. cur_obj_become_tangible(); @@ -91,6 +94,7 @@ void bhv_boo_cage_loop(void) { } break; + case BOO_CAGE_ACT_MARIO_JUMPING_IN: // All this action does is wait 100 frames after Mario starts // jumping into the cage to set the action to BOO_CAGE_ACT_USELESS, @@ -101,6 +105,7 @@ void bhv_boo_cage_loop(void) { } break; + case BOO_CAGE_ACT_USELESS: break; } diff --git a/src/game/behaviors/boulder.inc.c b/src/game/behaviors/boulder.inc.c index 18bd53fb..7a685bbd 100644 --- a/src/game/behaviors/boulder.inc.c +++ b/src/game/behaviors/boulder.inc.c @@ -1,4 +1,4 @@ -// boulder.c.inc +// boulder.inc.c void bhv_big_boulder_init(void) { o->oHomeX = o->oPosX; @@ -11,24 +11,27 @@ void bhv_big_boulder_init(void) { } void boulder_act_1(void) { - s16 sp1E; + s16 collisionFlags = object_step_without_floor_orient(); - sp1E = object_step_without_floor_orient(); - if ((sp1E & 0x09) == 0x01 && o->oVelY > 10.0f) { + if ((collisionFlags & OBJ_COL_FLAGS_LANDED) == OBJ_COL_FLAG_GROUNDED && o->oVelY > 10.0f) { cur_obj_play_sound_2(SOUND_GENERAL_GRINDEL_ROLL); spawn_mist_particles(); } - if (o->oForwardVel > 70.0) + if (o->oForwardVel > 70.0) { o->oForwardVel = 70.0f; + } - if (o->oPosY < -1000.0f) + if (o->oPosY < -1000.0f) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } } void bhv_big_boulder_loop(void) { cur_obj_scale(1.5f); + o->oGraphYOffset = 270.0f; + switch (o->oAction) { case 0: o->oForwardVel = 40.0f; @@ -47,20 +50,23 @@ void bhv_big_boulder_loop(void) { void bhv_big_boulder_generator_loop(void) { struct Object *sp1C; + if (o->oTimer >= 256) { o->oTimer = 0; } - if (!current_mario_room_check(4) || is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1500)) + if (!current_mario_room_check(4) + || is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1500)) { return; + } if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 6000)) { - if ((o->oTimer & 0x3F) == 0) { + if (!(o->oTimer & 0x3F)) { sp1C = spawn_object(o, MODEL_HMC_ROLLING_ROCK, bhvBigBoulder); sp1C->oMoveAngleYaw = random_float() * 4096.0f; } } else { - if ((o->oTimer & 0x7F) == 0) { + if (!(o->oTimer & 0x7F)) { sp1C = spawn_object(o, MODEL_HMC_ROLLING_ROCK, bhvBigBoulder); sp1C->oMoveAngleYaw = random_float() * 4096.0f; } diff --git a/src/game/behaviors/bouncing_fireball.inc.c b/src/game/behaviors/bouncing_fireball.inc.c index 89dcfd18..49b8bdc6 100644 --- a/src/game/behaviors/bouncing_fireball.inc.c +++ b/src/game/behaviors/bouncing_fireball.inc.c @@ -1,54 +1,79 @@ -// bouncing_fireball.c.inc +// bouncing_fireball.inc.c void bhv_bouncing_fireball_flame_loop(void) { o->activeFlags |= ACTIVE_FLAG_UNK10; + cur_obj_update_floor_and_walls(); + switch (o->oAction) { case 0: if (o->oTimer == 0) { o->oAnimState = random_float() * 10.0f; o->oVelY = 30.0f; } - if (o->oMoveFlags & OBJ_MOVE_LANDED) + + if (o->oMoveFlags & OBJ_MOVE_LANDED) { o->oAction++; + } break; + case 1: if (o->oTimer == 0) { o->oVelY = 50.0f; o->oForwardVel = 30.0f; } - if (o->oMoveFlags & (OBJ_MOVE_UNDERWATER_ON_GROUND | OBJ_MOVE_AT_WATER_SURFACE | OBJ_MOVE_ON_GROUND) && o->oTimer > 100) + + if (o->oMoveFlags + & (OBJ_MOVE_ON_GROUND | OBJ_MOVE_AT_WATER_SURFACE | OBJ_MOVE_UNDERWATER_ON_GROUND) + && o->oTimer > 100) { obj_mark_for_deletion(o); + } break; } - if (o->oTimer > 300) + + if (o->oTimer > 300) { obj_mark_for_deletion(o); + } + cur_obj_move_standard(78); + o->oInteractStatus = 0; } void bhv_bouncing_fireball_loop(void) { struct Object *sp2C; f32 sp28; + switch (o->oAction) { case 0: - if (o->oDistanceToMario < 2000.0f) + if (o->oDistanceToMario < 2000.0f) { o->oAction = 1; + } break; + case 1: sp2C = spawn_object(o, MODEL_RED_FLAME, bhvBouncingFireballFlame); sp28 = (10 - o->oTimer) * 0.5; + obj_scale_xyz(sp2C, sp28, sp28, sp28); - if (o->oTimer == 0) + + if (o->oTimer == 0) { obj_become_tangible(sp2C); - if (o->oTimer > 10) + } + + if (o->oTimer > 10) { o->oAction++; + } break; + case 2: - if (o->oTimer == 0) + if (o->oTimer == 0) { o->oBouncingFireBallUnkF4 = random_float() * 100.0f; - if (o->oBouncingFireBallUnkF4 + 100 < o->oTimer) + } + + if (o->oBouncingFireBallUnkF4 + 100 < o->oTimer) { o->oAction = 0; + } break; } } diff --git a/src/game/behaviors/bowling_ball.inc.c b/src/game/behaviors/bowling_ball.inc.c index f1e16cb1..34fefb36 100644 --- a/src/game/behaviors/bowling_ball.inc.c +++ b/src/game/behaviors/bowling_ball.inc.c @@ -1,4 +1,4 @@ -// bowling_ball.c.inc +// bowling_ball.inc.c static struct ObjectHitbox sBowlingBallHitbox = { /* interactType: */ INTERACT_DAMAGE, @@ -48,8 +48,9 @@ void bhv_bowling_ball_init(void) { void bowling_ball_set_hitbox(void) { obj_set_hitbox(o, &sBowlingBallHitbox); - if (o->oInteractStatus & INT_STATUS_INTERACTED) + if (o->oInteractStatus & INT_STATUS_INTERACTED) { o->oInteractStatus = 0; + } } void bowling_ball_set_waypoints(void) { @@ -78,13 +79,16 @@ void bowling_ball_set_waypoints(void) { void bhv_bowling_ball_roll_loop(void) { s16 collisionFlags; - s32 sp18; + s32 followStatus; +#ifdef AVOID_UB + followStatus = 0; +#endif bowling_ball_set_waypoints(); collisionFlags = object_step(); //! Uninitialzed parameter, but the parameter is unused in the called function - sp18 = cur_obj_follow_path(sp18); + followStatus = cur_obj_follow_path(followStatus); o->oBowlingBallTargetYaw = o->oPathedTargetYaw; o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oBowlingBallTargetYaw, 0x400); @@ -94,7 +98,7 @@ void bhv_bowling_ball_roll_loop(void) { bowling_ball_set_hitbox(); - if (sp18 == -1) { + if (followStatus == PATH_REACHED_END) { if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 7000)) { spawn_mist_particles(); spawn_mist_particles_variable(0, 0, 92.0f); @@ -103,17 +107,21 @@ void bhv_bowling_ball_roll_loop(void) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } - if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) && (o->oVelY > 5.0f)) + if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) && (o->oVelY > 5.0f)) { cur_obj_play_sound_2(SOUND_GENERAL_QUIET_POUND1_LOWPRIO); + } } -void bhv_bowling_ball_initializeLoop(void) { - s32 sp1c; +void bhv_bowling_ball_initialize_loop(void) { + s32 followStatus; +#ifdef AVOID_UB + followStatus = 0; +#endif bowling_ball_set_waypoints(); //! Uninitialzed parameter, but the parameter is unused in the called function - sp1c = cur_obj_follow_path(sp1c); + followStatus = cur_obj_follow_path(followStatus); o->oMoveAngleYaw = o->oPathedTargetYaw; @@ -146,7 +154,7 @@ void bhv_bowling_ball_loop(void) { switch (o->oAction) { case BBALL_ACT_INITIALIZE: o->oAction = BBALL_ACT_ROLL; - bhv_bowling_ball_initializeLoop(); + bhv_bowling_ball_initialize_loop(); break; case BBALL_ACT_ROLL: @@ -154,8 +162,9 @@ void bhv_bowling_ball_loop(void) { break; } - if (o->oBehParams2ndByte != 4) + if (o->oBehParams2ndByte != BBALL_BP_STYPE_THI_SMALL) { set_camera_shake_from_point(SHAKE_POS_BOWLING_BALL, o->oPosX, o->oPosY, o->oPosZ); + } set_object_visibility(o, 4000); } @@ -180,42 +189,39 @@ void bhv_generic_bowling_ball_spawner_init(void) { } void bhv_generic_bowling_ball_spawner_loop(void) { - struct Object *bowlingBall; - - if (o->oTimer == 256) + if (o->oTimer == 256) { o->oTimer = 0; + } if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1000) - || (o->oPosY < gMarioObject->header.gfx.pos[1])) + || o->oPosY < gMarioObject->header.gfx.pos[1]) { return; + } - if ((o->oTimer & o->oBBallSpawnerPeriodMinus1) == 0) /* Modulus */ - { - if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, o->oBBallSpawnerMaxSpawnDist)) { - if ((s32)(random_float() * o->oBBallSpawnerSpawnOdds) == 0) { - bowlingBall = spawn_object(o, MODEL_BOWLING_BALL, bhvBowlingBall); - bowlingBall->oBehParams2ndByte = o->oBehParams2ndByte; - } + if ((o->oTimer & o->oBBallSpawnerPeriodMinus1) == 0) { /* Modulus */ + if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, o->oBBallSpawnerMaxSpawnDist) + && (s32)(random_float() * o->oBBallSpawnerSpawnOdds) == 0) { + struct Object *bowlingBall = spawn_object(o, MODEL_BOWLING_BALL, bhvBowlingBall); + bowlingBall->oBehParams2ndByte = o->oBehParams2ndByte; } } } void bhv_thi_bowling_ball_spawner_loop(void) { - struct Object *bowlingBall; - - if (o->oTimer == 256) + if (o->oTimer == 256) { o->oTimer = 0; + } if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 800) - || (o->oPosY < gMarioObject->header.gfx.pos[1])) + || o->oPosY < gMarioObject->header.gfx.pos[1]) { return; + } if ((o->oTimer % 64) == 0) { - if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 12000)) { - if ((s32)(random_float() * 1.5) == 0) { - bowlingBall = spawn_object(o, MODEL_BOWLING_BALL, bhvBowlingBall); - bowlingBall->oBehParams2ndByte = o->oBehParams2ndByte; - } + if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 12000) + && (s32)(random_float() * 1.5) == 0) { + struct Object *bowlingBall = spawn_object(o, MODEL_BOWLING_BALL, bhvBowlingBall); + bowlingBall->oBehParams2ndByte = o->oBehParams2ndByte; } } } @@ -231,8 +237,9 @@ void bhv_bob_pit_bowling_ball_loop(void) { UNUSED s16 collisionFlags = object_step(); find_floor_height_and_data(o->oPosX, o->oPosY, o->oPosZ, &sp1c); - if ((sp1c->normalX == 0) && (sp1c->normalZ == 0)) + if ((sp1c->normalX == 0) && (sp1c->normalZ == 0)) { o->oForwardVel = 28.0f; + } bowling_ball_set_hitbox(); set_camera_shake_from_point(SHAKE_POS_BOWLING_BALL, o->oPosX, o->oPosY, o->oPosZ); @@ -253,6 +260,7 @@ void bhv_free_bowling_ball_init(void) { void bhv_free_bowling_ball_roll_loop(void) { s16 collisionFlags = object_step(); + bowling_ball_set_hitbox(); if (o->oForwardVel > 10.0f) { @@ -260,8 +268,9 @@ void bhv_free_bowling_ball_roll_loop(void) { cur_obj_play_sound_1(SOUND_ENV_UNKNOWN2); } - if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) && !(collisionFlags & OBJ_COL_FLAGS_LANDED)) + if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) && !(collisionFlags & OBJ_COL_FLAGS_LANDED)) { cur_obj_play_sound_2(SOUND_GENERAL_QUIET_POUND1_LOWPRIO); + } if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 6000)) { o->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE; @@ -292,8 +301,9 @@ void bhv_free_bowling_ball_loop(void) { break; case FREE_BBALL_ACT_RESET: - if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 5000)) + if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 5000)) { o->oAction = FREE_BBALL_ACT_IDLE; + } break; } } diff --git a/src/game/behaviors/bowser.inc.c b/src/game/behaviors/bowser.inc.c index 97cba2af..2cd9a96c 100644 --- a/src/game/behaviors/bowser.inc.c +++ b/src/game/behaviors/bowser.inc.c @@ -1,114 +1,177 @@ -// bowser.c.inc -void bowser_tail_anchor_act_0(void) { +/** + * Behavior for Bowser and it's actions (Tail, Flame, Body) + */ + +// Bowser's Tail + +/** + * Checks whenever the Bowser and his tail should be intangible or not + * By default it starts tangible + */ +void bowser_tail_anchor_act_default(void) { struct Object *bowser = o->parentObj; cur_obj_become_tangible(); cur_obj_scale(1.0f); - if (bowser->oAction == 19) + + if (bowser->oAction == BOWSER_ACT_TILT_LAVA_PLATFORM) { + // Bowser cannot be touched when he tilts BitFS platform bowser->oIntangibleTimer = -1; - else if (obj_check_if_collided_with_object(o, gMarioObject)) { + } else if (obj_check_if_collided_with_object(o, gMarioObject)) { + // When Mario collides his tail, it now gets + // intangible so he can grab it through bowser->oIntangibleTimer = 0; - o->oAction = 2; - } else + o->oAction = BOWSER_ACT_TAIL_TOUCHED_MARIO; + } else { bowser->oIntangibleTimer = -1; + } } -void bowser_tail_anchor_act_1(void) { - if (o->oTimer > 30) - o->oAction = 0; +/** + * While Bowser get's thrown, wait 30 frames then + * return to the default tail action check + */ +void bowser_tail_anchor_thrown(void) { + if (o->oTimer > 30) { + o->oAction = BOWSER_ACT_TAIL_DEFAULT; + } } -void bowser_tail_anchor_act_2(void) { - if (o->parentObj->oAction == 19) { +/** + * Makes the tail intangible so Mario can grab it + */ +void bowser_tail_anchor_act_touched_mario(void) { + // Return to main action when Bowser tilts BitFS platform + if (o->parentObj->oAction == BOWSER_ACT_TILT_LAVA_PLATFORM) { o->parentObj->oIntangibleTimer = -1; - o->oAction = 0; + o->oAction = BOWSER_ACT_TAIL_DEFAULT; } cur_obj_become_intangible(); } -void (*sBowserTailAnchorActions[])(void) = { bowser_tail_anchor_act_0, bowser_tail_anchor_act_1, - bowser_tail_anchor_act_2 }; -s8 D_8032F4FC[] = { 7, 8, 9, 12, 13, 14, 15, 4, 3, 16, 17, 19, 3, 3, 3, 3 }; -s16 D_8032F50C[] = { 60, 0 }; -s16 D_8032F510[] = { 50, 0 }; -s8 D_8032F514[] = { 24, 42, 60, -1 }; -s16 sBowserDefeatedDialogText[3] = { DIALOG_119, DIALOG_120, DIALOG_121 }; -s16 D_8032F520[][3] = { { 1, 10, 40 }, { 0, 0, 74 }, { -1, -10, 114 }, { 1, -20, 134 }, - { -1, 20, 154 }, { 1, 40, 164 }, { -1, -40, 174 }, { 1, -80, 179 }, - { -1, 80, 184 }, { 1, 160, 186 }, { -1, -160, 186 }, { 1, 0, 0 }, }; +void (*sBowserTailAnchorActions[])(void) = { + bowser_tail_anchor_act_default, + bowser_tail_anchor_thrown, + bowser_tail_anchor_act_touched_mario, +}; +/** + * Bowser's tail main loop + */ void bhv_bowser_tail_anchor_loop(void) { + // Call its actions cur_obj_call_action_function(sBowserTailAnchorActions); + // Position the tail o->oParentRelativePosX = 90.0f; - if (o->parentObj->oAction == 4) + + // Make it intangible while Bowser is dead + if (o->parentObj->oAction == BOWSER_ACT_DEAD) { o->parentObj->oIntangibleTimer = -1; + } + o->oInteractStatus = 0; } +// Bowser's Flame + +/** + * Bowser's Flame spawn main loop + */ void bhv_bowser_flame_spawn_loop(void) { struct Object *bowser = o->parentObj; - s32 sp30; - f32 sp2C; - f32 sp28; - f32 sp24 = coss(bowser->oMoveAngleYaw); - f32 sp20 = sins(bowser->oMoveAngleYaw); - s16 *sp1C = segmented_to_virtual(bowser_seg6_unkmoveshorts_060576FC); - if (bowser->oSoundStateID == 6) { - sp30 = bowser->header.gfx.animInfo.animFrame + 1.0f; - if (bowser->header.gfx.animInfo.curAnim->loopEnd == sp30) - sp30 = 0; - if (sp30 > 45 && sp30 < 85) { + s32 animFrame; + f32 posX; + f32 posZ; + f32 cossYaw = coss(bowser->oMoveAngleYaw); + f32 sinsYaw = sins(bowser->oMoveAngleYaw); + s16 *data = segmented_to_virtual(dBowserFlamesOrientationValues); + + // Check for Bowser breathing animation + if (bowser->oSoundStateID == BOWSER_ANIM_BREATH) { + + // Start counting anim frames then reset it when it ends + animFrame = bowser->header.gfx.animInfo.animFrame + 1.0f; + if (bowser->header.gfx.animInfo.curAnim->loopEnd == animFrame) { + animFrame = 0; + } + + // Bowser is breathing, play sound and adjust flame position + // each animFrame based off the orientantion data + if (animFrame > 45 && animFrame < 85) { cur_obj_play_sound_1(SOUND_AIR_BOWSER_SPIT_FIRE); - sp2C = sp1C[5 * sp30]; - sp28 = sp1C[5 * sp30 + 2]; - o->oPosX = bowser->oPosX + (sp28 * sp20 + sp2C * sp24); - o->oPosY = bowser->oPosY + sp1C[5 * sp30 + 1]; - o->oPosZ = bowser->oPosZ + (sp28 * sp24 - sp2C * sp20); - o->oMoveAnglePitch = sp1C[5 * sp30 + 4] + 0xC00; - o->oMoveAngleYaw = sp1C[5 * sp30 + 3] + (s16) bowser->oMoveAngleYaw; - if (!(sp30 & 1)) + posX = data[5 * animFrame]; + posZ = data[5 * animFrame + 2]; + o->oPosX = bowser->oPosX + (posZ * sinsYaw + posX * cossYaw); + o->oPosY = bowser->oPosY + data[5 * animFrame + 1]; + o->oPosZ = bowser->oPosZ + (posZ * cossYaw - posX * sinsYaw); + o->oMoveAnglePitch = data[5 * animFrame + 4] + 0xC00; + o->oMoveAngleYaw = data[5 * animFrame + 3] + (s16) bowser->oMoveAngleYaw; + // Spawns the flames on a non-odd animFrame value + if (!(animFrame & 1)) { spawn_object(o, MODEL_RED_FLAME, bhvFlameMovingForwardGrowing); + } } } } +/** + * Bowser's Body main loop + */ void bhv_bowser_body_anchor_loop(void) { + // Copy position and angles from Bowser itself obj_copy_pos_and_angle(o, o->parentObj); - if (o->parentObj->oAction == 4) { -#ifndef VERSION_JP - if (o->parentObj->oSubAction == 11) + // If Bowser is dead, set interaction type to text + // so that he can be ready to speak his dialog + if (o->parentObj->oAction == BOWSER_ACT_DEAD) { +#if BUGFIX_BOWSER_COLLIDE_BITS_DEAD + // Clear interaction type at the last sub action in BitS + // Fixes collision coliding after defeating him + if (o->parentObj->oSubAction == BOWSER_SUB_ACT_DEAD_FINAL_END_OVER) { o->oInteractType = 0; - else - o->oInteractType = 0x800000; + } else { + o->oInteractType = INTERACT_TEXT; + } #else - o->oInteractType = 0x800000; + o->oInteractType = INTERACT_TEXT; #endif } else { - o->oInteractType = 8; - if (o->parentObj->oOpacity < 100) + // Do damage if Mario touches Bowser + o->oInteractType = INTERACT_DAMAGE; + // Make body intangible while is transparent + // in BitFS (Teleporting) + if (o->parentObj->oOpacity < 100) { cur_obj_become_intangible(); - else + } else { cur_obj_become_tangible(); + } } - if (o->parentObj->oHeldState != HELD_FREE) + // Make body intangible while Bowser is getting grabbed + if (o->parentObj->oHeldState != HELD_FREE) { cur_obj_become_intangible(); + } o->oInteractStatus = 0; } +/** + * Bowser's shockwave attack, spawns only in BitS + */ s32 bowser_spawn_shockwave(void) { - struct Object *wave; - if (o->oBehParams2ndByte == 2) { - wave = spawn_object(o, MODEL_BOWSER_WAVE, bhvBowserShockWave); + if (o->oBehParams2ndByte == BOWSER_BP_BITS) { + struct Object *wave = spawn_object(o, MODEL_BOWSER_WAVE, bhvBowserShockWave); wave->oPosY = o->oFloorHeight; - return 1; + return TRUE; } - return 0; + return FALSE; } -void bowser_bounce(s32 *a) { +/** + * Misc effects that Bowser plays when he lands with drastic actions + * Plays step sound, spawns particles and changes camera event + */ +void bowser_bounce_effects(s32 *timer) { if (o->oMoveFlags & OBJ_MOVE_LANDED) { - a[0]++; - if (a[0] < 4) { + (*timer)++; + if (*timer < 4) { cur_obj_start_cam_event(o, CAM_EVENT_BOWSER_THROW_BOUNCE); spawn_mist_particles_variable(0, 0, 60.0f); cur_obj_play_sound_2(SOUND_OBJ_BOWSER_WALK); @@ -116,557 +179,854 @@ void bowser_bounce(s32 *a) { } } -#define BITDW (o->oBehParams2ndByte == 0) -#define BITFS (o->oBehParams2ndByte == 1) -#define BITS (o->oBehParams2ndByte == 2) - +/** + * Makes Bowser look up and walk on an specific animation frame + * Returns TRUE if the animation is almost over + */ s32 bowser_set_anim_look_up_and_walk(void) { - cur_obj_init_animation_with_sound(15); - if (cur_obj_check_anim_frame(21)) + cur_obj_init_animation_with_sound(BOWSER_ANIM_LOOK_UP_START_WALK); + if (cur_obj_check_anim_frame(21)) { o->oForwardVel = 3.0f; - if (cur_obj_check_if_near_animation_end()) - return 1; - else - return 0; + } + if (cur_obj_check_if_near_animation_end()) { + return TRUE; + } else { + return FALSE; + } } +/** + * Makes Bowser do a slow gait (or slow walk) + * Returns TRUE if the animation is almost over + */ s32 bowser_set_anim_slow_gait(void) { o->oForwardVel = 3.0f; - cur_obj_init_animation_with_sound(13); - if (cur_obj_check_if_near_animation_end()) - return 1; - else - return 0; + cur_obj_init_animation_with_sound(BOWSER_ANIM_SLOW_GAIT); + if (cur_obj_check_if_near_animation_end()) { + return TRUE; + } else { + return FALSE; + } } -s32 bowser_set_anim_look_down(void) { - cur_obj_init_animation_with_sound(14); - if (cur_obj_check_anim_frame(20)) +/** + * Makes Bowser look down and stop on an specific animation frame + * Returns TRUE if the animation is almost over + */ +s32 bowser_set_anim_look_down_stop_walk(void) { + cur_obj_init_animation_with_sound(BOWSER_ANIM_LOOK_DOWN_STOP_WALK); + if (cur_obj_check_anim_frame(20)) { o->oForwardVel = 0.0f; - if (cur_obj_check_if_near_animation_end()) - return 1; - else - return 0; + } + if (cur_obj_check_if_near_animation_end()) { + return TRUE; + } else { + return FALSE; + } } -void bowser_initialize_action(void) { - if (o->oBowserUnk88 == 0) - o->oAction = 5; - else if (o->oBowserUnk88 == 1) - o->oAction = 6; - else if (o->oBehParams2ndByte == 1) - o->oAction = 13; - else - o->oAction = 0; +/** + * Set Bowser an action depending of the CamAct value + * CamAct changes value on the cutscene itself (cutscene_bowser_arena) + */ +void bowser_init_camera_actions(void) { + if (o->oBowserCamAct == BOWSER_CAM_ACT_IDLE) { + o->oAction = BOWSER_ACT_WAIT; + } else if (o->oBowserCamAct == BOWSER_CAM_ACT_WALK) { + o->oAction = BOWSER_ACT_INTRO_WALK; + // Start with a big jump in BitFS to do a platform tilt + } else if (o->oBehParams2ndByte == BOWSER_BP_BITFS) { + o->oAction = BOWSER_ACT_BIG_JUMP; + } else { + o->oAction = BOWSER_ACT_DEFAULT; + } } -void bowser_act_text_wait(void) // not much -{ +/** + * Bowser's idle action that plays when he is initialized + * or the CamAct gets in idle mode + */ +void bowser_act_wait(void) { o->oForwardVel = 0.0f; - cur_obj_init_animation_with_sound(12); - bowser_initialize_action(); + cur_obj_init_animation_with_sound(BOWSER_ANIM_IDLE); + bowser_init_camera_actions(); } +/** + * Bowser's cutscene walk that last a few seconds to introduce itself + * Do subactions until the animation ends, then go to next subaction + */ void bowser_act_intro_walk(void) { + // First look up and walk if (o->oSubAction == 0) { - if (bowser_set_anim_look_up_and_walk()) + if (bowser_set_anim_look_up_and_walk()) { o->oSubAction++; - } else if (o->oSubAction == 1) { - if (bowser_set_anim_slow_gait()) - o->oSubAction++; - } else if (bowser_set_anim_look_down()) { - if (o->oBowserUnk88 == 1) - o->oBowserUnk88 = 0; - bowser_initialize_action(); - } -} - -static void bowser_debug_actions(void) // unused -{ - if (gDebugInfo[5][1] != 0) { - o->oAction = D_8032F4FC[gDebugInfo[5][2] & 0xf]; - gDebugInfo[5][1] = 0; - } -} - -void bowser_bitdw_act_controller(void) { - f32 rand = random_float(); - if (o->oBowserUnk110 == 0) { - if (o->oBowserUnkF4 & 2) { - if (o->oDistanceToMario < 1500.0f) - o->oAction = 15; // nearby - else - o->oAction = 17; // far away - } else - o->oAction = 14; - o->oBowserUnk110++; - } else { - o->oBowserUnk110 = 0; -#ifndef VERSION_JP - if (!gCurrDemoInput) { - if (rand < 0.1) - o->oAction = 3; // rare 1/10 chance - else - o->oAction = 14; // common - } else { - o->oAction = 14; // ensure demo starts with action 14. } -#else - if (rand < 0.1) - o->oAction = 3; // rare 1/10 chance - else - o->oAction = 14; // common -#endif + // Then slowly walk + } else if (o->oSubAction == 1) { + if (bowser_set_anim_slow_gait()) { + o->oSubAction++; + } + // And finally stop, and set to wait mode + } else if (bowser_set_anim_look_down_stop_walk()) { + if (o->oBowserCamAct == BOWSER_CAM_ACT_WALK) { + o->oBowserCamAct = BOWSER_CAM_ACT_IDLE; + } + bowser_init_camera_actions(); } } -void bowser_bitfs_act_controller(void) { +/** + * List of actions to debug Bowser + */ +s8 sBowserDebugActions[] = { + BOWSER_ACT_CHARGE_MARIO, + BOWSER_ACT_SPIT_FIRE_INTO_SKY, + BOWSER_ACT_SPIT_FIRE_ONTO_FLOOR, + BOWSER_ACT_HIT_MINE, + BOWSER_ACT_BIG_JUMP, + BOWSER_ACT_WALK_TO_MARIO, + BOWSER_ACT_BREATH_FIRE, + BOWSER_ACT_DEAD, + BOWSER_ACT_DANCE, + BOWSER_ACT_TELEPORT, + BOWSER_ACT_QUICK_JUMP, + BOWSER_ACT_TILT_LAVA_PLATFORM, + BOWSER_ACT_DANCE, + BOWSER_ACT_DANCE, + BOWSER_ACT_DANCE, + BOWSER_ACT_DANCE, +}; + +/** + * Debug function that allows to change Bowser's actions (most of them) + */ +UNUSED static void bowser_debug_actions(void) { + if (gDebugInfo[DEBUG_PAGE_ENEMYINFO][1] != 0) { + o->oAction = sBowserDebugActions[gDebugInfo[DEBUG_PAGE_ENEMYINFO][2] & 0x0F]; + gDebugInfo[DEBUG_PAGE_ENEMYINFO][1] = 0; + } +} + +/** + * Set actions (and attacks) for Bowser in "Bowser in the Dark World" + */ +void bowser_bitdw_actions(void) { + // Generate random float f32 rand = random_float(); - if (o->oBowserUnk110 == 0) { - if (o->oBowserUnkF4 & 2) { - if (o->oDistanceToMario < 1300.0f) // nearby - { - if (rand < 0.5) // 50/50 - o->oAction = 16; - else - o->oAction = 9; - } else // far away - { - o->oAction = 7; - if (500.0f < o->oBowserDistToCentre && o->oBowserDistToCentre < 1500.0f - && rand < 0.5) // away from centre and good luck - o->oAction = 13; + // Set attacks when Bowser Reacts + if (!o->oBowserIsReacting) { + if (o->oBowserStatus & BOWSER_STATUS_ANGLE_MARIO) { + if (o->oDistanceToMario < 1500.0f) { // nearby + o->oAction = BOWSER_ACT_BREATH_FIRE; + } else { // far away + o->oAction = BOWSER_ACT_QUICK_JUMP; } - } else - o->oAction = 14; - o->oBowserUnk110++; + } else { + // Keep walking + o->oAction = BOWSER_ACT_WALK_TO_MARIO; + } + o->oBowserIsReacting++; } else { - o->oBowserUnk110 = 0; - o->oAction = 14; - } -} - -void bowser_general_bits_act_controller(void) { - f32 rand = random_float(); - if (o->oBowserUnkF4 & 2) { - if (o->oDistanceToMario < 1000.0f) { - if (rand < 0.4) - o->oAction = 9; - else if (rand < 0.8) - o->oAction = 8; - else - o->oAction = 15; - } else if (rand < 0.5) - o->oAction = 13; - else - o->oAction = 7; - } else - o->oAction = 14; -} - -void bowser_set_act_jump(void) { - o->oAction = 13; -} - -void bowser_bits_act_controller(void) { - switch (o->oBowserUnk110) { - case 0: - if (o->oBowserUnk106 == 0) - bowser_general_bits_act_controller(); - else - bowser_set_act_jump(); - o->oBowserUnk110 = 1; - break; - case 1: - o->oBowserUnk110 = 0; - o->oAction = 14; - break; - } -} - + o->oBowserIsReacting = FALSE; + // Set starting Bowser level actions, randomly he can also start + // dancing after the introduction #ifndef VERSION_JP + if (gCurrDemoInput == NULL) { // demo check because entry exits post JP +#endif + if (rand < 0.1) { + o->oAction = BOWSER_ACT_DANCE; // 10% chance + } else { + o->oAction = BOWSER_ACT_WALK_TO_MARIO; // common + } +#ifndef VERSION_JP + } else { + o->oAction = BOWSER_ACT_WALK_TO_MARIO; + } +#endif + } +} + +/** + * Set actions (and attacks) for Bowser in "Bowser in the Fire Sea" + */ +void bowser_bitfs_actions(void) { + // Generate random float + f32 rand = random_float(); + // Set attacks when Bowser Reacts + if (!o->oBowserIsReacting) { + if (o->oBowserStatus & BOWSER_STATUS_ANGLE_MARIO) { + if (o->oDistanceToMario < 1300.0f) { // nearby + if (rand < 0.5) { // 50% chance + o->oAction = BOWSER_ACT_TELEPORT; + } else { + o->oAction = BOWSER_ACT_SPIT_FIRE_ONTO_FLOOR; + } + } else { // far away + o->oAction = BOWSER_ACT_CHARGE_MARIO; + if (500.0f < o->oBowserDistToCenter && o->oBowserDistToCenter < 1500.0f + && rand < 0.5) { // 50% chance + o->oAction = BOWSER_ACT_BIG_JUMP; + } + } + } else { + // Keep walking + o->oAction = BOWSER_ACT_WALK_TO_MARIO; + } + o->oBowserIsReacting++; + } else { + // Keep walking + o->oBowserIsReacting = FALSE; + o->oAction = BOWSER_ACT_WALK_TO_MARIO; + } +} + +/** + * List of actions (and attacks) for "Bowser in the Sky" + */ +void bowser_bits_action_list(void) { + f32 rand = random_float(); + if (o->oBowserStatus & BOWSER_STATUS_ANGLE_MARIO) { + if (o->oDistanceToMario < 1000.0f) { // nearby + if (rand < 0.4) { + o->oAction = BOWSER_ACT_SPIT_FIRE_ONTO_FLOOR; // 40% chance + } else if (rand < 0.8) { + o->oAction = BOWSER_ACT_SPIT_FIRE_INTO_SKY; // 80% chance + } else { + o->oAction = BOWSER_ACT_BREATH_FIRE; + } + } else { // far away + if (rand < 0.5) { + o->oAction = BOWSER_ACT_BIG_JUMP; // 50% chance + } else { + o->oAction = BOWSER_ACT_CHARGE_MARIO; + } + } + } else { + // Keep walking + o->oAction = BOWSER_ACT_WALK_TO_MARIO; + } +} + +/** + * Sets big jump action, not much to say + * Never gets called since oBowserBitsJustJump is always FALSE + */ +void bowser_set_act_big_jump(void) { + o->oAction = BOWSER_ACT_BIG_JUMP; +} + +/** + * Set actions (and attacks) for Bowser in "Bowser in the Sky" + */ +void bowser_bits_actions(void) { + switch (o->oBowserIsReacting) { + case FALSE: + // oBowserBitsJustJump never changes value, + // so its always FALSE, maybe a debug define + if (o->oBowserBitsJustJump == FALSE) { + bowser_bits_action_list(); + } else { + bowser_set_act_big_jump(); + } + o->oBowserIsReacting = TRUE; + break; + + case TRUE: + o->oBowserIsReacting = FALSE; + o->oAction = BOWSER_ACT_WALK_TO_MARIO; + break; + } +} + +/** + * Reset Bowser position and speed if he wasn't able to land properly on stage + */ +#if BUGFIX_BOWSER_FALLEN_OFF_STAGE void bowser_reset_fallen_off_stage(void) { - if (o->oVelY < 0 && o->oPosY < (o->oHomeY - 300.0f)) { - o->oPosX = o->oPosZ = 0; + if (o->oVelY < 0.0f && o->oPosY < (o->oHomeY - 300.0f)) { + o->oPosX = o->oPosZ = 0.0f; o->oPosY = o->oHomeY + 2000.0f; - o->oVelY = 0; - o->oForwardVel = 0; + o->oVelY = 0.0f; + o->oForwardVel = 0.0f; } } #endif -void bowser_act_unused_slow_walk(void) // unused? -{ - if (cur_obj_init_animation_and_check_if_near_end(12)) - o->oAction = 0; +/** + * Unused, makes Bowser be in idle and after it returns to default action + */ +void bowser_act_idle(void) { + if (cur_obj_init_animation_and_check_if_near_end(BOWSER_ANIM_IDLE)) { + o->oAction = BOWSER_ACT_DEFAULT; + } } -void bowser_act_default(void) // only lasts one frame -{ - o->oBowserEyesShut = 0; - cur_obj_init_animation_with_sound(12); - // stop him still +/** + * Default Bowser act that doesn't last very long + */ +void bowser_act_default(void) { + // Set eye state + o->oBowserEyesShut = FALSE; + // Set idle animation + cur_obj_init_animation_with_sound(BOWSER_ANIM_IDLE); + // Stop him still o->oAngleVelYaw = 0; o->oForwardVel = 0.0f; o->oVelY = 0.0f; - if (BITDW) - bowser_bitdw_act_controller(); - else if (BITFS) - bowser_bitfs_act_controller(); - else - bowser_bits_act_controller(); - // Action 14 commonly follows + // Set level specific actions + if (o->oBehParams2ndByte == BOWSER_BP_BITDW) { + bowser_bitdw_actions(); + } else if (o->oBehParams2ndByte == BOWSER_BP_BITFS) { + bowser_bitfs_actions(); + } else { // BOWSER_BP_BITS + bowser_bits_actions(); + } } +/** + * Makes Bowser play breath animation and sound effect + * The actual breath attack is in bhv_bowser_flame_spawn_loop + * called as a child obj behavior in Bowser + */ void bowser_act_breath_fire(void) { o->oForwardVel = 0.0f; - if (o->oTimer == 0) + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_OBJ_BOWSER_INHALING); - if (cur_obj_init_animation_and_check_if_near_end(6)) - o->oAction = 0; + } + // Init animation and return to default act after it ends + if (cur_obj_init_animation_and_check_if_near_end(BOWSER_ANIM_BREATH)) { + o->oAction = BOWSER_ACT_DEFAULT; + } } -void bowser_act_walk_to_mario(void) // turn towards Mario -{ +/** + * Makes Bowser walk towards Mario + */ +void bowser_act_walk_to_mario(void) { UNUSED s32 facing; // is Bowser facing Mario? s16 turnSpeed; s16 angleFromMario = abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario); - if (BITFS) + + // Set turning speed depending of the health + // Also special case for BitFS + if (o->oBehParams2ndByte == BOWSER_BP_BITFS) { turnSpeed = 0x400; - else if (o->oHealth > 2) - turnSpeed = 0x400; - else if (o->oHealth == 2) - turnSpeed = 0x300; - else - turnSpeed = 0x200; - facing = cur_obj_rotate_yaw_toward(o->oAngleToMario, turnSpeed); - if (o->oSubAction == 0) { - o->oBowserUnkF8 = 0; - if (bowser_set_anim_look_up_and_walk()) - o->oSubAction++; - } else if (o->oSubAction == 1) { - if (bowser_set_anim_slow_gait()) { - o->oBowserUnkF8++; - if (o->oBowserUnkF4 & 0x20000) { - if (o->oBowserUnkF8 > 4) - o->oBowserUnkF4 &= ~0x20000; - } else if (angleFromMario < 0x2000) - o->oSubAction++; + } else { // BOWSER_BP_BITDW or BOWSER_BP_BITS + if (o->oHealth >= 3) { + turnSpeed = 0x400; + } else if (o->oHealth == 2) { + turnSpeed = 0x300; + } else { // 1 health + turnSpeed = 0x200; } - } else if (bowser_set_anim_look_down()) - o->oAction = 0; + } + + facing = cur_obj_rotate_yaw_toward(o->oAngleToMario, turnSpeed); + + if (o->oSubAction == 0) { + o->oBowserTimer = 0; + // Start walking + if (bowser_set_anim_look_up_and_walk()) { + o->oSubAction++; + } + } else if (o->oSubAction == 1) { + // Keep walking slowly + if (bowser_set_anim_slow_gait()) { + o->oBowserTimer++; + // Reset fire sky status + if (o->oBowserStatus & BOWSER_STATUS_FIRE_SKY) { + if (o->oBowserTimer > 4) { + o->oBowserStatus &= ~BOWSER_STATUS_FIRE_SKY; + } + // Do subaction below if angles is less than 0x2000 + } else if (angleFromMario < 0x2000) { + o->oSubAction++; + } + } + // Stop walking and set to default action + } else if (bowser_set_anim_look_down_stop_walk()) { + o->oAction = BOWSER_ACT_DEFAULT; + } } +/** + * Makes Bowser teleport while invisible + */ void bowser_act_teleport(void) { switch (o->oSubAction) { - case 0: + // Set opacity target to invisible and become intangible + case BOWSER_SUB_ACT_TELEPORT_START: cur_obj_become_intangible(); - o->oBowserUnk1AC = 0; - o->oBowserUnkF8 = 30; - if (o->oTimer == 0) + o->oBowserTargetOpacity = 0; + o->oBowserTimer = 30; // set timer value + // Play sound effect + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_OBJ2_BOWSER_TELEPORT); + } + // Bowser is invisible, move angle to face Mario if (o->oOpacity == 0) { o->oSubAction++; o->oMoveAngleYaw = o->oAngleToMario; } break; - case 1: - if (o->oBowserUnkF8--) + + case BOWSER_SUB_ACT_TELEPORT_MOVE: + // reduce timer and set velocity teleport while at it + if (o->oBowserTimer--) { o->oForwardVel = 100.0f; - else { - o->oSubAction = 2; - o->oMoveAngleYaw = o->oAngleToMario; + } else { + o->oSubAction = BOWSER_SUB_ACT_TELEPORT_STOP; + o->oMoveAngleYaw = o->oAngleToMario; // update angle } - if (abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario) > 0x4000) + + if (abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario) > 0x4000) { if (o->oDistanceToMario > 500.0f) { - o->oSubAction = 2; - o->oMoveAngleYaw = o->oAngleToMario; // large change in angle? + o->oSubAction = BOWSER_SUB_ACT_TELEPORT_STOP; + o->oMoveAngleYaw = o->oAngleToMario; // update angle cur_obj_play_sound_2(SOUND_OBJ2_BOWSER_TELEPORT); } + } break; - case 2: - o->oForwardVel = 0.0f; - o->oBowserUnk1AC = 0xFF; - if (o->oOpacity == 0xFF) - o->oAction = 0; + + // Set opacity target to visible and become tangible + case BOWSER_SUB_ACT_TELEPORT_STOP: + o->oForwardVel = 0.0f; // reset velocity + o->oBowserTargetOpacity = 255; + // Set to default action once visible + if (o->oOpacity == 255) { + o->oAction = BOWSER_ACT_DEFAULT; + } cur_obj_become_tangible(); break; } } -void bowser_act_spit_fire_into_sky(void) // only in sky -{ - s32 frame; - cur_obj_init_animation_with_sound(11); - frame = o->header.gfx.animInfo.animFrame; - if (frame > 24 && frame < 36) { +/** + * Makes Bowser do a fire split into the sky + */ +void bowser_act_spit_fire_into_sky(void) { + s32 animFrame; + // Play animation + cur_obj_init_animation_with_sound(BOWSER_ANIM_BREATH_UP); + // Set frames + animFrame = o->header.gfx.animInfo.animFrame; + // Spawn flames in the middle of the animation + if (animFrame > 24 && animFrame < 36) { cur_obj_play_sound_1(SOUND_AIR_BOWSER_SPIT_FIRE); - if (frame == 35) - spawn_object_relative(1, 0, 0x190, 0x64, o, MODEL_RED_FLAME, bhvBlueBowserFlame); - else - spawn_object_relative(0, 0, 0x190, 0x64, o, MODEL_RED_FLAME, bhvBlueBowserFlame); + if (animFrame == 35) { // Spawns Blue flames at this frame + spawn_object_relative(1, 0, 400, 100, o, MODEL_RED_FLAME, bhvBlueBowserFlame); + } else { // Spawns Red flames + spawn_object_relative(0, 0, 400, 100, o, MODEL_RED_FLAME, bhvBlueBowserFlame); + } } - if (cur_obj_check_if_near_animation_end()) - o->oAction = 0; - o->oBowserUnkF4 |= 0x20000; + // Return to default act once the animation is over + if (cur_obj_check_if_near_animation_end()) { + o->oAction = BOWSER_ACT_DEFAULT; + } + // Set fire sky status + o->oBowserStatus |= BOWSER_STATUS_FIRE_SKY; } +/** + * Flips Bowser back on stage if he hits a mine with more than 1 health + */ void bowser_act_hit_mine(void) { + // Similar vel values from bowser_fly_back_dead if (o->oTimer == 0) { o->oForwardVel = -400.0f; o->oVelY = 100.0f; - o->oMoveAngleYaw = o->oBowserAngleToCentre + 0x8000; - o->oBowserEyesShut = 1; + o->oMoveAngleYaw = o->oBowserAngleToCenter + 0x8000; + o->oBowserEyesShut = TRUE; // close eyes } - if (o->oSubAction == 0) { - cur_obj_init_animation_with_sound(25); + // Play flip animation + if (o->oSubAction == BOWSER_SUB_ACT_HIT_MINE_START) { + cur_obj_init_animation_with_sound(BOWSER_ANIM_FLIP); o->oSubAction++; - o->oBowserUnkF8 = 0; - } else if (o->oSubAction == 1) { - cur_obj_init_animation_with_sound(25); + o->oBowserTimer = 0; + // Play flip animation again, extend it and play bounce effects + } else if (o->oSubAction == BOWSER_SUB_ACT_HIT_MINE_FALL) { + cur_obj_init_animation_with_sound(BOWSER_ANIM_FLIP); cur_obj_extend_animation_if_at_end(); - bowser_bounce(&o->oBowserUnkF8); - if ((o->oBowserUnkF8 > 2)) { - cur_obj_init_animation_with_sound(26); + bowser_bounce_effects(&o->oBowserTimer); + // Reset vel and stand up + if (o->oBowserTimer > 2) { + cur_obj_init_animation_with_sound(BOWSER_ANIM_STAND_UP_FROM_FLIP); o->oVelY = 0.0f; o->oForwardVel = 0.0f; o->oSubAction++; } - } else if (o->oSubAction == 2) { + // Play these actions once he is stand up + } else if (o->oSubAction == BOWSER_SUB_ACT_HIT_MINE_STOP) { if (cur_obj_check_if_near_animation_end()) { - if (o->oHealth == 1) - o->oAction = 3; - else - o->oAction = 0; - o->oBowserEyesShut = 0; + // Makes Bowser dance at one health (in BitS) + if (o->oHealth == 1) { + o->oAction = BOWSER_ACT_DANCE; + } else { + o->oAction = BOWSER_ACT_DEFAULT; + } + o->oBowserEyesShut = FALSE; // open eyes } } else { } } -s32 bowser_set_anim_in_air(void) { - cur_obj_init_animation_with_sound(9); - if (cur_obj_check_anim_frame(11)) - return 1; - else - return 0; +/** + * Makes Bowser do his jump start animation + * Returns TRUE on the middle of the jump + */ +s32 bowser_set_anim_jump(void) { + cur_obj_init_animation_with_sound(BOWSER_ANIM_JUMP_START); + if (cur_obj_check_anim_frame(11)) { + return TRUE; + } else { + return FALSE; + } } +/** + * Reset speed, play jump stop animation and do attacks in BitDW + * Returns TRUE when Bowser lands + */ s32 bowser_land(void) { if (o->oMoveFlags & OBJ_MOVE_LANDED) { - o->oForwardVel = 0; - o->oVelY = 0; + o->oForwardVel = 0.0f; + o->oVelY = 0.0f; spawn_mist_particles_variable(0, 0, 60.0f); - cur_obj_init_animation_with_sound(8); + cur_obj_init_animation_with_sound(BOWSER_ANIM_JUMP_STOP); o->header.gfx.animInfo.animFrame = 0; cur_obj_start_cam_event(o, CAM_EVENT_BOWSER_JUMP); - if (BITDW) { - if (o->oDistanceToMario < 850.0f) - gMarioObject->oInteractStatus |= INT_STATUS_MARIO_UNK1; - else - gMarioObject->oInteractStatus |= INT_STATUS_HOOT_GRABBED_BY_MARIO; // hmm... + // Set status attacks in BitDW since the other levels + // have different attacks defined + if (o->oBehParams2ndByte == BOWSER_BP_BITDW) { + if (o->oDistanceToMario < 850.0f) { + gMarioObject->oInteractStatus |= INT_STATUS_MARIO_KNOCKBACK_DMG; + } else { + gMarioObject->oInteractStatus |= INT_STATUS_MARIO_STUNNED; + } } - return 1; - } else - return 0; + return TRUE; + } else { + return FALSE; + } } +/** + * Makes Bowser do a second hop speed only in BitS + */ void bowser_short_second_hop(void) { - if (BITS && o->oBowserUnkF4 & 0x10000) - if (o->oBowserDistToCentre > 1000.0f) + if (o->oBehParams2ndByte == BOWSER_BP_BITS && o->oBowserStatus & BOWSER_STATUS_BIG_JUMP) { + if (o->oBowserDistToCenter > 1000.0f) { o->oForwardVel = 60.0f; + } + } } -void bowser_act_jump(void) { - UNUSED s32 unused; +/** + * Makes Bowser do a big jump + */ +void bowser_act_big_jump(void) { + UNUSED u8 filler[4]; + if (o->oSubAction == 0) { - if (bowser_set_anim_in_air()) { - if (BITS && o->oBowserUnkF4 & 0x10000) + // Set jump animation + if (bowser_set_anim_jump()) { + // Set vel depending of the stage and status + if (o->oBehParams2ndByte == BOWSER_BP_BITS && o->oBowserStatus & BOWSER_STATUS_BIG_JUMP) { o->oVelY = 70.0f; - else + } else { o->oVelY = 80.0f; - o->oBowserUnkF8 = 0; + } + o->oBowserTimer = 0; bowser_short_second_hop(); o->oSubAction++; } } else if (o->oSubAction == 1) { -#ifndef VERSION_JP - if (o->oBehParams2ndByte == 2 && o->oBowserUnkF4 & 0x10000) +#if BUGFIX_BOWSER_FALLEN_OFF_STAGE + // Reset Bowser back on stage in BitS if he doesn't land properly + if (o->oBehParams2ndByte == BOWSER_BP_BITS && o->oBowserStatus & BOWSER_STATUS_BIG_JUMP) { bowser_reset_fallen_off_stage(); + } #endif + // Land on stage, reset status jump and velocity if (bowser_land()) { - o->oBowserUnkF4 &= ~0x10000; + o->oBowserStatus &= ~BOWSER_STATUS_BIG_JUMP; o->oForwardVel = 0.0f; o->oSubAction++; + // Spawn shockwave (BitS only) if is not on a platform bowser_spawn_shockwave(); - if (BITFS) - o->oAction = 19; + // Tilt platform in BitFS + if (o->oBehParams2ndByte == BOWSER_BP_BITFS) { + o->oAction = BOWSER_ACT_TILT_LAVA_PLATFORM; + } } else { } - } else if (cur_obj_check_if_near_animation_end()) - o->oAction = 0; + // Set to default action when the animation is over + } else if (cur_obj_check_if_near_animation_end()) { + o->oAction = BOWSER_ACT_DEFAULT; + } } -void bowser_act_jump_towards_mario(void) { - f32 sp1C = D_8032F50C[0]; - f32 sp18 = D_8032F510[0]; +/** + * Fixed values for the quick jump action + */ +s16 sBowserVelYAir[] = { 60 }; +s16 sBowserFVelAir[] = { 50 }; + +/** + * Makes Bowser do a "quick" jump in BitDW + */ +void bowser_act_quick_jump(void) { + f32 velY = sBowserVelYAir[0]; + f32 fVel = sBowserFVelAir[0]; + if (o->oSubAction == 0) { - if (bowser_set_anim_in_air()) { - o->oVelY = sp1C; - o->oForwardVel = sp18; - o->oBowserUnkF8 = 0; + // Set fixed val positions while jumping + if (bowser_set_anim_jump()) { + o->oVelY = velY; + o->oForwardVel = fVel; + o->oBowserTimer = 0; o->oSubAction++; } + // Lands then quickly returns to default action } else if (o->oSubAction == 1) { - if (bowser_land()) + if (bowser_land()) { o->oSubAction++; - } else if (cur_obj_check_if_near_animation_end()) - o->oAction = 0; + } + } else if (cur_obj_check_if_near_animation_end()) { + o->oAction = BOWSER_ACT_DEFAULT; + } } +/** + * Makes Bowser moving around if he is on an edge floor + */ void bowser_act_hit_edge(void) { + // Reset speed and timer o->oForwardVel = 0.0f; - if (o->oTimer == 0) - o->oBowserUnkF8 = 0; + if (o->oTimer == 0) { + o->oBowserTimer = 0; + } + switch (o->oSubAction) { case 0: - cur_obj_init_animation_with_sound(23); - if (cur_obj_check_if_near_animation_end()) - o->oBowserUnkF8++; - if (o->oBowserUnkF8 > 0) + // Move on the edge + cur_obj_init_animation_with_sound(BOWSER_ANIM_EDGE_MOVE); + if (cur_obj_check_if_near_animation_end()) { + o->oBowserTimer++; + } + if (o->oBowserTimer > 0) { o->oSubAction++; + } break; + case 1: - cur_obj_init_animation_with_sound(24); - if (cur_obj_check_if_near_animation_end()) - o->oAction = 11; + // Stop moving on the edge + cur_obj_init_animation_with_sound(BOWSER_ANIM_EDGE_STOP); + // Turn around once the animation ends + if (cur_obj_check_if_near_animation_end()) { + o->oAction = BOWSER_ACT_TURN_FROM_EDGE; + } break; } } +/** + * Makes Bowser do a fire split attack + */ void bowser_act_spit_fire_onto_floor(void) { - if (gHudDisplay.wedges < 4) - o->oBowserUnk108 = 3; - else - o->oBowserUnk108 = random_float() * 3.0f + 1.0f; - cur_obj_init_animation_with_sound(22); - if (cur_obj_check_anim_frame(5)) + // Set fixed rand value if Mario is low health + if (gHudDisplay.wedges < 4) { + o->oBowserRandSplitFloor = 3; + } else { + o->oBowserRandSplitFloor = random_float() * 3.0f + 1.0f; + } + + // Play animation and split fire at a specific frame + cur_obj_init_animation_with_sound(BOWSER_ANIM_BREATH_QUICK); + if (cur_obj_check_anim_frame(5)) { obj_spit_fire(0, 200, 180, 7.0f, MODEL_RED_FLAME, 30.0f, 10.0f, 0x1000); - if (cur_obj_check_if_near_animation_end()) + } + // Use subaction as a timer when the animation is over + if (cur_obj_check_if_near_animation_end()) { o->oSubAction++; - if (o->oSubAction >= o->oBowserUnk108) - o->oAction = 0; + } + // Return to default act once we get past rand value + if (o->oSubAction >= o->oBowserRandSplitFloor) { + o->oAction = BOWSER_ACT_DEFAULT; + } } -s32 bowser_turn_on_timer(s32 a0, s16 a1) { +/** + * Turns around Bowser from an specific yaw angle + * Returns TRUE once the timer is bigger than the time set + */ +s32 bowser_turn_on_timer(s32 time, s16 yaw) { if (o->oSubAction == 0) { - if (cur_obj_init_animation_and_check_if_near_end(15)) + if (cur_obj_init_animation_and_check_if_near_end(BOWSER_ANIM_LOOK_UP_START_WALK)) { o->oSubAction++; + } } else if (o->oSubAction == 1) { - if (cur_obj_init_animation_and_check_if_near_end(14)) + if (cur_obj_init_animation_and_check_if_near_end(BOWSER_ANIM_LOOK_DOWN_STOP_WALK)) { o->oSubAction++; - } else - cur_obj_init_animation_with_sound(12); + } + } else { + cur_obj_init_animation_with_sound(BOWSER_ANIM_IDLE); + } + o->oForwardVel = 0.0f; - o->oMoveAngleYaw += a1; - if (o->oTimer >= a0) - return 1; - else - return 0; + o->oMoveAngleYaw += yaw; + + if (o->oTimer >= time) { + return TRUE; + } else { + return FALSE; + } } +/** + * Makes Bowser turn around after hitting the edge + */ void bowser_act_turn_from_edge(void) { - if (bowser_turn_on_timer(63, 0x200)) - o->oAction = 0; + if (bowser_turn_on_timer(63, 0x200)) { + o->oAction = BOWSER_ACT_DEFAULT; + } } +/** + * Makes Bowser charge (run) to Mario + */ void bowser_act_charge_mario(void) { - s32 sp34; - if (o->oTimer == 0) + s32 time; + // Reset Speed to prepare charge + if (o->oTimer == 0) { o->oForwardVel = 0.0f; + } + switch (o->oSubAction) { - case 0: - o->oBowserUnkF8 = 0; - if (cur_obj_init_animation_and_check_if_near_end(18)) - o->oSubAction = 1; - break; - case 1: - o->oForwardVel = 50.0f; - if (cur_obj_init_animation_and_check_if_near_end(0x13) != 0) { - o->oBowserUnkF8++; - if (o->oBowserUnkF8 >= 6) - o->oSubAction = 3; - if (o->oBowserUnkF8 >= 2) - if (abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw) > 0x2000) - o->oSubAction = 3; + case BOWSER_SUB_ACT_CHARGE_START: + // Start running + o->oBowserTimer = 0; + if (cur_obj_init_animation_and_check_if_near_end(BOWSER_ANIM_RUN_START)) { + o->oSubAction = BOWSER_SUB_ACT_CHARGE_RUN; } + break; + + case BOWSER_SUB_ACT_CHARGE_RUN: + // Set speed to run + o->oForwardVel = 50.0f; + if (cur_obj_init_animation_and_check_if_near_end(BOWSER_ANIM_RUN)) { + o->oBowserTimer++; + // Split if 6 timer frames has passed + if (o->oBowserTimer >= 6) { + o->oSubAction = BOWSER_SUB_ACT_CHARGE_SLIP; + } + // Slip if Mario has a differentiable angle and 2 timer frames has passed + if (o->oBowserTimer >= 2) { + if (abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw) > 0x2000) { + o->oSubAction = BOWSER_SUB_ACT_CHARGE_SLIP; + } + } + } + // Rotate to Mario cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x200); break; - case 3: - o->oBowserUnkF8 = 0; - cur_obj_init_animation_with_sound(21); + + case BOWSER_SUB_ACT_CHARGE_SLIP: + // Spawn smoke puff while slipping + o->oBowserTimer = 0; + cur_obj_init_animation_with_sound(BOWSER_ANIM_RUN_SLIP); spawn_object_relative_with_scale(0, 100, -50, 0, 3.0f, o, MODEL_SMOKE, bhvWhitePuffSmoke2); spawn_object_relative_with_scale(0, -100, -50, 0, 3.0f, o, MODEL_SMOKE, bhvWhitePuffSmoke2); - if (approach_f32_signed(&o->oForwardVel, 0, -1.0f)) - o->oSubAction = 2; + // End Charge once Bowser stops running + if (approach_f32_signed(&o->oForwardVel, 0, -1.0f)) { + o->oSubAction = BOWSER_SUB_ACT_CHARGE_END; + } cur_obj_extend_animation_if_at_end(); break; - case 2: + + case BOWSER_SUB_ACT_CHARGE_END: + // Stop running o->oForwardVel = 0.0f; - cur_obj_init_animation_with_sound(20); + cur_obj_init_animation_with_sound(BOWSER_ANIM_RUN_STOP); if (cur_obj_check_if_near_animation_end()) { - if (BITS) - sp34 = 10; - else - sp34 = 30; - if (o->oBowserUnkF8 > sp34) - o->oAction = 0; - o->oBowserUnkF8++; + // Set time delay to go to default action + if (o->oBehParams2ndByte == BOWSER_BP_BITS) { + time = 10; + } else { + time = 30; + } + if (o->oBowserTimer > time) { + o->oAction = BOWSER_ACT_DEFAULT; + } + o->oBowserTimer++; } cur_obj_extend_animation_if_at_end(); break; } - if (o->oMoveFlags & OBJ_MOVE_HIT_EDGE) - o->oAction = 10; + + // Bowser is close to falling so set hit edge action + if (o->oMoveFlags & OBJ_MOVE_HIT_EDGE) { + o->oAction = BOWSER_ACT_HIT_EDGE; + } } +/** + * Checks if Bowser hits a mine from a distance, returns TRUE if so + */ s32 bowser_check_hit_mine(void) { struct Object *mine; - f32 sp18; - mine = cur_obj_find_nearest_object_with_behavior(bhvBowserBomb, &sp18); - if (mine != NULL && sp18 < 800.0f) { + f32 dist; + + mine = cur_obj_find_nearest_object_with_behavior(bhvBowserBomb, &dist); + if (mine != NULL && dist < 800.0f) { mine->oInteractStatus |= INT_STATUS_HIT_MINE; - return 1; + return TRUE; } - return 0; + + return FALSE; } -void bowser_act_thrown_dropped(void) -{ - UNUSED s32 unused; - if (o->oTimer < 2) - o->oBowserUnkF8 = 0; +/** + * Bowser's thrown act that gets called after Mario releases him + */ +void bowser_act_thrown(void) { + UNUSED u8 filler[4]; + + // Keep Bowser's timer at 0 unless he lands + if (o->oTimer < 2) { + o->oBowserTimer = 0; + } if (o->oSubAction == 0) { - cur_obj_init_animation_with_sound(2); - bowser_bounce(&o->oBowserUnkF8); + // Play shake animations and do bounce effects + cur_obj_init_animation_with_sound(BOWSER_ANIM_SHAKING); + bowser_bounce_effects(&o->oBowserTimer); + // Reset speed when he moves on ground if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) { o->oForwardVel = 0.0f; - o->oSubAction++; + o->oSubAction++; // stops this current subaction } - } else if (cur_obj_init_animation_and_check_if_near_end(0)) - o->oAction = 0; + // Stand up and after play, set to default act + } else if (cur_obj_init_animation_and_check_if_near_end(BOWSER_ANIM_STAND_UP)) { + o->oAction = BOWSER_ACT_DEFAULT; + } + // Hit mine check, reduce health and set specific action depending of it if (bowser_check_hit_mine()) { o->oHealth--; - if (o->oHealth <= 0) - o->oAction = 4; - else - o->oAction = 12; + if (o->oHealth <= 0) { + o->oAction = BOWSER_ACT_DEAD; + } else { + o->oAction = BOWSER_ACT_HIT_MINE; + } } } +/** + * Set Bowser invisible and stops him (after falling) + */ void bowser_set_goal_invisible(void) { - o->oBowserUnk1AC = 0; + o->oBowserTargetOpacity = 0; if (o->oOpacity == 0) { o->oForwardVel = 0.0f; o->oVelY = 0.0f; @@ -674,60 +1034,86 @@ void bowser_set_goal_invisible(void) { } } +/** + * Makes Bowser jump back on stage after falling + */ void bowser_act_jump_onto_stage(void) { - s32 sp2C; - UNUSED s32 unused; - struct Surface *sp24 = o->oFloor; - if (sp24 != NULL && sp24->flags & 1) - sp2C = 1; - else - sp2C = 0; - o->oBowserUnkF4 |= 0x10000; + s32 onDynamicFloor; + UNUSED u8 filler[4]; + struct Surface *floor = o->oFloor; + + // Set dynamic floor check (Object platforms) + if (floor != NULL && floor->flags & SURFACE_FLAG_DYNAMIC) { + onDynamicFloor = TRUE; + } else { + onDynamicFloor = FALSE; + } + // Set status Jump + o->oBowserStatus |= BOWSER_STATUS_BIG_JUMP; + switch (o->oSubAction) { - case 0: + // Stops Bowser and makes him invisible + case BOWSER_SUB_ACT_JUMP_ON_STAGE_IDLE: if (o->oTimer == 0) { o->oFaceAnglePitch = 0; o->oFaceAngleRoll = 0; } //? missing else o->oFaceAnglePitch += 0x800; o->oFaceAngleRoll += 0x800; - if (!(o->oFaceAnglePitch & 0xFFFF)) + if (!(o->oFaceAnglePitch & 0xFFFF)) { o->oSubAction++; + } bowser_set_goal_invisible(); break; - case 1: - cur_obj_init_animation_with_sound(9); + + // Start jump animation and make him visible after an animation frame + case BOWSER_SUB_ACT_JUMP_ON_STAGE_START: + cur_obj_init_animation_with_sound(BOWSER_ANIM_JUMP_START); if (cur_obj_check_anim_frame(11)) { - o->oMoveAngleYaw = o->oBowserAngleToCentre; + o->oMoveAngleYaw = o->oBowserAngleToCenter; o->oVelY = 150.0f; - o->oBowserUnk1AC = 0xFF; - o->oBowserUnkF8 = 0; + o->oBowserTargetOpacity = 255; + o->oBowserTimer = 0; o->oSubAction++; - } else + } else { bowser_set_goal_invisible(); + } break; - case 2: + + // Approach him back on stage + case BOWSER_SUB_ACT_JUMP_ON_STAGE_LAND: if (o->oPosY > o->oHomeY) { o->oDragStrength = 0.0f; - if (o->oBowserDistToCentre < 2500.0f) { - if (absf(o->oFloorHeight - o->oHomeY) < 100.0f) + if (o->oBowserDistToCenter < 2500.0f) { + if (absf(o->oFloorHeight - o->oHomeY) < 100.0f) { approach_f32_signed(&o->oForwardVel, 0, -5.0f); - else + } else { cur_obj_forward_vel_approach_upward(150.0f, 2.0f); - } else + } + } else { cur_obj_forward_vel_approach_upward(150.0f, 2.0f); + } } + // Land on stage if (bowser_land()) { o->oDragStrength = 10.0f; o->oSubAction++; - if (sp2C == 0) + // Spawn shockwave (BitS only) if is not on a platform + if (onDynamicFloor == FALSE) { bowser_spawn_shockwave(); - else if (BITS) - o->oAction = 13; - if (BITFS) - o->oAction = 19; + // If is on a dynamic floor in BitS, then jump + // because of the falling platform + } else if (o->oBehParams2ndByte == BOWSER_BP_BITS) { + o->oAction = BOWSER_ACT_BIG_JUMP; + } + // If is on a dynamic floor in BitFS, then tilt platform + if (o->oBehParams2ndByte == BOWSER_BP_BITFS) { + o->oAction = BOWSER_ACT_TILT_LAVA_PLATFORM; + } } -#ifndef VERSION_JP + // Reset him back on stage if he still didn't landed yet + // Post-JP made this check as a separate function +#if BUGFIX_BOWSER_FALLEN_OFF_STAGE bowser_reset_fallen_off_stage(); #else if (o->oVelY < 0.0f && o->oPosY < o->oHomeY - 300.0f) { @@ -737,88 +1123,139 @@ void bowser_act_jump_onto_stage(void) { } #endif break; - case 3: + + // Bowser landed, so reset action after he's done jumping + case BOWSER_SUB_ACT_JUMP_ON_STAGE_STOP: if (cur_obj_check_if_near_animation_end()) { - o->oAction = 0; - o->oBowserUnkF4 &= ~0x10000; + o->oAction = BOWSER_ACT_DEFAULT; + o->oBowserStatus &= ~BOWSER_STATUS_BIG_JUMP; cur_obj_extend_animation_if_at_end(); } break; } + print_debug_bottom_up("sp %d", o->oForwardVel); } +/** + * The frames of the Bowser's timer on which to play a "stomp" sound + */ +s8 sBowserDanceStepNoises[] = { 24, 42, 60, -1 }; + +/** + * Makes Bowser's dance as a "taunt" + */ void bowser_act_dance(void) { - if (is_item_in_array(o->oTimer, D_8032F514)) + // Play a stomp sound effect on certain frames + if (is_item_in_array(o->oTimer, sBowserDanceStepNoises)) { cur_obj_play_sound_2(SOUND_OBJ_BOWSER_WALK); - if (cur_obj_init_animation_and_check_if_near_end(10)) - o->oAction = 0; + } + // Play dance animation and after that return to default action + if (cur_obj_init_animation_and_check_if_near_end(BOWSER_ANIM_DANCE)) { + o->oAction = BOWSER_ACT_DEFAULT; + } } -void bowser_spawn_grand_star_key(void) { - if (BITS) +/** + * Spawn collectable that Bowser spawns after despawning + * Spawns a Key in BitDW/BitFS or Grand Star in BitS + */ +void bowser_spawn_collectable(void) { + if (o->oBehParams2ndByte == BOWSER_BP_BITS) { gSecondCameraFocus = spawn_object(o, MODEL_STAR, bhvGrandStar); - else { + } else { gSecondCameraFocus = spawn_object(o, MODEL_BOWSER_KEY, bhvBowserKey); cur_obj_play_sound_2(SOUND_GENERAL2_BOWSER_KEY); } gSecondCameraFocus->oAngleVelYaw = o->oAngleVelYaw; } +/** + * Makes Bowser fly back on stage defeated + */ void bowser_fly_back_dead(void) { - cur_obj_init_animation_with_sound(16); - if (BITS) + cur_obj_init_animation_with_sound(BOWSER_ANIM_FLIP_DOWN); + // More knockback in BitS + if (o->oBehParams2ndByte == BOWSER_BP_BITS) { o->oForwardVel = -400.0f; - else + } else { o->oForwardVel = -200.0f; + } o->oVelY = 100.0f; - o->oMoveAngleYaw = o->oBowserAngleToCentre + 0x8000; - o->oBowserUnkF8 = 0; - o->oSubAction++; + o->oMoveAngleYaw = o->oBowserAngleToCenter + 0x8000; + o->oBowserTimer = 0; + o->oSubAction++; // BOWSER_SUB_ACT_DEAD_BOUNCE } +/** + * Plays bounce effects after landing upside down + */ void bowser_dead_bounce(void) { - o->oBowserEyesShut = 1; - bowser_bounce(&o->oBowserUnkF8); - if (o->oMoveFlags & OBJ_MOVE_LANDED) + o->oBowserEyesShut = TRUE; // close eyes + bowser_bounce_effects(&o->oBowserTimer); + if (o->oMoveFlags & OBJ_MOVE_LANDED) { cur_obj_play_sound_2(SOUND_OBJ_BOWSER_WALK); + } if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) { o->oForwardVel = 0.0f; - o->oSubAction++; + o->oSubAction++; // BOWSER_SUB_ACT_DEAD_WAIT } } +/** + * Wait for Mario to get close while Bowser is defeated + * Returns TRUE if he is close enough + */ s32 bowser_dead_wait_for_mario(void) { - s32 ret = 0; + s32 ret = FALSE; cur_obj_become_intangible(); - if (cur_obj_init_animation_and_check_if_near_end(17) && o->oDistanceToMario < 700.0f - && abs_angle_diff(gMarioObject->oMoveAngleYaw, o->oAngleToMario) > 0x6000) - ret = 1; + if (cur_obj_init_animation_and_check_if_near_end(BOWSER_ANIM_LAY_DOWN) && o->oDistanceToMario < 700.0f + && abs_angle_diff(gMarioObject->oMoveAngleYaw, o->oAngleToMario) > 0x6000) { + ret = TRUE; + } cur_obj_extend_animation_if_at_end(); - o->oBowserUnkF8 = 0; + o->oBowserTimer = 0; return ret; } -s32 bowser_dead_twirl_into_trophy(void) { - s32 ret = 0; - if (o->header.gfx.scale[0] < 0.8) +/** + * Makes Bowser twirl up by changing his scale + * Returns TRUE once done + */ +s32 bowser_dead_twirl_up(void) { + s32 ret = FALSE; + + // Set angle rotation once he has low X scale value + if (o->header.gfx.scale[0] < 0.8) { o->oAngleVelYaw += 0x80; + } + // Slowly scale down his X and Z value if (o->header.gfx.scale[0] > 0.2) { o->header.gfx.scale[0] = o->header.gfx.scale[0] - 0.02; o->header.gfx.scale[2] = o->header.gfx.scale[2] - 0.02; } else { + // Now scale down his Y value (and send Bowser up) o->header.gfx.scale[1] = o->header.gfx.scale[1] - 0.01; o->oVelY = 20.0f; o->oGravity = 0.0f; } - if (o->header.gfx.scale[1] < 0.5) - ret = 1; + // At half Y scale value, he is high enough, so we are done + if (o->header.gfx.scale[1] < 0.5) { + ret = TRUE; + } + // Copy angle rotation to moving rotation o->oMoveAngleYaw += o->oAngleVelYaw; - if (o->oOpacity >= 3) + // Slowly fade out + if (o->oOpacity >= 3) { o->oOpacity -= 2; + } + return ret; } +/** + * Hides Bowser after his death sequence is done + */ void bowser_dead_hide(void) { cur_obj_scale(0); o->oForwardVel = 0; @@ -826,288 +1263,458 @@ void bowser_dead_hide(void) { o->oGravity = 0; } -s32 bowser_dead_not_bits_end(void) { - s32 ret = 0; - if (o->oBowserUnkF8 < 2) { - if (o->oBowserUnkF8 == 0) { +/** + * Dialog values that are set on each stage Bowser's is defeated + */ +s16 sBowserDefeatedDialogText[3] = { DIALOG_119, DIALOG_120, DIALOG_121 }; + +/** + * Bowser's dead sequence that plays in BitDW/BitFS + * Returns TRUE once done + */ +s32 bowser_dead_default_stage_ending(void) { + s32 ret = FALSE; + + if (o->oBowserTimer < 2) { + // Lower music volume + if (o->oBowserTimer == 0) { seq_player_lower_volume(SEQ_PLAYER_LEVEL, 60, 40); - o->oBowserUnkF8++; + o->oBowserTimer++; } - if (cur_obj_update_dialog(2, 18, sBowserDefeatedDialogText[o->oBehParams2ndByte], 0)) { - o->oBowserUnkF8++; + // Play Bowser defeated dialog + if (cur_obj_update_dialog(MARIO_DIALOG_LOOK_UP, + (DIALOG_FLAG_TEXT_DEFAULT | DIALOG_FLAG_TIME_STOP_ENABLED), + sBowserDefeatedDialogText[o->oBehParams2ndByte], 0)) { + // Dialog is done, fade out music and play explode sound effect + o->oBowserTimer++; cur_obj_play_sound_2(SOUND_GENERAL2_BOWSER_EXPLODE); seq_player_unlower_volume(SEQ_PLAYER_LEVEL, 60); seq_player_fade_out(SEQ_PLAYER_LEVEL, 1); } - } else if (bowser_dead_twirl_into_trophy()) { + // Hide Bowser and spawn collectable once done twirling + } else if (bowser_dead_twirl_up()) { bowser_dead_hide(); - spawn_triangle_break_particles(20, 116, 1.0f, 0); - bowser_spawn_grand_star_key(); - set_mario_npc_dialog(0); - ret = 1; + spawn_triangle_break_particles(20, MODEL_YELLOW_COIN, 1.0f, 0); + bowser_spawn_collectable(); + set_mario_npc_dialog(MARIO_DIALOG_STOP); + ret = TRUE; } + return ret; } -s32 bowser_dead_bits_end(void) { - UNUSED s32 unused; - s32 ret = 0; +/** + * Bowser's dead sequence that plays in BitS + * Returns TRUE once done + */ +s32 bowser_dead_final_stage_ending(void) { + UNUSED u8 filler[4]; + s32 ret = FALSE; s32 dialogID; - if (o->oBowserUnkF8 < 2) { - if (gHudDisplay.stars < 120) + + if (o->oBowserTimer < 2) { + // Set dialog whenever you have 120 stars or not + if (gHudDisplay.stars < 120) { dialogID = DIALOG_121; - else + } else { dialogID = DIALOG_163; - if (o->oBowserUnkF8 == 0) { - seq_player_lower_volume(SEQ_PLAYER_LEVEL, 60, 40); - o->oBowserUnkF8++; } - if (cur_obj_update_dialog(2, 18, dialogID, 0)) { - cur_obj_set_model(MODEL_BOWSER2); + // Lower music volume + if (o->oBowserTimer == 0) { + seq_player_lower_volume(SEQ_PLAYER_LEVEL, 60, 40); + o->oBowserTimer++; + } + // Play Bowser defeated dialog + if (cur_obj_update_dialog(MARIO_DIALOG_LOOK_UP, + (DIALOG_FLAG_TEXT_DEFAULT | DIALOG_FLAG_TIME_STOP_ENABLED), dialogID, 0)) { + // Dialog is done, fade out music and spawn grand star + cur_obj_set_model(MODEL_BOWSER_NO_SHADOW); seq_player_unlower_volume(SEQ_PLAYER_LEVEL, 60); seq_player_fade_out(SEQ_PLAYER_LEVEL, 1); - bowser_spawn_grand_star_key(); - o->oBowserUnkF8++; + bowser_spawn_collectable(); + o->oBowserTimer++; } - } else if (o->oOpacity > 4) + // Slowly fade him out + } else if (o->oOpacity > 4) { o->oOpacity -= 4; - else { + } else { + // And at last, hide him bowser_dead_hide(); - ret = 1; + ret = TRUE; } + return ret; } +/** + * Bowser's dead action, plays when he has no health left + * This action is divided in subaction functions + */ void bowser_act_dead(void) { switch (o->oSubAction) { - case 0: + case BOWSER_SUB_ACT_DEAD_FLY_BACK: bowser_fly_back_dead(); break; - case 1: + + case BOWSER_SUB_ACT_DEAD_BOUNCE: bowser_dead_bounce(); break; - case 2: + + case BOWSER_SUB_ACT_DEAD_WAIT: + // Check if Mario is close to Bowser if (bowser_dead_wait_for_mario()) { - o->oBowserUnkF8 = 0; - if (BITS) - o->oSubAction = 10; - else { + o->oBowserTimer = 0; + // Set different (final) subaction in BitS + // Non-BitS Bowser uses default subaction and sets dithering + if (o->oBehParams2ndByte == BOWSER_BP_BITS) { + o->oSubAction = BOWSER_SUB_ACT_DEAD_FINAL_END; + } else { o->activeFlags |= ACTIVE_FLAG_DITHERED_ALPHA; - o->oSubAction++; + o->oSubAction++; // BOWSER_SUB_ACT_DEAD_DEFAULT_END } } break; - case 3: - if (bowser_dead_not_bits_end()) - o->oSubAction++; + + case BOWSER_SUB_ACT_DEAD_DEFAULT_END: + if (bowser_dead_default_stage_ending()) { + o->oSubAction++; // BOWSER_SUB_ACT_DEAD_DEFAULT_END_OVER + } break; - case 4: + + case BOWSER_SUB_ACT_DEAD_DEFAULT_END_OVER: break; - case 10: - if (bowser_dead_bits_end()) - o->oSubAction++; + + case BOWSER_SUB_ACT_DEAD_FINAL_END: + if (bowser_dead_final_stage_ending()) { + o->oSubAction++; // BOWSER_SUB_ACT_DEAD_FINAL_END_OVER + } break; - case 11: + + case BOWSER_SUB_ACT_DEAD_FINAL_END_OVER: break; } } -void bowser_tilt_platform(struct Object *platform, s16 a1) { - s16 angle; - angle = o->oBowserAngleToCentre + 0x8000; - platform->oAngleVelPitch = coss(angle) * a1; - platform->oAngleVelRoll = -sins(angle) * a1; +/** + * Sets values for the BitFS platform to tilt + */ +void bowser_tilt_platform(struct Object *platform, s16 angSpeed) { + s16 angle = o->oBowserAngleToCenter + 0x8000; + platform->oAngleVelPitch = coss(angle) * angSpeed; + platform->oAngleVelRoll = -sins(angle) * angSpeed; } -void bowser_act_ride_tilting_platform(void) { +/** + * Struct for the BitFS tilt platform + */ +struct BowserTiltPlatformInfo { + // Flag value to make sure platform moves smoothly + // 0 = Don't move + // 1 = Move angle behind Bowser + // -1 = Move angle in front of Bowser + s16 flag; + // Sets platform's tilt angle speed (pattern: positive then negative) + s16 angSpeed; + // Sets how much time the platform can tilt, increases each move + s16 time; +}; + +/** + * Data for the BitFS tilt Platform + */ +struct BowserTiltPlatformInfo sBowsertiltPlatformData[] = { + { 1, 10, 40 }, + { 0, 0, 74 }, + { -1, -10, 114 }, + { 1, -20, 134 }, + { -1, 20, 154 }, + { 1, 40, 164 }, + { -1, -40, 174 }, + { 1, -80, 179 }, + { -1, 80, 184 }, + { 1, 160, 186 }, + { -1, -160, 186 }, + { 1, 0, 0 }, +}; + +/** + * Makes the platform in BitFS tilt from left to right + */ +void bowser_act_tilt_lava_platform(void) { + // Set platform object struct Object *platform = cur_obj_nearest_object_with_behavior(bhvTiltingBowserLavaPlatform); - UNUSED s16 sp2A = o->oBowserAngleToCentre + 0x8000; - s16 sp28; - UNUSED s32 unused; - s32 i; - s32 sp1C; - if (platform == NULL) - o->oAction = 0; - else { - i = 0; - sp1C = 1; - while (D_8032F520[i][2] != 0) { - if (o->oTimer < D_8032F520[i][2]) { - sp28 = D_8032F520[i][1]; - if (D_8032F520[i][0] > 0) - sp28 = (D_8032F520[i][2] - o->oTimer - 1) * sp28; - else - sp28 = (o->oTimer - D_8032F520[i - 1][2]) * sp28; - bowser_tilt_platform(platform, sp28); - if (sp28 != 0) - play_sound(SOUND_ENV_UNKNOWN4, platform->header.gfx.cameraToObject); - sp1C = 0; + UNUSED s16 angle = o->oBowserAngleToCenter + 0x8000; + s16 angSpeed; + UNUSED u8 filler[4]; + + // If there's not platform, return to default action + if (platform == NULL) { + o->oAction = BOWSER_ACT_DEFAULT; + } else { + s32 i = 0; + s32 isNotTilting = TRUE; + // Active platform tilting if the timer is not 0 + while (sBowsertiltPlatformData[i].time != 0) { + // Move if the time values is more than the timer + if (o->oTimer < sBowsertiltPlatformData[i].time) { + // Set angle speed + angSpeed = sBowsertiltPlatformData[i].angSpeed; + // Move angle behind Bowser + if (sBowsertiltPlatformData[i].flag > 0) { + angSpeed = (sBowsertiltPlatformData[i].time - o->oTimer - 1) * angSpeed; + } else { // Move angle in front of Bowser + angSpeed = (o->oTimer - sBowsertiltPlatformData[i - 1].time) * angSpeed; + } + // Set angle values to the platform + bowser_tilt_platform(platform, angSpeed); + // Play sound effect + if (angSpeed != 0) { + play_sound(SOUND_ENV_MOVING_BIG_PLATFORM, platform->header.gfx.cameraToObject); + } + isNotTilting = FALSE; break; } i++; } - if (sp1C) { - o->oAction = 0; + // If Bowser is done tilting, reset platform angles + // and set Bowser to default action + if (isNotTilting) { + o->oAction = BOWSER_ACT_DEFAULT; platform->oAngleVelPitch = 0; platform->oAngleVelRoll = 0; platform->oFaceAnglePitch = 0; platform->oFaceAngleRoll = 0; } } + // Extend "idle" animation cur_obj_extend_animation_if_at_end(); } -s32 bowser_check_fallen_off_stage(void) // bowser off stage? -{ - if (o->oAction != 2 && o->oAction != 19) { - if (o->oPosY < o->oHomeY - 1000.0f) - return 1; +/** + * Check if Bowser is offstage from a large distance or landed on a lethal floor + */ +s32 bowser_check_fallen_off_stage(void) { + if (o->oAction != BOWSER_ACT_JUMP_ONTO_STAGE && o->oAction != BOWSER_ACT_TILT_LAVA_PLATFORM) { + if (o->oPosY < o->oHomeY - 1000.0f) { + return TRUE; + } if (o->oMoveFlags & OBJ_MOVE_LANDED) { - if (o->oFloorType == SURFACE_BURNING) - return 1; - if (o->oFloorType == SURFACE_DEATH_PLANE) - return 1; + // Check for Fire Sea + if (o->oFloorType == SURFACE_BURNING) { + return TRUE; + } + // Check for Dark World - Sky + if (o->oFloorType == SURFACE_DEATH_PLANE) { + return TRUE; + } } } - return 0; + return FALSE; } -void (*sBowserActions[])(void) = { bowser_act_default, bowser_act_thrown_dropped, bowser_act_jump_onto_stage, bowser_act_dance, - bowser_act_dead, bowser_act_text_wait, bowser_act_intro_walk, bowser_act_charge_mario, - bowser_act_spit_fire_into_sky, bowser_act_spit_fire_onto_floor, bowser_act_hit_edge, bowser_act_turn_from_edge, - bowser_act_hit_mine, bowser_act_jump, bowser_act_walk_to_mario, bowser_act_breath_fire, - bowser_act_teleport, bowser_act_jump_towards_mario, bowser_act_unused_slow_walk, bowser_act_ride_tilting_platform }; -struct SoundState D_8032F5B8[] = { { 0, 0, 0, NO_SOUND }, - { 0, 0, 0, NO_SOUND }, - { 0, 0, 0, NO_SOUND }, - { 0, 0, 0, NO_SOUND }, - { 0, 0, 0, NO_SOUND }, - { 0, 0, 0, NO_SOUND }, - { 0, 0, 0, NO_SOUND }, - { 0, 0, 0, NO_SOUND }, - { 1, 0, -1, SOUND_OBJ_BOWSER_WALK }, - { 1, 0, -1, SOUND_OBJ2_BOWSER_ROAR }, - { 1, 0, -1, SOUND_OBJ2_BOWSER_ROAR }, - { 0, 0, 0, NO_SOUND }, - { 0, 0, 0, NO_SOUND }, - { 1, 20, 40, SOUND_OBJ_BOWSER_WALK }, - { 1, 20, -1, SOUND_OBJ_BOWSER_WALK }, - { 1, 20, 40, SOUND_OBJ_BOWSER_WALK }, - { 1, 0, -1, SOUND_OBJ_BOWSER_TAIL_PICKUP }, - { 1, 0, -1, SOUND_OBJ_BOWSER_DEFEATED }, - { 1, 8, -1, SOUND_OBJ_BOWSER_WALK }, - { 1, 8, 17, SOUND_OBJ_BOWSER_WALK }, - { 1, 8, -10, SOUND_OBJ_BOWSER_WALK }, - { 0, 0, 0, NO_SOUND }, - { 1, 5, -1, SOUND_OBJ_FLAME_BLOWN }, - { 0, 0, 0, NO_SOUND }, - { 0, 0, 0, NO_SOUND }, - { 1, 0, -1, SOUND_OBJ_BOWSER_TAIL_PICKUP }, - { 1, 0, -1, SOUND_OBJ2_BOWSER_ROAR } }; -s8 D_8032F690[4] = { 0, 0, 1, 0 }; -s8 D_8032F694[4] = { 1, 1, 3, 0 }; -extern u8 bowser_3_seg7_collision_07004B94[]; -extern u8 bowser_3_seg7_collision_07004C18[]; -extern u8 bowser_3_seg7_collision_07004C9C[]; -extern u8 bowser_3_seg7_collision_07004D20[]; -extern u8 bowser_3_seg7_collision_07004DA4[]; -extern u8 bowser_3_seg7_collision_07004E28[]; -extern u8 bowser_3_seg7_collision_07004EAC[]; -extern u8 bowser_3_seg7_collision_07004F30[]; -extern u8 bowser_3_seg7_collision_07004FB4[]; -extern u8 bowser_3_seg7_collision_07005038[]; -struct Struct8032F698 D_8032F698[] = { { NULL, 0, 0, 0, 0 }, - { bowser_3_seg7_collision_07004B94, -800, -1000, -20992, 0 }, - { bowser_3_seg7_collision_07004C18, -1158, 390, -18432, 0 }, - { bowser_3_seg7_collision_07004C9C, -1158, 390, -7680, 0 }, - { bowser_3_seg7_collision_07004D20, 0, 1240, -6144, 0 }, - { bowser_3_seg7_collision_07004DA4, 0, 1240, 6144, 0 }, - { bowser_3_seg7_collision_07004E28, 1158, 390, 7680, 0 }, - { bowser_3_seg7_collision_07004EAC, 1158, 390, 18432, 0 }, - { bowser_3_seg7_collision_07004F30, 800, -1000, 20992, 0 }, - { bowser_3_seg7_collision_07004FB4, 800, -1000, -31744, 0 }, - { bowser_3_seg7_collision_07005038, -800, -1000, 31744, 0 } }; +/** + * Set Bowser's actions + */ +void (*sBowserActions[])(void) = { + bowser_act_default, + bowser_act_thrown, + bowser_act_jump_onto_stage, + bowser_act_dance, + bowser_act_dead, + bowser_act_wait, + bowser_act_intro_walk, + bowser_act_charge_mario, + bowser_act_spit_fire_into_sky, + bowser_act_spit_fire_onto_floor, + bowser_act_hit_edge, + bowser_act_turn_from_edge, + bowser_act_hit_mine, + bowser_act_big_jump, + bowser_act_walk_to_mario, + bowser_act_breath_fire, + bowser_act_teleport, + bowser_act_quick_jump, + bowser_act_idle, + bowser_act_tilt_lava_platform, +}; +/** + * Set Bowser's sound animations + */ +struct SoundState sBowserSoundStates[] = { + { 0, 0, 0, NO_SOUND }, + { 0, 0, 0, NO_SOUND }, + { 0, 0, 0, NO_SOUND }, + { 0, 0, 0, NO_SOUND }, + { 0, 0, 0, NO_SOUND }, + { 0, 0, 0, NO_SOUND }, + { 0, 0, 0, NO_SOUND }, + { 0, 0, 0, NO_SOUND }, + { 1, 0, -1, SOUND_OBJ_BOWSER_WALK }, + { 1, 0, -1, SOUND_OBJ2_BOWSER_ROAR }, + { 1, 0, -1, SOUND_OBJ2_BOWSER_ROAR }, + { 0, 0, 0, NO_SOUND }, + { 0, 0, 0, NO_SOUND }, + { 1, 20, 40, SOUND_OBJ_BOWSER_WALK }, + { 1, 20, -1, SOUND_OBJ_BOWSER_WALK }, + { 1, 20, 40, SOUND_OBJ_BOWSER_WALK }, + { 1, 0, -1, SOUND_OBJ_BOWSER_TAIL_PICKUP }, + { 1, 0, -1, SOUND_OBJ_BOWSER_DEFEATED }, + { 1, 8, -1, SOUND_OBJ_BOWSER_WALK }, + { 1, 8, 17, SOUND_OBJ_BOWSER_WALK }, + { 1, 8, -10, SOUND_OBJ_BOWSER_WALK }, + { 0, 0, 0, NO_SOUND }, + { 1, 5, -1, SOUND_OBJ_FLAME_BLOWN }, + { 0, 0, 0, NO_SOUND }, + { 0, 0, 0, NO_SOUND }, + { 1, 0, -1, SOUND_OBJ_BOWSER_TAIL_PICKUP }, + { 1, 0, -1, SOUND_OBJ2_BOWSER_ROAR }, +}; + +/** + * Set whenever Bowser should have rainbow light or not on each stage + */ +s8 sBowserRainbowLight[] = { FALSE, FALSE, TRUE }; + +/** + * Set how much health Bowser has on each stage + */ +s8 sBowserHealth[] = { 1, 1, 3 }; + +/** + * Update Bowser's actions when he's hands free + */ void bowser_free_update(void) { struct Surface *floor; struct Object *platform; UNUSED f32 floorHeight; - if ((platform = o->platform) != NULL) + + // Platform displacement check (for BitFS) + if ((platform = o->platform) != NULL) { apply_platform_displacement(FALSE, platform); - o->oBowserUnk10E = 0; + } + // Reset grabbed status + o->oBowserGrabbedStatus = BOWSER_GRAB_STATUS_NONE; + // Update positions and actions (default action) cur_obj_update_floor_and_walls(); cur_obj_call_action_function(sBowserActions); cur_obj_move_standard(-78); - if (bowser_check_fallen_off_stage()) - o->oAction = 2; // bowser go home? + // Jump on stage if Bowser has fallen off + if (bowser_check_fallen_off_stage()) { + o->oAction = BOWSER_ACT_JUMP_ONTO_STAGE; + } + // Check floor height and platform floorHeight = find_floor(o->oPosX, o->oPosY, o->oPosZ, &floor); - if ((floor != NULL) && (floor->object != 0)) + if ((floor != NULL) && (floor->object != NULL)) { o->platform = floor->object; - else + } else { o->platform = NULL; - exec_anim_sound_state(D_8032F5B8); + } + // Sound states for Bowser Animations + exec_anim_sound_state(sBowserSoundStates); } +/** + * Update Bowser's actions when he's getting held + */ void bowser_held_update(void) { - o->oBowserUnkF4 &= ~0x20000; + // Reset fire sky status and make him intangible + o->oBowserStatus &= ~BOWSER_STATUS_FIRE_SKY; cur_obj_become_intangible(); - switch (o->oBowserUnk10E) { - case 0: + + switch (o->oBowserGrabbedStatus) { + // Play pickup sound, start grabbed animation, and set throw action + // Throw action won't be played until he's actually released + case BOWSER_GRAB_STATUS_NONE: cur_obj_play_sound_2(SOUND_OBJ_BOWSER_TAIL_PICKUP); - cur_obj_unrender_and_reset_state(3, 1); - o->oBowserUnk10E++; + cur_obj_unrender_set_action_and_anim(BOWSER_ANIM_GRABBED, BOWSER_ACT_THROWN); + o->oBowserGrabbedStatus++; break; - case 1: + // After the grabbed animation ends, play shaking animation in a loop + case BOWSER_GRAB_STATUS_GRABBED: if (cur_obj_check_if_near_animation_end()) { - cur_obj_init_animation_with_sound(2); - o->oBowserUnk10E++; + cur_obj_init_animation_with_sound(BOWSER_ANIM_SHAKING); + o->oBowserGrabbedStatus++; } break; - case 2: + case BOWSER_GRAB_STATUS_HOLDING: break; } + + // Reset move flags o->oMoveFlags = 0; + // Copy angle values from Mario o->oBowserHeldAnglePitch = gMarioObject->oMoveAnglePitch; o->oBowserHeldAngleVelYaw = gMarioObject->oAngleVelYaw; o->oMoveAngleYaw = gMarioObject->oMoveAngleYaw; } +/** + * Update Bowser's actions when he's thrown and dropped + */ void bowser_thrown_dropped_update(void) { - f32 sp1C; - o->oBowserUnk10E = 0; - cur_obj_get_thrown_or_placed(1.0f, 1.0f, 1); - sp1C = o->oBowserHeldAngleVelYaw / 3000.0 * 70.0f; - if (sp1C < 0.0f) - sp1C = -sp1C; - if (sp1C > 90.0f) - sp1C *= 2.5; // > 90 => get bigger? - o->oForwardVel = coss(o->oBowserHeldAnglePitch) * sp1C; - o->oVelY = -sins(o->oBowserHeldAnglePitch) * sp1C; + f32 swingSpd; + + // Reset grabbed status + o->oBowserGrabbedStatus = BOWSER_GRAB_STATUS_NONE; + // Set throw action and vel values + cur_obj_get_thrown_or_placed(1.0f, 1.0f, BOWSER_ACT_THROWN); + // Set swing speed based of angle + swingSpd = o->oBowserHeldAngleVelYaw / 3000.0 * 70.0f; + // If less than 0, reduce speed + if (swingSpd < 0.0f) { + swingSpd = -swingSpd; + } + // If more than 90, increase speed + if (swingSpd > 90.0f) { + swingSpd *= 2.5; + } + // Set distance speed when throwing + o->oForwardVel = coss(o->oBowserHeldAnglePitch) * swingSpd; + o->oVelY = -sins(o->oBowserHeldAnglePitch) * swingSpd; cur_obj_become_intangible(); - o->prevObj->oAction = 1; // not sure what prevObj is + + // Reset timer and subactions + o->prevObj->oAction = BOWSER_ACT_TAIL_THROWN; // prevObj is Bowser's Tail o->prevObj->oTimer = 0; - o->prevObj->oSubAction = 0; + o->prevObj->oSubAction = 0; //! Tail doesn't have sub actions + o->oTimer = 0; o->oSubAction = 0; } +/** + * Bowser's main loop + */ void bhv_bowser_loop(void) { - s16 angleToMario; // AngleToMario from Bowser's perspective - s16 angleToCentre; // AngleToCentre from Bowser's perspective + s16 angleToMario; // AngleToMario from Bowser's perspective + s16 angleToCenter; // AngleToCenter from Bowser's perspective - o->oBowserDistToCentre = sqrtf(o->oPosX * o->oPosX + o->oPosZ * o->oPosZ); - o->oBowserAngleToCentre = atan2s(0.0f - o->oPosZ, 0.0f - o->oPosX); + // Set distance/angle values + o->oBowserDistToCenter = sqrtf(o->oPosX * o->oPosX + o->oPosZ * o->oPosZ); + o->oBowserAngleToCenter = atan2s(0.0f - o->oPosZ, 0.0f - o->oPosX); angleToMario = abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario); - angleToCentre = abs_angle_diff(o->oMoveAngleYaw, o->oBowserAngleToCentre); - o->oBowserUnkF4 &= ~0xFF; - if (angleToMario < 0x2000) - o->oBowserUnkF4 |= 2; - if (angleToCentre < 0x3800) - o->oBowserUnkF4 |= 4; - if (o->oBowserDistToCentre < 1000.0f) - o->oBowserUnkF4 |= 0x10; - if (o->oDistanceToMario < 850.0f) - o->oBowserUnkF4 |= 8; + angleToCenter = abs_angle_diff(o->oMoveAngleYaw, o->oBowserAngleToCenter); + + // Reset Status + o->oBowserStatus &= ~0xFF; + + // Set bitflag status for distance/angle values + // Only the first one is used + if (angleToMario < 0x2000) { + o->oBowserStatus |= BOWSER_STATUS_ANGLE_MARIO; + } + if (angleToCenter < 0x3800) { + o->oBowserStatus |= BOWSER_STATUS_ANGLE_CENTER; // unused + } + if (o->oBowserDistToCenter < 1000.0f) { + o->oBowserStatus |= BOWSER_STATUS_DIST_CENTER; // unused + } + if (o->oDistanceToMario < 850.0f) { + o->oBowserStatus |= BOWSER_STATUS_DIST_MARIO; // unused + } + + // Update Held state actions switch (o->oHeldState) { case HELD_FREE: bowser_free_update(); @@ -1122,465 +1729,248 @@ void bhv_bowser_loop(void) { bowser_thrown_dropped_update(); break; } + // Adjust model to the floor cur_obj_align_gfx_with_floor(); - if (o->oAction != 4) - if (o->oBowserUnk1AC != o->oOpacity) { - if (o->oBowserUnk1AC > o->oOpacity) { + + // Adjust opacity (when not dead) + // Mostly for the teleport action in BitFS + if (o->oAction != BOWSER_ACT_DEAD) { + if (o->oBowserTargetOpacity != o->oOpacity) { + // increase opacity when oBowserTargetOpacity is 255 + if (o->oBowserTargetOpacity > o->oOpacity) { o->oOpacity += 20; - if (o->oOpacity >= 0x100) - o->oOpacity = 0xFF; + if (o->oOpacity > 255) { + o->oOpacity = 255; + } + // reduce opacity when oBowserTargetOpacity is 0 } else { o->oOpacity -= 20; - if (o->oOpacity < 0) + if (o->oOpacity < 0) { o->oOpacity = 0; + } } } + } } +/** + * Bowser's initial values and actions + */ void bhv_bowser_init(void) { - s32 level; // 0 is dw, 1 is fs, 2 is sky - o->oBowserUnk110 = 1; - o->oOpacity = 0xFF; - o->oBowserUnk1AC = 0xFF; - if (gCurrLevelNum == LEVEL_BOWSER_2) - level = 1; - else if (gCurrLevelNum == LEVEL_BOWSER_3) - level = 2; - else - level = 0; + s32 level; + // Set "reaction" value + // It goes true when Bowser is a non-walking state + o->oBowserIsReacting = TRUE; + // Set no transparency opacity + o->oOpacity = 255; + o->oBowserTargetOpacity = 255; + // Set Bowser B-param depending of the stage + if (gCurrLevelNum == LEVEL_BOWSER_2) { + level = BOWSER_BP_BITFS; + } else if (gCurrLevelNum == LEVEL_BOWSER_3) { + level = BOWSER_BP_BITS; + } else { // LEVEL_BOWSER_1 + level = BOWSER_BP_BITDW; + } o->oBehParams2ndByte = level; - o->oBowserUnk1B2 = D_8032F690[level]; - o->oHealth = D_8032F694[level]; + // Set health and rainbow light depending of the level + o->oBowserRainbowLight = sBowserRainbowLight[level]; + o->oHealth = sBowserHealth[level]; + // Start camera event, this event is not defined so maybe + // the "start arena" cutscene was originally called this way cur_obj_start_cam_event(o, CAM_EVENT_BOWSER_INIT); - o->oAction = 5; - o->oBowserUnk1AE = 0; - o->oBowserEyesShut = 0; + o->oAction = BOWSER_ACT_WAIT; + // Set eyes status + o->oBowserEyesTimer = 0; + o->oBowserEyesShut = FALSE; } -#undef BITDW -#undef BITFS -#undef BITS - -Gfx *geo_update_body_rot_from_parent(s32 run, UNUSED struct GraphNode *node, Mat4 mtx) { - Mat4 sp20; - struct Object *sp1C; - - if (run == TRUE) { - sp1C = (struct Object *) gCurGraphNodeObject; - if (sp1C->prevObj != NULL) { - create_transformation_from_matrices(sp20, mtx, *gCurGraphNodeCamera->matrixPtr); - obj_update_pos_from_parent_transformation(sp20, sp1C->prevObj); - obj_set_gfx_pos_from_pos(sp1C->prevObj); +Gfx *geo_update_body_rot_from_parent(s32 callContext, UNUSED struct GraphNode *node, Mat4 mtx) { + if (callContext == GEO_CONTEXT_RENDER) { + Mat4 mtx2; + struct Object *obj = (struct Object *) gCurGraphNodeObject; + if (obj->prevObj != NULL) { + create_transformation_from_matrices(mtx2, mtx, *gCurGraphNodeCamera->matrixPtr); + obj_update_pos_from_parent_transformation(mtx2, obj->prevObj); + obj_set_gfx_pos_from_pos(obj->prevObj); } } + return NULL; } -void bowser_open_eye_switch(struct Object *a0, struct GraphNodeSwitchCase *switchCase) { - s32 sp1C; - s16 sp1A; - sp1A = abs_angle_diff(a0->oMoveAngleYaw, a0->oAngleToMario); - sp1C = switchCase->selectedCase; - switch (sp1C) { - case 0: - if (sp1A > 0x2000) { - if (a0->oAngleVelYaw > 0) - switchCase->selectedCase = 5; - if (a0->oAngleVelYaw < 0) - switchCase->selectedCase = 3; +/** + * Bowser's eyes Geo-Switch-Case IDs, defined from Mario's POV + */ +enum BowserEyesGSCId { + /*0x00*/ BOWSER_EYES_OPEN, + /*0x01*/ BOWSER_EYES_HALF_CLOSED, + /*0x02*/ BOWSER_EYES_CLOSED, + /*0x03*/ BOWSER_EYES_LEFT, + /*0x04*/ BOWSER_EYES_FAR_LEFT, + /*0x05*/ BOWSER_EYES_RIGHT, + /*0x06*/ BOWSER_EYES_FAR_RIGHT, + /*0x07*/ BOWSER_EYES_DERP, // unused + /*0x08*/ BOWSER_EYES_CROSS, // unused + /*0x08*/ BOWSER_EYES_RESET // set eyes back to open +}; + +/** + * Controls Bowser's eye open stage, including blinking and look directions + */ +void bowser_open_eye_switch(struct Object *obj, struct GraphNodeSwitchCase *switchCase) { + s32 eyeCase; + s16 angleFromMario; + + angleFromMario = abs_angle_diff(obj->oMoveAngleYaw, obj->oAngleToMario); + eyeCase = switchCase->selectedCase; + + switch (eyeCase) { + case BOWSER_EYES_OPEN: + // Mario is in Bowser's field of view + if (angleFromMario > 0x2000) { + if (obj->oAngleVelYaw > 0) { + switchCase->selectedCase = BOWSER_EYES_RIGHT; + } + if (obj->oAngleVelYaw < 0) { + switchCase->selectedCase = BOWSER_EYES_LEFT; + } } - if (a0->oBowserUnk1AE > 50) - switchCase->selectedCase = 1; - break; - case 1: - if (a0->oBowserUnk1AE > 2) - switchCase->selectedCase = 2; - break; - case 2: - if (a0->oBowserUnk1AE > 2) - switchCase->selectedCase = 9; - break; - case 9: - if (a0->oBowserUnk1AE > 2) - switchCase->selectedCase = 0; - break; - case 5: - if (a0->oBowserUnk1AE > 2) { - switchCase->selectedCase = 6; - if (a0->oAngleVelYaw <= 0) - switchCase->selectedCase = 0; + // Half close, start blinking + if (obj->oBowserEyesTimer > 50) { + switchCase->selectedCase = BOWSER_EYES_HALF_CLOSED; } break; - case 6: - if (a0->oAngleVelYaw <= 0) - switchCase->selectedCase = 5; - break; - case 3: - if (a0->oBowserUnk1AE > 2) { - switchCase->selectedCase = 4; - if (a0->oAngleVelYaw >= 0) - switchCase->selectedCase = 0; + + case BOWSER_EYES_HALF_CLOSED: + // Close, blinking + if (obj->oBowserEyesTimer > 2) { + switchCase->selectedCase = BOWSER_EYES_CLOSED; } break; - case 4: - if (a0->oAngleVelYaw >= 0) - switchCase->selectedCase = 3; + + case BOWSER_EYES_CLOSED: + // Reset blinking + if (obj->oBowserEyesTimer > 2) { + switchCase->selectedCase = BOWSER_EYES_RESET; + } break; + + case BOWSER_EYES_RESET: + // Open, no longer blinking + if (obj->oBowserEyesTimer > 2) { + switchCase->selectedCase = BOWSER_EYES_OPEN; + } + break; + + case BOWSER_EYES_RIGHT: + // Look more on the right if angle didn't change + // Otherwise, look at the center (open) + if (obj->oBowserEyesTimer > 2) { + switchCase->selectedCase = BOWSER_EYES_FAR_RIGHT; + if (obj->oAngleVelYaw <= 0) { + switchCase->selectedCase = BOWSER_EYES_OPEN; + } + } + break; + + case BOWSER_EYES_FAR_RIGHT: + // Look close right if angle was drastically changed + if (obj->oAngleVelYaw <= 0) { + switchCase->selectedCase = BOWSER_EYES_RIGHT; + } + break; + + case BOWSER_EYES_LEFT: + // Look more on the left if angle didn't change + // Otherwise, look at the center (open) + if (obj->oBowserEyesTimer > 2) { + switchCase->selectedCase = BOWSER_EYES_FAR_LEFT; + if (obj->oAngleVelYaw >= 0) { + switchCase->selectedCase = BOWSER_EYES_OPEN; + } + } + break; + + case BOWSER_EYES_FAR_LEFT: + // Look close left if angle was drastically changed + if (obj->oAngleVelYaw >= 0) { + switchCase->selectedCase = BOWSER_EYES_LEFT; + } + break; + default: - switchCase->selectedCase = 0; + switchCase->selectedCase = BOWSER_EYES_OPEN; + } + + // Reset timer if eye case has changed + if (switchCase->selectedCase != eyeCase) { + obj->oBowserEyesTimer = -1; } - if (switchCase->selectedCase != sp1C) - a0->oBowserUnk1AE = -1; } -/** Geo switch for controlling the state of bowser's eye direction and open/closed +/** + * Geo switch for controlling the state of Bowser's eye direction and open/closed * state. Checks whether oBowserEyesShut is TRUE and closes eyes if so and processes * direction otherwise. */ -Gfx *geo_switch_bowser_eyes(s32 run, struct GraphNode *node, UNUSED Mat4 *mtx) { - UNUSED s16 sp36; - UNUSED s32 unused; +Gfx *geo_switch_bowser_eyes(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx) { + UNUSED s16 eyeShut; + UNUSED u8 filler[4]; struct Object *obj = (struct Object *) gCurGraphNodeObject; struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *) node; - if (run == TRUE) { - if (gCurGraphNodeHeldObject != NULL) + + if (callContext == GEO_CONTEXT_RENDER) { + if (gCurGraphNodeHeldObject != NULL) { obj = gCurGraphNodeHeldObject->objNode; - switch (sp36 = obj->oBowserEyesShut) { - case 0: // eyes open, handle eye looking direction + } + + switch (eyeShut = obj->oBowserEyesShut) { + case FALSE: // eyes open, handle eye looking direction bowser_open_eye_switch(obj, switchCase); break; - case 1: // eyes closed, blinking - switchCase->selectedCase = 2; + case TRUE: // eyes closed, blinking + switchCase->selectedCase = BOWSER_EYES_CLOSED; break; } - obj->oBowserUnk1AE++; + + obj->oBowserEyesTimer++; } + return NULL; } -Gfx *geo_bits_bowser_coloring(s32 run, struct GraphNode *node, UNUSED s32 a2) { - Gfx *sp2C = NULL; - Gfx *sp28; - struct Object *sp24; - struct GraphNodeGenerated *sp20; +/** + * Geo switch that sets Bowser's Rainbow coloring (in BitS) + */ +Gfx *geo_bits_bowser_coloring(s32 callContext, struct GraphNode *node, UNUSED s32 context) { + Gfx *gfxHead = NULL; + Gfx *gfx; - if (run == 1) { - sp24 = (struct Object *) gCurGraphNodeObject; - sp20 = (struct GraphNodeGenerated *) node; - if (gCurGraphNodeHeldObject != 0) - sp24 = gCurGraphNodeHeldObject->objNode; - if (sp24->oOpacity == 0xFF) - sp20->fnNode.node.flags = (sp20->fnNode.node.flags & 0xFF) | GRAPH_NODE_TYPE_FUNCTIONAL; - else - sp20->fnNode.node.flags = (sp20->fnNode.node.flags & 0xFF) | (GRAPH_NODE_TYPE_FUNCTIONAL | GRAPH_NODE_TYPE_400); - sp28 = sp2C = alloc_display_list(2 * sizeof(Gfx)); + if (callContext == GEO_CONTEXT_RENDER) { + struct Object *obj = (struct Object *) gCurGraphNodeObject; + struct GraphNodeGenerated *graphNode = (struct GraphNodeGenerated *) node; - if (sp24->oBowserUnk1B2 != 0) { - gSPClearGeometryMode(sp28++, G_LIGHTING); + if (gCurGraphNodeHeldObject != NULL) { + obj = gCurGraphNodeHeldObject->objNode; } - gSPEndDisplayList(sp28); - } - return sp2C; -} -void falling_bowser_plat_act_0(void) { - o->oPlatformUnkF8 = cur_obj_nearest_object_with_behavior(bhvBowser); - obj_set_collision_data(o, D_8032F698[o->oBehParams2ndByte].unk0); - if (o->oPlatformUnkF8 != 0) - o->oAction = 1; -} - -void falling_bowser_plat_act_1(void) { - UNUSED s32 unused; - struct Object *sp0 = o->oPlatformUnkF8; - if (sp0->platform == o) - if (sp0->oAction == 13 && sp0->oBowserUnkF4 & 0x10000) - o->oAction = 2; - if (sp0->oHealth == 1 && (sp0->oAction == 3 || sp0->oHeldState != HELD_FREE)) - o->oSubAction = 1; - if (o->oSubAction == 0) - o->oPlatformUnkFC = 0; - else { - if ((gDebugInfo[4][6] + 20) * (o->oBehParams2ndByte - 1) < o->oPlatformUnkFC) - o->oAction = 2; - o->oPlatformUnkFC++; - } -} - -void falling_bowser_plat_act_2(void) { - Vec3f sp24; - s16 sp22; - f32 sp1C; - UNUSED struct Object *sp18 = o->oPlatformUnkF8; - if (o->oTimer == 0 || o->oTimer == 22) - cur_obj_play_sound_2(SOUND_GENERAL_BOWSER_PLATFORM_2); - if (o->oTimer < 22) { - set_environmental_camera_shake(SHAKE_ENV_FALLING_BITS_PLAT); - o->oVelY = 8.0f; - o->oGravity = 0.0f; - } else - o->oGravity = -4.0f; - if ((o->oTimer & 1) == 0 && o->oTimer < 14) { - sp22 = D_8032F698[o->oBehParams2ndByte].unk3 + (gDebugInfo[4][1] << 8); - sp1C = -(o->oTimer / 2) * 290 + 1740; - vec3f_copy_2(sp24, &o->oPosX); - o->oPosX = D_8032F698[o->oBehParams2ndByte].unk1 + sins(sp22 + 5296) * sp1C; - o->oPosZ = D_8032F698[o->oBehParams2ndByte].unk2 + coss(sp22 + 5296) * sp1C; - o->oPosY = 307.0f; - spawn_mist_particles_variable(4, 0, 100.0f); - o->oPosX = D_8032F698[o->oBehParams2ndByte].unk1 + sins(sp22 - 5296) * sp1C; - o->oPosZ = D_8032F698[o->oBehParams2ndByte].unk2 + coss(sp22 - 5296) * sp1C; - spawn_mist_particles_variable(4, 0, 100); - vec3f_copy_2(&o->oPosX, sp24); - } - cur_obj_move_using_fvel_and_gravity(); - if (o->oTimer > 300) - obj_mark_for_deletion(o); -} - -void (*sFallingBowserPlatformActions[])(void) = { falling_bowser_plat_act_0, - falling_bowser_plat_act_1, - falling_bowser_plat_act_2 }; - -struct ObjectHitbox sGrowingBowserFlameHitbox = { - /* interactType: */ INTERACT_FLAME, - /* downOffset: */ 20, - /* damageOrCoinValue: */ 1, - /* health: */ 0, - /* numLootCoins: */ 0, - /* radius: */ 10, - /* height: */ 40, - /* hurtboxRadius: */ 0, - /* hurtboxHeight: */ 0, -}; - -struct ObjectHitbox sBowserFlameHitbox = { - /* interactType: */ INTERACT_FLAME, - /* downOffset: */ 0, - /* damageOrCoinValue: */ 1, - /* health: */ 0, - /* numLootCoins: */ 0, - /* radius: */ 10, - /* height: */ 40, - /* hurtboxRadius: */ 0, - /* hurtboxHeight: */ 0, -}; - -f32 D_8032F748[] = { -8.0f, -6.0f, -3.0f }; - -void bhv_falling_bowser_platform_loop(void) { - cur_obj_call_action_function(sFallingBowserPlatformActions); -} - -void bowser_flame_despawn(void) { - obj_mark_for_deletion(o); - spawn_object_with_scale(o, MODEL_NONE, bhvBlackSmokeUpward, 1.0f); - if (random_float() < 0.1) - spawn_object(o, MODEL_YELLOW_COIN, bhvTemporaryYellowCoin); -} - -s32 bowser_flame_should_despawn(s32 maxTime) { - if (maxTime < o->oTimer) - return 1; - if (o->oFloorType == SURFACE_BURNING) - return 1; - if (o->oFloorType == SURFACE_DEATH_PLANE) - return 1; - return 0; -} - -void bhv_flame_bowser_init(void) { - o->oAnimState = (s32)(random_float() * 10.0f); - o->oMoveAngleYaw = random_u16(); - if (random_float() < 0.2) - o->oVelY = 80.0f; - else - o->oVelY = 20.0f; - o->oForwardVel = 10.0f; - o->oGravity = -1.0f; - o->oFlameScale = random_float() + 1.0f; -} - -void bhv_flame_large_burning_out_init(void) { - o->oAnimState = (s32)(random_float() * 10.0f); - o->oMoveAngleYaw = random_u16(); - o->oVelY = 10.0f; - o->oForwardVel = 0.0f; - o->oFlameScale = 7.0f; -} - -void bowser_flame_move(void) { - s32 sp4; - sp4 = ((o->oFlameSpeedTimerOffset + gGlobalTimer) & 0x3F) << 10; - o->oPosX += sins(o->oMoveAngleYaw) * sins(sp4) * 4.0f; - o->oPosZ += coss(o->oMoveAngleYaw) * sins(sp4) * 4.0f; -} - -void bhv_flame_bowser_loop(void) { - cur_obj_update_floor_and_walls(); - cur_obj_move_standard(78); - if (o->oVelY < -4.0f) - o->oVelY = -4.0f; - if (o->oAction == 0) { - cur_obj_become_intangible(); - bowser_flame_move(); - if (o->oMoveFlags & OBJ_MOVE_LANDED) { - o->oAction++; - if (cur_obj_has_behavior(bhvFlameLargeBurningOut)) - o->oFlameScale = 8.0f; - else - o->oFlameScale = random_float() * 2 + 6.0f; - o->oForwardVel = 0; - o->oVelY = 0; - o->oGravity = 0; + // Set layers if object is transparent or not + if (obj->oOpacity == 255) { + graphNode->fnNode.node.flags = (graphNode->fnNode.node.flags & 0xFF) | (LAYER_OPAQUE << 8); + } else { + graphNode->fnNode.node.flags = (graphNode->fnNode.node.flags & 0xFF) | (LAYER_TRANSPARENT << 8); } - } else { - cur_obj_become_tangible(); - if (o->oTimer > o->oFlameScale * 10 + 5.0f) { - o->oFlameScale -= 0.15; - if (o->oFlameScale <= 0) - bowser_flame_despawn(); + + gfx = gfxHead = alloc_display_list(2 * sizeof(Gfx)); + + // If TRUE, clear lighting to give rainbow color + if (obj->oBowserRainbowLight) { + gSPClearGeometryMode(gfx++, G_LIGHTING); } + + gSPEndDisplayList(gfx); } - cur_obj_scale(o->oFlameScale); - o->oGraphYOffset = o->header.gfx.scale[1] * 14.0f; - obj_set_hitbox(o, &sBowserFlameHitbox); -} -void bhv_flame_moving_forward_growing_init(void) { - o->oForwardVel = 30.0f; - obj_translate_xz_random(o, 80.0f); - o->oAnimState = (s32)(random_float() * 10.0f); - o->oFlameScale = 3.0f; -} - -void bhv_flame_moving_forward_growing_loop(void) { - UNUSED s32 unused; - UNUSED struct Object *sp18; - obj_set_hitbox(o, &sGrowingBowserFlameHitbox); - o->oFlameScale = o->oFlameScale + 0.5; - cur_obj_scale(o->oFlameScale); - if (o->oMoveAnglePitch > 0x800) - o->oMoveAnglePitch -= 0x200; - cur_obj_set_pos_via_transform(); - cur_obj_update_floor_height(); - if (o->oFlameScale > 30.0f) - obj_mark_for_deletion(o); - if (o->oPosY < o->oFloorHeight) { - o->oPosY = o->oFloorHeight; - sp18 = spawn_object(o, MODEL_RED_FLAME, bhvFlameBowser); - obj_mark_for_deletion(o); - } -} - -void bhv_flame_floating_landing_init(void) { - o->oAnimState = (s32)(random_float() * 10.0f); - o->oMoveAngleYaw = random_u16(); - if (o->oBehParams2ndByte != 0) - o->oForwardVel = random_float() * 5.0f; - else - o->oForwardVel = random_float() * 70.0f; - o->oVelY = random_float() * 20.0f; - o->oGravity = -1.0f; - o->oFlameSpeedTimerOffset = random_float() * 64.0f; -} - -void bhv_flame_floating_landing_loop(void) { - UNUSED s32 unused; - cur_obj_update_floor_and_walls(); - cur_obj_move_standard(0x4e); - bowser_flame_move(); - if (bowser_flame_should_despawn(900)) - obj_mark_for_deletion(o); - if (o->oVelY < D_8032F748[o->oBehParams2ndByte]) - o->oVelY = D_8032F748[o->oBehParams2ndByte]; - if (o->oMoveFlags & OBJ_MOVE_LANDED) { - if (o->oBehParams2ndByte == 0) - spawn_object(o, MODEL_RED_FLAME, bhvFlameLargeBurningOut); - else - spawn_object(o, MODEL_NONE, bhvBlueFlamesGroup); //? wonder if they meant MODEL_BLUE_FLAME? - obj_mark_for_deletion(o); - } - o->oGraphYOffset = o->header.gfx.scale[1] * 14.0f; -} - -void bhv_blue_bowser_flame_init(void) { - obj_translate_xz_random(o, 80.0f); - o->oAnimState = (s32)(random_float() * 10.0f); - o->oVelY = 7.0f; - o->oForwardVel = 35.0f; - o->oFlameScale = 3.0f; - o->oFlameUnkFC = random_float() * 0.5; - o->oGravity = 1.0f; - o->oFlameSpeedTimerOffset = (s32)(random_float() * 64.0f); -} - -void bhv_blue_bowser_flame_loop(void) { - s32 i; - obj_set_hitbox(o, &sGrowingBowserFlameHitbox); - if (o->oFlameScale < 16.0f) - o->oFlameScale = o->oFlameScale + 0.5; - cur_obj_scale(o->oFlameScale); - cur_obj_update_floor_and_walls(); - cur_obj_move_standard(0x4e); - if (o->oTimer > 0x14) { - if (o->oBehParams2ndByte == 0) - for (i = 0; i < 3; i++) - spawn_object_relative_with_scale(0, 0, 0, 0, 5.0f, o, MODEL_RED_FLAME, - bhvFlameFloatingLanding); - else { - spawn_object_relative_with_scale(1, 0, 0, 0, 8.0f, o, MODEL_BLUE_FLAME, - bhvFlameFloatingLanding); - spawn_object_relative_with_scale(2, 0, 0, 0, 8.0f, o, MODEL_BLUE_FLAME, - bhvFlameFloatingLanding); - } - obj_mark_for_deletion(o); - } -} - -void bhv_flame_bouncing_init(void) { - o->oAnimState = (s32)(random_float() * 10.0f); - o->oVelY = 30.0f; - o->oForwardVel = 20.0f; - o->oFlameScale = o->header.gfx.scale[0]; - o->oFlameSpeedTimerOffset = (s32)(random_float() * 64.0f); -} - -void bhv_flame_bouncing_loop(void) { - struct Object *bowser; - if (o->oTimer == 0) - o->oFlameBowser = cur_obj_nearest_object_with_behavior(bhvBowser); - bowser = o->oFlameBowser; - o->oForwardVel = 15.0f; - o->oBounciness = -1.0f; - cur_obj_scale(o->oFlameScale); - obj_set_hitbox(o, &sGrowingBowserFlameHitbox); - cur_obj_update_floor_and_walls(); - cur_obj_move_standard(78); - if (bowser_flame_should_despawn(300)) - obj_mark_for_deletion(o); - if (bowser != NULL) - if (bowser->oHeldState == 0) - if (lateral_dist_between_objects(o, bowser) < 300.0f) - obj_mark_for_deletion(o); -} - -void bhv_blue_flames_group_loop(void) { - struct Object *flame; - s32 i; - if (o->oTimer == 0) { - o->oMoveAngleYaw = obj_angle_to_object(o, gMarioObject); - o->oBlueFlameNextScale = 5.0f; - } - if (o->oTimer < 16) { - if ((o->oTimer & 1) == 0) { - for (i = 0; i < 3; i++) { - flame = spawn_object(o, MODEL_BLUE_FLAME, bhvFlameBouncing); - flame->oMoveAngleYaw += i * 0x5555; - flame->header.gfx.scale[0] = o->oBlueFlameNextScale; - } - o->oBlueFlameNextScale -= 0.5; - } - } else - obj_mark_for_deletion(o); + return gfxHead; } diff --git a/src/game/behaviors/bowser_bomb.inc.c b/src/game/behaviors/bowser_bomb.inc.c index e1e560ae..756b2051 100644 --- a/src/game/behaviors/bowser_bomb.inc.c +++ b/src/game/behaviors/bowser_bomb.inc.c @@ -1,14 +1,13 @@ -// bowser_bomb.c.inc +// bowser_bomb.inc.c void bhv_bowser_bomb_loop(void) { - if (obj_check_if_collided_with_object(o, gMarioObject) == 1) { + if (obj_check_if_collided_with_object(o, gMarioObject) == TRUE) { o->oInteractStatus &= ~INT_STATUS_INTERACTED; spawn_object(o, MODEL_EXPLOSION, bhvExplosion); o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } - if (o->oInteractStatus & INT_STATUS_HIT_MINE) - { + if (o->oInteractStatus & INT_STATUS_HIT_MINE) { spawn_object(o, MODEL_BOWSER_FLAMES, bhvBowserBombExplosion); create_sound_spawner(SOUND_GENERAL_BOWSER_BOMB_EXPLOSION); set_camera_shake_from_point(SHAKE_POS_LARGE, o->oPosX, o->oPosY, o->oPosZ); @@ -19,33 +18,40 @@ void bhv_bowser_bomb_loop(void) { } void bhv_bowser_bomb_explosion_loop(void) { - struct Object *mineSmoke; - cur_obj_scale((f32) o->oTimer / 14.0f * 9.0 + 1.0); + if ((o->oTimer % 4 == 0) && (o->oTimer < 20)) { - mineSmoke = spawn_object(o, MODEL_BOWSER_SMOKE, bhvBowserBombSmoke); + struct Object *mineSmoke = spawn_object(o, MODEL_BOWSER_SMOKE, bhvBowserBombSmoke); mineSmoke->oPosX += random_float() * 600.0f - 400.0f; mineSmoke->oPosZ += random_float() * 600.0f - 400.0f; mineSmoke->oVelY += random_float() * 10.0f; } - if (o->oTimer % 2 == 0) + if (o->oTimer % 2 == 0) { o->oAnimState++; - if (o->oTimer == 28) + } + + if (o->oTimer == 28) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } } void bhv_bowser_bomb_smoke_loop(void) { cur_obj_scale((f32) o->oTimer / 14.0f * 9.0 + 1.0); - if (o->oTimer % 2 == 0) + + if (o->oTimer % 2 == 0) { o->oAnimState++; + } o->oOpacity -= 10; - if (o->oOpacity < 10) + + if (o->oOpacity < 10) { o->oOpacity = 0; + } o->oPosY += o->oVelY; - if (o->oTimer == 28) + if (o->oTimer == 28) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } } diff --git a/src/game/behaviors/bowser_falling_platform.inc.c b/src/game/behaviors/bowser_falling_platform.inc.c new file mode 100644 index 00000000..85da27a7 --- /dev/null +++ b/src/game/behaviors/bowser_falling_platform.inc.c @@ -0,0 +1,107 @@ +// bowser_falling_platform.inc.c + +struct BowserFallingPlatformData { + const Collision *collision; + s16 posX; + s16 posZ; + s16 angle; +}; + +struct BowserFallingPlatformData sBowserFallingPlatform[] = { + { NULL, 0, 0, 0 }, + { bowser_3_seg7_collision_07004B94, -800, -1000, -20992 }, + { bowser_3_seg7_collision_07004C18, -1158, 390, -18432 }, + { bowser_3_seg7_collision_07004C9C, -1158, 390, -7680 }, + { bowser_3_seg7_collision_07004D20, 0, 1240, -6144 }, + { bowser_3_seg7_collision_07004DA4, 0, 1240, 6144 }, + { bowser_3_seg7_collision_07004E28, 1158, 390, 7680 }, + { bowser_3_seg7_collision_07004EAC, 1158, 390, 18432 }, + { bowser_3_seg7_collision_07004F30, 800, -1000, 20992 }, + { bowser_3_seg7_collision_07004FB4, 800, -1000, -31744 }, + { bowser_3_seg7_collision_07005038, -800, -1000, 31744 }, +}; + +void falling_bowser_plat_act_start(void) { + o->oBitsPlatformBowser = cur_obj_nearest_object_with_behavior(bhvBowser); + obj_set_collision_data(o, sBowserFallingPlatform[o->oBehParams2ndByte].collision); + if (o->oBitsPlatformBowser != NULL) { + o->oAction = BOWSER_BITS_PLAT_ACT_CHECK; + } +} + +void falling_bowser_plat_act_check(void) { + UNUSED u8 filler[4]; + struct Object *bowser = o->oBitsPlatformBowser; + + if (bowser->platform == o) { + if (bowser->oAction == BOWSER_ACT_BIG_JUMP + && bowser->oBowserStatus & BOWSER_STATUS_BIG_JUMP) { + o->oAction = BOWSER_BITS_PLAT_ACT_FALL; + } + } + + if (bowser->oHealth == 1 + && (bowser->oAction == BOWSER_ACT_DANCE || bowser->oHeldState != HELD_FREE)) { + o->oSubAction = 1; + } + + if (o->oSubAction == 0) { + o->oBitsPlatformTimer = 0; + } else { + if ((gDebugInfo[DEBUG_PAGE_EFFECTINFO][6] + 20) + * (o->oBehParams2ndByte - 1) < o->oBitsPlatformTimer) { + o->oAction = BOWSER_BITS_PLAT_ACT_FALL; + } + o->oBitsPlatformTimer++; + } +} + +void falling_bowser_plat_act_fall(void) { + Vec3f pos; + s16 angle; + f32 val; + UNUSED struct Object *bowser = o->oBitsPlatformBowser; + + if (o->oTimer == 0 || o->oTimer == 22) { + cur_obj_play_sound_2(SOUND_GENERAL_BOWSER_PLATFORM_2); + } + + if (o->oTimer < 22) { + set_environmental_camera_shake(SHAKE_ENV_FALLING_BITS_PLAT); + o->oVelY = 8.0f; + o->oGravity = 0.0f; + } else { + o->oGravity = -4.0f; + } + + if (!(o->oTimer & 1) && o->oTimer < 14) { + angle = sBowserFallingPlatform[o->oBehParams2ndByte].angle + + (gDebugInfo[DEBUG_PAGE_EFFECTINFO][1] << 8); + val = -(o->oTimer / 2) * 290 + 1740; + vec3f_copy_2(pos, &o->oPosX); + o->oPosX = sBowserFallingPlatform[o->oBehParams2ndByte].posX + sins(angle + 0x14B0) * val; + o->oPosZ = sBowserFallingPlatform[o->oBehParams2ndByte].posZ + coss(angle + 0x14B0) * val; + o->oPosY = 307.0f; + spawn_mist_particles_variable(4, 0, 100.0f); + o->oPosX = sBowserFallingPlatform[o->oBehParams2ndByte].posX + sins(angle - 0x14B0) * val; + o->oPosZ = sBowserFallingPlatform[o->oBehParams2ndByte].posZ + coss(angle - 0x14B0) * val; + spawn_mist_particles_variable(4, 0, 100); + vec3f_copy_2(&o->oPosX, pos); + } + + cur_obj_move_using_fvel_and_gravity(); + + if (o->oTimer > 300) { + obj_mark_for_deletion(o); + } +} + +void (*sFallingBowserPlatformActions[])(void) = { + falling_bowser_plat_act_start, + falling_bowser_plat_act_check, + falling_bowser_plat_act_fall, +}; + +void bhv_falling_bowser_platform_loop(void) { + cur_obj_call_action_function(sFallingBowserPlatformActions); +} diff --git a/src/game/behaviors/bowser_flame.inc.c b/src/game/behaviors/bowser_flame.inc.c new file mode 100644 index 00000000..08a6d670 --- /dev/null +++ b/src/game/behaviors/bowser_flame.inc.c @@ -0,0 +1,285 @@ +// bowser_flame.inc.c + +struct ObjectHitbox sGrowingBowserFlameHitbox = { + /* interactType: */ INTERACT_FLAME, + /* downOffset: */ 20, + /* damageOrCoinValue: */ 1, + /* health: */ 0, + /* numLootCoins: */ 0, + /* radius: */ 10, + /* height: */ 40, + /* hurtboxRadius: */ 0, + /* hurtboxHeight: */ 0, +}; + +struct ObjectHitbox sBowserFlameHitbox = { + /* interactType: */ INTERACT_FLAME, + /* downOffset: */ 0, + /* damageOrCoinValue: */ 1, + /* health: */ 0, + /* numLootCoins: */ 0, + /* radius: */ 10, + /* height: */ 40, + /* hurtboxRadius: */ 0, + /* hurtboxHeight: */ 0, +}; + +void bowser_flame_despawn(void) { + obj_mark_for_deletion(o); + spawn_object_with_scale(o, MODEL_NONE, bhvBlackSmokeUpward, 1.0f); + if (random_float() < 0.1) { + spawn_object(o, MODEL_YELLOW_COIN, bhvTemporaryYellowCoin); + } +} + +s32 bowser_flame_should_despawn(s32 maxTime) { + if (maxTime < o->oTimer) { + return TRUE; + } + + // Flames should despawn if they fall off the arena. + if (o->oFloorType == SURFACE_BURNING) { + return TRUE; + } + if (o->oFloorType == SURFACE_DEATH_PLANE) { + return TRUE; + } + + return FALSE; +} + +void bhv_flame_bowser_init(void) { + o->oAnimState = (s32)(random_float() * 10.0f); + o->oMoveAngleYaw = random_u16(); + o->oVelY = random_float() < 0.2 ? 80.0f : 20.0f; + o->oForwardVel = 10.0f; + o->oGravity = -1.0f; + o->oFlameScale = random_float() + 1.0f; +} + +void bhv_flame_large_burning_out_init(void) { + o->oAnimState = (s32)(random_float() * 10.0f); + o->oMoveAngleYaw = random_u16(); + o->oVelY = 10.0f; + o->oForwardVel = 0.0f; + o->oFlameScale = 7.0f; +} + +void bowser_flame_move(void) { + s32 timer = ((o->oFlameSpeedTimerOffset + gGlobalTimer) & 0x3F) << 10; + o->oPosX += sins(o->oMoveAngleYaw) * sins(timer) * 4.0f; + o->oPosZ += coss(o->oMoveAngleYaw) * sins(timer) * 4.0f; +} + +void bhv_flame_bowser_loop(void) { + cur_obj_update_floor_and_walls(); + cur_obj_move_standard(78); + + if (o->oVelY < -4.0f) { + o->oVelY = -4.0f; + } + + if (o->oAction == 0) { + cur_obj_become_intangible(); + bowser_flame_move(); + + if (o->oMoveFlags & OBJ_MOVE_LANDED) { + o->oAction++; + if (cur_obj_has_behavior(bhvFlameLargeBurningOut)) { + o->oFlameScale = 8.0f; + } else { + o->oFlameScale = random_float() * 2 + 6.0f; + } + o->oForwardVel = 0; + o->oVelY = 0; + o->oGravity = 0; + } + } else { + cur_obj_become_tangible(); + + if (o->oTimer > o->oFlameScale * 10 + 5.0f) { + o->oFlameScale -= 0.15; + if (o->oFlameScale <= 0) { + bowser_flame_despawn(); + } + } + } + + cur_obj_scale(o->oFlameScale); + o->oGraphYOffset = o->header.gfx.scale[1] * 14.0f; + obj_set_hitbox(o, &sBowserFlameHitbox); +} + +void bhv_flame_moving_forward_growing_init(void) { + o->oForwardVel = 30.0f; + obj_translate_xz_random(o, 80.0f); + o->oAnimState = (s32)(random_float() * 10.0f); + o->oFlameScale = 3.0f; +} + +void bhv_flame_moving_forward_growing_loop(void) { + UNUSED u8 filler[4]; + UNUSED struct Object *flame; + + obj_set_hitbox(o, &sGrowingBowserFlameHitbox); + o->oFlameScale = o->oFlameScale + 0.5; + cur_obj_scale(o->oFlameScale); + + if (o->oMoveAnglePitch > 0x800) { + o->oMoveAnglePitch -= 0x200; + } + + cur_obj_set_pos_via_transform(); + cur_obj_update_floor_height(); + + if (o->oFlameScale > 30.0f) { + obj_mark_for_deletion(o); + } + + if (o->oPosY < o->oFloorHeight) { + o->oPosY = o->oFloorHeight; + flame = spawn_object(o, MODEL_RED_FLAME, bhvFlameBowser); + obj_mark_for_deletion(o); + } +} + +void bhv_flame_floating_landing_init(void) { + o->oAnimState = (s32)(random_float() * 10.0f); + o->oMoveAngleYaw = random_u16(); + if (o->oBehParams2ndByte != 0) { + o->oForwardVel = random_float() * 5.0f; + } else { + o->oForwardVel = random_float() * 70.0f; + } + o->oVelY = random_float() * 20.0f; + o->oGravity = -1.0f; + o->oFlameSpeedTimerOffset = random_float() * 64.0f; +} + +f32 sFlameFloatingYLimit[] = { -8.0f, -6.0f, -3.0f }; + +void bhv_flame_floating_landing_loop(void) { + UNUSED u8 filler[4]; + + cur_obj_update_floor_and_walls(); + cur_obj_move_standard(78); + bowser_flame_move(); + + if (bowser_flame_should_despawn(900)) { + obj_mark_for_deletion(o); + } + + if (o->oVelY < sFlameFloatingYLimit[o->oBehParams2ndByte]) { + o->oVelY = sFlameFloatingYLimit[o->oBehParams2ndByte]; + } + + if (o->oMoveFlags & OBJ_MOVE_LANDED) { + if (o->oBehParams2ndByte == 0) { + spawn_object(o, MODEL_RED_FLAME, bhvFlameLargeBurningOut); + } else { + spawn_object(o, MODEL_NONE, bhvBlueFlamesGroup); //? wonder if they meant MODEL_BLUE_FLAME? + } + obj_mark_for_deletion(o); + } + + o->oGraphYOffset = o->header.gfx.scale[1] * 14.0f; +} + +void bhv_blue_bowser_flame_init(void) { + obj_translate_xz_random(o, 80.0f); + o->oAnimState = (s32)(random_float() * 10.0f); + o->oVelY = 7.0f; + o->oForwardVel = 35.0f; + o->oFlameScale = 3.0f; + o->oFlameUnusedRand = random_float() * 0.5; + o->oGravity = 1.0f; + o->oFlameSpeedTimerOffset = (s32)(random_float() * 64.0f); +} + +void bhv_blue_bowser_flame_loop(void) { + s32 i; + + obj_set_hitbox(o, &sGrowingBowserFlameHitbox); + + if (o->oFlameScale < 16.0f) { + o->oFlameScale = o->oFlameScale + 0.5; + } + + cur_obj_scale(o->oFlameScale); + cur_obj_update_floor_and_walls(); + cur_obj_move_standard(78); + + if (o->oTimer > 20) { + if (o->oBehParams2ndByte == 0) { + for (i = 0; i < 3; i++) { + spawn_object_relative_with_scale(0, 0, 0, 0, 5.0f, o, MODEL_RED_FLAME, + bhvFlameFloatingLanding); + } + } else { + spawn_object_relative_with_scale(1, 0, 0, 0, 8.0f, o, MODEL_BLUE_FLAME, + bhvFlameFloatingLanding); + spawn_object_relative_with_scale(2, 0, 0, 0, 8.0f, o, MODEL_BLUE_FLAME, + bhvFlameFloatingLanding); + } + obj_mark_for_deletion(o); + } +} + +void bhv_flame_bouncing_init(void) { + o->oAnimState = (s32)(random_float() * 10.0f); + o->oVelY = 30.0f; + o->oForwardVel = 20.0f; + o->oFlameScale = o->header.gfx.scale[0]; + o->oFlameSpeedTimerOffset = (s32)(random_float() * 64.0f); +} + +void bhv_flame_bouncing_loop(void) { + struct Object *bowser; + + if (o->oTimer == 0) { + o->oFlameBowser = cur_obj_nearest_object_with_behavior(bhvBowser); + } + + bowser = o->oFlameBowser; + o->oForwardVel = 15.0f; + o->oBounciness = -1.0f; + cur_obj_scale(o->oFlameScale); + obj_set_hitbox(o, &sGrowingBowserFlameHitbox); + cur_obj_update_floor_and_walls(); + cur_obj_move_standard(78); + + if (bowser_flame_should_despawn(300)) { + obj_mark_for_deletion(o); + } + + if (bowser != NULL) { + if (bowser->oHeldState == HELD_FREE) { + if (lateral_dist_between_objects(o, bowser) < 300.0f) { + obj_mark_for_deletion(o); + } + } + } +} + +void bhv_blue_flames_group_loop(void) { + struct Object *flame; + s32 i; + + if (o->oTimer == 0) { + o->oMoveAngleYaw = obj_angle_to_object(o, gMarioObject); + o->oBlueFlameNextScale = 5.0f; + } + + if (o->oTimer < 16) { + if (!(o->oTimer & 1)) { + for (i = 0; i < 3; i++) { + flame = spawn_object(o, MODEL_BLUE_FLAME, bhvFlameBouncing); + flame->oMoveAngleYaw += i * 0x5555; + flame->header.gfx.scale[0] = o->oBlueFlameNextScale; + } + o->oBlueFlameNextScale -= 0.5; + } + } else { + obj_mark_for_deletion(o); + } +} diff --git a/src/game/behaviors/bowser_key.inc.c b/src/game/behaviors/bowser_key.inc.c index 584b1900..df5d4447 100644 --- a/src/game/behaviors/bowser_key.inc.c +++ b/src/game/behaviors/bowser_key.inc.c @@ -1,41 +1,46 @@ -// bowser_key.c.inc +// bowser_key.inc.c struct ObjectHitbox sBowserKeyHitbox = { - /* interactType: */ INTERACT_STAR_OR_KEY, - /* downOffset: */ 0, + /* interactType: */ INTERACT_STAR_OR_KEY, + /* downOffset: */ 0, /* damageOrCoinValue: */ 0, - /* health: */ 0, - /* numLootCoins: */ 0, - /* radius: */ 160, - /* height: */ 100, - /* hurtboxRadius: */ 160, - /* hurtboxHeight: */ 100, + /* health: */ 0, + /* numLootCoins: */ 0, + /* radius: */ 160, + /* height: */ 100, + /* hurtboxRadius: */ 160, + /* hurtboxHeight: */ 100, }; void bhv_bowser_key_loop(void) { cur_obj_scale(0.5f); - if (o->oAngleVelYaw > 0x400) + + if (o->oAngleVelYaw > 0x400) { o->oAngleVelYaw -= 0x100; + } + o->oFaceAngleYaw += o->oAngleVelYaw; o->oFaceAngleRoll = -0x4000; o->oGraphYOffset = 165.0f; + if (o->oAction == 0) { - if (o->oTimer == 0) + if (o->oTimer == 0) { o->oVelY = 70.0f; + } + spawn_sparkle_particles(3, 200, 80, -60); spawn_object(o, MODEL_NONE, bhvSparkleSpawn); cur_obj_update_floor_and_walls(); cur_obj_move_standard(78); - if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) + + if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) { o->oAction++; - else if (o->oMoveFlags & OBJ_MOVE_LANDED) -#ifndef VERSION_JP - cur_obj_play_sound_2(SOUND_GENERAL_UNKNOWN3_2); -#else - cur_obj_play_sound_2(SOUND_GENERAL_UNKNOWN3_LOWPRIO); -#endif + } else if (o->oMoveFlags & OBJ_MOVE_LANDED) { + cur_obj_play_sound_2(SOUND_GENERAL_UNKNOWN3); + } } else { obj_set_hitbox(o, &sBowserKeyHitbox); + if (o->oInteractStatus & INT_STATUS_INTERACTED) { mark_obj_for_deletion(o); o->oInteractStatus = 0; diff --git a/src/game/behaviors/bowser_key_cutscene.inc.c b/src/game/behaviors/bowser_key_cutscene.inc.c index e840b893..6f3ac484 100644 --- a/src/game/behaviors/bowser_key_cutscene.inc.c +++ b/src/game/behaviors/bowser_key_cutscene.inc.c @@ -1,47 +1,55 @@ // bowser_key_cutscene.inc.c Gfx *geo_scale_bowser_key(s32 run, struct GraphNode *node, UNUSED f32 mtx[4][4]) { - struct Object *sp4; if (run == TRUE) { - sp4 = (struct Object *) gCurGraphNodeObject; + struct Object *sp4 = (struct Object *) gCurGraphNodeObject; ((struct GraphNodeScale *) node->next)->scale = sp4->oBowserKeyScale; } - return 0; + return NULL; } void bhv_bowser_key_unlock_door_loop(void) { - s32 animTimer; - animTimer = o->header.gfx.animInfo.animFrame; + s32 animFrame = o->header.gfx.animInfo.animFrame; + cur_obj_init_animation_with_sound(0); - if (animTimer < 38) + + if (animFrame < 38) { o->oBowserKeyScale = 0.0f; - else if (animTimer < 49) + } else if (animFrame < 49) { o->oBowserKeyScale = 0.2f; - else if (animTimer < 58) - o->oBowserKeyScale = (animTimer - 53) * 0.11875f + 0.2; // 0.11875? - else if (animTimer < 59) + } else if (animFrame < 58) { + o->oBowserKeyScale = (animFrame - 53) * 0.11875f + 0.2; // 0.11875? + } else if (animFrame < 59) { o->oBowserKeyScale = 1.1f; - else if (animTimer < 60) + } else if (animFrame < 60) { o->oBowserKeyScale = 1.05f; - else + } else { o->oBowserKeyScale = 1.0f; - if (o->oTimer > 150) + } + + if (o->oTimer > 150) { obj_mark_for_deletion(o); + } } void bhv_bowser_key_course_exit_loop(void) { - s32 animTimer = o->header.gfx.animInfo.animFrame; + s32 animFrame = o->header.gfx.animInfo.animFrame; + cur_obj_init_animation_with_sound(1); - if (animTimer < 38) + + if (animFrame < 38) { o->oBowserKeyScale = 0.2f; - else if (animTimer < 52) - o->oBowserKeyScale = (animTimer - 42) * 0.042857f + 0.2; // TODO 3/70? - else if (animTimer < 94) + } else if (animFrame < 52) { + o->oBowserKeyScale = (animFrame - 42) * 0.042857f + 0.2; // TODO 3/70? + } else if (animFrame < 94) { o->oBowserKeyScale = 0.8f; - else if (animTimer < 101) - o->oBowserKeyScale = (101 - animTimer) * 0.085714f + 0.2; // TODO 6/70? - else + } else if (animFrame < 101) { + o->oBowserKeyScale = (101 - animFrame) * 0.085714f + 0.2; // TODO 6/70? + } else { o->oBowserKeyScale = 0.2f; - if (o->oTimer > 138) + } + + if (o->oTimer > 138) { obj_mark_for_deletion(o); + } } diff --git a/src/game/behaviors/bowser_puzzle_piece.inc.c b/src/game/behaviors/bowser_puzzle_piece.inc.c index 14db4de6..aaed6022 100644 --- a/src/game/behaviors/bowser_puzzle_piece.inc.c +++ b/src/game/behaviors/bowser_puzzle_piece.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for the sliding Bowser puzzle in Lethal Lava Land. */ @@ -103,12 +104,13 @@ void bhv_lll_bowser_puzzle_spawn_pieces(f32 pieceWidth) { s32 i; // Spawn all 14 puzzle pieces. - for (i = 0; i < 14; i++) + for (i = 0; i < 14; i++) { bhv_lll_bowser_puzzle_spawn_piece(sBowserPuzzlePieces[i].model, bhvLllBowserPuzzlePiece, sBowserPuzzlePieces[i].xOffset * pieceWidth / 10.0f, sBowserPuzzlePieces[i].zOffset * pieceWidth / 10.0f, sBowserPuzzlePieces[i].initialAction, sBowserPuzzlePieces[i].actionList); + } // The pieces should only be spawned once so go to the next action. o->oAction++; @@ -119,17 +121,20 @@ void bhv_lll_bowser_puzzle_spawn_pieces(f32 pieceWidth) { */ void bhv_lll_bowser_puzzle_loop(void) { s32 i; - UNUSED struct Object *sp28; + switch (o->oAction) { case BOWSER_PUZZLE_ACT_SPAWN_PIECES: bhv_lll_bowser_puzzle_spawn_pieces(480.0f); break; + case BOWSER_PUZZLE_ACT_WAIT_FOR_COMPLETE: // If both completion flags are set and Mario is within 1000 units... if (o->oBowserPuzzleCompletionFlags == 3 && o->oDistanceToMario < 1000.0f) { // Spawn 5 coins. - for (i = 0; i < 5; i++) - sp28 = spawn_object(o, MODEL_YELLOW_COIN, bhvSingleCoinGetsSpawned); + for (i = 0; i < 5; i++) { + UNUSED struct Object *coin = + spawn_object(o, MODEL_YELLOW_COIN, bhvSingleCoinGetsSpawned); + } // Reset completion flags (even though they never get checked again). o->oBowserPuzzleCompletionFlags = 0; @@ -138,6 +143,7 @@ void bhv_lll_bowser_puzzle_loop(void) { o->oAction++; } break; + case BOWSER_PUZZLE_ACT_DONE: break; } @@ -164,8 +170,9 @@ void bhv_lll_bowser_puzzle_piece_update(void) { s8 *nextAction = o->oBowserPuzzlePieceNextAction; // If Mario is standing on this puzzle piece, set a flag in the parent. - if (gMarioObject->platform == o) + if (gMarioObject->platform == o) { o->parentObj->oBowserPuzzleCompletionFlags = 1; + } // If we should advance to the next action... if (o->oBowserPuzzlePieceContinuePerformingAction == 0) { @@ -193,14 +200,16 @@ void bhv_lll_bowser_puzzle_piece_update(void) { void bhv_lll_bowser_puzzle_piece_move(f32 xOffset, f32 zOffset, s32 duration, UNUSED s32 a3) { // For the first 20 frames, shake the puzzle piece up and down. if (o->oTimer < 20) { - if (o->oTimer % 2) + if (o->oTimer % 2) { o->oBowserPuzzlePieceOffsetY = 0.0f; - else + } else { o->oBowserPuzzlePieceOffsetY = -6.0f; + } } else { // On frame 20, play the shifting sound. - if (o->oTimer == 20) + if (o->oTimer == 20) { cur_obj_play_sound_2(SOUND_OBJ2_BOWSER_PUZZLE_PIECE_MOVE); + } // For the number of frames specified by duration, move the piece. if (o->oTimer < duration + 20) { @@ -208,8 +217,8 @@ void bhv_lll_bowser_puzzle_piece_move(f32 xOffset, f32 zOffset, s32 duration, UN o->oBowserPuzzlePieceOffsetZ += zOffset; } else { // This doesn't actually accomplish anything since - // cur_obj_change_action is going to be called before the - // next action is performed anyway. + // cur_obj_change_action is going to be called before the + // next action is performed anyway. o->oAction = 2; // Advance to the next action. @@ -219,14 +228,15 @@ void bhv_lll_bowser_puzzle_piece_move(f32 xOffset, f32 zOffset, s32 duration, UN } void bhv_lll_bowser_puzzle_piece_idle(void) { - UNUSED s32 sp4; + UNUSED s32 unused; // For the first 24 frames, do nothing. - if (o->oTimer < 24) - sp4 = 0; - else + if (o->oTimer < 24) { + unused = 0; + } else { // Then advance to the next action. o->oBowserPuzzlePieceContinuePerformingAction = 0; + } } void bhv_lll_bowser_puzzle_piece_move_left(void) { @@ -246,10 +256,13 @@ void bhv_lll_bowser_puzzle_piece_move_down(void) { } void (*sBowserPuzzlePieceActions[])(void) = { - bhv_lll_bowser_puzzle_piece_action_0, bhv_lll_bowser_puzzle_piece_action_1, - bhv_lll_bowser_puzzle_piece_idle, bhv_lll_bowser_puzzle_piece_move_left, - bhv_lll_bowser_puzzle_piece_move_right, bhv_lll_bowser_puzzle_piece_move_up, - bhv_lll_bowser_puzzle_piece_move_down + bhv_lll_bowser_puzzle_piece_action_0, + bhv_lll_bowser_puzzle_piece_action_1, + bhv_lll_bowser_puzzle_piece_idle, + bhv_lll_bowser_puzzle_piece_move_left, + bhv_lll_bowser_puzzle_piece_move_right, + bhv_lll_bowser_puzzle_piece_move_up, + bhv_lll_bowser_puzzle_piece_move_down, }; void bhv_lll_bowser_puzzle_piece_loop(void) { diff --git a/src/game/behaviors/break_particles.inc.c b/src/game/behaviors/break_particles.inc.c index a5a6a069..a3db1aa4 100644 --- a/src/game/behaviors/break_particles.inc.c +++ b/src/game/behaviors/break_particles.inc.c @@ -1,8 +1,9 @@ -// break_particles.c.inc +// break_particles.inc.c void spawn_triangle_break_particles(s16 numTris, s16 triModel, f32 triSize, s16 triAnimState) { struct Object *triangle; s32 i; + for (i = 0; i < numTris; i++) { triangle = spawn_object(o, triModel, bhvBreakBoxTriangle); triangle->oAnimState = triAnimState; @@ -11,7 +12,8 @@ void spawn_triangle_break_particles(s16 numTris, s16 triModel, f32 triSize, s16 triangle->oFaceAngleYaw = triangle->oMoveAngleYaw; triangle->oFaceAnglePitch = random_u16(); triangle->oVelY = random_f32_around_zero(50.0f); - if (triModel == 138 || triModel == 56) { + + if (triModel == MODEL_DIRT_ANIMATION || triModel == MODEL_SL_CRACKED_ICE_CHUNK) { triangle->oAngleVelPitch = 0xF00; triangle->oAngleVelYaw = 0x500; triangle->oForwardVel = 30.0f; @@ -19,6 +21,7 @@ void spawn_triangle_break_particles(s16 numTris, s16 triModel, f32 triSize, s16 triangle->oAngleVelPitch = 0x80 * (s32)(random_float() + 50.0f); triangle->oForwardVel = 30.0f; } + obj_scale(triangle, triSize); } } diff --git a/src/game/behaviors/breakable_box.inc.c b/src/game/behaviors/breakable_box.inc.c index f46954c3..361e9290 100644 --- a/src/game/behaviors/breakable_box.inc.c +++ b/src/game/behaviors/breakable_box.inc.c @@ -1,11 +1,14 @@ -// breakable_box.c.inc +// breakable_box.inc.c void bhv_breakable_box_loop(void) { obj_set_hitbox(o, &sBreakableBoxHitbox); cur_obj_set_model(MODEL_BREAKABLE_BOX_SMALL); - if (o->oTimer == 0) + + if (o->oTimer == 0) { breakable_box_init(); - if (cur_obj_was_attacked_or_ground_pounded() != 0) { + } + + if (cur_obj_was_attacked_or_ground_pounded()) { obj_explode_and_spawn_coins(46.0f, 1); create_sound_spawner(SOUND_GENERAL_BREAK_BOX); } diff --git a/src/game/behaviors/breakable_box_small.inc.c b/src/game/behaviors/breakable_box_small.inc.c index bb9a4edd..1cf6ae74 100644 --- a/src/game/behaviors/breakable_box_small.inc.c +++ b/src/game/behaviors/breakable_box_small.inc.c @@ -1,4 +1,4 @@ -// breakable_box.c.inc +// breakable_box.inc.c struct ObjectHitbox sBreakableBoxSmallHitbox = { /* interactType: */ INTERACT_GRABBABLE, @@ -29,27 +29,30 @@ void small_breakable_box_spawn_dust(void) { } void small_breakable_box_act_move(void) { - s16 sp1E = object_step(); + s16 collisionFlags = object_step(); obj_attack_collided_from_other_object(o); - if (sp1E == 1) + + if (collisionFlags == OBJ_COL_FLAG_GROUNDED) { cur_obj_play_sound_2(SOUND_GENERAL_BOX_LANDING_2); - if (sp1E & 1) { + } + + if (collisionFlags & OBJ_COL_FLAG_GROUNDED) { if (o->oForwardVel > 20.0f) { cur_obj_play_sound_2(SOUND_ENV_SLIDING); small_breakable_box_spawn_dust(); } } - if (sp1E & 2) { + if (collisionFlags & OBJ_COL_FLAG_HIT_WALL) { spawn_mist_particles(); - spawn_triangle_break_particles(20, 138, 0.7f, 3); + spawn_triangle_break_particles(20, MODEL_DIRT_ANIMATION, 0.7f, 3); obj_spawn_yellow_coins(o, 3); create_sound_spawner(SOUND_GENERAL_BREAK_BOX); o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } - obj_check_floor_death(sp1E, sObjFloor); + obj_check_floor_death(collisionFlags, sObjFloor); } void breakable_box_small_released_loop(void) { @@ -57,10 +60,11 @@ void breakable_box_small_released_loop(void) { // Begin flashing if (o->oBreakableBoxSmallFramesSinceReleased > 810) { - if (o->oBreakableBoxSmallFramesSinceReleased & 1) + if (o->oBreakableBoxSmallFramesSinceReleased & 1) { o->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE; - else + } else { o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE; + } } // Despawn, and create a corkbox respawner @@ -86,8 +90,9 @@ void breakable_box_small_idle_loop(void) { break; } - if (o->oBreakableBoxSmallReleased == 1) + if (o->oBreakableBoxSmallReleased == TRUE) { breakable_box_small_released_loop(); + } } void breakable_box_small_get_dropped(void) { @@ -96,7 +101,7 @@ void breakable_box_small_get_dropped(void) { cur_obj_get_dropped(); o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE; o->oHeldState = 0; - o->oBreakableBoxSmallReleased = 1; + o->oBreakableBoxSmallReleased = TRUE; o->oBreakableBoxSmallFramesSinceReleased = 0; } @@ -106,10 +111,10 @@ void breakable_box_small_get_thrown(void) { cur_obj_enable_rendering(); o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE; o->oHeldState = 0; - o->oFlags &= ~0x08; + o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; o->oForwardVel = 40.0f; o->oVelY = 20.0f; - o->oBreakableBoxSmallReleased = 1; + o->oBreakableBoxSmallReleased = TRUE; o->oBreakableBoxSmallFramesSinceReleased = 0; o->activeFlags &= ~ACTIVE_FLAG_UNK9; } diff --git a/src/game/behaviors/breakable_wall.inc.c b/src/game/behaviors/breakable_wall.inc.c index dbb92c8d..53e21de0 100644 --- a/src/game/behaviors/breakable_wall.inc.c +++ b/src/game/behaviors/breakable_wall.inc.c @@ -1,16 +1,22 @@ -// breakable_wall.c.inc +// breakable_wall.inc.c void bhv_wf_breakable_wall_loop(void) { if (gMarioStates[0].action == ACT_SHOT_FROM_CANNON) { cur_obj_become_tangible(); + if (obj_check_if_collided_with_object(o, gMarioObject)) { - if (cur_obj_has_behavior(bhvWfBreakableWallRight)) + if (cur_obj_has_behavior(bhvWfBreakableWallRight)) { play_puzzle_jingle(); + } + create_sound_spawner(SOUND_GENERAL_WALL_EXPLOSION); - o->oInteractType = 8; + + o->oInteractType = INTERACT_DAMAGE; o->oDamageOrCoinValue = 1; + obj_explode_and_spawn_coins(80.0f, 0); } - } else + } else { cur_obj_become_intangible(); + } } diff --git a/src/game/behaviors/bub.inc.c b/src/game/behaviors/bub.inc.c index e8e63096..47c9b6ae 100644 --- a/src/game/behaviors/bub.inc.c +++ b/src/game/behaviors/bub.inc.c @@ -1,23 +1,24 @@ -// bub.c.inc +// bub.inc.c // NOTE: These first set of functions spawn a school of bub depending on objF4's // value. The later action functions seem to check Y distance to Mario and proceed // to do nothing, which indicates this behavior set is incomplete. -// TODO: Rename these. These have nothing to do with birds. void bub_spawner_act_0(void) { s32 i; s32 sp18 = o->oBirdChirpChirpUnkF4; if (o->oDistanceToMario < 1500.0f) { - for (i = 0; i < sp18; i++) + for (i = 0; i < sp18; i++) { spawn_object(o, MODEL_BUB, bhvBub); + } o->oAction = 1; } } void bub_spawner_act_1(void) { - if (gMarioObject->oPosY - o->oPosY > 2000.0f) + if (gMarioObject->oPosY - o->oPosY > 2000.0f) { o->oAction = 2; + } } void bub_spawner_act_2(void) { @@ -28,8 +29,12 @@ void bub_spawner_act_3(void) { o->oAction = 0; } -void (*sBirdChirpChirpActions[])(void) = { bub_spawner_act_0, bub_spawner_act_1, - bub_spawner_act_2, bub_spawner_act_3 }; +void (*sBirdChirpChirpActions[])(void) = { + bub_spawner_act_0, + bub_spawner_act_1, + bub_spawner_act_2, + bub_spawner_act_3, +}; void bhv_bub_spawner_loop(void) { cur_obj_call_action_function(sBirdChirpChirpActions); @@ -38,9 +43,9 @@ void bhv_bub_spawner_loop(void) { void bub_move_vertically(s32 a0) { f32 sp1C = o->parentObj->oPosY; if (sp1C - 100.0f - o->oCheepCheepUnk104 < o->oPosY - && o->oPosY < sp1C + 1000.0f + o->oCheepCheepUnk104) + && o->oPosY < sp1C + 1000.0f + o->oCheepCheepUnk104) { o->oPosY = approach_f32_symmetric(o->oPosY, o->oCheepCheepUnkF8, a0); - else { + } else { } } @@ -52,73 +57,115 @@ void bub_act_0(void) { void bub_act_1(void) { f32 dy; + if (o->oTimer == 0) { o->oForwardVel = random_float() * 2 + 2; o->oCheepCheepUnk108 = random_float(); } + dy = o->oPosY - gMarioObject->oPosY; + if (o->oPosY < o->oCheepCheepUnkF4 - 50.0f) { - if (dy < 0.0f) + if (dy < 0.0f) { dy = 0.0f - dy; - if (dy < 500.0f) + } + + if (dy < 500.0f) { bub_move_vertically(1); - else + } else { bub_move_vertically(4); + } } else { o->oPosY = o->oCheepCheepUnkF4 - 50.0f; - if (dy > 300.0f) + + if (dy > 300.0f) { o->oPosY = o->oPosY - 1.0f; + } } - if (800.0f < cur_obj_lateral_dist_from_mario_to_home()) + + if (800.0f < cur_obj_lateral_dist_from_mario_to_home()) { o->oAngleToMario = cur_obj_angle_to_home(); + } + cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x100); - if (o->oDistanceToMario < 200.0f) - if (o->oCheepCheepUnk108 < 0.5) + + if (o->oDistanceToMario < 200.0f) { + if (o->oCheepCheepUnk108 < 0.5) { o->oAction = 2; - if (o->oInteractStatus & INT_STATUS_INTERACTED) + } + } + + if (o->oInteractStatus & INT_STATUS_INTERACTED) { o->oAction = 2; + } } void bub_act_2(void) { f32 dy; + if (o->oTimer < 20) { - if (o->oInteractStatus & INT_STATUS_INTERACTED) + if (o->oInteractStatus & INT_STATUS_INTERACTED) { spawn_object(o, MODEL_WHITE_PARTICLE_SMALL, bhvSmallParticleSnow); - } else + } + } else { o->oInteractStatus = 0; - if (o->oTimer == 0) + } + + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_GENERAL_MOVING_WATER); - if (o->oForwardVel == 0.0f) + } + + if (o->oForwardVel == 0.0f) { o->oForwardVel = 6.0f; + } + dy = o->oPosY - gMarioObject->oPosY; + if (o->oPosY < o->oCheepCheepUnkF4 - 50.0f) { - if (dy < 0.0f) + if (dy < 0.0f) { dy = 0.0f - dy; - if (dy < 500.0f) + } + + if (dy < 500.0f) { bub_move_vertically(2); - else + } else { bub_move_vertically(4); + } } else { o->oPosY = o->oCheepCheepUnkF4 - 50.0f; - if (dy > 300.0f) + + if (dy > 300.0f) { o->oPosY -= 1.0f; + } } - if (cur_obj_lateral_dist_from_mario_to_home() > 800.0f) + + if (cur_obj_lateral_dist_from_mario_to_home() > 800.0f) { o->oAngleToMario = cur_obj_angle_to_home(); + } + cur_obj_rotate_yaw_toward(o->oAngleToMario + 0x8000, 0x400); - if (o->oTimer > 200 && o->oDistanceToMario > 600.0f) + + if (o->oTimer > 200 && o->oDistanceToMario > 600.0f) { o->oAction = 1; + } } -void (*sCheepCheepActions[])(void) = { bub_act_0, bub_act_1, bub_act_2 }; +void (*sCheepCheepActions[])(void) = { + bub_act_0, + bub_act_1, + bub_act_2, +}; void bhv_bub_loop(void) { o->oCheepCheepUnkF4 = find_water_level(o->oPosX, o->oPosZ); o->oCheepCheepUnkF8 = gMarioObject->oPosY + o->oCheepCheepUnkFC; o->oWallHitboxRadius = 30.0f; + cur_obj_update_floor_and_walls(); cur_obj_call_action_function(sCheepCheepActions); cur_obj_move_using_fvel_and_gravity(); - if (o->parentObj->oAction == 2) + + if (o->parentObj->oAction == 2) { obj_mark_for_deletion(o); + } } diff --git a/src/game/behaviors/bubba.inc.c b/src/game/behaviors/bubba.inc.c index 9964b0fe..b973496d 100644 --- a/src/game/behaviors/bubba.inc.c +++ b/src/game/behaviors/bubba.inc.c @@ -13,9 +13,8 @@ static struct ObjectHitbox sBubbaHitbox = { }; void bubba_act_0(void) { - f32 sp24; + f32 sp24 = cur_obj_lateral_dist_to_home(); - sp24 = cur_obj_lateral_dist_to_home(); treat_far_home_as_mario(2000.0f); o->oAnimState = 0; @@ -33,12 +32,12 @@ void bubba_act_0(void) { o->oBubbaUnkF8 = random_linear_offset(20, 30); } - if ((o->oBubbaUnkFC = o->oMoveFlags & OBJ_MOVE_HIT_WALL) != 0) { + if ((o->oBubbaUnkFC = o->oMoveFlags & OBJ_MOVE_HIT_WALL)) { o->oBubbaUnk1AE = cur_obj_reflect_move_angle_off_wall(); } else if (o->oTimer > 30 && o->oDistanceToMario < 2000.0f) { o->oAction = 1; } else if (o->oBubbaUnkF8 != 0) { - o->oBubbaUnkF8 -= 1; + o->oBubbaUnkF8--; } else { o->oBubbaUnk1AE = obj_random_fixed_turn(0x2000); o->oBubbaUnkF8 = random_linear_offset(100, 100); @@ -48,6 +47,7 @@ void bubba_act_0(void) { void bubba_act_1(void) { treat_far_home_as_mario(2500.0f); + if (o->oDistanceToMario > 2500.0f) { o->oAction = 0; } else if (o->oBubbaUnk100 != 0) { @@ -96,7 +96,7 @@ void bubba_act_1(void) { } void bhv_bubba_loop(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; o->oInteractionSubtype &= ~INT_SUBTYPE_EATS_MARIO; o->oBubbaUnk104 = obj_turn_pitch_toward_mario(120.0f, 0); diff --git a/src/game/behaviors/bubble.inc.c b/src/game/behaviors/bubble.inc.c index 49b06275..9b977015 100644 --- a/src/game/behaviors/bubble.inc.c +++ b/src/game/behaviors/bubble.inc.c @@ -1,4 +1,4 @@ -// bubble.c.inc +// bubble.inc.c void bhv_object_bubble_init(void) { o->oPosX += random_float() * 30.0f; @@ -12,7 +12,7 @@ void bhv_object_bubble_loop(void) { f32 bubbleY = o->oPosY; if (bubbleY > waterY) { - if (gFreeObjectList.next) { + if (gFreeObjectList.next != NULL) { bubbleSplash = spawn_object_at_origin(o, 0, MODEL_SMALL_WATER_SPLASH, bhvBubbleSplash); bubbleSplash->oPosX = o->oPosX; bubbleSplash->oPosY = bubbleY + 5.0f; diff --git a/src/game/behaviors/bullet_bill.inc.c b/src/game/behaviors/bullet_bill.inc.c index 611bc945..64056cd6 100644 --- a/src/game/behaviors/bullet_bill.inc.c +++ b/src/game/behaviors/bullet_bill.inc.c @@ -1,6 +1,5 @@ // bullet_bill.inc.c -// bullet bill smoke void bhv_white_puff_smoke_init(void) { cur_obj_scale(random_float() * 2 + 2.0); } @@ -22,29 +21,37 @@ void bullet_bill_act_0(void) { void bullet_bill_act_1(void) { s16 sp1E = abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw); - if (sp1E < 0x2000 && 400.0f < o->oDistanceToMario && o->oDistanceToMario < 1500.0f) + if (sp1E < 0x2000 && 400.0f < o->oDistanceToMario && o->oDistanceToMario < 1500.0f) { o->oAction = 2; + } } void bullet_bill_act_2(void) { - if (o->oTimer < 40) + if (o->oTimer < 40) { o->oForwardVel = 3.0f; - else if (o->oTimer < 50) { - if (o->oTimer % 2) + } else if (o->oTimer < 50) { + if (o->oTimer % 2) { o->oForwardVel = 3.0f; - else + } else { o->oForwardVel = -3.0f; + } } else { - if (o->oTimer > 70) + if (o->oTimer > 70) { cur_obj_update_floor_and_walls(); + } + spawn_object(o, MODEL_SMOKE, bhvWhitePuffSmoke); o->oForwardVel = 30.0f; - if (o->oDistanceToMario > 300.0f) + + if (o->oDistanceToMario > 300.0f) { cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x100); + } + if (o->oTimer == 50) { cur_obj_play_sound_2(SOUND_OBJ_POUNDING_CANNON); cur_obj_shake_screen(SHAKE_POS_SMALL); } + if (o->oTimer > 150 || o->oMoveFlags & OBJ_MOVE_HIT_WALL) { o->oAction = 3; spawn_mist_particles(); @@ -61,18 +68,27 @@ void bullet_bill_act_4(void) { o->oForwardVel = -30.0f; cur_obj_become_intangible(); } + o->oFaceAnglePitch += 0x1000; o->oFaceAngleRoll += 0x1000; o->oPosY += 20.0f; - if (o->oTimer > 90) + + if (o->oTimer > 90) { o->oAction = 0; + } } -void (*sBulletBillActions[])(void) = { bullet_bill_act_0, bullet_bill_act_1, bullet_bill_act_2, - bullet_bill_act_3, bullet_bill_act_4 }; +void (*sBulletBillActions[])(void) = { + bullet_bill_act_0, + bullet_bill_act_1, + bullet_bill_act_2, + bullet_bill_act_3, + bullet_bill_act_4, +}; void bhv_bullet_bill_loop(void) { cur_obj_call_action_function(sBulletBillActions); - if (cur_obj_check_interacted()) + if (cur_obj_check_interacted()) { o->oAction = 4; + } } diff --git a/src/game/behaviors/bully.inc.c b/src/game/behaviors/bully.inc.c index 21c561a7..85340bc1 100644 --- a/src/game/behaviors/bully.inc.c +++ b/src/game/behaviors/bully.inc.c @@ -1,4 +1,4 @@ -// bully.c.inc +// bully.inc.c static struct ObjectHitbox sSmallBullyHitbox = { /* interactType: */ INTERACT_BULLY, @@ -57,14 +57,15 @@ void bully_check_mario_collision(void) { o->oAction != BULLY_ACT_LAVA_DEATH && o->oAction != BULLY_ACT_DEATH_PLANE_DEATH && #endif o->oInteractStatus & INT_STATUS_INTERACTED) { - if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) + if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) { cur_obj_play_sound_2(SOUND_OBJ2_BULLY_ATTACKED); - else + } else { cur_obj_play_sound_2(SOUND_OBJ2_LARGE_BULLY_ATTACKED); + } o->oInteractStatus &= ~INT_STATUS_INTERACTED; o->oAction = BULLY_ACT_KNOCKBACK; - o->oFlags &= ~0x8; /* bit 3 */ + o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; cur_obj_init_animation(3); o->oBullyMarioCollisionAngle = o->oMoveAngleYaw; } @@ -77,15 +78,17 @@ void bully_act_chase_mario(void) { if (o->oTimer < 10) { o->oForwardVel = 3.0; - obj_turn_toward_object(o, gMarioObject, 16, 4096); + obj_turn_toward_object(o, gMarioObject, 16, 0x1000); } else if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) { o->oForwardVel = 20.0; - if (o->oTimer >= 31) + if (o->oTimer > 30) { o->oTimer = 0; + } } else { o->oForwardVel = 30.0; - if (o->oTimer >= 36) + if (o->oTimer > 35) { o->oTimer = 0; + } } if (!is_point_within_radius_of_mario(homeX, posY, homeZ, 1000)) { @@ -98,11 +101,12 @@ void bully_act_knockback(void) { if (o->oForwardVel < 10.0 && (s32) o->oVelY == 0) { o->oForwardVel = 1.0; o->oBullyKBTimerAndMinionKOCounter++; - o->oFlags |= 0x8; /* bit 3 */ + o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; o->oMoveAngleYaw = o->oFaceAngleYaw; - obj_turn_toward_object(o, gMarioObject, 16, 1280); - } else + obj_turn_toward_object(o, gMarioObject, 16, 0x500); + } else { o->header.gfx.animInfo.animFrame = 0; + } if (o->oBullyKBTimerAndMinionKOCounter == 18) { o->oAction = BULLY_ACT_CHASE_MARIO; @@ -113,7 +117,7 @@ void bully_act_knockback(void) { void bully_act_back_up(void) { if (o->oTimer == 0) { - o->oFlags &= ~0x8; /* bit 3 */ + o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; o->oMoveAngleYaw += 0x8000; } @@ -128,14 +132,13 @@ void bully_act_back_up(void) { if (o->oTimer == 15) { o->oMoveAngleYaw = o->oFaceAngleYaw; - o->oFlags |= 0x8; /* bit 3 */ + o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; o->oAction = BULLY_ACT_PATROL; } } void bully_backup_check(s16 collisionFlags) { - if (!(collisionFlags & 0x8) && o->oAction != BULLY_ACT_KNOCKBACK) /* bit 3 */ - { + if (!(collisionFlags & OBJ_COL_FLAG_NO_Y_VEL) && o->oAction != BULLY_ACT_KNOCKBACK) { o->oPosX = o->oBullyPrevX; o->oPosZ = o->oBullyPrevZ; o->oAction = BULLY_ACT_BACK_UP; @@ -143,24 +146,27 @@ void bully_backup_check(s16 collisionFlags) { } void bully_play_stomping_sound(void) { - s16 sp26 = o->header.gfx.animInfo.animFrame; + s16 animFrame = o->header.gfx.animInfo.animFrame; + switch (o->oAction) { case BULLY_ACT_PATROL: - if (sp26 == 0 || sp26 == 12) { - if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) + if (animFrame == 0 || animFrame == 12) { + if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) { cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALK); - else + } else { cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALKING); + } } break; case BULLY_ACT_CHASE_MARIO: case BULLY_ACT_BACK_UP: - if (sp26 == 0 || sp26 == 5) { - if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) + if (animFrame == 0 || animFrame == 5) { + if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) { cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALK); - else + } else { cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALKING); + } } break; } @@ -168,26 +174,24 @@ void bully_play_stomping_sound(void) { void bully_step(void) { s16 collisionFlags = 0; + collisionFlags = object_step(); bully_backup_check(collisionFlags); bully_play_stomping_sound(); obj_check_floor_death(collisionFlags, sObjFloor); if (o->oBullySubtype & BULLY_STYPE_CHILL) { - if (o->oPosY < 1030.0f) + if (o->oPosY < 1030.0f) { o->oAction = BULLY_ACT_LAVA_DEATH; + } } } void bully_spawn_coin(void) { struct Object *coin = spawn_object(o, MODEL_YELLOW_COIN, bhvMovingYellowCoin); -#ifdef VERSION_JP // TODO: maybe move this ifdef logic to the header? + cur_obj_play_sound_2(SOUND_GENERAL_COIN_SPURT); -#elif defined(VERSION_EU) || defined(VERSION_SH) - cur_obj_play_sound_2(SOUND_GENERAL_COIN_SPURT_EU); -#else - cur_obj_play_sound_2(SOUND_GENERAL_COIN_SPURT_2); -#endif + coin->oForwardVel = 10.0f; coin->oVelY = 100.0f; coin->oPosY = o->oPosY + 310.0f; @@ -195,20 +199,21 @@ void bully_spawn_coin(void) { } void bully_act_level_death(void) { - if (obj_lava_death() == 1) { + if (obj_lava_death() == TRUE) { if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) { - if (o->oBullySubtype == BULLY_STYPE_MINION) + if (o->oBullySubtype == BULLY_STYPE_MINION) { o->parentObj->oBullyKBTimerAndMinionKOCounter++; + } bully_spawn_coin(); } else { spawn_mist_particles(); - if (o->oBullySubtype == BULLY_STYPE_CHILL) + if (o->oBullySubtype == BULLY_STYPE_CHILL) { spawn_default_star(130.0f, 1600.0f, -4335.0f); - else { + } else { spawn_default_star(0, 950.0f, -6800.0f); - spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvLllTumblingBridge, 0, 154, -5631, 0, 0, - 0); + spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvLllTumblingBridge, + 0, 154, -5631, 0, 0, 0); } } } @@ -229,7 +234,7 @@ void bhv_bully_loop(void) { case BULLY_ACT_PATROL: o->oForwardVel = 5.0; - if (obj_return_home_if_safe(o, o->oHomeX, o->oPosY, o->oHomeZ, 800) == 1) { + if (obj_return_home_if_safe(o, o->oHomeX, o->oPosY, o->oHomeZ, 800) == TRUE) { o->oAction = BULLY_ACT_CHASE_MARIO; cur_obj_init_animation(1); } @@ -264,14 +269,9 @@ void bhv_bully_loop(void) { set_object_visibility(o, 3000); } -// sp38 = arg0 -// sp3c = arg1 -// sp40 = arg2 -// sp44 = arg3 - -void big_bully_spawn_minion(s32 arg0, s32 arg1, s32 arg2, s16 arg3) { +void big_bully_spawn_minion(s32 x, s32 y, s32 z, s16 yaw) { struct Object *bully = - spawn_object_abs_with_rot(o, 0, MODEL_BULLY, bhvSmallBully, arg0, arg1, arg2, 0, arg3, 00); + spawn_object_abs_with_rot(o, 0, MODEL_BULLY, bhvSmallBully, x, y, z, 0, yaw, 0); bully->oBullySubtype = BULLY_STYPE_MINION; bully->oBehParams2ndByte = BULLY_BP_SIZE_SMALL; } @@ -289,7 +289,7 @@ void bhv_big_bully_with_minions_init(void) { } void big_bully_spawn_star(void) { - if (obj_lava_death() == 1) { + if (obj_lava_death() == TRUE) { spawn_mist_particles(); spawn_default_star(3700.0f, 600.0f, -5500.0f); } @@ -308,7 +308,7 @@ void bhv_big_bully_with_minions_loop(void) { case BULLY_ACT_PATROL: o->oForwardVel = 5.0; - if (obj_return_home_if_safe(o, o->oHomeX, o->oPosY, o->oHomeZ, 1000) == 1) { + if (obj_return_home_if_safe(o, o->oHomeX, o->oPosY, o->oHomeZ, 1000) == TRUE) { o->oAction = BULLY_ACT_CHASE_MARIO; cur_obj_init_animation(1); } @@ -339,17 +339,19 @@ void bhv_big_bully_with_minions_loop(void) { if (o->oBullyKBTimerAndMinionKOCounter == 3) { play_puzzle_jingle(); - if (o->oTimer >= 91) + if (o->oTimer > 90) { o->oAction = BULLY_ACT_ACTIVATE_AND_FALL; + } } break; case BULLY_ACT_ACTIVATE_AND_FALL: collisionFlags = object_step(); - if ((collisionFlags & 0x9) == 0x9) /* bits 0 and 3 */ + if ((collisionFlags & OBJ_COL_FLAGS_LANDED) == OBJ_COL_FLAGS_LANDED) { o->oAction = BULLY_ACT_PATROL; + } - if (collisionFlags == 1) { + if (collisionFlags == OBJ_COL_FLAG_GROUNDED) { cur_obj_play_sound_2(SOUND_OBJ_THWOMP); set_camera_shake_from_point(SHAKE_POS_SMALL, o->oPosX, o->oPosY, o->oPosZ); spawn_mist_particles(); diff --git a/src/game/behaviors/butterfly.inc.c b/src/game/behaviors/butterfly.inc.c index 2b530d81..7e9563b8 100644 --- a/src/game/behaviors/butterfly.inc.c +++ b/src/game/behaviors/butterfly.inc.c @@ -1,4 +1,4 @@ -// butterfly.c.inc +// butterfly.inc.c void bhv_butterfly_init(void) { cur_obj_init_animation(1); @@ -10,8 +10,6 @@ void bhv_butterfly_init(void) { o->oHomeZ = o->oPosZ; } -// sp28 = speed - void butterfly_step(s32 speed) { struct FloorGeometry *sp24; s16 yaw = o->oMoveAngleYaw; @@ -26,19 +24,22 @@ void butterfly_step(s32 speed) { o->oPosX += o->oVelX; o->oPosZ += o->oVelZ; - if (o->oAction == BUTTERFLY_ACT_FOLLOW_MARIO) + if (o->oAction == BUTTERFLY_ACT_FOLLOW_MARIO) { o->oPosY -= o->oVelY + coss((s32)(yPhase * 655.36)) * 20.0f / 4; - else + } else { o->oPosY -= o->oVelY; + } floorY = find_floor_height_and_data(o->oPosX, o->oPosY, o->oPosZ, &sp24); - if (o->oPosY < floorY + 2.0f) + if (o->oPosY < floorY + 2.0f) { o->oPosY = floorY + 2.0f; + } o->oButterflyYPhase++; - if (o->oButterflyYPhase >= 101) + if (o->oButterflyYPhase > 100) { o->oButterflyYPhase = 0; + } } void butterfly_calculate_angle(void) { @@ -67,8 +68,9 @@ void butterfly_act_follow_mario(void) { butterfly_step(7); - if (!is_point_within_radius_of_mario(o->oHomeX, o->oHomeY, o->oHomeZ, 1200)) + if (!is_point_within_radius_of_mario(o->oHomeX, o->oHomeY, o->oHomeZ, 1200)) { o->oAction = BUTTERFLY_ACT_RETURN_HOME; + } } void butterfly_act_return_home(void) { diff --git a/src/game/behaviors/camera_lakitu.inc.c b/src/game/behaviors/camera_lakitu.inc.c index c3e7f441..b3371198 100644 --- a/src/game/behaviors/camera_lakitu.inc.c +++ b/src/game/behaviors/camera_lakitu.inc.c @@ -28,13 +28,11 @@ void bhv_camera_lakitu_init(void) { static void camera_lakitu_intro_act_trigger_cutscene(void) { //! These bounds are slightly smaller than the actual bridge bounds, allowing // the RTA speedrunning method of lakitu skip - if (gMarioObject->oPosX > -544.0f && gMarioObject->oPosX < 545.0f && gMarioObject->oPosY > 800.0f - && gMarioObject->oPosZ > -2000.0f && gMarioObject->oPosZ < -177.0f - && gMarioObject->oPosZ < -177.0f) // always double check your conditions - { - if (set_mario_npc_dialog(2) == 1) { - o->oAction = CAMERA_LAKITU_INTRO_ACT_SPAWN_CLOUD; - } + if (gMarioObject->oPosX > -544.0f && gMarioObject->oPosX < 545.0f + && gMarioObject->oPosY > 800.0f && gMarioObject->oPosZ > -2000.0f + && gMarioObject->oPosZ < -177.0f && gMarioObject->oPosZ < -177.0f // always double check your conditions + && set_mario_npc_dialog(MARIO_DIALOG_LOOK_UP) == MARIO_DIALOG_STATUS_START) { + o->oAction = CAMERA_LAKITU_INTRO_ACT_SPAWN_CLOUD; } } @@ -42,7 +40,7 @@ static void camera_lakitu_intro_act_trigger_cutscene(void) { * Warp up into the air and spawn cloud, then enter the TODO action. */ static void camera_lakitu_intro_act_spawn_cloud(void) { - if (set_mario_npc_dialog(2) == 2) { + if (set_mario_npc_dialog(MARIO_DIALOG_LOOK_UP) == MARIO_DIALOG_STATUS_SPEAK) { o->oAction = CAMERA_LAKITU_INTRO_ACT_UNK2; o->oPosX = 1800.0f; @@ -63,6 +61,10 @@ static void camera_lakitu_intro_act_spawn_cloud(void) { static void camera_lakitu_intro_act_show_dialog(void) { s16 targetMovePitch; s16 targetMoveYaw; +#ifdef AVOID_UB + targetMovePitch = 0; + targetMoveYaw = 0; +#endif cur_obj_play_sound_1(SOUND_AIR_LAKITU_FLY); @@ -104,7 +106,6 @@ static void camera_lakitu_intro_act_show_dialog(void) { o->oCameraLakituUnk104 = TRUE; } #endif - // Once within 1000 units, slow down approach_f32_ptr(&o->oCameraLakituSpeed, 20.0f, 1.0f); if (o->oDistanceToMario < 500.0f @@ -115,15 +116,16 @@ static void camera_lakitu_intro_act_show_dialog(void) { } } } - } else if (cur_obj_update_dialog_with_cutscene(2, DIALOG_UNK2_FLAG_0, CUTSCENE_DIALOG, DIALOG_034) != 0) { + } else if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + DIALOG_FLAG_TURN_TO_MARIO, CUTSCENE_DIALOG, DIALOG_034)) { o->oCameraLakituFinishedDialog = TRUE; } } - o->oCameraLakituPitchVel = approach_s16_symmetric(o->oCameraLakituPitchVel, 0x7D0, 0x190); + o->oCameraLakituPitchVel = approach_s16_symmetric(o->oCameraLakituPitchVel, 2000, 400); obj_move_pitch_approach(targetMovePitch, o->oCameraLakituPitchVel); - o->oCameraLakituYawVel = approach_s16_symmetric(o->oCameraLakituYawVel, 0x7D0, 0x64); + o->oCameraLakituYawVel = approach_s16_symmetric(o->oCameraLakituYawVel, 2000, 100); cur_obj_rotate_yaw_toward(targetMoveYaw, o->oCameraLakituYawVel); // vel y is explicitly computed, so gravity doesn't apply @@ -151,7 +153,8 @@ void bhv_camera_lakitu_update(void) { break; } } else { - f32 val0C = (f32) 0x875C3D / 0x800 - gLakituState.curPos[0]; + f32 val0C = 4331.53f - gLakituState.curPos[0]; + if (gLakituState.curPos[0] < 1700.0f || val0C < 0.0f) { cur_obj_hide(); } else { @@ -168,7 +171,7 @@ void bhv_camera_lakitu_update(void) { o->oFaceAnglePitch = atan2s(cur_obj_lateral_dist_to_home(), o->oPosY - gLakituState.curFocus[1]); - o->oPosX = (f32) 0x875C3D / 0x800 + val0C; + o->oPosX = 4331.53f + val0C; } } } diff --git a/src/game/behaviors/cannon.inc.c b/src/game/behaviors/cannon.inc.c index 5f55ca83..2b0dac0d 100644 --- a/src/game/behaviors/cannon.inc.c +++ b/src/game/behaviors/cannon.inc.c @@ -1,4 +1,4 @@ -// cannon.c.inc +// cannon.inc.c void bhv_cannon_base_unused_loop(void) { o->oPosY += o->oVelY; @@ -17,18 +17,18 @@ void opened_cannon_act_0(void) { cur_obj_enable_rendering(); cur_obj_become_tangible(); } + if (o->oDistanceToMario < 500.0f) { cur_obj_become_tangible(); cur_obj_enable_rendering(); if (o->oInteractStatus & INT_STATUS_INTERACTED - && (!(o->oInteractStatus - & INT_STATUS_TOUCHED_BOB_OMB))) // bob-omb explodes when it gets into a cannon - { + && !(o->oInteractStatus & INT_STATUS_TOUCHED_BOB_OMB)) { // bob-omb explodes when it gets into a cannon o->oAction = 4; o->oCannonUnk10C = 1; o->oCannonUnkF8 = 1; - } else + } else { o->oInteractStatus = 0; + } } else { cur_obj_become_intangible(); cur_obj_disable_rendering(); @@ -37,11 +37,14 @@ void opened_cannon_act_0(void) { } void opened_cannon_act_4(void) { - if (o->oTimer == 0) + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_OBJ_CANNON1); + } + o->oPosY += 5.0f; o->oPosX += (f32)((o->oTimer / 2 & 1) - 0.5) * 2; o->oPosZ += (f32)((o->oTimer / 2 & 1) - 0.5) * 2; + if (o->oTimer > 67) { o->oPosX += (f32)((o->oTimer / 2 & 1) - 0.5) * 4; o->oPosZ += (f32)((o->oTimer / 2 & 1) - 0.5) * 4; @@ -50,8 +53,10 @@ void opened_cannon_act_4(void) { } void opened_cannon_act_6(void) { - if (o->oTimer == 0) + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_OBJ_CANNON2); + } + if (o->oTimer < 4) { o->oPosX += (f32)((o->oTimer / 2 & 1) - 0.5) * 4.0f; o->oPosZ += (f32)((o->oTimer / 2 & 1) - 0.5) * 4.0f; @@ -72,25 +77,30 @@ void opened_cannon_act_6(void) { } void opened_cannon_act_5(void) { - if (o->oTimer == 0) + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_OBJ_CANNON3); + } + if (o->oTimer < 4) { } else { if (o->oTimer < 20) { o->oCannonUnkF4 += 0x400; o->oMoveAnglePitch = sins(o->oCannonUnkF4) * 0x2000; } else if (o->oTimer < 25) { - } else + } else { o->oAction = 1; + } } } void opened_cannon_act_1(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; + cur_obj_become_intangible(); cur_obj_disable_rendering(); + o->oCannonUnk10C = 0; - gMarioShotFromCannon = 1; + gMarioShotFromCannon = TRUE; } void opened_cannon_act_2(void) { @@ -98,33 +108,41 @@ void opened_cannon_act_2(void) { } void opened_cannon_act_3(void) { - UNUSED s32 unused; - if (o->oTimer > 3) + UNUSED u8 filler[4]; + if (o->oTimer > 3) { o->oAction = 0; + } } -void (*sOpenedCannonActions[])(void) = { opened_cannon_act_0, opened_cannon_act_1, opened_cannon_act_2, - opened_cannon_act_3, opened_cannon_act_4, opened_cannon_act_5, - opened_cannon_act_6 }; - -u8 unused0EA1FC[] = { 2, 0, 0, 0, 0, 0, 0, 0, 63, 128, 0, 0, 2, 0, 0, 0, 65, 32, 0, 0, - 63, 128, 0, 0, 2, 0, 0, 0, 65, 160, 0, 0, 63, 128, 0, 0, 2, 0, 0, 0, - 65, 160, 0, 0, 63, 128, 0, 0, 8, 0, 0, 0, 65, 32, 0, 0, 63, 128, 0, 0 }; +void (*sOpenedCannonActions[])(void) = { + opened_cannon_act_0, + opened_cannon_act_1, + opened_cannon_act_2, + opened_cannon_act_3, + opened_cannon_act_4, + opened_cannon_act_5, + opened_cannon_act_6, +}; void bhv_cannon_base_loop(void) { cur_obj_call_action_function(sOpenedCannonActions); - if (o->oCannonUnkF8) + + if (o->oCannonUnkF8) { o->oCannonUnkF8++; + } + o->oInteractStatus = 0; } void bhv_cannon_barrel_loop(void) { struct Object *parent = o->parentObj; + if (parent->header.gfx.node.flags & GRAPH_RENDER_ACTIVE) { cur_obj_enable_rendering(); obj_copy_pos(o, o->parentObj); o->oMoveAngleYaw = o->parentObj->oMoveAngleYaw; o->oFaceAnglePitch = o->parentObj->oMoveAnglePitch; - } else + } else { cur_obj_disable_rendering(); + } } diff --git a/src/game/behaviors/cannon_door.inc.c b/src/game/behaviors/cannon_door.inc.c index cb710322..52ab3e86 100644 --- a/src/game/behaviors/cannon_door.inc.c +++ b/src/game/behaviors/cannon_door.inc.c @@ -1,11 +1,10 @@ -// cannon.c.inc +// cannon.inc.c void bhv_cannon_closed_init(void) { - struct Object *cannon; - - if (save_file_is_cannon_unlocked() == 1) { + if (save_file_is_cannon_unlocked() == TRUE) { // If the cannon is open, spawn a cannon and despawn the object. - cannon = spawn_object(o, MODEL_CANNON_BASE, bhvCannon); + struct Object *cannon = spawn_object(o, MODEL_CANNON_BASE, bhvCannon); + cannon->oBehParams2ndByte = o->oBehParams2ndByte; cannon->oPosX = o->oHomeX; cannon->oPosY = o->oHomeY; @@ -17,13 +16,14 @@ void bhv_cannon_closed_init(void) { } void cannon_door_act_opening(void) { - if (o->oTimer == 0) + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_GENERAL_CANNON_UP); + } if (o->oTimer < 30) { o->oVelY = -0.5f; o->oPosY += o->oVelY; - o->oVelX = 0; + o->oVelX = 0.0f; } else { if (o->oTimer == 80) { bhv_cannon_closed_init(); @@ -31,7 +31,7 @@ void cannon_door_act_opening(void) { } o->oVelX = 4.0f; - o->oVelY = 0; + o->oVelY = 0.0f; o->oPosX += o->oVelX; } } @@ -39,18 +39,19 @@ void cannon_door_act_opening(void) { void bhv_cannon_closed_loop(void) { switch (o->oAction) { case CANNON_TRAP_DOOR_ACT_CLOSED: - o->oVelX = 0; - o->oVelY = 0; + o->oVelX = 0.0f; + o->oVelY = 0.0f; o->oDrawingDistance = 4000.0f; - if (save_file_is_cannon_unlocked() == 1) + if (save_file_is_cannon_unlocked() == TRUE) { o->oAction = CANNON_TRAP_DOOR_ACT_CAM_ZOOM; + } break; case CANNON_TRAP_DOOR_ACT_CAM_ZOOM: - if (o->oTimer == 60) + if (o->oTimer == 60) { o->oAction = CANNON_TRAP_DOOR_ACT_OPENING; - + } o->oDrawingDistance = 20000.0f; break; diff --git a/src/game/behaviors/cap.inc.c b/src/game/behaviors/cap.inc.c index 066ff1fb..2aacb145 100644 --- a/src/game/behaviors/cap.inc.c +++ b/src/game/behaviors/cap.inc.c @@ -1,4 +1,4 @@ -// cap.c.inc +// cap.inc.c static struct ObjectHitbox sCapHitbox = { /* interactType: */ INTERACT_CAP, @@ -14,13 +14,14 @@ static struct ObjectHitbox sCapHitbox = { s32 cap_set_hitbox(void) { obj_set_hitbox(o, &sCapHitbox); + if (o->oInteractStatus & INT_STATUS_INTERACTED) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; o->oInteractStatus = 0; - return 1; + return TRUE; } - return 0; + return FALSE; } void cap_despawn(void) { @@ -30,8 +31,9 @@ void cap_despawn(void) { } void cap_check_quicksand(void) { - if (sObjFloor == NULL) + if (sObjFloor == NULL) { return; + } switch (sObjFloor->type) { case SURFACE_DEATH_PLANE: @@ -76,24 +78,24 @@ void cap_sink_quicksand(void) { break; case 11: - if (o->oTimer < 10) + if (o->oTimer < 10) { o->oGraphYOffset += -3.0f; - + } o->oFaceAnglePitch = 0x2000; break; case 12: o->oGraphYOffset += -1.0f; - if (o->oTimer >= 21) + if (o->oTimer > 20) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; - + } break; case 13: o->oGraphYOffset += -6.0f; - if (o->oTimer >= 21) + if (o->oTimer > 20) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; - + } o->oFaceAnglePitch = 0x2000; break; } @@ -118,11 +120,12 @@ void cap_scale_vertically(void) { } void wing_vanish_cap_act_0(void) { - s16 sp1E; + s16 collisionFlags; o->oFaceAngleYaw += o->oForwardVel * 128.0f; - sp1E = object_step(); - if (sp1E & 0x01) { + collisionFlags = object_step(); + + if (collisionFlags & OBJ_COL_FLAG_GROUNDED) { cap_check_quicksand(); if (o->oVelY != 0.0f) { o->oCapUnkF4 = 1; @@ -130,8 +133,9 @@ void wing_vanish_cap_act_0(void) { } } - if (o->oCapUnkF4 == 1) + if (o->oCapUnkF4 == 1) { cap_scale_vertically(); + } } void bhv_wing_vanish_cap_loop(void) { @@ -146,8 +150,9 @@ void bhv_wing_vanish_cap_loop(void) { break; } - if (o->oTimer > 20) + if (o->oTimer > 20) { cur_obj_become_tangible(); + } cap_despawn(); cap_set_hitbox(); @@ -157,16 +162,18 @@ void bhv_metal_cap_init(void) { o->oGravity = 2.4f; o->oFriction = 0.999f; o->oBuoyancy = 1.5f; - o->oOpacity = 0xFF; + o->oOpacity = 255; } void metal_cap_act_0(void) { - s16 sp1E; + s16 collisionFlags; o->oFaceAngleYaw += o->oForwardVel * 128.0f; - sp1E = object_step(); - if (sp1E & 0x01) + collisionFlags = object_step(); + + if (collisionFlags & OBJ_COL_FLAG_GROUNDED) { cap_check_quicksand(); + } } void bhv_metal_cap_loop(void) { @@ -181,8 +188,9 @@ void bhv_metal_cap_loop(void) { break; } - if (o->oTimer > 20) + if (o->oTimer > 20) { cur_obj_become_tangible(); + } cap_set_hitbox(); cap_despawn(); @@ -192,7 +200,7 @@ void bhv_normal_cap_init(void) { o->oGravity = 0.7f; o->oFriction = 0.89f; o->oBuoyancy = 0.9f; - o->oOpacity = 0xFF; + o->oOpacity = 255; save_file_set_cap_pos(o->oPosX, o->oPosY, o->oPosZ); } @@ -220,12 +228,13 @@ void normal_cap_set_save_flags(void) { } void normal_cap_act_0(void) { - s16 sp1E; + s16 collisionFlags; o->oFaceAngleYaw += o->oForwardVel * 128.0f; o->oFaceAnglePitch += o->oForwardVel * 80.0f; - sp1E = object_step(); - if (sp1E & 0x01) { + collisionFlags = object_step(); + + if (collisionFlags & OBJ_COL_FLAG_GROUNDED) { cap_check_quicksand(); if (o->oVelY != 0.0f) { @@ -235,8 +244,9 @@ void normal_cap_act_0(void) { } } - if (o->oCapUnkF4 == 1) + if (o->oCapUnkF4 == 1) { cap_scale_vertically(); + } } void bhv_normal_cap_loop(void) { @@ -251,14 +261,17 @@ void bhv_normal_cap_loop(void) { break; } - if ((s32) o->oForwardVel != 0) + if ((s32) o->oForwardVel != 0) { save_file_set_cap_pos(o->oPosX, o->oPosY, o->oPosZ); + } - if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) + if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) { normal_cap_set_save_flags(); + } - if (cap_set_hitbox() == 1) + if (cap_set_hitbox() == TRUE) { save_file_clear_flags(SAVE_FLAG_CAP_ON_GROUND); + } } void bhv_vanish_cap_init(void) { diff --git a/src/game/behaviors/capswitch.inc.c b/src/game/behaviors/capswitch.inc.c index 65ae62d2..aecde91d 100644 --- a/src/game/behaviors/capswitch.inc.c +++ b/src/game/behaviors/capswitch.inc.c @@ -1,52 +1,67 @@ -// capswitch.c.inc +// capswitch.inc.c + +UNUSED u8 sCapSwitchText[] = { DIALOG_010, DIALOG_011, DIALOG_012 }; void cap_switch_act_0(void) { o->oAnimState = o->oBehParams2ndByte; cur_obj_scale(0.5f); o->oPosY += 71.0f; + spawn_object_relative_with_scale(0, 0, -71, 0, 0.5f, o, MODEL_CAP_SWITCH_BASE, bhvCapSwitchBase); + if (gCurrLevelNum != LEVEL_UNKNOWN_32) { - if (save_file_get_flags() & D_8032F0C0[o->oBehParams2ndByte]) { + if (save_file_get_flags() & sCapSaveFlags[o->oBehParams2ndByte]) { o->oAction = 3; o->header.gfx.scale[1] = 0.1f; - } else + } else { o->oAction = 1; - } else + } + } else { o->oAction = 1; + } } void cap_switch_act_1(void) { if (cur_obj_is_mario_on_platform()) { - save_file_set_flags(D_8032F0C0[o->oBehParams2ndByte]); + save_file_set_flags(sCapSaveFlags[o->oBehParams2ndByte]); o->oAction = 2; cur_obj_play_sound_2(SOUND_GENERAL_ACTIVATE_CAP_SWITCH); } } void cap_switch_act_2(void) { - s32 sp1C; if (o->oTimer < 5) { cur_obj_scale_over_time(2, 4, 0.5f, 0.1f); if (o->oTimer == 4) { cur_obj_shake_screen(SHAKE_POS_SMALL); spawn_mist_particles(); - spawn_triangle_break_particles(60, 139, 0.3f, o->oBehParams2ndByte); -#ifdef VERSION_SH + spawn_triangle_break_particles(60, MODEL_CARTOON_STAR, 0.3f, o->oBehParams2ndByte); +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif } } else { - sp1C = cur_obj_update_dialog_with_cutscene(1, 0x0C, CUTSCENE_CAP_SWITCH_PRESS, 0); - if (sp1C) + //! Neither of these flags are defined in this function so they do nothing. + // On an extra note, there's a specific check for this cutscene and + // there's no dialog defined since the cutscene itself calls the dialog. + s32 dialogResponse = cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_FRONT, + (DIALOG_FLAG_TEXT_RESPONSE | DIALOG_FLAG_UNK_CAPSWITCH), CUTSCENE_CAP_SWITCH_PRESS, 0); + if (dialogResponse) { o->oAction = 3; + } } } +// dead function void cap_switch_act_3(void) { -} // dead function +} -void (*sCapSwitchActions[])(void) = { cap_switch_act_0, cap_switch_act_1, - cap_switch_act_2, cap_switch_act_3 }; +void (*sCapSwitchActions[])(void) = { + cap_switch_act_0, + cap_switch_act_1, + cap_switch_act_2, + cap_switch_act_3, +}; void bhv_cap_switch_loop(void) { cur_obj_call_action_function(sCapSwitchActions); diff --git a/src/game/behaviors/castle_floor_trap.inc.c b/src/game/behaviors/castle_floor_trap.inc.c index 4bceb9e4..ee91a020 100644 --- a/src/game/behaviors/castle_floor_trap.inc.c +++ b/src/game/behaviors/castle_floor_trap.inc.c @@ -1,8 +1,9 @@ -// castle_floor_trap.c.inc +// castle_floor_trap.inc.c void bhv_floor_trap_in_castle_loop(void) { - if (gMarioObject->platform == o) + if (gMarioObject->platform == o) { o->parentObj->oInteractStatus |= INT_STATUS_TRAP_TURN; + } o->oFaceAngleRoll = o->parentObj->oFaceAngleRoll; } @@ -15,20 +16,24 @@ void bhv_castle_floor_trap_init(void) { void bhv_castle_floor_trap_open_detect(void) { if (gMarioStates[0].action == ACT_SPECIAL_EXIT_AIRBORNE - || gMarioStates[0].action == ACT_SPECIAL_DEATH_EXIT) + || gMarioStates[0].action == ACT_SPECIAL_DEATH_EXIT) { o->oAction = 4; // rotates trapdoor so it looks always open - else { + } else { o->oAngleVelRoll = 0x400; - if (o->oInteractStatus & INT_STATUS_TRAP_TURN) + if (o->oInteractStatus & INT_STATUS_TRAP_TURN) { o->oAction = 1; // detects interact then opens the trapdoor + } } } void bhv_castle_floor_trap_open(void) { - if (o->oTimer == 0) + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_GENERAL_CASTLE_TRAP_OPEN); + } + o->oAngleVelRoll -= 0x100; o->oFaceAngleRoll += o->oAngleVelRoll; + if (o->oFaceAngleRoll < -0x4000) { o->oFaceAngleRoll = -0x4000; o->oAction = 2; // after opening is done, enable close detection @@ -36,12 +41,14 @@ void bhv_castle_floor_trap_open(void) { } void bhv_castle_floor_trap_close_detect(void) { - if (o->oDistanceToMario > 1000.0f) + if (o->oDistanceToMario > 1000.0f) { o->oAction = 3; // close trapdoor + } } void bhv_castle_floor_trap_close(void) { o->oFaceAngleRoll += 0x400; + if (o->oFaceAngleRoll > 0) { o->oFaceAngleRoll = 0; o->oAction = 0; // after closing, reloads open detection @@ -54,7 +61,8 @@ void bhv_castle_floor_trap_rotate(void) { } void bhv_castle_floor_trap_loop(void) { - UNUSED s32 unused[3]; + UNUSED u8 filler[12]; + switch (o->oAction) { case 0: bhv_castle_floor_trap_open_detect(); diff --git a/src/game/behaviors/celebration_star.inc.c b/src/game/behaviors/celebration_star.inc.c index 85f8964b..92cb866a 100644 --- a/src/game/behaviors/celebration_star.inc.c +++ b/src/game/behaviors/celebration_star.inc.c @@ -1,4 +1,4 @@ -// celebration_star.c.inc +// celebration_star.inc.c void bhv_celebration_star_init(void) { o->oHomeX = gMarioObject->header.gfx.pos[0]; @@ -10,7 +10,7 @@ void bhv_celebration_star_init(void) { if (gCurrLevelNum == LEVEL_BOWSER_1 || gCurrLevelNum == LEVEL_BOWSER_2) { o->header.gfx.sharedChild = gLoadedGraphNodes[MODEL_BOWSER_KEY]; o->oFaceAnglePitch = 0; - o->oFaceAngleRoll = 49152; + o->oFaceAngleRoll = 0xC000; cur_obj_scale(0.1f); o->oCelebStarUnkF4 = 1; } else { @@ -35,17 +35,19 @@ void celeb_star_act_spin_around_mario(void) { o->oFaceAngleYaw += 0x1000; o->oMoveAngleYaw += 0x2000; - if (o->oTimer == 40) + if (o->oTimer == 40) { o->oAction = CELEB_STAR_ACT_FACE_CAMERA; + } + if (o->oTimer < 35) { spawn_object(o, MODEL_SPARKLES, bhvCelebrationStarSparkle); o->oCelebStarDiameterOfRotation++; - } else + } else { o->oCelebStarDiameterOfRotation -= 20; + } } void celeb_star_act_face_camera(void) { - if (o->oTimer < 10) { #if BUGFIX_STAR_BOWSER_KEY if (o->oCelebStarUnkF4 == 0) { @@ -61,8 +63,9 @@ void celeb_star_act_face_camera(void) { o->oFaceAngleYaw = gMarioObject->header.gfx.angle[1]; } - if (o->oTimer == 59) + if (o->oTimer == 59) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } } void bhv_celebration_star_loop(void) { @@ -80,8 +83,9 @@ void bhv_celebration_star_loop(void) { void bhv_celebration_star_sparkle_loop(void) { o->oPosY -= 15.0f; - if (o->oTimer == 12) + if (o->oTimer == 12) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } } void bhv_star_key_collection_puff_spawner_loop(void) { diff --git a/src/game/behaviors/chain_chomp.inc.c b/src/game/behaviors/chain_chomp.inc.c index 382be8d7..54c136c9 100644 --- a/src/game/behaviors/chain_chomp.inc.c +++ b/src/game/behaviors/chain_chomp.inc.c @@ -13,15 +13,15 @@ * Hitbox for chain chomp. */ static struct ObjectHitbox sChainChompHitbox = { - /* interactType: */ INTERACT_MR_BLIZZARD, - /* downOffset: */ 0, + /* interactType: */ INTERACT_MR_BLIZZARD, + /* downOffset: */ 0, /* damageOrCoinValue: */ 3, - /* health: */ 1, - /* numLootCoins: */ 0, - /* radius: */ 80, - /* height: */ 160, - /* hurtboxRadius: */ 80, - /* hurtboxHeight: */ 160, + /* health: */ 1, + /* numLootCoins: */ 0, + /* radius: */ 80, + /* height: */ 160, + /* hurtboxRadius: */ 80, + /* hurtboxHeight: */ 160, }; /** @@ -190,7 +190,7 @@ static void chain_chomp_sub_act_turn(void) { o->oChainChompTargetPitch = obj_get_pitch_from_vel(); } } else { - o->oTimer -= 1; + o->oTimer--; } } else { o->oForwardVel = 0.0f; @@ -201,7 +201,7 @@ static void chain_chomp_sub_act_turn(void) { o->oVelY = 20.0f; } } else { - cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x190); + cur_obj_rotate_yaw_toward(o->oAngleToMario, 400); o->oTimer = 0; } } @@ -228,7 +228,7 @@ static void chain_chomp_sub_act_lunge(void) { } else { // Turn toward pivot cur_obj_rotate_yaw_toward(atan2s(o->oChainChompSegments[0].posZ, o->oChainChompSegments[0].posX), - 0x1000); + 0x1000); if (o->oChainChompUnk104 != 0.0f) { approach_f32_ptr(&o->oChainChompUnk104, 0.0f, 0.8f); @@ -256,8 +256,8 @@ static void chain_chomp_released_trigger_cutscene(void) { //! Can delay this if we get into a cutscene-unfriendly action after the // last post ground pound and before this - if (set_mario_npc_dialog(2) == 2 && (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) - && cutscene_object(CUTSCENE_STAR_SPAWN, o) == 1) { + if (set_mario_npc_dialog(MARIO_DIALOG_LOOK_UP) == MARIO_DIALOG_STATUS_SPEAK + && (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) && cutscene_object(CUTSCENE_STAR_SPAWN, o) == 1) { o->oChainChompReleaseStatus = CHAIN_CHOMP_RELEASED_LUNGE_AROUND; o->oTimer = 0; } @@ -274,9 +274,9 @@ static void chain_chomp_released_lunge_around(void) { if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) { // Before first bounce, turn toward mario and wait 2 seconds if (o->oChainChompNumLunges == 0) { - if (cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x320)) { + if (cur_obj_rotate_yaw_toward(o->oAngleToMario, 800)) { if (o->oTimer > 60) { - o->oChainChompNumLunges += 1; + o->oChainChompNumLunges++; // enable wall collision o->oWallHitboxRadius = 200.0f; } @@ -342,7 +342,7 @@ static void chain_chomp_released_jump_away(void) { */ static void chain_chomp_released_end_cutscene(void) { if (cutscene_object(CUTSCENE_STAR_SPAWN, o) == -1) { - set_mario_npc_dialog(0); + set_mario_npc_dialog(MARIO_DIALOG_STOP); o->oAction = CHAIN_CHOMP_ACT_UNLOAD_CHAIN; } } @@ -434,7 +434,7 @@ static void chain_chomp_act_move(void) { chain_chomp_update_chain_segments(); // Begin a lunge if mario tries to attack - if (obj_check_attacks(&sChainChompHitbox, o->oAction)) { + if (obj_check_attacks(&sChainChompHitbox, o->oAction) != 0) { o->oSubAction = CHAIN_CHOMP_SUB_ACT_LUNGE; o->oChainChompMaxDistFromPivotPerChainPart = 900.0f / 5; o->oForwardVel = 0.0f; @@ -536,7 +536,7 @@ void bhv_chain_chomp_gate_update(void) { spawn_mist_particles_with_sound(SOUND_GENERAL_WALL_EXPLOSION); set_camera_shake_from_point(SHAKE_POS_SMALL, o->oPosX, o->oPosY, o->oPosZ); spawn_mist_particles_variable(0, 0x7F, 200.0f); - spawn_triangle_break_particles(30, 0x8A, 3.0f, 4); + spawn_triangle_break_particles(30, MODEL_DIRT_ANIMATION, 3.0f, 4); obj_mark_for_deletion(o); } } diff --git a/src/game/behaviors/checkerboard_platform.inc.c b/src/game/behaviors/checkerboard_platform.inc.c index 30235a03..bfba5f0a 100644 --- a/src/game/behaviors/checkerboard_platform.inc.c +++ b/src/game/behaviors/checkerboard_platform.inc.c @@ -1,7 +1,15 @@ -// checkerboard_platform.c.inc +// checkerboard_platform.inc.c -struct Struct8032F754 D_8032F754[] = { { 145, { 0.7f, 1.5f, 0.7f }, 7.0f }, - { 235, { 1.2f, 2.0f, 1.2f }, 11.6f } }; +struct Struct8032F754 { + s32 unk0; + Vec3f unk1; + f32 unk2; +}; + +struct Struct8032F754 D_8032F754[] = { + { 145, { 0.7f, 1.5f, 0.7f }, 7.0f }, + { 235, { 1.2f, 2.0f, 1.2f }, 11.6f }, +}; void bhv_checkerboard_elevator_group_init(void) { s32 sp3C; @@ -9,15 +17,20 @@ void bhv_checkerboard_elevator_group_init(void) { s32 sp34; s32 i; struct Object *sp2C; - if (o->oBehParams2ndByte == 0) + + if (o->oBehParams2ndByte == 0) { o->oBehParams2ndByte = 65; + } + sp3C = o->oBehParams2ndByte * 10; - sp34 = (o->oBehParams >> 24) & 0XFF; + sp34 = (o->oBehParams >> 24) & 0xFF; + for (i = 0; i < 2; i++) { - if (i == 0) + if (i == 0) { sp38 = -D_8032F754[sp34].unk0; - else + } else { sp38 = D_8032F754[sp34].unk0; + } sp2C = spawn_object_relative(i, 0, i * sp3C, sp38, o, MODEL_CHECKERBOARD_PLATFORM, bhvCheckerboardPlatformSub); @@ -31,15 +44,17 @@ void checkerboard_plat_act_move_y(UNUSED s32 unused, f32 vel, s32 a2) { o->oAngleVelPitch = 0; o->oForwardVel = 0.0f; o->oVelY = vel; - if (o->oTimer > a2) + if (o->oTimer > a2) { o->oAction++; + } } void checkerboard_plat_act_rotate(s32 a0, s16 a1) { o->oVelY = 0.0f; o->oAngleVelPitch = a1; - if (o->oTimer + 1 == 0x8000 / absi(a1)) + if (o->oTimer + 1 == 0x8000 / absi(a1)) { o->oAction = a0; + } o->oCheckerBoardPlatformUnkF8 = a0; } @@ -49,15 +64,20 @@ void bhv_checkerboard_platform_init(void) { void bhv_checkerboard_platform_loop(void) { f32 sp24 = o->oCheckerBoardPlatformUnk1AC; + o->oCheckerBoardPlatformUnkF8 = 0; - if (o->oDistanceToMario < 1000.0f) + + if (o->oDistanceToMario < 1000.0f) { cur_obj_play_sound_1(SOUND_ENV_ELEVATOR4); + } + switch (o->oAction) { case 0: - if (o->oBehParams2ndByte == 0) + if (o->oBehParams2ndByte == 0) { o->oAction = 1; - else + } else { o->oAction = 3; + } break; case 1: checkerboard_plat_act_move_y(2, 10.0f, o->oCheckerBoardPlatformUnkFC); @@ -72,18 +92,23 @@ void bhv_checkerboard_platform_loop(void) { checkerboard_plat_act_rotate(1, -512); break; } + o->oMoveAnglePitch += absi(o->oAngleVelPitch); o->oFaceAnglePitch += absi(o->oAngleVelPitch); o->oFaceAngleYaw = o->oMoveAngleYaw; + if (o->oMoveAnglePitch != 0) { o->oForwardVel = signum_positive(o->oAngleVelPitch) * sins(o->oMoveAnglePitch) * sp24; o->oVelY = signum_positive(o->oAngleVelPitch) * coss(o->oMoveAnglePitch) * sp24; } + if (o->oCheckerBoardPlatformUnkF8 == 1) { o->oAngleVelPitch = 0; o->oFaceAnglePitch &= ~0x7FFF; cur_obj_move_using_fvel_and_gravity(); - } else + } else { cur_obj_move_using_fvel_and_gravity(); + } + load_object_collision_model(); } diff --git a/src/game/behaviors/chuckya.inc.c b/src/game/behaviors/chuckya.inc.c index f9e5dac0..6cc87f42 100644 --- a/src/game/behaviors/chuckya.inc.c +++ b/src/game/behaviors/chuckya.inc.c @@ -1,132 +1,185 @@ -// chuckya.c.inc +// chuckya.inc.c + +struct UnusedChuckyaData { + u8 unk0; + f32 unk4; + f32 unk8; +}; + +struct UnusedChuckyaData sUnusedChuckyaData[] = { + { 2, 0.f, 1.f }, + { 2, 10.f, 1.f }, + { 2, 20.f, 1.f }, + { 2, 20.f, 1.f }, + { 8, 10.f, 1.f }, +}; void common_anchor_mario_behavior(f32 sp28, f32 sp2C, s32 sp30) { switch (o->parentObj->oChuckyaUnk88) { case 0: break; + case 1: obj_set_gfx_pos_at_obj_pos(gMarioObject, o); break; + case 2: - gMarioObject->oInteractStatus |= (sp30 + INT_STATUS_MARIO_UNK2); + gMarioObject->oInteractStatus |= (INT_STATUS_MARIO_UNK2 + sp30); gMarioStates[0].forwardVel = sp28; gMarioStates[0].vel[1] = sp2C; o->parentObj->oChuckyaUnk88 = 0; break; + case 3: - gMarioObject->oInteractStatus |= - (INT_STATUS_MARIO_UNK2 + INT_STATUS_MARIO_UNK6); // loads 2 interactions at once? + gMarioObject->oInteractStatus |= (INT_STATUS_MARIO_UNK2 | INT_STATUS_MARIO_UNK6); gMarioStates[0].forwardVel = 10.0f; gMarioStates[0].vel[1] = 10.0f; o->parentObj->oChuckyaUnk88 = 0; break; } + o->oMoveAngleYaw = o->parentObj->oMoveAngleYaw; - if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) + + if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) { obj_mark_for_deletion(o); + } } void bhv_chuckya_anchor_mario_loop(void) { - common_anchor_mario_behavior(40.0f, 40.0f, 64); + common_anchor_mario_behavior(40.0f, 40.0f, INT_STATUS_MARIO_UNK6); } -s32 unknown_chuckya_function(s32 sp20, f32 sp24, f32 sp28, s32 sp2C) { +s32 unknown_chuckya_function(s32 sp20, f32 sp24, f32 sp28, s16 sp2C) { s32 sp1C = 0; + if (o->oChuckyaUnkF8 != 4) { if (sp24 < cur_obj_lateral_dist_from_mario_to_home()) { - if (cur_obj_lateral_dist_to_home() < 200.0f) + if (cur_obj_lateral_dist_to_home() < 200.0f) { sp1C = 0; - else { + } else { sp1C = 1; o->oAngleToMario = cur_obj_angle_to_home(); } } else if (o->oDistanceToMario > sp28) { - if (gGlobalTimer % (s16) sp2C == 0) + if (gGlobalTimer % sp2C == 0) { o->oAngleToMario = obj_angle_to_object(o, gMarioObject); + } sp1C = 2; - } else + } else { sp1C = 3; + } + if (sp20 && update_angle_from_move_flags(&o->oAngleToMario)) { sp1C = 4; o->oChuckyaUnkF8 = 4; } - } else + } else { sp1C = 4; + } + return sp1C; } -s32 approach_forward_vel(f32 *arr, f32 spC, f32 sp10) { +s32 approach_forward_vel(f32 *forwardVel, f32 spC, f32 sp10) { s32 sp4 = 0; - if (arr[0] > spC) { - arr[0] -= sp10; - if (arr[0] < spC) - arr[0] = spC; - } else if (arr[0] < spC) { - arr[0] += sp10; - if (arr[0] > spC) - arr[0] = spC; - } else + + if (*forwardVel > spC) { + *forwardVel -= sp10; + if (*forwardVel < spC) { + *forwardVel = spC; + } + } else if (*forwardVel < spC) { + *forwardVel += sp10; + if (*forwardVel > spC) { + *forwardVel = spC; + } + } else { sp4 = 1; + } + return sp4; } void chuckya_act_0(void) { s32 sp3C; - UNUSED u8 pad[16]; +#ifdef AVOID_UB + sp3C = 0; +#endif + UNUSED u8 filler[16]; s32 sp28; - if (o->oTimer == 0) + + if (o->oTimer == 0) { o->oChuckyaUnkFC = 0; + } + o->oAngleToMario = obj_angle_to_object(o, gMarioObject); + switch (sp28 = o->oSubAction) { case 0: - o->oForwardVel = 0; + o->oForwardVel = 0.0f; if (cur_obj_lateral_dist_from_mario_to_home() < 2000.0f) { cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x400); if (o->oChuckyaUnkFC > 40 - || abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario) < 0x1000) + || abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario) < 0x1000) { o->oSubAction = 1; - } else + } + } else { o->oSubAction = 3; + } break; + case 1: approach_forward_vel(&o->oForwardVel, 30.0f, 4.0f); - if (abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario) > 0x4000) + if (abs_angle_diff(o->oMoveAngleYaw, o->oAngleToMario) > 0x4000) { o->oSubAction = 2; - if (cur_obj_lateral_dist_from_mario_to_home() > 2000.0f) + } + if (cur_obj_lateral_dist_from_mario_to_home() > 2000.0f) { o->oSubAction = 3; + } break; + case 2: approach_forward_vel(&o->oForwardVel, 0, 4.0f); - if (o->oChuckyaUnkFC > 48) + if (o->oChuckyaUnkFC > 48) { o->oSubAction = 0; + } break; + case 3: - if (cur_obj_lateral_dist_to_home() < 500.0f) - o->oForwardVel = 0; - else { + if (cur_obj_lateral_dist_to_home() < 500.0f) { + o->oForwardVel = 0.0f; + } else { approach_forward_vel(&o->oForwardVel, 10.0f, 4.0f); o->oAngleToMario = cur_obj_angle_to_home(); cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x800); } - if (cur_obj_lateral_dist_from_mario_to_home() < 1900.0f) + if (cur_obj_lateral_dist_from_mario_to_home() < 1900.0f) { o->oSubAction = 0; + } break; } - if (o->oSubAction != sp28) + + if (o->oSubAction != sp28) { o->oChuckyaUnkFC = 0; - else + } else { o->oChuckyaUnkFC++; + } + cur_obj_init_animation_with_sound(4); - if (o->oForwardVel > 1.0f) + + if (o->oForwardVel > 1.0f) { cur_obj_play_sound_1(SOUND_AIR_CHUCKYA_MOVE); + } + print_debug_bottom_up("fg %d", sp3C); print_debug_bottom_up("sp %d", o->oForwardVel); } void chuckya_act_1(void) { if (o->oSubAction == 0) { - if (cur_obj_init_animation_and_check_if_near_end(0)) + if (cur_obj_init_animation_and_check_if_near_end(0)) { o->oSubAction++; + } o->oChuckyaUnkFC = random_float() * 30.0f + 10.0f; o->oChuckyaUnk100 = 0; o->oForwardVel = 0.0f; @@ -137,14 +190,14 @@ void chuckya_act_1(void) { if (o->oChuckyaUnk100 > 10) { o->oChuckyaUnk88 = 3; o->oAction = 3; - o->oInteractStatus &= ~(INT_STATUS_GRABBED_MARIO); + o->oInteractStatus &= ~INT_STATUS_GRABBED_MARIO; } else { cur_obj_init_animation_with_sound(1); o->oMoveAngleYaw += INT_STATUS_GRABBED_MARIO; - if (o->oChuckyaUnkFC-- < 0) - if (check_if_moving_over_floor(50.0f, 150.0f) || o->oChuckyaUnkFC < -16) { - o->oSubAction++; - } + if (o->oChuckyaUnkFC-- < 0 + && (check_if_moving_over_floor(50.0f, 150.0f) || o->oChuckyaUnkFC < -16)) { + o->oSubAction++; + } } } else { cur_obj_init_animation_with_sound(3); @@ -152,18 +205,19 @@ void chuckya_act_1(void) { cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN4); o->oChuckyaUnk88 = 2; o->oAction = 3; - o->oInteractStatus &= ~(INT_STATUS_GRABBED_MARIO); + o->oInteractStatus &= ~INT_STATUS_GRABBED_MARIO; } } } } void chuckya_act_3(void) { - o->oForwardVel = 0; - o->oVelY = 0; + o->oForwardVel = 0.0f; + o->oVelY = 0.0f; cur_obj_init_animation_with_sound(4); - if (o->oTimer > 100) + if (o->oTimer > 100) { o->oAction = 0; + } } void chuckya_act_2(void) { @@ -174,7 +228,12 @@ void chuckya_act_2(void) { } } -void (*sChuckyaActions[])(void) = { chuckya_act_0, chuckya_act_1, chuckya_act_2, chuckya_act_3 }; +void (*sChuckyaActions[])(void) = { + chuckya_act_0, + chuckya_act_1, + chuckya_act_2, + chuckya_act_3, +}; void chuckya_move(void) { cur_obj_update_floor_and_walls(); @@ -190,20 +249,24 @@ void chuckya_move(void) { void bhv_chuckya_loop(void) { f32 sp2C = 20.0f; f32 sp28 = 50.0f; + cur_obj_scale(2.0f); o->oInteractionSubtype |= INT_SUBTYPE_GRABS_MARIO; + switch (o->oHeldState) { case HELD_FREE: chuckya_move(); break; case HELD_HELD: - cur_obj_unrender_and_reset_state(2, 0); + cur_obj_unrender_set_action_and_anim(2, 0); break; case HELD_THROWN: case HELD_DROPPED: cur_obj_get_thrown_or_placed(sp2C, sp28, 2); break; } + o->oInteractStatus = 0; + print_debug_bottom_up("md %d", o->oAction); } diff --git a/src/game/behaviors/clam.inc.c b/src/game/behaviors/clam.inc.c index 36969800..5ee7b7eb 100644 --- a/src/game/behaviors/clam.inc.c +++ b/src/game/behaviors/clam.inc.c @@ -24,22 +24,20 @@ void clam_act_0(void) { cur_obj_play_sound_2(SOUND_GENERAL_CLAM_SHELL2); o->oAction = 1; } else if (o->oClamUnkF4 != 0) { - o->oClamUnkF4 -= 1; + o->oClamUnkF4--; cur_obj_shake_y(3.0f); } } void clam_act_1(void) { s16 val06; - s16 val04; - s16 val02; if (o->oTimer > 150) { o->oAction = 0; } else if (obj_is_rendering_enabled() && cur_obj_init_anim_check_frame(1, 8)) { for (val06 = -0x2000; val06 < 0x2000; val06 += 0x555) { - val04 = (s16)(100.0f * sins(val06)); - val02 = (s16)(100.0f * coss(val06)); + s16 val04 = (s16)(100.0f * sins(val06)); + s16 val02 = (s16)(100.0f * coss(val06)); spawn_object_relative(0, val04, 30, val02, o, MODEL_BUBBLE, bhvBubbleMaybe); } diff --git a/src/game/behaviors/clock_arm.inc.c b/src/game/behaviors/clock_arm.inc.c index 26ff8948..fbf8b931 100644 --- a/src/game/behaviors/clock_arm.inc.c +++ b/src/game/behaviors/clock_arm.inc.c @@ -1,9 +1,12 @@ +// clock_arm.inc.c + /** * Main loop of the hour and minute hands of the Tick Tock Clock painting. */ void bhv_rotating_clock_arm_loop(void) { struct Surface *marioSurface; u16 rollAngle = o->oFaceAngleRoll; + o->oFloorHeight = find_floor(gMarioObject->oPosX, gMarioObject->oPosY, gMarioObject->oPosZ, &marioSurface); @@ -12,9 +15,9 @@ void bhv_rotating_clock_arm_loop(void) { // Probably a safety check for when you leave the level through the painting // to make sure the setting isn't accidentally locked in as you fly out. if (o->oAction == 0) { - if (marioSurface->type == SURFACE_DEFAULT) - if (o->oTimer >= 4) - o->oAction++; + if (marioSurface->type == SURFACE_DEFAULT && o->oTimer >= 4) { + o->oAction++; + } } else if (o->oAction == 1) { // If Mario is touching the Tick Tock Clock painting... if (marioSurface != NULL @@ -26,16 +29,17 @@ void bhv_rotating_clock_arm_loop(void) { // Set Tick Tick Clock's speed based on the angle of the hand. // The angle actually counting down from 0xFFFF to 0 so // 11 o'clock is a small value and 1 o'clock is a large value. - if (rollAngle < 0xAAA) // > 345 degrees from 12 o'clock. + if (rollAngle < 0xAAA) { // > 345 degrees from 12 o'clock. gTTCSpeedSetting = TTC_SPEED_STOPPED; - else if (rollAngle < 0x6aa4) // 210..345 degrees from 12 o'clock. + } else if (rollAngle < 0x6AA4) { // 210..345 degrees from 12 o'clock. gTTCSpeedSetting = TTC_SPEED_FAST; - else if (rollAngle < 0x954C) // 150..210 degrees from 12 o'clock. + } else if (rollAngle < 0x954C) { // 150..210 degrees from 12 o'clock. gTTCSpeedSetting = TTC_SPEED_RANDOM; - else if (rollAngle < 0xf546) // 15..150 degrees from 12 o'clock. + } else if (rollAngle < 0xF546) { // 15..150 degrees from 12 o'clock. gTTCSpeedSetting = TTC_SPEED_SLOW; - else // < 15 degrees from 12 o'clock. + } else { // < 15 degrees from 12 o'clock. gTTCSpeedSetting = TTC_SPEED_STOPPED; + } } // Increment the action to stop animating the hands. @@ -45,6 +49,7 @@ void bhv_rotating_clock_arm_loop(void) { } // Only rotate the hands until Mario enters the painting. - if (o->oAction < 2) + if (o->oAction < 2) { cur_obj_rotate_face_angle_using_vel(); + } } diff --git a/src/game/behaviors/cloud.inc.c b/src/game/behaviors/cloud.inc.c index 527e5825..0efc7806 100644 --- a/src/game/behaviors/cloud.inc.c +++ b/src/game/behaviors/cloud.inc.c @@ -103,11 +103,9 @@ static void cloud_fwoosh_update(void) { * unloads, and when fwoosh blows wind. */ static void cloud_act_main(void) { - s16 localOffsetPhase; + s16 localOffsetPhase = 0x800 * gGlobalTimer; f32 localOffset; - localOffsetPhase = 0x800 * gGlobalTimer; - if (o->parentObj != o) { // Despawn if the parent lakitu does if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) { @@ -176,7 +174,7 @@ void bhv_cloud_part_update(void) { if (o->parentObj->oAction == CLOUD_ACT_UNLOAD) { obj_mark_for_deletion(o); } else { - f32 size = 2.0f / 3.0f * o->parentObj->header.gfx.scale[0]; + f32 scale = 2.0f / 3.0f * o->parentObj->header.gfx.scale[0]; s16 angleFromCenter = o->parentObj->oFaceAngleYaw + 0x10000 / 5 * o->oBehParams2ndByte; // Takes 32 frames to cycle @@ -185,22 +183,22 @@ void bhv_cloud_part_update(void) { f32 cloudRadius; - cur_obj_scale(size); + cur_obj_scale(scale); // Cap fwoosh's face size - if (o->oBehParams2ndByte == 5 && size > 2.0f) { - size = o->header.gfx.scale[1] = 2.0f; + if (o->oBehParams2ndByte == 5 && scale > 2.0f) { + scale = o->header.gfx.scale[1] = 2.0f; } // Move back and forth along (1, 1, 1) - localOffset = 2 * coss(localOffsetPhase) * size; + localOffset = 2 * coss(localOffsetPhase) * scale; - cloudRadius = 25.0f * size; + cloudRadius = 25.0f * scale; o->oPosX = o->parentObj->oCloudCenterX + cloudRadius * sins(angleFromCenter) + localOffset; o->oPosY = - o->parentObj->oCloudCenterY + localOffset + size * sCloudPartHeights[o->oBehParams2ndByte]; + o->parentObj->oCloudCenterY + localOffset + scale * sCloudPartHeights[o->oBehParams2ndByte]; o->oPosZ = o->parentObj->oPosZ + cloudRadius * coss(angleFromCenter) + localOffset; diff --git a/src/game/behaviors/coffin.inc.c b/src/game/behaviors/coffin.inc.c index 5926bff8..d675fdcd 100644 --- a/src/game/behaviors/coffin.inc.c +++ b/src/game/behaviors/coffin.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvCoffinSpawner and bhvCoffin. * The coffins are spawned by a singular spawner, @@ -37,7 +38,7 @@ void bhv_coffin_spawner_loop(void) { // Behavior param of 0 for all even i, 1 for all odd coffin = spawn_object_relative(i & 1, coffinRelativePos[i].x, 0, relativeZ, o, - MODEL_BBH_WOODEN_TOMB, bhvCoffin); + MODEL_BBH_WOODEN_TOMB, bhvCoffin); // Never true, game would enter a while(1) before it could. // Possible a remnant of days this didn't happen. @@ -49,7 +50,7 @@ void bhv_coffin_spawner_loop(void) { } } - o->oAction += 1; + o->oAction++; } } else if (o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM) { o->oAction = COFFIN_SPAWNER_ACT_COFFINS_UNLOADED; @@ -62,13 +63,6 @@ void bhv_coffin_spawner_loop(void) { * Also controls laying the coffin down after it has stood up. */ void coffin_act_idle(void) { - f32 yawCos; - f32 yawSin; - f32 dx; - f32 dz; - f32 distForwards; - f32 distSideways; - if (o->oBehParams2ndByte != COFFIN_BP_STATIC) { // Lay down if standing if (o->oFaceAnglePitch != 0) { @@ -90,25 +84,23 @@ void coffin_act_idle(void) { o->oTimer = 0; } else { // Yaw never changes and is aligned, so yawCos = 1 or -1, yawSin = 0 - yawCos = coss(o->oFaceAngleYaw); - yawSin = sins(o->oFaceAngleYaw); + f32 yawCos = coss(o->oFaceAngleYaw); + f32 yawSin = sins(o->oFaceAngleYaw); - dx = gMarioObject->oPosX - o->oPosX; - dz = gMarioObject->oPosZ - o->oPosZ; + f32 dx = gMarioObject->oPosX - o->oPosX; + f32 dz = gMarioObject->oPosZ - o->oPosZ; - distForwards = dx * yawCos + dz * yawSin; - distSideways = dz * yawCos - dx * yawSin; + f32 distForwards = dx * yawCos + dz * yawSin; + f32 distSideways = dz * yawCos - dx * yawSin; // This checks a box around the coffin and if it has been a bit since it stood up. // It also checks in the case Mario is squished, so he doesn't get permanently squished. if (o->oTimer > 60 - && (o->oDistanceToMario > 100.0f || gMarioState->action == ACT_SQUISHED)) { - if (gMarioObject->oPosY - o->oPosY < 200.0f && absf(distForwards) < 140.0f) { - if (distSideways < 150.0f && distSideways > -450.0f) { - cur_obj_play_sound_2(SOUND_GENERAL_BUTTON_PRESS_2_LOWPRIO); - o->oAction = COFFIN_ACT_STAND_UP; - } - } + && (o->oDistanceToMario > 100.0f || gMarioState->action == ACT_SQUISHED) + && gMarioObject->oPosY - o->oPosY < 200.0f && absf(distForwards) < 140.0f + && distSideways < 150.0f && distSideways > -450.0f) { + cur_obj_play_sound_2(SOUND_GENERAL_BUTTON_PRESS_2_LOWPRIO); + o->oAction = COFFIN_ACT_STAND_UP; } o->oAngleVelPitch = 0; diff --git a/src/game/behaviors/coin.inc.c b/src/game/behaviors/coin.inc.c index 2aeebca8..bbd07fcd 100644 --- a/src/game/behaviors/coin.inc.c +++ b/src/game/behaviors/coin.inc.c @@ -1,28 +1,39 @@ -// coin.c.inc +// coin.inc.c struct ObjectHitbox sYellowCoinHitbox = { - /* interactType: */ INTERACT_COIN, - /* downOffset: */ 0, + /* interactType: */ INTERACT_COIN, + /* downOffset: */ 0, /* damageOrCoinValue: */ 1, - /* health: */ 0, - /* numLootCoins: */ 0, - /* radius: */ 100, - /* height: */ 64, - /* hurtboxRadius: */ 0, - /* hurtboxHeight: */ 0, + /* health: */ 0, + /* numLootCoins: */ 0, + /* radius: */ 100, + /* height: */ 64, + /* hurtboxRadius: */ 0, + /* hurtboxHeight: */ 0, }; -s16 D_8032F2A4[][2] = { { 0, -150 }, { 0, -50 }, { 0, 50 }, { 0, 150 }, - { -50, 100 }, { -100, 50 }, { 50, 100 }, { 100, 50 } }; +s16 sCoinArrowPositions[][2] = { + { 0, -150 }, + { 0, -50 }, + { 0, 50 }, + { 0, 150 }, + { -50, 100 }, + { -100, 50 }, + { 50, 100 }, + { 100, 50 }, +}; s32 bhv_coin_sparkles_init(void) { - if (o->oInteractStatus & INT_STATUS_INTERACTED && !(o->oInteractStatus & INT_STATUS_TOUCHED_BOB_OMB)) { + if (o->oInteractStatus & INT_STATUS_INTERACTED + && !(o->oInteractStatus & INT_STATUS_TOUCHED_BOB_OMB)) { spawn_object(o, MODEL_SPARKLES, bhvGoldenCoinSparkles); obj_mark_for_deletion(o); - return 1; + return TRUE; } + o->oInteractStatus = 0; - return 0; + + return FALSE; } void bhv_yellow_coin_init(void) { @@ -30,10 +41,14 @@ void bhv_yellow_coin_init(void) { obj_set_hitbox(o, &sYellowCoinHitbox); bhv_init_room(); cur_obj_update_floor_height(); - if (500.0f < absf(o->oPosY - o->oFloorHeight)) + + if (500.0f < absf(o->oPosY - o->oFloorHeight)) { cur_obj_set_model(MODEL_YELLOW_COIN_NO_SHADOW); - if (o->oFloorHeight < FLOOR_LOWER_LIMIT_MISC) + } + + if (o->oFloorHeight < FLOOR_LOWER_LIMIT_MISC) { obj_mark_for_deletion(o); + } } void bhv_yellow_coin_loop(void) { @@ -43,8 +58,11 @@ void bhv_yellow_coin_loop(void) { void bhv_temp_coin_loop(void) { o->oAnimState++; - if (cur_obj_wait_then_blink(200, 20)) + + if (cur_obj_wait_then_blink(200, 20)) { obj_mark_for_deletion(o); + } + bhv_coin_sparkles_init(); } @@ -52,6 +70,7 @@ void bhv_coin_init(void) { o->oVelY = random_float() * 10.0f + 30 + o->oCoinUnk110; o->oForwardVel = random_float() * 10.0f; o->oMoveAngleYaw = random_u16(); + cur_obj_set_behavior(bhvYellowCoin); obj_set_hitbox(o, &sYellowCoinHitbox); cur_obj_become_intangible(); @@ -59,51 +78,58 @@ void bhv_coin_init(void) { void bhv_coin_loop(void) { struct Surface *sp1C; - s16 sp1A; + cur_obj_update_floor_and_walls(); cur_obj_if_hit_wall_bounce_away(); cur_obj_move_standard(-62); + if ((sp1C = o->oFloor) != NULL) { - if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) + if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) { o->oSubAction = 1; + } if (o->oSubAction == 1) { o->oBounciness = 0; if (sp1C->normal.y < 0.9) { - sp1A = atan2s(sp1C->normal.z, sp1C->normal.x); + s16 sp1A = atan2s(sp1C->normal.z, sp1C->normal.x); cur_obj_rotate_yaw_toward(sp1A, 0x400); } } } - if (o->oTimer == 0) -#if defined(VERSION_US) - cur_obj_play_sound_2(SOUND_GENERAL_COIN_SPURT_2); -#elif defined(VERSION_EU) || defined(VERSION_SH) - cur_obj_play_sound_2(SOUND_GENERAL_COIN_SPURT_EU); -#else + + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_GENERAL_COIN_SPURT); -#endif - if (o->oVelY < 0) + } + + if (o->oVelY < 0) { cur_obj_become_tangible(); + } + if (o->oMoveFlags & OBJ_MOVE_LANDED) { #ifndef VERSION_JP if (o->oMoveFlags & (OBJ_MOVE_ABOVE_DEATH_BARRIER | OBJ_MOVE_ABOVE_LAVA)) #else if (o->oMoveFlags & OBJ_MOVE_ABOVE_LAVA) #endif + { obj_mark_for_deletion(o); + } } -#ifndef VERSION_JP + if (o->oMoveFlags & OBJ_MOVE_BOUNCE) { - if (o->oCoinUnk1B0 < 5) +#ifndef VERSION_JP + if (o->oCoinUnk1B0 < 5) { cur_obj_play_sound_2(SOUND_GENERAL_COIN_DROP); + } o->oCoinUnk1B0++; - } #else - if (o->oMoveFlags & OBJ_MOVE_BOUNCE) cur_obj_play_sound_2(SOUND_GENERAL_COIN_DROP); #endif - if (cur_obj_wait_then_blink(400, 20)) + } + + if (cur_obj_wait_then_blink(400, 20)) { obj_mark_for_deletion(o); + } + bhv_coin_sparkles_init(); } @@ -112,25 +138,33 @@ void bhv_coin_formation_spawn_loop(void) { cur_obj_set_behavior(bhvYellowCoin); obj_set_hitbox(o, &sYellowCoinHitbox); bhv_init_room(); + if (o->oCoinUnkF8) { o->oPosY += 300.0f; cur_obj_update_floor_height(); - if (o->oPosY < o->oFloorHeight || o->oFloorHeight < FLOOR_LOWER_LIMIT_MISC) + + if (o->oPosY < o->oFloorHeight || o->oFloorHeight < FLOOR_LOWER_LIMIT_MISC) { obj_mark_for_deletion(o); - else + } else { o->oPosY = o->oFloorHeight; + } } else { cur_obj_update_floor_height(); - if (absf(o->oPosY - o->oFloorHeight) > 250.0f) + + if (absf(o->oPosY - o->oFloorHeight) > 250.0f) { cur_obj_set_model(MODEL_YELLOW_COIN_NO_SHADOW); + } } } else { - if (bhv_coin_sparkles_init()) + if (bhv_coin_sparkles_init()) { o->parentObj->oCoinUnkF4 |= bit_shift_left(o->oBehParams2ndByte); + } o->oAnimState++; } - if (o->parentObj->oAction == 2) + + if (o->parentObj->oAction == 2) { obj_mark_for_deletion(o); + } } void spawn_coin_in_formation(s32 sp50, s32 sp54) { @@ -138,18 +172,22 @@ void spawn_coin_in_formation(s32 sp50, s32 sp54) { Vec3i sp40; s32 sp3C = 1; s32 sp38 = 1; + sp40[0] = sp40[1] = sp40[2] = 0; + switch (sp54 & 7) { case 0: sp40[2] = 160 * (sp50 - 2); - if (sp50 > 4) + if (sp50 > 4) { sp3C = 0; + } break; case 1: sp38 = 0; sp40[1] = 160 * sp50 * 0.8; // 128 * sp50 - if (sp50 > 4) + if (sp50 > 4) { sp3C = 0; + } break; case 2: sp40[0] = sins(sp50 << 13) * 300.0f; @@ -161,12 +199,15 @@ void spawn_coin_in_formation(s32 sp50, s32 sp54) { sp40[1] = sins(sp50 << 13) * 200.0f + 200.0f; break; case 4: - sp40[0] = D_8032F2A4[sp50][0]; - sp40[2] = D_8032F2A4[sp50][1]; + sp40[0] = sCoinArrowPositions[sp50][0]; + sp40[2] = sCoinArrowPositions[sp50][1]; break; } - if (sp54 & 0x10) + + if (sp54 & 0x10) { sp38 = 0; + } + if (sp3C) { sp4C = spawn_object_relative(sp50, sp40[0], sp40[1], sp40[2], o, MODEL_YELLOW_COIN, bhvCoinFormationSpawn); @@ -180,19 +221,22 @@ void bhv_coin_formation_init(void) { void bhv_coin_formation_loop(void) { s32 bitIndex; + switch (o->oAction) { case 0: if (o->oDistanceToMario < 2000.0f) { for (bitIndex = 0; bitIndex < 8; bitIndex++) { - if (!(o->oCoinUnkF4 & (1 << bitIndex))) + if (!(o->oCoinUnkF4 & (1 << bitIndex))) { spawn_coin_in_formation(bitIndex, o->oBehParams2ndByte); + } } o->oAction++; } break; case 1: - if (o->oDistanceToMario > 2100.0f) + if (o->oDistanceToMario > 2100.0f) { o->oAction++; + } break; case 2: o->oAction = 0; @@ -206,31 +250,43 @@ void bhv_coin_formation_loop(void) { void coin_inside_boo_act_1(void) { cur_obj_update_floor_and_walls(); cur_obj_if_hit_wall_bounce_away(); - if (o->oMoveFlags & OBJ_MOVE_BOUNCE) + + if (o->oMoveFlags & OBJ_MOVE_BOUNCE) { cur_obj_play_sound_2(SOUND_GENERAL_COIN_DROP); + } + if (o->oTimer > 90 || (o->oMoveFlags & OBJ_MOVE_LANDED)) { obj_set_hitbox(o, &sYellowCoinHitbox); cur_obj_become_tangible(); cur_obj_set_behavior(bhvYellowCoin); } + cur_obj_move_standard(-30); bhv_coin_sparkles_init(); - if (cur_obj_has_model(MODEL_BLUE_COIN)) + + if (cur_obj_has_model(MODEL_BLUE_COIN)) { o->oDamageOrCoinValue = 5; - if (cur_obj_wait_then_blink(400, 20)) + } + + if (cur_obj_wait_then_blink(400, 20)) { obj_mark_for_deletion(o); + } } void coin_inside_boo_act_0(void) { s16 sp26; f32 sp20; struct Object *parent = o->parentObj; + cur_obj_become_intangible(); + if (o->oTimer == 0 && gCurrLevelNum == LEVEL_BBH) { cur_obj_set_model(MODEL_BLUE_COIN); - cur_obj_scale(0.7); + cur_obj_scale(0.7f); } + obj_copy_pos(o, parent); + if (parent->oBooDeathStatus == BOO_DEATH_STATUS_DYING) { o->oAction = 1; sp26 = gMarioObject->oMoveAngleYaw; @@ -241,7 +297,10 @@ void coin_inside_boo_act_0(void) { } } -void (*sCoinInsideBooActions[])(void) = { coin_inside_boo_act_0, coin_inside_boo_act_1 }; +void (*sCoinInsideBooActions[])(void) = { + coin_inside_boo_act_0, + coin_inside_boo_act_1, +}; void bhv_coin_inside_boo_loop(void) { cur_obj_call_action_function(sCoinInsideBooActions); @@ -253,8 +312,9 @@ void bhv_coin_sparkles_loop(void) { void bhv_golden_coin_sparkles_loop(void) { struct Object *sp2C; - UNUSED s32 unused; + UNUSED u8 filler[4]; f32 sp24 = 30.0f; + sp2C = spawn_object(o, MODEL_SPARKLES, bhvCoinSparkles); sp2C->oPosX += random_float() * sp24 - sp24 / 2; sp2C->oPosZ += random_float() * sp24 - sp24 / 2; diff --git a/src/game/behaviors/collide_particles.inc.c b/src/game/behaviors/collide_particles.inc.c index ff93a511..4f69d406 100644 --- a/src/game/behaviors/collide_particles.inc.c +++ b/src/game/behaviors/collide_particles.inc.c @@ -1,47 +1,49 @@ -// collide_particles.c.inc +// collide_particles.inc.c -s16 D_8032F2CC[] = { 0xD000, 0, 0x3000, 0, 0xDE67, 0x2199, - 0x2199, 0x2199, 0xDE67, 0xDE67, 0x2199, 0xDE67 }; +static s16 sTinyTriMovementParams[] = { 0xD000, 0, 0x3000, 0, 0xDE67, 0x2199, + 0x2199, 0x2199, 0xDE67, 0xDE67, 0x2199, 0xDE67 }; -s16 D_8032F2E4[] = { 0xE000, 0, 0, 0, 0x2000, 0, 0xE99A, - 0x1666, 0x1666, 0x1666, 0xE99A, 0xE99A, 0x1666, 0xE99A }; +static s16 sTinyStarMovementParams[] = { 0xE000, 0, 0, 0, 0x2000, 0, 0xE99A, + 0x1666, 0x1666, 0x1666, 0xE99A, 0xE99A, 0x1666, 0xE99A }; void bhv_punch_tiny_triangle_loop(void) { - s16 sp1E; if (o->oTimer == 0) { - sp1E = o->oMoveAngleYaw; + s16 sp1E = o->oMoveAngleYaw; o->oCollisionParticleUnkF4 = 1.28f; cur_obj_set_pos_relative(gMarioObject, 0.0f, 60.0f, 100.0f); o->oMoveAngleYaw = sp1E; } + cur_obj_move_using_fvel_and_gravity(); o->oAnimState = 5; cur_obj_scale(o->oCollisionParticleUnkF4); o->oCollisionParticleUnkF4 -= 0.2f; - if (gDebugInfo[4][0] + 6 < o->oTimer) + + if (gDebugInfo[DEBUG_PAGE_EFFECTINFO][0] + 6 < o->oTimer) { obj_mark_for_deletion(o); + } } void bhv_punch_tiny_triangle_init(void) { s32 i; - UNUSED s32 unused; - struct Object *triangle; + UNUSED u8 filler[4]; + for (i = 0; i < 6; i++) { - triangle = spawn_object(o, MODEL_DIRT_ANIMATION, bhvPunchTinyTriangle); - triangle->oMoveAngleYaw = gMarioObject->oMoveAngleYaw + D_8032F2CC[2 * i] + 0x8000; - triangle->oVelY = sins(D_8032F2CC[2 * i + 1]) * 25.0f; - triangle->oForwardVel = coss(D_8032F2CC[2 * i + 1]) * 25.0f; + struct Object *triangle = spawn_object(o, MODEL_DIRT_ANIMATION, bhvPunchTinyTriangle); + triangle->oMoveAngleYaw = gMarioObject->oMoveAngleYaw + sTinyTriMovementParams[2 * i] + 0x8000; + triangle->oVelY = sins(sTinyTriMovementParams[2 * i + 1]) * 25.0f; + triangle->oForwardVel = coss(sTinyTriMovementParams[2 * i + 1]) * 25.0f; } } void bhv_wall_tiny_star_particle_loop(void) { - s16 sp1E; if (o->oTimer == 0) { - sp1E = o->oMoveAngleYaw; + s16 sp1E = o->oMoveAngleYaw; o->oCollisionParticleUnkF4 = 0.28f; cur_obj_set_pos_relative(gMarioObject, 0.0f, 30.0f, 110.0f); o->oMoveAngleYaw = sp1E; } + cur_obj_move_using_fvel_and_gravity(); o->oAnimState = 4; cur_obj_scale(o->oCollisionParticleUnkF4); @@ -50,13 +52,13 @@ void bhv_wall_tiny_star_particle_loop(void) { void bhv_tiny_star_particles_init(void) { s32 i; - UNUSED s32 unused; - struct Object *particle; + UNUSED u8 filler[4]; + for (i = 0; i < 7; i++) { - particle = spawn_object(o, MODEL_CARTOON_STAR, bhvWallTinyStarParticle); - particle->oMoveAngleYaw = gMarioObject->oMoveAngleYaw + D_8032F2E4[2 * i] + 0x8000; - particle->oVelY = sins(D_8032F2E4[2 * i + 1]) * 25.0f; - particle->oForwardVel = coss(D_8032F2E4[2 * i + 1]) * 25.0f; + struct Object *particle = spawn_object(o, MODEL_CARTOON_STAR, bhvWallTinyStarParticle); + particle->oMoveAngleYaw = gMarioObject->oMoveAngleYaw + sTinyStarMovementParams[2 * i] + 0x8000; + particle->oVelY = sins(sTinyStarMovementParams[2 * i + 1]) * 25.0f; + particle->oForwardVel = coss(sTinyStarMovementParams[2 * i + 1]) * 25.0f; } } @@ -67,6 +69,7 @@ void bhv_pound_tiny_star_particle_loop(void) { o->oPosY -= 20.0f; o->oVelY = 14.0f; } + cur_obj_move_using_fvel_and_gravity(); o->oAnimState = 4; cur_obj_scale(o->oCollisionParticleUnkF4); @@ -76,9 +79,9 @@ void bhv_pound_tiny_star_particle_loop(void) { void bhv_pound_tiny_star_particle_init(void) { s32 sp24; s32 sp20 = 8; - struct Object *particle; + for (sp24 = 0; sp24 < sp20; sp24++) { - particle = spawn_object(o, MODEL_CARTOON_STAR, bhvPoundTinyStarParticle); + struct Object *particle = spawn_object(o, MODEL_CARTOON_STAR, bhvPoundTinyStarParticle); particle->oMoveAngleYaw = (sp24 * 65536) / sp20; } } diff --git a/src/game/behaviors/controllable_platform.inc.c b/src/game/behaviors/controllable_platform.inc.c index 17e8beee..ae03dc8a 100644 --- a/src/game/behaviors/controllable_platform.inc.c +++ b/src/game/behaviors/controllable_platform.inc.c @@ -1,4 +1,4 @@ -// controllable_platform.c.inc +// controllable_platform.inc.c static s8 D_80331694 = 0; @@ -11,8 +11,9 @@ void controllable_platform_act_1(void) { } void controllable_platform_act_2(void) { - if (o->oBehParams2ndByte == D_80331694) + if (o->oBehParams2ndByte == D_80331694) { return; + } o->oParentRelativePosY += 4.0f; if (o->oParentRelativePosY > 51.0f) { @@ -24,8 +25,9 @@ void controllable_platform_act_2(void) { void bhv_controllable_platform_sub_loop(void) { switch (o->oAction) { case 0: - if (o->oTimer < 30) + if (o->oTimer < 30) { break; + } if (gMarioObject->platform == o) { D_80331694 = o->oBehParams2ndByte; @@ -49,12 +51,14 @@ void bhv_controllable_platform_sub_loop(void) { o->oVelX = o->parentObj->oVelX; o->oVelZ = o->parentObj->oVelZ; - if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) + if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } } void bhv_controllable_platform_init(void) { struct Object *sp34; + sp34 = spawn_object_rel_with_rot(o, MODEL_HMC_METAL_ARROW_PLATFORM, bhvControllablePlatformSub, 0, 51, 204, 0, 0, 0); sp34->oBehParams2ndByte = 1; @@ -79,15 +83,15 @@ void controllable_platform_hit_wall(s8 sp1B) { D_80331694 = 5; cur_obj_play_sound_2(SOUND_GENERAL_QUIET_POUND1); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(50, 80); #endif } void controllable_platform_check_walls(s8 sp1B, s8 sp1C[3], Vec3f sp20, UNUSED Vec3f sp24, Vec3f sp28) { - if (sp1C[1] == 1 || (sp1C[0] == 1 && sp1C[2] == 1)) + if (sp1C[1] == 1 || (sp1C[0] == 1 && sp1C[2] == 1)) { controllable_platform_hit_wall(sp1B); - else { + } else { if (sp1C[0] == 1) { if (((sp1B == 1 || sp1B == 2) && (s32) sp20[2] != 0) || ((sp1B == 3 || sp1B == 4) && (s32) sp20[0] != 0)) { @@ -209,15 +213,17 @@ void bhv_controllable_platform_loop(void) { break; case 6: - if (obj_flicker_and_disappear(o, 150)) + if (obj_flicker_and_disappear(o, 150)) { spawn_object_abs_with_rot(o, 0, MODEL_HMC_METAL_PLATFORM, bhvControllablePlatform, o->oHomeX, o->oHomeY, o->oHomeZ, 0, 0, 0); + } break; } controllable_platform_tilt_from_mario(); o->oPosX += o->oVelX; o->oPosZ += o->oVelZ; - if (D_80331694 != 0 && D_80331694 != 6) + if (D_80331694 != 0 && D_80331694 != 6) { cur_obj_play_sound_1(SOUND_ENV_ELEVATOR2); + } } diff --git a/src/game/behaviors/corkbox.inc.c b/src/game/behaviors/corkbox.inc.c index e9316513..df2d7955 100644 --- a/src/game/behaviors/corkbox.inc.c +++ b/src/game/behaviors/corkbox.inc.c @@ -1,4 +1,4 @@ -// corkbox.c.inc +// corkbox.inc.c // TODO: This split seems weird. Investigate further? void bhv_bobomb_bully_death_smoke_init(void) { @@ -31,18 +31,18 @@ void bhv_bobomb_explosion_bubble_loop(void) { spawn_object(o, MODEL_SMALL_WATER_SPLASH, bhvObjectWaterSplash); } - if (o->oTimer >= 61) + if (o->oTimer > 60) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } o->oPosY += o->oVelY; o->oTimer++; } void bhv_respawner_loop(void) { - struct Object *spawnedObject; - if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, o->oRespawnerMinSpawnDist)) { - spawnedObject = spawn_object(o, o->oRespawnerModelToRespawn, o->oRespawnerBehaviorToRespawn); + struct Object *spawnedObject = spawn_object(o, o->oRespawnerModelToRespawn, + o->oRespawnerBehaviorToRespawn); spawnedObject->oBehParams = o->oBehParams; o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } diff --git a/src/game/behaviors/cruiser.inc.c b/src/game/behaviors/cruiser.inc.c index a705bb2c..71b22c03 100644 --- a/src/game/behaviors/cruiser.inc.c +++ b/src/game/behaviors/cruiser.inc.c @@ -1,4 +1,4 @@ -// cruiser.c.inc +// cruiser.inc.c void bhv_rr_cruiser_wing_init(void) { o->oRRCruiserWingUnkF4 = o->oFaceAngleYaw; diff --git a/src/game/behaviors/ddd_pole.inc.c b/src/game/behaviors/ddd_pole.inc.c index 58d7d616..86e5312a 100644 --- a/src/game/behaviors/ddd_pole.inc.c +++ b/src/game/behaviors/ddd_pole.inc.c @@ -1,3 +1,4 @@ +// ddd_pole.inc.c void bhv_ddd_pole_init(void) { if (!(save_file_get_flags() & (SAVE_FLAG_HAVE_KEY_2 | SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR))) { diff --git a/src/game/behaviors/ddd_sub.inc.c b/src/game/behaviors/ddd_sub.inc.c index d8479c65..2d59a223 100644 --- a/src/game/behaviors/ddd_sub.inc.c +++ b/src/game/behaviors/ddd_sub.inc.c @@ -1,6 +1,7 @@ -// ddd_sub.c.inc +// ddd_sub.inc.c void bhv_bowsers_sub_loop(void) { - if (save_file_get_flags() & (SAVE_FLAG_HAVE_KEY_2 | SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR)) + if (save_file_get_flags() & (SAVE_FLAG_HAVE_KEY_2 | SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR)) { obj_mark_for_deletion(o); + } } diff --git a/src/game/behaviors/ddd_warp.inc.c b/src/game/behaviors/ddd_warp.inc.c index 617e850f..15b00be4 100644 --- a/src/game/behaviors/ddd_warp.inc.c +++ b/src/game/behaviors/ddd_warp.inc.c @@ -1,8 +1,9 @@ -// ddd_warp.c.inc +// ddd_warp.inc.c void bhv_ddd_warp_loop(void) { - if (gDddPaintingStatus & BOWSERS_SUB_BEATEN) + if (gDddPaintingStatus & BOWSERS_SUB_BEATEN) { o->collisionData = segmented_to_virtual(inside_castle_seg7_collision_ddd_warp_2); - else + } else { o->collisionData = segmented_to_virtual(inside_castle_seg7_collision_ddd_warp); + } } diff --git a/src/game/behaviors/decorative_pendulum.inc.c b/src/game/behaviors/decorative_pendulum.inc.c index 2aa9539f..9d0ca338 100644 --- a/src/game/behaviors/decorative_pendulum.inc.c +++ b/src/game/behaviors/decorative_pendulum.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvDecorativePendulum. * This controls the pendulum that lies underneath the Tick Tock Clock painting. @@ -13,10 +14,11 @@ void bhv_decorative_pendulum_init(void) { * acceleration. */ void bhv_decorative_pendulum_loop(void) { - if (o->oFaceAngleRoll > 0) + if (o->oFaceAngleRoll > 0) { o->oAngleVelRoll -= 0x08; - else + } else { o->oAngleVelRoll += 0x08; + } o->oFaceAngleRoll += o->oAngleVelRoll; @@ -26,6 +28,7 @@ void bhv_decorative_pendulum_loop(void) { * This means the sound we hear when the pendulum hits its upswing is * actually one sound played twice in rapid succession. */ - if (o->oAngleVelRoll == 0x10 || o->oAngleVelRoll == -0x10) + if (o->oAngleVelRoll == 0x10 || o->oAngleVelRoll == -0x10) { cur_obj_play_sound_2(SOUND_GENERAL_BIG_CLOCK); + } } diff --git a/src/game/behaviors/donut_platform.inc.c b/src/game/behaviors/donut_platform.inc.c index f1503a0e..4c0eefc5 100644 --- a/src/game/behaviors/donut_platform.inc.c +++ b/src/game/behaviors/donut_platform.inc.c @@ -1,3 +1,5 @@ +// donut_platform.inc.c + static Vec3s sDonutPlatformPositions[] = { { 0x0B4C, 0xF7D7, 0x19A4 }, { 0xF794, 0x08A3, 0xFFA9 }, { 0x069C, 0x09D8, 0xFFE0 }, { 0x05CF, 0x09D8, 0xFFE0 }, { 0x0502, 0x09D8, 0xFFE0 }, { 0x054C, 0xF7D7, 0x19A4 }, @@ -15,24 +17,19 @@ static Vec3s sDonutPlatformPositions[] = { void bhv_donut_platform_spawner_update(void) { s32 i; s32 platformFlag; - f32 dx; - f32 dy; - f32 dz; - f32 marioSqDist; - for (i = 0, platformFlag = 1; i < 31; i++, platformFlag = platformFlag << 1) { + for (i = 0, platformFlag = 1; i < ARRAY_COUNT(sDonutPlatformPositions); i++, platformFlag = platformFlag << 1) { if (!(o->oDonutPlatformSpawnerSpawnedPlatforms & platformFlag)) { - dx = gMarioObject->oPosX - sDonutPlatformPositions[i][0]; - dy = gMarioObject->oPosY - sDonutPlatformPositions[i][1]; - dz = gMarioObject->oPosZ - sDonutPlatformPositions[i][2]; - marioSqDist = dx * dx + dy * dy + dz * dz; + f32 dx = gMarioObject->oPosX - sDonutPlatformPositions[i][0]; + f32 dy = gMarioObject->oPosY - sDonutPlatformPositions[i][1]; + f32 dz = gMarioObject->oPosZ - sDonutPlatformPositions[i][2]; + f32 marioSqDist = dx * dx + dy * dy + dz * dz; // dist > 1000 and dist < 2000 if (marioSqDist > 1000000.0f && marioSqDist < 4000000.0f) { if (spawn_object_relative(i, sDonutPlatformPositions[i][0], sDonutPlatformPositions[i][1], sDonutPlatformPositions[i][2], - o, MODEL_RR_DONUT_PLATFORM, bhvDonutPlatform) - != NULL) { + o, MODEL_RR_DONUT_PLATFORM, bhvDonutPlatform) != NULL) { o->oDonutPlatformSpawnerSpawnedPlatforms |= platformFlag; } } diff --git a/src/game/behaviors/door.inc.c b/src/game/behaviors/door.inc.c index db48e4f9..c25626c7 100644 --- a/src/game/behaviors/door.inc.c +++ b/src/game/behaviors/door.inc.c @@ -1,55 +1,57 @@ -// door.c.inc +// door.inc.c -struct DoorAction -{ +struct DoorAction { u32 flag; s32 action; }; -struct DoorAction D_8032F300[] = { { 0x40000, 3 }, { 0x80000, 4 }, { 0x10000, 1 }, { 0x20000, 2 }, { -1, 0 }, }; +static struct DoorAction sDoorActions[] = { { 0x40000, 3 }, { 0x80000, 4 }, { 0x10000, 1 }, { 0x20000, 2 }, { 0xFFFFFFFF, 0 }, }; -s32 D_8032F328[] = { SOUND_GENERAL_OPEN_WOOD_DOOR, SOUND_GENERAL_OPEN_IRON_DOOR }; +static s32 sDoorOpenSounds[] = { SOUND_GENERAL_OPEN_WOOD_DOOR, SOUND_GENERAL_OPEN_IRON_DOOR }; -s32 D_8032F330[] = { SOUND_GENERAL_CLOSE_WOOD_DOOR, SOUND_GENERAL_CLOSE_IRON_DOOR }; +static s32 sDoorCloseSounds[] = { SOUND_GENERAL_CLOSE_WOOD_DOOR, SOUND_GENERAL_CLOSE_IRON_DOOR }; void door_animation_and_reset(s32 sp18) { cur_obj_init_animation_with_sound(sp18); - if (cur_obj_check_if_near_animation_end()) + if (cur_obj_check_if_near_animation_end()) { o->oAction = 0; + } } void set_door_camera_event(void) { - if (segmented_to_virtual(bhvDoor) == o->behavior) + if (segmented_to_virtual(bhvDoor) == o->behavior) { gPlayerCameraState->cameraEvent = CAM_EVENT_DOOR; - else + } else { gPlayerCameraState->cameraEvent = CAM_EVENT_DOOR_WARP; + } gPlayerCameraState->usedObj = o; } void play_door_open_noise(void) { s32 sp1C = cur_obj_has_model(MODEL_HMC_METAL_DOOR); if (o->oTimer == 0) { - cur_obj_play_sound_2(D_8032F328[sp1C]); + cur_obj_play_sound_2(sDoorOpenSounds[sp1C]); gTimeStopState |= TIME_STOP_MARIO_OPENED_DOOR; } if (o->oTimer == 70) { - cur_obj_play_sound_2(D_8032F330[sp1C]); + cur_obj_play_sound_2(sDoorCloseSounds[sp1C]); } } void play_warp_door_open_noise(void) { s32 sp1C = cur_obj_has_model(MODEL_HMC_METAL_DOOR); - if (o->oTimer == 30) - cur_obj_play_sound_2(D_8032F330[sp1C]); + if (o->oTimer == 30) { + cur_obj_play_sound_2(sDoorCloseSounds[sp1C]); + } } void bhv_door_loop(void) { s32 sp1C = 0; - - while (D_8032F300[sp1C].flag != (u32)~0) { - if (cur_obj_clear_interact_status_flag(D_8032F300[sp1C].flag)) { + + while (sDoorActions[sp1C].flag != 0xFFFFFFFF) { + if (cur_obj_clear_interact_status_flag(sDoorActions[sp1C].flag)) { set_door_camera_event(); - cur_obj_change_action(D_8032F300[sp1C].action); + cur_obj_change_action(sDoorActions[sp1C].action); } sp1C++; } @@ -75,15 +77,21 @@ void bhv_door_loop(void) { play_warp_door_open_noise(); break; } - if (o->oAction == 0) + + if (o->oAction == 0) { load_object_collision_model(); + } + bhv_star_door_loop_2(); } void bhv_door_init(void) { - f32 x = o->oPosX; - f32 z = o->oPosZ; + f32 x; + f32 z; struct Surface *floor; + + x = o->oPosX; + z = o->oPosZ; find_floor(x, o->oPosY, z, &floor); if (floor != NULL) { o->oDoorUnkF8 = floor->room; @@ -110,30 +118,36 @@ void bhv_door_init(void) { } void bhv_star_door_loop_2(void) { - s32 sp4 = 0; + s32 sp4 = FALSE; + if (gMarioCurrentRoom != 0) { - if (o->oDoorUnkF8 == gMarioCurrentRoom) - sp4 = 1; - else if (gMarioCurrentRoom == o->oDoorUnkFC) - sp4 = 1; - else if (gMarioCurrentRoom == o->oDoorUnk100) - sp4 = 1; - else if (gDoorAdjacentRooms[gMarioCurrentRoom][0] == o->oDoorUnkFC) - sp4 = 1; - else if (gDoorAdjacentRooms[gMarioCurrentRoom][0] == o->oDoorUnk100) - sp4 = 1; - else if (gDoorAdjacentRooms[gMarioCurrentRoom][1] == o->oDoorUnkFC) - sp4 = 1; - else if (gDoorAdjacentRooms[gMarioCurrentRoom][1] == o->oDoorUnk100) - sp4 = 1; - } else - sp4 = 1; - if (sp4 == 1) { + if (o->oDoorUnkF8 == gMarioCurrentRoom) { + sp4 = TRUE; + } else if (gMarioCurrentRoom == o->oDoorUnkFC) { + sp4 = TRUE; + } else if (gMarioCurrentRoom == o->oDoorUnk100) { + sp4 = TRUE; + } else if (gDoorAdjacentRooms[gMarioCurrentRoom][0] == o->oDoorUnkFC) { + sp4 = TRUE; + } else if (gDoorAdjacentRooms[gMarioCurrentRoom][0] == o->oDoorUnk100) { + sp4 = TRUE; + } else if (gDoorAdjacentRooms[gMarioCurrentRoom][1] == o->oDoorUnkFC) { + sp4 = TRUE; + } else if (gDoorAdjacentRooms[gMarioCurrentRoom][1] == o->oDoorUnk100) { + sp4 = TRUE; + } + } else { + sp4 = TRUE; + } + + if (sp4 == TRUE) { o->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE; D_8035FEE4++; } - if (sp4 == 0) { + + if (!sp4) { o->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE; } + o->oDoorUnk88 = sp4; } diff --git a/src/game/behaviors/dorrie.inc.c b/src/game/behaviors/dorrie.inc.c index 3eb3c04e..8919677b 100644 --- a/src/game/behaviors/dorrie.inc.c +++ b/src/game/behaviors/dorrie.inc.c @@ -1,11 +1,10 @@ +// dorrie.inc.c void dorrie_raise_head(void) { - s16 startAngle; + s16 startAngle = o->oDorrieNeckAngle; f32 xzDisp; f32 yDisp; - startAngle = o->oDorrieNeckAngle; - o->oDorrieNeckAngle -= (s16) absf(370.0f * sins(o->oDorrieHeadRaiseSpeed)); xzDisp = 440.0f * (coss(o->oDorrieNeckAngle) - coss(startAngle)); @@ -16,12 +15,10 @@ void dorrie_raise_head(void) { } void dorrie_act_move(void) { - s16 startYaw; + s16 startYaw = o->oMoveAngleYaw; s16 targetYaw; s16 targetSpeed; - s16 circularTurn; - startYaw = o->oMoveAngleYaw; o->oDorrieNeckAngle = -0x26F4; cur_obj_init_animation_with_sound(1); @@ -36,7 +33,7 @@ void dorrie_act_move(void) { targetYaw = gMarioObject->oFaceAngleYaw; targetSpeed = 10; } else { - circularTurn = 0x4000 - atan2s(2000.0f, o->oDorrieDistToHome - 2000.0f); + s16 circularTurn = 0x4000 - atan2s(2000.0f, o->oDorrieDistToHome - 2000.0f); if ((s16)(o->oMoveAngleYaw - o->oDorrieAngleToHome) < 0) { circularTurn = -circularTurn; } @@ -68,7 +65,8 @@ void dorrie_act_lower_head(void) { if (o->oTimer > 150) { dorrie_begin_head_raise(FALSE); } else if (gMarioObject->platform == o) { - if (o->oDorrieForwardDistToMario > 830.0f && set_mario_npc_dialog(2) == 1) { + if (o->oDorrieForwardDistToMario > 830.0f + && set_mario_npc_dialog(MARIO_DIALOG_LOOK_UP) == MARIO_DIALOG_STATUS_START) { dorrie_begin_head_raise(TRUE); } else if (o->oDorrieForwardDistToMario > 320.0f) { o->oTimer = 0; @@ -77,7 +75,7 @@ void dorrie_act_lower_head(void) { #else if (gMarioObject->platform == o) { if (o->oDorrieOffsetY == -17.0f && o->oDorrieForwardDistToMario > 780.0f - && set_mario_npc_dialog(2) == 1) { + && set_mario_npc_dialog(MARIO_DIALOG_LOOK_UP) == MARIO_DIALOG_STATUS_START) { dorrie_begin_head_raise(TRUE); } else if (o->oDorrieForwardDistToMario > 320.0f) { o->oTimer = 0; @@ -97,10 +95,10 @@ void dorrie_act_raise_head(void) { if (cur_obj_check_if_near_animation_end()) { o->oAction = DORRIE_ACT_MOVE; } else if (o->oDorrieLiftingMario && o->header.gfx.animInfo.animFrame < 74) { - if (set_mario_npc_dialog(2) == 2) { + if (set_mario_npc_dialog(MARIO_DIALOG_LOOK_UP) == MARIO_DIALOG_STATUS_SPEAK) { o->oDorrieHeadRaiseSpeed += 0x1CC; if (cur_obj_check_anim_frame(73)) { - set_mario_npc_dialog(0); + set_mario_npc_dialog(MARIO_DIALOG_STOP); } dorrie_raise_head(); } else { @@ -111,8 +109,7 @@ void dorrie_act_raise_head(void) { void bhv_dorrie_update(void) { f32 boundsShift; - UNUSED s32 unused1; - UNUSED s32 unused2; + UNUSED u8 filler[8]; f32 maxOffsetY; if (!(o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) { diff --git a/src/game/behaviors/drawbridge.inc.c b/src/game/behaviors/drawbridge.inc.c index 0fd04905..6630b6b5 100644 --- a/src/game/behaviors/drawbridge.inc.c +++ b/src/game/behaviors/drawbridge.inc.c @@ -1,4 +1,4 @@ -// drawbridge.c.inc +// drawbridge.inc.c void bhv_lll_drawbridge_spawner_loop(void) { struct Object *drawbridge1, *drawbridge2; @@ -34,7 +34,7 @@ void bhv_lll_drawbridge_loop(void) { //! Because the global timer increments when the game is paused, pausing and unpausing // the game at regular intervals can leave the drawbridge raised indefinitely. - if (o->oTimer >= 51 && (globalTimer % 8) == 0) { + if (o->oTimer > 50 && (globalTimer % 8) == 0) { o->oAction = LLL_DRAWBRIDGE_ACT_LOWER; cur_obj_play_sound_2(SOUND_GENERAL_BOAT_TILT1); } @@ -45,7 +45,7 @@ void bhv_lll_drawbridge_loop(void) { //! Because the global timer increments when the game is paused, pausing and unpausing // the game at regular intervals can leave the drawbridge lowered indefinitely. - if (o->oTimer >= 51 && (globalTimer % 8) == 0) { + if (o->oTimer > 50 && (globalTimer % 8) == 0) { o->oAction = LLL_DRAWBRIDGE_ACT_RAISE; cur_obj_play_sound_2(SOUND_GENERAL_BOAT_TILT2); } diff --git a/src/game/behaviors/elevator.inc.c b/src/game/behaviors/elevator.inc.c index f9df6856..7d2ec042 100644 --- a/src/game/behaviors/elevator.inc.c +++ b/src/game/behaviors/elevator.inc.c @@ -1,4 +1,14 @@ -// elevator.c.inc +// elevator.inc.c + +static s16 sElevatorHeights[] = { + -51, 0, 0, + -461, 0, 0, + -512, 0, 0, + -2611, 0, 0, + -2360, 0, 0, + 214, 0, 0, + -50, 1945, 1, +}; void elevator_starting_shake(void) { cur_obj_play_sound_2(SOUND_GENERAL_QUIET_POUND1); @@ -9,56 +19,62 @@ void elevator_act_0(void) { o->oVelY = 0; if (o->oElevatorUnk100 == 2) { if (gMarioObject->platform == o) { - if (o->oPosY > o->oElevatorUnkFC) + if (o->oPosY > o->oElevatorUnkFC) { o->oAction = 2; - else + } else { o->oAction = 1; + } } } else if (gMarioObject->oPosY > o->oElevatorUnkFC || o->oElevatorUnk100 == 1) { o->oPosY = o->oElevatorUnkF8; - if (gMarioObject->platform == o) + if (gMarioObject->platform == o) { o->oAction = 2; + } } else { o->oPosY = o->oElevatorUnkF4; - if (gMarioObject->platform == o) + if (gMarioObject->platform == o) { o->oAction = 1; + } } } void elevator_act_1(void) { cur_obj_play_sound_1(SOUND_ENV_ELEVATOR1); - if (o->oTimer == 0 && cur_obj_is_mario_on_platform()) + if (o->oTimer == 0 && cur_obj_is_mario_on_platform()) { elevator_starting_shake(); + } approach_f32_signed(&o->oVelY, 10.0f, 2.0f); o->oPosY += o->oVelY; if (o->oPosY > o->oElevatorUnkF8) { o->oPosY = o->oElevatorUnkF8; - if (o->oElevatorUnk100 == 2 || o->oElevatorUnk100 == 1) + if (o->oElevatorUnk100 == 2 || o->oElevatorUnk100 == 1) { o->oAction = 3; - else if (gMarioObject->oPosY < o->oElevatorUnkFC) + } else if (gMarioObject->oPosY < o->oElevatorUnkFC) { o->oAction = 2; - else + } else { o->oAction = 3; + } } } -void elevator_act_2(void) // Pretty similar code to action 1 -{ +void elevator_act_2(void) { cur_obj_play_sound_1(SOUND_ENV_ELEVATOR1); - if (o->oTimer == 0 && cur_obj_is_mario_on_platform()) + if (o->oTimer == 0 && cur_obj_is_mario_on_platform()) { elevator_starting_shake(); + } approach_f32_signed(&o->oVelY, -10.0f, -2.0f); o->oPosY += o->oVelY; if (o->oPosY < o->oElevatorUnkF4) { o->oPosY = o->oElevatorUnkF4; - if (o->oElevatorUnk100 == 1) + if (o->oElevatorUnk100 == 1) { o->oAction = 4; - else if (o->oElevatorUnk100 == 2) + } else if (o->oElevatorUnk100 == 2) { o->oAction = 3; - else if (gMarioObject->oPosY > o->oElevatorUnkFC) + } else if (gMarioObject->oPosY > o->oElevatorUnkFC) { o->oAction = 1; - else + } else { o->oAction = 3; + } } } @@ -68,47 +84,44 @@ void elevator_act_4(void) { cur_obj_shake_screen(SHAKE_POS_SMALL); cur_obj_play_sound_2(SOUND_GENERAL_METAL_POUND); } - if (!mario_is_in_air_action() && !cur_obj_is_mario_on_platform()) + if (!mario_is_in_air_action() && !cur_obj_is_mario_on_platform()) { o->oAction = 1; + } } -void elevator_act_3(void) // nearly identical to action 2 -{ +void elevator_act_3(void) { o->oVelY = 0; if (o->oTimer == 0) { cur_obj_shake_screen(SHAKE_POS_SMALL); cur_obj_play_sound_2(SOUND_GENERAL_METAL_POUND); } - if (!mario_is_in_air_action() && !cur_obj_is_mario_on_platform()) + if (!mario_is_in_air_action() && !cur_obj_is_mario_on_platform()) { o->oAction = 0; + } } void bhv_elevator_init(void) { - s32 sp1C = D_8032F38C[o->oBehParams2ndByte * 3 + 2]; + s32 sp1C = sElevatorHeights[o->oBehParams2ndByte * 3 + 2]; if (sp1C == 0) { - o->oElevatorUnkF4 = D_8032F38C[o->oBehParams2ndByte * 3]; + o->oElevatorUnkF4 = sElevatorHeights[o->oBehParams2ndByte * 3]; o->oElevatorUnkF8 = o->oHomeY; o->oElevatorUnkFC = (o->oElevatorUnkF4 + o->oElevatorUnkF8) / 2; o->oElevatorUnk100 = cur_obj_has_behavior(bhvRrElevatorPlatform); } else { - o->oElevatorUnkF4 = D_8032F38C[o->oBehParams2ndByte * 3]; - o->oElevatorUnkF8 = D_8032F38C[o->oBehParams2ndByte * 3 + 1]; + o->oElevatorUnkF4 = sElevatorHeights[o->oBehParams2ndByte * 3]; + o->oElevatorUnkF8 = sElevatorHeights[o->oBehParams2ndByte * 3 + 1]; o->oElevatorUnkFC = (o->oElevatorUnkF4 + o->oElevatorUnkF8) / 2; o->oElevatorUnk100 = 2; } } -void (*sElevatorActions[])(void) = { elevator_act_0, elevator_act_1, elevator_act_2, elevator_act_3, - elevator_act_4 }; - -struct SpawnParticlesInfo D_8032F3CC = { 3, 20, MODEL_MIST, 20, 10, 5, 0, 0, 0, 30, 30.0f, 1.5f }; - -struct SpawnParticlesInfo D_8032F3E0 = { 0, 5, MODEL_SAND_DUST, 0, 0, 20, 20, 0, 252, 30, 5.0f, 2.0f }; - -s16 D_8032F3F4[] = { 2, -8, 1, 4 }; - -struct SpawnParticlesInfo D_8032F3FC = { 0, 5, MODEL_WHITE_PARTICLE_DL, 0, 0, 20, 20, 0, 252, 30, - 2.0f, 2.0f }; +void (*sElevatorActions[])(void) = { + elevator_act_0, + elevator_act_1, + elevator_act_2, + elevator_act_3, + elevator_act_4, +}; void bhv_elevator_loop(void) { cur_obj_call_action_function(sElevatorActions); diff --git a/src/game/behaviors/end_birds_1.inc.c b/src/game/behaviors/end_birds_1.inc.c index 532c2728..69889724 100644 --- a/src/game/behaviors/end_birds_1.inc.c +++ b/src/game/behaviors/end_birds_1.inc.c @@ -4,24 +4,28 @@ void bhv_end_birds_1_loop(void) { Vec3f sp34; UNUSED f32 sp30 = random_float(); - switch (gCurrentObject->oAction) { + switch (o->oAction) { case 0: cur_obj_scale(0.7f); - gCurrentObject->oIntroLakituUnk110 = -554.f; - gCurrentObject->oIntroLakituUnk10C = 3044.f; - gCurrentObject->oIntroLakituUnk108 = -1314.f; - gCurrentObject->oAction += 1; + o->oIntroLakituUnk110 = -554.0f; + o->oIntroLakituUnk10C = 3044.0f; + o->oIntroLakituUnk108 = -1314.0f; + o->oAction++; break; - case 1: - vec3f_set(sp34, gCurrentObject->oIntroLakituUnk110, gCurrentObject->oIntroLakituUnk10C, - gCurrentObject->oIntroLakituUnk108); - if (gCurrentObject->oTimer < 100) - obj_rotate_towards_point(gCurrentObject, sp34, 0, 0, 0x20, 0x20); - if ((gCurrentObject->oEndBirdUnk104 == 0.f) && (gCurrentObject->oTimer == 0)) + case 1: + vec3f_set(sp34, o->oIntroLakituUnk110, o->oIntroLakituUnk10C, + o->oIntroLakituUnk108); + + if (o->oTimer < 100) { + obj_rotate_towards_point(o, sp34, 0, 0, 0x20, 0x20); + } + if ((o->oEndBirdUnk104 == 0.0f) && (o->oTimer == 0)) { cur_obj_play_sound_2(SOUND_GENERAL_BIRDS_FLY_AWAY); - if (gCutsceneTimer == 0) - obj_mark_for_deletion(gCurrentObject); + } + if (gCutsceneTimer == 0) { + obj_mark_for_deletion(o); + } break; } diff --git a/src/game/behaviors/end_birds_2.inc.c b/src/game/behaviors/end_birds_2.inc.c index 9526448e..388a4781 100644 --- a/src/game/behaviors/end_birds_2.inc.c +++ b/src/game/behaviors/end_birds_2.inc.c @@ -2,28 +2,29 @@ void bhv_end_birds_2_loop(void) { Vec3f sp3C; - UNUSED f32 sp38; + UNUSED f32 sp38 = random_float(); f32 sp34; s16 sp32, sp30; - sp38 = random_float(); - gCurrentObject->oForwardVel = (random_float() * 10.f) + 25.f; + o->oForwardVel = (random_float() * 10.0f) + 25.0f; - switch (gCurrentObject->oAction) { + switch (o->oAction) { case 0: cur_obj_scale(0.7f); - gCurrentObject->oAction += 1; + o->oAction++; break; + case 1: vec3f_get_dist_and_angle(gCamera->pos, gCamera->focus, &sp34, &sp32, &sp30); sp30 += 0x1000; sp32 += 0; // nice work, Nintendo - vec3f_set_dist_and_angle(gCamera->pos, sp3C, 14000.f, sp32, sp30); - obj_rotate_towards_point(gCurrentObject, sp3C, 0, 0, 8, 8); + vec3f_set_dist_and_angle(gCamera->pos, sp3C, 14000.0f, sp32, sp30); + obj_rotate_towards_point(o, sp3C, 0, 0, 8, 8); - if ((gCurrentObject->oEndBirdUnk104 == 0.f) && (gCurrentObject->oTimer == 0)) + if ((o->oEndBirdUnk104 == 0.0f) && (o->oTimer == 0)) { cur_obj_play_sound_2(SOUND_GENERAL_BIRDS_FLY_AWAY); + } break; } diff --git a/src/game/behaviors/enemy_lakitu.inc.c b/src/game/behaviors/enemy_lakitu.inc.c index 056c3f13..b120d7dc 100644 --- a/src/game/behaviors/enemy_lakitu.inc.c +++ b/src/game/behaviors/enemy_lakitu.inc.c @@ -77,14 +77,14 @@ static void enemy_lakitu_update_speed_and_angle(void) { // Turn toward mario except right after throwing a spiny if (o->oEnemyLakituFaceForwardCountdown != 0) { - o->oEnemyLakituFaceForwardCountdown -= 1; + o->oEnemyLakituFaceForwardCountdown--; } else { obj_face_yaw_approach(o->oAngleToMario, 0x600); } // Change move angle toward mario faster when farther from mario turnSpeed = (s16)(distToMario * 2); - clamp_s16(&turnSpeed, 0xC8, 0xFA0); + clamp_s16(&turnSpeed, 200, 4000); cur_obj_rotate_yaw_toward(o->oAngleToMario, turnSpeed); } @@ -96,7 +96,7 @@ static void enemy_lakitu_sub_act_no_spiny(void) { cur_obj_init_animation_with_sound(1); if (o->oEnemyLakituSpinyCooldown != 0) { - o->oEnemyLakituSpinyCooldown -= 1; + o->oEnemyLakituSpinyCooldown--; } else if (o->oEnemyLakituNumSpinies < 3 && o->oDistanceToMario < 800.0f && abs_angle_diff(o->oAngleToMario, o->oFaceAngleYaw) < 0x4000) { struct Object *spiny = spawn_object(o, MODEL_SPINY_BALL, bhvSpiny); @@ -105,7 +105,7 @@ static void enemy_lakitu_sub_act_no_spiny(void) { spiny->oAction = SPINY_ACT_HELD_BY_LAKITU; obj_init_animation_with_sound(spiny, spiny_egg_seg5_anims_050157E4, 0); - o->oEnemyLakituNumSpinies += 1; + o->oEnemyLakituNumSpinies++; o->oSubAction = ENEMY_LAKITU_SUB_ACT_HOLD_SPINY; o->oEnemyLakituSpinyCooldown = 30; } @@ -120,7 +120,7 @@ static void enemy_lakitu_sub_act_hold_spiny(void) { cur_obj_init_anim_extend(3); if (o->oEnemyLakituSpinyCooldown != 0) { - o->oEnemyLakituSpinyCooldown -= 1; + o->oEnemyLakituSpinyCooldown--; } // TODO: Check if anything interesting happens if we bypass this with speed else if (o->oDistanceToMario > o->oDrawingDistance - 100.0f @@ -176,7 +176,7 @@ static void enemy_lakitu_act_main(void) { cur_obj_move_standard(78); // Die and drop held spiny when attacked by mario - if (obj_check_attacks(&sEnemyLakituHitbox, o->oAction)) { + if (obj_check_attacks(&sEnemyLakituHitbox, o->oAction) != 0) { // The spiny uses this as a signal to get thrown o->prevObj = NULL; } diff --git a/src/game/behaviors/exclamation_box.inc.c b/src/game/behaviors/exclamation_box.inc.c index 86486c35..bc664769 100644 --- a/src/game/behaviors/exclamation_box.inc.c +++ b/src/game/behaviors/exclamation_box.inc.c @@ -1,48 +1,59 @@ -// exclamation_box.c.inc +// exclamation_box.inc.c struct ObjectHitbox sExclamationBoxHitbox = { - /* interactType: */ INTERACT_BREAKABLE, - /* downOffset: */ 5, + /* interactType: */ INTERACT_BREAKABLE, + /* downOffset: */ 5, /* damageOrCoinValue: */ 0, - /* health: */ 1, - /* numLootCoins: */ 0, - /* radius: */ 40, - /* height: */ 30, - /* hurtboxRadius: */ 40, - /* hurtboxHeight: */ 30, + /* health: */ 1, + /* numLootCoins: */ 0, + /* radius: */ 40, + /* height: */ 30, + /* hurtboxRadius: */ 40, + /* hurtboxHeight: */ 30, }; -struct Struct802C0DF0 sExclamationBoxContents[] = { { 0, 0, 0, MODEL_MARIOS_WING_CAP, bhvWingCap }, - { 1, 0, 0, MODEL_MARIOS_METAL_CAP, bhvMetalCap }, - { 2, 0, 0, MODEL_MARIOS_CAP, bhvVanishCap }, - { 3, 0, 0, MODEL_KOOPA_SHELL, bhvKoopaShell }, - { 4, 0, 0, MODEL_YELLOW_COIN, - bhvSingleCoinGetsSpawned }, - { 5, 0, 0, MODEL_NONE, bhvThreeCoinsSpawn }, - { 6, 0, 0, MODEL_NONE, bhvTenCoinsSpawn }, - { 7, 0, 0, MODEL_1UP, bhv1upWalking }, - { 8, 0, 0, MODEL_STAR, bhvSpawnedStar }, - { 9, 0, 0, MODEL_1UP, bhv1upRunningAway }, - { 10, 0, 1, MODEL_STAR, bhvSpawnedStar }, - { 11, 0, 2, MODEL_STAR, bhvSpawnedStar }, - { 12, 0, 3, MODEL_STAR, bhvSpawnedStar }, - { 13, 0, 4, MODEL_STAR, bhvSpawnedStar }, - { 14, 0, 5, MODEL_STAR, bhvSpawnedStar }, - { 99, 0, 0, 0, NULL } }; +struct Struct802C0DF0 { + u8 unk0; + u8 unk1; + u8 unk2; + u8 model; + const BehaviorScript *behavior; +}; + +struct Struct802C0DF0 sExclamationBoxContents[] = { + { 0, 0, 0, MODEL_MARIOS_WING_CAP, bhvWingCap }, + { 1, 0, 0, MODEL_MARIOS_METAL_CAP, bhvMetalCap }, + { 2, 0, 0, MODEL_MARIOS_CAP, bhvVanishCap }, + { 3, 0, 0, MODEL_KOOPA_SHELL, bhvKoopaShell }, + { 4, 0, 0, MODEL_YELLOW_COIN, bhvSingleCoinGetsSpawned }, + { 5, 0, 0, MODEL_NONE, bhvThreeCoinsSpawn }, + { 6, 0, 0, MODEL_NONE, bhvTenCoinsSpawn }, + { 7, 0, 0, MODEL_1UP, bhv1upWalking }, + { 8, 0, 0, MODEL_STAR, bhvSpawnedStar }, + { 9, 0, 0, MODEL_1UP, bhv1upRunningAway }, + { 10, 0, 1, MODEL_STAR, bhvSpawnedStar }, + { 11, 0, 2, MODEL_STAR, bhvSpawnedStar }, + { 12, 0, 3, MODEL_STAR, bhvSpawnedStar }, + { 13, 0, 4, MODEL_STAR, bhvSpawnedStar }, + { 14, 0, 5, MODEL_STAR, bhvSpawnedStar }, + { 99, 0, 0, 0, NULL } +}; void bhv_rotating_exclamation_box_loop(void) { - if (o->parentObj->oAction != 1) + if (o->parentObj->oAction != 1) { obj_mark_for_deletion(o); + } } void exclamation_box_act_0(void) { if (o->oBehParams2ndByte < 3) { o->oAnimState = o->oBehParams2ndByte; - if ((save_file_get_flags() & D_8032F0C0[o->oBehParams2ndByte]) - || ((o->oBehParams >> 24) & 0xFF) != 0) + if ((save_file_get_flags() & sCapSaveFlags[o->oBehParams2ndByte]) + || ((o->oBehParams >> 24) & 0xFF)) { o->oAction = 2; - else + } else { o->oAction = 1; + } } else { o->oAnimState = 3; o->oAction = 2; @@ -55,8 +66,8 @@ void exclamation_box_act_1(void) { spawn_object(o, MODEL_EXCLAMATION_POINT, bhvRotatingExclamationMark); cur_obj_set_model(MODEL_EXCLAMATION_BOX_OUTLINE); } - if ((save_file_get_flags() & D_8032F0C0[o->oBehParams2ndByte]) - || ((o->oBehParams >> 24) & 0xFF) != 0) { + if ((save_file_get_flags() & sCapSaveFlags[o->oBehParams2ndByte]) + || ((o->oBehParams >> 24) & 0xFF)) { o->oAction = 2; cur_obj_set_model(MODEL_EXCLAMATION_BOX); } @@ -78,7 +89,7 @@ void exclamation_box_act_2(void) { o->oGravity = -8.0f; o->oFloorHeight = o->oPosY; o->oAction = 3; -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif } @@ -86,7 +97,7 @@ void exclamation_box_act_2(void) { } void exclamation_box_act_3(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; cur_obj_move_using_fvel_and_gravity(); if (o->oVelY < 0.0f) { o->oVelY = 0.0f; @@ -99,8 +110,9 @@ void exclamation_box_act_3(void) { o->header.gfx.scale[0] = o->oExclamationBoxUnkF4 * 2.0f; o->header.gfx.scale[1] = o->oExclamationBoxUnkF8 * 2.0f; o->header.gfx.scale[2] = o->oExclamationBoxUnkF4 * 2.0f; - if (o->oTimer == 7) + if (o->oTimer == 7) { o->oAction = 4; + } } void exclamation_box_spawn_contents(struct Struct802C0DF0 *a0, u8 a1) { @@ -113,8 +125,9 @@ void exclamation_box_spawn_contents(struct Struct802C0DF0 *a0, u8 a1) { sp1C->oForwardVel = 3.0f; sp1C->oMoveAngleYaw = gMarioObject->oMoveAngleYaw; o->oBehParams |= a0->unk2 << 24; - if (a0->model == 122) - o->oFlags |= 0x4000; + if (a0->model == MODEL_STAR) { + o->oFlags |= OBJ_FLAG_PERSISTENT_RESPAWN; + } break; } a0++; @@ -124,23 +137,30 @@ void exclamation_box_spawn_contents(struct Struct802C0DF0 *a0, u8 a1) { void exclamation_box_act_4(void) { exclamation_box_spawn_contents(sExclamationBoxContents, o->oBehParams2ndByte); spawn_mist_particles_variable(0, 0, 46.0f); - spawn_triangle_break_particles(20, 139, 0.3f, o->oAnimState); + spawn_triangle_break_particles(20, MODEL_CARTOON_STAR, 0.3f, o->oAnimState); create_sound_spawner(SOUND_GENERAL_BREAK_BOX); if (o->oBehParams2ndByte < 3) { o->oAction = 5; cur_obj_hide(); - } else + } else { obj_mark_for_deletion(o); + } } void exclamation_box_act_5(void) { - if (o->oTimer > 300) + if (o->oTimer > 300) { o->oAction = 2; + } } -void (*sExclamationBoxActions[])(void) = { exclamation_box_act_0, exclamation_box_act_1, - exclamation_box_act_2, exclamation_box_act_3, - exclamation_box_act_4, exclamation_box_act_5 }; +void (*sExclamationBoxActions[])(void) = { + exclamation_box_act_0, + exclamation_box_act_1, + exclamation_box_act_2, + exclamation_box_act_3, + exclamation_box_act_4, + exclamation_box_act_5, +}; void bhv_exclamation_box_loop(void) { cur_obj_scale(2.0f); diff --git a/src/game/behaviors/explosion.inc.c b/src/game/behaviors/explosion.inc.c index 75428d56..9122499c 100644 --- a/src/game/behaviors/explosion.inc.c +++ b/src/game/behaviors/explosion.inc.c @@ -1,4 +1,4 @@ -// explosion.c.inc +// explosion.inc.c void bhv_explosion_init(void) { create_sound_spawner(SOUND_GENERAL2_BOBOMB_EXPLOSION); @@ -12,10 +12,12 @@ void bhv_explosion_loop(void) { if (o->oTimer == 9) { if (find_water_level(o->oPosX, o->oPosZ) > o->oPosY) { - for (i = 0; i < 40; i++) + for (i = 0; i < 40; i++) { spawn_object(o, MODEL_WHITE_PARTICLE_SMALL, bhvBobombExplosionBubble); - } else + } + } else { spawn_object(o, MODEL_SMOKE, bhvBobombBullyDeathSmoke); + } o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } diff --git a/src/game/behaviors/express_elevator.inc.c b/src/game/behaviors/express_elevator.inc.c index f3536384..eaadc393 100644 --- a/src/game/behaviors/express_elevator.inc.c +++ b/src/game/behaviors/express_elevator.inc.c @@ -1,19 +1,22 @@ -// express_elevator.c.inc +// express_elevator.inc.c void bhv_wdw_express_elevator_loop(void) { o->oVelY = 0.0f; if (o->oAction == 0) { - if (cur_obj_is_mario_on_platform()) + if (cur_obj_is_mario_on_platform()) { o->oAction++; + } } else if (o->oAction == 1) { o->oVelY = -20.0f; o->oPosY += o->oVelY; cur_obj_play_sound_1(SOUND_ENV_ELEVATOR4); - if (o->oTimer > 132) + if (o->oTimer > 132) { o->oAction++; + } } else if (o->oAction == 2) { - if (o->oTimer > 110) + if (o->oTimer > 110) { o->oAction++; + } } else if (o->oAction == 3) { o->oVelY = 10.0f; o->oPosY += o->oVelY; @@ -22,6 +25,7 @@ void bhv_wdw_express_elevator_loop(void) { o->oPosY = o->oHomeY; o->oAction++; } - } else if (!cur_obj_is_mario_on_platform()) + } else if (!cur_obj_is_mario_on_platform()) { o->oAction = 0; + } } diff --git a/src/game/behaviors/eyerok.inc.c b/src/game/behaviors/eyerok.inc.c index 473d7475..89799afd 100644 --- a/src/game/behaviors/eyerok.inc.c +++ b/src/game/behaviors/eyerok.inc.c @@ -1,3 +1,5 @@ +// eyerok.inc.c + struct ObjectHitbox sEyerokHitbox = { /* interactType: */ INTERACT_BOUNCE_TOP, /* downOffset: */ 0, @@ -21,9 +23,8 @@ static s32 eyerok_check_mario_relative_z(s32 arg0) { } static void eyerok_spawn_hand(s16 side, s32 model, const BehaviorScript *behavior) { - struct Object *hand; - - hand = spawn_object_relative_with_scale(side, -500 * side, 0, 300, 1.5f, o, model, behavior); + struct Object *hand = spawn_object_relative_with_scale(side, -500 * side, 0, 300, 1.5f, + o, model, behavior); if (hand != NULL) { hand->oFaceAngleYaw -= 0x4000 * side; } @@ -44,17 +45,17 @@ static void eyerok_boss_act_wake_up(void) { if (o->oTimer > 5) { if (o->oSubAction == 0) { seq_player_lower_volume(SEQ_PLAYER_LEVEL, 60, 40); - o->oSubAction += 1; + o->oSubAction++; } - if (o->oEyerokBossUnk110 == 0.0f && mario_ready_to_speak() != 0) { + if (o->oEyerokBossUnk110 == 0.0f && mario_ready_to_speak()) { o->oAction = EYEROK_BOSS_ACT_SHOW_INTRO_TEXT; } else if (o->oTimer > 150) { if (approach_f32_ptr(&o->oEyerokBossUnk110, 0.0f, 10.0f)) { o->oTimer = 0; } } else if (o->oTimer > 90) { - approach_f32_ptr(&o->oEyerokBossUnk110, 300.f, 10.0f); + approach_f32_ptr(&o->oEyerokBossUnk110, 300.0f, 10.0f); } } } else { @@ -63,7 +64,7 @@ static void eyerok_boss_act_wake_up(void) { } static void eyerok_boss_act_show_intro_text(void) { - if (cur_obj_update_dialog_with_cutscene(2, 0, CUTSCENE_DIALOG, DIALOG_117)) { + if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, DIALOG_FLAG_NONE, CUTSCENE_DIALOG, DIALOG_117)) { o->oAction = EYEROK_BOSS_ACT_FIGHT; } } @@ -75,22 +76,22 @@ static void eyerok_boss_act_fight(void) { if (o->oEyerokBossUnk104 != 0) { if (approach_f32_ptr(&o->oEyerokBossUnk110, 1.0f, 0.02f)) { if (o->oEyerokBossUnk104 < 0) { - if (eyerok_check_mario_relative_z(400) == 0 && ++o->oEyerokBossUnk104 == 0) { + if (!eyerok_check_mario_relative_z(400) && ++o->oEyerokBossUnk104 == 0) { o->oEyerokBossUnk104 = 1; } } else { - o->oEyerokBossUnk104 -= 1; + o->oEyerokBossUnk104--; } if (o->oEyerokBossUnk104 != 0 && o->oEyerokBossUnk104 != 1) { - o->oEyerokBossUnkFC += 1; + o->oEyerokBossUnkFC++; if ((o->oEyerokBossActiveHand = o->oEyerokBossUnkFC & 0x1) == 0) { o->oEyerokBossActiveHand = -1; } } } } else { - o->oEyerokBossUnkFC += 1; + o->oEyerokBossUnkFC++; if (eyerok_check_mario_relative_z(400)) { o->oEyerokBossUnk104 = -8; @@ -117,10 +118,10 @@ static void eyerok_boss_act_fight(void) { static void eyerok_boss_act_die(void) { if (o->oTimer == 60) { - if (cur_obj_update_dialog_with_cutscene(2, 0, CUTSCENE_DIALOG, DIALOG_118)) { + if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, DIALOG_FLAG_NONE, CUTSCENE_DIALOG, DIALOG_118)) { spawn_default_star(0.0f, -900.0f, -3700.0f); } else { - o->oTimer -= 1; + o->oTimer--; } } else if (o->oTimer > 120) { stop_background_music(SEQUENCE_ARGS(4, SEQ_EVENT_BOSS)); @@ -156,7 +157,7 @@ static s32 eyerok_hand_check_attacked(void) { o->oAction = EYEROK_HAND_ACT_ATTACKED; o->oVelY = 30.0f; } else { - o->parentObj->oEyerokBossNumHands -= 1; + o->parentObj->oEyerokBossNumHands--; o->oAction = EYEROK_HAND_ACT_DIE; o->oVelY = 50.0f; } @@ -183,7 +184,7 @@ static void eyerok_hand_act_sleep(void) { if (o->parentObj->oAction != EYEROK_BOSS_ACT_SLEEP && ++o->oEyerokHandWakeUpTimer > -3 * o->oBehParams2ndByte) { if (cur_obj_check_if_near_animation_end()) { - o->parentObj->oEyerokBossNumHands += 1; + o->parentObj->oEyerokBossNumHands++; o->oAction = EYEROK_HAND_ACT_IDLE; o->collisionData = segmented_to_virtual(&ssl_seg7_collision_07028274); } else { @@ -216,7 +217,7 @@ static void eyerok_hand_act_idle(void) { } } else if (o->parentObj->oEyerokBossUnk1AC == 0 && o->parentObj->oEyerokBossActiveHand != 0) { if (o->parentObj->oEyerokBossActiveHand == o->oBehParams2ndByte) { - if (eyerok_check_mario_relative_z(400) != 0 || random_u16() % 2 != 0) { + if (eyerok_check_mario_relative_z(400) || random_u16() % 2 != 0) { o->oAction = EYEROK_HAND_ACT_TARGET_MARIO; o->oMoveAngleYaw = o->oAngleToMario; o->oGravity = 0.0f; @@ -262,23 +263,21 @@ static void eyerok_hand_act_open(void) { } static void eyerok_hand_act_show_eye(void) { - UNUSED s16 val06; - cur_obj_init_animation_with_sound(5); cur_obj_play_sound_at_anim_range(0, 0, SOUND_OBJ_EYEROK_SHOW_EYE); if (!eyerok_hand_check_attacked()) { if (o->parentObj->oEyerokBossActiveHand == 0) { if (o->oAnimState < 3) { - o->oAnimState += 1; + o->oAnimState++; } else if (cur_obj_check_if_near_animation_end()) { - val06 = (s16)(o->oAngleToMario - o->oFaceAngleYaw) * o->oBehParams2ndByte; + UNUSED s16 val06 = (s16)(o->oAngleToMario - o->oFaceAngleYaw) * o->oBehParams2ndByte; o->oAction = EYEROK_HAND_ACT_CLOSE; } } else { if (o->oEyerokHandUnk100--) { if (o->oEyerokHandUnkFC != 0) { - o->oEyerokHandUnkFC -= 1; + o->oEyerokHandUnkFC--; } o->oAnimState = D_80331BA4[o->oEyerokHandUnkFC]; } else { @@ -373,7 +372,7 @@ static void eyerok_hand_act_retreat(void) { } static void eyerok_hand_act_target_mario(void) { - if (eyerok_check_mario_relative_z(400) != 0 || o->oPosZ - gMarioObject->oPosZ > 0.0f + if (eyerok_check_mario_relative_z(400) || o->oPosZ - gMarioObject->oPosZ > 0.0f || o->oPosZ - o->parentObj->oPosZ > 1700.0f || absf(o->oPosX - o->parentObj->oPosX) > 900.0f || (o->oMoveFlags & OBJ_MOVE_HIT_WALL)) { o->oForwardVel = 0.0f; @@ -388,15 +387,13 @@ static void eyerok_hand_act_target_mario(void) { } static void eyerok_hand_act_smash(void) { - s16 sp1E; - if (o->oTimer > 20) { if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) { if (o->oGravity < -4.0f) { eyerok_hand_pound_ground(); o->oGravity = -4.0f; } else { - sp1E = abs_angle_diff(o->oFaceAngleYaw, o->oAngleToMario); + s16 sp1E = abs_angle_diff(o->oFaceAngleYaw, o->oAngleToMario); if (o->oDistanceToMario < 300.0f && sp1E > 0x2000 && sp1E < 0x6000) { o->oAction = EYEROK_HAND_ACT_FIST_SWEEP; if ((s16)(o->oFaceAngleYaw - o->oAngleToMario) < 0) { @@ -441,15 +438,13 @@ static void eyerok_hand_act_fist_sweep(void) { } static void eyerok_hand_act_begin_double_pound(void) { - f32 sp4; - if (o->parentObj->oEyerokBossUnk104 < 0 || o->parentObj->oEyerokBossActiveHand == o->oBehParams2ndByte) { o->oAction = EYEROK_HAND_ACT_DOUBLE_POUND; o->oMoveAngleYaw = (s32)(o->oFaceAngleYaw - 0x4000 * o->parentObj->oEyerokBossUnk108); } else { - sp4 = o->parentObj->oPosX + 400.0f * o->parentObj->oEyerokBossUnk108 - - 180.0f * o->oBehParams2ndByte; + f32 sp4 = o->parentObj->oPosX + 400.0f * o->parentObj->oEyerokBossUnk108 + - 180.0f * o->oBehParams2ndByte; o->oPosX = o->oHomeX + (sp4 - o->oHomeX) * o->parentObj->oEyerokBossUnk110; o->oPosY = o->oHomeY + 300.0f * o->parentObj->oEyerokBossUnk110; diff --git a/src/game/behaviors/falling_pillar.inc.c b/src/game/behaviors/falling_pillar.inc.c index 5c53b283..6d8fe380 100644 --- a/src/game/behaviors/falling_pillar.inc.c +++ b/src/game/behaviors/falling_pillar.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for the falling pillars inside the underwater cave area of * Jolly Roger Bay. @@ -42,13 +43,10 @@ void bhv_falling_pillar_spawn_hitboxes(void) { * Mario. */ s16 bhv_falling_pillar_calculate_angle_in_front_of_mario(void) { - f32 targetX; - f32 targetZ; - // Calculate target to be 500 units in front of Mario in // the direction he is facing (angle[1] is yaw). - targetX = sins(gMarioObject->header.gfx.angle[1]) * 500.0f + gMarioObject->header.gfx.pos[0]; - targetZ = coss(gMarioObject->header.gfx.angle[1]) * 500.0f + gMarioObject->header.gfx.pos[2]; + f32 targetX = sins(gMarioObject->header.gfx.angle[1]) * 500.0f + gMarioObject->header.gfx.pos[0]; + f32 targetZ = coss(gMarioObject->header.gfx.angle[1]) * 500.0f + gMarioObject->header.gfx.pos[2]; // Calculate the angle to the target from the pillar's current location. return atan2s(targetZ - o->oPosZ, targetX - o->oPosX); @@ -59,6 +57,7 @@ s16 bhv_falling_pillar_calculate_angle_in_front_of_mario(void) { */ void bhv_falling_pillar_loop(void) { s16 angleInFrontOfMario; + switch (o->oAction) { case FALLING_PILLAR_ACT_IDLE: // When Mario is within 1300 units of distance... @@ -86,8 +85,9 @@ void bhv_falling_pillar_loop(void) { o->oFaceAngleYaw = approach_s16_symmetric(o->oFaceAngleYaw, angleInFrontOfMario, 0x400); // After 10 ticks, start falling. - if (o->oTimer > 10) + if (o->oTimer > 10) { o->oAction = FALLING_PILLAR_ACT_FALLING; + } break; case FALLING_PILLAR_ACT_FALLING: @@ -139,6 +139,7 @@ void bhv_falling_pillar_hitbox_loop(void) { obj_set_hitbox(o, &sFallingPillarHitbox); // When the pillar goes inactive, the hitboxes also go inactive. - if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) + if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } } diff --git a/src/game/behaviors/falling_rising_platform.inc.c b/src/game/behaviors/falling_rising_platform.inc.c index 4bd7ecd5..38dd7192 100644 --- a/src/game/behaviors/falling_rising_platform.inc.c +++ b/src/game/behaviors/falling_rising_platform.inc.c @@ -1,15 +1,14 @@ -// falling_rising_platform.c.inc +// falling_rising_platform.inc.c void bhv_squishable_platform_loop(void) { - o->header.gfx.scale[1] = (sins(o->oPlatformTimer) + 1.0) * 0.3 + 0.4; - o->oPlatformTimer += 0x80; + o->header.gfx.scale[1] = (sins(o->oBitfsPlatformTimer) + 1.0) * 0.3 + 0.4; + o->oBitfsPlatformTimer += 0x80; } void bhv_bitfs_sinking_platform_loop(void) { - o->oPosY -= - sins(o->oPlatformTimer) - * 0.58; //! f32 double conversion error accumulates on Wii VC causing the platform to rise up - o->oPlatformTimer += 0x100; + //! f32 double conversion error accumulates on Wii VC causing the platform to rise up + o->oPosY -= sins(o->oBitfsPlatformTimer) * 0.58; + o->oBitfsPlatformTimer += 0x100; } // TODO: Named incorrectly. fix @@ -19,10 +18,13 @@ void bhv_ddd_moving_pole_loop(void) { void bhv_bitfs_sinking_cage_platform_loop(void) { if (o->oBehParams2ndByte != 0) { - if (o->oTimer == 0) + if (o->oTimer == 0) { o->oPosY -= 300.0f; - o->oPosY += sins(o->oPlatformTimer) * 7.0f; - } else - o->oPosY -= sins(o->oPlatformTimer) * 3.0f; - o->oPlatformTimer += 0x100; + } + o->oPosY += sins(o->oBitfsPlatformTimer) * 7.0f; + } else { + o->oPosY -= sins(o->oBitfsPlatformTimer) * 3.0f; + } + + o->oBitfsPlatformTimer += 0x100; } diff --git a/src/game/behaviors/ferris_wheel.inc.c b/src/game/behaviors/ferris_wheel.inc.c index 5eb12617..2fdaf047 100644 --- a/src/game/behaviors/ferris_wheel.inc.c +++ b/src/game/behaviors/ferris_wheel.inc.c @@ -9,8 +9,8 @@ * Properties for the ferris wheel axle and platforms. */ struct FerrisWheelProperties { - void const *axleCollision; - void const *platformCollision; + Collision const *axleCollision; + Collision const *platformCollision; s16 platformModel; }; @@ -31,7 +31,8 @@ void bhv_ferris_wheel_axle_init(void) { struct Object *platform; s32 i; - o->collisionData = segmented_to_virtual(sFerrisWheelProperties[o->oBehParams2ndByte].axleCollision); + o->collisionData = + segmented_to_virtual(sFerrisWheelProperties[o->oBehParams2ndByte].axleCollision); for (i = 0; i < 4; i++) { platform = spawn_object_relative(i, 0, 0, 0, o, diff --git a/src/game/behaviors/fire_piranha_plant.inc.c b/src/game/behaviors/fire_piranha_plant.inc.c index a6d867b2..be1ea9cb 100644 --- a/src/game/behaviors/fire_piranha_plant.inc.c +++ b/src/game/behaviors/fire_piranha_plant.inc.c @@ -1,3 +1,5 @@ +// fire_piranha_plant.inc.c + struct ObjectHitbox sFirePiranhaPlantHitbox = { /* interactType: */ INTERACT_BOUNCE_TOP, /* downOffset: */ 0, @@ -35,7 +37,7 @@ void bhv_fire_piranha_plant_init(void) { obj_set_hitbox(o, &sFirePiranhaPlantHitbox); if ((u16)(o->oBehParams >> 16) != 0) { - o->oFlags |= 0x00004000; + o->oFlags |= OBJ_FLAG_PERSISTENT_RESPAWN; o->oHealth = 1; if (o->oBehParams & 0x0000FF00) { @@ -44,6 +46,7 @@ void bhv_fire_piranha_plant_init(void) { o->oNumLootCoins = 2; } } + sNumActiveFirePiranhaPlants = sNumKilledFirePiranhaPlants = 0; } @@ -52,16 +55,16 @@ static void fire_piranha_plant_act_hide(void) { o->oMoveAngleYaw += (s32) o->oFirePiranhaPlantDeathSpinVel; approach_f32_ptr(&o->oFirePiranhaPlantDeathSpinVel, 0.0f, 200.0f); - if (cur_obj_check_if_near_animation_end()) { - if (--o->oFirePiranhaPlantDeathSpinTimer == 0) { - cur_obj_play_sound_2(SOUND_OBJ_ENEMY_DEFEAT_SHRINK); - } + if (cur_obj_check_if_near_animation_end() + && --o->oFirePiranhaPlantDeathSpinTimer == 0) { + cur_obj_play_sound_2(SOUND_OBJ_ENEMY_DEFEAT_SHRINK); } } else if (approach_f32_ptr(&o->oFirePiranhaPlantScale, 0.0f, 0.04f * o->oFirePiranhaPlantNeutralScale)) { cur_obj_become_intangible(); + if (o->oFirePiranhaPlantActive) { - sNumActiveFirePiranhaPlants -= 1; + sNumActiveFirePiranhaPlants--; o->oFirePiranhaPlantActive = FALSE; if ((u16)(o->oBehParams >> 16) != 0 && o->oHealth == 0) { @@ -72,12 +75,12 @@ static void fire_piranha_plant_act_hide(void) { obj_die_if_health_non_positive(); set_object_respawn_info_bits(o, 1); } - } else if (sNumActiveFirePiranhaPlants < 2 && o->oTimer > 100 && o->oDistanceToMario > 100.0f - && o->oDistanceToMario < 800.0f) { + } else if (sNumActiveFirePiranhaPlants < 2 && o->oTimer > 100 + && o->oDistanceToMario > 100.0f && o->oDistanceToMario < 800.0f) { cur_obj_play_sound_2(SOUND_OBJ_PIRANHA_PLANT_APPEAR); o->oFirePiranhaPlantActive = TRUE; - sNumActiveFirePiranhaPlants += 1; + sNumActiveFirePiranhaPlants++; cur_obj_unhide(); o->oAction = FIRE_PIRANHA_PLANT_ACT_GROW; @@ -101,16 +104,12 @@ static void fire_piranha_plant_act_grow(void) { cur_obj_init_animation_with_sound(0); } else if (o->oTimer < 50) { cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x400); - } else { // TODO: Check if we can put these conditionals on same line - if (obj_is_rendering_enabled()) { - if (cur_obj_check_anim_frame(56)) { - cur_obj_play_sound_2(SOUND_OBJ_FLAME_BLOWN); - obj_spit_fire(0, (s32)(30.0f * o->oFirePiranhaPlantNeutralScale), - (s32)(140.0f * o->oFirePiranhaPlantNeutralScale), - 2.5f * o->oFirePiranhaPlantNeutralScale, MODEL_RED_FLAME_SHADOW, - 20.0f, 15.0f, 0x1000); - } - } + } else if (obj_is_rendering_enabled() && cur_obj_check_anim_frame(56)) { + cur_obj_play_sound_2(SOUND_OBJ_FLAME_BLOWN); + obj_spit_fire(0, (s32)(30.0f * o->oFirePiranhaPlantNeutralScale), + (s32)(140.0f * o->oFirePiranhaPlantNeutralScale), + 2.5f * o->oFirePiranhaPlantNeutralScale, MODEL_RED_FLAME_SHADOW, + 20.0f, 15.0f, 0x1000); } } else if (o->oFirePiranhaPlantScale > o->oFirePiranhaPlantNeutralScale / 2) { cur_obj_become_tangible(); @@ -129,10 +128,10 @@ void bhv_fire_piranha_plant_update(void) { break; } - if (obj_check_attacks(&sFirePiranhaPlantHitbox, o->oAction)) { + if (obj_check_attacks(&sFirePiranhaPlantHitbox, o->oAction) != 0) { if (--o->oHealth < 0) { if (o->oFirePiranhaPlantActive) { - sNumActiveFirePiranhaPlants -= 1; + sNumActiveFirePiranhaPlants--; } } else { cur_obj_init_animation_with_sound(2); diff --git a/src/game/behaviors/fire_spitter.inc.c b/src/game/behaviors/fire_spitter.inc.c index 2a59a803..ce6e5255 100644 --- a/src/game/behaviors/fire_spitter.inc.c +++ b/src/game/behaviors/fire_spitter.inc.c @@ -1,6 +1,8 @@ +// fire_spitter.inc.c static void fire_spitter_act_idle(void) { approach_f32_ptr(&o->header.gfx.scale[0], 0.2f, 0.002f); + if (o->oTimer > 150 && o->oDistanceToMario < 800.0f && !(o->oMoveFlags & OBJ_MOVE_MASK_IN_WATER)) { o->oAction = FIRE_SPITTER_ACT_SPIT_FIRE; o->oFireSpitterScaleVel = 0.05f; @@ -16,6 +18,7 @@ static void fire_spitter_act_spit_fire(void) { // starting moving scale by 0.05 each frame toward 0.1. The first time // it becomes below 0.15 during this latter portion, shoot fire. scaleStatus = obj_grow_then_shrink(&o->oFireSpitterScaleVel, 0.15f, 0.1f); + if (scaleStatus != 0) { if (scaleStatus < 0) { o->oAction = FIRE_SPITTER_ACT_IDLE; diff --git a/src/game/behaviors/fish.inc.c b/src/game/behaviors/fish.inc.c index 33cc6028..7ef29699 100644 --- a/src/game/behaviors/fish.inc.c +++ b/src/game/behaviors/fish.inc.c @@ -1,3 +1,4 @@ + /** * @file fish.inc.c * Implements behaviour and spawning for fish located in the Secret Aquarium and other levels. @@ -13,10 +14,8 @@ static void fish_spawner_act_spawn(void) { s16 model; f32 minDistToMario; const struct Animation * const *fishAnimation; - struct Object *fishObject; switch (o->oBehParams2ndByte) { - // Cases need to be on one line to match with and without optimizations. case FISH_SPAWNER_BP_MANY_BLUE: model = MODEL_FISH; schoolQuantity = 20; minDistToMario = 1500.0f; fishAnimation = blue_fish_seg3_anims_0301C2B0; @@ -35,13 +34,12 @@ static void fish_spawner_act_spawn(void) { break; } - // Spawn and animate the schoolQuantity of fish if Mario enters render distance // or the stage is Secret Aquarium. // Fish moves randomly within a range of 700.0f. if (o->oDistanceToMario < minDistToMario || gCurrLevelNum == LEVEL_SA) { for (i = 0; i < schoolQuantity; i++) { - fishObject = spawn_object(o, model, bhvFish); + struct Object *fishObject = spawn_object(o, model, bhvFish); fishObject->oBehParams2ndByte = o->oBehParams2ndByte; obj_init_animation_with_sound(fishObject, fishAnimation, 0); obj_translate_xyz_random(fishObject, 700.0f); @@ -68,7 +66,9 @@ static void fish_spawner_act_respawn(void) { } static void (*sFishSpawnerActions[])(void) = { - fish_spawner_act_spawn, fish_spawner_act_idle, fish_spawner_act_respawn, + fish_spawner_act_spawn, + fish_spawner_act_idle, + fish_spawner_act_respawn, }; void bhv_fish_spawner_loop(void) { @@ -122,7 +122,7 @@ static void fish_act_roam(void) { } o->oFishGoalY = gMarioObject->oPosY + o->oFishHeightOffset; - + // Rotate the fish towards Mario. cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x400); @@ -156,6 +156,7 @@ static void fish_act_roam(void) { static void fish_act_flee(void) { f32 fishY = o->oPosY - gMarioObject->oPosY; UNUSED s32 distance; + o->oFishGoalY = gMarioObject->oPosY + o->oFishHeightOffset; // Initialize some variables when the flee action first starts. @@ -163,12 +164,15 @@ static void fish_act_flee(void) { o->oFishActiveDistance = random_float() * 300.0f; o->oFishYawVel = random_float() * 1024.0f + 1024.0f; o->oFishGoalVel = random_float() * 4.0f + 8.0f + 5.0f; + if (o->oDistanceToMario < 600.0f) { distance = 1; } else { distance = (s32)(1.0 / (o->oDistanceToMario / 600.0)); } + distance *= 127; + cur_obj_play_sound_2(SOUND_GENERAL_MOVING_WATER); } @@ -183,6 +187,7 @@ static void fish_act_flee(void) { if (o->oForwardVel < o->oFishGoalVel) { o->oForwardVel = o->oForwardVel + 0.5; } + o->oFishGoalY = gMarioObject->oPosY + o->oFishHeightOffset; // Rotate fish away from Mario. @@ -198,7 +203,7 @@ static void fish_act_flee(void) { } else { fish_vertical_roam(4); } - + // Don't let the fish leave the water vertically. } else { o->oPosY = o->oFishWaterLevel - 50.0f; @@ -225,15 +230,16 @@ static void fish_act_init(void) { } static void (*sFishActions[])(void) = { - fish_act_init, fish_act_roam, fish_act_flee, + fish_act_init, + fish_act_roam, + fish_act_flee, }; /** * Main loop for fish */ -void bhv_fish_loop(void) -{ - UNUSED s32 unused[4]; +void bhv_fish_loop(void) { + UNUSED u8 filler[16]; cur_obj_scale(1.0f); // oFishWaterLevel tracks if a fish has roamed out of water. diff --git a/src/game/behaviors/fishing_boo.inc.c b/src/game/behaviors/fishing_boo.inc.c index 12189464..dffe8d69 100644 --- a/src/game/behaviors/fishing_boo.inc.c +++ b/src/game/behaviors/fishing_boo.inc.c @@ -1,4 +1,4 @@ -// fishing_boo.c.inc +// fishing_boo.inc.c // Unused behavior file for the Fishing Boo enemy. // The fire circles around mario and would make it @@ -10,6 +10,7 @@ void bhv_beta_moving_flames_spawn_loop(void) { o->oDistanceToMario = lateral_dist_between_objects(o, gMarioObject); o->oPosY -= 100.0f; + switch (o->oAction) { case 0: case 1: @@ -32,6 +33,7 @@ void bhv_beta_moving_flames_spawn_loop(void) { void bhv_beta_moving_flames_loop(void) { cur_obj_scale(5.0f); + o->oForwardVel = sins(o->oMovingFlameTimer) * 70.0f; o->oMovingFlameTimer += 0x800; } diff --git a/src/game/behaviors/flame.inc.c b/src/game/behaviors/flame.inc.c index 2508ee55..801b1fa5 100644 --- a/src/game/behaviors/flame.inc.c +++ b/src/game/behaviors/flame.inc.c @@ -6,6 +6,7 @@ void bhv_small_piranha_flame_loop(void) { obj_mark_for_deletion(o); } else { f32 rnd = random_float() - 0.5f; + o->header.gfx.scale[1] = o->header.gfx.scale[2] * (1.0f + 0.7f * rnd); o->header.gfx.scale[0] = o->header.gfx.scale[2] * (0.9f - 0.5f * rnd); @@ -13,6 +14,7 @@ void bhv_small_piranha_flame_loop(void) { } } else { cur_obj_update_floor_and_walls(); + if (approach_f32_ptr(&o->oSmallPiranhaFlameStartSpeed, o->oSmallPiranhaFlameEndSpeed, 0.6f)) { cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x200); } @@ -32,7 +34,8 @@ void bhv_small_piranha_flame_loop(void) { obj_check_attacks(&sPiranhaPlantFireHitbox, o->oAction); o->oSmallPiranhaFlameSpeed += o->oSmallPiranhaFlameStartSpeed; - if (o->oSmallPiranhaFlameSpeed > 1500.0f || (o->oMoveFlags & (OBJ_MOVE_HIT_WALL | OBJ_MOVE_MASK_IN_WATER))) { + if (o->oSmallPiranhaFlameSpeed > 1500.0f + || (o->oMoveFlags & (OBJ_MOVE_HIT_WALL | OBJ_MOVE_MASK_IN_WATER))) { obj_die_if_health_non_positive(); } } diff --git a/src/game/behaviors/flame_mario.inc.c b/src/game/behaviors/flame_mario.inc.c index 52e4bae6..c19da1e8 100644 --- a/src/game/behaviors/flame_mario.inc.c +++ b/src/game/behaviors/flame_mario.inc.c @@ -1,4 +1,4 @@ -// flame_mario.c.inc +// flame_mario.inc.c void bhv_black_smoke_upward_loop(void) { spawn_object_with_scale(o, MODEL_BURN_SMOKE, bhvBlackSmokeBowser, o->header.gfx.scale[0]); @@ -8,9 +8,11 @@ void bhv_black_smoke_bowser_loop(void) { if (o->oTimer == 0) { o->oForwardVel = random_float() * 2 + 0.5; o->oMoveAngleYaw = random_u16(); - o->oVelY = 8; + o->oVelY = 8.0f; + o->oBlackSmokeBowserUnkF4 = o->header.gfx.scale[0]; } + o->oMoveAngleYaw += o->oAngleVelYaw; o->oPosY += o->oVelY; } @@ -18,23 +20,30 @@ void bhv_black_smoke_bowser_loop(void) { void bhv_black_smoke_mario_loop(void) { if (o->oTimer == 0) { cur_obj_set_pos_relative(gMarioObject, 0, 0, -30.0f); + o->oForwardVel = random_float() * 2 + 0.5; o->oMoveAngleYaw = (gMarioObject->oMoveAngleYaw + 0x7000) + random_float() * 8192.0f; - o->oVelY = 8; + o->oVelY = 8.0f; } + o->oMoveAngleYaw += o->oAngleVelYaw; o->oPosY += o->oVelY; } void bhv_flame_mario_loop(void) { cur_obj_scale(2.0f); - if (o->oTimer != 0) - if (o->oTimer & 1) + + if (o->oTimer != 0) { + if (o->oTimer & 1) { spawn_object(o, MODEL_BURN_SMOKE, bhvBlackSmokeMario); + } + } + gMarioObject->prevObj = o; // weird? obj_set_parent_relative_pos(o, 40, -120, 0); - if (!(gMarioObject->oMarioParticleFlags & 0x800)) { - o->parentObj->oActiveParticleFlags &= ~0x800; + + if (!(gMarioObject->oMarioParticleFlags & ACTIVE_PARTICLE_FIRE)) { + o->parentObj->oActiveParticleFlags &= ~ACTIVE_PARTICLE_FIRE; obj_mark_for_deletion(o); gMarioObject->prevObj = NULL; } diff --git a/src/game/behaviors/flamethrower.inc.c b/src/game/behaviors/flamethrower.inc.c index 8d78349e..ae0922aa 100644 --- a/src/game/behaviors/flamethrower.inc.c +++ b/src/game/behaviors/flamethrower.inc.c @@ -1,35 +1,49 @@ -// flamethrower.c.inc +// flamethrower.inc.c void bhv_flamethrower_flame_loop(void) { - f32 size; + f32 scale; s32 sp18; + if (o->oTimer == 0) { o->oAnimState = (s32)(random_float() * 10.0f); obj_translate_xyz_random(o, 10.0f); } - if (o->oBehParams2ndByte == 2) - size = o->oTimer * (o->oForwardVel - 6.0f) / 100.0 + 2.0; - else - size = o->oTimer * (o->oForwardVel - 20.0) / 100.0 + 1.0; + + if (o->oBehParams2ndByte == 2) { + scale = o->oTimer * (o->oForwardVel - 6.0f) / 100.0 + 2.0; + } else { + scale = o->oTimer * (o->oForwardVel - 20.0) / 100.0 + 1.0; + } + if (o->oBehParams2ndByte == 3) { o->hitboxHeight = 200.0f; o->hitboxDownOffset = 150.0f; o->oVelY = -28.0f; + cur_obj_update_floor_height(); - if (o->oPosY - 25.0f * size < o->oFloorHeight) { + + if (o->oPosY - 25.0f * scale < o->oFloorHeight) { o->oVelY = 0; - o->oPosY = o->oFloorHeight + 25.0f * size; + o->oPosY = o->oFloorHeight + 25.0f * scale; } + sp18 = o->parentObj->oFlameThowerFlameUnk110 / 1.2; - } else + } else { sp18 = o->parentObj->oFlameThowerFlameUnk110; - cur_obj_scale(size); - if (o->oBehParams2ndByte == 4) + } + + cur_obj_scale(scale); + + if (o->oBehParams2ndByte == 4) { o->oPosY += o->oForwardVel; // weird? - else + } else { cur_obj_move_using_fvel_and_gravity(); - if (o->oTimer > sp18) + } + + if (o->oTimer > sp18) { obj_mark_for_deletion(o); + } + o->oInteractStatus = 0; } @@ -38,35 +52,49 @@ void bhv_flamethrower_loop(void) { f32 flameVel; s32 sp34; s32 model; - UNUSED u8 pad[8]; + UNUSED u8 filler[8]; + if (o->oAction == 0) { - if (gCurrLevelNum != LEVEL_BBH || gMarioOnMerryGoRound == TRUE) - if (o->oDistanceToMario < 2000.0f) - o->oAction++; + if ((gCurrLevelNum != LEVEL_BBH || gMarioOnMerryGoRound == TRUE) + && o->oDistanceToMario < 2000.0f) { + o->oAction++; + } } else if (o->oAction == 1) { model = MODEL_RED_FLAME; flameVel = 95.0f; - if (o->oBehParams2ndByte == 1) + + if (o->oBehParams2ndByte == 1) { model = MODEL_BLUE_FLAME; - if (o->oBehParams2ndByte == 2) + } + + if (o->oBehParams2ndByte == 2) { flameVel = 50.0f; + } + sp34 = 1; - if (o->oTimer < 60) + + if (o->oTimer < 60) { sp34 = 15; - else if (o->oTimer < 74) + } else if (o->oTimer < 74) { sp34 = 75 - o->oTimer; // Range: [15..2] - else + } else { o->oAction++; + } + o->oFlameThowerUnk110 = sp34; + flame = spawn_object_relative(o->oBehParams2ndByte, 0, 0, 0, o, model, bhvFlamethrowerFlame); flame->oForwardVel = flameVel; + cur_obj_play_sound_1(SOUND_AIR_BLOW_FIRE); - } else if (o->oTimer > 60) + } else if (o->oTimer > 60) { o->oAction = 0; + } } void bhv_rr_rotating_bridge_platform_loop(void) { o->oMoveAngleYaw -= 0x80; o->oAngleVelYaw = -0x80; + bhv_flamethrower_loop(); } diff --git a/src/game/behaviors/floating_box.inc.c b/src/game/behaviors/floating_box.inc.c index 166ce6c9..dcfe9490 100644 --- a/src/game/behaviors/floating_box.inc.c +++ b/src/game/behaviors/floating_box.inc.c @@ -1,4 +1,4 @@ -// floating_box.c.inc +// floating_box.inc.c void bhv_jrb_floating_box_loop(void) { o->oPosY = o->oHomeY + sins(o->oTimer * 0x400) * 10.0f; diff --git a/src/game/behaviors/floating_platform.inc.c b/src/game/behaviors/floating_platform.inc.c index 79fe0edd..1dea8a68 100644 --- a/src/game/behaviors/floating_platform.inc.c +++ b/src/game/behaviors/floating_platform.inc.c @@ -1,12 +1,10 @@ -// floating_platform.c.inc +// floating_platform.inc.c f32 floating_platform_find_home_y(void) { struct Surface *sp24; - f32 sp20; - f32 sp1C; + f32 sp20 = find_water_level(o->oPosX, o->oPosZ); + f32 sp1C = find_floor(o->oPosX, o->oPosY, o->oPosZ, &sp24); - sp20 = find_water_level(o->oPosX, o->oPosZ); - sp1C = find_floor(o->oPosX, o->oPosY, o->oPosZ, &sp24); if (sp20 > sp1C + o->oFloatingPlatformUnkFC) { o->oFloatingPlatformUnkF4 = 0; return sp20 + o->oFloatingPlatformUnkFC; @@ -25,40 +23,53 @@ void floating_platform_act_0(void) { if (gMarioObject->platform == o) { o->oFaceAnglePitch = sp4 * 2; o->oFaceAngleRoll = -sp6 * 2; + o->oVelY -= 1.0f; - if (o->oVelY < 0.0f) + if (o->oVelY < 0.0f) { o->oVelY = 0.0f; + } o->oFloatingPlatformUnkF8 += o->oVelY; - if (o->oFloatingPlatformUnkF8 > 90.0f) + + if (o->oFloatingPlatformUnkF8 > 90.0f) { o->oFloatingPlatformUnkF8 = 90.0f; + } } else { o->oFaceAnglePitch /= 2; o->oFaceAngleRoll /= 2; + o->oFloatingPlatformUnkF8 -= 5.0; + o->oVelY = 10.0f; - if (o->oFloatingPlatformUnkF8 < 0.0f) + + if (o->oFloatingPlatformUnkF8 < 0.0f) { o->oFloatingPlatformUnkF8 = 0.0f; + } } - o->oPosY = o->oHomeY - 64.0f - o->oFloatingPlatformUnkF8 + sins(o->oFloatingPlatformUnk100 * 0x800) * 10.0f; + o->oPosY = o->oHomeY - 64.0f - o->oFloatingPlatformUnkF8 + + sins(o->oFloatingPlatformUnk100 * 0x800) * 10.0f; + o->oFloatingPlatformUnk100++; - if (o->oFloatingPlatformUnk100 == 32) + + if (o->oFloatingPlatformUnk100 == 32) { o->oFloatingPlatformUnk100 = 0; + } } void bhv_floating_platform_loop(void) { o->oHomeY = floating_platform_find_home_y(); - if (o->oFloatingPlatformUnkF4 == 0) + + if (o->oFloatingPlatformUnkF4 == 0) { o->oAction = 0; - else + } else { o->oAction = 1; + } switch (o->oAction) { case 0: floating_platform_act_0(); break; - case 1: o->oPosY = o->oHomeY; break; diff --git a/src/game/behaviors/fly_guy.inc.c b/src/game/behaviors/fly_guy.inc.c index 4ae1f844..d5911582 100644 --- a/src/game/behaviors/fly_guy.inc.c +++ b/src/game/behaviors/fly_guy.inc.c @@ -29,11 +29,13 @@ static s16 sFlyGuyJitterAmounts[] = { 0x1000, -0x2000, 0x2000 }; */ static void fly_guy_act_idle(void) { o->oForwardVel = 0.0f; + if (approach_f32_ptr(&o->header.gfx.scale[0], 1.5f, 0.02f)) { // If we are >2000 units from home or Mario is <2000 units from us if (o->oDistanceToMario >= 25000.0f || o->oDistanceToMario < 2000.0f) { // Turn toward home or Mario obj_face_yaw_approach(o->oAngleToMario, 0x300); + if (cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x300)) { o->oAction = FLY_GUY_ACT_APPROACH_MARIO; } @@ -45,7 +47,7 @@ static void fly_guy_act_idle(void) { o->oAction = FLY_GUY_ACT_APPROACH_MARIO; } else { o->oFlyGuyUnusedJitter = o->oMoveAngleYaw + sFlyGuyJitterAmounts[o->oFlyGuyIdleTimer]; - o->oFlyGuyIdleTimer += 1; + o->oFlyGuyIdleTimer++; } } } @@ -66,20 +68,19 @@ static void fly_guy_act_approach_mario(void) { // If facing toward mario and we are either near mario laterally or // far above him - if (abs_angle_diff(o->oAngleToMario, o->oFaceAngleYaw) < 0x2000) { - if (o->oPosY - gMarioObject->oPosY > 400.0f || o->oDistanceToMario < 400.0f) { - // Either shoot fire or lunge - if (o->oBehParams2ndByte != 0 && random_u16() % 2) { - o->oAction = FLY_GUY_ACT_SHOOT_FIRE; - o->oFlyGuyScaleVel = 0.06f; - } else { - o->oAction = FLY_GUY_ACT_LUNGE; - o->oFlyGuyLungeTargetPitch = obj_turn_pitch_toward_mario(-200.0f, 0); + if (abs_angle_diff(o->oAngleToMario, o->oFaceAngleYaw) < 0x2000 + && (o->oPosY - gMarioObject->oPosY > 400.0f || o->oDistanceToMario < 400.0f)) { + // Either shoot fire or lunge + if (o->oBehParams2ndByte != 0 && random_u16() % 2) { + o->oAction = FLY_GUY_ACT_SHOOT_FIRE; + o->oFlyGuyScaleVel = 0.06f; + } else { + o->oAction = FLY_GUY_ACT_LUNGE; + o->oFlyGuyLungeTargetPitch = obj_turn_pitch_toward_mario(-200.0f, 0); - o->oForwardVel = 25.0f * coss(o->oFlyGuyLungeTargetPitch); - o->oVelY = 25.0f * -sins(o->oFlyGuyLungeTargetPitch); - o->oFlyGuyLungeYDecel = -o->oVelY / 30.0f; - } + o->oForwardVel = 25.0f * coss(o->oFlyGuyLungeTargetPitch); + o->oVelY = 25.0f * -sins(o->oFlyGuyLungeTargetPitch); + o->oFlyGuyLungeYDecel = -o->oVelY / 30.0f; } } } else if (obj_forward_vel_approach(0.0f, 0.2f)) { @@ -107,7 +108,7 @@ static void fly_guy_act_lunge(void) { // Twirl back upward obj_face_pitch_approach(0, 0x100); - obj_face_roll_approach(o->oFlyGuyTargetRoll, 0x12C); + obj_face_roll_approach(o->oFlyGuyTargetRoll, 300); // Twirl in a spiral with curvature proportional to oFaceAngleRoll o->oMoveAngleYaw -= o->oFaceAngleRoll / 4; @@ -131,17 +132,18 @@ static void fly_guy_act_lunge(void) { * Turn toward mario, then shoot fire. Then enter the idle action. */ static void fly_guy_act_shoot_fire(void) { - s32 scaleStatus; - o->oForwardVel = 0.0f; if (obj_face_yaw_approach(o->oAngleToMario, 0x800)) { + s32 scaleStatus; + o->oMoveAngleYaw = o->oFaceAngleYaw; // Increase scale by 0.06, 0.05, ..., -0.03. Then wait ~8 frames, then // starting moving scale by 0.05 each frame toward 1.1. The first time // it becomes below 1.2 during this latter portion, shoot fire. scaleStatus = obj_grow_then_shrink(&o->oFlyGuyScaleVel, 1.2f, 1.1f); + if (scaleStatus != 0) { if (scaleStatus < 0) { // We have reached scale 1.1 @@ -149,6 +151,7 @@ static void fly_guy_act_shoot_fire(void) { } else { // We have reached below scale 1.2 in the shrinking portion s16 fireMovePitch = obj_turn_pitch_toward_mario(0.0f, 0); + cur_obj_play_sound_2(SOUND_OBJ_FLAME_BLOWN); clamp_s16(&fireMovePitch, 0x800, 0x3000); @@ -190,7 +193,7 @@ void bhv_fly_guy_update(void) { } // Oscillate up and down - o->oFlyGuyOscTimer += 1; + o->oFlyGuyOscTimer++; o->oPosY += coss(0x400 * o->oFlyGuyOscTimer) * 1.5f; switch (o->oAction) { diff --git a/src/game/behaviors/flying_bookend_switch.inc.c b/src/game/behaviors/flying_bookend_switch.inc.c index 370265de..91d7fdc9 100644 --- a/src/game/behaviors/flying_bookend_switch.inc.c +++ b/src/game/behaviors/flying_bookend_switch.inc.c @@ -38,9 +38,12 @@ struct ObjectHitbox sBookSwitchHitbox = { void flying_bookend_act_0(void) { if (obj_is_near_to_and_facing_mario(400.0f, 0x3000)) { cur_obj_play_sound_2(SOUND_OBJ_DEFAULT_DEATH); + o->oAction = 1; + o->oBookendUnkF4 = o->oFaceAnglePitch + 0x7FFF; o->oBookendUnkF8 = o->oFaceAngleRoll - 0x7FFF; + cur_obj_set_model(MODEL_BOOKEND_PART); } } @@ -52,6 +55,7 @@ void flying_bookend_act_1(void) { o->oForwardVel = 0.0f; } else { o->oForwardVel = 3.0f; + if (o->oTimer > 5) { obj_face_pitch_approach(o->oBookendUnkF4, 2000); if (o->oTimer >= 10) { @@ -88,7 +92,7 @@ void flying_bookend_act_3(void) { o->oDamageOrCoinValue = 1; o->oNumLootCoins = 0; - if (o->oTimer >= 4) { + if (o->oTimer > 3) { o->oAction = 2; o->oForwardVel = 50.0f; } @@ -118,6 +122,7 @@ void bhv_flying_bookend_loop(void) { } obj_check_attacks(&sFlyingBookendHitbox, -1); + if (o->oAction == -1 || (o->oMoveFlags & (OBJ_MOVE_MASK_ON_GROUND | OBJ_MOVE_HIT_WALL))) { o->oNumLootCoins = 0; obj_die_if_health_non_positive(); @@ -128,26 +133,26 @@ void bhv_flying_bookend_loop(void) { } void bhv_bookend_spawn_loop(void) { - struct Object *sp1C; - if (!(o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) { if (o->oTimer > 40 && obj_is_near_to_and_facing_mario(600.0f, 0x2000)) { - sp1C = spawn_object(o, MODEL_BOOKEND, bhvFlyingBookend); + struct Object *sp1C = spawn_object(o, MODEL_BOOKEND, bhvFlyingBookend); + if (sp1C != NULL) { sp1C->oAction = 3; cur_obj_play_sound_2(SOUND_OBJ_DEFAULT_DEATH); } + o->oTimer = 0; } } } void bookshelf_manager_act_0(void) { - s32 val04; + s32 i; if (!(o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) { - for (val04 = 0; val04 < 3; val04++) { - spawn_object_relative(val04, D_80331B30[val04].unk00, D_80331B30[val04].unk02, 0, o, + for (i = 0; i < 3; i++) { + spawn_object_relative(i, D_80331B30[i].unk00, D_80331B30[i].unk02, 0, o, MODEL_BOOKEND, bhvBookSwitch); } @@ -231,18 +236,14 @@ void bhv_haunted_bookshelf_manager_loop(void) { } void bhv_book_switch_loop(void) { - s32 sp3C; - struct Object *sp38; - s16 sp36; - s16 sp34; - o->header.gfx.scale[0] = 2.0f; o->header.gfx.scale[1] = 0.9f; if (o->parentObj->oAction == 4) { obj_mark_for_deletion(o); } else { - sp3C = obj_check_attacks(&sBookSwitchHitbox, o->oAction); + s32 attackType = obj_check_attacks(&sBookSwitchHitbox, o->oAction); + if (o->parentObj->oBookSwitchManagerUnkF8 != 0 || o->oAction == 1) { if (o->oDistanceToMario < 100.0f) { cur_obj_become_tangible(); @@ -251,48 +252,50 @@ void bhv_book_switch_loop(void) { } o->oAction = 1; + if (o->oBookSwitchUnkF4 == 0.0f) { cur_obj_play_sound_2(SOUND_OBJ_DEFAULT_DEATH); } if (approach_f32_ptr(&o->oBookSwitchUnkF4, 50.0f, 20.0f)) { - if (o->parentObj->oBookSwitchManagerUnkF4 >= 0 && o->oTimer > 60) { - if (sp3C == 1 || sp3C == 2 || sp3C == 6) { - o->oAction = 2; - } + if (o->parentObj->oBookSwitchManagerUnkF4 >= 0 && o->oTimer > 60 + && (attackType == ATTACK_PUNCH || attackType == ATTACK_KICK_OR_TRIP + || attackType == ATTACK_FROM_BELOW)) { + o->oAction = 2; } } else { o->oTimer = 0; } } else { cur_obj_become_intangible(); - if (approach_f32_ptr(&o->oBookSwitchUnkF4, 0.0f, 20.0f)) { - if (o->oAction != 0) { - if (o->parentObj->oBookSwitchManagerUnkF4 == o->oBehParams2ndByte) { - play_sound(SOUND_GENERAL2_RIGHT_ANSWER, gGlobalSoundSource); - o->parentObj->oBookSwitchManagerUnkF4 += 1; - } else { - sp36 = random_u16() & 0x1; - sp34 = gMarioObject->oPosZ + 1.5f * gMarioStates[0].vel[2]; - play_sound(SOUND_MENU_CAMERA_BUZZ, gGlobalSoundSource); - if (sp34 > 0) { - sp34 = 0; - } + if (approach_f32_ptr(&o->oBookSwitchUnkF4, 0.0f, 20.0f) && o->oAction != 0) { + if (o->parentObj->oBookSwitchManagerUnkF4 == o->oBehParams2ndByte) { + play_sound(SOUND_GENERAL2_RIGHT_ANSWER, gGlobalSoundSource); + o->parentObj->oBookSwitchManagerUnkF4++; + } else { + struct Object *sp38; + s16 sp36 = random_u16() & 0x1; + s16 sp34 = gMarioObject->oPosZ + 1.5f * gMarioStates[0].vel[2]; - sp38 = spawn_object_abs_with_rot(o, 0, MODEL_BOOKEND, bhvFlyingBookend, - 0x1FC * sp36 - 0x8CA, 890, sp34, 0, - 0x8000 * sp36 + 0x4000, 0); + play_sound(SOUND_MENU_CAMERA_BUZZ, gGlobalSoundSource); - if (sp38 != NULL) { - sp38->oAction = 3; - } - - o->parentObj->oBookSwitchManagerUnkF4 = -1; + if (sp34 > 0) { + sp34 = 0; } - o->oAction = 0; + sp38 = spawn_object_abs_with_rot(o, 0, MODEL_BOOKEND, bhvFlyingBookend, + 0x1FC * sp36 - 0x8CA, 890, sp34, 0, + 0x8000 * sp36 + 0x4000, 0); + + if (sp38 != NULL) { + sp38->oAction = 3; + } + + o->parentObj->oBookSwitchManagerUnkF4 = -1; } + + o->oAction = 0; } } diff --git a/src/game/behaviors/goomba.inc.c b/src/game/behaviors/goomba.inc.c index 2dab2fec..7089c34f 100644 --- a/src/game/behaviors/goomba.inc.c +++ b/src/game/behaviors/goomba.inc.c @@ -67,13 +67,10 @@ static u8 sGoombaAttackHandlers[][6] = { * Update function for goomba triplet spawner. */ void bhv_goomba_triplet_spawner_update(void) { - UNUSED s32 unused1; + UNUSED u8 filler1[4]; s16 goombaFlag; - UNUSED s16 unused2; + UNUSED u8 filler2[2]; s32 angle; - s32 dAngle; - s16 dx; - s16 dz; // If mario is close enough and the goombas aren't currently loaded, then // spawn them @@ -81,23 +78,22 @@ void bhv_goomba_triplet_spawner_update(void) { if (o->oDistanceToMario < 3000.0f) { // The spawner is capable of spawning more than 3 goombas, but this // is not used in the game - dAngle = + s32 dAngle = 0x10000 / (((o->oBehParams2ndByte & GOOMBA_TRIPLET_SPAWNER_BP_EXTRA_GOOMBAS_MASK) >> 2) + 3); for (angle = 0, goombaFlag = 1 << 8; angle < 0xFFFF; angle += dAngle, goombaFlag <<= 1) { // Only spawn goombas which haven't been killed yet if (!(o->oBehParams & goombaFlag)) { - dx = 500.0f * coss(angle); - dz = 500.0f * sins(angle); + s16 dx = 500.0f * coss(angle); + s16 dz = 500.0f * sins(angle); spawn_object_relative((o->oBehParams2ndByte & GOOMBA_TRIPLET_SPAWNER_BP_SIZE_MASK) - | (goombaFlag >> 6), - dx, 0, dz, o, MODEL_GOOMBA, bhvGoomba); + | (goombaFlag >> 6), dx, 0, dz, o, MODEL_GOOMBA, bhvGoomba); } } - o->oAction += 1; + o->oAction++; } } else if (o->oDistanceToMario > 4000.0f) { // If mario is too far away, enter the unloaded action. The goombas @@ -128,6 +124,7 @@ void bhv_goomba_init(void) { */ static void goomba_begin_jump(void) { cur_obj_play_sound_2(SOUND_OBJ_GOOMBA_ALERT); + o->oAction = GOOMBA_ACT_JUMP; o->oForwardVel = 0.0f; o->oVelY = 50.0f / 3.0f * o->oGoombaScale; @@ -140,8 +137,8 @@ static void goomba_begin_jump(void) { */ static void mark_goomba_as_dead(void) { if (o->parentObj != o) { - set_object_respawn_info_bits(o->parentObj, - (o->oBehParams2ndByte & GOOMBA_BP_TRIPLET_FLAG_MASK) >> 2); + set_object_respawn_info_bits( + o->parentObj, (o->oBehParams2ndByte & GOOMBA_BP_TRIPLET_FLAG_MASK) >> 2); o->parentObj->oBehParams = o->parentObj->oBehParams | (o->oBehParams2ndByte & GOOMBA_BP_TRIPLET_FLAG_MASK) << 6; @@ -195,8 +192,9 @@ static void goomba_act_walk(void) { // and occasionally jumping o->oGoombaRelativeSpeed = 4.0f / 3.0f; + if (o->oGoombaWalkTimer != 0) { - o->oGoombaWalkTimer -= 1; + o->oGoombaWalkTimer--; } else { if (random_u16() & 3) { o->oGoombaTargetYaw = obj_random_fixed_turn(0x2000); @@ -270,8 +268,7 @@ void bhv_goomba_update(void) { f32 animSpeed; if (obj_update_standard_actions(o->oGoombaScale)) { - // If this goomba has a spawner and mario moved away from the spawner, - // unload + // If this goomba has a spawner and mario moved away from the spawner, unload if (o->parentObj != o) { if (o->parentObj->oAction == GOOMBA_TRIPLET_SPAWNER_ACT_UNLOADED) { obj_mark_for_deletion(o); @@ -285,6 +282,7 @@ void bhv_goomba_update(void) { if ((animSpeed = o->oForwardVel / o->oGoombaScale * 0.4f) < 1.0f) { animSpeed = 1.0f; } + cur_obj_init_animation_with_accel_and_sound(0, animSpeed); switch (o->oAction) { @@ -312,6 +310,6 @@ void bhv_goomba_update(void) { cur_obj_move_standard(-78); } else { - o->oAnimState = TRUE; + o->oAnimState = 1; } } diff --git a/src/game/behaviors/grand_star.inc.c b/src/game/behaviors/grand_star.inc.c index afdf0855..214b57d4 100644 --- a/src/game/behaviors/grand_star.inc.c +++ b/src/game/behaviors/grand_star.inc.c @@ -1,15 +1,19 @@ -// grand_star.c.inc +// grand_star.inc.c s32 arc_to_goal_pos(Vec3f a0, Vec3f a1, f32 yVel, f32 gravity) { f32 dx = a0[0] - a1[0]; f32 dz = a0[2] - a1[2]; f32 planarDist = sqrtf(dx * dx + dz * dz); s32 time; + o->oMoveAngleYaw = atan2s(dz, dx); o->oVelY = yVel; o->oGravity = gravity; + time = -2.0f / o->oGravity * yVel - 1.0f; + o->oForwardVel = planarDist / time; + return time; } @@ -20,52 +24,68 @@ void grand_star_zero_velocity(void) { } void bhv_grand_star_loop(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; Vec3f sp28; + sp28[0] = sp28[1] = sp28[2] = 0.0f; + if (o->oAction == 0) { if (o->oTimer == 0) { obj_set_angle(o, 0, 0, 0); o->oAngleVelYaw = 0x400; + cur_obj_play_sound_2(SOUND_GENERAL2_STAR_APPEARS); } - if (o->oTimer > 70) + + if (o->oTimer > 70) { o->oAction++; + } + spawn_sparkle_particles(3, 200, 80, -60); } else if (o->oAction == 1) { if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_GENERAL_GRAND_STAR); + cutscene_object(CUTSCENE_STAR_SPAWN, o); o->oGrandStarUnk108 = arc_to_goal_pos(sp28, &o->oPosX, 80.0f, -2.0f); } + cur_obj_move_using_fvel_and_gravity(); + if (o->oSubAction == 0) { if (o->oPosY < o->oHomeY) { o->oPosY = o->oHomeY; o->oVelY = 60.0f; o->oForwardVel = 0.0f; o->oSubAction++; + cur_obj_play_sound_2(SOUND_GENERAL_GRAND_STAR_JUMP); } } else if (o->oVelY < 0.0f && o->oPosY < o->oHomeY + 200.0f) { o->oPosY = o->oHomeY + 200.0f; grand_star_zero_velocity(); - gObjCutsceneDone = 1; - set_mario_npc_dialog(0); + gObjCutsceneDone = TRUE; + set_mario_npc_dialog(MARIO_DIALOG_STOP); o->oAction++; o->oInteractStatus = 0; + cur_obj_play_sound_2(SOUND_GENERAL_GRAND_STAR_JUMP); } + spawn_sparkle_particles(3, 200, 80, -60); } else { cur_obj_become_tangible(); + if (o->oInteractStatus & INT_STATUS_INTERACTED) { obj_mark_for_deletion(o); o->oInteractStatus = 0; } } - if (o->oAngleVelYaw > 0x400) + + if (o->oAngleVelYaw > 0x400) { o->oAngleVelYaw -= 0x100; + } + o->oFaceAngleYaw += o->oAngleVelYaw; cur_obj_scale(2.0f); o->oGraphYOffset = 110.0f; diff --git a/src/game/behaviors/grill_door.inc.c b/src/game/behaviors/grill_door.inc.c index 3cff966b..99ce3583 100644 --- a/src/game/behaviors/grill_door.inc.c +++ b/src/game/behaviors/grill_door.inc.c @@ -1,50 +1,71 @@ -// grill_door.c.inc +// grill_door.inc.c -struct OpenableGrill gOpenableGrills[] = { { 320, MODEL_BOB_BARS_GRILLS, bob_seg7_collision_gate }, - { 410, MODEL_HMC_RED_GRILLS, hmc_seg7_collision_0702B65C } }; +struct OpenableGrill { + s16 halfWidth; + s16 modelID; + const Collision *collision; +}; + +struct OpenableGrill gOpenableGrills[] = { + { 320, MODEL_BOB_BARS_GRILLS, bob_seg7_collision_gate }, + { 410, MODEL_HMC_RED_GRILLS, hmc_seg7_collision_0702B65C }, +}; void bhv_openable_cage_door_loop(void) { - if (gCurrentObject->oAction == 0) { - if (gCurrentObject->parentObj->oOpenableGrillUnk88 != 0) - gCurrentObject->oAction++; - } else if (gCurrentObject->oAction == 1) { - if (gCurrentObject->oTimer < 64) - gCurrentObject->oMoveAngleYaw -= gCurrentObject->oBehParams2ndByte * 0x100; - else - gCurrentObject->oAction++; + if (o->oAction == 0) { + if (o->parentObj->oOpenableGrillUnk88 != 0) { + o->oAction++; + } + } else if (o->oAction == 1) { + if (o->oTimer < 64) { + o->oMoveAngleYaw -= o->oBehParams2ndByte * 0x100; + } else { + o->oAction++; + } } } void bhv_openable_grill_loop(void) { struct Object *grillObj; s32 grillIdx; + switch (o->oAction) { case 0: grillIdx = o->oBehParams2ndByte; - grillObj = spawn_object_relative(-1, gOpenableGrills[grillIdx].halfWidth, 0, 0, o, gOpenableGrills[grillIdx].modelID, - bhvOpenableCageDoor); + + grillObj = spawn_object_relative(-1, gOpenableGrills[grillIdx].halfWidth, 0, 0, o, + gOpenableGrills[grillIdx].modelID, bhvOpenableCageDoor); grillObj->oMoveAngleYaw += 0x8000; obj_set_collision_data(grillObj, gOpenableGrills[grillIdx].collision); - grillObj = spawn_object_relative(1, -gOpenableGrills[grillIdx].halfWidth, 0, 0, o, gOpenableGrills[grillIdx].modelID, - bhvOpenableCageDoor); + + grillObj = spawn_object_relative(1, -gOpenableGrills[grillIdx].halfWidth, 0, 0, o, + gOpenableGrills[grillIdx].modelID, bhvOpenableCageDoor); obj_set_collision_data(grillObj, gOpenableGrills[grillIdx].collision); + o->oAction++; break; + case 1: - if ((o->oOpenableGrillUnkF4 = cur_obj_nearest_object_with_behavior(bhvFloorSwitchGrills)) - != NULL) + if ((o->oOpenableGrillUnkF4 = + cur_obj_nearest_object_with_behavior(bhvFloorSwitchGrills)) != NULL) { o->oAction++; + } break; + case 2: grillObj = o->oOpenableGrillUnkF4; + if (grillObj->oAction == 2) { o->oOpenableGrillUnk88 = 2; cur_obj_play_sound_2(SOUND_GENERAL_CAGE_OPEN); o->oAction++; - if (o->oBehParams2ndByte != 0) + + if (o->oBehParams2ndByte != 0) { play_puzzle_jingle(); + } } break; + case 3: break; } diff --git a/src/game/behaviors/ground_particles.inc.c b/src/game/behaviors/ground_particles.inc.c index 26dd285a..aff00af5 100644 --- a/src/game/behaviors/ground_particles.inc.c +++ b/src/game/behaviors/ground_particles.inc.c @@ -1,33 +1,82 @@ -// ground_particles.c.inc +// ground_particles.inc.c void bhv_pound_white_puffs_init(void) { - clear_particle_flags(0x8000); + clear_particle_flags(ACTIVE_PARTICLE_MIST_CIRCLE); spawn_mist_from_global(); } +static struct SpawnParticlesInfo sGlobalMistParticles = { + /* behParam: */ 3, + /* count: */ 20, + /* model: */ MODEL_MIST, + /* offsetY: */ 20, + /* forwardVelBase: */ 10, + /* forwardVelRange: */ 5, + /* velYBase: */ 0, + /* velYRange: */ 0, + /* gravity: */ 0, + /* dragStrength: */ 30, + /* sizeBase: */ 30.0f, + /* sizeRange: */ 1.5f, +}; + void spawn_mist_from_global(void) { - cur_obj_spawn_particles(&D_8032F3CC); + cur_obj_spawn_particles(&sGlobalMistParticles); } +static struct SpawnParticlesInfo sSandParticles = { + /* behParam: */ 0, + /* count: */ 5, + /* model: */ MODEL_SAND_DUST, + /* offsetY: */ 0, + /* forwardVelBase: */ 0, + /* forwardVelRange: */ 20, + /* velYBase: */ 20, + /* velYRange: */ 0, + /* gravity: */ 252, + /* dragStrength: */ 30, + /* sizeBase: */ 5.0f, + /* sizeRange: */ 2.0f, +}; + void bhv_ground_sand_init(void) { - clear_particle_flags(0x4000); - cur_obj_spawn_particles(&D_8032F3E0); + clear_particle_flags(ACTIVE_PARTICLE_DIRT); + cur_obj_spawn_particles(&sSandParticles); } +static s16 sSmokeMovementParams[] = { 2, -8, 1, 4 }; + void spawn_smoke_with_velocity(void) { struct Object *smoke = spawn_object_with_scale(o, MODEL_SMOKE, bhvWhitePuffSmoke2, 1.0f); - smoke->oForwardVel = D_8032F3F4[0]; - smoke->oVelY = D_8032F3F4[1]; - smoke->oGravity = D_8032F3F4[2]; - obj_translate_xyz_random(smoke, D_8032F3F4[3]); + + smoke->oForwardVel = sSmokeMovementParams[0]; + smoke->oVelY = sSmokeMovementParams[1]; + smoke->oGravity = sSmokeMovementParams[2]; + + obj_translate_xyz_random(smoke, sSmokeMovementParams[3]); } // TODO Fix name void clear_particle_flags(u32 flags) { - o->parentObj->oActiveParticleFlags &= flags ^ -1; // Clear the flags given (could just be ~flags) + o->parentObj->oActiveParticleFlags &= flags ^ 0xFFFFFFFF; // Clear the flags given (could just be ~flags) } +static struct SpawnParticlesInfo sSnowParticles = { + /* behParam: */ 0, + /* count: */ 5, + /* model: */ MODEL_WHITE_PARTICLE_DL, + /* offsetY: */ 0, + /* forwardVelBase: */ 0, + /* forwardVelRange: */ 20, + /* velYBase: */ 20, + /* velYRange: */ 0, + /* gravity: */ 252, + /* dragStrength: */ 30, + /* sizeBase: */ 2.0f, + /* sizeRange: */ 2.0f, +}; + void bhv_ground_snow_init(void) { - clear_particle_flags(1 << 16); - cur_obj_spawn_particles(&D_8032F3FC); + clear_particle_flags(ACTIVE_PARTICLE_SNOW); + cur_obj_spawn_particles(&sSnowParticles); } diff --git a/src/game/behaviors/haunted_chair.inc.c b/src/game/behaviors/haunted_chair.inc.c index 398d2283..d66b34c6 100644 --- a/src/game/behaviors/haunted_chair.inc.c +++ b/src/game/behaviors/haunted_chair.inc.c @@ -17,6 +17,7 @@ void bhv_haunted_chair_init(void) { f32 val00; val04 = cur_obj_find_nearest_object_with_behavior(bhvMadPiano, &val00); + if (val04 != NULL && val00 < 300.0f) { o->parentObj = val04; } else { @@ -25,14 +26,14 @@ void bhv_haunted_chair_init(void) { } void haunted_chair_act_0(void) { - s16 val0E; - if (o->parentObj != o) { if (o->oHauntedChairUnk104 == 0) { if (lateral_dist_between_objects(o, o->parentObj) < 250.0f) { - val0E = obj_angle_to_object(o, o->parentObj) - o->oFaceAngleYaw + 0x2000; + s16 val0E = obj_angle_to_object(o, o->parentObj) - o->oFaceAngleYaw + 0x2000; + if (val0E & 0x4000) { o->oHauntedChairUnk100 = &o->oFaceAngleRoll; + if (val0E > 0) { o->oHauntedChairUnk104 = 0x4000; } else { @@ -40,6 +41,7 @@ void haunted_chair_act_0(void) { } } else { o->oHauntedChairUnk100 = &o->oFaceAnglePitch; + if (val0E < 0) { o->oHauntedChairUnk104 = 0x5000; } else { @@ -59,11 +61,12 @@ void haunted_chair_act_0(void) { } } else if (o->oHauntedChairUnkF4 != 0) { if (o->oDistanceToMario < 500.0f) { - o->oHauntedChairUnkF4 -= 1; + o->oHauntedChairUnkF4--; } - o->oTimer = 0.0f; + + o->oTimer = 0; } else { - if ((o->oTimer & 0x8) != 0) { + if (o->oTimer & 0x8) { f32 val08; if (o->oFaceAnglePitch < 0) { @@ -83,6 +86,7 @@ void haunted_chair_act_0(void) { if (o->oTimer > 30) { o->oAction = 1; + o->oHauntedChairUnkF8 = 0.0f; o->oHauntedChairUnkFC = 200.0f; o->oHauntedChairUnkF4 = 40; @@ -103,20 +107,24 @@ void haunted_chair_act_1(void) { } o->oGravity = 0.0f; + oscillate_toward(&o->oFaceAnglePitch, &o->oHauntedChairUnkF8, -4000, 200.0f, 20.0f, 2.0f); oscillate_toward(&o->oFaceAngleRoll, &o->oHauntedChairUnkFC, 0, 0.0f, 20.0f, 1.0f); } else { if (o->oHauntedChairUnkF4 != 0) { if (--o->oHauntedChairUnkF4 == 0) { cur_obj_play_sound_2(SOUND_GENERAL_HAUNTED_CHAIR); + o->oMoveAnglePitch = obj_turn_pitch_toward_mario(120.0f, 0); o->oMoveAngleYaw = o->oAngleToMario; + obj_compute_vel_from_move_pitch(50.0f); } else if (o->oHauntedChairUnkF4 > 20) { if (gGlobalTimer % 4 == 0) { cur_obj_play_sound_2(SOUND_GENERAL_SWISH_AIR_2); } - o->oFaceAngleYaw += 0x2710; + + o->oFaceAngleYaw += 10000; } } else if (o->oMoveFlags & (OBJ_MOVE_MASK_ON_GROUND | OBJ_MOVE_HIT_WALL)) { obj_die_if_health_non_positive(); @@ -137,6 +145,7 @@ void bhv_haunted_chair_loop(void) { haunted_chair_act_1(); break; } + cur_obj_spin_all_dimensions(30.0f, 30.0f); } } diff --git a/src/game/behaviors/heave_ho.inc.c b/src/game/behaviors/heave_ho.inc.c index 9afe9c58..2a8ab260 100644 --- a/src/game/behaviors/heave_ho.inc.c +++ b/src/game/behaviors/heave_ho.inc.c @@ -1,4 +1,4 @@ -// heave_ho.c.inc +// heave_ho.inc.c s16 D_8032F460[][2] = { { 30, 0 }, { 42, 1 }, { 52, 0 }, { 64, 1 }, { 74, 0 }, { 86, 1 }, { 96, 0 }, { 108, 1 }, { 118, 0 }, { -1, 0 }, }; @@ -7,7 +7,9 @@ void bhv_heave_ho_throw_mario_loop(void) { o->oParentRelativePosX = 200.0f; o->oParentRelativePosY = -50.0f; o->oParentRelativePosZ = 0.0f; + o->oMoveAngleYaw = o->parentObj->oMoveAngleYaw; + switch (o->parentObj->oHeaveHoUnk88) { case 0: break; @@ -25,35 +27,45 @@ void bhv_heave_ho_throw_mario_loop(void) { void heave_ho_act_1(void) { s32 sp1C = 0; + o->oForwardVel = 0.0f; cur_obj_reverse_animation(); + while (TRUE) { if (D_8032F460[sp1C][0] == -1) { o->oAction = 2; break; } + if (o->oTimer < D_8032F460[sp1C][0]) { cur_obj_init_animation_with_accel_and_sound(2, D_8032F460[sp1C][1]); break; } + sp1C++; } } void heave_ho_act_2(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; s16 angleVel; - if (1000.0f < cur_obj_lateral_dist_from_mario_to_home()) + + if (cur_obj_lateral_dist_from_mario_to_home() > 1000.0f) { o->oAngleToMario = cur_obj_angle_to_home(); + } + if (o->oTimer > 150) { o->oHeaveHoUnkF4 = (302 - o->oTimer) / 152.0f; if (o->oHeaveHoUnkF4 < 0.1) { - o->oHeaveHoUnkF4 = 0.1; + o->oHeaveHoUnkF4 = 0.1f; o->oAction = 1; } - } else + } else { o->oHeaveHoUnkF4 = 1.0f; + } + cur_obj_init_animation_with_accel_and_sound(0, o->oHeaveHoUnkF4); + o->oForwardVel = o->oHeaveHoUnkF4 * 10.0f; angleVel = o->oHeaveHoUnkF4 * 0x400; o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oAngleToMario, angleVel); @@ -61,18 +73,24 @@ void heave_ho_act_2(void) { void heave_ho_act_3(void) { o->oForwardVel = 0.0f; - if (o->oTimer == 0) + + if (o->oTimer == 0) { o->oHeaveHoUnk88 = 2; + } + if (o->oTimer == 1) { cur_obj_init_animation_with_accel_and_sound(1, 1.0f); o->numCollidedObjs = 20; } - if (cur_obj_check_if_near_animation_end()) + + if (cur_obj_check_if_near_animation_end()) { o->oAction = 1; + } } void heave_ho_act_0(void) { cur_obj_set_pos_to_home(); + if (find_water_level(o->oPosX, o->oPosZ) < o->oPosY && o->oDistanceToMario < 4000.0f) { cur_obj_become_tangible(); cur_obj_unhide(); @@ -83,20 +101,32 @@ void heave_ho_act_0(void) { } } -void (*sHeaveHoActions[])(void) = { heave_ho_act_0, heave_ho_act_1, heave_ho_act_2, heave_ho_act_3 }; +void (*sHeaveHoActions[])(void) = { + heave_ho_act_0, + heave_ho_act_1, + heave_ho_act_2, + heave_ho_act_3, +}; void heave_ho_move(void) { cur_obj_update_floor_and_walls(); cur_obj_call_action_function(sHeaveHoActions); cur_obj_move_standard(-78); - if (o->oMoveFlags & OBJ_MOVE_MASK_IN_WATER) + + if (o->oMoveFlags & OBJ_MOVE_MASK_IN_WATER) { o->oGraphYOffset = -15.0f; - else + } else { o->oGraphYOffset = 0.0f; - if (o->oForwardVel > 3.0f) + } + + if (o->oForwardVel > 3.0f) { cur_obj_play_sound_1(SOUND_AIR_HEAVEHO_MOVE); - if (o->oAction != 0 && o->oMoveFlags & OBJ_MOVE_MASK_IN_WATER) + } + + if (o->oAction != 0 && o->oMoveFlags & OBJ_MOVE_MASK_IN_WATER) { o->oAction = 0; + } + if (o->oInteractStatus & INT_STATUS_GRABBED_MARIO) { o->oInteractStatus = 0; o->oHeaveHoUnk88 = 1; @@ -106,12 +136,13 @@ void heave_ho_move(void) { void bhv_heave_ho_loop(void) { cur_obj_scale(2.0f); + switch (o->oHeldState) { case HELD_FREE: heave_ho_move(); break; case HELD_HELD: - cur_obj_unrender_and_reset_state(0, 0); + cur_obj_unrender_set_action_and_anim(0, 0); break; case HELD_THROWN: cur_obj_get_dropped(); @@ -120,5 +151,6 @@ void bhv_heave_ho_loop(void) { cur_obj_get_dropped(); break; } + o->oInteractStatus = 0; } diff --git a/src/game/behaviors/hidden_star.inc.c b/src/game/behaviors/hidden_star.inc.c index 344e8962..9dd2c1e3 100644 --- a/src/game/behaviors/hidden_star.inc.c +++ b/src/game/behaviors/hidden_star.inc.c @@ -1,25 +1,24 @@ -// hidden_star.c.inc +// hidden_star.inc.c void bhv_hidden_star_init(void) { - s16 sp36; - struct Object *sp30; + s16 count = count_objects_with_behavior(bhvHiddenStarTrigger); - sp36 = count_objects_with_behavior(bhvHiddenStarTrigger); - if (sp36 == 0) { - sp30 = - spawn_object_abs_with_rot(o, 0, MODEL_STAR, bhvStar, o->oPosX, o->oPosY, o->oPosZ, 0, 0, 0); - sp30->oBehParams = o->oBehParams; + if (count == 0) { + struct Object *star = spawn_object_abs_with_rot(o, 0, MODEL_STAR, bhvStar, + o->oPosX, o->oPosY, o->oPosZ, 0, 0, 0); + star->oBehParams = o->oBehParams; o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } - o->oHiddenStarTriggerCounter = 5 - sp36; + o->oHiddenStarTriggerCounter = 5 - count; } void bhv_hidden_star_loop(void) { switch (o->oAction) { case 0: - if (o->oHiddenStarTriggerCounter == 5) + if (o->oHiddenStarTriggerCounter == 5) { o->oAction = 1; + } break; case 1: @@ -32,13 +31,13 @@ void bhv_hidden_star_loop(void) { } } -/* TODO: this is likely not a checkpoint but a Secret */ void bhv_hidden_star_trigger_loop(void) { - struct Object *hiddenStar; - if (obj_check_if_collided_with_object(o, gMarioObject) == 1) { - hiddenStar = cur_obj_nearest_object_with_behavior(bhvHiddenStar); + if (obj_check_if_collided_with_object(o, gMarioObject) == TRUE) { + struct Object *hiddenStar = cur_obj_nearest_object_with_behavior(bhvHiddenStar); + if (hiddenStar != NULL) { hiddenStar->oHiddenStarTriggerCounter++; + if (hiddenStar->oHiddenStarTriggerCounter != 5) { spawn_orange_number(hiddenStar->oHiddenStarTriggerCounter, 0, 0, 0); } @@ -47,8 +46,7 @@ void bhv_hidden_star_trigger_loop(void) { play_sound(SOUND_MENU_STAR_SOUND, gGlobalSoundSource); #else play_sound(SOUND_MENU_COLLECT_SECRET - + (((u8) hiddenStar->oHiddenStarTriggerCounter - 1) << 16), - gGlobalSoundSource); + + (((u8) hiddenStar->oHiddenStarTriggerCounter - 1) << 16), gGlobalSoundSource); #endif } @@ -58,10 +56,12 @@ void bhv_hidden_star_trigger_loop(void) { void bhv_bowser_course_red_coin_star_loop(void) { gRedCoinsCollected = o->oHiddenStarTriggerCounter; + switch (o->oAction) { case 0: - if (o->oHiddenStarTriggerCounter == 8) + if (o->oHiddenStarTriggerCounter == 8) { o->oAction = 1; + } break; case 1: diff --git a/src/game/behaviors/hoot.inc.c b/src/game/behaviors/hoot.inc.c index f43f0ffd..238d2754 100644 --- a/src/game/behaviors/hoot.inc.c +++ b/src/game/behaviors/hoot.inc.c @@ -1,4 +1,4 @@ -// hoot.c.inc +// hoot.inc.c void bhv_hoot_init(void) { cur_obj_init_animation(0); @@ -11,45 +11,44 @@ void bhv_hoot_init(void) { cur_obj_become_intangible(); } -// sp28 = arg0 -// sp2c = arg1 - -f32 hoot_find_next_floor(struct FloorGeometry **arg0, f32 arg1) { +f32 hoot_find_next_floor(struct FloorGeometry **floorGeo, f32 arg1) { f32 sp24 = arg1 * sins(o->oMoveAngleYaw) + o->oPosX; UNUSED f32 sp20 = o->oPosY; f32 sp1c = arg1 * coss(o->oMoveAngleYaw) + o->oPosZ; - f32 floorY = find_floor_height_and_data(sp24, 10000.0f, sp1c, arg0); + f32 floorY = find_floor_height_and_data(sp24, 10000.0f, sp1c, floorGeo); return floorY; } void hoot_floor_bounce(void) { - struct FloorGeometry *sp1c; + struct FloorGeometry *floorGeo; f32 floorY; - floorY = hoot_find_next_floor(&sp1c, 375.0f); - if (floorY + 75.0f > o->oPosY) + floorY = hoot_find_next_floor(&floorGeo, 375.0f); + if (floorY + 75.0f > o->oPosY) { o->oMoveAnglePitch -= 3640.8888; + } - floorY = hoot_find_next_floor(&sp1c, 200.0f); - if (floorY + 125.0f > o->oPosY) + floorY = hoot_find_next_floor(&floorGeo, 200.0f); + if (floorY + 125.0f > o->oPosY) { o->oMoveAnglePitch -= 7281.7776; + } - floorY = hoot_find_next_floor(&sp1c, 0); - if (floorY + 125.0f > o->oPosY) + floorY = hoot_find_next_floor(&floorGeo, 0); + if (floorY + 125.0f > o->oPosY) { o->oPosY = floorY + 125.0f; - if (o->oMoveAnglePitch < -21845.3328) + } + + if (o->oMoveAnglePitch < -21845.3328) { o->oMoveAnglePitch = -21845; + } } -// sp30 = fastOscY -// sp34 = speed - void hoot_free_step(s16 fastOscY, s32 speed) { - struct FloorGeometry *sp2c; + struct FloorGeometry *floorGeo; s16 yaw = o->oMoveAngleYaw; s16 pitch = o->oMoveAnglePitch; - s16 sp26 = o->header.gfx.animInfo.animFrame; + s16 animFrame = o->header.gfx.animInfo.animFrame; f32 xPrev = o->oPosX; f32 zPrev = o->oPosZ; f32 hSpeed; @@ -60,42 +59,44 @@ void hoot_free_step(s16 fastOscY, s32 speed) { o->oVelZ = coss(yaw) * hSpeed; o->oPosX += o->oVelX; - if (fastOscY == 0) - o->oPosY -= o->oVelY + coss((s32)(sp26 * 3276.8)) * 50.0f / 4; - else - o->oPosY -= o->oVelY + coss((s32)(sp26 * 6553.6)) * 50.0f / 4; + if (fastOscY == 0) { + o->oPosY -= o->oVelY + coss((s32)(animFrame * 3276.8)) * 50.0f / 4; + } else { + o->oPosY -= o->oVelY + coss((s32)(animFrame * 6553.6)) * 50.0f / 4; + } o->oPosZ += o->oVelZ; - find_floor_height_and_data(o->oPosX, o->oPosY, o->oPosZ, &sp2c); - if (sp2c == NULL) { + find_floor_height_and_data(o->oPosX, o->oPosY, o->oPosZ, &floorGeo); + if (floorGeo == NULL) { o->oPosX = xPrev; o->oPosZ = zPrev; } - if (sp26 == 0) + if (animFrame == 0) { cur_obj_play_sound_2(SOUND_GENERAL_SWISH_WATER); + } } void hoot_player_set_yaw(void) { s16 stickX = gPlayer3Controller->rawStickX; s16 stickY = gPlayer3Controller->rawStickY; UNUSED s16 pitch = o->oMoveAnglePitch; - if (stickX < 10 && stickX >= -9) + + if (stickX < 10 && stickX >= -9) { stickX = 0; - if (stickY < 10 && stickY >= -9) + } + + if (stickY < 10 && stickY >= -9) { stickY = 0; + } o->oMoveAngleYaw -= 5 * stickX; } -// sp28 = speed -// sp2c = xPrev -// sp30 = zPrev - void hoot_carry_step(s32 speed, UNUSED f32 xPrev, UNUSED f32 zPrev) { s16 yaw = o->oMoveAngleYaw; s16 pitch = o->oMoveAnglePitch; - s16 sp22 = o->header.gfx.animInfo.animFrame; + s16 animFrame = o->header.gfx.animInfo.animFrame; f32 hSpeed; o->oVelY = sins(pitch) * speed; @@ -104,19 +105,16 @@ void hoot_carry_step(s32 speed, UNUSED f32 xPrev, UNUSED f32 zPrev) { o->oVelZ = coss(yaw) * hSpeed; o->oPosX += o->oVelX; - o->oPosY -= o->oVelY + coss((s32)(sp22 * 6553.6)) * 50.0f / 4; + o->oPosY -= o->oVelY + coss((s32)(animFrame * 6553.6)) * 50.0f / 4; o->oPosZ += o->oVelZ; - if (sp22 == 0) + if (animFrame == 0) { cur_obj_play_sound_2(SOUND_GENERAL_SWISH_WATER); + } } -// sp48 = xPrev -// sp4c = yPrev -// sp50 = zPrev - void hoot_surface_collision(f32 xPrev, UNUSED f32 yPrev, f32 zPrev) { - struct FloorGeometry *sp44; + struct FloorGeometry *floorGeo; struct WallCollisionData hitbox; f32 floorY; @@ -130,26 +128,28 @@ void hoot_surface_collision(f32 xPrev, UNUSED f32 yPrev, f32 zPrev) { o->oPosX = hitbox.x; o->oPosY = hitbox.y; o->oPosZ = hitbox.z; - gMarioObject->oInteractStatus |= INT_STATUS_MARIO_UNK7; /* bit 7 */ + gMarioObject->oInteractStatus |= INT_STATUS_MARIO_UNK7; } - floorY = find_floor_height_and_data(o->oPosX, o->oPosY, o->oPosZ, &sp44); - if (sp44 == NULL) { + floorY = find_floor_height_and_data(o->oPosX, o->oPosY, o->oPosZ, &floorGeo); + if (floorGeo == NULL) { o->oPosX = xPrev; o->oPosZ = zPrev; return; } - if (absf_2(o->oPosX) > 8000.0f) + if (absf_2(o->oPosX) > 8000.0f) { o->oPosX = xPrev; - if (absf_2(o->oPosZ) > 8000.0f) - o->oPosZ = zPrev; - if (floorY + 125.0f > o->oPosY) - o->oPosY = floorY + 125.0f; -} + } -// sp28 = xPrev -// sp2c = zPrev + if (absf_2(o->oPosZ) > 8000.0f) { + o->oPosZ = zPrev; + } + + if (floorY + 125.0f > o->oPosY) { + o->oPosY = floorY + 125.0f; + } +} void hoot_act_ascent(f32 xPrev, f32 zPrev) { f32 negX = 0 - o->oPosX; @@ -164,8 +164,9 @@ void hoot_act_ascent(f32 xPrev, f32 zPrev) { o->header.gfx.animInfo.animFrame = 1; } - if (o->oPosY > 6500.0f) + if (o->oPosY > 6500.0f) { o->oAction = HOOT_ACT_CARRY; + } hoot_carry_step(60, xPrev, zPrev); } @@ -188,9 +189,8 @@ void hoot_action_loop(void) { if (o->oPosY < 2700.0f) { set_time_stop_flags(TIME_STOP_ENABLED | TIME_STOP_MARIO_AND_DOORS); - if (cutscene_object_with_dialog(CUTSCENE_DIALOG, o, DIALOG_045)) { + if (cutscene_object_with_dialog(CUTSCENE_DIALOG, o, DIALOG_045) != 0) { clear_time_stop_flags(TIME_STOP_ENABLED | TIME_STOP_MARIO_AND_DOORS); - o->oAction = HOOT_ACT_TIRED; } } @@ -205,8 +205,9 @@ void hoot_action_loop(void) { hoot_carry_step(20, xPrev, zPrev); - if (o->oTimer >= 61) - gMarioObject->oInteractStatus |= INT_STATUS_MARIO_UNK7; /* bit 7 */ + if (o->oTimer > 60) { + gMarioObject->oInteractStatus |= INT_STATUS_MARIO_UNK7; + } break; } @@ -225,7 +226,7 @@ void hoot_turn_to_home(void) { } void hoot_awake_loop(void) { - if (o->oInteractStatus == INT_STATUS_HOOT_GRABBED_BY_MARIO) { + if (o->oInteractStatus == TRUE) { //! Note: Not a flag, treated as a TRUE/FALSE statement hoot_action_loop(); cur_obj_init_animation(1); } else { @@ -254,8 +255,9 @@ void bhv_hoot_loop(void) { case HOOT_AVAIL_WANTS_TO_TALK: hoot_awake_loop(); - if (set_mario_npc_dialog(2) == 2 && cutscene_object_with_dialog(CUTSCENE_DIALOG, o, DIALOG_044)) { - set_mario_npc_dialog(0); + if (set_mario_npc_dialog(MARIO_DIALOG_LOOK_UP) == MARIO_DIALOG_STATUS_SPEAK + && cutscene_object_with_dialog(CUTSCENE_DIALOG, o, DIALOG_044)) { + set_mario_npc_dialog(MARIO_DIALOG_STOP); cur_obj_become_tangible(); diff --git a/src/game/behaviors/horizontal_grindel.inc.c b/src/game/behaviors/horizontal_grindel.inc.c index c0b5fe15..e842443d 100644 --- a/src/game/behaviors/horizontal_grindel.inc.c +++ b/src/game/behaviors/horizontal_grindel.inc.c @@ -1,3 +1,4 @@ +// horizontal_grindel.inc.c void bhv_horizontal_grindel_init(void) { o->oHorizontalGrindelTargetYaw = o->oMoveAngleYaw; @@ -7,7 +8,9 @@ void bhv_horizontal_grindel_update(void) { if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) { if (!o->oHorizontalGrindelOnGround) { cur_obj_play_sound_2(SOUND_OBJ_THWOMP); + o->oHorizontalGrindelOnGround = TRUE; + set_camera_shake_from_point(SHAKE_POS_SMALL, o->oPosX, o->oPosY, o->oPosZ); o->oHorizontalGrindelDistToHome = cur_obj_lateral_dist_to_home(); @@ -22,6 +25,7 @@ void bhv_horizontal_grindel_update(void) { o->oHorizontalGrindelDistToHome = 0.0f; } else { cur_obj_play_sound_2(SOUND_OBJ_KING_BOBOMB_JUMP); + o->oForwardVel = 11.0f; o->oVelY = 70.0f; o->oGravity = -4.0f; @@ -33,11 +37,13 @@ void bhv_horizontal_grindel_update(void) { } } else { o->oHorizontalGrindelOnGround = FALSE; + if (o->oVelY < 0.0f) { o->oGravity = -16.0f; } } o->oFaceAngleYaw = o->oMoveAngleYaw + 0x4000; + cur_obj_move_standard(78); } diff --git a/src/game/behaviors/intro_lakitu.inc.c b/src/game/behaviors/intro_lakitu.inc.c index 7b12a651..7ca8055d 100644 --- a/src/game/behaviors/intro_lakitu.inc.c +++ b/src/game/behaviors/intro_lakitu.inc.c @@ -1,15 +1,15 @@ + /** * @file intro_lakitu.inc.c * This file implements lakitu's behvaior during the intro cutscene. * It's also used during the ending cutscene. */ - /** * Add the camera's position to `offset`, rotate the point to be relative to the camera's focus, then * set lakitu's location. */ -void intro_lakitu_set_offset_from_camera(struct Object *o, Vec3f offset) { +void intro_lakitu_set_offset_from_camera(struct Object *obj, Vec3f offset) { f32 dist; Vec3s focusAngles; s16 offsetPitch, offsetYaw; @@ -20,75 +20,96 @@ void intro_lakitu_set_offset_from_camera(struct Object *o, Vec3f offset) { vec3f_get_dist_and_angle(gCamera->pos, offset, &dist, &offsetPitch, &offsetYaw); vec3f_set_dist_and_angle(gCamera->pos, offset, dist, focusAngles[0] + offsetPitch, focusAngles[1] + offsetYaw); - vec3f_to_object_pos(o, offset); + vec3f_to_object_pos(obj, offset); } -void intro_lakitu_set_focus(struct Object *o, Vec3f newFocus) { - UNUSED Vec3f unusedVec3f; +void intro_lakitu_set_focus(struct Object *obj, Vec3f newFocus) { + UNUSED u8 filler1[12]; Vec3f origin; f32 dist; s16 pitch, yaw; - UNUSED u32 unused; + UNUSED u8 filler2[4]; // newFocus is an offset from lakitu's origin, not a point in the world. - vec3f_set(origin, 0.f, 0.f, 0.f); + vec3f_set(origin, 0.0f, 0.0f, 0.0f); vec3f_get_dist_and_angle(origin, newFocus, &dist, &pitch, &yaw); - o->oFaceAnglePitch = pitch; - o->oFaceAngleYaw = yaw; + + obj->oFaceAnglePitch = pitch; + obj->oFaceAngleYaw = yaw; } /** * Move lakitu along the spline `offset`, relative to the camera, and face him towards the corresponding * location along the spline `focus`. */ -s32 intro_lakitu_set_pos_and_focus(struct Object *o, struct CutsceneSplinePoint offset[], +s32 intro_lakitu_set_pos_and_focus(struct Object *obj, struct CutsceneSplinePoint offset[], struct CutsceneSplinePoint focus[]) { Vec3f newOffset, newFocus; s32 splineFinished = 0; - s16 splineSegment = o->oIntroLakituSplineSegment; + s16 splineSegment = obj->oIntroLakituSplineSegment; - if ((move_point_along_spline(newFocus, offset, &splineSegment, &(o->oIntroLakituSplineSegmentProgress)) == 1) - || (move_point_along_spline(newOffset, focus, &splineSegment, &(o->oIntroLakituSplineSegmentProgress)) == 1)) - splineFinished += 1; + if ((move_point_along_spline(newFocus, offset, &splineSegment, + &obj->oIntroLakituSplineSegmentProgress) == 1) + || (move_point_along_spline(newOffset, focus, &splineSegment, + &obj->oIntroLakituSplineSegmentProgress) == 1)) { + splineFinished++; + } + + obj->oIntroLakituSplineSegment = splineSegment; + + intro_lakitu_set_offset_from_camera(obj, newOffset); + intro_lakitu_set_focus(obj, newFocus); - o->oIntroLakituSplineSegment = splineSegment; - intro_lakitu_set_offset_from_camera(o, newOffset); - intro_lakitu_set_focus(o, newFocus); return splineFinished; } +#ifdef VERSION_EU +#define TIMER1 599 +#define TIMER2 74 +#else +#define TIMER1 720 +#define TIMER2 98 +#endif + void bhv_intro_lakitu_loop(void) { Vec3f sp64, sp58, sp4C; - UNUSED u32 pad[4]; + UNUSED u8 filler[16]; - switch (gCurrentObject->oAction) { + switch (o->oAction) { case 0: cur_obj_disable_rendering(); - gCurrentObject->oIntroLakituSplineSegment = 0.f; - gCurrentObject->oIntroLakituSplineSegmentProgress = 0.f; - gCurrentObject->oIntroLakituCloud = - spawn_object_relative_with_scale(1, 0, 0, 0, 2.f, gCurrentObject, MODEL_MIST, bhvCloud); - if (gCamera->cutscene == CUTSCENE_END_WAVING) - gCurrentObject->oAction = 100; - else - gCurrentObject->oAction += 1; + + o->oIntroLakituSplineSegment = 0.0f; + o->oIntroLakituSplineSegmentProgress = 0.0f; + o->oIntroLakituCloud = + spawn_object_relative_with_scale(1, 0, 0, 0, 2.0f, o, MODEL_MIST, bhvCloud); + + if (gCamera->cutscene == CUTSCENE_END_WAVING) { + o->oAction = 100; + } else { + o->oAction++; + } break; case 1: cur_obj_enable_rendering(); + if ((gCutsceneTimer > 350) && (gCutsceneTimer < 458)) { - gCurrentObject->oPosX = gCamera->pos[0]; - gCurrentObject->oPosY = gCamera->pos[1] + 500.f; - gCurrentObject->oPosZ = gCamera->pos[2]; + o->oPosX = gCamera->pos[0]; + o->oPosY = gCamera->pos[1] + 500.0f; + o->oPosZ = gCamera->pos[2]; } - if (gCutsceneTimer > 52) + + if (gCutsceneTimer > 52) { cur_obj_play_sound_1(SOUND_AIR_LAKITU_FLY_HIGHPRIO); + } - if (intro_lakitu_set_pos_and_focus(gCurrentObject, gIntroLakituStartToPipeOffsetFromCamera, - gIntroLakituStartToPipeFocus) == 1) - gCurrentObject->oAction += 1; + if (intro_lakitu_set_pos_and_focus(o, gIntroLakituStartToPipeOffsetFromCamera, + gIntroLakituStartToPipeFocus) == 1) { + o->oAction++; + } - switch (gCurrentObject->oTimer) { + switch (o->oTimer) { #if defined(VERSION_US) || defined(VERSION_SH) case 534: cur_obj_play_sound_2(SOUND_ACTION_FLYING_FAST); @@ -98,129 +119,134 @@ void bhv_intro_lakitu_loop(void) { break; #endif case 73: - gCurrentObject->oAnimState += 1; + o->oAnimState++; break; case 74: - gCurrentObject->oAnimState -= 1; + o->oAnimState--; break; case 82: - gCurrentObject->oAnimState += 1; + o->oAnimState++; break; case 84: - gCurrentObject->oAnimState -= 1; + o->oAnimState--; break; } #ifdef VERSION_EU - if (gCurrentObject->oTimer == 446) + if (o->oTimer == 446) { cur_obj_play_sound_2(SOUND_ACTION_FLYING_FAST); - if (gCurrentObject->oTimer == 485) + } + if (o->oTimer == 485) { cur_obj_play_sound_2(SOUND_ACTION_INTRO_UNK45E); + } #endif break; + case 2: -#ifdef VERSION_EU - if (gCutsceneTimer > 599) { -#else - if (gCutsceneTimer > 720) { -#endif - gCurrentObject->oAction += 1; - gCurrentObject->oIntroLakituUnk100 = 1400.f; - gCurrentObject->oIntroLakituUnk104 = -4096.f; - gCurrentObject->oIntroLakituUnk108 = 2048.f; - gCurrentObject->oIntroLakituUnk10C = -200.f; - gCurrentObject->oMoveAngleYaw = 0x8000; - gCurrentObject->oFaceAngleYaw = gCurrentObject->oMoveAngleYaw + 0x4000; - gCurrentObject->oMoveAnglePitch = 0x800; + if (gCutsceneTimer > TIMER1) { + o->oAction++; + + o->oIntroLakituUnk100 = 1400.0f; + o->oIntroLakituUnk104 = -4096.0f; + o->oIntroLakituUnk108 = 2048.0f; + o->oIntroLakituUnk10C = -200.0f; + + o->oMoveAngleYaw = 0x8000; + o->oFaceAngleYaw = o->oMoveAngleYaw + 0x4000; + o->oMoveAnglePitch = 0x800; } + cur_obj_play_sound_1(SOUND_AIR_LAKITU_FLY_HIGHPRIO); break; case 3: cur_obj_play_sound_1(SOUND_AIR_LAKITU_FLY_HIGHPRIO); - vec3f_set(sp58, -1128.f, 560.f, 4664.f); - gCurrentObject->oMoveAngleYaw += 0x200; - gCurrentObject->oIntroLakituUnk100 = - approach_f32_asymptotic(gCurrentObject->oIntroLakituUnk100, 100.f, 0.03f); - gCurrentObject->oFaceAnglePitch = atan2s(200.f, gCurrentObject->oPosY - 400.f); - gCurrentObject->oFaceAngleYaw = approach_s16_asymptotic( - gCurrentObject->oFaceAngleYaw, gCurrentObject->oMoveAngleYaw + 0x8000, 4); - vec3f_set_dist_and_angle(sp58, sp4C, gCurrentObject->oIntroLakituUnk100, 0, - gCurrentObject->oMoveAngleYaw); - sp4C[1] += 150.f * coss((s16) gCurrentObject->oIntroLakituUnk104); - gCurrentObject->oIntroLakituUnk104 += gCurrentObject->oIntroLakituUnk108; - gCurrentObject->oIntroLakituUnk108 = - approach_f32_asymptotic(gCurrentObject->oIntroLakituUnk108, 512.f, 0.05f); - sp4C[0] += gCurrentObject->oIntroLakituUnk10C; - gCurrentObject->oIntroLakituUnk10C = - approach_f32_asymptotic(gCurrentObject->oIntroLakituUnk10C, 0.f, 0.05f); - vec3f_to_object_pos(gCurrentObject, sp4C); - if (gCurrentObject->oTimer == 31) { - gCurrentObject->oPosY -= 158.f; + vec3f_set(sp58, -1128.0f, 560.0f, 4664.0f); + o->oMoveAngleYaw += 0x200; + o->oIntroLakituUnk100 = approach_f32_asymptotic(o->oIntroLakituUnk100, 100.0f, 0.03f); + o->oFaceAnglePitch = atan2s(200.0f, o->oPosY - 400.0f); + o->oFaceAngleYaw = approach_s16_asymptotic(o->oFaceAngleYaw, o->oMoveAngleYaw + 0x8000, 4); + vec3f_set_dist_and_angle(sp58, sp4C, o->oIntroLakituUnk100, 0, o->oMoveAngleYaw); + sp4C[1] += 150.0f * coss((s16) o->oIntroLakituUnk104); + o->oIntroLakituUnk104 += o->oIntroLakituUnk108; + o->oIntroLakituUnk108 = approach_f32_asymptotic(o->oIntroLakituUnk108, 512.0f, 0.05f); + sp4C[0] += o->oIntroLakituUnk10C; + o->oIntroLakituUnk10C = approach_f32_asymptotic(o->oIntroLakituUnk10C, 0.0f, 0.05f); + vec3f_to_object_pos(o, sp4C); + + if (o->oTimer == 31) { + o->oPosY -= 158.0f; // Spawn white ground particles spawn_mist_from_global(); - gCurrentObject->oPosY += 158.f; + o->oPosY += 158.0f; } -#ifdef VERSION_EU -#define TIMER 74 -#else -#define TIMER 98 -#endif - if (gCurrentObject->oTimer == TIMER) { - obj_mark_for_deletion(gCurrentObject); - obj_mark_for_deletion(gCurrentObject->oIntroLakituCloud); + if (o->oTimer == TIMER2) { + obj_mark_for_deletion(o); + obj_mark_for_deletion(o->oIntroLakituCloud); } + #ifndef VERSION_JP - if (gCurrentObject->oTimer == 14) + if (o->oTimer == 14) { cur_obj_play_sound_2(SOUND_ACTION_INTRO_UNK45F); + } #endif break; + case 100: cur_obj_enable_rendering(); - vec3f_set(sp64, -100.f, 100.f, 300.f); + + vec3f_set(sp64, -100.0f, 100.0f, 300.0f); offset_rotated(sp4C, gCamera->pos, sp64, sMarioCamState->faceAngle); - vec3f_to_object_pos(gCurrentObject, sp4C); - gCurrentObject->oMoveAnglePitch = 0x1000; - gCurrentObject->oMoveAngleYaw = 0x9000; - gCurrentObject->oFaceAnglePitch = gCurrentObject->oMoveAnglePitch / 2; - gCurrentObject->oFaceAngleYaw = gCurrentObject->oMoveAngleYaw; - gCurrentObject->oAction += 1; + vec3f_to_object_pos(o, sp4C); + + o->oMoveAnglePitch = 0x1000; + o->oMoveAngleYaw = 0x9000; + o->oFaceAnglePitch = o->oMoveAnglePitch / 2; + o->oFaceAngleYaw = o->oMoveAngleYaw; + + o->oAction++; break; case 101: - object_pos_to_vec3f(sp4C, gCurrentObject); - if (gCurrentObject->oTimer > 60) { - gCurrentObject->oForwardVel = - approach_f32_asymptotic(gCurrentObject->oForwardVel, -10.f, 0.05f); - gCurrentObject->oMoveAngleYaw += 0x78; - gCurrentObject->oMoveAnglePitch += 0x40; - gCurrentObject->oFaceAngleYaw = camera_approach_s16_symmetric( - gCurrentObject->oFaceAngleYaw, (s16) calculate_yaw(sp4C, gCamera->pos), - 0x200); + object_pos_to_vec3f(sp4C, o); + + if (o->oTimer > 60) { + o->oForwardVel = approach_f32_asymptotic(o->oForwardVel, -10.0f, 0.05f); + o->oMoveAngleYaw += 0x78; + o->oMoveAnglePitch += 0x40; + o->oFaceAngleYaw = camera_approach_s16_symmetric( + o->oFaceAngleYaw, calculate_yaw(sp4C, gCamera->pos), 0x200); } - if (gCurrentObject->oTimer > 105) { - gCurrentObject->oAction += 1; - gCurrentObject->oMoveAnglePitch = 0xE00; + + if (o->oTimer > 105) { + o->oAction++; + o->oMoveAnglePitch = 0xE00; } - gCurrentObject->oFaceAnglePitch = 0; + + o->oFaceAnglePitch = 0; + cur_obj_set_pos_via_transform(); break; case 102: - object_pos_to_vec3f(sp4C, gCurrentObject); - gCurrentObject->oForwardVel = - approach_f32_asymptotic(gCurrentObject->oForwardVel, 60.f, 0.05f); - gCurrentObject->oFaceAngleYaw = camera_approach_s16_symmetric( - gCurrentObject->oFaceAngleYaw, (s16) calculate_yaw(sp4C, gCamera->pos), 0x200); - if (gCurrentObject->oTimer < 62) - gCurrentObject->oMoveAngleYaw = - approach_s16_asymptotic(gCurrentObject->oMoveAngleYaw, 0x1800, 0x1E); - gCurrentObject->oMoveAnglePitch = - camera_approach_s16_symmetric(gCurrentObject->oMoveAnglePitch, -0x2000, 0x5A); - gCurrentObject->oFaceAnglePitch = 0; + object_pos_to_vec3f(sp4C, o); + + o->oForwardVel = approach_f32_asymptotic(o->oForwardVel, 60.0f, 0.05f); + o->oFaceAngleYaw = camera_approach_s16_symmetric( + o->oFaceAngleYaw, calculate_yaw(sp4C, gCamera->pos), 0x200); + + if (o->oTimer < 62) { + o->oMoveAngleYaw = approach_s16_asymptotic(o->oMoveAngleYaw, 0x1800, 0x1E); + } + + o->oMoveAnglePitch = camera_approach_s16_symmetric(o->oMoveAnglePitch, -0x2000, 0x5A); + o->oFaceAnglePitch = 0; + cur_obj_set_pos_via_transform(); break; } } -#undef TIMER + +#undef TIMER1 +#undef TIMER2 diff --git a/src/game/behaviors/intro_peach.inc.c b/src/game/behaviors/intro_peach.inc.c index 2838a910..551b3108 100644 --- a/src/game/behaviors/intro_peach.inc.c +++ b/src/game/behaviors/intro_peach.inc.c @@ -4,50 +4,58 @@ * Set peach's location relative to the camera focus. * If nonzero, make peach's opacity approach targetOpacity by increment */ -void intro_peach_set_pos_and_opacity(struct Object *o, f32 targetOpacity, f32 increment) { +void intro_peach_set_pos_and_opacity(struct Object *obj, f32 targetOpacity, f32 increment) { Vec3f newPos; s16 focusPitch, focusYaw; f32 UNUSED dist, newOpacity; vec3f_get_dist_and_angle(gLakituState.pos, gLakituState.focus, &dist, &focusPitch, &focusYaw); - vec3f_set_dist_and_angle(gLakituState.pos, newPos, o->oIntroPeachDistToCamera, o->oIntroPeachPitchFromFocus + focusPitch, - o->oIntroPeachYawFromFocus + focusYaw); - vec3f_to_object_pos(o, newPos); - newOpacity = o->oOpacity; + vec3f_set_dist_and_angle(gLakituState.pos, newPos, obj->oIntroPeachDistToCamera, + obj->oIntroPeachPitchFromFocus + focusPitch, + obj->oIntroPeachYawFromFocus + focusYaw); + vec3f_to_object_pos(obj, newPos); + + newOpacity = obj->oOpacity; camera_approach_f32_symmetric_bool(&newOpacity, targetOpacity, increment); - o->oOpacity = newOpacity; + obj->oOpacity = newOpacity; } void bhv_intro_peach_loop(void) { - switch (gCurrentObject->oAction) { + switch (o->oAction) { case 0: - gCurrentObject->oAction += 1; - gCurrentObject->oFaceAnglePitch = 0x400; - gCurrentObject->oFaceAngleYaw = 0x7500; - gCurrentObject->oFaceAngleRoll = -0x3700; - gCurrentObject->oIntroPeachDistToCamera = 186.f; - gCurrentObject->oIntroPeachPitchFromFocus = -9984.f; - gCurrentObject->oIntroPeachYawFromFocus = -768.f; - gCurrentObject->oOpacity = 255; - gCurrentObject->header.gfx.animInfo.animFrame = 100; + o->oAction++; + o->oFaceAnglePitch = 0x400; + o->oFaceAngleYaw = 0x7500; + o->oFaceAngleRoll = -0x3700; + o->oIntroPeachDistToCamera = 186.0f; + o->oIntroPeachPitchFromFocus = -9984.0f; + o->oIntroPeachYawFromFocus = -768.0f; + o->oOpacity = 255; + o->header.gfx.animInfo.animFrame = 100; break; + case 1: - intro_peach_set_pos_and_opacity(gCurrentObject, 0.f, 0.f); + intro_peach_set_pos_and_opacity(o, 0.0f, 0.0f); - if (gCurrentObject->oTimer > 20) - gCurrentObject->oAction += 1; + if (o->oTimer > 20) { + o->oAction++; + } break; + case 2: - intro_peach_set_pos_and_opacity(gCurrentObject, 255.f, 3.f); + intro_peach_set_pos_and_opacity(o, 255.0f, 3.0f); - if ((gCurrentObject->oTimer > 100) && (get_dialog_id() == -1)) - gCurrentObject->oAction += 1; + if ((o->oTimer > 100) && (get_dialog_id() == DIALOG_NONE)) { + o->oAction++; + } break; - case 3: - intro_peach_set_pos_and_opacity(gCurrentObject, 0.f, 8.f); - if (gCurrentObject->oTimer > 60) - obj_mark_for_deletion(gCurrentObject); + case 3: + intro_peach_set_pos_and_opacity(o, 0.0f, 8.0f); + + if (o->oTimer > 60) { + obj_mark_for_deletion(o); + } break; } } diff --git a/src/game/behaviors/intro_scene.inc.c b/src/game/behaviors/intro_scene.inc.c index 7b6a2475..42d5e806 100644 --- a/src/game/behaviors/intro_scene.inc.c +++ b/src/game/behaviors/intro_scene.inc.c @@ -1,73 +1,84 @@ // intro_scene.inc.c -void spawn_child_obj_relative(struct Object *parent, s16 xOffset, s16 yOffset, s16 zOffset, s16 pitchOffset, - s16 yawOffset, s16 rollOffset, s16 forwardVel, - s32 model, const BehaviorScript *behavior) { - struct Object *sp1C = spawn_object(parent, model, behavior); +void spawn_child_obj_relative(struct Object *parent, s16 xOffset, s16 yOffset, s16 zOffset, + s16 pitchOffset, s16 yawOffset, s16 rollOffset, + s16 forwardVel, s32 model, const BehaviorScript *behavior) { + struct Object *obj = spawn_object(parent, model, behavior); - sp1C->header.gfx.animInfo.animFrame = random_float() * 6.f; - sp1C->oEndBirdUnk104 = sCutsceneVars[9].point[0]; - sCutsceneVars[9].point[0] += 1.f; - sp1C->oPosX += xOffset; - sp1C->oPosY += yOffset; - if (gCutsceneTimer > 700) - sp1C->oPosY += -150.f; - sp1C->oPosZ += zOffset; - sp1C->oMoveAnglePitch += pitchOffset; - sp1C->oMoveAngleYaw += yawOffset; - sp1C->oMoveAngleRoll += rollOffset; - sp1C->oForwardVel = forwardVel; + obj->header.gfx.animInfo.animFrame = random_float() * 6.0f; + obj->oEndBirdUnk104 = sCutsceneVars[9].point[0]; + + sCutsceneVars[9].point[0] += 1.0f; + + obj->oPosX += xOffset; + obj->oPosY += yOffset; + + if (gCutsceneTimer > 700) { + obj->oPosY += -150.0f; + } + + obj->oPosZ += zOffset; + obj->oMoveAnglePitch += pitchOffset; + obj->oMoveAngleYaw += yawOffset; + obj->oMoveAngleRoll += rollOffset; + obj->oForwardVel = forwardVel; } void bhv_intro_scene_loop(void) { - UNUSED struct Object *sp34; + UNUSED struct Object *obj; if (gCutsceneObjSpawn != 0) { - gCurrentObject->oPosX = gCamera->pos[0]; - gCurrentObject->oPosY = gCamera->pos[1]; - gCurrentObject->oPosZ = gCamera->pos[2]; - gCurrentObject->oMoveAnglePitch = 0; - gCurrentObject->oMoveAngleYaw = 0; + o->oPosX = gCamera->pos[0]; + o->oPosY = gCamera->pos[1]; + o->oPosZ = gCamera->pos[2]; + + o->oMoveAnglePitch = 0; + o->oMoveAngleYaw = 0; switch (gCutsceneObjSpawn) { case 6: - sp34 = spawn_object(gCurrentObject, MODEL_LAKITU, bhvBeginningLakitu); + obj = spawn_object(o, MODEL_LAKITU, bhvBeginningLakitu); break; + case 5: - sp34 = spawn_object(gCurrentObject, MODEL_PEACH, bhvBeginningPeach); + obj = spawn_object(o, MODEL_PEACH, bhvBeginningPeach); break; + case 7: - spawn_child_obj_relative(gCurrentObject, 0, 205, 500, 0x1000, 0x6000, -0x1E00, 25, MODEL_BIRDS, - bhvEndBirds1); - spawn_child_obj_relative(gCurrentObject, 0, 205, 800, 0x1800, 0x6000, -0x1400, 35, MODEL_BIRDS, - bhvEndBirds1); - spawn_child_obj_relative(gCurrentObject, -100, 300, 500, 0x800, 0x6000, 0, 25, MODEL_BIRDS, - bhvEndBirds1); - spawn_child_obj_relative(gCurrentObject, 100, -200, 800, 0, 0x4000, 0x1400, 45, MODEL_BIRDS, - bhvEndBirds1); - spawn_child_obj_relative(gCurrentObject, -80, 300, 350, 0x1800, 0x5000, 0xA00, 35, MODEL_BIRDS, - bhvEndBirds1); - spawn_child_obj_relative(gCurrentObject, -300, 300, 500, 0x800, 0x6000, 0x2800, 25, MODEL_BIRDS, - bhvEndBirds1); - spawn_child_obj_relative(gCurrentObject, -400, -200, 800, 0, 0x4000, -0x1400, 45, MODEL_BIRDS, - bhvEndBirds1); + spawn_child_obj_relative( + o, 0, 205, 500, 0x1000, 0x6000, -0x1E00, 25, MODEL_BIRDS, bhvEndBirds1); + spawn_child_obj_relative( + o, 0, 205, 800, 0x1800, 0x6000, -0x1400, 35, MODEL_BIRDS, bhvEndBirds1); + spawn_child_obj_relative( + o, -100, 300, 500, 0x800, 0x6000, 0, 25, MODEL_BIRDS, bhvEndBirds1); + spawn_child_obj_relative( + o, 100, -200, 800, 0, 0x4000, 0x1400, 45, MODEL_BIRDS, bhvEndBirds1); + spawn_child_obj_relative( + o, -80, 300, 350, 0x1800, 0x5000, 0xA00, 35, MODEL_BIRDS, bhvEndBirds1); + spawn_child_obj_relative( + o, -300, 300, 500, 0x800, 0x6000, 0x2800, 25, MODEL_BIRDS, bhvEndBirds1); + spawn_child_obj_relative( + o, -400, -200, 800, 0, 0x4000, -0x1400, 45, MODEL_BIRDS, bhvEndBirds1); break; + case 9: - spawn_child_obj_relative(gCurrentObject, 50, 205, 500, 0x1000, 0x6000, 0, 35, MODEL_BIRDS, - bhvEndBirds1); - spawn_child_obj_relative(gCurrentObject, 0, 285, 800, 0x1800, 0x6000, 0, 35, MODEL_BIRDS, - bhvEndBirds1); + spawn_child_obj_relative( + o, 50, 205, 500, 0x1000, 0x6000, 0, 35, MODEL_BIRDS, bhvEndBirds1); + spawn_child_obj_relative( + o, 0, 285, 800, 0x1800, 0x6000, 0, 35, MODEL_BIRDS, bhvEndBirds1); break; + case 8: - spawn_child_obj_relative(gCurrentObject, -100, -100, -700, 0, 0, -0xF00, 25, MODEL_BIRDS, - bhvEndBirds2); - spawn_child_obj_relative(gCurrentObject, -250, 255, -200, 0, 0, -0x1400, 25, MODEL_BIRDS, - bhvEndBirds2); - spawn_child_obj_relative(gCurrentObject, -100, 155, -600, 0, 0, -0x500, 35, MODEL_BIRDS, - bhvEndBirds2); - spawn_child_obj_relative(gCurrentObject, 250, 200, -1200, 0, 0, -0x700, 25, MODEL_BIRDS, - bhvEndBirds2); - spawn_child_obj_relative(gCurrentObject, -250, 255, -700, 0, 0, 0, 25, MODEL_BIRDS, bhvEndBirds2); + spawn_child_obj_relative( + o, -100, -100, -700, 0, 0, -0xF00, 25, MODEL_BIRDS, bhvEndBirds2); + spawn_child_obj_relative( + o, -250, 255, -200, 0, 0, -0x1400, 25, MODEL_BIRDS, bhvEndBirds2); + spawn_child_obj_relative( + o, -100, 155, -600, 0, 0, -0x500, 35, MODEL_BIRDS, bhvEndBirds2); + spawn_child_obj_relative( + o, 250, 200, -1200, 0, 0, -0x700, 25, MODEL_BIRDS, bhvEndBirds2); + spawn_child_obj_relative( + o, -250, 255, -700, 0, 0, 0, 25, MODEL_BIRDS, bhvEndBirds2); break; } diff --git a/src/game/behaviors/jrb_ship.inc.c b/src/game/behaviors/jrb_ship.inc.c index 3b627da0..0918d8d0 100644 --- a/src/game/behaviors/jrb_ship.inc.c +++ b/src/game/behaviors/jrb_ship.inc.c @@ -1,36 +1,43 @@ -// jrb_ship.c.inc +// jrb_ship.inc.c struct ObjectHitbox sSkullSlidingBoxHitbox = { - /* interactType: */ INTERACT_DAMAGE, - /* downOffset: */ 0, + /* interactType: */ INTERACT_DAMAGE, + /* downOffset: */ 0, /* damageOrCoinValue: */ 1, - /* health: */ 1, - /* numLootCoins: */ 0, - /* radius: */ 130, - /* height: */ 100, - /* hurtboxRadius: */ 0, - /* hurtboxHeight: */ 0, + /* health: */ 1, + /* numLootCoins: */ 0, + /* radius: */ 130, + /* height: */ 100, + /* hurtboxRadius: */ 0, + /* hurtboxHeight: */ 0, }; void bhv_sunken_ship_part_loop(void) { - if (o->oDistanceToMario > 10000.0f) + if (o->oDistanceToMario > 10000.0f) { o->oOpacity = 140; - else + } else { o->oOpacity = o->oDistanceToMario * 140.0f / 10000.0; + } + cur_obj_disable_rendering(); } void bhv_ship_part_3_loop(void) { s16 sp1E = o->oFaceAnglePitch; s16 sp1C = o->oFaceAngleRoll; + cur_obj_set_pos_to_home_with_debug(); + o->oShipPart3UnkF4 += 0x100; - o->oFaceAnglePitch = sins(o->oShipPart3UnkF4) * 1024.0f; - o->oFaceAngleRoll = sins(o->oShipPart3UnkF8) * 1024.0f; + + o->oFaceAnglePitch = sins(o->oShipPart3UnkF4) * 0x400; + o->oFaceAngleRoll = sins(o->oShipPart3UnkF8) * 0x400; o->oAngleVelPitch = o->oFaceAnglePitch - sp1E; o->oAngleVelRoll = o->oFaceAngleRoll - sp1C; - if (gMarioObject->oPosY > 1000.0f) + + if (gMarioObject->oPosY > 1000.0f) { cur_obj_play_sound_1(SOUND_ENV_BOAT_ROCKING1); + } } void bhv_jrb_sliding_box_loop(void) { @@ -43,47 +50,66 @@ void bhv_jrb_sliding_box_loop(void) { UNUSED Vec3f sp2C; Vec3f sp20; s16 sp1E; + if (o->oJrbSlidingBoxUnkF4 == NULL) { sp3C = cur_obj_nearest_object_with_behavior(bhvInSunkenShip3); - if (sp3C != NULL) // NULL check only for assignment, not for dereference? + + if (sp3C != NULL) { // NULL check only for assignment, not for dereference? o->oJrbSlidingBoxUnkF4 = sp3C; + } + o->oParentRelativePosX = o->oPosX - sp3C->oPosX; o->oParentRelativePosY = o->oPosY - sp3C->oPosY; o->oParentRelativePosZ = o->oPosZ - sp3C->oPosZ; } else { sp3C = o->oJrbSlidingBoxUnkF4; + sp40[0] = sp3C->oFaceAnglePitch; sp40[1] = sp3C->oFaceAngleYaw; sp40[2] = sp3C->oFaceAngleRoll; + sp54[0] = o->oParentRelativePosX; sp54[1] = o->oParentRelativePosY; sp54[2] = o->oParentRelativePosZ; + mtxf_rotate_zxy_and_translate(sp60, sp54, sp40); linear_mtxf_mul_vec3f(sp60, sp48, sp54); + o->oPosX = sp3C->oPosX + sp48[0]; o->oPosY = sp3C->oPosY + sp48[1]; o->oPosZ = sp3C->oPosZ + sp48[2]; + sp1E = sp3C->oFaceAnglePitch; } + sp20[0] = o->oPosX; sp20[1] = o->oPosY; sp20[2] = o->oPosZ; + find_floor(sp20[0], sp20[1], sp20[2], &sp38); + if (sp38 != NULL) { sp2C[0] = sp38->normal.x; sp2C[1] = sp38->normal.y; sp2C[2] = sp38->normal.z; + o->oFaceAnglePitch = sp1E; } + o->oJrbSlidingBoxUnkFC = sins(o->oJrbSlidingBoxUnkF8) * 20.0f; o->oJrbSlidingBoxUnkF8 += 0x100; o->oParentRelativePosZ += o->oJrbSlidingBoxUnkFC; - if (gMarioObject->oPosY > 1000.0f) - if (absf(o->oJrbSlidingBoxUnkFC) > 3.0f) - cur_obj_play_sound_1(SOUND_AIR_ROUGH_SLIDE); + + if (gMarioObject->oPosY > 1000.0f && absf(o->oJrbSlidingBoxUnkFC) > 3.0f) { + cur_obj_play_sound_1(SOUND_AIR_ROUGH_SLIDE); + } + obj_set_hitbox(o, &sSkullSlidingBoxHitbox); - if (!(o->oJrbSlidingBoxUnkF8 & 0x7FFF)) + + if (!(o->oJrbSlidingBoxUnkF8 & 0x7FFF)) { cur_obj_become_tangible(); + } + if (obj_check_if_collided_with_object(o, gMarioObject)) { o->oInteractStatus = 0; cur_obj_become_intangible(); diff --git a/src/game/behaviors/jumping_box.inc.c b/src/game/behaviors/jumping_box.inc.c index 287d7377..2a8fc9cd 100644 --- a/src/game/behaviors/jumping_box.inc.c +++ b/src/game/behaviors/jumping_box.inc.c @@ -1,21 +1,23 @@ -// jumping_box.c.inc +// jumping_box.inc.c struct ObjectHitbox sJumpingBoxHitbox = { - /* interactType: */ INTERACT_GRABBABLE, - /* downOffset: */ 20, + /* interactType: */ INTERACT_GRABBABLE, + /* downOffset: */ 20, /* damageOrCoinValue: */ 0, - /* health: */ 1, - /* numLootCoins: */ 5, - /* radius: */ 150, - /* height: */ 250, - /* hurtboxRadius: */ 150, - /* hurtboxHeight: */ 250, + /* health: */ 1, + /* numLootCoins: */ 5, + /* radius: */ 150, + /* height: */ 250, + /* hurtboxRadius: */ 150, + /* hurtboxHeight: */ 250, }; void jumping_box_act_0(void) { if (o->oSubAction == 0) { - if (o->oJumpingBoxUnkF8-- < 0) + if (o->oJumpingBoxUnkF8-- < 0) { o->oSubAction++; + } + if (o->oTimer > o->oJumpingBoxUnkF4) { o->oVelY = random_float() * 5.0f + 15.0f; o->oSubAction++; @@ -33,7 +35,10 @@ void jumping_box_act_1(void) { } } -void (*sJumpingBoxActions[])(void) = { jumping_box_act_0, jumping_box_act_1 }; +void (*sJumpingBoxActions[])(void) = { + jumping_box_act_0, + jumping_box_act_1, +}; void jumping_box_free_update(void) { cur_obj_set_model(MODEL_BREAKABLE_BOX); @@ -49,22 +54,27 @@ void bhv_jumping_box_loop(void) { case HELD_FREE: jumping_box_free_update(); break; + case HELD_HELD: obj_copy_pos(o, gMarioObject); cur_obj_set_model(MODEL_BREAKABLE_BOX_SMALL); - cur_obj_unrender_and_reset_state(-1, 0); + cur_obj_unrender_set_action_and_anim(-1, 0); break; + case HELD_THROWN: cur_obj_get_thrown_or_placed(40.0f, 20.0f, 1); break; + case HELD_DROPPED: cur_obj_get_dropped(); o->oAction = 1; break; } + if (o->oInteractStatus & INT_STATUS_STOP_RIDING) { create_sound_spawner(SOUND_GENERAL_BREAK_BOX); obj_explode_and_spawn_coins(46.0f, 1); } + o->oInteractStatus = 0; } diff --git a/src/game/behaviors/kickable_board.inc.c b/src/game/behaviors/kickable_board.inc.c index 8ba05e54..87cf7466 100644 --- a/src/game/behaviors/kickable_board.inc.c +++ b/src/game/behaviors/kickable_board.inc.c @@ -1,22 +1,28 @@ -// kickable_board.c.inc +// kickable_board.inc.c -s32 check_mario_attacking(UNUSED s32 sp18) { - if (obj_check_if_collided_with_object(o, gMarioObject)) { - if (abs_angle_diff(o->oMoveAngleYaw, gMarioObject->oMoveAngleYaw) > 0x6000) { - if (gMarioStates[0].action == ACT_SLIDE_KICK) - return 1; - if (gMarioStates[0].action == ACT_PUNCHING) - return 1; - if (gMarioStates[0].action == ACT_MOVE_PUNCHING) - return 1; - if (gMarioStates[0].action == ACT_SLIDE_KICK_SLIDE) - return 1; - if (gMarioStates[0].action == ACT_JUMP_KICK) - return 2; - if (gMarioStates[0].action == ACT_WALL_KICK_AIR) - return 2; +s32 check_mario_attacking(UNUSED s32 unused) { + if (obj_check_if_collided_with_object(o, gMarioObject) + && abs_angle_diff(o->oMoveAngleYaw, gMarioObject->oMoveAngleYaw) > 0x6000) { + if (gMarioStates[0].action == ACT_SLIDE_KICK) { + return 1; + } + if (gMarioStates[0].action == ACT_PUNCHING) { + return 1; + } + if (gMarioStates[0].action == ACT_MOVE_PUNCHING) { + return 1; + } + if (gMarioStates[0].action == ACT_SLIDE_KICK_SLIDE) { + return 1; + } + if (gMarioStates[0].action == ACT_JUMP_KICK) { + return 2; + } + if (gMarioStates[0].action == ACT_WALL_KICK_AIR) { + return 2; } } + return 0; } @@ -27,53 +33,72 @@ void init_kickable_board_rock(void) { void bhv_kickable_board_loop(void) { s32 sp24; + switch (o->oAction) { case 0: o->oFaceAnglePitch = 0; - if (check_mario_attacking(0)) { + + if (check_mario_attacking(0) != 0) { init_kickable_board_rock(); o->oAction++; } + load_object_collision_model(); break; + case 1: o->oFaceAnglePitch = 0; load_object_collision_model(); o->oFaceAnglePitch = -sins(o->oKickableBoardF4) * o->oKickableBoardF8; + if (o->oTimer > 30 && (sp24 = check_mario_attacking(0))) { if (gMarioObject->oPosY > o->oPosY + 160.0f && sp24 == 2) { o->oAction++; cur_obj_play_sound_2(SOUND_GENERAL_BUTTON_PRESS_2); - } else + } else { o->oTimer = 0; + } } + if (o->oTimer != 0) { o->oKickableBoardF8 -= 8; - if (o->oKickableBoardF8 < 0) + if (o->oKickableBoardF8 < 0) { o->oAction = 0; - } else + } + } else { init_kickable_board_rock(); - if (!(o->oKickableBoardF4 & 0x7FFF)) + } + + if (!(o->oKickableBoardF4 & 0x7FFF)) { cur_obj_play_sound_2(SOUND_GENERAL_BUTTON_PRESS_2); + } + o->oKickableBoardF4 += 0x400; break; + case 2: cur_obj_become_intangible(); cur_obj_set_model(MODEL_WF_KICKABLE_BOARD_FELLED); + o->oAngleVelPitch -= 0x80; o->oFaceAnglePitch += o->oAngleVelPitch; + if (o->oFaceAnglePitch < -0x4000) { o->oFaceAnglePitch = -0x4000; o->oAngleVelPitch = 0; o->oAction++; + cur_obj_shake_screen(SHAKE_POS_SMALL); cur_obj_play_sound_2(SOUND_GENERAL_UNKNOWN4); } + load_object_collision_model(); break; + case 3: load_object_collision_model(); break; } + o->header.gfx.throwMatrix = NULL; } diff --git a/src/game/behaviors/king_bobomb.inc.c b/src/game/behaviors/king_bobomb.inc.c index b8a54aa6..3c35449d 100644 --- a/src/game/behaviors/king_bobomb.inc.c +++ b/src/game/behaviors/king_bobomb.inc.c @@ -1,23 +1,22 @@ -// king_bobomb.c.inc +// king_bobomb.inc.c // Copy of geo_update_projectile_pos_from_parent Gfx *geo_update_held_mario_pos(s32 run, UNUSED struct GraphNode *node, Mat4 mtx) { - Mat4 sp20; - struct Object *sp1C; - if (run == TRUE) { - sp1C = (struct Object *) gCurGraphNodeObject; + Mat4 sp20; + struct Object *sp1C = (struct Object *) gCurGraphNodeObject; if (sp1C->prevObj != NULL) { create_transformation_from_matrices(sp20, mtx, *gCurGraphNodeCamera->matrixPtr); obj_update_pos_from_parent_transformation(sp20, sp1C->prevObj); obj_set_gfx_pos_from_pos(sp1C->prevObj); } } + return NULL; } void bhv_bobomb_anchor_mario_loop(void) { - common_anchor_mario_behavior(50.0f, 50.0f, 64); + common_anchor_mario_behavior(50.0f, 50.0f, INT_STATUS_MARIO_UNK6); } void king_bobomb_act_0(void) { @@ -25,17 +24,20 @@ void king_bobomb_act_0(void) { o->oForwardVel = 0.0f; o->oVelY = 0.0f; #endif + if (o->oSubAction == 0) { cur_obj_become_intangible(); gSecondCameraFocus = o; cur_obj_init_animation_with_sound(5); cur_obj_set_pos_to_home(); o->oHealth = 3; + if (cur_obj_can_mario_activate_textbox_2(500.0f, 100.0f)) { o->oSubAction++; seq_player_lower_volume(SEQ_PLAYER_LEVEL, 60, 40); } - } else if (cur_obj_update_dialog_with_cutscene(2, 1, CUTSCENE_DIALOG, DIALOG_017)) { + } else if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + DIALOG_FLAG_TURN_TO_MARIO, CUTSCENE_DIALOG, DIALOG_017)) { o->oAction = 2; o->oFlags |= OBJ_FLAG_HOLDABLE; } @@ -51,21 +53,28 @@ s32 mario_is_far_below_object(f32 arg0) { void king_bobomb_act_2(void) { cur_obj_become_tangible(); + if (o->oPosY - o->oHomeY < -100.0f) { // Thrown off hill o->oAction = 5; cur_obj_become_intangible(); } + if (o->oKingBobombUnk100 == 0) { - if (cur_obj_check_anim_frame(15)) + if (cur_obj_check_anim_frame(15)) { cur_obj_shake_screen(SHAKE_POS_SMALL); - if (cur_obj_init_animation_and_check_if_near_end(4)) + } + + if (cur_obj_init_animation_and_check_if_near_end(4)) { o->oKingBobombUnk100++; + } } else { if (o->oKingBobombUnk100 == 1) { cur_obj_init_animation_and_anim_frame(11, 7); o->oKingBobombUnk100 = 2; - } else + } else { cur_obj_init_animation_with_sound(11); + } + if (o->oKingBobombUnk108 == 0) { o->oForwardVel = 3.0f; cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x100); @@ -74,8 +83,11 @@ void king_bobomb_act_2(void) { o->oKingBobombUnk108--; } } - if (cur_obj_check_grabbed_mario()) + + if (cur_obj_check_grabbed_mario()) { o->oAction = 3; + } + if (mario_is_far_below_object(1200.0f)) { o->oAction = 0; stop_background_music(SEQUENCE_ARGS(4, SEQ_EVENT_BOSS)); @@ -84,53 +96,64 @@ void king_bobomb_act_2(void) { void king_bobomb_act_3(void) { if (o->oSubAction == 0) { - o->oForwardVel = 0; + o->oForwardVel = 0.0f; o->oKingBobombUnk104 = 0; o->oKingBobombUnkFC = 0; - if (o->oTimer == 0) + + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN3); + } + if (cur_obj_init_animation_and_check_if_near_end(0)) { o->oSubAction++; cur_obj_init_animation_and_anim_frame(1, 0); } - } else { - if (o->oSubAction == 1) { - cur_obj_init_animation_with_sound(1); - o->oKingBobombUnkFC += player_performed_grab_escape_action(); - print_debug_bottom_up("%d", o->oKingBobombUnkFC); - if (o->oKingBobombUnkFC > 10) { - o->oKingBobombUnk88 = 3; - o->oAction = 2; - o->oKingBobombUnk108 = 35; - o->oInteractStatus &= ~(INT_STATUS_GRABBED_MARIO); - } else { - o->oForwardVel = 3.0f; - if (o->oKingBobombUnk104 > 20 && cur_obj_rotate_yaw_toward(0, 0x400)) { - o->oSubAction++; - cur_obj_init_animation_and_anim_frame(9, 22); - } - } - o->oKingBobombUnk104++; + } else if (o->oSubAction == 1) { + cur_obj_init_animation_with_sound(1); + o->oKingBobombUnkFC += player_performed_grab_escape_action(); + + print_debug_bottom_up("%d", o->oKingBobombUnkFC); + + if (o->oKingBobombUnkFC > 10) { + o->oKingBobombUnk88 = 3; + o->oAction = 2; + o->oKingBobombUnk108 = 35; + o->oInteractStatus &= ~INT_STATUS_GRABBED_MARIO; } else { - cur_obj_init_animation_with_sound(9); - if (cur_obj_check_anim_frame(31)) { - o->oKingBobombUnk88 = 2; - cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN4); - } else if (cur_obj_check_if_near_animation_end()) { - o->oAction = 1; - o->oInteractStatus &= ~(INT_STATUS_GRABBED_MARIO); + o->oForwardVel = 3.0f; + + if (o->oKingBobombUnk104 > 20 && cur_obj_rotate_yaw_toward(0, 0x400)) { + o->oSubAction++; + cur_obj_init_animation_and_anim_frame(9, 22); } } + + o->oKingBobombUnk104++; + } else { + cur_obj_init_animation_with_sound(9); + + if (cur_obj_check_anim_frame(31)) { + o->oKingBobombUnk88 = 2; + cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN4); + } else if (cur_obj_check_if_near_animation_end()) { + o->oAction = 1; + o->oInteractStatus &= ~INT_STATUS_GRABBED_MARIO; + } } } void king_bobomb_act_1(void) { - o->oForwardVel = 0; - o->oVelY = 0; + o->oForwardVel = 0.0f; + o->oVelY = 0.0f; + cur_obj_init_animation_with_sound(11); - o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oAngleToMario, 512); - if (o->oDistanceToMario < 2500.0f) + + o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oAngleToMario, 0x200); + + if (o->oDistanceToMario < 2500.0f) { o->oAction = 2; + } + if (mario_is_far_below_object(1200.0f)) { o->oAction = 0; stop_background_music(SEQUENCE_ARGS(4, SEQ_EVENT_BOSS)); @@ -141,137 +164,181 @@ void king_bobomb_act_6(void) { if (o->oSubAction == 0) { if (o->oTimer == 0) { o->oKingBobombUnk104 = 0; + cur_obj_play_sound_2(SOUND_OBJ_KING_BOBOMB); cur_obj_play_sound_2(SOUND_OBJ2_KING_BOBOMB_DAMAGE); cur_obj_shake_screen(SHAKE_POS_SMALL); spawn_mist_particles_variable(0, 0, 100.0f); - o->oInteractType = 8; + + o->oInteractType = INTERACT_DAMAGE; + cur_obj_become_tangible(); } - if (cur_obj_init_animation_and_check_if_near_end(2)) + + if (cur_obj_init_animation_and_check_if_near_end(2)) { o->oKingBobombUnk104++; + } + if (o->oKingBobombUnk104 > 3) { o->oSubAction++; } + } else if (o->oSubAction == 1) { + if (cur_obj_init_animation_and_check_if_near_end(10)) { + o->oSubAction++; + o->oInteractType = INTERACT_GRABBABLE; + + cur_obj_become_intangible(); + } } else { - if (o->oSubAction == 1) { - if (cur_obj_init_animation_and_check_if_near_end(10)) { - o->oSubAction++; - o->oInteractType = 2; - cur_obj_become_intangible(); - } - } else { - cur_obj_init_animation_with_sound(11); - if (cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x800) == 1) - o->oAction = 2; + cur_obj_init_animation_with_sound(11); + + if (cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x800) == TRUE) { + o->oAction = 2; } } } void king_bobomb_act_7(void) { cur_obj_init_animation_with_sound(2); - if (cur_obj_update_dialog_with_cutscene(2, 2, CUTSCENE_DIALOG, DIALOG_116)) { + if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + DIALOG_FLAG_TEXT_DEFAULT, CUTSCENE_DIALOG, DIALOG_116)) { create_sound_spawner(SOUND_OBJ_KING_WHOMP_DEATH); + cur_obj_hide(); cur_obj_become_intangible(); + spawn_mist_particles_variable(0, 0, 200.0f); - spawn_triangle_break_particles(20, 138, 3.0f, 4); + spawn_triangle_break_particles(20, MODEL_DIRT_ANIMATION, 3.0f, 4); cur_obj_shake_screen(SHAKE_POS_SMALL); + #ifndef VERSION_JP cur_obj_spawn_star_at_y_offset(2000.0f, 4500.0f, -4500.0f, 200.0f); #else o->oPosY += 100.0f; spawn_default_star(2000.0f, 4500.0f, -4500.0f); #endif + o->oAction = 8; } } void king_bobomb_act_8(void) { - if (o->oTimer == 60) + if (o->oTimer == 60) { stop_background_music(SEQUENCE_ARGS(4, SEQ_EVENT_BOSS)); + } } void king_bobomb_act_4(void) { // bobomb been thrown if (o->oPosY - o->oHomeY > -100.0f) { // not thrown off hill if (o->oMoveFlags & OBJ_MOVE_LANDED) { o->oHealth--; - o->oForwardVel = 0; - o->oVelY = 0; + + o->oForwardVel = 0.0f; + o->oVelY = 0.0f; + cur_obj_play_sound_2(SOUND_OBJ_KING_BOBOMB); - if (o->oHealth) + + if (o->oHealth != 0) { o->oAction = 6; - else + } else { o->oAction = 7; + } + } + } else if (o->oSubAction == 0) { + if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) { + o->oForwardVel = 0.0f; + o->oVelY = 0.0f; + + o->oSubAction++; + } else if (o->oMoveFlags & OBJ_MOVE_LANDED) { + cur_obj_play_sound_2(SOUND_OBJ_KING_BOBOMB); } } else { - if (o->oSubAction == 0) { - if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) { - o->oForwardVel = 0; - o->oVelY = 0; - o->oSubAction++; - } else if (o->oMoveFlags & OBJ_MOVE_LANDED) - cur_obj_play_sound_2(SOUND_OBJ_KING_BOBOMB); - } else { - if (cur_obj_init_animation_and_check_if_near_end(10)) - o->oAction = 5; // Go back to top of hill - o->oSubAction++; + if (cur_obj_init_animation_and_check_if_near_end(10)) { + o->oAction = 5; // Go back to top of hill } + + o->oSubAction++; } } void king_bobomb_act_5(void) { // bobomb returns home switch (o->oSubAction) { case 0: - if (o->oTimer == 0) + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_OBJ_KING_BOBOMB_JUMP); + } + o->oKingBobombUnkF8 = 1; + cur_obj_init_animation_and_extend_if_at_end(8); - o->oMoveAngleYaw = cur_obj_angle_to_home(); - if (o->oPosY < o->oHomeY) + o->oMoveAngleYaw = cur_obj_angle_to_home(); + + if (o->oPosY < o->oHomeY) { o->oVelY = 100.0f; - else { + } else { arc_to_goal_pos(&o->oHomeX, &o->oPosX, 100.0f, -4.0f); o->oSubAction++; } break; + case 1: cur_obj_init_animation_and_extend_if_at_end(8); + if (o->oVelY < 0 && o->oPosY < o->oHomeY) { o->oPosY = o->oHomeY; o->oVelY = 0; o->oForwardVel = 0; o->oGravity = -4.0f; + o->oKingBobombUnkF8 = 0; + cur_obj_init_animation_with_sound(7); cur_obj_play_sound_2(SOUND_OBJ_KING_BOBOMB); cur_obj_shake_screen(SHAKE_POS_SMALL); + o->oSubAction++; } break; + case 2: - if (cur_obj_init_animation_and_check_if_near_end(7)) + if (cur_obj_init_animation_and_check_if_near_end(7)) { o->oSubAction++; + } break; + case 3: if (mario_is_far_below_object(1200.0f)) { o->oAction = 0; stop_background_music(SEQUENCE_ARGS(4, SEQ_EVENT_BOSS)); } - if (cur_obj_can_mario_activate_textbox_2(500.0f, 100.0f)) + + if (cur_obj_can_mario_activate_textbox_2(500.0f, 100.0f)) { o->oSubAction++; + } break; + case 4: - if (cur_obj_update_dialog_with_cutscene(2, 1, CUTSCENE_DIALOG, DIALOG_128)) + if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + DIALOG_FLAG_TURN_TO_MARIO, CUTSCENE_DIALOG, DIALOG_128)) { o->oAction = 2; + } break; } } void (*sKingBobombActions[])(void) = { - king_bobomb_act_0, king_bobomb_act_1, king_bobomb_act_2, king_bobomb_act_3, king_bobomb_act_4, - king_bobomb_act_5, king_bobomb_act_6, king_bobomb_act_7, king_bobomb_act_8, + king_bobomb_act_0, + king_bobomb_act_1, + king_bobomb_act_2, + king_bobomb_act_3, + king_bobomb_act_4, + king_bobomb_act_5, + king_bobomb_act_6, + king_bobomb_act_7, + king_bobomb_act_8, }; + struct SoundState sKingBobombSoundStates[] = { { 0, 0, 0, NO_SOUND }, { 1, 1, 20, SOUND_OBJ_POUNDING1_HIGHPRIO }, @@ -289,29 +356,36 @@ struct SoundState sKingBobombSoundStates[] = { void king_bobomb_move(void) { cur_obj_update_floor_and_walls(); - if (o->oKingBobombUnkF8 == 0) + + if (o->oKingBobombUnkF8 == 0) { cur_obj_move_standard(-78); - else + } else { cur_obj_move_using_fvel_and_gravity(); + } + cur_obj_call_action_function(sKingBobombActions); exec_anim_sound_state(sKingBobombSoundStates); - if (o->oDistanceToMario < 5000.0f) + + if (o->oDistanceToMario < 5000.0f) { cur_obj_enable_rendering(); - else + } else { cur_obj_disable_rendering(); + } } void bhv_king_bobomb_loop(void) { f32 sp34 = 20.0f; f32 sp30 = 50.0f; - UNUSED u8 pad[8]; + UNUSED u8 filler[8]; + o->oInteractionSubtype |= INT_SUBTYPE_GRABS_MARIO; + switch (o->oHeldState) { case HELD_FREE: king_bobomb_move(); break; case HELD_HELD: - cur_obj_unrender_and_reset_state(6, 1); + cur_obj_unrender_set_action_and_anim(6, 1); break; case HELD_THROWN: case HELD_DROPPED: @@ -320,5 +394,6 @@ void bhv_king_bobomb_loop(void) { o->oPosY += 20.0f; break; } + o->oInteractStatus = 0; } diff --git a/src/game/behaviors/klepto.inc.c b/src/game/behaviors/klepto.inc.c index 46d7ffcc..9a1e10b3 100644 --- a/src/game/behaviors/klepto.inc.c +++ b/src/game/behaviors/klepto.inc.c @@ -1,3 +1,5 @@ +// klepto.inc.c + static struct ObjectHitbox sKleptoHitbox = { /* interactType: */ INTERACT_HIT_FROM_BELOW, /* downOffset: */ 0, @@ -61,9 +63,9 @@ static void klepto_anim_dive(void) { } } else { obj_move_pitch_approach(o->oKleptoUnk1B0, 600); - if (klepto_set_and_check_if_anim_at_end() != 0) { + if (klepto_set_and_check_if_anim_at_end()) { if (o->oKleptoUnk1AE != 0) { - o->oKleptoUnk1AE += 1; + o->oKleptoUnk1AE++; } else if (o->oKleptoUnk1B0 > -100) { o->oKleptoUnk1AE = random_linear_offset(60, 60); } @@ -91,14 +93,13 @@ void bhv_klepto_init(void) { static void klepto_change_target(void) { s32 newTarget = 0; - s32 i; - f32 dx; - f32 dz; - f32 targetDist; - f32 minTargetDist; if (o->oDistanceToMario > 2000.0f) { - minTargetDist = 99999.0f; + s32 i; + f32 dx; + f32 dz; + f32 targetDist; + f32 minTargetDist = 99999.0f; for (i = 0; i < 3; i++) { dx = gMarioObject->oPosX - sKleptoTargetPositions[i][0]; @@ -125,9 +126,6 @@ static void klepto_change_target(void) { } static void klepto_circle_target(f32 radius, f32 targetSpeed) { - s16 turnAmount; - f32 accel; - if (o->oAnimState != KLEPTO_ANIM_STATE_HOLDING_NOTHING && ((o->oTimer > 60 && o->oDistanceToMario > 2000.0f) || o->oTimer >= o->oKleptoTimeUntilTargetChange)) { @@ -135,8 +133,9 @@ static void klepto_circle_target(f32 radius, f32 targetSpeed) { o->oKleptoTimeUntilTargetChange = random_linear_offset(300, 300); o->oAction = KLEPTO_ACT_APPROACH_TARGET_HOLDING; } else { - turnAmount = 0x4000 - atan2s(radius, o->oKleptoDistanceToTarget - radius); - accel = 0.05f; + s16 turnAmount = 0x4000 - atan2s(radius, o->oKleptoDistanceToTarget - radius); + f32 accel = 0.05f; + if ((s16)(o->oMoveAngleYaw - o->oKleptoYawToTarget) < 0) { turnAmount = -turnAmount; } @@ -146,8 +145,8 @@ static void klepto_circle_target(f32 radius, f32 targetSpeed) { //! The multiplied value is sometimes out of range for an s16 during the s32 -> s16 cast, // which might invert sign. - turnAmount = - (s16)(s32)(abs_angle_diff(o->oKleptoYawToTarget, o->oMoveAngleYaw) * (0.03f * o->oKleptoSpeed)); + turnAmount = (s16)(s32)(abs_angle_diff(o->oKleptoYawToTarget, o->oMoveAngleYaw) + * (0.03f * o->oKleptoSpeed)); clamp_s16(&turnAmount, 400, 700); obj_rotate_yaw_and_bounce_off_walls(o->oKleptoYawToTarget, turnAmount); @@ -180,7 +179,7 @@ static void klepto_act_wait_for_mario(void) { klepto_target_mario(); if (o->oKleptoDistanceToTarget < 1000.0f) { o->oAction = KLEPTO_ACT_TURN_TOWARD_MARIO; - o->oFlags &= ~0x00000008; + o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; } } @@ -190,12 +189,13 @@ static void klepto_act_wait_for_mario(void) { static void klepto_act_turn_toward_mario(void) { klepto_target_mario(); - if (klepto_set_and_check_if_anim_at_end() && cur_obj_check_if_at_animation_end() && o->oKleptoDistanceToTarget > 800.0f + if (klepto_set_and_check_if_anim_at_end() && cur_obj_check_if_at_animation_end() + && o->oKleptoDistanceToTarget > 800.0f && abs_angle_diff(o->oAngleToMario, o->oFaceAngleYaw) < 0x800 && o->oKleptoUnk1B0 < 0x400) { cur_obj_play_sound_2(SOUND_OBJ_KLEPTO1); o->oAction = KLEPTO_ACT_DIVE_AT_MARIO; o->oMoveAngleYaw = o->oFaceAngleYaw; - o->oFlags |= 0x00000008; + o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; cur_obj_init_animation_with_sound(3); } @@ -206,6 +206,7 @@ static void klepto_act_turn_toward_mario(void) { static void klepto_act_dive_at_mario(void) { approach_f32_ptr(&o->oKleptoSpeed, 60.0f, 10.0f); + if (o->oSoundStateID == 2) { if (cur_obj_check_anim_frame(11)) { cur_obj_play_sound_2(SOUND_GENERAL_SWISH_WATER); @@ -221,6 +222,7 @@ static void klepto_act_dive_at_mario(void) { } } else { f32 dy = o->oPosY - gMarioObject->oPosY; + if (o->oSoundStateID == 3) { cur_obj_set_anim_if_at_end(4); } else if (o->oVelY > 0.0f && dy > 200.0f) { @@ -228,22 +230,22 @@ static void klepto_act_dive_at_mario(void) { } o->oKleptoUnk1B0 = -0x3000; + if (o->oAnimState == KLEPTO_ANIM_STATE_HOLDING_NOTHING) { if (o->oSubAction == 0) { o->oKleptoUnk1B0 = obj_turn_pitch_toward_mario(0.0f, 0); o->oKleptoYawToTarget = o->oAngleToMario; if (dy < 160.0f) { - o->oSubAction += 1; + o->oSubAction++; } } if (gMarioStates[0].action != ACT_SLEEPING && !(gMarioStates[0].action & (ACT_FLAG_SHORT_HITBOX | ACT_FLAG_BUTT_OR_STOMACH_SLIDE)) - && o->oDistanceToMario < 200.0f && dy > 50.0f && dy < 90.0f) { - if (mario_lose_cap_to_enemy(1)) { - o->oAnimState = KLEPTO_ANIM_STATE_HOLDING_CAP; - } + && o->oDistanceToMario < 200.0f && dy > 50.0f && dy < 90.0f + && mario_lose_cap_to_enemy(1)) { + o->oAnimState = KLEPTO_ANIM_STATE_HOLDING_CAP; } } } @@ -282,14 +284,13 @@ static void klepto_act_retreat(void) { obj_face_pitch_approach(o->oMoveAnglePitch, 1000); obj_rotate_yaw_and_bounce_off_walls(o->oKleptoYawToTarget, 600); - if (obj_face_yaw_approach(o->oMoveAngleYaw, 1000)) { - if (abs_angle_diff(o->oFaceAnglePitch, o->oMoveAnglePitch) == 0) { - o->oAction = KLEPTO_ACT_RESET_POSITION; - o->oHomeY = 1500.0f; - o->oKleptoUnk1AE = -100; - o->oFlags |= 0x00000008; - cur_obj_become_tangible(); - } + if (obj_face_yaw_approach(o->oMoveAngleYaw, 1000) + && abs_angle_diff(o->oFaceAnglePitch, o->oMoveAnglePitch) == 0) { + o->oAction = KLEPTO_ACT_RESET_POSITION; + o->oHomeY = 1500.0f; + o->oKleptoUnk1AE = -100; + o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; + cur_obj_become_tangible(); } } @@ -319,7 +320,7 @@ void obj_set_speed_to_zero(void) { } void bhv_klepto_update(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; cur_obj_update_floor_and_walls(); @@ -371,7 +372,8 @@ void bhv_klepto_update(void) { o->oGravity = -2.0f; o->oMoveAngleYaw = o->oAngleToMario + 0x8000; - o->oFlags &= ~0x00000008; + o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; + cur_obj_become_intangible(); } else if (gMarioStates[0].action == ACT_SLEEPING || (gMarioStates[0].action diff --git a/src/game/behaviors/koopa.inc.c b/src/game/behaviors/koopa.inc.c index 49c1c2dc..04b345c9 100644 --- a/src/game/behaviors/koopa.inc.c +++ b/src/game/behaviors/koopa.inc.c @@ -53,7 +53,7 @@ static u8 sKoopaShelledAttackHandlers[] = { struct KoopaTheQuickProperties { s16 initText; s16 winText; - void const *path; + Trajectory const *path; Vec3s starPos; }; @@ -62,7 +62,7 @@ struct KoopaTheQuickProperties { */ static struct KoopaTheQuickProperties sKoopaTheQuickProperties[] = { { DIALOG_005, DIALOG_007, bob_seg7_trajectory_koopa, { 3030, 4500, -4600 } }, - { DIALOG_009, DIALOG_031, thi_seg7_trajectory_koopa, { 7100, -1300, -6000 } } + { DIALOG_009, DIALOG_031, thi_seg7_trajectory_koopa, { 7100, -1300, -6000 } }, }; /** @@ -91,6 +91,7 @@ void bhv_koopa_init(void) { */ static void koopa_play_footstep_sound(s8 animFrame1, s8 animFrame2) { s32 sound; + if (o->header.gfx.scale[0] > 1.5f) { sound = SOUND_OBJ_KOOPA_THE_QUICK_WALK; } else { @@ -133,7 +134,7 @@ static void koopa_walk_start(void) { obj_forward_vel_approach(3.0f * o->oKoopaAgility, 0.3f * o->oKoopaAgility); if (cur_obj_init_anim_and_check_if_end(11)) { - o->oSubAction += 1; + o->oSubAction++; o->oKoopaCountdown = random_linear_offset(30, 100); } } @@ -146,9 +147,9 @@ static void koopa_walk(void) { koopa_play_footstep_sound(2, 17); if (o->oKoopaCountdown != 0) { - o->oKoopaCountdown -= 1; + o->oKoopaCountdown--; } else if (cur_obj_check_if_near_animation_end()) { - o->oSubAction += 1; + o->oSubAction++; } } @@ -244,7 +245,7 @@ static void koopa_shelled_act_lying(void) { cur_obj_init_anim_extend(5); koopa_dive_update_speed(0.3f); } else if (o->oKoopaCountdown != 0) { - o->oKoopaCountdown -= 1; + o->oKoopaCountdown--; cur_obj_extend_animation_if_at_end(); } else if (cur_obj_init_anim_and_check_if_end(6)) { o->oAction = KOOPA_SHELLED_ACT_STOPPED; @@ -350,7 +351,7 @@ static void koopa_unshelled_act_run(void) { obj_bounce_off_walls_edges_objects(&o->oKoopaTargetYaw))) { // Otherwise run around randomly if (o->oKoopaUnshelledTimeUntilTurn != 0) { - o->oKoopaUnshelledTimeUntilTurn -= 1; + o->oKoopaUnshelledTimeUntilTurn--; } else { o->oKoopaTargetYaw = obj_random_fixed_turn(0x2000); } @@ -424,7 +425,7 @@ static void koopa_unshelled_act_dive(void) { } koopa_dive_update_speed(0.5f); } else if (o->oKoopaCountdown != 0) { - o->oKoopaCountdown -= 1; + o->oKoopaCountdown--; cur_obj_extend_animation_if_at_end(); } else if (cur_obj_init_anim_and_check_if_end(6)) { o->oAction = KOOPA_UNSHELLED_ACT_RUN; @@ -482,7 +483,7 @@ s32 obj_begin_race(s32 noTimer) { } // Unfreeze mario and disable time stop to begin the race - set_mario_npc_dialog(0); + set_mario_npc_dialog(MARIO_DIALOG_STOP); disable_time_stop_including_mario(); } else if (o->oTimer > 50) { return TRUE; @@ -498,7 +499,7 @@ static void koopa_the_quick_act_wait_before_race(void) { koopa_shelled_act_stopped(); if (o->oKoopaTheQuickInitTextboxCooldown != 0) { - o->oKoopaTheQuickInitTextboxCooldown -= 1; + o->oKoopaTheQuickInitTextboxCooldown--; } else if (cur_obj_can_mario_activate_textbox_2(400.0f, 400.0f)) { //! The next action doesn't execute until next frame, giving mario one // frame where he can jump, and thus no longer be ready to speak. @@ -518,8 +519,8 @@ static void koopa_the_quick_act_show_init_text(void) { s32 response = obj_update_race_proposition_dialog( sKoopaTheQuickProperties[o->oKoopaTheQuickRaceIndex].initText); - if (response == 1) { - UNUSED s32 unused; + if (response == DIALOG_RESPONSE_YES) { + UNUSED u8 filler[4]; gMarioShotFromCannon = FALSE; o->oAction = KOOPA_THE_QUICK_ACT_RACE; @@ -531,7 +532,7 @@ static void koopa_the_quick_act_show_init_text(void) { o->oKoopaTurningAwayFromWall = FALSE; o->oFlags |= OBJ_FLAG_ACTIVE_FROM_AFAR; - } else if (response == 2) { + } else if (response == DIALOG_RESPONSE_NO) { o->oAction = KOOPA_THE_QUICK_ACT_WAIT_BEFORE_RACE; o->oKoopaTheQuickInitTextboxCooldown = 60; } @@ -544,13 +545,12 @@ static void koopa_the_quick_act_show_init_text(void) { static s32 koopa_the_quick_detect_bowling_ball(void) { struct Object *ball; f32 distToBall; - s16 angleToBall; - f32 ballSpeedInKoopaRunDir; ball = cur_obj_find_nearest_object_with_behavior(bhvBowlingBall, &distToBall); + if (ball != NULL) { - angleToBall = obj_turn_toward_object(o, ball, O_MOVE_ANGLE_YAW_INDEX, 0); - ballSpeedInKoopaRunDir = ball->oForwardVel * coss(ball->oMoveAngleYaw - o->oMoveAngleYaw); + s16 angleToBall = obj_turn_toward_object(o, ball, O_MOVE_ANGLE_YAW_INDEX, 0); + f32 ballSpeedInKoopaRunDir = ball->oForwardVel * coss(ball->oMoveAngleYaw - o->oMoveAngleYaw); if (abs_angle_diff(o->oMoveAngleYaw, angleToBall) < 0x4000) { // The ball is in front of ktq @@ -593,9 +593,6 @@ static void koopa_the_quick_animate_footsteps(void) { * down or jumping. After finishing the race, enter the decelerate action. */ static void koopa_the_quick_act_race(void) { - f32 downhillSteepness; - s32 bowlingBallStatus; - if (obj_begin_race(FALSE)) { // Hitbox is slightly larger while racing cur_obj_push_mario_away_from_cylinder(180.0f, 300.0f); @@ -603,6 +600,9 @@ static void koopa_the_quick_act_race(void) { if (cur_obj_follow_path(0) == PATH_REACHED_END) { o->oAction = KOOPA_THE_QUICK_ACT_DECELERATE; } else { + f32 downhillSteepness; + s32 bowlingBallStatus; + downhillSteepness = 1.0f + sins((s16)(f32) o->oPathedTargetPitch); cur_obj_rotate_yaw_toward(o->oPathedTargetYaw, (s32)(o->oKoopaAgility * 150.0f)); @@ -663,7 +663,7 @@ static void koopa_the_quick_act_race(void) { // ktq if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) { if (cur_obj_init_anim_and_check_if_end(13)) { - o->oSubAction -= 1; + o->oSubAction--; } koopa_the_quick_detect_bowling_ball(); @@ -707,7 +707,7 @@ static void koopa_the_quick_act_stop(void) { static void koopa_the_quick_act_after_race(void) { cur_obj_init_animation_with_sound(7); - if (o->parentObj->oKoopaRaceEndpointUnk100 == 0) { + if (o->parentObj->oKoopaRaceEndpointDialog == 0) { if (cur_obj_can_mario_activate_textbox_2(400.0f, 400.0f)) { stop_background_music(SEQUENCE_ARGS(4, SEQ_LEVEL_SLIDE)); @@ -717,29 +717,30 @@ static void koopa_the_quick_act_after_race(void) { if (o->parentObj->oKoopaRaceEndpointRaceStatus < 0) { // Mario cheated o->parentObj->oKoopaRaceEndpointRaceStatus = 0; - o->parentObj->oKoopaRaceEndpointUnk100 = DIALOG_006; + o->parentObj->oKoopaRaceEndpointDialog = DIALOG_006; } else { // Mario won - o->parentObj->oKoopaRaceEndpointUnk100 = + o->parentObj->oKoopaRaceEndpointDialog = sKoopaTheQuickProperties[o->oKoopaTheQuickRaceIndex].winText; } } else { // KtQ won - o->parentObj->oKoopaRaceEndpointUnk100 = DIALOG_041; + o->parentObj->oKoopaRaceEndpointDialog = DIALOG_041; } o->oFlags &= ~OBJ_FLAG_ACTIVE_FROM_AFAR; } - } else if (o->parentObj->oKoopaRaceEndpointUnk100 > 0) { - s32 dialogResponse = cur_obj_update_dialog_with_cutscene(2, 1, CUTSCENE_DIALOG, o->parentObj->oKoopaRaceEndpointUnk100); + } else if (o->parentObj->oKoopaRaceEndpointDialog > 0) { + s32 dialogResponse = cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + DIALOG_FLAG_TURN_TO_MARIO, CUTSCENE_DIALOG, o->parentObj->oKoopaRaceEndpointDialog); if (dialogResponse != 0) { - o->parentObj->oKoopaRaceEndpointUnk100 = -1; + o->parentObj->oKoopaRaceEndpointDialog = DIALOG_NONE; o->oTimer = 0; } } else if (o->parentObj->oKoopaRaceEndpointRaceStatus != 0) { spawn_default_star(sKoopaTheQuickProperties[o->oKoopaTheQuickRaceIndex].starPos[0], - sKoopaTheQuickProperties[o->oKoopaTheQuickRaceIndex].starPos[1], - sKoopaTheQuickProperties[o->oKoopaTheQuickRaceIndex].starPos[2]); + sKoopaTheQuickProperties[o->oKoopaTheQuickRaceIndex].starPos[1], + sKoopaTheQuickProperties[o->oKoopaTheQuickRaceIndex].starPos[2]); o->parentObj->oKoopaRaceEndpointRaceStatus = 0; } @@ -789,6 +790,7 @@ static void koopa_the_quick_update(void) { */ void bhv_koopa_update(void) { // PARTIAL_UPDATE + o->oDeathSound = SOUND_OBJ_KOOPA_FLYGUY_DEATH; if (o->oKoopaMovementType >= KOOPA_BP_KOOPA_THE_QUICK_BASE) { diff --git a/src/game/behaviors/koopa_shell.inc.c b/src/game/behaviors/koopa_shell.inc.c index 1fcbf406..dec89024 100644 --- a/src/game/behaviors/koopa_shell.inc.c +++ b/src/game/behaviors/koopa_shell.inc.c @@ -1,23 +1,25 @@ -// koopa_shell.c.inc +// koopa_shell.inc.c struct ObjectHitbox sKoopaShellHitbox = { - /* interactType: */ INTERACT_KOOPA_SHELL, - /* downOffset: */ 0, + /* interactType: */ INTERACT_KOOPA_SHELL, + /* downOffset: */ 0, /* damageOrCoinValue: */ 4, - /* health: */ 1, - /* numLootCoins: */ 1, - /* radius: */ 50, - /* height: */ 50, - /* hurtboxRadius: */ 50, - /* hurtboxHeight: */ 50, + /* health: */ 1, + /* numLootCoins: */ 1, + /* radius: */ 50, + /* height: */ 50, + /* hurtboxRadius: */ 50, + /* hurtboxHeight: */ 50, }; void koopa_shell_spawn_water_drop(void) { - UNUSED s32 unused; - struct Object *drop; + UNUSED u8 filler[4]; + spawn_object(o, MODEL_WAVE_TRAIL, bhvObjectWaveTrail); + if (gMarioStates[0].forwardVel > 10.0f) { - drop = spawn_object_with_scale(o, MODEL_WHITE_PARTICLE_SMALL, bhvWaterDroplet, 1.5f); + struct Object *drop = spawn_object_with_scale(o, MODEL_WHITE_PARTICLE_SMALL, + bhvWaterDroplet, 1.5f); drop->oVelY = random_float() * 30.0f; obj_translate_xz_random(drop, 110.0f); } @@ -30,20 +32,25 @@ void bhv_koopa_shell_flame_loop(void) { o->oGravity = -4.0f; o->oAnimState = random_float() * 10.0f; obj_translate_xz_random(o, 110.0f); - o->oKoopaShellFlameUnkF8 = 4.0f; + o->oKoopaShellFlameScale = 4.0f; } + cur_obj_update_floor_height(); cur_obj_move_using_fvel_and_gravity(); - if (o->oFloorHeight > o->oPosY || o->oTimer > 10) + + if (o->oFloorHeight > o->oPosY || o->oTimer > 10) { obj_mark_for_deletion(o); - o->oKoopaShellFlameUnkF8 += -0.3; - cur_obj_scale(o->oKoopaShellFlameUnkF8); + } + + o->oKoopaShellFlameScale += -0.3; + cur_obj_scale(o->oKoopaShellFlameScale); } void bhv_koopa_shell_flame_spawn(void) { s32 i; - for (i = 0; i < 2; i++) + for (i = 0; i < 2; i++) { spawn_object(o, MODEL_RED_FLAME, bhvKoopaShellFlame); + } } void koopa_shell_spawn_sparkles(f32 a) { @@ -53,31 +60,42 @@ void koopa_shell_spawn_sparkles(f32 a) { void bhv_koopa_shell_loop(void) { struct Surface *sp34; + obj_set_hitbox(o, &sKoopaShellHitbox); cur_obj_scale(1.0f); + switch (o->oAction) { case 0: cur_obj_update_floor_and_walls(); cur_obj_if_hit_wall_bounce_away(); - if (o->oInteractStatus & INT_STATUS_INTERACTED) + + if (o->oInteractStatus & INT_STATUS_INTERACTED) { o->oAction++; + } + o->oFaceAngleYaw += 0x1000; cur_obj_move_standard(-20); koopa_shell_spawn_sparkles(10.0f); break; + case 1: obj_copy_pos(o, gMarioObject); sp34 = cur_obj_update_floor_height_and_get_floor(); - if (absf(find_water_level(o->oPosX, o->oPosZ) - o->oPosY) < 10.0f) + + if (absf(find_water_level(o->oPosX, o->oPosZ) - o->oPosY) < 10.0f) { koopa_shell_spawn_water_drop(); - else if (5.0f > absf(o->oPosY - o->oFloorHeight)) { - if (sp34 != NULL && sp34->type == 1) + } else if (absf(o->oPosY - o->oFloorHeight) < 5.0f) { + if (sp34 != NULL && sp34->type == 1) { bhv_koopa_shell_flame_spawn(); - else + } else { koopa_shell_spawn_sparkles(10.0f); - } else + } + } else { koopa_shell_spawn_sparkles(10.0f); + } + o->oFaceAngleYaw = gMarioObject->oMoveAngleYaw; + if (o->oInteractStatus & INT_STATUS_STOP_RIDING) { obj_mark_for_deletion(o); spawn_mist_particles(); @@ -85,5 +103,6 @@ void bhv_koopa_shell_loop(void) { } break; } + o->oInteractStatus = 0; } diff --git a/src/game/behaviors/koopa_shell_underwater.inc.c b/src/game/behaviors/koopa_shell_underwater.inc.c index ff0eef70..9b06618a 100644 --- a/src/game/behaviors/koopa_shell_underwater.inc.c +++ b/src/game/behaviors/koopa_shell_underwater.inc.c @@ -1,15 +1,15 @@ -// koopa_shell_underwater.c.inc +// koopa_shell_underwater.inc.c struct ObjectHitbox sKoopaShellUnderwaterHitbox = { - /* interactType: */ INTERACT_GRABBABLE, - /* downOffset: */ 0, + /* interactType: */ INTERACT_GRABBABLE, + /* downOffset: */ 0, /* damageOrCoinValue: */ 0, - /* health: */ 1, - /* numLootCoins: */ 0, - /* radius: */ 80, - /* height: */ 50, - /* hurtboxRadius: */ 0, - /* hurtboxHeight: */ 0, + /* health: */ 1, + /* numLootCoins: */ 0, + /* radius: */ 80, + /* height: */ 50, + /* hurtboxRadius: */ 0, + /* hurtboxHeight: */ 0, }; void set_koopa_shell_underwater_hitbox(void) { @@ -22,7 +22,7 @@ void bhv_koopa_shell_underwater_loop(void) { set_koopa_shell_underwater_hitbox(); break; case HELD_HELD: - cur_obj_unrender_and_reset_state(-1, 0); + cur_obj_unrender_set_action_and_anim(-1, 0); break; case HELD_THROWN: case HELD_DROPPED: @@ -30,9 +30,11 @@ void bhv_koopa_shell_underwater_loop(void) { spawn_mist_particles(); break; } + if (o->oInteractStatus & INT_STATUS_STOP_RIDING) { obj_mark_for_deletion(o); spawn_mist_particles(); } + o->oInteractStatus = 0; } diff --git a/src/game/behaviors/lll_floating_wood_piece.inc.c b/src/game/behaviors/lll_floating_wood_piece.inc.c index cb4dad48..6abb42a1 100644 --- a/src/game/behaviors/lll_floating_wood_piece.inc.c +++ b/src/game/behaviors/lll_floating_wood_piece.inc.c @@ -1,32 +1,40 @@ -// lll_floating_wood_piece.c.inc +// lll_floating_wood_piece.inc.c void bhv_lll_wood_piece_loop(void) { - if (o->oTimer == 0) + if (o->oTimer == 0) { o->oPosY -= 100.0f; + } + o->oPosY += sins(o->oLllWoodPieceOscillationTimer) * 3.0f; o->oLllWoodPieceOscillationTimer += 0x400; - if (o->parentObj->oAction == 2) + + if (o->parentObj->oAction == 2) { obj_mark_for_deletion(o); + } } void bhv_lll_floating_wood_bridge_loop(void) { struct Object *sp3C; s32 i; + switch (o->oAction) { case 0: if (o->oDistanceToMario < 2500.0f) { for (i = 1; i < 4; i++) { - sp3C = spawn_object_relative(0, (i - 2) * 300, 0, 0, o, MODEL_LLL_WOOD_BRIDGE, - bhvLllWoodPiece); - sp3C->oLllWoodPieceOscillationTimer = i * 4096; + sp3C = spawn_object_relative(0, (i - 2) * 300, 0, 0, o, + MODEL_LLL_WOOD_BRIDGE, bhvLllWoodPiece); + sp3C->oLllWoodPieceOscillationTimer = i * 0x1000; } o->oAction = 1; } break; + case 1: - if (o->oDistanceToMario > 2600.0f) + if (o->oDistanceToMario > 2600.0f) { o->oAction = 2; + } break; + case 2: o->oAction = 0; break; diff --git a/src/game/behaviors/lll_hexagonal_ring.inc.c b/src/game/behaviors/lll_hexagonal_ring.inc.c index a0a4d6b7..28a34565 100644 --- a/src/game/behaviors/lll_hexagonal_ring.inc.c +++ b/src/game/behaviors/lll_hexagonal_ring.inc.c @@ -1,51 +1,72 @@ -// lll_hexagonal_ring.c.inc +// lll_hexagonal_ring.inc.c void hexagonal_ring_spawn_flames(void) { - struct Object *sp1C; + struct Object *sp1C = spawn_object(o, MODEL_RED_FLAME, bhvVolcanoFlames); f32 size; - sp1C = spawn_object(o, MODEL_RED_FLAME, bhvVolcanoFlames); + sp1C->oPosY += 550.0f; - sp1C->oMoveAngleYaw = random_u16() << 0x10 >> 0x10; + sp1C->oMoveAngleYaw = (s16) random_u16(); sp1C->oForwardVel = random_float() * 40.0f + 20.0f; sp1C->oVelY = random_float() * 50.0f + 10.0f; + size = random_float() * 6.0 + 3.0; + obj_scale_xyz(sp1C, size, size, size); - if (random_float() < 0.1) + + if (random_float() < 0.1) { cur_obj_play_sound_2(SOUND_GENERAL_VOLCANO_EXPLOSION); + } } void bhv_lll_rotating_hexagonal_ring_loop(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; + o->oCollisionDistance = 4000.0f; o->oDrawingDistance = 8000.0f; + switch (o->oAction) { case 0: - if (gMarioObject->platform == o) + if (gMarioObject->platform == o) { o->oAction++; + } + o->oAngleVelYaw = 0x100; break; + case 1: - o->oAngleVelYaw = 256.0f - sins(o->oTimer << 7) * 256.0f; - if (o->oTimer > 128) + o->oAngleVelYaw = 256.0f - sins(o->oTimer * 128) * 256.0f; + + if (o->oTimer > 128) { o->oAction++; + } break; + case 2: - if (gMarioObject->platform != o) + if (gMarioObject->platform != o) { o->oAction++; - if (o->oTimer > 128) + } + + if (o->oTimer > 128) { o->oAction++; + } + o->oAngleVelYaw = 0; hexagonal_ring_spawn_flames(); break; + case 3: - o->oAngleVelYaw = sins(o->oTimer << 7) * 256.0f; - if (o->oTimer > 128) + o->oAngleVelYaw = sins(o->oTimer * 128) * 256.0f; + + if (o->oTimer > 128) { o->oAction = 0; + } break; + case 4: o->oAction = 0; break; } + o->oAngleVelYaw = -o->oAngleVelYaw; o->oMoveAngleYaw += o->oAngleVelYaw; } diff --git a/src/game/behaviors/lll_octagonal_rotating_mesh.inc.c b/src/game/behaviors/lll_octagonal_rotating_mesh.inc.c index 7fc4936f..054723fd 100644 --- a/src/game/behaviors/lll_octagonal_rotating_mesh.inc.c +++ b/src/game/behaviors/lll_octagonal_rotating_mesh.inc.c @@ -1,4 +1,4 @@ -// lll_octagonal_rotating_mesh.c.inc +// lll_octagonal_rotating_mesh.inc.c s16 D_8032F860[] = { 2, 30, 0x4000, 0, 1, 220, 900, 30, 1, 30, 0, -30, 2, 30, -0x4000, 0, 1, 220, 900, 30, 1, 30, 0, -30, 3, 0 }; @@ -6,7 +6,6 @@ s16 D_8032F894[] = { 4, 0, 0, 0, 1, 475, 900, 30, 1, 30, 0, -30, 2, 30, 0x8000, 0, 1, 475, 900, 30, 1, 30, 0, -30, 3, 0 }; s16 *D_8032F8C8[] = { D_8032F860, D_8032F894 }; - s32 lll_octagonal_mesh_move(s16 *a0, s32 a1) { switch (a0[a1]) { case 4: @@ -17,6 +16,7 @@ s32 lll_octagonal_mesh_move(s16 *a0, s32 a1) { o->oTimer = 0; } break; + case 2: o->oMoveAngleYaw = a0[a1 + 2]; o->oForwardVel = a0[a1 + 3] / 100.0f; @@ -25,6 +25,7 @@ s32 lll_octagonal_mesh_move(s16 *a0, s32 a1) { o->oTimer = 0; } break; + case 1: approach_f32_signed(&o->oForwardVel, a0[a1 + 2] / 100.0f, a0[a1 + 3] / 100.0f); if (o->oTimer > a0[a1 + 1]) { @@ -32,45 +33,57 @@ s32 lll_octagonal_mesh_move(s16 *a0, s32 a1) { o->oTimer = 0; } break; + case 3: o->oForwardVel = 0.0f; a1 = 0; break; } + return a1; } s32 lll_octagonal_mesh_find_y_offset(s32 *a0, f32 *a1, s32 a2, s32 a3) { if (cur_obj_is_mario_on_platform()) { - if (a0[0] < 0x4000) + if (a0[0] < 0x4000) { a0[0] += a2; - else + } else { a0[0] = 0x4000; + } } else { - if (a0[0] > 0) + if (a0[0] > 0) { a0[0] -= a2; - else + } else { a0[0] = 0; + } } + a1[0] = sins(a0[0]) * a3; - if (a0[0] == 0 || a0[0] == 0x4000) - return 1; - else - return 0; + + if (a0[0] == 0 || a0[0] == 0x4000) { + return TRUE; + } else { + return FALSE; + } } void bhv_lll_moving_octagonal_mesh_platform_loop(void) { if (o->oAction == 0) { o->oHorizontalMovementUnkF8 = 0; o->oAction++; - } else + } else { o->oHorizontalMovementUnkF8 = lll_octagonal_mesh_move(D_8032F8C8[o->oBehParams2ndByte], o->oHorizontalMovementUnkF8); + } + print_debug_top_down_objectinfo("number %d\n", o->oHorizontalMovementUnkF8); cur_obj_move_using_fvel_and_gravity(); - if (lll_octagonal_mesh_find_y_offset(&o->oHorizontalMovementUnk104, &o->oHorizontalMovementUnk108, 0x400, -80)) { + + if (lll_octagonal_mesh_find_y_offset(&o->oHorizontalMovementUnk104, + &o->oHorizontalMovementUnk108, 0x400, -80)) { o->oHorizontalMovementUnkF4 += 0x800; o->oHorizontalMovementUnk100 -= sins(o->oHorizontalMovementUnkF4) * 2; } + o->oPosY = o->oHorizontalMovementUnk100 + o->oHomeY + o->oHorizontalMovementUnk108; } diff --git a/src/game/behaviors/lll_rotating_hex_flame.inc.c b/src/game/behaviors/lll_rotating_hex_flame.inc.c index efabfca8..4637f317 100644 --- a/src/game/behaviors/lll_rotating_hex_flame.inc.c +++ b/src/game/behaviors/lll_rotating_hex_flame.inc.c @@ -1,23 +1,28 @@ -// lll_rotating_hex_flame.c.inc +// lll_rotating_hex_flame.inc.c void bhv_lll_rotating_hex_flame_loop(void) { f32 sp24 = o->oLllRotatingHexFlameUnkF4; f32 sp20 = o->oLllRotatingHexFlameUnkF8; f32 sp1C = o->oLllRotatingHexFlameUnkFC; + cur_obj_set_pos_relative(o->parentObj, sp24, sp20, sp1C); o->oPosY = o->parentObj->oPosY + 100.0f; - if (o->parentObj->oAction == 3) + + if (o->parentObj->oAction == 3) { obj_mark_for_deletion(o); + } } void fire_bar_spawn_flames(s16 a0) { struct Object *sp2C; - UNUSED s32 unused; + UNUSED u8 filler[4]; s32 i; s32 sp20; f32 sp1C = sins(a0) * 200.0f; f32 sp18 = coss(a0) * 200.0f; - sp20 = (o->oBehParams2ndByte == 0) ? 4 : 3; + + sp20 = o->oBehParams2ndByte == 0 ? 4 : 3; + for (i = 0; i < sp20; i++) { sp2C = spawn_object(o, MODEL_RED_FLAME, bhvLllRotatingHexFlame); sp2C->oLllRotatingHexFlameUnkF4 += sp1C; @@ -30,8 +35,9 @@ void fire_bar_spawn_flames(s16 a0) { } void fire_bar_act_0(void) { - if (o->oDistanceToMario < 3000.0f) + if (o->oDistanceToMario < 3000.0f) { o->oAction = 1; + } } void fire_bar_act_1(void) { @@ -45,19 +51,25 @@ void fire_bar_act_1(void) { void fire_bar_act_2(void) { o->oAngleVelYaw = -0x100; o->oMoveAngleYaw += o->oAngleVelYaw; - if (o->oDistanceToMario > 3200.0f) + if (o->oDistanceToMario > 3200.0f) { o->oAction = 3; + } } void fire_bar_act_3(void) { o->oAction = 0; } -void (*sRotatingCwFireBarsActions[])(void) = { fire_bar_act_0, fire_bar_act_1, - fire_bar_act_2, fire_bar_act_3 }; +void (*sRotatingCwFireBarsActions[])(void) = { + fire_bar_act_0, + fire_bar_act_1, + fire_bar_act_2, + fire_bar_act_3, +}; void bhv_lll_rotating_block_fire_bars_loop(void) { cur_obj_call_action_function(sRotatingCwFireBarsActions); - if (o->oBehParams2ndByte == 0) + if (o->oBehParams2ndByte == 0) { load_object_collision_model(); + } } diff --git a/src/game/behaviors/lll_sinking_rectangle.inc.c b/src/game/behaviors/lll_sinking_rectangle.inc.c index bda4a844..22d8fd8a 100644 --- a/src/game/behaviors/lll_sinking_rectangle.inc.c +++ b/src/game/behaviors/lll_sinking_rectangle.inc.c @@ -1,14 +1,16 @@ -// lll_sinking_rectangle.c.inc +// lll_sinking_rectangle.inc.c void sinking_rectangular_plat_actions(f32 a0, s32 a1) { switch (o->oAction) { case 0: o->oAction++; break; + case 1: o->oPosY -= sins(o->oLllWoodPieceOscillationTimer) * a0; o->oLllWoodPieceOscillationTimer += a1; break; + case 2: break; break; // Two breaks needed? @@ -18,10 +20,11 @@ void sinking_rectangular_plat_actions(f32 a0, s32 a1) { void bhv_lll_sinking_rectangular_platform_loop(void) { f32 sp1C = 0.4f; s32 sp18 = 0x100; - if (o->oMoveAngleYaw != 0) + + if (o->oMoveAngleYaw != 0) { sinking_rectangular_plat_actions(sp1C, sp18); - else { - o->oFaceAnglePitch = sins(o->oLllWoodPieceOscillationTimer) * 512.0f; + } else { + o->oFaceAnglePitch = sins(o->oLllWoodPieceOscillationTimer) * 0x200; o->oLllWoodPieceOscillationTimer += 0x100; } } @@ -29,5 +32,6 @@ void bhv_lll_sinking_rectangular_platform_loop(void) { void bhv_lll_sinking_square_platforms_loop(void) { f32 sp1C = 0.5f; s32 sp18 = 0x100; + sinking_rectangular_plat_actions(sp1C, sp18); } diff --git a/src/game/behaviors/lll_sinking_rock_block.inc.c b/src/game/behaviors/lll_sinking_rock_block.inc.c index 056d0aaa..d057abe2 100644 --- a/src/game/behaviors/lll_sinking_rock_block.inc.c +++ b/src/game/behaviors/lll_sinking_rock_block.inc.c @@ -1,7 +1,8 @@ -// lll_sinking_rock_block.c.inc +// lll_sinking_rock_block.inc.c void bhv_lll_sinking_rock_block_loop(void) { - lll_octagonal_mesh_find_y_offset(&o->oSinkWhenSteppedOnUnk104, &o->oSinkWhenSteppedOnUnk108, 124, -110); + lll_octagonal_mesh_find_y_offset(&o->oSinkWhenSteppedOnUnk104, + &o->oSinkWhenSteppedOnUnk108, 124, -110); o->oGraphYOffset = 0.0f; o->oPosY = o->oHomeY + o->oSinkWhenSteppedOnUnk108; } diff --git a/src/game/behaviors/lll_volcano_flames.inc.c b/src/game/behaviors/lll_volcano_flames.inc.c index aa2fbc6f..204521b3 100644 --- a/src/game/behaviors/lll_volcano_flames.inc.c +++ b/src/game/behaviors/lll_volcano_flames.inc.c @@ -1,13 +1,16 @@ -// lll_volcano_flames.c.inc +// lll_volcano_flames.inc.c void bhv_volcano_flames_loop(void) { cur_obj_update_floor_height(); cur_obj_compute_vel_xz(); + o->oPosX += o->oVelX; o->oPosZ += o->oVelZ; + cur_obj_move_y(-4.0f, -0.7f, 2.0f); - if (o->oMoveFlags & (OBJ_MOVE_MASK_ON_GROUND | OBJ_MOVE_AT_WATER_SURFACE - | OBJ_MOVE_UNDERWATER_OFF_GROUND)) + if (o->oMoveFlags & (OBJ_MOVE_MASK_ON_GROUND | OBJ_MOVE_AT_WATER_SURFACE + | OBJ_MOVE_UNDERWATER_OFF_GROUND)) { obj_mark_for_deletion(o); + } } diff --git a/src/game/behaviors/mad_piano.inc.c b/src/game/behaviors/mad_piano.inc.c index efefaba4..70d816d1 100644 --- a/src/game/behaviors/mad_piano.inc.c +++ b/src/game/behaviors/mad_piano.inc.c @@ -1,3 +1,4 @@ +// mad_piano.inc.c static struct ObjectHitbox sMadPianoHitbox = { /* interactType: */ INTERACT_MR_BLIZZARD, @@ -15,11 +16,9 @@ static void mad_piano_act_wait(void) { cur_obj_init_animation_with_sound(0); if (o->oDistanceToMario < 500.0f) { - if (o->oTimer > 20) { - if (gMarioStates[0].forwardVel > 10.0f) { - o->oAction = MAD_PIANO_ACT_ATTACK; - cur_obj_become_tangible(); - } + if (o->oTimer > 20 && gMarioStates[0].forwardVel > 10.0f) { + o->oAction = MAD_PIANO_ACT_ATTACK; + cur_obj_become_tangible(); } } else { o->oTimer = 0; diff --git a/src/game/behaviors/manta_ray.inc.c b/src/game/behaviors/manta_ray.inc.c index 4b79abc3..62224840 100644 --- a/src/game/behaviors/manta_ray.inc.c +++ b/src/game/behaviors/manta_ray.inc.c @@ -1,3 +1,4 @@ + /** * @file Behavior file for the manta ray in DDD. * @@ -33,27 +34,29 @@ static struct ObjectHitbox sMantaRayHitbox = { * Initializes the manta ray when spawned. */ void bhv_manta_ray_init(void) { - struct Object *ringManager; - ringManager = spawn_object(o, MODEL_NONE, bhvMantaRayRingManager); + struct Object *ringManager = spawn_object(o, MODEL_NONE, bhvMantaRayRingManager); o->parentObj = ringManager; obj_set_hitbox(o, &sMantaRayHitbox); cur_obj_scale(2.5f); } static void manta_ray_move(void) { - s16 animFrame; + s16 animFrame = o->header.gfx.animInfo.animFrame; s32 pathStatus; +#ifdef AVOID_UB + pathStatus = 0; +#endif - animFrame = o->header.gfx.animInfo.animFrame; - gCurrentObject->oPathedStartWaypoint = (struct Waypoint *) sMantaRayTraj; + o->oPathedStartWaypoint = (struct Waypoint *) sMantaRayTraj; pathStatus = cur_obj_follow_path(pathStatus); + o->oMantaTargetYaw = o->oPathedTargetYaw; o->oMantaTargetPitch = o->oPathedTargetPitch; o->oForwardVel = 10.0f; - o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oMantaTargetYaw, 0x80); + o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oMantaTargetYaw, 0x80); o->oMoveAnglePitch = approach_s16_symmetric(o->oMoveAnglePitch, o->oMantaTargetPitch, 0x80); - + // This causes the ray to tilt as it turns. if ((s16) o->oMantaTargetYaw != (s16) o->oMoveAngleYaw) { o->oMoveAngleRoll -= 91; @@ -75,14 +78,13 @@ static void manta_ray_move(void) { static void manta_ray_act_spawn_ring(void) { struct Object *ringManager = o->parentObj; - struct Object *ring; if (o->oTimer == 300) { o->oTimer = 0; } if (o->oTimer == 0 || o->oTimer == 50 || o->oTimer == 150 || o->oTimer == 200 || o->oTimer == 250) { - ring = spawn_object(o, MODEL_WATER_RING, bhvMantaRayWaterRing); + struct Object *ring = spawn_object(o, MODEL_WATER_RING, bhvMantaRayWaterRing); ring->oFaceAngleYaw = o->oMoveAngleYaw; ring->oFaceAnglePitch = o->oMoveAnglePitch + 0x4000; diff --git a/src/game/behaviors/metal_box.inc.c b/src/game/behaviors/metal_box.inc.c index ce3957bf..c0dddc60 100644 --- a/src/game/behaviors/metal_box.inc.c +++ b/src/game/behaviors/metal_box.inc.c @@ -1,15 +1,15 @@ -// metal_box.c.inc +// metal_box.inc.c struct ObjectHitbox sMetalBoxHitbox = { - /* interactType: */ 0, - /* downOffset: */ 0, + /* interactType: */ 0, + /* downOffset: */ 0, /* damageOrCoinValue: */ 0, - /* health: */ 1, - /* numLootCoins: */ 0, - /* radius: */ 220, - /* height: */ 300, - /* hurtboxRadius: */ 220, - /* hurtboxHeight: */ 300, + /* health: */ 1, + /* numLootCoins: */ 0, + /* radius: */ 220, + /* height: */ 300, + /* hurtboxRadius: */ 220, + /* hurtboxHeight: */ 300, }; s32 check_if_moving_over_floor(f32 a0, f32 a1) { @@ -17,27 +17,33 @@ s32 check_if_moving_over_floor(f32 a0, f32 a1) { f32 sp20 = o->oPosX + sins(o->oMoveAngleYaw) * a1; f32 floorHeight; f32 sp18 = o->oPosZ + coss(o->oMoveAngleYaw) * a1; + floorHeight = find_floor(sp20, o->oPosY, sp18, &sp24); - if (absf(floorHeight - o->oPosY) < a0) // abs - return 1; - else - return 0; + + if (absf(floorHeight - o->oPosY) < a0) { + return TRUE; + } else { + return FALSE; + } } void bhv_pushable_loop(void) { UNUSED s16 unused; - s16 sp1C; + obj_set_hitbox(o, &sMetalBoxHitbox); o->oForwardVel = 0.0f; - if (obj_check_if_collided_with_object(o, gMarioObject) && gMarioStates[0].flags & MARIO_UNKNOWN_31) { - sp1C = obj_angle_to_object(o, gMarioObject); + + if (obj_check_if_collided_with_object(o, gMarioObject) + && (gMarioStates[0].flags & MARIO_UNKNOWN_31)) { + s16 sp1C = obj_angle_to_object(o, gMarioObject); if (abs_angle_diff(sp1C, gMarioObject->oMoveAngleYaw) > 0x4000) { - o->oMoveAngleYaw = (s16)((gMarioObject->oMoveAngleYaw + 0x2000) & 0xc000); + o->oMoveAngleYaw = (s16)((gMarioObject->oMoveAngleYaw + 0x2000) & 0xC000); if (check_if_moving_over_floor(8.0f, 150.0f)) { o->oForwardVel = 4.0f; cur_obj_play_sound_1(SOUND_ENV_METAL_BOX_PUSH); } } } + cur_obj_move_using_fvel_and_gravity(); } diff --git a/src/game/behaviors/mips.inc.c b/src/game/behaviors/mips.inc.c index 980457eb..0aed1ec9 100644 --- a/src/game/behaviors/mips.inc.c +++ b/src/game/behaviors/mips.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for MIPS (everyone's favorite yellow rabbit). */ @@ -8,7 +9,7 @@ */ void bhv_mips_init(void) { // Retrieve star flags for Castle Secret Stars on current save file. - u8 starFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, -1); + u8 starFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(COURSE_NONE)); // If the player has >= 15 stars and hasn't collected first MIPS star... if (save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1) >= 15 @@ -53,14 +54,11 @@ s16 bhv_mips_find_furthest_waypoint_to_mario(void) { s16 furthestWaypointIndex = -1; f32 furthestWaypointDistance = -10000.0f; f32 distanceToMario; - struct Waypoint **pathBase; - struct Waypoint *waypoint; - - pathBase = segmented_to_virtual(&inside_castle_seg7_trajectory_mips); + struct Waypoint **pathBase = segmented_to_virtual(&inside_castle_seg7_trajectory_mips); // For each waypoint in MIPS path... for (i = 0; i < 10; i++) { - waypoint = segmented_to_virtual(pathBase[i]); + struct Waypoint *waypoint = segmented_to_virtual(pathBase[i]); x = waypoint->pos[0]; y = waypoint->pos[1]; z = waypoint->pos[2]; @@ -111,12 +109,13 @@ void bhv_mips_act_wait_for_nearby_mario(void) { void bhv_mips_act_follow_path(void) { s16 collisionFlags = 0; s32 followStatus; - struct Waypoint **pathBase; - struct Waypoint *waypoint; +#ifdef AVOID_UB + followStatus = 0; +#endif // Retrieve current waypoint. - pathBase = segmented_to_virtual(&inside_castle_seg7_trajectory_mips); - waypoint = segmented_to_virtual(*(pathBase + o->oMipsStartWaypointIndex)); + struct Waypoint **pathBase = segmented_to_virtual(&inside_castle_seg7_trajectory_mips); + struct Waypoint *waypoint = segmented_to_virtual(*(pathBase + o->oMipsStartWaypointIndex)); // Set start waypoint and follow the path from there. o->oPathedStartWaypoint = waypoint; @@ -138,10 +137,10 @@ void bhv_mips_act_follow_path(void) { } // Play sounds during walk animation. - if (cur_obj_check_if_near_animation_end() == 1 && (collisionFlags & OBJ_COL_FLAG_UNDERWATER)) { + if (cur_obj_check_if_near_animation_end() == TRUE && (collisionFlags & OBJ_COL_FLAG_UNDERWATER)) { cur_obj_play_sound_2(SOUND_OBJ_MIPS_RABBIT_WATER); spawn_object(o, MODEL_NONE, bhvShallowWaterSplash); - } else if (cur_obj_check_if_near_animation_end() == 1) { + } else if (cur_obj_check_if_near_animation_end() == TRUE) { cur_obj_play_sound_2(SOUND_OBJ_MIPS_RABBIT); } } @@ -150,7 +149,7 @@ void bhv_mips_act_follow_path(void) { * Seems to wait until the current animation is done, then go idle. */ void bhv_mips_act_wait_for_animation_done(void) { - if (cur_obj_check_if_near_animation_end() == 1) { + if (cur_obj_check_if_near_animation_end() == TRUE) { cur_obj_init_animation(0); o->oAction = MIPS_ACT_IDLE; } @@ -160,20 +159,20 @@ void bhv_mips_act_wait_for_animation_done(void) { * Handles MIPS falling down after being thrown. */ void bhv_mips_act_fall_down(void) { - s16 collisionFlags = 0; collisionFlags = object_step(); o->header.gfx.animInfo.animFrame = 0; - if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) == 1) { + if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) == OBJ_COL_FLAG_GROUNDED) { o->oAction = MIPS_ACT_WAIT_FOR_ANIMATION_DONE; o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; o->oMoveAngleYaw = o->oFaceAngleYaw; - if (collisionFlags & OBJ_COL_FLAG_UNDERWATER) + if (collisionFlags & OBJ_COL_FLAG_UNDERWATER) { spawn_object(o, MODEL_NONE, bhvShallowWaterSplash); + } } } @@ -183,7 +182,7 @@ void bhv_mips_act_fall_down(void) { void bhv_mips_act_idle(void) { UNUSED s16 collisionFlags = 0; - o->oForwardVel = 0; + o->oForwardVel = 0.0f; collisionFlags = object_step(); // Spawn a star if he was just picked up for the first time. @@ -234,18 +233,19 @@ void bhv_mips_held(void) { // If MIPS hasn't spawned his star yet... if (o->oMipsStarStatus == MIPS_STAR_STATUS_HAVENT_SPAWNED_STAR) { // Choose dialog based on which MIPS encounter this is. - if (o->oBehParams2ndByte == 0) + if (o->oBehParams2ndByte == 0) { dialogID = DIALOG_084; - else + } else { dialogID = DIALOG_162; + } - if (set_mario_npc_dialog(1) == 2) { + if (set_mario_npc_dialog(MARIO_DIALOG_LOOK_FRONT) == MARIO_DIALOG_STATUS_SPEAK) { o->activeFlags |= ACTIVE_FLAG_INITIATED_TIME_STOP; - if (cutscene_object_with_dialog(CUTSCENE_DIALOG, o, dialogID)) { + if (cutscene_object_with_dialog(CUTSCENE_DIALOG, o, dialogID) != 0) { o->oInteractionSubtype |= INT_SUBTYPE_DROP_IMMEDIATELY; o->activeFlags &= ~ACTIVE_FLAG_INITIATED_TIME_STOP; o->oMipsStarStatus = MIPS_STAR_STATUS_SHOULD_SPAWN_STAR; - set_mario_npc_dialog(0); + set_mario_npc_dialog(MARIO_DIALOG_STOP); } } } diff --git a/src/game/behaviors/moat_drainer.inc.c b/src/game/behaviors/moat_drainer.inc.c index 0c719c83..68db956a 100644 --- a/src/game/behaviors/moat_drainer.inc.c +++ b/src/game/behaviors/moat_drainer.inc.c @@ -1,4 +1,4 @@ -// moat_drainer.c.inc +// moat_drainer.inc.c void bhv_invisible_objects_under_bridge_init(void) { if (save_file_get_flags() & SAVE_FLAG_MOAT_DRAINED) { diff --git a/src/game/behaviors/moat_grill.inc.c b/src/game/behaviors/moat_grill.inc.c index e2b4da82..7ccfa966 100644 --- a/src/game/behaviors/moat_grill.inc.c +++ b/src/game/behaviors/moat_grill.inc.c @@ -1,8 +1,9 @@ -// moat_grill.c.inc +// moat_grill.inc.c void bhv_moat_grills_loop(void) { - if (save_file_get_flags() & SAVE_FLAG_MOAT_DRAINED) + if (save_file_get_flags() & SAVE_FLAG_MOAT_DRAINED) { cur_obj_set_model(MODEL_NONE); - else + } else { load_object_collision_model(); + } } diff --git a/src/game/behaviors/moneybag.inc.c b/src/game/behaviors/moneybag.inc.c index 7c366632..9f819208 100644 --- a/src/game/behaviors/moneybag.inc.c +++ b/src/game/behaviors/moneybag.inc.c @@ -1,4 +1,4 @@ -// moneybag.c.inc +// moneybag.inc.c static struct ObjectHitbox sMoneybagHitbox = { /* interactType: */ INTERACT_BOUNCE_TOP, @@ -35,16 +35,13 @@ void bhv_moneybag_init(void) { void moneybag_check_mario_collision(void) { obj_set_hitbox(o, &sMoneybagHitbox); - if (o->oInteractStatus & INT_STATUS_INTERACTED) /* bit 15 */ - { - if (o->oInteractStatus & INT_STATUS_ATTACKED_MARIO) /* bit 13 */ - { + if (o->oInteractStatus & INT_STATUS_INTERACTED) { + if (o->oInteractStatus & INT_STATUS_ATTACKED_MARIO) { o->oMoveAngleYaw = o->oAngleToMario + 0x8000; o->oVelY = 30.0f; } - if (o->oInteractStatus & INT_STATUS_WAS_ATTACKED) /* bit 14 */ - { + if (o->oInteractStatus & INT_STATUS_WAS_ATTACKED) { o->oAction = MONEYBAG_ACT_DEATH; } @@ -52,8 +49,6 @@ void moneybag_check_mario_collision(void) { } } -// sp20 = collisionFlags - void moneybag_jump(s8 collisionFlags) { s16 animFrame = o->header.gfx.animInfo.animFrame; @@ -65,7 +60,7 @@ void moneybag_jump(s8 collisionFlags) { o->oVelY = 40.0f; } - if (cur_obj_check_if_near_animation_end() == 1) { + if (cur_obj_check_if_near_animation_end() == TRUE) { o->oMoneybagJumpState = MONEYBAG_JUMP_JUMP; cur_obj_play_sound_2(SOUND_GENERAL_BOING2_LOWPRIO); } @@ -74,8 +69,7 @@ void moneybag_jump(s8 collisionFlags) { case MONEYBAG_JUMP_JUMP: cur_obj_init_animation(2); - if ((collisionFlags & 1) == 1) /* bit 0 */ - { + if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) == OBJ_COL_FLAG_GROUNDED) { o->oForwardVel = 0; o->oVelY = 0; o->oMoneybagJumpState = MONEYBAG_JUMP_LANDING; @@ -85,15 +79,16 @@ void moneybag_jump(s8 collisionFlags) { case MONEYBAG_JUMP_JUMP_AND_BOUNCE: cur_obj_init_animation(3); - if (cur_obj_check_if_near_animation_end() == 1) + if (cur_obj_check_if_near_animation_end() == TRUE) { o->oMoneybagJumpState = MONEYBAG_JUMP_LANDING; + } break; case MONEYBAG_JUMP_WALK_AROUND: cur_obj_init_animation(4); o->oForwardVel = 10.0f; - if (o->oTimer >= 61) { + if (o->oTimer > 60) { o->oMoneybagJumpState = MONEYBAG_JUMP_LANDING; o->oForwardVel = 0; o->header.gfx.animInfo.animFrame = 0; @@ -119,16 +114,18 @@ void moneybag_act_move_around(void) { if ((s32)(random_float() * 6.0f) == 1) { o->oMoneybagJumpState = MONEYBAG_JUMP_WALK_AROUND; o->oTimer = 0; - } else + } else { o->oMoneybagJumpState = MONEYBAG_JUMP_PREPARE; + } } moneybag_jump(collisionFlags); moneybag_check_mario_collision(); if (!is_point_within_radius_of_mario(o->oHomeX, o->oHomeY, o->oHomeZ, 800) - && ((collisionFlags & OBJ_COL_FLAGS_LANDED) == OBJ_COL_FLAGS_LANDED)) + && ((collisionFlags & OBJ_COL_FLAGS_LANDED) == OBJ_COL_FLAGS_LANDED)) { o->oAction = MONEYBAG_ACT_RETURN_HOME; + } } void moneybag_act_return_home(void) { @@ -136,12 +133,14 @@ void moneybag_act_return_home(void) { f32 sp28 = o->oHomeX - o->oPosX; f32 sp24 = o->oHomeZ - o->oPosZ; s16 sp22 = atan2s(sp24, sp28); - o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, sp22, 0x800); + o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, sp22, 0x800); collisionFlags = object_step(); + if (((collisionFlags & OBJ_COL_FLAGS_LANDED) == OBJ_COL_FLAGS_LANDED) - && (o->oMoneybagJumpState == MONEYBAG_JUMP_LANDING)) + && (o->oMoneybagJumpState == MONEYBAG_JUMP_LANDING)) { o->oMoneybagJumpState = MONEYBAG_JUMP_WALK_HOME; + } moneybag_jump(collisionFlags); moneybag_check_mario_collision(); @@ -156,7 +155,7 @@ void moneybag_act_return_home(void) { o->oMoneybagJumpState = MONEYBAG_JUMP_LANDING; } - if (is_point_within_radius_of_mario(o->oHomeX, o->oHomeY, o->oHomeZ, 800) == 1) { + if (is_point_within_radius_of_mario(o->oHomeX, o->oHomeY, o->oHomeZ, 800) == TRUE) { o->oAction = MONEYBAG_ACT_MOVE_AROUND; o->oMoneybagJumpState = MONEYBAG_JUMP_LANDING; } @@ -184,7 +183,7 @@ void bhv_moneybag_loop(void) { case MONEYBAG_ACT_APPEAR: case MONEYBAG_ACT_UNUSED_APPEAR: o->oOpacity += 12; - if (o->oOpacity >= 256) { + if (o->oOpacity > 255) { o->oOpacity = 255; o->parentObj->activeFlags = ACTIVE_FLAG_DEACTIVATED; o->oAction = MONEYBAG_ACT_MOVE_AROUND; @@ -193,8 +192,9 @@ void bhv_moneybag_loop(void) { case MONEYBAG_ACT_MOVE_AROUND: moneybag_act_move_around(); - if (o->oTimer >= 31) + if (o->oTimer > 30) { cur_obj_become_tangible(); + } break; case MONEYBAG_ACT_RETURN_HOME: diff --git a/src/game/behaviors/monty_mole.inc.c b/src/game/behaviors/monty_mole.inc.c index 685f5aae..884774ad 100644 --- a/src/game/behaviors/monty_mole.inc.c +++ b/src/game/behaviors/monty_mole.inc.c @@ -30,15 +30,10 @@ f32 sMontyMoleLastKilledPosZ; * start of this list. */ static struct Object *link_objects_with_behavior(const BehaviorScript *behavior) { - const BehaviorScript *behaviorAddr; + const BehaviorScript *behaviorAddr = segmented_to_virtual(behavior); struct Object *obj; - struct Object *lastObject; - struct ObjectNode *listHead; - - behaviorAddr = segmented_to_virtual(behavior); - lastObject = NULL; - - listHead = &gObjectLists[get_object_list_from_behavior(behaviorAddr)]; + struct Object *lastObject = NULL; + struct ObjectNode *listHead = &gObjectLists[get_object_list_from_behavior(behaviorAddr)]; obj = (struct Object *) listHead->next; while (obj != (struct Object *) listHead) { @@ -104,7 +99,7 @@ void bhv_monty_mole_hole_update(void) { sMontyMoleHoleList = link_objects_with_behavior(bhvMontyMoleHole); sMontyMoleKillStreak = 0; } else if (o->oMontyMoleHoleCooldown > 0) { - o->oMontyMoleHoleCooldown -= 1; + o->oMontyMoleHoleCooldown--; } } @@ -112,7 +107,7 @@ void bhv_monty_mole_hole_update(void) { * Spawn dirt particles when rising out of the ground. */ void monty_mole_spawn_dirt_particles(s8 offsetY, s8 velYBase) { - static struct SpawnParticlesInfo sMontyMoleRiseFromGroundParticles = { + static struct SpawnParticlesInfo montyMoleRiseFromGroundParticles = { /* behParam: */ 0, /* count: */ 3, /* model: */ MODEL_SAND_DUST, @@ -127,9 +122,10 @@ void monty_mole_spawn_dirt_particles(s8 offsetY, s8 velYBase) { /* sizeRange: */ 7.0f, }; - sMontyMoleRiseFromGroundParticles.offsetY = offsetY; - sMontyMoleRiseFromGroundParticles.velYBase = velYBase; - cur_obj_spawn_particles(&sMontyMoleRiseFromGroundParticles); + montyMoleRiseFromGroundParticles.offsetY = offsetY; + montyMoleRiseFromGroundParticles.velYBase = velYBase; + + cur_obj_spawn_particles(&montyMoleRiseFromGroundParticles); } /** @@ -366,7 +362,7 @@ void bhv_monty_mole_update(void) { } // Spawn a 1-up if you kill 8 monty moles - if (obj_check_attacks(&sMontyMoleHitbox, o->oAction)) { + if (obj_check_attacks(&sMontyMoleHitbox, o->oAction) != 0) { if (sMontyMoleKillStreak != 0) { f32 dx = o->oPosX - sMontyMoleLastKilledPosX; f32 dy = o->oPosY - sMontyMoleLastKilledPosY; @@ -388,7 +384,7 @@ void bhv_monty_mole_update(void) { } //! No overflow check - sMontyMoleKillStreak += 1; + sMontyMoleKillStreak++; sMontyMoleLastKilledPosX = o->oPosX; sMontyMoleLastKilledPosY = o->oPosY; @@ -421,7 +417,7 @@ static void monty_mole_rock_act_held(void) { o->oAction = MONTY_MOLE_ROCK_ACT_MOVE; // The angle is adjusted to compensate for the start position offset - o->oMoveAngleYaw = (s32)(o->parentObj->oMoveAngleYaw + 0x1F4 - distToMario * 0.1f); + o->oMoveAngleYaw = (s32)(o->parentObj->oMoveAngleYaw + 500 - distToMario * 0.1f); o->oForwardVel = 40.0f; o->oVelY = distToMario * 0.08f + 8.0f; diff --git a/src/game/behaviors/moving_coin.inc.c b/src/game/behaviors/moving_coin.inc.c index d992b13e..63fea18d 100644 --- a/src/game/behaviors/moving_coin.inc.c +++ b/src/game/behaviors/moving_coin.inc.c @@ -1,6 +1,4 @@ -// coin.c.inc - -// sp18 = collisionFlagsPtr +// moving_coin.inc.c static struct ObjectHitbox sMovingYellowCoinHitbox = { /* interactType: */ INTERACT_COIN, @@ -31,13 +29,13 @@ s32 coin_step(s16 *collisionFlagsPtr) { obj_check_floor_death(*collisionFlagsPtr, sObjFloor); - if ((*collisionFlagsPtr & 0x1) != 0 && (*collisionFlagsPtr & 0x8) == 0) /* bit 0, bit 3 */ - { + if ((*collisionFlagsPtr & OBJ_COL_FLAG_GROUNDED) + && !(*collisionFlagsPtr & OBJ_COL_FLAG_NO_Y_VEL)) { cur_obj_play_sound_2(SOUND_GENERAL_COIN_DROP); - return 1; + return TRUE; } - return 0; + return FALSE; } void moving_coin_flicker(void) { @@ -62,17 +60,20 @@ void bhv_moving_yellow_coin_init(void) { void bhv_moving_yellow_coin_loop(void) { s16 collisionFlags; + switch (o->oAction) { case MOV_YCOIN_ACT_IDLE: coin_step(&collisionFlags); - if (o->oTimer < 10) + if (o->oTimer < 10) { cur_obj_become_intangible(); - else + } else { cur_obj_become_tangible(); + } - if (o->oTimer >= 301) - o->oAction = 1; + if (o->oTimer > 300) { + o->oAction = MOV_YCOIN_ACT_BLINKING; + } break; case MOV_YCOIN_ACT_BLINKING: @@ -88,8 +89,7 @@ void bhv_moving_yellow_coin_loop(void) { break; } - if ((o->oInteractStatus & INT_STATUS_INTERACTED) != 0) /* bit 15 */ - { + if (o->oInteractStatus & INT_STATUS_INTERACTED) { coin_collected(); o->oInteractStatus = 0; } @@ -108,29 +108,32 @@ void bhv_moving_blue_coin_loop(void) { switch (o->oAction) { case MOV_BCOIN_ACT_STILL: - if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1500)) - o->oAction = 1; + if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1500)) { + o->oAction = MOV_BCOIN_ACT_MOVING; + } break; case MOV_BCOIN_ACT_MOVING: collisionFlags = object_step(); - if ((collisionFlags & OBJ_COL_FLAG_GROUNDED)) /* bit 0 */ - { - o->oForwardVel += 25.0f; - if (!(collisionFlags & OBJ_COL_FLAG_NO_Y_VEL)) - cur_obj_play_sound_2(SOUND_GENERAL_COIN_DROP); /* bit 3 */ - } else - o->oForwardVel *= 0.98; - if (o->oForwardVel > 75.0) + if (collisionFlags & OBJ_COL_FLAG_GROUNDED) { + o->oForwardVel += 25.0f; + if (!(collisionFlags & OBJ_COL_FLAG_NO_Y_VEL)) { + cur_obj_play_sound_2(SOUND_GENERAL_COIN_DROP); + } + } else { + o->oForwardVel *= 0.98; + } + + if (o->oForwardVel > 75.0) { o->oForwardVel = 75.0f; + } obj_flicker_and_disappear(o, 600); break; } - if ((o->oInteractStatus & INT_STATUS_INTERACTED) != 0) /* bit 15 */ - { + if (o->oInteractStatus & INT_STATUS_INTERACTED) { coin_collected(); o->oInteractStatus = 0; } @@ -150,13 +153,17 @@ void blue_coin_sliding_away_from_mario(void) { o->oForwardVel = 15.0; o->oMoveAngleYaw = o->oAngleToMario + 0x8000; - if (coin_step(&collisionFlags) != 0) + if (coin_step(&collisionFlags)) { o->oVelY += 18.0f; - if ((collisionFlags & 0x2) != 0) - o->oAction = 3; /* bit 1 */ + } - if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1000) == 0) + if (collisionFlags & OBJ_COL_FLAG_HIT_WALL) { + o->oAction = 3; + } + + if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1000)) { o->oAction = 2; + } } void blue_coin_sliding_slow_down(void) { @@ -164,11 +171,13 @@ void blue_coin_sliding_slow_down(void) { coin_step(&collisionFlags); - if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 500) == 1) + if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 500) == TRUE) { o->oAction = 1; + } - if (o->oTimer >= 151) + if (o->oTimer > 150) { o->oAction = 3; + } } void bhv_blue_coin_sliding_loop(void) { @@ -176,8 +185,9 @@ void bhv_blue_coin_sliding_loop(void) { switch (o->oAction) { case 0: - if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 500) == 1) + if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 500) == TRUE) { o->oAction = 1; + } set_object_visibility(o, 3000); break; @@ -193,8 +203,9 @@ void bhv_blue_coin_sliding_loop(void) { case 3: coin_step(&collisionFlags); - if (o->oTimer >= 61) + if (o->oTimer > 60) { o->oAction = 4; + } break; case 4: @@ -210,8 +221,7 @@ void bhv_blue_coin_sliding_loop(void) { break; } - if ((o->oInteractStatus & INT_STATUS_INTERACTED) != 0) /* bit 15 */ - { + if (o->oInteractStatus & INT_STATUS_INTERACTED) { coin_collected(); o->oInteractStatus = 0; } @@ -246,8 +256,9 @@ void bhv_blue_coin_jumping_loop(void) { case 3: coin_step(&collisionFlags); - if (o->oTimer >= 61) + if (o->oTimer > 60) { o->oAction = 4; + } break; case 4: @@ -255,8 +266,7 @@ void bhv_blue_coin_jumping_loop(void) { break; } - if ((o->oInteractStatus & INT_STATUS_INTERACTED) != 0) /* bit 15 */ - { + if (o->oInteractStatus & INT_STATUS_INTERACTED) { coin_collected(); o->oInteractStatus = 0; } diff --git a/src/game/behaviors/mr_blizzard.inc.c b/src/game/behaviors/mr_blizzard.inc.c index c8630a69..019f85e3 100644 --- a/src/game/behaviors/mr_blizzard.inc.c +++ b/src/game/behaviors/mr_blizzard.inc.c @@ -1,3 +1,5 @@ +// mr_blizzard.inc.c + // Mr. Blizzard hitbox struct ObjectHitbox sMrBlizzardHitbox = { /* interactType: */ INTERACT_MR_BLIZZARD, @@ -34,13 +36,13 @@ void mr_blizzard_spawn_white_particles(s8 count, s8 offsetY, s8 forwardVelBase, D_80331A00.forwardVelBase = forwardVelBase; D_80331A00.velYBase = velYBase; D_80331A00.sizeBase = sizeBase; + cur_obj_spawn_particles(&D_80331A00); } /** * Mr. Blizzard initialization function. */ - void bhv_mr_blizzard_init(void) { if (o->oBehParams2ndByte == MR_BLIZZARD_STYPE_JUMPING) { // Jumping Mr. Blizzard. @@ -48,11 +50,10 @@ void bhv_mr_blizzard_init(void) { o->oMrBlizzardGraphYOffset = 24.0f; o->oMrBlizzardTargetMoveYaw = o->oMoveAngleYaw; } else { - if (o->oBehParams2ndByte != MR_BLIZZARD_STYPE_NO_CAP) { - // Cap wearing Mr. Blizzard from SL. - if (save_file_get_flags() & SAVE_FLAG_CAP_ON_MR_BLIZZARD) { - o->oAnimState = 1; - } + // Cap wearing Mr. Blizzard from SL. + if ((o->oBehParams2ndByte != MR_BLIZZARD_STYPE_NO_CAP) + && (save_file_get_flags() & SAVE_FLAG_CAP_ON_MR_BLIZZARD)) { + o->oAnimState = 1; } // Mr. Blizzard starts under the floor holding nothing. @@ -64,9 +65,7 @@ void bhv_mr_blizzard_init(void) { /** * Handler for spawning Mr. Blizzard's snowball. */ - static void mr_blizzard_act_spawn_snowball(void) { - // If Mr. Blizzard is not holding a snowball, and the animation reaches 5 frames // spawn the Mr. Blizzard snowball. if (o->oMrBlizzardHeldObj == NULL && cur_obj_init_anim_check_frame(0, 5)) { @@ -89,9 +88,7 @@ static void mr_blizzard_act_spawn_snowball(void) { /** * Handler for Mario entering or exiting Mr. Blizzard's range. */ - static void mr_blizzard_act_hide_unhide(void) { - if (o->oDistanceToMario < 1000.0f) { // If Mario is in range, move to rising action, make Mr. Blizzard visible, // make Mr. Blizzard tangible, and initialize GraphYVel. @@ -112,12 +109,10 @@ static void mr_blizzard_act_hide_unhide(void) { /** * Handler for Mr. Blizzard popping up out of the ground. */ - static void mr_blizzard_act_rise_from_ground(void) { - // If the timer is not 0, decrement by 1 until it reaches 0. if (o->oMrBlizzardTimer != 0) { - o->oMrBlizzardTimer -= 1; + o->oMrBlizzardTimer--; } else if ((o->oMrBlizzardGraphYOffset += o->oMrBlizzardGraphYVel) > 24.0f) { // Increments GraphYOffset by GraphYVel until it is greater than 24, // moving Mr. Blizzard's graphical position upward each frame. @@ -142,14 +137,11 @@ static void mr_blizzard_act_rise_from_ground(void) { /** * Handler for Mr. Blizzard's rotation. */ - static void mr_blizzard_act_rotate(void) { - - s16 angleDiff; - f32 prevDizziness; // While Mr. Blizzard is on the ground, rotate toward Mario at // 8.4375 degrees/frame. if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) { + s16 angleDiff; cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x600); // Modify the ChangeInDizziness based on Mario's angle to Mr. Blizzard. @@ -164,7 +156,7 @@ static void mr_blizzard_act_rotate(void) { // Incremement Dizziness by value of ChangeInDizziness o->oMrBlizzardDizziness += o->oMrBlizzardChangeInDizziness; } else if (o->oMrBlizzardDizziness != 0.0f) { - prevDizziness = o->oMrBlizzardDizziness; + f32 prevDizziness = o->oMrBlizzardDizziness; // Slowly move Dizziness back to 0 by making ChangeInDizziness positive if Dizziness // is negative, and making ChangeInDizziness negative if Dizziness is positive. if (o->oMrBlizzardDizziness < 0.0f) { @@ -188,13 +180,15 @@ static void mr_blizzard_act_rotate(void) { o->prevObj = o->oMrBlizzardHeldObj = NULL; cur_obj_become_intangible(); } - // If Mario gets too far away, move to burrow action and delete the snowball. - } else if (o->oDistanceToMario > 1500.0f) { + } + // If Mario gets too far away, move to burrow action and delete the snowball. + else if (o->oDistanceToMario > 1500.0f) { o->oAction = MR_BLIZZARD_ACT_BURROW; o->oMrBlizzardChangeInDizziness = 300.0f; o->prevObj = o->oMrBlizzardHeldObj = NULL; - // After 60 frames, if Mario is within 11.25 degrees of Mr. Blizzard, throw snowball action. - } else if (o->oTimer > 60 && abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw) < 0x800) { + } + // After 60 frames, if Mario is within 11.25 degrees of Mr. Blizzard, throw snowball action. + else if (o->oTimer > 60 && abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw) < 0x800) { o->oAction = MR_BLIZZARD_ACT_THROW_SNOWBALL; } } @@ -203,17 +197,14 @@ static void mr_blizzard_act_rotate(void) { /** * Handler for Mr. Blizzard's death. */ - static void mr_blizzard_act_death(void) { - - struct Object *cap; - if (clamp_f32(&o->oMrBlizzardDizziness, -0x4000, 0x4000)) { if (o->oMrBlizzardChangeInDizziness != 0.0f) { cur_obj_play_sound_2(SOUND_OBJ_SNOW_SAND1); // If Mr. Blizzard is wearing Mario's cap, clear // the save flag and spawn Mario's cap. - if (o->oAnimState) { + if (o->oAnimState != 0) { + struct Object *cap; save_file_clear_flags(SAVE_FLAG_CAP_ON_MR_BLIZZARD); cap = spawn_object_relative(0, 5, 105, 0, o, MODEL_MARIOS_CAP, bhvNormalCap); @@ -253,8 +244,9 @@ static void mr_blizzard_act_death(void) { set_object_respawn_info_bits(o, 1); } } - // Reset Mr. Blizzard if Mario leaves its radius. - } else if (o->oDistanceToMario > 1000.0f) { + } + // Reset Mr. Blizzard if Mario leaves its radius. + else if (o->oDistanceToMario > 1000.0f) { cur_obj_init_animation_with_sound(1); o->oAction = MR_BLIZZARD_ACT_SPAWN_SNOWBALL; @@ -269,9 +261,7 @@ static void mr_blizzard_act_death(void) { /** * Handler for snowball throw. */ - static void mr_blizzard_act_throw_snowball(void) { - // Play a sound and set HeldObj to NULL. Then set action to 0. if (cur_obj_init_anim_check_frame(1, 7)) { cur_obj_play_sound_2(SOUND_OBJ2_SCUTTLEBUG_ALERT); @@ -284,9 +274,7 @@ static void mr_blizzard_act_throw_snowball(void) { /** * Mr. Blizzard's going back into the ground function. */ - static void mr_blizzard_act_burrow(void) { - // Reset Dizziness by increasing ChangeInDizziness if // dizziness is negative and decreasing it if Dizziness o->oMrBlizzardDizziness += o->oMrBlizzardChangeInDizziness; @@ -307,9 +295,7 @@ static void mr_blizzard_act_burrow(void) { /** * Jumping Mr. Blizzard handler function. */ - static void mr_blizzard_act_jump(void) { - if (o->oMrBlizzardTimer != 0) { cur_obj_rotate_yaw_toward(o->oMrBlizzardTargetMoveYaw, 3400); @@ -323,8 +309,9 @@ static void mr_blizzard_act_jump(void) { o->oVelY = 25.0f; o->oMrBlizzardTimer = 30; o->oMrBlizzardDistFromHome = 0; - // Jump forward. - } else { + } + // Jump forward. + else { o->oForwardVel = 10.0f; o->oVelY = 50.0f; o->oMoveFlags = 0; @@ -350,7 +337,6 @@ static void mr_blizzard_act_jump(void) { /** * Mr. Blizzard update function. */ - void bhv_mr_blizzard_update(void) { cur_obj_update_floor_and_walls(); @@ -397,7 +383,6 @@ void bhv_mr_blizzard_update(void) { /** * Snowball initial takeoff position handler. */ - static void mr_blizzard_snowball_act_0(void) { cur_obj_move_using_fvel_and_gravity(); if (o->parentObj->prevObj == o) { @@ -410,13 +395,10 @@ static void mr_blizzard_snowball_act_0(void) { /** * Snowball launching action. */ - static void mr_blizzard_snowball_act_1(void) { - f32 marioDist; - if (o->parentObj->prevObj == NULL) { if (o->parentObj->oAction == MR_BLIZZARD_ACT_THROW_SNOWBALL) { - marioDist = o->oDistanceToMario; + f32 marioDist = o->oDistanceToMario; if (marioDist > 800.0f) { marioDist = 800.0f; } @@ -431,6 +413,7 @@ static void mr_blizzard_snowball_act_1(void) { o->oMoveFlags = 0; } } + // Snowball hitbox. struct ObjectHitbox sMrBlizzardSnowballHitbox = { /* interactType: */ INTERACT_MR_BLIZZARD, @@ -447,7 +430,6 @@ struct ObjectHitbox sMrBlizzardSnowballHitbox = { /** * Snowball collision function. */ - static void mr_blizzard_snowball_act_2(void) { // Set snowball to interact with walls, floors, and Mario. cur_obj_update_floor_and_walls(); @@ -466,7 +448,6 @@ static void mr_blizzard_snowball_act_2(void) { /** * Snowball behavior loop. */ - void bhv_mr_blizzard_snowball(void) { switch (o->oAction) { case 0: diff --git a/src/game/behaviors/mr_i.inc.c b/src/game/behaviors/mr_i.inc.c index 4d883ddf..cbf0a759 100644 --- a/src/game/behaviors/mr_i.inc.c +++ b/src/game/behaviors/mr_i.inc.c @@ -1,4 +1,4 @@ -// mr_i.c.inc +// mr_i.inc.c // this is actually the MrI particle loop function. piranha // plant code later on reuses this function. @@ -15,9 +15,11 @@ void mr_i_piranha_particle_act_0(void) { cur_obj_scale(3.0f); o->oForwardVel = 20.0f; cur_obj_update_floor_and_walls(); - if (0x8000 & o->oInteractStatus) + + if (o->oInteractStatus & INT_STATUS_INTERACTED) { o->oAction = 1; - else if ((o->oTimer >= 101) || (o->oMoveFlags & OBJ_MOVE_HIT_WALL) || o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM) { + } else if ((o->oTimer > 100) || (o->oMoveFlags & OBJ_MOVE_HIT_WALL) + || (o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) { obj_mark_for_deletion(o); spawn_mist_particles(); } @@ -26,11 +28,15 @@ void mr_i_piranha_particle_act_0(void) { void mr_i_piranha_particle_act_1(void) { s32 i; obj_mark_for_deletion(o); - for (i = 0; i < 10; i++) + for (i = 0; i < 10; i++) { spawn_object(o, MODEL_PURPLE_MARBLE, bhvPurpleParticle); + } } -void (*sMrIParticleActions[])(void) = { mr_i_piranha_particle_act_0, mr_i_piranha_particle_act_1 }; +void (*sMrIParticleActions[])(void) = { + mr_i_piranha_particle_act_0, + mr_i_piranha_particle_act_1, +}; void bhv_mr_i_particle_loop(void) { cur_obj_call_action_function(sMrIParticleActions); @@ -39,32 +45,39 @@ void bhv_mr_i_particle_loop(void) { void spawn_mr_i_particle(void) { struct Object *particle; f32 sp18 = o->header.gfx.scale[1]; + particle = spawn_object(o, MODEL_PURPLE_MARBLE, bhvMrIParticle); particle->oPosY += 50.0f * sp18; particle->oPosX += sins(o->oMoveAngleYaw) * 90.0f * sp18; particle->oPosZ += coss(o->oMoveAngleYaw) * 90.0f * sp18; + cur_obj_play_sound_2(SOUND_OBJ_MRI_SHOOT); } void bhv_mr_i_body_loop(void) { obj_copy_pos_and_angle(o, o->parentObj); + if (!(o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) { obj_copy_scale(o, o->parentObj); obj_set_parent_relative_pos(o, 0, 0, o->header.gfx.scale[1] * 100.0f); obj_build_transform_from_pos_and_angle(o, 44, 15); obj_translate_local(o, 6, 44); o->oFaceAnglePitch = o->oMoveAnglePitch; - o->oGraphYOffset = o->header.gfx.scale[1] * 100.f; + o->oGraphYOffset = o->header.gfx.scale[1] * 100.0f; } - if (o->parentObj->oMrIUnk110 != 1) + + if (o->parentObj->oMrIUnk110 != 1) { o->oAnimState = -1; - else { + } else { o->oAnimState++; - if (o->oAnimState == 15) + if (o->oAnimState == 15) { o->parentObj->oMrIUnk110 = 0; + } } - if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) + + if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) { obj_mark_for_deletion(o); + } } void mr_i_act_3(void) { @@ -72,31 +85,43 @@ void mr_i_act_3(void) { s16 sp34; f32 sp30; f32 sp2C; - UNUSED u8 pad[8]; + UNUSED u8 filler[8]; f32 sp20; f32 sp1C; - if (o->oBehParams2ndByte) + + if (o->oBehParams2ndByte != 0) { sp1C = 2.0f; - else + } else { sp1C = 1.0f; - if (o->oMrIUnk100 < 0) + } + + if (o->oMrIUnk100 < 0) { sp34 = 0x1000; - else + } else { sp34 = -0x1000; + } + sp2C = (o->oTimer + 1) / 96.0f; + if (o->oTimer < 64) { sp36 = o->oMoveAngleYaw; o->oMoveAngleYaw += sp34 * coss(0x4000 * sp2C); - if (sp36 < 0 && o->oMoveAngleYaw >= 0) + + if (sp36 < 0 && o->oMoveAngleYaw >= 0) { cur_obj_play_sound_2(SOUND_OBJ2_MRI_SPINNING); + } + o->oMoveAnglePitch = (1.0 - coss(0x4000 * sp2C)) * -0x4000; cur_obj_shake_y(4.0f); } else if (o->oTimer < 96) { - if (o->oTimer == 64) + if (o->oTimer == 64) { cur_obj_play_sound_2(SOUND_OBJ_MRI_DEATH); + } + sp30 = (f32)(o->oTimer - 63) / 32; o->oMoveAngleYaw += sp34 * coss(0x4000 * sp2C); o->oMoveAnglePitch = (1.0 - coss(0x4000 * sp2C)) * -0x4000; + cur_obj_shake_y((s32)((1.0f - sp30) * 4)); // trucating the f32? sp20 = coss(0x4000 * sp30) * 0.4 + 0.6; cur_obj_scale(sp20 * sp1C); @@ -106,66 +131,86 @@ void mr_i_act_3(void) { if (o->oTimer == 104) { cur_obj_become_intangible(); spawn_mist_particles(); - o->oMrISize = sp1C * 0.6; - if (o->oBehParams2ndByte) { + o->oMrIScale = sp1C * 0.6; + if (o->oBehParams2ndByte != 0) { o->oPosY += 100.0f; spawn_default_star(1370, 2000.0f, -320.0f); obj_mark_for_deletion(o); - } else + } else { cur_obj_spawn_loot_blue_coin(); + } } - o->oMrISize -= 0.2 * sp1C; - if (o->oMrISize < 0) - o->oMrISize = 0; - cur_obj_scale(o->oMrISize); - } else + + o->oMrIScale -= 0.2 * sp1C; + + if (o->oMrIScale < 0) { + o->oMrIScale = 0; + } + + cur_obj_scale(o->oMrIScale); + } else { obj_mark_for_deletion(o); + } } void mr_i_act_2(void) { - s16 sp1E; + s16 sp1E = o->oMoveAngleYaw; s16 sp1C; - sp1E = o->oMoveAngleYaw; + if (o->oTimer == 0) { - if (o->oBehParams2ndByte) + if (o->oBehParams2ndByte != 0) { o->oMrIUnkF4 = 200; - else + } else { o->oMrIUnkF4 = 120; + } o->oMrIUnkFC = 0; o->oMrIUnk100 = 0; o->oMrIUnk104 = 0; } + obj_turn_toward_object(o, gMarioObject, 0x10, 0x800); obj_turn_toward_object(o, gMarioObject, 0x0F, 0x400); + sp1C = sp1E - (s16)(o->oMoveAngleYaw); - if (!sp1C) { + + if (sp1C == 0) { o->oMrIUnkFC = 0; o->oMrIUnk100 = 0; } else if (sp1C > 0) { - if (o->oMrIUnk100 > 0) + if (o->oMrIUnk100 > 0) { o->oMrIUnkFC += sp1C; - else + } else { o->oMrIUnkFC = 0; + } o->oMrIUnk100 = 1; } else { - if (o->oMrIUnk100 < 0) + if (o->oMrIUnk100 < 0) { o->oMrIUnkFC -= sp1C; - else + } else { o->oMrIUnkFC = 0; + } o->oMrIUnk100 = -1; } - if (!o->oMrIUnkFC) + + if (o->oMrIUnkFC == 0) { o->oMrIUnkF4 = 120; - if (o->oMrIUnkFC > 1 << 16) + } + if (o->oMrIUnkFC > 65536) { o->oAction = 3; - o->oMrIUnkF4 -= 1; - if (!o->oMrIUnkF4) { + } + + o->oMrIUnkF4--; + + if (o->oMrIUnkF4 == 0) { o->oMrIUnkF4 = 120; o->oMrIUnkFC = 0; } + if (o->oMrIUnkFC < 5000) { - if (o->oMrIUnk104 == o->oMrIUnk108) + if (o->oMrIUnk104 == o->oMrIUnk108) { o->oMrIUnk110 = 1; + } + if (o->oMrIUnk104 == o->oMrIUnk108 + 20) { spawn_mr_i_particle(); o->oMrIUnk104 = 0; @@ -176,39 +221,45 @@ void mr_i_act_2(void) { o->oMrIUnk104 = 0; o->oMrIUnk108 = (s32)(random_float() * 50.0f + 50.0f); } - if (o->oDistanceToMario > 800.0f) + + if (o->oDistanceToMario > 800.0f) { o->oAction = 1; + } } void mr_i_act_1(void) { - s16 sp1E; - s16 sp1C; - s16 sp1A; - sp1E = obj_angle_to_object(o, gMarioObject); - sp1C = abs_angle_diff(o->oMoveAngleYaw, sp1E); - sp1A = abs_angle_diff(o->oMoveAngleYaw, gMarioObject->oFaceAngleYaw); + s16 sp1E = obj_angle_to_object(o, gMarioObject); + s16 sp1C = abs_angle_diff(o->oMoveAngleYaw, sp1E); + s16 sp1A = abs_angle_diff(o->oMoveAngleYaw, gMarioObject->oFaceAngleYaw); + if (o->oTimer == 0) { cur_obj_become_tangible(); o->oMoveAnglePitch = 0; o->oMrIUnk104 = 30; o->oMrIUnk108 = random_float() * 20.0f; - if (o->oMrIUnk108 & 1) + if (o->oMrIUnk108 & 1) { o->oAngleVelYaw = -256; - else + } else { o->oAngleVelYaw = 256; + } } + if (sp1C < 1024 && sp1A > 0x4000) { - if (o->oDistanceToMario < 700.0f) + if (o->oDistanceToMario < 700.0f) { o->oAction = 2; - else + } else { o->oMrIUnk104++; + } } else { o->oMoveAngleYaw += o->oAngleVelYaw; o->oMrIUnk104 = 30; } - if (o->oMrIUnk104 == o->oMrIUnk108 + 60) + + if (o->oMrIUnk104 == o->oMrIUnk108 + 60) { o->oMrIUnk110 = 1; - if (o->oMrIUnk108 + 80 < o->oMrIUnk104) { + } + + if (o->oMrIUnk104 > o->oMrIUnk108 + 80) { o->oMrIUnk104 = 0; o->oMrIUnk108 = random_float() * 80.0f; spawn_mr_i_particle(); @@ -224,31 +275,44 @@ void mr_i_act_0(void) { o->oMoveAngleRoll = 0; #endif cur_obj_scale(o->oBehParams2ndByte + 1); - if (o->oTimer == 0) + + if (o->oTimer == 0) { cur_obj_set_pos_to_home(); - if (o->oDistanceToMario < 1500.0f) + } + + if (o->oDistanceToMario < 1500.0f) { o->oAction = 1; + } } -void (*sMrIActions[])(void) = { mr_i_act_0, mr_i_act_1, mr_i_act_2, mr_i_act_3 }; +void (*sMrIActions[])(void) = { + mr_i_act_0, + mr_i_act_1, + mr_i_act_2, + mr_i_act_3, +}; struct ObjectHitbox sMrIHitbox = { - /* interactType: */ INTERACT_DAMAGE, - /* downOffset: */ 0, + /* interactType: */ INTERACT_DAMAGE, + /* downOffset: */ 0, /* damageOrCoinValue: */ 2, - /* health: */ 2, - /* numLootCoins: */ 5, - /* radius: */ 80, - /* height: */ 150, - /* hurtboxRadius: */ 0, - /* hurtboxHeight: */ 0, + /* health: */ 2, + /* numLootCoins: */ 5, + /* radius: */ 80, + /* height: */ 150, + /* hurtboxRadius: */ 0, + /* hurtboxHeight: */ 0, }; void bhv_mr_i_loop(void) { obj_set_hitbox(o, &sMrIHitbox); cur_obj_call_action_function(sMrIActions); - if (o->oAction != 3) - if (o->oDistanceToMario > 3000.0f || o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM) + + if (o->oAction != 3) { + if ((o->oDistanceToMario > 3000.0f) || (o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) { o->oAction = 0; + } + } + o->oInteractStatus = 0; } diff --git a/src/game/behaviors/mushroom_1up.inc.c b/src/game/behaviors/mushroom_1up.inc.c index 1466802d..ae0a7735 100644 --- a/src/game/behaviors/mushroom_1up.inc.c +++ b/src/game/behaviors/mushroom_1up.inc.c @@ -1,13 +1,13 @@ -// mushroom_1up.c.inc +// mushroom_1up.inc.c void bhv_1up_interact(void) { - UNUSED s32 sp1C; + UNUSED u8 filler[4]; - if (obj_check_if_collided_with_object(o, gMarioObject) == 1) { + if (obj_check_if_collided_with_object(o, gMarioObject) == TRUE) { play_sound(SOUND_GENERAL_COLLECT_1UP, gGlobalSoundSource); gMarioState->numLives++; o->activeFlags = ACTIVE_FLAG_DEACTIVATED; -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif } @@ -51,21 +51,27 @@ void pole_1up_move_towards_mario(void) { s16 sp2A = atan2s(sqrtf(sqr(sp34) + sqr(sp2C)), sp30); obj_turn_toward_object(o, gMarioObject, 16, 0x1000); + o->oMoveAnglePitch = approach_s16_symmetric(o->oMoveAnglePitch, sp2A, 0x1000); o->oVelY = sins(o->oMoveAnglePitch) * 30.0f; o->oForwardVel = coss(o->oMoveAnglePitch) * 30.0f; + bhv_1up_interact(); } -void one_up_move_away_from_mario(s16 sp1A) { +void one_up_move_away_from_mario(s16 collisionFlags) { o->oForwardVel = 8.0f; o->oMoveAngleYaw = o->oAngleToMario + 0x8000; - bhv_1up_interact(); - if (sp1A & 0x02) - o->oAction = 2; - if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 3000)) + bhv_1up_interact(); + + if (collisionFlags & OBJ_COL_FLAG_HIT_WALL) { o->oAction = 2; + } + + if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 3000)) { + o->oAction = 2; + } } void bhv_1up_walking_loop(void) { @@ -73,11 +79,13 @@ void bhv_1up_walking_loop(void) { switch (o->oAction) { case 0: - if (o->oTimer >= 18) + if (o->oTimer > 17) { spawn_object(o, MODEL_NONE, bhvSparkleSpawn); + } - if (o->oTimer == 0) + if (o->oTimer == 0) { play_sound(SOUND_GENERAL2_1UP_APPEAR, gGlobalSoundSource); + } one_up_loop_in_air(); @@ -89,8 +97,9 @@ void bhv_1up_walking_loop(void) { break; case 1: - if (o->oTimer > 300) + if (o->oTimer > 300) { o->oAction = 2; + } bhv_1up_interact(); break; @@ -105,16 +114,17 @@ void bhv_1up_walking_loop(void) { } void bhv_1up_running_away_loop(void) { - s16 sp26; + s16 collisionFlags = object_step(); - sp26 = object_step(); switch (o->oAction) { case 0: - if (o->oTimer >= 18) + if (o->oTimer > 17) { spawn_object(o, MODEL_NONE, bhvSparkleSpawn); + } - if (o->oTimer == 0) + if (o->oTimer == 0) { play_sound(SOUND_GENERAL2_1UP_APPEAR, gGlobalSoundSource); + } one_up_loop_in_air(); @@ -127,7 +137,7 @@ void bhv_1up_running_away_loop(void) { case 1: spawn_object(o, MODEL_NONE, bhvSparkleSpawn); - one_up_move_away_from_mario(sp26); + one_up_move_away_from_mario(collisionFlags); break; case 2: @@ -140,29 +150,31 @@ void bhv_1up_running_away_loop(void) { } void sliding_1up_move(void) { - s16 sp1E; + s16 collisionFlags = object_step(); - sp1E = object_step(); - if (sp1E & 0x01) { + if (collisionFlags & OBJ_COL_FLAG_GROUNDED) { o->oForwardVel += 25.0f; - o->oVelY = 0; + o->oVelY = 0.0f; } else { o->oForwardVel *= 0.98; } - if (o->oForwardVel > 40.0) + if (o->oForwardVel > 40.0) { o->oForwardVel = 40.0f; + } - if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 5000)) + if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 5000)) { o->oAction = 2; + } } void bhv_1up_sliding_loop(void) { switch (o->oAction) { case 0: set_object_visibility(o, 3000); - if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1000)) + if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1000)) { o->oAction = 1; + } break; case 1: @@ -185,7 +197,7 @@ void bhv_1up_loop(void) { } void bhv_1up_jump_on_approach_loop(void) { - s16 sp26; + s16 collisionFlags; switch (o->oAction) { case 0: @@ -196,13 +208,13 @@ void bhv_1up_jump_on_approach_loop(void) { break; case 1: - sp26 = object_step(); - one_up_move_away_from_mario(sp26); + collisionFlags = object_step(); + one_up_move_away_from_mario(collisionFlags); spawn_object(o, MODEL_NONE, bhvSparkleSpawn); break; case 2: - sp26 = object_step(); + collisionFlags = object_step(); bhv_1up_interact(); obj_flicker_and_disappear(o, 30); break; @@ -212,7 +224,8 @@ void bhv_1up_jump_on_approach_loop(void) { } void bhv_1up_hidden_loop(void) { - s16 sp26; + s16 collisionFlags; + switch (o->oAction) { case 0: o->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE; @@ -225,21 +238,22 @@ void bhv_1up_hidden_loop(void) { break; case 1: - sp26 = object_step(); - one_up_move_away_from_mario(sp26); + collisionFlags = object_step(); + one_up_move_away_from_mario(collisionFlags); spawn_object(o, MODEL_NONE, bhvSparkleSpawn); break; case 2: - sp26 = object_step(); + collisionFlags = object_step(); bhv_1up_interact(); obj_flicker_and_disappear(o, 30); break; case 3: - sp26 = object_step(); - if (o->oTimer >= 18) + collisionFlags = object_step(); + if (o->oTimer > 17) { spawn_object(o, MODEL_NONE, bhvSparkleSpawn); + } one_up_loop_in_air(); @@ -253,18 +267,19 @@ void bhv_1up_hidden_loop(void) { } void bhv_1up_hidden_trigger_loop(void) { - struct Object *sp1C; - if (obj_check_if_collided_with_object(o, gMarioObject) == 1) { - sp1C = cur_obj_nearest_object_with_behavior(bhvHidden1up); - if (sp1C != NULL) + if (obj_check_if_collided_with_object(o, gMarioObject) == TRUE) { + struct Object *sp1C = cur_obj_nearest_object_with_behavior(bhvHidden1up); + if (sp1C != NULL) { sp1C->o1UpHiddenUnkF4++; + } o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } } void bhv_1up_hidden_in_pole_loop(void) { - UNUSED s16 sp26; + UNUSED s16 collisionFlags; + switch (o->oAction) { case 0: o->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE; @@ -278,13 +293,14 @@ void bhv_1up_hidden_in_pole_loop(void) { case 1: pole_1up_move_towards_mario(); - sp26 = object_step(); + collisionFlags = object_step(); break; case 3: - sp26 = object_step(); - if (o->oTimer >= 18) + collisionFlags = object_step(); + if (o->oTimer > 17) { spawn_object(o, MODEL_NONE, bhvSparkleSpawn); + } one_up_loop_in_air(); @@ -298,10 +314,8 @@ void bhv_1up_hidden_in_pole_loop(void) { } void bhv_1up_hidden_in_pole_trigger_loop(void) { - struct Object *sp1C; - - if (obj_check_if_collided_with_object(o, gMarioObject) == 1) { - sp1C = cur_obj_nearest_object_with_behavior(bhvHidden1upInPole); + if (obj_check_if_collided_with_object(o, gMarioObject) == TRUE) { + struct Object *sp1C = cur_obj_nearest_object_with_behavior(bhvHidden1upInPole); if (sp1C != NULL) { sp1C->o1UpHiddenUnkF4++; } @@ -311,12 +325,11 @@ void bhv_1up_hidden_in_pole_trigger_loop(void) { } void bhv_1up_hidden_in_pole_spawner_loop(void) { - s8 sp2F; - if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 700)) { + s8 i; spawn_object_relative(2, 0, 50, 0, o, MODEL_1UP, bhvHidden1upInPole); - for (sp2F = 0; sp2F < 2; sp2F++) { - spawn_object_relative(0, 0, sp2F * -200, 0, o, MODEL_NONE, bhvHidden1upInPoleTrigger); + for (i = 0; i < 2; i++) { + spawn_object_relative(0, 0, i * -200, 0, o, MODEL_NONE, bhvHidden1upInPoleTrigger); } o->activeFlags = ACTIVE_FLAG_DEACTIVATED; diff --git a/src/game/behaviors/music_touch.inc.c b/src/game/behaviors/music_touch.inc.c index 5f3277d9..1597fb2e 100644 --- a/src/game/behaviors/music_touch.inc.c +++ b/src/game/behaviors/music_touch.inc.c @@ -1,4 +1,4 @@ -// music_touch.c.inc +// music_touch.inc.c void bhv_play_music_track_when_touched_loop(void) { if (o->oAction == 0) { diff --git a/src/game/behaviors/orange_number.inc.c b/src/game/behaviors/orange_number.inc.c index 84bf01e9..3b5554d8 100644 --- a/src/game/behaviors/orange_number.inc.c +++ b/src/game/behaviors/orange_number.inc.c @@ -1,4 +1,4 @@ -// orange_number.c.inc +// orange_number.inc.c void bhv_orange_number_init(void) { o->oAnimState = o->oBehParams2ndByte; @@ -6,15 +6,16 @@ void bhv_orange_number_init(void) { } void bhv_orange_number_loop(void) { - struct Object *sp1C; o->oPosY += o->oVelY; o->oVelY -= 2.0f; - if (o->oVelY < -21.0f) + + if (o->oVelY < -21.0f) { o->oVelY = 14.0; + } if (o->oTimer == 35) { - sp1C = spawn_object(o, MODEL_SPARKLES, bhvGoldenCoinSparkles); - sp1C->oPosY -= 30.f; + struct Object *sp1C = spawn_object(o, MODEL_SPARKLES, bhvGoldenCoinSparkles); + sp1C->oPosY -= 30.0f; o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } } diff --git a/src/game/behaviors/piranha_bubbles.inc.c b/src/game/behaviors/piranha_bubbles.inc.c index 447c2751..21e01f66 100644 --- a/src/game/behaviors/piranha_bubbles.inc.c +++ b/src/game/behaviors/piranha_bubbles.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvPiranhaPlantBubble and bhvPiranhaPlantWakingBubbles. * @@ -30,12 +31,10 @@ void bhv_piranha_plant_bubble_loop(void) { struct Object *parent = o->parentObj; // the Piranha Plant f32 scale = 0; s32 i; - s32 frame = parent->header.gfx.animInfo.animFrame; + s32 animFrame = parent->header.gfx.animInfo.animFrame; // TODO: rename lastFrame if it is inaccurate s32 lastFrame = parent->header.gfx.animInfo.curAnim->loopEnd - 2; - s32 UNUSED unused; - f32 doneShrinkingFrame; // the first frame after shrinking is done - f32 beginGrowingFrame; // the frame just before growing begins + UNUSED u8 filler[4]; cur_obj_set_pos_relative(parent, 0, 72.0f, 180.0f); @@ -60,21 +59,21 @@ void bhv_piranha_plant_bubble_loop(void) { * slightly after halfway. This leaves about 8 frames during * which the bubble is at its smallest, where its scale is 1.0f. */ - doneShrinkingFrame = lastFrame / 2.0f - 4.0f; - beginGrowingFrame = lastFrame / 2.0f + 4.0f; + // the first frame after shrinking is done + f32 doneShrinkingFrame = lastFrame / 2.0f - 4.0f; + // the frame just before growing begins + f32 beginGrowingFrame = lastFrame / 2.0f + 4.0f; // Note that the bubble always starts this loop at its largest. - if (frame < doneShrinkingFrame) { + if (animFrame < doneShrinkingFrame) { // Shrink from 5.0f to 1.0f. - scale = coss(frame / doneShrinkingFrame * 0x4000) * 4.0f + 1.0; - } else if (frame > beginGrowingFrame) { + scale = coss(animFrame / doneShrinkingFrame * 0x4000) * 4.0f + 1.0; + } else if (animFrame > beginGrowingFrame) { // Grow from 1.0f to 5.0f. scale = sins(( - // they should have used beginGrowingFrame here: - (frame - (lastFrame / 2.0f + 4.0f)) / beginGrowingFrame) - * 0x4000) - * 4.0f - + 1.0; + // they should have used beginGrowingFrame here: + (animFrame - (lastFrame / 2.0f + 4.0f)) / beginGrowingFrame + ) * 0x4000) * 4.0f + 1.0; } else { // Stay at 1.0f for a few frames. scale = 1.0f; @@ -90,7 +89,7 @@ void bhv_piranha_plant_bubble_loop(void) { case PIRANHA_PLANT_BUBBLE_ACT_BURST: cur_obj_disable_rendering(); - scale = 0; + scale = 0.0f; // Spawn 15 small bubbles to make it look like this bubble burst. for (i = 0; i < 15; i++) { @@ -101,5 +100,6 @@ void bhv_piranha_plant_bubble_loop(void) { scale = 1.0f; // this has no effect; it is set to 0 in the idle state break; } + cur_obj_scale(scale); } diff --git a/src/game/behaviors/piranha_plant.inc.c b/src/game/behaviors/piranha_plant.inc.c index 17f298dd..9e97a8b6 100644 --- a/src/game/behaviors/piranha_plant.inc.c +++ b/src/game/behaviors/piranha_plant.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvPiranhaPlant. * This controls Piranha Plants, which alternate between sleeping, attacking, @@ -19,7 +20,7 @@ void piranha_plant_act_idle(void) { * with a scale below 1, which would cause it to appear shrunken. See * documentation for, and calls to, piranha_plant_reset_when_far(). */ - cur_obj_scale(1); + cur_obj_scale(1.0f); #endif if (o->oDistanceToMario < 1200.0f) { @@ -33,11 +34,12 @@ void piranha_plant_act_idle(void) { * with it through some other means (e.g. by running into it), move it to the * woken up state. * - * @return 1 if the player interacted with the Piranha Plant, 0 otherwise + * @return TRUE if the player interacted with the Piranha Plant, FALSE otherwise */ s32 piranha_plant_check_interactions(void) { s32 i; - s32 interacted = 1; + s32 interacted = TRUE; + if (o->oInteractStatus & INT_STATUS_INTERACTED) { func_80321080(50); if (o->oInteractStatus & INT_STATUS_WAS_ATTACKED) { @@ -53,13 +55,12 @@ s32 piranha_plant_check_interactions(void) { } o->oInteractStatus = 0; } else { - interacted = 0; + interacted = FALSE; } + return interacted; } -#define PIRANHA_PLANT_SLEEP_MUSIC_PLAYING 0 - /** * Make the Piranha Plant sleep. If Mario moves too quickly, move the Piranha * Plant to the woken up state. Otherwise, play the lullaby if Mario is close @@ -114,12 +115,13 @@ void piranha_plant_act_woken_up(void) { */ o->oDamageOrCoinValue = 3; #endif - if (o->oTimer == 0) + if (o->oTimer == 0) { func_80321080(50); + } - if (piranha_plant_check_interactions() == 0) - if (o->oTimer > 10) - o->oAction = PIRANHA_PLANT_ACT_BITING; + if (!piranha_plant_check_interactions() && o->oTimer > 10) { + o->oAction = PIRANHA_PLANT_ACT_BITING; + } } #if BUGFIX_PIRANHA_PLANT_STATE_RESET @@ -153,8 +155,9 @@ void piranha_plant_attacked(void) { cur_obj_become_intangible(); cur_obj_init_animation_with_sound(2); o->oInteractStatus = 0; - if (cur_obj_check_if_near_animation_end()) + if (cur_obj_check_if_near_animation_end()) { o->oAction = PIRANHA_PLANT_ACT_SHRINK_AND_DIE; + } #if BUGFIX_PIRANHA_PLANT_STATE_RESET piranha_plant_reset_when_far(); // see this function's comment #endif @@ -240,7 +243,7 @@ static s8 sPiranhaPlantBiteSoundFrames[] = { 12, 28, 50, 64, -1 }; * Piranha Plant will move to the attacked state. */ void piranha_plant_act_biting(void) { - s32 frame = o->header.gfx.animInfo.animFrame; + s32 animFrame = o->header.gfx.animInfo.animFrame; cur_obj_become_tangible(); @@ -252,22 +255,22 @@ void piranha_plant_act_biting(void) { cur_obj_set_hurtbox_radius_and_height(150.0f, 100.0f); // Play a bite sound effect on certain frames. - if (is_item_in_array(frame, sPiranhaPlantBiteSoundFrames)) { + if (is_item_in_array(animFrame, sPiranhaPlantBiteSoundFrames)) { cur_obj_play_sound_2(SOUND_OBJ2_PIRANHA_PLANT_BITE); } // Move to face the player. o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oAngleToMario, 0x400); - if (o->oDistanceToMario > 500.0f) - if (cur_obj_check_if_near_animation_end()) - o->oAction = PIRANHA_PLANT_ACT_STOPPED_BITING; + if (o->oDistanceToMario > 500.0f && cur_obj_check_if_near_animation_end()) { + o->oAction = PIRANHA_PLANT_ACT_STOPPED_BITING; + } // If the player is wearing the Metal Cap and interacts with the Piranha // Plant, the Piranha Plant will die. - if (o->oInteractStatus & INT_STATUS_INTERACTED) - if (gMarioState->flags & MARIO_METAL_CAP) - o->oAction = PIRANHA_PLANT_ACT_ATTACKED; + if ((o->oInteractStatus & INT_STATUS_INTERACTED) && (gMarioState->flags & MARIO_METAL_CAP)) { + o->oAction = PIRANHA_PLANT_ACT_ATTACKED; + } } /** @@ -277,11 +280,13 @@ void piranha_plant_act_biting(void) { * This is called from both the "stopped biting" state and the "sleeping" state. */ s32 mario_moving_fast_enough_to_make_piranha_plant_bite(void) { - if (gMarioStates[0].vel[1] > 10.0f) - return 1; - if (gMarioStates[0].forwardVel > 10.0f) - return 1; - return 0; + if (gMarioStates[0].vel[1] > 10.0f) { + return TRUE; + } + if (gMarioStates[0].forwardVel > 10.0f) { + return TRUE; + } + return FALSE; } /** @@ -293,8 +298,9 @@ void piranha_plant_act_stopped_biting(void) { cur_obj_become_intangible(); cur_obj_init_animation_with_sound(6); - if (cur_obj_check_if_near_animation_end()) + if (cur_obj_check_if_near_animation_end()) { o->oAction = PIRANHA_PLANT_ACT_SLEEPING; + } /** * Note that this state only occurs initially when the player goes further @@ -303,9 +309,9 @@ void piranha_plant_act_stopped_biting(void) { * of the Piranha Plant during the short time the Piranha Plant's nod * animation plays. */ - if (o->oDistanceToMario < 400.0f) - if (mario_moving_fast_enough_to_make_piranha_plant_bite()) - o->oAction = PIRANHA_PLANT_ACT_BITING; + if (o->oDistanceToMario < 400.0f && mario_moving_fast_enough_to_make_piranha_plant_bite()) { + o->oAction = PIRANHA_PLANT_ACT_BITING; + } } /** @@ -320,7 +326,7 @@ void (*TablePiranhaPlantActions[])(void) = { piranha_plant_attacked, // PIRANHA_PLANT_ATTACKED, piranha_plant_act_shrink_and_die, // PIRANHA_PLANT_ACT_SHRINK_AND_DIE, piranha_plant_act_wait_to_respawn, // PIRANHA_PLANT_ACT_WAIT_TO_RESPAWN, - piranha_plant_act_respawn // PIRANHA_PLANT_ACT_RESPAWN + piranha_plant_act_respawn, // PIRANHA_PLANT_ACT_RESPAWN }; /** @@ -331,10 +337,12 @@ void bhv_piranha_plant_loop(void) { // In WF, hide all Piranha Plants once high enough up. if (gCurrLevelNum == LEVEL_WF) { - if (gMarioObject->oPosY > 3400.0f) + if (gMarioObject->oPosY > 3400.0f) { cur_obj_hide(); - else + } else { cur_obj_unhide(); + } } + o->oInteractStatus = 0; } diff --git a/src/game/behaviors/platform_on_track.inc.c b/src/game/behaviors/platform_on_track.inc.c index f33a1656..51007e62 100644 --- a/src/game/behaviors/platform_on_track.inc.c +++ b/src/game/behaviors/platform_on_track.inc.c @@ -8,7 +8,7 @@ /** * Collision models for the different types of platforms. */ -static void const *sPlatformOnTrackCollisionModels[] = { +static Collision const *sPlatformOnTrackCollisionModels[] = { /* PLATFORM_ON_TRACK_TYPE_CARPET */ rr_seg7_collision_07029038, /* PLATFORM_ON_TRACK_TYPE_SKI_LIFT */ ccm_seg7_collision_070163F8, /* PLATFORM_ON_TRACK_TYPE_CHECKERED */ checkerboard_platform_seg8_collision_0800D710, @@ -18,10 +18,16 @@ static void const *sPlatformOnTrackCollisionModels[] = { /** * Paths for the different instances of these platforms. */ -static void const *sPlatformOnTrackPaths[] = { - rr_seg7_trajectory_0702EC3C, rr_seg7_trajectory_0702ECC0, ccm_seg7_trajectory_0701669C, - bitfs_seg7_trajectory_070159AC, hmc_seg7_trajectory_0702B86C, lll_seg7_trajectory_0702856C, - lll_seg7_trajectory_07028660, rr_seg7_trajectory_0702ED9C, rr_seg7_trajectory_0702EEE0, +static Trajectory const *sPlatformOnTrackPaths[] = { + rr_seg7_trajectory_0702EC3C, + rr_seg7_trajectory_0702ECC0, + ccm_seg7_trajectory_0701669C, + bitfs_seg7_trajectory_070159AC, + hmc_seg7_trajectory_0702B86C, + lll_seg7_trajectory_0702856C, + lll_seg7_trajectory_07028660, + rr_seg7_trajectory_0702ED9C, + rr_seg7_trajectory_0702EEE0, }; /** diff --git a/src/game/behaviors/pokey.inc.c b/src/game/behaviors/pokey.inc.c index df5d11f5..9f870869 100644 --- a/src/game/behaviors/pokey.inc.c +++ b/src/game/behaviors/pokey.inc.c @@ -66,7 +66,7 @@ void bhv_pokey_body_part_update(void) { o->parentObj->oPokeyAliveBodyPartFlags = o->parentObj->oPokeyAliveBodyPartFlags & ((1 << o->oBehParams2ndByte) ^ ~0); - o->oBehParams2ndByte -= 1; + o->oBehParams2ndByte--; } // Set the bottom body part size, and gradually increase it. @@ -109,7 +109,7 @@ void bhv_pokey_body_part_update(void) { // then die after a delay. if (obj_handle_attacks(&sPokeyBodyPartHitbox, o->oAction, sPokeyBodyPartAttackHandlers)) { - o->parentObj->oPokeyNumAliveBodyParts -= 1; + o->parentObj->oPokeyNumAliveBodyParts--; if (o->oBehParams2ndByte == 0) { o->parentObj->oPokeyHeadWasKilled = TRUE; // Last minute change to blue coins - not sure why they didn't @@ -123,7 +123,7 @@ void bhv_pokey_body_part_update(void) { cur_obj_become_intangible(); if (--o->oPokeyBodyPartDeathDelayAfterHeadKilled < 0) { - o->parentObj->oPokeyNumAliveBodyParts -= 1; + o->parentObj->oPokeyNumAliveBodyParts--; obj_die_if_health_non_positive(); } } else { @@ -181,7 +181,6 @@ static void pokey_act_uninitialized(void) { */ static void pokey_act_wander(void) { s32 targetAngleOffset; - struct Object *bodyPart; if (o->oPokeyNumAliveBodyParts == 0) { obj_mark_for_deletion(o); @@ -204,13 +203,14 @@ static void pokey_act_wander(void) { // is killed, the new part's index is equal to the number // of living body parts - bodyPart = spawn_object_relative(o->oPokeyNumAliveBodyParts, 0, 0, 0, o, - MODEL_POKEY_BODY_PART, bhvPokeyBodyPart); + struct Object *bodyPart + = spawn_object_relative(o->oPokeyNumAliveBodyParts, 0, 0, 0, o, + MODEL_POKEY_BODY_PART, bhvPokeyBodyPart); if (bodyPart != NULL) { o->oPokeyAliveBodyPartFlags = o->oPokeyAliveBodyPartFlags | (1 << o->oPokeyNumAliveBodyParts); - o->oPokeyNumAliveBodyParts += 1; + o->oPokeyNumAliveBodyParts++; o->oPokeyBottomBodyPartSize = 0.0f; obj_scale(bodyPart, 0.0f); @@ -234,7 +234,7 @@ static void pokey_act_wander(void) { if (!(o->oPokeyTurningAwayFromWall = obj_bounce_off_walls_edges_objects(&o->oPokeyTargetYaw))) { if (o->oPokeyChangeTargetTimer != 0) { - o->oPokeyChangeTargetTimer -= 1; + o->oPokeyChangeTargetTimer--; } else if (o->oDistanceToMario > 2000.0f) { o->oPokeyTargetYaw = obj_random_fixed_turn(0x2000); o->oPokeyChangeTargetTimer = random_linear_offset(30, 50); diff --git a/src/game/behaviors/pole.inc.c b/src/game/behaviors/pole.inc.c index d727751c..1066e003 100644 --- a/src/game/behaviors/pole.inc.c +++ b/src/game/behaviors/pole.inc.c @@ -1,3 +1,4 @@ + /** * Behaviors for bhvPoleGrabbing and bhvGiantPole. * @@ -16,7 +17,7 @@ void bhv_pole_init(void) { * This is equivalent to using `o->oBehParams2ndByte` according to * `spawn_objects_from_info`. */ - s32 tenthHitboxHeight = o->oBehParams >> 0x10 & 0xFF; + s32 tenthHitboxHeight = (o->oBehParams >> 16) & 0xFF; o->hitboxHeight = tenthHitboxHeight * 10; } @@ -26,9 +27,8 @@ void bhv_pole_init(void) { * first frame. */ void bhv_giant_pole_loop(void) { - struct Object *topBall; if (o->oTimer == 0) { - topBall = spawn_object(o, MODEL_YELLOW_SPHERE, bhvYellowBall); + struct Object *topBall = spawn_object(o, MODEL_YELLOW_SPHERE, bhvYellowBall); topBall->oPosY += o->hitboxHeight + 50.0f; } bhv_pole_base_loop(); diff --git a/src/game/behaviors/pole_base.inc.c b/src/game/behaviors/pole_base.inc.c index 543fa28d..874c8704 100644 --- a/src/game/behaviors/pole_base.inc.c +++ b/src/game/behaviors/pole_base.inc.c @@ -2,8 +2,9 @@ void bhv_pole_base_loop(void) { if (o->oPosY - 10.0f < gMarioObject->oPosY - && gMarioObject->oPosY < o->oPosY + o->hitboxHeight + 30.0f) - if (o->oTimer > 10) - if (!(gMarioStates[0].action & MARIO_PUNCHING)) - cur_obj_push_mario_away(70.0f); + && gMarioObject->oPosY < o->oPosY + o->hitboxHeight + 30.0f) { + if (o->oTimer > 10 && !(gMarioStates[0].action & MARIO_PUNCHING)) { + cur_obj_push_mario_away(70.0f); + } + } } diff --git a/src/game/behaviors/purple_switch.inc.c b/src/game/behaviors/purple_switch.inc.c index 912f7c00..a5157746 100644 --- a/src/game/behaviors/purple_switch.inc.c +++ b/src/game/behaviors/purple_switch.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvFloorSwitchHardcodedModel, bhvFloorSwitchGrills, and * bhvFloorSwitchAnimatesObject. @@ -7,7 +8,8 @@ */ void bhv_purple_switch_loop(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; + switch (o->oAction) { /** * Set the switch's model and scale. If Mario is standing near the @@ -22,6 +24,7 @@ void bhv_purple_switch_loop(void) { } } break; + /** * Collapse the switch downward, play a sound, and shake the screen. * Immediately transition to the ticking state. @@ -32,11 +35,12 @@ void bhv_purple_switch_loop(void) { cur_obj_play_sound_2(SOUND_GENERAL2_PURPLE_SWITCH); o->oAction = PURPLE_SWITCH_TICKING; cur_obj_shake_screen(SHAKE_POS_SMALL); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif } break; + /** * Play a continuous ticking sound that gets faster when time is almost * up. When time is up, move to a waiting-while-pressed state. @@ -57,6 +61,7 @@ void bhv_purple_switch_loop(void) { } } break; + /** * Make the switch look unpressed again, and transition back to the * idle state. @@ -67,6 +72,7 @@ void bhv_purple_switch_loop(void) { o->oAction = PURPLE_SWITCH_IDLE; } break; + /** * Mario is standing on the switch, but time has expired. Wait for * him to get off the switch, and when he does so, transition to the diff --git a/src/game/behaviors/pyramid_elevator.inc.c b/src/game/behaviors/pyramid_elevator.inc.c index 4379e70d..ac089de9 100644 --- a/src/game/behaviors/pyramid_elevator.inc.c +++ b/src/game/behaviors/pyramid_elevator.inc.c @@ -1,3 +1,4 @@ + /** * Behaviors for bhvPyramidElevator and bhvPyramidElevatorTrajectoryMarkerBall. * @@ -11,10 +12,10 @@ */ void bhv_pyramid_elevator_init(void) { s32 i; - struct Object *ball; for (i = 0; i < 10; i++) { - ball = spawn_object(o, MODEL_TRAJECTORY_MARKER_BALL, bhvPyramidElevatorTrajectoryMarkerBall); + struct Object *ball = spawn_object(o, MODEL_TRAJECTORY_MARKER_BALL, + bhvPyramidElevatorTrajectoryMarkerBall); ball->oPosY = 4600 - i * 460; } } @@ -26,8 +27,9 @@ void bhv_pyramid_elevator_loop(void) { * transition to the starting state. */ case PYRAMID_ELEVATOR_IDLE: - if (gMarioObject->platform == o) + if (gMarioObject->platform == o) { o->oAction = PYRAMID_ELEVATOR_START_MOVING; + } break; /** @@ -36,8 +38,9 @@ void bhv_pyramid_elevator_loop(void) { */ case PYRAMID_ELEVATOR_START_MOVING: o->oPosY = o->oHomeY - sins(o->oTimer * 0x1000) * 10.0f; - if (o->oTimer == 8) + if (o->oTimer == 8) { o->oAction = PYRAMID_ELEVATOR_CONSTANT_VELOCITY; + } break; /** diff --git a/src/game/behaviors/pyramid_top.inc.c b/src/game/behaviors/pyramid_top.inc.c index 824d24f2..14b6bc2f 100644 --- a/src/game/behaviors/pyramid_top.inc.c +++ b/src/game/behaviors/pyramid_top.inc.c @@ -1,3 +1,4 @@ + /** * Behaviors for bhvPyramidTop, bhvPyramidTopFragment, and * bhvPyramidPillarTouchDetector. @@ -14,14 +15,14 @@ * Spawn the four pillars' touch detectors. */ void bhv_pyramid_top_init(void) { - spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvPyramidPillarTouchDetector, 1789, 1024, 764, 0, 0, - 0); - spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvPyramidPillarTouchDetector, 1789, 896, -2579, 0, 0, - 0); - spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvPyramidPillarTouchDetector, -5883, 1024, -2579, 0, 0, - 0); - spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvPyramidPillarTouchDetector, -5883, 1024, 764, 0, 0, - 0); + spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvPyramidPillarTouchDetector, + 1789, 1024, 764, 0, 0, 0); + spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvPyramidPillarTouchDetector, + 1789, 896, -2579, 0, 0, 0); + spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvPyramidPillarTouchDetector, + -5883, 1024, -2579, 0, 0, 0); + spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvPyramidPillarTouchDetector, + -5883, 1024, 764, 0, 0, 0); } /** @@ -29,8 +30,6 @@ void bhv_pyramid_top_init(void) { * fragments in the process. */ void bhv_pyramid_top_spinning(void) { - struct Object *pyramidFragment; - // (TODO: What is this doing) o->oPosX = o->oHomeX + sins(o->oTimer * 0x4000) * 40.0f; @@ -52,7 +51,7 @@ void bhv_pyramid_top_spinning(void) { // Every frame until 90 frames have passed, generate a pyramid fragment // with a random velocity and angle. if (o->oTimer < 90) { - pyramidFragment = spawn_object(o, MODEL_DIRT_ANIMATION, bhvPyramidTopFragment); + struct Object *pyramidFragment = spawn_object(o, MODEL_DIRT_ANIMATION, bhvPyramidTopFragment); pyramidFragment->oForwardVel = random_float() * 10.0f + 20.0f; pyramidFragment->oMoveAngleYaw = random_u16(); pyramidFragment->oPyramidTopFragmentsScale = 0.8f; @@ -76,9 +75,7 @@ void bhv_pyramid_top_explode(void) { // Generate 30 pyramid fragments with random properties. for (i = 0; i < 30; i++) { - pyramidFragment = spawn_object( - o, MODEL_DIRT_ANIMATION, bhvPyramidTopFragment - ); + pyramidFragment = spawn_object(o, MODEL_DIRT_ANIMATION, bhvPyramidTopFragment); pyramidFragment->oForwardVel = random_float() * 50 + 80; pyramidFragment->oVelY = random_float() * 80 + 20; pyramidFragment->oMoveAngleYaw = random_u16(); @@ -147,7 +144,7 @@ void bhv_pyramid_top_fragment_loop(void) { */ void bhv_pyramid_pillar_touch_detector_loop(void) { cur_obj_become_tangible(); - if (obj_check_if_collided_with_object(o, gMarioObject) == 1) { + if (obj_check_if_collided_with_object(o, gMarioObject) == TRUE) { // Increase the pyramid top's count of pillars touched. o->parentObj->oPyramidTopPillarsTouched++; o->activeFlags = ACTIVE_FLAG_DEACTIVATED; diff --git a/src/game/behaviors/pyramid_wall.inc.c b/src/game/behaviors/pyramid_wall.inc.c index 4e805f8d..8306aca6 100644 --- a/src/game/behaviors/pyramid_wall.inc.c +++ b/src/game/behaviors/pyramid_wall.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvSslMovingPyramidWall. * @@ -11,7 +12,6 @@ * positions. */ void bhv_ssl_moving_pyramid_wall_init(void) { - switch (o->oBehParams2ndByte) { case PYRAMID_WALL_BP_POSITION_HIGH: break; @@ -36,14 +36,16 @@ void bhv_ssl_moving_pyramid_wall_loop(void) { switch (o->oAction) { case PYRAMID_WALL_ACT_MOVING_DOWN: o->oVelY = -5.12f; - if (o->oTimer == 100) + if (o->oTimer == 100) { o->oAction = PYRAMID_WALL_ACT_MOVING_UP; + } break; case PYRAMID_WALL_ACT_MOVING_UP: o->oVelY = 5.12f; - if (o->oTimer == 100) + if (o->oTimer == 100) { o->oAction = PYRAMID_WALL_ACT_MOVING_DOWN; + } break; } diff --git a/src/game/behaviors/racing_penguin.inc.c b/src/game/behaviors/racing_penguin.inc.c index 5aeeb257..21639ec1 100644 --- a/src/game/behaviors/racing_penguin.inc.c +++ b/src/game/behaviors/racing_penguin.inc.c @@ -1,3 +1,5 @@ +// racing_penguin.inc.c + struct RacingPenguinData { s16 text; f32 radius; @@ -27,7 +29,7 @@ static void racing_penguin_act_wait_for_mario(void) { static void racing_penguin_act_show_init_text(void) { s32 response = obj_update_race_proposition_dialog(sRacingPenguinData[o->oBehParams2ndByte].text); - if (response == 1) { + if (response == DIALOG_RESPONSE_YES) { struct Object *child; child = cur_obj_nearest_object_with_behavior(bhvPenguinRaceFinishLine); @@ -42,7 +44,7 @@ static void racing_penguin_act_show_init_text(void) { o->oAction = RACING_PENGUIN_ACT_PREPARE_FOR_RACE; o->oVelY = 60.0f; - } else if (response == 2) { + } else if (response == DIALOG_RESPONSE_NO) { o->oAction = RACING_PENGUIN_ACT_WAIT_FOR_MARIO; o->oRacingPenguinInitTextCooldown = 60; } @@ -58,15 +60,12 @@ static void racing_penguin_act_prepare_for_race(void) { } static void racing_penguin_act_race(void) { - f32 targetSpeed; - f32 minSpeed; - if (cur_obj_follow_path(0) == PATH_REACHED_END) { o->oRacingPenguinReachedBottom = TRUE; o->oAction = RACING_PENGUIN_ACT_FINISH_RACE; } else { - targetSpeed = o->oPosY - gMarioObject->oPosY; - minSpeed = 70.0f; + f32 targetSpeed = o->oPosY - gMarioObject->oPosY; + f32 minSpeed = 70.0f; cur_obj_play_sound_1(SOUND_AIR_ROUGH_SLIDE); @@ -108,14 +107,12 @@ static void racing_penguin_act_finish_race(void) { set_camera_shake_from_point(SHAKE_POS_SMALL, o->oPosX, o->oPosY, o->oPosZ); o->oForwardVel = 0.0f; } - } else if (cur_obj_init_anim_and_check_if_end(2) != 0) { + } else if (cur_obj_init_anim_and_check_if_end(2)) { o->oAction = RACING_PENGUIN_ACT_SHOW_FINAL_TEXT; } } static void racing_penguin_act_show_final_text(void) { - s32 textResult; - if (o->oRacingPenguinFinalTextbox == 0) { if (cur_obj_rotate_yaw_toward(0, 200)) { cur_obj_init_animation_with_sound(3); @@ -143,7 +140,9 @@ static void racing_penguin_act_show_final_text(void) { o->oForwardVel = 4.0f; } } else if (o->oRacingPenguinFinalTextbox > 0) { - if ((textResult = cur_obj_update_dialog_with_cutscene(2, 1, CUTSCENE_DIALOG, o->oRacingPenguinFinalTextbox)) != 0) { + s32 textResult; + if ((textResult = cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + DIALOG_FLAG_TURN_TO_MARIO, CUTSCENE_DIALOG, o->oRacingPenguinFinalTextbox))) { o->oRacingPenguinFinalTextbox = -1; o->oTimer = 0; } @@ -184,15 +183,14 @@ void bhv_racing_penguin_update(void) { cur_obj_move_standard(78); cur_obj_align_gfx_with_floor(); cur_obj_push_mario_away_from_cylinder(sRacingPenguinData[o->oBehParams2ndByte].radius, - sRacingPenguinData[o->oBehParams2ndByte].height); + sRacingPenguinData[o->oBehParams2ndByte].height); } void bhv_penguin_race_finish_line_update(void) { - if (o->parentObj->oRacingPenguinReachedBottom - || (o->oDistanceToMario < 1000.0f && gMarioObject->oPosZ - o->oPosZ < 0.0f)) { - if (!o->parentObj->oRacingPenguinReachedBottom) { - o->parentObj->oRacingPenguinMarioWon = TRUE; - } + if ((o->parentObj->oRacingPenguinReachedBottom + || (o->oDistanceToMario < 1000.0f && gMarioObject->oPosZ - o->oPosZ < 0.0f)) + && !o->parentObj->oRacingPenguinReachedBottom) { + o->parentObj->oRacingPenguinMarioWon = TRUE; } } diff --git a/src/game/behaviors/recovery_heart.inc.c b/src/game/behaviors/recovery_heart.inc.c index 6bebfaa3..83e082e5 100644 --- a/src/game/behaviors/recovery_heart.inc.c +++ b/src/game/behaviors/recovery_heart.inc.c @@ -1,3 +1,4 @@ +// recovery_heart.inc.c struct ObjectHitbox sRecoveryHeartHitbox = { /* interactType: */ 0, @@ -16,7 +17,7 @@ void bhv_recovery_heart_loop(void) { if (obj_check_if_collided_with_object(o, gMarioObject)) { if (o->oSpinningHeartPlayedSound == 0) { cur_obj_play_sound_2(SOUND_GENERAL_HEART_SPIN); - o->oSpinningHeartPlayedSound += 1; + o->oSpinningHeartPlayedSound++; } o->oAngleVelYaw = (s32)(200.0f * gMarioStates[0].forwardVel) + 1000; diff --git a/src/game/behaviors/red_coin.inc.c b/src/game/behaviors/red_coin.inc.c index 40d7d6da..6c4ef8ef 100644 --- a/src/game/behaviors/red_coin.inc.c +++ b/src/game/behaviors/red_coin.inc.c @@ -1,3 +1,4 @@ + /** * This file contains the initialization and behavior for red coins. * Behavior controls audio and the orange number spawned, as well as interacting with @@ -27,19 +28,17 @@ void bhv_red_coin_init(void) { struct Surface *dummyFloor; UNUSED f32 floorHeight = find_floor(o->oPosX, o->oPosY, o->oPosZ, &dummyFloor); + // Set the red coins to have a parent of the closest red coin star. struct Object *hiddenRedCoinStar; - // Set the red coins to have a parent of the closest red coin star. - hiddenRedCoinStar = cur_obj_nearest_object_with_behavior(bhvHiddenRedCoinStar); - if (hiddenRedCoinStar != NULL) + if ((hiddenRedCoinStar = + cur_obj_nearest_object_with_behavior(bhvHiddenRedCoinStar)) != NULL) { o->parentObj = hiddenRedCoinStar; - else { - hiddenRedCoinStar = cur_obj_nearest_object_with_behavior(bhvBowserCourseRedCoinStar); - if (hiddenRedCoinStar != NULL) { - o->parentObj = hiddenRedCoinStar; - } else { - o->parentObj = NULL; - } + } else if ((hiddenRedCoinStar = + cur_obj_nearest_object_with_behavior(bhvBowserCourseRedCoinStar)) != NULL) { + o->parentObj = hiddenRedCoinStar; + } else { + o->parentObj = NULL; } obj_set_hitbox(o, &sRedCoinHitbox); @@ -69,7 +68,7 @@ void bhv_red_coin_loop(void) { // On all versions but the JP version, each coin collected plays a higher noise. #ifndef VERSION_JP play_sound(SOUND_MENU_COLLECT_RED_COIN - + (((u8) o->parentObj->oHiddenStarTriggerCounter - 1) << 16), + + (((u8) o->parentObj->oHiddenStarTriggerCounter - 1) << 16), gGlobalSoundSource); #endif } diff --git a/src/game/behaviors/reds_star_marker.inc.c b/src/game/behaviors/reds_star_marker.inc.c index eab82d20..03298a64 100644 --- a/src/game/behaviors/reds_star_marker.inc.c +++ b/src/game/behaviors/reds_star_marker.inc.c @@ -1,4 +1,4 @@ - +// reds_star_marker.inc.c // Filename is abbreviated to prevent compiler seg fault void bhv_red_coin_star_marker_init(void) { diff --git a/src/game/behaviors/rolling_log.inc.c b/src/game/behaviors/rolling_log.inc.c index dd88e552..d77a3b5b 100644 --- a/src/game/behaviors/rolling_log.inc.c +++ b/src/game/behaviors/rolling_log.inc.c @@ -1,4 +1,4 @@ -// rolling_log.c.inc +// rolling_log.inc.c // why are the falling platforms and rolling logs grouped // together? seems strange, but it also cooresponds to the @@ -10,50 +10,56 @@ void bhv_ttm_rolling_log_init(void) { o->oPitouneUnkF8 = 3970.0f; o->oPitouneUnkFC = 3654.0f; o->oPitouneUnkF4 = 271037.0f; + o->oMoveAngleYaw = 8810; - o->oForwardVel = 0; - o->oVelX = 0; - o->oVelZ = 0; + o->oForwardVel = 0.0f; + o->oVelX = 0.0f; + o->oVelZ = 0.0f; o->oFaceAnglePitch = 0; o->oAngleVelPitch = 0; } void rolling_log_roll_log(void) { - f32 sp24; - if (gMarioObject->platform == o) { - sp24 = (gMarioObject->header.gfx.pos[2] - o->oPosZ) * coss(-1*o->oMoveAngleYaw) - - (gMarioObject->header.gfx.pos[0] - o->oPosX) * sins(-1*o->oMoveAngleYaw); - if (sp24 > 0) + f32 sp24 = (gMarioObject->header.gfx.pos[2] - o->oPosZ) * coss(-1*o->oMoveAngleYaw) + - (gMarioObject->header.gfx.pos[0] - o->oPosX) * sins(-1*o->oMoveAngleYaw); + if (sp24 > 0) { o->oAngleVelPitch += 0x10; - else + } else { o->oAngleVelPitch -= 0x10; + } - if (o->oAngleVelPitch > 0x200) + if (o->oAngleVelPitch > 0x200) { o->oAngleVelPitch = 0x200; + } - if (o->oAngleVelPitch < -0x200) + if (o->oAngleVelPitch < -0x200) { o->oAngleVelPitch = -0x200; + } } else { if (is_point_close_to_object(o, o->oHomeX, o->oHomeY, o->oHomeZ, 100)) { if (o->oAngleVelPitch != 0) { - if (o->oAngleVelPitch > 0) + if (o->oAngleVelPitch > 0) { o->oAngleVelPitch -= 0x10; - else + } else { o->oAngleVelPitch += 0x10; + } - if (o->oAngleVelPitch < 0x10 && o->oAngleVelPitch > -0x10) + if (o->oAngleVelPitch < 0x10 && o->oAngleVelPitch > -0x10) { o->oAngleVelPitch = 0; + } } } else { if (o->oAngleVelPitch != 0x100) { - if (o->oAngleVelPitch > 0x100) + if (o->oAngleVelPitch > 0x100) { o->oAngleVelPitch -= 0x10; - else + } else { o->oAngleVelPitch += 0x10; + } - if (o->oAngleVelPitch < 0x110 && o->oAngleVelPitch > 0xF0) + if (o->oAngleVelPitch < 0x110 && o->oAngleVelPitch > 0xF0) { o->oAngleVelPitch = 0x100; + } } } } @@ -73,11 +79,11 @@ void bhv_rolling_log_loop(void) { o->oPosZ += o->oVelZ; if (o->oPitouneUnkF4 < sqr(o->oPosX - o->oPitouneUnkF8) + sqr(o->oPosZ - o->oPitouneUnkFC)) { - o->oForwardVel = 0; + o->oForwardVel = 0.0f; o->oPosX = prevX; o->oPosZ = prevZ; - o->oVelX = 0; - o->oVelZ = 0; + o->oVelX = 0.0f; + o->oVelZ = 0.0f; } o->oFaceAnglePitch += o->oAngleVelPitch; @@ -104,11 +110,14 @@ void volcano_act_1(void) { void volcano_act_3(void) { o->oAngleVelPitch = 0x90; o->oFaceAnglePitch += o->oAngleVelPitch; - if (o->oFaceAnglePitch > 0) - o->oFaceAnglePitch = 0; - if (o->oTimer == 200) + if (o->oFaceAnglePitch > 0) { + o->oFaceAnglePitch = 0; + } + + if (o->oTimer == 200) { o->oAction = 0; + } } void bhv_volcano_trap_loop(void) { @@ -146,9 +155,9 @@ void bhv_lll_rolling_log_init(void) { o->oPitouneUnkF4 = 1048576.0f; o->oMoveAngleYaw = 0x3FFF; - o->oForwardVel = 0; - o->oVelX = 0; - o->oVelZ = 0; + o->oForwardVel = 0.0f; + o->oVelX = 0.0f; + o->oVelZ = 0.0f; o->oFaceAnglePitch = 0; o->oAngleVelPitch = 0; } diff --git a/src/game/behaviors/rotating_octagonal_plat.inc.c b/src/game/behaviors/rotating_octagonal_plat.inc.c index 86d758c8..3e644848 100644 --- a/src/game/behaviors/rotating_octagonal_plat.inc.c +++ b/src/game/behaviors/rotating_octagonal_plat.inc.c @@ -1,15 +1,15 @@ // rotating_octagonal_plat.inc.c -void const *D_80331A44[] = { +static const Collision *sOctagonalPlatformCollision[] = { bits_seg7_collision_0701AA84, rr_seg7_collision_07029508, }; -s16 D_80331A4C[] = { 300, -300, 600, -600 }; +static s16 sOctagonalPlatformAngularVelocities[] = { 300, -300, 600, -600 }; void bhv_rotating_octagonal_plat_init(void) { - o->collisionData = segmented_to_virtual(D_80331A44[(u8)(o->oBehParams >> 16)]); - o->oAngleVelYaw = D_80331A4C[(u8)(o->oBehParams >> 24)]; + o->collisionData = segmented_to_virtual(sOctagonalPlatformCollision[(o->oBehParams >> 16) & 0xFF]); + o->oAngleVelYaw = sOctagonalPlatformAngularVelocities[(o->oBehParams >> 24) & 0xFF]; } void bhv_rotating_octagonal_plat_loop(void) { diff --git a/src/game/behaviors/rotating_platform.inc.c b/src/game/behaviors/rotating_platform.inc.c index c81aaa80..9f381b8e 100644 --- a/src/game/behaviors/rotating_platform.inc.c +++ b/src/game/behaviors/rotating_platform.inc.c @@ -1,11 +1,18 @@ -// rotating_platform.c.inc +// rotating_platform.inc.c #include "levels/wf/header.h" #include "levels/wdw/header.h" +struct WFRotatingPlatformData { + s16 unused; + s16 scale; + const Collision *collisionData; + s16 collisionDistance; +}; + struct WFRotatingPlatformData sWFRotatingPlatformData[] = { { 0, 100, wf_seg7_collision_rotating_platform, 2000 }, - { 0, 150, wdw_seg7_collision_070186B4, 1000 } + { 0, 150, wdw_seg7_collision_070186B4, 1000 }, }; void bhv_wf_rotating_wooden_platform_loop(void) { @@ -16,8 +23,9 @@ void bhv_wf_rotating_wooden_platform_loop(void) { } } else { o->oAngleVelYaw = 0x100; - if (o->oTimer > 126) + if (o->oTimer > 126) { o->oAction = 0; + } cur_obj_play_sound_1(SOUND_ENV_ELEVATOR2); } cur_obj_rotate_face_angle_using_vel(); diff --git a/src/game/behaviors/scuttlebug.inc.c b/src/game/behaviors/scuttlebug.inc.c index 16840e1c..6ec01555 100644 --- a/src/game/behaviors/scuttlebug.inc.c +++ b/src/game/behaviors/scuttlebug.inc.c @@ -1,15 +1,15 @@ -// scuttlebug.c.inc +// scuttlebug.inc.c struct ObjectHitbox sScuttlebugHitbox = { - /* interactType: */ INTERACT_BOUNCE_TOP, - /* downOffset: */ 0, + /* interactType: */ INTERACT_BOUNCE_TOP, + /* downOffset: */ 0, /* damageOrCoinValue: */ 1, - /* health: */ 1, - /* numLootCoins: */ 3, - /* radius: */ 130, - /* height: */ 70, - /* hurtboxRadius: */ 90, - /* hurtboxHeight: */ 60, + /* health: */ 1, + /* numLootCoins: */ 3, + /* radius: */ 130, + /* height: */ 70, + /* hurtboxRadius: */ 90, + /* hurtboxHeight: */ 60, }; s32 update_angle_from_move_flags(s32 *angle) { @@ -24,19 +24,26 @@ s32 update_angle_from_move_flags(s32 *angle) { } void bhv_scuttlebug_loop(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; f32 sp18; + cur_obj_update_floor_and_walls(); + if (o->oSubAction != 0 && cur_obj_set_hitbox_and_die_if_attacked(&sScuttlebugHitbox, SOUND_OBJ_DYING_ENEMY1, - o->oScuttlebugUnkF4)) + o->oScuttlebugUnkF4)) { o->oSubAction = 3; - if (o->oSubAction != 1) + } + + if (o->oSubAction != 1) { o->oScuttlebugUnkF8 = 0; + } + switch (o->oSubAction) { case 0: - if (o->oMoveFlags & OBJ_MOVE_LANDED) + if (o->oMoveFlags & OBJ_MOVE_LANDED) { cur_obj_play_sound_2(SOUND_OBJ_GOOMBA_ALERT); + } if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) { o->oHomeX = o->oPosX; o->oHomeY = o->oPosY; @@ -44,11 +51,12 @@ void bhv_scuttlebug_loop(void) { o->oSubAction++; } break; + case 1: o->oForwardVel = 5.0f; - if (cur_obj_lateral_dist_from_mario_to_home() > 1000.0f) + if (cur_obj_lateral_dist_from_mario_to_home() > 1000.0f) { o->oAngleToMario = cur_obj_angle_to_home(); - else { + } else { if (o->oScuttlebugUnkF8 == 0) { o->oScuttlebugUnkFC = 0; o->oAngleToMario = obj_angle_to_object(o, gMarioObject); @@ -60,66 +68,84 @@ void bhv_scuttlebug_loop(void) { } else if (o->oScuttlebugUnkF8 == 1) { o->oForwardVel = 15.0f; o->oScuttlebugUnkFC++; - if (o->oScuttlebugUnkFC > 50) + if (o->oScuttlebugUnkFC > 50) { o->oScuttlebugUnkF8 = 0; + } } } - if (update_angle_from_move_flags(&o->oAngleToMario)) + if (update_angle_from_move_flags(&o->oAngleToMario)) { o->oSubAction = 2; + } cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x200); break; + case 2: o->oForwardVel = 5.0f; - if ((s16) o->oMoveAngleYaw == (s16) o->oAngleToMario) + if ((s16) o->oMoveAngleYaw == (s16) o->oAngleToMario) { o->oSubAction = 1; - if (o->oPosY - o->oHomeY < -200.0f) + } + if (o->oPosY - o->oHomeY < -200.0f) { obj_mark_for_deletion(o); + } cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x400); break; + case 3: - o->oFlags &= ~8; + o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; o->oForwardVel = -10.0f; o->oVelY = 30.0f; cur_obj_play_sound_2(SOUND_OBJ2_SCUTTLEBUG_ALERT); o->oSubAction++; break; + case 4: o->oForwardVel = -10.0f; if (o->oMoveFlags & OBJ_MOVE_LANDED) { o->oSubAction++; o->oVelY = 0.0f; o->oScuttlebugUnkFC = 0; - o->oFlags |= 8; + o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; o->oInteractStatus = 0; } break; + case 5: o->oForwardVel = 2.0f; o->oScuttlebugUnkFC++; - if (o->oScuttlebugUnkFC > 30) + if (o->oScuttlebugUnkFC > 30) { o->oSubAction = 0; + } break; } - if (o->oForwardVel < 10.0f) + + if (o->oForwardVel < 10.0f) { sp18 = 1.0f; - else + } else { sp18 = 3.0f; - cur_obj_init_animation_with_accel_and_sound(0, sp18); - if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) - set_obj_anim_with_accel_and_sound(1, 23, SOUND_OBJ2_SCUTTLEBUG_WALK); - if (o->parentObj != o) { - if (obj_is_hidden(o)) - obj_mark_for_deletion(o); - if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) - o->parentObj->oScuttlebugSpawnerUnk88 = 1; } + + cur_obj_init_animation_with_accel_and_sound(0, sp18); + + if (o->oMoveFlags & OBJ_MOVE_MASK_ON_GROUND) { + set_obj_anim_with_accel_and_sound(1, 23, SOUND_OBJ2_SCUTTLEBUG_WALK); + } + + if (o->parentObj != o) { + if (obj_is_hidden(o)) { + obj_mark_for_deletion(o); + } + if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) { + o->parentObj->oScuttlebugSpawnerUnk88 = 1; + } + } + cur_obj_move_standard(-50); } void bhv_scuttlebug_spawn_loop(void) { - struct Object *scuttlebug; if (o->oAction == 0) { if (o->oTimer > 30 && 500.0f < o->oDistanceToMario && o->oDistanceToMario < 1500.0f) { + struct Object *scuttlebug; cur_obj_play_sound_2(SOUND_OBJ2_SCUTTLEBUG_ALERT); scuttlebug = spawn_object(o, MODEL_SCUTTLEBUG, bhvScuttlebug); scuttlebug->oScuttlebugUnkF4 = o->oScuttlebugSpawnerUnkF4; diff --git a/src/game/behaviors/seaweed.inc.c b/src/game/behaviors/seaweed.inc.c index 4a9528d2..4399d029 100644 --- a/src/game/behaviors/seaweed.inc.c +++ b/src/game/behaviors/seaweed.inc.c @@ -1,4 +1,4 @@ -// seaweed.c.inc +// seaweed.inc.c void bhv_seaweed_init(void) { o->header.gfx.animInfo.animFrame = random_float() * 80.0f; diff --git a/src/game/behaviors/seesaw_platform.inc.c b/src/game/behaviors/seesaw_platform.inc.c index 81a47e76..5b2e4bc1 100644 --- a/src/game/behaviors/seesaw_platform.inc.c +++ b/src/game/behaviors/seesaw_platform.inc.c @@ -6,10 +6,15 @@ /** * Collision models for the different seesaw platforms. */ -static void const *sSeesawPlatformCollisionModels[] = { - bitdw_seg7_collision_0700F70C, bits_seg7_collision_0701ADD8, bits_seg7_collision_0701AE5C, - bob_seg7_collision_bridge, bitfs_seg7_collision_07015928, rr_seg7_collision_07029750, - rr_seg7_collision_07029858, vcutm_seg7_collision_0700AC44, +static Collision const *sSeesawPlatformCollisionModels[] = { + bitdw_seg7_collision_0700F70C, + bits_seg7_collision_0701ADD8, + bits_seg7_collision_0701AE5C, + bob_seg7_collision_bridge, + bitfs_seg7_collision_07015928, + rr_seg7_collision_07029750, + rr_seg7_collision_07029858, + vcutm_seg7_collision_0700AC44, }; /** @@ -39,7 +44,7 @@ void bhv_seesaw_platform_update(void) { if (gMarioObject->platform == o) { // Rotate toward mario f32 rotation = o->oDistanceToMario * coss(o->oAngleToMario - o->oMoveAngleYaw); - UNUSED s32 unused; + UNUSED u8 filler[4]; // Deceleration is faster than acceleration if (o->oSeesawPlatformPitchVel * rotation < 0) { diff --git a/src/game/behaviors/shock_wave.inc.c b/src/game/behaviors/shock_wave.inc.c index c714e91a..a580baa2 100644 --- a/src/game/behaviors/shock_wave.inc.c +++ b/src/game/behaviors/shock_wave.inc.c @@ -1,25 +1,44 @@ -// shock_wave.c.inc +// shock_wave.inc.c -f32 D_8032F420[] = { 1.9f, 2.4f, 4.0f, 4.8f }; +/** + * Shockwave scale distance hit points + */ +f32 sBowserShockwaveHitPoints[] = { 1.9f, 2.4f, 4.0f, 4.8f }; +/** + * Bowser's shockwave attack main loop + */ void bhv_bowser_shock_wave_loop(void) { - f32 sp2C, sp28, sp24, sp20; - s16 sp1E = 70; - o->oBowserShockWaveUnkF4 = o->oTimer * 10; - cur_obj_scale(o->oBowserShockWaveUnkF4); - if (gGlobalTimer % 3) - o->oOpacity -= 1; - if (o->oTimer > sp1E) + f32 distMin1, distMax1, distMin2, distMax2; + s16 fadeFrames = 70; + + // Scale shockwave as the timer goes on + o->oBowserShockWaveScale = o->oTimer * 10; + cur_obj_scale(o->oBowserShockWaveScale); + + // Slightly reduce opacity each 3 frames + if (gGlobalTimer % 3 != 0) { + o->oOpacity--; + } + // Reduce opacity faster after 70 frames have passed + if (o->oTimer > fadeFrames) { o->oOpacity -= 5; - if (o->oOpacity <= 0) + } + // Delete object when it's fully transparent + if (o->oOpacity <= 0) { obj_mark_for_deletion(o); - if (o->oTimer < sp1E && mario_is_in_air_action() == 0) { - sp2C = o->oBowserShockWaveUnkF4 * D_8032F420[0]; - sp28 = o->oBowserShockWaveUnkF4 * D_8032F420[1]; - sp24 = o->oBowserShockWaveUnkF4 * D_8032F420[2]; - sp20 = o->oBowserShockWaveUnkF4 * D_8032F420[3]; - if ((sp2C < o->oDistanceToMario && o->oDistanceToMario < sp28) - || (sp24 < o->oDistanceToMario && o->oDistanceToMario < sp20)) - gMarioObject->oInteractStatus |= INT_STATUS_HIT_BY_SHOCKWAVE; + } + // If object times is less than 70 frame and Mario is not in the air... + if (o->oTimer < fadeFrames && !mario_is_in_air_action()) { + // ..define distance values depending of the scale multiplied by hit points + distMin1 = o->oBowserShockWaveScale * sBowserShockwaveHitPoints[0]; + distMax1 = o->oBowserShockWaveScale * sBowserShockwaveHitPoints[1]; + distMin2 = o->oBowserShockWaveScale * sBowserShockwaveHitPoints[2]; + distMax2 = o->oBowserShockWaveScale * sBowserShockwaveHitPoints[3]; + // If Mario is in between distMin and distMax values, shock him + if ((distMin1 < o->oDistanceToMario && o->oDistanceToMario < distMax1) + || (distMin2 < o->oDistanceToMario && o->oDistanceToMario < distMax2)) { + gMarioObject->oInteractStatus |= INT_STATUS_MARIO_SHOCKWAVE; + } } } diff --git a/src/game/behaviors/skeeter.inc.c b/src/game/behaviors/skeeter.inc.c index a726760f..522d38d1 100644 --- a/src/game/behaviors/skeeter.inc.c +++ b/src/game/behaviors/skeeter.inc.c @@ -1,3 +1,5 @@ +// skeeter.inc.c + struct Struct80331C38 { s16 unk00; s16 unk02; @@ -45,10 +47,10 @@ static void skeeter_act_idle(void) { if (o->oMoveFlags & OBJ_MOVE_AT_WATER_SURFACE) { skeeter_spawn_waves(); if (o->oTimer > 60 - && obj_smooth_turn(&o->oSkeeterUnk1AC, &o->oMoveAngleYaw, o->oSkeeterTargetAngle, 0.02f, - 5, 50, 200)) { + && obj_smooth_turn(&o->oSkeeterUnk1AC, &o->oMoveAngleYaw, o->oSkeeterTargetAngle, + 0.02f, 5, 50, 200)) { if (o->oSkeeterWaitTime != 0) { - o->oSkeeterWaitTime -= 1; + o->oSkeeterWaitTime--; } else if (cur_obj_check_if_near_animation_end()) { cur_obj_play_sound_2(SOUND_OBJ_WALKING_WATER); o->oAction = SKEETER_ACT_LUNGE; @@ -70,7 +72,7 @@ static void skeeter_act_lunge(void) { if (o->oMoveFlags & OBJ_MOVE_HIT_WALL) { o->oMoveAngleYaw = cur_obj_reflect_move_angle_off_wall(); o->oForwardVel *= 0.3f; - o->oFlags &= ~0x00000008; + o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; } if (obj_forward_vel_approach(0.0f, 0.8f) && cur_obj_check_if_at_animation_end()) { @@ -84,7 +86,7 @@ static void skeeter_act_lunge(void) { o->oAction = SKEETER_ACT_IDLE; o->oSkeeterWaitTime = random_linear_offset(0, 30); - o->oFlags |= 0x00000008; + o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; } } } @@ -101,23 +103,23 @@ static void skeeter_act_walk(void) { cur_obj_init_animation_with_accel_and_sound(2, sp24); cur_obj_play_sound_at_anim_range(3, 13, SOUND_OBJ_SKEETER_WALK); - if (o->oSkeeterUnkF8 != 0) { - o->oSkeeterUnkF8 = obj_resolve_collisions_and_turn(o->oSkeeterTargetAngle, 0x400); + if (o->oSkeeterTurningAwayFromWall) { + o->oSkeeterTurningAwayFromWall = obj_resolve_collisions_and_turn(o->oSkeeterTargetAngle, 0x400); } else { if (o->oDistanceToMario >= 25000.0f) { o->oSkeeterTargetAngle = o->oAngleToMario; o->oSkeeterWaitTime = random_linear_offset(20, 30); } - if ((o->oSkeeterUnkF8 = obj_bounce_off_walls_edges_objects(&o->oSkeeterTargetAngle)) == 0) { + if (!(o->oSkeeterTurningAwayFromWall = obj_bounce_off_walls_edges_objects(&o->oSkeeterTargetAngle))) { if (o->oDistanceToMario < 500.0f) { o->oSkeeterTargetAngle = o->oAngleToMario; o->oSkeeterUnkFC = 20.0f; } else { o->oSkeeterUnkFC = 10.0f; if (o->oSkeeterWaitTime != 0) { - o->oSkeeterWaitTime -= 1; - } else if (cur_obj_check_if_near_animation_end() != 0) { + o->oSkeeterWaitTime--; + } else if (cur_obj_check_if_near_animation_end()) { if (random_u16() & 0x0003) { o->oSkeeterTargetAngle = obj_random_fixed_turn(0x2000); o->oSkeeterWaitTime = random_linear_offset(100, 100); diff --git a/src/game/behaviors/sl_snowman_wind.inc.c b/src/game/behaviors/sl_snowman_wind.inc.c index 7d84258b..2bdc5ca2 100644 --- a/src/game/behaviors/sl_snowman_wind.inc.c +++ b/src/game/behaviors/sl_snowman_wind.inc.c @@ -1,42 +1,47 @@ -// sl_snowman_wind.c.inc +// sl_snowman_wind.inc.c void bhv_sl_snowman_wind_loop(void) { - UNUSED s32 unusedVar = 0; + UNUSED s32 unused = 0; s16 marioAngleFromWindSource; Vec3f tempPos; - - if (o->oTimer == 0) + + if (o->oTimer == 0) { o->oSLSnowmanWindOriginalYaw = o->oMoveAngleYaw; - + } + // Waiting for Mario to approach. if (o->oSubAction == SL_SNOWMAN_WIND_ACT_IDLE) { o->oDistanceToMario = 0; - + // Check if Mario is within 1000 units of the center of the bridge, and ready to speak. vec3f_copy_2(tempPos, &o->oPosX); obj_set_pos(o, 1100, 3328, 1164); // Position is in the middle of the ice bridge - if (cur_obj_can_mario_activate_textbox(1000.0f, 30.0f, 0x7FFF)) + if (cur_obj_can_mario_activate_textbox(1000.0f, 30.0f, 0x7FFF)) { o->oSubAction++; + } vec3f_copy_2(&o->oPosX, tempPos); - + // Mario has come close, begin dialog. } else if (o->oSubAction == SL_SNOWMAN_WIND_ACT_TALKING) { - if (cur_obj_update_dialog(2, 2, DIALOG_153, 0)) + if (cur_obj_update_dialog(MARIO_DIALOG_LOOK_UP, DIALOG_FLAG_TEXT_DEFAULT, DIALOG_153, 0)) { o->oSubAction++; - + } + // Blowing, spawn wind particles (SL_SNOWMAN_WIND_ACT_BLOWING) } else if (o->oDistanceToMario < 1500.0f && absf(gMarioObject->oPosY - o->oHomeY) < 500.0f) { // Point towards Mario, but only within 0x1500 angle units of the original angle. if ((marioAngleFromWindSource = o->oAngleToMario - o->oSLSnowmanWindOriginalYaw) > 0) { - if (marioAngleFromWindSource < 0x1500) + if (marioAngleFromWindSource < 0x1500) { o->oMoveAngleYaw = o->oAngleToMario; - else + } else { o->oMoveAngleYaw = o->oSLSnowmanWindOriginalYaw + 0x1500; + } } else { - if (marioAngleFromWindSource > -0x1500) + if (marioAngleFromWindSource > -0x1500) { o->oMoveAngleYaw = o->oAngleToMario; - else + } else { o->oMoveAngleYaw = o->oSLSnowmanWindOriginalYaw - 0x1500; + } } // Spawn wind and play wind sound cur_obj_spawn_strong_wind_particles(12, 3.0f, 0, 0, 0); diff --git a/src/game/behaviors/sl_walking_penguin.inc.c b/src/game/behaviors/sl_walking_penguin.inc.c index f5b60a8a..11273ebc 100644 --- a/src/game/behaviors/sl_walking_penguin.inc.c +++ b/src/game/behaviors/sl_walking_penguin.inc.c @@ -1,4 +1,4 @@ -// sl_walking_penguin.c.inc +// sl_walking_penguin.inc.c struct SLWalkingPenguinStep { s32 stepLength; @@ -15,31 +15,32 @@ struct SLWalkingPenguinStep sSLWalkingPenguinErraticSteps[] = { { 30, PENGUIN_ANIM_IDLE, 0.0f, 1.0f }, // Stop for 1 second { 30, PENGUIN_ANIM_WALK, -6.0f, 1.0f }, // Walk backwards for 1 second { 30, PENGUIN_ANIM_IDLE, 0.0f, 1.0f }, // Stop for 1 second - { -1, 0, 0.0f, 0.0f } }; // Repeat - + { -1, 0, 0.0f, 0.0f }, // Repeat +}; static s32 sl_walking_penguin_turn(void) { // Stay still and use walking animation for the turn. o->oForwardVel = 0.0f; cur_obj_init_animation_with_accel_and_sound(PENGUIN_ANIM_WALK, 1.0f); - + // Turn around. o->oAngleVelYaw = 0x400; o->oMoveAngleYaw += o->oAngleVelYaw; - - if (o->oTimer == 31) + + if (o->oTimer == 31) { return TRUE; // Finished turning - else + } else { return FALSE; + } } void bhv_sl_walking_penguin_loop(void) { f32 adjustedXPos, adjustedZPos; f32 perpendicularOffset = 100.0f; - + o->oAngleVelYaw = 0; cur_obj_update_floor_and_walls(); - + switch (o->oAction) { // Walk erratically across the ice bridge using preset steps. case SL_WALKING_PENGUIN_ACT_MOVING_FORWARDS: @@ -48,68 +49,74 @@ void bhv_sl_walking_penguin_loop(void) { o->oSLWalkingPenguinCurStep = 0; o->oSLWalkingPenguinCurStepTimer = 0; } - - if (o->oSLWalkingPenguinCurStepTimer < sSLWalkingPenguinErraticSteps[o->oSLWalkingPenguinCurStep].stepLength) + + if (o->oSLWalkingPenguinCurStepTimer < + sSLWalkingPenguinErraticSteps[o->oSLWalkingPenguinCurStep].stepLength) { o->oSLWalkingPenguinCurStepTimer++; - else { + } else { // Move to next step o->oSLWalkingPenguinCurStepTimer = 0; o->oSLWalkingPenguinCurStep++; - if (sSLWalkingPenguinErraticSteps[o->oSLWalkingPenguinCurStep].stepLength < 0) + if (sSLWalkingPenguinErraticSteps[o->oSLWalkingPenguinCurStep].stepLength < 0) { // Reached the end of the list, go back to the start o->oSLWalkingPenguinCurStep = 0; + } } - - if (o->oPosX < 300.0f) + + if (o->oPosX < 300.0f) { o->oAction++; // If reached the end of the bridge, turn around and head back. - else { + } else { // Move and animate the penguin o->oForwardVel = sSLWalkingPenguinErraticSteps[o->oSLWalkingPenguinCurStep].speed; - + cur_obj_init_animation_with_accel_and_sound( sSLWalkingPenguinErraticSteps[o->oSLWalkingPenguinCurStep].anim, sSLWalkingPenguinErraticSteps[o->oSLWalkingPenguinCurStep].animSpeed ); } break; - + // At the end, turn around and prepare to head back across the bridge. case SL_WALKING_PENGUIN_ACT_TURNING_BACK: - if (sl_walking_penguin_turn()) + if (sl_walking_penguin_turn()) { o->oAction++; // Finished turning + } break; - + // Walk back across the bridge at a constant speed. case SL_WALKING_PENGUIN_ACT_RETURNING: // Move and animate the penguin o->oForwardVel = 12.0f; cur_obj_init_animation_with_accel_and_sound(PENGUIN_ANIM_WALK, 2.0f); - - if (o->oPosX > 1700.0f) + + if (o->oPosX > 1700.0f) { o->oAction++; // If reached the start of the bridge, turn around. + } break; - + // At the start, turn around and prepare to walk erratically across the bridge. case SL_WALKING_PENGUIN_ACT_TURNING_FORWARDS: - if (sl_walking_penguin_turn()) + if (sl_walking_penguin_turn()) { o->oAction = SL_WALKING_PENGUIN_ACT_MOVING_FORWARDS; // Finished turning + } break; } - + cur_obj_move_standard(-78); - if (!cur_obj_hide_if_mario_far_away_y(1000.0f)) + if (!cur_obj_hide_if_mario_far_away_y(1000.0f)) { play_penguin_walking_sound(PENGUIN_WALK_BIG); - + } + // Adjust the position to get a point better lined up with the visual model, for stopping the wind. // The new point is 60 units behind the penguin and 100 units perpedicularly, away from the snowman. - + adjustedXPos = o->oPosX + sins(0xDBB0) * 60.0f; // 0xDBB0 = -51 degrees, the angle the penguin is facing adjustedZPos = o->oPosZ + coss(0xDBB0) * 60.0f; adjustedXPos += perpendicularOffset * sins(0x1BB0); // 0x1BB0 = 39 degrees, perpendicular to the penguin adjustedZPos += perpendicularOffset * coss(0x1BB0); o->oSLWalkingPenguinWindCollisionXPos = adjustedXPos; o->oSLWalkingPenguinWindCollisionZPos = adjustedZPos; - + print_debug_bottom_up("x %d", o->oPosX); print_debug_bottom_up("z %d", o->oPosZ); } diff --git a/src/game/behaviors/sliding_platform.inc.c b/src/game/behaviors/sliding_platform.inc.c index 0e2087e1..1b8f73ce 100644 --- a/src/game/behaviors/sliding_platform.inc.c +++ b/src/game/behaviors/sliding_platform.inc.c @@ -1,4 +1,4 @@ -// sliding_platform.c.inc +// sliding_platform.inc.c void bhv_wf_sliding_platform_init(void) { o->oFaceAngleYaw -= 0x4000; @@ -25,7 +25,7 @@ void bhv_wf_sliding_platform_init(void) { void bhv_wf_sliding_platform_loop(void) { switch (o->oAction) { case WF_SLID_BRICK_PTFM_ACT_WAIT: - if (o->oTimer >= 101) { + if (o->oTimer > 100) { o->oAction = WF_SLID_BRICK_PTFM_ACT_EXTEND; o->oForwardVel = o->oWFSlidBrickPtfmMovVel; } @@ -33,7 +33,7 @@ void bhv_wf_sliding_platform_loop(void) { case WF_SLID_BRICK_PTFM_ACT_EXTEND: if (o->oTimer >= 500.0f / o->oWFSlidBrickPtfmMovVel) { - o->oForwardVel = 0; + o->oForwardVel = 0.0f; o->oPosX = o->oHomeX + 510.0f; } @@ -46,7 +46,7 @@ void bhv_wf_sliding_platform_loop(void) { case WF_SLID_BRICK_PTFM_ACT_RETRACT: if (o->oTimer >= 500.0f / o->oWFSlidBrickPtfmMovVel) { - o->oForwardVel = 0; + o->oForwardVel = 0.0f; o->oPosX = o->oHomeX; } diff --git a/src/game/behaviors/sliding_platform_2.inc.c b/src/game/behaviors/sliding_platform_2.inc.c index 55946e7d..853bc409 100644 --- a/src/game/behaviors/sliding_platform_2.inc.c +++ b/src/game/behaviors/sliding_platform_2.inc.c @@ -1,6 +1,6 @@ // sliding_platform_2.inc.c -static void const *sSlidingPlatform2CollisionData[] = { +static Collision const *sSlidingPlatform2CollisionData[] = { bits_seg7_collision_0701A9A0, bits_seg7_collision_0701AA0C, bitfs_seg7_collision_07015714, @@ -12,9 +12,8 @@ static void const *sSlidingPlatform2CollisionData[] = { }; void bhv_sliding_plat_2_init(void) { - s32 collisionDataIndex; + s32 collisionDataIndex = ((u16)(o->oBehParams >> 16) & 0x0380) >> 7; - collisionDataIndex = ((u16)(o->oBehParams >> 16) & 0x0380) >> 7; o->collisionData = segmented_to_virtual(sSlidingPlatform2CollisionData[collisionDataIndex]); o->oBackAndForthPlatformPathLength = 50.0f * ((u16)(o->oBehParams >> 16) & 0x003F); diff --git a/src/game/behaviors/snow_mound.inc.c b/src/game/behaviors/snow_mound.inc.c index f8fcc539..3710f86e 100644 --- a/src/game/behaviors/snow_mound.inc.c +++ b/src/game/behaviors/snow_mound.inc.c @@ -1,13 +1,13 @@ -// snow_mound.c.inc +// snow_mound.inc.c void bhv_sliding_snow_mound_loop(void) { switch (o->oAction) { case 0: o->oVelX = -40.0f; o->oPosX += o->oVelX; - if (o->oTimer >= 118) + if (o->oTimer > 117) { o->oAction = 1; - + } cur_obj_play_sound_1(SOUND_ENV_SINK_QUICKSAND); break; @@ -17,8 +17,9 @@ void bhv_sliding_snow_mound_loop(void) { o->oVelY = -10.0f; o->oPosY += o->oVelY; o->oPosZ = o->oHomeZ - 2.0f; - if (o->oTimer > 50) + if (o->oTimer > 50) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } break; } } @@ -27,17 +28,20 @@ void bhv_snow_mound_spawn_loop(void) { struct Object *sp1C; if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 6000) - || o->oPosY + 1000.0f < gMarioObject->header.gfx.pos[1]) + || o->oPosY + 1000.0f < gMarioObject->header.gfx.pos[1]) { return; + } - if (o->oTimer == 64 || o->oTimer == 128 || o->oTimer == 192 || o->oTimer == 224 || o->oTimer == 256) + if (o->oTimer == 64 || o->oTimer == 128 || o->oTimer == 192 || o->oTimer == 224 || o->oTimer == 256) { sp1C = spawn_object(o, MODEL_SL_SNOW_TRIANGLE, bhvSlidingSnowMound); + } if (o->oTimer == 256) { sp1C->header.gfx.scale[0] = 2.0f; sp1C->header.gfx.scale[1] = 2.0f; } - if (o->oTimer >= 256) + if (o->oTimer >= 256) { o->oTimer = 0; + } } diff --git a/src/game/behaviors/snowman.inc.c b/src/game/behaviors/snowman.inc.c index 97374f93..93ed9dfd 100644 --- a/src/game/behaviors/snowman.inc.c +++ b/src/game/behaviors/snowman.inc.c @@ -1,4 +1,4 @@ -// snowman.c.inc +// snowman.inc.c static struct ObjectHitbox sRollingSphereHitbox = { /* interactType: */ INTERACT_DAMAGE, @@ -13,7 +13,7 @@ static struct ObjectHitbox sRollingSphereHitbox = { }; void bhv_snowmans_bottom_init(void) { - struct Object *sp34; + struct Object *snowmansHead; o->oHomeX = o->oPosX; o->oHomeY = o->oPosY; @@ -25,11 +25,11 @@ void bhv_snowmans_bottom_init(void) { o->oVelY = 0; o->oForwardVel = 0; - o->oSnowmansBottomUnkF4 = 0.4f; + o->oSnowmansBottomScale = 0.4f; - sp34 = cur_obj_nearest_object_with_behavior(bhvSnowmansHead); - if (sp34 != NULL) { - o->parentObj = sp34; + snowmansHead = cur_obj_nearest_object_with_behavior(bhvSnowmansHead); + if (snowmansHead != NULL) { + o->parentObj = snowmansHead; } spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvSnowmansBodyCheckpoint, -402, 461, -2898, 0, 0, 0); } @@ -37,35 +37,39 @@ void bhv_snowmans_bottom_init(void) { void set_rolling_sphere_hitbox(void) { obj_set_hitbox(o, &sRollingSphereHitbox); - if ((o->oInteractStatus & INT_STATUS_INTERACTED) != 0) { + if (o->oInteractStatus & INT_STATUS_INTERACTED) { o->oInteractStatus = 0; } } void adjust_rolling_face_pitch(f32 f12) { o->oFaceAnglePitch += (s16)(o->oForwardVel * (100.0f / f12)); - o->oSnowmansBottomUnkF4 += o->oForwardVel * 1e-4; + o->oSnowmansBottomScale += o->oForwardVel * 0.0001; - if (o->oSnowmansBottomUnkF4 > 1.0) - o->oSnowmansBottomUnkF4 = 1.0f; + if (o->oSnowmansBottomScale > 1.0) { + o->oSnowmansBottomScale = 1.0f; + } } void snowmans_bottom_act_1(void) { - UNUSED s16 sp26; - s32 sp20; - UNUSED s16 sp1E; + UNUSED s16 collisionFlags; + s32 followStatus; +#ifdef AVOID_UB + followStatus = 0; +#endif o->oPathedStartWaypoint = segmented_to_virtual(&ccm_seg7_trajectory_snowman); - sp26 = object_step_without_floor_orient(); - sp20 = cur_obj_follow_path(sp20); + collisionFlags = object_step_without_floor_orient(); + followStatus = cur_obj_follow_path(followStatus); o->oSnowmansBottomUnkF8 = o->oPathedTargetYaw; o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oSnowmansBottomUnkF8, 0x400); - if (o->oForwardVel > 70.0) + if (o->oForwardVel > 70.0) { o->oForwardVel = 70.0f; + } - if (sp20 == -1) { - sp1E = (u16) o->oAngleToMario - (u16) o->oMoveAngleYaw; + if (followStatus == PATH_REACHED_END) { + UNUSED s16 sp1E = (u16) o->oAngleToMario - (u16) o->oMoveAngleYaw; if (obj_check_if_facing_toward_angle(o->oMoveAngleYaw, o->oAngleToMario, 0x2000) == TRUE && o->oSnowmansBottomUnk1AC == 1) { o->oSnowmansBottomUnkF8 = o->oAngleToMario; @@ -77,11 +81,11 @@ void snowmans_bottom_act_1(void) { } void snowmans_bottom_act_2(void) { - UNUSED s16 sp26; + UNUSED s16 collisionFlags = object_step_without_floor_orient(); - sp26 = object_step_without_floor_orient(); - if (o->oForwardVel > 70.0) + if (o->oForwardVel > 70.0) { o->oForwardVel = 70.0f; + } o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oSnowmansBottomUnkF8, 0x400); if (is_point_close_to_object(o, -4230.0f, -1344.0f, 1813.0f, 300)) { @@ -103,15 +107,14 @@ void snowmans_bottom_act_2(void) { } void snowmans_bottom_act_3(void) { - UNUSED s16 sp1E; + s16 collisionFlags = object_step_without_floor_orient(); - sp1E = object_step_without_floor_orient(); - if ((sp1E & 0x09) == 0x09) { + if ((collisionFlags & OBJ_COL_FLAGS_LANDED) == OBJ_COL_FLAGS_LANDED) { o->oAction = 4; cur_obj_become_intangible(); } - if ((sp1E & 0x01) != 0) { + if (collisionFlags & OBJ_COL_FLAG_GROUNDED) { spawn_mist_particles_variable(0, 0, 70.0f); o->oPosX = -4230.0f; o->oPosZ = 1813.0f; @@ -120,30 +123,28 @@ void snowmans_bottom_act_3(void) { } void bhv_snowmans_bottom_loop(void) { - s16 sp1E; - switch (o->oAction) { case 0: if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 400) == 1 - && set_mario_npc_dialog(1) == 2) { - sp1E = cutscene_object_with_dialog(CUTSCENE_DIALOG, o, DIALOG_110); - if (sp1E) { + && set_mario_npc_dialog(MARIO_DIALOG_LOOK_FRONT) == MARIO_DIALOG_STATUS_SPEAK) { + s16 response = cutscene_object_with_dialog(CUTSCENE_DIALOG, o, DIALOG_110); + if (response != DIALOG_RESPONSE_NONE) { o->oForwardVel = 10.0f; o->oAction = 1; - set_mario_npc_dialog(0); + set_mario_npc_dialog(MARIO_DIALOG_STOP); } } break; case 1: snowmans_bottom_act_1(); - adjust_rolling_face_pitch(o->oSnowmansBottomUnkF4); + adjust_rolling_face_pitch(o->oSnowmansBottomScale); cur_obj_play_sound_1(SOUND_ENV_UNKNOWN2); break; case 2: snowmans_bottom_act_2(); - adjust_rolling_face_pitch(o->oSnowmansBottomUnkF4); + adjust_rolling_face_pitch(o->oSnowmansBottomScale); cur_obj_play_sound_1(SOUND_ENV_UNKNOWN2); break; @@ -158,16 +159,13 @@ void bhv_snowmans_bottom_loop(void) { set_rolling_sphere_hitbox(); set_object_visibility(o, 8000); - cur_obj_scale(o->oSnowmansBottomUnkF4); - o->oGraphYOffset = o->oSnowmansBottomUnkF4 * 180.0f; + cur_obj_scale(o->oSnowmansBottomScale); + o->oGraphYOffset = o->oSnowmansBottomScale * 180.0f; } void bhv_snowmans_head_init(void) { - u8 sp37; - s8 sp36; - - sp37 = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1); - sp36 = (o->oBehParams >> 24) & 0xFF; + u8 starFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); + s8 sp36 = (o->oBehParams >> 24) & 0xFF; cur_obj_scale(0.7f); @@ -175,7 +173,7 @@ void bhv_snowmans_head_init(void) { o->oFriction = 0.999f; o->oBuoyancy = 2.0f; - if ((sp37 & (1 << sp36)) && gCurrActNum != sp36 + 1) { + if ((starFlags & (1 << sp36)) && gCurrActNum != sp36 + 1) { spawn_object_abs_with_rot(o, 0, MODEL_CCM_SNOWMAN_BASE, bhvBigSnowmanWhole, -4230, -1344, 1813, 0, 0, 0); o->oPosX = -4230.0f; @@ -186,22 +184,24 @@ void bhv_snowmans_head_init(void) { } void bhv_snowmans_head_loop(void) { - UNUSED s16 sp1E; - s16 sp1C; + UNUSED s16 unused; + s16 collisionFlags; switch (o->oAction) { case 0: - if (trigger_obj_dialog_when_facing(&o->oSnowmansHeadUnkF4, DIALOG_109, 400.0f, 1)) + if (trigger_obj_dialog_when_facing(&o->oSnowmansHeadDialogActive, DIALOG_109, 400.0f, MARIO_DIALOG_LOOK_FRONT)) { o->oAction = 1; + } break; case 1: break; case 2: - sp1C = object_step_without_floor_orient(); - if (sp1C & 0x08) + collisionFlags = object_step_without_floor_orient(); + if (collisionFlags & OBJ_COL_FLAG_NO_Y_VEL) { o->oAction = 3; + } break; case 3: @@ -215,7 +215,7 @@ void bhv_snowmans_head_loop(void) { break; case 4: - if (trigger_obj_dialog_when_facing(&o->oSnowmansHeadUnkF4, DIALOG_111, 700.0f, 2)) { + if (trigger_obj_dialog_when_facing(&o->oSnowmansHeadDialogActive, DIALOG_111, 700.0f, MARIO_DIALOG_LOOK_UP)) { spawn_mist_particles(); spawn_default_star(-4700.0f, -1024.0f, 1890.0f); o->oAction = 1; @@ -232,6 +232,7 @@ void bhv_snowmans_body_checkpoint_loop(void) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } - if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) + if (o->parentObj->activeFlags == ACTIVE_FLAG_DEACTIVATED) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } } diff --git a/src/game/behaviors/snufit.inc.c b/src/game/behaviors/snufit.inc.c index f3a0c9ef..d3a9fc59 100644 --- a/src/game/behaviors/snufit.inc.c +++ b/src/game/behaviors/snufit.inc.c @@ -1,3 +1,4 @@ + /** * Behavior file for bhvSnufit and bhvSnufitBalls. * Snufits are present in HMC and CotMC, and are the fly guy @@ -34,12 +35,10 @@ struct ObjectHitbox sSnufitBulletHitbox = { * since the parts move independently. */ Gfx *geo_snufit_move_mask(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) { - struct Object *obj; - struct GraphNodeTranslationRotation *transNode; - if (callContext == GEO_CONTEXT_RENDER) { - obj = (struct Object *) gCurGraphNodeObject; - transNode = (struct GraphNodeTranslationRotation *) node->next; + struct Object *obj = (struct Object *) gCurGraphNodeObject; + struct GraphNodeTranslationRotation *transNode + = (struct GraphNodeTranslationRotation *) node->next; transNode->translation[0] = obj->oSnufitXOffset; transNode->translation[1] = obj->oSnufitYOffset; @@ -53,12 +52,9 @@ Gfx *geo_snufit_move_mask(s32 callContext, struct GraphNode *node, UNUSED Mat4 * * This function scales the body of snufit, which needs done seperately from its mask. */ Gfx *geo_snufit_scale_body(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) { - struct Object *obj; - struct GraphNodeScale *scaleNode; - if (callContext == GEO_CONTEXT_RENDER) { - obj = (struct Object *) gCurGraphNodeObject; - scaleNode = (struct GraphNodeScale *) node->next; + struct Object *obj = (struct Object *) gCurGraphNodeObject; + struct GraphNodeScale *scaleNode = (struct GraphNodeScale *) node->next; scaleNode->scale = obj->oSnufitBodyScale / 1000.0f; } @@ -71,13 +67,12 @@ Gfx *geo_snufit_scale_body(s32 callContext, struct GraphNode *node, UNUSED Mat4 * then prepares to shoot after a period. */ void snufit_act_idle(void) { - s32 marioDist; - // This line would could cause a crash in certain PU situations, // if the game would not have already crashed. - marioDist = (s32)(o->oDistanceToMario / 10.0f); + s32 marioDist = (s32)(o->oDistanceToMario / 10.0f); + if (o->oTimer > marioDist && o->oDistanceToMario < 800.0f) { - + // Controls an alternating scaling factor in a cos. o->oSnufitBodyScalePeriod = approach_s16_symmetric(o->oSnufitBodyScalePeriod, 0, 1500); @@ -105,7 +100,7 @@ void snufit_act_shoot(void) { if ((u16) o->oSnufitBodyScalePeriod == 0x8000 && o->oSnufitBodyBaseScale == 167) { o->oAction = SNUFIT_ACT_IDLE; } else if (o->oSnufitBullets < 3 && o->oTimer >= 3) { - o->oSnufitBullets += 1; + o->oSnufitBullets++; cur_obj_play_sound_2(SOUND_OBJ_SNUFIT_SHOOT); spawn_object_relative(0, 0, -20, 40, o, MODEL_BOWLING_BALL, bhvSnufitBalls); o->oSnufitRecoil = -30; @@ -121,7 +116,7 @@ void bhv_snufit_loop(void) { // Only update if Mario is in the current room. if (!(o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) { o->oDeathSound = SOUND_OBJ_SNUFIT_SKEETER_DEATH; - + // Face Mario if he is within range. if (o->oDistanceToMario < 800.0f) { obj_turn_pitch_toward_mario(120.0f, 2000); @@ -189,7 +184,7 @@ void bhv_snufit_balls_loop(void) { cur_obj_update_floor_and_walls(); obj_compute_vel_from_move_pitch(40.0f); - if (obj_check_attacks(&sSnufitBulletHitbox, 1)) { + if (obj_check_attacks(&sSnufitBulletHitbox, 1) != 0) { // We hit Mario while he is metal! // Bounce off, and fall until the first check is true. o->oMoveAngleYaw += 0x8000; @@ -199,7 +194,7 @@ void bhv_snufit_balls_loop(void) { cur_obj_become_intangible(); } else if (o->oAction == 1 - || (o->oMoveFlags & (OBJ_MOVE_MASK_ON_GROUND | OBJ_MOVE_HIT_WALL))) { + || (o->oMoveFlags & (OBJ_MOVE_MASK_ON_GROUND | OBJ_MOVE_HIT_WALL))) { // The Snufit shot Mario and has fulfilled its lonely existance. //! The above check could theoretically be avoided by finding a geometric //! situation that does not trigger those flags (Water?). If found, diff --git a/src/game/behaviors/sound_ambient.inc.c b/src/game/behaviors/sound_ambient.inc.c index bf5765da..73a1de7a 100644 --- a/src/game/behaviors/sound_ambient.inc.c +++ b/src/game/behaviors/sound_ambient.inc.c @@ -1,8 +1,9 @@ // sound_ambient.inc.c void bhv_ambient_sounds_init(void) { - if (gCamera->mode == CAMERA_MODE_BEHIND_MARIO) + if (gCamera->mode == CAMERA_MODE_BEHIND_MARIO) { return; + } play_sound(SOUND_AIR_CASTLE_OUTDOORS_AMBIENT, gGlobalSoundSource); } diff --git a/src/game/behaviors/sound_birds.inc.c b/src/game/behaviors/sound_birds.inc.c index db7ea534..214c0c40 100644 --- a/src/game/behaviors/sound_birds.inc.c +++ b/src/game/behaviors/sound_birds.inc.c @@ -1,8 +1,9 @@ // sound_birds.inc.c void bhv_birds_sound_loop(void) { - if (gCamera->mode == CAMERA_MODE_BEHIND_MARIO) + if (gCamera->mode == CAMERA_MODE_BEHIND_MARIO) { return; + } switch (o->oBehParams2ndByte) { case 0: diff --git a/src/game/behaviors/sound_sand.inc.c b/src/game/behaviors/sound_sand.inc.c index 95535b68..9a5c3bb3 100644 --- a/src/game/behaviors/sound_sand.inc.c +++ b/src/game/behaviors/sound_sand.inc.c @@ -1,8 +1,9 @@ // sound_sand.inc.c void bhv_sand_sound_loop(void) { - if (gCamera->mode == CAMERA_MODE_BEHIND_MARIO) + if (gCamera->mode == CAMERA_MODE_BEHIND_MARIO) { return; + } cur_obj_play_sound_1(SOUND_ENV_MOVINGSAND); } diff --git a/src/game/behaviors/sound_spawner.inc.c b/src/game/behaviors/sound_spawner.inc.c index 7f0b27ed..6f40d2be 100644 --- a/src/game/behaviors/sound_spawner.inc.c +++ b/src/game/behaviors/sound_spawner.inc.c @@ -1,4 +1,4 @@ -// sound_spawner.c.inc +// sound_spawner.inc.c void bhv_sound_spawner_init(void) { s32 sp1C = o->oSoundEffectUnkF4; diff --git a/src/game/behaviors/sparkle_spawn.inc.c b/src/game/behaviors/sparkle_spawn.inc.c index b5f2a418..90b1ac2e 100644 --- a/src/game/behaviors/sparkle_spawn.inc.c +++ b/src/game/behaviors/sparkle_spawn.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvSparkleSpawn. * @@ -5,6 +6,7 @@ * random local position and scale, each sparkle's behavior is thereafter * controlled by bhvSparkle. This spawner is deleted after 1 frame. */ + void bhv_sparkle_spawn_loop(void) { struct Object *sparkle = try_to_spawn_object(0, 1.0f, o, MODEL_SPARKLES_ANIMATION, bhvSparkle); if (sparkle != NULL) { diff --git a/src/game/behaviors/sparkle_spawn_star.inc.c b/src/game/behaviors/sparkle_spawn_star.inc.c index b6608708..f9d7510b 100644 --- a/src/game/behaviors/sparkle_spawn_star.inc.c +++ b/src/game/behaviors/sparkle_spawn_star.inc.c @@ -1,24 +1,29 @@ -// sparkle_spawn_star.c.inc +// sparkle_spawn_star.inc.c struct ObjectHitbox sSparkleSpawnStarHitbox = { - /* interactType: */ INTERACT_STAR_OR_KEY, - /* downOffset: */ 0, + /* interactType: */ INTERACT_STAR_OR_KEY, + /* downOffset: */ 0, /* damageOrCoinValue: */ 0, - /* health: */ 0, - /* numLootCoins: */ 0, - /* radius: */ 80, - /* height: */ 50, - /* hurtboxRadius: */ 0, - /* hurtboxHeight: */ 0, + /* health: */ 0, + /* numLootCoins: */ 0, + /* radius: */ 80, + /* height: */ 50, + /* hurtboxRadius: */ 0, + /* hurtboxHeight: */ 0, }; void bhv_spawned_star_init(void) { s32 sp24; - if (!(o->oInteractionSubtype & INT_SUBTYPE_NO_EXIT)) + + if (!(o->oInteractionSubtype & INT_SUBTYPE_NO_EXIT)) { o->oBehParams = o->parentObj->oBehParams; + } sp24 = (o->oBehParams >> 24) & 0xFF; - if (bit_shift_left(sp24) & save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1)) + + if (bit_shift_left(sp24) & save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum))) { cur_obj_set_model(MODEL_TRANSPARENT_STAR); + } + cur_obj_play_sound_2(SOUND_GENERAL2_STAR_APPEARS); } @@ -33,24 +38,28 @@ void set_sparkle_spawn_star_hitbox(void) { void set_home_to_mario(void) { f32 sp1C; f32 sp18; + o->oHomeX = gMarioObject->oPosX; o->oHomeZ = gMarioObject->oPosZ; o->oHomeY = gMarioObject->oPosY; o->oHomeY += 250.0f; o->oPosY = o->oHomeY; + sp1C = o->oHomeX - o->oPosX; sp18 = o->oHomeZ - o->oPosZ; + o->oForwardVel = sqrtf(sp1C * sp1C + sp18 * sp18) / 23.0f; } void set_y_home_to_pos(void) { - o->oForwardVel = 0; + o->oForwardVel = 0.0f; o->oHomeY = o->oPosY; } void slow_star_rotation(void) { - if (o->oAngleVelYaw > 0x400) + if (o->oAngleVelYaw > 0x400) { o->oAngleVelYaw -= 0x40; + } } void bhv_spawned_star_loop(void) { @@ -60,10 +69,11 @@ void bhv_spawned_star_loop(void) { set_time_stop_flags(TIME_STOP_ENABLED | TIME_STOP_MARIO_AND_DOORS); o->activeFlags |= ACTIVE_FLAG_INITIATED_TIME_STOP; o->oAngleVelYaw = 0x800; - if (o->oBehParams2ndByte == 0) + if (o->oBehParams2ndByte == 0) { set_home_to_mario(); - else + } else { set_y_home_to_pos(); + } o->oMoveAngleYaw = cur_obj_angle_to_home(); o->oVelY = 50.0f; o->oGravity = -4.0f; @@ -76,18 +86,20 @@ void bhv_spawned_star_loop(void) { o->oForwardVel = 0; o->oVelY = 20.0f; o->oGravity = -1.0f; - if (o->oInteractionSubtype & INT_SUBTYPE_NO_EXIT) + if (o->oInteractionSubtype & INT_SUBTYPE_NO_EXIT) { #ifdef VERSION_JP play_power_star_jingle(FALSE); #else play_power_star_jingle(TRUE); #endif - else + } else { play_power_star_jingle(TRUE); + } } } else if (o->oAction == 1) { - if (o->oVelY < -4.0f) + if (o->oVelY < -4.0f) { o->oVelY = -4.0f; + } if (o->oVelY < 0 && o->oPosY < o->oHomeY) { gObjCutsceneDone = TRUE; o->oVelY = 0; @@ -105,6 +117,7 @@ void bhv_spawned_star_loop(void) { set_sparkle_spawn_star_hitbox(); slow_star_rotation(); } + cur_obj_move_using_fvel_and_gravity(); o->oFaceAngleYaw += o->oAngleVelYaw; o->oInteractStatus = 0; diff --git a/src/game/behaviors/spawn_star.inc.c b/src/game/behaviors/spawn_star.inc.c index 9a194a5c..96f71a63 100644 --- a/src/game/behaviors/spawn_star.inc.c +++ b/src/game/behaviors/spawn_star.inc.c @@ -1,4 +1,4 @@ -// spawn_default_star.c.inc +// spawn_star.inc.c static struct ObjectHitbox sCollectStarHitbox = { /* interactType: */ INTERACT_STAR_OR_KEY, @@ -13,11 +13,9 @@ static struct ObjectHitbox sCollectStarHitbox = { }; void bhv_collect_star_init(void) { - s8 starId; - u8 currentLevelStarFlags; + s8 starId = (o->oBehParams >> 24) & 0xFF; + u8 currentLevelStarFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); - starId = (o->oBehParams >> 24) & 0xFF; - currentLevelStarFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1); if (currentLevelStarFlags & (1 << starId)) { o->header.gfx.sharedChild = gLoadedGraphNodes[MODEL_TRANSPARENT_STAR]; } else { @@ -42,10 +40,12 @@ void bhv_star_spawn_init(void) { o->oVelY = (o->oHomeY - o->oPosY) / 30.0f; o->oForwardVel = o->oStarSpawnDisFromHome / 30.0f; o->oStarSpawnUnkFC = o->oPosY; - if (o->oBehParams2ndByte == 0 || gCurrCourseNum == COURSE_BBH) + + if (o->oBehParams2ndByte == 0 || gCurrCourseNum == COURSE_BBH) { cutscene_object(CUTSCENE_STAR_SPAWN, o); - else + } else { cutscene_object(CUTSCENE_RED_COIN_STAR_SPAWN, o); + } set_time_stop_flags(TIME_STOP_ENABLED | TIME_STOP_MARIO_AND_DOORS); o->activeFlags |= ACTIVE_FLAG_INITIATED_TIME_STOP; @@ -56,8 +56,9 @@ void bhv_star_spawn_loop(void) { switch (o->oAction) { case 0: o->oFaceAngleYaw += 0x1000; - if (o->oTimer > 20) + if (o->oTimer > 20) { o->oAction = 1; + } break; case 1: @@ -75,10 +76,11 @@ void bhv_star_spawn_loop(void) { break; case 2: - if (o->oTimer < 20) + if (o->oTimer < 20) { o->oVelY = 20 - o->oTimer; - else + } else { o->oVelY = -10.0f; + } spawn_object(o, MODEL_NONE, bhvSparkleSpawn); obj_move_xyz_using_fvel_and_yaw(o); @@ -122,48 +124,47 @@ struct Object *spawn_star(struct Object *sp30, f32 sp34, f32 sp38, f32 sp3C) { } void spawn_default_star(f32 sp20, f32 sp24, f32 sp28) { - struct Object *sp1C; - sp1C = spawn_star(sp1C, sp20, sp24, sp28); + struct Object *sp1C = spawn_star(sp1C, sp20, sp24, sp28); sp1C->oBehParams2ndByte = 0; } void spawn_red_coin_cutscene_star(f32 sp20, f32 sp24, f32 sp28) { - struct Object *sp1C; - sp1C = spawn_star(sp1C, sp20, sp24, sp28); + struct Object *sp1C = spawn_star(sp1C, sp20, sp24, sp28); sp1C->oBehParams2ndByte = 1; } void spawn_no_exit_star(f32 sp20, f32 sp24, f32 sp28) { - struct Object *sp1C; - sp1C = spawn_star(sp1C, sp20, sp24, sp28); + struct Object *sp1C = spawn_star(sp1C, sp20, sp24, sp28); sp1C->oBehParams2ndByte = 1; sp1C->oInteractionSubtype |= INT_SUBTYPE_NO_EXIT; } void bhv_hidden_red_coin_star_init(void) { - s16 sp36; - struct Object *sp30; + s16 count; - if (gCurrCourseNum != COURSE_JRB) + if (gCurrCourseNum != COURSE_JRB) { spawn_object(o, MODEL_TRANSPARENT_STAR, bhvRedCoinStarMarker); + } - sp36 = count_objects_with_behavior(bhvRedCoin); - if (sp36 == 0) { - sp30 = - spawn_object_abs_with_rot(o, 0, MODEL_STAR, bhvStar, o->oPosX, o->oPosY, o->oPosZ, 0, 0, 0); - sp30->oBehParams = o->oBehParams; + count = count_objects_with_behavior(bhvRedCoin); + if (count == 0) { + struct Object *star = spawn_object_abs_with_rot(o, 0, MODEL_STAR, bhvStar, + o->oPosX, o->oPosY, o->oPosZ, 0, 0, 0); + star->oBehParams = o->oBehParams; o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } - o->oHiddenStarTriggerCounter = 8 - sp36; + o->oHiddenStarTriggerCounter = 8 - count; } void bhv_hidden_red_coin_star_loop(void) { gRedCoinsCollected = o->oHiddenStarTriggerCounter; + switch (o->oAction) { case 0: - if (o->oHiddenStarTriggerCounter == 8) + if (o->oHiddenStarTriggerCounter == 8) { o->oAction = 1; + } break; case 1: diff --git a/src/game/behaviors/spawn_star_exit.inc.c b/src/game/behaviors/spawn_star_exit.inc.c index 8c5515a3..aab63b2a 100644 --- a/src/game/behaviors/spawn_star_exit.inc.c +++ b/src/game/behaviors/spawn_star_exit.inc.c @@ -1,4 +1,4 @@ -// spawn_star_exit.c.inc +// spawn_star_exit.inc.c void bhv_ccm_touched_star_spawn_loop(void) { if (gCCMEnteredSlide & 1) { diff --git a/src/game/behaviors/spindel.inc.c b/src/game/behaviors/spindel.inc.c index 6cbe3ced..b3c4ebf7 100644 --- a/src/game/behaviors/spindel.inc.c +++ b/src/game/behaviors/spindel.inc.c @@ -1,4 +1,4 @@ -// spindel.c.inc +// spindel.inc.c void bhv_spindel_init(void) { o->oHomeY = o->oPosY; @@ -23,12 +23,14 @@ void bhv_spindel_loop(void) { sp18 = 10 - o->oSpindelUnkF4; - if (sp18 < 0) + if (sp18 < 0) { sp18 *= -1; + } sp18 -= 6; - if (sp18 < 0) + if (sp18 < 0) { sp18 = 0; + } if (o->oTimer == sp18 + 8) { o->oTimer = 0; @@ -44,12 +46,13 @@ void bhv_spindel_loop(void) { } } - if (sp18 == 4 || sp18 == 3) + if (sp18 == 4 || sp18 == 3) { sp18 = 4; - else if (sp18 == 2 || sp18 == 1) + } else if (sp18 == 2 || sp18 == 1) { sp18 = 2; - else if (sp18 == 0) + } else if (sp18 == 0) { sp18 = 1; + } if (o->oTimer < sp18 * 8) { if (o->oSpindelUnkF8 == 0) { @@ -68,12 +71,14 @@ void bhv_spindel_loop(void) { } sp1C = sins(o->oMoveAnglePitch * 4) * 23.0; - if (sp1C < 0.0f) + if (sp1C < 0.0f) { sp1C *= -1.0f; + } o->oPosY = o->oHomeY + sp1C; - if (o->oTimer + 1 == sp18 * 8) + if (o->oTimer + 1 == sp18 * 8) { set_camera_shake_from_point(SHAKE_POS_SMALL, o->oPosX, o->oPosY, o->oPosZ); + } } } diff --git a/src/game/behaviors/spindrift.inc.c b/src/game/behaviors/spindrift.inc.c index bc04018e..8651ad1c 100644 --- a/src/game/behaviors/spindrift.inc.c +++ b/src/game/behaviors/spindrift.inc.c @@ -1,40 +1,46 @@ -// spindrift.c.inc +// spindrift.inc.c struct ObjectHitbox sSpindriftHitbox = { - /* interactType: */ INTERACT_BOUNCE_TOP, - /* downOffset: */ 0, + /* interactType: */ INTERACT_BOUNCE_TOP, + /* downOffset: */ 0, /* damageOrCoinValue: */ 2, - /* health: */ 1, - /* numLootCoins: */ 3, - /* radius: */ 90, - /* height: */ 80, - /* hurtboxRadius: */ 80, - /* hurtboxHeight: */ 70, + /* health: */ 1, + /* numLootCoins: */ 3, + /* radius: */ 90, + /* height: */ 80, + /* hurtboxRadius: */ 80, + /* hurtboxHeight: */ 70, }; void bhv_spindrift_loop(void) { o->activeFlags |= ACTIVE_FLAG_UNK10; - if (cur_obj_set_hitbox_and_die_if_attacked(&sSpindriftHitbox, SOUND_OBJ_DYING_ENEMY1, 0)) + + if (cur_obj_set_hitbox_and_die_if_attacked(&sSpindriftHitbox, SOUND_OBJ_DYING_ENEMY1, 0)) { cur_obj_change_action(1); + } cur_obj_update_floor_and_walls(); + switch (o->oAction) { case 0: approach_forward_vel(&o->oForwardVel, 4.0f, 1.0f); - if (cur_obj_lateral_dist_from_mario_to_home() > 1000.0f) + if (cur_obj_lateral_dist_from_mario_to_home() > 1000.0f) { o->oAngleToMario = cur_obj_angle_to_home(); - else if (o->oDistanceToMario > 300.0f) + } else if (o->oDistanceToMario > 300.0f) { o->oAngleToMario = obj_angle_to_object(o, gMarioObject); + } cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x400); break; + case 1: - o->oFlags &= ~8; + o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; o->oForwardVel = -10.0f; if (o->oTimer > 20) { o->oAction = 0; o->oInteractStatus = 0; - o->oFlags |= 8; + o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; } break; } + cur_obj_move_standard(-60); } diff --git a/src/game/behaviors/spiny.inc.c b/src/game/behaviors/spiny.inc.c index 3d894bfc..b62eda74 100644 --- a/src/game/behaviors/spiny.inc.c +++ b/src/game/behaviors/spiny.inc.c @@ -46,7 +46,7 @@ static s32 spiny_check_active(void) { // behave similar to a regular goomba. // It can also be used on a bob-omb respawner to change its model // to a butterfly or fish. - o->parentObj->oEnemyLakituNumSpinies -= 1; + o->parentObj->oEnemyLakituNumSpinies--; obj_mark_for_deletion(o); return FALSE; } @@ -85,7 +85,7 @@ static void spiny_act_walk(void) { obj_bounce_off_walls_edges_objects(&o->oSpinyTargetYaw))) { // Walk and occasionally randomly change direction if (o->oSpinyTimeUntilTurn != 0) { - o->oSpinyTimeUntilTurn -= 1; + o->oSpinyTimeUntilTurn--; } else { o->oSpinyTargetYaw = o->oMoveAngleYaw + (s16) random_sign() * 0x2000; o->oSpinyTimeUntilTurn = random_linear_offset(100, 100); @@ -169,10 +169,8 @@ static void spiny_act_thrown_by_lakitu(void) { cur_obj_move_standard(-78); - if (obj_check_attacks(&sSpinyHitbox, o->oAction)) { - if (o->parentObj != o) { - o->parentObj->oEnemyLakituNumSpinies -= 1; - } + if (obj_check_attacks(&sSpinyHitbox, o->oAction) != 0 && o->parentObj != o) { + o->parentObj->oEnemyLakituNumSpinies--; } } } diff --git a/src/game/behaviors/square_platform_cycle.inc.c b/src/game/behaviors/square_platform_cycle.inc.c index 24eacb02..a3525a82 100644 --- a/src/game/behaviors/square_platform_cycle.inc.c +++ b/src/game/behaviors/square_platform_cycle.inc.c @@ -1,38 +1,45 @@ -// square_platform_cycle.c.inc +// square_platform_cycle.inc.c s32 square_plat_set_yaw_until_timer(u16 yaw, s32 a) { o->oMoveAngleYaw = yaw; - if (a < o->oTimer) - return 1; - else - return 0; + if (a < o->oTimer) { + return TRUE; + } else { + return FALSE; + } } void bhv_squarish_path_moving_loop(void) { o->oForwardVel = 10.0f; + switch (o->oAction) { case 0: o->oAction = (o->oBehParams2ndByte & 3) + 1; break; case 1: - if (square_plat_set_yaw_until_timer(0, 60)) + if (square_plat_set_yaw_until_timer(0, 60)) { o->oAction++; + } break; case 2: - if (square_plat_set_yaw_until_timer(0x4000, 60)) + if (square_plat_set_yaw_until_timer(0x4000, 60)) { o->oAction++; + } break; case 3: - if (square_plat_set_yaw_until_timer(0x8000, 60)) + if (square_plat_set_yaw_until_timer(0x8000, 60)) { o->oAction++; + } break; case 4: - if (square_plat_set_yaw_until_timer(0xc000, 60)) + if (square_plat_set_yaw_until_timer(0xc000, 60)) { o->oAction = 1; + } break; default: break; } + cur_obj_move_using_fvel_and_gravity(); load_object_collision_model(); } diff --git a/src/game/behaviors/star_door.inc.c b/src/game/behaviors/star_door.inc.c index 2d7dad1f..23faf8b4 100644 --- a/src/game/behaviors/star_door.inc.c +++ b/src/game/behaviors/star_door.inc.c @@ -1,53 +1,62 @@ -// star_door.c.inc +// star_door.inc.c void star_door_update_pos(void) { - o->oVelX = (o->oUnkBC) * coss(o->oMoveAngleYaw); - o->oVelZ = (o->oUnkBC) * -sins(o->oMoveAngleYaw); + o->oVelX = (o->oLeftVel) * coss(o->oMoveAngleYaw); + o->oVelZ = (o->oLeftVel) * -sins(o->oMoveAngleYaw); o->oPosX += o->oVelX; o->oPosZ += o->oVelZ; } void bhv_star_door_loop(void) { - UNUSED u8 pad[4]; - struct Object *sp18; - sp18 = cur_obj_nearest_object_with_behavior(bhvStarDoor); + UNUSED u8 filler[4]; + struct Object *sp18 = cur_obj_nearest_object_with_behavior(bhvStarDoor); + switch (o->oAction) { case 0: cur_obj_become_tangible(); - if (0x30000 & o->oInteractStatus) + if (o->oInteractStatus & (INT_STATUS_UNK16 | INT_STATUS_UNK17)) { o->oAction = 1; - if (sp18 != NULL && sp18->oAction != 0) + } + if (sp18 != NULL && sp18->oAction != 0) { o->oAction = 1; + } break; + case 1: - if (o->oTimer == 0 && (s16)(o->oMoveAngleYaw) >= 0) { + if (o->oTimer == 0 && (s16) o->oMoveAngleYaw >= 0) { cur_obj_play_sound_2(SOUND_GENERAL_STAR_DOOR_OPEN); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(35, 30); #endif } cur_obj_become_intangible(); - o->oUnkBC = -8.0f; + o->oLeftVel = -8.0f; star_door_update_pos(); - if (o->oTimer >= 16) + if (o->oTimer > 15) { o->oAction++; + } break; + case 2: - if (o->oTimer >= 31) + if (o->oTimer > 30) { o->oAction++; + } break; + case 3: - if (o->oTimer == 0 && (s16)(o->oMoveAngleYaw) >= 0) { + if (o->oTimer == 0 && (s16) o->oMoveAngleYaw >= 0) { cur_obj_play_sound_2(SOUND_GENERAL_STAR_DOOR_CLOSE); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(35, 30); #endif } - o->oUnkBC = 8.0f; + o->oLeftVel = 8.0f; star_door_update_pos(); - if (o->oTimer >= 16) + if (o->oTimer > 15) { o->oAction++; + } break; + case 4: o->oInteractStatus = 0; o->oAction = 0; diff --git a/src/game/behaviors/static_checkered_platform.inc.c b/src/game/behaviors/static_checkered_platform.inc.c index 0537489b..a9e27cee 100644 --- a/src/game/behaviors/static_checkered_platform.inc.c +++ b/src/game/behaviors/static_checkered_platform.inc.c @@ -1,21 +1,24 @@ -// static_checkered_platform.c.inc +// static_checkered_platform.inc.c void bhv_static_checkered_platform_loop(void) { - if (gDebugInfo[5][0] == 1) { + if (gDebugInfo[DEBUG_PAGE_ENEMYINFO][0] == 1) { obj_set_angle(o, 0, 0, 0); o->oAngleVelPitch = 0; o->oAngleVelYaw = 0; o->oAngleVelRoll = 0; } - if (gDebugInfo[5][0] == 2) { - o->oFaceAnglePitch = gDebugInfo[5][1] << 12; - o->oFaceAngleYaw = gDebugInfo[5][2] << 12; - o->oFaceAngleRoll = gDebugInfo[5][3] << 12; + + if (gDebugInfo[DEBUG_PAGE_ENEMYINFO][0] == 2) { + o->oFaceAnglePitch = gDebugInfo[DEBUG_PAGE_ENEMYINFO][1] << 12; + o->oFaceAngleYaw = gDebugInfo[DEBUG_PAGE_ENEMYINFO][2] << 12; + o->oFaceAngleRoll = gDebugInfo[DEBUG_PAGE_ENEMYINFO][3] << 12; } - o->oAngleVelPitch = gDebugInfo[5][4]; - o->oAngleVelYaw = gDebugInfo[5][5]; - o->oAngleVelRoll = gDebugInfo[5][6]; - if (gDebugInfo[5][0] == 3) { + + o->oAngleVelPitch = gDebugInfo[DEBUG_PAGE_ENEMYINFO][4]; + o->oAngleVelYaw = gDebugInfo[DEBUG_PAGE_ENEMYINFO][5]; + o->oAngleVelRoll = gDebugInfo[DEBUG_PAGE_ENEMYINFO][6]; + + if (gDebugInfo[DEBUG_PAGE_ENEMYINFO][0] == 3) { o->oFaceAnglePitch += o->oAngleVelPitch; o->oFaceAngleYaw += o->oAngleVelYaw; o->oFaceAngleRoll += o->oAngleVelRoll; diff --git a/src/game/behaviors/strong_wind_particle.inc.c b/src/game/behaviors/strong_wind_particle.inc.c index 50cd04be..993c22a7 100644 --- a/src/game/behaviors/strong_wind_particle.inc.c +++ b/src/game/behaviors/strong_wind_particle.inc.c @@ -1,39 +1,40 @@ -// strong_wind_particle.c.inc +// strong_wind_particle.inc.c struct ObjectHitbox sStrongWindParticleHitbox = { - /* interactType: */ INTERACT_STRONG_WIND, - /* downOffset: */ 0, + /* interactType: */ INTERACT_STRONG_WIND, + /* downOffset: */ 0, /* damageOrCoinValue: */ 0, - /* health: */ 0, - /* numLootCoins: */ 0, - /* radius: */ 20, - /* height: */ 70, - /* hurtboxRadius: */ 20, - /* hurtboxHeight: */ 70, + /* health: */ 0, + /* numLootCoins: */ 0, + /* radius: */ 20, + /* height: */ 70, + /* hurtboxRadius: */ 20, + /* hurtboxHeight: */ 70, }; void bhv_strong_wind_particle_loop(void) { struct Object *penguinObj; f32 distanceFromPenguin; f32 penguinXDist, penguinZDist; - + obj_set_hitbox(o, &sStrongWindParticleHitbox); - + if (o->oTimer == 0) { o->oStrongWindParticlePenguinObj = cur_obj_nearest_object_with_behavior(bhvSLWalkingPenguin); obj_translate_xyz_random(o, 100.0f); - + o->oForwardVel = coss(o->oMoveAnglePitch) * 100.0f; o->oVelY = sins(o->oMoveAnglePitch) * -100.0f; - + o->oMoveAngleYaw += random_f32_around_zero(o->oBehParams2ndByte * 500); // Wind spread o->oOpacity = 100; } - + cur_obj_move_using_fvel_and_gravity(); - if (o->oTimer > 15) // Deactivate after 15 frames + if (o->oTimer > 15) { // Deactivate after 15 frames obj_mark_for_deletion(o); - + } + // If collided with the SL walking penguin, deactivate. penguinObj = o->oStrongWindParticlePenguinObj; if (penguinObj != NULL) { @@ -51,13 +52,14 @@ void bhv_strong_wind_particle_loop(void) { // Used for the Snowman in SL and Fwoosh. void cur_obj_spawn_strong_wind_particles(s32 windSpread, f32 scale, f32 relPosX, f32 relPosY, f32 relPosZ) { // Alternate between tiny particles and regular particles each frame. - if ((gGlobalTimer & 1) != 0) { + if (gGlobalTimer & 1) { // Because the tiny particles are unimportant objects, invisible wind particles are spawned to provide collision. // There was absolutely no reason to make the smaller particles unimportant, though... spawn_object_relative_with_scale(windSpread, relPosX, relPosY, relPosZ, 0.5f, o, MODEL_WHITE_PARTICLE_DL, bhvTinyStrongWindParticle); spawn_object_relative_with_scale(windSpread, relPosX, relPosY, relPosZ, scale, o, MODEL_NONE, bhvStrongWindParticle); - } else + } else { spawn_object_relative_with_scale(windSpread, relPosX, relPosY, relPosZ, scale, o, MODEL_MIST, bhvStrongWindParticle); + } // There is also no need to spawn additional invisible wind particles here. // If the devs were worried about object overload when making small particles unimportant, why spawn these? // It isn't to ensure collision, as even 1 particle every 2 frames is enough to ensure this reliably. diff --git a/src/game/behaviors/sushi.inc.c b/src/game/behaviors/sushi.inc.c index 52282c64..48fff5ea 100644 --- a/src/game/behaviors/sushi.inc.c +++ b/src/game/behaviors/sushi.inc.c @@ -1,19 +1,26 @@ -// sushi.c.inc +// sushi.inc.c void bhv_sushi_shark_collision_loop(void) { } void bhv_sushi_shark_loop(void) { f32 sp1C = find_water_level(o->oPosX, o->oPosZ); + o->oPosX = o->oHomeX + sins(o->oSushiSharkUnkF4) * 1700.0f; o->oPosZ = o->oHomeZ + coss(o->oSushiSharkUnkF4) * 1700.0f; o->oPosY = sp1C + o->oHomeY + sins(o->oSushiSharkUnkF4) * 200.0f; + o->oMoveAngleYaw = o->oSushiSharkUnkF4 + 0x4000; o->oSushiSharkUnkF4 += 0x80; - if (gMarioObject->oPosY - sp1C > -500.0f) - if (o->oPosY - sp1C > -200.0f) + + if (gMarioObject->oPosY - sp1C > -500.0f) { + if (o->oPosY - sp1C > -200.0f) { spawn_object_with_scale(o, MODEL_WAVE_TRAIL, bhvObjectWaveTrail, 4.0f); - if ((o->oTimer & 0xF) == 0) + } + } + if (!(o->oTimer & 0x0F)) { cur_obj_play_sound_2(SOUND_OBJ_SUSHI_SHARK_WATER_SOUND); + } + o->oInteractStatus = 0; } diff --git a/src/game/behaviors/swing_platform.inc.c b/src/game/behaviors/swing_platform.inc.c index e3fb2911..b51cee97 100644 --- a/src/game/behaviors/swing_platform.inc.c +++ b/src/game/behaviors/swing_platform.inc.c @@ -1,3 +1,4 @@ +// swing_platform.inc.c void bhv_swing_platform_init(void) { o->oSwingPlatformAngle = 0x2000; diff --git a/src/game/behaviors/switch_hidden_objects.inc.c b/src/game/behaviors/switch_hidden_objects.inc.c index e159700f..0dc44789 100644 --- a/src/game/behaviors/switch_hidden_objects.inc.c +++ b/src/game/behaviors/switch_hidden_objects.inc.c @@ -1,20 +1,21 @@ -// switch_hidden_objects.c.inc +// switch_hidden_objects.inc.c struct ObjectHitbox sBreakableBoxHitbox = { - /* interactType: */ INTERACT_BREAKABLE, - /* downOffset: */ 20, + /* interactType: */ INTERACT_BREAKABLE, + /* downOffset: */ 20, /* damageOrCoinValue: */ 0, - /* health: */ 1, - /* numLootCoins: */ 0, - /* radius: */ 150, - /* height: */ 200, - /* hurtboxRadius: */ 150, - /* hurtboxHeight: */ 200, + /* health: */ 1, + /* numLootCoins: */ 0, + /* radius: */ 150, + /* height: */ 200, + /* hurtboxRadius: */ 150, + /* hurtboxHeight: */ 200, }; void breakable_box_init(void) { o->oHiddenObjectUnkF4 = NULL; o->oAnimState = 1; + switch (o->oBehParams2ndByte) { case 0: o->oNumLootCoins = 0; @@ -33,28 +34,34 @@ void breakable_box_init(void) { void hidden_breakable_box_actions(void) { struct Object *sp1C; + obj_set_hitbox(o, &sBreakableBoxHitbox); cur_obj_set_model(MODEL_BREAKABLE_BOX_SMALL); + if (o->oAction == 0) { cur_obj_disable_rendering(); cur_obj_become_intangible(); - if (o->oTimer == 0) + if (o->oTimer == 0) { breakable_box_init(); - if (o->oHiddenObjectUnkF4 == NULL) + } + if (o->oHiddenObjectUnkF4 == NULL) { o->oHiddenObjectUnkF4 = cur_obj_nearest_object_with_behavior(bhvFloorSwitchHiddenObjects); - if ((sp1C = o->oHiddenObjectUnkF4) != NULL) + } + if ((sp1C = o->oHiddenObjectUnkF4) != NULL) { if (sp1C->oAction == 2) { o->oAction++; cur_obj_enable_rendering(); cur_obj_unhide(); } + } } else if (o->oAction == 1) { cur_obj_become_tangible(); - if (cur_obj_wait_then_blink(360, 20)) + if (cur_obj_wait_then_blink(360, 20)) { o->oAction = 0; + } if (cur_obj_was_attacked_or_ground_pounded()) { spawn_mist_particles(); - spawn_triangle_break_particles(30, 138, 3.0f, 4); + spawn_triangle_break_particles(30, MODEL_DIRT_ANIMATION, 3.0f, 4); o->oAction++; cur_obj_play_sound_2(SOUND_GENERAL_BREAK_BOX); } @@ -63,37 +70,45 @@ void hidden_breakable_box_actions(void) { cur_obj_become_intangible(); cur_obj_disable_rendering(); o->oInteractStatus = 0; - if ((sp1C = o->oHiddenObjectUnkF4) != NULL) - if (sp1C->oAction == 0) + if ((sp1C = o->oHiddenObjectUnkF4) != NULL) { + if (sp1C->oAction == 0) { o->oAction = 0; + } + } } } void hidden_unbreakable_box_actions(void) { struct Object *sp1C; + obj_set_collision_data(o, wdw_seg7_collision_07018528); + if (o->oAction == 0) { cur_obj_disable_rendering(); cur_obj_become_intangible(); - if (o->oHiddenObjectUnkF4 == NULL) + if (o->oHiddenObjectUnkF4 == NULL) { o->oHiddenObjectUnkF4 = cur_obj_nearest_object_with_behavior(bhvFloorSwitchHiddenObjects); - if ((sp1C = o->oHiddenObjectUnkF4) != NULL) + } + if ((sp1C = o->oHiddenObjectUnkF4) != NULL) { if (sp1C->oAction == 2) { o->oAction++; cur_obj_enable_rendering(); cur_obj_unhide(); } + } } else { cur_obj_become_tangible(); - if (cur_obj_wait_then_blink(360, 20)) + if (cur_obj_wait_then_blink(360, 20)) { o->oAction = 0; + } load_object_collision_model(); } } void bhv_hidden_object_loop(void) { - if (o->oBehParams2ndByte == 0) + if (o->oBehParams2ndByte == 0) { hidden_breakable_box_actions(); // Confused, that function has code depending on the action - else + } else { hidden_unbreakable_box_actions(); + } } diff --git a/src/game/behaviors/swoop.inc.c b/src/game/behaviors/swoop.inc.c index 8e628cf4..84f0473d 100644 --- a/src/game/behaviors/swoop.inc.c +++ b/src/game/behaviors/swoop.inc.c @@ -61,7 +61,7 @@ static void swoop_act_move(void) { o->oFaceAngleRoll = 0; } else { if (o->oSwoopBonkCountdown != 0) { - o->oSwoopBonkCountdown -= 1; + o->oSwoopBonkCountdown--; } else if (o->oVelY != 0.0f) { // If we're not done swooping, turn toward mario. When between // 0 and 200 units above mario, increase speed and stop swooping diff --git a/src/game/behaviors/thi_top.inc.c b/src/game/behaviors/thi_top.inc.c index 23c97a06..8b5a9bca 100644 --- a/src/game/behaviors/thi_top.inc.c +++ b/src/game/behaviors/thi_top.inc.c @@ -1,31 +1,43 @@ -// thi_top.c.inc +// thi_top.inc.c -struct SpawnParticlesInfo D_8032F134 = { - 0, 30, MODEL_WHITE_PARTICLE_SMALL, 0, 40, 0, 20, 40, 252, 30, 20.0f, 0.0f +static struct SpawnParticlesInfo sThiTopPuffs = { + /* behParam: */ 0, + /* count: */ 30, + /* model: */ MODEL_WHITE_PARTICLE_SMALL, + /* offsetY: */ 0, + /* forwardVelBase: */ 40, + /* forwardVelRange: */ 0, + /* velYBase: */ 20, + /* velYRange: */ 40, + /* gravity: */ 252, + /* dragStrength: */ 30, + /* sizeBase: */ 20.0f, + /* sizeRange: */ 0.0f, }; -UNUSED u8 unused8032F134[] = { 10, 11, 12 }; - void bhv_thi_huge_island_top_loop(void) { if (gTHIWaterDrained & 1) { - if (o->oTimer == 0) + if (o->oTimer == 0) { gEnvironmentRegions[18] = 3000; + } cur_obj_hide(); - } else + } else { load_object_collision_model(); + } } void bhv_thi_tiny_island_top_loop(void) { if (!(gTHIWaterDrained & 1)) { if (o->oAction == 0) { - if (o->oDistanceToMario < 500.0f) + if (o->oDistanceToMario < 500.0f) { if (gMarioStates[0].action == ACT_GROUND_POUND_LAND) { o->oAction++; - cur_obj_spawn_particles(&D_8032F134); - spawn_triangle_break_particles(20, 138, 0.3f, 3); + cur_obj_spawn_particles(&sThiTopPuffs); + spawn_triangle_break_particles(20, MODEL_DIRT_ANIMATION, 0.3f, 3); cur_obj_play_sound_2(SOUND_GENERAL_ACTIVATE_CAP_SWITCH); cur_obj_hide(); } + } } else { if (o->oTimer < 50) { gEnvironmentRegions[18]--; @@ -33,12 +45,13 @@ void bhv_thi_tiny_island_top_loop(void) { } else { gTHIWaterDrained |= 1; play_puzzle_jingle(); - o->oAction += 1; + o->oAction++; } } } else { - if (o->oTimer == 0) + if (o->oTimer == 0) { gEnvironmentRegions[18] = 700; + } cur_obj_hide(); } } diff --git a/src/game/behaviors/thwomp.inc.c b/src/game/behaviors/thwomp.inc.c index fdb3345b..00093c9d 100644 --- a/src/game/behaviors/thwomp.inc.c +++ b/src/game/behaviors/thwomp.inc.c @@ -1,10 +1,12 @@ -// thwomp.c.inc +// thwomp.inc.c void grindel_thwomp_act_4(void) { - if (o->oTimer == 0) + if (o->oTimer == 0) { o->oThwompRandomTimer = random_float() * 10.0f + 20.0f; - if (o->oTimer > o->oThwompRandomTimer) + } + if (o->oTimer > o->oThwompRandomTimer) { o->oAction = 0; + } } void grindel_thwomp_act_2(void) { @@ -12,39 +14,48 @@ void grindel_thwomp_act_2(void) { o->oPosY += o->oVelY; if (o->oPosY < o->oHomeY) { o->oPosY = o->oHomeY; - o->oVelY = 0; + o->oVelY = 0.0f; o->oAction = 3; } } void grindel_thwomp_act_3(void) { - if (o->oTimer == 0) + if (o->oTimer == 0) { if (o->oDistanceToMario < 1500.0f) { cur_obj_shake_screen(SHAKE_POS_SMALL); cur_obj_play_sound_2(SOUND_OBJ_THWOMP); } - if (o->oTimer > 9) + } + if (o->oTimer >= 10) { o->oAction = 4; + } } void grindel_thwomp_act_1(void) { - if (o->oTimer == 0) + if (o->oTimer == 0) { o->oThwompRandomTimer = random_float() * 30.0f + 10.0f; - if (o->oTimer > o->oThwompRandomTimer) + } + if (o->oTimer > o->oThwompRandomTimer) { o->oAction = 2; + } } void grindel_thwomp_act_0(void) { if (o->oBehParams2ndByte + 40 < o->oTimer) { o->oAction = 1; o->oPosY += 5.0f; - } else + } else { o->oPosY += 10.0f; + } } -void (*sGrindelThwompActions[])(void) = { grindel_thwomp_act_0, grindel_thwomp_act_1, - grindel_thwomp_act_2, grindel_thwomp_act_3, - grindel_thwomp_act_4 }; +void (*sGrindelThwompActions[])(void) = { + grindel_thwomp_act_0, + grindel_thwomp_act_1, + grindel_thwomp_act_2, + grindel_thwomp_act_3, + grindel_thwomp_act_4, +}; void bhv_grindel_thwomp_loop(void) { cur_obj_call_action_function(sGrindelThwompActions); diff --git a/src/game/behaviors/tilting_inverted_pyramid.inc.c b/src/game/behaviors/tilting_inverted_pyramid.inc.c index ebce64fc..77193dc7 100644 --- a/src/game/behaviors/tilting_inverted_pyramid.inc.c +++ b/src/game/behaviors/tilting_inverted_pyramid.inc.c @@ -1,3 +1,4 @@ + /** * This is the behavior file for the tilting inverted pyramids in BitFS/LLL. * The object essentially just tilts and moves Mario with it. @@ -77,9 +78,9 @@ void bhv_tilting_inverted_pyramid_loop(void) { f32 mz; s32 marioOnPlatform = FALSE; - UNUSED s32 unused; + UNUSED u8 filler1[4]; Mat4 *transform = &o->transform; - UNUSED s32 unused2[7]; + UNUSED u8 filler2[28]; if (gMarioObject->platform == o) { get_mario_pos(&mx, &my, &mz); @@ -107,8 +108,9 @@ void bhv_tilting_inverted_pyramid_loop(void) { dz = 0.0f; } - if (o->oTiltingPyramidMarioOnPlatform == TRUE) + if (o->oTiltingPyramidMarioOnPlatform == TRUE) { marioOnPlatform++; + } o->oTiltingPyramidMarioOnPlatform = TRUE; } else { @@ -126,7 +128,7 @@ void bhv_tilting_inverted_pyramid_loop(void) { create_transform_from_normals(*transform, o->oTiltingPyramidNormalX, o->oTiltingPyramidNormalY, o->oTiltingPyramidNormalZ); // If Mario is on the platform, adjust his position for the platform tilt. - if (marioOnPlatform != FALSE) { + if (marioOnPlatform) { linear_mtxf_mul_vec3f(*transform, posAfterRotation, dist); mx += posAfterRotation[0] - posBeforeRotation[0]; my += posAfterRotation[1] - posBeforeRotation[1]; diff --git a/src/game/behaviors/tower_door.inc.c b/src/game/behaviors/tower_door.inc.c index 70bdf31c..513a9a45 100644 --- a/src/game/behaviors/tower_door.inc.c +++ b/src/game/behaviors/tower_door.inc.c @@ -1,9 +1,11 @@ -// tower_door.c.inc +// tower_door.inc.c void bhv_tower_door_loop(void) { - if (o->oTimer == 0) + if (o->oTimer == 0) { o->oMoveAngleYaw -= 0x4000; - if (check_mario_attacking(0)) { + } + + if (check_mario_attacking(0) != 0) { obj_explode_and_spawn_coins(80.0f, 0); create_sound_spawner(SOUND_GENERAL_WALL_EXPLOSION); } diff --git a/src/game/behaviors/tower_platform.inc.c b/src/game/behaviors/tower_platform.inc.c index 8103fa5d..aca5c371 100644 --- a/src/game/behaviors/tower_platform.inc.c +++ b/src/game/behaviors/tower_platform.inc.c @@ -1,81 +1,104 @@ -// tower_platform.c.inc +// tower_platform.inc.c void bhv_wf_solid_tower_platform_loop(void) { - if (o->parentObj->oAction == 3) + if (o->parentObj->oAction == 3) { obj_mark_for_deletion(o); + } } void bhv_wf_elevator_tower_platform_loop(void) { switch (o->oAction) { case 0: - if (gMarioObject->platform == o) + if (gMarioObject->platform == o) { o->oAction++; + } break; + case 1: cur_obj_play_sound_1(SOUND_ENV_ELEVATOR1); - if (o->oTimer > 140) + if (o->oTimer > 140) { o->oAction++; - else + } else { o->oPosY += 5.0f; + } break; + case 2: - if (o->oTimer > 60) + if (o->oTimer > 60) { o->oAction++; + } break; + case 3: cur_obj_play_sound_1(SOUND_ENV_ELEVATOR1); - if (o->oTimer > 140) + if (o->oTimer > 140) { o->oAction = 0; - else + } else { o->oPosY -= 5.0f; + } break; } - if (o->parentObj->oAction == 3) + + if (o->parentObj->oAction == 3) { obj_mark_for_deletion(o); + } } void bhv_wf_sliding_tower_platform_loop(void) { s32 sp24 = o->oPlatformUnk110 / o->oPlatformUnk10C; + switch (o->oAction) { case 0: - if (o->oTimer > sp24) + if (o->oTimer > sp24) { o->oAction++; + } o->oForwardVel = -o->oPlatformUnk10C; break; + case 1: - if (o->oTimer > sp24) + if (o->oTimer > sp24) { o->oAction = 0; + } o->oForwardVel = o->oPlatformUnk10C; break; } + cur_obj_compute_vel_xz(); + o->oPosX += o->oVelX; o->oPosZ += o->oVelZ; - if (o->parentObj->oAction == 3) + + if (o->parentObj->oAction == 3) { obj_mark_for_deletion(o); + } } void spawn_and_init_wf_platforms(s16 a, const BehaviorScript *bhv) { s16 yaw; struct Object *platform = spawn_object(o, a, bhv); + yaw = o->oPlatformSpawnerUnkF4 * o->oPlatformSpawnerUnkFC + o->oPlatformSpawnerUnkF8; + platform->oMoveAngleYaw = yaw; platform->oPosX += o->oPlatformSpawnerUnk100 * sins(yaw); platform->oPosY += 100 * o->oPlatformSpawnerUnkF4; platform->oPosZ += o->oPlatformSpawnerUnk100 * coss(yaw); platform->oPlatformUnk110 = o->oPlatformSpawnerUnk104; platform->oPlatformUnk10C = o->oPlatformSpawnerUnk108; + o->oPlatformSpawnerUnkF4++; } void spawn_wf_platform_group(void) { UNUSED s32 unused = 8; + o->oPlatformSpawnerUnkF4 = 0; o->oPlatformSpawnerUnkF8 = 0; o->oPlatformSpawnerUnkFC = 0x2000; o->oPlatformSpawnerUnk100 = 704.0f; o->oPlatformSpawnerUnk104 = 380.0f; o->oPlatformSpawnerUnk108 = 3.0f; + spawn_and_init_wf_platforms(MODEL_WF_TOWER_SQUARE_PLATORM, bhvWfSolidTowerPlatform); spawn_and_init_wf_platforms(MODEL_WF_TOWER_SQUARE_PLATORM, bhvWfSlidingTowerPlatform); spawn_and_init_wf_platforms(MODEL_WF_TOWER_SQUARE_PLATORM, bhvWfSolidTowerPlatform); @@ -88,20 +111,27 @@ void spawn_wf_platform_group(void) { void bhv_tower_platform_group_loop(void) { f32 marioY = gMarioObject->oPosY; + o->oDistanceToMario = dist_between_objects(o, gMarioObject); + switch (o->oAction) { case 0: - if (marioY > o->oHomeY - 1000.0f) + if (marioY > o->oHomeY - 1000.0f) { o->oAction++; + } break; + case 1: spawn_wf_platform_group(); o->oAction++; break; + case 2: - if (marioY < o->oHomeY - 1000.0f) + if (marioY < o->oHomeY - 1000.0f) { o->oAction++; + } break; + case 3: o->oAction = 0; break; diff --git a/src/game/behaviors/tox_box.inc.c b/src/game/behaviors/tox_box.inc.c index 2bbb40bf..47c25b20 100644 --- a/src/game/behaviors/tox_box.inc.c +++ b/src/game/behaviors/tox_box.inc.c @@ -1,4 +1,4 @@ -// tox_box.c.inc +// tox_box.inc.c s8 D_8032F8F0[] = { 4, 1, 4, 1, 6, 1, 6, 1, 5, 1, 5, 1, 6, 1, 6, 1, 5, 1, 2, 4, 1, 4, 1, 4, 1, 2, 5, 1, 5, 1, 7, 1, 7, 1, 4, 1, 4, 1, 7, 1, 7, 1, 5, 1, 5, 1, 5, 1, 2, 4, 1, -1 }; @@ -9,60 +9,70 @@ s8 D_8032F948[] = { 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 2, 5, 1, 5, 1, 5, 1, 5, s8 *D_8032F96C[] = { D_8032F8F0, D_8032F924, D_8032F948 }; void tox_box_shake_screen(void) { - if (o->oDistanceToMario < 3000.0f) + if (o->oDistanceToMario < 3000.0f) { cur_obj_shake_screen(SHAKE_POS_SMALL); + } } -void tox_box_move(f32 forwardVel, f32 a1, s16 deltaPitch, s16 deltaRoll) -{ +void tox_box_move(f32 forwardVel, f32 a1, s16 deltaPitch, s16 deltaRoll) { o->oPosY = 99.41124 * sins((f32)(o->oTimer + 1) / 8 * 0x8000) + o->oHomeY + 3.0f; o->oForwardVel = forwardVel; - o->oUnkC0 = a1; + o->oUpVel = a1; o->oFaceAnglePitch += deltaPitch; - if ((s16) o->oFaceAnglePitch < 0) + + if ((s16) o->oFaceAnglePitch < 0) { deltaRoll = -deltaRoll; + } + o->oFaceAngleRoll += deltaRoll; cur_obj_set_pos_via_transform(); + if (o->oTimer == 7) { o->oAction = cur_obj_progress_direction_table(); -#ifndef VERSION_JP cur_obj_play_sound_2(SOUND_GENERAL_UNK46); -#else - cur_obj_play_sound_2(SOUND_GENERAL_UNK46_LOWPRIO); -#endif } } void tox_box_act_4(void) { tox_box_move(64.0f, 0.0f, 0x800, 0); } + void tox_box_act_5(void) { tox_box_move(-64.0f, 0.0f, -0x800, 0); } + void tox_box_act_6(void) { tox_box_move(0.0f, -64.0f, 0, 0x800); } + void tox_box_act_7(void) { tox_box_move(0.0f, 64.0f, 0, -0x800); } void tox_box_act_1(void) { o->oForwardVel = 0.0f; - if (o->oTimer == 0) + + if (o->oTimer == 0) { tox_box_shake_screen(); + } + o->oPosY = o->oHomeY + 3.0f; - if (o->oTimer == 20) + + if (o->oTimer == 20) { o->oAction = cur_obj_progress_direction_table(); + } } void tox_box_act_2(void) { - if (o->oTimer == 20) + if (o->oTimer == 20) { o->oAction = cur_obj_progress_direction_table(); + } } void tox_box_act_3(void) { - if (o->oTimer == 20) + if (o->oTimer == 20) { o->oAction = cur_obj_progress_direction_table(); + } } void tox_box_act_0(void) { @@ -70,8 +80,16 @@ void tox_box_act_0(void) { o->oAction = cur_obj_set_direction_table(sp1C); } -void (*sToxBoxActions[])(void) = { tox_box_act_0, tox_box_act_1, tox_box_act_2, tox_box_act_3, - tox_box_act_4, tox_box_act_5, tox_box_act_6, tox_box_act_7 }; +void (*sToxBoxActions[])(void) = { + tox_box_act_0, + tox_box_act_1, + tox_box_act_2, + tox_box_act_3, + tox_box_act_4, + tox_box_act_5, + tox_box_act_6, + tox_box_act_7, +}; void bhv_tox_box_loop(void) { cur_obj_call_action_function(sToxBoxActions); diff --git a/src/game/behaviors/treasure_chest.inc.c b/src/game/behaviors/treasure_chest.inc.c index 938a7581..55a6b0cc 100644 --- a/src/game/behaviors/treasure_chest.inc.c +++ b/src/game/behaviors/treasure_chest.inc.c @@ -1,4 +1,4 @@ -// treasure_chest.c.inc +// treasure_chest.inc.c /** * Hitbox for treasure chest bottom. @@ -20,8 +20,9 @@ void bhv_treasure_chest_top_loop(void) { switch (o->oAction) { case 0: - if (o->parentObj->oAction == 1) + if (o->parentObj->oAction == 1) { o->oAction = 1; + } break; case 1: @@ -34,18 +35,20 @@ void bhv_treasure_chest_top_loop(void) { } } - o->oFaceAnglePitch += -0x200; + o->oFaceAnglePitch -= 0x200; if (o->oFaceAnglePitch < -0x4000) { o->oFaceAnglePitch = -0x4000; o->oAction++; - if (o->parentObj->oBehParams2ndByte != 4) + if (o->parentObj->oBehParams2ndByte != 4) { spawn_orange_number(o->parentObj->oBehParams2ndByte, 0, -40, 0); + } } break; case 2: - if (o->parentObj->oAction == 0) + if (o->parentObj->oAction == 0) { o->oAction = 3; + } break; case 3: @@ -65,34 +68,33 @@ void bhv_treasure_chest_bottom_init(void) { void bhv_treasure_chest_bottom_loop(void) { switch (o->oAction) { case 0: - if (obj_check_if_facing_toward_angle(o->oMoveAngleYaw, gMarioObject->header.gfx.angle[1] + 0x8000, 0x3000)) { - if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 150)) { - if (!o->parentObj->oTreasureChestUnkF8) { - if (o->parentObj->oTreasureChestUnkF4 == o->oBehParams2ndByte) { - play_sound(SOUND_GENERAL2_RIGHT_ANSWER, gGlobalSoundSource); - o->parentObj->oTreasureChestUnkF4++; - o->oAction = 1; - } else { - o->parentObj->oTreasureChestUnkF4 = 1; - o->parentObj->oTreasureChestUnkF8 = 1; - o->oAction = 2; - cur_obj_become_tangible(); - play_sound(SOUND_MENU_CAMERA_BUZZ, gGlobalSoundSource); - } - } + if (obj_check_if_facing_toward_angle(o->oMoveAngleYaw, gMarioObject->header.gfx.angle[1] + 0x8000, 0x3000) + && is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 150) + && !o->parentObj->oTreasureChestUnkF8) { + if (o->parentObj->oTreasureChestUnkF4 == o->oBehParams2ndByte) { + play_sound(SOUND_GENERAL2_RIGHT_ANSWER, gGlobalSoundSource); + o->parentObj->oTreasureChestUnkF4++; + o->oAction = 1; + } else { + o->parentObj->oTreasureChestUnkF4 = 1; + o->parentObj->oTreasureChestUnkF8 = TRUE; + o->oAction = 2; + cur_obj_become_tangible(); + play_sound(SOUND_MENU_CAMERA_BUZZ, gGlobalSoundSource); } } break; case 1: - if (o->parentObj->oTreasureChestUnkF8 == 1) + if (o->parentObj->oTreasureChestUnkF8 == TRUE) { o->oAction = 0; + } break; case 2: cur_obj_become_intangible(); if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 500)) { - o->parentObj->oTreasureChestUnkF8 = 0; + o->parentObj->oTreasureChestUnkF8 = FALSE; o->oAction = 0; } } @@ -101,10 +103,9 @@ void bhv_treasure_chest_bottom_loop(void) { o->oInteractStatus = 0; } -void spawn_treasure_chest(s8 sp3B, s32 sp3C, s32 sp40, s32 sp44, s16 sp4A) { - struct Object *sp34; - sp34 = spawn_object_abs_with_rot(o, 0, MODEL_TREASURE_CHEST_BASE, bhvTreasureChestBottom, sp3C, - sp40, sp44, 0, sp4A, 0); +void spawn_treasure_chest(s8 sp3B, s32 x, s32 y, s32 z, s16 yaw) { + struct Object *sp34 = spawn_object_abs_with_rot(o, 0, MODEL_TREASURE_CHEST_BASE, + bhvTreasureChestBottom, x, y, z, 0, yaw, 0); sp34->oBehParams2ndByte = sp3B; } @@ -129,14 +130,14 @@ void bhv_treasure_chest_ship_loop(void) { case 1: if (gEnvironmentRegions != NULL) { - gEnvironmentRegions[6] += -5; + gEnvironmentRegions[6] -= 5; play_sound(SOUND_ENV_WATER_DRAIN, gGlobalSoundSource); set_environmental_camera_shake(SHAKE_ENV_JRB_SHIP_DRAIN); if (gEnvironmentRegions[6] < -335) { gEnvironmentRegions[6] = -335; o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers_2(2); #endif } diff --git a/src/game/behaviors/tree_particles.inc.c b/src/game/behaviors/tree_particles.inc.c index 6c5587ff..7fca3654 100644 --- a/src/game/behaviors/tree_particles.inc.c +++ b/src/game/behaviors/tree_particles.inc.c @@ -1,30 +1,42 @@ -// tree_particles.c.inc +// tree_particles.inc.c void bhv_tree_snow_or_leaf_loop(void) { cur_obj_update_floor_height(); + if (o->oTimer == 0) { o->oAngleVelPitch = (random_float() - 0.5) * 0x1000; o->oAngleVelRoll = (random_float() - 0.5) * 0x1000; o->oTreeSnowOrLeafUnkF8 = 4; o->oTreeSnowOrLeafUnkFC = random_float() * 0x400 + 0x600; } - if (o->oPosY < o->oFloorHeight) + + if (o->oPosY < o->oFloorHeight) { obj_mark_for_deletion(o); - if (o->oFloorHeight < -11000.0f) + } + if (o->oFloorHeight < FLOOR_LOWER_LIMIT) { obj_mark_for_deletion(o); - if (o->oTimer > 100) + } + if (o->oTimer > 100) { obj_mark_for_deletion(o); - if (gPrevFrameObjectCount > 212) + } + if (gPrevFrameObjectCount > (OBJECT_POOL_CAPACITY - 28)) { obj_mark_for_deletion(o); + } + o->oFaceAnglePitch += o->oAngleVelPitch; o->oFaceAngleRoll += o->oAngleVelRoll; o->oVelY += -3.0f; - if (o->oVelY < -8.0f) + + if (o->oVelY < -8.0f) { o->oVelY = -8.0f; - if (o->oForwardVel > 0) + } + + if (o->oForwardVel > 0) { o->oForwardVel -= 0.3; - else + } else { o->oForwardVel = 0; + } + o->oPosX += sins(o->oMoveAngleYaw) * sins(o->oTreeSnowOrLeafUnkF4) * o->oTreeSnowOrLeafUnkF8; o->oPosZ += coss(o->oMoveAngleYaw) * sins(o->oTreeSnowOrLeafUnkF4) * o->oTreeSnowOrLeafUnkF8; o->oTreeSnowOrLeafUnkF4 += o->oTreeSnowOrLeafUnkFC; @@ -33,15 +45,19 @@ void bhv_tree_snow_or_leaf_loop(void) { void bhv_snow_leaf_particle_spawn_init(void) { struct Object *obj; // Either snow or leaf - UNUSED s32 unused; + UNUSED u8 filler1[4]; s32 isSnow; f32 scale; - UNUSED s32 unused2; - gMarioObject->oActiveParticleFlags &= ~0x2000; - if (gCurrLevelNum == LEVEL_CCM || gCurrLevelNum == LEVEL_SL) - isSnow = 1; - else - isSnow = 0; + UNUSED u8 filler2[4]; + + gMarioObject->oActiveParticleFlags &= ~ACTIVE_PARTICLE_LEAF; + + if (gCurrLevelNum == LEVEL_CCM || gCurrLevelNum == LEVEL_SL) { + isSnow = TRUE; + } else { + isSnow = FALSE; + } + if (isSnow) { if (random_float() < 0.5) { obj = spawn_object(o, MODEL_WHITE_PARTICLE_DL, bhvTreeSnow); diff --git a/src/game/behaviors/triplet_butterfly.inc.c b/src/game/behaviors/triplet_butterfly.inc.c index 3da4f574..d39a3164 100644 --- a/src/game/behaviors/triplet_butterfly.inc.c +++ b/src/game/behaviors/triplet_butterfly.inc.c @@ -1,3 +1,5 @@ +// triplet_butterfly.inc.c + struct TripletButterflyActivationData { s32 model; const BehaviorScript *behavior; @@ -22,10 +24,9 @@ static struct TripletButterflyActivationData sTripletButterflyActivationData[] = }; static void triplet_butterfly_act_init(void) { - s32 butterflyNum; + s32 butterflyNum = o->oBehParams2ndByte & TRIPLET_BUTTERFLY_BP_BUTTERFLY_NUM; s32 i; - butterflyNum = o->oBehParams2ndByte & TRIPLET_BUTTERFLY_BP_BUTTERFLY_NUM; if (butterflyNum != 0 || o->oDistanceToMario < 200.0f) { if (butterflyNum == 0) { for (i = 1; i <= 2; i++) { @@ -116,8 +117,6 @@ static void triplet_butterfly_act_activate(void) { } static void triplet_butterfly_act_explode(void) { - f32 scaleIncrease; - obj_check_attacks(&sTripletButterflyExplodeHitbox, -1); if (o->oAction == -1 || (o->oMoveFlags & OBJ_MOVE_HIT_WALL) || o->oTimer >= 158) { @@ -126,7 +125,7 @@ static void triplet_butterfly_act_explode(void) { obj_mark_for_deletion(o); } else { if (o->oTimer > 120) { - scaleIncrease = 0.04f * coss(o->oTripletButterflyScalePhase); + f32 scaleIncrease = 0.04f * coss(o->oTripletButterflyScalePhase); if (scaleIncrease > 0.0f) { scaleIncrease *= 4.5f; o->oTripletButterflyScalePhase += 10000; diff --git a/src/game/behaviors/ttc_2d_rotator.inc.c b/src/game/behaviors/ttc_2d_rotator.inc.c index 46c7603e..a403381c 100644 --- a/src/game/behaviors/ttc_2d_rotator.inc.c +++ b/src/game/behaviors/ttc_2d_rotator.inc.c @@ -51,7 +51,7 @@ void bhv_ttc_2d_rotator_update(void) { s32 startYaw = o->oFaceAngleYaw; if (o->oTTC2DRotatorRandomDirTimer != 0) { - o->oTTC2DRotatorRandomDirTimer -= 1; + o->oTTC2DRotatorRandomDirTimer--; } // Wait until rotated to target yaw @@ -67,7 +67,7 @@ void bhv_ttc_2d_rotator_update(void) { // If ready for a change in direction, then pick a new // direction if (o->oTTC2DRotatorRandomDirTimer == 0) { - if (random_u16() & 0x3) { + if (random_u16() & 0x03) { o->oTTC2DRotatorIncrement = o->oTTC2DRotatorSpeed; o->oTTC2DRotatorRandomDirTimer = random_mod_offset(90, 60, 4); } else { diff --git a/src/game/behaviors/ttc_elevator.inc.c b/src/game/behaviors/ttc_elevator.inc.c index a4debfc2..f0f4fe12 100644 --- a/src/game/behaviors/ttc_elevator.inc.c +++ b/src/game/behaviors/ttc_elevator.inc.c @@ -20,7 +20,7 @@ void bhv_ttc_elevator_init(void) { // If behParam is nonzero, then move 100 * behParam units. Otherwise default // to 500 f32 peakOffset = - ((o->oBehParams >> 16) & 0xFFFF) != 0 ? 100.0f * ((o->oBehParams >> 16) & 0xFFFF) : 500.0f; + ((o->oBehParams >> 16) & 0xFFFF) ? 100.0f * ((o->oBehParams >> 16) & 0xFFFF) : 500.0f; o->oTTCElevatorPeakY = o->oPosY + peakOffset; } diff --git a/src/game/behaviors/ttc_moving_bar.inc.c b/src/game/behaviors/ttc_moving_bar.inc.c index e54e3c42..fb6efe05 100644 --- a/src/game/behaviors/ttc_moving_bar.inc.c +++ b/src/game/behaviors/ttc_moving_bar.inc.c @@ -43,11 +43,11 @@ static void ttc_moving_bar_act_wait(void) { // This is zero except on the first cycle, and is used to desync the // bars from each other at the very beginning if (o->oTTCMovingBarStoppedTimer != 0) { - o->oTTCMovingBarStoppedTimer -= 1; + o->oTTCMovingBarStoppedTimer--; } else { if (gTTCSpeedSetting == TTC_SPEED_RANDOM) { // Set the delay for the next cycle - o->oTTCMovingBarDelay = sTTCMovingBarRandomDelays[random_u16() & 0x3]; + o->oTTCMovingBarDelay = sTTCMovingBarRandomDelays[random_u16() & 0x03]; // With 50% probability, pause after pulling back if (random_u16() % 2 == 0) { @@ -70,7 +70,7 @@ static void ttc_moving_bar_act_pull_back(void) { if ((o->oTTCMovingBarSpeed += 0.73f) > 0.0f) { // Possibly pause after pulling back if (o->oTTCMovingBarStoppedTimer != 0) { - o->oTTCMovingBarStoppedTimer -= 1; + o->oTTCMovingBarStoppedTimer--; o->oTTCMovingBarSpeed = 0.0f; } else { // Begin extending diff --git a/src/game/behaviors/ttc_pendulum.inc.c b/src/game/behaviors/ttc_pendulum.inc.c index b63282e2..a492a4ce 100644 --- a/src/game/behaviors/ttc_pendulum.inc.c +++ b/src/game/behaviors/ttc_pendulum.inc.c @@ -42,7 +42,7 @@ void bhv_ttc_pendulum_update(void) { // Stay still for a while if (o->oTTCPendulumDelay != 0) { - o->oTTCPendulumDelay -= 1; + o->oTTCPendulumDelay--; } else { // Accelerate in the direction that moves angle to zero if (o->oTTCPendulumAngle * o->oTTCPendulumAccelDir > 0.0f) { diff --git a/src/game/behaviors/ttc_pit_block.inc.c b/src/game/behaviors/ttc_pit_block.inc.c index 1f3c221f..ccc45f58 100644 --- a/src/game/behaviors/ttc_pit_block.inc.c +++ b/src/game/behaviors/ttc_pit_block.inc.c @@ -56,10 +56,10 @@ void bhv_ttc_pit_block_update(void) { cur_obj_move_using_fvel_and_gravity(); if (clamp_f32(&o->oPosY, o->oHomeY, o->oTTCPitBlockPeakY)) { - o->oTTCPitBlockDir = o->oTTCPitBlockDir ^ 0x1; + o->oTTCPitBlockDir = o->oTTCPitBlockDir ^ 0x01; if ((o->oTTCPitBlockWaitTime = - sTTCPitBlockProperties[gTTCSpeedSetting][o->oTTCPitBlockDir & 0x1].waitTime) + sTTCPitBlockProperties[gTTCSpeedSetting][o->oTTCPitBlockDir & 0x01].waitTime) < 0) { o->oTTCPitBlockWaitTime = random_mod_offset(10, 20, 6); } diff --git a/src/game/behaviors/ttc_rotating_solid.inc.c b/src/game/behaviors/ttc_rotating_solid.inc.c index 238a8835..6a7a5a5b 100644 --- a/src/game/behaviors/ttc_rotating_solid.inc.c +++ b/src/game/behaviors/ttc_rotating_solid.inc.c @@ -7,7 +7,7 @@ /** * The collision models for cube and triangular prism, respectively. */ -static void const *sTTCRotatingSolidCollisionModels[] = { +static Collision const *sTTCRotatingSolidCollisionModels[] = { ttc_seg7_collision_07014F70, ttc_seg7_collision_07015008, }; @@ -51,7 +51,7 @@ void bhv_ttc_rotating_solid_update(void) { (s32)((f32) o->oTTCRotatingSolidNumTurns / o->oTTCRotatingSolidNumSides * 0x10000); s32 startRoll = o->oFaceAngleRoll; - obj_face_roll_approach(targetRoll, 0x4B0); + obj_face_roll_approach(targetRoll, 1200); o->oAngleVelRoll = o->oFaceAngleRoll - startRoll; if (o->oAngleVelRoll == 0) { diff --git a/src/game/behaviors/ttc_treadmill.inc.c b/src/game/behaviors/ttc_treadmill.inc.c index 537540b1..4a6c210b 100644 --- a/src/game/behaviors/ttc_treadmill.inc.c +++ b/src/game/behaviors/ttc_treadmill.inc.c @@ -25,7 +25,7 @@ extern s16 ttc_movtex_tris_big_surface_treadmill[]; extern s16 ttc_movtex_tris_small_surface_treadmill[]; void bhv_ttc_treadmill_init(void) { - o->collisionData = segmented_to_virtual(sTTCTreadmillCollisionModels[o->oBehParams2ndByte & 0x1]); + o->collisionData = segmented_to_virtual(sTTCTreadmillCollisionModels[o->oBehParams2ndByte & 0x01]); o->oTTCTreadmillBigSurface = segmented_to_virtual(ttc_movtex_tris_big_surface_treadmill); o->oTTCTreadmillSmallSurface = segmented_to_virtual(ttc_movtex_tris_small_surface_treadmill); diff --git a/src/game/behaviors/tumbling_bridge.inc.c b/src/game/behaviors/tumbling_bridge.inc.c index ffe02a12..8caf618c 100644 --- a/src/game/behaviors/tumbling_bridge.inc.c +++ b/src/game/behaviors/tumbling_bridge.inc.c @@ -1,15 +1,23 @@ -// tumbling_bridge.c.inc +// tumbling_bridge.inc.c #include "levels/wf/header.h" #include "levels/bbh/header.h" #include "levels/lll/header.h" #include "levels/bitfs/header.h" +struct Struct8032F34C { + s16 numBridgeSections; + s16 bridgeRelativeStartingXorZ; + s16 platformWidth; + s16 model; + const Collision *collision; +}; + struct Struct8032F34C sTumblingBridgeParams[] = { { 9, -512, 0x80, MODEL_WF_TUMBLING_BRIDGE_PART, wf_seg7_collision_tumbling_bridge }, { 9, -412, 103, MODEL_BBH_TUMBLING_PLATFORM_PART, bbh_seg7_collision_07026B1C }, { 9, -512, 0x80, MODEL_LLL_FALLING_PLATFORM, lll_seg7_collision_0701D21C }, - { 9, -512, 0x80, MODEL_BITFS_TUMBLING_PLATFORM_PART, bitfs_seg7_collision_07015288 } + { 9, -512, 0x80, MODEL_BITFS_TUMBLING_PLATFORM_PART, bitfs_seg7_collision_07015288 }, }; void bhv_tumbling_bridge_platform_loop(void) { @@ -20,6 +28,7 @@ void bhv_tumbling_bridge_platform_loop(void) { o->oTumblingBridgeUnkF4 = random_sign() * 0x80; } break; + case 1: cur_obj_update_floor_height(); if (o->oTimer > 5) { @@ -27,22 +36,29 @@ void bhv_tumbling_bridge_platform_loop(void) { cur_obj_play_sound_2(SOUND_GENERAL_PLATFORM); } break; + case 2: - if (o->oAngleVelPitch < 0x400) + if (o->oAngleVelPitch < 0x400) { o->oAngleVelPitch += 0x80; - if (o->oAngleVelRoll > -0x400 && o->oAngleVelRoll < 0x400) + } + if (o->oAngleVelRoll > -0x400 && o->oAngleVelRoll < 0x400) { o->oAngleVelRoll += o->oTumblingBridgeUnkF4; // acceleration? + } o->oGravity = -3.0f; cur_obj_rotate_face_angle_using_vel(); cur_obj_move_using_fvel_and_gravity(); - if (o->oPosY < o->oFloorHeight - 300.0f) + if (o->oPosY < o->oFloorHeight - 300.0f) { o->oAction++; + } break; + case 3: break; } - if (o->parentObj->oAction == 3) + + if (o->parentObj->oAction == 3) { obj_mark_for_deletion(o); + } } void tumbling_bridge_act_1(void) { @@ -58,16 +74,18 @@ void tumbling_bridge_act_1(void) { relativePlatformX = 0; relativePlatformZ = 0; - if (bridgeID == 3) + if (bridgeID == 3) { relativePlatformX = sTumblingBridgeParams[bridgeID].bridgeRelativeStartingXorZ + sTumblingBridgeParams[bridgeID].platformWidth * i; - else + } else { relativePlatformZ = sTumblingBridgeParams[bridgeID].bridgeRelativeStartingXorZ + sTumblingBridgeParams[bridgeID].platformWidth * i; + } if (cur_obj_has_behavior(bhvLllTumblingBridge)) { - if (i % 3 == 0) + if (i % 3 == 0) { relativePlatformY -= 150; + } relativeInitialPlatformY = 450; } @@ -75,7 +93,7 @@ void tumbling_bridge_act_1(void) { 0, relativePlatformX, relativePlatformY + relativeInitialPlatformY, relativePlatformZ, o, sTumblingBridgeParams[bridgeID].model, bhvTumblingBridgePlatform); - obj_set_collision_data(platformObj, sTumblingBridgeParams[bridgeID].segAddr); + obj_set_collision_data(platformObj, sTumblingBridgeParams[bridgeID].collision); } o->oAction = 2; @@ -83,9 +101,9 @@ void tumbling_bridge_act_1(void) { void tumbling_bridge_act_2(void) { cur_obj_hide(); - if (cur_obj_has_behavior(bhvLllTumblingBridge)) + if (cur_obj_has_behavior(bhvLllTumblingBridge)) { cur_obj_unhide(); - else if (o->oDistanceToMario > 1200.0f) { + } else if (o->oDistanceToMario > 1200.0f) { o->oAction = 3; cur_obj_unhide(); } @@ -97,15 +115,17 @@ void tumbling_bridge_act_3(void) { } void tumbling_bridge_act_0(void) { - if (cur_obj_has_behavior(bhvLllTumblingBridge) || o->oDistanceToMario < 1000.0f) + if (cur_obj_has_behavior(bhvLllTumblingBridge) || o->oDistanceToMario < 1000.0f) { o->oAction = 1; + } } -void (*sTumblingBridgeActions[])(void) = { tumbling_bridge_act_0, tumbling_bridge_act_1, - tumbling_bridge_act_2, tumbling_bridge_act_3 }; - -s16 D_8032F38C[] = { -51, 0, 0, -461, 0, 0, -512, 0, 0, -2611, 0, - 0, -2360, 0, 0, 214, 0, 0, -50, 1945, 1, 0 }; +void (*sTumblingBridgeActions[])(void) = { + tumbling_bridge_act_0, + tumbling_bridge_act_1, + tumbling_bridge_act_2, + tumbling_bridge_act_3, +}; void bhv_tumbling_bridge_loop(void) { cur_obj_call_action_function(sTumblingBridgeActions); diff --git a/src/game/behaviors/tuxie.inc.c b/src/game/behaviors/tuxie.inc.c index 1dae5850..c3c98f98 100644 --- a/src/game/behaviors/tuxie.inc.c +++ b/src/game/behaviors/tuxie.inc.c @@ -1,69 +1,78 @@ -// tuxie.c.inc +// tuxie.inc.c void play_penguin_walking_sound(s32 walk) { s32 sound; + if (o->oSoundStateID == 0) { - if (walk == PENGUIN_WALK_BABY) + if (walk == PENGUIN_WALK_BABY) { sound = SOUND_OBJ_BABY_PENGUIN_WALK; - else // PENGUIN_WALK_BIG + } else { // PENGUIN_WALK_BIG sound = SOUND_OBJ_BIG_PENGUIN_WALK; + } set_obj_anim_with_accel_and_sound(1, 11, sound); } } void tuxies_mother_act_2(void) { f32 sp24; - UNUSED s32 unused; + UNUSED u8 filler[4]; struct Object *sp1C = cur_obj_find_nearest_object_with_behavior(bhvSmallPenguin, &sp24); if (cur_obj_find_nearby_held_actor(bhvUnused20E0, 1000.0f) != NULL) { if (o->oSubAction == 0) { cur_obj_init_animation_with_sound(0); o->oForwardVel = 10.0f; - if (800.0f < cur_obj_lateral_dist_from_mario_to_home()) + if (cur_obj_lateral_dist_from_mario_to_home() > 800.0f) { o->oSubAction = 1; + } cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x400); } else { o->oForwardVel = 0.0f; cur_obj_init_animation_with_sound(3); - if (cur_obj_lateral_dist_from_mario_to_home() < 700.0f) + if (cur_obj_lateral_dist_from_mario_to_home() < 700.0f) { o->oSubAction = 0; + } } } else { o->oForwardVel = 0.0f; cur_obj_init_animation_with_sound(3); } + if (sp1C != NULL && sp24 < 300.0f && sp1C->oHeldState != HELD_FREE) { o->oAction = 1; - sp1C->oSmallPenguinUnk88 = 1; + sp1C->oSmallPenguinUnk88 = TRUE; o->prevObj = sp1C; } } void tuxies_mother_act_1(void) { - s32 sp2C; - s32 sp28; - s32 dialogID; switch (o->oSubAction) { case 0: cur_obj_init_animation_with_sound(3); if (!cur_obj_is_mario_on_platform()) { - sp2C = (o->oBehParams >> 0x10) & 0xFF; - sp28 = (o->prevObj->oBehParams >> 0x10) & 0xFF; - if (sp2C == sp28) + s32 sp2C = (o->oBehParams >> 16) & 0xFF; + s32 sp28 = (o->prevObj->oBehParams >> 16) & 0xFF; + s32 dialogID; + + if (sp2C == sp28) { dialogID = DIALOG_058; - else + } else { dialogID = DIALOG_059; - if (cur_obj_update_dialog_with_cutscene(2, 1, CUTSCENE_DIALOG, dialogID)) { - if (dialogID == DIALOG_058) + } + if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + DIALOG_FLAG_TURN_TO_MARIO, CUTSCENE_DIALOG, dialogID)) { + if (dialogID == DIALOG_058) { o->oSubAction = 1; - else + } else { o->oSubAction = 2; + } o->prevObj->oInteractionSubtype |= INT_SUBTYPE_DROP_IMMEDIATELY; } - } else + } else { cur_obj_init_animation_with_sound(0); + } break; + case 1: if (o->prevObj->oHeldState == HELD_FREE) { //! This line is was almost certainly supposed to be something @@ -84,6 +93,7 @@ void tuxies_mother_act_1(void) { o->oAction = 2; } break; + case 2: if (o->prevObj->oHeldState == HELD_FREE) { //! Same bug as above @@ -96,42 +106,52 @@ void tuxies_mother_act_1(void) { } void tuxies_mother_act_0(void) { - s32 sp2C; + s32 sp2C = FALSE; f32 sp28; - struct Object *sp24; - sp2C = 0; - sp24 = cur_obj_find_nearest_object_with_behavior(bhvSmallPenguin, &sp28); + struct Object *sp24 = cur_obj_find_nearest_object_with_behavior(bhvSmallPenguin, &sp28); + cur_obj_scale(4.0f); cur_obj_init_animation_with_sound(3); - if (sp28 < 500.0f) - sp2C = 1; + + if (sp28 < 500.0f) { + sp2C = TRUE; + } + if (sp24 != NULL && sp28 < 300.0f && sp24->oHeldState != HELD_FREE) { o->oAction = 1; - sp24->oSmallPenguinUnk88 = 1; + sp24->oSmallPenguinUnk88 = TRUE; o->prevObj = sp24; } else { switch (o->oSubAction) { case 0: - if (cur_obj_can_mario_activate_textbox_2(300.0f, 100.0f)) - if (sp2C == 0) - o->oSubAction++; + if (cur_obj_can_mario_activate_textbox_2(300.0f, 100.0f) && !sp2C) { + o->oSubAction++; + } break; case 1: - if (cur_obj_update_dialog_with_cutscene(2, 1, CUTSCENE_DIALOG, DIALOG_057)) + if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + DIALOG_FLAG_TURN_TO_MARIO, CUTSCENE_DIALOG, DIALOG_057)) { o->oSubAction++; + } break; case 2: - if (o->oDistanceToMario > 450.0f) + if (o->oDistanceToMario > 450.0f) { o->oSubAction = 0; + } break; } } - if (cur_obj_check_anim_frame(1)) + + if (cur_obj_check_anim_frame(1)) { cur_obj_play_sound_2(SOUND_OBJ_BIG_PENGUIN_YELL); + } } -void (*sTuxiesMotherActions[])(void) = { tuxies_mother_act_0, tuxies_mother_act_1, - tuxies_mother_act_2 }; +void (*sTuxiesMotherActions[])(void) = { + tuxies_mother_act_0, + tuxies_mother_act_1, + tuxies_mother_act_2, +}; void bhv_tuxies_mother_loop(void) { o->activeFlags |= ACTIVE_FLAG_UNK10; @@ -150,39 +170,46 @@ void small_penguin_dive_with_mario(void) { } void small_penguin_act_2(void) { - s32 sp1C = 0; - if (o->oTimer == 0) - if (cur_obj_dist_to_nearest_object_with_behavior(bhvTuxiesMother) < 1000.0f) - sp1C = 1; + s32 sp1C = FALSE; + + if (o->oTimer == 0 + && cur_obj_dist_to_nearest_object_with_behavior(bhvTuxiesMother) < 1000.0f) { + sp1C = TRUE; + } cur_obj_init_animation_with_sound(0); o->oForwardVel = o->oSmallPenguinUnk104 + 3.0f; cur_obj_rotate_yaw_toward(o->oAngleToMario + 0x8000, o->oSmallPenguinUnk110 + 0x600); - if (o->oDistanceToMario > o->oSmallPenguinUnk108 + 500.0f) + if (o->oDistanceToMario > o->oSmallPenguinUnk108 + 500.0f) { o->oAction = 0; + } small_penguin_dive_with_mario(); - if (sp1C) + if (sp1C) { o->oAction = 5; + } } void small_penguin_act_1(void) { cur_obj_init_animation_with_sound(0); o->oForwardVel = o->oSmallPenguinUnk104 + 3.0f; cur_obj_rotate_yaw_toward(o->oAngleToMario, o->oSmallPenguinUnk110 + 0x600); - if (o->oDistanceToMario < o->oSmallPenguinUnk108 + 300.0f) + if (o->oDistanceToMario < o->oSmallPenguinUnk108 + 300.0f) { o->oAction = 0; - if (o->oDistanceToMario > 1100.0f) + } + if (o->oDistanceToMario > 1100.0f) { o->oAction = 0; + } small_penguin_dive_with_mario(); } void small_penguin_act_3(void) { if (o->oTimer > 5) { - if (o->oTimer == 6) + if (o->oTimer == 6) { cur_obj_play_sound_2(SOUND_OBJ_BABY_PENGUIN_DIVE); + } cur_obj_init_animation_with_sound(1); - if (o->oTimer > 25) - if (!mario_is_dive_sliding()) - o->oAction = 4; + if (o->oTimer > 25 && !mario_is_dive_sliding()) { + o->oAction = 4; + } } } @@ -190,63 +217,78 @@ void small_penguin_act_4(void) { if (o->oTimer > 20) { o->oForwardVel = 0.0f; cur_obj_init_animation_with_sound(2); - if (o->oTimer > 40) + if (o->oTimer > 40) { o->oAction = o->oSmallPenguinUnk100; + } } } void small_penguin_act_0(void) { - s32 sp1C; + s32 sp1C = FALSE; - sp1C = 0; cur_obj_init_animation_with_sound(3); if (o->oTimer == 0) { o->oSmallPenguinUnk110 = (s32)(random_float() * 0x400); o->oSmallPenguinUnk108 = random_float() * 100.0f; o->oSmallPenguinUnk104 = random_float(); o->oForwardVel = 0.0f; - if (cur_obj_dist_to_nearest_object_with_behavior(bhvTuxiesMother) < 1000.0f) - sp1C = 1; + if (cur_obj_dist_to_nearest_object_with_behavior(bhvTuxiesMother) < 1000.0f) { + sp1C = TRUE; + } } - if (o->oDistanceToMario < 1000.0f && o->oSmallPenguinUnk108 + 600.0f < o->oDistanceToMario) + if (o->oDistanceToMario < 1000.0f && o->oDistanceToMario > o->oSmallPenguinUnk108 + 600.0f) { o->oAction = 1; - else if (o->oDistanceToMario < o->oSmallPenguinUnk108 + 300.0f) + } else if (o->oDistanceToMario < o->oSmallPenguinUnk108 + 300.0f) { o->oAction = 2; - if (sp1C) + } + if (sp1C) { o->oAction = 5; - if (cur_obj_mario_far_away()) + } + if (cur_obj_mario_far_away()) { cur_obj_set_pos_to_home(); + } } void small_penguin_act_5(void) { f32 sp24; s16 sp22; struct Object *sp1C = cur_obj_nearest_object_with_behavior(bhvTuxiesMother); + if (sp1C != NULL) { - if (o->oDistanceToMario < 1000.0f) + if (o->oDistanceToMario < 1000.0f) { o->oForwardVel = 2.0f; - else + } else { o->oForwardVel = 0.0f; + } + sp24 = dist_between_objects(o, sp1C); sp22 = obj_angle_to_object(o, sp1C); - if (sp24 > 200.0f) + + if (sp24 > 200.0f) { cur_obj_rotate_yaw_toward(sp22, 0x400); - else + } else { cur_obj_rotate_yaw_toward(sp22 + 0x8000, 0x400); + } + cur_obj_init_animation_with_sound(0); } + small_penguin_dive_with_mario(); } void (*sSmallPenguinActions[])(void) = { - small_penguin_act_0, small_penguin_act_1, small_penguin_act_2, - small_penguin_act_3, small_penguin_act_4, small_penguin_act_5 + small_penguin_act_0, + small_penguin_act_1, + small_penguin_act_2, + small_penguin_act_3, + small_penguin_act_4, + small_penguin_act_5, }; void small_penguin_free_actions(void) { - if (o->oSmallPenguinUnk88 != 0) { + if (o->oSmallPenguinUnk88) { o->oAction = 5; - o->oSmallPenguinUnk88 = 0; + o->oSmallPenguinUnk88 = FALSE; } cur_obj_update_floor_and_walls(); cur_obj_call_action_function(sSmallPenguinActions); @@ -260,16 +302,18 @@ void bhv_small_penguin_loop(void) { small_penguin_free_actions(); break; case HELD_HELD: - cur_obj_unrender_and_reset_state(0, 0); - if (cur_obj_has_behavior(bhvPenguinBaby)) + cur_obj_unrender_set_action_and_anim(0, 0); + if (cur_obj_has_behavior(bhvPenguinBaby)) { obj_set_behavior(o, bhvSmallPenguin); + } obj_copy_pos(o, gMarioObject); - if (gGlobalTimer % 30 == 0) + if (gGlobalTimer % 30 == 0) { #ifndef VERSION_JP play_sound(SOUND_OBJ2_BABY_PENGUIN_YELL, gMarioObject->header.gfx.cameraToObject); #else play_sound(SOUND_OBJ2_BABY_PENGUIN_YELL, o->header.gfx.cameraToObject); #endif + } break; case HELD_THROWN: cur_obj_get_thrown_or_placed(0, 0, 0); @@ -284,33 +328,34 @@ void bhv_small_penguin_loop(void) { * 4 is unused, and is the eye state seen in Shoshinkai 1995 footage. */ Gfx *geo_switch_tuxie_mother_eyes(s32 run, struct GraphNode *node, UNUSED Mat4 *mtx) { - struct Object *obj; - struct GraphNodeSwitchCase *switchCase; - s32 timer; - if (run == TRUE) { - obj = (struct Object *) gCurGraphNodeObject; - switchCase = (struct GraphNodeSwitchCase *) node; + struct Object *obj = (struct Object *) gCurGraphNodeObject; + struct GraphNodeSwitchCase *switchCase = (struct GraphNodeSwitchCase *) node; + s32 timer; + switchCase->selectedCase = 0; // timer logic for blinking. uses cases 0-2. timer = gGlobalTimer % 50; - if (timer < 43) + if (timer < 43) { switchCase->selectedCase = 0; - else if (timer < 45) + } else if (timer < 45) { switchCase->selectedCase = 1; - else if (timer < 47) + } else if (timer < 47) { switchCase->selectedCase = 2; - else + } else { switchCase->selectedCase = 1; + } /** make Tuxie's Mother have angry eyes if Mario takes the correct baby * after giving it back. The easiest way to check this is to see if she's * moving, since she only does when she's chasing Mario. */ - if (segmented_to_virtual(bhvTuxiesMother) == obj->behavior) - if (obj->oForwardVel > 5.0f) + if (obj->behavior == segmented_to_virtual(bhvTuxiesMother)) { + if (obj->oForwardVel > 5.0f) { switchCase->selectedCase = 3; + } + } } return NULL; } diff --git a/src/game/behaviors/tweester.inc.c b/src/game/behaviors/tweester.inc.c index 67ad5f2d..8bd28c63 100644 --- a/src/game/behaviors/tweester.inc.c +++ b/src/game/behaviors/tweester.inc.c @@ -1,3 +1,4 @@ + /** * Behavior file for bhvTweester and bhvTweesterSandParticle * Tweester swaps between twhree action- an idle action, a chasing @@ -25,11 +26,11 @@ void tweester_scale_and_move(f32 preScale) { s16 dYaw = 0x2C00; f32 scale = preScale * 0.4; - o->header.gfx.scale[0] + o->header.gfx.scale[0] = (( coss(o->oTweesterScaleTimer) + 1.0) * 0.5 * 0.3 + 1.0) * scale; - o->header.gfx.scale[1] + o->header.gfx.scale[1] = ((-coss(o->oTweesterScaleTimer) + 1.0) * 0.5 * 0.5 + 0.5) * scale; - o->header.gfx.scale[2] + o->header.gfx.scale[2] = (( coss(o->oTweesterScaleTimer) + 1.0) * 0.5 * 0.3 + 1.0) * scale; o->oTweesterScaleTimer += 0x200; @@ -46,21 +47,23 @@ void tweester_act_idle(void) { if (o->oSubAction == TWEESTER_SUB_ACT_WAIT) { cur_obj_become_tangible(); cur_obj_set_pos_to_home(); - cur_obj_scale(0); + cur_obj_scale(0.0f); // Hard to have any idea of this purpose, only set here. o->oTweesterUnused = 0; // If Mario is within range, change to the growth sub-action. - if (o->oDistanceToMario < 1500.0f) + if (o->oDistanceToMario < 1500.0f) { o->oSubAction++; + } o->oTimer = 0; } else { cur_obj_play_sound_1(SOUND_ENV_WIND1); tweester_scale_and_move(o->oTimer / 60.0f); - if (o->oTimer > 59) + if (o->oTimer >= 60) { o->oAction = TWEESTER_ACT_CHASE; + } } } @@ -81,22 +84,26 @@ void tweester_act_chase(void) { cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x200); print_debug_top_down_objectinfo("off ", 0); - if (gMarioStates[0].action == ACT_TWIRLING) + if (gMarioStates[0].action == ACT_TWIRLING) { o->oSubAction++; + } } else { o->oForwardVel = 20.0f; cur_obj_rotate_yaw_toward(o->oAngleToHome, 0x200); - if (cur_obj_lateral_dist_to_home() < 200.0f) + if (cur_obj_lateral_dist_to_home() < 200.0f) { o->oAction = TWEESTER_ACT_HIDE; + } } - if (o->oDistanceToMario > 3000.0f) + if (o->oDistanceToMario > 3000.0f) { o->oAction = TWEESTER_ACT_HIDE; + } cur_obj_update_floor_and_walls(); - if (o->oMoveFlags & OBJ_MOVE_HIT_WALL) + if (o->oMoveFlags & OBJ_MOVE_HIT_WALL) { o->oMoveAngleYaw = o->oWallAngle; + } cur_obj_move_standard(60); tweester_scale_and_move(1.0f); @@ -110,19 +117,25 @@ void tweester_act_chase(void) { void tweester_act_hide(void) { f32 shrinkTimer = 60.0f - o->oTimer; - if (shrinkTimer >= 0.0f) + if (shrinkTimer >= 0.0f) { tweester_scale_and_move(shrinkTimer / 60.0f); - else { + } else { cur_obj_become_intangible(); - if (cur_obj_lateral_dist_from_mario_to_home() > 2500.0f) + if (cur_obj_lateral_dist_from_mario_to_home() > 2500.0f) { o->oAction = TWEESTER_ACT_IDLE; - if (o->oTimer > 360) + } + if (o->oTimer > 360) { o->oAction = TWEESTER_ACT_IDLE; + } } } // Array of Tweester action functions. -void (*sTweesterActions[])(void) = { tweester_act_idle, tweester_act_chase, tweester_act_hide }; +void (*sTweesterActions[])(void) = { + tweester_act_idle, + tweester_act_chase, + tweester_act_hide, +}; /** * Loop behavior for Tweester. @@ -151,6 +164,7 @@ void bhv_tweester_sand_particle_loop(void) { o->oFaceAngleYaw = random_u16(); } - if (o->oTimer > 15) + if (o->oTimer > 15) { obj_mark_for_deletion(o); + } } diff --git a/src/game/behaviors/ukiki.inc.c b/src/game/behaviors/ukiki.inc.c index 2e6ce836..ffc3e2d5 100644 --- a/src/game/behaviors/ukiki.inc.c +++ b/src/game/behaviors/ukiki.inc.c @@ -1,4 +1,3 @@ -// ukiki.c.inc /** * @file Contains behavior for the ukiki objects. @@ -27,10 +26,9 @@ void handle_cap_ukiki_reset(void) { * the cap ukiki. */ s32 is_cap_ukiki_and_mario_has_normal_cap_on_head(void) { - if (o->oBehParams2ndByte == UKIKI_CAP) { - if (does_mario_have_normal_cap_on_head(gMarioState)) { - return TRUE; - } + if (o->oBehParams2ndByte == UKIKI_CAP + && does_mario_have_normal_cap_on_head(gMarioState)) { + return TRUE; } return FALSE; @@ -41,11 +39,10 @@ s32 is_cap_ukiki_and_mario_has_normal_cap_on_head(void) { */ Gfx *geo_update_projectile_pos_from_parent_copy(s32 run,UNUSED struct GraphNode *node, Mat4 mtx) { Mat4 mtx2; - struct Object* obj; if (run == TRUE) { // TODO: change global type to Object pointer - obj = (struct Object*)gCurGraphNodeObject; + struct Object *obj = (struct Object *) gCurGraphNodeObject; if (obj->prevObj != NULL) { create_transformation_from_matrices(mtx2, mtx, *gCurGraphNodeCamera->matrixPtr); @@ -74,7 +71,7 @@ void idle_ukiki_taunt(void) { } // Switch goes from 1-4. - switch(o->oSubAction) { + switch (o->oSubAction) { case UKIKI_SUB_ACT_TAUNT_ITCH: cur_obj_init_animation_with_sound(UKIKI_ANIM_ITCH); @@ -127,8 +124,8 @@ void ukiki_act_idle(void) { if (is_cap_ukiki_and_mario_has_normal_cap_on_head()) { if (o->oDistanceToMario > 700.0f && o->oDistanceToMario < 1000.0f) { o->oAction = UKIKI_ACT_RUN; - } else if (o->oDistanceToMario <= 700.0f && 200.0f < o->oDistanceToMario) { - if (abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw) > 0x1000) { + } else if (o->oDistanceToMario <= 700.0f && o->oDistanceToMario > 200.0f) { + if (abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw) > 0x1000) { o->oAction = UKIKI_ACT_TURN_TO_MARIO; } } @@ -174,7 +171,7 @@ void ukiki_act_idle(void) { * Only used for the cap ukiki. */ void ukiki_act_return_home(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; cur_obj_init_animation_with_sound(UKIKI_ANIM_RUN); o->oMoveAngleYaw = cur_obj_angle_to_home(); @@ -232,7 +229,7 @@ void ukiki_act_turn_to_mario(void) { o->oAction = UKIKI_ACT_IDLE; } - if (is_cap_ukiki_and_mario_has_normal_cap_on_head()){ + if (is_cap_ukiki_and_mario_has_normal_cap_on_head()) { if (o->oDistanceToMario > 500.0f) { o->oAction = UKIKI_ACT_RUN; } @@ -272,18 +269,15 @@ void ukiki_act_run(void) { o->oAction = UKIKI_ACT_TURN_TO_MARIO; } - if (fleeMario) { - if (o->oDistanceToMario < 200.0f) { - if((o->oMoveFlags & OBJ_MOVE_HIT_WALL) && - is_mario_moving_fast_or_in_air(10)) { - o->oAction = UKIKI_ACT_JUMP; - o->oMoveAngleYaw = o->oWallAngle; - } else if((o->oMoveFlags & OBJ_MOVE_HIT_EDGE)) { - if (is_mario_moving_fast_or_in_air(10)) { - o->oAction = UKIKI_ACT_JUMP; - o->oMoveAngleYaw += 0x8000; - } - } + if (fleeMario && o->oDistanceToMario < 200.0f) { + if ((o->oMoveFlags & OBJ_MOVE_HIT_WALL) + && is_mario_moving_fast_or_in_air(10)) { + o->oAction = UKIKI_ACT_JUMP; + o->oMoveAngleYaw = o->oWallAngle; + } else if ((o->oMoveFlags & OBJ_MOVE_HIT_EDGE) + && is_mario_moving_fast_or_in_air(10)) { + o->oAction = UKIKI_ACT_JUMP; + o->oMoveAngleYaw += 0x8000; } } } @@ -300,7 +294,7 @@ void ukiki_act_jump(void) { if (o->oTimer == 0) { cur_obj_set_y_vel_and_animation(random_float() * 10.0f + 45.0f, UKIKI_ANIM_JUMP); } else if (o->oMoveFlags & (OBJ_MOVE_MASK_ON_GROUND | OBJ_MOVE_AT_WATER_SURFACE - | OBJ_MOVE_UNDERWATER_ON_GROUND)) { + | OBJ_MOVE_UNDERWATER_ON_GROUND)) { o->oSubAction++; o->oVelY = 0.0f; } @@ -338,7 +332,7 @@ static Trajectory sCageUkikiPath[] = { * our death. Ukiki is a tad suicidal. */ void ukiki_act_go_to_cage(void) { - struct Object* obj; + struct Object *obj; f32 latDistToCage = 0.0f; s16 yawToCage = 0; obj = cur_obj_nearest_object_with_behavior(bhvUkikiCageChild); @@ -354,7 +348,7 @@ void ukiki_act_go_to_cage(void) { o->oFlags |= OBJ_FLAG_ACTIVE_FROM_AFAR; // Switch goes from 0-7 in order. - switch(o->oSubAction) { + switch (o->oSubAction) { case UKIKI_SUB_ACT_CAGE_RUN_TO_CAGE: cur_obj_init_animation_with_sound(UKIKI_ANIM_RUN); @@ -377,13 +371,14 @@ void ukiki_act_go_to_cage(void) { if (cur_obj_can_mario_activate_textbox(200.0f, 30.0f, 0x7FFF)) { o->oSubAction++; // fallthrough } else { - break; + break; } case UKIKI_SUB_ACT_CAGE_TALK_TO_MARIO: cur_obj_init_animation_with_sound(UKIKI_ANIM_HANDSTAND); - if (cur_obj_update_dialog_with_cutscene(3, 1, CUTSCENE_DIALOG, DIALOG_080)) { + if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_DOWN, + DIALOG_FLAG_TURN_TO_MARIO, CUTSCENE_DIALOG, DIALOG_080)) { o->oSubAction++; } break; @@ -490,7 +485,7 @@ void ukiki_free_loop(void) { cur_obj_move_standard(steepSlopeAngleDegrees); handle_cap_ukiki_reset(); - if(!(o->oMoveFlags & OBJ_MOVE_MASK_IN_WATER)) { + if (!(o->oMoveFlags & OBJ_MOVE_MASK_IN_WATER)) { exec_anim_sound_state(sUkikiSoundStates); } } @@ -501,7 +496,7 @@ void ukiki_free_loop(void) { * * Possibly unused so AnimState could be used for wearing a cap? */ -static void ukiki_blink_timer(void) { +UNUSED static void ukiki_blink_timer(void) { if (gGlobalTimer % 50 < 7) { o->oAnimState = UKIKI_ANIM_STATE_EYE_CLOSED; } else { @@ -514,18 +509,18 @@ static void ukiki_blink_timer(void) { */ void cage_ukiki_held_loop(void) { if (o->oPosY - o->oHomeY > -100.0f) { - switch(o->oUkikiTextState) { + switch (o->oUkikiTextState) { case UKIKI_TEXT_DEFAULT: - if (set_mario_npc_dialog(2) == 2) { + if (set_mario_npc_dialog(MARIO_DIALOG_LOOK_UP) == MARIO_DIALOG_STATUS_SPEAK) { create_dialog_box_with_response(DIALOG_079); o->oUkikiTextState = UKIKI_TEXT_CAGE_TEXTBOX; } break; case UKIKI_TEXT_CAGE_TEXTBOX: - if (gDialogResponse != 0) { - set_mario_npc_dialog(0); - if (gDialogResponse == 1) { + if (gDialogResponse != DIALOG_RESPONSE_NONE) { + set_mario_npc_dialog(MARIO_DIALOG_STOP); + if (gDialogResponse == DIALOG_RESPONSE_YES) { o->oInteractionSubtype |= INT_SUBTYPE_DROP_IMMEDIATELY; o->oUkikiTextState = UKIKI_TEXT_GO_TO_CAGE; } else { @@ -558,16 +553,17 @@ void cage_ukiki_held_loop(void) { * Called by the main behavior function for the cap ukiki whenever it is held. */ void cap_ukiki_held_loop(void) { - switch(o->oUkikiTextState) { + switch (o->oUkikiTextState) { case UKIKI_TEXT_DEFAULT: if (mario_lose_cap_to_enemy(2)) { o->oUkikiTextState = UKIKI_TEXT_STEAL_CAP; o->oUkikiHasCap |= UKIKI_CAP_ON; - } else {} + } else { + } break; case UKIKI_TEXT_STEAL_CAP: - if (cur_obj_update_dialog(2, 2, DIALOG_100, 0)) { + if (cur_obj_update_dialog(MARIO_DIALOG_LOOK_UP, DIALOG_FLAG_TEXT_DEFAULT, DIALOG_100, 0)) { o->oInteractionSubtype |= INT_SUBTYPE_DROP_IMMEDIATELY; o->oUkikiTextState = UKIKI_TEXT_STOLE_CAP; } @@ -577,9 +573,10 @@ void cap_ukiki_held_loop(void) { break; case UKIKI_TEXT_HAS_CAP: - if (cur_obj_update_dialog(2, 18, DIALOG_101, 0)) { + if (cur_obj_update_dialog(MARIO_DIALOG_LOOK_UP, + (DIALOG_FLAG_TEXT_DEFAULT | DIALOG_FLAG_TIME_STOP_ENABLED), DIALOG_101, 0)) { mario_retrieve_cap(); - set_mario_npc_dialog(0); + set_mario_npc_dialog(MARIO_DIALOG_STOP); o->oUkikiHasCap &= ~UKIKI_CAP_ON; o->oUkikiTextState = UKIKI_TEXT_GAVE_CAP_BACK; } @@ -596,11 +593,10 @@ void cap_ukiki_held_loop(void) { * Initializatation for ukiki, determines if it has Mario's cap. */ void bhv_ukiki_init(void) { - if (o->oBehParams2ndByte == UKIKI_CAP) { - if (save_file_get_flags() & SAVE_FLAG_CAP_ON_UKIKI) { - o->oUkikiTextState = UKIKI_TEXT_HAS_CAP; - o->oUkikiHasCap |= UKIKI_CAP_ON; - } + if ((o->oBehParams2ndByte == UKIKI_CAP) + && (save_file_get_flags() & SAVE_FLAG_CAP_ON_UKIKI)) { + o->oUkikiTextState = UKIKI_TEXT_HAS_CAP; + o->oUkikiHasCap |= UKIKI_CAP_ON; } } @@ -609,7 +605,7 @@ void bhv_ukiki_init(void) { * dependent on the held state and whick ukiki it is (cage or cap). */ void bhv_ukiki_loop(void) { - switch(o->oHeldState) { + switch (o->oHeldState) { case HELD_FREE: //! @bug (PARTIAL_UPDATE) o->oUkikiTextboxTimer = 0; @@ -617,7 +613,7 @@ void bhv_ukiki_loop(void) { break; case HELD_HELD: - cur_obj_unrender_and_reset_state(UKIKI_ANIM_HELD, 0); + cur_obj_unrender_set_action_and_anim(UKIKI_ANIM_HELD, 0); obj_copy_pos(o, gMarioObject); if (o->oBehParams2ndByte == UKIKI_CAP) { @@ -640,6 +636,7 @@ void bhv_ukiki_loop(void) { } o->oInteractStatus = 0; + print_debug_bottom_up("mode %d\n", o->oAction); print_debug_bottom_up("action %d\n", o->oHeldState); } diff --git a/src/game/behaviors/ukiki_cage.inc.c b/src/game/behaviors/ukiki_cage.inc.c index 68a64e8a..206268d1 100644 --- a/src/game/behaviors/ukiki_cage.inc.c +++ b/src/game/behaviors/ukiki_cage.inc.c @@ -1,4 +1,3 @@ -// ukiki_cage.c.inc /** * @file Contains behavior for the ukiki's cage @@ -20,9 +19,9 @@ void bhv_ukiki_cage_star_loop(void) { // Initialization to see if the star is collected (blue) or not (yellow). if (o->oTimer == 0) { if (bit_shift_left(1) - & save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1)) { - cur_obj_set_model(MODEL_TRANSPARENT_STAR); - } + & save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum))) { + cur_obj_set_model(MODEL_TRANSPARENT_STAR); + } } obj_copy_pos(o, o->parentObj); @@ -33,10 +32,11 @@ void bhv_ukiki_cage_star_loop(void) { o->oAction++; } break; + case UKIKI_CAGE_STAR_ACT_SPAWN_STAR: obj_mark_for_deletion(o); spawn_mist_particles(); - spawn_triangle_break_particles(20, 138, 0.7, 3); + spawn_triangle_break_particles(20, MODEL_DIRT_ANIMATION, 0.7f, 3); spawn_default_star(2500.0f, -1200.0f, 1300.0f); break; } @@ -94,8 +94,10 @@ void ukiki_cage_act_hide(void) { * An array of the cage's actions. */ void (*sUkikiCageActions[])(void) = { - ukiki_cage_act_wait_for_ukiki, ukiki_cage_act_spin, - ukiki_cage_act_fall, ukiki_cage_act_hide, + ukiki_cage_act_wait_for_ukiki, + ukiki_cage_act_spin, + ukiki_cage_act_fall, + ukiki_cage_act_hide, }; /** diff --git a/src/game/behaviors/unagi.inc.c b/src/game/behaviors/unagi.inc.c index df9041e9..33f37609 100644 --- a/src/game/behaviors/unagi.inc.c +++ b/src/game/behaviors/unagi.inc.c @@ -47,13 +47,11 @@ void unagi_act_1_4(s32 arg0) { if (cur_obj_check_anim_frame(30)) { o->oForwardVel = 40.0f; } - } else { - if (cur_obj_check_if_at_animation_end()) { - if (o->oAction != arg0 && (o->oPathedPrevWaypointFlags & 0xFF) >= 7) { - cur_obj_init_animation_with_sound(3); - } else { - cur_obj_init_animation_with_sound(2); - } + } else if (cur_obj_check_if_at_animation_end()) { + if (o->oAction != arg0 && (o->oPathedPrevWaypointFlags & 0xFF) >= 7) { + cur_obj_init_animation_with_sound(3); + } else { + cur_obj_init_animation_with_sound(2); } } @@ -61,7 +59,7 @@ void unagi_act_1_4(s32 arg0) { cur_obj_play_sound_2(SOUND_GENERAL_MOVING_WATER); } - if (cur_obj_follow_path(0) == -1) { + if (cur_obj_follow_path(0) == PATH_REACHED_END) { o->oAction = arg0; } @@ -140,13 +138,13 @@ void unagi_act_3(void) { } void bhv_unagi_loop(void) { - s32 val04; + s32 i; if (o->oUnagiUnk1B2 == 0) { o->oUnagiUnk1AC = 99999.0f; if (o->oDistanceToMario < 3000.0f) { - for (val04 = -4; val04 < 4; val04++) { - spawn_object_relative(val04, 0, 0, 0, o, MODEL_NONE, bhvUnagiSubobject); + for (i = -4; i < 4; i++) { + spawn_object_relative(i, 0, 0, 0, o, MODEL_NONE, bhvUnagiSubobject); } o->oUnagiUnk1B2 = 1; } @@ -173,12 +171,10 @@ void bhv_unagi_loop(void) { } void bhv_unagi_subobject_loop(void) { - f32 val04; - if (o->parentObj->oUnagiUnk1B2 == 0) { obj_mark_for_deletion(o); } else { - val04 = 300.0f * o->oBehParams2ndByte; + f32 val04 = 300.0f * o->oBehParams2ndByte; o->oPosY = o->parentObj->oPosY - val04 * sins(o->parentObj->oFaceAnglePitch) * 1.13f; diff --git a/src/game/behaviors/unused_particle_spawn.inc.c b/src/game/behaviors/unused_particle_spawn.inc.c index 2e22855d..0370e2da 100644 --- a/src/game/behaviors/unused_particle_spawn.inc.c +++ b/src/game/behaviors/unused_particle_spawn.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvUnusedParticleSpawn. * diff --git a/src/game/behaviors/unused_poundable_platform.inc.c b/src/game/behaviors/unused_poundable_platform.inc.c index 23816905..f4c96442 100644 --- a/src/game/behaviors/unused_poundable_platform.inc.c +++ b/src/game/behaviors/unused_poundable_platform.inc.c @@ -1,3 +1,4 @@ + /** * Behavior for bhvUnusedPoundablePlatform. * @@ -18,11 +19,12 @@ void bhv_unused_poundable_platform(void) { if (o->oAction == 0) { if (cur_obj_is_mario_ground_pounding_platform()) { spawn_mist_particles(); - spawn_triangle_break_particles(20, 56, 3.0f, 0); + spawn_triangle_break_particles(20, MODEL_SL_CRACKED_ICE_CHUNK, 3.0f, 0); o->oAction++; } } else if (o->oTimer > 7) { obj_mark_for_deletion(o); } + load_object_collision_model(); } diff --git a/src/game/behaviors/warp.inc.c b/src/game/behaviors/warp.inc.c index 107af849..0e910186 100644 --- a/src/game/behaviors/warp.inc.c +++ b/src/game/behaviors/warp.inc.c @@ -1,32 +1,36 @@ -// warp.c.inc +// warp.inc.c void bhv_warp_loop(void) { - u16 sp6; if (o->oTimer == 0) { - sp6 = (o->oBehParams >> 24) & 0xFF; - if (sp6 == 0) + u16 sp6 = (o->oBehParams >> 24) & 0xFF; + + if (sp6 == 0) { o->hitboxRadius = 50.0f; - else if (sp6 == 0xFF) + } else if (sp6 == 0xFF) { o->hitboxRadius = 10000.0f; - else + } else { o->hitboxRadius = sp6 * 10.0; + } o->hitboxHeight = 50.0f; } + o->oInteractStatus = 0; } -void bhv_fading_warp_loop() // identical to the above function except for o->hitboxRadius -{ - u16 sp6; +// identical to the above function except for o->hitboxRadius +void bhv_fading_warp_loop() { if (o->oTimer == 0) { - sp6 = (o->oBehParams >> 24) & 0xFF; - if (sp6 == 0) + u16 sp6 = (o->oBehParams >> 24) & 0xFF; + + if (sp6 == 0) { o->hitboxRadius = 85.0f; - else if (sp6 == 0xFF) + } else if (sp6 == 0xFF) { o->hitboxRadius = 10000.0f; - else + } else { o->hitboxRadius = sp6 * 10.0; + } o->hitboxHeight = 50.0f; } + o->oInteractStatus = 0; } diff --git a/src/game/behaviors/water_bomb.inc.c b/src/game/behaviors/water_bomb.inc.c index 41333803..889ca462 100644 --- a/src/game/behaviors/water_bomb.inc.c +++ b/src/game/behaviors/water_bomb.inc.c @@ -30,16 +30,15 @@ static struct ObjectHitbox sWaterBombHitbox = { */ void bhv_water_bomb_spawner_update(void) { f32 latDistToMario; - f32 spawnerRadius; + f32 spawnerRadius = 50 * (u16)(o->oBehParams >> 16) + 200.0f; - spawnerRadius = 50 * (u16)(o->oBehParams >> 16) + 200.0f; latDistToMario = lateral_dist_between_objects(o, gMarioObject); // When mario is in range and a water bomb isn't already active if (!o->oWaterBombSpawnerBombActive && latDistToMario < spawnerRadius && gMarioObject->oPosY - o->oPosY < 1000.0f) { if (o->oWaterBombSpawnerTimeToSpawn != 0) { - o->oWaterBombSpawnerTimeToSpawn -= 1; + o->oWaterBombSpawnerTimeToSpawn--; } else { struct Object *waterBomb = spawn_object_relative(0, 0, 2000, 0, o, MODEL_WATER_BOMB, bhvWaterBomb); @@ -68,7 +67,7 @@ void bhv_water_bomb_spawner_update(void) { * Spawn particles when the water bomb explodes. */ void water_bomb_spawn_explode_particles(s8 offsetY, s8 forwardVelRange, s8 velYBase) { - static struct SpawnParticlesInfo sWaterBombExplodeParticles = { + static struct SpawnParticlesInfo waterBombExplodeParticles = { /* behParam: */ 0, /* count: */ 5, /* model: */ MODEL_BUBBLE, @@ -83,10 +82,11 @@ void water_bomb_spawn_explode_particles(s8 offsetY, s8 forwardVelRange, s8 velYB /* sizeRange: */ 10.0f, }; - sWaterBombExplodeParticles.offsetY = offsetY; - sWaterBombExplodeParticles.forwardVelRange = forwardVelRange; - sWaterBombExplodeParticles.velYBase = velYBase; - cur_obj_spawn_particles(&sWaterBombExplodeParticles); + waterBombExplodeParticles.offsetY = offsetY; + waterBombExplodeParticles.forwardVelRange = forwardVelRange; + waterBombExplodeParticles.velYBase = velYBase; + + cur_obj_spawn_particles(&waterBombExplodeParticles); } /** @@ -175,8 +175,7 @@ static void water_bomb_act_explode(void) { * Despawn after 100 frames. */ static void water_bomb_act_shot_from_cannon(void) { - - static struct SpawnParticlesInfo sWaterBombCannonParticle = { + static struct SpawnParticlesInfo waterBombCannonParticle = { /* behParam: */ 0, /* count: */ 1, /* model: */ MODEL_BUBBLE, @@ -198,7 +197,7 @@ static void water_bomb_act_shot_from_cannon(void) { if (o->oTimer == 1) { water_bomb_spawn_explode_particles(-20, 10, 30); } - cur_obj_spawn_particles(&sWaterBombCannonParticle); + cur_obj_spawn_particles(&waterBombCannonParticle); } if (o->header.gfx.scale[1] > 1.2f) { diff --git a/src/game/behaviors/water_bomb_cannon.inc.c b/src/game/behaviors/water_bomb_cannon.inc.c index 8e9ba33b..a2134821 100644 --- a/src/game/behaviors/water_bomb_cannon.inc.c +++ b/src/game/behaviors/water_bomb_cannon.inc.c @@ -1,8 +1,6 @@ // water_bomb_cannon.inc.c void bhv_bubble_cannon_barrel_loop(void) { - struct Object *val04; - if (o->parentObj->oAction == 2) { obj_mark_for_deletion(o); } else { @@ -20,12 +18,14 @@ void bhv_bubble_cannon_barrel_loop(void) { // check this if (o->parentObj->oWaterCannonUnkF4 != 0) { if (o->oForwardVel == 0.0f) { + struct Object *waterBomb; + o->oForwardVel = 35.0f; - val04 = spawn_object(o, MODEL_WATER_BOMB, bhvWaterBomb); - if (val04 != NULL) { - val04->oForwardVel = -100.0f; - val04->header.gfx.scale[1] = 1.7f; + waterBomb = spawn_object(o, MODEL_WATER_BOMB, bhvWaterBomb); + if (waterBomb != NULL) { + waterBomb->oForwardVel = -100.0f; + waterBomb->header.gfx.scale[1] = 1.7f; } set_camera_shake_from_point(SHAKE_POS_MEDIUM, o->oPosX, o->oPosY, o->oPosZ); @@ -52,18 +52,18 @@ void water_bomb_cannon_act_1(void) { o->oAction = 2; } else if (o->oBehParams2ndByte == 0) { if (o->oWaterCannonUnkF4 != 0) { - o->oWaterCannonUnkF4 -= 1; + o->oWaterCannonUnkF4--; } else { obj_move_pitch_approach(o->oWaterCannonUnkFC, 0x80); obj_face_yaw_approach(o->oWaterCannonUnk100, 0x100); if ((s16) o->oFaceAngleYaw == (s16) o->oWaterCannonUnk100) { if (o->oWaterCannonUnkF8 != 0) { - o->oWaterCannonUnkF8 -= 1; + o->oWaterCannonUnkF8--; } else { cur_obj_play_sound_2(SOUND_OBJ_CANNON4); o->oWaterCannonUnkF4 = 70; - o->oWaterCannonUnkFC = 0x1000 + 0x400 * (random_u16() & 0x3); + o->oWaterCannonUnkFC = 0x1000 + 0x400 * (random_u16() & 0x03); o->oWaterCannonUnk100 = -0x2000 + o->oMoveAngleYaw + 0x1000 * (random_u16() % 5); o->oWaterCannonUnkF8 = 60; } diff --git a/src/game/behaviors/water_mist.inc.c b/src/game/behaviors/water_mist.inc.c index 64d25c77..a11fd24a 100644 --- a/src/game/behaviors/water_mist.inc.c +++ b/src/game/behaviors/water_mist.inc.c @@ -1,4 +1,4 @@ -// water_mist.c.inc +// water_mist.inc.c // TODO: there is confusion with the earlier mist file. Clarify? void bhv_water_mist_2_loop(void) { diff --git a/src/game/behaviors/water_mist_particle.inc.c b/src/game/behaviors/water_mist_particle.inc.c index cb9243ae..d3b10ddf 100644 --- a/src/game/behaviors/water_mist_particle.inc.c +++ b/src/game/behaviors/water_mist_particle.inc.c @@ -1,21 +1,25 @@ -// water_mist_particle.c.inc +// water_mist_particle.inc.c // TODO: Is this really "mist"? void bhv_water_mist_spawn_loop(void) { - clear_particle_flags(0x20000); + clear_particle_flags(ACTIVE_PARTICLE_BREATH); spawn_object(o, MODEL_MIST, bhvWaterMist); } void bhv_water_mist_loop(void) { - f32 sp1C; + f32 scale; + if (o->oTimer == 0) { o->oMoveAngleYaw = gMarioObject->oMoveAngleYaw; obj_translate_xz_random(o, 10.0f); } + cur_obj_move_using_fvel_and_gravity(); o->oOpacity -= 42; - sp1C = (254 - o->oOpacity) / 254.0 * 1.0 + 0.5; // seen this before - cur_obj_scale(sp1C); - if (o->oOpacity < 2) + scale = (254 - o->oOpacity) / 254.0 * 1.0 + 0.5; // seen this before + cur_obj_scale(scale); + + if (o->oOpacity < 2) { obj_mark_for_deletion(o); + } } diff --git a/src/game/behaviors/water_objs.inc.c b/src/game/behaviors/water_objs.inc.c index e907e93e..67128100 100644 --- a/src/game/behaviors/water_objs.inc.c +++ b/src/game/behaviors/water_objs.inc.c @@ -1,4 +1,4 @@ -// water_objs.c.inc +// water_objs.inc.c // TODO: Better name, please void bhv_water_air_bubble_init(void) { @@ -9,9 +9,11 @@ void bhv_water_air_bubble_init(void) { void bhv_water_air_bubble_loop(void) { s32 i; + o->header.gfx.scale[0] = sins(o->oWaterObjUnkF4) * 0.5 + 4.0; o->header.gfx.scale[1] = -sins(o->oWaterObjUnkF4) * 0.5 + 4.0; o->oWaterObjUnkF4 += 0x400; + if (o->oTimer < 30) { cur_obj_become_intangible(); o->oPosY += 3.0f; @@ -21,16 +23,22 @@ void bhv_water_air_bubble_loop(void) { o->oMoveAngleYaw = obj_angle_to_object(o, gMarioObject); cur_obj_move_using_fvel_and_gravity(); } + o->oPosX += random_float() * 4.0f - 2.0f; o->oPosZ += random_float() * 4.0f - 2.0f; + if (o->oInteractStatus & INT_STATUS_INTERACTED || o->oTimer > 200) { cur_obj_play_sound_2(SOUND_GENERAL_QUIET_BUBBLE); obj_mark_for_deletion(o); - for (i = 0; i < 30; i++) + for (i = 0; i < 30; i++) { spawn_object(o, MODEL_BUBBLE, bhvBubbleMaybe); + } } - if (find_water_level(o->oPosX, o->oPosZ) < o->oPosY) + + if (find_water_level(o->oPosX, o->oPosZ) < o->oPosY) { obj_mark_for_deletion(o); + } + o->oInteractStatus = 0; } @@ -48,6 +56,7 @@ void bhv_bubble_maybe_loop(void) { o->oPosY += random_float() * 3.0f + 6.0f; o->oPosX += random_float() * 10.0f - 5.0f; o->oPosZ += random_float() * 10.0f - 5.0f; + o->header.gfx.scale[0] = sins(o->oWaterObjUnkF4) * 0.2 + 1.0; o->oWaterObjUnkF4 += o->oWaterObjUnkFC; o->header.gfx.scale[1] = sins(o->oWaterObjUnkF8) * 0.2 + 1.0; @@ -56,18 +65,23 @@ void bhv_bubble_maybe_loop(void) { void bhv_small_water_wave_loop(void) { f32 sp1C = find_water_level(o->oPosX, o->oPosZ); + o->header.gfx.scale[0] = sins(o->oWaterObjUnkF4) * 0.2 + 1.0; o->oWaterObjUnkF4 += o->oWaterObjUnkFC; o->header.gfx.scale[1] = sins(o->oWaterObjUnkF8) * 0.2 + 1.0; o->oWaterObjUnkF8 += o->oWaterObjUnk100; + if (o->oPosY > sp1C) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; o->oPosY += 5.0f; - if (gFreeObjectList.next != NULL) + if (gFreeObjectList.next != NULL) { spawn_object(o, MODEL_SMALL_WATER_SPLASH, bhvObjectWaterSplash); + } } - if (o->oInteractStatus & INT_STATUS_INTERACTED) + + if (o->oInteractStatus & INT_STATUS_INTERACTED) { obj_mark_for_deletion(o); + } } void scale_bubble_sin(void) { @@ -89,7 +103,7 @@ void bhv_particle_loop() { o->oPosY += 5.0f; obj_translate_xz_random(o, 4.0f); scale_bubble_sin(); - if (o->oPosY > sp24 && o->oTimer) { + if (o->oPosY > sp24 && o->oTimer != 0) { obj_mark_for_deletion(o); try_to_spawn_object(5, 0, o, MODEL_SMALL_WATER_SPLASH, bhvObjectWaterSplash); } @@ -102,13 +116,14 @@ void bhv_small_bubbles_loop(void) { } void bhv_fish_group_loop(void) { - if (gMarioCurrentRoom == 15 || gMarioCurrentRoom == 7) - if (gGlobalTimer & 1) - spawn_object(o, MODEL_WHITE_PARTICLE_SMALL, bhvSmallParticleBubbles); + if ((gMarioCurrentRoom == 15 || gMarioCurrentRoom == 7) && (gGlobalTimer & 1)) { + spawn_object(o, MODEL_WHITE_PARTICLE_SMALL, bhvSmallParticleBubbles); + } } void bhv_water_waves_init(void) { - s32 sp1C; - for (sp1C = 0; sp1C < 3; sp1C++) + s32 i; + for (i = 0; i < 3; i++) { spawn_object(o, MODEL_WHITE_PARTICLE_SMALL, bhvSmallParticle); + } } diff --git a/src/game/behaviors/water_pillar.inc.c b/src/game/behaviors/water_pillar.inc.c index 60920c73..2cb9f464 100644 --- a/src/game/behaviors/water_pillar.inc.c +++ b/src/game/behaviors/water_pillar.inc.c @@ -1,7 +1,8 @@ -// water_pillar.c.inc +// water_pillar.inc.c void water_level_pillar_undrained(void) { struct Object *otherWaterPillar; + switch (o->oAction) { case 0: if (cur_obj_is_mario_ground_pounding_platform()) { @@ -9,30 +10,35 @@ void water_level_pillar_undrained(void) { spawn_mist_particles(); } break; + case 1: - if (o->oTimer < 4) + if (o->oTimer < 4) { o->oPosY -= 20.0f; - else + } else { o->oAction++; + } break; + case 2: otherWaterPillar = cur_obj_nearest_object_with_behavior(bhvWaterLevelPillar); if (otherWaterPillar != NULL) { - if (otherWaterPillar->oAction < 2) + if (otherWaterPillar->oAction < 2) { o->oAction++; + } } break; + case 3: otherWaterPillar = cur_obj_nearest_object_with_behavior(bhvWaterLevelPillar); if (otherWaterPillar != NULL) { if (otherWaterPillar->oAction > 1) { o->oAction++; - save_file_set_flags(SAVE_FLAG_MOAT_DRAINED); play_puzzle_jingle(); } } break; + case 4: cur_obj_play_sound_1(SOUND_ENV_WATER_DRAIN); if (o->oTimer < 300) { @@ -40,12 +46,14 @@ void water_level_pillar_undrained(void) { (s32) approach_f32_symmetric(gEnvironmentLevels[2], -2450.0f, 5.0f); gEnvironmentLevels[0] = (s32) approach_f32_symmetric(gEnvironmentLevels[0], -2450.0f, 5.0f); -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers_2(2); #endif - } else + } else { o->oAction++; + } break; + case 5: break; } @@ -60,15 +68,17 @@ void water_level_pillar_drained(void) { } void bhv_water_level_pillar_init(void) { - if (save_file_get_flags() & SAVE_FLAG_MOAT_DRAINED) - o->oWaterLevelPillarDrained = 1; + if (save_file_get_flags() & SAVE_FLAG_MOAT_DRAINED) { + o->oWaterLevelPillarDrained = TRUE; + } } void bhv_water_level_pillar_loop(void) { - if (o->oWaterLevelPillarDrained) + if (o->oWaterLevelPillarDrained) { water_level_pillar_drained(); - else + } else { water_level_pillar_undrained(); + } gEnvironmentRegions[18] = gEnvironmentLevels[2]; gEnvironmentRegions[6] = gEnvironmentLevels[0]; } diff --git a/src/game/behaviors/water_ring.inc.c b/src/game/behaviors/water_ring.inc.c index 68aab7b6..22dcce74 100644 --- a/src/game/behaviors/water_ring.inc.c +++ b/src/game/behaviors/water_ring.inc.c @@ -1,4 +1,4 @@ -// water_ring.c.inc +// water_ring.inc.c f32 water_ring_calc_mario_dist(void) { f32 marioDistX = o->oPosX - gMarioObject->header.gfx.pos[0]; @@ -41,23 +41,20 @@ void bhv_jet_stream_water_ring_init(void) { o->oFaceAnglePitch = 0x8000; } -// sp28 = arg0 -// sp2c = ringManager - void water_ring_check_collection(f32 avgScale, struct Object *ringManager) { f32 marioDistInFront = water_ring_calc_mario_dist(); - struct Object *ringSpawner; if (!is_point_close_to_object(o, gMarioObject->header.gfx.pos[0], - gMarioObject->header.gfx.pos[1] + 80.0f, gMarioObject->header.gfx.pos[2], - (avgScale + 0.2) * 120.0)) { + gMarioObject->header.gfx.pos[1] + 80.0f, + gMarioObject->header.gfx.pos[2], (avgScale + 0.2) * 120.0)) { o->oWaterRingMarioDistInFront = marioDistInFront; return; } - if (o->oWaterRingMarioDistInFront * marioDistInFront < 0) { - ringSpawner = o->parentObj; - if (ringSpawner) { + if (o->oWaterRingMarioDistInFront * marioDistInFront < 0.0f) { + struct Object *ringSpawner = o->parentObj; + + if (ringSpawner != NULL) { if ((o->oWaterRingIndex == ringManager->oWaterRingMgrLastRingCollected + 1) || (ringSpawner->oWaterRingSpawnerRingsCollected == 0)) { ringSpawner->oWaterRingSpawnerRingsCollected++; @@ -67,14 +64,14 @@ void water_ring_check_collection(f32 avgScale, struct Object *ringManager) { play_sound(SOUND_MENU_STAR_SOUND, gGlobalSoundSource); #else play_sound(SOUND_MENU_COLLECT_SECRET - + (((u8) ringSpawner->oWaterRingSpawnerRingsCollected - 1) << 16), + + (((u8) ringSpawner->oWaterRingSpawnerRingsCollected - 1) << 16), gGlobalSoundSource); #endif } - ringManager->oWaterRingMgrLastRingCollected = o->oWaterRingIndex; - } else + } else { ringSpawner->oWaterRingSpawnerRingsCollected = 0; + } } o->oAction = WATER_RING_ACT_COLLECTED; @@ -95,12 +92,14 @@ void water_ring_set_scale(f32 avgScale) { void water_ring_act_collected(void) { f32 avgScale = (f32) o->oTimer * 0.2 + o->oWaterRingAvgScale; - if (o->oTimer >= 21) + if (o->oTimer > 20) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } o->oOpacity -= 10; - if (o->oOpacity < 0) + if (o->oOpacity < 0) { o->oOpacity = 0; + } water_ring_set_scale(avgScale); } @@ -113,10 +112,11 @@ void water_ring_act_not_collected(void) { struct Object *ringSpawner = o->parentObj; struct Object *ringManager = ringSpawner->parentObj; - if (o->oTimer >= 226) { + if (o->oTimer > 225) { o->oOpacity -= 2; - if (o->oOpacity < 3) + if (o->oOpacity < 3) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } } water_ring_check_collection(avgScale, ringManager); @@ -127,8 +127,9 @@ void water_ring_act_not_collected(void) { set_object_visibility(o, 5000); if (ringSpawner->oWaterRingSpawnerRingsCollected == 4 - && o->oWaterRingIndex == ringManager->oWaterRingMgrLastRingCollected + 1) + && o->oWaterRingIndex == ringManager->oWaterRingMgrLastRingCollected + 1) { o->oOpacity = sins(o->oTimer * 0x1000) * 200.0f + 50.0f; + } o->oWaterRingAvgScale = avgScale; } @@ -155,20 +156,22 @@ void water_ring_spawner_act_inactive(void) { // from the Manta Ray, which spawns rings but also has a Ring Manager object as its // parent. The Jet Stream Ring Spawner functions as both a spawner and a Ring Manager. struct Object *currentObj = o->parentObj; - struct Object *waterRing; //! Because the index counter overflows at 10000, it's possible to wait // for about 4 hours and 38 minutes if you miss a ring, and the index will // come around again. - if (o->oTimer == 300) + if (o->oTimer == 300) { o->oTimer = 0; + } + if ((o->oTimer == 0) || (o->oTimer == 50) || (o->oTimer == 150) || (o->oTimer == 200) || (o->oTimer == 250)) { - waterRing = spawn_object(o, MODEL_WATER_RING, bhvJetStreamWaterRing); + struct Object *waterRing = spawn_object(o, MODEL_WATER_RING, bhvJetStreamWaterRing); waterRing->oWaterRingIndex = currentObj->oWaterRingMgrNextRingIndex; currentObj->oWaterRingMgrNextRingIndex++; - if (currentObj->oWaterRingMgrNextRingIndex >= 10001) + if (currentObj->oWaterRingMgrNextRingIndex > 10000) { currentObj->oWaterRingMgrNextRingIndex = 0; + } } } @@ -179,9 +182,7 @@ void bhv_jet_stream_ring_spawner_loop(void) { if (o->oWaterRingSpawnerRingsCollected == 5) { spawn_mist_particles(); - spawn_default_star(3400.0f, -3200.0f, -500.0f); - o->oAction = JS_RING_SPAWNER_ACT_INACTIVE; } break; @@ -197,17 +198,19 @@ void bhv_manta_ray_water_ring_init(void) { } void manta_water_ring_act_not_collected(void) { - f32 avgScale = (f32) o->oTimer / 50.0f * 1.3 + 0.1; + f32 avgScale = (f32) o->oTimer / 50 * 1.3 + 0.1; struct Object *ringSpawner = o->parentObj; struct Object *ringManager = ringSpawner->parentObj; - if (avgScale > 1.3) + if (avgScale > 1.3) { avgScale = 1.3; + } - if (o->oTimer >= 151) { + if (o->oTimer > 150) { o->oOpacity -= 2; - if (o->oOpacity < 3) + if (o->oOpacity < 3) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } } water_ring_check_collection(avgScale, ringManager); @@ -215,8 +218,9 @@ void manta_water_ring_act_not_collected(void) { set_object_visibility(o, 5000); if (ringSpawner->oWaterRingSpawnerRingsCollected == 4 - && o->oWaterRingIndex == ringManager->oWaterRingMgrLastRingCollected + 1) + && o->oWaterRingIndex == ringManager->oWaterRingMgrLastRingCollected + 1) { o->oOpacity = sins(o->oTimer * 0x1000) * 200.0f + 50.0f; + } o->oWaterRingAvgScale = avgScale; } diff --git a/src/game/behaviors/water_splashes_and_waves.inc.c b/src/game/behaviors/water_splashes_and_waves.inc.c index de512d51..89948910 100644 --- a/src/game/behaviors/water_splashes_and_waves.inc.c +++ b/src/game/behaviors/water_splashes_and_waves.inc.c @@ -1,4 +1,4 @@ -// water_splashes_and_waves.c.inc +// water_splashes_and_waves.inc.c // Water droplets from Mario jumping in a pool of water. struct WaterDropletParams sWaterSplashDropletParams = { @@ -48,23 +48,27 @@ struct WaterDropletParams gShallowWaterWaveDropletParams = { void bhv_water_splash_spawn_droplets(void) { s32 i; - if (o->oTimer == 0) + if (o->oTimer == 0) { o->oPosY = find_water_level(o->oPosX, o->oPosZ); + } - if (o->oPosY > FLOOR_LOWER_LIMIT_MISC) // Make sure it is not at the default water level - for (i = 0; i < 3; i++) + if (o->oPosY > FLOOR_LOWER_LIMIT_MISC) { // Make sure it is not at the default water level + for (i = 0; i < 3; i++) { spawn_water_droplet(o, &sWaterSplashDropletParams); + } + } } void bhv_water_droplet_loop(void) { - UNUSED u32 unusedVar; + UNUSED u8 filler[4]; f32 waterLevel = find_water_level(o->oPosX, o->oPosZ); if (o->oTimer == 0) { - if (cur_obj_has_model(MODEL_FISH)) + if (cur_obj_has_model(MODEL_FISH)) { o->header.gfx.node.flags &= ~GRAPH_RENDER_BILLBOARD; - else + } else { o->header.gfx.node.flags |= GRAPH_RENDER_BILLBOARD; + } o->oFaceAngleYaw = random_u16(); } // Apply gravity @@ -76,18 +80,20 @@ void bhv_water_droplet_loop(void) { // Create the smaller splash try_to_spawn_object(0, 1.0f, o, MODEL_SMALL_WATER_SPLASH, bhvWaterDropletSplash); obj_mark_for_deletion(o); - } else if (o->oTimer > 20) + } else if (o->oTimer > 20) { obj_mark_for_deletion(o); + } } - if (waterLevel < FLOOR_LOWER_LIMIT_MISC) + if (waterLevel < FLOOR_LOWER_LIMIT_MISC) { obj_mark_for_deletion(o); + } } void bhv_idle_water_wave_loop(void) { obj_copy_pos(o, gMarioObject); o->oPosY = gMarioStates[0].waterLevel + 5; if (!(gMarioObject->oMarioParticleFlags & ACTIVE_PARTICLE_IDLE_WATER_WAVE)) { - gMarioObject->oActiveParticleFlags &= (u16)~ACTIVE_PARTICLE_IDLE_WATER_WAVE; + gMarioObject->oActiveParticleFlags &= (u16) ~ACTIVE_PARTICLE_IDLE_WATER_WAVE; o->activeFlags = ACTIVE_FLAG_DEACTIVATED; } } @@ -103,11 +109,9 @@ void bhv_bubble_splash_init(void) { } void bhv_shallow_water_splash_init(void) { - struct Object *fishObj; // Have a 1 in 256 chance to spawn the fish particle easter egg. - if ((random_u16() & 0xFF) <= 0) // Strange - { - fishObj = spawn_water_droplet(o, &sWaterDropletFishParams); + if ((random_u16() & 0xFF) <= 0) { // Strange + struct Object *fishObj = spawn_water_droplet(o, &sWaterDropletFishParams); obj_init_animation_with_sound(fishObj, blue_fish_seg3_anims_0301C2B0, 0); } } @@ -115,18 +119,20 @@ void bhv_shallow_water_splash_init(void) { void bhv_wave_trail_shrink(void) { f32 waterLevel = find_water_level(o->oPosX, o->oPosZ); // Destroy every other water wave to space them out (this is a terrible way of doing it) - if (o->oTimer == 0) - if (gGlobalTimer & 1) - obj_mark_for_deletion(o); + if ((o->oTimer == 0) && (gGlobalTimer & 1)) { + obj_mark_for_deletion(o); + } o->oPosY = waterLevel + 5.0f; - if (o->oTimer == 0) + if (o->oTimer == 0) { o->oWaveTrailSize = o->header.gfx.scale[0]; + } if (o->oAnimState > 3) { o->oWaveTrailSize = o->oWaveTrailSize - 0.1; // Shrink the wave - if (o->oWaveTrailSize < 0.0f) + if (o->oWaveTrailSize < 0.0f) { o->oWaveTrailSize = 0.0f; + } o->header.gfx.scale[0] = o->oWaveTrailSize; o->header.gfx.scale[2] = o->oWaveTrailSize; } diff --git a/src/game/behaviors/water_wave.inc.c b/src/game/behaviors/water_wave.inc.c index 4fae68d9..cc4b4e04 100644 --- a/src/game/behaviors/water_wave.inc.c +++ b/src/game/behaviors/water_wave.inc.c @@ -1,4 +1,4 @@ -// water_wave.c.inc +// water_wave.inc.c // TODO: Rename to avoid confusion with water_splashes_and_waves void bhv_object_water_wave_init(void) { @@ -7,6 +7,7 @@ void bhv_object_water_wave_init(void) { void bhv_object_water_wave_loop(void) { s32 globalTimer = gGlobalTimer; - if ((globalTimer % 16) == 0) + if (globalTimer % 16 == 0) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; + } } diff --git a/src/game/behaviors/wdw_water_level.inc.c b/src/game/behaviors/wdw_water_level.inc.c index 6a8a346b..3b43a793 100644 --- a/src/game/behaviors/wdw_water_level.inc.c +++ b/src/game/behaviors/wdw_water_level.inc.c @@ -1,15 +1,16 @@ -// wdw_water_level.c.inc +// wdw_water_level.inc.c // called when WDW is loaded. void bhv_init_changing_water_level_loop(void) { - if (gCurrentObject->oAction == 0) { - if (gEnvironmentRegions != NULL) - gCurrentObject->oAction++; - } else if (gCurrentObject->oTimer < 10) - *gEnvironmentLevels = gEnvironmentRegions[6]; - else { - gEnvironmentRegions[6] = *gEnvironmentLevels + sins(o->oWaterLevelTriggerUnkF4) * 20.0f; - gCurrentObject->oWaterLevelTriggerUnkF4 += 0x200; + if (o->oAction == 0) { + if (gEnvironmentRegions != NULL) { + o->oAction++; + } + } else if (o->oTimer < 10) { + gEnvironmentLevels[0] = gEnvironmentRegions[6]; + } else { + gEnvironmentRegions[6] = gEnvironmentLevels[0] + sins(o->oWaterLevelTriggerUnkF4) * 20.0f; + o->oWaterLevelTriggerUnkF4 += 0x200; } } @@ -19,49 +20,54 @@ void bhv_water_level_diamond_loop(void) { case WATER_LEVEL_DIAMOND_ACT_INIT: o->oFaceAngleYaw = 0; o->oWaterLevelTriggerTargetWaterLevel = (s32) o->oPosY; - if (o->oTimer > 10) + if (o->oTimer > 10) { o->oAction++; // Sets to WATER_LEVEL_DIAMOND_ACT_IDLE - break; - case WATER_LEVEL_DIAMOND_ACT_IDLE: - if (obj_check_if_collided_with_object(o, gMarioObject)) { - if (gWDWWaterLevelChanging == 0) { - o->oAction++; // Sets to WATER_LEVEL_DIAMOND_ACT_CHANGE_WATER_LEVEL - gWDWWaterLevelChanging = 1; - } } break; + + case WATER_LEVEL_DIAMOND_ACT_IDLE: + if (obj_check_if_collided_with_object(o, gMarioObject) && !gWDWWaterLevelChanging) { + o->oAction++; // Sets to WATER_LEVEL_DIAMOND_ACT_CHANGE_WATER_LEVEL + gWDWWaterLevelChanging = TRUE; + } + break; + case WATER_LEVEL_DIAMOND_ACT_CHANGE_WATER_LEVEL: o->oAngleVelYaw = 0; - *gEnvironmentLevels = (s32) approach_f32_symmetric( - (f32) *gEnvironmentLevels, (f32) o->oWaterLevelTriggerTargetWaterLevel, 10.0f); - if (*gEnvironmentLevels == o->oWaterLevelTriggerTargetWaterLevel) { - if ((s16) o->oFaceAngleYaw == 0) + gEnvironmentLevels[0] = (s32) approach_f32_symmetric( + (f32) gEnvironmentLevels[0], (f32) o->oWaterLevelTriggerTargetWaterLevel, 10.0f); + if (gEnvironmentLevels[0] == o->oWaterLevelTriggerTargetWaterLevel) { + if ((s16) o->oFaceAngleYaw == 0) { o->oAction++; // Sets to WATER_LEVEL_DIAMOND_ACT_IDLE_SPINNING - else + } else { o->oAngleVelYaw = 0x800; + } } else { - if (o->oTimer == 0) + if (o->oTimer == 0) { cur_obj_play_sound_2(SOUND_GENERAL_WATER_LEVEL_TRIG); - else { - if (*gEnvironmentLevels > o->oWaterLevelTriggerTargetWaterLevel) + } else { + if (gEnvironmentLevels[0] > o->oWaterLevelTriggerTargetWaterLevel) { cur_obj_play_sound_1(SOUND_ENV_WATER_DRAIN); - else + } else { cur_obj_play_sound_1(SOUND_ENV_WATER_DRAIN); // same as above + } } o->oAngleVelYaw = 0x800; -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers_2(2); #endif } break; + case WATER_LEVEL_DIAMOND_ACT_IDLE_SPINNING: if (!obj_check_if_collided_with_object(o, gMarioObject)) { - gWDWWaterLevelChanging = 0; + gWDWWaterLevelChanging = FALSE; o->oAction = WATER_LEVEL_DIAMOND_ACT_IDLE; o->oAngleVelYaw = 0; } break; } + o->oFaceAngleYaw += o->oAngleVelYaw; } } diff --git a/src/game/behaviors/whirlpool.inc.c b/src/game/behaviors/whirlpool.inc.c index 405e0518..84a5105d 100644 --- a/src/game/behaviors/whirlpool.inc.c +++ b/src/game/behaviors/whirlpool.inc.c @@ -1,4 +1,4 @@ -// whirlpool.c.inc +// whirlpool.inc.c static struct ObjectHitbox sWhirlpoolHitbox = { /* interactType: */ INTERACT_WHIRLPOOL, @@ -51,7 +51,7 @@ void bhv_whirlpool_loop(void) { whirpool_orient_graph(); - o->oFaceAngleYaw += 0x1F40; + o->oFaceAngleYaw += 8000; } else { o->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE; gEnvFxBubbleConfig[ENVFX_STATE_PARTICLECOUNT] = 0; @@ -68,8 +68,9 @@ void bhv_jet_stream_loop(void) { gEnvFxBubbleConfig[ENVFX_STATE_SRC_X] = o->oPosX; gEnvFxBubbleConfig[ENVFX_STATE_SRC_Y] = o->oPosY; gEnvFxBubbleConfig[ENVFX_STATE_SRC_Z] = o->oPosZ; - } else + } else { gEnvFxBubbleConfig[ENVFX_STATE_PARTICLECOUNT] = 0; + } cur_obj_play_sound_1(SOUND_ENV_WATER); } diff --git a/src/game/behaviors/white_puff.inc.c b/src/game/behaviors/white_puff.inc.c index 5bd7872d..55512ea3 100644 --- a/src/game/behaviors/white_puff.inc.c +++ b/src/game/behaviors/white_puff.inc.c @@ -1,20 +1,25 @@ -// white_puff.c.inc +// white_puff.inc.c void bhv_white_puff_1_loop(void) { f32 sp1C = 0.1f; f32 sp18 = 0.5f; + if (o->oTimer == 0) { obj_translate_xz_random(o, 40.0f); o->oPosY += 30.0f; } + cur_obj_scale(o->oTimer * sp18 + sp1C); o->oOpacity = 50; cur_obj_move_using_fvel_and_gravity(); - if (o->oTimer > 4) + + if (o->oTimer > 4) { obj_mark_for_deletion(o); + } } void bhv_white_puff_2_loop(void) { - if (o->oTimer == 0) + if (o->oTimer == 0) { obj_translate_xz_random(o, 40.0f); + } } diff --git a/src/game/behaviors/white_puff_explode.inc.c b/src/game/behaviors/white_puff_explode.inc.c index 510058ad..8b153da5 100644 --- a/src/game/behaviors/white_puff_explode.inc.c +++ b/src/game/behaviors/white_puff_explode.inc.c @@ -1,7 +1,6 @@ -// white_puff_explode.c.inc +// white_puff_explode.inc.c void bhv_white_puff_exploding_loop(void) { - f32 sp24; if (o->oTimer == 0) { cur_obj_compute_vel_xz(); o->oWhitePuffUnkF4 = o->header.gfx.scale[0]; @@ -18,20 +17,29 @@ void bhv_white_puff_exploding_loop(void) { break; } } + cur_obj_move_using_vel_and_gravity(); cur_obj_apply_drag_xz(o->oDragStrength); - if (o->oVelY > 100.0f) + + if (o->oVelY > 100.0f) { o->oVelY = 100.0f; - if (o->oTimer > 20) + } + + if (o->oTimer > 20) { obj_mark_for_deletion(o); + } + if (o->oOpacity) { + f32 scale; o->oOpacity += o->oWhitePuffUnkF8; - if (o->oOpacity < 2) + if (o->oOpacity < 2) { obj_mark_for_deletion(o); - if (o->oWhitePuffUnkFC) - sp24 = o->oWhitePuffUnkF4 * ((254 - o->oOpacity) / 254.0); - else - sp24 = o->oWhitePuffUnkF4 * (o->oOpacity / 254.0); - cur_obj_scale(sp24); + } + if (o->oWhitePuffUnkFC) { + scale = o->oWhitePuffUnkF4 * ((254 - o->oOpacity) / 254.0); + } else { + scale = o->oWhitePuffUnkF4 * (o->oOpacity / 254.0); + } + cur_obj_scale(scale); } } diff --git a/src/game/behaviors/whomp.inc.c b/src/game/behaviors/whomp.inc.c index 138e1753..fe39da7c 100644 --- a/src/game/behaviors/whomp.inc.c +++ b/src/game/behaviors/whomp.inc.c @@ -1,22 +1,26 @@ -// whomp.c.inc +// whomp.inc.c void whomp_play_sfx_from_pound_animation(void) { - UNUSED s32 sp2C = o->header.gfx.animInfo.animFrame; - s32 sp28 = 0; + UNUSED s32 animFrame = o->header.gfx.animInfo.animFrame; + s32 playSound = FALSE; + if (o->oForwardVel < 5.0f) { - sp28 = cur_obj_check_anim_frame(0); - sp28 |= cur_obj_check_anim_frame(23); + playSound = cur_obj_check_anim_frame(0); + playSound |= cur_obj_check_anim_frame(23); } else { - sp28 = cur_obj_check_anim_frame_in_range(0, 3); - sp28 |= cur_obj_check_anim_frame_in_range(23, 3); + playSound = cur_obj_check_anim_frame_in_range(0, 3); + playSound |= cur_obj_check_anim_frame_in_range(23, 3); } - if (sp28) + + if (playSound) { cur_obj_play_sound_2(SOUND_OBJ_POUNDING1); + } } -void whomp_act_0(void) { +void whomp_init(void) { cur_obj_init_animation_with_accel_and_sound(0, 1.0f); cur_obj_set_pos_to_home(); + if (o->oBehParams2ndByte != 0) { gSecondCameraFocus = o; cur_obj_scale(2.0f); @@ -28,87 +32,104 @@ void whomp_act_0(void) { cur_obj_set_pos_to_home(); o->oHealth = 3; } - } else if (cur_obj_update_dialog_with_cutscene(2, 1, CUTSCENE_DIALOG, DIALOG_114)) + } else if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + DIALOG_FLAG_TURN_TO_MARIO, CUTSCENE_DIALOG, DIALOG_114)) { o->oAction = 2; - } else if (o->oDistanceToMario < 500.0f) + } + } else if (o->oDistanceToMario < 500.0f) { o->oAction = 1; + } + whomp_play_sfx_from_pound_animation(); } -void whomp_act_7(void) { +void whomp_turn(void) { if (o->oSubAction == 0) { o->oForwardVel = 0.0f; cur_obj_init_animation_with_accel_and_sound(0, 1.0f); - if (o->oTimer > 31) + if (o->oTimer > 31) { o->oSubAction++; - else + } else { o->oMoveAngleYaw += 0x400; + } } else { o->oForwardVel = 3.0f; - if (o->oTimer > 42) + if (o->oTimer > 42) { o->oAction = 1; + } } + whomp_play_sfx_from_pound_animation(); } -void whomp_act_1(void) { - s16 sp26; - f32 sp20; - f32 sp1C; - sp26 = abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw); - sp20 = cur_obj_lateral_dist_to_home(); - if (gCurrLevelNum == LEVEL_BITS) - sp1C = 200.0f; - else - sp1C = 700.0f; +void whomp_patrol(void) { + s16 marioAngle = abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw); + f32 distWalked = cur_obj_lateral_dist_to_home(); + f32 patrolDist; + + if (gCurrLevelNum == LEVEL_BITS) { + patrolDist = 200.0f; + } else { + patrolDist = 700.0f; + } + cur_obj_init_animation_with_accel_and_sound(0, 1.0f); o->oForwardVel = 3.0f; - if (sp20 > sp1C) + + if (distWalked > patrolDist) { o->oAction = 7; - else if (sp26 < 0x2000) { + } else if (marioAngle < 0x2000) { if (o->oDistanceToMario < 1500.0f) { o->oForwardVel = 9.0f; cur_obj_init_animation_with_accel_and_sound(0, 3.0f); } - if (o->oDistanceToMario < 300.0f) + if (o->oDistanceToMario < 300.0f) { o->oAction = 3; + } } + whomp_play_sfx_from_pound_animation(); } -void whomp_act_2(void) { - s16 sp1E; +void king_whomp_chase(void) { cur_obj_init_animation_with_accel_and_sound(0, 1.0f); o->oForwardVel = 3.0f; cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x200); + if (o->oTimer > 30) { - sp1E = abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw); - if (sp1E < 0x2000) { + s16 marioAngle = abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw); + if (marioAngle < 0x2000) { if (o->oDistanceToMario < 1500.0f) { o->oForwardVel = 9.0f; cur_obj_init_animation_with_accel_and_sound(0, 3.0f); } - if (o->oDistanceToMario < 300.0f) + if (o->oDistanceToMario < 300.0f) { o->oAction = 3; + } } } + whomp_play_sfx_from_pound_animation(); + if (mario_is_far_below_object(1000.0f)) { o->oAction = 0; stop_background_music(SEQUENCE_ARGS(4, SEQ_EVENT_BOSS)); } } -void whomp_act_3(void) { +void whomp_prepare_jump(void) { o->oForwardVel = 0.0f; cur_obj_init_animation_with_accel_and_sound(1, 1.0f); - if (cur_obj_check_if_near_animation_end()) + if (cur_obj_check_if_near_animation_end()) { o->oAction = 4; + } } -void whomp_act_4(void) { - if (o->oTimer == 0) +void whomp_jump(void) { + if (o->oTimer == 0) { o->oVelY = 40.0f; + } + if (o->oTimer < 8) { } else { o->oAngleVelPitch += 0x100; @@ -121,31 +142,33 @@ void whomp_act_4(void) { } } -void whomp_act_5(void) { +void whomp_land(void) { if (o->oSubAction == 0 && o->oMoveFlags & OBJ_MOVE_LANDED) { - cur_obj_play_sound_2(SOUND_OBJ_WHOMP_LOWPRIO); + cur_obj_play_sound_2(SOUND_OBJ_WHOMP); cur_obj_shake_screen(SHAKE_POS_SMALL); o->oVelY = 0.0f; o->oSubAction++; } - if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) + + if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) { o->oAction = 6; + } } void king_whomp_on_ground(void) { - Vec3f pos; if (o->oSubAction == 0) { if (cur_obj_is_mario_ground_pounding_platform()) { + Vec3f pos; o->oHealth--; cur_obj_play_sound_2(SOUND_OBJ2_WHOMP_SOUND_SHORT); cur_obj_play_sound_2(SOUND_OBJ_KING_WHOMP_DEATH); - if (o->oHealth == 0) + if (o->oHealth == 0) { o->oAction = 8; - else { + } else { vec3f_copy_2(pos, &o->oPosX); vec3f_copy_2(&o->oPosX, &gMarioObject->oPosX); spawn_mist_particles_variable(0, 0, 100.0f); - spawn_triangle_break_particles(20, 138, 3.0f, 4); + spawn_triangle_break_particles(20, MODEL_DIRT_ANIMATION, 3.0f, 4); cur_obj_shake_screen(SHAKE_POS_SMALL); vec3f_copy_2(&o->oPosX, pos); } @@ -154,12 +177,14 @@ void king_whomp_on_ground(void) { o->oWhompShakeVal = 0; } else { if (o->oWhompShakeVal < 10) { - if (o->oWhompShakeVal % 2) + if (o->oWhompShakeVal % 2) { o->oPosY += 8.0f; - else + } else { o->oPosY -= 8.0f; - } else + } + } else { o->oSubAction = 10; + } o->oWhompShakeVal++; } } @@ -176,45 +201,49 @@ void whomp_on_ground(void) { o->oSubAction++; } } - } else if (!cur_obj_is_mario_on_platform()) + } else if (!cur_obj_is_mario_on_platform()) { o->oSubAction = 0; + } } -void whomp_act_6(void) { +void whomp_on_ground_general(void) { if (o->oSubAction != 10) { o->oForwardVel = 0.0f; o->oAngleVelPitch = 0; o->oAngleVelYaw = 0; o->oAngleVelRoll = 0; - if (o->oBehParams2ndByte != 0) + + if (o->oBehParams2ndByte != 0) { king_whomp_on_ground(); - else - whomp_on_ground(); - if (o->oTimer > 100 || (gMarioState->action == ACT_SQUISHED && o->oTimer > 30)) - o->oSubAction = 10; - } else { - if (o->oFaceAnglePitch > 0) { - o->oAngleVelPitch = -0x200; - o->oFaceAnglePitch += o->oAngleVelPitch; } else { - o->oAngleVelPitch = 0; - o->oFaceAnglePitch = 0; - if (o->oBehParams2ndByte != 0) - o->oAction = 2; - else - o->oAction = 1; + whomp_on_ground(); + } + if (o->oTimer > 100 || (gMarioState->action == ACT_SQUISHED && o->oTimer > 30)) { + o->oSubAction = 10; + } + } else if (o->oFaceAnglePitch > 0) { + o->oAngleVelPitch = -0x200; + o->oFaceAnglePitch += o->oAngleVelPitch; + } else { + o->oAngleVelPitch = 0; + o->oFaceAnglePitch = 0; + if (o->oBehParams2ndByte != 0) { + o->oAction = 2; + } else { + o->oAction = 1; } } } -void whomp_act_8(void) { +void whomp_die(void) { if (o->oBehParams2ndByte != 0) { - if (cur_obj_update_dialog_with_cutscene(2, 2, CUTSCENE_DIALOG, DIALOG_115)) { + if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + DIALOG_FLAG_TEXT_DEFAULT, CUTSCENE_DIALOG, DIALOG_115)) { obj_set_angle(o, 0, 0, 0); cur_obj_hide(); cur_obj_become_intangible(); spawn_mist_particles_variable(0, 0, 200.0f); - spawn_triangle_break_particles(20, 138, 3.0f, 4); + spawn_triangle_break_particles(20, MODEL_DIRT_ANIMATION, 3.0f, 4); cur_obj_shake_screen(SHAKE_POS_SMALL); o->oPosY += 100.0f; spawn_default_star(180.0f, 3880.0f, 340.0f); @@ -223,33 +252,41 @@ void whomp_act_8(void) { } } else { spawn_mist_particles_variable(0, 0, 100.0f); - spawn_triangle_break_particles(20, 138, 3.0f, 4); + spawn_triangle_break_particles(20, MODEL_DIRT_ANIMATION, 3.0f, 4); cur_obj_shake_screen(SHAKE_POS_SMALL); create_sound_spawner(SOUND_OBJ_THWOMP); obj_mark_for_deletion(o); } } -void whomp_act_9(void) { - if (o->oTimer == 60) +void king_whomp_stop_music(void) { + if (o->oTimer == 60) { stop_background_music(SEQUENCE_ARGS(4, SEQ_EVENT_BOSS)); + } } void (*sWhompActions[])(void) = { - whomp_act_0, whomp_act_1, whomp_act_2, whomp_act_3, whomp_act_4, - whomp_act_5, whomp_act_6, whomp_act_7, whomp_act_8, whomp_act_9 + whomp_init, + whomp_patrol, + king_whomp_chase, + whomp_prepare_jump, + whomp_jump, + whomp_land, + whomp_on_ground_general, + whomp_turn, whomp_die, + king_whomp_stop_music, }; -// MM void bhv_whomp_loop(void) { cur_obj_update_floor_and_walls(); cur_obj_call_action_function(sWhompActions); cur_obj_move_standard(-20); if (o->oAction != 9) { - if (o->oBehParams2ndByte != 0) + if (o->oBehParams2ndByte != 0) { cur_obj_hide_if_mario_far_away_y(2000.0f); - else + } else { cur_obj_hide_if_mario_far_away_y(1000.0f); + } load_object_collision_model(); } } diff --git a/src/game/behaviors/wiggler.inc.c b/src/game/behaviors/wiggler.inc.c index 3d27856b..5ba10254 100644 --- a/src/game/behaviors/wiggler.inc.c +++ b/src/game/behaviors/wiggler.inc.c @@ -91,8 +91,7 @@ void bhv_wiggler_body_part_update(void) { // the floor o->oPosY += -30.0f; cur_obj_update_floor_height(); - if (o->oFloorHeight > o->oPosY) // TODO: Check ineq swap - { + if (o->oFloorHeight > o->oPosY) { // TODO: Check ineq swap o->oPosY = o->oFloorHeight; } } @@ -117,10 +116,8 @@ void bhv_wiggler_body_part_update(void) { */ void wiggler_init_segments(void) { s32 i; - struct ChainSegment *segments; - struct Object *bodyPart; + struct ChainSegment *segments = mem_pool_alloc(gObjectMemoryPool, 4 * sizeof(struct ChainSegment)); - segments = mem_pool_alloc(gObjectMemoryPool, 4 * sizeof(struct ChainSegment)); if (segments != NULL) { // Each segment represents the global position and orientation of each // object. Segment 0 represents the wiggler's head, and segment i>0 @@ -141,7 +138,7 @@ void wiggler_init_segments(void) { // Spawn each body part for (i = 1; i <= 3; i++) { - bodyPart = + struct Object *bodyPart = spawn_object_relative(i, 0, 0, 0, o, MODEL_WIGGLER_BODY, bhvWigglerBody); if (bodyPart != NULL) { obj_init_animation_with_sound(bodyPart, wiggler_seg5_anims_0500C874, 0); @@ -175,9 +172,7 @@ void wiggler_init_segments(void) { s16 dyaw; f32 dxz; s32 i; - f32 segmentLength; - - segmentLength = 35.0f * o->header.gfx.scale[0]; + f32 segmentLength = 35.0f * o->header.gfx.scale[0]; for (i = 1; i <= 3; i++) { prevBodyPart = &o->oWigglerSegments[i - 1]; @@ -228,7 +223,8 @@ static void wiggler_act_walk(void) { // If Mario is positioned below the wiggler, assume he entered through the // lower cave entrance, so don't display text. - if (gMarioObject->oPosY < o->oPosY || cur_obj_update_dialog_with_cutscene(2, 0, CUTSCENE_DIALOG, DIALOG_150) != 0) { + if (gMarioObject->oPosY < o->oPosY || cur_obj_update_dialog_with_cutscene( + MARIO_DIALOG_LOOK_UP, DIALOG_FLAG_NONE, CUTSCENE_DIALOG, DIALOG_150)) { o->oWigglerTextStatus = WIGGLER_TEXT_STATUS_COMPLETED_DIALOG; } } else { @@ -239,7 +235,7 @@ static void wiggler_act_walk(void) { obj_forward_vel_approach(sWigglerSpeeds[o->oHealth - 1], 1.0f); if (o->oWigglerWalkAwayFromWallTimer != 0) { - o->oWigglerWalkAwayFromWallTimer -= 1; + o->oWigglerWalkAwayFromWallTimer--; } else { if (o->oDistanceToMario >= 25000.0f) { // If >1200 away from home, turn to home @@ -255,7 +251,7 @@ static void wiggler_act_walk(void) { if (o->oHealth < 4) { o->oWigglerTargetYaw = o->oAngleToMario; } else if (o->oWigglerTimeUntilRandomTurn != 0) { - o->oWigglerTimeUntilRandomTurn -= 1; + o->oWigglerTimeUntilRandomTurn--; } else { o->oWigglerTargetYaw = o->oMoveAngleYaw + 0x4000 * (s16) random_sign(); o->oWigglerTimeUntilRandomTurn = random_linear_offset(30, 50); @@ -304,7 +300,8 @@ static void wiggler_act_jumped_on(void) { // defeated) or go back to walking if (o->header.gfx.scale[1] >= 4.0f) { if (o->oTimer > 30) { - if (cur_obj_update_dialog_with_cutscene(2, 0, CUTSCENE_DIALOG, attackText[o->oHealth - 2]) != 0) { + if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + DIALOG_FLAG_NONE, CUTSCENE_DIALOG, attackText[o->oHealth - 2])) { // Because we don't want the wiggler to disappear after being // defeated, we leave its health at 1 if (--o->oHealth == 1) { diff --git a/src/game/behaviors/wind.inc.c b/src/game/behaviors/wind.inc.c index a1c58dd4..e95acffa 100644 --- a/src/game/behaviors/wind.inc.c +++ b/src/game/behaviors/wind.inc.c @@ -1,4 +1,4 @@ -// wind.c.inc +// wind.inc.c void spawn_wind_particles(s16 pitch, s16 yaw) { s32 i; @@ -11,7 +11,8 @@ void spawn_wind_particles(s16 pitch, s16 yaw) { void bhv_wind_loop(void) { s16 sp2E = 500; - f32 sp28 = 1.0f; + f32 scale = 1.0f; + if (o->oTimer == 0) { o->oOpacity = 100; if (o->oMoveAnglePitch == 0) { @@ -29,10 +30,13 @@ void bhv_wind_loop(void) { o->oForwardVel = 10.0f; } obj_set_billboard(o); - cur_obj_scale(sp28); + cur_obj_scale(scale); } - if (o->oTimer > 8) + + if (o->oTimer > 8) { obj_mark_for_deletion(o); + } + o->oFaceAnglePitch += 4000.0f + 2000.0f * random_float(); o->oFaceAngleYaw += 4000.0f + 2000.0f * random_float(); cur_obj_move_using_fvel_and_gravity(); diff --git a/src/game/behaviors/yoshi.inc.c b/src/game/behaviors/yoshi.inc.c index c588d311..461a5a68 100644 --- a/src/game/behaviors/yoshi.inc.c +++ b/src/game/behaviors/yoshi.inc.c @@ -1,4 +1,4 @@ -// yoshi.c.inc +// yoshi.inc.c // X/Z coordinates of Yoshi's homes that he switches between. // Note that this doesn't contain the Y coordinate since the castle roof is flat, @@ -18,21 +18,26 @@ void bhv_yoshi_init(void) { } void yoshi_walk_loop(void) { - UNUSED s16 sp26; - s16 sp24 = o->header.gfx.animInfo.animFrame; + UNUSED s16 collisionFlags; + s16 animFrame = o->header.gfx.animInfo.animFrame; o->oForwardVel = 10.0f; - sp26 = object_step(); + collisionFlags = object_step(); o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oYoshiTargetYaw, 0x500); - if (is_point_close_to_object(o, o->oHomeX, 3174.0f, o->oHomeZ, 200)) + + if (is_point_close_to_object(o, o->oHomeX, 3174.0f, o->oHomeZ, 200)) { o->oAction = YOSHI_ACT_IDLE; + } cur_obj_init_animation(1); - if (sp24 == 0 || sp24 == 15) - cur_obj_play_sound_2(SOUND_GENERAL_YOSHI_WALK); - if (o->oInteractStatus == INT_STATUS_INTERACTED) + if (animFrame == 0 || animFrame == 15) { + cur_obj_play_sound_2(SOUND_GENERAL_YOSHI_WALK); + } + + if (o->oInteractStatus == INT_STATUS_INTERACTED) { o->oAction = YOSHI_ACT_TALK; + } if (o->oPosY < 2100.0f) { create_respawner(MODEL_YOSHI, bhvYoshi, 3000); @@ -42,7 +47,7 @@ void yoshi_walk_loop(void) { void yoshi_idle_loop(void) { s16 chosenHome; - UNUSED s16 sp1C = o->header.gfx.animInfo.animFrame; + UNUSED s16 animFrame = o->header.gfx.animInfo.animFrame; if (o->oTimer > 90) { chosenHome = random_float() * 3.99; @@ -60,8 +65,10 @@ void yoshi_idle_loop(void) { } cur_obj_init_animation(0); - if (o->oInteractStatus == INT_STATUS_INTERACTED) + + if (o->oInteractStatus == INT_STATUS_INTERACTED) { o->oAction = YOSHI_ACT_TALK; + } // Credits; Yoshi appears at this position overlooking the castle near the end of the credits if (gPlayerCameraState->cameraEvent == CAM_EVENT_START_ENDING || @@ -76,9 +83,9 @@ void yoshi_idle_loop(void) { void yoshi_talk_loop(void) { if ((s16) o->oMoveAngleYaw == (s16) o->oAngleToMario) { cur_obj_init_animation(0); - if (set_mario_npc_dialog(1) == 2) { + if (set_mario_npc_dialog(MARIO_DIALOG_LOOK_FRONT) == MARIO_DIALOG_STATUS_SPEAK) { o->activeFlags |= ACTIVE_FLAG_INITIATED_TIME_STOP; - if (cutscene_object_with_dialog(CUTSCENE_DIALOG, o, DIALOG_161)) { + if (cutscene_object_with_dialog(CUTSCENE_DIALOG, o, DIALOG_161) != 0) { o->activeFlags &= ~ACTIVE_FLAG_INITIATED_TIME_STOP; o->oInteractStatus = 0; o->oHomeX = sYoshiHomeLocations[2]; @@ -95,15 +102,18 @@ void yoshi_talk_loop(void) { } void yoshi_walk_and_jump_off_roof_loop(void) { - s16 sp26 = o->header.gfx.animInfo.animFrame; + s16 animFrame = o->header.gfx.animInfo.animFrame; o->oForwardVel = 10.0f; object_step(); cur_obj_init_animation(1); - if (o->oTimer == 0) + + if (o->oTimer == 0) { cutscene_object(CUTSCENE_STAR_SPAWN, o); + } o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oYoshiTargetYaw, 0x500); + if (is_point_close_to_object(o, o->oHomeX, 3174.0f, o->oHomeZ, 200)) { cur_obj_init_animation(2); cur_obj_play_sound_2(SOUND_GENERAL_ENEMY_ALERT1); @@ -113,7 +123,7 @@ void yoshi_walk_and_jump_off_roof_loop(void) { o->oAction = YOSHI_ACT_FINISH_JUMPING_AND_DESPAWN; } - if (sp26 == 0 || sp26 == 15) { + if (animFrame == 0 || animFrame == 15) { cur_obj_play_sound_2(SOUND_GENERAL_YOSHI_WALK); } } @@ -121,9 +131,11 @@ void yoshi_walk_and_jump_off_roof_loop(void) { void yoshi_finish_jumping_and_despawn_loop(void) { cur_obj_extend_animation_if_at_end(); obj_move_xyz_using_fvel_and_yaw(o); + o->oVelY -= 2.0; + if (o->oPosY < 2100.0f) { - set_mario_npc_dialog(0); + set_mario_npc_dialog(MARIO_DIALOG_STOP); gObjCutsceneDone = TRUE; sYoshiDead = TRUE; o->activeFlags = ACTIVE_FLAG_DEACTIVATED; @@ -131,7 +143,7 @@ void yoshi_finish_jumping_and_despawn_loop(void) { } void yoshi_give_present_loop(void) { - s32 sp1C = gGlobalTimer; + s32 globalTimer = gGlobalTimer; if (gHudDisplay.lives == 100) { play_sound(SOUND_GENERAL_COLLECT_1UP, gGlobalSoundSource); @@ -140,7 +152,7 @@ void yoshi_give_present_loop(void) { return; } - if ((sp1C & 0x03) == 0) { + if (!(globalTimer & 3)) { play_sound(SOUND_MENU_YOSHI_GAIN_LIVES, gGlobalSoundSource); gMarioState->numLives++; } diff --git a/src/game/camera.c b/src/game/camera.c index 2ae110ce..216fe0e3 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -390,9 +390,13 @@ struct CameraStoredInfo sCameraStoreCutscene; // first iteration of data u32 unused8032CFC0 = 0; struct Object *gCutsceneFocus = NULL; -// other camera focuses? + u32 unused8032CFC8 = 0; u32 unused8032CFCC = 0; + +/** + * The information of a second focus camera used by some objects + */ struct Object *gSecondCameraFocus = NULL; /** @@ -431,7 +435,7 @@ u8 sFramesSinceCutsceneEnded = 0; * 2 = No * 3 = Dialog doesn't have a response */ -u8 sCutsceneDialogResponse = 0; +u8 sCutsceneDialogResponse = DIALOG_RESPONSE_NONE; struct PlayerCameraState *sMarioCamState = &gPlayerCameraState[0]; struct PlayerCameraState *sLuigiCamState = &gPlayerCameraState[1]; u32 unused8032D008 = 0; @@ -664,7 +668,7 @@ void unused_set_camera_pitch_shake_env(s16 shake) { BAD_RETURN(f32) calc_y_to_curr_floor(f32 *posOff, f32 posMul, f32 posBound, f32 *focOff, f32 focMul, f32 focBound) { f32 floorHeight = sMarioGeometry.currFloorHeight; f32 waterHeight; - UNUSED s32 filler; + UNUSED u8 filler[4]; if (!(sMarioCamState->action & ACT_FLAG_METAL_WATER)) { //! @bug this should use sMarioGeometry.waterHeight @@ -900,11 +904,10 @@ s32 update_radial_camera(struct Camera *c, Vec3f focus, Vec3f pos) { f32 cenDistZ = sMarioCamState->pos[2] - c->areaCenZ; s16 camYaw = atan2s(cenDistZ, cenDistX) + sModeOffsetYaw; s16 pitch = look_down_slopes(camYaw); - UNUSED f32 unused1; + UNUSED u8 filler1[4]; f32 posY; f32 focusY; - UNUSED f32 unused2; - UNUSED f32 unused3; + UNUSED u8 filler2[8]; f32 yOff = 125.f; f32 baseDist = 1000.f; @@ -926,9 +929,7 @@ s32 update_8_directions_camera(struct Camera *c, Vec3f focus, Vec3f pos) { s16 pitch = look_down_slopes(camYaw); f32 posY; f32 focusY; - UNUSED f32 unused1; - UNUSED f32 unused2; - UNUSED f32 unused3; + UNUSED u8 filler[12]; f32 yOff = 125.f; f32 baseDist = 1000.f; @@ -958,7 +959,7 @@ void radial_camera_move(struct Camera *c) { UNUSED s32 unused2 = 0; f32 areaDistX = sMarioCamState->pos[0] - c->areaCenX; f32 areaDistZ = sMarioCamState->pos[2] - c->areaCenZ; - UNUSED s32 filler; + UNUSED u8 filler[4]; // How much the camera's yaw changed s16 yawOffset = calculate_yaw(sMarioCamState->pos, c->pos) - atan2s(areaDistZ, areaDistX); @@ -1140,9 +1141,9 @@ void update_yaw_and_dist_from_c_up(UNUSED struct Camera *c) { */ void mode_radial_camera(struct Camera *c) { Vec3f pos; - UNUSED u8 unused1[8]; + UNUSED u8 filler1[8]; s16 oldAreaYaw = sAreaYaw; - UNUSED u8 unused2[4]; + UNUSED u8 filler2[4]; if (gCameraMovementFlags & CAM_MOVING_INTO_MODE) { update_yaw_and_dist_from_c_up(c); @@ -1170,7 +1171,7 @@ void mode_radial_camera(struct Camera *c) { */ void mode_8_directions_camera(struct Camera *c) { Vec3f pos; - UNUSED u8 unused[8]; + UNUSED u8 filler[8]; s16 oldAreaYaw = sAreaYaw; radial_camera_input(c, 0.f); @@ -1268,7 +1269,7 @@ s32 update_parallel_tracking_camera(struct Camera *c, Vec3f focus, Vec3f pos) { f32 marioFloorDist; Vec3f marioPos; UNUSED u8 filler4[12]; - UNUSED Vec3f unused4; + UNUSED Vec3f unused; Vec3s pathAngle; // Variables for changing to the next/prev path in the list Vec3f oldPos; @@ -1281,9 +1282,9 @@ s32 update_parallel_tracking_camera(struct Camera *c, Vec3f focus, Vec3f pos) { s16 prevYaw; s16 nextYaw; - unused4[0] = 0.f; - unused4[1] = 0.f; - unused4[2] = 0.f; + unused[0] = 0.f; + unused[1] = 0.f; + unused[2] = 0.f; // Store camera pos, for changing between paths vec3f_copy(oldPos, pos); @@ -1678,18 +1679,14 @@ struct UnusedDanceInfo { }; struct UnusedDanceInfo unusedDanceInfo1 = { - {-3026.0f, 912.0f, -2148.0f}, - 600.0f, - 0.3f + { -3026.0f, 912.0f, -2148.0f }, 600.0f, 0.3f }; u32 unusedDanceType = 0; -struct UnusedDanceInfo unusedDanceInfo2 = { - {-4676.0f, 917.0f, -3802.0f}, - 600.0f, - 0.3f -}; +struct UnusedDanceInfo unusedDanceInfo2 = { + { -4676.0f, 917.0f, -3802.0f }, 600.0f, 0.3f +}; /** * Table that dictates camera movement in bookend room. @@ -1703,9 +1700,12 @@ struct ParallelTrackingPoint sBBHLibraryParTrackPath[] = { }; s32 unused_update_mode_5_camera(UNUSED struct Camera *c, UNUSED Vec3f focus, UNUSED Vec3f pos) { +#ifdef AVOID_UB + return 0; +#endif } -static void stub_camera_1(UNUSED s32 unused) { +UNUSED static void stub_camera_1(UNUSED s32 unused) { } void mode_boss_fight_camera(struct Camera *c) { @@ -1730,7 +1730,7 @@ void mode_parallel_tracking_camera(struct Camera *c) { * Fixed camera mode, the camera rotates around a point and looks and zooms toward Mario. */ void mode_fixed_camera(struct Camera *c) { - UNUSED u8 unused[8]; + UNUSED u8 filler[8]; if (gCurrLevelNum == LEVEL_BBH) { set_fov_function(CAM_FOV_BBH); @@ -1749,9 +1749,9 @@ void mode_fixed_camera(struct Camera *c) { * The C-Buttons rotate the camera 90 degrees left/right and 67.5 degrees up/down. */ s32 update_behind_mario_camera(struct Camera *c, Vec3f focus, Vec3f pos) { - UNUSED u8 unused2[12]; + UNUSED u8 filler1[12]; f32 dist; - UNUSED u8 unused3[4]; + UNUSED u8 filler2[4]; s16 absPitch; s16 pitch; s16 yaw; @@ -1760,7 +1760,7 @@ s32 update_behind_mario_camera(struct Camera *c, Vec3f focus, Vec3f pos) { s16 goalYawOff = 0; s16 yawSpeed; s16 pitchInc = 32; - UNUSED u8 unused[12]; + UNUSED u8 filler3[12]; f32 maxDist = 800.f; f32 focYOff = 125.f; @@ -2028,6 +2028,9 @@ void mode_behind_mario_camera(struct Camera *c) { } s32 nop_update_water_camera(UNUSED struct Camera *c, UNUSED Vec3f focus, UNUSED Vec3f pos) { +#ifdef AVOID_UB + return 0; +#endif } /** @@ -2055,7 +2058,7 @@ s32 update_mario_camera(UNUSED struct Camera *c, Vec3f focus, Vec3f pos) { s16 update_default_camera(struct Camera *c) { Vec3f tempPos; Vec3f cPos; - UNUSED u8 unused1[12]; + UNUSED u8 filler1[12]; struct Surface *marioFloor; struct Surface *cFloor; struct Surface *tempFloor; @@ -2063,7 +2066,7 @@ s16 update_default_camera(struct Camera *c) { f32 camFloorHeight; f32 tempFloorHeight; f32 marioFloorHeight; - UNUSED u8 unused2[4]; + UNUSED u8 filler2[4]; f32 dist; f32 zoomDist; f32 waterHeight; @@ -2078,7 +2081,7 @@ s16 update_default_camera(struct Camera *c) { s16 tempPitch; s16 tempYaw; f32 xzDist; - UNUSED u8 unused4[4]; + UNUSED u8 filler3[4]; s16 nextYawVel; s16 yawVel = 0; f32 scale; @@ -2226,7 +2229,7 @@ s16 update_default_camera(struct Camera *c) { if ((closeToMario & 1) && avoidStatus != 0) { yawVel = 0; } - if (yawVel != 0 && get_dialog_id() == -1) { + if (yawVel != 0 && get_dialog_id() == DIALOG_NONE) { camera_approach_s16_symmetric_bool(&yaw, yawGoal, yawVel); } } @@ -2405,7 +2408,7 @@ void mode_mario_camera(struct Camera *c) { * Rotates the camera around the spiral staircase. */ s32 update_spiral_stairs_camera(struct Camera *c, Vec3f focus, Vec3f pos) { - UNUSED s16 unused1; + UNUSED s16 unused; /// The returned yaw s16 camYaw; // unused @@ -2416,7 +2419,7 @@ s32 update_spiral_stairs_camera(struct Camera *c, Vec3f focus, Vec3f pos) { s16 posPitch; /// The camera's yaw around the stairs s16 posYaw; - UNUSED s32 unused2; + UNUSED u8 filler[4]; Vec3f cPos; Vec3f checkPos; struct Surface *floor; @@ -2721,7 +2724,7 @@ void move_into_c_up(struct Camera *c) { * The main update function for C-Up mode */ s32 mode_c_up_camera(struct Camera *c) { - UNUSED u8 unused[12]; + UNUSED u8 filler[12]; // Play a sound when entering C-Up mode if (!(sCameraSoundFlags & CAM_SOUND_C_UP_PLAYED)) { @@ -2779,7 +2782,7 @@ s32 update_in_cannon(UNUSED struct Camera *c, Vec3f focus, Vec3f pos) { * sCannonYOffset is used to make the camera rotate down when Mario has just entered the cannon */ void mode_cannon_camera(struct Camera *c) { - UNUSED u8 unused[24]; + UNUSED u8 filler[24]; sLakituPitch = 0; gCameraMovementFlags &= ~CAM_MOVING_INTO_MODE; @@ -2904,10 +2907,10 @@ void update_lakitu(struct Camera *c) { struct Surface *floor = NULL; Vec3f newPos; Vec3f newFoc; - UNUSED Vec3f unusedVec3f; + UNUSED u8 filler1[12]; f32 distToFloor; s16 newYaw; - UNUSED u8 unused1[8]; + UNUSED u8 filler2[8]; if (gCameraMovementFlags & CAM_MOVE_PAUSE_SCREEN) { } else { @@ -3006,7 +3009,7 @@ void update_lakitu(struct Camera *c) { * Gets controller input, checks for cutscenes, handles mode changes, and moves the camera */ void update_camera(struct Camera *c) { - UNUSED u8 unused[24]; + UNUSED u8 filler[24]; gCamera = c; update_camera_hud_status(c); @@ -3203,7 +3206,7 @@ void update_camera(struct Camera *c) { */ void reset_camera(struct Camera *c) { UNUSED s32 unused = 0; - UNUSED u8 unused1[16]; + UNUSED u8 filler[16]; UNUSED struct LinearTransitionPoint *start = &sModeInfo.transitionStart; UNUSED struct LinearTransitionPoint *end = &sModeInfo.transitionEnd; @@ -3327,12 +3330,18 @@ void init_camera(struct Camera *c) { // Set the camera's starting position or start a cutscene for certain levels switch (gCurrLevelNum) { + // Calls the initial cutscene when you enter Bowser battle levels + // Note: This replaced an "old" way to call these cutscenes using + // a camEvent value: CAM_EVENT_BOWSER_INIT case LEVEL_BOWSER_1: #ifndef VERSION_JP + // Since Bowser 1 has a demo entry, check for it + // If it is, then set CamAct to the end to directly activate Bowser + // If it isn't, then start cutscene if (gCurrDemoInput == NULL) { start_cutscene(c, CUTSCENE_ENTER_BOWSER_ARENA); } else if (gSecondCameraFocus != NULL) { - gSecondCameraFocus->oBowserUnk88 = 2; + gSecondCameraFocus->oBowserCamAct = BOWSER_CAM_ACT_END; } #else start_cutscene(c, CUTSCENE_ENTER_BOWSER_ARENA); @@ -3442,11 +3451,11 @@ void init_camera(struct Camera *c) { * modulo-4's the result, because each 8-bit mask only has 4 area bits for each level */ void zoom_out_if_paused_and_outside(struct GraphNodeCamera *camera) { - UNUSED u8 unused1[8]; + UNUSED u8 filler1[8]; UNUSED f32 dist; UNUSED s16 pitch; s16 yaw; - UNUSED u8 unused2[4]; + UNUSED u8 filler2[4]; s32 areaMaskIndex = gCurrLevelArea / 32; s32 areaBit = 1 << (((gCurrLevelArea & 0x10) / 4) + (((gCurrLevelArea & 0xF) - 1) & 3)); @@ -3503,7 +3512,7 @@ void create_camera(struct GraphNodeCamera *gc, struct AllocOnlyPool *pool) { * Copy Lakitu's pos and foc into `gc` */ void update_graph_node_camera(struct GraphNodeCamera *gc) { - UNUSED u8 unused[8]; + UNUSED u8 filler[8]; UNUSED struct Camera *c = gc->config.camera; gc->rollScreen = gLakituState.roll; @@ -3569,7 +3578,7 @@ void evaluate_cubic_spline(f32 u, Vec3f Q, Vec3f a0, Vec3f a1, Vec3f a2, Vec3f a f32 x; f32 y; f32 z; - UNUSED u8 unused[16]; + UNUSED u8 filler[16]; if (u > 1.f) { u = 1.f; @@ -3670,7 +3679,7 @@ s32 move_point_along_spline(Vec3f p, struct CutsceneSplinePoint spline[], s16 *s *splineSegment = 0; finished = 1; } - *progress -= 1; + (*progress)--; } return finished; } @@ -3795,7 +3804,7 @@ void shake_camera_handheld(Vec3f pos, Vec3f focus) { f32 dist; s16 pitch; s16 yaw; - UNUSED u8 unused[8]; + UNUSED u8 filler[8]; if (sHandheldShakeMag == 0) { vec3f_set(shakeOffset, 0.f, 0.f, 0.f); @@ -4232,7 +4241,7 @@ f32 camera_approach_f32_symmetric(f32 current, f32 target, f32 increment) { */ void random_vec3s(Vec3s dst, s16 xRange, s16 yRange, s16 zRange) { f32 randomFloat; - UNUSED u8 unused[4]; + UNUSED u8 filler[4]; f32 tempXRange; f32 tempYRange; f32 tempZRange; @@ -4328,7 +4337,7 @@ s32 clamp_positions_and_find_yaw(Vec3f pos, Vec3f origin, f32 xMax, f32 xMin, f3 */ s32 calc_avoid_yaw(s16 yawFromMario, s16 wallYaw) { s16 yawDiff; - UNUSED u8 unused[34]; // Debug print buffer? ;) + UNUSED u8 filler[34]; // Debug print buffer? ;) UNUSED s32 unused1 = 0; UNUSED s32 unused2 = 0; @@ -4366,7 +4375,7 @@ s32 is_surf_within_bounding_box(struct Surface *surf, f32 xMax, f32 yMax, f32 zM f32 dx; f32 dy; f32 dz; - UNUSED u8 unused[4]; + UNUSED u8 filler[4]; s32 i; s32 j; // result @@ -4444,7 +4453,7 @@ s32 is_range_behind_surface(Vec3f from, Vec3f to, struct Surface *surf, s16 rang s32 behindSurface = TRUE; s32 leftBehind = 0; s32 rightBehind = 0; - UNUSED u8 unused[20]; + UNUSED u8 filler[20]; f32 checkDist; s16 checkPitch; s16 checkYaw; @@ -4713,7 +4722,7 @@ void shake_camera_yaw(Vec3f pos, Vec3f focus) { * Apply a rotational shake to the camera by adjusting its roll */ void shake_camera_roll(s16 *roll) { - UNUSED u8 unused[8]; + UNUSED u8 filler[8]; if (gLakituState.shakeMagnitude[2] != 0) { increment_shake_offset(&gLakituState.shakeRollPhase, gLakituState.shakeRollVel); @@ -4848,6 +4857,9 @@ void play_sound_if_cam_switched_to_lakitu_or_mario(void) { */ s32 radial_camera_input(struct Camera *c, UNUSED f32 unused) { s16 dummy; +#ifdef AVOID_UB + dummy = 0; +#endif if ((gCameraMovementFlags & CAM_MOVE_ENTERED_ROTATE_SURFACE) || !(gCameraMovementFlags & CAM_MOVE_ROTATE)) { @@ -5065,15 +5077,15 @@ s32 determine_dance_cutscene(UNUSED struct Camera *c) { u8 cutscene = 0; u8 cutsceneIndex = 0; u8 starIndex = (gLastCompletedStarNum - 1) / 2; - u8 courseIndex = gCurrCourseNum; + u8 courseNum = gCurrCourseNum; if (starIndex > 3) { starIndex = 0; } - if (courseIndex > COURSE_MAX) { - courseIndex = COURSE_NONE; + if (courseNum > COURSE_MAX) { + courseNum = COURSE_NONE; } - cutsceneIndex = sDanceCutsceneIndexTable[courseIndex][starIndex]; + cutsceneIndex = sDanceCutsceneIndexTable[courseNum][starIndex]; if (gLastCompletedStarNum & 1) { // Odd stars take the lower four bytes @@ -5108,9 +5120,9 @@ u8 open_door_cutscene(u8 pullResult, u8 pushResult) { * @return the cutscene that should start, 0 if none */ u8 get_cutscene_from_mario_status(struct Camera *c) { - UNUSED u8 unused1[4]; + UNUSED u8 filler1[4]; u8 cutscene = c->cutscene; - UNUSED u8 unused2[12]; + UNUSED u8 filler2[12]; if (cutscene == 0) { // A cutscene started by an object, if any, will start if nothing else happened @@ -5315,7 +5327,7 @@ void set_focus_rel_mario(struct Camera *c, f32 leftRight, f32 yOff, f32 forwBack * @param forwBack offset to Mario's front/back, relative to his faceAngle * @param yawOff offset to Mario's faceAngle, changes the direction of `leftRight` and `forwBack` */ -static void unused_set_pos_rel_mario(struct Camera *c, f32 leftRight, f32 yOff, f32 forwBack, s16 yawOff) { +UNUSED static void unused_set_pos_rel_mario(struct Camera *c, f32 leftRight, f32 yOff, f32 forwBack, s16 yawOff) { u16 yaw = sMarioCamState->faceAngle[1] + yawOff; c->pos[0] = sMarioCamState->pos[0] + forwBack * sins(yaw) + leftRight * coss(yaw); @@ -5364,7 +5376,7 @@ void determine_pushing_or_pulling_door(s16 *rotation) { if (sMarioCamState->action == ACT_PULLING_DOOR) { *rotation = 0; } else { - *rotation = DEGREES(180); + *rotation = DEGREES(-180); } } @@ -5389,14 +5401,13 @@ s16 next_lakitu_state(Vec3f newPos, Vec3f newFoc, Vec3f curPos, Vec3f curFoc, s16 pitchVelocity; f32 distVelocity; f32 goalDist; - UNUSED f32 unusedDist; + UNUSED u8 filler1[4]; s16 goalPitch; s16 goalYaw; - UNUSED s16 unusedPitch; - UNUSED s16 unusedYaw; + UNUSED u8 filler2[4]; f32 distTimer = sModeTransition.framesLeft; s16 angleTimer = sModeTransition.framesLeft; - UNUSED s16 inTransition = 0; + UNUSED s16 inTransition = FALSE; Vec3f nextPos; Vec3f nextFoc; Vec3f startPos; @@ -5427,7 +5438,7 @@ s16 next_lakitu_state(Vec3f newPos, Vec3f newFoc, Vec3f curPos, Vec3f curFoc, // Transition from the last mode to the current one if (sModeTransition.framesLeft > 0) { - inTransition = 1; + inTransition = TRUE; vec3f_get_dist_and_angle(curFoc, curPos, &goalDist, &goalPitch, &goalYaw); distVelocity = ABS(goalDist - sModeTransition.posDist) / distTimer; @@ -5684,7 +5695,7 @@ BAD_RETURN(s32) cam_sl_free_roam(struct Camera *c) { * Warps the camera underneath the floor, used in HMC to move under the elevator platforms */ void move_camera_through_floor_while_descending(struct Camera *c, f32 height) { - UNUSED f32 pad; + UNUSED u8 filler[4]; if ((sMarioGeometry.currFloorHeight < height - 100.f) && (sMarioGeometry.prevFloorHeight > sMarioGeometry.currFloorHeight)) { @@ -6070,17 +6081,17 @@ u32 surface_type_modes(struct Camera *c) { switch (sMarioGeometry.currFloorType) { case SURFACE_CLOSE_CAMERA: transition_to_camera_mode(c, CAMERA_MODE_CLOSE, 90); - modeChanged += 1; + modeChanged++; break; case SURFACE_CAMERA_FREE_ROAM: transition_to_camera_mode(c, CAMERA_MODE_FREE_ROAM, 90); - modeChanged += 1; + modeChanged++; break; case SURFACE_NO_CAM_COL_SLIPPERY: transition_to_camera_mode(c, CAMERA_MODE_CLOSE, 90); - modeChanged += 1; + modeChanged++; break; } return modeChanged; @@ -6549,7 +6560,7 @@ s16 camera_course_processing(struct Camera *c) { } } - b += 1; + b++; } } @@ -6581,8 +6592,7 @@ s16 camera_course_processing(struct Camera *c) { case AREA_BBH: // if camera is fixed at bbh_room_13_balcony_camera (but as floats) - if (vec3f_compare(sFixedModeBasePosition, 210.f, 420.f, 3109.f) == 1) - { + if (vec3f_compare(sFixedModeBasePosition, 210.f, 420.f, 3109.f) == TRUE) { if (sMarioCamState->pos[1] < 1800.f) { transition_to_camera_mode(c, CAMERA_MODE_CLOSE, 30); } @@ -6723,24 +6733,24 @@ void resolve_geometry_collisions(Vec3f pos, UNUSED Vec3f lastGood) { * @return 3 if a wall is covering Mario, 1 if a wall is only near the camera. */ s32 rotate_camera_around_walls(struct Camera *c, Vec3f cPos, s16 *avoidYaw, s16 yawRange) { - UNUSED f32 unused1; + UNUSED u8 filler1[4]; struct WallCollisionData colData; struct Surface *wall; - UNUSED Vec3f unused2; + UNUSED u8 filler2[12]; f32 dummyDist, checkDist; - UNUSED f32 unused3; + UNUSED u8 filler3[4]; f32 coarseRadius; f32 fineRadius; s16 wallYaw, horWallNorm; - UNUSED s16 unused4; + UNUSED s16 unused; s16 dummyPitch; // The yaw of the vector from Mario to the camera. s16 yawFromMario; - UNUSED s16 unused5; + UNUSED u8 filler4[2]; s32 status = 0; /// The current iteration. The algorithm takes 8 equal steps from Mario back to the camera. s32 step = 0; - UNUSED s32 unused6; + UNUSED u8 filler5[4]; vec3f_get_dist_and_angle(sMarioCamState->pos, cPos, &dummyDist, &dummyPitch, &yawFromMario); sStatusFlags &= ~CAM_FLAG_CAM_NEAR_WALL; @@ -6863,31 +6873,31 @@ void start_object_cutscene(u8 cutscene, struct Object *o) { */ u8 start_object_cutscene_without_focus(u8 cutscene) { sObjectCutscene = cutscene; - sCutsceneDialogResponse = 0; + sCutsceneDialogResponse = DIALOG_RESPONSE_NONE; return 0; } -s32 unused_dialog_cutscene_response(u8 cutscene) { +s16 unused_dialog_cutscene_response(u8 cutscene) { // if not in a cutscene, start this one if ((gCamera->cutscene == 0) && (sObjectCutscene == 0)) { sObjectCutscene = cutscene; } // if playing this cutscene and Mario responded, return the response - if ((gCamera->cutscene == cutscene) && (sCutsceneDialogResponse != 0)) { - return (s16) sCutsceneDialogResponse; + if ((gCamera->cutscene == cutscene) && (sCutsceneDialogResponse)) { + return sCutsceneDialogResponse; } else { return 0; } } s16 cutscene_object_with_dialog(u8 cutscene, struct Object *o, s16 dialogID) { - s16 response = 0; + s16 response = DIALOG_RESPONSE_NONE; if ((gCamera->cutscene == 0) && (sObjectCutscene == 0)) { if (gRecentCutscene != cutscene) { start_object_cutscene(cutscene, o); - if (dialogID != -1) { + if (dialogID != DIALOG_NONE) { sCutsceneDialogID = dialogID; } else { sCutsceneDialogID = DIALOG_001; @@ -6902,7 +6912,7 @@ s16 cutscene_object_with_dialog(u8 cutscene, struct Object *o, s16 dialogID) { } s16 cutscene_object_without_dialog(u8 cutscene, struct Object *o) { - s16 response = cutscene_object_with_dialog(cutscene, o, -1); + s16 response = cutscene_object_with_dialog(cutscene, o, DIALOG_NONE); return response; } @@ -6958,15 +6968,15 @@ void init_spline_point(struct CutsceneSplinePoint *splinePoint, s8 index, u8 spe void copy_spline_segment(struct CutsceneSplinePoint dst[], struct CutsceneSplinePoint src[]) { s32 j = 0; s32 i = 0; - UNUSED s32 pad[2]; + UNUSED u8 filler[8]; init_spline_point(&dst[i], src[j].index, src[j].speed, src[j].point); - i += 1; + i++; do { do { init_spline_point(&dst[i], src[j].index, src[j].speed, src[j].point); - i += 1; - j += 1; + i++; + j++; } while ((src[j].index != -1) && (src[j].index != -1)); //! same comparison performed twice } while (j > 16); @@ -6987,7 +6997,7 @@ void copy_spline_segment(struct CutsceneSplinePoint dst[], struct CutsceneSpline s16 cutscene_common_set_dialog_state(s32 state) { s16 timer = gCutsceneTimer; // If the dialog ended, return CUTSCENE_LOOP, which would end the cutscene shot - if (set_mario_npc_dialog(state) == 2) { + if (set_mario_npc_dialog(state) == MARIO_DIALOG_STATUS_SPEAK) { timer = CUTSCENE_LOOP; } return timer; @@ -6995,19 +7005,19 @@ s16 cutscene_common_set_dialog_state(s32 state) { /// Unused SSL cutscene? static UNUSED void unused_cutscene_mario_dialog_looking_down(UNUSED struct Camera *c) { - gCutsceneTimer = cutscene_common_set_dialog_state(3); + gCutsceneTimer = cutscene_common_set_dialog_state(MARIO_DIALOG_LOOK_DOWN); } /** * Cause Mario to enter the normal dialog state. */ static BAD_RETURN(s32) cutscene_mario_dialog(UNUSED struct Camera *c) { - gCutsceneTimer = cutscene_common_set_dialog_state(1); + gCutsceneTimer = cutscene_common_set_dialog_state(MARIO_DIALOG_LOOK_FRONT); } /// Unused SSL cutscene? static UNUSED void unused_cutscene_mario_dialog_looking_up(UNUSED struct Camera *c) { - gCutsceneTimer = cutscene_common_set_dialog_state(2); + gCutsceneTimer = cutscene_common_set_dialog_state(MARIO_DIALOG_LOOK_UP); } /** @@ -7148,7 +7158,7 @@ static UNUSED void unused_vec3f_to_vec3s(Vec3s dst, Vec3f src) { * Rotate the camera's focus around the camera's position by incYaw and incPitch */ void pan_camera(struct Camera *c, s16 incPitch, s16 incYaw) { - UNUSED Vec3f unused1; + UNUSED u8 filler[12]; f32 distCamToFocus; s16 pitch, yaw; @@ -7196,7 +7206,7 @@ void cutscene_unsoften_music(UNUSED struct Camera *c) { seq_player_unlower_volume(SEQ_PLAYER_LEVEL, 60); } -static void stub_camera_5(UNUSED struct Camera *c) { +UNUSED static void stub_camera_5(UNUSED struct Camera *c) { } BAD_RETURN(s32) cutscene_unused_start(UNUSED struct Camera *c) { @@ -7682,7 +7692,7 @@ BAD_RETURN(s32) cutscene_dance_rotate_move_towards_mario(struct Camera *c) { /** * Speculated to be dance-related due to its proximity to the other dance functions */ -static BAD_RETURN(s32) cutscene_dance_unused(UNUSED struct Camera *c) { +UNUSED static BAD_RETURN(s32) cutscene_dance_unused(UNUSED struct Camera *c) { } /** @@ -7763,7 +7773,7 @@ BAD_RETURN(s32) star_dance_bound_yaw(struct Camera *c, s16 absYaw, s16 yawMax) { * Store the camera's focus in cvar9. */ BAD_RETURN(s32) cutscene_dance_closeup_start(struct Camera *c) { - UNUSED s32 pad[2]; + UNUSED u8 filler[8]; if ((gLastCompletedStarNum == 4) && (gCurrCourseNum == COURSE_JRB)) { star_dance_bound_yaw(c, 0x0, 0x4000); @@ -8033,10 +8043,10 @@ BAD_RETURN(s32) cutscene_bowser_area_shake_fov(UNUSED struct Camera *c) { } /** - * Set oBowserUnk88 to 1, which causes bowser to start walking. + * Set oBowserCamAct to 1, which causes bowser to start walking. */ BAD_RETURN(s32) cutscene_bowser_area_start_bowser_walking(UNUSED struct Camera *c) { - gSecondCameraFocus->oBowserUnk88 = 1; + gSecondCameraFocus->oBowserCamAct = BOWSER_CAM_ACT_WALK; } /** @@ -8093,11 +8103,11 @@ BAD_RETURN(s32) cutscene_bowser_arena_pan_left(UNUSED struct Camera *c) { * Duplicate of cutscene_mario_dialog(). */ BAD_RETURN(s32) cutscene_bowser_arena_mario_dialog(UNUSED struct Camera *c) { - cutscene_common_set_dialog_state(1); + cutscene_common_set_dialog_state(MARIO_DIALOG_LOOK_FRONT); } void cutscene_stop_dialog(UNUSED struct Camera *c) { - cutscene_common_set_dialog_state(0); + cutscene_common_set_dialog_state(MARIO_DIALOG_STOP); } /** @@ -8138,7 +8148,7 @@ BAD_RETURN(s32) bowser_fight_intro_dialog(UNUSED struct Camera *c) { case LEVEL_BOWSER_2: dialog = DIALOG_092; break; - default: + default: // LEVEL_BOWSER_3 dialog = DIALOG_093; } @@ -8151,7 +8161,7 @@ BAD_RETURN(s32) bowser_fight_intro_dialog(UNUSED struct Camera *c) { BAD_RETURN(s32) cutscene_bowser_arena_dialog(struct Camera *c) { cutscene_event(bowser_fight_intro_dialog, c, 0, 0); - if (get_dialog_id() == -1) { + if (get_dialog_id() == DIALOG_NONE) { gCutsceneTimer = CUTSCENE_LOOP; } } @@ -8165,7 +8175,7 @@ BAD_RETURN(s32) cutscene_bowser_arena_end(struct Camera *c) { transition_next_state(c, 20); sStatusFlags |= CAM_FLAG_UNUSED_CUTSCENE_ACTIVE; sModeOffsetYaw = sMarioCamState->faceAngle[1] + DEGREES(90); - gSecondCameraFocus->oBowserUnk88 = 2; + gSecondCameraFocus->oBowserCamAct = BOWSER_CAM_ACT_END; } /** @@ -8200,9 +8210,9 @@ BAD_RETURN(s32) cutscene_star_spawn_store_info(struct Camera *c) { * Focus on the top of the star. */ BAD_RETURN(s32) cutscene_star_spawn_focus_star(struct Camera *c) { - UNUSED f32 hMul; + UNUSED u8 filler1[4]; // hMul? Vec3f starPos; - UNUSED f32 vMul; + UNUSED u8 filler2[4]; // vMul? if (gCutsceneFocus != NULL) { object_pos_to_vec3f(starPos, gCutsceneFocus); @@ -8409,7 +8419,7 @@ BAD_RETURN(s32) cutscene_red_coin_star_end(struct Camera *c) { * @param rotYaw constant yaw offset to add to the camera's focus */ void cutscene_goto_cvar_pos(struct Camera *c, f32 goalDist, s16 goalPitch, s16 rotPitch, s16 rotYaw) { - UNUSED f32 unused1; + UNUSED u8 filler[4]; f32 nextDist; s16 nextPitch, nextYaw; // The next 2 polar coord points are only used in CUTSCENE_PREPARE_CANNON @@ -8417,8 +8427,10 @@ void cutscene_goto_cvar_pos(struct Camera *c, f32 goalDist, s16 goalPitch, s16 r s16 cannonPitch, cannonYaw; f32 curDist; s16 curPitch, curYaw; - UNUSED f64 unused2; + UNUSED f64 unused; + vec3f_get_dist_and_angle(sCutsceneVars[3].point, c->pos, &nextDist, &nextPitch, &nextYaw); + // If over 8000 units away from the cannon, just teleport there if ((nextDist > 8000.f) && (c->cutscene == CUTSCENE_PREPARE_CANNON)) { nextDist = goalDist * 4.f; @@ -8595,7 +8607,7 @@ BAD_RETURN(s32) cutscene_death_stomach_goto_mario(struct Camera *c) { /** * Ah, yes */ -static void unused_water_death_move_to_side_of_mario(struct Camera *c) { +UNUSED static void unused_water_death_move_to_side_of_mario(struct Camera *c) { water_death_move_to_mario_side(c); } @@ -8677,9 +8689,9 @@ BAD_RETURN(s32) cutscene_suffocation_fly_away(UNUSED struct Camera *c) { * Keep Lakitu above the gas level. */ BAD_RETURN(s32) cutscene_suffocation_stay_above_gas(struct Camera *c) { - UNUSED f32 unused1; + UNUSED u8 filler1[4]; f32 gasLevel; - UNUSED f32 unused2; + UNUSED u8 filler2[4]; cutscene_goto_cvar_pos(c, 400.f, 0x2800, 0x200, 0); gasLevel = find_poison_gas_level(sMarioCamState->pos[0], sMarioCamState->pos[2]); @@ -8729,7 +8741,7 @@ BAD_RETURN(s32) cutscene_enter_pool_start(struct Camera *c) { } BAD_RETURN(s32) cutscene_enter_pool_loop(struct Camera *c) { - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; cutscene_goto_cvar_pos(c, 1200.f, 0x2000, 0x200, 0); } @@ -8814,7 +8826,7 @@ BAD_RETURN(s32) cutscene_pyramid_top_explode_cam_shake(UNUSED struct Camera *c) * Warp back to the old position, and start a heavy camera shake. */ BAD_RETURN(s32) cutscene_pyramid_top_explode_warp_back(struct Camera *c) { - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; vec3f_copy(c->pos, sCutsceneVars[4].point); vec3f_copy(c->focus, sCutsceneVars[5].point); @@ -8869,7 +8881,7 @@ BAD_RETURN(s32) cutscene_enter_pyramid_top(struct Camera *c) { } } -static void unused_cutscene_goto_cvar(struct Camera *c) { +UNUSED static void unused_cutscene_goto_cvar(struct Camera *c) { f32 dist; dist = calc_abs_dist(sCutsceneVars[3].point, sMarioCamState->pos); @@ -8884,11 +8896,10 @@ static void unused_cutscene_goto_cvar(struct Camera *c) { * cvar9.angle[1] is the yaw between Mario and the gCutsceneFocus */ BAD_RETURN(s32) cutscene_dialog_start(struct Camera *c) { - UNUSED f32 unused1; - UNUSED s16 unused2; + UNUSED u8 filler[4]; + UNUSED s16 unused; s16 yaw; - cutscene_soften_music(c); set_time_stop_flags(TIME_STOP_ENABLED | TIME_STOP_DIALOG); @@ -8967,7 +8978,7 @@ BAD_RETURN(s32) cutscene_dialog_create_dialog_box(struct Camera *c) { } //! Unused. This may have been used before sCutsceneDialogResponse was implemented. - sCutsceneVars[8].angle[0] = 3; + sCutsceneVars[8].angle[0] = DIALOG_RESPONSE_NOT_DEFINED; } /** @@ -8979,13 +8990,13 @@ BAD_RETURN(s32) cutscene_dialog(struct Camera *c) { cutscene_event(cutscene_dialog_create_dialog_box, c, 10, 10); sStatusFlags |= CAM_FLAG_SMOOTH_MOVEMENT; - if (gDialogResponse != 0) { + if (gDialogResponse != DIALOG_RESPONSE_NONE) { sCutsceneDialogResponse = gDialogResponse; } - if ((get_dialog_id() == -1) && (sCutsceneVars[8].angle[0] != 0)) { + if ((get_dialog_id() == DIALOG_NONE) && (sCutsceneVars[8].angle[0] != 0)) { if (c->cutscene != CUTSCENE_RACE_DIALOG) { - sCutsceneDialogResponse = 3; + sCutsceneDialogResponse = DIALOG_RESPONSE_NOT_DEFINED; } gCutsceneTimer = CUTSCENE_LOOP; @@ -9030,7 +9041,7 @@ BAD_RETURN(s32) cutscene_read_message_start(struct Camera *c) { sCutsceneVars[0].angle[0] = 0; } -static void unused_cam_to_mario(struct Camera *c) { +UNUSED static void unused_cam_to_mario(struct Camera *c) { Vec3s dir; vec3s_set(dir, 0, sMarioCamState->faceAngle[1], 0); @@ -9042,7 +9053,7 @@ static void unused_cam_to_mario(struct Camera *c) { * Cutscene that plays when Mario is reading a message (a sign or message on the wall) */ BAD_RETURN(s32) cutscene_read_message(struct Camera *c) { - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; cutscene_event(cutscene_read_message_start, c, 0, 0); sStatusFlags |= CAM_FLAG_SMOOTH_MOVEMENT; @@ -9050,8 +9061,8 @@ BAD_RETURN(s32) cutscene_read_message(struct Camera *c) { switch (sCutsceneVars[0].angle[0]) { // Do nothing until message is gone. case 0: - if (get_dialog_id() != -1) { - sCutsceneVars[0].angle[0] += 1; + if (get_dialog_id() != DIALOG_NONE) { + sCutsceneVars[0].angle[0]++; set_time_stop_flags(TIME_STOP_ENABLED | TIME_STOP_DIALOG); } break; @@ -9062,7 +9073,7 @@ BAD_RETURN(s32) cutscene_read_message(struct Camera *c) { // This could cause softlocks. If a message starts one frame after another one closes, the // cutscene will never end. - if (get_dialog_id() == -1) { + if (get_dialog_id() == DIALOG_NONE) { gCutsceneTimer = CUTSCENE_LOOP; retrieve_info_star(c); transition_next_state(c, 15); @@ -9109,9 +9120,9 @@ BAD_RETURN(s32) cutscene_exit_succ_start(UNUSED struct Camera *c) { * Set the camera pos depending on which level Mario exited. */ BAD_RETURN(s32) cutscene_non_painting_set_cam_pos(struct Camera *c) { - UNUSED u32 unused1; + UNUSED u8 filler1[4]; struct Surface *floor; - UNUSED Vec3f unused2; + UNUSED u8 filler2[12]; switch (gPrevLevel) { case LEVEL_HMC: @@ -9293,9 +9304,9 @@ BAD_RETURN(s32) cutscene_non_painting_death(struct Camera *c) { * because cvar1 rotates until is reaches 0, so it's important that it's a multiple of 0x100. */ BAD_RETURN(s32) cutscene_cap_switch_press_start(struct Camera *c) { - UNUSED s16 unused1; + UNUSED s16 unused; s16 yaw; - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; store_info_star(c); yaw = calculate_yaw(sMarioCamState->pos, c->pos); @@ -9312,7 +9323,7 @@ BAD_RETURN(s32) cutscene_cap_switch_press_rotate_around_mario(struct Camera *c) f32 dist; s16 pitch, yaw; UNUSED s16 unusedYaw = sMarioCamState->faceAngle[1] + 0x1000; - UNUSED s16 unused; + UNUSED u8 filler[2]; UNUSED s32 cvar1Yaw = sCutsceneVars[1].angle[1]; vec3f_get_dist_and_angle(sMarioCamState->pos, c->pos, &dist, &pitch, &yaw); @@ -9395,11 +9406,11 @@ BAD_RETURN(s32) cutscene_cap_switch_press(struct Camera *c) { cutscene_event(cutscene_cap_switch_press_create_dialog, c, 10, 10); vec3f_get_dist_and_angle(sMarioCamState->pos, c->pos, &dist, &pitch, &yaw); - if (gDialogResponse != 0) { + if (gDialogResponse != DIALOG_RESPONSE_NONE) { sCutsceneVars[4].angle[0] = gDialogResponse; } - if ((get_dialog_id() == -1) && (sCutsceneVars[4].angle[0] != 0)) { + if ((get_dialog_id() == DIALOG_NONE) && (sCutsceneVars[4].angle[0] != 0)) { sCutsceneDialogResponse = sCutsceneVars[4].angle[0]; if (sCutsceneVars[4].angle[0] == 1) { cap_switch_save(gCutsceneFocus->oBehParams2ndByte); @@ -9493,8 +9504,8 @@ s32 intro_peach_move_camera_start_to_pipe(struct Camera *c, struct CutsceneSplin // The two splines used by this function are reflected in the horizontal plane for some reason, // so they are rotated every frame. Why do this, Nintendo? - rotate_in_xz(c->focus, c->focus, DEGREES(180)); - rotate_in_xz(c->pos, c->pos, DEGREES(180)); + rotate_in_xz(c->focus, c->focus, DEGREES(-180)); + rotate_in_xz(c->pos, c->pos, DEGREES(-180)); vec3f_set(offset, -1328.f, 260.f, 4664.f); vec3f_add(c->focus, offset); @@ -9532,7 +9543,7 @@ BAD_RETURN(s32) cutscene_intro_peach_start_to_pipe_spline(struct Camera *c) { * Loop the cutscene until Mario exits the dialog. */ BAD_RETURN(s32) cutscene_intro_peach_dialog(struct Camera *c) { - if (get_dialog_id() == -1) { + if (get_dialog_id() == DIALOG_NONE) { vec3f_copy(gLakituState.goalPos, c->pos); vec3f_copy(gLakituState.goalFocus, c->focus); sStatusFlags |= (CAM_FLAG_SMOOTH_MOVEMENT | CAM_FLAG_UNUSED_CUTSCENE_ACTIVE); @@ -9612,7 +9623,7 @@ BAD_RETURN(s32) cutscene_intro_peach_fly_to_pipe(struct Camera *c) { * Lakitu flies around the warp pipe, then Mario jumps out. */ BAD_RETURN(s32) cutscene_intro_peach_mario_appears(struct Camera *c) { - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; sMarioCamState->cameraEvent = 0; cutscene_event(cutscene_intro_peach_reset_spline, c, 0, 0); @@ -9654,7 +9665,7 @@ BAD_RETURN(s32) cutscene_intro_peach_letter(struct Camera *c) { cutscene_event(play_sound_peach_reading_letter, c, 83, 83); #endif - if ((gCutsceneTimer > 120) && (get_dialog_id() == -1)) { + if ((gCutsceneTimer > 120) && (get_dialog_id() == DIALOG_NONE)) { // Start the next scene gCutsceneTimer = CUTSCENE_LOOP; } @@ -9856,7 +9867,7 @@ BAD_RETURN(s32) cutscene_credits(struct Camera *c) { //! Checks if the "Snowman's Lost His Head" star was collected. The credits likely would //! have avoided the snowman if the player didn't collect that star, but in the end the //! developers decided against it. - if (save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1) & 0x10) { + if (save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)) & (1 << 4)) { pos = sCcmOutsideCreditsSplinePositions; focus = sCcmOutsideCreditsSplineFocus; } else { @@ -9926,7 +9937,7 @@ BAD_RETURN(s32) cutscene_sliding_doors_fly_back_up(UNUSED struct Camera *c) { */ BAD_RETURN(s32) cutscene_sliding_doors_follow_mario(struct Camera *c) { Vec3f pos; - UNUSED u32 pad[5]; + UNUSED u8 filler[20]; vec3f_copy(pos, c->pos); // Update cvar1 with Mario's position (the y value doesn't change) @@ -9952,7 +9963,7 @@ BAD_RETURN(s32) cutscene_sliding_doors_follow_mario(struct Camera *c) { * Note: the star door unlocking event is not a cutscene, it's handled by Mario separately. */ BAD_RETURN(s32) cutscene_sliding_doors_open(struct Camera *c) { - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; reset_pan_distance(c); cutscene_event(cutscene_sliding_doors_open_start, c, 0, 8); @@ -10123,8 +10134,7 @@ BAD_RETURN(s32) cutscene_exit_painting(struct Camera *c) { * Unused. Warp the camera to Mario. */ BAD_RETURN(s32) cutscene_unused_exit_start(struct Camera *c) { - UNUSED Vec3f unused1; - UNUSED Vec3s unused2; + UNUSED u8 filler[18]; Vec3f offset; Vec3s marioAngle; @@ -10174,7 +10184,7 @@ BAD_RETURN(s32) cutscene_enter_cannon_end(struct Camera *c) { */ BAD_RETURN(s32) cutscene_enter_cannon_raise(struct Camera *c) { struct Object *o; - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; f32 floorHeight; struct Surface *floor; Vec3f cannonFocus; @@ -10218,8 +10228,7 @@ BAD_RETURN(s32) cutscene_enter_cannon_raise(struct Camera *c) { * Start the cannon entering cutscene */ BAD_RETURN(s32) cutscene_enter_cannon_start(struct Camera *c) { - UNUSED u32 cvar3Start; - UNUSED u32 cvar4Start; + UNUSED u8 filler[8]; // cvar3Start, cvar4Start? struct Object *o; sStatusFlags |= CAM_FLAG_SMOOTH_MOVEMENT; @@ -10328,7 +10337,7 @@ BAD_RETURN(s32) cutscene_door_end(struct Camera *c) { * Used for entering a room that uses a specific camera mode, like the castle lobby or BBH */ BAD_RETURN(s32) cutscene_door_mode(struct Camera *c) { - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; reset_pan_distance(c); camera_course_processing(c); @@ -11152,7 +11161,7 @@ struct CutsceneSplinePoint sCcmOutsideCreditsSplineFocus[] = { * the duration they want the flag to be active. */ void play_cutscene(struct Camera *c) { - UNUSED u32 pad[3]; + UNUSED u8 filler[12]; UNUSED s16 unusedYawFocToMario; s16 cutsceneDuration; u8 oldCutscene; @@ -11222,12 +11231,12 @@ void play_cutscene(struct Camera *c) { //! @bug This should check for 0x7FFF (CUTSCENE_LOOP) //! instead, cutscenes that last longer than 0x3FFF frames will never end on their own if (gCutsceneTimer < 0x3FFF) { - gCutsceneTimer += 1; + gCutsceneTimer++; } //! Because gCutsceneTimer is often set to 0x7FFF (CUTSCENE_LOOP), this conditional can only //! check for == due to overflow if (gCutsceneTimer == cutsceneDuration) { - sCutsceneShot += 1; + sCutsceneShot++; gCutsceneTimer = 0; } } else { @@ -11535,6 +11544,8 @@ void obj_rotate_towards_point(struct Object *o, Vec3f point, s16 pitchOff, s16 y o->oMoveAngleYaw = approach_s16_asymptotic(o->oMoveAngleYaw, yaw + yawOff, yawDiv); } +#define o gCurrentObject + #include "behaviors/intro_peach.inc.c" #include "behaviors/intro_lakitu.inc.c" #include "behaviors/end_birds_1.inc.c" diff --git a/src/game/camera.h b/src/game/camera.h index f56ed027..dc729270 100644 --- a/src/game/camera.h +++ b/src/game/camera.h @@ -295,8 +295,7 @@ /** * A copy of player information that is relevant to the camera. */ -struct PlayerCameraState -{ +struct PlayerCameraState { /** * Mario's action on this frame. */ @@ -317,8 +316,7 @@ struct PlayerCameraState * Struct containing info that is used when transition_next_state() is called. Stores the intermediate * distances and angular displacements from lakitu's goal position and focus. */ -struct TransitionInfo -{ +struct TransitionInfo { /*0x00*/ s16 posPitch; /*0x02*/ s16 posYaw; /*0x04*/ f32 posDist; @@ -327,17 +325,16 @@ struct TransitionInfo /*0x0C*/ f32 focDist; /*0x10*/ s32 framesLeft; /*0x14*/ Vec3f marioPos; - /*0x20*/ u8 pad; // for the structs to align, there has to be an extra unused variable here. type is unknown. + /*0x20*/ u8 unused; // for the structs to align, there has to be an extra unused variable here. type is unknown. }; /** * A point that's used in a spline, controls the direction to move the camera in * during the shake effect. */ -struct HandheldShakePoint -{ +struct HandheldShakePoint { /*0x00*/ s8 index; // only set to -1 - /*0x04 (aligned)*/ u32 pad; + /*0x04 (aligned)*/ u32 unused; /*0x08*/ Vec3s point; }; // size = 0x10 @@ -359,8 +356,7 @@ typedef CameraEvent CutsceneShot; /** * Defines a bounding box which activates an event while Mario is inside */ -struct CameraTrigger -{ +struct CameraTrigger { /** * The area this should be checked in, or -1 if it should run in every area of the level. * @@ -388,8 +384,7 @@ struct CameraTrigger * A camera shot that is active for a number of frames. * Together, a sequence of shots makes up a cutscene. */ -struct Cutscene -{ +struct Cutscene { /// The function that gets called. CutsceneShot shot; /// How long the shot lasts. @@ -399,8 +394,7 @@ struct Cutscene /** * Info for the camera's field of view and the FOV shake effect. */ -struct CameraFOVStatus -{ +struct CameraFOVStatus { /// The current function being used to set the camera's field of view (before any fov shake is applied). /*0x00*/ u8 fovFunc; /// The current field of view in degrees @@ -425,8 +419,7 @@ struct CameraFOVStatus /** * Information for a control point in a spline segment. */ -struct CutsceneSplinePoint -{ +struct CutsceneSplinePoint { /* The index of this point in the spline. Ignored except for -1, which ends the spline. An index of -1 should come four points after the start of the last segment. */ s8 index; @@ -440,8 +433,7 @@ struct CutsceneSplinePoint * Struct containing the nearest floor and ceiling to the player, as well as the previous floor and * ceiling. It also stores their distances from the player's position. */ -struct PlayerGeometry -{ +struct PlayerGeometry { /*0x00*/ struct Surface *currFloor; /*0x04*/ f32 currFloorHeight; /*0x08*/ s16 currFloorType; @@ -461,8 +453,7 @@ struct PlayerGeometry /** * Point used in transitioning between camera modes and C-Up. */ -struct LinearTransitionPoint -{ +struct LinearTransitionPoint { Vec3f focus; Vec3f pos; f32 dist; @@ -473,8 +464,7 @@ struct LinearTransitionPoint /** * Info about transitioning between camera modes. */ -struct ModeTransitionInfo -{ +struct ModeTransitionInfo { s16 newMode; s16 lastMode; s16 max; @@ -486,8 +476,7 @@ struct ModeTransitionInfo /** * A point in a path used by update_parallel_tracking_camera */ -struct ParallelTrackingPoint -{ +struct ParallelTrackingPoint { /// Whether this point is the start of a path s16 startOfPath; /// Point used to define a line segment to follow @@ -501,8 +490,7 @@ struct ParallelTrackingPoint /** * Stores the camera's info */ -struct CameraStoredInfo -{ +struct CameraStoredInfo { /*0x00*/ Vec3f pos; /*0x0C*/ Vec3f focus; /*0x18*/ f32 panDist; @@ -514,8 +502,7 @@ struct CameraStoredInfo * * See the sCutsceneVars[] array in camera.c for more details. */ -struct CutsceneVariable -{ +struct CutsceneVariable { /// Perhaps an index s32 unused1; Vec3f point; @@ -530,8 +517,7 @@ struct CutsceneVariable * update_lakitu, its pos and focus are used to calculate lakitu's next position and focus, which are * then used to render the game. */ -struct Camera -{ +struct Camera { /*0x00*/ u8 mode; // What type of mode the camera uses (see defines above) /*0x01*/ u8 defMode; /** @@ -553,9 +539,9 @@ struct Camera /// For example, this is what makes the camera rotate around the hill in BoB /*0x2C*/ f32 areaCenZ; /*0x30*/ u8 cutscene; - /*0x31*/ u8 filler31[0x8]; + /*0x31*/ u8 filler1[8]; /*0x3A*/ s16 nextYaw; - /*0x3C*/ u8 filler3C[0x28]; + /*0x3C*/ u8 filler2[40]; /*0x64*/ u8 doorStatus; /// The y coordinate of the "center" of the area. Unlike areaCenX and areaCenZ, this is only used /// when paused. See zoom_out_if_paused_and_outside @@ -570,8 +556,7 @@ struct Camera * * @see update_lakitu() */ -struct LakituState -{ +struct LakituState { /** * Lakitu's position, which (when CAM_FLAG_SMOOTH_MOVEMENT is set), approaches his goalPos every frame. */ @@ -591,14 +576,14 @@ struct LakituState */ /*0x24*/ Vec3f goalPos; - /*0x30*/ u8 filler30[12]; // extra unused Vec3f? + /*0x30*/ u8 filler1[12]; // extra unused Vec3f? /// Copy of the active camera mode /*0x3C*/ u8 mode; /// Copy of the default camera mode /*0x3D*/ u8 defMode; - /*0x3E*/ u8 filler3E[10]; + /*0x3E*/ u8 filler2[10]; /*0x48*/ f32 focusDistance; // unused /*0x4C*/ s16 oldPitch; // unused @@ -617,7 +602,7 @@ struct LakituState /*0x60*/ Vec3f unusedVec1; /*0x6C*/ Vec3s unusedVec2; - /*0x72*/ u8 filler72[8]; + /*0x72*/ u8 filler3[8]; /// Used to rotate the screen when rendering. /*0x7A*/ s16 roll; diff --git a/src/game/crash_screen.c b/src/game/crash_screen.c index 5f384de4..64a0f81a 100644 --- a/src/game/crash_screen.c +++ b/src/game/crash_screen.c @@ -17,6 +17,7 @@ u8 gCrashScreenCharToGlyph[128] = { 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, }; +// A height of seven pixels for each Character * nine rows of characters + one row unused. u32 gCrashScreenFont[7 * 9 + 1] = { #include "textures/crash_screen/crash_screen_font.ia1.inc.c" }; @@ -181,12 +182,10 @@ void draw_crash_screen(OSThread *thread) { __OSThreadContext *tc = &thread->context; cause = (tc->cause >> 2) & 0x1f; - if (cause == 23) // EXC_WATCH - { + if (cause == 23) { // EXC_WATCH cause = 16; } - if (cause == 31) // EXC_VCED - { + if (cause == 31) { // EXC_VCED cause = 17; } @@ -300,14 +299,15 @@ void crash_screen_init(void) { gCrashScreen.height = 0x10; #endif osCreateMesgQueue(&gCrashScreen.mesgQueue, &gCrashScreen.mesg, 1); - osCreateThread(&gCrashScreen.thread, 2, thread2_crash_screen, NULL, - (u8 *) gCrashScreen.stack + sizeof(gCrashScreen.stack), + osCreateThread( + &gCrashScreen.thread, 2, thread2_crash_screen, NULL, + (u8 *) gCrashScreen.stack + sizeof(gCrashScreen.stack), #ifdef VERSION_EU - OS_PRIORITY_APPMAX + OS_PRIORITY_APPMAX #else - OS_PRIORITY_RMON + OS_PRIORITY_RMON #endif - ); + ); osStartThread(&gCrashScreen.thread); } diff --git a/src/game/debug.c b/src/game/debug.c index e735035d..c2b71720 100644 --- a/src/game/debug.c +++ b/src/game/debug.c @@ -81,7 +81,7 @@ s64 get_current_clock(void) { return wtf; } -s64 get_clock_difference(UNUSED s64 arg0) { +s64 get_clock_difference(UNUSED s64 cycles) { s64 wtf = 0; return wtf; @@ -113,7 +113,7 @@ void print_text_array_info(s16 *printState, const char *str, s32 number) { || (printState[DEBUG_PSTATE_MAX_X_CURSOR] < printState[DEBUG_PSTATE_Y_CURSOR])) { print_text(printState[DEBUG_PSTATE_X_CURSOR], printState[DEBUG_PSTATE_Y_CURSOR], "DPRINT OVER"); - printState[DEBUG_PSTATE_DISABLED] += 1; // why not just = TRUE... + printState[DEBUG_PSTATE_DISABLED]++; // why not just = TRUE... } else { print_text_fmt_int(printState[DEBUG_PSTATE_X_CURSOR], printState[DEBUG_PSTATE_Y_CURSOR], str, number); @@ -162,13 +162,13 @@ void print_debug_top_down_normal(const char *str, s32 number) { } } -#ifndef VERSION_EU void print_mapinfo(void) { + // EU mostly stubbed this function out. struct Surface *pfloor; - f32 bgY; - f32 water; - s32 area; - s32 angY; + UNUSED f32 bgY; // unused in EU + UNUSED f32 water; // unused in EU + UNUSED s32 area; // unused in EU + UNUSED s32 angY; // unused in EU angY = gCurrentObject->oMoveAngleYaw / 182.044000; area = ((s32) gCurrentObject->oPosX + 0x2000) / 1024 @@ -178,6 +178,7 @@ void print_mapinfo(void) { water = find_water_level(gCurrentObject->oPosX, gCurrentObject->oPosZ); print_debug_top_down_normal("mapinfo", 0); +#ifndef VERSION_EU print_debug_top_down_mapinfo("area %x", area); print_debug_top_down_mapinfo("wx %d", gCurrentObject->oPosX); //! Fat finger: programmer hit tab instead of space. Japanese @@ -188,8 +189,7 @@ void print_mapinfo(void) { print_debug_top_down_mapinfo("bgY %d", bgY); print_debug_top_down_mapinfo("angY %d", angY); - if (pfloor) // not null - { + if (pfloor != NULL) { print_debug_top_down_mapinfo("bgcode %d", pfloor->type); print_debug_top_down_mapinfo("bgstatus %d", pfloor->flags); print_debug_top_down_mapinfo("bgarea %d", pfloor->room); @@ -198,42 +198,8 @@ void print_mapinfo(void) { if (gCurrentObject->oPosY < water) { print_debug_top_down_mapinfo("water %d", water); } -} -#else -void print_mapinfo(void) { - // EU mostly stubbed this function out. - struct Surface *pfloor; - UNUSED f32 bgY; - UNUSED f32 water; - UNUSED s32 area; - // s32 angY; - // - // angY = gCurrentObject->oMoveAngleYaw / 182.044000; - // area = ((s32)gCurrentObject->oPosX + 0x2000) / 1024 - // + ((s32)gCurrentObject->oPosZ + 0x2000) / 1024 * 16; - // - bgY = find_floor(gCurrentObject->oPosX, gCurrentObject->oPosY, gCurrentObject->oPosZ, &pfloor); - water = find_water_level(gCurrentObject->oPosX, gCurrentObject->oPosZ); - - print_debug_top_down_normal("mapinfo", 0); - // print_debug_top_down_mapinfo("area %x", area); - // print_debug_top_down_mapinfo("wx %d", gCurrentObject->oPosX); - // print_debug_top_down_mapinfo("wy\t %d", gCurrentObject->oPosY); - // print_debug_top_down_mapinfo("wz %d", gCurrentObject->oPosZ); - // print_debug_top_down_mapinfo("bgY %d", bgY); - // print_debug_top_down_mapinfo("angY %d", angY); - // - // if(pfloor) // not null - //{ - // print_debug_top_down_mapinfo("bgcode %d", pfloor->type); - // print_debug_top_down_mapinfo("bgstatus %d", pfloor->flags); - // print_debug_top_down_mapinfo("bgarea %d", pfloor->room); - //} - // - // if(gCurrentObject->oPosY < water) - // print_debug_top_down_mapinfo("water %d", water); -} #endif +} void print_checkinfo(void) { print_debug_top_down_normal("checkinfo", 0); @@ -257,7 +223,7 @@ void print_string_array_info(const char **strArr) { s32 i; if (!sDebugStringArrPrinted) { - sDebugStringArrPrinted += 1; // again, why not = TRUE... + sDebugStringArrPrinted++; // again, why not = TRUE... for (i = 0; i < 8; i++) { // sDebugPage is assumed to be 4 or 5 here. print_debug_top_down_mapinfo(strArr[i], gDebugInfo[sDebugPage][i]); @@ -296,7 +262,7 @@ void update_debug_dpadmask(void) { } else { sDebugInfoDPadMask = 0; } - sDebugInfoDPadUpdID += 1; + sDebugInfoDPadUpdID++; if (sDebugInfoDPadUpdID >= 8) { sDebugInfoDPadUpdID = 6; // rapidly set to 6 from 8 as long as dPadMask is being set. } @@ -305,7 +271,7 @@ void update_debug_dpadmask(void) { void debug_unknown_level_select_check(void) { if (!sDebugLvSelectCheckFlag) { - sDebugLvSelectCheckFlag += 1; // again, just do = TRUE... + sDebugLvSelectCheckFlag++; // again, just do = TRUE... if (!gDebugLevelSelect) { gDebugInfoFlags = DEBUG_INFO_NOFLAGS; @@ -337,18 +303,16 @@ void reset_debug_objectinfo(void) { * C Right) and then toggles the debug flags from FF to 2; 2 is unused, * despite so this has no effect, being called. (unused) */ -static void check_debug_button_seq(void) { - s16 *buttonArr; +UNUSED static void check_debug_button_seq(void) { + s16 *buttonArr = sDebugInfoButtonSeq; s16 cButtonMask; - buttonArr = sDebugInfoButtonSeq; - if (!(gPlayer1Controller->buttonDown & L_TRIG)) { sDebugInfoButtonSeqID = 0; } else { if ((s16)(cButtonMask = (gPlayer1Controller->buttonPressed & C_BUTTONS))) { if (buttonArr[sDebugInfoButtonSeqID] == cButtonMask) { - sDebugInfoButtonSeqID += 1; + sDebugInfoButtonSeqID++; if (buttonArr[sDebugInfoButtonSeqID] == -1) { if (gDebugInfoFlags == DEBUG_INFO_FLAG_ALL) { gDebugInfoFlags = DEBUG_INFO_FLAG_LSELECT; @@ -367,15 +331,15 @@ static void check_debug_button_seq(void) { * Poll the debug info flags and controller for appropriate presses that * control sDebugPage's range. (unused) */ -static void try_change_debug_page(void) { +UNUSED static void try_change_debug_page(void) { if (gDebugInfoFlags & DEBUG_INFO_FLAG_DPRINT) { if ((gPlayer1Controller->buttonPressed & L_JPAD) && (gPlayer1Controller->buttonDown & (L_TRIG | R_TRIG))) { - sDebugPage += 1; + sDebugPage++; } if ((gPlayer1Controller->buttonPressed & R_JPAD) && (gPlayer1Controller->buttonDown & (L_TRIG | R_TRIG))) { - sDebugPage -= 1; + sDebugPage--; } if (sDebugPage >= (DEBUG_PAGE_MAX + 1)) { sDebugPage = DEBUG_PAGE_MIN; @@ -392,8 +356,8 @@ static void try_change_debug_page(void) { * sDebugSysCursor. This is used to adjust enemy and effect behaviors * on the fly. (unused) */ -#ifndef VERSION_SH -static +#ifdef VERSION_EU +UNUSED static #endif void try_modify_debug_controls(void) { s32 sp4; @@ -408,14 +372,14 @@ void try_modify_debug_controls(void) { } if (sDebugInfoDPadMask & U_JPAD) { - sDebugSysCursor -= 1; + sDebugSysCursor--; if (sDebugSysCursor < 0) { sDebugSysCursor = 0; } } if (sDebugInfoDPadMask & D_JPAD) { - sDebugSysCursor += 1; + sDebugSysCursor++; if (sDebugSysCursor >= 8) { sDebugSysCursor = 7; } @@ -467,11 +431,11 @@ void try_print_debug_mario_object_info(void) { print_debug_top_down_mapinfo("obj %d", gObjectCounter); - if (gNumFindFloorMisses) { + if (gNumFindFloorMisses != 0) { print_debug_bottom_up("NULLBG %d", gNumFindFloorMisses); } - if (gUnknownWallCount) { + if (gUnknownWallCount != 0) { print_debug_bottom_up("WALL %d", gUnknownWallCount); } } @@ -507,7 +471,7 @@ void try_print_debug_mario_level_info(void) { * [5][7] (b7 in the string array) to 1 to enable debug spawn. */ void try_do_mario_debug_object_spawn(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; if (sDebugPage == DEBUG_PAGE_STAGEINFO && gDebugInfo[DEBUG_PAGE_ENEMYINFO][7] == 1) { if (gPlayer1Controller->buttonPressed & R_JPAD) { @@ -525,9 +489,6 @@ void try_do_mario_debug_object_spawn(void) { } // TODO: figure out what this is -#ifndef VERSION_SH -static -#endif void debug_print_obj_move_flags(void) { #ifndef VERSION_EU // TODO: Is there a better way to diff this? static EU doesn't seem to work. if (gCurrentObject->oMoveFlags & OBJ_MOVE_LANDED) { diff --git a/src/game/envfx_bubbles.c b/src/game/envfx_bubbles.c index 9bc0e6e9..3c1d672a 100644 --- a/src/game/envfx_bubbles.c +++ b/src/game/envfx_bubbles.c @@ -45,10 +45,10 @@ s32 particle_is_laterally_close(s32 index, s32 x, s32 z, s32 distance) { s32 zPos = (gEnvFxBuffer + index)->zPos; if (sqr(xPos - x) + sqr(zPos - z) > sqr(distance)) { - return 0; + return FALSE; } - return 1; + return TRUE; } /** @@ -73,7 +73,7 @@ s32 random_flower_offset(void) { void envfx_update_flower(Vec3s centerPos) { s32 i; struct FloorGeometry *floorGeo; // unused - s32 timer = gGlobalTimer; + s32 globalTimer = gGlobalTimer; s16 centerX = centerPos[0]; UNUSED s16 centerY = centerPos[1]; @@ -81,14 +81,14 @@ void envfx_update_flower(Vec3s centerPos) { for (i = 0; i < sBubbleParticleMaxCount; i++) { (gEnvFxBuffer + i)->isAlive = particle_is_laterally_close(i, centerX, centerZ, 3000); - if ((gEnvFxBuffer + i)->isAlive == 0) { + if (!(gEnvFxBuffer + i)->isAlive) { (gEnvFxBuffer + i)->xPos = random_flower_offset() + centerX; (gEnvFxBuffer + i)->zPos = random_flower_offset() + centerZ; (gEnvFxBuffer + i)->yPos = find_floor_height_and_data((gEnvFxBuffer + i)->xPos, 10000.0f, (gEnvFxBuffer + i)->zPos, &floorGeo); - (gEnvFxBuffer + i)->isAlive = 1; + (gEnvFxBuffer + i)->isAlive = TRUE; (gEnvFxBuffer + i)->animFrame = random_float() * 5.0f; - } else if ((timer & 0x03) == 0) { + } else if (!(globalTimer & 3)) { (gEnvFxBuffer + i)->animFrame += 1; if ((gEnvFxBuffer + i)->animFrame > 5) { (gEnvFxBuffer + i)->animFrame = 0; @@ -109,11 +109,10 @@ void envfx_update_flower(Vec3s centerPos) { void envfx_set_lava_bubble_position(s32 index, Vec3s centerPos) { struct Surface *surface; s16 floorY; - s16 centerX, centerY, centerZ; - centerX = centerPos[0]; - centerY = centerPos[1]; - centerZ = centerPos[2]; + s16 centerX = centerPos[0]; + s16 centerY = centerPos[1]; + s16 centerZ = centerPos[2]; (gEnvFxBuffer + index)->xPos = random_float() * 6000.0f - 3000.0f + centerX; (gEnvFxBuffer + index)->zPos = random_float() * 6000.0f - 3000.0f + centerZ; @@ -152,22 +151,21 @@ void envfx_set_lava_bubble_position(s32 index, Vec3s centerPos) { */ void envfx_update_lava(Vec3s centerPos) { s32 i; - s32 timer = gGlobalTimer; + s32 globalTimer = gGlobalTimer; s8 chance; - UNUSED s16 centerX, centerY, centerZ; - centerX = centerPos[0]; - centerY = centerPos[1]; - centerZ = centerPos[2]; + UNUSED s16 centerX = centerPos[0]; + UNUSED s16 centerY = centerPos[1]; + UNUSED s16 centerZ = centerPos[2]; for (i = 0; i < sBubbleParticleMaxCount; i++) { - if ((gEnvFxBuffer + i)->isAlive == 0) { + if (!(gEnvFxBuffer + i)->isAlive) { envfx_set_lava_bubble_position(i, centerPos); - (gEnvFxBuffer + i)->isAlive = 1; - } else if ((timer & 0x01) == 0) { + (gEnvFxBuffer + i)->isAlive = TRUE; + } else if (!(globalTimer & 1)) { (gEnvFxBuffer + i)->animFrame += 1; if ((gEnvFxBuffer + i)->animFrame > 8) { - (gEnvFxBuffer + i)->isAlive = 0; + (gEnvFxBuffer + i)->isAlive = FALSE; (gEnvFxBuffer + i)->animFrame = 0; } } @@ -205,17 +203,17 @@ void envfx_rotate_around_whirlpool(s32 *x, s32 *y, s32 *z) { * low or close to the center. */ s32 envfx_is_whirlpool_bubble_alive(s32 index) { - s32 UNUSED sp4; + UNUSED u8 filler[4]; if ((gEnvFxBuffer + index)->bubbleY < gEnvFxBubbleConfig[ENVFX_STATE_DEST_Y] - 100) { - return 0; + return FALSE; } if ((gEnvFxBuffer + index)->angleAndDist[1] < 10) { - return 0; + return FALSE; } - return 1; + return TRUE; } /** @@ -227,7 +225,7 @@ void envfx_update_whirlpool(void) { for (i = 0; i < sBubbleParticleMaxCount; i++) { (gEnvFxBuffer + i)->isAlive = envfx_is_whirlpool_bubble_alive(i); - if ((gEnvFxBuffer + i)->isAlive == 0) { + if (!(gEnvFxBuffer + i)->isAlive) { (gEnvFxBuffer + i)->angleAndDist[1] = random_float() * 1000.0f; (gEnvFxBuffer + i)->angleAndDist[0] = random_float() * 65536.0f; (gEnvFxBuffer + i)->xPos = @@ -240,7 +238,7 @@ void envfx_update_whirlpool(void) { gEnvFxBubbleConfig[ENVFX_STATE_SRC_Y] + (random_float() * 100.0f - 50.0f); (gEnvFxBuffer + i)->yPos = (i + gEnvFxBuffer)->bubbleY; (gEnvFxBuffer + i)->unusedBubbleVar = 0; - (gEnvFxBuffer + i)->isAlive = 1; + (gEnvFxBuffer + i)->isAlive = TRUE; envfx_rotate_around_whirlpool(&(gEnvFxBuffer + i)->xPos, &(gEnvFxBuffer + i)->yPos, &(gEnvFxBuffer + i)->zPos); @@ -268,15 +266,15 @@ void envfx_update_whirlpool(void) { * 1000 units away from the source or 1500 units above it. */ s32 envfx_is_jestream_bubble_alive(s32 index) { - UNUSED s32 unk; + UNUSED u8 filler[4]; if (!particle_is_laterally_close(index, gEnvFxBubbleConfig[ENVFX_STATE_SRC_X], gEnvFxBubbleConfig[ENVFX_STATE_SRC_Z], 1000) || gEnvFxBubbleConfig[ENVFX_STATE_SRC_Y] + 1500 < (gEnvFxBuffer + index)->yPos) { - return 0; + return FALSE; } - return 1; + return TRUE; } /** @@ -288,7 +286,7 @@ void envfx_update_jetstream(void) { for (i = 0; i < sBubbleParticleMaxCount; i++) { (gEnvFxBuffer + i)->isAlive = envfx_is_jestream_bubble_alive(i); - if ((gEnvFxBuffer + i)->isAlive == 0) { + if (!(gEnvFxBuffer + i)->isAlive) { (gEnvFxBuffer + i)->angleAndDist[1] = random_float() * 300.0f; (gEnvFxBuffer + i)->angleAndDist[0] = random_u16(); (gEnvFxBuffer + i)->xPos = @@ -318,7 +316,7 @@ s32 envfx_init_bubble(s32 mode) { switch (mode) { case ENVFX_MODE_NONE: - return 0; + return FALSE; case ENVFX_FLOWERS: sBubbleParticleCount = 30; @@ -339,9 +337,10 @@ s32 envfx_init_bubble(s32 mode) { break; } - gEnvFxBuffer = mem_pool_alloc(gEffectsMemoryPool, sBubbleParticleCount * sizeof(struct EnvFxParticle)); - if (!gEnvFxBuffer) { - return 0; + gEnvFxBuffer = mem_pool_alloc(gEffectsMemoryPool, + sBubbleParticleCount * sizeof(struct EnvFxParticle)); + if (gEnvFxBuffer == NULL) { + return FALSE; } bzero(gEnvFxBuffer, sBubbleParticleCount * sizeof(struct EnvFxParticle)); @@ -356,7 +355,7 @@ s32 envfx_init_bubble(s32 mode) { } gEnvFxMode = mode; - return 1; + return TRUE; } /** @@ -473,10 +472,8 @@ Gfx *envfx_update_bubble_particles(s32 mode, UNUSED Vec3s marioPos, Vec3s camFro Vec3s vertex2; Vec3s vertex3; - Gfx *gfxStart; - - gfxStart = alloc_display_list(((sBubbleParticleMaxCount / 5) * 10 + sBubbleParticleMaxCount + 3) - * sizeof(Gfx)); + Gfx *gfxStart = alloc_display_list(((sBubbleParticleMaxCount / 5) * 10 + sBubbleParticleMaxCount + 3) + * sizeof(Gfx)); if (gfxStart == NULL) { return NULL; } @@ -529,7 +526,7 @@ void envfx_set_max_bubble_particles(s32 mode) { Gfx *envfx_update_bubbles(s32 mode, Vec3s marioPos, Vec3s camTo, Vec3s camFrom) { Gfx *gfx; - if (gEnvFxMode == 0 && !envfx_init_bubble(mode)) { + if (gEnvFxMode == ENVFX_MODE_NONE && !envfx_init_bubble(mode)) { return NULL; } diff --git a/src/game/envfx_snow.c b/src/game/envfx_snow.c index 192219db..3b55ced8 100644 --- a/src/game/envfx_snow.c +++ b/src/game/envfx_snow.c @@ -1,6 +1,7 @@ #include #include "sm64.h" +#include "dialog_ids.h" #include "game_init.h" #include "memory.h" #include "ingame_menu.h" @@ -37,7 +38,7 @@ s16 gSnowParticleCount; s16 gSnowParticleMaxCount; /* DATA */ -s8 gEnvFxMode = 0; +s8 gEnvFxMode = ENVFX_MODE_NONE; UNUSED s32 D_80330644 = 0; /// Template for a snow particle triangle @@ -61,7 +62,7 @@ extern void *tiny_bubble_dl_0B006CD8; s32 envfx_init_snow(s32 mode) { switch (mode) { case ENVFX_MODE_NONE: - return 0; + return FALSE; case ENVFX_SNOW_NORMAL: gSnowParticleMaxCount = 140; @@ -79,15 +80,16 @@ s32 envfx_init_snow(s32 mode) { break; } - gEnvFxBuffer = mem_pool_alloc(gEffectsMemoryPool, gSnowParticleMaxCount * sizeof(struct EnvFxParticle)); - if (!gEnvFxBuffer) { - return 0; + gEnvFxBuffer = mem_pool_alloc(gEffectsMemoryPool, + gSnowParticleMaxCount * sizeof(struct EnvFxParticle)); + if (gEnvFxBuffer == NULL) { + return FALSE; } bzero(gEnvFxBuffer, gSnowParticleMaxCount * sizeof(struct EnvFxParticle)); gEnvFxMode = mode; - return 1; + return TRUE; } /** @@ -97,12 +99,13 @@ s32 envfx_init_snow(s32 mode) { * Blizzard snows starts at the maximum amount and doesn't change. */ void envfx_update_snowflake_count(s32 mode, Vec3s marioPos) { - s32 timer = gGlobalTimer; + s32 globalTimer = gGlobalTimer; f32 waterLevel; + switch (mode) { case ENVFX_SNOW_NORMAL: if (gSnowParticleMaxCount > gSnowParticleCount) { - if ((timer & 0x3F) == 0) { + if (!(globalTimer & 63)) { gSnowParticleCount += 5; } } @@ -112,7 +115,7 @@ void envfx_update_snowflake_count(s32 mode, Vec3s marioPos) { waterLevel = find_water_level(marioPos[0], marioPos[2]); gSnowParticleCount = - (((s32)((waterLevel - 400.f - (f32) marioPos[1]) * 1.0e-3) << 0x10) >> 0x10) * 5; + (((s32)((waterLevel - 400.0f - (f32) marioPos[1]) * 0.001) << 0x10) >> 0x10) * 5; if (gSnowParticleCount < 0) { gSnowParticleCount = 0; @@ -134,7 +137,7 @@ void envfx_update_snowflake_count(s32 mode, Vec3s marioPos) { * to none. */ void envfx_cleanup_snow(void *snowParticleArray) { - if (gEnvFxMode) { + if (gEnvFxMode != ENVFX_MODE_NONE) { if (snowParticleArray) { mem_pool_free(gEffectsMemoryPool, snowParticleArray); } @@ -177,14 +180,14 @@ s32 envfx_is_snowflake_alive(s32 index, s32 snowCylinderX, s32 snowCylinderY, s3 s32 z = (gEnvFxBuffer + index)->zPos; if (sqr(x - snowCylinderX) + sqr(z - snowCylinderZ) > sqr(300)) { - return 0; + return FALSE; } if ((y < snowCylinderY - 201) || (snowCylinderY + 201 < y)) { - return 0; + return FALSE; } - return 1; + return TRUE; } /** @@ -210,13 +213,13 @@ void envfx_update_snow_normal(s32 snowCylinderX, s32 snowCylinderY, s32 snowCyli for (i = 0; i < gSnowParticleCount; i++) { (gEnvFxBuffer + i)->isAlive = envfx_is_snowflake_alive(i, snowCylinderX, snowCylinderY, snowCylinderZ); - if ((gEnvFxBuffer + i)->isAlive == 0) { + if (!(gEnvFxBuffer + i)->isAlive) { (gEnvFxBuffer + i)->xPos = 400.0f * random_float() - 200.0f + snowCylinderX + (s16)(deltaX * 2); (gEnvFxBuffer + i)->zPos = 400.0f * random_float() - 200.0f + snowCylinderZ + (s16)(deltaZ * 2); (gEnvFxBuffer + i)->yPos = 200.0f * random_float() + snowCylinderY; - (gEnvFxBuffer + i)->isAlive = 1; + (gEnvFxBuffer + i)->isAlive = TRUE; } else { (gEnvFxBuffer + i)->xPos += random_float() * 2 - 1.0f + (s16)(deltaX / 1.2); (gEnvFxBuffer + i)->yPos -= 2 -(s16)(deltaY * 0.8); @@ -244,13 +247,13 @@ void envfx_update_snow_blizzard(s32 snowCylinderX, s32 snowCylinderY, s32 snowCy for (i = 0; i < gSnowParticleCount; i++) { (gEnvFxBuffer + i)->isAlive = envfx_is_snowflake_alive(i, snowCylinderX, snowCylinderY, snowCylinderZ); - if ((gEnvFxBuffer + i)->isAlive == 0) { + if (!(gEnvFxBuffer + i)->isAlive) { (gEnvFxBuffer + i)->xPos = 400.0f * random_float() - 200.0f + snowCylinderX + (s16)(deltaX * 2); (gEnvFxBuffer + i)->zPos = 400.0f * random_float() - 200.0f + snowCylinderZ + (s16)(deltaZ * 2); (gEnvFxBuffer + i)->yPos = 400.0f * random_float() - 200.0f + snowCylinderY; - (gEnvFxBuffer + i)->isAlive = 1; + (gEnvFxBuffer + i)->isAlive = TRUE; } else { (gEnvFxBuffer + i)->xPos += random_float() * 2 - 1.0f + (s16)(deltaX / 1.2) + 20.0f; (gEnvFxBuffer + i)->yPos -= 5 -(s16)(deltaY * 0.8); @@ -272,11 +275,11 @@ void envfx_update_snow_blizzard(s32 snowCylinderX, s32 snowCylinderY, s32 snowCy * find it. The radius of 3000 units is quite large for that though, covering * more than half of the mirror room. */ -static s32 is_in_mystery_snow_area(s32 x, UNUSED s32 y, s32 z) { +UNUSED static s32 is_in_mystery_snow_area(s32 x, UNUSED s32 y, s32 z) { if (sqr(x - 3380) + sqr(z + 520) < sqr(3000)) { - return 1; + return TRUE; } - return 0; + return FALSE; } /** @@ -289,11 +292,11 @@ void envfx_update_snow_water(s32 snowCylinderX, s32 snowCylinderY, s32 snowCylin for (i = 0; i < gSnowParticleCount; i++) { (gEnvFxBuffer + i)->isAlive = envfx_is_snowflake_alive(i, snowCylinderX, snowCylinderY, snowCylinderZ); - if ((gEnvFxBuffer + i)->isAlive == 0) { + if (!(gEnvFxBuffer + i)->isAlive) { (gEnvFxBuffer + i)->xPos = 400.0f * random_float() - 200.0f + snowCylinderX; (gEnvFxBuffer + i)->zPos = 400.0f * random_float() - 200.0f + snowCylinderZ; (gEnvFxBuffer + i)->yPos = 400.0f * random_float() - 200.0f + snowCylinderY; - (gEnvFxBuffer + i)->isAlive = 1; + (gEnvFxBuffer + i)->isAlive = TRUE; } } } @@ -463,12 +466,12 @@ Gfx *envfx_update_snow(s32 snowMode, Vec3s marioPos, Vec3s camFrom, Vec3s camTo) Gfx *envfx_update_particles(s32 mode, Vec3s marioPos, Vec3s camTo, Vec3s camFrom) { Gfx *gfx; - if (get_dialog_id() != -1) { + if (get_dialog_id() != DIALOG_NONE) { return NULL; } - if (gEnvFxMode != 0 && mode != gEnvFxMode) { - mode = 0; + if (gEnvFxMode != ENVFX_MODE_NONE && gEnvFxMode != mode) { + mode = ENVFX_MODE_NONE; } if (mode >= ENVFX_BUBBLE_START) { @@ -476,7 +479,7 @@ Gfx *envfx_update_particles(s32 mode, Vec3s marioPos, Vec3s camTo, Vec3s camFrom return gfx; } - if (gEnvFxMode == 0 && envfx_init_snow(mode) == 0) { + if (gEnvFxMode == ENVFX_MODE_NONE && !envfx_init_snow(mode)) { return NULL; } diff --git a/src/game/envfx_snow.h b/src/game/envfx_snow.h index 7a83b536..378dae9a 100644 --- a/src/game/envfx_snow.h +++ b/src/game/envfx_snow.h @@ -25,7 +25,7 @@ struct EnvFxParticle { s32 angleAndDist[2]; // for whirpools, [0] = angle from center, [1] = distance from center s32 unusedBubbleVar; // set to zero for bubbles when respawning, never used elsewhere s32 bubbleY; // for Bubbles, yPos is always set to this - s8 filler20[56 - 0x20]; + u8 filler[24]; }; extern s8 gEnvFxMode; @@ -35,7 +35,7 @@ extern struct EnvFxParticle *gEnvFxBuffer; extern Vec3i gSnowCylinderLastPos; extern s16 gSnowParticleCount; -Gfx *envfx_update_particles(s32 snowMode, Vec3s marioPos, Vec3s camTo, Vec3s camFrom); +Gfx *envfx_update_particles(s32 mode, Vec3s marioPos, Vec3s camTo, Vec3s camFrom); void orbit_from_positions(Vec3s from, Vec3s to, s16 *radius, s16 *pitch, s16 *yaw); void rotate_triangle_vertices(Vec3s vertex1, Vec3s vertex2, Vec3s vertex3, s16 pitch, s16 yaw); diff --git a/src/game/game_init.c b/src/game/game_init.c index b6334688..4be1c7b5 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -19,53 +19,72 @@ #include "segment2.h" #include "segment_symbols.h" #include "rumble_init.h" -#include -// FIXME: I'm not sure all of these variables belong in this file, but I don't -// know of a good way to split them +// First 3 controller slots struct Controller gControllers[3]; + +// Gfx handlers struct SPTask *gGfxSPTask; Gfx *gDisplayListHead; u8 *gGfxPoolEnd; struct GfxPool *gGfxPool; + +// OS Controllers OSContStatus gControllerStatuses[4]; OSContPad gControllerPads[4]; u8 gControllerBits; -s8 gEepromProbe; -OSMesgQueue gGameVblankQueue; -OSMesgQueue D_80339CB8; -OSMesg D_80339CD0; -OSMesg D_80339CD4; -struct VblankHandler gGameVblankHandler; -uintptr_t gPhysicalFrameBuffers[3]; -uintptr_t gPhysicalZBuffer; -void *D_80339CF0; -void *D_80339CF4; -struct MarioAnimation D_80339D10; -struct MarioAnimation gDemo; -UNUSED u8 filler80339D30[0x90]; +s8 gEepromProbe; // Save Data Probe -s32 unused8032C690 = 0; +// OS Messages +OSMesgQueue gGameVblankQueue; +OSMesgQueue gGfxVblankQueue; +OSMesg gGameMesgBuf[1]; +OSMesg gGfxMesgBuf[1]; + +// Vblank Handler +struct VblankHandler gGameVblankHandler; + +// Buffers +uintptr_t gPhysicalFramebuffers[3]; +uintptr_t gPhysicalZBuffer; + +// Mario Anims and Demo allocation +void *gMarioAnimsMemAlloc; +void *gDemoInputsMemAlloc; +struct DmaHandlerList gMarioAnimsBuf; +struct DmaHandlerList gDemoInputsBuf; + +// fillers +UNUSED static u8 sfillerGameInit[0x90]; +static s32 sUnusedGameInitValue = 0; + +// General timer that runs as the game starts u32 gGlobalTimer = 0; -static u16 sCurrFBNum = 0; -u16 frameBufferIndex = 0; +// Framebuffer rendering values (max 3) +u16 sRenderedFramebuffer = 0; +u16 sRenderingFramebuffer = 0; + +// Goddard Vblank Function Caller void (*gGoddardVblankCallback)(void) = NULL; + +// Defined controller slots struct Controller *gPlayer1Controller = &gControllers[0]; struct Controller *gPlayer2Controller = &gControllers[1]; -// probably debug only, see note below -struct Controller *gPlayer3Controller = &gControllers[2]; -struct DemoInput *gCurrDemoInput = NULL; // demo input sequence +struct Controller *gPlayer3Controller = &gControllers[2]; // Probably debug only, see note below + +// Title Screen Demo Handler +struct DemoInput *gCurrDemoInput = NULL; u16 gDemoInputListID = 0; -struct DemoInput gRecordedDemoInput = { 0 }; // possibly removed in EU. TODO: Check +struct DemoInput gRecordedDemoInput = { 0 }; + +// Display +// ---------------------------------------------------------------------------------------------------- /** - * Initializes the Reality Display Processor (RDP). - * This function initializes settings such as texture filtering mode, - * scissoring, and render mode (although keep in mind that this render - * mode is not used in-game, where it is set in render_graph_node.c). + * Sets the initial RDP (Reality Display Processor) rendering settings. */ -void my_rdp_init(void) { +void init_rdp(void) { gDPPipeSync(gDisplayListHead++); gDPPipelineMode(gDisplayListHead++, G_PM_1PRIMITIVE); @@ -92,11 +111,9 @@ void my_rdp_init(void) { } /** - * Initializes the RSP's built-in geometry and lighting engines. - * Most of these (with the notable exception of gSPNumLights), are - * almost immediately overwritten. + * Sets the initial RSP (Reality Signal Processor) settings. */ -void my_rsp_init(void) { +void init_rsp(void) { gSPClearGeometryMode(gDisplayListHead++, G_SHADE | G_SHADING_SMOOTH | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR | G_LOD); @@ -105,17 +122,17 @@ void my_rsp_init(void) { gSPNumLights(gDisplayListHead++, NUMLIGHTS_1); gSPTexture(gDisplayListHead++, 0, 0, 0, G_TX_RENDERTILE, G_OFF); - // @bug Nintendo did not explicitly define the clipping ratio. - // For Fast3DEX2, this causes the dreaded warped vertices issue - // unless the clipping ratio is changed back to the intended value, - // as Fast3DEX2 uses a different initial value than Fast3D(EX). + // @bug Failing to set the clip ratio will result in warped triangles in F3DEX2 + // without this change: https://jrra.zone/n64/doc/n64man/gsp/gSPClipRatio.htm #ifdef F3DEX_GBI_2 gSPClipRatio(gDisplayListHead++, FRUSTRATIO_1); #endif } -/** Clear the Z buffer. */ -void clear_z_buffer(void) { +/** + * Initialize the z buffer for the current frame. + */ +void init_z_buffer(void) { gDPPipeSync(gDisplayListHead++); gDPSetDepthSource(gDisplayListHead++, G_ZS_PIXEL); @@ -129,19 +146,24 @@ void clear_z_buffer(void) { SCREEN_HEIGHT - 1 - BORDER_HEIGHT); } -/** Sets up the final framebuffer image. */ -void display_frame_buffer(void) { +/** + * Tells the RDP which of the three framebuffers it shall draw to. + */ +void select_framebuffer(void) { gDPPipeSync(gDisplayListHead++); gDPSetCycleType(gDisplayListHead++, G_CYC_1CYCLE); gDPSetColorImage(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_WIDTH, - gPhysicalFrameBuffers[frameBufferIndex]); + gPhysicalFramebuffers[sRenderingFramebuffer]); gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 0, BORDER_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - BORDER_HEIGHT); } -/** Clears the framebuffer, allowing it to be overwritten. */ -void clear_frame_buffer(s32 color) { +/** + * Clear the framebuffer and fill it with a 32-bit color. + * Information about the color argument: https://jrra.zone/n64/doc/n64man/gdp/gDPSetFillColor.htm + */ +void clear_framebuffer(s32 color) { gDPPipeSync(gDisplayListHead++); gDPSetRenderMode(gDisplayListHead++, G_RM_OPA_SURF, G_RM_OPA_SURF2); @@ -157,7 +179,9 @@ void clear_frame_buffer(s32 color) { gDPSetCycleType(gDisplayListHead++, G_CYC_1CYCLE); } -/** Clears and initializes the viewport. */ +/** + * Resets the viewport, readying it for the final image. + */ void clear_viewport(Vp *viewport, s32 color) { s16 vpUlx = (viewport->vp.vtrans[0] - viewport->vp.vscale[0]) / 4 + 1; s16 vpUly = (viewport->vp.vtrans[1] - viewport->vp.vscale[1]) / 4 + 1; @@ -182,7 +206,9 @@ void clear_viewport(Vp *viewport, s32 color) { gDPSetCycleType(gDisplayListHead++, G_CYC_1CYCLE); } -/** Draws the horizontal screen borders */ +/** + * Draw the horizontal screen borders. + */ void draw_screen_borders(void) { gDPPipeSync(gDisplayListHead++); @@ -201,6 +227,10 @@ void draw_screen_borders(void) { #endif } +/** + * Defines the viewport scissoring rectangle. + * Scissoring: https://jrra.zone/n64/doc/pro-man/pro12/12-03.htm#01 + */ void make_viewport_clip_rect(Vp *viewport) { s16 vpUlx = (viewport->vp.vtrans[0] - viewport->vp.vscale[0]) / 4 + 1; s16 vpPly = (viewport->vp.vtrans[1] - viewport->vp.vscale[1]) / 4 + 1; @@ -211,14 +241,13 @@ void make_viewport_clip_rect(Vp *viewport) { } /** - * Loads the F3D microcodes. - * Refer to this function if you would like to load - * other microcodes (i.e. S2DEX). + * Initializes the Fast3D OSTask structure. + * If you plan on using gSPLoadUcode, make sure to add OS_TASK_LOADABLE to the flags member. */ -void create_task_structure(void) { +void create_gfx_task_structure(void) { s32 entries = gDisplayListHead - gGfxPool->buffer; - gGfxSPTask->msgqueue = &D_80339CB8; + gGfxSPTask->msgqueue = &gGfxVblankQueue; gGfxSPTask->msg = (OSMesg) 2; gGfxSPTask->task.t.type = M_GFXTASK; gGfxSPTask->task.t.ucode_boot = rspF3DBootStart; @@ -239,16 +268,20 @@ void create_task_structure(void) { gGfxSPTask->task.t.yield_data_size = OS_YIELD_DATA_SIZE; } -/** Starts rendering the scene. */ -void init_render_image(void) { +/** + * Set default RCP (Reality Co-Processor) settings. + */ +void init_rcp(void) { move_segment_table_to_dmem(); - my_rdp_init(); - my_rsp_init(); - clear_z_buffer(); - display_frame_buffer(); + init_rdp(); + init_rsp(); + init_z_buffer(); + select_framebuffer(); } -/** Ends the master display list. */ +/** + * End the master display list and initialize the graphics task structure for the next frame to be rendered. + */ void end_master_display_list(void) { draw_screen_borders(); if (gShowProfiler) { @@ -258,94 +291,113 @@ void end_master_display_list(void) { gDPFullSync(gDisplayListHead++); gSPEndDisplayList(gDisplayListHead++); - create_task_structure(); + create_gfx_task_structure(); } +/** + * Draw the bars that appear when the N64 is soft reset. + */ void draw_reset_bars(void) { - s32 sp24; - s32 sp20; + s32 width, height; s32 fbNum; - u64 *sp18; + u64 *fbPtr; - if (gResetTimer != 0 && D_8032C648 < 15) { - if (sCurrFBNum == 0) { + if (gResetTimer != 0 && gNmiResetBarsTimer < 15) { + if (sRenderedFramebuffer == 0) { fbNum = 2; } else { - fbNum = sCurrFBNum - 1; + fbNum = sRenderedFramebuffer - 1; } - sp18 = (u64 *) PHYSICAL_TO_VIRTUAL(gPhysicalFrameBuffers[fbNum]); - sp18 += D_8032C648++ * (SCREEN_WIDTH / 4); + fbPtr = (u64 *) PHYSICAL_TO_VIRTUAL(gPhysicalFramebuffers[fbNum]); + fbPtr += gNmiResetBarsTimer++ * (SCREEN_WIDTH / 4); - for (sp24 = 0; sp24 < ((SCREEN_HEIGHT / 16) + 1); sp24++) { + for (width = 0; width < ((SCREEN_HEIGHT / 16) + 1); width++) { // Loop must be one line to match on -O2 - for (sp20 = 0; sp20 < (SCREEN_WIDTH / 4); sp20++) *sp18++ = 0; - sp18 += ((SCREEN_WIDTH / 4) * 14); + for (height = 0; height < (SCREEN_WIDTH / 4); height++) *fbPtr++ = 0; + fbPtr += ((SCREEN_WIDTH / 4) * 14); } } osWritebackDCacheAll(); - osRecvMesg(&gGameVblankQueue, &D_80339BEC, OS_MESG_BLOCK); - osRecvMesg(&gGameVblankQueue, &D_80339BEC, OS_MESG_BLOCK); + osRecvMesg(&gGameVblankQueue, &gMainReceivedMesg, OS_MESG_BLOCK); + osRecvMesg(&gGameVblankQueue, &gMainReceivedMesg, OS_MESG_BLOCK); } -void rendering_init(void) { +/** + * Initial settings for the first rendered frame. + */ +void render_init(void) { gGfxPool = &gGfxPools[0]; set_segment_base_addr(1, gGfxPool->buffer); gGfxSPTask = &gGfxPool->spTask; gDisplayListHead = gGfxPool->buffer; - gGfxPoolEnd = (u8 *) (gGfxPool->buffer + GFX_POOL_SIZE); - init_render_image(); - clear_frame_buffer(0); + gGfxPoolEnd = (u8 *)(gGfxPool->buffer + GFX_POOL_SIZE); + init_rcp(); + clear_framebuffer(0); end_master_display_list(); - send_display_list(&gGfxPool->spTask); + exec_display_list(&gGfxPool->spTask); - frameBufferIndex++; + sRenderingFramebuffer++; gGlobalTimer++; } -void config_gfx_pool(void) { - gGfxPool = &gGfxPools[gGlobalTimer % 2]; +/** + * Selects the location of the F3D output buffer (gDisplayListHead). + */ +void select_gfx_pool(void) { + gGfxPool = &gGfxPools[gGlobalTimer % ARRAY_COUNT(gGfxPools)]; set_segment_base_addr(1, gGfxPool->buffer); gGfxSPTask = &gGfxPool->spTask; gDisplayListHead = gGfxPool->buffer; gGfxPoolEnd = (u8 *) (gGfxPool->buffer + GFX_POOL_SIZE); } -/** Handles vsync. */ +/** + * This function: + * - Sends the current master display list out to be rendered. + * - Tells the VI which color framebuffer to be displayed. + * - Yields to the VI framerate twice, locking the game at 30 FPS. + * - Selects which framebuffer will be rendered and displayed to next time. + */ void display_and_vsync(void) { profiler_log_thread5_time(BEFORE_DISPLAY_LISTS); - osRecvMesg(&D_80339CB8, &D_80339BEC, OS_MESG_BLOCK); + osRecvMesg(&gGfxVblankQueue, &gMainReceivedMesg, OS_MESG_BLOCK); if (gGoddardVblankCallback != NULL) { gGoddardVblankCallback(); gGoddardVblankCallback = NULL; } - send_display_list(&gGfxPool->spTask); + exec_display_list(&gGfxPool->spTask); profiler_log_thread5_time(AFTER_DISPLAY_LISTS); - osRecvMesg(&gGameVblankQueue, &D_80339BEC, OS_MESG_BLOCK); - osViSwapBuffer((void *) PHYSICAL_TO_VIRTUAL(gPhysicalFrameBuffers[sCurrFBNum])); + osRecvMesg(&gGameVblankQueue, &gMainReceivedMesg, OS_MESG_BLOCK); + osViSwapBuffer((void *) PHYSICAL_TO_VIRTUAL(gPhysicalFramebuffers[sRenderedFramebuffer])); profiler_log_thread5_time(THREAD5_END); - osRecvMesg(&gGameVblankQueue, &D_80339BEC, OS_MESG_BLOCK); - if (++sCurrFBNum == 3) { - sCurrFBNum = 0; + osRecvMesg(&gGameVblankQueue, &gMainReceivedMesg, OS_MESG_BLOCK); + if (++sRenderedFramebuffer == 3) { + sRenderedFramebuffer = 0; } - if (++frameBufferIndex == 3) { - frameBufferIndex = 0; + if (++sRenderingFramebuffer == 3) { + sRenderingFramebuffer = 0; } gGlobalTimer++; } -// this function records distinct inputs over a 255-frame interval to RAM locations and was likely -// used to record the demo sequences seen in the final game. This function is unused. -static void record_demo(void) { - // record the player's button mask and current rawStickX and rawStickY. +// Controls +// ---------------------------------------------------------------------------------------------------- + +/** + * This function records distinct inputs over a 255-frame interval to RAM locations and was likely + * used to record the demo sequences seen in the final game. This function is unused. + */ +UNUSED static void record_demo(void) { + // Record the player's button mask and current rawStickX and rawStickY. u8 buttonMask = ((gPlayer1Controller->buttonDown & (A_BUTTON | B_BUTTON | Z_TRIG | START_BUTTON)) >> 8) | (gPlayer1Controller->buttonDown & (U_CBUTTONS | D_CBUTTONS | L_CBUTTONS | R_CBUTTONS)); s8 rawStickX = gPlayer1Controller->rawStickX; s8 rawStickY = gPlayer1Controller->rawStickY; - // if the stick is in deadzone, set its value to 0 to + // If the stick is in deadzone, set its value to 0 to // nullify the effects. We do not record deadzone inputs. if (rawStickX > -8 && rawStickX < 8) { rawStickX = 0; @@ -355,9 +407,8 @@ static void record_demo(void) { rawStickY = 0; } - // record the distinct input and timer so long as they - // are unique. If the timer hits 0xFF, reset the timer - // for the next demo input. + // Rrecord the distinct input and timer so long as they are unique. + // If the timer hits 0xFF, reset the timer for the next demo input. if (gRecordedDemoInput.timer == 0xFF || buttonMask != gRecordedDemoInput.buttonMask || rawStickX != gRecordedDemoInput.rawStickX || rawStickY != gRecordedDemoInput.rawStickY) { gRecordedDemoInput.timer = 0; @@ -368,16 +419,17 @@ static void record_demo(void) { gRecordedDemoInput.timer++; } -// take the updated controller struct and calculate -// the new x, y, and distance floats. +/** + * Take the updated controller struct and calculate the new x, y, and distance floats. + */ void adjust_analog_stick(struct Controller *controller) { - UNUSED u8 pad[8]; + UNUSED u8 filler[8]; - // reset the controller's x and y floats. + // Reset the controller's x and y floats. controller->stickX = 0; controller->stickY = 0; - // modulate the rawStickX and rawStickY to be the new f32 values by adding/subtracting 6. + // Modulate the rawStickX and rawStickY to be the new f32 values by adding/subtracting 6. if (controller->rawStickX <= -8) { controller->stickX = controller->rawStickX + 6; } @@ -394,12 +446,12 @@ void adjust_analog_stick(struct Controller *controller) { controller->stickY = controller->rawStickY - 6; } - // calculate f32 magnitude from the center by vector length. + // Calculate f32 magnitude from the center by vector length. controller->stickMag = sqrtf(controller->stickX * controller->stickX + controller->stickY * controller->stickY); - // magnitude cannot exceed 64.0f: if it does, modify the values appropriately to - // flatten the values down to the allowed maximum value. + // Magnitude cannot exceed 64.0f: if it does, modify the values + // appropriately to flatten the values down to the allowed maximum value. if (controller->stickMag > 64) { controller->stickX *= 64 / controller->stickMag; controller->stickY *= 64 / controller->stickMag; @@ -407,64 +459,56 @@ void adjust_analog_stick(struct Controller *controller) { } } -// if a demo sequence exists, this will run the demo -// input list until it is complete. called every frame. +/** + * If a demo sequence exists, this will run the demo input list until it is complete. + */ void run_demo_inputs(void) { - // eliminate the unused bits. + // Eliminate the unused bits. gControllers[0].controllerData->button &= VALID_BUTTONS; - /* - Check if a demo inputs list - exists and if so, run the - active demo input list. - */ + // Check if a demo inputs list exists and if so, + // run the active demo input list. if (gCurrDemoInput != NULL) { - /* - clear player 2's inputs if they exist. Player 2's controller - cannot be used to influence a demo. At some point, Nintendo - may have planned for there to be a demo where 2 players moved - around instead of just one, so clearing player 2's influence from - the demo had to have been necessary to perform this. Co-op mode, perhaps? - */ + // Clear player 2's inputs if they exist. Player 2's controller + // cannot be used to influence a demo. At some point, Nintendo + // may have planned for there to be a demo where 2 players moved + // around instead of just one, so clearing player 2's influence from + // the demo had to have been necessary to perform this. Co-op mode, perhaps? if (gControllers[1].controllerData != NULL) { gControllers[1].controllerData->stick_x = 0; gControllers[1].controllerData->stick_y = 0; gControllers[1].controllerData->button = 0; } - // the timer variable being 0 at the current input means the demo is over. - // set the button to the END_DEMO mask to end the demo. + // The timer variable being 0 at the current input means the demo is over. + // Set the button to the END_DEMO mask to end the demo. if (gCurrDemoInput->timer == 0) { gControllers[0].controllerData->stick_x = 0; gControllers[0].controllerData->stick_y = 0; gControllers[0].controllerData->button = END_DEMO; } else { - // backup the start button if it is pressed, since we don't want the + // Backup the start button if it is pressed, since we don't want the // demo input to override the mask where start may have been pressed. u16 startPushed = gControllers[0].controllerData->button & START_BUTTON; - // perform the demo inputs by assigning the current button mask and the stick inputs. + // Perform the demo inputs by assigning the current button mask and the stick inputs. gControllers[0].controllerData->stick_x = gCurrDemoInput->rawStickX; gControllers[0].controllerData->stick_y = gCurrDemoInput->rawStickY; - /* - to assign the demo input, the button information is stored in - an 8-bit mask rather than a 16-bit mask. this is because only - A, B, Z, Start, and the C-Buttons are used in a demo, as bits - in that order. In order to assign the mask, we need to take the - upper 4 bits (A, B, Z, and Start) and shift then left by 8 to - match the correct input mask. We then add this to the masked - lower 4 bits to get the correct button mask. - */ + // To assign the demo input, the button information is stored in + // an 8-bit mask rather than a 16-bit mask. this is because only + // A, B, Z, Start, and the C-Buttons are used in a demo, as bits + // in that order. In order to assign the mask, we need to take the + // upper 4 bits (A, B, Z, and Start) and shift then left by 8 to + // match the correct input mask. We then add this to the masked + // lower 4 bits to get the correct button mask. gControllers[0].controllerData->button = ((gCurrDemoInput->buttonMask & 0xF0) << 8) + ((gCurrDemoInput->buttonMask & 0xF)); - // if start was pushed, put it into the demo sequence being input to - // end the demo. + // If start was pushed, put it into the demo sequence being input to end the demo. gControllers[0].controllerData->button |= startPushed; - // run the current demo input's timer down. if it hits 0, advance the - // demo input list. + // Run the current demo input's timer down. if it hits 0, advance the demo input list. if (--gCurrDemoInput->timer == 0) { gCurrDemoInput++; } @@ -472,16 +516,17 @@ void run_demo_inputs(void) { } } -// update the controller struct with available inputs if present. +/** + * Update the controller struct with available inputs if present. + */ void read_controller_inputs(void) { s32 i; - // if any controllers are plugged in, update the - // controller information. + // If any controllers are plugged in, update the controller information. if (gControllerBits) { - osRecvMesg(&gSIEventMesgQueue, &D_80339BEC, OS_MESG_BLOCK); + osRecvMesg(&gSIEventMesgQueue, &gMainReceivedMesg, OS_MESG_BLOCK); osContGetReadData(&gControllerPads[0]); -#ifdef VERSION_SH +#if ENABLE_RUMBLE release_rumble_pak_control(); #endif } @@ -490,8 +535,7 @@ void read_controller_inputs(void) { for (i = 0; i < 2; i++) { struct Controller *controller = &gControllers[i]; - // if we're receiving inputs, update the controller struct - // with the new button info. + // if we're receiving inputs, update the controller struct with the new button info. if (controller->controllerData != NULL) { controller->rawStickX = controller->controllerData->stick_x; controller->rawStickY = controller->controllerData->stick_y; @@ -500,8 +544,7 @@ void read_controller_inputs(void) { // 0.5x A presses are a good meme controller->buttonDown = controller->controllerData->button; adjust_analog_stick(controller); - } else // otherwise, if the controllerData is NULL, 0 out all of the inputs. - { + } else { // otherwise, if the controllerData is NULL, 0 out all of the inputs. controller->rawStickX = 0; controller->rawStickY = 0; controller->buttonPressed = 0; @@ -512,9 +555,9 @@ void read_controller_inputs(void) { } } - // For some reason, player 1's inputs are copied to player 3's port. This - // potentially may have been a way the developers "recorded" the inputs - // for demos, despite record_demo existing. + // For some reason, player 1's inputs are copied to player 3's port. + // This potentially may have been a way the developers "recorded" + // the inputs for demos, despite record_demo existing. gPlayer3Controller->rawStickX = gPlayer1Controller->rawStickX; gPlayer3Controller->rawStickY = gPlayer1Controller->rawStickY; gPlayer3Controller->stickX = gPlayer1Controller->stickX; @@ -524,33 +567,35 @@ void read_controller_inputs(void) { gPlayer3Controller->buttonDown = gPlayer1Controller->buttonDown; } -// initialize the controller structs to point at the OSCont information. +/** + * Initialize the controller structs to point at the OSCont information. + */ void init_controllers(void) { s16 port, cont; - // set controller 1 to point to the set of status/pads for input 1 and + // Set controller 1 to point to the set of status/pads for input 1 and // init the controllers. gControllers[0].statusData = &gControllerStatuses[0]; gControllers[0].controllerData = &gControllerPads[0]; osContInit(&gSIEventMesgQueue, &gControllerBits, &gControllerStatuses[0]); - // strangely enough, the EEPROM probe for save data is done in this function. - // save pak detection? + // Strangely enough, the EEPROM probe for save data is done in this function. + // Save Pak detection? gEepromProbe = osEepromProbe(&gSIEventMesgQueue); - // loop over the 4 ports and link the controller structs to the appropriate + // Loop over the 4 ports and link the controller structs to the appropriate // status and pad. Interestingly, although there are pointers to 3 controllers, // only 2 are connected here. The third seems to have been reserved for debug // purposes and was never connected in the retail ROM, thus gPlayer3Controller // cannot be used, despite being referenced in various code. for (cont = 0, port = 0; port < 4 && cont < 2; port++) { - // is controller plugged in? + // Is controller plugged in? if (gControllerBits & (1 << port)) { - // the game allows you to have just 1 controller plugged + // The game allows you to have just 1 controller plugged // into any port in order to play the game. this was probably // so if any of the ports didn't work, you can have controllers // plugged into any of them and it will work. -#ifdef VERSION_SH +#if ENABLE_RUMBLE gControllers[cont].port = port; #endif gControllers[cont].statusData = &gControllerStatuses[port]; @@ -559,69 +604,83 @@ void init_controllers(void) { } } -void setup_game_memory(void) { - UNUSED u8 pad[8]; +// Game thread core +// ---------------------------------------------------------------------------------------------------- +/** + * Setup main segments and framebuffers. + */ +void setup_game_memory(void) { + UNUSED u8 filler[8]; + + // Setup general Segment 0 set_segment_base_addr(0, (void *) 0x80000000); - osCreateMesgQueue(&D_80339CB8, &D_80339CD4, 1); - osCreateMesgQueue(&gGameVblankQueue, &D_80339CD0, 1); + // Create Mesg Queues + osCreateMesgQueue(&gGfxVblankQueue, gGfxMesgBuf, ARRAY_COUNT(gGfxMesgBuf)); + osCreateMesgQueue(&gGameVblankQueue, gGameMesgBuf, ARRAY_COUNT(gGameMesgBuf)); + // Setup z buffer and framebuffer gPhysicalZBuffer = VIRTUAL_TO_PHYSICAL(gZBuffer); - gPhysicalFrameBuffers[0] = VIRTUAL_TO_PHYSICAL(gFrameBuffer0); - gPhysicalFrameBuffers[1] = VIRTUAL_TO_PHYSICAL(gFrameBuffer1); - gPhysicalFrameBuffers[2] = VIRTUAL_TO_PHYSICAL(gFrameBuffer2); - D_80339CF0 = main_pool_alloc(0x4000, MEMORY_POOL_LEFT); - set_segment_base_addr(17, (void *) D_80339CF0); - func_80278A78(&D_80339D10, gMarioAnims, D_80339CF0); - D_80339CF4 = main_pool_alloc(2048, MEMORY_POOL_LEFT); - set_segment_base_addr(24, (void *) D_80339CF4); - func_80278A78(&gDemo, gDemoInputs, D_80339CF4); + gPhysicalFramebuffers[0] = VIRTUAL_TO_PHYSICAL(gFramebuffer0); + gPhysicalFramebuffers[1] = VIRTUAL_TO_PHYSICAL(gFramebuffer1); + gPhysicalFramebuffers[2] = VIRTUAL_TO_PHYSICAL(gFramebuffer2); + // Setup Mario Animations + gMarioAnimsMemAlloc = main_pool_alloc(0x4000, MEMORY_POOL_LEFT); + set_segment_base_addr(17, (void *) gMarioAnimsMemAlloc); + setup_dma_table_list(&gMarioAnimsBuf, gMarioAnims, gMarioAnimsMemAlloc); + // Setup Demo Inputs List + gDemoInputsMemAlloc = main_pool_alloc(0x800, MEMORY_POOL_LEFT); + set_segment_base_addr(24, (void *) gDemoInputsMemAlloc); + setup_dma_table_list(&gDemoInputsBuf, gDemoInputs, gDemoInputsMemAlloc); + // Setup Level Script Entry load_segment(0x10, _entrySegmentRomStart, _entrySegmentRomEnd, MEMORY_POOL_LEFT); + // Setup Segment 2 (Fonts, Text, etc) load_segment_decompress(2, _segment2_mio0SegmentRomStart, _segment2_mio0SegmentRomEnd); } -// main game loop thread. runs forever as long as the game -// continues. +/** + * Main game loop thread. Runs forever as long as the game continues. + */ void thread5_game_loop(UNUSED void *arg) { struct LevelCommand *addr; setup_game_memory(); -#ifdef VERSION_SH +#if ENABLE_RUMBLE init_rumble_pak_scheduler_queue(); #endif init_controllers(); -#ifdef VERSION_SH +#if ENABLE_RUMBLE create_thread_6(); #endif save_file_load_all(); set_vblank_handler(2, &gGameVblankHandler, &gGameVblankQueue, (OSMesg) 1); - // point addr to the entry point into the level script data. + // Point address to the entry point into the level script data. addr = segmented_to_virtual(level_script_entry); play_music(SEQ_PLAYER_SFX, SEQUENCE_ARGS(0, SEQ_SOUND_PLAYER), 0); set_sound_mode(save_file_get_sound_mode()); - rendering_init(); + render_init(); while (TRUE) { - // if the reset timer is active, run the process to reset the game. - if (gResetTimer) { + // If the reset timer is active, run the process to reset the game. + if (gResetTimer != 0) { draw_reset_bars(); continue; } profiler_log_thread5_time(THREAD5_START); - // if any controllers are plugged in, start read the data for when + // If any controllers are plugged in, start read the data for when // read_controller_inputs is called later. if (gControllerBits) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE block_until_rumble_pak_free(); #endif osContStartReadData(&gSIEventMesgQueue); } audio_game_loop_tick(); - config_gfx_pool(); + select_gfx_pool(); read_controller_inputs(); addr = level_script_execute(addr); diff --git a/src/game/game_init.h b/src/game/game_init.h index 454686ad..4ab929e0 100644 --- a/src/game/game_init.h +++ b/src/game/game_init.h @@ -9,15 +9,14 @@ #include "types.h" #include "memory.h" -#define GFX_POOL_SIZE 6400 +#define GFX_POOL_SIZE 6400 // Size of how large the master display list (gDisplayListHead) can be struct GfxPool { Gfx buffer[GFX_POOL_SIZE]; struct SPTask spTask; }; -struct DemoInput -{ +struct DemoInput { u8 timer; // time until next input. if this value is 0, it means the demo is over s8 rawStickX; s8 rawStickY; @@ -28,14 +27,14 @@ extern struct Controller gControllers[3]; extern OSContStatus gControllerStatuses[4]; extern OSContPad gControllerPads[4]; extern OSMesgQueue gGameVblankQueue; -extern OSMesgQueue D_80339CB8; -extern OSMesg D_80339CD0; -extern OSMesg D_80339CD4; +extern OSMesgQueue gGfxVblankQueue; +extern OSMesg gGameMesgBuf[1]; +extern OSMesg gGfxMesgBuf[1]; extern struct VblankHandler gGameVblankHandler; -extern uintptr_t gPhysicalFrameBuffers[3]; +extern uintptr_t gPhysicalFramebuffers[3]; extern uintptr_t gPhysicalZBuffer; -extern void *D_80339CF0; -extern void *D_80339CF4; +extern void *gMarioAnimsMemAlloc; +extern void *gDemoInputsMemAlloc; extern struct SPTask *gGfxSPTask; extern Gfx *gDisplayListHead; extern u8 *gGfxPoolEnd; @@ -53,24 +52,24 @@ extern struct DemoInput gRecordedDemoInput; // this area is the demo input + the header. when the demo is loaded in, there is a header the size // of a single word next to the input list. this word is the current ID count. -extern struct MarioAnimation D_80339D10; -extern struct MarioAnimation gDemo; +extern struct DmaHandlerList gMarioAnimsBuf; +extern struct DmaHandlerList gDemoInputsBuf; extern u8 gMarioAnims[]; extern u8 gDemoInputs[]; -extern u16 frameBufferIndex; +extern u16 sRenderingFramebuffer; extern u32 gGlobalTimer; void setup_game_memory(void); void thread5_game_loop(UNUSED void *arg); -void clear_frame_buffer(s32 color); +void clear_framebuffer(s32 color); void clear_viewport(Vp *viewport, s32 color); void make_viewport_clip_rect(Vp *viewport); -void init_render_image(void); +void init_rcp(void); void end_master_display_list(void); -void rendering_init(void); -void config_gfx_pool(void); +void render_init(void); +void select_gfx_pool(void); void display_and_vsync(void); #endif // GAME_INIT_H diff --git a/src/game/geo_misc.h b/src/game/geo_misc.h index 904633af..c43b4305 100644 --- a/src/game/geo_misc.h +++ b/src/game/geo_misc.h @@ -4,8 +4,7 @@ #include #include -enum FlyingCarpetState -{ +enum FlyingCarpetState { FLYING_CARPET_IDLE = 0, FLYING_CARPET_MOVING_WITHOUT_MARIO = 1, FLYING_CARPET_MOVING_WITH_MARIO = 2 diff --git a/src/game/hud.c b/src/game/hud.c index 8d4daa54..5a0f6806 100644 --- a/src/game/hud.c +++ b/src/game/hud.c @@ -53,7 +53,7 @@ static struct PowerMeterHUD sPowerMeterHUD = { // when the power meter is hidden. s32 sPowerMeterVisibleTimer = 0; -static struct UnusedHUDStruct sUnusedHUDValues = { 0x00, 0x0A, 0x00 }; +UNUSED static struct UnusedHUDStruct sUnusedHUDValues = { 0x00, 0x0A, 0x00 }; static struct CameraHUD sCameraHUD = { CAM_STATUS_NONE }; @@ -90,9 +90,7 @@ void render_hud_small_tex_lut(s32 x, s32 y, u8 *texture) { * Renders power meter health segment texture using a table list. */ void render_power_meter_health_segment(s16 numHealthWedges) { - u8 *(*healthLUT)[]; - - healthLUT = segmented_to_virtual(&power_meter_health_segments_lut); + u8 *(*healthLUT)[] = segmented_to_virtual(&power_meter_health_segments_lut); gDPPipeSync(gDisplayListHead++); gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_16b, 1, @@ -108,9 +106,7 @@ void render_power_meter_health_segment(s16 numHealthWedges) { * That includes the "POWER" base and the colored health segment textures. */ void render_dl_power_meter(s16 numHealthWedges) { - Mtx *mtx; - - mtx = alloc_display_list(sizeof(Mtx)); + Mtx *mtx = alloc_display_list(sizeof(Mtx)); if (mtx == NULL) { return; @@ -136,8 +132,7 @@ void render_dl_power_meter(s16 numHealthWedges) { * Checks its timer to later change into deemphasizing mode. */ void animate_power_meter_emphasized(void) { - s16 hudDisplayFlags; - hudDisplayFlags = gHudDisplay.flags; + s16 hudDisplayFlags = gHudDisplay.flags; if (!(hudDisplayFlags & HUD_DISPLAY_FLAG_EMPHASIZE_POWER)) { if (sPowerMeterVisibleTimer == 45.0) { @@ -155,21 +150,21 @@ void animate_power_meter_emphasized(void) { static void animate_power_meter_deemphasizing(void) { s16 speed = 5; - if (sPowerMeterHUD.y >= 181) { + if (sPowerMeterHUD.y > 180) { speed = 3; } - if (sPowerMeterHUD.y >= 191) { + if (sPowerMeterHUD.y > 190) { speed = 2; } - if (sPowerMeterHUD.y >= 196) { + if (sPowerMeterHUD.y > 195) { speed = 1; } sPowerMeterHUD.y += speed; - if (sPowerMeterHUD.y >= 201) { + if (sPowerMeterHUD.y > 200) { sPowerMeterHUD.y = 200; sPowerMeterHUD.animation = POWER_METER_VISIBLE; } @@ -181,7 +176,7 @@ static void animate_power_meter_deemphasizing(void) { */ static void animate_power_meter_hiding(void) { sPowerMeterHUD.y += 20; - if (sPowerMeterHUD.y >= 301) { + if (sPowerMeterHUD.y > 300) { sPowerMeterHUD.animation = POWER_METER_HIDDEN; sPowerMeterVisibleTimer = 0; } @@ -192,7 +187,8 @@ static void animate_power_meter_hiding(void) { */ void handle_power_meter_actions(s16 numHealthWedges) { // Show power meter if health is not full, less than 8 - if (numHealthWedges < 8 && sPowerMeterStoredHealth == 8 && sPowerMeterHUD.animation == POWER_METER_HIDDEN) { + if (numHealthWedges < 8 && sPowerMeterStoredHealth == 8 + && sPowerMeterHUD.animation == POWER_METER_HIDDEN) { sPowerMeterHUD.animation = POWER_METER_EMPHASIZED; sPowerMeterHUD.y = 166; } @@ -253,7 +249,7 @@ void render_hud_power_meter(void) { render_dl_power_meter(shownHealthWedges); - sPowerMeterVisibleTimer += 1; + sPowerMeterVisibleTimer++; } #ifdef VERSION_JP @@ -293,7 +289,7 @@ void render_hud_coins(void) { void render_hud_stars(void) { s8 showX = 0; - if (gHudFlash == 1 && gGlobalTimer & 0x08) { + if (gHudFlash == 1 && gGlobalTimer & 8) { return; } @@ -325,14 +321,12 @@ void render_hud_keys(void) { * Renders the timer when Mario start sliding in PSS. */ void render_hud_timer(void) { - u8 *(*hudLUT)[58]; - u16 timerValFrames; - u16 timerMins; - u16 timerSecs; - u16 timerFracSecs; + u8 *(*hudLUT)[58] = segmented_to_virtual(&main_hud_lut); + u16 timerValFrames = gHudDisplay.timer; + u16 timerMins = timerValFrames / (30 * 60); + u16 timerSecs = (timerValFrames - (timerMins * 1800)) / 30; + u16 timerFracSecs = ((timerValFrames - (timerMins * 1800) - (timerSecs * 30)) & 0xFFFF) / 3; - hudLUT = segmented_to_virtual(&main_hud_lut); - timerValFrames = gHudDisplay.timer; #ifdef VERSION_EU switch (eu_get_language()) { case LANGUAGE_ENGLISH: @@ -345,17 +339,14 @@ void render_hud_timer(void) { print_text(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(150), 185, "ZEIT"); break; } -#endif - timerMins = timerValFrames / (30 * 60); - timerSecs = (timerValFrames - (timerMins * 1800)) / 30; - - timerFracSecs = ((timerValFrames - (timerMins * 1800) - (timerSecs * 30)) & 0xFFFF) / 3; -#ifndef VERSION_EU +#else print_text(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(150), 185, "TIME"); #endif + print_text_fmt_int(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(91), 185, "%0d", timerMins); print_text_fmt_int(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(71), 185, "%02d", timerSecs); print_text_fmt_int(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(37), 185, "%d", timerFracSecs); + gSPDisplayList(gDisplayListHead++, dl_hud_img_begin); render_hud_tex_lut(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(81), 32, (*hudLUT)[GLYPH_APOSTROPHE]); render_hud_tex_lut(GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(46), 32, (*hudLUT)[GLYPH_DOUBLE_QUOTE]); @@ -375,13 +366,9 @@ void set_hud_camera_status(s16 status) { * the camera status called, a defined glyph is rendered. */ void render_hud_camera_status(void) { - u8 *(*cameraLUT)[6]; - s32 x; - s32 y; - - cameraLUT = segmented_to_virtual(&main_hud_camera_lut); - x = GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(54); - y = 205; + u8 *(*cameraLUT)[6] = segmented_to_virtual(&main_hud_camera_lut); + s32 x = GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(54); + s32 y = 205; if (sCameraHUD.status == CAM_STATUS_NONE) { return; @@ -419,12 +406,7 @@ void render_hud_camera_status(void) { * excluding the cannon reticle which detects a camera preset for it. */ void render_hud(void) { - s16 hudDisplayFlags; -#ifdef VERSION_EU - Mtx *mtx; -#endif - - hudDisplayFlags = gHudDisplay.flags; + s16 hudDisplayFlags = gHudDisplay.flags; if (hudDisplayFlags == HUD_DISPLAY_NONE) { sPowerMeterHUD.animation = POWER_METER_HIDDEN; @@ -433,16 +415,17 @@ void render_hud(void) { } else { #ifdef VERSION_EU // basically create_dl_ortho_matrix but guOrtho screen width is different + Mtx *mtx = alloc_display_list(sizeof(*mtx)); - mtx = alloc_display_list(sizeof(*mtx)); if (mtx == NULL) { return; } + create_dl_identity_matrix(); guOrtho(mtx, -16.0f, SCREEN_WIDTH + 16, 0, SCREEN_HEIGHT, -10.0f, 10.0f, 1.0f); gSPPerspNormalize(gDisplayListHead++, 0xFFFF); gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(mtx), - G_MTX_PROJECTION | G_MTX_MUL | G_MTX_NOPUSH); + G_MTX_PROJECTION | G_MTX_MUL | G_MTX_NOPUSH); #else create_dl_ortho_matrix(); #endif diff --git a/src/game/ingame_menu.c b/src/game/ingame_menu.c index 8190f88d..5c74037f 100644 --- a/src/game/ingame_menu.c +++ b/src/game/ingame_menu.c @@ -23,13 +23,18 @@ #include "text_strings.h" #include "types.h" +#ifdef VERSION_EU +#undef LANGUAGE_FUNCTION +#define LANGUAGE_FUNCTION gInGameLanguage +#endif + u16 gDialogColorFadeTimer; s8 gLastDialogLineNum; s32 gDialogVariable; u16 gDialogTextAlpha; #if defined(VERSION_EU) -s16 gDialogX; // D_8032F69A -s16 gDialogY; // D_8032F69C +s16 gDialogX; +s16 gDialogY; #endif s16 gCutsceneMsgXOffset; s16 gCutsceneMsgYOffset; @@ -56,8 +61,6 @@ enum DialogBoxType { DIALOG_TYPE_ZOOM // used in signposts and wall signs and etc }; -enum DialogMark { DIALOG_MARK_NONE = 0, DIALOG_MARK_DAKUTEN = 1, DIALOG_MARK_HANDAKUTEN = 2 }; - #define DEFAULT_DIALOG_BOX_ANGLE 90.0f #define DEFAULT_DIALOG_BOX_SCALE 19.0f @@ -99,17 +102,17 @@ f32 gDialogBoxOpenTimer = DEFAULT_DIALOG_BOX_ANGLE; f32 gDialogBoxScale = DEFAULT_DIALOG_BOX_SCALE; s16 gDialogScrollOffsetY = 0; s8 gDialogBoxType = DIALOG_TYPE_ROTATE; -s16 gDialogID = -1; +s16 gDialogID = DIALOG_NONE; s16 gLastDialogPageStrPos = 0; s16 gDialogTextPos = 0; #ifdef VERSION_EU -s32 gInGameLanguage = 0; +s32 gInGameLanguage = LANGUAGE_ENGLISH; #endif s8 gDialogLineNum = 1; s8 gLastDialogResponse = 0; u8 gMenuHoldKeyIndex = 0; u8 gMenuHoldKeyTimer = 0; -s32 gDialogResponse = 0; +s32 gDialogResponse = DIALOG_RESPONSE_NONE; void create_dl_identity_matrix(void) { @@ -141,11 +144,13 @@ void create_dl_translation_matrix(s8 pushOp, f32 x, f32 y, f32 z) { guTranslate(matrix, x, y, z); - if (pushOp == MENU_MTX_PUSH) + if (pushOp == MENU_MTX_PUSH) { gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_PUSH); + } - if (pushOp == MENU_MTX_NOPUSH) + if (pushOp == MENU_MTX_NOPUSH) { gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); + } } void create_dl_rotation_matrix(s8 pushOp, f32 a, f32 x, f32 y, f32 z) { @@ -157,11 +162,13 @@ void create_dl_rotation_matrix(s8 pushOp, f32 a, f32 x, f32 y, f32 z) { guRotate(matrix, a, x, y, z); - if (pushOp == MENU_MTX_PUSH) + if (pushOp == MENU_MTX_PUSH) { gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_PUSH); + } - if (pushOp == MENU_MTX_NOPUSH) + if (pushOp == MENU_MTX_NOPUSH) { gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); + } } void create_dl_scale_matrix(s8 pushOp, f32 x, f32 y, f32 z) { @@ -173,11 +180,13 @@ void create_dl_scale_matrix(s8 pushOp, f32 x, f32 y, f32 z) { guScale(matrix, x, y, z); - if (pushOp == MENU_MTX_PUSH) + if (pushOp == MENU_MTX_PUSH) { gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_PUSH); + } - if (pushOp == MENU_MTX_NOPUSH) + if (pushOp == MENU_MTX_NOPUSH) { gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH); + } } void create_dl_ortho_matrix(void) { @@ -197,13 +206,16 @@ void create_dl_ortho_matrix(void) { gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(matrix), G_MTX_PROJECTION | G_MTX_MUL | G_MTX_NOPUSH) } +#if defined(VERSION_US) || defined(VERSION_EU) +UNUSED +#endif static u8 *alloc_ia8_text_from_i1(u16 *in, s16 width, s16 height) { s32 inPos; u16 bitMask; u8 *out; s16 outPos = 0; - out = alloc_display_list((u32) width * (u32) height); + out = (u8 *) alloc_display_list((u32) width * (u32) height); if (out == NULL) { return NULL; @@ -228,24 +240,18 @@ static u8 *alloc_ia8_text_from_i1(u16 *in, s16 width, s16 height) { } void render_generic_char(u8 c) { - void **fontLUT; - void *packedTexture; + void **fontLUT = segmented_to_virtual(main_font_lut); + void *packedTexture = segmented_to_virtual(fontLUT[c]); #if defined(VERSION_JP) || defined(VERSION_SH) - void *unpackedTexture; + void *unpackedTexture = alloc_ia8_text_from_i1(packedTexture, 8, 16); #endif - fontLUT = segmented_to_virtual(main_font_lut); - packedTexture = segmented_to_virtual(fontLUT[c]); - -#if defined(VERSION_JP) || defined(VERSION_SH) - unpackedTexture = alloc_ia8_text_from_i1(packedTexture, 8, 16); - +#ifndef VERSION_EU gDPPipeSync(gDisplayListHead++); +#endif +#if defined(VERSION_JP) || defined(VERSION_SH) gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_8b, 1, VIRTUAL_TO_PHYSICAL(unpackedTexture)); #else -#ifdef VERSION_US - gDPPipeSync(gDisplayListHead++); -#endif gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_16b, 1, VIRTUAL_TO_PHYSICAL(packedTexture)); #endif gSPDisplayList(gDisplayListHead++, dl_ia_text_tex_settings); @@ -260,10 +266,9 @@ u8 *alloc_ia4_tex_from_i1(u8 *in, s16 width, s16 height) { u32 size = (u32) width * (u32) height; u8 *out; s32 inPos; - s16 outPos; + s16 outPos = 0; u8 bitMask; - outPos = 0; out = (u8 *) alloc_display_list(size); if (out == NULL) { @@ -272,6 +277,7 @@ u8 *alloc_ia4_tex_from_i1(u8 *in, s16 width, s16 height) { for (inPos = 0; inPos < (width * height) / 4; inPos++) { bitMask = 0x80; + while (bitMask != 0) { out[outPos] = (in[inPos] & bitMask) ? 0xF0 : 0x00; bitMask /= 2; @@ -285,13 +291,9 @@ u8 *alloc_ia4_tex_from_i1(u8 *in, s16 width, s16 height) { } void render_generic_char_at_pos(s16 xPos, s16 yPos, u8 c) { - void **fontLUT; - void *packedTexture; - void *unpackedTexture; - - fontLUT = segmented_to_virtual(main_font_lut); - packedTexture = segmented_to_virtual(fontLUT[c]); - unpackedTexture = alloc_ia4_tex_from_i1(packedTexture, 8, 8); + void **fontLUT = segmented_to_virtual(main_font_lut); + void *packedTexture = segmented_to_virtual(fontLUT[c]); + void *unpackedTexture = alloc_ia4_tex_from_i1(packedTexture, 8, 8); gDPPipeSync(gDisplayListHead++); gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_16b, 1, VIRTUAL_TO_PHYSICAL(unpackedTexture)); @@ -313,7 +315,7 @@ void render_uppercase_diacritic(s16 *xPos, s16 *yPos, u8 letter, u8 diacritic) { } #endif // VERSION_EU -#if !defined(VERSION_JP) && !defined(VERSION_SH) +#if defined(VERSION_US) || defined(VERSION_EU) struct MultiTextEntry { u8 length; u8 str[4]; @@ -329,7 +331,7 @@ enum MultiStringIDs { STRING_THE, STRING_YOU }; * 0: 'the' * 1: 'you' */ -#ifdef VERSION_US +#if defined(VERSION_US) void render_multi_text_string(s8 multiTextID) #elif defined(VERSION_EU) void render_multi_text_string(s16 *xPos, s16 *yPos, s8 multiTextID) @@ -342,9 +344,10 @@ void render_multi_text_string(s16 *xPos, s16 *yPos, s8 multiTextID) }; for (i = 0; i < textLengths[multiTextID].length; i++) { -#ifdef VERSION_US +#if defined(VERSION_US) render_generic_char(textLengths[multiTextID].str[i]); - create_dl_translation_matrix(MENU_MTX_NOPUSH, (f32)(gDialogCharWidths[textLengths[multiTextID].str[i]]), 0.0f, 0.0f); + create_dl_translation_matrix( + MENU_MTX_NOPUSH, (f32)(gDialogCharWidths[textLengths[multiTextID].str[i]]), 0.0f, 0.0f); #elif defined(VERSION_EU) render_generic_char_at_pos(*xPos, *yPos, textLengths[multiTextID].str[i]); *xPos += gDialogCharWidths[textLengths[multiTextID].str[i]]; @@ -354,9 +357,13 @@ void render_multi_text_string(s16 *xPos, s16 *yPos, s8 multiTextID) #endif #if defined(VERSION_JP) || defined(VERSION_SH) -#define MAX_STRING_WIDTH 18 + #define MAX_STRING_WIDTH 18 + #define CHAR_WIDTH_SPACE 5.0f + #define CHAR_WIDTH_DEFAULT 10.0f #else -#define MAX_STRING_WIDTH 16 + #define MAX_STRING_WIDTH 16 + #define CHAR_WIDTH_SPACE (f32)(gDialogCharWidths[DIALOG_CHAR_SPACE]) + #define CHAR_WIDTH_DEFAULT (f32)(gDialogCharWidths[str[strPos]]) #endif /** @@ -444,12 +451,14 @@ void print_generic_string(s16 x, s16 y, const u8 *str) { gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); break; #endif -#if !defined(VERSION_JP) && !defined(VERSION_SH) + +#if defined(VERSION_US) || defined(VERSION_EU) case DIALOG_CHAR_SLASH: -#ifdef VERSION_US - create_dl_translation_matrix(MENU_MTX_NOPUSH, (f32)(gDialogCharWidths[DIALOG_CHAR_SPACE] * 2), 0.0f, 0.0f); -#elif defined(VERSION_EU) +#ifdef VERSION_EU xCoord += gDialogCharWidths[DIALOG_CHAR_SPACE] * 2; +#else + create_dl_translation_matrix( + MENU_MTX_NOPUSH, (f32)(gDialogCharWidths[DIALOG_CHAR_SPACE] * 2), 0.0f, 0.0f); #endif break; case DIALOG_CHAR_MULTI_THE: @@ -467,36 +476,33 @@ void print_generic_string(s16 x, s16 y, const u8 *str) { #endif break; #endif + #ifndef VERSION_EU case DIALOG_CHAR_SPACE: -#if defined(VERSION_JP) || defined(VERSION_SH) - create_dl_translation_matrix(MENU_MTX_NOPUSH, 5.0f, 0.0f, 0.0f); + create_dl_translation_matrix(MENU_MTX_NOPUSH, CHAR_WIDTH_SPACE, 0.0f, 0.0f); break; -#else - create_dl_translation_matrix(MENU_MTX_NOPUSH, (f32)(gDialogCharWidths[DIALOG_CHAR_SPACE]), 0.0f, 0.0f); -#endif -#endif +#ifdef VERSION_JP break; // ? needed to match +#endif +#endif + default: #ifdef VERSION_EU render_generic_char_at_pos(xCoord, yCoord, str[strPos]); xCoord += gDialogCharWidths[str[strPos]]; - break; #else render_generic_char(str[strPos]); if (mark != DIALOG_MARK_NONE) { create_dl_translation_matrix(MENU_MTX_PUSH, 5.0f, 5.0f, 0.0f); - render_generic_char(mark + 0xEF); + render_generic_char(DIALOG_CHAR_MARK_START + mark); gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); mark = DIALOG_MARK_NONE; } -#if defined(VERSION_JP) || defined(VERSION_SH) - create_dl_translation_matrix(MENU_MTX_NOPUSH, 10.0f, 0.0f, 0.0f); -#else - create_dl_translation_matrix(MENU_MTX_NOPUSH, (f32)(gDialogCharWidths[str[strPos]]), 0.0f, 0.0f); - break; // what an odd difference. US added a useless break here. + create_dl_translation_matrix(MENU_MTX_NOPUSH, CHAR_WIDTH_DEFAULT, 0.0f, 0.0f); #endif +#ifndef VERSION_JP + break; // what an odd difference. US (and probably later) versions added a useless break here. #endif } @@ -651,7 +657,7 @@ void print_menu_generic_string(s16 x, s16 y, const u8 *str) { #ifndef VERSION_EU if (mark != DIALOG_MARK_NONE) { - gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_8b, 1, fontLUT[mark + 0xEF]); + gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_8b, 1, fontLUT[DIALOG_CHAR_MARK_START + mark]); gDPLoadSync(gDisplayListHead++); gDPLoadBlock(gDisplayListHead++, G_TX_LOADTILE, 0, 0, 8 * 8 - 1, CALC_DXT(8, G_IM_SIZ_8b_BYTES)); gSPTextureRectangle(gDisplayListHead++, (curX + 6) << 2, (curY - 7) << 2, @@ -724,21 +730,21 @@ void handle_menu_scrolling(s8 scrollDirection, s8 *currentIndex, s8 minIndex, s8 } if (((index ^ gMenuHoldKeyIndex) & index) == 2) { - if (currentIndex[0] == maxIndex) { + if (*currentIndex == maxIndex) { //! Probably originally a >=, but later replaced with an == and an else statement. - currentIndex[0] = maxIndex; + *currentIndex = maxIndex; } else { play_sound(SOUND_MENU_CHANGE_SELECT, gGlobalSoundSource); - currentIndex[0]++; + (*currentIndex)++; } } if (((index ^ gMenuHoldKeyIndex) & index) == 1) { - if (currentIndex[0] == minIndex) { + if (*currentIndex == minIndex) { // Same applies to here as above } else { play_sound(SOUND_MENU_CHANGE_SELECT, gGlobalSoundSource); - currentIndex[0]--; + (*currentIndex)--; } } @@ -756,7 +762,7 @@ void handle_menu_scrolling(s8 scrollDirection, s8 *currentIndex, s8 minIndex, s8 } // EU has both get_str_x_pos_from_center and get_str_x_pos_from_center_scale -// US and JP only implement one or the other +// JP, US and Shindou only implement one or the other #if defined(VERSION_US) || defined(VERSION_EU) s16 get_str_x_pos_from_center(s16 centerPos, u8 *str, UNUSED f32 scale) { s16 strPos = 0; @@ -794,7 +800,7 @@ s16 get_str_x_pos_from_center_scale(s16 centerPos, u8 *str, f32 scale) { } #endif -#if !defined(VERSION_JP) && !defined(VERSION_SH) +#if defined(VERSION_US) || defined(VERSION_EU) s16 get_string_width(u8 *str) { s16 strPos = 0; s16 width = 0; @@ -810,14 +816,14 @@ s16 get_string_width(u8 *str) { u8 gHudSymCoin[] = { GLYPH_COIN, GLYPH_SPACE }; u8 gHudSymX[] = { GLYPH_MULTIPLY, GLYPH_SPACE }; -void print_hud_my_score_coins(s32 useCourseCoinScore, s8 fileNum, s8 courseNum, s16 x, s16 y) { +void print_hud_my_score_coins(s32 useCourseCoinScore, s8 fileIndex, s8 courseIndex, s16 x, s16 y) { u8 strNumCoins[4]; s16 numCoins; if (!useCourseCoinScore) { - numCoins = (u16)(save_file_get_max_coin_score(courseNum) & 0xFFFF); + numCoins = (u16)(save_file_get_max_coin_score(courseIndex) & 0xFFFF); } else { - numCoins = save_file_get_course_coin_score(fileNum, courseNum); + numCoins = save_file_get_course_coin_score(fileIndex, courseIndex); } if (numCoins != 0) { @@ -828,14 +834,14 @@ void print_hud_my_score_coins(s32 useCourseCoinScore, s8 fileNum, s8 courseNum, } } -void print_hud_my_score_stars(s8 fileNum, s8 courseNum, s16 x, s16 y) { +void print_hud_my_score_stars(s8 fileIndex, s8 courseIndex, s16 x, s16 y) { u8 strStarCount[4]; s16 starCount; u8 textSymStar[] = { GLYPH_STAR, GLYPH_SPACE }; UNUSED u16 unused; u8 textSymX[] = { GLYPH_MULTIPLY, GLYPH_SPACE }; - starCount = save_file_get_course_star_count(fileNum, courseNum); + starCount = save_file_get_course_star_count(fileIndex, courseIndex); if (starCount != 0) { print_hud_lut_string(HUD_LUT_GLOBAL, x, y, textSymStar); @@ -878,14 +884,14 @@ s16 get_dialog_id(void) { } void create_dialog_box(s16 dialog) { - if (gDialogID == -1) { + if (gDialogID == DIALOG_NONE) { gDialogID = dialog; gDialogBoxType = DIALOG_TYPE_ROTATE; } } void create_dialog_box_with_var(s16 dialog, s32 dialogVar) { - if (gDialogID == -1) { + if (gDialogID == DIALOG_NONE) { gDialogID = dialog; gDialogVariable = dialogVar; gDialogBoxType = DIALOG_TYPE_ROTATE; @@ -893,14 +899,14 @@ void create_dialog_box_with_var(s16 dialog, s32 dialogVar) { } void create_dialog_inverted_box(s16 dialog) { - if (gDialogID == -1) { + if (gDialogID == DIALOG_NONE) { gDialogID = dialog; gDialogBoxType = DIALOG_TYPE_ZOOM; } } void create_dialog_box_with_response(s16 dialog) { - if (gDialogID == -1) { + if (gDialogID == DIALOG_NONE) { gDialogID = dialog; gDialogBoxType = DIALOG_TYPE_ROTATE; gLastDialogResponse = 1; @@ -917,25 +923,25 @@ void reset_dialog_render_state(void) { gDialogBoxScale = 19.0f; gDialogBoxOpenTimer = 90.0f; gDialogBoxState = DIALOG_STATE_OPENING; - gDialogID = -1; + gDialogID = DIALOG_NONE; gDialogTextPos = 0; gLastDialogResponse = 0; gLastDialogPageStrPos = 0; - gDialogResponse = 0; + gDialogResponse = DIALOG_RESPONSE_NONE; } #if defined(VERSION_JP) || defined(VERSION_SH) -#define X_VAL1 -5.0f -#define Y_VAL1 2.0 -#define Y_VAL2 4 + #define X_VAL1 -5.0f + #define Y_VAL1 2.0 + #define Y_VAL2 4 #else -#define X_VAL1 -7.0f -#define Y_VAL1 5.0 -#define Y_VAL2 5.0f + #define X_VAL1 -7.0f + #define Y_VAL1 5.0 + #define Y_VAL2 5.0f #endif void render_dialog_box_type(struct DialogEntry *dialog, s8 linesPerBox) { - UNUSED s32 unused; + UNUSED u8 filler[4]; create_dl_translation_matrix(MENU_MTX_NOPUSH, dialog->leftOffset, dialog->width, 0); @@ -992,26 +998,16 @@ void change_and_flash_dialog_text_color_lines(s8 colorMode, s8 lineNum) { #ifdef VERSION_EU void render_generic_dialog_char_at_pos(struct DialogEntry *dialog, s16 x, s16 y, u8 c) { - s16 width; - s16 height; - s16 tmpX; - s16 tmpY; - s16 xCoord; - s16 yCoord; - void **fontLUT; - void *packedTexture; - void *unpackedTexture; + s16 width = (8.0 - (gDialogBoxScale * 0.8)); + s16 height = (16.0 - (gDialogBoxScale * 0.8)); + s16 tmpX = (dialog->leftOffset + (65.0 - (65.0 / gDialogBoxScale))); + s16 tmpY = ((240 - dialog->width) - ((40.0 / gDialogBoxScale) - 40)); + s16 xCoord = (tmpX + (x / gDialogBoxScale)); + s16 yCoord = (tmpY + (y / gDialogBoxScale)); - width = (8.0 - (gDialogBoxScale * 0.8)); - height = (16.0 - (gDialogBoxScale * 0.8)); - tmpX = (dialog->leftOffset + (65.0 - (65.0 / gDialogBoxScale))); - tmpY = ((240 - dialog->width) - ((40.0 / gDialogBoxScale) - 40)); - xCoord = (tmpX + (x / gDialogBoxScale)); - yCoord = (tmpY + (y / gDialogBoxScale)); - - fontLUT = segmented_to_virtual(main_font_lut); - packedTexture = segmented_to_virtual(fontLUT[c]); - unpackedTexture = alloc_ia4_tex_from_i1(packedTexture, 8, 8); + void **fontLUT = segmented_to_virtual(main_font_lut); + void *packedTexture = segmented_to_virtual(fontLUT[c]); + void *unpackedTexture = alloc_ia4_tex_from_i1(packedTexture, 8, 8); gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_IA, G_IM_SIZ_16b, 1, VIRTUAL_TO_PHYSICAL(unpackedTexture)); gSPDisplayList(gDisplayListHead++, dl_ia_text_tex_settings); @@ -1021,11 +1017,11 @@ void render_generic_dialog_char_at_pos(struct DialogEntry *dialog, s16 x, s16 y, #endif #if defined(VERSION_JP) || defined(VERSION_SH) -#define X_VAL3 5.0f -#define Y_VAL3 20 + #define X_VAL3 5.0f + #define Y_VAL3 20 #else -#define X_VAL3 0.0f -#define Y_VAL3 16 + #define X_VAL3 0.0f + #define Y_VAL3 16 #endif #ifdef VERSION_EU @@ -1039,7 +1035,7 @@ void handle_dialog_scroll_page_state(s8 lineNum, s8 totalLines, s8 *pageState, s #endif if (lineNum == totalLines) { - pageState[0] = DIALOG_PAGE_STATE_SCROLL; + *pageState = DIALOG_PAGE_STATE_SCROLL; return; } #ifdef VERSION_EU @@ -1047,15 +1043,15 @@ void handle_dialog_scroll_page_state(s8 lineNum, s8 totalLines, s8 *pageState, s #else create_dl_translation_matrix(MENU_MTX_PUSH, X_VAL3, 2 - (lineNum * Y_VAL3), 0); - linePos[0] = 0; + *linePos = 0; #endif - xMatrix[0] = 1; + *xMatrix = 1; } #if defined(VERSION_JP) || defined(VERSION_SH) void adjust_pos_and_print_period_char(s8 *xMatrix, s16 *linePos) { - if (linePos[0] != 0) { - create_dl_translation_matrix(MENU_MTX_NOPUSH, xMatrix[0] * 10, 0, 0); + if (*linePos != 0) { + create_dl_translation_matrix(MENU_MTX_NOPUSH, 10 * *xMatrix, 0, 0); } create_dl_translation_matrix(MENU_MTX_PUSH, -2.0f, -5.0f, 0); @@ -1063,8 +1059,8 @@ void adjust_pos_and_print_period_char(s8 *xMatrix, s16 *linePos) { gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); - linePos[0]++; - xMatrix[0] = 1; + (*linePos)++; + *xMatrix = 1; } #endif @@ -1079,57 +1075,57 @@ void render_star_count_dialog_text(s8 *xMatrix, s16 *linePos) if (tensDigit != 0) { #if defined(VERSION_JP) || defined(VERSION_SH) - create_dl_translation_matrix(MENU_MTX_NOPUSH, xMatrix[0] * 10, 0, 0); + create_dl_translation_matrix(MENU_MTX_NOPUSH, 10 * *xMatrix, 0, 0); render_generic_char(tensDigit); -#elif defined(VERSION_EU) - render_generic_dialog_char_at_pos(dialog, gDialogX, gDialogY, tensDigit); - gDialogX += gDialogCharWidths[tensDigit]; - linePos[0] = 1; -#else - if (xMatrix[0] != 1) { - create_dl_translation_matrix(MENU_MTX_NOPUSH, (f32)(gDialogCharWidths[DIALOG_CHAR_SPACE] * xMatrix[0]), 0, 0); +#elif defined(VERSION_US) + if (*xMatrix != 1) { + create_dl_translation_matrix( + MENU_MTX_NOPUSH, (f32)(gDialogCharWidths[DIALOG_CHAR_SPACE] * *xMatrix), 0, 0); } render_generic_char(tensDigit); create_dl_translation_matrix(MENU_MTX_NOPUSH, (f32) gDialogCharWidths[tensDigit], 0, 0); - xMatrix[0] = 1; - linePos[0]++; + *xMatrix = 1; + (*linePos)++; +#elif defined(VERSION_EU) + render_generic_dialog_char_at_pos(dialog, gDialogX, gDialogY, tensDigit); + gDialogX += gDialogCharWidths[tensDigit]; + *linePos = 1; #endif } #ifndef VERSION_EU else { #if defined(VERSION_JP) || defined(VERSION_SH) - xMatrix[0]++; + (*xMatrix)++; #endif } #endif -#ifdef VERSION_EU - render_generic_dialog_char_at_pos(dialog, gDialogX, gDialogY, onesDigit); - gDialogX += gDialogCharWidths[onesDigit]; - linePos[0] = 1; -#else - +#ifndef VERSION_EU #if defined(VERSION_JP) || defined(VERSION_SH) - create_dl_translation_matrix(MENU_MTX_NOPUSH, xMatrix[0] * 10, 0, 0); + create_dl_translation_matrix(MENU_MTX_NOPUSH, 10 * *xMatrix, 0, 0); render_generic_char(onesDigit); -#else - if (xMatrix[0] != 1) { - create_dl_translation_matrix(MENU_MTX_NOPUSH, (f32)(gDialogCharWidths[DIALOG_CHAR_SPACE] * (xMatrix[0] - 1)), 0, 0); +#elif defined(VERSION_US) + if (*xMatrix != 1) { + create_dl_translation_matrix( + MENU_MTX_NOPUSH, (f32)(gDialogCharWidths[DIALOG_CHAR_SPACE] * (*xMatrix - 1)), 0, 0); } render_generic_char(onesDigit); create_dl_translation_matrix(MENU_MTX_NOPUSH, (f32) gDialogCharWidths[onesDigit], 0, 0); #endif - - linePos[0]++; - xMatrix[0] = 1; + (*linePos)++; + *xMatrix = 1; +#else // VERSION_EU + render_generic_dialog_char_at_pos(dialog, gDialogX, gDialogY, onesDigit); + gDialogX += gDialogCharWidths[onesDigit]; + *linePos = 1; #endif } -#if !defined(VERSION_JP) && !defined(VERSION_SH) +#if defined(VERSION_US) || defined(VERSION_EU) #ifdef VERSION_EU -void render_multi_text_string_lines(s8 multiTextId, s8 lineNum, s8 linesPerBox, UNUSED s16 linePos, s8 lowerBound, struct DialogEntry *dialog) +void render_multi_text_string_lines(s8 multiTextId, s8 lineNum, s8 linesPerBox, UNUSED s8 xMatrix, s8 lowerBound, struct DialogEntry *dialog) #else void render_multi_text_string_lines(s8 multiTextId, s8 lineNum, s16 *linePos, s8 linesPerBox, s8 xMatrix, s8 lowerBound) #endif @@ -1142,8 +1138,9 @@ void render_multi_text_string_lines(s8 multiTextId, s8 lineNum, s16 *linePos, s8 if (lineNum >= lowerBound && lineNum <= (lowerBound + linesPerBox)) { #ifdef VERSION_US - if (linePos[0] != 0 || (xMatrix != 1)) { - create_dl_translation_matrix(MENU_MTX_NOPUSH, (gDialogCharWidths[DIALOG_CHAR_SPACE] * (xMatrix - 1)), 0, 0); + if (*linePos != 0 || xMatrix != 1) { + create_dl_translation_matrix( + MENU_MTX_NOPUSH, (gDialogCharWidths[DIALOG_CHAR_SPACE] * (xMatrix - 1)), 0, 0); } #endif for (i = 0; i < textLengths[multiTextId].length; i++) { @@ -1152,10 +1149,12 @@ void render_multi_text_string_lines(s8 multiTextId, s8 lineNum, s16 *linePos, s8 gDialogX += gDialogCharWidths[textLengths[multiTextId].str[i]]; #else render_generic_char(textLengths[multiTextId].str[i]); - create_dl_translation_matrix(MENU_MTX_NOPUSH, (gDialogCharWidths[textLengths[multiTextId].str[i]]), 0, 0); + create_dl_translation_matrix( + MENU_MTX_NOPUSH, (gDialogCharWidths[textLengths[multiTextId].str[i]]), 0, 0); #endif } } + #ifdef VERSION_US linePos += textLengths[multiTextId].length; #endif @@ -1184,30 +1183,24 @@ u32 ensure_nonnegative(s16 value) { return value; } -#if defined(VERSION_JP) +#ifdef VERSION_JP void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog) #else void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 lowerBound) #endif { - UNUSED s32 pad[2]; + UNUSED u8 filler[8]; #ifdef VERSION_EU s16 startY = 14; #endif - u8 strChar; - u8 *str = segmented_to_virtual(dialog->str); s8 lineNum = 1; - s8 totalLines; - s8 pageState = DIALOG_PAGE_STATE_NONE; - UNUSED s8 mark = DIALOG_MARK_NONE; // unused in US, EU + UNUSED s8 mark = DIALOG_MARK_NONE; // unused in US and EU s8 xMatrix = 1; - s8 linesPerBox = dialog->linesPerBox; - s16 strIdx; #ifndef VERSION_EU s16 linePos = 0; @@ -1222,7 +1215,9 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l } gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); + strIdx = gDialogTextPos; + #ifdef VERSION_EU gDialogX = 0; gDialogY = startY; @@ -1259,10 +1254,11 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l #else handle_dialog_scroll_page_state(lineNum, totalLines, &pageState, &xMatrix, &linePos); #ifdef VERSION_SH - mark = 0; + mark = DIALOG_MARK_NONE; #endif #endif break; + #ifdef VERSION_EU case DIALOG_CHAR_LOWER_A_GRAVE: case DIALOG_CHAR_LOWER_A_CIRCUMFLEX: @@ -1316,6 +1312,7 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l mark = DIALOG_MARK_HANDAKUTEN; break; #endif + case DIALOG_CHAR_SPACE: #ifdef VERSION_EU gDialogX += gDialogCharWidths[DIALOG_CHAR_SPACE]; @@ -1328,9 +1325,9 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l } #endif linePos++; - #endif break; + #if defined(VERSION_JP) || defined(VERSION_SH) case DIALOG_CHAR_PERIOD: adjust_pos_and_print_period_char(&xMatrix, &linePos); @@ -1361,6 +1358,7 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l xMatrix = 1; break; #endif + case DIALOG_CHAR_STAR_COUNT: #ifdef VERSION_EU render_star_count_dialog_text(dialog, &xMatrix); @@ -1368,37 +1366,39 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l render_star_count_dialog_text(&xMatrix, &linePos); #endif break; + #ifdef VERSION_EU case DIALOG_CHAR_DOUBLE_LOW_QUOTE: render_generic_dialog_char_at_pos(dialog, gDialogX, gDialogY + 8, 0xF6); gDialogX += gDialogCharWidths[0xF6]; break; #endif + default: // any other character #if defined(VERSION_JP) || defined(VERSION_SH) #ifdef VERSION_SH - if (lineNum >= lowerBound && lineNum <= lowerBound + linesPerBox) { + if (lineNum >= lowerBound && lineNum <= (lowerBound + linesPerBox)) { #endif if (linePos != 0) { - create_dl_translation_matrix(MENU_MTX_NOPUSH, xMatrix * 10, 0, 0); + create_dl_translation_matrix(MENU_MTX_NOPUSH, 10 * xMatrix, 0, 0); } render_generic_char(strChar); xMatrix = 1; linePos++; - if (mark != 0) { + if (mark != DIALOG_MARK_NONE) { create_dl_translation_matrix(MENU_MTX_PUSH, 5.0f, 7.0f, 0); - render_generic_char(mark + 0xEF); + render_generic_char(DIALOG_CHAR_MARK_START + mark); gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); - mark = 0; + mark = DIALOG_MARK_NONE; } #ifdef VERSION_SH } #endif #elif defined(VERSION_US) - if (lineNum >= lowerBound && lineNum <= lowerBound + linesPerBox) { - if (linePos || xMatrix != 1) { + if (lineNum >= lowerBound && lineNum <= (lowerBound + linesPerBox)) { + if (linePos != 0 || xMatrix != 1) { create_dl_translation_matrix( MENU_MTX_NOPUSH, (f32)(gDialogCharWidths[DIALOG_CHAR_SPACE] * (xMatrix - 1)), 0, 0); } @@ -1409,14 +1409,14 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l linePos++; } #else // VERSION_EU - if (lineNum >= lowerBound && lineNum <= lowerBound + linesPerBox) { + if (lineNum >= lowerBound && lineNum <= (lowerBound + linesPerBox)) { render_generic_dialog_char_at_pos(dialog, gDialogX, gDialogY, strChar); } gDialogX += gDialogCharWidths[strChar]; #endif } -#if defined(VERSION_JP) +#ifdef VERSION_JP if (linePos == 12) { if (str[strIdx + 1] == DIALOG_CHAR_PERIOD) { adjust_pos_and_print_period_char(&xMatrix, &linePos); @@ -1424,7 +1424,7 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l } if (str[strIdx + 1] == DIALOG_CHAR_COMMA) { - create_dl_translation_matrix(MENU_MTX_NOPUSH, xMatrix * 10, 0, 0); + create_dl_translation_matrix(MENU_MTX_NOPUSH, 10 * xMatrix, 0, 0); render_generic_char(DIALOG_CHAR_COMMA); strIdx++; } @@ -1446,6 +1446,7 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l strIdx++; } + gSPDisplayList(gDisplayListHead++, dl_ia_text_end); if (gDialogBoxState == DIALOG_STATE_VERTICAL) { @@ -1460,15 +1461,15 @@ void handle_dialog_text_and_pages(s8 colorMode, struct DialogEntry *dialog, s8 l } #if defined(VERSION_JP) || defined(VERSION_SH) -#define X_VAL4_1 50 -#define X_VAL4_2 25 -#define Y_VAL4_1 1 -#define Y_VAL4_2 20 + #define X_VAL4_1 50 + #define X_VAL4_2 25 + #define Y_VAL4_1 1 + #define Y_VAL4_2 20 #else -#define X_VAL4_1 56 -#define X_VAL4_2 47 -#define Y_VAL4_1 2 -#define Y_VAL4_2 16 + #define X_VAL4_1 56 + #define X_VAL4_2 47 + #define Y_VAL4_1 2 + #define Y_VAL4_2 16 #endif void render_dialog_triangle_choice(void) { @@ -1487,27 +1488,27 @@ void render_dialog_triangle_choice(void) { gSPDisplayList(gDisplayListHead++, dl_draw_triangle); } -#ifdef VERSION_EU -#define X_VAL5 122.0f -#define Y_VAL5_1 -16 -#define Y_VAL5_2 3 -#define X_Y_VAL6 0.5f +#if defined(VERSION_JP) || defined(VERSION_SH) + #define X_VAL5 123.0f + #define Y_VAL5_1 -20 + #define Y_VAL5_2 2 + #define X_Y_VAL6 0.8f #elif defined(VERSION_US) -#define X_VAL5 118.0f -#define Y_VAL5_1 -16 -#define Y_VAL5_2 5 -#define X_Y_VAL6 0.8f -#elif defined(VERSION_JP) || defined(VERSION_SH) -#define X_VAL5 123.0f -#define Y_VAL5_1 -20 -#define Y_VAL5_2 2 -#define X_Y_VAL6 0.8f + #define X_VAL5 118.0f + #define Y_VAL5_1 -16 + #define Y_VAL5_2 5 + #define X_Y_VAL6 0.8f +#elif defined(VERSION_EU) + #define X_VAL5 122.0f + #define Y_VAL5_1 -16 + #define Y_VAL5_2 3 + #define X_Y_VAL6 0.5f #endif -void render_dialog_string_color(s8 linesPerBox) { - s32 timer = gGlobalTimer; +void render_dialog_triangle_next(s8 linesPerBox) { + s32 globalTimer = gGlobalTimer; - if (timer & 0x08) { + if (globalTimer & 8) { return; } @@ -1527,18 +1528,18 @@ void render_dialog_string_color(s8 linesPerBox) { void handle_special_dialog_text(s16 dialogID) { // dialog ID tables, in order // King Bob-omb (Start), Whomp (Start), King Bob-omb (throw him out), Eyerock (Start), Wiggler (Start) - s16 dialogBossStart[] = { 17, 114, 128, 117, 150 }; - // Koopa the Quick (BOB), Koopa the Quick (THI), Penguin Race, Fat Penguin Race (120 stars) - s16 dialogRaceSound[] = { 5, 9, 55, 164 }; + s16 dialogBossStart[] = { DIALOG_017, DIALOG_114, DIALOG_128, DIALOG_117, DIALOG_150 }; + // Koopa the Quick (BoB), Koopa the Quick (THI), Penguin Race, Fat Penguin Race (120 stars) + s16 dialogRaceSound[] = { DIALOG_005, DIALOG_009, DIALOG_055, DIALOG_164 }; // Red Switch, Green Switch, Blue Switch, 100 coins star, Bowser Red Coin Star - s16 dialogStarSound[] = { 10, 11, 12, 13, 14 }; + s16 dialogStarSound[] = { DIALOG_010, DIALOG_011, DIALOG_012, DIALOG_013, DIALOG_014 }; // King Bob-omb (Start), Whomp (Defeated), King Bob-omb (Defeated, missing in JP), Eyerock (Defeated), Wiggler (Defeated) #if BUGFIX_KING_BOB_OMB_FADE_MUSIC - s16 dialogBossStop[] = { 17, 115, 116, 118, 152 }; + s16 dialogBossStop[] = { DIALOG_017, DIALOG_115, DIALOG_116, DIALOG_118, DIALOG_152 }; #else - //! @bug JP misses King Bob-omb defeated dialog "116", meaning that the boss music will still - //! play after King Bob-omb is defeated until BOB loads it's music after the star cutscene - s16 dialogBossStop[] = { 17, 115, 118, 152 }; + //! @bug JP misses King Bob-omb defeated DIALOG_116, meaning that the boss music will still + //! play after King Bob-omb is defeated until BoB loads it's music after the star cutscene + s16 dialogBossStop[] = { DIALOG_017, DIALOG_115, DIALOG_118, DIALOG_152 }; #endif s16 i; @@ -1572,7 +1573,7 @@ void handle_special_dialog_text(s16 dialogID) { // dialog ID tables, in order } } -s16 gMenuMode = -1; +s16 gMenuMode = MENU_MODE_NONE; u8 gEndCutsceneStrEn0[] = { TEXT_FILE_MARIO_EXCLAMATION }; u8 gEndCutsceneStrEn1[] = { TEXT_POWER_STARS_RESTORED }; @@ -1658,18 +1659,19 @@ s8 gDialogCameraAngleIndex = CAM_SELECTION_MARIO; s8 gDialogCourseActNum = 1; #if defined(VERSION_JP) || defined(VERSION_SH) -#define DIAG_VAL1 20 -#define DIAG_VAL3 130 -#define DIAG_VAL4 4 + #define DIAG_VAL1 20 + #define DIAG_VAL2 240 + #define DIAG_VAL3 130 + #define DIAG_VAL4 4 #else -#define DIAG_VAL1 16 -#define DIAG_VAL3 132 // US & EU -#define DIAG_VAL4 5 + #define DIAG_VAL1 16 +#ifdef VERSION_US + #define DIAG_VAL2 240 +#else + #define DIAG_VAL2 238 #endif -#ifdef VERSION_EU -#define DIAG_VAL2 238 -#else -#define DIAG_VAL2 240 // JP & US + #define DIAG_VAL3 132 + #define DIAG_VAL4 5 #endif void render_dialog_entries(void) { @@ -1681,6 +1683,7 @@ void render_dialog_entries(void) { #if defined(VERSION_US) || defined(VERSION_SH) s8 lowerBound; #endif + #ifdef VERSION_EU gInGameLanguage = eu_get_language(); switch (gInGameLanguage) { @@ -1699,9 +1702,9 @@ void render_dialog_entries(void) { #endif dialog = segmented_to_virtual(dialogTable[gDialogID]); - // if the dialog entry is invalid, set the ID to -1. + // if the dialog entry is invalid, set the ID to DIALOG_NONE. if (segmented_to_virtual(NULL) == dialog) { - gDialogID = -1; + gDialogID = DIALOG_NONE; return; } @@ -1729,10 +1732,11 @@ void render_dialog_entries(void) { gDialogBoxState = DIALOG_STATE_VERTICAL; gDialogLineNum = 1; } -#if !defined(VERSION_JP) +#ifndef VERSION_JP lowerBound = 1; #endif break; + case DIALOG_STATE_VERTICAL: gDialogBoxOpenTimer = 0.0f; @@ -1746,10 +1750,11 @@ void render_dialog_entries(void) { play_sound(SOUND_MENU_MESSAGE_NEXT_PAGE, gGlobalSoundSource); } } -#if !defined(VERSION_JP) +#ifndef VERSION_JP lowerBound = 1; #endif break; + case DIALOG_STATE_HORIZONTAL: gDialogScrollOffsetY += dialog->linesPerBox * 2; @@ -1758,10 +1763,11 @@ void render_dialog_entries(void) { gDialogBoxState = DIALOG_STATE_VERTICAL; gDialogScrollOffsetY = 0; } -#if !defined(VERSION_JP) +#ifndef VERSION_JP lowerBound = (gDialogScrollOffsetY / DIAG_VAL1) + 1; #endif break; + case DIALOG_STATE_CLOSING: if (gDialogBoxOpenTimer == 20.0f) { level_set_transition(0, NULL); @@ -1779,13 +1785,13 @@ void render_dialog_entries(void) { if (gDialogBoxOpenTimer == DEFAULT_DIALOG_BOX_ANGLE) { gDialogBoxState = DIALOG_STATE_OPENING; - gDialogID = -1; + gDialogID = DIALOG_NONE; gDialogTextPos = 0; gLastDialogResponse = 0; gLastDialogPageStrPos = 0; - gDialogResponse = 0; + gDialogResponse = DIALOG_RESPONSE_NONE; } -#if !defined(VERSION_JP) +#ifndef VERSION_JP lowerBound = 1; #endif break; @@ -1793,30 +1799,33 @@ void render_dialog_entries(void) { render_dialog_box_type(dialog, dialog->linesPerBox); - gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, - // Horizontal scissoring isn't really required and can potentially mess up widescreen enhancements. + gDPSetScissor( + gDisplayListHead++, G_SC_NON_INTERLACE, + // Horizontal scissoring isn't really required and can potentially mess up widescreen enhancements. #ifdef WIDESCREEN - 0, + 0, #else - ensure_nonnegative(dialog->leftOffset), + ensure_nonnegative(dialog->leftOffset), #endif - ensure_nonnegative(DIAG_VAL2 - dialog->width), + ensure_nonnegative(DIAG_VAL2 - dialog->width), #ifdef VERSION_EU #ifdef WIDESCREEN - SCREEN_WIDTH, + SCREEN_WIDTH, #else - ensure_nonnegative(dialog->leftOffset + DIAG_VAL3 / gDialogBoxScale), + ensure_nonnegative(dialog->leftOffset + (DIAG_VAL3 / gDialogBoxScale)), #endif - ensure_nonnegative((240 - dialog->width) + ((dialog->linesPerBox * 80) / DIAG_VAL4) / gDialogBoxScale)); + ensure_nonnegative((240 - dialog->width) + (dialog->linesPerBox * 80 / DIAG_VAL4 / gDialogBoxScale)) #else #ifdef WIDESCREEN - SCREEN_WIDTH, + SCREEN_WIDTH, #else - ensure_nonnegative(DIAG_VAL3 + dialog->leftOffset), + ensure_nonnegative(dialog->leftOffset + DIAG_VAL3), #endif - ensure_nonnegative(240 + ((dialog->linesPerBox * 80) / DIAG_VAL4) - dialog->width)); + ensure_nonnegative((240 - dialog->width) + (dialog->linesPerBox * 80 / DIAG_VAL4)) #endif -#if defined(VERSION_JP) + ); + +#ifdef VERSION_JP handle_dialog_text_and_pages(0, dialog); #else handle_dialog_text_and_pages(0, dialog, lowerBound); @@ -1825,23 +1834,25 @@ void render_dialog_entries(void) { if (gLastDialogPageStrPos == -1 && gLastDialogResponse == 1) { render_dialog_triangle_choice(); } + #ifdef VERSION_EU #undef BORDER_HEIGHT #define BORDER_HEIGHT 8 #endif - gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 2, 2, SCREEN_WIDTH - BORDER_HEIGHT/2, SCREEN_HEIGHT - BORDER_HEIGHT/2); + gDPSetScissor(gDisplayListHead++, G_SC_NON_INTERLACE, 2, 2, SCREEN_WIDTH - BORDER_HEIGHT / 2, SCREEN_HEIGHT - BORDER_HEIGHT / 2); #ifdef VERSION_EU #undef BORDER_HEIGHT #define BORDER_HEIGHT 1 #endif + if (gLastDialogPageStrPos != -1 && gDialogBoxState == DIALOG_STATE_VERTICAL) { - render_dialog_string_color(dialog->linesPerBox); + render_dialog_triangle_next(dialog->linesPerBox); } } // Calls a gMenuMode value defined by render_menus_and_dialogs cases void set_menu_mode(s16 mode) { - if (gMenuMode == -1) { + if (gMenuMode == MENU_MODE_NONE) { gMenuMode = mode; } } @@ -1877,15 +1888,19 @@ u8 ascii_to_credits_char(u8 c) { if (c == ' ') { return GLOBAL_CHAR_SPACE; } + if (c == '.') { return 0x24; } + if (c == '3') { return ASCII_TO_DIALOG('3'); } + if (c == '4') { return ASCII_TO_DIALOG('4'); } + if (c == '6') { return ASCII_TO_DIALOG('6'); } @@ -1985,17 +2000,17 @@ void do_cutscene_handler(void) { } #ifdef VERSION_JP -#define PEACH_MESSAGE_TIMER 170 + #define PEACH_MESSAGE_TIMER 170 #else -#define PEACH_MESSAGE_TIMER 250 + #define PEACH_MESSAGE_TIMER 250 #endif #if defined(VERSION_JP) || defined(VERSION_SH) -#define STR_X 53 -#define STR_Y 136 + #define STR_X 53 + #define STR_Y 136 #else -#define STR_X 38 -#define STR_Y 142 + #define STR_X 38 + #define STR_Y 142 #endif // "Dear Mario" message handler @@ -2003,6 +2018,7 @@ void print_peach_letter_message(void) { void **dialogTable; struct DialogEntry *dialog; u8 *str; + #ifdef VERSION_EU gInGameLanguage = eu_get_language(); switch (gInGameLanguage) { @@ -2020,7 +2036,6 @@ void print_peach_letter_message(void) { dialogTable = segmented_to_virtual(seg2_dialog_table); #endif dialog = segmented_to_virtual(dialogTable[gDialogID]); - str = segmented_to_virtual(dialog->str); create_dl_translation_matrix(MENU_MTX_PUSH, 97.0f, 118.0f, 0); @@ -2062,7 +2077,7 @@ void print_peach_letter_message(void) { if (gCutsceneMsgTimer > (PEACH_MESSAGE_TIMER + 20)) { gCutsceneMsgIndex = -1; gCutsceneMsgFade = 0; //! uselessly reset since the next execution will just set it to 0 again. - gDialogID = -1; + gDialogID = DIALOG_NONE; gCutsceneMsgTimer = 0; return; // return to avoid incrementing the timer } @@ -2117,11 +2132,11 @@ void shade_screen(void) { // This is a bit weird. It reuses the dialog text box (width 130, height -80), // so scale to at least fit the screen. -#ifndef WIDESCREEN - create_dl_scale_matrix(MENU_MTX_NOPUSH, 2.6f, 3.4f, 1.0f); -#else +#ifdef WIDESCREEN create_dl_scale_matrix(MENU_MTX_NOPUSH, GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_HEIGHT / 130.0f, 3.0f, 1.0f); +#else + create_dl_scale_matrix(MENU_MTX_NOPUSH, 2.6f, 3.4f, 1.0f); #endif gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, 110); @@ -2130,13 +2145,13 @@ void shade_screen(void) { } void print_animated_red_coin(s16 x, s16 y) { - s32 timer = gGlobalTimer; + s32 globalTimer = gGlobalTimer; create_dl_translation_matrix(MENU_MTX_PUSH, x, y, 0); create_dl_scale_matrix(MENU_MTX_NOPUSH, 0.2f, 0.2f, 1.0f); gDPSetRenderMode(gDisplayListHead++, G_RM_TEX_EDGE, G_RM_TEX_EDGE2); - switch (timer & 6) { + switch (globalTimer & 6) { case 0: gSPDisplayList(gDisplayListHead++, coin_seg3_dl_03007940); break; @@ -2164,28 +2179,36 @@ void render_pause_red_coins(void) { } #ifdef VERSION_EU -u8 gTextCourseArr[][7] = { +u8 gTextCourse[][7] = { { TEXT_COURSE }, { TEXT_COURSE_FR }, { TEXT_COURSE_DE } }; +#define textCourse gTextCourse #endif #if defined(VERSION_JP) || defined(VERSION_SH) -#define CRS_NUM_X1 93 -#else -#define CRS_NUM_X1 100 + #define CRS_NUM_X1 93 +#elif defined(VERSION_US) + #define CRS_NUM_X1 100 +#elif defined(VERSION_EU) + #define CRS_NUM_X1 get_string_width(LANGUAGE_ARRAY(textCourse)) + 51 #endif + #ifdef VERSION_EU -#define TXT_STAR_X 89 -#define ACT_NAME_X 107 -#define LVL_NAME_X 108 -#define MYSCORE_X 48 + #define TXT_COURSE_X 48 + #define TXT_STAR_X 89 + #define ACT_NAME_X 107 + #define LVL_NAME_X 108 + #define SECRET_LVL_NAME_X get_str_x_pos_from_center(159, &courseName[3], 10.0f) + #define MYSCORE_X 48 #else -#define TXT_STAR_X 98 -#define ACT_NAME_X 116 -#define LVL_NAME_X 117 -#define MYSCORE_X 62 + #define TXT_COURSE_X 63 + #define TXT_STAR_X 98 + #define ACT_NAME_X 116 + #define LVL_NAME_X 117 + #define SECRET_LVL_NAME_X 94 + #define MYSCORE_X 62 #endif void render_pause_my_score_coins(void) { @@ -2195,7 +2218,6 @@ void render_pause_my_score_coins(void) { { TEXT_MY_SCORE_FR }, { TEXT_MY_SCORE_DE } }; -#define textMyScore textMyScore[gInGameLanguage] #else u8 textCourse[] = { TEXT_COURSE }; u8 textMyScore[] = { TEXT_MY_SCORE }; @@ -2216,8 +2238,8 @@ void render_pause_my_score_coins(void) { actNameTbl = segmented_to_virtual(seg2_act_name_table); #endif - courseIndex = gCurrCourseNum - 1; - starFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1); + courseIndex = COURSE_NUM_TO_INDEX(gCurrCourseNum); + starFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); #ifdef VERSION_EU switch (gInGameLanguage) { @@ -2239,7 +2261,7 @@ void render_pause_my_score_coins(void) { gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin); gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); - if (courseIndex < COURSE_STAGES_COUNT) { + if (courseIndex <= COURSE_NUM_TO_INDEX(COURSE_STAGES_MAX)) { print_hud_my_score_coins(1, gCurrSaveFileNum - 1, courseIndex, 178, 103); print_hud_my_score_stars(gCurrSaveFileNum - 1, courseIndex, 118, 103); } @@ -2249,59 +2271,49 @@ void render_pause_my_score_coins(void) { gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); - if (courseIndex < COURSE_STAGES_COUNT && save_file_get_course_star_count(gCurrSaveFileNum - 1, courseIndex) != 0) { - print_generic_string(MYSCORE_X, 121, textMyScore); + if (courseIndex <= COURSE_NUM_TO_INDEX(COURSE_STAGES_MAX) + && save_file_get_course_star_count(gCurrSaveFileNum - 1, courseIndex) != 0) { + print_generic_string(MYSCORE_X, 121, LANGUAGE_ARRAY(textMyScore)); } courseName = segmented_to_virtual(courseNameTbl[courseIndex]); - if (courseIndex < COURSE_STAGES_COUNT) { -#ifdef VERSION_EU - print_generic_string(48, 157, gTextCourseArr[gInGameLanguage]); -#else - print_generic_string(63, 157, textCourse); -#endif + if (courseIndex <= COURSE_NUM_TO_INDEX(COURSE_STAGES_MAX)) { + print_generic_string(TXT_COURSE_X, 157, LANGUAGE_ARRAY(textCourse)); int_to_str(gCurrCourseNum, strCourseNum); -#ifdef VERSION_EU - print_generic_string(get_string_width(gTextCourseArr[gInGameLanguage]) + 51, 157, strCourseNum); -#else print_generic_string(CRS_NUM_X1, 157, strCourseNum); -#endif - actName = segmented_to_virtual(actNameTbl[(gCurrCourseNum - 1) * 6 + gDialogCourseActNum - 1]); + actName = segmented_to_virtual(actNameTbl[COURSE_NUM_TO_INDEX(gCurrCourseNum) * 6 + gDialogCourseActNum - 1]); if (starFlags & (1 << (gDialogCourseActNum - 1))) { print_generic_string(TXT_STAR_X, 140, textStar); } else { print_generic_string(TXT_STAR_X, 140, textUnfilledStar); } + print_generic_string(ACT_NAME_X, 140, actName); #ifndef VERSION_JP print_generic_string(LVL_NAME_X, 157, &courseName[3]); + } else { + print_generic_string(SECRET_LVL_NAME_X, 157, &courseName[3]); #endif } -#ifndef VERSION_JP - else { -#if defined(VERSION_US) || defined(VERSION_SH) - print_generic_string(94, 157, &courseName[3]); -#elif defined(VERSION_EU) - print_generic_string(get_str_x_pos_from_center(159, &courseName[3], 10.0f), 157, &courseName[3]); -#endif - } -#else - print_generic_string(117, 157, &courseName[3]); + +#ifdef VERSION_JP + print_generic_string(LVL_NAME_X, 157, &courseName[3]); #endif + gSPDisplayList(gDisplayListHead++, dl_ia_text_end); } #if defined(VERSION_JP) || defined(VERSION_SH) -#define TXT1_X 4 -#define TXT2_X 116 -#define Y_VAL7 0 + #define TXT1_X 4 + #define TXT2_X 116 + #define Y_VAL7 0 #else -#define TXT1_X 3 -#define TXT2_X 119 -#define Y_VAL7 2 + #define TXT1_X 3 + #define TXT2_X 119 + #define Y_VAL7 2 #endif void render_pause_camera_options(s16 x, s16 y, s8 *index, s16 xIndex) { @@ -2318,8 +2330,6 @@ void render_pause_camera_options(s16 x, s16 y, s8 *index, s16 xIndex) { { TEXT_NORMAL_FIXED_FR }, { TEXT_NORMAL_FIXED_DE }, }; -#define textNormalUpClose textNormalUpClose[gInGameLanguage] -#define textNormalFixed textNormalFixed[gInGameLanguage] #else u8 textNormalUpClose[] = { TEXT_NORMAL_UPCLOSE }; u8 textNormalFixed[] = { TEXT_NORMAL_FIXED }; @@ -2331,32 +2341,32 @@ void render_pause_camera_options(s16 x, s16 y, s8 *index, s16 xIndex) { gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); print_generic_string(x + 14, y + 2, textLakituMario); - print_generic_string(x + TXT1_X, y - 13, textNormalUpClose); + print_generic_string(x + TXT1_X, y - 13, LANGUAGE_ARRAY(textNormalUpClose)); print_generic_string(x + 124, y + 2, textLakituStop); - print_generic_string(x + TXT2_X, y - 13, textNormalFixed); + print_generic_string(x + TXT2_X, y - 13, LANGUAGE_ARRAY(textNormalFixed)); gSPDisplayList(gDisplayListHead++, dl_ia_text_end); - create_dl_translation_matrix(MENU_MTX_PUSH, ((index[0] - 1) * xIndex) + x, y + Y_VAL7, 0); + create_dl_translation_matrix(MENU_MTX_PUSH, ((*index - 1) * xIndex) + x, y + Y_VAL7, 0); gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); gSPDisplayList(gDisplayListHead++, dl_draw_triangle); gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); - switch (index[0]) { - case 1: - cam_select_alt_mode(1); + switch (*index) { + case CAM_SELECTION_MARIO: + cam_select_alt_mode(CAM_SELECTION_MARIO); break; - case 2: - cam_select_alt_mode(2); + case CAM_SELECTION_FIXED: + cam_select_alt_mode(CAM_SELECTION_FIXED); break; } } #if defined(VERSION_JP) || defined(VERSION_SH) -#define X_VAL8 0 -#define Y_VAL8 4 + #define X_VAL8 0 + #define Y_VAL8 4 #else -#define X_VAL8 4 -#define Y_VAL8 2 + #define X_VAL8 4 + #define Y_VAL8 2 #endif void render_pause_course_options(s16 x, s16 y, s8 *index, s16 yIndex) { @@ -2376,9 +2386,6 @@ void render_pause_course_options(s16 x, s16 y, s8 *index, s16 yIndex) { { TEXT_CAMERA_ANGLE_R_FR }, { TEXT_CAMERA_ANGLE_R_DE } }; -#define textContinue textContinue[gInGameLanguage] -#define textExitCourse textExitCourse[gInGameLanguage] -#define textCameraAngleR textCameraAngleR[gInGameLanguage] #else u8 textContinue[] = { TEXT_CONTINUE }; u8 textExitCourse[] = { TEXT_EXIT_COURSE }; @@ -2390,21 +2397,21 @@ void render_pause_course_options(s16 x, s16 y, s8 *index, s16 yIndex) { gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); - print_generic_string(x + 10, y - 2, textContinue); - print_generic_string(x + 10, y - 17, textExitCourse); + print_generic_string(x + 10, y - 2, LANGUAGE_ARRAY(textContinue)); + print_generic_string(x + 10, y - 17, LANGUAGE_ARRAY(textExitCourse)); - if (index[0] != 3) { - print_generic_string(x + 10, y - 33, textCameraAngleR); + if (*index != MENU_OPT_CAMERA_ANGLE_R) { + print_generic_string(x + 10, y - 33, LANGUAGE_ARRAY(textCameraAngleR)); gSPDisplayList(gDisplayListHead++, dl_ia_text_end); - create_dl_translation_matrix(MENU_MTX_PUSH, x - X_VAL8, (y - ((index[0] - 1) * yIndex)) - Y_VAL8, 0); + create_dl_translation_matrix(MENU_MTX_PUSH, x - X_VAL8, (y - ((*index - 1) * yIndex)) - Y_VAL8, 0); gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); gSPDisplayList(gDisplayListHead++, dl_draw_triangle); gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); } - if (index[0] == 3) { + if (*index == MENU_OPT_CAMERA_ANGLE_R) { render_pause_camera_options(x - 42, y - 42, &gDialogCameraAngleIndex, 110); } } @@ -2429,50 +2436,51 @@ void render_pause_castle_menu_box(s16 x, s16 y) { } void highlight_last_course_complete_stars(void) { - u8 courseDone; + u8 doneCourseIndex; if (gLastCompletedCourseNum == COURSE_NONE) { - courseDone = 0; + doneCourseIndex = 0; } else { - courseDone = gLastCompletedCourseNum - 1; + doneCourseIndex = COURSE_NUM_TO_INDEX(gLastCompletedCourseNum); - if (courseDone >= COURSE_STAGES_COUNT) { - courseDone = COURSE_STAGES_COUNT; + if (doneCourseIndex >= COURSE_NUM_TO_INDEX(COURSE_BONUS_STAGES)) { + doneCourseIndex = COURSE_NUM_TO_INDEX(COURSE_BONUS_STAGES); } } - gDialogLineNum = courseDone; + gDialogLineNum = doneCourseIndex; } +#ifdef VERSION_EU + #define PAUSE_X get_str_x_pos_from_center_scale(SCREEN_WIDTH / 2, textPause, 12.0f) +#else + #define PAUSE_X 123 +#endif + void print_hud_pause_colorful_str(void) { u8 textPause[] = { TEXT_PAUSE }; gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin); gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); -#ifdef VERSION_EU - print_hud_lut_string(HUD_LUT_GLOBAL, get_str_x_pos_from_center_scale( - SCREEN_WIDTH / 2, textPause, 12.0f), 81, textPause); -#else - print_hud_lut_string(HUD_LUT_GLOBAL, 123, 81, textPause); -#endif + print_hud_lut_string(HUD_LUT_GLOBAL, PAUSE_X, 81, textPause); gSPDisplayList(gDisplayListHead++, dl_rgba16_text_end); } -void render_pause_castle_course_stars(s16 x, s16 y, s16 fileNum, s16 courseNum) { +void render_pause_castle_course_stars(s16 x, s16 y, s16 fileIndex, s16 courseIndex) { s16 hasStar = 0; u8 str[COURSE_STAGES_COUNT * 2]; u8 textStar[] = { TEXT_STAR }; - u8 starFlags = save_file_get_star_flags(fileNum, courseNum); - u16 starCount = save_file_get_course_star_count(fileNum, courseNum); + u8 starFlags = save_file_get_star_flags(fileIndex, courseIndex); + u16 starCount = save_file_get_course_star_count(fileIndex, courseIndex); u16 nextStar = 0; - if (starFlags & 0x40) { + if (starFlags & (1 << 6)) { starCount--; print_generic_string(x + 89, y - 5, textStar); } @@ -2517,7 +2525,7 @@ void render_pause_castle_main_strings(s16 x, s16 y) { void *courseName; u8 strVal[8]; - s16 starNum = gDialogLineNum; + s16 prevCourseIndex = gDialogLineNum; #ifdef VERSION_EU switch (gInGameLanguage) { @@ -2533,26 +2541,30 @@ void render_pause_castle_main_strings(s16 x, s16 y) { } #endif - handle_menu_scrolling(MENU_SCROLL_VERTICAL, &gDialogLineNum, -1, COURSE_STAGES_COUNT + 1); + handle_menu_scrolling( + MENU_SCROLL_VERTICAL, &gDialogLineNum, + COURSE_NUM_TO_INDEX(COURSE_MIN) - 1, COURSE_NUM_TO_INDEX(COURSE_BONUS_STAGES) + 1 + ); - if (gDialogLineNum == COURSE_STAGES_COUNT + 1) { - gDialogLineNum = 0; + if (gDialogLineNum == COURSE_NUM_TO_INDEX(COURSE_BONUS_STAGES) + 1) { + gDialogLineNum = COURSE_NUM_TO_INDEX(COURSE_MIN); // Exceeded max, set to min } - if (gDialogLineNum == -1) { - gDialogLineNum = COURSE_STAGES_COUNT; + if (gDialogLineNum == COURSE_NUM_TO_INDEX(COURSE_MIN) - 1) { + gDialogLineNum = COURSE_NUM_TO_INDEX(COURSE_BONUS_STAGES); // Exceeded min, set to max } - if (gDialogLineNum != COURSE_STAGES_COUNT) { + if (gDialogLineNum != COURSE_NUM_TO_INDEX(COURSE_BONUS_STAGES)) { while (save_file_get_course_star_count(gCurrSaveFileNum - 1, gDialogLineNum) == 0) { - if (gDialogLineNum >= starNum) { + if (gDialogLineNum >= prevCourseIndex) { gDialogLineNum++; } else { gDialogLineNum--; } - if (gDialogLineNum == COURSE_STAGES_COUNT || gDialogLineNum == -1) { - gDialogLineNum = COURSE_STAGES_COUNT; + if (gDialogLineNum == COURSE_NUM_TO_INDEX(COURSE_STAGES_MAX) + 1 + || gDialogLineNum == COURSE_NUM_TO_INDEX(COURSE_MIN) - 1) { + gDialogLineNum = COURSE_NUM_TO_INDEX(COURSE_BONUS_STAGES); break; } } @@ -2561,7 +2573,7 @@ void render_pause_castle_main_strings(s16 x, s16 y) { gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); - if (gDialogLineNum < COURSE_STAGES_COUNT) { + if (gDialogLineNum <= COURSE_NUM_TO_INDEX(COURSE_STAGES_MAX)) { // Main courses courseName = segmented_to_virtual(courseNameTbl[gDialogLineNum]); render_pause_castle_course_stars(x, y, gCurrSaveFileNum - 1, gDialogLineNum); print_generic_string(x + 34, y - 5, textCoin); @@ -2573,7 +2585,7 @@ void render_pause_castle_main_strings(s16 x, s16 y) { #ifdef VERSION_EU print_generic_string(x - 17, y + 30, courseName); #endif - } else { + } else { // Castle secret stars u8 textStarX[] = { TEXT_STAR_X }; courseName = segmented_to_virtual(courseNameTbl[COURSE_MAX]); print_generic_string(x + 40, y + 13, textStarX); @@ -2591,13 +2603,13 @@ void render_pause_castle_main_strings(s16 x, s16 y) { gSPDisplayList(gDisplayListHead++, dl_ia_text_end); } -s8 gCourseCompleteCoinsEqual = 0; +s8 gCourseCompleteCoinsEqual = FALSE; s32 gCourseDoneMenuTimer = 0; s32 gCourseCompleteCoins = 0; s8 gHudFlash = 0; s16 render_pause_courses_and_castle(void) { - s16 num; + s16 index; #ifdef VERSION_EU gInGameLanguage = eu_get_language(); @@ -2605,14 +2617,10 @@ s16 render_pause_courses_and_castle(void) { switch (gDialogBoxState) { case DIALOG_STATE_OPENING: - gDialogLineNum = 1; + gDialogLineNum = MENU_OPT_DEFAULT; gDialogTextAlpha = 0; level_set_transition(-1, NULL); -#ifdef VERSION_JP play_sound(SOUND_MENU_PAUSE, gGlobalSoundSource); -#else - play_sound(SOUND_MENU_PAUSE_HIGHPRIO, gGlobalSoundSource); -#endif if (gCurrCourseNum >= COURSE_MIN && gCurrCourseNum <= COURSE_MAX) { change_dialog_camera_angle(); @@ -2622,6 +2630,7 @@ s16 render_pause_courses_and_castle(void) { gDialogBoxState = DIALOG_STATE_HORIZONTAL; } break; + case DIALOG_STATE_VERTICAL: shade_screen(); render_pause_my_score_coins(); @@ -2635,23 +2644,24 @@ s16 render_pause_courses_and_castle(void) { if (gPlayer3Controller->buttonPressed & (A_BUTTON | Z_TRIG | START_BUTTON)) #else if (gPlayer3Controller->buttonPressed & A_BUTTON - || gPlayer3Controller->buttonPressed & START_BUTTON) + || gPlayer3Controller->buttonPressed & START_BUTTON) #endif { level_set_transition(0, NULL); play_sound(SOUND_MENU_PAUSE_2, gGlobalSoundSource); gDialogBoxState = DIALOG_STATE_OPENING; - gMenuMode = -1; + gMenuMode = MENU_MODE_NONE; - if (gDialogLineNum == 2) { - num = gDialogLineNum; - } else { - num = 1; + if (gDialogLineNum == MENU_OPT_EXIT_COURSE) { + index = gDialogLineNum; + } else { // MENU_OPT_CONTINUE or MENU_OPT_CAMERA_ANGLE_R + index = MENU_OPT_DEFAULT; } - return num; + return index; } break; + case DIALOG_STATE_HORIZONTAL: shade_screen(); print_hud_pause_colorful_str(); @@ -2662,15 +2672,15 @@ s16 render_pause_courses_and_castle(void) { if (gPlayer3Controller->buttonPressed & (A_BUTTON | Z_TRIG | START_BUTTON)) #else if (gPlayer3Controller->buttonPressed & A_BUTTON - || gPlayer3Controller->buttonPressed & START_BUTTON) + || gPlayer3Controller->buttonPressed & START_BUTTON) #endif { level_set_transition(0, NULL); play_sound(SOUND_MENU_PAUSE_2, gGlobalSoundSource); - gMenuMode = -1; + gMenuMode = MENU_MODE_NONE; gDialogBoxState = DIALOG_STATE_OPENING; - return 1; + return MENU_OPT_DEFAULT; } break; } @@ -2679,21 +2689,25 @@ s16 render_pause_courses_and_castle(void) { gDialogTextAlpha += 25; } - return 0; + return MENU_OPT_NONE; } #if defined(VERSION_JP) -#define TXT_HISCORE_X 112 -#define TXT_HISCORE_Y 48 -#define TXT_CONGRATS_X 60 + #define TXT_HISCORE_X 112 + #define TXT_HISCORE_Y 48 + #define TXT_CONGRATS_X 60 +#elif defined(VERSION_US) + #define TXT_HISCORE_X 109 + #define TXT_HISCORE_Y 36 + #define TXT_CONGRATS_X 70 +#elif defined(VERSION_EU) + #define TXT_HISCORE_X get_str_x_pos_from_center_scale(160, LANGUAGE_ARRAY(textHiScore), 12.0f) + #define TXT_HISCORE_Y 36 + #define TXT_CONGRATS_X get_str_x_pos_from_center_scale(160, LANGUAGE_ARRAY(textCongratulations), 12.0f) #elif defined(VERSION_SH) -#define TXT_HISCORE_X 118 -#define TXT_HISCORE_Y 48 -#define TXT_CONGRATS_X 70 -#else -#define TXT_HISCORE_X 109 -#define TXT_HISCORE_Y 36 -#define TXT_CONGRATS_X 70 + #define TXT_HISCORE_X 118 + #define TXT_HISCORE_Y 48 + #define TXT_CONGRATS_X 70 #endif #define HUD_PRINT_HISCORE 0 @@ -2722,19 +2736,9 @@ void print_hud_course_complete_string(s8 str) { gDPSetEnvColor(gDisplayListHead++, colorFade, colorFade, colorFade, 255); if (str == HUD_PRINT_HISCORE) { -#ifdef VERSION_EU - print_hud_lut_string(HUD_LUT_GLOBAL, get_str_x_pos_from_center_scale(160, textHiScore[gInGameLanguage], 12.0f), - 36, textHiScore[gInGameLanguage]); -#else - print_hud_lut_string(HUD_LUT_GLOBAL, TXT_HISCORE_X, TXT_HISCORE_Y, textHiScore); -#endif + print_hud_lut_string(HUD_LUT_GLOBAL, TXT_HISCORE_X, TXT_HISCORE_Y, LANGUAGE_ARRAY(textHiScore)); } else { // HUD_PRINT_CONGRATULATIONS -#ifdef VERSION_EU - print_hud_lut_string(HUD_LUT_GLOBAL, get_str_x_pos_from_center_scale(160, textCongratulations[gInGameLanguage], 12.0f), - 67, textCongratulations[gInGameLanguage]); -#else - print_hud_lut_string(HUD_LUT_GLOBAL, TXT_CONGRATS_X, 67, textCongratulations); -#endif + print_hud_lut_string(HUD_LUT_GLOBAL, TXT_CONGRATS_X, 67, LANGUAGE_ARRAY(textCongratulations)); } gSPDisplayList(gDisplayListHead++, dl_rgba16_text_end); @@ -2757,7 +2761,7 @@ void print_hud_course_complete_coins(s16 x, s16 y) { gSPDisplayList(gDisplayListHead++, dl_rgba16_text_end); if (gCourseCompleteCoins >= gHudDisplay.coins) { - gCourseCompleteCoinsEqual = 1; + gCourseCompleteCoinsEqual = TRUE; gCourseCompleteCoins = gHudDisplay.coins; if (gGotFileCoinHiScore) { @@ -2770,7 +2774,7 @@ void print_hud_course_complete_coins(s16 x, s16 y) { if (gCourseCompleteCoins == 50 || gCourseCompleteCoins == 100 || gCourseCompleteCoins == 150) { play_sound(SOUND_GENERAL_COLLECT_1UP, gGlobalSoundSource); - gMarioState[0].numLives++; + gMarioState->numLives++; } } @@ -2788,22 +2792,23 @@ void play_star_fanfare_and_flash_hud(s32 arg, u8 starNum) { } #ifdef VERSION_EU -#define TXT_NAME_X1 centerX -#define TXT_NAME_X2 centerX - 1 + #define TXT_NAME_X1 centerX + #define TXT_NAME_X2 centerX - 1 #else -#define TXT_NAME_X1 71 -#define TXT_NAME_X2 69 + #define TXT_NAME_X1 71 + #define TXT_NAME_X2 TXT_NAME_X1 - 2 #endif + #if defined(VERSION_JP) || defined(VERSION_SH) -#define CRS_NUM_X2 95 -#define CRS_NUM_X3 93 -#define TXT_CLEAR_X1 205 -#define TXT_CLEAR_X2 203 + #define CRS_NUM_X2 95 + #define CRS_NUM_X3 CRS_NUM_X2 - 2 + #define TXT_CLEAR_X1 205 + #define TXT_CLEAR_X2 TXT_CLEAR_X1 - 2 #else -#define CRS_NUM_X2 104 -#define CRS_NUM_X3 102 -#define TXT_CLEAR_X1 get_string_width(name) + 81 -#define TXT_CLEAR_X2 get_string_width(name) + 79 + #define CRS_NUM_X2 104 + #define CRS_NUM_X3 CRS_NUM_X2 - 2 + #define TXT_CLEAR_X1 get_string_width(name) + 81 + #define TXT_CLEAR_X2 TXT_CLEAR_X1 - 2 #endif void render_course_complete_lvl_info_and_hud_str(void) { @@ -2815,7 +2820,6 @@ void render_course_complete_lvl_info_and_hud_str(void) { #elif defined(VERSION_EU) UNUSED u8 textCatch[] = { TEXT_CATCH }; // unused in EU u8 textSymStar[] = { GLYPH_STAR, GLYPH_SPACE }; -#define textCourse gTextCourseArr[gInGameLanguage] #else u8 textCourse[] = { TEXT_COURSE }; UNUSED u8 textCatch[] = { TEXT_CATCH }; // unused in US @@ -2850,28 +2854,36 @@ void render_course_complete_lvl_info_and_hud_str(void) { courseNameTbl = segmented_to_virtual(seg2_course_name_table); #endif - if (gLastCompletedCourseNum <= COURSE_STAGES_MAX) { + if (gLastCompletedCourseNum <= COURSE_STAGES_MAX) { // Main courses print_hud_course_complete_coins(118, 103); play_star_fanfare_and_flash_hud(1, 1 << (gLastCompletedStarNum - 1)); if (gLastCompletedStarNum == 7) { name = segmented_to_virtual(actNameTbl[COURSE_STAGES_MAX * 6 + 1]); } else { - name = segmented_to_virtual(actNameTbl[(gLastCompletedCourseNum - 1) * 6 + gLastCompletedStarNum - 1]); + name = segmented_to_virtual(actNameTbl[COURSE_NUM_TO_INDEX(gLastCompletedCourseNum) * 6 + gLastCompletedStarNum - 1]); } + // Print course number gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); + int_to_str(gLastCompletedCourseNum, strCourseNum); + gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, gDialogTextAlpha); - print_generic_string(65, 165, textCourse); + print_generic_string(65, 165, LANGUAGE_ARRAY(textCourse)); print_generic_string(CRS_NUM_X2, 165, strCourseNum); + gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); - print_generic_string(63, 167, textCourse); + print_generic_string(63, 167, LANGUAGE_ARRAY(textCourse)); print_generic_string(CRS_NUM_X3, 167, strCourseNum); + gSPDisplayList(gDisplayListHead++, dl_ia_text_end); - } else if (gLastCompletedCourseNum == COURSE_BITDW || gLastCompletedCourseNum == COURSE_BITFS) { - name = segmented_to_virtual(courseNameTbl[gLastCompletedCourseNum - 1]); + } else if (gLastCompletedCourseNum == COURSE_BITDW || gLastCompletedCourseNum == COURSE_BITFS) { // Bowser courses + name = segmented_to_virtual(courseNameTbl[COURSE_NUM_TO_INDEX(gLastCompletedCourseNum)]); + + // Print course name and clear text gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); + gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, gDialogTextAlpha); #ifdef VERSION_EU centerX = get_str_x_pos_from_center(153, name, 12.0f); @@ -2880,85 +2892,95 @@ void render_course_complete_lvl_info_and_hud_str(void) { #ifndef VERSION_EU print_generic_string(TXT_CLEAR_X1, 130, textClear); #endif + gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); print_generic_string(TXT_NAME_X2, 132, name); #ifndef VERSION_EU print_generic_string(TXT_CLEAR_X2, 132, textClear); #endif + gSPDisplayList(gDisplayListHead++, dl_ia_text_end); + print_hud_course_complete_string(HUD_PRINT_CONGRATULATIONS); print_hud_course_complete_coins(118, 111); play_star_fanfare_and_flash_hud(2, 0); //! 2 isn't defined, originally for key hud? + return; - } else { + } else { // Castle secret stars name = segmented_to_virtual(actNameTbl[COURSE_STAGES_MAX * 6]); + print_hud_course_complete_coins(118, 103); play_star_fanfare_and_flash_hud(1, 1 << (gLastCompletedStarNum - 1)); } + // Print star glyph gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin); + gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); print_hud_lut_string(HUD_LUT_GLOBAL, 55, 77, textSymStar); + gSPDisplayList(gDisplayListHead++, dl_rgba16_text_end); + + // Print act name and catch text gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); + gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, gDialogTextAlpha); print_generic_string(76, 145, name); #if defined(VERSION_JP) || defined(VERSION_SH) print_generic_string(220, 145, textCatch); #endif + gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); print_generic_string(74, 147, name); #if defined(VERSION_JP) || defined(VERSION_SH) print_generic_string(218, 147, textCatch); #endif + gSPDisplayList(gDisplayListHead++, dl_ia_text_end); } #if defined(VERSION_JP) || defined(VERSION_SH) -#define TXT_SAVEOPTIONS_X x + 10 -#elif defined(VERSION_US) -#define TXT_SAVEOPTIONS_X x + 12 -#elif defined(VERSION_EU) -#define TXT_SAVEOPTIONS_X xOffset -#endif -#if defined(VERSION_JP) || defined(VERSION_SH) -#define TXT_SAVECONT_Y 2 -#define TXT_SAVEQUIT_Y 18 -#define TXT_CONTNOSAVE_Y 38 + #define X_VAL9 x + #define TXT_SAVEOPTIONS_X x + 10 + #define TXT_SAVECONT_Y 2 + #define TXT_SAVEQUIT_Y 18 + #define TXT_CONTNOSAVE_Y 38 #else -#define TXT_SAVECONT_Y 0 -#define TXT_SAVEQUIT_Y 20 -#define TXT_CONTNOSAVE_Y 40 +#ifdef VERSION_EU + #define X_VAL9 xOffset - 12 + #define TXT_SAVEOPTIONS_X xOffset +#else + #define X_VAL9 x + #define TXT_SAVEOPTIONS_X x + 12 +#endif + #define TXT_SAVECONT_Y 0 + #define TXT_SAVEQUIT_Y 20 + #define TXT_CONTNOSAVE_Y 40 #endif #ifdef VERSION_EU -#define X_VAL9 xOffset - 12 void render_save_confirmation(s16 y, s8 *index, s16 sp6e) #else -#define X_VAL9 x void render_save_confirmation(s16 x, s16 y, s8 *index, s16 sp6e) #endif { #ifdef VERSION_EU - u8 textSaveAndContinueArr[][24] = { + u8 textSaveAndContinue[][24] = { { TEXT_SAVE_AND_CONTINUE }, { TEXT_SAVE_AND_CONTINUE_FR }, { TEXT_SAVE_AND_CONTINUE_DE } }; - u8 textSaveAndQuitArr[][22] = { + u8 textSaveAndQuit[][22] = { { TEXT_SAVE_AND_QUIT }, { TEXT_SAVE_AND_QUIT_FR }, { TEXT_SAVE_AND_QUIT_DE } }; - u8 textContinueWithoutSaveArr[][27] = { + u8 textContinueWithoutSave[][27] = { { TEXT_CONTINUE_WITHOUT_SAVING }, { TEXT_CONTINUE_WITHOUT_SAVING_FR }, { TEXT_CONTINUE_WITHOUT_SAVING_DE } }; -#define textSaveAndContinue textSaveAndContinueArr[gInGameLanguage] -#define textSaveAndQuit textSaveAndQuitArr[gInGameLanguage] -#define textContinueWithoutSave textContinueWithoutSaveArr[gInGameLanguage] - s16 xOffset = get_str_x_pos_from_center(160, textContinueWithoutSaveArr[gInGameLanguage], 12.0f); + s16 xOffset = get_str_x_pos_from_center(160, LANGUAGE_ARRAY(textContinueWithoutSave), 12.0f); #else u8 textSaveAndContinue[] = { TEXT_SAVE_AND_CONTINUE }; u8 textSaveAndQuit[] = { TEXT_SAVE_AND_QUIT }; @@ -2970,13 +2992,13 @@ void render_save_confirmation(s16 x, s16 y, s8 *index, s16 sp6e) gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); - print_generic_string(TXT_SAVEOPTIONS_X, y + TXT_SAVECONT_Y, textSaveAndContinue); - print_generic_string(TXT_SAVEOPTIONS_X, y - TXT_SAVEQUIT_Y, textSaveAndQuit); - print_generic_string(TXT_SAVEOPTIONS_X, y - TXT_CONTNOSAVE_Y, textContinueWithoutSave); + print_generic_string(TXT_SAVEOPTIONS_X, y + TXT_SAVECONT_Y, LANGUAGE_ARRAY(textSaveAndContinue)); + print_generic_string(TXT_SAVEOPTIONS_X, y - TXT_SAVEQUIT_Y, LANGUAGE_ARRAY(textSaveAndQuit)); + print_generic_string(TXT_SAVEOPTIONS_X, y - TXT_CONTNOSAVE_Y, LANGUAGE_ARRAY(textContinueWithoutSave)); gSPDisplayList(gDisplayListHead++, dl_ia_text_end); - create_dl_translation_matrix(MENU_MTX_PUSH, X_VAL9, y - ((index[0] - 1) * sp6e), 0); + create_dl_translation_matrix(MENU_MTX_PUSH, X_VAL9, y - ((*index - 1) * sp6e), 0); gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, gDialogTextAlpha); gSPDisplayList(gDisplayListHead++, dl_draw_triangle); @@ -2985,7 +3007,7 @@ void render_save_confirmation(s16 x, s16 y, s8 *index, s16 sp6e) } s16 render_course_complete_screen(void) { - s16 num; + s16 index; #ifdef VERSION_EU gInGameLanguage = eu_get_language(); #endif @@ -2993,13 +3015,14 @@ s16 render_course_complete_screen(void) { switch (gDialogBoxState) { case DIALOG_STATE_OPENING: render_course_complete_lvl_info_and_hud_str(); - if (gCourseDoneMenuTimer > 100 && gCourseCompleteCoinsEqual == 1) { + if (gCourseDoneMenuTimer > 100 && gCourseCompleteCoinsEqual == TRUE) { gDialogBoxState = DIALOG_STATE_VERTICAL; level_set_transition(-1, NULL); gDialogTextAlpha = 0; - gDialogLineNum = 1; + gDialogLineNum = MENU_OPT_DEFAULT; } break; + case DIALOG_STATE_VERTICAL: shade_screen(); render_course_complete_lvl_info_and_hud_str(); @@ -3019,14 +3042,14 @@ s16 render_course_complete_screen(void) { level_set_transition(0, NULL); play_sound(SOUND_MENU_STAR_SOUND, gGlobalSoundSource); gDialogBoxState = DIALOG_STATE_OPENING; - gMenuMode = -1; - num = gDialogLineNum; + gMenuMode = MENU_MODE_NONE; + index = gDialogLineNum; gCourseDoneMenuTimer = 0; gCourseCompleteCoins = 0; - gCourseCompleteCoinsEqual = 0; + gCourseCompleteCoinsEqual = FALSE; gHudFlash = 0; - return num; + return index; } break; } @@ -3037,41 +3060,41 @@ s16 render_course_complete_screen(void) { gCourseDoneMenuTimer++; - return 0; + return MENU_OPT_NONE; } -// Only case 1 and 2 are used s16 render_menus_and_dialogs(void) { - s16 mode = 0; + s16 index = MENU_OPT_NONE; create_dl_ortho_matrix(); - if (gMenuMode != -1) { + if (gMenuMode != MENU_MODE_NONE) { switch (gMenuMode) { - case 0: - mode = render_pause_courses_and_castle(); + case MENU_MODE_UNUSED_0: + index = render_pause_courses_and_castle(); break; - case 1: - mode = render_pause_courses_and_castle(); + case MENU_MODE_RENDER_PAUSE_SCREEN: + index = render_pause_courses_and_castle(); break; - case 2: - mode = render_course_complete_screen(); + case MENU_MODE_RENDER_COURSE_COMPLETE_SCREEN: + index = render_course_complete_screen(); break; - case 3: - mode = render_course_complete_screen(); + case MENU_MODE_UNUSED_3: + index = render_course_complete_screen(); break; } gDialogColorFadeTimer = (s16) gDialogColorFadeTimer + 0x1000; - } else if (gDialogID != -1) { + } else if (gDialogID != DIALOG_NONE) { // The Peach "Dear Mario" message needs to be repositioned separately - if (gDialogID == 20) { + if (gDialogID == DIALOG_020) { print_peach_letter_message(); - return mode; + return index; } render_dialog_entries(); gDialogColorFadeTimer = (s16) gDialogColorFadeTimer + 0x1000; } - return mode; + + return index; } diff --git a/src/game/ingame_menu.h b/src/game/ingame_menu.h index c68e37ba..d341855e 100644 --- a/src/game/ingame_menu.h +++ b/src/game/ingame_menu.h @@ -27,20 +27,23 @@ #define HUD_LUT_DIFF HUD_LUT_GLOBAL #endif -#define RENDER_PAUSE_SCREEN 1 -#define RENDER_COURSE_DONE_SCREEN 2 - +enum MenuMode { + MENU_MODE_NONE = -1, + MENU_MODE_UNUSED_0, + MENU_MODE_RENDER_PAUSE_SCREEN, + MENU_MODE_RENDER_COURSE_COMPLETE_SCREEN, + MENU_MODE_UNUSED_3 +}; extern s8 gDialogCourseActNum; extern s8 gHudFlash; -struct DialogEntry -{ - /*0x00*/ u32 unused; - /*0x04*/ s8 linesPerBox; - /*0x06*/ s16 leftOffset; - /*0x08*/ s16 width; - /*0x0C*/ const u8 *str; +struct DialogEntry { + /*0x00*/ u32 unused; + /*0x04*/ s8 linesPerBox; + /*0x06*/ s16 leftOffset; + /*0x08*/ s16 width; + /*0x0C*/ const u8 *str; }; // EU only @@ -55,6 +58,12 @@ enum SpecialFontChars { GLOBAR_CHAR_TERMINATOR = 0xFF }; +enum DialogMark { + DIALOG_MARK_NONE, + DIALOG_MARK_DAKUTEN, + DIALOG_MARK_HANDAKUTEN +}; + // definitions for some of the special characters defined in charmap.txt enum DialogSpecialChars { #ifdef VERSION_EU @@ -97,14 +106,23 @@ enum DialogSpecialChars { DIALOG_CHAR_SPACE = 0x9E, DIALOG_CHAR_STAR_COUNT = 0xE0, // number of stars DIALOG_CHAR_UMLAUT = 0xE9, - DIALOG_CHAR_DAKUTEN = 0xF0, - DIALOG_CHAR_PERIOD_OR_HANDAKUTEN = 0xF1, + DIALOG_CHAR_MARK_START = 0xEF, + DIALOG_CHAR_DAKUTEN = DIALOG_CHAR_MARK_START + DIALOG_MARK_DAKUTEN, + DIALOG_CHAR_PERIOD_OR_HANDAKUTEN = DIALOG_CHAR_MARK_START + DIALOG_MARK_HANDAKUTEN, DIALOG_CHAR_STAR_FILLED = 0xFA, DIALOG_CHAR_STAR_OPEN = 0xFD, DIALOG_CHAR_NEWLINE = 0xFE, DIALOG_CHAR_TERMINATOR = 0xFF }; +// gDialogResponse +enum DialogResponseDefines { + DIALOG_RESPONSE_NONE, + DIALOG_RESPONSE_YES, + DIALOG_RESPONSE_NO, + DIALOG_RESPONSE_NOT_DEFINED +}; + extern s32 gDialogResponse; extern u16 gDialogColorFadeTimer; extern s8 gLastDialogLineNum; @@ -130,7 +148,7 @@ s16 get_str_x_pos_from_center(s16 centerPos, u8 *str, f32 scale); #if defined(VERSION_JP) || defined(VERSION_EU) || defined(VERSION_SH) s16 get_str_x_pos_from_center_scale(s16 centerPos, u8 *str, f32 scale); #endif -void print_hud_my_score_coins(s32 useCourseCoinScore, s8 fileNum, s8 courseNum, s16 x, s16 y); +void print_hud_my_score_coins(s32 useCourseCoinScore, s8 fileIndex, s8 courseIndex, s16 x, s16 y); void int_to_str(s32 num, u8 *dst); s16 get_dialog_id(void); void create_dialog_box(s16 dialog); diff --git a/src/game/interaction.c b/src/game/interaction.c index 1ae0b24e..c35d1b3e 100644 --- a/src/game/interaction.c +++ b/src/game/interaction.c @@ -336,7 +336,7 @@ void mario_stop_riding_and_holding(struct MarioState *m) { mario_stop_riding_object(m); if (m->action == ACT_RIDING_HOOT) { - m->usedObj->oInteractStatus = 0; + m->usedObj->oInteractStatus = FALSE; m->usedObj->oHootMarioReleaseTime = gGlobalTimer; } } @@ -526,7 +526,7 @@ void hit_object_from_below(struct MarioState *m, UNUSED struct Object *o) { set_camera_shake_from_hit(SHAKE_HIT_FROM_BELOW); } -static u32 unused_determine_knockback_action(struct MarioState *m) { +UNUSED static u32 unused_determine_knockback_action(struct MarioState *m) { u32 bonkAction; s16 angleToObject = mario_obj_angle_to_object(m, m->interactObj); s16 facingDYaw = angleToObject - m->faceAngle[1]; @@ -699,7 +699,7 @@ u32 take_damage_from_interact_object(struct MarioState *m) { m->hurtCounter += 4 * damage; -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif set_camera_shake_from_hit(shake); @@ -750,7 +750,7 @@ u32 interact_coin(struct MarioState *m, UNUSED u32 interactType, struct Object * && m->numCoins >= 100) { bhv_spawn_star_no_level_exit(6); } -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (o->oDamageOrCoinValue >= 2) { queue_rumble_data(5, 80); } @@ -773,7 +773,7 @@ u32 interact_star_or_key(struct MarioState *m, UNUSED u32 interactType, struct O if (m->health >= 0x100) { mario_stop_riding_and_holding(m); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif @@ -876,7 +876,7 @@ u32 interact_warp(struct MarioState *m, UNUSED u32 interactType, struct Object * m->interactObj = o; m->usedObj = o; -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (o->collisionData == segmented_to_virtual(warp_pipe_seg3_collision_03009AC8)) { play_sound(SOUND_MENU_ENTER_PIPE, m->marioObj->header.gfx.cameraToObject); queue_rumble_data(15, 80); @@ -1100,7 +1100,7 @@ u32 interact_tornado(struct MarioState *m, UNUSED u32 interactType, struct Objec marioObj->oMarioTornadoPosY = m->pos[1] - o->oPosY; play_sound(SOUND_MARIO_WAAAOOOW, m->marioObj->header.gfx.cameraToObject); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(30, 60); #endif return set_mario_action(m, ACT_TORNADO_TWIRLING, m->action == ACT_TWIRLING); @@ -1123,7 +1123,7 @@ u32 interact_whirlpool(struct MarioState *m, UNUSED u32 interactType, struct Obj marioObj->oMarioWhirlpoolPosY = m->pos[1] - o->oPosY; play_sound(SOUND_MARIO_WAAAOOOW, m->marioObj->header.gfx.cameraToObject); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(30, 60); #endif return set_mario_action(m, ACT_CAUGHT_IN_WHIRLPOOL, 0); @@ -1159,7 +1159,7 @@ u32 interact_flame(struct MarioState *m, UNUSED u32 interactType, struct Object if (!sInvulnerable && !(m->flags & MARIO_METAL_CAP) && !(m->flags & MARIO_VANISH_CAP) && !(o->oInteractionSubtype & INT_SUBTYPE_DELAY_INVINCIBILITY)) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif o->oInteractStatus = INT_STATUS_INTERACTED; @@ -1226,7 +1226,7 @@ u32 interact_clam_or_bubba(struct MarioState *m, UNUSED u32 interactType, struct } u32 interact_bully(struct MarioState *m, UNUSED u32 interactType, struct Object *o) { - UNUSED u32 unused; + UNUSED u8 filler[4]; u32 interaction; if (m->flags & MARIO_METAL_CAP) { @@ -1238,7 +1238,7 @@ u32 interact_bully(struct MarioState *m, UNUSED u32 interactType, struct Object m->interactObj = o; if (interaction & INT_ATTACK_NOT_FROM_BELOW) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif push_mario_out_of_object(m, o, 5.0f); @@ -1263,7 +1263,7 @@ u32 interact_bully(struct MarioState *m, UNUSED u32 interactType, struct Object push_mario_out_of_object(m, o, 5.0f); drop_and_set_mario_action(m, bully_knock_back_mario(m), 0); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif return TRUE; @@ -1282,7 +1282,7 @@ u32 interact_shock(struct MarioState *m, UNUSED u32 interactType, struct Object take_damage_from_interact_object(m); play_sound(SOUND_MARIO_ATTACKED, m->marioObj->header.gfx.cameraToObject); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(70, 60); #endif @@ -1301,7 +1301,7 @@ u32 interact_shock(struct MarioState *m, UNUSED u32 interactType, struct Object return FALSE; } -static u32 interact_stub(UNUSED struct MarioState *m, UNUSED u32 interactType, struct Object *o) { +UNUSED static u32 interact_stub(UNUSED struct MarioState *m, UNUSED u32 interactType, struct Object *o) { if (!(o->oInteractionSubtype & INT_SUBTYPE_DELAY_INVINCIBILITY)) { sDelayInvincTimer = TRUE; } @@ -1321,7 +1321,7 @@ u32 interact_mr_blizzard(struct MarioState *m, UNUSED u32 interactType, struct O } u32 interact_hit_from_below(struct MarioState *m, UNUSED u32 interactType, struct Object *o) { - UNUSED u32 unused; + UNUSED u8 filler[4]; u32 interaction; if (m->flags & MARIO_METAL_CAP) { @@ -1331,7 +1331,7 @@ u32 interact_hit_from_below(struct MarioState *m, UNUSED u32 interactType, struc } if (interaction & INT_ANY_ATTACK) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif attack_object(o, interaction); @@ -1373,7 +1373,7 @@ u32 interact_bounce_top(struct MarioState *m, UNUSED u32 interactType, struct Ob } if (interaction & INT_ATTACK_NOT_FROM_BELOW) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif attack_object(o, interaction); @@ -1495,7 +1495,7 @@ u32 check_object_grab_mario(struct MarioState *m, UNUSED u32 interactType, struc update_mario_sound_and_camera(m); play_sound(SOUND_MARIO_OOOF, m->marioObj->header.gfx.cameraToObject); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif return set_mario_action(m, ACT_GRABBED, 0); @@ -1546,7 +1546,7 @@ u32 interact_pole(struct MarioState *m, UNUSED u32 interactType, struct Object * marioObj->oMarioPoleYawVel = (s32)(m->forwardVel * 0x100 + 0x1000); #endif reset_mario_pitch(m); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif return set_mario_action(m, ACT_GRAB_POLE_FAST, 0); @@ -1564,11 +1564,12 @@ u32 interact_hoot(struct MarioState *m, UNUSED u32 interactType, struct Object * if (actionId >= 0x080 && actionId < 0x098 && (gGlobalTimer - m->usedObj->oHootMarioReleaseTime > 30)) { mario_stop_riding_and_holding(m); - o->oInteractStatus = INT_STATUS_HOOT_GRABBED_BY_MARIO; + + o->oInteractStatus = TRUE; //! Note: Not a flag, treated as a TRUE/FALSE statement m->interactObj = o; m->usedObj = o; -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif update_mario_sound_and_camera(m); @@ -1781,7 +1782,7 @@ void mario_process_interactions(struct MarioState *m) { if (!(m->action & ACT_FLAG_INTANGIBLE) && m->collidedObjInteractTypes != 0) { s32 i; - for (i = 0; i < 31; i++) { + for (i = 0; i < ARRAY_COUNT(sInteractionHandlers); i++) { u32 interactType = sInteractionHandlers[i].interactType; if (m->collidedObjInteractTypes & interactType) { struct Object *object = mario_get_collided_object(m, interactType); @@ -1798,7 +1799,7 @@ void mario_process_interactions(struct MarioState *m) { } if (m->invincTimer > 0 && !sDelayInvincTimer) { - m->invincTimer -= 1; + m->invincTimer--; } //! If the kick/punch flags are set and an object collision changes Mario's diff --git a/src/game/interaction.h b/src/game/interaction.h index dd27aad8..9d063a81 100644 --- a/src/game/interaction.h +++ b/src/game/interaction.h @@ -80,18 +80,25 @@ #define INT_STATUS_ATTACK_MASK 0x000000FF -#define INT_STATUS_HOOT_GRABBED_BY_MARIO (1 << 0) /* 0x00000001 */ -#define INT_STATUS_MARIO_UNK1 (1 << 1) /* 0x00000002 */ +// Mario Interaction Status +#define INT_STATUS_MARIO_STUNNED (1 << 0) /* 0x00000001 */ +#define INT_STATUS_MARIO_KNOCKBACK_DMG (1 << 1) /* 0x00000002 */ #define INT_STATUS_MARIO_UNK2 (1 << 2) /* 0x00000004 */ #define INT_STATUS_MARIO_DROP_OBJECT (1 << 3) /* 0x00000008 */ -#define INT_STATUS_HIT_BY_SHOCKWAVE (1 << 4) /* 0x00000010 */ +#define INT_STATUS_MARIO_SHOCKWAVE (1 << 4) /* 0x00000010 */ #define INT_STATUS_MARIO_UNK5 (1 << 5) /* 0x00000020 */ #define INT_STATUS_MARIO_UNK6 (1 << 6) /* 0x00000040 */ #define INT_STATUS_MARIO_UNK7 (1 << 7) /* 0x00000080 */ + +// Object Interaction Status #define INT_STATUS_GRABBED_MARIO (1 << 11) /* 0x00000800 */ #define INT_STATUS_ATTACKED_MARIO (1 << 13) /* 0x00002000 */ #define INT_STATUS_WAS_ATTACKED (1 << 14) /* 0x00004000 */ #define INT_STATUS_INTERACTED (1 << 15) /* 0x00008000 */ +#define INT_STATUS_UNK16 (1 << 16) /* 0x00010000 */ +#define INT_STATUS_UNK17 (1 << 17) /* 0x00020000 */ +#define INT_STATUS_UNK18 (1 << 18) /* 0x00040000 */ +#define INT_STATUS_UNK19 (1 << 19) /* 0x00080000 */ #define INT_STATUS_TRAP_TURN (1 << 20) /* 0x00100000 */ #define INT_STATUS_HIT_MINE (1 << 21) /* 0x00200000 */ #define INT_STATUS_STOP_RIDING (1 << 22) /* 0x00400000 */ diff --git a/src/game/level_geo.h b/src/game/level_geo.h index a99f9ddd..e4b4016c 100644 --- a/src/game/level_geo.h +++ b/src/game/level_geo.h @@ -4,13 +4,6 @@ #include #include -struct Struct802761D0 -{ - u16 unk0; - s16 unk2; - u8 filler4[0x18-0x4]; -}; - Gfx *geo_envfx_main(s32 callContext, struct GraphNode *node, Mat4 mtxf); Gfx *geo_skybox_main(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx); diff --git a/src/game/level_update.c b/src/game/level_update.c index 4ecb9024..03d44077 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -55,28 +55,17 @@ const char *credits01[] = { "1GAME DIRECTOR", "SHIGERU MIYAMOTO" }; const char *credits02[] = { "2ASSISTANT DIRECTORS", "YOSHIAKI KOIZUMI", "TAKASHI TEZUKA" }; const char *credits03[] = { "2SYSTEM PROGRAMMERS", "YASUNARI NISHIDA", "YOSHINORI TANIMOTO" }; const char *credits04[] = { "3PROGRAMMERS", "HAJIME YAJIMA", "DAIKI IWAMOTO", "TOSHIO IWAWAKI" }; + #if defined(VERSION_JP) || defined(VERSION_SH) + const char *credits05[] = { "1CAMERA PROGRAMMER", "TAKUMI KAWAGOE" }; const char *credits06[] = { "1MARIO FACE PROGRAMMER", "GILES GODDARD" }; const char *credits07[] = { "2COURSE DIRECTORS", "YOICHI YAMADA", "YASUHISA YAMAMURA" }; const char *credits08[] = { "2COURSE DESIGNERS", "KENTA USUI", "NAOKI MORI" }; -const char *credits09[] = { "3COURSE DESIGNERS", "YOSHIKI HARUHANA", "MAKOTO MIYANAGA", - "KATSUHIKO KANNO" }; +const char *credits09[] = { "3COURSE DESIGNERS", "YOSHIKI HARUHANA", "MAKOTO MIYANAGA", "KATSUHIKO KANNO" }; const char *credits10[] = { "1SOUND COMPOSER", "KOJI KONDO" }; -#ifdef VERSION_SH -const char *credits11[] = { "4SOUND EFFECTS", "SOUND PROGRAMMER", "YOJI INAGAKI", "HIDEAKI SHIMIZU" }; -const char *credits12[] = { "23D ANIMATORS", "YOSHIAKI KOIZUMI", "SATORU TAKIZAWA" }; -const char *credits13[] = { "1CG DESIGNER", "MASANAO ARIMOTO" }; -const char *credits14[] = { "3TECHNICAL SUPPORT", "TAKAO SAWANO", "HIROHITO YOSHIMOTO", "HIROTO YADA" }; -const char *credits15[] = { "1TECHNICAL SUPPORT", "SGI. 64PROJECT STAFF" }; -const char *credits16[] = { "2PROGRESS MANAGEMENT", "KIMIYOSHI FUKUI", "KEIZO KATO" }; -const char *credits17[] = { "4MARIO VOICE", "PEACH VOICE", "CHARLES MARTINET", "LESLIE SWAN" }; -const char *credits18[] = { "3SPECIAL THANKS TO", "JYOHO KAIHATUBU", "ALL NINTENDO", - "MARIO CLUB STAFF" }; -const char *credits19[] = { "1PRODUCER", "SHIGERU MIYAMOTO" }; -const char *credits20[] = { "1EXECUTIVE PRODUCER", "HIROSHI YAMAUCHI" }; -#else // VERSION_JP +#ifdef VERSION_JP const char *credits11[] = { "1SOUND EFFECTS", "YOJI INAGAKI" }; const char *credits12[] = { "1SOUND PROGRAMMER", "HIDEAKI SHIMIZU" }; const char *credits13[] = { "23D ANIMATORS", "YOSHIAKI KOIZUMI", "SATORU TAKIZAWA" }; @@ -84,55 +73,63 @@ const char *credits14[] = { "1CG DESIGNER", "MASANAO ARIMOTO" }; const char *credits15[] = { "3TECHNICAL SUPPORT", "TAKAO SAWANO", "HIROHITO YOSHIMOTO", "HIROTO YADA" }; const char *credits16[] = { "1TECHNICAL SUPPORT", "SGI. 64PROJECT STAFF" }; const char *credits17[] = { "2PROGRESS MANAGEMENT", "KIMIYOSHI FUKUI", "KEIZO KATO" }; -const char *credits18[] = { "3SPECIAL THANKS TO", "JYOHO KAIHATUBU", "ALL NINTENDO", - "MARIO CLUB STAFF" }; -const char *credits19[] = { "1PRODUCER", "SHIGERU MIYAMOTO" }; -const char *credits20[] = { "1EXECUTIVE PRODUCER", "HIROSHI YAMAUCHI" }; +#else // VERSION_SH +// Shindou combines sound effects and sound programmer in order to make room for Mario voice and Peach voice +const char *credits11[] = { "4SOUND EFFECTS", "SOUND PROGRAMMER", "YOJI INAGAKI", "HIDEAKI SHIMIZU" }; +const char *credits12[] = { "23D ANIMATORS", "YOSHIAKI KOIZUMI", "SATORU TAKIZAWA" }; +const char *credits13[] = { "1CG DESIGNER", "MASANAO ARIMOTO" }; +const char *credits14[] = { "3TECHNICAL SUPPORT", "TAKAO SAWANO", "HIROHITO YOSHIMOTO", "HIROTO YADA" }; +const char *credits15[] = { "1TECHNICAL SUPPORT", "SGI. 64PROJECT STAFF" }; +const char *credits16[] = { "2PROGRESS MANAGEMENT", "KIMIYOSHI FUKUI", "KEIZO KATO" }; #endif + #else // VERSION_US || VERSION_EU -const char *credits05[] = { - "4CAMERA PROGRAMMER", "MARIO FACE PROGRAMMER", "TAKUMI KAWAGOE", "GILES GODDARD" -}; // US combines camera programmer and Mario face programmer + +// US and EU combine camera programmer and Mario face programmer... +const char *credits05[] = { "4CAMERA PROGRAMMER", "MARIO FACE PROGRAMMER", "TAKUMI KAWAGOE", "GILES GODDARD" }; const char *credits06[] = { "2COURSE DIRECTORS", "YOICHI YAMADA", "YASUHISA YAMAMURA" }; const char *credits07[] = { "2COURSE DESIGNERS", "KENTA USUI", "NAOKI MORI" }; -const char *credits08[] = { "3COURSE DESIGNERS", "YOSHIKI HARUHANA", "MAKOTO MIYANAGA", - "KATSUHIKO KANNO" }; +const char *credits08[] = { "3COURSE DESIGNERS", "YOSHIKI HARUHANA", "MAKOTO MIYANAGA", "KATSUHIKO KANNO" }; + #ifdef VERSION_US const char *credits09[] = { "1SOUND COMPOSER", "KOJI KONDO" }; -const char *credits10[] = { "4SOUND EFFECTS", "SOUND PROGRAMMER", "YOJI INAGAKI", - "HIDEAKI SHIMIZU" }; // as well as sound effects and sound programmer +// ...as well as sound effects and sound programmer in order to make room for screen text writer, Mario voice, and Peach voice +const char *credits10[] = { "4SOUND EFFECTS", "SOUND PROGRAMMER", "YOJI INAGAKI", "HIDEAKI SHIMIZU" }; const char *credits11[] = { "23-D ANIMATORS", "YOSHIAKI KOIZUMI", "SATORU TAKIZAWA" }; const char *credits12[] = { "1ADDITIONAL GRAPHICS", "MASANAO ARIMOTO" }; const char *credits13[] = { "3TECHNICAL SUPPORT", "TAKAO SAWANO", "HIROHITO YOSHIMOTO", "HIROTO YADA" }; const char *credits14[] = { "1TECHNICAL SUPPORT", "SGI N64 PROJECT STAFF" }; const char *credits15[] = { "2PROGRESS MANAGEMENT", "KIMIYOSHI FUKUI", "KEIZO KATO" }; -const char *credits16[] = { "5SCREEN TEXT WRITER", "TRANSLATION", "LESLIE SWAN", "MINA AKINO", - "HIRO YAMADA" }; // ...in order to make room for these 2 new lines +const char *credits16[] = { "5SCREEN TEXT WRITER", "TRANSLATION", "LESLIE SWAN", "MINA AKINO", "HIRO YAMADA" }; #else // VERSION_EU -const char *credits09[] = { "7SOUND COMPOSER", "SOUND EFFECTS", "SOUND PROGRAMMER", "KOJI KONDO", - "YOJI INAGAKI", "HIDEAKI SHIMIZU" }; -const char *credits10[] = { "63-D ANIMATORS", "ADDITIONAL GRAPHICS", "YOSHIAKI KOIZUMI", "SATORU TAKIZAWA", - "MASANAO ARIMOTO" }; +// ...as well as sound composer, sound effects, and sound programmer, and... +const char *credits09[] = { "7SOUND COMPOSER", "SOUND EFFECTS", "SOUND PROGRAMMER", "KOJI KONDO", "YOJI INAGAKI", "HIDEAKI SHIMIZU" }; +// ...3D animators and additional graphics in order to make room for screen text writer(s), Mario voice, and Peach voice +const char *credits10[] = { "63-D ANIMATORS", "ADDITIONAL GRAPHICS", "YOSHIAKI KOIZUMI", "SATORU TAKIZAWA", "MASANAO ARIMOTO" }; const char *credits11[] = { "3TECHNICAL SUPPORT", "TAKAO SAWANO", "HIROHITO YOSHIMOTO", "HIROTO YADA" }; const char *credits12[] = { "1TECHNICAL SUPPORT", "SGI N64 PROJECT STAFF" }; const char *credits13[] = { "2PROGRESS MANAGEMENT", "KIMIYOSHI FUKUI", "KEIZO KATO" }; -const char *credits14[] = { "5SCREEN TEXT WRITER", "ENGLISH TRANSLATION", "LESLIE SWAN", "MINA AKINO", - "HIRO YAMADA" }; -const char *credits15[] = { "4SCREEN TEXT WRITER", "FRENCH TRANSLATION", "JULIEN BARDAKOFF", - "KENJI HARAGUCHI" }; -const char *credits16[] = { "4SCREEN TEXT WRITER", "GERMAN TRANSLATION", "THOMAS GOERG", - "THOMAS SPINDLER" }; +const char *credits14[] = { "5SCREEN TEXT WRITER", "ENGLISH TRANSLATION", "LESLIE SWAN", "MINA AKINO", "HIRO YAMADA" }; +const char *credits15[] = { "4SCREEN TEXT WRITER", "FRENCH TRANSLATION", "JULIEN BARDAKOFF", "KENJI HARAGUCHI" }; +const char *credits16[] = { "4SCREEN TEXT WRITER", "GERMAN TRANSLATION", "THOMAS GOERG", "THOMAS SPINDLER" }; #endif + +#endif + +#ifndef VERSION_JP const char *credits17[] = { "4MARIO VOICE", "PEACH VOICE", "CHARLES MARTINET", "LESLIE SWAN" }; -const char *credits18[] = { "3SPECIAL THANKS TO", "EAD STAFF", "ALL NINTENDO PERSONNEL", -#ifdef VERSION_US - "MARIO CLUB STAFF" }; -#else // VERSION_EU - "SUPER MARIO CLUB STAFF" }; #endif + +#if defined(VERSION_JP) || defined(VERSION_SH) +const char *credits18[] = { "3SPECIAL THANKS TO", "JYOHO KAIHATUBU", "ALL NINTENDO", "MARIO CLUB STAFF" }; +#elif defined(VERSION_US) +const char *credits18[] = { "3SPECIAL THANKS TO", "EAD STAFF", "ALL NINTENDO PERSONNEL", "MARIO CLUB STAFF" }; +#else // VERSION_EU +const char *credits18[] = { "3SPECIAL THANKS TO", "EAD STAFF", "ALL NINTENDO PERSONNEL", "SUPER MARIO CLUB STAFF" }; +#endif + const char *credits19[] = { "1PRODUCER", "SHIGERU MIYAMOTO" }; const char *credits20[] = { "1EXECUTIVE PRODUCER", "HIROSHI YAMAUCHI" }; -#endif struct CreditsEntry sCreditsSequence[] = { @@ -182,8 +179,8 @@ s8 gNeverEnteredCastle; struct MarioState *gMarioState = &gMarioStates[0]; u8 unused1[4] = { 0 }; s8 sWarpCheckpointActive = FALSE; -u8 unused3[4]; -u8 unused4[2]; +u8 unused2[4]; +u8 unused3[2]; u16 level_control_timer(s32 timerOp) { switch (timerOp) { @@ -212,10 +209,10 @@ u16 level_control_timer(s32 timerOp) { } u32 pressed_pause(void) { - u32 val4 = get_dialog_id() >= 0; + u32 dialogActive = get_dialog_id() >= 0; u32 intangible = (gMarioState->action & ACT_FLAG_INTANGIBLE) != 0; - if (!intangible && !val4 && !gWarpTransition.isActive && sDelayedWarpOp == WARP_OP_NONE + if (!intangible && !dialogActive && !gWarpTransition.isActive && sDelayedWarpOp == WARP_OP_NONE && (gPlayer1Controller->buttonPressed & START_BUTTON)) { return TRUE; } @@ -266,12 +263,13 @@ void load_level_init_text(u32 arg) { gotAchievement = save_file_get_flags() & SAVE_FLAG_HAVE_WING_CAP; break; - case 255: + case (u8)DIALOG_NONE: // 255, cast value to u8 to match (-1) gotAchievement = TRUE; break; default: - gotAchievement = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1); + gotAchievement = + save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); break; } @@ -440,10 +438,9 @@ void init_mario_after_warp(void) { play_cap_music(SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP)); } -#ifndef VERSION_JP +#if BUGFIX_KOOPA_RACE_MUSIC if (gCurrLevelNum == LEVEL_BOB - && get_current_background_music() != SEQUENCE_ARGS(4, SEQ_LEVEL_SLIDE) - && sTimerRunning) { + && get_current_background_music() != SEQUENCE_ARGS(4, SEQ_LEVEL_SLIDE) && sTimerRunning) { play_music(SEQ_PLAYER_LEVEL, SEQUENCE_ARGS(4, SEQ_LEVEL_SLIDE), 0); } #endif @@ -454,8 +451,10 @@ void init_mario_after_warp(void) { #else && sWarpDest.nodeId == 31 #endif - ) + ) { play_sound(SOUND_MENU_MARIO_CASTLE_WARP, gGlobalSoundSource); + } + #ifndef VERSION_JP if (sWarpDest.levelNum == LEVEL_CASTLE_GROUNDS && sWarpDest.areaIdx == 1 && (sWarpDest.nodeId == 7 || sWarpDest.nodeId == 10 || sWarpDest.nodeId == 20 @@ -585,7 +584,7 @@ s16 music_changed_through_warp(s16 arg) { sp2C = get_current_background_music(); if (sp2C == SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP | SEQ_VARIATION) || sp2C == SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP)) { - val4 = 0; + val4 = FALSE; } } else { u16 val8 = gAreas[destArea].musicParam; @@ -689,7 +688,7 @@ void initiate_painting_warp(void) { play_sound(SOUND_MENU_STAR_SOUND, gGlobalSoundSource); fadeout_music(398); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(80, 70); func_sh_8024C89C(1); #endif @@ -864,7 +863,7 @@ void initiate_delayed_warp(void) { case WARP_OP_CREDITS_NEXT: sound_banks_disable(SEQ_PLAYER_SFX, SOUND_BANKS_ALL); - gCurrCreditsEntry += 1; + gCurrCreditsEntry++; gCurrActNum = gCurrCreditsEntry->unk02 & 0x07; if ((gCurrCreditsEntry + 1)->levelNum == LEVEL_NONE) { destWarpNode = WARP_NODE_CREDITS_END; @@ -903,7 +902,7 @@ void update_hud_values(void) { } if (gHudDisplay.coins < gMarioState->numCoins) { - if (gGlobalTimer & 0x00000001) { + if (gGlobalTimer & 1) { u32 coinSound; if (gMarioState->action & (ACT_FLAG_SWIMMING | ACT_FLAG_METAL_WATER)) { coinSound = SOUND_GENERAL_COIN_WATER; @@ -911,7 +910,7 @@ void update_hud_values(void) { coinSound = SOUND_GENERAL_COIN; } - gHudDisplay.coins += 1; + gHudDisplay.coins++; play_sound(coinSound, gMarioState->marioObj->header.gfx.cameraToObject); } } @@ -982,7 +981,7 @@ s32 play_mode_normal(void) { check_instant_warp(); if (sTimerRunning && gHudDisplay.timer < 17999) { - gHudDisplay.timer += 1; + gHudDisplay.timer++; } area_update_objects(); @@ -1004,7 +1003,7 @@ s32 play_mode_normal(void) { set_play_mode(PLAY_MODE_CHANGE_AREA); } else if (pressed_pause()) { lower_background_noise(1); -#ifdef VERSION_SH +#if ENABLE_RUMBLE cancel_rumble(); #endif gCameraMovementFlags |= CAM_MOVE_PAUSE_SCREEN; @@ -1016,15 +1015,13 @@ s32 play_mode_normal(void) { } s32 play_mode_paused(void) { - if (gPauseScreenMode == 0) { - set_menu_mode(RENDER_PAUSE_SCREEN); - } else if (gPauseScreenMode == 1) { + if (gMenuOptSelectIndex == MENU_OPT_NONE) { + set_menu_mode(MENU_MODE_RENDER_PAUSE_SCREEN); + } else if (gMenuOptSelectIndex == MENU_OPT_DEFAULT) { raise_background_noise(1); gCameraMovementFlags &= ~CAM_MOVE_PAUSE_SCREEN; set_play_mode(PLAY_MODE_NORMAL); - } else { - // Exit level - + } else { // MENU_OPT_EXIT_COURSE if (gDebugLevelSelect) { fade_into_special_warp(-9, 1); } else { @@ -1074,14 +1071,14 @@ void level_set_transition(s16 length, void (*updateFunction)(s16 *)) { s32 play_mode_change_area(void) { //! This maybe was supposed to be sTransitionTimer == -1? sTransitionUpdate // is never set to -1. - if (sTransitionUpdate == (void (*)(s16 *)) - 1) { + if (sTransitionUpdate == (void (*)(s16 *)) -1) { update_camera(gCurrentArea->camera); } else if (sTransitionUpdate != NULL) { sTransitionUpdate(&sTransitionTimer); } if (sTransitionTimer > 0) { - sTransitionTimer -= 1; + sTransitionTimer--; } if (sTransitionTimer == 0) { @@ -1118,7 +1115,7 @@ s32 play_mode_change_level(void) { /** * Unused play mode. Doesn't call transition update and doesn't reset transition at the end. */ -static s32 play_mode_unused(void) { +UNUSED static s32 play_mode_unused(void) { if (--sTransitionTimer == -1) { gHudDisplay.flags = HUD_DISPLAY_NONE; @@ -1162,7 +1159,7 @@ s32 update_level(void) { } s32 init_level(void) { - s32 val4 = 0; + s32 val4 = FALSE; set_play_mode(PLAY_MODE_NORMAL); @@ -1201,13 +1198,13 @@ s32 init_level(void) { set_mario_action(gMarioState, ACT_IDLE, 0); } else { set_mario_action(gMarioState, ACT_INTRO_CUTSCENE, 0); - val4 = 1; + val4 = TRUE; } } } } - if (val4 != 0) { + if (val4) { play_transition(WARP_TRANSITION_FADE_FROM_COLOR, 0x5A, 0xFF, 0xFF, 0xFF); } else { play_transition(WARP_TRANSITION_FADE_FROM_STAR, 0x10, 0xFF, 0xFF, 0xFF); @@ -1217,7 +1214,7 @@ s32 init_level(void) { set_background_music(gCurrentArea->musicParam, gCurrentArea->musicParam2, 0); } } -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (gCurrDemoInput == NULL) { cancel_rumble(); } @@ -1250,8 +1247,8 @@ s32 lvl_init_or_update(s16 initOrUpdate, UNUSED s32 unused) { s32 lvl_init_from_save_file(UNUSED s16 arg0, s32 levelNum) { #ifdef VERSION_EU - s16 var = eu_get_language(); - switch (var) { + s16 language = eu_get_language(); + switch (language) { case LANGUAGE_ENGLISH: load_segment_decompress(0x19, _translation_en_mio0SegmentRomStart, _translation_en_mio0SegmentRomEnd); @@ -1300,7 +1297,8 @@ s32 lvl_set_current_level(UNUSED s16 arg0, s32 levelNum) { && gCurrLevelNum != LEVEL_BOWSER_3) { gMarioState->numCoins = 0; gHudDisplay.coins = 0; - gCurrCourseStarFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1); + gCurrCourseStarFlags = + save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); } if (gSavedCourseNum != gCurrCourseNum) { diff --git a/src/game/level_update.h b/src/game/level_update.h index 521b4efe..b55d2737 100644 --- a/src/game/level_update.h +++ b/src/game/level_update.h @@ -50,8 +50,7 @@ #define MARIO_SPAWN_UNKNOWN_27 0x27 -struct CreditsEntry -{ +struct CreditsEntry { /*0x00*/ u8 levelNum; /*0x01*/ u8 areaIndex; /*0x02*/ u8 unk02; @@ -69,7 +68,7 @@ extern s16 sCurrPlayMode; extern u16 D_80339ECA; extern s16 sTransitionTimer; extern void (*sTransitionUpdate)(s16 *); -extern u8 unused3[4]; +extern u8 unused2[4]; struct WarpDest { u8 type; @@ -86,7 +85,7 @@ extern s16 sDelayedWarpOp; extern s16 sDelayedWarpTimer; extern s16 sSourceWarpNodeId; extern s32 sDelayedWarpArg; -extern u8 unused4[2]; +extern u8 unused3[2]; extern s8 sTimerRunning; struct HudDisplay { diff --git a/src/game/macro_special_objects.c b/src/game/macro_special_objects.c index a0ef16ae..bd02e19c 100644 --- a/src/game/macro_special_objects.c +++ b/src/game/macro_special_objects.c @@ -79,7 +79,7 @@ void spawn_macro_abs_special(s32 model, const BehaviorScript *behavior, s16 x, s newObj->oMacroUnk110 = (f32) unkC; } -static void spawn_macro_coin_unknown(const BehaviorScript *behavior, s16 a1[]) { +UNUSED static void spawn_macro_coin_unknown(const BehaviorScript *behavior, s16 a1[]) { struct Object *sp3C; s16 model; @@ -105,7 +105,7 @@ struct LoadedPreset { #define MACRO_OBJ_PARAMS 4 void spawn_macro_objects(s16 areaIndex, s16 *macroObjList) { - UNUSED u32 pad5C; + UNUSED u8 filler[4]; s32 presetID; s16 macroObject[5]; // see the 5 #define statements above @@ -147,18 +147,18 @@ void spawn_macro_objects(s16 areaIndex, s16 *macroObjList) { if (((macroObject[MACRO_OBJ_PARAMS] >> 8) & RESPAWN_INFO_DONT_RESPAWN) != RESPAWN_INFO_DONT_RESPAWN) { // Spawn the new macro object. - newObj = - spawn_object_abs_with_rot(&gMacroObjectDefaultParent, // Parent object - 0, // Unused - preset.model, // Model ID - preset.behavior, // Behavior address - macroObject[MACRO_OBJ_X], // X-position - macroObject[MACRO_OBJ_Y], // Y-position - macroObject[MACRO_OBJ_Z], // Z-position - 0, // X-rotation - convert_rotation(macroObject[MACRO_OBJ_Y_ROT]), // Y-rotation - 0 // Z-rotation - ); + newObj = spawn_object_abs_with_rot( + &gMacroObjectDefaultParent, // Parent object + 0, // Unused + preset.model, // Model ID + preset.behavior, // Behavior address + macroObject[MACRO_OBJ_X], // X-position + macroObject[MACRO_OBJ_Y], // Y-position + macroObject[MACRO_OBJ_Z], // Z-position + 0, // X-rotation + convert_rotation(macroObject[MACRO_OBJ_Y_ROT]), // Y-rotation + 0 // Z-rotation + ); newObj->oUnk1A8 = macroObject[MACRO_OBJ_PARAMS]; newObj->oBehParams = ((macroObject[MACRO_OBJ_PARAMS] & 0x00FF) << 16) @@ -172,7 +172,7 @@ void spawn_macro_objects(s16 areaIndex, s16 *macroObjList) { } void spawn_macro_objects_hardcoded(s16 areaIndex, s16 *macroObjList) { - UNUSED u8 pad[8]; + UNUSED u8 filler1[8]; // This version of macroObjList has the preset and Y-Rotation separated, // and lacks behavior params. Might be an early version of the macro object list? @@ -182,7 +182,7 @@ void spawn_macro_objects_hardcoded(s16 areaIndex, s16 *macroObjList) { s16 macroObjPreset; s16 macroObjRY; // Y Rotation - UNUSED u8 pad2[10]; + UNUSED u8 filler2[10]; gMacroObjectDefaultParent.header.gfx.areaIndex = areaIndex; gMacroObjectDefaultParent.header.gfx.activeAreaIndex = areaIndex; @@ -203,7 +203,7 @@ void spawn_macro_objects_hardcoded(s16 areaIndex, s16 *macroObjList) { // However, BBH doesn't use this function so this might just be an early test? switch (macroObjPreset) { case 0: - spawn_macro_abs_yrot_2params(MODEL_NONE, bhvBooBossSpawnedBridge, macroObjX, macroObjY, + spawn_macro_abs_yrot_2params(MODEL_NONE, bhvBooStaircase, macroObjX, macroObjY, macroObjZ, macroObjRY, 0); break; case 1: diff --git a/src/game/main.c b/src/game/main.c index 9615f25a..3fd86ce3 100644 --- a/src/game/main.c +++ b/src/game/main.c @@ -26,7 +26,7 @@ OSThread gGameLoopThread; OSThread gSoundThread; OSIoMesg gDmaIoMesg; -OSMesg D_80339BEC; +OSMesg gMainReceivedMesg; OSMesgQueue gDmaMesgQueue; OSMesgQueue gSIEventMesgQueue; @@ -50,7 +50,7 @@ struct SPTask *sNextDisplaySPTask = NULL; s8 sAudioEnabled = TRUE; u32 gNumVblanks = 0; s8 gResetTimer = 0; -s8 D_8032C648 = 0; +s8 gNmiResetBarsTimer = 0; s8 gDebugLevelSelect = FALSE; s8 D_8032C650 = 0; @@ -89,6 +89,10 @@ void unknown_main_func(void) { // uninitialized OSTime time; u32 b; +#ifdef AVOID_UB + time = 0; + b = 0; +#endif osSetTime(time); osMapTLB(0, b, NULL, 0, 0, 0); @@ -143,7 +147,7 @@ extern void func_sh_802f69cc(void); void handle_nmi_request(void) { gResetTimer = 1; - D_8032C648 = 0; + gNmiResetBarsTimer = 0; stop_sounds_in_continuous_banks(); sound_banks_disable(SEQ_PLAYER_SFX, SOUND_BANKS_BACKGROUND); fadeout_music(90); @@ -179,7 +183,7 @@ void receive_new_tasks(void) { } void start_sptask(s32 taskType) { - UNUSED s32 pad; // needed to pad the stack + UNUSED u8 filler[4]; if (taskType == M_AUDTASK) { gActiveSPTask = sCurrentAudioSPTask; @@ -214,7 +218,7 @@ void pretend_audio_sptask_done(void) { } void handle_vblank(void) { - UNUSED s32 pad; // needed to pad the stack + UNUSED u8 filler[4]; stub_main_3(); gNumVblanks++; @@ -253,7 +257,7 @@ void handle_vblank(void) { start_sptask(M_GFXTASK); } } -#ifdef VERSION_SH +#if ENABLE_RUMBLE rumble_thread_update_vi(); #endif @@ -386,7 +390,8 @@ void dispatch_audio_sptask(struct SPTask *spTask) { } } -void send_display_list(struct SPTask *spTask) { +#ifndef TARGET_NDS +void exec_display_list(struct SPTask *spTask) { if (spTask != NULL) { osWritebackDCacheAll(); spTask->state = SPTASK_STATE_NOT_STARTED; @@ -399,6 +404,7 @@ void send_display_list(struct SPTask *spTask) { } } } +#endif void turn_on_audio(void) { sAudioEnabled = TRUE; @@ -448,7 +454,7 @@ void thread1_idle(UNUSED void *arg) { } void main_func(void) { - UNUSED u8 pad[64]; // needed to pad the stack + UNUSED u8 filler[64]; osInitialize(); stub_main_1(); diff --git a/src/game/main.h b/src/game/main.h index 58bd659e..91f99015 100644 --- a/src/game/main.h +++ b/src/game/main.h @@ -1,6 +1,8 @@ #ifndef MAIN_H #define MAIN_H +#include "config.h" + struct RumbleData { u8 unk00; u8 unk01; @@ -24,7 +26,7 @@ extern OSThread gIdleThread; extern OSThread gMainThread; extern OSThread gGameLoopThread; extern OSThread gSoundThread; -#ifdef VERSION_SH +#if ENABLE_RUMBLE extern OSThread gRumblePakThread; extern s32 gRumblePakPfs; // Actually an OSPfs but we don't have that header yet @@ -33,7 +35,7 @@ extern s32 gRumblePakPfs; // Actually an OSPfs but we don't have that header yet extern OSMesgQueue gPIMesgQueue; extern OSMesgQueue gIntrMesgQueue; extern OSMesgQueue gSPTaskMesgQueue; -#ifdef VERSION_SH +#if ENABLE_RUMBLE extern OSMesgQueue gRumblePakSchedulerMesgQueue; extern OSMesgQueue gRumbleThreadVIMesgQueue; #endif @@ -43,10 +45,10 @@ extern OSMesg gSIEventMesgBuf[1]; extern OSMesg gIntrMesgBuf[16]; extern OSMesg gUnknownMesgBuf[16]; extern OSIoMesg gDmaIoMesg; -extern OSMesg D_80339BEC; +extern OSMesg gMainReceivedMesg; extern OSMesgQueue gDmaMesgQueue; extern OSMesgQueue gSIEventMesgQueue; -#ifdef VERSION_SH +#if ENABLE_RUMBLE extern OSMesg gRumblePakSchedulerMesgBuf[1]; extern OSMesg gRumbleThreadVIMesgBuf[1]; @@ -59,7 +61,7 @@ extern struct VblankHandler *gVblankHandler2; extern struct SPTask *gActiveSPTask; extern u32 gNumVblanks; extern s8 gResetTimer; -extern s8 D_8032C648; +extern s8 gNmiResetBarsTimer; extern s8 gDebugLevelSelect; extern s8 D_8032C650; extern s8 gShowProfiler; @@ -67,6 +69,6 @@ extern s8 gShowDebugText; void set_vblank_handler(s32 index, struct VblankHandler *handler, OSMesgQueue *queue, OSMesg *msg); void dispatch_audio_sptask(struct SPTask *spTask); -void send_display_list(struct SPTask *spTask); +void exec_display_list(struct SPTask *spTask); #endif // MAIN_H diff --git a/src/game/mario.c b/src/game/mario.c index 96df7938..cc5e8646 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -34,7 +34,7 @@ #include "rumble_init.h" u32 unused80339F10; -s8 filler80339F1C[20]; +u8 unused80339F1C[20]; /************************************************** * ANIMATIONS * @@ -63,9 +63,9 @@ s32 is_anim_past_end(struct MarioState *m) { */ s16 set_mario_animation(struct MarioState *m, s32 targetAnimID) { struct Object *o = m->marioObj; - struct Animation *targetAnim = m->animation->targetAnim; + struct Animation *targetAnim = m->animList->bufTarget; - if (load_patchable_table(m->animation, targetAnimID)) { + if (load_patchable_table(m->animList, targetAnimID)) { targetAnim->values = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->values); targetAnim->index = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->index); } @@ -96,9 +96,9 @@ s16 set_mario_animation(struct MarioState *m, s32 targetAnimID) { */ s16 set_mario_anim_with_accel(struct MarioState *m, s32 targetAnimID, s32 accel) { struct Object *o = m->marioObj; - struct Animation *targetAnim = m->animation->targetAnim; + struct Animation *targetAnim = m->animList->bufTarget; - if (load_patchable_table(m->animation, targetAnimID)) { + if (load_patchable_table(m->animList, targetAnimID)) { targetAnim->values = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->values); targetAnim->index = (void *) VIRTUAL_TO_PHYSICAL((u8 *) targetAnim + (uintptr_t) targetAnim->index); } @@ -133,7 +133,7 @@ void set_anim_to_frame(struct MarioState *m, s16 animFrame) { struct AnimInfo *animInfo = &m->marioObj->header.gfx.animInfo; struct Animation *curAnim = animInfo->curAnim; - if (animInfo->animAccel) { + if (animInfo->animAccel != 0) { if (curAnim->flags & ANIM_FLAG_FORWARD) { animInfo->animFrameAccelAssist = (animFrame << 0x10) + animInfo->animAccel; } else { @@ -154,7 +154,7 @@ s32 is_anim_past_frame(struct MarioState *m, s16 animFrame) { struct AnimInfo *animInfo = &m->marioObj->header.gfx.animInfo; struct Animation *curAnim = animInfo->curAnim; - if (animInfo->animAccel) { + if (animInfo->animAccel != 0) { if (curAnim->flags & ANIM_FLAG_FORWARD) { isPastFrame = (animInfo->animFrameAccelAssist > acceleratedFrame) @@ -545,7 +545,7 @@ struct Surface *resolve_and_return_wall_collisions(Vec3f pos, f32 offset, f32 ra * Finds the ceiling from a vec3f horizontally and a height (with 80 vertical buffer). */ f32 vec3f_find_ceil(Vec3f pos, f32 height, struct Surface **ceil) { - UNUSED f32 unused; + UNUSED u8 filler[4]; return find_ceil(pos[0], height + 80.0f, pos[2], ceil); } @@ -774,7 +774,7 @@ static void set_mario_y_vel_based_on_fspeed(struct MarioState *m, f32 initialVel * Transitions for a variety of airborne actions. */ static u32 set_mario_action_airborne(struct MarioState *m, u32 action, u32 actionArg) { - f32 fowardVel; + f32 forwardVel; if ((m->squishTimer != 0 || m->quicksandDepth >= 1.0f) && (action == ACT_DOUBLE_JUMP || action == ACT_TWIRLING)) { @@ -854,10 +854,10 @@ static u32 set_mario_action_airborne(struct MarioState *m, u32 action, u32 actio break; case ACT_DIVE: - if ((fowardVel = m->forwardVel + 15.0f) > 48.0f) { - fowardVel = 48.0f; + if ((forwardVel = m->forwardVel + 15.0f) > 48.0f) { + forwardVel = 48.0f; } - mario_set_forward_vel(m, fowardVel); + mario_set_forward_vel(m, forwardVel); break; case ACT_LONG_JUMP: @@ -1277,13 +1277,13 @@ void update_mario_button_inputs(struct MarioState *m) { if (m->input & INPUT_A_PRESSED) { m->framesSinceA = 0; } else if (m->framesSinceA < 0xFF) { - m->framesSinceA += 1; + m->framesSinceA++; } if (m->input & INPUT_B_PRESSED) { m->framesSinceB = 0; } else if (m->framesSinceB < 0xFF) { - m->framesSinceB += 1; + m->framesSinceB++; } } @@ -1393,10 +1393,11 @@ void update_mario_inputs(struct MarioState *m) { if (!(m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED))) { m->input |= INPUT_UNKNOWN_5; } - + + // These 3 flags are defined by Bowser stomping attacks if (m->marioObj->oInteractStatus - & (INT_STATUS_HOOT_GRABBED_BY_MARIO | INT_STATUS_MARIO_UNK1 | INT_STATUS_HIT_BY_SHOCKWAVE)) { - m->input |= INPUT_UNKNOWN_10; + & (INT_STATUS_MARIO_STUNNED | INT_STATUS_MARIO_KNOCKBACK_DMG | INT_STATUS_MARIO_SHOCKWAVE)) { + m->input |= INPUT_STOMPED; } // This function is located near other unused trampoline functions, @@ -1495,8 +1496,8 @@ void update_mario_health(struct MarioState *m) { // Play a noise to alert the player when Mario is close to drowning. if (((m->action & ACT_GROUP_MASK) == ACT_GROUP_SUBMERGED) && (m->health < 0x300)) { play_sound(SOUND_MOVING_ALMOST_DROWNING, gGlobalSoundSource); -#ifdef VERSION_SH - if (!gRumblePakTimer) { +#if ENABLE_RUMBLE + if (gRumblePakTimer == 0) { gRumblePakTimer = 36; if (is_rumble_finished_and_queue_empty()) { queue_rumble_data(3, 30); @@ -1661,7 +1662,7 @@ void mario_update_hitbox_and_cap_model(struct MarioState *m) { * An unused and possibly a debug function. Z + another button input * sets Mario with a different cap. */ -static void debug_update_mario_cap(u16 button, s32 flags, u16 capTimer, u16 capMusic) { +UNUSED static void debug_update_mario_cap(u16 button, s32 flags, u16 capTimer, u16 capMusic) { // This checks for Z_TRIG instead of Z_DOWN flag // (which is also what other debug functions do), // so likely debug behavior rather than unused behavior. @@ -1677,7 +1678,7 @@ static void debug_update_mario_cap(u16 button, s32 flags, u16 capTimer, u16 capM } } -#ifdef VERSION_SH +#if ENABLE_RUMBLE void func_sh_8025574C(void) { if (gMarioState->particleFlags & PARTICLE_HORIZONTAL_STAR) { queue_rumble_data(5, 80); @@ -1770,7 +1771,7 @@ s32 execute_mario_action(UNUSED struct Object *o) { play_infinite_stairs_music(); gMarioState->marioObj->oInteractStatus = 0; -#ifdef VERSION_SH +#if ENABLE_RUMBLE func_sh_8025574C(); #endif @@ -1875,7 +1876,7 @@ void init_mario_from_save_file(void) { gMarioState->statusForCamera = &gPlayerCameraState[0]; gMarioState->marioBodyState = &gBodyStates[0]; gMarioState->controller = &gControllers[0]; - gMarioState->animation = &D_80339D10; + gMarioState->animList = &gMarioAnimsBuf; gMarioState->numCoins = 0; gMarioState->numStars = diff --git a/src/game/mario_actions_airborne.c b/src/game/mario_actions_airborne.c index 34090a55..60c7c091 100644 --- a/src/game/mario_actions_airborne.c +++ b/src/game/mario_actions_airborne.c @@ -65,7 +65,11 @@ s32 check_fall_damage(struct MarioState *m, u32 hardFallAction) { fallHeight = m->peakHeight - m->pos[1]; #pragma GCC diagnostic push +#if defined(__clang__) +#pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" +#elif defined(__GNUC__) #pragma GCC diagnostic ignored "-Wtype-limits" +#endif //! Never true if (m->actionState == ACT_GROUND_POUND) { @@ -80,7 +84,7 @@ s32 check_fall_damage(struct MarioState *m, u32 hardFallAction) { if (m->vel[1] < -55.0f) { if (fallHeight > 3000.0f) { m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 16 : 24; -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif set_camera_shake_from_hit(SHAKE_FALL_DAMAGE); @@ -89,7 +93,7 @@ s32 check_fall_damage(struct MarioState *m, u32 hardFallAction) { } else if (fallHeight > damageHeight && !mario_floor_is_slippery(m)) { m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 8 : 12; m->squishTimer = 30; -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif set_camera_shake_from_hit(SHAKE_FALL_DAMAGE); @@ -133,7 +137,7 @@ s32 check_fall_damage_or_get_stuck(struct MarioState *m, u32 hardFallAction) { #endif m->particleFlags |= PARTICLE_MIST_CIRCLE; drop_and_set_mario_action(m, ACT_FEET_STUCK_IN_GROUND, 0); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif return TRUE; @@ -327,7 +331,7 @@ void update_flying_pitch(struct MarioState *m) { } void update_flying(struct MarioState *m) { - UNUSED u32 unused; + UNUSED u8 filler[4]; update_flying_pitch(m); update_flying_yaw(m); @@ -385,7 +389,7 @@ u32 common_air_action_step(struct MarioState *m, u32 landAction, s32 animation, set_mario_animation(m, animation); if (m->forwardVel > 16.0f) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 40); #endif mario_bonk_reflection(m, FALSE); @@ -493,7 +497,7 @@ s32 act_triple_jump(struct MarioState *m) { #endif common_air_action_step(m, ACT_TRIPLE_JUMP_LAND, MARIO_ANIM_TRIPLE_JUMP, 0); -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (m->action == ACT_TRIPLE_JUMP_LAND) { queue_rumble_data(5, 40); } @@ -509,7 +513,7 @@ s32 act_backflip(struct MarioState *m) { play_mario_sound(m, SOUND_ACTION_TERRAIN_JUMP, SOUND_MARIO_YAH_WAH_HOO); common_air_action_step(m, ACT_BACKFLIP_LAND, MARIO_ANIM_BACKFLIP, 0); -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (m->action == ACT_BACKFLIP_LAND) { queue_rumble_data(5, 40); } @@ -641,7 +645,7 @@ s32 act_long_jump(struct MarioState *m) { } common_air_action_step(m, ACT_LONG_JUMP_LAND, animation, AIR_STEP_CHECK_LEDGE_GRAB); -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (m->action == ACT_LONG_JUMP_LAND) { queue_rumble_data(5, 40); } @@ -712,7 +716,7 @@ s32 act_twirling(struct MarioState *m) { } m->marioObj->header.gfx.angle[1] += m->twirlYaw; -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers(); #endif return FALSE; @@ -749,7 +753,7 @@ s32 act_dive(struct MarioState *m) { case AIR_STEP_LANDED: if (should_get_stuck_in_ground(m) && m->faceAngle[0] == -0x2AAA) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif #ifdef VERSION_JP @@ -947,7 +951,7 @@ s32 act_ground_pound(struct MarioState *m) { stepResult = perform_air_step(m, 0); if (stepResult == AIR_STEP_LANDED) { if (should_get_stuck_in_ground(m)) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif #ifdef VERSION_JP @@ -998,7 +1002,7 @@ s32 act_burning_jump(struct MarioState *m) { if (m->health < 0x100) { m->health = 0xFF; } -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers(); #endif return FALSE; @@ -1020,7 +1024,7 @@ s32 act_burning_fall(struct MarioState *m) { if (m->health < 0x100) { m->health = 0xFF; } -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers(); #endif return FALSE; @@ -1071,7 +1075,7 @@ s32 act_crazy_box_bounce(struct MarioState *m) { m->heldObj = NULL; set_mario_action(m, ACT_STOMACH_SLIDE, 0); } -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif m->particleFlags |= PARTICLE_MIST_CIRCLE; @@ -1103,7 +1107,7 @@ u32 common_air_knockback_step(struct MarioState *m, u32 landAction, u32 hardFall break; case AIR_STEP_LANDED: -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (m->action != ACT_SOFT_BONK) { queue_rumble_data(5, 40); } @@ -1505,13 +1509,13 @@ s32 act_hold_butt_slide_air(struct MarioState *m) { } s32 act_lava_boost(struct MarioState *m) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (!(m->flags & MARIO_MARIO_SOUND_PLAYED)) { +#endif play_sound_if_no_flag(m, SOUND_MARIO_ON_FIRE, MARIO_MARIO_SOUND_PLAYED); +#if ENABLE_RUMBLE queue_rumble_data(5, 80); } -#else - play_sound_if_no_flag(m, SOUND_MARIO_ON_FIRE, MARIO_MARIO_SOUND_PLAYED); #endif if (!(m->input & INPUT_NONZERO_ANALOG)) { @@ -1529,7 +1533,7 @@ s32 act_lava_boost(struct MarioState *m) { } m->vel[1] = 84.0f; play_sound(SOUND_MARIO_ON_FIRE, m->marioObj->header.gfx.cameraToObject); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif } else { @@ -1537,7 +1541,7 @@ s32 act_lava_boost(struct MarioState *m) { if (m->actionState < 2 && m->vel[1] < 0.0f) { m->vel[1] = -m->vel[1] * 0.4f; mario_set_forward_vel(m, m->forwardVel * 0.5f); - m->actionState += 1; + m->actionState++; } else { set_mario_action(m, ACT_LAVA_BOOST_LAND, 0); } @@ -1567,7 +1571,7 @@ s32 act_lava_boost(struct MarioState *m) { } m->marioBodyState->eyeState = MARIO_EYES_DEAD; -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers(); #endif return FALSE; @@ -1679,7 +1683,7 @@ s32 act_shot_from_cannon(struct MarioState *m) { set_mario_action(m, ACT_DIVE_SLIDE, 0); m->faceAngle[0] = 0; set_camera_mode(m->area->camera, m->area->camera->defMode, 1); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif break; @@ -1713,7 +1717,7 @@ s32 act_shot_from_cannon(struct MarioState *m) { if (m->vel[1] > 0.0f) { m->particleFlags |= PARTICLE_DUST; } -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers(); #endif return FALSE; @@ -1778,7 +1782,7 @@ s32 act_flying(struct MarioState *m) { m->faceAngle[0] = 0; set_camera_mode(m->area->camera, m->area->camera->defMode, 1); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 60); #endif break; @@ -1833,7 +1837,7 @@ s32 act_flying(struct MarioState *m) { play_sound(SOUND_MARIO_YAHOO_WAHA_YIPPEE + ((gAudioRandom % 5) << 16), m->marioObj->header.gfx.cameraToObject); #endif -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(50, 40); #endif } @@ -1849,7 +1853,7 @@ s32 act_riding_hoot(struct MarioState *m) { m->usedObj->oHootMarioReleaseTime = gGlobalTimer; play_sound_if_no_flag(m, SOUND_MARIO_UH, MARIO_MARIO_SOUND_PLAYED); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(4, 40); #endif return set_mario_action(m, ACT_FREEFALL, 0); @@ -1907,7 +1911,7 @@ s32 act_flying_triple_jump(struct MarioState *m) { if (is_anim_past_end(m)) { set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(8, 80); #endif m->actionState = 1; @@ -1970,7 +1974,7 @@ s32 act_vertical_wind(struct MarioState *m) { set_mario_animation(m, MARIO_ANIM_FORWARD_SPINNING_FLIP); if (m->marioObj->header.gfx.animInfo.animFrame == 1) { play_sound(SOUND_ACTION_SPIN, m->marioObj->header.gfx.cameraToObject); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(8, 80); #endif } diff --git a/src/game/mario_actions_automatic.c b/src/game/mario_actions_automatic.c index 22690873..40235766 100644 --- a/src/game/mario_actions_automatic.c +++ b/src/game/mario_actions_automatic.c @@ -56,9 +56,7 @@ void play_climbing_sounds(struct MarioState *m, s32 b) { } s32 set_pole_position(struct MarioState *m, f32 offsetY) { - UNUSED s32 unused1; - UNUSED s32 unused2; - UNUSED s32 unused3; + UNUSED u8 filler[12]; struct Surface *floor; struct Surface *ceil; f32 floorHeight; @@ -171,7 +169,7 @@ s32 act_holding_pole(struct MarioState *m) { } } play_climbing_sounds(m, 2); -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers(); #endif set_sound_moving_speed(SOUND_BANK_MOVING, marioObj->oMarioPoleYawVel / 0x100 * 2); @@ -299,7 +297,7 @@ s32 act_top_of_pole(struct MarioState *m) { } s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos) { - UNUSED s32 unused; + UNUSED u8 filler[4]; struct Surface *ceil; struct Surface *floor; f32 ceilHeight; @@ -385,7 +383,7 @@ void update_hang_stationary(struct MarioState *m) { } s32 act_start_hanging(struct MarioState *m) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (m->actionTimer++ == 0) { queue_rumble_data(5, 80); } @@ -470,7 +468,7 @@ s32 act_hang_moving(struct MarioState *m) { if (m->marioObj->header.gfx.animInfo.animFrame == 12) { play_sound(SOUND_ACTION_HANGING_STEP, m->marioObj->header.gfx.cameraToObject); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(1, 30); #endif } @@ -563,8 +561,8 @@ s32 act_ledge_grab(struct MarioState *m) { return set_mario_action(m, ACT_LEDGE_CLIMB_FAST, 0); } - if (m->input & INPUT_UNKNOWN_10) { - if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_UNK1) { + if (m->input & INPUT_STOMPED) { + if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_KNOCKBACK_DMG) { m->hurtCounter += (m->flags & MARIO_CAP_ON_HEAD) ? 12 : 18; } return let_go_of_ledge(m); @@ -662,7 +660,7 @@ s32 act_grabbed(struct MarioState *m) { m->faceAngle[1] = m->usedObj->oMoveAngleYaw; vec3f_copy(m->pos, m->marioObj->header.gfx.pos); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 60); #endif @@ -744,14 +742,14 @@ s32 act_in_cannon(struct MarioState *m) { m->marioObj->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE; set_mario_action(m, ACT_SHOT_FROM_CANNON, 0); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(60, 70); #endif m->usedObj->oAction = 2; return FALSE; } else if (m->faceAngle[0] != startFacePitch || m->faceAngle[1] != startFaceYaw) { play_sound(SOUND_MOVING_AIM_CANNON, m->marioObj->header.gfx.cameraToObject); -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers_2(0); #endif } @@ -838,7 +836,7 @@ s32 act_tornado_twirling(struct MarioState *m) { vec3f_copy(m->marioObj->header.gfx.pos, m->pos); vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1] + m->twirlYaw, 0); -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers(); #endif diff --git a/src/game/mario_actions_cutscene.c b/src/game/mario_actions_cutscene.c index e2cbbb6b..ab797405 100644 --- a/src/game/mario_actions_cutscene.c +++ b/src/game/mario_actions_cutscene.c @@ -18,6 +18,7 @@ #include "level_table.h" #include "level_update.h" #include "mario.h" +#include "mario_actions_cutscene.h" #include "mario_actions_moving.h" #include "mario_step.h" #include "moving_texture.h" @@ -28,9 +29,6 @@ #include "sound_init.h" #include "rumble_init.h" -// TODO: put this elsewhere -enum SaveOption { SAVE_OPT_SAVE_AND_CONTINUE = 1, SAVE_OPT_SAVE_AND_QUIT, SAVE_OPT_CONTINUE_DONT_SAVE }; - static struct Object *sIntroWarpPipeObj; static struct Object *sEndPeachObj; static struct Object *sEndRightToadObj; @@ -216,9 +214,9 @@ s32 geo_switch_peach_eyes(s32 run, struct GraphNode *node, UNUSED s32 a2) { } // unused -static void stub_is_textbox_active(u16 *a0) { - if (get_dialog_id() == -1) { - *a0 = 0; +UNUSED static void stub_is_textbox_active(u16 *arg) { + if (get_dialog_id() == DIALOG_NONE) { + *arg = 0; } } @@ -250,23 +248,23 @@ s32 get_star_collection_dialog(struct MarioState *m) { void handle_save_menu(struct MarioState *m) { s32 dialogID; // wait for the menu to show up - if (is_anim_past_end(m) && gSaveOptSelectIndex != 0) { + if (is_anim_past_end(m) && gSaveOptSelectIndex != MENU_OPT_NONE) { // save and continue / save and quit - if (gSaveOptSelectIndex == SAVE_OPT_SAVE_AND_CONTINUE || gSaveOptSelectIndex == SAVE_OPT_SAVE_AND_QUIT) { + if (gSaveOptSelectIndex == MENU_OPT_SAVE_AND_CONTINUE || gSaveOptSelectIndex == MENU_OPT_SAVE_AND_QUIT) { save_file_do_save(gCurrSaveFileNum - 1); - if (gSaveOptSelectIndex == SAVE_OPT_SAVE_AND_QUIT) { + if (gSaveOptSelectIndex == MENU_OPT_SAVE_AND_QUIT) { fade_into_special_warp(-2, 0); // reset game } } // not quitting - if (gSaveOptSelectIndex != SAVE_OPT_SAVE_AND_QUIT) { + if (gSaveOptSelectIndex != MENU_OPT_SAVE_AND_QUIT) { disable_time_stop(); m->faceAngle[1] += 0x8000; // figure out what dialog to show, if we should dialogID = get_star_collection_dialog(m); - if (dialogID != 0) { + if (dialogID) { play_peachs_jingle(); // look up for dialog set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, dialogID); @@ -345,24 +343,24 @@ s32 mario_ready_to_speak(void) { // 1 = starting dialog // 2 = speaking s32 set_mario_npc_dialog(s32 actionArg) { - s32 dialogState = 0; + s32 dialogState = MARIO_DIALOG_STATUS_NONE; // in dialog if (gMarioState->action == ACT_READING_NPC_DIALOG) { if (gMarioState->actionState < 8) { - dialogState = 1; // starting dialog + dialogState = MARIO_DIALOG_STATUS_START; // starting dialog } if (gMarioState->actionState == 8) { - if (actionArg == 0) { + if (actionArg == MARIO_DIALOG_STOP) { gMarioState->actionState++; // exit dialog } else { - dialogState = 2; + dialogState = MARIO_DIALOG_STATUS_SPEAK; } } } else if (actionArg != 0 && mario_ready_to_speak()) { gMarioState->usedObj = gCurrentObject; set_mario_action(gMarioState, ACT_READING_NPC_DIALOG, actionArg); - dialogState = 1; // starting dialog + dialogState = MARIO_DIALOG_STATUS_START; // starting dialog } return dialogState; @@ -381,10 +379,10 @@ s32 act_reading_npc_dialog(struct MarioState *m) { s32 headTurnAmount = 0; s16 angleToNPC; - if (m->actionArg == 2) { + if (m->actionArg == MARIO_DIALOG_LOOK_UP) { headTurnAmount = -1024; } - if (m->actionArg == 3) { + if (m->actionArg == MARIO_DIALOG_LOOK_DOWN) { headTurnAmount = 384; } @@ -612,7 +610,7 @@ void general_star_dance_handler(struct MarioState *m, s32 isInWater) { break; case 80: - if ((m->actionArg & 1) == 0) { + if (!(m->actionArg & 1)) { level_trigger_warp(m, WARP_OP_STAR_EXIT); } else { enable_time_stop(); @@ -621,8 +619,8 @@ void general_star_dance_handler(struct MarioState *m, s32 isInWater) { } break; } - } else if (m->actionState == 1 && gDialogResponse) { - if (gDialogResponse == 1) { + } else if (m->actionState == 1 && gDialogResponse != DIALOG_RESPONSE_NONE) { + if (gDialogResponse == DIALOG_RESPONSE_YES) { save_file_do_save(gCurrSaveFileNum - 1); } m->actionState = 2; @@ -630,7 +628,7 @@ void general_star_dance_handler(struct MarioState *m, s32 isInWater) { disable_time_stop(); enable_background_sound(); dialogID = get_star_collection_dialog(m); - if (dialogID != 0) { + if (dialogID) { // look up for dialog set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, dialogID); } else { @@ -863,7 +861,7 @@ s32 act_entering_star_door(struct MarioState *m) { s16 targetAngle; if (m->actionTimer++ == 0) { - m->interactObj->oInteractStatus = 0x00010000; + m->interactObj->oInteractStatus = INT_STATUS_UNK16; // ~30 degrees / 1/12 rot targetAngle = m->usedObj->oMoveAngleYaw + 0x1555; @@ -921,10 +919,10 @@ s32 act_entering_star_door(struct MarioState *m) { s32 act_going_through_door(struct MarioState *m) { if (m->actionTimer == 0) { if (m->actionArg & 1) { - m->interactObj->oInteractStatus = 0x00010000; + m->interactObj->oInteractStatus = INT_STATUS_UNK16; set_mario_animation(m, MARIO_ANIM_PULL_DOOR_WALK_IN); } else { - m->interactObj->oInteractStatus = 0x00020000; + m->interactObj->oInteractStatus = INT_STATUS_UNK17; set_mario_animation(m, MARIO_ANIM_PUSH_DOOR_WALK_IN); } } @@ -954,9 +952,9 @@ s32 act_warp_door_spawn(struct MarioState *m) { if (m->actionState == 0) { m->actionState = 1; if (m->actionArg & 1) { - m->usedObj->oInteractStatus = 0x00040000; + m->usedObj->oInteractStatus = INT_STATUS_UNK18; } else { - m->usedObj->oInteractStatus = 0x00080000; + m->usedObj->oInteractStatus = INT_STATUS_UNK19; } } else if (m->usedObj->oAction == 0) { if (gNeverEnteredCastle == TRUE && gCurrLevelNum == LEVEL_CASTLE) { @@ -1087,8 +1085,8 @@ s32 act_exit_land_save_dialog(struct MarioState *m) { enable_time_stop(); } - set_menu_mode(RENDER_COURSE_DONE_SCREEN); - gSaveOptSelectIndex = 0; + set_menu_mode(MENU_MODE_RENDER_COURSE_COMPLETE_SCREEN); + gSaveOptSelectIndex = MENU_OPT_NONE; m->actionState = 3; // star exit with cap if (!(m->flags & MARIO_CAP_ON_HEAD)) { @@ -1106,13 +1104,13 @@ s32 act_exit_land_save_dialog(struct MarioState *m) { switch (animFrame) { case -1: spawn_obj_at_mario_rel_yaw(m, MODEL_BOWSER_KEY_CUTSCENE, bhvBowserKeyCourseExit, -32768); - //! fall through + //! fallthrough case 67: play_sound(SOUND_ACTION_KEY_SWISH, m->marioObj->header.gfx.cameraToObject); - //! fall through + //! fallthrough case 83: play_sound(SOUND_ACTION_PAT_BACK, m->marioObj->header.gfx.cameraToObject); - //! fall through + //! fallthrough case 111: play_sound(SOUND_ACTION_UNKNOWN45C, m->marioObj->header.gfx.cameraToObject); // no break @@ -1139,7 +1137,7 @@ s32 act_exit_land_save_dialog(struct MarioState *m) { cutscene_take_cap_off(m); break; case 37: - // fall through + // fallthrough case 53: play_sound(SOUND_ACTION_BRUSH_HAIR, m->marioObj->header.gfx.cameraToObject); break; @@ -1163,7 +1161,7 @@ s32 act_death_exit(struct MarioState *m) { #else play_sound(SOUND_MARIO_OOOF2, m->marioObj->header.gfx.cameraToObject); #endif -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif m->numLives--; @@ -1198,7 +1196,7 @@ s32 act_falling_death_exit(struct MarioState *m) { #else play_sound(SOUND_MARIO_OOOF2, m->marioObj->header.gfx.cameraToObject); #endif -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif m->numLives--; @@ -1245,7 +1243,7 @@ s32 act_special_death_exit(struct MarioState *m) { } if (launch_mario_until_land(m, ACT_HARD_BACKWARD_GROUND_KB, MARIO_ANIM_BACKWARD_AIR_KB, -24.0f)) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif m->numLives--; @@ -1306,7 +1304,7 @@ s32 act_bbh_enter_spin(struct MarioState *m) { m->actionState = 1; m->actionTimer = 100; - // fall through + // fallthrough case 1: m->faceAngle[1] = atan2s(cageDZ, cageDX); @@ -1324,14 +1322,14 @@ s32 act_bbh_enter_spin(struct MarioState *m) { break; case 2: - // fall through + // fallthrough case 3: m->faceAngle[1] = atan2s(cageDZ, cageDX); mario_set_forward_vel(m, forwardVel); m->flags &= ~MARIO_UNKNOWN_08; if (perform_air_step(m, 0) == AIR_STEP_LANDED) { level_trigger_warp(m, WARP_OP_UNKNOWN_02); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(15, 80); #endif m->actionState = 4; @@ -1399,7 +1397,7 @@ s32 act_teleport_fade_out(struct MarioState *m) { set_mario_animation(m, m->prevAction == ACT_CROUCHING ? MARIO_ANIM_CROUCHING : MARIO_ANIM_FIRST_PERSON); -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (m->actionTimer == 0) { queue_rumble_data(30, 70); func_sh_8024C89C(2); @@ -1425,7 +1423,7 @@ s32 act_teleport_fade_in(struct MarioState *m) { play_sound_if_no_flag(m, SOUND_ACTION_TELEPORT, MARIO_ACTION_SOUND_PLAYED); set_mario_animation(m, MARIO_ANIM_FIRST_PERSON); -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (m->actionTimer == 0) { queue_rumble_data(30, 70); func_sh_8024C89C(2); @@ -1484,7 +1482,7 @@ s32 act_shocked(struct MarioState *m) { } s32 act_squished(struct MarioState *m) { - UNUSED s32 pad; + UNUSED u8 filler[4]; f32 squishAmount; f32 spaceUnderCeil; s16 surfAngle; @@ -1518,7 +1516,7 @@ s32 act_squished(struct MarioState *m) { // Both of the 1.8's are really floats, but one of them has to // be written as a double for this to match on -O2. vec3f_set(m->marioObj->header.gfx.scale, 1.8, 0.05f, 1.8f); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(10, 80); #endif m->actionState = 1; @@ -1622,7 +1620,7 @@ void stuck_in_ground_handler(struct MarioState *m, s32 animation, s32 unstuckFra if (animFrame == -1) { play_sound_and_spawn_particles(m, SOUND_ACTION_TERRAIN_STUCK_IN_GROUND, 1); } else if (animFrame == unstuckFrame) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif play_sound_and_spawn_particles(m, SOUND_ACTION_UNSTUCK_FROM_GROUND, 1); @@ -1720,9 +1718,9 @@ static void intro_cutscene_jump_out_of_pipe(struct MarioState *m) { play_sound_if_no_flag(m, SOUND_MARIO_YAHOO, MARIO_MARIO_SOUND_PLAYED); #else play_sound_if_no_flag(m, SOUND_MARIO_YAHOO, MARIO_MARIO_SOUND_PLAYED); - #ifndef VERSION_JP +#ifndef VERSION_JP play_sound_if_no_flag(m, SOUND_ACTION_HIT_3, MARIO_ACTION_SOUND_PLAYED); - #endif +#endif #endif set_mario_animation(m, MARIO_ANIM_SINGLE_JUMP); @@ -1904,7 +1902,7 @@ static s32 jumbo_star_cutscene_flying(struct MarioState *m) { set_mario_animation(m, MARIO_ANIM_WING_CAP_FLY); anim_spline_init(sJumboStarKeyframes); m->actionState++; - // fall through + // fallthrough case 1: if (anim_spline_poll(targetPos)) { // does this twice @@ -2047,7 +2045,7 @@ static void end_peach_cutscene_summon_jumbo_star(struct MarioState *m) { advance_cutscene_step(m); } - sEndJumboStarObj->oFaceAngleYaw += 0x0400; + sEndJumboStarObj->oFaceAngleYaw += 0x400; generate_yellow_sparkles(0, 2528, -1800, 250.0f); play_sound(SOUND_AIR_PEACH_TWINKLE, sEndJumboStarObj->header.gfx.cameraToObject); } diff --git a/src/game/mario_actions_cutscene.h b/src/game/mario_actions_cutscene.h index 276826cf..31a8b5d3 100644 --- a/src/game/mario_actions_cutscene.h +++ b/src/game/mario_actions_cutscene.h @@ -6,6 +6,17 @@ #include "macros.h" #include "types.h" +// set_mario_npc_dialog +// actionArg +#define MARIO_DIALOG_STOP 0 +#define MARIO_DIALOG_LOOK_FRONT 1 // no head turn +#define MARIO_DIALOG_LOOK_UP 2 +#define MARIO_DIALOG_LOOK_DOWN 3 +// dialogState +#define MARIO_DIALOG_STATUS_NONE 0 +#define MARIO_DIALOG_STATUS_START 1 +#define MARIO_DIALOG_STATUS_SPEAK 2 + void print_displaying_credits_entry(void); void bhv_end_peach_loop(void); void bhv_end_toad_loop(void); diff --git a/src/game/mario_actions_moving.c b/src/game/mario_actions_moving.c index 8b8e8e1b..071ea66c 100644 --- a/src/game/mario_actions_moving.c +++ b/src/game/mario_actions_moving.c @@ -483,7 +483,7 @@ s32 analog_stick_held_back(struct MarioState *m) { } s32 check_ground_dive_or_punch(struct MarioState *m) { - UNUSED s32 unused; + UNUSED u8 filler[4]; if (m->input & INPUT_B_PRESSED) { //! Speed kick (shoutouts to SimpleFlips) @@ -1238,7 +1238,7 @@ s32 act_riding_shell_ground(struct MarioState *m) { } adjust_sound_for_speed(m); -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers(); #endif return FALSE; @@ -1344,7 +1344,7 @@ s32 act_burning_ground(struct MarioState *m) { } m->marioBodyState->eyeState = MARIO_EYES_DEAD; -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers(); #endif return FALSE; @@ -1362,7 +1362,7 @@ void common_slide_action(struct MarioState *m, u32 endAction, u32 airAction, s32 vec3f_copy(pos, m->pos); play_sound(SOUND_MOVING_TERRAIN_SLIDE + m->terrainSoundAddend, m->marioObj->header.gfx.cameraToObject); -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers(); #endif @@ -1488,7 +1488,7 @@ s32 act_crouch_slide(struct MarioState *m) { s32 act_slide_kick_slide(struct MarioState *m) { if (m->input & INPUT_A_PRESSED) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif return set_jumping_action(m, ACT_FORWARD_ROLLOUT, 0); @@ -1520,7 +1520,7 @@ s32 act_slide_kick_slide(struct MarioState *m) { s32 stomach_slide_action(struct MarioState *m, u32 stopAction, u32 airAction, s32 animation) { if (m->actionTimer == 5) { if (!(m->input & INPUT_ABOVE_SLIDE) && (m->input & (INPUT_A_PRESSED | INPUT_B_PRESSED))) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif return drop_and_set_mario_action( @@ -1556,7 +1556,7 @@ s32 act_hold_stomach_slide(struct MarioState *m) { s32 act_dive_slide(struct MarioState *m) { if (!(m->input & INPUT_ABOVE_SLIDE) && (m->input & (INPUT_A_PRESSED | INPUT_B_PRESSED))) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif return set_mario_action(m, m->forwardVel > 0.0f ? ACT_FORWARD_ROLLOUT : ACT_BACKWARD_ROLLOUT, @@ -1955,7 +1955,7 @@ s32 check_common_moving_cancels(struct MarioState *m) { return set_water_plunge_action(m); } - if (!(m->action & ACT_FLAG_INVULNERABLE) && (m->input & INPUT_UNKNOWN_10)) { + if (!(m->action & ACT_FLAG_INVULNERABLE) && (m->input & INPUT_STOMPED)) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } diff --git a/src/game/mario_actions_object.c b/src/game/mario_actions_object.c index fabc3635..99f40bc6 100644 --- a/src/game/mario_actions_object.c +++ b/src/game/mario_actions_object.c @@ -37,7 +37,7 @@ s32 mario_update_punch_sequence(struct MarioState *m) { switch (m->actionArg) { case 0: play_sound(SOUND_MARIO_PUNCH_YAH, m->marioObj->header.gfx.cameraToObject); - // Fall-through: + // fallthrough case 1: set_mario_animation(m, MARIO_ANIM_FIRST_PUNCH); if (is_anim_past_end(m)) { @@ -77,7 +77,7 @@ s32 mario_update_punch_sequence(struct MarioState *m) { case 3: play_sound(SOUND_MARIO_PUNCH_WAH, m->marioObj->header.gfx.cameraToObject); - // Fall-through: + // fallthrough case 4: set_mario_animation(m, MARIO_ANIM_SECOND_PUNCH); if (is_anim_past_end(m)) { @@ -145,7 +145,7 @@ s32 mario_update_punch_sequence(struct MarioState *m) { } s32 act_punching(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -173,7 +173,7 @@ s32 act_punching(struct MarioState *m) { } s32 act_picking_up(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -211,7 +211,7 @@ s32 act_picking_up(struct MarioState *m) { } s32 act_dive_picking_up(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -231,7 +231,7 @@ s32 act_dive_picking_up(struct MarioState *m) { } s32 act_placing_down(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -252,7 +252,7 @@ s32 act_throwing(struct MarioState *m) { return set_mario_action(m, ACT_PLACING_DOWN, 0); } - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -264,7 +264,7 @@ s32 act_throwing(struct MarioState *m) { mario_throw_held_object(m); play_sound_if_no_flag(m, SOUND_MARIO_WAH2, MARIO_MARIO_SOUND_PLAYED); play_sound_if_no_flag(m, SOUND_ACTION_THROW, MARIO_ACTION_SOUND_PLAYED); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(3, 50); #endif } @@ -274,7 +274,7 @@ s32 act_throwing(struct MarioState *m) { } s32 act_heavy_throw(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -286,7 +286,7 @@ s32 act_heavy_throw(struct MarioState *m) { mario_drop_held_object(m); play_sound_if_no_flag(m, SOUND_MARIO_WAH2, MARIO_MARIO_SOUND_PLAYED); play_sound_if_no_flag(m, SOUND_ACTION_THROW, MARIO_ACTION_SOUND_PLAYED); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(3, 50); #endif } @@ -296,7 +296,7 @@ s32 act_heavy_throw(struct MarioState *m) { } s32 act_stomach_slide_stop(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -318,7 +318,7 @@ s32 act_picking_up_bowser(struct MarioState *m) { m->angleVel[1] = 0; m->marioBodyState->grabPos = GRAB_POS_BOWSER; mario_grab_used_object(m); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif play_sound(SOUND_MARIO_HRMM, m->marioObj->header.gfx.cameraToObject); @@ -396,13 +396,13 @@ s32 act_holding_bowser(struct MarioState *m) { // play sound on overflow if (m->angleVel[1] <= -0x100 && spin < m->faceAngle[1]) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(4, 20); #endif play_sound(SOUND_OBJ_BOWSER_SPINNING, m->marioObj->header.gfx.cameraToObject); } if (m->angleVel[1] >= 0x100 && spin > m->faceAngle[1]) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(4, 20); #endif play_sound(SOUND_OBJ_BOWSER_SPINNING, m->marioObj->header.gfx.cameraToObject); @@ -421,12 +421,12 @@ s32 act_holding_bowser(struct MarioState *m) { s32 act_releasing_bowser(struct MarioState *m) { if (++m->actionTimer == 1) { if (m->actionArg == 0) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 50); #endif mario_throw_held_object(m); } else { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(4, 50); #endif mario_drop_held_object(m); diff --git a/src/game/mario_actions_stationary.c b/src/game/mario_actions_stationary.c index 580d2544..6475e1f8 100644 --- a/src/game/mario_actions_stationary.c +++ b/src/game/mario_actions_stationary.c @@ -23,7 +23,7 @@ s32 check_common_idle_cancels(struct MarioState *m) { return mario_push_off_steep_floor(m, ACT_FREEFALL, 0); } - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -70,7 +70,7 @@ s32 check_common_hold_idle_cancels(struct MarioState *m) { return set_mario_action(m, ACT_PLACING_DOWN, 0); } - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -257,7 +257,7 @@ s32 act_sleeping(struct MarioState *m) { s32 animFrame; if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE - | INPUT_FIRST_PERSON | INPUT_UNKNOWN_10 | INPUT_B_PRESSED | INPUT_Z_PRESSED)) { + | INPUT_FIRST_PERSON | INPUT_STOMPED | INPUT_B_PRESSED | INPUT_Z_PRESSED)) { return set_mario_action(m, ACT_WAKING_UP, m->actionState); } @@ -333,7 +333,7 @@ s32 act_waking_up(struct MarioState *m) { raise_background_noise(2); } - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -361,7 +361,7 @@ s32 act_waking_up(struct MarioState *m) { s32 act_shivering(struct MarioState *m) { s32 animFrame; - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -375,7 +375,7 @@ s32 act_shivering(struct MarioState *m) { if (m->input & (INPUT_NONZERO_ANALOG | INPUT_A_PRESSED | INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE - | INPUT_FIRST_PERSON | INPUT_UNKNOWN_10 | INPUT_B_PRESSED | INPUT_Z_PRESSED)) { + | INPUT_FIRST_PERSON | INPUT_STOMPED | INPUT_B_PRESSED | INPUT_Z_PRESSED)) { m->actionState = 2; } @@ -459,7 +459,7 @@ s32 act_hold_idle(struct MarioState *m) { } s32 act_hold_heavy_idle(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -485,7 +485,7 @@ s32 act_hold_heavy_idle(struct MarioState *m) { } s32 act_standing_against_wall(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -526,7 +526,7 @@ s32 act_in_quicksand(struct MarioState *m) { } s32 act_crouching(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -564,7 +564,7 @@ s32 act_crouching(struct MarioState *m) { } s32 act_panting(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -591,7 +591,7 @@ s32 act_hold_panting_unused(struct MarioState *m) { return drop_and_set_mario_action(m, ACT_PANTING, 0); } - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -618,7 +618,7 @@ void stopping_step(struct MarioState *m, s32 animID, u32 action) { } s32 act_braking_stop(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -640,7 +640,7 @@ s32 act_braking_stop(struct MarioState *m) { } s32 act_butt_slide_stop(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -661,7 +661,7 @@ s32 act_hold_butt_slide_stop(struct MarioState *m) { return drop_and_set_mario_action(m, ACT_IDLE, 0); } - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -678,7 +678,7 @@ s32 act_hold_butt_slide_stop(struct MarioState *m) { } s32 act_slide_kick_slide_stop(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -691,7 +691,7 @@ s32 act_slide_kick_slide_stop(struct MarioState *m) { } s32 act_start_crouching(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -716,7 +716,7 @@ s32 act_start_crouching(struct MarioState *m) { } s32 act_stop_crouching(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -749,7 +749,7 @@ s32 act_start_crawling(struct MarioState *m) { return set_mario_action(m, ACT_FREEFALL, 0); } - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -767,7 +767,7 @@ s32 act_start_crawling(struct MarioState *m) { } s32 act_stop_crawling(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -791,18 +791,18 @@ s32 act_shockwave_bounce(struct MarioState *m) { s16 sp1E; f32 sp18; - if (m->marioObj->oInteractStatus & INT_STATUS_HIT_BY_SHOCKWAVE) { -#ifdef VERSION_SH + if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_SHOCKWAVE) { +#if ENABLE_RUMBLE queue_rumble_data(70, 40); #endif return hurt_and_set_mario_action(m, ACT_SHOCKED, 0, 4); } if (m->actionTimer == 0) { -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(70, 40); #endif - if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_UNK1) { + if (m->marioObj->oInteractStatus & INT_STATUS_MARIO_KNOCKBACK_DMG) { return hurt_and_set_mario_action(m, ACT_BACKWARD_GROUND_KB, 0, 0xc); } } @@ -837,7 +837,7 @@ s32 landing_step(struct MarioState *m, s32 arg1, u32 action) { } s32 check_common_landing_cancels(struct MarioState *m, u32 action) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -951,7 +951,7 @@ s32 act_hold_jump_land_stop(struct MarioState *m) { return drop_and_set_mario_action(m, ACT_IDLE, 0); } - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -972,7 +972,7 @@ s32 act_hold_freefall_land_stop(struct MarioState *m) { return drop_and_set_mario_action(m, ACT_IDLE, 0); } - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -988,7 +988,7 @@ s32 act_hold_freefall_land_stop(struct MarioState *m) { } s32 act_air_throw_land(struct MarioState *m) { - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -1006,7 +1006,7 @@ s32 act_air_throw_land(struct MarioState *m) { s32 act_twirl_land(struct MarioState *m) { m->actionState = 1; - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -1036,7 +1036,7 @@ s32 act_twirl_land(struct MarioState *m) { s32 act_ground_pound_land(struct MarioState *m) { m->actionState = 1; - if (m->input & INPUT_UNKNOWN_10) { + if (m->input & INPUT_STOMPED) { return drop_and_set_mario_action(m, ACT_SHOCKWAVE_BOUNCE, 0); } @@ -1053,7 +1053,7 @@ s32 act_ground_pound_land(struct MarioState *m) { } s32 act_first_person(struct MarioState *m) { - s32 sp1C = (m->input & (INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE | INPUT_UNKNOWN_10)) != 0; + s32 sp1C = (m->input & (INPUT_OFF_FLOOR | INPUT_ABOVE_SLIDE | INPUT_STOMPED)) != 0; if (m->actionState == 0) { lower_background_noise(2); diff --git a/src/game/mario_actions_submerged.c b/src/game/mario_actions_submerged.c index 2db01580..4fc919f7 100644 --- a/src/game/mario_actions_submerged.c +++ b/src/game/mario_actions_submerged.c @@ -24,9 +24,9 @@ static s16 sWasAtSurface = FALSE; static s16 sSwimStrength = MIN_SWIM_STRENGTH; static s16 sWaterCurrentSpeeds[] = { 28, 12, 8, 4 }; -static s16 D_80339FD0; -static s16 D_80339FD2; -static f32 D_80339FD4; +static s16 sBobTimer; +static s16 sBobIncrement; +static f32 sBobHeight; static void set_swimming_at_surface_particles(struct MarioState *m, u32 particleFlag) { s16 atSurface = m->pos[1] >= m->waterLevel - 130; @@ -165,7 +165,7 @@ static void apply_water_current(struct MarioState *m, Vec3f step) { } static u32 perform_water_step(struct MarioState *m) { - UNUSED u32 unused; + UNUSED u8 filler[4]; u32 stepResult; Vec3f nextPos; Vec3f step; @@ -416,21 +416,24 @@ static s32 act_hold_water_action_end(struct MarioState *m) { return FALSE; } -static void reset_float_globals(struct MarioState *m) { - D_80339FD0 = 0; - D_80339FD2 = 0x800; - D_80339FD4 = m->faceAngle[0] / 256.0f + 20.0f; +static void reset_bob_variables(struct MarioState *m) { + sBobTimer = 0; + sBobIncrement = 0x800; + sBobHeight = m->faceAngle[0] / 256.0f + 20.0f; } -static void float_surface_gfx(struct MarioState *m) { - if (D_80339FD2 != 0 && m->pos[1] > m->waterLevel - 85 && m->faceAngle[0] >= 0) { - if ((D_80339FD0 += D_80339FD2) >= 0) { - m->marioObj->header.gfx.pos[1] += D_80339FD4 * sins(D_80339FD0); +/** + * Controls the bobbing that happens when you swim near the surface. + */ +static void surface_swim_bob(struct MarioState *m) { + if (sBobIncrement != 0 && m->pos[1] > m->waterLevel - 85 && m->faceAngle[0] >= 0) { + if ((sBobTimer += sBobIncrement) >= 0) { + m->marioObj->header.gfx.pos[1] += sBobHeight * sins(sBobTimer); return; } } - D_80339FD2 = 0; + sBobIncrement = 0; } static void common_swimming_step(struct MarioState *m, s16 swimStrength) { @@ -475,7 +478,7 @@ static void common_swimming_step(struct MarioState *m, s16 swimStrength) { update_water_pitch(m); m->marioBodyState->headAngle[0] = approach_s32(m->marioBodyState->headAngle[0], 0, 0x200, 0x200); - float_surface_gfx(m); + surface_swim_bob(m); set_swimming_at_surface_particles(m, PARTICLE_WAVE_TRAIL); } @@ -551,10 +554,10 @@ static s32 act_breaststroke(struct MarioState *m) { if (m->actionTimer == 1) { play_sound(sSwimStrength == MIN_SWIM_STRENGTH ? SOUND_ACTION_SWIM : SOUND_ACTION_SWIM_FAST, m->marioObj->header.gfx.cameraToObject); - reset_float_globals(m); + reset_bob_variables(m); } -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (m->actionTimer < 6) { func_sh_8024CA04(); } @@ -675,7 +678,7 @@ static s32 act_hold_breaststroke(struct MarioState *m) { if (m->actionTimer == 1) { play_sound(SOUND_ACTION_SWIM, m->marioObj->header.gfx.cameraToObject); - reset_float_globals(m); + reset_bob_variables(m); } set_mario_animation(m, MARIO_ANIM_SWIM_WITH_OBJ_PART1); @@ -802,7 +805,7 @@ static s32 act_water_throw(struct MarioState *m) { if (m->actionTimer++ == 5) { mario_throw_held_object(m); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(3, 50); #endif } @@ -978,7 +981,7 @@ static s32 act_water_plunge(struct MarioState *m) { m->particleFlags |= PARTICLE_WATER_SPLASH; m->actionState = 1; -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (m->prevAction & ACT_FLAG_AIR) { queue_rumble_data(5, 80); } @@ -1006,7 +1009,7 @@ static s32 act_water_plunge(struct MarioState *m) { set_mario_action(m, ACT_HOLD_METAL_WATER_FALLING, 0); break; } - D_80339FD2 = 0; + sBobIncrement = 0; } switch (stateFlags) { @@ -1087,7 +1090,7 @@ static s32 act_caught_in_whirlpool(struct MarioState *m) { set_mario_animation(m, MARIO_ANIM_GENERAL_FALL); vec3f_copy(m->marioObj->header.gfx.pos, m->pos); vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0); -#ifdef VERSION_SH +#if ENABLE_RUMBLE reset_rumble_timers(); #endif diff --git a/src/game/mario_misc.c b/src/game/mario_misc.c index 5184a807..b2eb7ddb 100644 --- a/src/game/mario_misc.c +++ b/src/game/mario_misc.c @@ -15,6 +15,7 @@ #include "goddard/renderer.h" #include "interaction.h" #include "level_update.h" +#include "mario_actions_cutscene.h" #include "mario_misc.h" #include "memory.h" #include "object_helpers.h" @@ -122,8 +123,8 @@ static void toad_message_opaque(void) { } static void toad_message_talking(void) { - if (cur_obj_update_dialog_with_cutscene(3, 1, CUTSCENE_DIALOG, gCurrentObject->oToadMessageDialogId) - != 0) { + if (cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_DOWN, + DIALOG_FLAG_TURN_TO_MARIO, CUTSCENE_DIALOG, gCurrentObject->oToadMessageDialogId)) { gCurrentObject->oToadMessageRecentlyTalked = TRUE; gCurrentObject->oToadMessageState = TOAD_MESSAGE_FADING; switch (gCurrentObject->oToadMessageDialogId) { @@ -237,9 +238,9 @@ void bhv_unlock_door_star_init(void) { } void bhv_unlock_door_star_loop(void) { - UNUSED u8 unused1[4]; + UNUSED u8 filler1[4]; s16 prevYaw = gCurrentObject->oMoveAngleYaw; - UNUSED u8 unused2[4]; + UNUSED u8 filler2[4]; // Speed up the star every frame if (gCurrentObject->oUnlockDoorStarYawVel < 0x2400) { @@ -320,12 +321,12 @@ static Gfx *make_gfx_mario_alpha(struct GraphNodeGenerated *node, s16 alpha) { * Sets the correct blend mode and color for mirror Mario. */ Gfx *geo_mirror_mario_set_alpha(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) { - UNUSED u8 unused1[4]; + UNUSED u8 filler1[4]; Gfx *gfx = NULL; struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *) node; struct MarioBodyState *bodyState = &gBodyStates[asGenerated->parameter]; s16 alpha; - UNUSED u8 unused2[4]; + UNUSED u8 filler2[4]; if (callContext == GEO_CONTEXT_RENDER) { alpha = (bodyState->modelState & 0x100) ? (bodyState->modelState & 0xFF) : 255; @@ -612,9 +613,9 @@ Gfx *geo_render_mirror_mario(s32 callContext, struct GraphNode *node, UNUSED Mat gMirrorMario.pos[0] = mirroredX + MIRROR_X; gMirrorMario.angle[1] = -gMirrorMario.angle[1]; gMirrorMario.scale[0] *= -1.0f; - ((struct GraphNode *) &gMirrorMario)->flags |= 1; + ((struct GraphNode *) &gMirrorMario)->flags |= GRAPH_RENDER_ACTIVE; } else { - ((struct GraphNode *) &gMirrorMario)->flags &= ~1; + ((struct GraphNode *) &gMirrorMario)->flags &= ~GRAPH_RENDER_ACTIVE; } break; } diff --git a/src/game/memory.c b/src/game/memory.c index 868224e6..83f55f7c 100644 --- a/src/game/memory.c +++ b/src/game/memory.c @@ -256,7 +256,7 @@ static void dma_read(u8 *dest, u8 *srcStart, u8 *srcEnd) { osPiStartDma(&gDmaIoMesg, OS_MESG_PRI_NORMAL, OS_READ, (uintptr_t) srcStart, dest, copySize, &gDmaMesgQueue); - osRecvMesg(&gDmaMesgQueue, &D_80339BEC, OS_MESG_BLOCK); + osRecvMesg(&gDmaMesgQueue, &gMainReceivedMesg, OS_MESG_BLOCK); dest += copySize; srcStart += copySize; @@ -539,41 +539,37 @@ void *alloc_display_list(u32 size) { return ptr; } -static struct MarioAnimDmaRelatedThing *func_802789F0(u8 *srcAddr) { - struct MarioAnimDmaRelatedThing *sp1C = dynamic_dma_read(srcAddr, srcAddr + sizeof(u32), +static struct DmaTable *load_dma_table_address(u8 *srcAddr) { + struct DmaTable *table = dynamic_dma_read(srcAddr, srcAddr + sizeof(u32), MEMORY_POOL_LEFT); - u32 size = sizeof(u32) + (sizeof(u8 *) - sizeof(u32)) + sizeof(u8 *) + - sp1C->count * sizeof(struct OffsetSizePair); - main_pool_free(sp1C); + u32 size = table->count * sizeof(struct OffsetSizePair) + + sizeof(struct DmaTable) - sizeof(struct OffsetSizePair); + main_pool_free(table); - sp1C = dynamic_dma_read(srcAddr, srcAddr + size, MEMORY_POOL_LEFT); - sp1C->srcAddr = srcAddr; - return sp1C; + table = dynamic_dma_read(srcAddr, srcAddr + size, MEMORY_POOL_LEFT); + table->srcAddr = srcAddr; + return table; } -void func_80278A78(struct MarioAnimation *a, void *b, struct Animation *target) { - if (b != NULL) { - a->animDmaTable = func_802789F0(b); +void setup_dma_table_list(struct DmaHandlerList *list, void *srcAddr, void *buffer) { + if (srcAddr != NULL) { + list->dmaTable = load_dma_table_address(srcAddr); } - a->currentAnimAddr = NULL; - a->targetAnim = target; + list->currentAddr = NULL; + list->bufTarget = buffer; } -// TODO: (Scrub C) -s32 load_patchable_table(struct MarioAnimation *a, u32 index) { +s32 load_patchable_table(struct DmaHandlerList *list, s32 index) { s32 ret = FALSE; - struct MarioAnimDmaRelatedThing *sp20 = a->animDmaTable; - u8 *addr; - u32 size; + struct DmaTable *table = list->dmaTable; - if (index < sp20->count) { - do { - addr = sp20->srcAddr + sp20->anim[index].offset; - size = sp20->anim[index].size; - } while (0); - if (a->currentAnimAddr != addr) { - dma_read((u8 *) a->targetAnim, addr, addr + size); - a->currentAnimAddr = addr; + if ((u32)index < table->count) { + u8 *addr = table->srcAddr + table->anim[index].offset; + s32 size = table->anim[index].size; + + if (list->currentAddr != addr) { + dma_read(list->bufTarget, addr, addr + size); + list->currentAddr = addr; ret = TRUE; } } diff --git a/src/game/memory.h b/src/game/memory.h index 7a51e590..0d958b8e 100644 --- a/src/game/memory.h +++ b/src/game/memory.h @@ -8,9 +8,7 @@ #define MEMORY_POOL_LEFT 0 #define MEMORY_POOL_RIGHT 1 - -struct AllocOnlyPool -{ +struct AllocOnlyPool { s32 totalSpace; s32 usedSpace; u8 *startPtr; @@ -19,6 +17,23 @@ struct AllocOnlyPool struct MemoryPool; +struct OffsetSizePair { + u32 offset; + u32 size; +}; + +struct DmaTable { + u32 count; + u8 *srcAddr; + struct OffsetSizePair anim[1]; // dynamic size +}; + +struct DmaHandlerList { + struct DmaTable *dmaTable; + void *currentAddr; + void *bufTarget; +}; + #ifndef INCLUDED_FROM_MEMORY_C // Declaring this variable extern puts it in the wrong place in the bss order // when this file is included from memory.c (first instead of last). Hence, @@ -63,7 +78,7 @@ void *mem_pool_alloc(struct MemoryPool *pool, u32 size); void mem_pool_free(struct MemoryPool *pool, void *addr); void *alloc_display_list(u32 size); -void func_80278A78(struct MarioAnimation *a, void *b, struct Animation *target); -s32 load_patchable_table(struct MarioAnimation *a, u32 b); +void setup_dma_table_list(struct DmaHandlerList *list, void *srcAddr, void *buffer); +s32 load_patchable_table(struct DmaHandlerList *list, s32 index); #endif // MEMORY_H diff --git a/src/game/moving_texture.c b/src/game/moving_texture.c index 268d7efd..175b854a 100644 --- a/src/game/moving_texture.c +++ b/src/game/moving_texture.c @@ -523,8 +523,8 @@ extern u8 sl_movtex_water[]; extern u8 wdw_movtex_area1_water[]; extern u8 wdw_movtex_area2_water[]; extern u8 jrb_movtex_water[]; -extern u8 jrb_movtex_intial_mist[]; -extern u8 jrb_movtex_sinked_boat_water[]; +extern u8 jrb_movtex_initial_mist[]; +extern u8 jrb_movtex_sunken_ship_water[]; extern u8 thi_movtex_area1_water[]; extern u8 thi_movtex_area2_water[]; extern u8 castle_grounds_movtex_water[]; @@ -566,10 +566,10 @@ void *get_quad_collection_from_id(u32 id) { return wdw_movtex_area2_water; case JRB_MOVTEX_WATER: return jrb_movtex_water; - case JRB_MOVTEX_INTIAL_MIST: - return jrb_movtex_intial_mist; - case JRB_MOVTEX_SINKED_BOAT_WATER: - return jrb_movtex_sinked_boat_water; + case JRB_MOVTEX_INITIAL_MIST: + return jrb_movtex_initial_mist; + case JRB_MOVTEX_SUNKEN_SHIP_WATER: + return jrb_movtex_sunken_ship_water; case THI_MOVTEX_AREA1_WATER: return thi_movtex_area1_water; case THI_MOVTEX_AREA2_WATER: @@ -605,7 +605,7 @@ void movtex_change_texture_format(u32 quadCollectionId, Gfx **gfx) { case SSL_MOVTEX_TOXBOX_QUICKSAND_MIST: gSPDisplayList((*gfx)++, dl_waterbox_ia16_begin); break; - case JRB_MOVTEX_INTIAL_MIST: + case JRB_MOVTEX_INITIAL_MIST: gSPDisplayList((*gfx)++, dl_waterbox_ia16_begin); break; default: @@ -643,11 +643,12 @@ Gfx *geo_movtex_draw_water_regions(s32 callContext, struct GraphNode *node, UNUS gfx = gfxHead; } asGenerated = (struct GraphNodeGenerated *) node; - if (asGenerated->parameter == JRB_MOVTEX_INTIAL_MIST) { + if (asGenerated->parameter == JRB_MOVTEX_INITIAL_MIST) { if (gLakituState.goalPos[1] < 1024.0) { // if camera under water return NULL; } - if (save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_JRB - 1) & 1) { // first star in JRB complete + if (save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(COURSE_JRB)) + & (1 << 0)) { // the "Plunder in the Sunken Ship" star in JRB is collected return NULL; } } else if (asGenerated->parameter == HMC_MOVTEX_TOXIC_MAZE_MIST) { diff --git a/src/game/moving_texture.h b/src/game/moving_texture.h index 9d2e3db1..05858a99 100644 --- a/src/game/moving_texture.h +++ b/src/game/moving_texture.h @@ -10,8 +10,7 @@ #define ROTATE_COUNTER_CLOCKWISE 1 /// Ids for textures used for moving textures -enum MovtexRectTextureId -{ +enum MovtexRectTextureId { TEXTURE_WATER, TEXTURE_MIST, TEXTURE_JRB_WATER, @@ -71,8 +70,8 @@ extern f32 gPaintingMarioYEntry; #define WDW_MOVTEX_AREA1_WATER ( 1 | MOVTEX_AREA_WDW) #define WDW_MOVTEX_AREA2_WATER ( 2 | MOVTEX_AREA_WDW) #define JRB_MOVTEX_WATER ( 1 | MOVTEX_AREA_JRB) -#define JRB_MOVTEX_INTIAL_MIST ( 5 | MOVTEX_AREA_JRB) -#define JRB_MOVTEX_SINKED_BOAT_WATER ( 2 | MOVTEX_AREA_JRB) +#define JRB_MOVTEX_INITIAL_MIST ( 5 | MOVTEX_AREA_JRB) +#define JRB_MOVTEX_SUNKEN_SHIP_WATER ( 2 | MOVTEX_AREA_JRB) #define THI_MOVTEX_AREA1_WATER ( 1 | MOVTEX_AREA_THI) #define THI_MOVTEX_AREA2_WATER ( 2 | MOVTEX_AREA_THI) #define CASTLE_GROUNDS_MOVTEX_WATER ( 1 | MOVTEX_AREA_CASTLE_GROUNDS) diff --git a/src/game/obj_behaviors.c b/src/game/obj_behaviors.c index 64bb141e..68c78e23 100644 --- a/src/game/obj_behaviors.c +++ b/src/game/obj_behaviors.c @@ -91,7 +91,7 @@ Gfx UNUSED *geo_obj_transparency_something(s32 callContext, struct GraphNode *no struct Object *heldObject; struct Object *obj; UNUSED struct Object *unusedObject; - UNUSED s32 pad; + UNUSED u8 filler[4]; gfxHead = NULL; @@ -406,7 +406,7 @@ void obj_splash(s32 waterY, s32 objY) { } // Spawns bubbles if underwater. - if ((objY + 50) < waterY && (globalTimer & 0x1F) == 0) { + if ((objY + 50) < waterY && !(globalTimer & 31)) { spawn_object(o, MODEL_WHITE_PARTICLE_SMALL, bhvObjectBubble); } } @@ -593,7 +593,7 @@ s8 obj_check_if_facing_toward_angle(u32 base, u32 goal, s16 range) { */ s8 obj_find_wall_displacement(Vec3f dist, f32 x, f32 y, f32 z, f32 radius) { struct WallCollisionData hitbox; - UNUSED u8 filler[0x20]; + UNUSED u8 filler[32]; hitbox.x = x; hitbox.y = y; @@ -680,20 +680,18 @@ s8 current_mario_room_check(s16 room) { * Triggers dialog when Mario is facing an object and controls it while in the dialog. */ s16 trigger_obj_dialog_when_facing(s32 *inDialog, s16 dialogID, f32 dist, s32 actionArg) { - s16 dialogueResponse; - if ((is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, (s32) dist) == TRUE && obj_check_if_facing_toward_angle(o->oFaceAngleYaw, gMarioObject->header.gfx.angle[1] + 0x8000, 0x1000) == TRUE && obj_check_if_facing_toward_angle(o->oMoveAngleYaw, o->oAngleToMario, 0x1000) == TRUE) - || (*inDialog == 1)) { - *inDialog = 1; + || (*inDialog == TRUE)) { + *inDialog = TRUE; - if (set_mario_npc_dialog(actionArg) == 2) { //If Mario is speaking. - dialogueResponse = cutscene_object_with_dialog(CUTSCENE_DIALOG, o, dialogID); - if (dialogueResponse != 0) { - set_mario_npc_dialog(0); - *inDialog = 0; - return dialogueResponse; + if (set_mario_npc_dialog(actionArg) == MARIO_DIALOG_STATUS_SPEAK) { //If Mario is speaking. + s16 dialogResponse = cutscene_object_with_dialog(CUTSCENE_DIALOG, o, dialogID); + if (dialogResponse != DIALOG_RESPONSE_NONE) { + set_mario_npc_dialog(MARIO_DIALOG_STOP); + *inDialog = FALSE; + return dialogResponse; } return 0; } @@ -732,7 +730,7 @@ void obj_check_floor_death(s16 collisionFlags, struct Surface *floor) { s8 obj_lava_death(void) { struct Object *deathSmoke; - if (o->oTimer >= 31) { + if (o->oTimer > 30) { o->activeFlags = ACTIVE_FLAG_DEACTIVATED; return TRUE; } else { @@ -775,7 +773,7 @@ s8 sDebugTimer = 0; /** * Unused presumably debug function that tracks for a sequence of inputs. */ -s8 UNUSED debug_sequence_tracker(s16 debugInputSequence[]) { +UNUSED s8 debug_sequence_tracker(s16 debugInputSequence[]) { // If end of sequence reached, return true. if (debugInputSequence[sDebugSequenceTracker] == 0) { sDebugSequenceTracker = 0; diff --git a/src/game/obj_behaviors.h b/src/game/obj_behaviors.h index 02a0567f..9755984f 100644 --- a/src/game/obj_behaviors.h +++ b/src/game/obj_behaviors.h @@ -107,7 +107,7 @@ void bhv_big_bully_with_minions_loop(void); f32 water_ring_calc_mario_dist(void); void water_ring_init(void); void bhv_jet_stream_water_ring_init(void); -void water_ring_check_collection(f32 avgScale, struct Object* ringManager); +void water_ring_check_collection(f32 avgScale, struct Object *ringManager); void water_ring_set_scale(f32 avgScale); void water_ring_act_collected(void); void water_ring_act_not_collected(void); @@ -148,7 +148,7 @@ void bhv_bowling_ball_init(void); void bowling_ball_set_hitbox(void); void bowling_ball_set_waypoints(void); void bhv_bowling_ball_roll_loop(void); -void bhv_bowling_ball_initializeLoop(void); +void bhv_bowling_ball_initialize_loop(void); void bhv_bowling_ball_loop(void); void bhv_generic_bowling_ball_spawner_init(void); void bhv_generic_bowling_ball_spawner_loop(void); diff --git a/src/game/obj_behaviors_2.c b/src/game/obj_behaviors_2.c index 056d178a..3715a137 100644 --- a/src/game/obj_behaviors_2.c +++ b/src/game/obj_behaviors_2.c @@ -15,6 +15,7 @@ #include "engine/surface_load.h" #include "game_init.h" #include "geo_misc.h" +#include "ingame_menu.h" #include "interaction.h" #include "level_table.h" #include "level_update.h" @@ -98,10 +99,11 @@ static s16 obj_get_pitch_from_vel(void) { */ static s32 obj_update_race_proposition_dialog(s16 dialogID) { s32 dialogResponse = - cur_obj_update_dialog_with_cutscene(2, DIALOG_UNK2_FLAG_0 | DIALOG_UNK2_LEAVE_TIME_STOP_ENABLED, CUTSCENE_RACE_DIALOG, dialogID); + cur_obj_update_dialog_with_cutscene(MARIO_DIALOG_LOOK_UP, + (DIALOG_FLAG_TURN_TO_MARIO | DIALOG_FLAG_TIME_STOP_ENABLED), CUTSCENE_RACE_DIALOG, dialogID); - if (dialogResponse == 2) { - set_mario_npc_dialog(0); + if (dialogResponse == DIALOG_RESPONSE_NO) { + set_mario_npc_dialog(MARIO_DIALOG_STOP); disable_time_stop_including_mario(); } @@ -150,7 +152,7 @@ static void platform_on_track_update_pos_or_spawn_ball(s32 ballIndex, f32 x, f32 struct Waypoint *initialPrevWaypoint; struct Waypoint *nextWaypoint; struct Waypoint *prevWaypoint; - UNUSED s32 unused; + UNUSED u8 filler[4]; f32 amountToMove; f32 dx; f32 dy; @@ -172,7 +174,7 @@ static void platform_on_track_update_pos_or_spawn_ball(s32 ballIndex, f32 x, f32 do { prevWaypoint = nextWaypoint; - nextWaypoint += 1; + nextWaypoint++; if (nextWaypoint->flags == WAYPOINT_FLAGS_END) { if (ballIndex == 0) { o->oPlatformOnTrackPrevWaypointFlags = WAYPOINT_FLAGS_END; @@ -533,7 +535,7 @@ static s32 oscillate_toward(s32 *value, f32 *vel, s32 target, f32 velCloseToZero static void obj_update_blinking(s32 *blinkTimer, s16 baseCycleLength, s16 cycleLengthRange, s16 blinkLength) { if (*blinkTimer != 0) { - *blinkTimer -= 1; + (*blinkTimer)--; } else { *blinkTimer = random_linear_offset(baseCycleLength, cycleLengthRange); } @@ -640,7 +642,7 @@ static void obj_die_if_health_non_positive(void) { } } -static void obj_unused_die(void) { +UNUSED static void obj_unused_die(void) { o->oHealth = 0; obj_die_if_health_non_positive(); } diff --git a/src/game/object_collision.c b/src/game/object_collision.c index c8d867ae..59ae99b5 100644 --- a/src/game/object_collision.c +++ b/src/game/object_collision.c @@ -9,7 +9,7 @@ struct Object *debug_print_obj_collision(struct Object *a) { struct Object *sp24; - UNUSED s32 unused; + UNUSED u8 filler[4]; s32 i; for (i = 0; i < a->numCollidedObjs; i++) { @@ -57,6 +57,9 @@ s32 detect_object_hitbox_overlap(struct Object *a, struct Object *b) { } //! no return value +#ifdef AVOID_UB + return 0; +#endif } s32 detect_object_hurtbox_overlap(struct Object *a, struct Object *b) { @@ -89,6 +92,9 @@ s32 detect_object_hurtbox_overlap(struct Object *a, struct Object *b) { } //! no return value +#ifdef AVOID_UB + return 0; +#endif } void clear_object_collision(struct Object *a) { diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index 0d86000b..338d5263 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -27,8 +27,8 @@ #include "spawn_object.h" #include "spawn_sound.h" -s8 D_8032F0A0[] = { -8, 8, -4, 4 }; -s16 D_8032F0A4[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; +static s8 sBbhStairJiggleOffsets[] = { -8, 8, -4, 4 }; +static s16 sPowersOfTwo[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; static s8 sLevelsWithRooms[] = { LEVEL_BBH, LEVEL_CASTLE, LEVEL_HMC, -1 }; static s32 clear_move_flag(u32 *, s32); @@ -64,7 +64,7 @@ Gfx *geo_update_layer_transparency(s32 callContext, struct GraphNode *node, UNUS currentGraphNode = (struct GraphNodeGenerated *) node; sp2C = (struct GraphNodeGenerated *) node; - if (gCurGraphNodeHeldObject) { + if (gCurGraphNodeHeldObject != NULL) { objectGraphNode = gCurGraphNodeHeldObject->objNode; } @@ -393,7 +393,7 @@ s16 obj_angle_to_object(struct Object *obj1, struct Object *obj2) { s16 obj_turn_toward_object(struct Object *obj, struct Object *target, s16 angleIndex, s16 turnAmount) { f32 a, b, c, d; - UNUSED s32 unused; + UNUSED u8 filler[4]; s16 targetAngle, startAngle; switch (angleIndex) { @@ -452,26 +452,26 @@ void obj_set_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll) { */ struct Object *spawn_object_abs_with_rot(struct Object *parent, s16 uselessArg, u32 model, const BehaviorScript *behavior, - s16 x, s16 y, s16 z, s16 rx, s16 ry, s16 rz) { + s16 x, s16 y, s16 z, s16 pitch, s16 yaw, s16 roll) { // 'uselessArg' is unused in the function spawn_object_at_origin() struct Object *newObj = spawn_object_at_origin(parent, uselessArg, model, behavior); obj_set_pos(newObj, x, y, z); - obj_set_angle(newObj, rx, ry, rz); + obj_set_angle(newObj, pitch, yaw, roll); return newObj; } /* * Spawns an object relative to the parent with a specified angle... is what it is supposed to do. - * The rz argument is never used, and the z offset is used for z-rotation instead. This is most likely + * The roll argument is never used, and the z offset is used for z-rotation instead. This is most likely * a copy-paste typo by one of the programmers. */ struct Object *spawn_object_rel_with_rot(struct Object *parent, u32 model, const BehaviorScript *behavior, - s16 xOff, s16 yOff, s16 zOff, s16 rx, s16 ry, UNUSED s16 rz) { + s16 xOff, s16 yOff, s16 zOff, s16 pitch, s16 yaw, UNUSED s16 roll) { struct Object *newObj = spawn_object_at_origin(parent, 0, model, behavior); newObj->oFlags |= OBJ_FLAG_TRANSFORM_RELATIVE_TO_PARENT; obj_set_parent_relative_pos(newObj, xOff, yOff, zOff); - obj_set_angle(newObj, rx, ry, zOff); // Nice typo you got there Nintendo. + obj_set_angle(newObj, pitch, yaw, zOff); // Nice typo you got there Nintendo. return newObj; } @@ -790,7 +790,7 @@ void cur_obj_unused_init_on_floor(void) { cur_obj_enable_rendering(); o->oPosY = find_floor_height(o->oPosX, o->oPosY, o->oPosZ); - if (o->oPosY < -10000.0f) { + if (o->oPosY < FLOOR_LOWER_LIMIT_MISC) { cur_obj_set_pos_relative_to_parent(0, 0, -70); o->oPosY = find_floor_height(o->oPosX, o->oPosY, o->oPosZ); } @@ -1048,20 +1048,21 @@ s32 mario_is_dive_sliding(void) { } } -void cur_obj_set_y_vel_and_animation(f32 sp18, s32 sp1C) { - o->oVelY = sp18; - cur_obj_init_animation_with_sound(sp1C); +void cur_obj_set_y_vel_and_animation(f32 yVel, s32 animIndex) { + o->oVelY = yVel; + cur_obj_init_animation_with_sound(animIndex); } -void cur_obj_unrender_and_reset_state(s32 sp18, s32 sp1C) { +void cur_obj_unrender_set_action_and_anim(s32 animIndex, s32 action) { cur_obj_become_intangible(); cur_obj_disable_rendering(); - - if (sp18 >= 0) { - cur_obj_init_animation_with_sound(sp18); + + // only set animation if non-negative value + if (animIndex >= 0) { + cur_obj_init_animation_with_sound(animIndex); } - o->oAction = sp1C; + o->oAction = action; } static void cur_obj_move_after_thrown_or_dropped(f32 forwardVel, f32 velY) { @@ -1070,7 +1071,7 @@ static void cur_obj_move_after_thrown_or_dropped(f32 forwardVel, f32 velY) { if (o->oFloorHeight > o->oPosY) { o->oPosY = o->oFloorHeight; - } else if (o->oFloorHeight < -10000.0f) { + } else if (o->oFloorHeight < FLOOR_LOWER_LIMIT_MISC) { //! OoB failsafe obj_copy_pos(o, gMarioObject); o->oFloorHeight = find_floor_height(o->oPosX, o->oPosY, o->oPosZ); @@ -1123,7 +1124,7 @@ void mario_set_flag(s32 flag) { s32 cur_obj_clear_interact_status_flag(s32 flag) { if (o->oInteractStatus & flag) { - o->oInteractStatus &= flag ^ ~(0); + o->oInteractStatus &= flag ^ 0xFFFFFFFF; return TRUE; } return FALSE; @@ -1206,7 +1207,7 @@ static s32 cur_obj_move_xz(f32 steepSlopeNormalY, s32 careAboutEdgesAndSteepSlop f32 intendedFloorHeight = find_floor(intendedX, o->oPosY, intendedZ, &intendedFloor); f32 deltaFloorHeight = intendedFloorHeight - o->oFloorHeight; - UNUSED f32 unused; + UNUSED u8 filler[4]; UNUSED f32 ny; o->oMoveFlags &= ~OBJ_MOVE_HIT_EDGE; @@ -1218,7 +1219,7 @@ static s32 cur_obj_move_xz(f32 steepSlopeNormalY, s32 careAboutEdgesAndSteepSlop } } - if (intendedFloorHeight < -10000.0f) { + if (intendedFloorHeight < FLOOR_LOWER_LIMIT_MISC) { // Don't move into OoB o->oMoveFlags |= OBJ_MOVE_HIT_EDGE; return FALSE; @@ -1318,7 +1319,7 @@ static f32 cur_obj_move_y_and_get_water_level(f32 gravity, f32 buoyancy) { o->oPosY += o->oVelY; if (o->activeFlags & ACTIVE_FLAG_UNK10) { - waterLevel = -11000.0f; + waterLevel = FLOOR_LOWER_LIMIT; } else { waterLevel = find_water_level(o->oPosX, o->oPosZ); } @@ -1376,7 +1377,7 @@ void cur_obj_move_y(f32 gravity, f32 bounciness, f32 buoyancy) { } } -static void stub_obj_helpers_1(void) { +UNUSED static void stub_obj_helpers_1(void) { } static s32 clear_move_flag(u32 *bitSet, s32 flag) { @@ -1566,9 +1567,10 @@ void cur_obj_start_cam_event(UNUSED struct Object *obj, s32 cameraEvent) { gSecondCameraFocus = o; } -void set_mario_interact_hoot_if_in_range(UNUSED s32 sp0, UNUSED s32 sp4, f32 sp8) { - if (o->oDistanceToMario < sp8) { - gMarioObject->oInteractStatus = INT_STATUS_HOOT_GRABBED_BY_MARIO; +// unused, self explanatory, maybe oInteractStatus originally had TRUE/FALSE statements +void set_mario_interact_true_if_in_range(UNUSED s32 arg0, UNUSED s32 arg1, f32 range) { + if (o->oDistanceToMario < range) { + gMarioObject->oInteractStatus = TRUE; } } @@ -1675,7 +1677,7 @@ static s32 cur_obj_detect_steep_floor(s16 steepAngleDegrees) { intendedFloorHeight = find_floor(intendedX, o->oPosY, intendedZ, &intendedFloor); deltaFloorHeight = intendedFloorHeight - o->oFloorHeight; - if (intendedFloorHeight < -10000.0f) { + if (intendedFloorHeight < FLOOR_LOWER_LIMIT_MISC) { o->oWallAngle = o->oMoveAngleYaw + 0x8000; return 2; } else if (intendedFloor->normal.y < steepNormalY && deltaFloorHeight > 0 @@ -1982,7 +1984,7 @@ s32 cur_obj_follow_path(UNUSED s32 unusedArg) { struct Waypoint *lastWaypoint; struct Waypoint *targetWaypoint; f32 prevToNextX, prevToNextY, prevToNextZ; - UNUSED s32 sp2C; + UNUSED u8 filler[4]; f32 objToNextXZ; f32 objToNextX, objToNextY, objToNextZ; @@ -2057,14 +2059,15 @@ void obj_translate_xz_random(struct Object *obj, f32 rangeLength) { obj->oPosZ += random_float() * rangeLength - rangeLength * 0.5f; } -static void obj_build_vel_from_transform(struct Object *a0) { - f32 spC = a0->oUnkC0; - f32 sp8 = a0->oUnkBC; - f32 sp4 = a0->oForwardVel; +static void obj_build_vel_from_transform(struct Object *obj) { + f32 up = obj->oUpVel; + f32 left = obj->oLeftVel; + f32 forward = obj->oForwardVel; - a0->oVelX = a0->transform[0][0] * spC + a0->transform[1][0] * sp8 + a0->transform[2][0] * sp4; - a0->oVelY = a0->transform[0][1] * spC + a0->transform[1][1] * sp8 + a0->transform[2][1] * sp4; - a0->oVelZ = a0->transform[0][2] * spC + a0->transform[1][2] * sp8 + a0->transform[2][2] * sp4; + //! Typo, up and left should be swapped + obj->oVelX = obj->transform[0][0] * up + obj->transform[1][0] * left + obj->transform[2][0] * forward; + obj->oVelY = obj->transform[0][1] * up + obj->transform[1][1] * left + obj->transform[2][1] * forward; + obj->oVelZ = obj->transform[0][2] * up + obj->transform[1][2] * left + obj->transform[2][2] * forward; } void cur_obj_set_pos_via_transform(void) { @@ -2087,13 +2090,13 @@ void cur_obj_spawn_particles(struct SpawnParticlesInfo *info) { s32 numParticles = info->count; // If there are a lot of objects already, limit the number of particles - if (gPrevFrameObjectCount > 150 && numParticles > 10) { + if ((gPrevFrameObjectCount > (OBJECT_POOL_CAPACITY - 90)) && numParticles > 10) { numParticles = 10; } // We're close to running out of object slots, so don't spawn particles at // all - if (gPrevFrameObjectCount > 210) { + if (gPrevFrameObjectCount > (OBJECT_POOL_CAPACITY - 30)) { numParticles = 0; } @@ -2232,7 +2235,7 @@ void bhv_dust_smoke_loop(void) { o->oSmokeTimer++; } -static void stub_obj_helpers_2(void) { +UNUSED static void stub_obj_helpers_2(void) { } s32 cur_obj_set_direction_table(s8 *a0) { @@ -2279,10 +2282,10 @@ void cur_obj_scale_over_time(s32 a0, s32 a1, f32 sp10, f32 sp14) { } void cur_obj_set_pos_to_home_with_debug(void) { - o->oPosX = o->oHomeX + gDebugInfo[5][0]; - o->oPosY = o->oHomeY + gDebugInfo[5][1]; - o->oPosZ = o->oHomeZ + gDebugInfo[5][2]; - cur_obj_scale(gDebugInfo[5][3] / 100.0f + 1.0l); + o->oPosX = o->oHomeX + gDebugInfo[DEBUG_PAGE_ENEMYINFO][0]; + o->oPosY = o->oHomeY + gDebugInfo[DEBUG_PAGE_ENEMYINFO][1]; + o->oPosZ = o->oHomeZ + gDebugInfo[DEBUG_PAGE_ENEMYINFO][2]; + cur_obj_scale(gDebugInfo[DEBUG_PAGE_ENEMYINFO][3] / 100.0f + 1.0l); } void stub_obj_helpers_4(void) { @@ -2310,12 +2313,12 @@ s32 cur_obj_shake_y_until(s32 cycles, s32 amount) { } } -s32 cur_obj_move_up_and_down(s32 a0) { +s32 jiggle_bbh_stair(s32 a0) { if (a0 >= 4 || a0 < 0) { return TRUE; } - o->oPosY += D_8032F0A0[a0]; + o->oPosY += sBbhStairJiggleOffsets[a0]; return FALSE; } @@ -2340,7 +2343,7 @@ void spawn_base_star_with_no_lvl_exit(void) { } s32 bit_shift_left(s32 a0) { - return D_8032F0A4[a0]; + return sPowersOfTwo[a0]; } s32 cur_obj_mario_far_away(void) { @@ -2380,7 +2383,7 @@ s32 is_item_in_array(s8 item, s8 *array) { return FALSE; } -static void stub_obj_helpers_5(void) { +UNUSED static void stub_obj_helpers_5(void) { } void bhv_init_room(void) { @@ -2461,7 +2464,7 @@ s32 cur_obj_set_hitbox_and_die_if_attacked(struct ObjectHitbox *hitbox, s32 deat void obj_explode_and_spawn_coins(f32 sp18, s32 sp1C) { spawn_mist_particles_variable(0, 0, sp18); - spawn_triangle_break_particles(30, 138, 3.0f, 4); + spawn_triangle_break_particles(30, MODEL_DIRT_ANIMATION, 3.0f, 4); obj_mark_for_deletion(o); if (sp1C == 1) { @@ -2501,17 +2504,17 @@ Gfx *geo_offset_klepto_held_object(s32 callContext, struct GraphNode *node, UNUS return NULL; } -s32 geo_offset_klepto_debug(s32 callContext, struct GraphNode *a1, UNUSED s32 sp8) { +Gfx *geo_offset_klepto_debug(s32 callContext, struct GraphNode *node, UNUSED Mat4 mtx) { if (callContext == GEO_CONTEXT_RENDER) { - ((struct GraphNode_802A45E4 *) a1->next)->unk18 = gDebugInfo[4][0]; - ((struct GraphNode_802A45E4 *) a1->next)->unk1A = gDebugInfo[4][1]; - ((struct GraphNode_802A45E4 *) a1->next)->unk1C = gDebugInfo[4][2]; - ((struct GraphNode_802A45E4 *) a1->next)->unk1E = gDebugInfo[4][3]; - ((struct GraphNode_802A45E4 *) a1->next)->unk20 = gDebugInfo[4][4]; - ((struct GraphNode_802A45E4 *) a1->next)->unk22 = gDebugInfo[4][5]; + ((struct GraphNodeTranslationRotation *) node->next)->translation[0] = gDebugInfo[DEBUG_PAGE_EFFECTINFO][0]; + ((struct GraphNodeTranslationRotation *) node->next)->translation[1] = gDebugInfo[DEBUG_PAGE_EFFECTINFO][1]; + ((struct GraphNodeTranslationRotation *) node->next)->translation[2] = gDebugInfo[DEBUG_PAGE_EFFECTINFO][2]; + ((struct GraphNodeTranslationRotation *) node->next)->rotation[0] = gDebugInfo[DEBUG_PAGE_EFFECTINFO][3]; + ((struct GraphNodeTranslationRotation *) node->next)->rotation[1] = gDebugInfo[DEBUG_PAGE_EFFECTINFO][4]; + ((struct GraphNodeTranslationRotation *) node->next)->rotation[2] = gDebugInfo[DEBUG_PAGE_EFFECTINFO][5]; } - return 0; + return NULL; } s32 obj_is_hidden(struct Object *obj) { @@ -2562,29 +2565,18 @@ static void cur_obj_end_dialog(s32 dialogFlags, s32 dialogResult) { o->oDialogResponse = dialogResult; o->oDialogState++; - if (!(dialogFlags & DIALOG_UNK1_FLAG_4)) { - set_mario_npc_dialog(0); + if (!(dialogFlags & DIALOG_FLAG_TIME_STOP_ENABLED)) { + set_mario_npc_dialog(MARIO_DIALOG_STOP); } } s32 cur_obj_update_dialog(s32 actionArg, s32 dialogFlags, s32 dialogID, UNUSED s32 unused) { - s32 dialogResponse = 0; + s32 dialogResponse = DIALOG_RESPONSE_NONE; UNUSED s32 doneTurning = TRUE; switch (o->oDialogState) { -#ifdef VERSION_JP - case DIALOG_UNK1_ENABLE_TIME_STOP: - //! We enable time stop even if Mario is not ready to speak. This - // allows us to move during time stop as long as Mario never enters - // an action that can be interrupted with text. - if (gMarioState->health >= 0x100) { - gTimeStopState |= TIME_STOP_ENABLED; - o->activeFlags |= ACTIVE_FLAG_INITIATED_TIME_STOP; - o->oDialogState++; - } - break; -#else - case DIALOG_UNK1_ENABLE_TIME_STOP: +#if BUGFIX_DIALOG_TIME_STOP + case DIALOG_STATUS_ENABLE_TIME_STOP: // Patched :( // Wait for Mario to be ready to speak, and then enable time stop if (mario_ready_to_speak() || gMarioState->action == ACT_READING_NPC_DIALOG) { @@ -2596,48 +2588,67 @@ s32 cur_obj_update_dialog(s32 actionArg, s32 dialogFlags, s32 dialogID, UNUSED s } // Fall through so that Mario's action is interrupted immediately // after time is stopped +#else + case DIALOG_STATUS_ENABLE_TIME_STOP: + //! We enable time stop even if Mario is not ready to speak. This + // allows us to move during time stop as long as Mario never enters + // an action that can be interrupted with text. + if (gMarioState->health >= 0x100) { + gTimeStopState |= TIME_STOP_ENABLED; + o->activeFlags |= ACTIVE_FLAG_INITIATED_TIME_STOP; + o->oDialogState++; + } + break; #endif - - case DIALOG_UNK1_INTERRUPT_MARIO_ACTION: - if (set_mario_npc_dialog(actionArg) == 2) { + case DIALOG_STATUS_INTERRUPT: + // Interrupt until Mario is actually speaking with the NPC + if (set_mario_npc_dialog(actionArg) == MARIO_DIALOG_STATUS_SPEAK) { o->oDialogState++; } break; - case DIALOG_UNK1_BEGIN_DIALOG: - if (dialogFlags & DIALOG_UNK1_FLAG_RESPONSE) { + case DIALOG_STATUS_START_DIALOG: + // Starts dialog, depending of the flag defined, it calls + // a default dialog or a dialog with response. + if (dialogFlags & DIALOG_FLAG_TEXT_RESPONSE) { create_dialog_box_with_response(dialogID); - } else if (dialogFlags & DIALOG_UNK1_FLAG_DEFAULT) { + } else if (dialogFlags & DIALOG_FLAG_TEXT_DEFAULT) { create_dialog_box(dialogID); } o->oDialogState++; break; - case DIALOG_UNK1_AWAIT_DIALOG: - if (dialogFlags & DIALOG_UNK1_FLAG_RESPONSE) { - if (gDialogResponse != 0) { + case DIALOG_STATUS_STOP_DIALOG: + // Stops dialog, if the flag dialog response was called + // then it defines the value to let the object do the rest. + if (dialogFlags & DIALOG_FLAG_TEXT_RESPONSE) { + if (gDialogResponse != DIALOG_RESPONSE_NONE) { cur_obj_end_dialog(dialogFlags, gDialogResponse); } - } else if (dialogFlags & DIALOG_UNK1_FLAG_DEFAULT) { - if (get_dialog_id() == -1) { - cur_obj_end_dialog(dialogFlags, 3); + } else if (dialogFlags & DIALOG_FLAG_TEXT_DEFAULT) { + if (get_dialog_id() == DIALOG_NONE) { + cur_obj_end_dialog(dialogFlags, DIALOG_RESPONSE_NOT_DEFINED); } } else { - cur_obj_end_dialog(dialogFlags, 3); + cur_obj_end_dialog(dialogFlags, DIALOG_RESPONSE_NOT_DEFINED); } break; - case DIALOG_UNK1_DISABLE_TIME_STOP: - if (gMarioState->action != ACT_READING_NPC_DIALOG || (dialogFlags & DIALOG_UNK1_FLAG_4)) { + case DIALOG_STATUS_DISABLE_TIME_STOP: + // We disable time stop for a few seconds when Mario is no longer + // speaking or the flag is defined, then we enable it again. + // Usually, an object disables time stop using a separate function + // after a certain condition is met. + if (gMarioState->action != ACT_READING_NPC_DIALOG || (dialogFlags & DIALOG_FLAG_TIME_STOP_ENABLED)) { gTimeStopState &= ~TIME_STOP_ENABLED; o->activeFlags &= ~ACTIVE_FLAG_INITIATED_TIME_STOP; dialogResponse = o->oDialogResponse; - o->oDialogState = DIALOG_UNK1_ENABLE_TIME_STOP; + o->oDialogState = DIALOG_STATUS_ENABLE_TIME_STOP; } break; default: - o->oDialogState = DIALOG_UNK1_ENABLE_TIME_STOP; + o->oDialogState = DIALOG_STATUS_ENABLE_TIME_STOP; break; } @@ -2645,12 +2656,25 @@ s32 cur_obj_update_dialog(s32 actionArg, s32 dialogFlags, s32 dialogID, UNUSED s } s32 cur_obj_update_dialog_with_cutscene(s32 actionArg, s32 dialogFlags, s32 cutsceneTable, s32 dialogID) { - s32 dialogResponse = 0; + s32 dialogResponse = DIALOG_RESPONSE_NONE; s32 doneTurning = TRUE; switch (o->oDialogState) { -#ifdef VERSION_JP - case DIALOG_UNK2_ENABLE_TIME_STOP: +#if BUGFIX_DIALOG_TIME_STOP + case DIALOG_STATUS_ENABLE_TIME_STOP: + // Wait for Mario to be ready to speak, and then enable time stop + if (mario_ready_to_speak() || gMarioState->action == ACT_READING_NPC_DIALOG) { + gTimeStopState |= TIME_STOP_ENABLED; + o->activeFlags |= ACTIVE_FLAG_INITIATED_TIME_STOP; + o->oDialogState++; + o->oDialogResponse = DIALOG_RESPONSE_NONE; + } else { + break; + } + // Fall through so that Mario's action is interrupted immediately + // after time is stopped +#else + case DIALOG_STATUS_ENABLE_TIME_STOP: //! We enable time stop even if Mario is not ready to speak. This // allows us to move during time stop as long as Mario never enters // an action that can be interrupted with text. @@ -2658,63 +2682,61 @@ s32 cur_obj_update_dialog_with_cutscene(s32 actionArg, s32 dialogFlags, s32 cuts gTimeStopState |= TIME_STOP_ENABLED; o->activeFlags |= ACTIVE_FLAG_INITIATED_TIME_STOP; o->oDialogState++; - o->oDialogResponse = 0; + o->oDialogResponse = DIALOG_RESPONSE_NONE; } break; -#else - case DIALOG_UNK2_ENABLE_TIME_STOP: - // Wait for Mario to be ready to speak, and then enable time stop - if (mario_ready_to_speak() || gMarioState->action == ACT_READING_NPC_DIALOG) { - gTimeStopState |= TIME_STOP_ENABLED; - o->activeFlags |= ACTIVE_FLAG_INITIATED_TIME_STOP; - o->oDialogState++; - o->oDialogResponse = 0; - } else { - break; - } - // Fall through so that Mario's action is interrupted immediately - // after time is stopped #endif - - case DIALOG_UNK2_TURN_AND_INTERRUPT_MARIO_ACTION: - if (dialogFlags & DIALOG_UNK2_FLAG_0) { + case DIALOG_STATUS_INTERRUPT: + // Additional flag that makes the NPC rotate towards to Mario + if (dialogFlags & DIALOG_FLAG_TURN_TO_MARIO) { doneTurning = cur_obj_rotate_yaw_toward(obj_angle_to_object(o, gMarioObject), 0x800); + // Failsafe just in case it takes more than 33 frames somehow if (o->oDialogResponse >= 33) { doneTurning = TRUE; } } - - if (set_mario_npc_dialog(actionArg) == 2 && doneTurning) { + // Interrupt status until Mario is actually speaking with the NPC and if the + // object is done turning to Mario + if (set_mario_npc_dialog(actionArg) == MARIO_DIALOG_STATUS_SPEAK && doneTurning) { o->oDialogResponse = 0; o->oDialogState++; } else { - o->oDialogResponse++; + o->oDialogResponse++; // treated as a timer for the failsafe } break; - case DIALOG_UNK2_AWAIT_DIALOG: + case DIALOG_STATUS_START_DIALOG: + // Special check for Cap Switch cutscene since the cutscene itself + // handles what dialog should use if (cutsceneTable == CUTSCENE_CAP_SWITCH_PRESS) { - if ((o->oDialogResponse = cutscene_object_without_dialog(cutsceneTable, o)) != 0) { + if ((o->oDialogResponse = cutscene_object_without_dialog(cutsceneTable, o))) { o->oDialogState++; } } else { - if ((o->oDialogResponse = cutscene_object_with_dialog(cutsceneTable, o, dialogID)) != 0) { + // General dialog cutscene function, most of the time + // the "CUTSCENE_DIALOG" cutscene is called + if ((o->oDialogResponse = cutscene_object_with_dialog(cutsceneTable, o, dialogID))) { o->oDialogState++; } } break; - case DIALOG_UNK2_END_DIALOG: - if (dialogFlags & DIALOG_UNK2_LEAVE_TIME_STOP_ENABLED) { + case DIALOG_STATUS_STOP_DIALOG: + // If flag defined, keep time stop enabled until the object + // decided to disable it independently + if (dialogFlags & DIALOG_FLAG_TIME_STOP_ENABLED) { dialogResponse = o->oDialogResponse; - o->oDialogState = DIALOG_UNK2_ENABLE_TIME_STOP; + o->oDialogState = DIALOG_STATUS_ENABLE_TIME_STOP; } else if (gMarioState->action != ACT_READING_NPC_DIALOG) { + // Disable time stop, then enable time stop for a frame + // until the set_mario_npc_dialog function disables it gTimeStopState &= ~TIME_STOP_ENABLED; o->activeFlags &= ~ACTIVE_FLAG_INITIATED_TIME_STOP; dialogResponse = o->oDialogResponse; - o->oDialogState = DIALOG_UNK2_ENABLE_TIME_STOP; + o->oDialogState = DIALOG_STATUS_ENABLE_TIME_STOP; } else { - set_mario_npc_dialog(0); + // And finally stop Mario dialog status + set_mario_npc_dialog(MARIO_DIALOG_STOP); } break; } @@ -2886,7 +2908,7 @@ void cur_obj_spawn_loot_blue_coin(void) { #ifndef VERSION_JP void cur_obj_spawn_star_at_y_offset(f32 targetX, f32 targetY, f32 targetZ, f32 offsetY) { f32 objectPosY = o->oPosY; - o->oPosY += offsetY + gDebugInfo[5][0]; + o->oPosY += offsetY + gDebugInfo[DEBUG_PAGE_ENEMYINFO][0]; spawn_default_star(targetX, targetY, targetZ); o->oPosY = objectPosY; } diff --git a/src/game/object_helpers.h b/src/game/object_helpers.h index 895604fc..fcd985b4 100644 --- a/src/game/object_helpers.h +++ b/src/game/object_helpers.h @@ -7,8 +7,7 @@ #include "types.h" // used for chain chomp and wiggler -struct ChainSegment -{ +struct ChainSegment { f32 posX; f32 posY; f32 posZ; @@ -25,8 +24,7 @@ struct ChainSegment #define WATER_DROPLET_FLAG_RAND_ANGLE_INCR 0x80 // Unused // Call spawn_water_droplet with this struct to spawn an object. -struct WaterDropletParams -{ +struct WaterDropletParams { s16 flags; // Droplet spawn flags, see defines above s16 model; const BehaviorScript *behavior; @@ -50,9 +48,7 @@ struct Struct802A272C { Vec3s vecS; }; -// TODO: Field names -struct SpawnParticlesInfo -{ +struct SpawnParticlesInfo { /*0x00*/ s8 behParam; /*0x01*/ s8 count; /*0x02*/ u8 model; @@ -94,9 +90,9 @@ void obj_set_pos(struct Object *obj, s16 x, s16 y, s16 z); void obj_set_angle(struct Object *obj, s16 pitch, s16 yaw, s16 roll); struct Object *spawn_object_abs_with_rot(struct Object *parent, s16 uselessArg, u32 model, const BehaviorScript *behavior, - s16 x, s16 y, s16 z, s16 rx, s16 ry, s16 rz); + s16 x, s16 y, s16 z, s16 pitch, s16 yaw, s16 roll); struct Object *spawn_object_rel_with_rot(struct Object *parent, u32 model, const BehaviorScript *behavior, - s16 xOff, s16 yOff, s16 zOff, s16 rx, s16 ry, UNUSED s16 rz); + s16 xOff, s16 yOff, s16 zOff, s16 pitch, s16 yaw, UNUSED s16 roll); struct Object *spawn_obj_with_transform_flags(struct Object *sp20, s32 model, const BehaviorScript *sp28); struct Object *spawn_water_droplet(struct Object *parent, struct WaterDropletParams *params); struct Object *spawn_object_at_origin(struct Object *, s32, u32, const BehaviorScript *); @@ -119,7 +115,7 @@ void linear_mtxf_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v); void linear_mtxf_transpose_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v); void obj_apply_scale_to_transform(struct Object *obj); void obj_copy_scale(struct Object *dst, struct Object *src); -void obj_scale_xyz(struct Object* obj, f32 xScale, f32 yScale, f32 zScale); +void obj_scale_xyz(struct Object *obj, f32 xScale, f32 yScale, f32 zScale); void obj_scale(struct Object *obj, f32 scale); void cur_obj_scale(f32 scale); void cur_obj_init_animation_with_sound(s32 animIndex); @@ -154,7 +150,7 @@ s32 cur_obj_check_frame_prior_current_frame(s16 *a0); s32 mario_is_in_air_action(void); s32 mario_is_dive_sliding(void); void cur_obj_set_y_vel_and_animation(f32 sp18, s32 sp1C); -void cur_obj_unrender_and_reset_state(s32 sp18, s32 sp1C); +void cur_obj_unrender_set_action_and_anim(s32 sp18, s32 sp1C); void cur_obj_get_thrown_or_placed(f32 forwardVel, f32 velY, s32 thrownAction); void cur_obj_get_dropped(void); void cur_obj_set_model(s32 modelID); @@ -186,7 +182,7 @@ void cur_obj_set_pos_to_home(void); void cur_obj_set_pos_to_home_and_stop(void); void cur_obj_shake_y(f32 amount); void cur_obj_start_cam_event(UNUSED struct Object *obj, s32 cameraEvent); -void set_mario_interact_hoot_if_in_range(UNUSED s32 sp0, UNUSED s32 sp4, f32 sp8); +void set_mario_interact_true_if_in_range(UNUSED s32 sp0, UNUSED s32 sp4, f32 sp8); void obj_set_billboard(struct Object *obj); void cur_obj_set_hitbox_radius_and_height(f32 radius, f32 height); void cur_obj_set_hurtbox_radius_and_height(f32 radius, f32 height); @@ -226,16 +222,6 @@ s16 cur_obj_reflect_move_angle_off_wall(void); #define PATH_REACHED_END -1 #define PATH_REACHED_WAYPOINT 1 -struct GraphNode_802A45E4 { - /*0x00*/ s8 filler0[0x18 - 0x00]; - /*0x18*/ s16 unk18; - /*0x1A*/ s16 unk1A; - /*0x1C*/ s16 unk1C; - /*0x1E*/ s16 unk1E; - /*0x20*/ s16 unk20; - /*0x22*/ s16 unk22; -}; - void obj_set_hitbox(struct Object *obj, struct ObjectHitbox *hitbox); s32 signum_positive(s32 x); f32 absf(f32 x); @@ -252,7 +238,7 @@ void stub_obj_helpers_3(UNUSED s32 sp0, UNUSED s32 sp4); void cur_obj_scale_over_time(s32 a0, s32 a1, f32 sp10, f32 sp14); void cur_obj_set_pos_to_home_with_debug(void); s32 cur_obj_is_mario_on_platform(void); -s32 cur_obj_move_up_and_down(s32 a0); +s32 jiggle_bbh_stair(s32 a0); void cur_obj_call_action_function(void (*actionFunctions[])(void)); void spawn_base_star_with_no_lvl_exit(void); s32 bit_shift_left(s32 a0); @@ -266,7 +252,7 @@ void obj_set_collision_data(struct Object *obj, const void *segAddr); void cur_obj_if_hit_wall_bounce_away(void); s32 cur_obj_hide_if_mario_far_away_y(f32 distY); Gfx *geo_offset_klepto_held_object(s32 callContext, struct GraphNode *node, UNUSED Mat4 mtx); -s32 geo_offset_klepto_debug(s32 a0, struct GraphNode *a1, UNUSED s32 sp8); +Gfx *geo_offset_klepto_debug(s32 callContext, struct GraphNode *node, UNUSED Mat4 mtx); s32 obj_is_hidden(struct Object *obj); void enable_time_stop(void); void disable_time_stop(void); diff --git a/src/game/object_list_processor.c b/src/game/object_list_processor.c index d01f5eb4..80a49fb6 100644 --- a/src/game/object_list_processor.c +++ b/src/game/object_list_processor.c @@ -225,7 +225,7 @@ void copy_mario_state_to_object(void) { s32 i = 0; // L is real if (gCurrentObject != gMarioObject) { - i += 1; + i++; } gCurrentObject->oVelX = gMarioStates[i].vel[0]; @@ -300,7 +300,7 @@ s32 update_objects_starting_at(struct ObjectNode *objList, struct ObjectNode *fi cur_obj_update(); firstObj = firstObj->next; - count += 1; + count++; } return count; @@ -470,7 +470,7 @@ void spawn_objects_from_info(UNUSED s32 unused, struct SpawnInfo *spawnInfo) { while (spawnInfo != NULL) { struct Object *object; - UNUSED s32 unused; + UNUSED u8 filler[4]; const BehaviorScript *script; UNUSED s16 arg16 = (s16)(spawnInfo->behaviorArg & 0xFFFF); @@ -571,13 +571,13 @@ void update_terrain_objects(void) { * the order specified by sObjectListUpdateOrder. */ void update_non_terrain_objects(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; s32 listIndex; s32 i = 2; while ((listIndex = sObjectListUpdateOrder[i]) != -1) { gObjectCounter += update_objects_in_list(&gObjectLists[listIndex]); - i += 1; + i++; } } @@ -585,13 +585,13 @@ void update_non_terrain_objects(void) { * Unload deactivated objects in any object list. */ void unload_deactivated_objects(void) { - UNUSED s32 unused; + UNUSED u8 filler[4]; s32 listIndex; s32 i = 0; while ((listIndex = sObjectListUpdateOrder[i]) != -1) { unload_deactivated_objects_in_list(&gObjectLists[listIndex]); - i += 1; + i++; } // TIME_STOP_UNKNOWN_0 was most likely intended to be used to track whether @@ -602,7 +602,7 @@ void unload_deactivated_objects(void) { /** * Unused profiling function. */ -static u16 unused_get_elapsed_time(u64 *cycleCounts, s32 index) { +UNUSED static u16 unused_get_elapsed_time(u64 *cycleCounts, s32 index) { u16 time; f64 cycles; diff --git a/src/game/object_list_processor.h b/src/game/object_list_processor.h index e3884f34..aed11fb9 100644 --- a/src/game/object_list_processor.h +++ b/src/game/object_list_processor.h @@ -29,8 +29,7 @@ * Every object is categorized into an object list, which controls the order * they are processed and which objects they can collide with. */ -enum ObjectList -{ +enum ObjectList { OBJ_LIST_PLAYER, // (0) Mario OBJ_LIST_UNUSED_1, // (1) (unused) OBJ_LIST_DESTRUCTIVE, // (2) things that can be used to destroy other objects, like diff --git a/src/game/paintings.c b/src/game/paintings.c index 83bd2ce9..481db8f3 100644 --- a/src/game/paintings.c +++ b/src/game/paintings.c @@ -254,6 +254,9 @@ f32 painting_ripple_y(struct Painting *painting, s8 ySource) { return painting->size / 2.0; // some concentric ripples don't care about Mario break; } +#ifdef AVOID_UB + return 0.0f; +#endif } /** @@ -279,6 +282,9 @@ f32 painting_nearest_4th(struct Painting *painting) { } else if (painting->floorEntered & ENTER_RIGHT) { return thirdQuarter; } +#ifdef AVOID_UB + return 0.0f; +#endif } /** @@ -310,6 +316,9 @@ f32 painting_ripple_x(struct Painting *painting, s8 xSource) { return painting->size / 2.0; break; } +#ifdef AVOID_UB + return 0.0f; +#endif } /** @@ -1100,7 +1109,7 @@ void reset_painting(struct Painting *painting) { */ void move_ddd_painting(struct Painting *painting, f32 frontPos, f32 backPos, f32 speed) { // Obtain the DDD star flags - u32 dddFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_DDD - 1); + u32 dddFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(COURSE_DDD)); // Get the other save file flags u32 saveFileFlags = save_file_get_flags(); // Find out whether Board Bowser's Sub was collected diff --git a/src/game/paintings.h b/src/game/paintings.h index 3f4334b4..8c930331 100644 --- a/src/game/paintings.h +++ b/src/game/paintings.h @@ -15,7 +15,7 @@ #define PAINTING_ID_DDD 7 -#define BOARD_BOWSERS_SUB 1 +#define BOARD_BOWSERS_SUB (1 << 0) #define BOWSERS_SUB_BEATEN 0x2 #define DDD_BACK 0x1 @@ -32,8 +32,7 @@ /// Painting that has one texture used for an environment map effect #define PAINTING_ENV_MAP 1 -struct Painting -{ +struct Painting { s16 id; /// How many images should be drawn when the painting is rippling. s8 imageCount; diff --git a/src/game/platform_displacement.c b/src/game/platform_displacement.c index 9153bc4d..40a19940 100644 --- a/src/game/platform_displacement.c +++ b/src/game/platform_displacement.c @@ -21,7 +21,7 @@ struct Object *gMarioPlatform = NULL; */ void update_mario_platform(void) { struct Surface *floor; - UNUSED u32 unused; + UNUSED u8 filler[4]; f32 marioX; f32 marioY; f32 marioZ; @@ -99,9 +99,9 @@ void apply_platform_displacement(u32 isMario, struct Object *platform) { Vec3f relativeOffset; Vec3f newObjectOffset; Vec3s rotation; - UNUSED s16 unused1; - UNUSED s16 unused2; - UNUSED s16 unused3; + UNUSED s16 unusedPitch; + UNUSED s16 unusedRoll; + UNUSED s16 unusedYaw; f32 displaceMatrix[4][4]; rotation[0] = platform->oAngleVelPitch; @@ -121,9 +121,9 @@ void apply_platform_displacement(u32 isMario, struct Object *platform) { z += platform->oVelZ; if (rotation[0] != 0 || rotation[1] != 0 || rotation[2] != 0) { - unused1 = rotation[0]; - unused2 = rotation[2]; - unused3 = platform->oFaceAngleYaw; + unusedPitch = rotation[0]; + unusedRoll = rotation[2]; + unusedYaw = platform->oFaceAngleYaw; if (isMario) { gMarioStates[0].faceAngle[1] += rotation[1]; diff --git a/src/game/print.c b/src/game/print.c index e5972271..c804cb4a 100644 --- a/src/game/print.c +++ b/src/game/print.c @@ -107,8 +107,7 @@ void format_integer(s32 n, s32 base, char *dest, s32 *totalLength, u8 width, s8 n -= digit * powBase; } - } else // n is zero. - { + } else { // n is zero. numDigits = 1; if (width > numDigits) { for (len = 0; len < width - numDigits; len++) dest[len] = pad; @@ -138,8 +137,7 @@ void parse_width_field(const char *str, s32 *srcIndex, u8 *width, s8 *zeroPad) { while (str[*srcIndex] != 'd' && str[*srcIndex] != 'x') { digits[digitsLen] = str[*srcIndex] - '0'; - if (digits[digitsLen] < 0 || digits[digitsLen] >= 10) // not a valid digit - { + if (digits[digitsLen] < 0 || digits[digitsLen] >= 10) { // not a valid digit *width = 0; return; } @@ -206,8 +204,7 @@ void print_text_fmt_int(s32 x, s32 y, const char *str, s32 n) { srcIndex++; format_integer(n, base, sTextLabels[sTextLabelsCount]->buffer + len, &len, width, zeroPad); - } else // straight copy - { + } else { // straight copy sTextLabels[sTextLabelsCount]->buffer[len] = c; len++; srcIndex++; diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index 58238e83..8ea0d399 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -58,12 +58,12 @@ struct GeoAnimState { // of separate global variables. It won't match EU otherwise. struct GeoAnimState gGeoTempState; -u8 gCurAnimType; -u8 gCurAnimEnabled; +u8 gCurrAnimType; +u8 gCurrAnimEnabled; s16 gCurrAnimFrame; -f32 gCurAnimTranslationMultiplier; +f32 gCurrAnimTranslationMultiplier; u16 *gCurrAnimAttribute; -s16 *gCurAnimData; +s16 *gCurrAnimData; struct AllocOnlyPool *gDisplayListHeap; @@ -200,7 +200,7 @@ static void geo_append_display_list(void *displayList, s16 layer) { */ static void geo_process_master_list(struct GraphNodeMasterList *node) { s32 i; - UNUSED s32 sp1C; + UNUSED u8 filler[4]; if (gCurGraphNodeMasterList == NULL && node->node.children != NULL) { gCurGraphNodeMasterList = node; @@ -546,43 +546,43 @@ static void geo_process_animated_part(struct GraphNodeAnimatedPart *node) { vec3s_copy(rotation, gVec3sZero); vec3f_set(translation, node->translation[0], node->translation[1], node->translation[2]); - if (gCurAnimType == ANIM_TYPE_TRANSLATION) { - translation[0] += gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] - * gCurAnimTranslationMultiplier; - translation[1] += gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] - * gCurAnimTranslationMultiplier; - translation[2] += gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] - * gCurAnimTranslationMultiplier; - gCurAnimType = ANIM_TYPE_ROTATION; + if (gCurrAnimType == ANIM_TYPE_TRANSLATION) { + translation[0] += gCurrAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] + * gCurrAnimTranslationMultiplier; + translation[1] += gCurrAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] + * gCurrAnimTranslationMultiplier; + translation[2] += gCurrAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] + * gCurrAnimTranslationMultiplier; + gCurrAnimType = ANIM_TYPE_ROTATION; } else { - if (gCurAnimType == ANIM_TYPE_LATERAL_TRANSLATION) { + if (gCurrAnimType == ANIM_TYPE_LATERAL_TRANSLATION) { translation[0] += - gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] - * gCurAnimTranslationMultiplier; + gCurrAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] + * gCurrAnimTranslationMultiplier; gCurrAnimAttribute += 2; translation[2] += - gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] - * gCurAnimTranslationMultiplier; - gCurAnimType = ANIM_TYPE_ROTATION; + gCurrAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] + * gCurrAnimTranslationMultiplier; + gCurrAnimType = ANIM_TYPE_ROTATION; } else { - if (gCurAnimType == ANIM_TYPE_VERTICAL_TRANSLATION) { + if (gCurrAnimType == ANIM_TYPE_VERTICAL_TRANSLATION) { gCurrAnimAttribute += 2; translation[1] += - gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] - * gCurAnimTranslationMultiplier; + gCurrAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] + * gCurrAnimTranslationMultiplier; gCurrAnimAttribute += 2; - gCurAnimType = ANIM_TYPE_ROTATION; - } else if (gCurAnimType == ANIM_TYPE_NO_TRANSLATION) { + gCurrAnimType = ANIM_TYPE_ROTATION; + } else if (gCurrAnimType == ANIM_TYPE_NO_TRANSLATION) { gCurrAnimAttribute += 6; - gCurAnimType = ANIM_TYPE_ROTATION; + gCurrAnimType = ANIM_TYPE_ROTATION; } } } - if (gCurAnimType == ANIM_TYPE_ROTATION) { - rotation[0] = gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]; - rotation[1] = gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]; - rotation[2] = gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]; + if (gCurrAnimType == ANIM_TYPE_ROTATION) { + rotation[0] = gCurrAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]; + rotation[1] = gCurrAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]; + rotation[2] = gCurrAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)]; } mtxf_rotate_xyz_and_translate(matrix, translation, rotation); mtxf_mul(gMatStack[gMatStackIndex + 1], matrix, gMatStack[gMatStackIndex]); @@ -610,24 +610,24 @@ void geo_set_animation_globals(struct AnimInfo *node, s32 hasAnimation) { } node->animTimer = gAreaUpdateCounter; if (anim->flags & ANIM_FLAG_HOR_TRANS) { - gCurAnimType = ANIM_TYPE_VERTICAL_TRANSLATION; + gCurrAnimType = ANIM_TYPE_VERTICAL_TRANSLATION; } else if (anim->flags & ANIM_FLAG_VERT_TRANS) { - gCurAnimType = ANIM_TYPE_LATERAL_TRANSLATION; + gCurrAnimType = ANIM_TYPE_LATERAL_TRANSLATION; } else if (anim->flags & ANIM_FLAG_6) { - gCurAnimType = ANIM_TYPE_NO_TRANSLATION; + gCurrAnimType = ANIM_TYPE_NO_TRANSLATION; } else { - gCurAnimType = ANIM_TYPE_TRANSLATION; + gCurrAnimType = ANIM_TYPE_TRANSLATION; } gCurrAnimFrame = node->animFrame; - gCurAnimEnabled = (anim->flags & ANIM_FLAG_5) == 0; + gCurrAnimEnabled = (anim->flags & ANIM_FLAG_5) == 0; gCurrAnimAttribute = segmented_to_virtual((void *) anim->index); - gCurAnimData = segmented_to_virtual((void *) anim->values); + gCurrAnimData = segmented_to_virtual((void *) anim->values); if (anim->animYTransDivisor == 0) { - gCurAnimTranslationMultiplier = 1.0f; + gCurrAnimTranslationMultiplier = 1.0f; } else { - gCurAnimTranslationMultiplier = (f32) node->animYTrans / (f32) anim->animYTransDivisor; + gCurrAnimTranslationMultiplier = (f32) node->animYTrans / (f32) anim->animYTransDivisor; } } @@ -659,21 +659,21 @@ static void geo_process_shadow(struct GraphNodeShadow *node) { } objScale = 1.0f; - if (gCurAnimEnabled) { - if (gCurAnimType == ANIM_TYPE_TRANSLATION - || gCurAnimType == ANIM_TYPE_LATERAL_TRANSLATION) { + if (gCurrAnimEnabled) { + if (gCurrAnimType == ANIM_TYPE_TRANSLATION + || gCurrAnimType == ANIM_TYPE_LATERAL_TRANSLATION) { geo = node->node.children; if (geo != NULL && geo->type == GRAPH_NODE_TYPE_SCALE) { objScale = ((struct GraphNodeScale *) geo)->scale; } animOffset[0] = - gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] - * gCurAnimTranslationMultiplier * objScale; + gCurrAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] + * gCurrAnimTranslationMultiplier * objScale; animOffset[1] = 0.0f; gCurrAnimAttribute += 2; animOffset[2] = - gCurAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] - * gCurAnimTranslationMultiplier * objScale; + gCurrAnimData[retrieve_animation_index(gCurrAnimFrame, &gCurrAnimAttribute)] + * gCurrAnimTranslationMultiplier * objScale; gCurrAnimAttribute -= 6; // simple matrix rotation so the shadow offset rotates along with the object @@ -846,7 +846,7 @@ static void geo_process_object(struct Object *node) { } gMatStackIndex--; - gCurAnimType = ANIM_TYPE_NONE; + gCurrAnimType = ANIM_TYPE_NONE; node->header.gfx.throwMatrix = NULL; } } @@ -904,13 +904,13 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { gMatStackIndex++; mtxf_to_mtx(mtx, gMatStack[gMatStackIndex]); gMatStackFixed[gMatStackIndex] = mtx; - gGeoTempState.type = gCurAnimType; - gGeoTempState.enabled = gCurAnimEnabled; + gGeoTempState.type = gCurrAnimType; + gGeoTempState.enabled = gCurrAnimEnabled; gGeoTempState.frame = gCurrAnimFrame; - gGeoTempState.translationMultiplier = gCurAnimTranslationMultiplier; + gGeoTempState.translationMultiplier = gCurrAnimTranslationMultiplier; gGeoTempState.attribute = gCurrAnimAttribute; - gGeoTempState.data = gCurAnimData; - gCurAnimType = 0; + gGeoTempState.data = gCurrAnimData; + gCurrAnimType = 0; gCurGraphNodeHeldObject = (void *) node; if (node->objNode->header.gfx.animInfo.curAnim != NULL) { geo_set_animation_globals(&node->objNode->header.gfx.animInfo, hasAnimation); @@ -918,12 +918,12 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) { geo_process_node_and_siblings(node->objNode->header.gfx.sharedChild); gCurGraphNodeHeldObject = NULL; - gCurAnimType = gGeoTempState.type; - gCurAnimEnabled = gGeoTempState.enabled; + gCurrAnimType = gGeoTempState.type; + gCurrAnimEnabled = gGeoTempState.enabled; gCurrAnimFrame = gGeoTempState.frame; - gCurAnimTranslationMultiplier = gGeoTempState.translationMultiplier; + gCurrAnimTranslationMultiplier = gGeoTempState.translationMultiplier; gCurrAnimAttribute = gGeoTempState.attribute; - gCurAnimData = gGeoTempState.data; + gCurrAnimData = gGeoTempState.data; gMatStackIndex--; } @@ -1040,7 +1040,7 @@ void geo_process_node_and_siblings(struct GraphNode *firstNode) { * to set up the projection and draw display lists. */ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) { - UNUSED s32 unused; + UNUSED u8 filler[4]; if (node->node.flags & GRAPH_RENDER_ACTIVE) { Mtx *initialMatrix; @@ -1050,17 +1050,17 @@ void geo_process_root(struct GraphNodeRoot *node, Vp *b, Vp *c, s32 clearColor) MEMORY_POOL_LEFT); initialMatrix = alloc_display_list(sizeof(*initialMatrix)); gMatStackIndex = 0; - gCurAnimType = 0; + gCurrAnimType = 0; vec3s_set(viewport->vp.vtrans, node->x * 4, node->y * 4, 511); vec3s_set(viewport->vp.vscale, node->width * 4, node->height * 4, 511); if (b != NULL) { - clear_frame_buffer(clearColor); + clear_framebuffer(clearColor); make_viewport_clip_rect(b); *viewport = *b; } else if (c != NULL) { - clear_frame_buffer(clearColor); + clear_framebuffer(clearColor); make_viewport_clip_rect(c); } diff --git a/src/game/rumble_init.c b/src/game/rumble_init.c index a708a5c1..6c89f86f 100644 --- a/src/game/rumble_init.c +++ b/src/game/rumble_init.c @@ -4,8 +4,9 @@ #include "buffers/buffers.h" #include "main.h" #include "rumble_init.h" +#include "config.h" -#ifdef VERSION_SH +#if ENABLE_RUMBLE OSThread gRumblePakThread; @@ -21,8 +22,8 @@ OSMesgQueue gRumbleThreadVIMesgQueue; struct RumbleData gRumbleDataQueue[3]; struct StructSH8031D9B0 gCurrRumbleSettings; -s32 sRumblePakThreadActive = 0; -s32 sRumblePakActive = 0; +s32 sRumblePakThreadActive = FALSE; +s32 sRumblePakActive = FALSE; s32 sRumblePakErrorCount = 0; s32 gRumblePakTimer = 0; @@ -290,7 +291,7 @@ void create_thread_6(void) { } void rumble_thread_update_vi(void) { - if (sRumblePakThreadActive == FALSE) { + if (!sRumblePakThreadActive) { return; } diff --git a/src/game/rumble_init.h b/src/game/rumble_init.h index 67aca829..cc47d75b 100644 --- a/src/game/rumble_init.h +++ b/src/game/rumble_init.h @@ -1,7 +1,11 @@ #ifndef RUMBLE_INIT_H #define RUMBLE_INIT_H -#ifdef VERSION_SH +#include + +#include "config.h" + +#if ENABLE_RUMBLE extern s32 gRumblePakTimer; @@ -18,6 +22,6 @@ void cancel_rumble(void); void create_thread_6(void); void rumble_thread_update_vi(void); -#endif // VERSION_SH +#endif // ENABLE_RUMBLE #endif // RUMBLE_INIT_H diff --git a/src/game/save_file.c b/src/game/save_file.c index 9cc97a5f..85e5df18 100644 --- a/src/game/save_file.c +++ b/src/game/save_file.c @@ -26,7 +26,7 @@ s8 gSaveFileModified; u8 gLastCompletedCourseNum = COURSE_NONE; u8 gLastCompletedStarNum = 0; -s8 sUnusedGotGlobalCoinHiScore = 0; +s8 sUnusedGotGlobalCoinHiScore = FALSE; u8 gGotFileCoinHiScore = FALSE; u8 gCurrCourseStarFlags = 0; @@ -47,7 +47,7 @@ STATIC_ASSERT(ARRAY_COUNT(gLevelToCourseNumTable) == LEVEL_COUNT - 1, // This was probably used to set progress to 100% for debugging, but // it was removed from the release ROM. static void stub_save_file_1(void) { - UNUSED s32 pad; + UNUSED u8 filler[4]; } /** @@ -64,12 +64,12 @@ static s32 read_eeprom_data(void *buffer, s32 size) { u32 offset = (u32)((u8 *) buffer - (u8 *) &gSaveBuffer) / 8; do { -#ifdef VERSION_SH +#if ENABLE_RUMBLE block_until_rumble_pak_free(); #endif triesLeft--; status = osEepromLongRead(&gSIEventMesgQueue, offset, buffer, size); -#ifdef VERSION_SH +#if ENABLE_RUMBLE release_rumble_pak_control(); #endif } while (triesLeft > 0 && status != 0); @@ -92,12 +92,12 @@ static s32 write_eeprom_data(void *buffer, s32 size) { u32 offset = (u32)((u8 *) buffer - (u8 *) &gSaveBuffer) >> 3; do { -#ifdef VERSION_SH +#if ENABLE_RUMBLE block_until_rumble_pak_free(); #endif triesLeft--; status = osEepromLongWrite(&gSIEventMesgQueue, offset, buffer, size); -#ifdef VERSION_SH +#if ENABLE_RUMBLE release_rumble_pak_control(); #endif } while (triesLeft > 0 && status != 0); @@ -225,7 +225,7 @@ static void touch_coin_score_age(s32 fileIndex, s32 courseIndex) { static void touch_high_score_ages(s32 fileIndex) { s32 i; - for (i = 0; i < 15; i++) { + for (i = COURSE_NUM_TO_INDEX(COURSE_MIN); i <= COURSE_NUM_TO_INDEX(COURSE_STAGES_MAX); i++) { touch_coin_score_age(fileIndex, i); } } @@ -278,7 +278,7 @@ void save_file_erase(s32 fileIndex) { //! Needs to be s32 to match on -O2, despite no return value. BAD_RETURN(s32) save_file_copy(s32 srcFileIndex, s32 destFileIndex) { - UNUSED s32 pad; + UNUSED u8 filler[4]; touch_high_score_ages(destFileIndex); bcopy(&gSaveBuffer.files[srcFileIndex][0], &gSaveBuffer.files[destFileIndex][0], @@ -356,22 +356,23 @@ void save_file_reload(void) { */ void save_file_collect_star_or_key(s16 coinScore, s16 starIndex) { s32 fileIndex = gCurrSaveFileNum - 1; - s32 courseIndex = gCurrCourseNum - 1; + s32 courseIndex = COURSE_NUM_TO_INDEX(gCurrCourseNum); s32 starFlag = 1 << starIndex; UNUSED s32 flags = save_file_get_flags(); gLastCompletedCourseNum = courseIndex + 1; gLastCompletedStarNum = starIndex + 1; - sUnusedGotGlobalCoinHiScore = 0; + sUnusedGotGlobalCoinHiScore = FALSE; gGotFileCoinHiScore = FALSE; - if (courseIndex >= 0 && courseIndex < COURSE_STAGES_COUNT) { + if (courseIndex >= COURSE_NUM_TO_INDEX(COURSE_MIN) + && courseIndex <= COURSE_NUM_TO_INDEX(COURSE_STAGES_MAX)) { //! Compares the coin score as a 16 bit value, but only writes the 8 bit // truncation. This can allow a high score to decrease. if (coinScore > ((u16) save_file_get_max_coin_score(courseIndex) & 0xFFFF)) { - sUnusedGotGlobalCoinHiScore = 1; + sUnusedGotGlobalCoinHiScore = TRUE; } if (coinScore > save_file_get_course_coin_score(fileIndex, courseIndex)) { @@ -460,7 +461,7 @@ s32 save_file_get_total_star_count(s32 fileIndex, s32 minCourse, s32 maxCourse) } // Add castle secret star count. - return save_file_get_course_star_count(fileIndex, -1) + count; + return save_file_get_course_star_count(fileIndex, COURSE_NUM_TO_INDEX(COURSE_NONE)) + count; } void save_file_set_flags(u32 flags) { @@ -483,12 +484,12 @@ u32 save_file_get_flags(void) { /** * Return the bitset of obtained stars in the specified course. - * If course is -1, return the bitset of obtained castle secret stars. + * If course is COURSE_NONE, return the bitset of obtained castle secret stars. */ u32 save_file_get_star_flags(s32 fileIndex, s32 courseIndex) { u32 starFlags; - if (courseIndex == -1) { + if (courseIndex == COURSE_NUM_TO_INDEX(COURSE_NONE)) { starFlags = SAVE_FLAG_TO_STAR_FLAG(gSaveBuffer.files[fileIndex][0].flags); } else { starFlags = gSaveBuffer.files[fileIndex][0].courseStars[courseIndex] & 0x7F; @@ -499,10 +500,10 @@ u32 save_file_get_star_flags(s32 fileIndex, s32 courseIndex) { /** * Add to the bitset of obtained stars in the specified course. - * If course is -1, add to the bitset of obtained castle secret stars. + * If course is COURSE_NONE, add to the bitset of obtained castle secret stars. */ void save_file_set_star_flags(s32 fileIndex, s32 courseIndex, u32 starFlags) { - if (courseIndex == -1) { + if (courseIndex == COURSE_NUM_TO_INDEX(COURSE_NONE)) { gSaveBuffer.files[fileIndex][0].flags |= STAR_FLAG_TO_SAVE_FLAG(starFlags); } else { gSaveBuffer.files[fileIndex][0].courseStars[courseIndex] |= starFlags; @@ -520,14 +521,14 @@ s32 save_file_get_course_coin_score(s32 fileIndex, s32 courseIndex) { * Return TRUE if the cannon is unlocked in the current course. */ s32 save_file_is_cannon_unlocked(void) { - return (gSaveBuffer.files[gCurrSaveFileNum - 1][0].courseStars[gCurrCourseNum] & 0x80) != 0; + return (gSaveBuffer.files[gCurrSaveFileNum - 1][0].courseStars[gCurrCourseNum] & (1 << 7)) != 0; } /** * Sets the cannon status to unlocked in the current course. */ void save_file_set_cannon_unlocked(void) { - gSaveBuffer.files[gCurrSaveFileNum - 1][0].courseStars[gCurrCourseNum] |= 0x80; + gSaveBuffer.files[gCurrSaveFileNum - 1][0].courseStars[gCurrCourseNum] |= (1 << 7); gSaveBuffer.files[gCurrSaveFileNum - 1][0].flags |= SAVE_FLAG_FILE_EXISTS; gSaveFileModified = TRUE; } diff --git a/src/game/save_file.h b/src/game/save_file.h index ae6fcf35..ad1b62a9 100644 --- a/src/game/save_file.h +++ b/src/game/save_file.h @@ -11,14 +11,12 @@ #define EEPROM_SIZE 0x200 #define NUM_SAVE_FILES 4 -struct SaveBlockSignature -{ +struct SaveBlockSignature { u16 magic; u16 chksum; }; -struct SaveFile -{ +struct SaveFile { // Location of lost cap. // Note: the coordinates get set, but are never actually used, since the // cap can always be found in a fixed spot within the course @@ -45,8 +43,7 @@ enum SaveFileIndex { SAVE_FILE_D }; -struct MainMenuSaveData -{ +struct MainMenuSaveData { // Each save file has a 2 bit "age" for each course. The higher this value, // the older the high score is. This is used for tie-breaking when displaying // on the high score screen. @@ -66,8 +63,7 @@ struct MainMenuSaveData struct SaveBlockSignature signature; }; -struct SaveBuffer -{ +struct SaveBuffer { // Each of the four save files has two copies. If one is bad, the other is used as a backup. struct SaveFile files[NUM_SAVE_FILES][2]; // The main menu data has two copies. If one is bad, the other is used as a backup. diff --git a/src/game/screen_transition.c b/src/game/screen_transition.c index 190a436d..b9fa99b5 100644 --- a/src/game/screen_transition.c +++ b/src/game/screen_transition.c @@ -239,6 +239,9 @@ s32 render_screen_transition(s8 fadeTimer, s8 transType, u8 transTime, struct Wa return render_textured_transition(fadeTimer, transTime, transData, TEX_TRANS_BOWSER, TRANS_TYPE_MIRROR); break; } +#ifdef AVOID_UB + return 0; +#endif } Gfx *render_cannon_circle_base(void) { diff --git a/src/game/screen_transition.h b/src/game/screen_transition.h index 70b3c21a..43fa0510 100644 --- a/src/game/screen_transition.h +++ b/src/game/screen_transition.h @@ -7,16 +7,14 @@ #include "macros.h" #include "types.h" -enum TextureTransitionID -{ +enum TextureTransitionID { TEX_TRANS_STAR, TEX_TRANS_CIRCLE, TEX_TRANS_MARIO, TEX_TRANS_BOWSER }; -enum TextureTransitionType -{ +enum TextureTransitionType { TRANS_TYPE_MIRROR, TRANS_TYPE_CLAMP }; diff --git a/src/game/shadow.c b/src/game/shadow.c index e8605075..5856272d 100644 --- a/src/game/shadow.c +++ b/src/game/shadow.c @@ -187,6 +187,9 @@ f32 get_water_level_below_shadow(struct Shadow *s) { } //! @bug Missing return statement. This compiles to return `waterLevel` //! incidentally. +#ifdef AVOID_UB + return waterLevel; +#endif } /** @@ -208,7 +211,7 @@ s8 init_shadow(struct Shadow *s, f32 xPos, f32 yPos, f32 zPos, s16 shadowScale, s->floorHeight = find_floor_height_and_data(s->parentX, s->parentY, s->parentZ, &floorGeometry); - if (gEnvironmentRegions != 0) { + if (gEnvironmentRegions != NULL) { waterLevel = get_water_level_below_shadow(s); } if (gShadowAboveWaterOrLava) { @@ -306,8 +309,8 @@ void make_shadow_vertex_at_xyz(Vtx *vertices, s8 index, f32 relX, f32 relY, f32 vtxY += 5; vtxZ += 5; } - make_vertex(vertices, index, vtxX, vtxY, vtxZ, textureX << 5, textureY << 5, 255, 255, 255, - alpha // shadows are black + make_vertex( // shadows are black + vertices, index, vtxX, vtxY, vtxZ, textureX << 5, textureY << 5, 255, 255, 255, alpha ); } diff --git a/src/game/shadow.h b/src/game/shadow.h index 36b3ef06..d527260a 100644 --- a/src/game/shadow.h +++ b/src/game/shadow.h @@ -8,8 +8,7 @@ * Shadow types. Shadows are circles, squares, or hardcoded rectangles, and * can be composed of either 4 or 9 vertices. */ -enum ShadowType -{ +enum ShadowType { SHADOW_CIRCLE_9_VERTS = 0, SHADOW_CIRCLE_4_VERTS = 1, SHADOW_CIRCLE_4_VERTS_FLAT_UNUSED = 2, diff --git a/src/game/skybox.c b/src/game/skybox.c index 1cf58f5c..055d1ce9 100644 --- a/src/game/skybox.c +++ b/src/game/skybox.c @@ -302,8 +302,9 @@ Gfx *create_skybox_facing_camera(s8 player, s8 background, f32 fov, f32 cameraFaceZ = focZ - posZ; s8 colorIndex = 1; - // If the first star is collected in JRB, make the sky darker and slightly green - if (background == 8 && !(save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_JRB - 1) & 1)) { + // If the "Plunder in the Sunken Ship" star in JRB is collected, make the sky darker and slightly green + if (background == 8 + && !(save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(COURSE_JRB)) & (1 << 0))) { colorIndex = 0; } diff --git a/src/game/sound_init.c b/src/game/sound_init.c index 49122920..c4bad21c 100644 --- a/src/game/sound_init.c +++ b/src/game/sound_init.c @@ -23,13 +23,15 @@ static OSMesgQueue sSoundMesgQueue; static OSMesg sSoundMesgBuf[1]; static struct VblankHandler sSoundVblankHandler; -static u8 D_8032C6C0 = 0; -static u8 D_8032C6C4 = 0; +// Only written to, never read. +static u8 sMusicVolume = 0; + +static u8 sBgMusicDisabled = FALSE; static u16 sCurrentMusic = MUSIC_NONE; static u16 sCurrentShellMusic = MUSIC_NONE; static u16 sCurrentCapMusic = MUSIC_NONE; static u8 sPlayingInfiniteStairs = FALSE; -static u8 unused8032C6D8[16] = { 0 }; +UNUSED static u8 unused8032C6D8[16] = { 0 }; static s16 sSoundMenuModeToSoundMode[] = { SOUND_MODE_STEREO, SOUND_MODE_MONO, SOUND_MODE_HEADSET }; // Only the 20th array element is used. static u32 sMenuSoundsExtra[] = { @@ -78,7 +80,7 @@ void play_menu_sounds_extra(s32 a, void *b); * Called from threads: thread5_game_loop */ void reset_volume(void) { - D_8032C6C0 = 0; + sMusicVolume = 0; } /** @@ -93,7 +95,7 @@ void lower_background_noise(s32 a) { seq_player_lower_volume(SEQ_PLAYER_LEVEL, 60, 40); break; } - D_8032C6C0 |= a; + sMusicVolume |= a; } /** @@ -108,15 +110,15 @@ void raise_background_noise(s32 a) { seq_player_unlower_volume(SEQ_PLAYER_LEVEL, 60); break; } - D_8032C6C0 &= ~a; + sMusicVolume &= ~a; } /** * Called from threads: thread5_game_loop */ void disable_background_sound(void) { - if (D_8032C6C4 == 0) { - D_8032C6C4 = 1; + if (sBgMusicDisabled == FALSE) { + sBgMusicDisabled = TRUE; sound_banks_disable(SEQ_PLAYER_SFX, SOUND_BANKS_BACKGROUND); } } @@ -125,8 +127,8 @@ void disable_background_sound(void) { * Called from threads: thread5_game_loop */ void enable_background_sound(void) { - if (D_8032C6C4 == 1) { - D_8032C6C4 = 0; + if (sBgMusicDisabled == TRUE) { + sBgMusicDisabled = FALSE; sound_banks_enable(SEQ_PLAYER_SFX, SOUND_BANKS_BACKGROUND); } } @@ -169,7 +171,7 @@ void play_menu_sounds(s16 soundMenuFlags) { if (soundMenuFlags & 0x100) { play_menu_sounds_extra(20, NULL); } -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (soundMenuFlags & SOUND_MENU_FLAG_LETGOMARIOFACE) { queue_rumble_data(10, 60); } @@ -347,11 +349,7 @@ void thread4_sound(UNUSED void *arg) { if (gResetTimer < 25) { struct SPTask *spTask; profiler_log_thread4_time(); -#ifdef VERSION_SH - spTask = func_sh_802f5a80(); // The function was probably just moved to a different file. Don't kill me. -#else spTask = create_next_audio_frame_task(); -#endif if (spTask != NULL) { dispatch_audio_sptask(spTask); } diff --git a/src/game/spawn_object.c b/src/game/spawn_object.c index b670751b..4cc1636b 100644 --- a/src/game/spawn_object.c +++ b/src/game/spawn_object.c @@ -163,7 +163,7 @@ void clear_object_lists(struct ObjectNode *objLists) { * This function looks broken, but it appears to attempt to delete the leaf * graph nodes under obj and obj's siblings. */ -static void unused_delete_leaf_nodes(struct Object *obj) { +UNUSED static void unused_delete_leaf_nodes(struct Object *obj) { struct Object *children; struct Object *sibling; struct Object *obj0 = obj; diff --git a/src/game/spawn_sound.c b/src/game/spawn_sound.c index a59767d6..abca0d81 100644 --- a/src/game/spawn_sound.c +++ b/src/game/spawn_sound.c @@ -68,14 +68,14 @@ void cur_obj_play_sound_1(s32 soundMagic) { void cur_obj_play_sound_2(s32 soundMagic) { if (gCurrentObject->header.gfx.node.flags & GRAPH_RENDER_ACTIVE) { play_sound(soundMagic, gCurrentObject->header.gfx.cameraToObject); -#ifdef VERSION_SH +#if ENABLE_RUMBLE if (soundMagic == SOUND_OBJ_BOWSER_WALK) { queue_rumble_data(3, 60); } if (soundMagic == SOUND_OBJ_POUNDING_LOUD) { queue_rumble_data(3, 60); } - if (soundMagic == SOUND_OBJ_WHOMP_LOWPRIO) { + if (soundMagic == SOUND_OBJ_WHOMP) { queue_rumble_data(5, 80); } #endif @@ -93,8 +93,7 @@ void cur_obj_play_sound_2(s32 soundMagic) { * Technically, these functions are only educated guesses. Trust these * interpretations at your own discretion. */ -s32 calc_dist_to_volume_range_1(f32 distance) // range from 60-124 -{ +s32 calc_dist_to_volume_range_1(f32 distance) { // range from 60-124 s32 volume; if (distance < 500.0f) { @@ -108,8 +107,7 @@ s32 calc_dist_to_volume_range_1(f32 distance) // range from 60-124 return volume; } -s32 calc_dist_to_volume_range_2(f32 distance) // range from 79.2-143.2 -{ +s32 calc_dist_to_volume_range_2(f32 distance) { // range from 79.2-143.2 s32 volume; if (distance < 1300.0f) { diff --git a/src/game/spawn_sound.h b/src/game/spawn_sound.h index c00a13be..b4652978 100644 --- a/src/game/spawn_sound.h +++ b/src/game/spawn_sound.h @@ -3,8 +3,7 @@ #include -struct SoundState -{ +struct SoundState { s16 playSound; // if this is 1, the info below will // be used to determine the sound behavior // for the object. if 0, this is skipped. diff --git a/src/goddard/debug_utils.c b/src/goddard/debug_utils.c index 3bd2d2fd..08783004 100644 --- a/src/goddard/debug_utils.c +++ b/src/goddard/debug_utils.c @@ -220,7 +220,7 @@ void remove_all_timers(void) { for (i = 0; i < ARRAY_COUNT(sTimers); i++) { sTimers[i].name = NULL; sTimers[i].total = 0; - sTimers[i].unused0C = 0.0f; + sTimers[i].unused = 0.0f; sTimers[i].scaledTotal = 0.0f; sTimers[i].prevScaledTotal = 0.0f; sTimers[i].gadgetColourNum = sTimerGadgetColours[(u32) i % 7]; @@ -470,7 +470,7 @@ void print_stack_trace(void) { */ void fatal_printf(const char *fmt, ...) { char cur; - UNUSED u8 pad[4]; + UNUSED u8 filler[4]; va_list vl; va_start(vl, fmt); @@ -488,7 +488,11 @@ void fatal_printf(const char *fmt, ...) { gd_printf("%s", va_arg(vl, char *)); break; case 'c': +#ifdef AVOID_UB + gd_printf("%c", (char)va_arg(vl, int)); +#else gd_printf("%c", va_arg(vl, char)); +#endif break; case 'x': gd_printf("%x", va_arg(vl, s32)); @@ -700,7 +704,7 @@ char *sprint_val_withspecifiers(char *str, union PrintVal val, char *specifiers) s32 intPart; // sp38 s32 intPrec; // sp34 s32 fracPrec; // sp30 - UNUSED u8 pad[4]; + UNUSED u8 filler[4]; char cur; // sp2B fracPrec = 6; @@ -836,7 +840,7 @@ struct GdFile *gd_fopen(const char *filename, const char *mode) { struct GdFile *f; // sp74 char *loadedname; // sp70 u32 i; // sp6C - UNUSED u32 pad68; + UNUSED u8 filler[4]; struct UnkBufThing buf; // sp24 u8 *bufbytes; // sp20 u8 *fileposptr; // sp1C @@ -928,7 +932,7 @@ s32 is_newline(char c) { s32 gd_fread_line(char *buf, u32 size, struct GdFile *f) { signed char c; u32 pos = 0; - UNUSED u32 pad1c; + UNUSED u8 filler[4]; do { if (gd_fread(&c, 1, 1, f) == -1) { diff --git a/src/goddard/debug_utils.h b/src/goddard/debug_utils.h index 4c2bcafb..036d0f73 100644 --- a/src/goddard/debug_utils.h +++ b/src/goddard/debug_utils.h @@ -21,7 +21,7 @@ struct GdTimer { /* 0x00 */ s32 start; // in cycles /* 0x04 */ s32 end; // in cycles /* 0x08 */ s32 total; // in cycles - /* 0x0C */ f32 unused0C; + /* 0x0C */ f32 unused; /* 0x10 */ f32 scaledTotal; // total / sTimeScaleFactor (1.0f) Unused function modified value /* 0x14 */ f32 prevScaledTotal; /* 0x18 */ const char *name; @@ -37,7 +37,7 @@ union PrintVal { /* based on fields set in gd_fopen; gd_malloc_perm(84) for size */ struct GdFile { - /* 0x00 */ u8 pad00[4]; + /* 0x00 */ u8 filler1[4]; /* 0x04 */ u32 pos; /* 0x08 */ s8 *stream; /* Known Flags for +0xC field: @@ -45,7 +45,7 @@ struct GdFile { ** 2 : binary mode ** 4 : eof */ /* 0x0C */ u32 flags; - /* 0x10 */ u8 pad10[0x50-0x10]; + /* 0x10 */ u8 filler2[64]; /* 0x50 */ u32 size; }; /* sizeof() = 0x54 */ diff --git a/src/goddard/draw_objects.c b/src/goddard/draw_objects.c index 095f1e1e..85974d50 100644 --- a/src/goddard/draw_objects.c +++ b/src/goddard/draw_objects.c @@ -40,7 +40,7 @@ enum SceneType { * texture S,T coordinates. */ struct BetaVtx { - /* 0x00 */ u8 pad[0x44 - 0]; + /* 0x00 */ u8 filler[68]; /* 0x44 */ f32 s; /* 0x48 */ f32 t; }; @@ -59,7 +59,7 @@ static struct GdColour sClrYellow = { 1.0, 1.0, 0.0 }; // @ 801A80DC static struct GdColour sLightColours[1] = { { 1.0, 1.0, 0.0 } }; // @ 801A80E8 static struct GdColour *sSelectedColour = &sClrRed; // @ 801A80F4 struct ObjCamera *gViewUpdateCamera = NULL; // @ 801A80F8 -static void *sUnref801A80FC = NULL; +UNUSED static void *sUnref801A80FC = NULL; static s32 sUnreadShapeFlag = 0; // @ 801A8100 struct GdColour *sColourPalette[5] = { // @ 801A8104 &sClrWhite, &sClrYellow, &sClrRed, &sClrBlack, &sClrBlack @@ -69,20 +69,20 @@ struct GdColour *sWhiteBlack[2] = { &sClrWhite, &sClrBlack, }; -static Mat4f sUnref801A8120 = { +UNUSED static Mat4f sUnref801A8120 = { { 1.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0 } }; -static Mat4f sUnrefIden801A8160 = { +UNUSED static Mat4f sUnrefIden801A8160 = { { 1.0, 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0, 0.0 }, { 0.0, 0.0, 1.0, 0.0 }, { 0.0, 0.0, 0.0, 1.0 } }; static s32 sLightDlCounter = 1; // @ 801A81A0 -static s32 sUnref801A81A4[4] = { 0 }; +UNUSED static s32 sUnref801A81A4[4] = { 0 }; // bss u8 gUnref_801B9B30[0x88]; struct ObjGroup *gGdLightGroup; // @ 801B9BB8; is this the main light group? only light group? -static u8 sUnref_801B9BBC[0x40]; +UNUSED static u8 sUnref_801B9BBC[0x40]; static enum SceneType sSceneProcessType; // @ 801B9C00 static s32 sUseSelectedColor; // @ 801B9C04 static s16 sPickBuffer[100]; ///< buffer of objects near click @@ -91,12 +91,12 @@ static f32 sPickObjDistance; ///< distance between object position a static struct GdObj *sPickedObject; ///< object selected with cursor /// Various counters and pointers set in update_view() and used in various `draw_XXX` functions static struct { - u32 pad00; // @ 801B9CE0 + u8 filler1[4]; // @ 801B9CE0 struct ObjView *view; // @ 801B9CE4 s32 unreadCounter; // @ 801B9CE8 s32 mtlDlNum; // @ 801B9CEC; name is a big guess s32 shapesDrawn; // @ 801B9CF0 - s32 unused18; // @ 801B9CF4 + s32 unused; // @ 801B9CF4 } sUpdateViewState; static struct ObjLight *sPhongLight; // material light? phong light? static struct GdVec3f sPhongLightPosition; //@ 801B9D00; guess; light source unit position for light @@ -168,7 +168,7 @@ void draw_shape(struct ObjShape *shape, s32 flag, f32 c, f32 d, f32 e, // "sweep f32 i, f32 j, f32 k, // translate shape f32 l, f32 m, f32 n, // rotate x, y, z s32 colorIdx, Mat4f *rotMtx) { - UNUSED u8 unused[8]; + UNUSED u8 filler[8]; struct GdVec3f sp1C; restart_timer("drawshape"); @@ -245,7 +245,7 @@ void draw_shape(struct ObjShape *shape, s32 flag, f32 c, f32 d, f32 e, // "sweep void draw_shape_2d(struct ObjShape *shape, s32 flag, UNUSED f32 c, UNUSED f32 d, UNUSED f32 e, f32 f, f32 g, f32 h, UNUSED f32 i, UNUSED f32 j, UNUSED f32 k, UNUSED f32 l, UNUSED f32 m, UNUSED f32 n, UNUSED s32 color, UNUSED s32 p) { - UNUSED u8 unused[8]; + UNUSED u8 filler[8]; struct GdVec3f sp1C; restart_timer("drawshape2d"); @@ -437,15 +437,14 @@ void draw_face(struct ObjFace *face) { f32 z; // 38 f32 y; // 34 f32 x; // 30 - UNUSED u8 pad[12]; + UNUSED u8 filler[12]; s32 i; // 20; also used to store mtl's gddl number s32 hasTextCoords; // 1c Vtx *gbiVtx; // 18 imin("draw_face"); hasTextCoords = FALSE; - if (sUseSelectedColor == FALSE && face->mtlId >= 0) // -1 == colored face - { + if (sUseSelectedColor == FALSE && face->mtlId >= 0) { // -1 == colored face if (face->mtl != NULL) { if ((i = face->mtl->gddlNumber) != 0) { if (i != sUpdateViewState.mtlDlNum) { @@ -536,7 +535,7 @@ void Unknown801792F0(struct GdObj *obj) { void draw_label(struct ObjLabel *label) { struct GdVec3f position; char strbuf[0x100]; - UNUSED u8 unused[16]; + UNUSED u8 filler[16]; struct ObjValPtr *valptr; union ObjVarVal varval; valptrproc_t valfn = label->valfn; @@ -594,7 +593,7 @@ void draw_label(struct ObjLabel *label) { void draw_net(struct ObjNet *self) { struct ObjNet *net = self; s32 netColor; - UNUSED u8 unused[80]; + UNUSED u8 filler[80]; if (sSceneProcessType == FIND_PICKS) { return; @@ -728,9 +727,9 @@ void world_pos_to_screen_coords(struct GdVec3f *pos, struct ObjCamera *cam, stru * @param input `GdObj` to check position of * @return void */ -void check_grabable_click(struct GdObj *input) { +void check_grabbable_click(struct GdObj *input) { struct GdVec3f objPos; - UNUSED u8 unused[12]; + UNUSED u8 filler[12]; struct GdObj *obj; Mat4f *mtx; @@ -738,7 +737,7 @@ void check_grabable_click(struct GdObj *input) { return; } obj = input; - if (!(obj->drawFlags & OBJ_IS_GRABBALE)) { + if (!(obj->drawFlags & OBJ_IS_GRABBABLE)) { return; } @@ -773,7 +772,7 @@ void check_grabable_click(struct GdObj *input) { * @param lightgrp lights of `ObjView */ void drawscene(enum SceneType process, struct ObjGroup *interactables, struct ObjGroup *lightgrp) { - UNUSED u8 unused[16]; + UNUSED u8 filler[16]; restart_timer("drawscene"); imin("draw_scene()"); @@ -820,7 +819,7 @@ void drawscene(enum SceneType process, struct ObjGroup *interactables, struct Ob restart_timer("drawobj"); imin("process_group"); if (sSceneProcessType == FIND_PICKS) { - apply_to_obj_types_in_group(OBJ_TYPE_ALL, (applyproc_t) check_grabable_click, interactables); + apply_to_obj_types_in_group(OBJ_TYPE_ALL, (applyproc_t) check_grabbable_click, interactables); } else { apply_to_obj_types_in_group(OBJ_TYPE_LIGHTS | OBJ_TYPE_GADGETS | OBJ_TYPE_NETS | OBJ_TYPE_PARTICLES, @@ -869,11 +868,11 @@ void draw_shape_faces(struct ObjShape *shape) { */ void draw_particle(struct GdObj *obj) { struct ObjParticle *ptc = (struct ObjParticle *) obj; - UNUSED u8 unused1[16]; + UNUSED u8 filler1[16]; struct GdColour *white; struct GdColour *black; f32 brightness; - UNUSED u8 unused2[16]; + UNUSED u8 filler2[16]; if (ptc->timeout > 0) { white = sColourPalette[0]; @@ -909,9 +908,9 @@ void draw_particle(struct GdObj *obj) { */ void draw_bone(struct GdObj *obj) { struct ObjBone *bone = (struct ObjBone *) obj; - UNUSED u8 unused1[4]; + UNUSED u8 filler1[4]; s32 colour; - UNUSED u8 unused2[4]; + UNUSED u8 filler2[4]; struct GdVec3f scale; // guess return; @@ -940,14 +939,14 @@ void draw_bone(struct GdObj *obj) { */ void draw_joint(struct GdObj *obj) { struct ObjJoint *joint = (struct ObjJoint *) obj; - UNUSED u8 unused1[4]; + UNUSED u8 filler1[4]; UNUSED f32 sp7C = 70.0f; - UNUSED u8 unused2[4]; + UNUSED u8 filler2[4]; UNUSED s32 sp74 = 1; s32 colour; - UNUSED u8 unused[8]; + UNUSED u8 filler3[8]; struct ObjShape *boneShape; - UNUSED u8 unused3[28]; + UNUSED u8 filler4[28]; if ((boneShape = joint->shapePtr) == NULL) { return; @@ -1341,7 +1340,7 @@ void map_vertices(struct ObjGroup *facegrp, struct ObjGroup *vtxgrp) { */ void unpick_obj(struct GdObj *obj) { struct GdObj *why = obj; - if (why->drawFlags & OBJ_IS_GRABBALE) { + if (why->drawFlags & OBJ_IS_GRABBABLE) { why->drawFlags &= ~(OBJ_PICKED | OBJ_HIGHLIGHTED); } } @@ -1357,10 +1356,10 @@ void unpick_obj(struct GdObj *obj) { */ void find_closest_pickable_obj(struct GdObj *input) { struct GdObj *obj = input; - UNUSED u8 unused[12]; + UNUSED u8 filler[12]; f32 distance; - if (obj->drawFlags & OBJ_IS_GRABBALE) { + if (obj->drawFlags & OBJ_IS_GRABBABLE) { if (obj->index == sPickDataTemp) { if (gViewUpdateCamera != NULL) { distance = d_calc_world_dist_btwn(&gViewUpdateCamera->header, obj); @@ -1412,7 +1411,7 @@ void update_view(struct ObjView *view) { char objTypeAbbr[0x100]; sUpdateViewState.shapesDrawn = 0; - sUpdateViewState.unused18 = 0; + sUpdateViewState.unused = 0; if (!(view->flags & VIEW_UPDATE)) { view->flags &= ~VIEW_WAS_UPDATED; @@ -1517,8 +1516,7 @@ void update_view(struct ObjView *view) { } find_and_drag_picked_object(sUpdateViewState.view->components); - } else // check for any previously picked objects, and turn off? - { + } else { // check for any previously picked objects, and turn off? if (sUpdateViewState.view->pickedObj != NULL) { sUpdateViewState.view->pickedObj->drawFlags &= ~OBJ_PICKED; sUpdateViewState.view->pickedObj->drawFlags &= ~OBJ_HIGHLIGHTED; diff --git a/src/goddard/dynlist_proc.c b/src/goddard/dynlist_proc.c index 4b9f21c4..82ddae28 100644 --- a/src/goddard/dynlist_proc.c +++ b/src/goddard/dynlist_proc.c @@ -159,7 +159,7 @@ void reset_dynlist(void) { * Normally the dynlist specifically sets an object for return. */ struct GdObj *proc_dynlist(struct DynList *dylist) { - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; if (dylist++->cmd != 0xD1D4) { fatal_printf("proc_dynlist() not a valid dyn list"); @@ -416,8 +416,7 @@ static struct DynObjInfo *get_dynobj_info(DynObjName name) { gd_strcat(buf, sDynNameSuffix); foundDynobj = NULL; for (i = 0; i < sLoadedDynObjs; i++) { - if (gd_str_not_equal(sGdDynObjList[i].name, buf) == 0) - { + if (gd_str_not_equal(sGdDynObjList[i].name, buf) == 0) { foundDynobj = &sGdDynObjList[i]; break; } @@ -434,7 +433,7 @@ static struct DynObjInfo *get_dynobj_info(DynObjName name) { * @note Not called */ void reset_dynamic_objs(void) { - UNUSED s32 pad; + UNUSED u8 filler[4]; if (sLoadedDynObjs == 0) { return; @@ -486,7 +485,7 @@ void d_end_net_with_subgroup(DynObjName name) { */ void d_attach_joint_to_net(UNUSED s32 arg0, DynObjName name) { UNUSED struct DynObjInfo *curInfo = sDynListCurInfo; - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; d_makeobj(D_JOINT, name); d_set_type(3); @@ -517,7 +516,7 @@ void d_make_netfromshapeid(DynObjName name) { * the shape is not moved into the dynamic list. */ void d_make_netfromshape_ptrptr(struct ObjShape **shapePtr) { - UNUSED u32 pad; + UNUSED u8 filler[4]; struct ObjNet *net = make_netfromshape(*shapePtr); printf("dMakeNetFromShapePtrPtr\n"); @@ -531,7 +530,7 @@ void d_make_netfromshape_ptrptr(struct ObjShape **shapePtr) { * needed later. */ void add_to_dynobj_list(struct GdObj *newobj, DynObjName name) { - UNUSED u32 pad; + UNUSED u8 filler[4]; char idbuf[0x100]; start_memtracker("dynlist"); @@ -719,9 +718,9 @@ void d_attach(DynObjName name) { * the "attach flags" of the current dynamic object to `flag` */ void d_attach_to(s32 flag, struct GdObj *obj) { - UNUSED u32 pad4C; + UNUSED u8 filler1[4]; struct ObjGroup *attgrp; - UNUSED u32 pad[2]; + UNUSED u8 filler2[8]; UNUSED struct DynObjInfo *curInfo = sDynListCurInfo; struct GdVec3f currObjPos; // transformed into attach offset struct GdVec3f objPos; @@ -843,7 +842,7 @@ void copy_bytes(u8 *src, u8 *dst, s32 num) { * rather than solely byted copied like the other types. */ void alloc_animdata(struct ObjAnimator *animator) { - UNUSED u32 pad5C; + UNUSED u8 filler1[4]; // probably should be three GdVec3fs, not triangle... // vec0 = position; vec1 = scale? rotation?; vec2 = translation struct GdTriangleF tri; //+58; temp float for converting half to f32? @@ -859,7 +858,7 @@ void alloc_animdata(struct ObjAnimator *animator) { void *allocSpace; //+30; allocated animdata space f32 allocMtxScale = 0.1f; //+2C; scale postion/rotation of GD_ANIM_SCALE3S_POS3S_ROT3S data struct AnimMtxVec *curMtxVec; //+28 - UNUSED u32 pad20; + UNUSED u8 filler2[4]; start_memtracker("animdata"); @@ -975,7 +974,7 @@ void chk_shapegen(struct ObjShape *shape) { struct ObjGroup *shapeMtls; // sp50 struct ObjGroup *shapeFaces; // sp4C struct ObjGroup *shapeVtx; // sp48 - UNUSED u32 pad44; + UNUSED u8 filler[4]; struct ObjGroup *madeFaces; // sp40 struct ObjGroup *madeVtx; // sp3C u32 i; // sp38 @@ -990,8 +989,7 @@ void chk_shapegen(struct ObjShape *shape) { shapeVtx = shape->vtxGroup; if (shapeVtx != NULL && shapeFaces != NULL) { - if ((shapeVtx->linkType & 1) && (shapeFaces->linkType & 1)) //? needs the double if - { + if ((shapeVtx->linkType & 1) && (shapeFaces->linkType & 1)) { //? needs the double if // These ListNodes point to special, compressed data structures vtxdata = (struct GdVtxData *) shapeVtx->firstMember->obj; facedata = (struct GdFaceData *) shapeFaces->firstMember->obj; @@ -1082,7 +1080,7 @@ void chk_shapegen(struct ObjShape *shape) { */ void d_set_nodegroup(DynObjName name) { struct DynObjInfo *info; // sp2C - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; if (sDynListCurObj == NULL) { fatal_printf("proc_dynlist(): No current object"); @@ -1148,7 +1146,7 @@ void d_set_matgroup(DynObjName name) { * ST coordinates. */ void d_set_texture_st(UNUSED f32 s, UNUSED f32 t) { - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; if (sDynListCurObj == NULL) { fatal_printf("proc_dynlist(): No current object"); @@ -1259,7 +1257,7 @@ void d_map_vertices(DynObjName name) { */ void d_set_planegroup(DynObjName name) { struct DynObjInfo *info; - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; if (sDynListCurObj == NULL) { fatal_printf("proc_dynlist(): No current object"); @@ -1400,7 +1398,7 @@ void d_start_group(DynObjName name) { * and this call. */ void d_end_group(DynObjName name) { - UNUSED u32 pad; + UNUSED u8 filler[4]; struct DynObjInfo *info = get_dynobj_info(name); struct ObjGroup *dynGrp; s32 i; @@ -1421,7 +1419,7 @@ void d_end_group(DynObjName name) { * Add the current dynamic object to the dynamic `ObjGroup` `name`. */ void d_addto_group(DynObjName name) { - UNUSED u32 pad; + UNUSED u8 filler[4]; struct DynObjInfo *info = get_dynobj_info(name); struct ObjGroup *targetGrp; @@ -1448,9 +1446,9 @@ void d_use_integer_names(s32 isIntBool) { * to `(x, y, z)`. */ void d_set_init_pos(f32 x, f32 y, f32 z) { - UNUSED u32 pad2c[3]; + UNUSED u8 filler1[12]; struct GdObj *dynobj = sDynListCurObj; // sp28 - UNUSED u32 pad[1]; + UNUSED u8 filler2[4]; if (sDynListCurObj == NULL) { fatal_printf("proc_dynlist(): No current object"); @@ -1907,7 +1905,7 @@ void d_set_att_offset(const struct GdVec3f *off) { */ void d_set_att_to_offset(UNUSED u32 a) { struct GdObj *dynobj; // sp3c - UNUSED u8 pad[24]; + UNUSED u8 filler[24]; if (sDynListCurObj == NULL) { fatal_printf("proc_dynlist(): No current object"); @@ -2246,7 +2244,7 @@ void d_set_scale(f32 x, f32 y, f32 z) { */ void d_set_rotation(f32 x, f32 y, f32 z) { struct GdObj *dynobj; // sp2C - UNUSED u32 pad; + UNUSED u8 filler[4]; if (sDynListCurObj == NULL) { fatal_printf("proc_dynlist(): No current object"); diff --git a/src/goddard/gd_main.c b/src/goddard/gd_main.c index e515b328..77f7c0d5 100644 --- a/src/goddard/gd_main.c +++ b/src/goddard/gd_main.c @@ -14,11 +14,11 @@ // data s32 gGdMoveScene = TRUE; // @ 801A8050 -static s32 sUnref801A8054 = TRUE; +UNUSED static s32 sUnref801A8054 = TRUE; f32 D_801A8058 = -600.0f; s32 gGdUseVtxNormal = TRUE; // @ 801A805C; instead of face normals -static s32 sUnrefScnWidth = 320; -static s32 sUnrefScnHeight = 240; +UNUSED static s32 sUnrefScnWidth = 320; +UNUSED static s32 sUnrefScnHeight = 240; // bss struct GdControl gGdCtrl; // @ 801B9920; processed controller info @@ -28,7 +28,7 @@ struct GdControl gGdCtrlPrev; // @ 801B9A18; previous frame's controller info * Unused main function possibly from when this was a standalone demo */ u32 __main__(void) { - UNUSED u32 pad1C; + UNUSED u8 filler[4]; gd_printf("%x, %x\n", (u32) (uintptr_t) &D_801A8058, (u32) (uintptr_t) &gGdMoveScene); imin("main"); diff --git a/src/goddard/gd_main.h b/src/goddard/gd_main.h index 2fa0c3ec..58226ad3 100644 --- a/src/goddard/gd_main.h +++ b/src/goddard/gd_main.h @@ -23,7 +23,7 @@ // structs struct GdControl { // gGdCtrl /* 0x00 */ s32 unk00; // set but never used - /* 0x04 */ u8 pad04[4]; + /* 0x04 */ u8 filler1[4]; /* 0x08 */ s32 dleft; // Dpad-left (mask) /* 0x0C */ s32 dright; // Dpad-right (mask) /* 0x10 */ s32 dup; // Dpad-up (mask) @@ -37,22 +37,22 @@ struct GdControl { // gGdCtrl /* 0x30 */ void * unk30; // null-checked ptr? symbol not deref-ed in extant code? /* 0x34 */ s32 btnA; // bool A button /* 0x38 */ s32 btnB; // bool B button - /* 0x3C */ u8 pad3C[0x44-0x3C]; + /* 0x3C */ u8 filler2[8]; /* 0x44 */ s32 trgL; // bool L trigger pressed /* 0x48 */ s32 trgR; // bool R trigger pressed /* 0x4C */ s32 unk4C; /* 0x50 */ s32 unk50; /* 0x54 */ s32 newStartPress; // toggle bit? start pressed? - /* 0x58 */ u8 pad58[0x7C-0x58]; + /* 0x58 */ u8 filler3[36]; /* 0x7C */ f32 stickXf; /* 0x80 */ f32 stickYf; - /* 0x84 */ u8 pad84[4]; + /* 0x84 */ u8 filler4[4]; /* 0x88 */ f32 unk88; // set but never used - /* 0x8C */ u8 pad8c[0xA0-0x8C]; + /* 0x8C */ u8 filler5[20]; /* 0xA0 */ f32 unkA0; // set but never used - /* 0xA4 */ u8 padA4[0xAC-0xA4]; + /* 0xA4 */ u8 filler6[8]; /* 0xAC */ f32 unkAC; - /* 0xB0 */ u8 padB0[0xB8-0xB0]; + /* 0xB0 */ u8 filler7[8]; /* 0xB8 */ s32 dragStartX; // cursor x position when there was a new (A) press? /* 0xBC */ s32 dragStartY; // cursor y position when there was a new (A) press? /* 0xC0 */ s32 stickDeltaX; @@ -70,9 +70,9 @@ struct GdControl { // gGdCtrl /* b04 */ u8 unkD8b04 : 1; /* b02 */ u8 AbtnPressWait : 1; // bool 10 frames between (A) presses (cursor cool down?) /* 0xDC */ u32 dragStartFrame; // first frame of new a press - /* 0xE0 */ u8 padE0[0xE8-0xE0]; + /* 0xE0 */ u8 filler8[8]; /* 0xE8 */ u32 currFrame; // frame count? - /* 0xEC */ u8 padEC[0xF0-0xEC]; + /* 0xEC */ u8 filler9[4]; /* 0xF0 */ struct GdControl *prevFrame; // previous frame data }; diff --git a/src/goddard/gd_math.c b/src/goddard/gd_math.c index bc155f6c..baf43dd8 100644 --- a/src/goddard/gd_math.c +++ b/src/goddard/gd_math.c @@ -397,8 +397,7 @@ void gd_inverse_mat4f(Mat4f *src, Mat4f *dst) { gd_adjunct_mat4f(src, dst); determinant = gd_mat4f_det(dst); - if (ABS(determinant) < 1e-5) //? 1e-5f - { + if (ABS(determinant) < 1e-5) { //? 1e-5f fatal_print("Non-singular matrix, no inverse!\n"); } @@ -602,7 +601,7 @@ void UNUSED gd_quat_rotation(f32 quat[4], UNUSED s32 unused, f32 c, f32 s, s32 i s32 j; s32 k; f32 quatVal; - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; if ((j = i + 1) >= 4) { j = 1; @@ -876,7 +875,7 @@ void gd_mult_mat4f(const Mat4f *mA, const Mat4f *mB, Mat4f *dst) { * Printed the prefix at some point, as shown by how the function is used. */ void gd_print_vec(UNUSED const char *prefix, const struct GdVec3f *vec) { - UNUSED u8 pad[8]; + UNUSED u8 filler[8]; printf("%f,%f,%f\n", vec->x, vec->y, vec->z); printf("\n"); @@ -888,7 +887,7 @@ void gd_print_vec(UNUSED const char *prefix, const struct GdVec3f *vec) { * Printed a prefix at some point, as shone by how the function is used. */ void gd_print_bounding_box(UNUSED const char *prefix, UNUSED const struct GdBoundingBox *p) { - UNUSED u8 pad[8]; + UNUSED u8 filler[8]; printf("Min X = %f, Max X = %f \n", p->minX, p->maxX); printf("Min Y = %f, Max Y = %f \n", p->minY, p->maxY); diff --git a/src/goddard/gd_types.h b/src/goddard/gd_types.h index a0213d44..cff1fff6 100644 --- a/src/goddard/gd_types.h +++ b/src/goddard/gd_types.h @@ -4,8 +4,7 @@ #include /* Vector Types */ -struct GdVec3f -{ +struct GdVec3f { f32 x, y, z; }; @@ -78,11 +77,11 @@ enum ObjTypeFlag { typedef void (*drawmethod_t)(void *); /// Flags for the drawFlags field of an GdObj enum ObjDrawingFlags { - OBJ_DRAW_UNK01 = 0x01, - OBJ_INVISIBLE = 0x02, ///< This `GdObj` shouldn't be drawn when updating a scene - OBJ_PICKED = 0x04, ///< This `GdObj` is held by the cursor - OBJ_IS_GRABBALE = 0x08, ///< This `GdObj` can be grabbed/picked by the cursor - OBJ_HIGHLIGHTED = 0x10 + OBJ_DRAW_UNK01 = 0x01, + OBJ_INVISIBLE = 0x02, ///< This `GdObj` shouldn't be drawn when updating a scene + OBJ_PICKED = 0x04, ///< This `GdObj` is held by the cursor + OBJ_IS_GRABBABLE = 0x08, ///< This `GdObj` can be grabbed/picked by the cursor + OBJ_HIGHLIGHTED = 0x10 }; /** @@ -160,9 +159,9 @@ struct ObjBone { /* 0x020 */ struct ObjBone *prev; // maybe, based on make_bone /* 0x024 */ struct ObjBone *next; // maybe, based on make_bone /* 0x028 */ struct GdVec3f unk28; // "rotation"?? from dead code in draw_bone - /* 0x034 */ u8 pad34[0x40-0x34]; + /* 0x034 */ u8 filler1[12]; /* 0x040 */ struct GdVec3f unk40; - /* 0x04C */ u8 pad4C[0x58-0x4C]; + /* 0x04C */ u8 filler2[12]; /* 0x058 */ struct GdVec3f unk58; // orientation? /* 0x064 */ struct GdVec3f unk64; /* 0x070 */ Mat4f mat70; @@ -178,7 +177,7 @@ struct ObjBone { /* 0x110 */ f32 spring; /* 0x114 */ f32 unk114; /* 0x118 */ f32 unk118; - /* 0x11C */ u8 pad11C[0x124-0x11C]; + /* 0x11C */ u8 filler3[8]; }; /* sizeof = 0x124 */ struct ObjJoint { @@ -192,7 +191,7 @@ struct ObjJoint { /* 0x03C */ struct GdVec3f unk3C; // relative position? /* 0x048 */ struct GdVec3f unk48; /* 0x054 */ struct GdVec3f initPos; // attached offset? (with +200 as well) - /* 0x060 */ u8 pad60[0x6C-0x60]; + /* 0x060 */ u8 filler1[12]; /* 0x06C */ struct GdVec3f unk6C; // initial rotation vec /* 0x078 */ struct GdVec3f velocity; /* 0x084 */ struct GdVec3f unk84; @@ -202,27 +201,27 @@ struct ObjJoint { /* 0x0B4 */ struct GdVec3f unkB4; /* 0x0C0 */ struct GdVec3f shapeOffset; /* 0x0CC */ struct GdVec3f unkCC; - /* 0x0D8 */ u8 padD8[4]; + /* 0x0D8 */ u8 filler2[4]; /* 0x0DC */ struct GdVec3f friction; /* 0x0E8 */ Mat4f matE8; //matrix4x4 /* 0x128 */ Mat4f mat128; // "rot matrix" /* 0x168 */ Mat4f mat168; // "id matrix" /* 0x1A8 */ struct GdVec3f unk1A8; /* 0x1B4 */ s32 id; - /* 0x1B8 */ u8 pad1B8[4]; + /* 0x1B8 */ u8 filler3[4]; /* 0x1BC */ s32 flags; // "flags" - 0x2000 = grabbed /* 0x1C0 */ s32 unk1C0; /* 0x1C4 */ struct ObjGroup *unk1C4; // bone group? /* 0x1C8 */ s32 colourNum; /* 0x1CC */ s32 type; // 0 = normal joint, 5 = grabbable joint. seems to be set, but never used /* 0x1D0 */ struct ObjAnimator *rootAnimator; // root animator? used by eye_joint_update_func - /* 0x1D4 */ u8 pad1D4[0x1f4-0x1d4]; + /* 0x1D4 */ u8 filler4[32]; /* 0x1F4 */ struct ObjGroup *weightGrp; //Group of ObjWeights, only? skin weights? /* 0x1F8 */ struct ObjGroup *attachedObjsGrp; //attach object group /* 0x1FC */ s32 attachFlags; //d_attach_to arg 0; "AttFlag" /* 0x200 */ struct GdVec3f attachOffset; /* 0x20C */ struct GdObj *attachedToObj; // object that this object is attached to - /* 0x210 */ u8 pad210[0x228-0x210]; + /* 0x210 */ u8 filler5[24]; /* 0x228 */ f32 unk228; }; /* sizeof = 0x22C */ @@ -232,30 +231,30 @@ struct ObjJoint { struct ObjParticle { /* 0x00 */ struct GdObj header; - /* 0x14 */ u8 pad14[0x1C-0x14]; + /* 0x14 */ u8 filler1[8]; /* 0x1C */ struct ObjShape *shapePtr; // looks like a shape... /* 0x20 */ struct GdVec3f pos; // some kind of position - relative? world? - /* 0x2C */ u8 pad2C[0x30-0x2C]; + /* 0x2C */ u8 filler2[4]; /* 0x30 */ f32 unk30; - /* 0x34 */ u8 pad34[0x38-0x34]; + /* 0x34 */ u8 filler3[4]; /* 0x38 */ struct GdVec3f unk38; /* 0x44 */ f32 unk44; //not vec? /* 0x48 */ f32 unk48; //not vec? - /* 0x4C */ u8 pad4C[0x50-0x4C]; + /* 0x4C */ u8 filler4[4]; /* 0x50 */ s32 id; /* 0x54 */ u32 flags; // "dflags"? /* 0x58 */ s32 colourNum; /* 0x5C */ s32 timeout; // when this reaches zero, the particle disappears /* 0x60 */ s32 unk60; //type? /* 0x64 */ s32 unk64; //type? (1 = has 50 sub-particles, 2,3 = has 30 sub-particles - /* 0x68 */ u8 pad68[0x6C-0x68]; + /* 0x68 */ u8 filler5[4]; /* 0x6C */ struct ObjGroup *subParticlesGrp; // group of other Particles ? - /* 0x70 */ u8 pad70[4]; + /* 0x70 */ u8 filler6[4]; /* 0x74 */ s32 unk74; /* 0x78 */ u8 unk78[4]; /* 0x7C */ struct ObjAnimator *unk7C; // guessing on type; doesn't seem to be used in final code /* 0x80 */ struct ObjLight *unk80; // could be a Net or Light; not seen as non-null in running code - /* 0x84 */ u8 pad84[0xB0-0x84]; + /* 0x84 */ u8 filler7[44]; /* 0xB0 */ s32 unkB0; //state? /* 0xB4 */ struct ObjGroup *attachedObjsGrp; // attach group? unused group of particles /* 0xB8 */ s32 attachFlags; //attached arg0; "AttFlag" @@ -272,7 +271,7 @@ struct ObjShape { /* 0x1C */ struct ObjGroup *faceGroup; /* face group; based on get_3DG1_shape */ /* 0x20 */ struct ObjGroup *vtxGroup; /* vtx group; based on get_3DG1_shape */ /* 0x24 */ struct ObjGroup *scaledVtxGroup; /* group for type 2 shapenets only ? vertices whose scaleFactor is not 1 get put into this group. */ - /* 0x28 */ u8 pad28[4]; + /* 0x28 */ u8 filler1[4]; /* 0x2C */ struct ObjGroup *mtlGroup; /* what does this group do? materials? */ /* 0x30 */ s32 unk30; /* 0x34 */ s32 faceCount; /* face count? based on get_3DG1_shape */ @@ -282,7 +281,7 @@ struct ObjShape { /* 0x44 */ s32 flag; // what are the flag values? only from dynlists? /* 0x48 */ s32 dlNums[2]; // gd dl number for each frame buffer (??) [0, 1] s32 unk50; // frame number (index into dlNums)? - /* 0x54 */ u8 pad54[0x58-0x54]; // part of above array?? + /* 0x54 */ u8 filler2[4]; // part of above array?? /* 0x58 */ f32 alpha; // paramF? opacitiy? something with rendertype /* 0x5C */ char name[0x40]; }; /* sizeof = 0x9C */ @@ -307,7 +306,7 @@ struct ObjNet { /* 0x000 */ struct GdObj header; /* 0x014 */ struct GdVec3f worldPos; // position? d_set_initpos + d_set_world_pos; print_net says world /* 0x020 */ struct GdVec3f initPos; // position? d_set_initpos? attached offset? dynamic? scratch? - /* 0x02C */ u8 pad2c[0x34-0x2C]; + /* 0x02C */ u8 filler1[8]; /* 0x034 */ s32 flags; // "dflags"? /* 0x038 */ u32 id; // some sort of id? from move_net /* 0x03C */ s32 unk3C; // state flags? vertex info flags? @@ -348,7 +347,7 @@ struct ObjNet { /* 0x200 */ struct GdVec3f unk200; /* 0x20C */ struct ObjGroup *unk20C; /* 0x210 */ s32 ctrlType; // has no purpose - /* 0x214 */ u8 pad214[0x21C-0x214]; + /* 0x214 */ u8 filler2[8]; /* 0x21C */ struct ObjGroup *unk21C; }; /* sizeof = 0x220 */ @@ -402,7 +401,7 @@ struct ObjCamera { /* 0x040 */ struct GdVec3f unk40; // relative position related? /* 0x04C */ struct GdVec3f unk4C; /* 0x058 */ f32 unk58; // GdVec3f ? - /* 0x05C */ u8 pad5C[0x4]; + /* 0x05C */ u8 filler[4]; /* 0x060 */ f32 unk60; /* 0x064 */ Mat4f unk64; //matrix4x4 /* 0x0A4 */ f32 unkA4; @@ -429,24 +428,24 @@ enum GdMtlTypes { struct ObjMaterial { /* 0x00 */ struct GdObj header; - /* 0x14 */ u8 pad14[0x1c-0x14]; + /* 0x14 */ u8 filler1[8]; /* 0x1C */ s32 id; /* 0x20 */ char name[8]; /* 0x28 */ s32 type; - /* 0x2C */ u8 pad2C[4]; + /* 0x2C */ u8 filler2[4]; /* 0x30 */ struct GdColour Ka; // ambient color /* 0x3C */ struct GdColour Kd; // diffuse color - /* 0x48 */ u8 pad48[0x58-0x48]; + /* 0x48 */ u8 filler3[16]; /* 0x58 */ void *texture; //set by d_usetexture; never seems to be non-null though. /* 0x5C */ s32 gddlNumber; }; /* sizeof = 0x60 */ struct ObjWeight { /* 0x00 */ struct GdObj header; - /* 0x14 */ u8 pad14[0x8]; + /* 0x14 */ u8 filler1[8]; /* 0x1C */ s32 vtxId; // ID of vertex that this weight applies to /* 0x20 */ struct GdVec3f vec20; // based on func_80181894? maybe a GdBoundingBox? - /* 0x2C */ u8 pad2C[0x38-0x2c]; + /* 0x2C */ u8 filler2[12]; /* 0x38 */ f32 weightVal; // weight (unit?) /* 0x3C */ struct ObjVertex* vtx; }; /* sizeof = 0x40 */ @@ -468,7 +467,7 @@ struct ObjGadget { /* 0x20 */ s32 unk20; // unused; only ever set to 0 /* 0x24 */ s32 type; /* 0x28 */ f32 sliderPos; // position of the slider (from 0 to 1) - /* 0x2C */ u8 pad2C[4]; + /* 0x2C */ u8 filler1[4]; /* 0x30 */ union ObjVarVal varval; //retype and rename varval30 /* 0x38 */ f32 rangeMin; /* 0x3C */ f32 rangeMax; @@ -476,7 +475,7 @@ struct ObjGadget { /* 0x4C */ struct ObjGroup *valueGrp; // group containing `ObjValPtr`s controlled by this gadget /* 0x50 */ struct ObjShape *shapePtr; /* 0x54 */ struct ObjGroup *unk54; //node group? - /* 0x58 */ u8 pad58[4]; + /* 0x58 */ u8 filler2[4]; /* 0x5C */ s32 colourNum; }; /* sizeof = 0x60 */ @@ -501,7 +500,7 @@ enum GdViewFlags { struct ObjView { /* 0x00 */ struct GdObj header; - /* 0x14 */ u8 pad14[0x8]; + /* 0x14 */ u8 filler1[8]; /* 0x1C */ s32 unk1C; // set as nonexistent return of `setup_view_buffers` /* 0x20 */ s32 id; /* 0x24 */ struct ObjCamera *activeCam; // is this really active? @@ -513,7 +512,7 @@ struct ObjView { /* 0x3C */ struct GdVec3f upperLeft; // position vec? /* 0x48 */ f32 unk48; // what are these? are they another vec? /* 0x4C */ f32 unk4C; - /* 0x50 */ u8 pad50[0x4]; + /* 0x50 */ u8 filler2[4]; /* 0x54 */ struct GdVec3f lowerRight; /* 0x60 */ struct GdVec3f clipping; // z-coordinate of (x: near, y: far) clipping plane? /* 0x6C */ const char *namePtr; @@ -549,14 +548,14 @@ struct ObjAnimator { /* 0x00 */ struct GdObj header; /* 0x14 */ struct ObjGroup* animatedPartsGrp; // group containing objects animated by this animator. I think all of them are joints. /* 0x18 */ struct ObjGroup* animdataGrp; //animation data? a group, but the link points to something weird.. - /* 0x1C */ u8 pad1C[0x4]; + /* 0x1C */ u8 filler1[4]; /* 0x20 */ s32 animSeqNum; // which entry in the AnimDataInfo array to use /* 0x24 */ f32 unk24; /* 0x28 */ f32 frame; // key frame number. This is a float so that it can interpolate between key frames, though I think in practice, it's always a whole number. - /* 0x2C */ u8 pad2C[4]; + /* 0x2C */ u8 filler2[4]; /* 0x30 */ struct ObjGroup *attachedObjsGrp; /* 0x34 */ s32 attachFlags; //attach arg0, not used - /* 0x38 */ u8 pad38[0x44-0x38]; + /* 0x38 */ u8 filler3[12]; /* 0x44 */ struct GdObj* attachedToObj; // object that this object is attached to. Normally another Objanimator? /* 0x48 */ void (*controlFunc) (struct ObjAnimator *); // function that "controls" the animation sequence by choosing the frame number /* 0x4C */ s32 state; //state enum? @@ -616,17 +615,17 @@ enum GdLightFlags { struct ObjLight { /* 0x00 */ struct GdObj header; - /* 0x14 */ u8 pad0[0x8]; + /* 0x14 */ u8 filler1[8]; /* 0x1C */ s32 id; /* 0x20 */ char name[8]; - /* 0x28 */ u8 pad28[4]; + /* 0x28 */ u8 filler2[4]; /* 0x2C */ s32 flags; /* 0x30 */ f32 unk30; // color (5C) = Kd (50) * 30 - /* 0x34 */ u8 pad34[4]; + /* 0x34 */ u8 filler3[4]; /* 0x38 */ f32 unk38; // calculated diffuse theta (in degrees?) /* 0x3C */ s32 unk3C; /* 0x40 */ s32 unk40; - /* 0x44 */ u8 pad3[0x8]; + /* 0x44 */ u8 filler4[8]; /* 0x4C */ s32 unk4C; /* 0x50 */ struct GdColour diffuse; /* 0x5C */ struct GdColour colour; @@ -643,12 +642,12 @@ struct ObjZone { /* 0x14 */ struct GdBoundingBox boundingBox; /* 0x2C */ struct ObjGroup *unk2C; // plane group? /* 0x30 */ struct ObjGroup *unk30; // guess based on Unknown801781DC; might have to change later - /* 0x34 */ u8 pad[4]; + /* 0x34 */ u8 filler[4]; }; /* sizeof = 0x38*/ struct ObjUnk200000 { /* 0x00 */ struct GdObj header; - /* 0x14 */ u8 pad14[0x30-0x14]; + /* 0x14 */ u8 filler[28]; /* 0x30 */ struct ObjVertex *unk30; //not sure; guessing for Unknown801781DC; 30 and 34 could switch with ObjZone /* 0x34 */ struct ObjFace *unk34; //not sure; guessing for Unknown801781DC }; /* sizeof = 0x38*/ diff --git a/src/goddard/joints.c b/src/goddard/joints.c index e48eea27..00178efb 100644 --- a/src/goddard/joints.c +++ b/src/goddard/joints.c @@ -47,13 +47,13 @@ void set_joint_vecs(struct ObjJoint *, f32, f32, f32); * Controls movement of grabbable joints */ void grabbable_joint_update_func(struct ObjJoint *self) { - UNUSED u8 pad78[0xC8 - 0x78]; + UNUSED u8 filler1[80]; Mat4f *attObjMtx; - UNUSED u8 pad70[4]; + UNUSED u8 filler2[4]; struct GdVec3f offset; // difference between current position and initial position - UNUSED u8 pad50[0x10]; + UNUSED u8 filler3[16]; register struct ListNode *att; - UNUSED u8 pad48[0x8]; + UNUSED u8 filler4[8]; struct GdObj *attobj; // The joint acts somewhat like a spring in that the further it is moved @@ -71,8 +71,7 @@ void grabbable_joint_update_func(struct ObjJoint *self) { self->flags |= 0x2000; ; // needed to match } else { - if (gGdCtrl.trgR == FALSE) // R trigger is released - { + if (gGdCtrl.trgR == FALSE) { // R trigger is released // Set velocity so that the joint approaches its initial position self->velocity.x -= offset.x * 0.5; //? 0.5f self->velocity.y -= offset.y * 0.5; //? 0.5f @@ -85,10 +84,8 @@ void grabbable_joint_update_func(struct ObjJoint *self) { // If the joint's velocity has decayed enough and it is very close // to its original position, stop its movement altogether - if (ABS(self->velocity.x) + ABS(self->velocity.y) + ABS(self->velocity.z) < 1.0) - { - if (ABS(offset.x) + ABS(offset.y) + ABS(offset.z) < 1.0) - { + if (ABS(self->velocity.x) + ABS(self->velocity.y) + ABS(self->velocity.z) < 1.0) { + if (ABS(offset.x) + ABS(offset.y) + ABS(offset.z) < 1.0) { self->velocity.x = self->velocity.y = self->velocity.z = 0.0f; self->mat128[3][0] -= offset.x; self->mat128[3][1] -= offset.y; @@ -137,7 +134,7 @@ void eye_joint_update_func(struct ObjJoint *self) { Mat4f *sp5C; struct GdVec3f sp50; struct GdVec3f sp44; - UNUSED u8 pad2c[0x18]; + UNUSED u8 filler[24]; register struct ListNode *att; struct GdObj *attobj; @@ -230,7 +227,7 @@ void set_joint_vecs(struct ObjJoint *j, f32 x, f32 y, f32 z) { struct ObjJoint *make_joint(s32 flags, f32 x, f32 y, f32 z) { struct ObjJoint *j; // sp24 struct ObjJoint *oldhead; - UNUSED u32 pad1C; + UNUSED u8 filler[4]; j = (struct ObjJoint *) make_object(OBJ_TYPE_JOINTS); sJointCount++; @@ -284,7 +281,7 @@ struct ObjJoint *make_grabber_joint(struct ObjShape *shape, s32 flags, f32 x, f3 j->type = 5; j->flags |= flags; j->colourNum = COLOUR_PINK; - j->header.drawFlags |= OBJ_IS_GRABBALE; + j->header.drawFlags |= OBJ_IS_GRABBABLE; j->header.drawFlags |= OBJ_INVISIBLE; j->updateFunc = grabbable_joint_update_func; j->rootAnimator = NULL; @@ -331,7 +328,7 @@ void func_8018F4CC(struct ObjJoint *j) { void func_8018F520(struct ObjBone *b) { struct ObjJoint *joint1; struct ObjJoint *joint2; - UNUSED u32 pad[3]; + UNUSED u8 filler[12]; struct GdVec3f sp90; struct GdVec3f sp84; struct GdVec3f sp78; @@ -397,7 +394,7 @@ void func_8018F520(struct ObjBone *b) { void func_8018F89C(struct ObjBone *b) { struct ObjJoint *spAC; struct ObjJoint *spA8; - UNUSED u8 pad64[0x44]; + UNUSED u8 filler[68]; struct ObjGroup *grp; // sp60 struct ListNode *link; // sp5c Mat4f mtx; // sp1c @@ -494,7 +491,7 @@ void add_joint2bone(struct ObjBone *b, struct ObjJoint *j) { struct ObjBone *make_bone(s32 a0, struct ObjJoint *j1, struct ObjJoint *j2, UNUSED s32 a3) { struct ObjBone *b; // sp34 struct ObjBone *oldhead; - UNUSED u32 pad1C[5]; + UNUSED u8 filler[20]; b = (struct ObjBone *) make_object(OBJ_TYPE_BONES); sBoneCount++; @@ -596,11 +593,11 @@ s32 func_8018FFE8(struct ObjBone **a0, struct ObjJoint **a1, struct ObjJoint *a2 void func_80190168(struct ObjBone *b, UNUSED struct ObjJoint *a1, UNUSED struct ObjJoint *a2, struct GdVec3f *a3) { struct GdVec3f sp7C; - UNUSED u8 pad64[0x7c - 0x64]; + UNUSED u8 filler1[24]; f32 sp60; f32 sp5C; f32 sp58; - UNUSED u8 pad1C[0x58 - 0x1C]; + UNUSED u8 filler2[60]; return; @@ -672,21 +669,20 @@ void func_801903E8(struct ObjJoint *j, struct GdVec3f *a1, f32 x, f32 y, f32 z) } /* 23EBB8 -> 23F184 */ -void func_80190574(s32 a0, struct ObjJoint *a1, struct ObjJoint *a2, f32 x, f32 y, f32 z) // sp278 -{ +void func_80190574(s32 a0, struct ObjJoint *a1, struct ObjJoint *a2, f32 x, f32 y, f32 z) { // sp278 struct ObjJoint *sp274; // = a2? struct ObjJoint *sp270; // mid-point of stack array? struct ObjJoint *sp26C; // jointstackarr[i]? curjoint? - UNUSED u32 pad268; - UNUSED u32 sp264 = 0; - UNUSED u32 sp258[3]; // unused vec? + UNUSED u8 filler1[4]; + UNUSED u32 unused = 0; + UNUSED u8 filler2[12]; // unused vec? struct GdVec3f sp24C; struct GdVec3f sp240; - UNUSED u32 pad238[2]; + UNUSED u8 filler3[8]; s32 sp234; // i? s32 sp230; s32 sp22C = 1; - UNUSED u32 pad228; + UNUSED u8 filler4[4]; s32 sp224; s32 sp220; struct ObjJoint *sp120[0x40]; @@ -788,7 +784,7 @@ void func_801909B4(void) { /* 23F1F0 -> 23F324; not called */ void func_80190A20(void) { struct ObjJoint *j; // sp3c - UNUSED u32 pad38; + UNUSED u8 filler[4]; struct GdVec3f vec; // sp2C struct ObjGroup *grp; struct ListNode *link; @@ -812,16 +808,15 @@ void func_80190A20(void) { } /* 23F324 -> 23F638 */ -void func_80190B54(struct ObjJoint *a0, struct ObjJoint *a1, struct GdVec3f *a2) // b0 -{ +void func_80190B54(struct ObjJoint *a0, struct ObjJoint *a1, struct GdVec3f *a2) { // b0 struct GdVec3f spA4; - UNUSED struct GdVec3f pad98; + UNUSED u8 filler1[12]; struct GdVec3f sp8C; struct GdVec3f sp80; f32 sp7C; f32 sp78; Mat4f sp38; - UNUSED u8 pad1C[0x1C]; + UNUSED u8 filler2[28]; if (a1 != NULL) { spA4.x = a1->unk3C.x; @@ -878,7 +873,7 @@ void func_80190E68(struct GdObj *obj, f32 x, f32 y, f32 z) { struct ObjJoint *sp44; struct GdObj *sp40; struct GdVec3f vec; - UNUSED u32 pad1C[6]; + UNUSED u8 filler[24]; vec.x = x; vec.y = y; @@ -968,7 +963,7 @@ void func_80191220(struct ObjJoint *j) { /* 23FB90 -> 23FBC0 */ void func_801913C0(struct ObjJoint *j) { - UNUSED u32 pad[4]; + UNUSED u8 filler[16]; func_80181894(j); } @@ -1040,7 +1035,7 @@ void reset_joint(struct ObjJoint *j) { /* 23FFF4 -> 2400C4 */ void func_80191824(struct ObjJoint *j) { UNUSED struct ObjNet *sp14; - UNUSED u32 pad00[4]; + UNUSED u8 filler[16]; sp14 = gGdSkinNet->unk1F0; if (j->flags & 0x1) { diff --git a/src/goddard/objects.c b/src/goddard/objects.c index f8504b1a..b1d136cd 100644 --- a/src/goddard/objects.c +++ b/src/goddard/objects.c @@ -23,11 +23,11 @@ // structs struct Unk801B9E68 { /* 0x00 */ s32 count; - /* 0x04 */ u8 pad[0x14]; + /* 0x04 */ u8 filler[20]; }; /* sizeof() = 0x18 */ struct Unk8017F3CC { - /*0x00*/ u8 pad[0x20]; + /*0x00*/ u8 filler[32]; /*0x20*/ struct GdVec3f unk20; }; @@ -434,9 +434,7 @@ void reset_plane(struct ObjPlane *plane) { struct ObjFace *sp4C; f32 sp48; f32 sp44; - UNUSED u32 sp40; - UNUSED u32 sp3C; - UNUSED u32 sp38; + UNUSED u8 filler[12]; s32 i; s32 sp30; register f32 sp28; @@ -513,7 +511,7 @@ void reset_plane(struct ObjPlane *plane) { /* @ 22B60C for 0x94; orig name: func_8017CE3C */ struct ObjPlane *make_plane(s32 inZone, struct ObjFace *a1) { - UNUSED u32 pad1C; + UNUSED u8 filler[4]; struct ObjPlane *newPlane = (struct ObjPlane *) make_object(OBJ_TYPE_PLANES); gGdPlaneCount++; @@ -754,11 +752,9 @@ void format_object_id(char *str, struct GdObj *obj) { struct ObjGroup *make_group(s32 count, ...) { va_list args; s32 i; - UNUSED u32 sp5C; + UNUSED u8 filler1[4]; struct GdObj *curObj; - UNUSED u32 sp54; - UNUSED u32 sp50; - UNUSED u32 sp4C; + UNUSED u8 filler2[12]; struct ObjGroup *newGroup; struct ObjGroup *oldGroupListHead; struct GdObj *vargObj; @@ -818,7 +814,7 @@ struct ObjGroup *make_group(s32 count, ...) { */ void addto_group(struct ObjGroup *group, struct GdObj *obj) { char strbuf[0x20]; - UNUSED u8 pad[0x8]; + UNUSED u8 filler[8]; imin("addto_group"); @@ -1031,7 +1027,7 @@ void menu_cb_reset_positions(void) { * Unused (not called) - does nothing useful */ struct GdObj *func_8017E2F0(struct GdObj *obj, enum ObjTypeFlag type) { - UNUSED u32 sp2C; + UNUSED u8 filler[4]; enum ObjTypeFlag curObjType; struct ListNode *node; @@ -1071,7 +1067,7 @@ s32 apply_to_obj_types_in_group(s32 types, applyproc_t func, struct ObjGroup *gr struct GdObj *linkedObj; enum ObjTypeFlag linkedObjType; applyproc_t objFn; - UNUSED u8 pad2C[0x20]; + UNUSED u8 filler[32]; s32 fnAppliedCount; fnAppliedCount = 0; @@ -1122,9 +1118,9 @@ void func_8017E584(struct ObjNet *a0, struct GdVec3f *a1, struct GdVec3f *a2) { struct GdVec3f sp88; struct GdVec3f sp7C; struct GdVec3f sp70; - UNUSED u8 pad30[0x40]; // unused MyMatrix4x4? f32[4][4] + UNUSED u8 filler1[64]; // unused MyMatrix4x4? f32[4][4] f32 sp2C; - UNUSED u32 sp28; + UNUSED u8 filler2[4]; struct GdVec3f sp1C; sp70.x = a2->x; @@ -1174,12 +1170,10 @@ void func_8017E584(struct ObjNet *a0, struct GdVec3f *a1, struct GdVec3f *a2) { /* @ 22D008 for 0x1B4 */ void func_8017E838(struct ObjNet *a0, struct GdVec3f *a1, struct GdVec3f *a2) { - UNUSED u32 sp84; - UNUSED u32 sp80; - UNUSED u32 sp7C; + UNUSED u8 filler1[12]; struct GdVec3f sp70; struct GdVec3f sp64; - UNUSED u8 pad24[0x40]; + UNUSED u8 filler2[64]; struct GdVec3f sp18; sp64.x = a1->x; @@ -1374,13 +1368,13 @@ s32 gd_plane_point_within(struct GdBoundingBox *box1, struct GdBoundingBox *box2 s32 transform_child_objects_recursive(struct GdObj *obj, struct GdObj *parentObj) { struct ListNode *curLink; struct ObjGroup *curGroup; - UNUSED u32 sp54; + UNUSED u8 filler1[4]; Mat4f *parentUnkMtx; Mat4f *iMtx; Mat4f *unkMtx; Mat4f *rotMtx; Mat4f *rotMtx2; - UNUSED u8 pad20[0x18]; + UNUSED u8 filler2[24]; struct GdVec3f scale; if (parentObj != NULL) { @@ -1428,13 +1422,13 @@ s32 transform_child_objects_recursive(struct GdObj *obj, struct GdObj *parentObj s32 func_8017F210(struct GdObj *a0, struct GdObj *a1) { struct ListNode *sp6C; struct ObjGroup *sp68; - UNUSED u32 sp64; + UNUSED u8 filler1[4]; UNUSED Mat4f *sp60; Mat4f *sp5C; UNUSED Mat4f *sp58; Mat4f *sp54; Mat4f *sp50; - UNUSED u8 pad38[0x18]; + UNUSED u8 filler2[24]; struct GdVec3f sp2C; s32 count = 0; @@ -1483,7 +1477,7 @@ void func_8017F3CC(struct Unk8017F3CC *a0) { /* @ 22DBD4 for 0x20 */ void stub_objects_3(UNUSED f32 a0, UNUSED struct GdObj *a1, UNUSED struct GdObj *a2) { - UNUSED u8 pad[0x30]; + UNUSED u8 filler[48]; } /** @@ -1536,9 +1530,7 @@ void move_animator(struct ObjAnimator *animObj) { s16(*animDataCam)[6]; // camera GdPlaneH[]? struct GdObj *stubObj1 = NULL; // used only for call to stubbed function struct GdObj *stubObj2 = NULL; // used only for call to stubbed function - UNUSED s32 sp50; - UNUSED s32 sp4C; - UNUSED s32 sp48; + UNUSED u8 filler[12]; UNUSED struct GdVec3f unusedVec; s32 currKeyFrame; s32 nextKeyFrame; @@ -1771,17 +1763,15 @@ void move_animator(struct ObjAnimator *animObj) { /* @ 22EDF4 for 0x300; orig name: func_80180624 */ void drag_picked_object(struct GdObj *inputObj) { - UNUSED u32 spE4; - UNUSED u32 spE0; - UNUSED u32 spDC; + UNUSED u8 filler1[12]; struct GdVec3f displacement; struct GdVec3f spC4; struct GdControl *ctrl; Mat4f sp80; Mat4f sp40; - UNUSED u32 pad34[3]; + UNUSED u8 filler2[12]; struct GdObj *obj; - UNUSED u32 pad2C; + UNUSED u8 filler3[4]; f32 dispMag; ctrl = &gGdCtrl; @@ -1852,10 +1842,10 @@ void move_camera(struct ObjCamera *cam) { struct GdVec3f spE0; struct GdVec3f spD4; struct GdVec3f spC8; - UNUSED u8 padBC[0xC8 - 0xBC]; + UNUSED u8 filler1[12]; struct GdVec3f spB0; Mat4f sp70; - UNUSED u8 pad30[0x70 - 0x30]; + UNUSED u8 filler2[64]; Mat4f *sp2C; struct GdControl *ctrl; @@ -1975,7 +1965,7 @@ void move_cameras_in_grp(struct ObjGroup *group) { /* @ 22F7DC for 0x36C*/ void func_8018100C(struct ObjLight *light) { Mat4f mtx; - UNUSED u32 pad1C[3]; + UNUSED u8 filler[12]; if (light->unk40 == 3) { if (light->unk30 > 0.0) { //? 0.0f diff --git a/src/goddard/old_menu.c b/src/goddard/old_menu.c index 7d4751cb..23ce508b 100644 --- a/src/goddard/old_menu.c +++ b/src/goddard/old_menu.c @@ -23,7 +23,7 @@ // bss static char sDefSettingsMenuStr[0x100]; static struct GdVec3f sStaticVec; -static struct GdVec3f unusedVec; +UNUSED static struct GdVec3f unusedVec; static struct ObjGadget *sCurGadgetPtr; // forward declarations @@ -173,7 +173,7 @@ void set_static_gdgt_value(struct ObjValPtr *vp) { /* 23A488 -> 23A4D0 */ static void reset_gadget_default(struct ObjGadget *gdgt) { - UNUSED u8 pad[4]; + UNUSED u8 filler[4]; sCurGadgetPtr = gdgt; apply_to_obj_types_in_group(OBJ_TYPE_VALPTRS, (applyproc_t) set_static_gdgt_value, gdgt->valueGrp); @@ -181,7 +181,7 @@ static void reset_gadget_default(struct ObjGadget *gdgt) { /* 23A4D0 -> 23A784 */ void adjust_gadget(struct ObjGadget *gdgt, s32 a1, s32 a2) { - UNUSED u8 pad[8]; + UNUSED u8 filler[8]; f32 range; struct ObjValPtr *vp; @@ -220,7 +220,7 @@ void adjust_gadget(struct ObjGadget *gdgt, s32 a1, s32 a2) { /* 23A784 -> 23A940; orig name: Unknown8018BFB4 */ void reset_gadget(struct ObjGadget *gdgt) { - UNUSED u8 pad[8]; + UNUSED u8 filler[8]; f32 range; struct ObjValPtr *vp; diff --git a/src/goddard/particles.c b/src/goddard/particles.c index 26b3cb86..2fd83b18 100644 --- a/src/goddard/particles.c +++ b/src/goddard/particles.c @@ -19,7 +19,7 @@ typedef union { struct Connection { struct GdObj header; // this header is never used - u8 filler14[8]; + u8 filler[8]; VtxPtc node1; // first connected vertex or particle VtxPtc node2; // second connected vertex or particle f32 unk24; @@ -27,7 +27,7 @@ struct Connection { }; // data -static void *sUnused801A81D0 = NULL; +UNUSED static void *sUnused801A81D0 = NULL; static s32 D_801A81D4[25] = { /* ID? X Y Z */ 9, 3, 12, -14, 25, 5, 16, -25, 42, 4, 15, -39, 55, @@ -105,7 +105,7 @@ void Unknown80181D14(struct ObjFace *face) { /* 230680 -> 230858 */ void func_80181EB0(struct Connection *cxn) { struct GdVec3f sp34; - UNUSED u8 unused[0x2C]; + UNUSED u8 filler[44]; struct ObjParticle *sp4 = cxn->node1.ptc; struct ObjParticle *sp0 = cxn->node2.ptc; @@ -134,7 +134,7 @@ void func_80181EB0(struct Connection *cxn) { /* @ 230858 -> 230B70 */ void func_80182088(struct Connection *cxn) { struct GdVec3f sp4C; - UNUSED u8 unused[0x24]; + UNUSED u8 filler[36]; f32 sp24; f32 sp20; struct ObjParticle *sp1C; @@ -208,7 +208,7 @@ void func_801823A0(struct ObjNet *net) { /* 230CC0 -> 230DCC */ struct ObjParticle *make_particle(u32 flags, s32 colourNum, f32 x, f32 y, f32 z) { struct ObjParticle *particle = (struct ObjParticle *) make_object(OBJ_TYPE_PARTICLES); - UNUSED u8 unused[8]; + UNUSED u8 filler[8]; particle->pos.x = x; particle->pos.y = y; @@ -317,13 +317,12 @@ void func_80182A08(struct ObjParticle *ptc, struct GdVec3f *b) { /* 231454 -> 231D40; orig name: Unknown80182C84 */ void move_particle(struct ObjParticle *ptc) { f32 sp7C; - UNUSED u8 unused2[12]; + UNUSED u8 filler1[12]; struct GdVec3f sp64; struct ObjParticle *sp60; - UNUSED u8 unused1[4]; + UNUSED u8 filler2[4]; s32 i; - UNUSED u8 unused4[4]; - UNUSED u8 unused5[4]; + UNUSED u8 filler3[8]; struct ObjCamera *sp4C; struct GdVec3f sp40; struct GdVec3f sp34; diff --git a/src/goddard/renderer.c b/src/goddard/renderer.c index e569b6d8..75ff7338 100644 --- a/src/goddard/renderer.c +++ b/src/goddard/renderer.c @@ -2,10 +2,6 @@ #include #include -#if defined(VERSION_JP) || defined(VERSION_US) -#include "prevent_bss_reordering.h" -#endif - #include "debug_utils.h" #include "draw_objects.h" #include "dynlist_proc.h" @@ -66,7 +62,7 @@ struct GdDisplayList { /* GD DL Info */ /*0x40*/ u32 id; // user specified /*0x44*/ u32 number; // count - /*0x48*/ u8 pad48[4]; + /*0x48*/ u8 filler[4]; /*0x4C*/ struct GdDisplayList *parent; // not quite sure? }; /* sizeof = 0x50 */ // accessor macros for gd dl @@ -113,10 +109,10 @@ static u8 D_801BAEA0; static struct ObjGadget *sTimerGadgets[GD_NUM_TIMERS]; // @ 801BAEA8 static u32 D_801BAF28; // RAM addr offset? static s16 sTriangleBuf[13][8]; // [[s16; 8]; 13]? vert indices? -static u32 unref_801bb000[3]; +UNUSED static u32 unref_801bb000[3]; static u8 *sMemBlockPoolBase; // @ 801BB00C static u32 sAllocMemory; // @ 801BB010; malloc-ed bytes -static u32 unref_801bb014; +UNUSED static u32 unref_801bb014; static s32 D_801BB018; static s32 D_801BB01C; static void *sLoadedTextures[0x10]; // texture pointers @@ -136,11 +132,11 @@ static s32 sVertexBufStartIndex; // Vtx start in GD Dl static struct ObjView *sCarSceneView; // @ 801BB0D0 static s32 sUpdateYoshiScene; // @ 801BB0D4; update dl Vtx from ObjVertex? static s32 sUpdateMarioScene; // @ 801BB0D8; update dl Vtx from ObjVertex? -static u32 unref_801bb0dc; +UNUSED static u32 unref_801bb0dc; static s32 sUpdateCarScene; // @ 801BB0E0; guess, not really used -static u32 unref_801bb0e4; +UNUSED static u32 unref_801bb0e4; static struct GdVec3f sTextDrawPos; // position to draw text? only set in one function, never used -static u32 unref_801bb0f8[2]; +UNUSED static u32 unref_801bb0f8[2]; static Mtx sIdnMtx; // @ 801BB100 static Mat4f sInitIdnMat4; // @ 801BB140 static s8 sVtxCvrtNormBuf[3]; // @ 801BB180 @@ -170,21 +166,21 @@ static LookAt D_801BE7D0[3]; #if defined(VERSION_JP) || defined(VERSION_US) static OSMesgQueue D_801BE830; // controller msg queue static OSMesg D_801BE848[10]; -static u32 unref_801be870[16]; +UNUSED static u32 unref_801be870[16]; static OSMesgQueue D_801BE8B0; static OSMesgQueue sGdDMAQueue; // @ 801BE8C8 -static u32 unref_801be8e0[25]; +UNUSED static u32 unref_801be8e0[25]; static OSMesg sGdMesgBuf[1]; // @ 801BE944 -static u32 unref_801be948[13]; +UNUSED static u32 unref_801be948[13]; static OSMesg sGdDMACompleteMsg; // msg buf for D_801BE8B0 queue static OSIoMesg sGdDMAReqMesg; static struct ObjView *D_801BE994; // store if View flag 0x40 set #endif // data -static u32 unref_801a8670 = 0; +UNUSED static u32 unref_801a8670 = 0; static s32 D_801A8674 = 0; -static u32 unref_801a8678 = 0; +UNUSED static u32 unref_801a8678 = 0; static s32 D_801A867C = 0; static s32 D_801A8680 = 0; static f32 sTracked1FrameTime = 0.0f; // @ 801A8684 @@ -199,11 +195,11 @@ static struct GdTimer *D_801A86A4 = NULL; // timer for dlgen, dynamics, or rcp static struct GdTimer *D_801A86A8 = NULL; // timer for dlgen, dynamics, or rcp static struct GdTimer *D_801A86AC = NULL; // timer for dlgen, dynamics, or rcp s32 gGdFrameBufNum = 0; // @ 801A86B0 -static u32 unref_801a86B4 = 0; +UNUSED static u32 unref_801a86B4 = 0; static struct ObjShape *sHandShape = NULL; // @ 801A86B8 static s32 D_801A86BC = 1; static s32 D_801A86C0 = 0; // gd_dl id for something? -static u32 unref_801a86C4 = 10; +UNUSED static u32 unref_801a86C4 = 10; static s32 sMtxParamType = G_MTX_PROJECTION; static struct GdVec3f D_801A86CC = { 1.0f, 1.0f, 1.0f }; static struct ObjView *sActiveView = NULL; // @ 801A86D8 current view? used when drawing dl @@ -214,7 +210,7 @@ static struct ObjView *sMenuView = NULL; // @ 801A86E8 static u32 sItemsInMenu = 0; // @ 801A86EC static s32 sDebugViewsCount = 0; // number of elements in the sDebugViews array static s32 sCurrDebugViewIndex = 0; // @ 801A86F4; timing activate cool down counter? -static u32 unref_801a86F8 = 0; +UNUSED static u32 unref_801a86F8 = 0; static struct GdDisplayList *sCurrentGdDl = NULL; // @ 801A86FC static u32 sGdDlCount = 0; // @ 801A8700 static struct DynListBankInfo sDynLists[] = { // @ 801A8704 @@ -225,7 +221,7 @@ static struct DynListBankInfo sDynLists[] = { // @ 801A8704 }; // textures and display list data -static Gfx gd_texture1_dummy_aligner1[] = { // @ 801A8728 +UNUSED static Gfx gd_texture1_dummy_aligner1[] = { // @ 801A8728 gsSPEndDisplayList(), }; @@ -233,7 +229,7 @@ ALIGNED8 static Texture gd_texture_hand_open[] = { #include "textures/intro_raw/hand_open.rgba16.inc.c" }; -static Gfx gd_texture2_dummy_aligner1[] = { +UNUSED static Gfx gd_texture2_dummy_aligner1[] = { gsSPEndDisplayList() }; @@ -494,7 +490,7 @@ ALIGNED8 static Texture gd_texture_sparkle_4[] = { //! No reference to this texture. Two DL's uses the same previous texture // instead of using this texture. -ALIGNED8 static Texture gd_texture_sparkle_5[] = { +UNUSED ALIGNED8 static Texture gd_texture_sparkle_5[] = { #include "textures/intro_raw/sparkle_5.rgba16.inc.c" }; @@ -649,7 +645,7 @@ static Gfx *gd_silver_sparkle_dl_array[] = { gd_dl_silver_sparkle_4_dup, }; -static Gfx gd_texture3_dummy_aligner1[] = { +UNUSED static Gfx gd_texture3_dummy_aligner1[] = { gsSPEndDisplayList(), }; @@ -694,13 +690,13 @@ static Gfx gd_dl_rdp_init[] = { gsSPEndDisplayList(), }; -static u32 gd_unused_pad1 = 0; +UNUSED static u32 gd_unused_pad1 = 0; float sGdPerspTimer = 1.0; -static u32 gd_unused_pad2 = 0; +UNUSED static u32 gd_unused_pad2 = 0; -static Gfx gd_texture4_dummy_aligner1[] = { +UNUSED static Gfx gd_texture4_dummy_aligner1[] = { gsDPPipeSync(), gsSPEndDisplayList(), }; @@ -717,7 +713,7 @@ static Vtx_t gd_unused_mesh_vertex_group2[] = { {{ 3, -7, 0}, 0, { 0, 0}, { 0xFF, 0x00, 0x00, 0xFF}}, }; -static Gfx gd_dl_unused_mesh[] = { +UNUSED static Gfx gd_dl_unused_mesh[] = { gsDPPipeSync(), gsDPSetRenderMode(G_RM_OPA_SURF, G_RM_OPA_SURF2), gsSPClearGeometryMode(0xFFFFFFFF), @@ -872,14 +868,14 @@ f64 stub_renderer_1(UNUSED f64 x) { /* 249BCC -> 24A19C */ void gd_printf(const char *format, ...) { s32 i; - UNUSED u32 pad158; + UNUSED u8 filler1[4]; char c; char f; - UNUSED u32 pad150; + UNUSED u8 filler2[4]; char buf[0x100]; char *csr = buf; char spec[8]; // specifier string - UNUSED u32 pad40; + UNUSED u8 filler3[4]; union PrintVal val; va_list args; @@ -1053,7 +1049,7 @@ void draw_indexed_dl(s32 dlNum, s32 gfxIdx) { /* 24A598 -> 24A610; orig name: func_8019BDC8 */ void branch_cur_dl_to_num(s32 dlNum) { Gfx *dl; - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; dl = sGdDLArray[dlNum]->gfx; gSPDisplayList(next_gfx(), GD_VIRTUAL_TO_PHYSICAL(dl)); @@ -1152,7 +1148,7 @@ void gd_add_to_heap(void *addr, u32 size) { /* 24AAE0 -> 24AB7C */ void gdm_init(void *blockpool, u32 size) { - UNUSED u32 pad; + UNUSED u8 filler[4]; imin("gdm_init"); // Align downwards? @@ -1172,7 +1168,7 @@ void gdm_init(void *blockpool, u32 size) { * Initializes the Mario head demo */ void gdm_setup(void) { - UNUSED u32 pad; + UNUSED u8 filler[4]; imin("gdm_setup"); sYoshiSceneGrp = NULL; @@ -1213,7 +1209,7 @@ struct ObjView *make_view_withgrp(char *name, struct ObjGroup *grp) { /* 24AD14 -> 24AEB8 */ void gdm_maketestdl(s32 id) { - UNUSED u32 pad[3]; + UNUSED u8 filler[12]; imin("gdm_maketestdl"); switch (id) { @@ -1307,7 +1303,7 @@ s32 gd_sfx_to_play(void) { Gfx *gdm_gettestdl(s32 id) { struct GdObj *dobj; struct GdDisplayList *gddl; - UNUSED u32 pad28[2]; + UNUSED u8 filler[8]; struct GdVec3f vec; start_timer("dlgen"); @@ -1599,7 +1595,7 @@ void gd_dl_set_fill(struct GdColour *colour) { } /* 24CDB4 -> 24CE10; orig name: func_8019E5E4 */ -void gd_dl_set_zbuffer_area(void) { +void gd_dl_set_z_buffer_area(void) { gDPSetDepthImage(next_gfx(), GD_LOWER_24(sActiveView->parent->zbuf)); } @@ -1985,7 +1981,7 @@ void func_801A0038(void) { /* 24E840 -> 24E9BC */ void gd_dl_flush_vertices(void) { - UNUSED u32 pad; + UNUSED u8 filler[4]; s32 i; UNUSED s32 startvtx = sVertexBufStartIndex; @@ -2070,13 +2066,13 @@ void gd_dl_hilite(s32 idx, // material GdDl number; offsets into hilite array struct GdVec3f *arg4, // vector to light source? struct GdColour *colour // light color ) { - UNUSED u32 pad2[24]; + UNUSED u8 filler1[96]; Hilite *hilite; // 4c struct GdVec3f sp40; f32 sp3C; // magnitude of sp40 f32 sp38; f32 sp34; - UNUSED u32 pad[6]; + UNUSED u8 filler2[24]; sp38 = 32.0f; // x scale factor? sp34 = 32.0f; // y scale factor? @@ -2115,7 +2111,7 @@ void gd_dl_hilite(s32 idx, // material GdDl number; offsets into hilite array * Adds some display list commands that perform lighting for a material */ s32 gd_dl_material_lighting(s32 id, struct GdColour *colour, s32 material) { - UNUSED u32 pad60[2]; + UNUSED u8 filler[8]; s32 i; s32 numLights = sNumLights; s32 scaledColours[3]; @@ -2307,7 +2303,7 @@ void Unknown801A1E70(void) { gDPPipeSync(next_gfx()); gDPSetCycleType(next_gfx(), G_CYC_FILL); gDPSetRenderMode(next_gfx(), G_RM_OPA_SURF, G_RM_OPA_SURF2); - gd_dl_set_zbuffer_area(); + gd_dl_set_z_buffer_area(); gDPSetColorImage(next_gfx(), G_IM_FMT_RGBA, G_IM_SIZ_16b, sActiveView->parent->lowerRight.x, GD_LOWER_24(sActiveView->parent->zbuf)); gDPSetFillColor(next_gfx(), GPACK_ZDZ(G_MAXFBZ, 0) << 16 | GPACK_ZDZ(G_MAXFBZ, 0)); @@ -2326,7 +2322,7 @@ void gd_set_one_cycle(void) { /* 250B30 -> 250B44 */ void stub_renderer_3(void) { - UNUSED u32 pad[4]; + UNUSED u8 filler[16]; } /* 250B44 -> 250B58 */ @@ -2519,8 +2515,7 @@ void stub_renderer_4(f32 arg0) { return; // dead code - if (D_801BD768.x * D_801A86CC.x + arg0 * 2.0f > 160.0) - { + if (D_801BD768.x * D_801A86CC.x + arg0 * 2.0f > 160.0) { func_801A3370(D_801BD758.x - D_801BD768.x, -20.0f, 0.0f); D_801BD768.x = D_801BD758.x; } @@ -2718,11 +2713,11 @@ void gd_create_ortho_matrix(f32 l, f32 r, f32 b, f32 t, f32 n, f32 f) { /* 25245C -> 25262C */ void gd_create_perspective_matrix(f32 fovy, f32 aspect, f32 near, f32 far) { u16 perspNorm; - UNUSED u32 unused1; + UNUSED u8 filler1[4]; uintptr_t perspecMtx; uintptr_t rotMtx; - UNUSED u32 unused2; - UNUSED f32 unusedf = 0.0625f; + UNUSED u8 filler2[4]; + UNUSED f32 unused = 0.0625f; sGdPerspTimer += 0.1; guPerspective(&DL_CURRENT_MTX(sCurrentGdDl), &perspNorm, fovy, aspect, near, far, 1.0f); @@ -2837,6 +2832,9 @@ void stub_renderer_6(UNUSED struct GdObj *obj) { */ long defpup(UNUSED const char *menufmt, ...) { //! @bug no return; function was stubbed +#ifdef AVOID_UB + return 0; +#endif } /** @@ -2986,9 +2984,9 @@ void stub_renderer_10(UNUSED u32 arg0) { /* 2530A8 -> 2530C0 */ void stub_draw_label_text(UNUSED char *s) { - UNUSED u32 pad2; + UNUSED u8 filler1[4]; UNUSED char *save = s; - UNUSED u8 pad[0x18]; + UNUSED u8 filler2[24]; } /* 2530C0 -> 2530D8; orig name: func_801A48F0 */ @@ -3104,13 +3102,13 @@ void Unknown801A4F58(void) { r = (s16)(colour >> 11 & 0x1F); g = (s16)(colour >> 6 & 0x1F); b = (s16)(colour >> 1 & 0x1F); - if ((r -= 1) < 0) { + if (--r < 0) { r = 0; } - if ((g -= 1) < 0) { + if (--g < 0) { g = 0; } - if ((b -= 1) < 0) { + if (--b < 0) { b = 0; } @@ -3132,7 +3130,7 @@ void Proc801A5110(struct ObjView *view) { /* 253938 -> 2539DC; orig name: func_801A5168 */ void update_view_and_dl(struct ObjView *view) { - UNUSED u32 pad; + UNUSED u8 filler[4]; s32 prevFlags; // 18 prevFlags = view->flags; @@ -3149,7 +3147,7 @@ void update_view_and_dl(struct ObjView *view) { * Unused - called by __main__ */ void func_801A520C(void) { - UNUSED u32 pad[2]; + UNUSED u8 filler[8]; start_timer("1frame"); start_timer("cpu"); @@ -3199,7 +3197,7 @@ void Unknown801A5344(void) { /* 253BC8 -> 2540E0 */ void gd_init(void) { s32 i; // 34 - UNUSED u32 pad30; + UNUSED u8 filler[4]; s8 *data; // 2c imin("gd_init"); @@ -3434,7 +3432,7 @@ void Unknown801A5D90(struct ObjGroup *arg0) { sp23C = FALSE; for (;;) { - trackerNum += 1; + trackerNum++; mt = get_memtracker_by_index(trackerNum); if (mt->name != NULL) { @@ -3481,11 +3479,11 @@ void Unknown801A5FF8(struct ObjGroup *arg0) { struct ObjView *menuview; // 3c UNUSED struct ObjLabel *label; // 38 struct ObjGroup *menugrp; // 34 - UNUSED u32 pad2C[2]; + UNUSED u8 filler[8]; d_start_group("menug"); sMenuGadgets[0] = d_makeobj(D_GADGET, "menu0"); - d_set_obj_draw_flag(OBJ_IS_GRABBALE); + d_set_obj_draw_flag(OBJ_IS_GRABBABLE); d_set_world_pos(5.0f, 0.0f, 0.0f); d_set_scale(100.0f, 20.0f, 0.0f); d_set_type(6); @@ -3496,7 +3494,7 @@ void Unknown801A5FF8(struct ObjGroup *arg0) { d_add_valptr("menu0", 0x40000, 0, (uintptr_t) NULL); sMenuGadgets[1] = d_makeobj(D_GADGET, "menu1"); - d_set_obj_draw_flag(OBJ_IS_GRABBALE); + d_set_obj_draw_flag(OBJ_IS_GRABBABLE); d_set_world_pos(5.0f, 25.0f, 0.0f); d_set_scale(100.0f, 20.0f, 0.0f); d_set_type(6); @@ -3507,7 +3505,7 @@ void Unknown801A5FF8(struct ObjGroup *arg0) { d_add_valptr("menu1", 0x40000, 0, (uintptr_t) NULL); sMenuGadgets[2] = d_makeobj(D_GADGET, "menu2"); - d_set_obj_draw_flag(OBJ_IS_GRABBALE); + d_set_obj_draw_flag(OBJ_IS_GRABBABLE); d_set_world_pos(5.0f, 50.0f, 0.0f); d_set_scale(100.0f, 20.0f, 0.0f); d_set_type(6); @@ -3599,7 +3597,7 @@ void view_proc_print_timers(struct ObjView *self) { void make_timer_gadgets(void) { struct ObjLabel *timerLabel; struct ObjGroup *timerg; - UNUSED u32 pad6C; + UNUSED u8 filler[4]; struct ObjView *timersview; struct ObjGadget *bar1; struct ObjGadget *bar2; @@ -3613,7 +3611,7 @@ void make_timer_gadgets(void) { d_start_group("timerg"); d_makeobj(D_GADGET, "bar1"); - d_set_obj_draw_flag(OBJ_IS_GRABBALE); + d_set_obj_draw_flag(OBJ_IS_GRABBABLE); d_set_world_pos(20.0f, 5.0f, 0.0f); d_set_scale(50.0f, 5.0f, 0.0f); d_set_type(4); @@ -3624,7 +3622,7 @@ void make_timer_gadgets(void) { bar1->colourNum = COLOUR_WHITE; d_makeobj(D_GADGET, "bar2"); - d_set_obj_draw_flag(OBJ_IS_GRABBALE); + d_set_obj_draw_flag(OBJ_IS_GRABBABLE); d_set_world_pos(70.0f, 5.0f, 0.0f); d_set_scale(50.0f, 5.0f, 0.0f); d_set_type(4); @@ -3635,7 +3633,7 @@ void make_timer_gadgets(void) { bar2->colourNum = COLOUR_PINK; d_makeobj(D_GADGET, "bar3"); - d_set_obj_draw_flag(OBJ_IS_GRABBALE); + d_set_obj_draw_flag(OBJ_IS_GRABBABLE); d_set_world_pos(120.0f, 5.0f, 0.0f); d_set_scale(50.0f, 5.0f, 0.0f); d_set_type(4); @@ -3646,7 +3644,7 @@ void make_timer_gadgets(void) { bar3->colourNum = COLOUR_WHITE; d_makeobj(D_GADGET, "bar4"); - d_set_obj_draw_flag(OBJ_IS_GRABBALE); + d_set_obj_draw_flag(OBJ_IS_GRABBABLE); d_set_world_pos(170.0f, 5.0f, 0.0f); d_set_scale(50.0f, 5.0f, 0.0f); d_set_type(4); @@ -3657,7 +3655,7 @@ void make_timer_gadgets(void) { bar4->colourNum = COLOUR_PINK; d_makeobj(D_GADGET, "bar5"); - d_set_obj_draw_flag(OBJ_IS_GRABBALE); + d_set_obj_draw_flag(OBJ_IS_GRABBABLE); d_set_world_pos(220.0f, 5.0f, 0.0f); d_set_scale(50.0f, 5.0f, 0.0f); d_set_type(4); @@ -3668,7 +3666,7 @@ void make_timer_gadgets(void) { bar5->colourNum = COLOUR_WHITE; d_makeobj(D_GADGET, "bar6"); - d_set_obj_draw_flag(OBJ_IS_GRABBALE); + d_set_obj_draw_flag(OBJ_IS_GRABBABLE); d_set_world_pos(270.0f, 5.0f, 0.0f); d_set_scale(50.0f, 5.0f, 0.0f); d_set_type(4); @@ -3684,7 +3682,7 @@ void make_timer_gadgets(void) { timer = get_timernum(i); d_makeobj(D_GADGET, timerNameBuf); - d_set_obj_draw_flag(OBJ_IS_GRABBALE); + d_set_obj_draw_flag(OBJ_IS_GRABBABLE); d_set_world_pos(20.0f, (f32)((i * 15) + 15), 0.0f); d_set_scale(50.0f, 14.0f, 0); d_set_type(4); @@ -3839,7 +3837,7 @@ void func_801A71CC(struct ObjNet *net) { f32 spAC; f32 spA8; struct GdBoundingBox bbox; - UNUSED u32 pad8C; + UNUSED u8 filler1[4]; struct ObjZone *sp88; register struct ListNode *link; // s0 (84) s32 sp80; // linked planes contained in zone? @@ -3848,13 +3846,13 @@ void func_801A71CC(struct ObjNet *net) { register struct ListNode *link2; // s2 (74) register struct ListNode *link3; // s3 (70) struct GdVec3f sp64; - UNUSED u32 pad60; + UNUSED u8 filler2[4]; struct ObjPlane *plane; // 5c - UNUSED u32 pad58; + UNUSED u8 filler3[4]; struct ObjZone *linkedZone; // 54 - UNUSED u32 pad50; + UNUSED u8 filler4[4]; struct ObjPlane *planeL2; // 4c - UNUSED u32 pad48; + UNUSED u8 filler5[4]; struct ObjPlane *planeL3; // 44 if (net->unk21C == NULL) { @@ -3903,11 +3901,11 @@ void func_801A71CC(struct ObjNet *net) { for (link2 = net->unk1CC->firstMember; link2 != NULL; link2 = link2->next) { planeL2 = (struct ObjPlane *) link2->obj; - sp7C += 1; + sp7C++; if (gd_plane_point_within(&planeL2->boundingBox, &sp88->boundingBox)) { planeL2->unk18 = TRUE; addto_group(sp88->unk2C, &planeL2->header); - sp80 += 1; + sp80++; } } diff --git a/src/goddard/shape_helper.c b/src/goddard/shape_helper.c index a0cd7ff0..ee1dbf63 100644 --- a/src/goddard/shape_helper.c +++ b/src/goddard/shape_helper.c @@ -1,5 +1,9 @@ #include +#if defined(VERSION_JP) || defined(VERSION_US) +#include "prevent_bss_reordering.h" +#endif + #include "debug_utils.h" #include "draw_objects.h" #include "dynlist_proc.h" @@ -16,10 +20,6 @@ #include "shape_helper.h" #include "skin.h" -#ifndef VERSION_EU -#include -#endif - // data struct ObjGroup *gMarioFaceGrp = NULL; // @ 801A82E0; returned by load_dynlist struct ObjShape *gSpotShape = NULL; // Shape used for drawing lights? @@ -35,24 +35,24 @@ static struct GdAnimTransform unusedAnimData1[] = { { {1.0, 1.0, 1.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0} }, }; -static struct AnimDataInfo unusedAnim1 = { ARRAY_COUNT(unusedAnimData1), GD_ANIM_SCALE3F_ROT3F_POS3F_2, unusedAnimData1 }; +UNUSED static struct AnimDataInfo unusedAnim1 = { ARRAY_COUNT(unusedAnimData1), GD_ANIM_SCALE3F_ROT3F_POS3F_2, unusedAnimData1 }; static struct GdAnimTransform unusedAnimData2[] = { { {1.0, 1.0, 1.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0} }, }; -static struct AnimDataInfo unusedAnim2 = { ARRAY_COUNT(unusedAnimData2), GD_ANIM_SCALE3F_ROT3F_POS3F_2, unusedAnimData2 }; +UNUSED static struct AnimDataInfo unusedAnim2 = { ARRAY_COUNT(unusedAnimData2), GD_ANIM_SCALE3F_ROT3F_POS3F_2, unusedAnimData2 }; static struct GdAnimTransform unusedAnimData3[] = { { {1.0, 1.0, 1.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, 0.0} }, }; -static struct AnimDataInfo unusedAnim3 = { ARRAY_COUNT(unusedAnimData3), GD_ANIM_SCALE3F_ROT3F_POS3F_2, unusedAnimData3 }; +UNUSED static struct AnimDataInfo unusedAnim3 = { ARRAY_COUNT(unusedAnimData3), GD_ANIM_SCALE3F_ROT3F_POS3F_2, unusedAnimData3 }; -static s32 sUnref801A838C[6] = { 0 }; +UNUSED static s32 sUnref801A838C[6] = { 0 }; struct ObjShape *sSimpleShape = NULL; -static s32 sUnref801A83A8[31] = { 0 }; -static struct DynList sSimpleDylist[8] = { // unused +UNUSED static s32 sUnref801A83A8[31] = { 0 }; +UNUSED static struct DynList sSimpleDylist[8] = { // unused BeginList(), StartGroup("simpleg"), MakeDynObj(D_NET, "simple"), @@ -67,17 +67,17 @@ static struct DynList sDynlist801A84E4[3] = { SetFlag(0x1800), EndList(), }; -static struct DynList sDynlist801A85B3[5] = { +UNUSED static struct DynList sDynlist801A85B3[5] = { BeginList(), CallList(sDynlist801A84E4), SetFlag(0x400), SetFriction(0.04, 0.01, 0.01), EndList(), }; -static struct DynList sDynlist801A85A4[4] = { +UNUSED static struct DynList sDynlist801A85A4[4] = { BeginList(), CallList(sDynlist801A84E4), SetFriction(0.04, 0.01, 0.01), EndList(), }; -static struct DynList sDynlist801A8604[4] = { +UNUSED static struct DynList sDynlist801A8604[4] = { BeginList(), CallList(sDynlist801A84E4), SetFriction(0.005, 0.005, 0.005), @@ -86,35 +86,35 @@ static struct DynList sDynlist801A8604[4] = { static f64 D_801A8668 = 0.0; // bss -static u8 sUnrefSpaceB00[0x2C]; // @ 801BAB00 +UNUSED static u8 sUnrefSpaceB00[0x2C]; // @ 801BAB00 static struct ObjGroup *sCubeShapeGroup; // @ 801BAB2C -static u8 sUnrefSpaceB30[0xC]; // @ 801BAB30 +UNUSED static u8 sUnrefSpaceB30[0xC]; // @ 801BAB30 static struct ObjShape *sCubeShape; // @ 801BAB3C -static u8 sUnrefSpaceB40[0x8]; // @ 801BAB40 +UNUSED static u8 sUnrefSpaceB40[0x8]; // @ 801BAB40 static char sGdLineBuf[0x100]; // @ 801BAB48 static s32 sGdLineBufCsr; // @ 801BAC48 static struct GdFile *sGdShapeFile; // @ 801BAC4C static struct ObjShape *sGdShapeListHead; // @ 801BAC50 static u32 sGdShapeCount; // @ 801BAC54 -static u8 sUnrefSpaceC58[0x8]; // @ 801BAC58 +UNUSED static u8 sUnrefSpaceC58[0x8]; // @ 801BAC58 static struct GdVec3f D_801BAC60; -static u32 sUnrefSpaceC6C; // @ 801BAC6C -static u32 sUnrefSpaceC70; // @ 801BAC70 +UNUSED static u32 sUnrefSpaceC6C; // @ 801BAC6C +UNUSED static u32 sUnrefSpaceC70; // @ 801BAC70 static struct ObjPlane *D_801BAC74; static struct ObjPlane *D_801BAC78; // sShapeNetHead? -static u8 sUnrefSpaceC80[0x1C]; // @ 801BAC80 +UNUSED static u8 sUnrefSpaceC80[0x1C]; // @ 801BAC80 static struct ObjFace *D_801BAC9C; static struct ObjFace *D_801BACA0; -static u8 sUnrefSpaceCA8[0x10]; // @ 801BACA8 +UNUSED static u8 sUnrefSpaceCA8[0x10]; // @ 801BACA8 /// factor for scaling vertices in an `ObjShape` when calling `scale_verts_in_shape()` static struct GdVec3f sVertexScaleFactor; /// factor for translating vertices in an `ObjShape` when calling `translate_verts_in_shape()` static struct GdVec3f sVertexTranslateOffset; -static u8 sUnrefSpaceCD8[0x30]; // @ 801BACD8 +UNUSED static u8 sUnrefSpaceCD8[0x30]; // @ 801BACD8 static struct ObjGroup *D_801BAD08; // group of planes from make_netfromshape -static u8 sUnrefSpaceD10[0x20]; // @ 801BAD10 +UNUSED static u8 sUnrefSpaceD10[0x20]; // @ 801BAD10 static struct GdVec3f sShapeCenter; // printed with "c=" -static u8 sUnrefSpaceD40[0x120]; // @ 801BAD40 +UNUSED static u8 sUnrefSpaceD40[0x120]; // @ 801BAD40 // Forward Declarations struct ObjMaterial *find_or_add_new_mtl(struct ObjGroup *, s32, f32, f32, f32); @@ -131,7 +131,7 @@ void func_80197280(void) { * Computes the normal vector for a face based on three of its vertices. */ void calc_face_normal(struct ObjFace *face) { - UNUSED u32 pad5C; + UNUSED u8 filler1[4]; struct GdVec3f p1; struct GdVec3f p2; struct GdVec3f p3; @@ -139,7 +139,7 @@ void calc_face_normal(struct ObjFace *face) { struct ObjVertex *vtx1; struct ObjVertex *vtx2; struct ObjVertex *vtx3; - UNUSED u32 pad1C; + UNUSED u8 filler2[4]; f32 mul = 1000.0f; imin("calc_facenormal"); @@ -260,7 +260,7 @@ void add_3_vtx_to_face(struct ObjFace *face, struct ObjVertex *vtx1, struct ObjV struct ObjShape *make_shape(s32 flag, const char *name) { struct ObjShape *newShape; struct ObjShape *curShapeHead; - UNUSED u32 pad; + UNUSED u8 filler[4]; newShape = (struct ObjShape *) make_object(OBJ_TYPE_SHAPES); @@ -604,7 +604,7 @@ void Unknown801985E8(struct ObjShape *shape) { /* @ 246ED4 for 0x4FC; orig name: func_80198704 */ void get_3DG1_shape(struct ObjShape *shape) { - UNUSED u8 pad78[8]; + UNUSED u8 filler[8]; struct GdVec3f tempNormal; /* maybe? */ s32 curFaceVtx; s32 faceVtxID; @@ -723,7 +723,7 @@ void get_3DG1_shape(struct ObjShape *shape) { /* @ 2473D0 for 0x390; orig name: func_80198C00 */ void get_OBJ_shape(struct ObjShape *shape) { - UNUSED u8 pad7D54[4]; + UNUSED u8 filler[4]; struct GdColour faceClr; s32 curFaceVtx; s32 faceVtxIndex; @@ -881,7 +881,7 @@ void read_ARK_shape(struct ObjShape *shape, char *fileName) { union { s8 bytes[0x48]; struct { - u8 pad[0x40]; + u8 filler[0x40]; s32 word40; s32 word44; } data; @@ -911,7 +911,7 @@ void read_ARK_shape(struct ObjShape *shape, char *fileName) { } data; } vtx; - UNUSED u8 pad54[4]; + UNUSED u8 filler[4]; struct GdVec3f sp48; struct ObjFace *sp44; // newly made face with mtl sp34; struct ObjFace *sp40 = NULL; // first made face @@ -1048,13 +1048,12 @@ struct GdFile *get_shape_from_file(struct ObjShape *shape, char *fileName) { /* @ 247F78 for 0x69c; orig name: Unknown801997A8 */ struct ObjShape *make_grid_shape(enum ObjTypeFlag gridType, s32 a1, s32 a2, s32 a3, s32 a4) { - UNUSED u32 pad1074; + UNUSED u8 filler1[4]; void *objBuf[32][32]; // vertex or particle depending on gridType f32 sp70; f32 sp6C; f32 sp68; - UNUSED u32 pad64; - UNUSED u32 pad60; + UNUSED u8 filler2[8]; f32 sp5C; s32 parI; s32 row; @@ -1064,13 +1063,13 @@ struct ObjShape *make_grid_shape(enum ObjTypeFlag gridType, s32 a1, s32 a2, s32 f32 sp44; struct ObjFace *sp40 = NULL; // first made shape? struct ObjGroup *parOrVtxGrp; // group of made particles or vertices (based on gridType) - UNUSED u32 pad38; + UNUSED u8 filler3[4]; struct ObjGroup *mtlGroup; struct GdVec3f *sp30; // GdVec3f* ? from gd_get_colour struct GdVec3f *sp2C; //^ struct ObjMaterial *mtl1; // first made material struct ObjMaterial *mtl2; // second made material - UNUSED u32 pad20; + UNUSED u8 filler4[4]; sp30 = (struct GdVec3f *) gd_get_colour(a1); sp2C = (struct GdVec3f *) gd_get_colour(a2); @@ -1238,7 +1237,7 @@ void animate_mario_head_normal(struct ObjAnimator *self) { if (self->frame == 810.0f) { self->frame = 750.0f; - self->nods -= 1; + self->nods--; if (self->nods == 0) { state = 3; } @@ -1300,9 +1299,9 @@ void animate_mario_head_normal(struct ObjAnimator *self) { */ s32 load_mario_head(void (*aniFn)(struct ObjAnimator *)) { struct ObjNet *sp54; // net made with sp48 group - UNUSED u8 pad4C[0x54 - 0x4c]; + UNUSED u8 filler1[8]; struct ObjGroup *sp48; // Joint group - UNUSED u8 pad40[0x48 - 0x40]; + UNUSED u8 filler2[8]; struct ObjGroup *mainShapesGrp; struct GdObj *sp38; // object list head before making a bunch of joints struct GdObj *faceJoint; // joint on the face that `grabberJoint` pulls @@ -1418,7 +1417,7 @@ s32 load_mario_head(void (*aniFn)(struct ObjAnimator *)) { grabberJoint->attachedObjsGrp = make_group(1, faceJoint); grabberJoint->updateFunc = eye_joint_update_func; grabberJoint->rootAnimator = animator; - grabberJoint->header.drawFlags &= ~OBJ_IS_GRABBALE; + grabberJoint->header.drawFlags &= ~OBJ_IS_GRABBABLE; // make the right eye follow cursor grabberJoint = make_grabber_joint(sGrabJointTestShape, 0, -100.0f, 200.0f, 400.0f); @@ -1426,7 +1425,7 @@ s32 load_mario_head(void (*aniFn)(struct ObjAnimator *)) { grabberJoint->attachedObjsGrp = make_group(1, faceJoint); grabberJoint->updateFunc = eye_joint_update_func; grabberJoint->rootAnimator = animator; - grabberJoint->header.drawFlags &= ~OBJ_IS_GRABBALE; + grabberJoint->header.drawFlags &= ~OBJ_IS_GRABBABLE; sp48 = make_group_of_type(OBJ_TYPE_JOINTS, sp38, NULL); sp54 = make_net(0, NULL, sp48, NULL, NULL); @@ -1528,11 +1527,10 @@ struct ObjGroup *Unknown8019ADC4(UNUSED u32 a0) { /* @ 249694 for 0x5c */ struct ObjGroup *Unknown8019AEC4(UNUSED u32 a0) { - UNUSED u32 sp24; - UNUSED u32 sp20; - UNUSED struct GdObj *sp1C; + UNUSED u8 filler[8]; + UNUSED struct GdObj *sp1C = gGdObjectList; - sp1C = gGdObjectList; gGdLightGroup = make_group(0); + return gGdLightGroup; } diff --git a/src/goddard/skin.c b/src/goddard/skin.c index 069d0c55..8088dc50 100644 --- a/src/goddard/skin.c +++ b/src/goddard/skin.c @@ -1,6 +1,6 @@ #include -#if defined(VERSION_EU) || defined(VERSION_SH) +#ifdef VERSION_EU #include "prevent_bss_reordering.h" #endif @@ -92,7 +92,7 @@ void func_80192294(struct ObjNet *net) { /* 240ACC -> 240B84 */ void func_801922FC(struct ObjNet *net) { struct ObjGroup *group; // 24 - UNUSED u32 pad18[2]; + UNUSED u8 filler[8]; gGdSkinNet = net; // TODO: netype constants? @@ -200,10 +200,9 @@ void collision_something_801926A4(struct ObjNet *net) { /* 2412A0 -> 24142C; not called */ void func_80192AD0(struct ObjNet *net) { - UNUSED u32 pad64; + UNUSED u8 filler1[4]; struct ObjGroup *sp60; - UNUSED u32 pad20[0x10]; - UNUSED u32 sp1C; + UNUSED u8 filler2[68]; struct ObjNet *sp18; if ((sp60 = net->unk1C8) == NULL) { @@ -232,7 +231,7 @@ void func_80192AD0(struct ObjNet *net) { /* 24142C -> 24149C; orig name: func_80192C5C */ void move_bonesnet(struct ObjNet *net) { struct ObjGroup *sp24; - UNUSED u32 pad18[3]; + UNUSED u8 filler[12]; imin("move_bonesnet"); gd_set_identity_mat4(&D_801B9DC8); @@ -300,10 +299,10 @@ void func_80192CCC(struct ObjNet *net) { /* 241768 -> 241AB4; orig name: func_80192F98 */ void convert_gd_verts_to_Vn(struct ObjGroup *grp) { - UNUSED u8 pad[0x40 - 0x2c]; + UNUSED u8 filler1[20]; Vtx *vn; // 28 u8 nx, ny, nz; // 24, 25, 26 - UNUSED u32 pad20; + UNUSED u8 filler2[4]; register struct VtxLink *vtxlink; // a1 #ifndef GBI_FLOATS register s16 *vnPos; // a2 @@ -348,7 +347,7 @@ void convert_gd_verts_to_Vn(struct ObjGroup *grp) { /* 241AB4 -> 241BCC; orig name: func_801932E4 */ void convert_gd_verts_to_Vtx(struct ObjGroup *grp) { - UNUSED u32 pad24[6]; + UNUSED u8 filler[24]; register struct VtxLink *vtxlink; // a1 #ifndef GBI_FLOATS register s16 *vtxcoords; // a2 diff --git a/src/goddard/skin_movement.c b/src/goddard/skin_movement.c index 7105ec76..05cb7e31 100644 --- a/src/goddard/skin_movement.c +++ b/src/goddard/skin_movement.c @@ -66,7 +66,7 @@ void scale_verts(struct ObjGroup *a0) { /* @ 23000C for 0x58; orig name: func8018183C*/ void move_skin(struct ObjNet *net) { - UNUSED u8 pad1C[8]; + UNUSED u8 filler[8]; if (net->shapePtr != NULL) { scale_verts(net->shapePtr->scaledVtxGroup); @@ -89,8 +89,7 @@ void func_80181894(struct ObjJoint *joint) { linkedObj = link->obj; curWeight = (struct ObjWeight *) linkedObj; - if (curWeight->weightVal > 0.0) //? 0.0f - { + if (curWeight->weightVal > 0.0) { //? 0.0f stackVec.x = curWeight->vec20.x; stackVec.y = curWeight->vec20.y; stackVec.z = curWeight->vec20.z; @@ -110,7 +109,7 @@ void func_80181894(struct ObjJoint *joint) { /* @ 2301A0 for 0x110 */ void reset_weight_vtx(struct ObjVertex *vtx) { struct GdVec3f localVec; - UNUSED u8 pad24[0x10]; + UNUSED u8 filler[16]; if (sResetWeightVtxNum++ == sResetCurWeight->vtxId) { // found matching vertex sResetCurWeight->vtx = vtx; @@ -129,7 +128,7 @@ void reset_weight_vtx(struct ObjVertex *vtx) { void reset_weight(struct ObjWeight *weight) { UNUSED u32 vtxCount; - UNUSED u32 pad20; + UNUSED u8 filler[4]; struct ObjGroup *skinGroup; sResetCurWeight = weight; diff --git a/src/menu/file_select.c b/src/menu/file_select.c index c8947978..fce9a9e2 100644 --- a/src/menu/file_select.c +++ b/src/menu/file_select.c @@ -548,7 +548,7 @@ void exit_score_file_to_score_menu(struct Object *scoreFileButton, s8 scoreButto if (scoreFileButton->oMenuButtonState == MENU_BUTTON_STATE_FULLSCREEN && sCursorClickingTimer == 2) { play_sound(SOUND_MENU_CAMERA_ZOOM_OUT, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif scoreFileButton->oMenuButtonState = MENU_BUTTON_STATE_SHRINKING; @@ -627,6 +627,7 @@ void render_score_menu_buttons(struct Object *scoreButton) { #else #define SCORE_TIMER 31 #endif + /** * In the score menu, checks if a button was clicked to play a sound, button state and other functions. */ @@ -643,7 +644,7 @@ void check_score_menu_clicked_buttons(struct Object *scoreButton) { if (buttonID == MENU_BUTTON_SCORE_RETURN || buttonID == MENU_BUTTON_SCORE_COPY_FILE || buttonID == MENU_BUTTON_SCORE_ERASE_FILE) { play_sound(SOUND_MENU_CLICK_FILE_SELECT, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[buttonID]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN_OUT; @@ -654,7 +655,7 @@ void check_score_menu_clicked_buttons(struct Object *scoreButton) { // If clicked in a existing save file, select it too see it's score if (save_file_exists(buttonID - MENU_BUTTON_SCORE_MIN) == TRUE) { play_sound(SOUND_MENU_CAMERA_ZOOM_IN, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[buttonID]->oMenuButtonState = MENU_BUTTON_STATE_GROWING; @@ -663,7 +664,7 @@ void check_score_menu_clicked_buttons(struct Object *scoreButton) { else { // If clicked in a non-existing save file, play buzz sound play_sound(SOUND_MENU_CAMERA_BUZZ, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[buttonID]->oMenuButtonState = @@ -681,6 +682,7 @@ void check_score_menu_clicked_buttons(struct Object *scoreButton) { } } } + #undef SCORE_TIMER /** @@ -759,7 +761,7 @@ void copy_action_file_button(struct Object *copyButton, s32 copyFileButtonID) { if (save_file_exists(copyFileButtonID - MENU_BUTTON_COPY_MIN) == TRUE) { // If clicked in a existing save file, ask where it wants to copy play_sound(SOUND_MENU_CLICK_FILE_SELECT, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[copyFileButtonID]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN; @@ -770,7 +772,7 @@ void copy_action_file_button(struct Object *copyButton, s32 copyFileButtonID) { } else { // If clicked in a non-existing save file, play buzz sound play_sound(SOUND_MENU_CAMERA_BUZZ, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[copyFileButtonID]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN_OUT; @@ -785,7 +787,7 @@ void copy_action_file_button(struct Object *copyButton, s32 copyFileButtonID) { if (save_file_exists(copyFileButtonID - MENU_BUTTON_COPY_MIN) == FALSE) { // If clicked in a non-existing save file, copy the file play_sound(SOUND_MENU_STAR_SOUND, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif copyButton->oMenuButtonActionPhase = COPY_PHASE_COPY_COMPLETE; @@ -800,7 +802,7 @@ void copy_action_file_button(struct Object *copyButton, s32 copyFileButtonID) { // If clicked in a existing save file, play buzz sound if (MENU_BUTTON_COPY_FILE_A + sSelectedFileIndex == copyFileButtonID) { play_sound(SOUND_MENU_CAMERA_BUZZ, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[MENU_BUTTON_COPY_FILE_A + sSelectedFileIndex]->oMenuButtonState = @@ -843,7 +845,7 @@ void check_copy_menu_clicked_buttons(struct Object *copyButton) { || buttonID == MENU_BUTTON_COPY_ERASE_FILE) { if (copyButton->oMenuButtonActionPhase == COPY_PHASE_MAIN) { play_sound(SOUND_MENU_CLICK_FILE_SELECT, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[buttonID]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN_OUT; @@ -941,7 +943,7 @@ void erase_action_file_button(struct Object *eraseButton, s32 eraseFileButtonID) if (save_file_exists(eraseFileButtonID - MENU_BUTTON_ERASE_MIN) == TRUE) { // If clicked in a existing save file, ask if it wants to delete it play_sound(SOUND_MENU_CLICK_FILE_SELECT, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[eraseFileButtonID]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN; @@ -952,7 +954,7 @@ void erase_action_file_button(struct Object *eraseButton, s32 eraseFileButtonID) } else { // If clicked in a non-existing save file, play buzz sound play_sound(SOUND_MENU_CAMERA_BUZZ, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[eraseFileButtonID]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN_OUT; @@ -969,7 +971,7 @@ void erase_action_file_button(struct Object *eraseButton, s32 eraseFileButtonID) // Note: The prompt functions are actually called when the ERASE_MSG_PROMPT // message is displayed with print_erase_menu_prompt play_sound(SOUND_MENU_CLICK_FILE_SELECT, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[MENU_BUTTON_ERASE_MIN + sSelectedFileIndex]->oMenuButtonState = @@ -980,6 +982,7 @@ void erase_action_file_button(struct Object *eraseButton, s32 eraseFileButtonID) break; } } + #undef BUZZ_TIMER /** @@ -999,7 +1002,7 @@ void check_erase_menu_clicked_buttons(struct Object *eraseButton) { || buttonID == MENU_BUTTON_ERASE_COPY_FILE) { if (eraseButton->oMenuButtonActionPhase == ERASE_PHASE_MAIN) { play_sound(SOUND_MENU_CLICK_FILE_SELECT, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[buttonID]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN_OUT; @@ -1025,6 +1028,7 @@ void check_erase_menu_clicked_buttons(struct Object *eraseButton) { } } } + #undef ACTION_TIMER #undef MAIN_RETURN_TIMER @@ -1074,6 +1078,7 @@ void render_sound_mode_menu_buttons(struct Object *soundModeButton) { sMainMenuButtons[MENU_BUTTON_OPTION_MIN + sSoundMode]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN; #endif } + #undef SOUND_BUTTON_Y /** @@ -1094,7 +1099,7 @@ void check_sound_mode_menu_clicked_buttons(struct Object *soundModeButton) { || buttonID == MENU_BUTTON_HEADSET) { if (soundModeButton->oMenuButtonActionPhase == SOUND_MODE_PHASE_MAIN) { play_sound(SOUND_MENU_CLICK_FILE_SELECT, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[buttonID]->oMenuButtonState = MENU_BUTTON_STATE_ZOOM_IN_OUT; @@ -1200,9 +1205,8 @@ void load_score_menu_from_submenu(s16 prevMenuButtonID, struct Object *sourceBut // If the previous button is in default state if (sMainMenuButtons[prevMenuButtonID]->oMenuButtonState == MENU_BUTTON_STATE_DEFAULT) { // Hide buttons of corresponding button menu groups - if (prevMenuButtonID == MENU_BUTTON_SCORE) //! Not possible, this is checking if the score menu - //! was opened from the score menu! - { + //! Not possible, this is checking if the score menu was opened from the score menu! + if (prevMenuButtonID == MENU_BUTTON_SCORE) { for (buttonID = MENU_BUTTON_SCORE_MIN; buttonID < MENU_BUTTON_SCORE_MAX; buttonID++) { mark_obj_for_deletion(sMainMenuButtons[buttonID]); } @@ -1246,9 +1250,8 @@ void load_copy_menu_from_submenu(s16 prevMenuButtonID, struct Object *sourceButt mark_obj_for_deletion(sMainMenuButtons[buttonID]); } } - if (prevMenuButtonID == MENU_BUTTON_COPY) //! Not possible, this is checking if the copy menu - //! was opened from the copy menu! - { + //! Not possible, this is checking if the copy menu was opened from the copy menu! + if (prevMenuButtonID == MENU_BUTTON_COPY) { for (buttonID = MENU_BUTTON_COPY_MIN; buttonID < MENU_BUTTON_COPY_MAX; buttonID++) { mark_obj_for_deletion(sMainMenuButtons[buttonID]); } @@ -1292,9 +1295,8 @@ void load_erase_menu_from_submenu(s16 prevMenuButtonID, struct Object *sourceBut mark_obj_for_deletion(sMainMenuButtons[buttonID]); } } - if (prevMenuButtonID == MENU_BUTTON_ERASE) //! Not possible, this is checking if the erase menu - //! was opened from the erase menu! - { + //! Not possible, this is checking if the erase menu was opened from the erase menu! + if (prevMenuButtonID == MENU_BUTTON_ERASE) { for (buttonID = MENU_BUTTON_ERASE_MIN; buttonID < MENU_BUTTON_ERASE_MAX; buttonID++) { mark_obj_for_deletion(sMainMenuButtons[buttonID]); } @@ -1376,7 +1378,7 @@ void bhv_menu_button_manager_init(void) { sTextBaseAlpha = 0; } -#if defined(VERSION_JP) +#ifdef VERSION_JP #define SAVE_FILE_SOUND SOUND_MENU_STAR_SOUND #else #define SAVE_FILE_SOUND SOUND_MENU_STAR_SOUND_OKEY_DOKEY @@ -1425,28 +1427,28 @@ void check_main_menu_clicked_buttons(void) { switch (sSelectedButtonID) { case MENU_BUTTON_PLAY_FILE_A: play_sound(SAVE_FILE_SOUND, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(60, 70); func_sh_8024C89C(1); #endif break; case MENU_BUTTON_PLAY_FILE_B: play_sound(SAVE_FILE_SOUND, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(60, 70); func_sh_8024C89C(1); #endif break; case MENU_BUTTON_PLAY_FILE_C: play_sound(SAVE_FILE_SOUND, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(60, 70); func_sh_8024C89C(1); #endif break; case MENU_BUTTON_PLAY_FILE_D: play_sound(SAVE_FILE_SOUND, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(60, 70); func_sh_8024C89C(1); #endif @@ -1454,28 +1456,28 @@ void check_main_menu_clicked_buttons(void) { // Play sound of the button clicked and render buttons of that menu. case MENU_BUTTON_SCORE: play_sound(SOUND_MENU_CAMERA_ZOOM_IN, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif render_score_menu_buttons(sMainMenuButtons[MENU_BUTTON_SCORE]); break; case MENU_BUTTON_COPY: play_sound(SOUND_MENU_CAMERA_ZOOM_IN, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif render_copy_menu_buttons(sMainMenuButtons[MENU_BUTTON_COPY]); break; case MENU_BUTTON_ERASE: play_sound(SOUND_MENU_CAMERA_ZOOM_IN, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif render_erase_menu_buttons(sMainMenuButtons[MENU_BUTTON_ERASE]); break; case MENU_BUTTON_SOUND_MODE: play_sound(SOUND_MENU_CAMERA_ZOOM_IN, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif render_sound_mode_menu_buttons(sMainMenuButtons[MENU_BUTTON_SOUND_MODE]); @@ -1485,6 +1487,7 @@ void check_main_menu_clicked_buttons(void) { } #endif } + #undef SAVE_FILE_SOUND /** @@ -1622,10 +1625,11 @@ void handle_cursor_button_input(void) { || sSelectedButtonID == MENU_BUTTON_SCORE_FILE_D) { if (gPlayer3Controller->buttonPressed #ifdef VERSION_EU - & (B_BUTTON | START_BUTTON | Z_TRIG)) { + & (B_BUTTON | START_BUTTON | Z_TRIG) #else - & (B_BUTTON | START_BUTTON)) { + & (B_BUTTON | START_BUTTON) #endif + ) { sClickPos[0] = sCursorPos[0]; sClickPos[1] = sCursorPos[1]; sCursorClickingTimer = 1; @@ -1801,7 +1805,7 @@ void print_save_file_star_count(s8 fileIndex, s16 x, s16 y) { #define SAVEFILE_X2 209 #define MARIOTEXT_X1 92 #define MARIOTEXT_X2 207 -#else // VERSION_EU +#elif defined(VERSION_EU) #define SAVEFILE_X1 97 #define SAVEFILE_X2 204 #define MARIOTEXT_X1 97 @@ -1888,15 +1892,15 @@ void print_main_lang_strings(void) { } #endif -#ifdef VERSION_EU -#define CHECK_FILE_X checkFileX -#define NOSAVE_DATA_X1 noSaveDataX -#elif defined(VERSION_JP) || defined(VERSION_SH) -#define CHECK_FILE_X 90 -#define NOSAVE_DATA_X1 90 -#else -#define CHECK_FILE_X 95 -#define NOSAVE_DATA_X1 99 +#if defined(VERSION_JP) || defined(VERSION_SH) + #define CHECK_FILE_X 90 + #define NOSAVE_DATA_X1 90 +#elif defined(VERSION_US) + #define CHECK_FILE_X 95 + #define NOSAVE_DATA_X1 99 +#elif defined(VERSION_EU) + #define CHECK_FILE_X checkFileX + #define NOSAVE_DATA_X1 noSaveDataX #endif /** @@ -1927,14 +1931,14 @@ void score_menu_display_message(s8 messageID) { #define RETURN_X 45 #define COPYFILE_X1 128 #define ERASEFILE_X1 228 +#elif defined(VERSION_US) + #define RETURN_X 44 + #define COPYFILE_X1 135 + #define ERASEFILE_X1 231 #elif defined(VERSION_EU) #define RETURN_X centeredX #define COPYFILE_X1 centeredX #define ERASEFILE_X1 centeredX -#else - #define RETURN_X 44 - #define COPYFILE_X1 135 - #define ERASEFILE_X1 231 #endif #ifdef VERSION_EU @@ -2014,6 +2018,13 @@ void print_score_menu_strings(void) { #define NOSAVE_DATA_X2 90 #define COPYCOMPLETE_X 90 #define SAVE_EXISTS_X1 90 +#elif defined(VERSION_US) + #define NOFILE_COPY_X 119 + #define COPY_FILE_X 104 + #define COPYIT_WHERE_X 109 + #define NOSAVE_DATA_X2 101 + #define COPYCOMPLETE_X 110 + #define SAVE_EXISTS_X1 110 #elif defined(VERSION_EU) #define NOFILE_COPY_X centeredX #define COPY_FILE_X centeredX @@ -2021,13 +2032,6 @@ void print_score_menu_strings(void) { #define NOSAVE_DATA_X2 centeredX #define COPYCOMPLETE_X centeredX #define SAVE_EXISTS_X1 centeredX -#else - #define NOFILE_COPY_X 119 - #define COPY_FILE_X 104 - #define COPYIT_WHERE_X 109 - #define NOSAVE_DATA_X2 101 - #define COPYCOMPLETE_X 110 - #define SAVE_EXISTS_X1 110 #endif /** @@ -2129,14 +2133,14 @@ void copy_menu_update_message(void) { #if defined(VERSION_JP) #define VIEWSCORE_X1 133 #define ERASEFILE_X2 220 -#elif defined(VERSION_SH) - #define VIEWSCORE_X1 133 +#elif defined(VERSION_US) + #define VIEWSCORE_X1 128 #define ERASEFILE_X2 230 #elif defined(VERSION_EU) #define VIEWSCORE_X1 centeredX #define ERASEFILE_X2 centeredX -#else - #define VIEWSCORE_X1 128 +#elif defined(VERSION_SH) + #define VIEWSCORE_X1 133 #define ERASEFILE_X2 230 #endif @@ -2192,12 +2196,12 @@ void print_copy_menu_strings(void) { #endif } -#if defined(VERSION_JP) +#if defined(VERSION_JP) || defined(VERSION_SH) +#ifdef VERSION_JP #define CURSOR_X 160.0f - #define MENU_ERASE_YES_MIN_X 145 - #define MENU_ERASE_YES_MAX_X 164 -#elif defined(VERSION_SH) +#else #define CURSOR_X (x + 70) +#endif #define MENU_ERASE_YES_MIN_X 145 #define MENU_ERASE_YES_MAX_X 164 #else @@ -2248,7 +2252,7 @@ void print_erase_menu_prompt(s16 x, s16 y) { // ..and is hovering "YES", delete file if (sEraseYesNoHoverState == MENU_ERASE_HOVER_YES) { play_sound(SOUND_MARIO_WAAAOOOW, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[MENU_BUTTON_ERASE]->oMenuButtonActionPhase = ERASE_PHASE_MARIO_ERASED; @@ -2263,7 +2267,7 @@ void print_erase_menu_prompt(s16 x, s16 y) { // ..and is hovering "NO", return back to main phase } else if (sEraseYesNoHoverState == MENU_ERASE_HOVER_NO) { play_sound(SOUND_MENU_CLICK_FILE_SELECT, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(5, 80); #endif sMainMenuButtons[MENU_BUTTON_ERASE_MIN + sSelectedFileIndex]->oMenuButtonState = @@ -2289,27 +2293,27 @@ void print_erase_menu_prompt(s16 x, s16 y) { // M a r i o A --- マ リ オ A // 0 1 2 3 4 5 6 --- 0 1 2 3 #if defined(VERSION_JP) || defined(VERSION_SH) -#ifdef VERSION_SH - #define ERASE_FILE_X 111 -#else +#ifdef VERSION_JP #define ERASE_FILE_X 96 +#else + #define ERASE_FILE_X 111 #endif #define NOSAVE_DATA_X3 90 #define MARIO_ERASED_VAR 3 #define MARIO_ERASED_X 90 #define SAVE_EXISTS_X2 90 +#elif defined(VERSION_US) + #define ERASE_FILE_X 98 + #define NOSAVE_DATA_X3 100 + #define MARIO_ERASED_VAR 6 + #define MARIO_ERASED_X 100 + #define SAVE_EXISTS_X2 100 #elif defined(VERSION_EU) #define ERASE_FILE_X centeredX #define NOSAVE_DATA_X3 centeredX #define MARIO_ERASED_VAR 6 #define MARIO_ERASED_X centeredX #define SAVE_EXISTS_X2 centeredX -#else - #define ERASE_FILE_X 98 - #define NOSAVE_DATA_X3 100 - #define MARIO_ERASED_VAR 6 - #define MARIO_ERASED_X 100 - #define SAVE_EXISTS_X2 100 #endif /** @@ -2404,11 +2408,11 @@ void erase_menu_update_message(void) { } #if defined(VERSION_JP) || defined(VERSION_SH) -#define VIEWSCORE_X2 133 -#define COPYFILE_X2 223 + #define VIEWSCORE_X2 133 + #define COPYFILE_X2 223 #else -#define VIEWSCORE_X2 127 -#define COPYFILE_X2 233 + #define VIEWSCORE_X2 127 + #define COPYFILE_X2 233 #endif /** @@ -2671,9 +2675,14 @@ void print_score_file_star_score(s8 fileIndex, s16 courseIndex, s16 x, s16 y) { #define SECRET_STARS_PAD 6 #define LEVEL_NAME_X 23 #define STAR_SCORE_X 171 +#ifdef VERSION_EU + #define MYSCORE_X get_str_x_pos_from_center(257, textMyScore[sLanguageMode], 10.0f) + #define HISCORE_X get_str_x_pos_from_center(257, textHiScore[sLanguageMode], 10.0f) +#else #define MYSCORE_X 238 #define HISCORE_X 231 #endif +#endif #ifdef VERSION_EU #include "game/segment7.h" @@ -2750,7 +2759,6 @@ void print_save_file_scores(s8 fileIndex) { PRINT_COURSE_SCORES(COURSE_THI, 0) PRINT_COURSE_SCORES(COURSE_TTC, 0) PRINT_COURSE_SCORES(COURSE_RR, 0) - #undef PRINT_COURSE_SCORES // Print castle secret stars text @@ -2761,20 +2769,11 @@ void print_save_file_scores(s8 fileIndex) { // Print current coin score mode if (sScoreFileCoinScoreMode == 0) { -#ifdef VERSION_EU - print_menu_generic_string(get_str_x_pos_from_center(257, textMyScore[sLanguageMode], 10.0f), - 24, textMyScore[sLanguageMode]); -#else - print_menu_generic_string(MYSCORE_X, 24, textMyScore); -#endif + print_menu_generic_string(MYSCORE_X, 24, LANGUAGE_ARRAY(textMyScore)); } else { -#ifdef VERSION_EU - print_menu_generic_string(get_str_x_pos_from_center(257, textHiScore[sLanguageMode], 10.0f), - 24,textHiScore[sLanguageMode]); -#else - print_menu_generic_string(HISCORE_X, 24, textHiScore); -#endif + print_menu_generic_string(HISCORE_X, 24, LANGUAGE_ARRAY(textHiScore)); } + gSPDisplayList(gDisplayListHead++, dl_menu_ia8_text_end); } @@ -2783,8 +2782,7 @@ void print_save_file_scores(s8 fileIndex) { * Also checks if all saves exists and defines text and main menu timers. */ static void print_file_select_strings(void) { - UNUSED s32 unused1; - UNUSED s32 unused2; + UNUSED u8 filler[8]; create_dl_ortho_matrix(); switch (sSelectedButtonID) { @@ -2834,7 +2832,7 @@ static void print_file_select_strings(void) { sTextBaseAlpha += 10; } if (sMainMenuTimer < 1000) { - sMainMenuTimer += 1; + sMainMenuTimer++; } } diff --git a/src/menu/intro_geo.c b/src/menu/intro_geo.c index e2e5bb92..efbbfbbb 100644 --- a/src/menu/intro_geo.c +++ b/src/menu/intro_geo.c @@ -10,7 +10,6 @@ #include "buffers/framebuffers.h" #include "game/game_init.h" #include "audio/external.h" -#include "prevent_bss_reordering.h" // frame counts for the zoom in, hold, and zoom out of title model #define INTRO_STEPS_ZOOM_IN 20 @@ -29,7 +28,7 @@ struct GraphNodeMore { // intro geo bss #ifdef VERSION_SH -static u16 *sFrameBuffers[3]; +static u16 *sFramebuffers[3]; #endif static s32 sGameOverFrameCounter; static s32 sGameOverTableIndex; @@ -272,11 +271,12 @@ Gfx *geo_intro_gameover_backdrop(s32 state, struct GraphNode *node, UNUSED void } #ifdef VERSION_SH + extern Gfx title_screen_bg_dl_0A0065E8[]; extern Gfx title_screen_bg_dl_0A006618[]; extern Gfx title_screen_bg_dl_0A007548[]; -//Data +// Data s8 sFaceVisible[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -296,8 +296,7 @@ s8 sFaceToggleOrder[] = { s8 sFaceCounter = 0; -void intro_gen_face_texrect(Gfx **dlIter) -{ +void intro_gen_face_texrect(Gfx **dlIter) { s32 x; s32 y; @@ -311,8 +310,7 @@ void intro_gen_face_texrect(Gfx **dlIter) } } -Gfx *intro_draw_face(u16 *image, s32 imageW, s32 imageH) -{ +Gfx *intro_draw_face(u16 *image, s32 imageW, s32 imageH) { Gfx *dl; Gfx *dlIter; @@ -337,7 +335,7 @@ Gfx *intro_draw_face(u16 *image, s32 imageW, s32 imageH) return dl; } -u16 *intro_sample_frame_buffer(s32 imageW, s32 imageH, s32 sampleW, s32 sampleH) { +u16 *intro_sample_framebuffer(s32 imageW, s32 imageH, s32 sampleW, s32 sampleH) { u16 *fb; u16 *image; s32 pixel; @@ -348,7 +346,7 @@ u16 *intro_sample_frame_buffer(s32 imageW, s32 imageH, s32 sampleW, s32 sampleH) s32 xOffset = 120; s32 yOffset = 80; - fb = sFrameBuffers[frameBufferIndex]; + fb = sFramebuffers[sRenderingFramebuffer]; image = alloc_display_list(imageW * imageH * sizeof(u16)); if (image == NULL) { @@ -398,9 +396,9 @@ Gfx *geo_intro_face_easter_egg(s32 state, struct GraphNode *node, UNUSED void *c s32 i; if (state != 1) { - sFrameBuffers[0] = gFrameBuffer0; - sFrameBuffers[1] = gFrameBuffer1; - sFrameBuffers[2] = gFrameBuffer2; + sFramebuffers[0] = gFramebuffer0; + sFramebuffers[1] = gFramebuffer1; + sFramebuffers[2] = gFramebuffer2; for (i = 0; i < 48; i++) { sFaceVisible[i] = 0; @@ -422,7 +420,7 @@ Gfx *geo_intro_face_easter_egg(s32 state, struct GraphNode *node, UNUSED void *c // Draw while the first or last face is visible. if (sFaceVisible[0] == 1 || sFaceVisible[17] == 1) { - image = intro_sample_frame_buffer(40, 40, 2, 2); + image = intro_sample_framebuffer(40, 40, 2, 2); if (image != NULL) { genNode->fnNode.node.flags = (genNode->fnNode.node.flags & 0xFF) | (LAYER_OPAQUE << 8); dl = intro_draw_face(image, 40, 40); @@ -439,6 +437,10 @@ Gfx *geo_intro_rumble_pak_graphic(s32 state, struct GraphNode *node, UNUSED void Gfx *dl; s32 introContext; s8 backgroundTileSix; +#ifdef AVOID_UB + dl = NULL; + backgroundTileSix = 0; +#endif if (state != 1) { dl = NULL; @@ -465,4 +467,3 @@ Gfx *geo_intro_rumble_pak_graphic(s32 state, struct GraphNode *node, UNUSED void } #endif - diff --git a/src/menu/level_select_menu.h b/src/menu/level_select_menu.h deleted file mode 100644 index fcb2b9ac..00000000 --- a/src/menu/level_select_menu.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef LEVEL_SELECT_MENU_H -#define LEVEL_SELECT_MENU_H - -#include - -#include "macros.h" - -s32 lvl_intro_update(s16 arg1, UNUSED s32 arg2); - -#endif // LEVEL_SELECT_MENU_H diff --git a/src/menu/star_select.c b/src/menu/star_select.c index 025dbf24..f7d1d740 100644 --- a/src/menu/star_select.c +++ b/src/menu/star_select.c @@ -19,7 +19,6 @@ #include "sm64.h" #include "star_select.h" #include "text_strings.h" -#include "prevent_bss_reordering.h" /** * @file star_select.c @@ -108,7 +107,7 @@ void render_100_coin_star(u8 stars) { void bhv_act_selector_init(void) { s16 i = 0; s32 selectorModelIDs[10]; - u8 stars = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1); + u8 stars = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); sVisibleStars = 0; while (i != sObtainedStars) { @@ -167,7 +166,7 @@ void bhv_act_selector_init(void) { void bhv_act_selector_loop(void) { s8 i; u8 starIndexCounter; - u8 stars = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1); + u8 stars = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); if (sObtainedStars != 6) { // Sometimes, stars are not selectable even if they appear on the screen. @@ -271,14 +270,12 @@ void print_act_selector_strings(void) { u8 **actNameTbl; #else u8 **levelNameTbl = segmented_to_virtual(seg2_course_name_table); - u8 *currLevelName = segmented_to_virtual(levelNameTbl[gCurrCourseNum - 1]); + u8 *currLevelName = segmented_to_virtual(levelNameTbl[COURSE_NUM_TO_INDEX(gCurrCourseNum)]); u8 **actNameTbl = segmented_to_virtual(seg2_act_name_table); #endif u8 *selectedActName; -#ifndef VERSION_EU s16 lvlNameX; s16 actNameX; -#endif s8 i; #ifdef VERSION_EU s16 language = eu_get_language(); @@ -301,19 +298,19 @@ void print_act_selector_strings(void) { levelNameTbl = segmented_to_virtual(course_name_table_eu_de); break; } - currLevelName = segmented_to_virtual(levelNameTbl[gCurrCourseNum - 1]); + currLevelName = segmented_to_virtual(levelNameTbl[COURSE_NUM_TO_INDEX(gCurrCourseNum)]); #endif // Print the coin highscore. gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin); gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 255); - print_hud_my_score_coins(1, gCurrSaveFileNum - 1, gCurrCourseNum - 1, 155, 106); + print_hud_my_score_coins(1, gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum), 155, 106); gSPDisplayList(gDisplayListHead++, dl_rgba16_text_end); gSPDisplayList(gDisplayListHead++, dl_ia_text_begin); gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, 255); // Print the "MY SCORE" text if the coin score is more than 0 - if (save_file_get_course_coin_score(gCurrSaveFileNum - 1, gCurrCourseNum - 1) != 0) { + if (save_file_get_course_coin_score(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)) != 0) { #ifdef VERSION_EU print_generic_string(95, 118, myScore[language]); #else @@ -321,12 +318,8 @@ void print_act_selector_strings(void) { #endif } -#ifdef VERSION_EU - print_generic_string(get_str_x_pos_from_center(160, currLevelName + 3, 10.0f), 33, currLevelName + 3); -#else lvlNameX = get_str_x_pos_from_center(160, currLevelName + 3, 10.0f); print_generic_string(lvlNameX, 33, currLevelName + 3); -#endif gSPDisplayList(gDisplayListHead++, dl_ia_text_end); @@ -340,14 +333,10 @@ void print_act_selector_strings(void) { gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, 255); // Print the name of the selected act. if (sVisibleStars != 0) { - selectedActName = segmented_to_virtual(actNameTbl[(gCurrCourseNum - 1) * 6 + sSelectedActIndex]); + selectedActName = segmented_to_virtual(actNameTbl[COURSE_NUM_TO_INDEX(gCurrCourseNum) * 6 + sSelectedActIndex]); -#ifdef VERSION_EU - print_menu_generic_string(get_str_x_pos_from_center(ACT_NAME_X, selectedActName, 8.0f), 81, selectedActName); -#else actNameX = get_str_x_pos_from_center(ACT_NAME_X, selectedActName, 8.0f); print_menu_generic_string(actNameX, 81, selectedActName); -#endif } // Print the numbers above each star. @@ -383,13 +372,14 @@ Gfx *geo_act_selector_strings(s16 callContext, UNUSED struct GraphNode *node) { * Also load how much stars a course has, without counting the 100 coin star. */ s32 lvl_init_act_selector_values_and_stars(UNUSED s32 arg, UNUSED s32 unused) { - u8 stars = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1); + u8 stars = save_file_get_star_flags(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); sLoadedActNum = 0; sInitSelectedActNum = 0; sVisibleStars = 0; sActSelectorMenuTimer = 0; - sObtainedStars = save_file_get_course_star_count(gCurrSaveFileNum - 1, gCurrCourseNum - 1); + sObtainedStars = + save_file_get_course_star_count(gCurrSaveFileNum - 1, COURSE_NUM_TO_INDEX(gCurrCourseNum)); // Don't count 100 coin star if (stars & (1 << 6)) { @@ -407,7 +397,7 @@ s32 lvl_init_act_selector_values_and_stars(UNUSED s32 arg, UNUSED s32 unused) { * Also updates objects and returns act number selected after is chosen. */ s32 lvl_update_obj_and_load_act_button_actions(UNUSED s32 arg, UNUSED s32 unused) { - if (sActSelectorMenuTimer >= 11) { + if (sActSelectorMenuTimer > 10) { // If any of these buttons are pressed, play sound and go to course act #ifndef VERSION_EU if ((gPlayer3Controller->buttonPressed & A_BUTTON) @@ -416,12 +406,12 @@ s32 lvl_update_obj_and_load_act_button_actions(UNUSED s32 arg, UNUSED s32 unused #else if ((gPlayer3Controller->buttonPressed & (A_BUTTON | START_BUTTON | B_BUTTON | Z_TRIG))) { #endif -#if defined(VERSION_JP) +#ifdef VERSION_JP play_sound(SOUND_MENU_STAR_SOUND, gGlobalSoundSource); #else play_sound(SOUND_MENU_STAR_SOUND_LETS_A_GO, gGlobalSoundSource); #endif -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(60, 70); func_sh_8024C89C(1); #endif diff --git a/src/menu/star_select.h b/src/menu/star_select.h index 6388b3f6..d00afb1a 100644 --- a/src/menu/star_select.h +++ b/src/menu/star_select.h @@ -6,8 +6,7 @@ #include "types.h" -enum StarSelectorTypes -{ +enum StarSelectorTypes { STAR_SELECTOR_NOT_SELECTED, STAR_SELECTOR_SELECTED, STAR_SELECTOR_100_COINS diff --git a/src/menu/level_select_menu.c b/src/menu/title_screen.c similarity index 55% rename from src/menu/level_select_menu.c rename to src/menu/title_screen.c index 2b1010b3..071714f0 100644 --- a/src/menu/level_select_menu.c +++ b/src/menu/title_screen.c @@ -14,71 +14,81 @@ #include "level_table.h" #include "seq_ids.h" #include "sm64.h" +#include "title_screen.h" -#define PRESS_START_DEMO_TIMER 800 +/** + * @file title_screen.c + * This file implements how title screen functions. + * That includes playing demo sequences, introduction screens + * and a level select used for testing purposes. + */ #define STUB_LEVEL(textname, _1, _2, _3, _4, _5, _6, _7, _8) textname, #define DEFINE_LEVEL(textname, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) textname, -static char gLevelSelect_StageNamesText[64][16] = { +static char sLevelSelectStageNames[64][16] = { #include "levels/level_defines.h" }; #undef STUB_LEVEL #undef DEFINE_LEVEL -static u16 gDemoCountdown = 0; +static u16 sDemoCountdown = 0; #ifndef VERSION_JP -static s16 D_U_801A7C34 = 1; -static s16 gameOverNotPlayed = 1; +static s16 sPlayMarioGreeting = TRUE; +static s16 sPlayMarioGameOver = TRUE; #endif -// run the demo timer on the PRESS START screen. -// this function will return a non-0 timer once -// the demo starts, signaling to the subsystem that -// the demo needs to be ran. +#define PRESS_START_DEMO_TIMER 800 -// don't shift this function from being the first function in the segment. -// the level scripts assume this function is the first, so it cant be moved. -s32 run_press_start_demo_timer(s32 timer) { +/** + * Run the demo timer on the PRESS START screen after a number of frames. + * This function returns the level ID from the first byte of a demo file. + * It also returns the level ID from intro_regular (file select or level select menu) + */ +s32 run_level_id_or_demo(s32 level) { gCurrDemoInput = NULL; - if (timer == 0) { + if (level == LEVEL_NONE) { if (!gPlayer1Controller->buttonDown && !gPlayer1Controller->stickMag) { - if ((++gDemoCountdown) == PRESS_START_DEMO_TIMER) { - // start the demo. 800 frames has passed while - // player is idle on PRESS START screen. + // start the demo. 800 frames has passed while + // player is idle on PRESS START screen. + if ((++sDemoCountdown) == PRESS_START_DEMO_TIMER) { // start the Mario demo animation for the demo list. - load_patchable_table(&gDemo, gDemoInputListID); + load_patchable_table(&gDemoInputsBuf, gDemoInputListID); // if the next demo sequence ID is the count limit, reset it back to // the first sequence. - if (++gDemoInputListID == gDemo.animDmaTable->count) { + if (++gDemoInputListID == gDemoInputsBuf.dmaTable->count) { gDemoInputListID = 0; } - // add 1 (+4) to the pointer to skip the demoID. - gCurrDemoInput = ((struct DemoInput *) gDemo.targetAnim) + 1; - timer = (s8)((struct DemoInput *) gDemo.targetAnim)->timer; + // add 1 (+4) to the pointer to skip the first 4 bytes + // Use the first 4 bytes to store level ID, + // then use the rest of the values for inputs + gCurrDemoInput = ((struct DemoInput *) gDemoInputsBuf.bufTarget) + 1; + level = (s8)((struct DemoInput *) gDemoInputsBuf.bufTarget)->timer; gCurrSaveFileNum = 1; gCurrActNum = 1; } } else { // activity was detected, so reset the demo countdown. - gDemoCountdown = 0; + sDemoCountdown = 0; } } - return timer; + return level; } -// input loop for the level select menu. updates the selected stage -// count if an input was received. signals the stage to be started -// or the level select to be exited if start or the quit combo is -// pressed. - -s16 level_select_input_loop(void) { +/** + * Level select intro function, updates the selected stage + * count if an input was received. signals the stage to be started + * or the level select to be exited if start or the quit combo is pressed. + */ +s16 intro_level_select(void) { s32 stageChanged = FALSE; // perform the ID updates per each button press. + // runs into a loop so after a button is pressed + // stageChanged goes back to FALSE if (gPlayer1Controller->buttonPressed & A_BUTTON) { ++gCurrLevelNum, stageChanged = TRUE; } @@ -103,7 +113,6 @@ s16 level_select_input_loop(void) { play_sound(SOUND_GENERAL_LEVEL_SELECT_CHANGE, gGlobalSoundSource); } - // TODO: enum counts for the stage lists if (gCurrLevelNum > LEVEL_MAX) { gCurrLevelNum = LEVEL_MIN; // exceeded max. set to min. } @@ -112,12 +121,14 @@ s16 level_select_input_loop(void) { gCurrLevelNum = LEVEL_MAX; // exceeded min. set to max. } - gCurrSaveFileNum = 4; // file 4 is used for level select tests + // Use file 4 and last act as a test + gCurrSaveFileNum = 4; gCurrActNum = 6; + print_text_centered(160, 80, "SELECT STAGE"); print_text_centered(160, 30, "PRESS START BUTTON"); print_text_fmt_int(40, 60, "%2d", gCurrLevelNum); - print_text(80, 60, gLevelSelect_StageNamesText[gCurrLevelNum - 1]); // print stage name + print_text(80, 60, sLevelSelectStageNames[gCurrLevelNum - 1]); // print stage name #define QUIT_LEVEL_SELECT_COMBO (Z_TRIG | START_BUTTON | L_CBUTTONS | R_CBUTTONS) @@ -135,42 +146,55 @@ s16 level_select_input_loop(void) { return 0; } -s32 intro_default(void) { - s32 sp1C = 0; +/** + * Regular intro function that handles Mario's greeting voice and game start. + */ +s32 intro_regular(void) { + s32 level = LEVEL_NONE; #ifndef VERSION_JP - if (D_U_801A7C34 == 1) { - if (gGlobalTimer < 0x81) { + // When the game stars, gGlobalTimer is less than 129 frames, + // so Mario greets the player. After that, he will always say + // "press start to play" when it goes back to the title screen + // (using SAVE AND QUIT) + if (sPlayMarioGreeting == TRUE) { + if (gGlobalTimer < 129) { play_sound(SOUND_MARIO_HELLO, gGlobalSoundSource); } else { play_sound(SOUND_MARIO_PRESS_START_TO_PLAY, gGlobalSoundSource); } - D_U_801A7C34 = 0; + sPlayMarioGreeting = FALSE; } #endif print_intro_text(); if (gPlayer1Controller->buttonPressed & START_BUTTON) { play_sound(SOUND_MENU_STAR_SOUND, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(60, 70); func_sh_8024C89C(1); #endif - sp1C = 100 + gDebugLevelSelect; + // calls level ID 100 (or 101 adding level select bool value) + // defined in level_intro_mario_head_regular JUMP_IF commands + // 100 is File Select - 101 is Level Select + level = 100 + gDebugLevelSelect; #ifndef VERSION_JP - D_U_801A7C34 = 1; + sPlayMarioGreeting = TRUE; #endif } - return run_press_start_demo_timer(sp1C); + return run_level_id_or_demo(level); } +/** + * Game over intro function that handles Mario's game over voice and game start. + */ s32 intro_game_over(void) { - s32 sp1C = 0; + s32 level = LEVEL_NONE; #ifndef VERSION_JP - if (gameOverNotPlayed == 1) { + if (sPlayMarioGameOver == TRUE) { play_sound(SOUND_MARIO_GAME_OVER, gGlobalSoundSource); - gameOverNotPlayed = 0; + sPlayMarioGameOver = FALSE; } #endif @@ -178,39 +202,47 @@ s32 intro_game_over(void) { if (gPlayer1Controller->buttonPressed & START_BUTTON) { play_sound(SOUND_MENU_STAR_SOUND, gGlobalSoundSource); -#ifdef VERSION_SH +#if ENABLE_RUMBLE queue_rumble_data(60, 70); func_sh_8024C89C(1); #endif - sp1C = 100 + gDebugLevelSelect; + // same criteria as intro_regular + level = 100 + gDebugLevelSelect; #ifndef VERSION_JP - gameOverNotPlayed = 1; + sPlayMarioGameOver = TRUE; #endif } - return run_press_start_demo_timer(sp1C); + return run_level_id_or_demo(level); } +/** + * Plays the casual "It's a me mario" when the game stars. + */ s32 intro_play_its_a_me_mario(void) { set_background_music(0, SEQ_SOUND_PLAYER, 0); play_sound(SOUND_MENU_COIN_ITS_A_ME_MARIO, gGlobalSoundSource); return 1; } -s32 lvl_intro_update(s16 arg1, UNUSED s32 arg2) { +/** + * Update intro functions to handle title screen actions. + * Returns a level ID after their criteria is met. + */ +s32 lvl_intro_update(s16 arg, UNUSED s32 unusedArg) { s32 retVar; - switch (arg1) { - case 0: + switch (arg) { + case LVL_INTRO_PLAY_ITS_A_ME_MARIO: retVar = intro_play_its_a_me_mario(); break; - case 1: - retVar = intro_default(); + case LVL_INTRO_REGULAR: + retVar = intro_regular(); break; - case 2: + case LVL_INTRO_GAME_OVER: retVar = intro_game_over(); break; - case 3: - retVar = level_select_input_loop(); + case LVL_INTRO_LEVEL_SELECT: + retVar = intro_level_select(); break; } return retVar; diff --git a/src/menu/title_screen.h b/src/menu/title_screen.h new file mode 100644 index 00000000..4893158f --- /dev/null +++ b/src/menu/title_screen.h @@ -0,0 +1,17 @@ +#ifndef TITLE_SCREEN_H +#define TITLE_SCREEN_H + +#include + +#include "macros.h" + +enum LevelScriptIntroArgs { + LVL_INTRO_PLAY_ITS_A_ME_MARIO, + LVL_INTRO_REGULAR, + LVL_INTRO_GAME_OVER, + LVL_INTRO_LEVEL_SELECT +}; + +s32 lvl_intro_update(s16 arg, UNUSED s32 unusedArg); + +#endif // TITLE_SCREEN_H diff --git a/src/nds/main.c b/src/nds/main.c index 45c71925..571f94c8 100644 --- a/src/nds/main.c +++ b/src/nds/main.c @@ -10,31 +10,16 @@ #include "game/game_init.h" #include "nds_renderer.h" -OSMesg D_80339BEC; -OSMesgQueue gSIEventMesgQueue; - -s8 gResetTimer; -s8 D_8032C648; -s8 gDebugLevelSelect; -s8 gShowProfiler; -s8 gShowDebugText; - -u8 audio_state; +u8 nds_audio_state; static u8 audio_step; -void set_vblank_handler(UNUSED s32 index, UNUSED struct VblankHandler *handler, UNUSED OSMesgQueue *queue, UNUSED OSMesg *msg) { -} - -void dispatch_audio_sptask(UNUSED struct SPTask *spTask) { -} - -void send_display_list(struct SPTask *spTask) { +void exec_display_list(struct SPTask *spTask) { draw_frame((Gfx*)spTask->task.t.data_ptr); } static void update_audio(void) { // Update audio at the ARM7's request - if (audio_state == 0) { + if (nds_audio_state == 0) { // Update the audio logic at 30 Hz if ((audio_step = (audio_step + 1) & 7) == 0) { update_game_sound(); @@ -44,12 +29,12 @@ static void update_audio(void) { // Update the sequences at 240 Hz process_sequences(0); - } else if (audio_state == 1) { + } else if (nds_audio_state == 1) { // Disable audio for (int i = 0; i < 16; i++) { gNotes[i].enabled = false; } - audio_state = 2; + nds_audio_state = 2; } // Tell the ARM7 it can go ahead diff --git a/src/nds/nds_controller.c b/src/nds/nds_controller.c index 2c66da91..56ef4e2e 100644 --- a/src/nds/nds_controller.c +++ b/src/nds/nds_controller.c @@ -2,7 +2,7 @@ #include "lib/src/osContInternal.h" -extern u8 audio_state; +extern u8 nds_audio_state; s32 osContInit(UNUSED OSMesgQueue *mq, u8 *controllerBits, UNUSED OSContStatus *status) { *controllerBits = 1; @@ -63,6 +63,6 @@ void osContGetReadData(OSContPad *pad) { } if (keysDown() & KEY_SELECT) { - audio_state = !audio_state; + nds_audio_state = !nds_audio_state; } } diff --git a/tools/.gitignore b/tools/.gitignore index d9eb16e4..1be0f736 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -7,7 +7,7 @@ /n64cksum /n64graphics /n64graphics_ci -/patch_libultra_math +/patch_elf_32bit /skyconv /tabledesign /textconv diff --git a/tools/Makefile b/tools/Makefile index e5b493d8..b85d96c4 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -7,7 +7,7 @@ CC := gcc CXX := g++ CFLAGS := -I . -Wall -Wextra -Wno-unused-parameter -pedantic -O2 -s LDFLAGS := -lm -ALL_PROGRAMS := armips n64graphics n64graphics_ci mio0 n64cksum textconv patch_libultra_math aifc_decode aiff_extract_codebook vadpcm_enc tabledesign extract_data_for_mio skyconv adpcm_xq +ALL_PROGRAMS := armips n64graphics n64graphics_ci mio0 n64cksum textconv patch_elf_32bit aifc_decode aiff_extract_codebook vadpcm_enc tabledesign extract_data_for_mio skyconv adpcm_xq LIBAUDIOFILE := audiofile/libaudiofile.a # Only build armips from tools if it is not found on the system @@ -32,7 +32,7 @@ n64cksum_CFLAGS := -DN64CKSUM_STANDALONE textconv_SOURCES := textconv.c utf8.c hashtable.c -patch_libultra_math_SOURCES := patch_libultra_math.c +patch_elf_32bit_SOURCES := patch_elf_32bit.c aifc_decode_SOURCES := aifc_decode.c diff --git a/tools/aiff_extract_codebook.c b/tools/aiff_extract_codebook.c index 78864e38..c229139a 100644 --- a/tools/aiff_extract_codebook.c +++ b/tools/aiff_extract_codebook.c @@ -2,7 +2,6 @@ * Create an ADPCM codebook either by extracting it from an AIFF section, or * by executing tabledesign. */ -#define _XOPEN_SOURCE 500 #include #include #include diff --git a/tools/assemble_sound.py b/tools/assemble_sound.py index 0e5f184e..e1cc9272 100755 --- a/tools/assemble_sound.py +++ b/tools/assemble_sound.py @@ -693,7 +693,7 @@ def serialize_ctl(bank, base_ser, is_shindou): base_ser.add(ser.finish()) return pack( - "BBBB", bank.sample_bank.index, 0xFF, len(json["instrument_list"]), len(drums) + "hh", (bank.sample_bank.index << 8) | 0xFF, (len(json["instrument_list"]) << 8) | len(drums) ) @@ -748,7 +748,8 @@ def serialize_seqfile( ser = ReserveSerializer() ser.add(pack("H", len(entries))) ser.align(16) - sh_magic = 0x0204 if magic == TYPE_TBL else 0x0203 + medium = 0x02 # cartridge + sh_magic = 0x04 if magic == TYPE_TBL else 0x03 # Ignore entry_list and loop over all entries instead. This makes a # difference for sample banks, where US/JP/EU doesn't use a normal @@ -756,9 +757,9 @@ def serialize_seqfile( # sample bank offset/length. Shindou uses a normal header and makes the # mapping part of the sound bank header instead (part of entry_meta). for i in range(len(entries)): - ser.add(pack("PIH", entry_offsets[i], entry_lens[i], sh_magic)) + ser.add(pack("PIbb", entry_offsets[i], entry_lens[i], medium, sh_magic)) ser.add(entry_meta[i] or b"\0\0\0\0") - ser.align(16) + ser.align(WORD_BYTES) if out_header_filename: with open(out_header_filename, "wb") as f: diff --git a/tools/demo_data_converter.py b/tools/demo_data_converter.py index ab656bd7..86ea94c5 100755 --- a/tools/demo_data_converter.py +++ b/tools/demo_data_converter.py @@ -62,7 +62,7 @@ def main(): structdef.append("u8 " + item["name"] + "[" + str(len(demobytes)) + "];") structobj.append("{" + ",".join(hex(x) for x in demobytes) + "},") - print("#include \"types.h\"") + print("#include \"game/memory.h\"") print("#include ") print("") diff --git a/tools/ido5.3_recomp/libc_impl.c b/tools/ido5.3_recomp/libc_impl.c index 929d58fa..af4ca713 100644 --- a/tools/ido5.3_recomp/libc_impl.c +++ b/tools/ido5.3_recomp/libc_impl.c @@ -177,13 +177,13 @@ static char bin_dir[PATH_MAX + 1]; #endif static int g_file_max = 3; -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__APPLE__) static size_t g_Pagesize; #endif static uint8_t *memory_map(size_t length) { -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__APPLE__) uint8_t *mem = mmap(0, length, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); g_Pagesize = sysconf(_SC_PAGESIZE); assert(((uintptr_t)mem & (g_Pagesize-1)) == 0); @@ -201,7 +201,7 @@ static void memory_allocate(uint8_t *mem, uint32_t start, uint32_t end) { assert(start >= MEM_REGION_START); assert(end <= MEM_REGION_START + MEM_REGION_SIZE); -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__APPLE__) uintptr_t _start = ((uintptr_t)mem + start) & ~(g_Pagesize-1); uintptr_t _end = ((uintptr_t)mem + end + (g_Pagesize-1)) & ~(g_Pagesize-1); diff --git a/tools/ido5.3_recomp/recomp.cpp b/tools/ido5.3_recomp/recomp.cpp index 59543056..2bf6e132 100644 --- a/tools/ido5.3_recomp/recomp.cpp +++ b/tools/ido5.3_recomp/recomp.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -21,9 +22,6 @@ #define LABELS_64_BIT 1 -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - #define u32be(x) (uint32_t)(((x & 0xff) << 24) + ((x & 0xff00) << 8) + ((x & 0xff0000) >> 8) + ((uint32_t)(x) >> 24)) #define u16be(x) (uint16_t)(((x & 0xff) << 8) + ((x & 0xff00) >> 8)) #define read_u32_be(buf) (uint32_t)(((buf)[0] << 24) + ((buf)[1] << 16) + ((buf)[2] << 8) + ((buf)[3])) @@ -280,24 +278,31 @@ static const struct { static void disassemble(void) { csh handle; cs_insn *disasm; - static size_t disasm_size; + size_t disasm_size = 0; assert(cs_open(CS_ARCH_MIPS, (cs_mode)(CS_MODE_MIPS64 | CS_MODE_BIG_ENDIAN), &handle) == CS_ERR_OK); cs_option(handle, CS_OPT_DETAIL, CS_OPT_ON); - disasm_size = cs_disasm(handle, text_section, text_section_len, text_vaddr, 0, &disasm); - for (size_t i = 0; i < disasm_size; i++) { - insns.push_back(Insn()); - Insn& insn = insns.back(); - insn.id = disasm[i].id; - insn.mnemonic = disasm[i].mnemonic; - insn.op_str = disasm[i].op_str; - if (disasm[i].detail != nullptr && disasm[i].detail->mips.op_count > 0) { - insn.op_count = disasm[i].detail->mips.op_count; - memcpy(insn.operands, disasm[i].detail->mips.operands, sizeof(insn.operands)); + insns.reserve(1 + text_section_len / sizeof(uint32_t)); // +1 for dummy instruction + while (text_section_len > disasm_size * sizeof(uint32_t)) { + size_t disasm_len = disasm_size * sizeof(uint32_t); + size_t remaining = text_section_len - disasm_len; + size_t current_len = std::min(remaining, 1024); + size_t cur_disasm_size = cs_disasm(handle, &text_section[disasm_len], current_len, text_vaddr + disasm_len, 0, &disasm); + disasm_size += cur_disasm_size; + for (size_t i = 0; i < cur_disasm_size; i++) { + insns.push_back(Insn()); + Insn& insn = insns.back(); + insn.id = disasm[i].id; + insn.mnemonic = disasm[i].mnemonic; + insn.op_str = disasm[i].op_str; + if (disasm[i].detail != nullptr && disasm[i].detail->mips.op_count > 0) { + insn.op_count = disasm[i].detail->mips.op_count; + memcpy(insn.operands, disasm[i].detail->mips.operands, sizeof(insn.operands)); + } + insn.is_jump = cs_insn_group(handle, &disasm[i], MIPS_GRP_JUMP) || insn.id == MIPS_INS_JAL || insn.id == MIPS_INS_BAL || insn.id == MIPS_INS_JALR; + insn.linked_insn = -1; } - insn.is_jump = cs_insn_group(handle, &disasm[i], MIPS_GRP_JUMP) || insn.id == MIPS_INS_JAL || insn.id == MIPS_INS_BAL || insn.id == MIPS_INS_JALR; - insn.linked_insn = -1; + cs_free(disasm, cur_disasm_size); } - cs_free(disasm, disasm_size); cs_close(&handle); { @@ -334,7 +339,7 @@ static void link_with_lui(int offset, uint32_t reg, int mem_imm) #define MAX_LOOKBACK 128 // don't attempt to compute addresses for zero offset // end search after some sane max number of instructions - int end_search = MAX(0, offset - MAX_LOOKBACK); + int end_search = std::max(0, offset - MAX_LOOKBACK); for (int search = offset - 1; search >= end_search; search--) { // use an `if` instead of `case` block to allow breaking out of the `for` loop if (insns[search].id == MIPS_INS_LUI) { @@ -421,7 +426,7 @@ static void link_with_lui(int offset, uint32_t reg, int mem_imm) static void link_with_jalr(int offset) { // end search after some sane max number of instructions - int end_search = MAX(0, offset - MAX_LOOKBACK); + int end_search = std::max(0, offset - MAX_LOOKBACK); for (int search = offset - 1; search >= end_search; search--) { if (insns[search].operands[0].reg == MIPS_REG_T9) { if (insns[search].id == MIPS_INS_LW || insns[search].id == MIPS_INS_LI) { @@ -2332,16 +2337,16 @@ static void dump_c(void) { uint32_t max_addr = 0; if (data_section_len > 0) { - min_addr = MIN(min_addr, data_vaddr); - max_addr = MAX(max_addr, data_vaddr + data_section_len); + min_addr = std::min(min_addr, data_vaddr); + max_addr = std::max(max_addr, data_vaddr + data_section_len); } if (rodata_section_len > 0) { - min_addr = MIN(min_addr, rodata_vaddr); - max_addr = MAX(max_addr, rodata_vaddr + rodata_section_len); + min_addr = std::min(min_addr, rodata_vaddr); + max_addr = std::max(max_addr, rodata_vaddr + rodata_section_len); } if (bss_section_len) { - min_addr = MIN(min_addr, bss_vaddr); - max_addr = MAX(max_addr, bss_vaddr + bss_section_len); + min_addr = std::min(min_addr, bss_vaddr); + max_addr = std::max(max_addr, bss_vaddr + bss_section_len); } min_addr = min_addr & ~0xfff; diff --git a/tools/mario_anims_converter.py b/tools/mario_anims_converter.py index 361662ae..fcf92a54 100755 --- a/tools/mario_anims_converter.py +++ b/tools/mario_anims_converter.py @@ -136,7 +136,7 @@ try: structdef.append("{} {}[{}];".format(type, name, len(arr))) structobj.append("{" + ",".join(arr) + "},") - print("#include \"types.h\"") + print("#include \"game/memory.h\"") print("#include ") print("") diff --git a/tools/output_level_headers.py b/tools/output_level_headers.py deleted file mode 100644 index a1ea4aa0..00000000 --- a/tools/output_level_headers.py +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env python3 -import sys -for line in sys.stdin: - if line.strip(): - print('#include "{}"'.format(line.strip())) diff --git a/tools/patch_libultra_math.c b/tools/patch_elf_32bit.c similarity index 68% rename from tools/patch_libultra_math.c rename to tools/patch_elf_32bit.c index e6bdcc0c..8e529520 100644 --- a/tools/patch_libultra_math.c +++ b/tools/patch_elf_32bit.c @@ -3,6 +3,9 @@ #include #include +#define ARMAG "!\n" +#define SARMAG 8 + /* from elf.h */ /* Type for a 16-bit quantity. */ @@ -78,13 +81,36 @@ struct ar_header { //These constants found by inspecting output of objdump #define FLAGS_MIPS3 0x20 #define FLAGS_O32ABI 0x100000 -int main(int argc, char **argv) { - FILE *f = fopen(argv[1], "r+"); - if (f == NULL) { - printf("Failed to open file! %s\n", argv[1]); +int fix_mips_elf(FILE *f, size_t filesize) +{ + Elf32_Ehdr hdr; + if (filesize < sizeof(hdr) || (1 != fread(&hdr, sizeof(hdr), 1, f))) { + printf("Failed to read ELF header\n"); return -1; } + + if (strncmp((const char *) hdr.e_ident, ELFMAG, SELFMAG) == 0) { + // found an ELF file. + if (hdr.e_ident[EI_CLASS] != ELFCLASS32 || hdr.e_ident[EI_DATA] != ELFDATA2MSB) { + printf("Expected 32bit big endian object files\n"); + return -1; + } + + if ((hdr.e_flags & 0xFF) == FLAGS_MIPS3 && (hdr.e_flags & FLAGS_O32ABI) == 0) { + hdr.e_flags |= FLAGS_O32ABI; + fseek(f, -(long)sizeof(hdr), SEEK_CUR); + if (1 != fwrite(&hdr, sizeof(hdr), 1, f)) { + printf("Failed to write back ELF header after patching.\n"); + return -1; + } + } + } + return 0; +} + +int fix_mips_ar(FILE *f) +{ struct ar_header current_header; fseek(f, 0x8, SEEK_SET); // skip header, this is safe enough given that we check to make sure the // file header is valid @@ -95,32 +121,41 @@ int main(int argc, char **argv) { return -1; } size_t filesize = atoi(current_header.file_size_in_bytes); - Elf32_Ehdr hdr; - if (filesize < sizeof(hdr) || (1 != fread(&hdr, sizeof(hdr), 1, f))) { - printf("Failed to read ELF header\n"); + if (fix_mips_elf(f, filesize)) { return -1; } - - if (strncmp((const char *) hdr.e_ident, ELFMAG, SELFMAG) == 0) { - // found an ELF file. - if (hdr.e_ident[EI_CLASS] != ELFCLASS32 || hdr.e_ident[EI_DATA] != ELFDATA2MSB) { - printf("Expected 32bit big endian object files\n"); - return -1; - } - - if ((hdr.e_flags & 0xFF) == FLAGS_MIPS3 && (hdr.e_flags & FLAGS_O32ABI) == 0) { - hdr.e_flags |= FLAGS_O32ABI; - fseek(f, -sizeof(hdr), SEEK_CUR); - if (1 != fwrite(&hdr, sizeof(hdr), 1, f)) { - printf("Failed to write back ELF header after patching.\n"); - return -1; - } - } - } if (filesize % 2 == 1) filesize++; - fseek(f, filesize - sizeof(hdr), SEEK_CUR); + fseek(f, filesize - sizeof(Elf32_Ehdr), SEEK_CUR); } - fclose(f); return 0; } + +int main(int argc, char **argv) { + FILE *f = fopen(argv[1], "r+b"); + uint8_t magic[8]; + int status = 0; + + if (f == NULL) { + printf("Failed to open file! %s\n", argv[1]); + return -1; + } + if (1 != fread(&magic, sizeof(magic), 1, f)) { + printf("Failed to read file magic\n"); + return -1; + } + rewind(f); + if (!memcmp(ARMAG, magic, SARMAG)) { + status = fix_mips_ar(f); + } else if (!memcmp(ELFMAG, magic, SELFMAG)) { + fseek(f, 0, SEEK_END); + size_t filesize = ftell(f); + rewind(f); + status = fix_mips_elf(f, filesize); + } else { + printf("Unknown file magic: %02x%02x%02X%02X\n", magic[0], magic[1], magic[2], magic[3]); + status = -1; + } + fclose(f); + return status; +} diff --git a/tools/seq_decoder.py b/tools/seq_decoder.py index ce238209..9329e702 100755 --- a/tools/seq_decoder.py +++ b/tools/seq_decoder.py @@ -162,8 +162,8 @@ if len(sys.argv) != 2: sys.exit(0) if sys.argv[1] == "--emit-asm-macros": - print("# Macros for disassembled sequence files. This file was automatically generated by seq_decoder.py.") - print("# To regenerate it, run: ./tools/seq_decoder.py --emit-asm-macros >seq_macros.inc") + print("// Macros for disassembled sequence files. This file was automatically generated by seq_decoder.py.") + print("// To regenerate it, run: ./tools/seq_decoder.py --emit-asm-macros > include/seq_macros.inc") print() def print_hword(x): print(f" .byte {x} >> 8, {x} & 0xff") @@ -219,7 +219,7 @@ if sys.argv[1] == "--emit-asm-macros": print(".endm\n") for key in ['seq', 'chan', 'layer']: - print(f"# {key} commands\n") + print(f"// {key} commands\n") if key == 'layer': cmds = commands['layer_large'] for op in sorted(commands['layer_small'].keys()): @@ -267,31 +267,31 @@ if sys.argv[1] == "--emit-asm-macros": emit_cmd(key, 0xc0, ['delay_long', 'var_long']) emit_cmd(key, 0x40, ['note1_long', 'bits:4', 'var_long', 'u8']) if eu_sh or us_jp or sh or non_sh: - print(".ifdef VERSION_SH\n") + print("#ifdef VERSION_SH\n") for (op, cmd) in eu_sh: emit_cmd(key, op, cmd) for (op, cmd) in sh: emit_cmd(key, op, cmd) - print(".else\n") + print("#else\n") for (op, cmd) in non_sh: emit_cmd(key, op, cmd) - print(".ifdef VERSION_EU\n") + print("#ifdef VERSION_EU\n") for (op, cmd) in eu_sh: emit_cmd(key, op, cmd) - print(".else\n") + print("#else\n") for (op, cmd) in us_jp: emit_cmd(key, op, cmd) - print(".endif\n") - print(".endif\n") + print("#endif\n") + print("#endif\n") - print("# envelope commands\n") + print("// envelope commands\n") emit_env_cmd(0, ['disable', 'u16']) emit_env_cmd(2**16-1, ['hang', 'u16:ign']) emit_env_cmd(2**16-2, ['goto', 'u16']) emit_env_cmd(2**16-3, ['restart', 'u16:ign']) emit_env_cmd(None, ['line', 'u16', 'u16']) - print("# other commands\n") + print("// other commands\n") print(".macro var_long x") print(" .byte (0x80 | (\\x & 0x7f00) >> 8), (\\x & 0xff)") print(".endm\n")