HackerSM64 v2.0.0

* buffers: refresh 15 and revert to base decomp

* behavior script

* color helper functions

* extended bounds

* egeo_layout

* fixed model ids

* camera conf improved

* message panel ucode small

* graph node

* level script

* mathutil updates

* mathutil updates (allow unused funcs)

* behaviors a - beta_fish

* Add librtc and fix some data declarations

* Move GRUCODE define to proper location in makefile

* Refresh 15

* extra

* Make ROM name smaller and change messages printed on build a bit

* Fix console (lol)

* Update UNF to latest master

* Make ucode load from .o's (and also fix Super3D)

* Fix crash with rumble + custom mario model

* graph node and mathutil

* removed behaviors

* Ldtob documentation

* _Putfld labeling

* area

* behavior actions

* camera

* debug updates

* bubbles

* envfx snow

* farcall helpers

* game init

* geo misc

* hud

* only check if VC on render init

* ingame menu

* revert goddard to base decomp

* insn disasm

* interaction documentation

* level geo

* level update defines

* macro special objects formatting changes

* main.h documentation

* map parser documentation & formatting

* airborne documentation

* mario actions automatic documentation

* mario actions cutscene documentation

* mario actions moving documentation and options

* mario actions object documentation and options

* mario stationary documentation

* mario submerged documentation

* mario misc documentation

* mario step: ledge grab fixes and documentation

* mario documentation

* memory.h documentation

* moving textures

* object behaviors

* object collision

* fix flamethrower bug

* object helpers

* object list processor documentation

* paintings

* platform displacement

* print / printf

* puppycam absf

* puppyprint updates and formatting changes

* rendering graph node performance optimizations

* rumble opt and doc

* hqvm back to ultrasm64

* save file documentation and unlock defines

* s2d engine

* reset various files to ultrasm64

* file select

* intro geo documentation

* screen transition documentation

* segment2.h

* shadow overhaul

* skybox refactor

* sound init: clean up define usage + documentation

* spawn object optimizations and documentation

* spawn sound cleanup

* sram to ultrasm64

* star select cleanup

* title screen cleanup

* dialogs / text

* rename stomp smoke

* stomp smoke -> small water splash

* updated README

* compilation flags

* optimized file positions + support function/data sections

* surface collision performance improvements

* surface load optimizations

* camera conf documentation

* Allow easier command for opening puppyprint debug

* Rearranged framebuffers & fixed puppyprint console printing

* Fix shadow scaling and shifting

* Fix SILHOUETTE, OBJECTS_REJ, and ucode loading, also clean up render phase system a bit.

* Fixed build with BETTER_HANGING off

* Clean up OBJECTS_REJ ifdefs

* Fix duplicate comment & graph render layers/flags bitmask

* Fixed build with BETTER_HANGING off

* Fix Fast64 importing by reverting sSegmentTable change

* Readded missing functions that caused build errors with Mario head enabled

* Fixed clang compilation issues

* Add INTER mode for geo_update_layer_transparency

* Fix build warnings

* bugfix: miscalculation in obj_turn_toward_object

* Some puppytech fixes

* Further Puppycamera fixes

* Fix BUGFIX_DIALOG_TIME_STOP

Fixes #136

* Fix sliding platform bparams

* Add LEGACY_SHADOW_IDS define for Fast64 compatibility

* Apply suggested changes

* Better find_in_bounds_yaw_wdw_bob_thi ifdef

* Fix build warnings for unused functions

* Fixed stale reference bug from obj_mark_for_deletion change

* Fixed incorrect digit for 100s #145

* Change groundpound-fix define and functionality to just disable bonking

* Fixed puppyroll #134

* Adjust height value for terrain angle to kick in

* fixed hi score flashing

* Remove menudata backup (#131)

Not considered important enough to keep

* Fix fread() build warning

* Add COURSE_NUM_TO_INDEX to save_file_get_star_flags check in bhv_unagi_init

* Fix approach_s16 return value

* Use boolean defines for oCapDoScaleVertically

* Make the door lock a part of the key door model to eliminate z-fighting, also reduce z fighting on numbered doors with AUTO_LOD enabled.

* Move flames to LAYER_TRANSPARENT_INTER

* Resolved some compiler warnings and added FALL_THROUGH define (#168)

* Address some more compiler warnings with different define toggles

* Remove unnecessary fallthrough attribute

* fixed geo_process_billboard floating point exception

* Allow water to face any direction

* Initialize focOffset so that BBH doesn't crash

* Removed superfluous RDP commands when switching microcodes which would override scissor

* Set OBJ_FLAG_DONT_CALC_COLL_DIST on bhvUkikiCage

* Fix rumble build

* Fixed UNLOCK_FPS strobing

* Update src/game/object_helpers.c

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>

* Update src/game/object_helpers.c

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>

* Fix LEGACY_SHADOW_IDS id conflict

* Use the vanilla default value for rotating fire bars if bparam2 is 0

* START_LEVEL safeguard

* Fix some drawing distance issues caused by AUTO_COLLISION_DISTANCE

* Fix rumble build

* Fixed spline poll code using the wrong values for keyframes

* Update readme with better credits

Better credits for individual contributors

* add arthur

* added falco and moose

* add fazana

* le funny typo

* added S2DEX engine to credits

* silhouette + axo + ratio

* remove specific callouts + add auto col distance

* Update data/behavior_data.c

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>

* Update data/behavior_data.c

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>

* Update data/behavior_data.c

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>

* Revert formatting changes to match vanilla decomp

* Re-implement Y buffer for find_ceil

* Re-implement POWER_STARS_HEAL for normal Power Stars

* Start level comment & exit course comment/collapse

* utilize reonucam technique for FAST_VERTICAL_CAMERA_MOVEMENT

* Fix "MAX_REFERENCED_WALLS" typo

* Allow stop_and_set_height_to_floor to work at any height if Mario is teleporting (#213)

* Revert stop_and_set_height_to_floor to vanilla

Fixes #208

* Fixed sAudioEnabled so that it disables audio CPU processing as well

* Fixed puppyprint debug RDP us calculations

* Renamed sAudioEnabled to gAudioEnabled

* Replaced mtxf_to_mtx_asm with an equivalent implementation that supports WORLD_SCALE

* Moved extended bounds and world scale configuration to a new config_world.h file

* Default all objects to non-rej (#227)

Fixes #221 (Default all objects to non-rej)

* Fix #221

* Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled (#211)

* Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled

* Change vtl decrement in visual_surface_display from 6 to 3

Fixes #207

* Make area in SL igloo wider to prevent a softlock (#233)

Fixes #210

* Fix coin formation coins being deleted if they spawn in the middle of a floor, also fix TTM slide coin position (#232)

Fixes #201

* Make UNLOCK_ALL apply to more things

* Fix wrong ifdef/ifndef in bhv_invisible_objects_under_bridge_init

* Change chain chomp load/unload distances depending on number of segments (#237)

Fixes #192

* added WATER_PLUNGE_UPWARP define

* Add reonucam patch (#239)

* added reonucam patch
Fixes #218

* Fix how shadows handle water/transparency/height (#228)

* Fix how shadows handle water/transparency/height

* Change shadow check for flying carpets from a level specific check to a oPlatformOnTrackType check

Fixes #179

* added reonucam credit

* delete unnecesary patches

* Apply suggested changes

* murdered more patches

* UNLOCK_ALL unlocks the cap boxes

* UNLOCK_ALL unlocks cap boxes (slightly more epic edition)

* revert ceil buffer

* Renamed HD_INTRO_TEXTURES define, separated intro floombas

* prevent double definition of floombas

* actually prevent floomba redefinition

* Develop/refactor  default defines (#242)

* Changed default config options

* Added build dir to includePaths for pngs

* disable NO_SLEEP by default

* Disable puppyprint by default

Sorry fazana 😔

* fix typos

* add comment about BETTER_REVERB console perf

* disable blue coin switch retry by default

* Update config_audio.h

Co-authored-by: Reonu <danileon95@gmail.com>
Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com>

* revert air step line to vanilla to fix bitfs scaling platform issue (#247)

Fixes #200

* Fix stuttering on thin slopes (#248)

* Fix stuttering on thin slopes

* Revert vec3f_find_ceil calls to vanilla

* Rename vec3f_find_ceil to find_mario_ceil

* Update src/engine/surface_collision.h

Fixes #249

* Swap static and dynamic surface checks back to vanilla order (#253)

* Swap static and dynamic surface checks back to vanilla order

* re-enable DISABLE_ALL config

Fixes #251 #252

* Fixed save and quitting while in widescreen (#257)

* Fixed save and quitting while in widescreen

* use define for the level

* all my homies hate ifdefs

* skip wall offsets < 0 (#255)

Fixes #255

* #264: Document non-stop stars' issues (#267)

* #264: Document non-stop stars' issues

* Update include/config/config_game.h

* nonstop vanilla comment

* derive margin_radius from radius after capping at 200 (#266)

Fixes #259

* Config cleanup/refactor (#269)

* Moved puppyprint define to graphics / rearranged some debug defines for ease of access

* Moved compatibility safeguards to config_safeguards.h

* spacing and comment formatting

* #272 Move GFX_POOL_SIZE to config_graphics.h

* disable EASIER_DIALOG_TRIGGER by default

* prevent redefining warnings

* small ifdef typo

* changed ifndef to undefs

Fixes #262
Fixes #272

* Improved movement config documentation related to turning around (#271)

Fixes #270

* rename CUSTOM_DEBUG, add comments (#275)

* Update README.md (#277)

* v2.0.0

Co-authored-by: CrashOveride95 <crashoveride953@gmail.com>
Co-authored-by: Arceveti <73617174+Arceveti@users.noreply.github.com>
Co-authored-by: n64 <n64>
Co-authored-by: Fazana <52551480+FazanaJ@users.noreply.github.com>
Co-authored-by: Mr-Wiseguy <mrwiseguyromhacking@gmail.com>
Co-authored-by: aglab2 <aglab3@gmail.com>
Co-authored-by: gheskett <gheskett@gmail.com>
Co-authored-by: Reonu <danileon95@gmail.com>
Co-authored-by: Axollyon <20480418+Axollyon@users.noreply.github.com>
Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com>
This commit is contained in:
+1 authored and GitHub committed 2021-12-30 16:57:51 +00:00
1 parent 3a558060ab
commit f3e61a31aa
924 files changed
+44258 -30676

No files matched your search

+14 -22
View File
@@ -4,31 +4,23 @@
#ifdef VERSION_SH
struct ReverbSettingsEU sReverbSettings[] = {
{0x01, 0x30, 0x2fff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000},
{0x01, 0x28, 0x47ff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000},
{0x01, 0x40, 0x2fff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000},
{0x01, 0x38, 0x3fff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000},
{0x01, 0x30, 0x4fff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000},
{0x01, 0x28, 0x37ff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000},
{ 0x01, 0x30, 0x2fff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000 },
{ 0x01, 0x28, 0x47ff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000 },
{ 0x01, 0x40, 0x2fff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000 },
{ 0x01, 0x38, 0x3fff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000 },
{ 0x01, 0x30, 0x4fff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000 },
{ 0x01, 0x28, 0x37ff, 0x0000, 0x0000, -1, 0x3000, 0x0000, 0x0000 },
};
struct AudioSessionSettingsEU gAudioSessionPresets[] = {
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[0], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
0x00000000, 0x00004400, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[1], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
0x00000000, 0x00004400, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[2], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
0x00000000, 0x00004400, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[3], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
0x00000000, 0x00004400, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[4], 0x7fff, 0x0000, 0x00003a40, 0x00006d00,
0x00000000, 0x00004400, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[0], 0x7fff, 0x0000, 0x00004000, 0x00006e00,
0x00000000, 0x00003f00, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[1], 0x7fff, 0x0000, 0x00004100, 0x00006e00,
0x00000000, 0x00004400, 0x00002a80, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x14, 0x01, 0x00, &sReverbSettings[5], 0x7fff, 0x0000, 0x00003500, 0x00006280,
0x00000000, 0x00004000, 0x00001b00, 0x00000000, 0x00000000, 0x00000000 }
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[0], 0x7fff, 0x0000, 0x00003a40, 0x00006d00, 0x00000000, 0x00004400, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[1], 0x7fff, 0x0000, 0x00003a40, 0x00006d00, 0x00000000, 0x00004400, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[2], 0x7fff, 0x0000, 0x00003a40, 0x00006d00, 0x00000000, 0x00004400, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[3], 0x7fff, 0x0000, 0x00003a40, 0x00006d00, 0x00000000, 0x00004400, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[4], 0x7fff, 0x0000, 0x00003a40, 0x00006d00, 0x00000000, 0x00004400, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[0], 0x7fff, 0x0000, 0x00004000, 0x00006e00, 0x00000000, 0x00003f00, 0x00002a00, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x10, 0x01, 0x00, &sReverbSettings[1], 0x7fff, 0x0000, 0x00004100, 0x00006e00, 0x00000000, 0x00004400, 0x00002a80, 0x00000000, 0x00000000, 0x00000000 },
{ 0x00007d00, 0x01, 0x14, 0x01, 0x00, &sReverbSettings[5], 0x7fff, 0x0000, 0x00003500, 0x00006280, 0x00000000, 0x00004000, 0x00001b00, 0x00000000, 0x00000000, 0x00000000 }
};
s16 gTatumsPerBeat = TATUMS_PER_BEAT;
@@ -11,14 +11,6 @@
#include "audio/external.h"
#include "audio/effects.h"
#define PORTAMENTO_IS_SPECIAL(x) ((x).mode & 0x80)
#define PORTAMENTO_MODE(x) ((x).mode & ~0x80)
#define PORTAMENTO_MODE_1 1
#define PORTAMENTO_MODE_2 2
#define PORTAMENTO_MODE_3 3
#define PORTAMENTO_MODE_4 4
#define PORTAMENTO_MODE_5 5
#define COPT 0
#if COPT
#define M64_READ_U8(state, dst) \
@@ -35,7 +27,6 @@
}
#endif
#if COPT
#define M64_READ_S16(state, dst) \
dst = m64_read_s16(state);
@@ -115,23 +106,20 @@ struct Instrument **instOut = _instOut;\
#endif
void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
struct SequencePlayer *seqPlayer; // sp5C, t4
struct SequenceChannel *seqChannel; // sp58, t5
struct M64ScriptState *state;
struct Portamento *portamento;
struct AudioBankSound *sound;
struct Instrument *instrument;
struct Drum *drum;
s32 temp_a0_5;
u8 sameSound;
u8 cmd; // a0 sp3E, EU s2
u8 cmdSemitone; // sp3D, t0
u16 sp3A = 0; // t2, a0, a1
f32 tuning; // f0
s32 vel = 0; // sp30, t3
s32 vel = 0; // sp30, t3
s32 usedSemitone; // a1
f32 freqScale = 0.0f; // sp28, f0
f32 sp24 = 0.0f;
f32 sp24 = 0.0f;
f32 temp_f12;
f32 temp_f2;
@@ -143,7 +131,7 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
#pragma inline routine(get_instrument)
#endif
sameSound = TRUE;
u8 sameSound = TRUE;
if ((*layer).enabled == FALSE) {
return;
}
@@ -166,8 +154,8 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
layer->portamento.mode = 0;
}
seqChannel = (*layer).seqChannel;
seqPlayer = (*seqChannel).seqPlayer;
struct SequenceChannel *seqChannel = (*layer).seqChannel;
struct SequencePlayer *seqPlayer = (*seqChannel).seqPlayer;
for (;;) {
state = &layer->scriptState;
//M64_READ_U8(state, cmd);
@@ -222,7 +210,7 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
if (cmd == 0xc1) {
layer->velocitySquare = (f32)(temp_a0_5 * temp_a0_5);
} else {
layer->pan = (f32) temp_a0_5 / US_FLOAT(128.0);
layer->pan = (f32) temp_a0_5 / 128.0f;
}
break;
@@ -373,7 +361,7 @@ l1138:
} else {
layer->adsr.envelope = drum->envelope;
layer->adsr.releaseRate = drum->releaseRate;
layer->pan = FLOAT_CAST(drum->pan) / US_FLOAT(128.0);
layer->pan = FLOAT_CAST(drum->pan) / 128.0f;
layer->sound = &drum->sound;
layer->freqScale = layer->sound->tuning;
}
@@ -424,13 +412,13 @@ l1138:
goto l13cc;
}
l13cc:
portamento->extent = sp24 / freqScale - US_FLOAT(1.0);
portamento->extent = sp24 / freqScale - 1.0f;
if (PORTAMENTO_IS_SPECIAL((*layer).portamento)) {
portamento->speed = US_FLOAT(32512.0) * FLOAT_CAST((*seqPlayer).tempo)
portamento->speed = 32512.0f * FLOAT_CAST((*seqPlayer).tempo)
/ ((f32)(*layer).delay * (f32) gTempoInternalToExternal
* FLOAT_CAST((*layer).portamentoTime));
} else {
portamento->speed = US_FLOAT(127.0) / FLOAT_CAST((*layer).portamentoTime);
portamento->speed = 127.0f / FLOAT_CAST((*layer).portamentoTime);
}
portamento->cur = 0.0f;
layer->freqScale = freqScale;
+51 -42
View File
@@ -8,19 +8,19 @@ extern struct OSMesgQueue OSMesgQueue1;
extern struct OSMesgQueue OSMesgQueue2;
extern struct OSMesgQueue OSMesgQueue3;
//Since the audio session is just one now, the reverb settings are duplicated to match the original audio setting scenario.
//It's a bit hacky but whatever lol. Index range must be defined, since it's needed by the compiler.
//To increase reverb window sizes beyond 64, please increase the REVERB_WINDOW_SIZE_MAX in heap.c by a factor of 0x40 and update AUDIO_HEAP_SIZE by 4x the same amount.
// Since the audio session is just one now, the reverb settings are duplicated to match the original audio setting scenario.
// It's a bit hacky but whatever lol. Index range must be defined, since it's needed by the compiler.
// To increase reverb window sizes beyond 64, please increase the REVERB_WINDOW_SIZE_MAX in heap.c by a factor of 0x40 and update AUDIO_HEAP_SIZE by 4x the same amount.
#ifdef VERSION_EU
struct ReverbSettingsEU sReverbSettings[8] = {
{/*Downsample Rate*/ 1,/*Window Size*/ 64,/*Gain*/ 0x2FFF },
{/*Downsample Rate*/ 1,/*Window Size*/ 40,/*Gain*/ 0x47FF },
{/*Downsample Rate*/ 1,/*Window Size*/ 64,/*Gain*/ 0x2FFF },
{/*Downsample Rate*/ 1,/*Window Size*/ 60,/*Gain*/ 0x3FFF },
{/*Downsample Rate*/ 1,/*Window Size*/ 48,/*Gain*/ 0x4FFF },
{/*Downsample Rate*/ 1,/*Window Size*/ 64,/*Gain*/ 0x2FFF }, //Duplicate of the first index
{/*Downsample Rate*/ 1,/*Window Size*/ 40,/*Gain*/ 0x47FF }, //Duplicate of the second index
{/*Downsample Rate*/ 1,/*Window Size*/ 40,/*Gain*/ 0x37FF },
{ /*Downsample Rate*/ 1, /*Window Size*/ 64, /*Gain*/ 0x2FFF },
{ /*Downsample Rate*/ 1, /*Window Size*/ 40, /*Gain*/ 0x47FF },
{ /*Downsample Rate*/ 1, /*Window Size*/ 64, /*Gain*/ 0x2FFF },
{ /*Downsample Rate*/ 1, /*Window Size*/ 60, /*Gain*/ 0x3FFF },
{ /*Downsample Rate*/ 1, /*Window Size*/ 48, /*Gain*/ 0x4FFF },
{ /*Downsample Rate*/ 1, /*Window Size*/ 64, /*Gain*/ 0x2FFF }, // Duplicate of the first index
{ /*Downsample Rate*/ 1, /*Window Size*/ 40, /*Gain*/ 0x47FF }, // Duplicate of the second index
{ /*Downsample Rate*/ 1, /*Window Size*/ 40, /*Gain*/ 0x37FF },
};
/**
1: Frequency
@@ -38,9 +38,9 @@ struct ReverbSettingsEU sReverbSettings[8] = {
struct AudioSessionSettingsEU gAudioSessionPresets[] = {
#ifdef EXPAND_AUDIO_HEAP
{/*1*/ 32000,/*2*/ 1,/*3*/ 40,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x8200,/*9*/ 0xDC00,/*10*/ 0xE800,/*11*/ 0x5500 },
{ /*1*/ 32000,/*2*/ 1,/*3*/ 40,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x8200,/*9*/ 0xDC00,/*10*/ 0xE800,/*11*/ 0x5500 },
#else
{/*1*/ 32000,/*2*/ 1,/*3*/ 20,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x4100,/*9*/ 0x6E00,/*10*/ 0x7400,/*11*/ 0x2A80 },
{ /*1*/ 32000,/*2*/ 1,/*3*/ 20,/*4*/ 1,/*5*/ 0, &sReverbSettings[0],/*6*/ 0x7FFF,/*7*/ 0,/*8*/ 0x4100,/*9*/ 0x6E00,/*10*/ 0x7400,/*11*/ 0x2A80 },
#endif
};
#endif
@@ -59,26 +59,25 @@ struct AudioSessionSettingsEU gAudioSessionPresets[] = {
// To increase reverb window sizes beyond 0x1000, please increase the REVERB_WINDOW_SIZE_MAX in heap.c and update AUDIO_HEAP_SIZE by the same amount.
#if defined(VERSION_JP) || defined(VERSION_US)
struct ReverbSettingsUS gReverbSettings[18] =
{
{1, 0x0C00, 0x2FFF},
{1, 0x0A00, 0x47FF},
{1, 0x1000, 0x2FFF},
{1, 0x0E00, 0x3FFF},
{1, 0x0C00, 0x4FFF},
{1, 0x0C00, 0x2FFF},
{1, 0x0A00, 0x47FF},
{1, 0x0800, 0x37FF},
{1, 0x0800, 0x2FFF},
{1, 0x0800, 0x3FFF},
{1, 0x1000, 0x3FFF},
{1, 0x1000, 0x2FFF},
{1, 0x0C00, 0x3FFF},
{1, 0x0800, 0x4FFF},
{1, 0x0800, 0x2FFF},
{1, 0x0800, 0x2FFF},
{1, 0x0800, 0x2FFF},
{1, 0x0800, 0x2FFF},
struct ReverbSettingsUS gReverbSettings[18] = {
{ 1, 0x0C00, 0x2FFF },
{ 1, 0x0A00, 0x47FF },
{ 1, 0x1000, 0x2FFF },
{ 1, 0x0E00, 0x3FFF },
{ 1, 0x0C00, 0x4FFF },
{ 1, 0x0C00, 0x2FFF },
{ 1, 0x0A00, 0x47FF },
{ 1, 0x0800, 0x37FF },
{ 1, 0x0800, 0x2FFF },
{ 1, 0x0800, 0x3FFF },
{ 1, 0x1000, 0x3FFF },
{ 1, 0x1000, 0x2FFF },
{ 1, 0x0C00, 0x3FFF },
{ 1, 0x0800, 0x4FFF },
{ 1, 0x0800, 0x2FFF },
{ 1, 0x0800, 0x2FFF },
{ 1, 0x0800, 0x2FFF },
{ 1, 0x0800, 0x2FFF },
};
// TODO: Does using 40/20 instead of 32/16 for gMaxSimultaneousNotes cause memory problems at high capacities or is it good as is?
@@ -102,15 +101,15 @@ u16 gAudioCosineTable[128] = {
26220, 25975, 25726, 25473, 25216, 24956, 24691, 24423, 24151, 23875, 23596, 23313, 23026,
22736, 22442, 22145, 21845, 21541, 21234, 20924, 20610, 20294, 19974, 19651, 19325, 18997,
18665, 18331, 17993, 17653, 17310, 16965, 16617, 16266, 15913, 15558, 15200, 14840, 14477,
14113, 13746, 13377, 13006, 12633, 12258, 11881, 11503, 11122, 10740, 10357, 9971, 9584,
9196, 8806, 8415, 8023, 7630, 7235, 6839, 6442, 6044, 5646, 5246, 4845, 4444,
4042, 3640, 3237, 2833, 2429, 2025, 1620, 1216, 810, 405, 0,
14113, 13746, 13377, 13006, 12633, 12258, 11881, 11503, 11122, 10740, 10357, 9971, 9584,
9196, 8806, 8415, 8023, 7630, 7235, 6839, 6442, 6044, 5646, 5246, 4845, 4444,
4042, 3640, 3237, 2833, 2429, 2025, 1620, 1216, 810, 405, 0,
};
#endif
// Transforms a pitch scale factor in -127..127 into a frequency scale factor
// between -1 and +1 octave.
// gPitchBendFrequencyScale[k] = 0.5 * 2^(k/127)
// gPitchBendFrequencyScale[k] = (0.5 * 2^(k/127))
#ifndef VERSION_SH
#if defined(VERSION_EU)
f32 gPitchBendFrequencyScale[256] = {
@@ -118,7 +117,7 @@ f32 gPitchBendFrequencyScale[256] = {
#else
f32 gPitchBendFrequencyScale[255] = {
#endif
0.5f, 0.502736f, 0.505488f, 0.508254f, 0.511036f, 0.513833f, 0.516645f, 0.519472f, 0.522315f,
0.500000f, 0.502736f, 0.505488f, 0.508254f, 0.511036f, 0.513833f, 0.516645f, 0.519472f, 0.522315f,
0.525174f, 0.528048f, 0.530938f, 0.533843f, 0.536765f, 0.539702f, 0.542656f, 0.545626f, 0.548612f,
0.551614f, 0.554633f, 0.557669f, 0.560721f, 0.563789f, 0.566875f, 0.569977f, 0.573097f, 0.576233f,
0.579387f, 0.582558f, 0.585746f, 0.588951f, 0.592175f, 0.595415f, 0.598674f, 0.601950f, 0.605245f,
@@ -132,7 +131,7 @@ f32 gPitchBendFrequencyScale[255] = {
0.858284f, 0.862982f, 0.867704f, 0.872453f, 0.877228f, 0.882029f, 0.886856f, 0.891709f, 0.896590f,
0.901496f, 0.906430f, 0.911391f, 0.916379f, 0.921394f, 0.926436f, 0.931507f, 0.936604f, 0.941730f,
0.946884f, 0.952066f, 0.957277f, 0.962516f, 0.967783f, 0.973080f, 0.978405f, 0.983760f, 0.989144f,
0.994557f, 1.0f, 1.005473f, 1.010975f, 1.016508f, 1.022071f, 1.027665f, 1.033289f, 1.038944f,
0.994557f, 1.000000f, 1.005473f, 1.010975f, 1.016508f, 1.022071f, 1.027665f, 1.033289f, 1.038944f,
1.044630f, 1.050347f, 1.056095f, 1.061875f, 1.067687f, 1.073530f, 1.079405f, 1.085312f, 1.091252f,
1.097224f, 1.103229f, 1.109267f, 1.115337f, 1.121441f, 1.127579f, 1.133750f, 1.139955f, 1.146193f,
1.152466f, 1.158773f, 1.165115f, 1.171491f, 1.177903f, 1.184349f, 1.190831f, 1.197348f, 1.203901f,
@@ -146,7 +145,7 @@ f32 gPitchBendFrequencyScale[255] = {
1.707225f, 1.716569f, 1.725963f, 1.735409f, 1.744906f, 1.754456f, 1.764058f, 1.773712f, 1.783419f,
1.793179f, 1.802993f, 1.812860f, 1.822782f, 1.832757f, 1.842788f, 1.852873f, 1.863013f, 1.873209f,
1.883461f, 1.893768f, 1.904132f, 1.914553f, 1.925031f, 1.935567f, 1.946159f, 1.956810f, 1.967520f,
1.978287f, 1.989114f, 2.0f
1.978287f, 1.989114f, 2.000000f
};
// Frequencies for notes using the standard twelve-tone equal temperament scale.
@@ -387,7 +386,12 @@ s16 sSawtoothWave[0x40] = {
-0x4FFF, -19455, -0x47FF, -17407, -0x3FFF, -15359, -0x37FF, -13311, -0x2FFF, -11263, -10239,
-9215, -8191, -7167, -6143, -5119, -4095, -3071, -2047, -1023,
};
s16 *gWaveSamples[4] = { sSawtoothWave, sTriangleWave, sSineWave, sSquareWave };
s16 *gWaveSamples[4] = {
sSawtoothWave,
sTriangleWave,
sSineWave,
sSquareWave
};
#endif
#ifdef VERSION_SH
@@ -902,7 +906,12 @@ u8 bufferDelete2[12] = { 0 };
u8 D_EU_80302010 = 0;
u8 D_EU_80302014 = 0;
struct OSMesgQueue *OSMesgQueues[4] = { &OSMesgQueue0, &OSMesgQueue1, &OSMesgQueue2, &OSMesgQueue3 };
struct OSMesgQueue *OSMesgQueues[4] = {
&OSMesgQueue0,
&OSMesgQueue1,
&OSMesgQueue2,
&OSMesgQueue3
};
#endif
// .bss
+9 -7
View File
@@ -7,7 +7,7 @@
#include "types.h"
#include "synthesis.h"
#define AUDIO_LOCK_UNINITIALIZED 0
#define AUDIO_LOCK_UNINITIALIZED 0x00000000
#define AUDIO_LOCK_NOT_LOADING 0x76557364
#define AUDIO_LOCK_LOADING 0x19710515
@@ -110,15 +110,15 @@ extern u32 gAudioRandom;
#ifdef EXPAND_AUDIO_HEAP
#if defined(VERSION_US) || defined(VERSION_JP) || defined(VERSION_EU)
#define EXT_AUDIO_HEAP_SIZE 0x27400
#define EXT_AUDIO_INIT_POOL_SIZE 0x8000
#define EXT_AUDIO_HEAP_SIZE 0x27400
#define EXT_AUDIO_INIT_POOL_SIZE 0x02000
#else
// SH not yet supported for expanded audio heap
#define EXT_AUDIO_HEAP_SIZE 0x0
#define EXT_AUDIO_HEAP_SIZE 0x0
#define EXT_AUDIO_INIT_POOL_SIZE 0x0
#endif
#else
#define EXT_AUDIO_HEAP_SIZE 0x0
#define EXT_AUDIO_HEAP_SIZE 0x0
#define EXT_AUDIO_INIT_POOL_SIZE 0x0
#endif
@@ -148,13 +148,15 @@ extern OSMesgQueue *D_SH_80350FA8;
#endif
#if defined(VERSION_EU) || defined(VERSION_SH)
#define AUDIO_HEAP_SIZE (0x3AB00 + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE + BETTER_REVERB_SIZE)
#define AUDIO_HEAP_BASE 0x36B00
#define AUDIO_INIT_POOL_SIZE (0x2C00 + EXT_AUDIO_INIT_POOL_SIZE)
#else
#define AUDIO_HEAP_SIZE (0x34750 + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE + BETTER_REVERB_SIZE)
#define AUDIO_HEAP_BASE 0x30750
#define AUDIO_INIT_POOL_SIZE (0x2500 + EXT_AUDIO_INIT_POOL_SIZE)
#endif
#define AUDIO_HEAP_SIZE (AUDIO_HEAP_BASE + EXT_AUDIO_HEAP_SIZE + EXT_AUDIO_INIT_POOL_SIZE + BETTER_REVERB_SIZE + REVERB_WINDOW_HEAP_SIZE)
#ifdef VERSION_SH
extern u32 D_SH_80315EF0;
extern u16 D_SH_80315EF4;
+23 -52
View File
@@ -5,12 +5,7 @@
#include "data.h"
#include "seqplayer.h"
#include "game/main.h"
#ifdef VERSION_JP
#define US_FLOAT2(x) x##.0
#else
#define US_FLOAT2(x) x
#endif
#include "engine/math_util.h"
#if defined(VERSION_EU) || defined(VERSION_SH)
void sequence_channel_process_sound(struct SequenceChannel *seqChannel, s32 recalculateVolume) {
@@ -58,18 +53,15 @@ void sequence_channel_process_sound(struct SequenceChannel *seqChannel, s32 reca
}
#else
static void sequence_channel_process_sound(struct SequenceChannel *seqChannel) {
f32 channelVolume;
f32 panLayerWeight;
f32 panFromChannel;
s32 i;
channelVolume = seqChannel->volume * seqChannel->volumeScale * seqChannel->seqPlayer->fadeVolume;
f32 channelVolume = seqChannel->volume * seqChannel->volumeScale * seqChannel->seqPlayer->fadeVolume;
if (seqChannel->seqPlayer->muted && (seqChannel->muteBehavior & MUTE_BEHAVIOR_SOFTEN) != 0) {
channelVolume *= seqChannel->seqPlayer->muteVolumeScale;
}
panFromChannel = seqChannel->pan * seqChannel->panChannelWeight;
panLayerWeight = US_FLOAT(1.0) - seqChannel->panChannelWeight;
f32 panFromChannel = seqChannel->pan * seqChannel->panChannelWeight;
f32 panLayerWeight = 1.0f - seqChannel->panChannelWeight;
for (i = 0; i < 4; i++) {
struct SequenceChannelLayer *layer = seqChannel->layers[i];
@@ -90,13 +82,7 @@ void sequence_player_process_sound(struct SequencePlayer *seqPlayer) {
#if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->recalculateVolume = TRUE;
#endif
if (seqPlayer->fadeVolume > US_FLOAT2(1)) {
seqPlayer->fadeVolume = US_FLOAT2(1);
}
if (seqPlayer->fadeVolume < 0) {
seqPlayer->fadeVolume = 0;
}
seqPlayer->fadeVolume = CLAMP(seqPlayer->fadeVolume, 0, 1);
if (--seqPlayer->fadeRemainingFrames == 0) {
#if defined(VERSION_EU) || defined(VERSION_SH)
@@ -146,8 +132,6 @@ void sequence_player_process_sound(struct SequencePlayer *seqPlayer) {
}
f32 get_portamento_freq_scale(struct Portamento *p) {
u32 v0;
f32 result;
#if defined(VERSION_JP) || defined(VERSION_US)
if (p->mode == 0) {
return 1.0f;
@@ -155,43 +139,38 @@ f32 get_portamento_freq_scale(struct Portamento *p) {
#endif
p->cur += p->speed;
v0 = (u32) p->cur;
u32 v0 = (u32) p->cur;
#if defined(VERSION_EU) || defined(VERSION_SH)
if (v0 > 127)
if (v0 > 127) {
#else
if (v0 >= 127)
if (v0 >= 127) {
#endif
{
v0 = 127;
}
#if defined(VERSION_EU) || defined(VERSION_SH)
result = US_FLOAT(1.0) + p->extent * (gPitchBendFrequencyScale[v0 + 128] - US_FLOAT(1.0));
return (1.0f + (p->extent * (gPitchBendFrequencyScale[v0 + 128] - 1.0f)));
#else
result = US_FLOAT(1.0) + p->extent * (gPitchBendFrequencyScale[v0 + 127] - US_FLOAT(1.0));
return (1.0f + (p->extent * (gPitchBendFrequencyScale[v0 + 127] - 1.0f)));
#endif
return result;
}
s32 get_vibrato_pitch_change(struct VibratoState *vib) {
#if defined(VERSION_EU) || defined(VERSION_SH)
s16 get_vibrato_pitch_change(struct VibratoState *vib) {
s32 index;
vib->time += (s32) vib->rate;
index = (vib->time >> 10) & 0x3F;
s32 index = (vib->time >> 10) & 0x3F;
return vib->curve[index] >> 8;
}
#else
s8 get_vibrato_pitch_change(struct VibratoState *vib) {
s32 index;
vib->time += vib->rate;
index = (vib->time >> 10) & 0x3F;
s32 index = (vib->time >> 10) & 0x3F;
switch (index & 0x30) {
case 0x10:
index = 31 - index;
// fall through
// fallthrough
case 0x00:
return vib->curve[index];
@@ -210,10 +189,6 @@ s8 get_vibrato_pitch_change(struct VibratoState *vib) {
#endif
f32 get_vibrato_freq_scale(struct VibratoState *vib) {
s32 pitchChange;
f32 extent;
f32 result;
if (vib->delay != 0) {
vib->delay--;
return 1;
@@ -252,15 +227,14 @@ f32 get_vibrato_freq_scale(struct VibratoState *vib) {
return 1.0f;
}
pitchChange = get_vibrato_pitch_change(vib);
extent = (f32) vib->extent / US_FLOAT(4096.0);
s32 pitchChange = get_vibrato_pitch_change(vib);
f32 extent = (f32) vib->extent / 4096.0f;
#if defined(VERSION_EU) || defined(VERSION_SH)
result = US_FLOAT(1.0) + extent * (gPitchBendFrequencyScale[pitchChange + 128] - US_FLOAT(1.0));
return 1.0f + extent * (gPitchBendFrequencyScale[pitchChange + 128] - 1.0f);
#else
result = US_FLOAT(1.0) + extent * (gPitchBendFrequencyScale[pitchChange + 127] - US_FLOAT(1.0));
return 1.0f + extent * (gPitchBendFrequencyScale[pitchChange + 127] - 1.0f);
#endif
return result;
}
void note_vibrato_update(struct Note *note) {
@@ -282,8 +256,6 @@ void note_vibrato_update(struct Note *note) {
}
void note_vibrato_init(struct Note *note) {
struct VibratoState *vib;
UNUSED struct SequenceChannel *seqChannel;
#if defined(VERSION_EU) || defined(VERSION_SH)
struct NotePlaybackState *seqPlayerState = (struct NotePlaybackState *) &note->priority;
#endif
@@ -291,7 +263,7 @@ void note_vibrato_init(struct Note *note) {
note->vibratoFreqScale = 1.0f;
note->portamentoFreqScale = 1.0f;
vib = &note->vibratoState;
struct VibratoState *vib = &note->vibratoState;
/* This code was probably removed from EU and SH for a reason; probably because it's dumb and makes vibrato harder to use well.
#if defined(VERSION_JP) || defined(VERSION_US)
@@ -327,7 +299,7 @@ void note_vibrato_init(struct Note *note) {
#else
vib->curve = gVibratoCurve;
vib->seqChannel = note->parentLayer->seqChannel;
seqChannel = vib->seqChannel;
struct SequenceChannel *seqChannel = vib->seqChannel;
if ((vib->extentChangeTimer = seqChannel->vibratoExtentChangeDelay) == 0) {
vib->extent = seqChannel->vibratoExtentTarget;
@@ -390,20 +362,19 @@ s32 adsr_update(struct AdsrState *adsr) {
break;
}
}
// fall through
// fallthrough
case ADSR_STATE_START_LOOP:
adsr->envIndex = 0;
#if defined(VERSION_JP) || defined(VERSION_US)
adsr->currentHiRes = adsr->current << 0x10;
adsr->currentHiRes = (adsr->current << 0x10);
#endif
adsr->state = ADSR_STATE_LOOP;
#ifdef VERSION_SH
restart:
#endif
// fall through
// fallthrough
case ADSR_STATE_LOOP:
adsr->delay = BSWAP16(adsr->envelope[adsr->envIndex].delay);
switch (adsr->delay) {
+22 -16
View File
@@ -6,24 +6,30 @@
#include "internal.h"
#include "platform_info.h"
#define ADSR_STATE_DISABLED 0
#define ADSR_STATE_INITIAL 1
#define ADSR_STATE_START_LOOP 2
#define ADSR_STATE_LOOP 3
#define ADSR_STATE_FADE 4
#define ADSR_STATE_HANG 5
#define ADSR_STATE_DECAY 6
#define ADSR_STATE_RELEASE 7
#define ADSR_STATE_SUSTAIN 8
enum ADSRStates {
ADSR_STATE_DISABLED,
ADSR_STATE_INITIAL,
ADSR_STATE_START_LOOP,
ADSR_STATE_LOOP,
ADSR_STATE_FADE,
ADSR_STATE_HANG,
ADSR_STATE_DECAY,
ADSR_STATE_RELEASE,
ADSR_STATE_SUSTAIN
};
#define ADSR_ACTION_RELEASE 0x10
#define ADSR_ACTION_DECAY 0x20
#define ADSR_ACTION_HANG 0x40
enum ADSRActions {
ADSR_ACTION_RELEASE = (1 << 4), // 0x10
ADSR_ACTION_DECAY = (1 << 5), // 0x20
ADSR_ACTION_HANG = (1 << 6), // 0x40
};
#define ADSR_DISABLE 0
#define ADSR_HANG -1
#define ADSR_GOTO -2
#define ADSR_RESTART -3
enum ADSRDelays {
ADSR_DISABLE = 0,
ADSR_HANG = -1,
ADSR_GOTO = -2,
ADSR_RESTART = -3,
};
// Envelopes are always stored as big endian, to match sequence files which are
// byte blobs and can embed envelopes. Hence this byteswapping macro.
+114 -273
View File
@@ -7,6 +7,7 @@
#include "external.h"
#include "playback.h"
#include "synthesis.h"
#include "game/main.h"
#include "game/level_update.h"
#include "game/object_list_processor.h"
#include "game/camera.h"
@@ -14,15 +15,11 @@
#include "seq_ids.h"
#include "dialog_ids.h"
#define EU_FLOAT(x) x##f
// N.B. sound banks are different from the audio banks referred to in other
// files. We should really fix our naming to be less ambiguous...
#define MAX_BACKGROUND_MUSIC_QUEUE_SIZE 6
#define MAX_CHANNELS_PER_SOUND_BANK 1
#define SEQUENCE_NONE 0xFF
#define SAMPLES_TO_OVERPRODUCE 0x10
#define EXTRA_BUFFERED_AI_SAMPLES_TARGET 0x40
@@ -68,31 +65,28 @@ s32 sGameLoopTicked = 0;
// You're no slouch, but I'm a better sledder! Better luck next time!"), spoken
// by Koopa instead of the penguin in JP.
#define UKIKI 0
#define TUXIE 1
#define BOWS1 2 // Bowser Intro / Doors Laugh
#define KOOPA 3
#define KBOMB 4
#define BOO 5
#define BOMB 6
#define BOWS2 7 // Bowser Battle Laugh
#define GRUNT 8
#define WIGLR 9
#define YOSHI 10
#define _ 0xFF
enum DialogSpeakers {
UKIKI,
TUXIE,
BOWS1, // Bowser Intro / Doors Laugh
KOOPA,
KBOMB,
BOO,
BOMB,
BOWS2, // Bowser Battle Laugh
GRUNT,
WIGLR,
YOSHI
};
#ifdef VERSION_JP
#define DIFF KOOPA
#else
#define DIFF TUXIE
#endif
#define _ 0xFF
u8 sDialogSpeaker[] = {
// 0 1 2 3 4 5 6 7 8 9
/* 0*/ _, BOMB, BOMB, BOMB, BOMB, KOOPA, KOOPA, KOOPA, _, KOOPA,
/* 1*/ _, _, _, _, _, _, _, KBOMB, _, _,
/* 2*/ _, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1, BOWS1,
/* 3*/ _, _, _, _, _, _, _, DIFF, _, _,
/* 3*/ _, _, _, _, _, _, _, TUXIE, _, _,
/* 4*/ _, KOOPA, _, _, _, _, _, BOMB, _, _,
/* 5*/ _, _, _, _, _, TUXIE, TUXIE, TUXIE, TUXIE, TUXIE,
/* 6*/ _, _, _, _, _, _, _, BOWS2, _, _,
@@ -143,14 +137,16 @@ u8 sSoundRequestCount = 0;
// come in the same order as the macros.
// TODO: dynamic isn't a great term for this, it means other things in music...
#define MARIO_X_GE 0
#define MARIO_Y_GE 1
#define MARIO_Z_GE 2
#define MARIO_X_LT 3
#define MARIO_Y_LT 4
#define MARIO_Z_LT 5
#define MARIO_IS_IN_AREA 6
#define MARIO_IS_IN_ROOM 7
enum MusicDynConditionTypes {
MARIO_X_GE,
MARIO_Y_GE,
MARIO_Z_GE,
MARIO_X_LT,
MARIO_Y_LT,
MARIO_Z_LT,
MARIO_IS_IN_AREA,
MARIO_IS_IN_ROOM,
};
#define DYN1(cond1, val1, res) (s16)(1 << (15 - cond1) | res), val1
#define DYN2(cond1, val1, cond2, val2, res) \
@@ -225,8 +221,8 @@ struct MusicDynamic sMusicDynamics[8] = {
{ 0x0e43, 127, 200, 0x0000, 0, 200 }, // SEQ_LEVEL_WATER
{ 0x02ff, 127, 100, 0x0100, 0, 100 }, // SEQ_LEVEL_UNDERGROUND
{ 0x03f7, 127, 100, 0x0008, 0, 100 }, // SEQ_LEVEL_UNDERGROUND
{ 0x0070, 127, 10, 0x0000, 0, 100 }, // SEQ_LEVEL_SPOOKY
{ 0x0000, 127, 100, 0x0070, 0, 10 }, // SEQ_LEVEL_SPOOKY
{ 0x0070, 127, 10, 0x0000, 0, 100 }, // SEQ_LEVEL_SPOOKY
{ 0x0000, 127, 100, 0x0070, 0, 10 }, // SEQ_LEVEL_SPOOKY
{ 0xffff, 127, 100, 0x0000, 0, 100 }, // any (unused)
};
@@ -251,7 +247,7 @@ u16 sLevelAcousticReaches[LEVEL_COUNT] = {
#undef STUB_LEVEL
#undef DEFINE_LEVEL
#define AUDIO_MAX_DISTANCE US_FLOAT(22000.0)
#define AUDIO_MAX_DISTANCE 22000.0f
#define LOW_VOLUME_REVERB 40.0f
@@ -338,12 +334,7 @@ u8 sBackgroundMusicQueueSize = 0;
s16 *gCurrAiBuffer;
#endif
#ifdef VERSION_SH
s8 D_SH_80343CD0_pad[0x20];
s32 D_SH_80343CF0;
s8 D_SH_80343CF8_pad[0x8];
struct UnkStruct80343D00 D_SH_80343D00;
s8 D_SH_8034DC8_pad[0x8];
s8 D_SH_80343E48_pad[0x8];
#endif
struct Sound sSoundRequests[0x100];
@@ -379,7 +370,9 @@ extern OSMesgQueue *OSMesgQueues[];
struct EuAudioCmd sAudioCmd[0x100];
OSMesg OSMesg0;
s32 pad1; // why is there 1 s32 here
OSMesg OSMesg1;
s32 pad2[2]; // it's not just that the struct is bigger than we think, because there are 2 here
OSMesg OSMesg2; // and none here. wth nintendo
OSMesg OSMesg3;
#else // VERSION_SH
@@ -387,11 +380,7 @@ extern OSMesgQueue *D_SH_80350F88;
extern OSMesgQueue *D_SH_80350FA8;
#endif
#ifdef VERSION_JP
typedef u16 FadeT;
#else
typedef s32 FadeT;
#endif
// some sort of main thread -> sound thread dispatchers
extern void func_802ad728(u32 bits, f32 arg);
@@ -405,81 +394,6 @@ void process_level_music_dynamics(void);
static u8 begin_background_music_fade(u16 fadeDuration);
void func_80320ED8(void);
#ifndef VERSION_JP
void unused_8031E4F0(void) {
// This is a debug function which is almost entirely optimized away,
// except for loops, string literals, and a read of a volatile variable.
// The string literals have allowed it to be partially reconstructed.
s32 i;
stubbed_printf("AUTOSEQ ");
stubbed_printf("%2x %2x <%5x : %5x / %5x>\n", gSeqLoadedPool.temporary.entries[0].id,
gSeqLoadedPool.temporary.entries[1].id, gSeqLoadedPool.temporary.entries[0].size,
gSeqLoadedPool.temporary.entries[1].size, gSeqLoadedPool.temporary.pool.size);
stubbed_printf("AUTOBNK ");
stubbed_printf("%2x %3x <%5x : %5x / %5x>\n", gBankLoadedPool.temporary.entries[0].id,
gBankLoadedPool.temporary.entries[1].id, gBankLoadedPool.temporary.entries[0].size,
gBankLoadedPool.temporary.entries[1].size, gBankLoadedPool.temporary.pool.size);
stubbed_printf("STAYSEQ ");
stubbed_printf("[%2x] <%5x / %5x>\n", gSeqLoadedPool.persistent.numEntries,
gSeqLoadedPool.persistent.pool.cur - gSeqLoadedPool.persistent.pool.start,
gSeqLoadedPool.persistent.pool.size);
for (i = 0; (u32) i < gSeqLoadedPool.persistent.numEntries; i++) {
stubbed_printf("%2x ", gSeqLoadedPool.persistent.entries[i].id);
}
stubbed_printf("\n");
stubbed_printf("STAYBNK ");
stubbed_printf("[%2x] <%5x / %5x>\n", gBankLoadedPool.persistent.numEntries,
gBankLoadedPool.persistent.pool.cur - gBankLoadedPool.persistent.pool.start,
gBankLoadedPool.persistent.pool.size);
for (i = 0; (u32) i < gBankLoadedPool.persistent.numEntries; i++) {
stubbed_printf("%2x ", gBankLoadedPool.persistent.entries[i].id);
}
stubbed_printf("\n\n");
stubbed_printf(" 0123456789ABCDEF0123456789ABCDEF01234567\n");
stubbed_printf("--------------------------------------------\n");
// gSeqLoadStatus/gBankLoadStatus, 4 entries at a time?
stubbed_printf("SEQ ");
for (i = 0; i < 40; i++) {
stubbed_printf("%1x", 0);
}
stubbed_printf("\n");
stubbed_printf("BNK ");
for (i = 0; i < 40; i += 4) {
stubbed_printf("%1x", 0);
}
stubbed_printf("\n");
stubbed_printf("FIXHEAP ");
stubbed_printf("%4x / %4x\n", 0, 0);
stubbed_printf("DRVHEAP ");
stubbed_printf("%5x / %5x\n", 0, 0);
stubbed_printf("DMACACHE %4d Blocks\n", 0);
stubbed_printf("CHANNELS %2d / MAX %3d \n", 0, 0);
stubbed_printf("TEMPOMAX %d\n", gTempoInternalToExternal / TEMPO_SCALE);
stubbed_printf("TEMPO G0 %d\n", gSequencePlayers[SEQ_PLAYER_LEVEL].tempo / TEMPO_SCALE);
stubbed_printf("TEMPO G1 %d\n", gSequencePlayers[SEQ_PLAYER_ENV].tempo / TEMPO_SCALE);
stubbed_printf("TEMPO G2 %d\n", gSequencePlayers[SEQ_PLAYER_SFX].tempo / TEMPO_SCALE);
stubbed_printf("DEBUGFLAG %8x\n", gAudioErrorFlags);
}
void unused_8031E568(void) {
stubbed_printf("COUNT %8d\n", gAudioFrameCount);
}
#endif
#if defined(VERSION_EU) || defined(VERSION_SH)
const char unusedErrorStr1[] = "Error : Queue is not empty ( %x ) \n";
const char unusedErrorStr2[] = "specchg error\n";
#endif
/**
* Fade out a sequence player
* Called from threads: thread5_game_loop
@@ -513,12 +427,10 @@ void audio_reset_session_eu(s32 presetId) {
static void seq_player_fade_to_zero_volume(s32 player, FadeT fadeDuration) {
struct SequencePlayer *seqPlayer = &gSequencePlayers[player];
#ifndef VERSION_JP
// fadeDuration is never 0 in practice
if (fadeDuration == 0) {
fadeDuration++;
}
#endif
seqPlayer->fadeVelocity = -(seqPlayer->fadeVolume / fadeDuration);
seqPlayer->state = SEQUENCE_PLAYER_STATE_FADE_OUT;
@@ -550,7 +462,7 @@ static void seq_player_fade_to_percentage_of_volume(s32 player, FadeT fadeDurati
f32 targetVolume;
#if defined(VERSION_EU) || defined(VERSION_SH)
if (seqPlayer->state == 2) {
if (seqPlayer->state == SEQUENCE_PLAYER_STATE_2) {
return;
}
#else
@@ -559,7 +471,7 @@ static void seq_player_fade_to_percentage_of_volume(s32 player, FadeT fadeDurati
}
#endif
targetVolume = (FLOAT_CAST(percentage) / EU_FLOAT(100.0)) * seqPlayer->fadeVolume;
targetVolume = (FLOAT_CAST(percentage) / 100.0f) * seqPlayer->fadeVolume;
seqPlayer->volume = seqPlayer->fadeVolume;
seqPlayer->fadeRemainingFrames = 0;
@@ -569,7 +481,7 @@ static void seq_player_fade_to_percentage_of_volume(s32 player, FadeT fadeDurati
}
seqPlayer->fadeVelocity = (targetVolume - seqPlayer->fadeVolume) / fadeDuration;
#if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->state = 0;
seqPlayer->state = SEQUENCE_PLAYER_STATE_0;
#else
seqPlayer->state = SEQUENCE_PLAYER_STATE_4;
#endif
@@ -584,7 +496,7 @@ static void seq_player_fade_to_normal_volume(s32 player, FadeT fadeDuration) {
struct SequencePlayer *seqPlayer = &gSequencePlayers[player];
#if defined(VERSION_EU) || defined(VERSION_SH)
if (seqPlayer->state == 2) {
if (seqPlayer->state == SEQUENCE_PLAYER_STATE_2) {
return;
}
#else
@@ -600,7 +512,7 @@ static void seq_player_fade_to_normal_volume(s32 player, FadeT fadeDuration) {
}
seqPlayer->fadeVelocity = (seqPlayer->volume - seqPlayer->fadeVolume) / fadeDuration;
#if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->state = 0;
seqPlayer->state = SEQUENCE_PLAYER_STATE_0;
#else
seqPlayer->state = SEQUENCE_PLAYER_STATE_2;
#endif
@@ -622,12 +534,12 @@ static void seq_player_fade_to_target_volume(s32 player, FadeT fadeDuration, u8
seqPlayer->fadeRemainingFrames = 0;
if (fadeDuration == 0) {
seqPlayer->fadeVolume = (FLOAT_CAST(targetVolume) / EU_FLOAT(127.0));
seqPlayer->fadeVolume = (FLOAT_CAST(targetVolume) / 127.0f);
return;
}
seqPlayer->fadeVelocity =
(((f32)(FLOAT_CAST(targetVolume) / EU_FLOAT(127.0)) - seqPlayer->fadeVolume)
(((f32)(FLOAT_CAST(targetVolume) / 127.0f) - seqPlayer->fadeVolume)
/ (f32) fadeDuration);
#if defined(VERSION_EU) || defined(VERSION_SH)
seqPlayer->state = 0;
@@ -738,8 +650,11 @@ struct SPTask *create_next_audio_frame_task(void) {
// For the function to match we have to preserve some arbitrary variable
// across this function call.
flags = 0;
gAudioCmd = synthesis_execute(gAudioCmd, &writtenCmds, gCurrAiBuffer, gAiBufferLengths[index]);
gAudioRandom = ((gAudioRandom + gAudioFrameCount) * gAudioFrameCount);
if (gAudioEnabled)
{
gAudioCmd = synthesis_execute(gAudioCmd, &writtenCmds, gCurrAiBuffer, gAiBufferLengths[index]);
gAudioRandom = ((gAudioRandom + gAudioFrameCount) * gAudioFrameCount);
}
index = gAudioTaskIndex;
gAudioTask->msgqueue = NULL;
@@ -781,19 +696,15 @@ void play_sound(s32 soundBits, f32 *pos) {
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
static void process_sound_request(u32 bits, f32 *pos) {
s32 bank;
s32 soundIndex;
s32 counter = 0;
f32 dist;
const f32 one = 1.0f;
bank = (bits & SOUNDARGS_MASK_BANK) >> SOUNDARGS_SHIFT_BANK;
s32 bank = (bits & SOUNDARGS_MASK_BANK) >> SOUNDARGS_SHIFT_BANK;
if (sSoundBankDisabled[bank]) {
return;
}
soundIndex = sSoundBanks[bank][0].next;
s32 soundIndex = sSoundBanks[bank][0].next;
while (soundIndex != 0xff && soundIndex != 0) {
// If an existing sound from the same source exists in the bank, then we should either
// interrupt that sound and replace it with the new sound, or we should drop the new sound.
@@ -842,7 +753,7 @@ static void process_sound_request(u32 bits, f32 *pos) {
// Allocate from free list
soundIndex = sSoundBankFreeListFront[bank];
dist = sqrtf(sqr(pos[0]) + sqr(pos[1]) + sqr(pos[2])) * one;
f32 dist = sqrtf(sqr(pos[0]) + sqr(pos[1]) + sqr(pos[2]));
sSoundBanks[bank][soundIndex].x = &pos[0];
sSoundBanks[bank][soundIndex].y = &pos[1];
sSoundBanks[bank][soundIndex].z = &pos[2];
@@ -970,24 +881,21 @@ static void select_current_sounds(u8 bank) {
// Recompute distance each frame since the sound's position may have changed
sSoundBanks[bank][soundIndex].distance =
sqrtf((*sSoundBanks[bank][soundIndex].x * *sSoundBanks[bank][soundIndex].x)
+ (*sSoundBanks[bank][soundIndex].y * *sSoundBanks[bank][soundIndex].y)
+ (*sSoundBanks[bank][soundIndex].z * *sSoundBanks[bank][soundIndex].z))
* 1;
sqrtf(sqr(*sSoundBanks[bank][soundIndex].x)
+ sqr(*sSoundBanks[bank][soundIndex].y)
+ sqr(*sSoundBanks[bank][soundIndex].z));
requestedPriority = (sSoundBanks[bank][soundIndex].soundBits & SOUNDARGS_MASK_PRIORITY)
>> SOUNDARGS_SHIFT_PRIORITY;
// Recompute priority, possibly based on the sound's source position relative to the
// camera.
// (Note that the sound's priority is the opposite of requestedPriority; lower is
// more important)
// Recompute priority, possibly based on the sound's source position relative to the camera.
// (Note that the sound's priority is the opposite of requestedPriority; lower is more important)
if (sSoundBanks[bank][soundIndex].soundBits & SOUND_NO_PRIORITY_LOSS) {
sSoundBanks[bank][soundIndex].priority = 0x4c * (0xff - requestedPriority);
} else if (*sSoundBanks[bank][soundIndex].z > 0.0f) {
sSoundBanks[bank][soundIndex].priority =
(u32) sSoundBanks[bank][soundIndex].distance
+ (u32)(*sSoundBanks[bank][soundIndex].z / US_FLOAT(6.0))
+ (u32)(*sSoundBanks[bank][soundIndex].z / 6.0f)
+ 0x4c * (0xff - requestedPriority);
} else {
sSoundBanks[bank][soundIndex].priority =
@@ -1056,13 +964,7 @@ static void select_current_sounds(u8 bank) {
& (SOUND_DISCRETE | SOUNDARGS_MASK_STATUS);
if (isDiscreteAndStatus >= (SOUND_DISCRETE | SOUND_STATUS_PLAYING)
&& sSoundBanks[bank][sCurrentSound[bank][i]].soundStatus != SOUND_STATUS_STOPPED) {
//! @bug On JP, if a discrete sound that lowers the background music is
// interrupted in this way, it will keep the background music low afterward.
// There are only a few of these sounds, and it probably isn't possible to do
// it in practice without using a time stop glitch like triple star spawn.
#ifndef VERSION_JP
update_background_music_after_sound(bank, sCurrentSound[bank][i]);
#endif
sSoundBanks[bank][sCurrentSound[bank][i]].soundBits = NO_SOUND;
sSoundBanks[bank][sCurrentSound[bank][i]].soundStatus = SOUND_STATUS_STOPPED;
@@ -1118,16 +1020,14 @@ static void select_current_sounds(u8 bank) {
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
static f32 get_sound_pan(f32 x, f32 z) {
f32 absX;
f32 absZ;
f32 pan;
absX = (x < 0 ? -x : x);
f32 absX = absf(x);
if (absX > AUDIO_MAX_DISTANCE) {
absX = AUDIO_MAX_DISTANCE;
}
absZ = (z < 0 ? -z : z);
f32 absZ = absf(z);
if (absZ > AUDIO_MAX_DISTANCE) {
absZ = AUDIO_MAX_DISTANCE;
}
@@ -1137,23 +1037,18 @@ static f32 get_sound_pan(f32 x, f32 z) {
// 2. far right pan: between 1:30 and 4:30
// 3. far left pan: between 7:30 and 10:30
// 4. center pan: between 4:30 and 7:30 or between 10:30 and 1:30
if (x == US_FLOAT(0.0) && z == US_FLOAT(0.0)) {
if (x == 0.0f && z == 0.0f) {
// x and z being 0 results in a center pan
pan = US_FLOAT(0.5);
} else if (x >= US_FLOAT(0.0) && absX >= absZ) {
pan = 0.5f;
} else if (x >= 0.0f && absX >= absZ) {
// far right pan
pan = US_FLOAT(1.0) - (2 * AUDIO_MAX_DISTANCE - absX) / (US_FLOAT(3.0) * (2 * AUDIO_MAX_DISTANCE - absZ));
pan = (1.0f - (2 * AUDIO_MAX_DISTANCE - absX) / (3.0f * (2 * AUDIO_MAX_DISTANCE - absZ)));
} else if (x < 0 && absX > absZ) {
// far left pan
pan = (2 * AUDIO_MAX_DISTANCE - absX) / (US_FLOAT(3.0) * (2 * AUDIO_MAX_DISTANCE - absZ));
pan = (2 * AUDIO_MAX_DISTANCE - absX) / (3.0f * (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);
pan = 0.5f + x / (6.0f * absZ);
}
return pan;
@@ -1163,28 +1058,25 @@ static f32 get_sound_pan(f32 x, f32 z) {
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
static f32 get_sound_volume(u8 bank, u8 soundIndex, f32 volumeRange) {
f32 maxSoundDistance;
f32 intensity;
#ifndef VERSION_JP
s32 div = bank < 3 ? 2 : 3;
#endif
if (!(sSoundBanks[bank][soundIndex].soundBits & SOUND_NO_VOLUME_LOSS)) {
#ifdef VERSION_JP
// Intensity linearly lowers from 1 at the camera to 0 at maxSoundDistance
maxSoundDistance = sLevelAcousticReaches[gCurrLevelNum];
f32 maxSoundDistance = sLevelAcousticReaches[gCurrLevelNum];
if (maxSoundDistance < sSoundBanks[bank][soundIndex].distance) {
intensity = 0.0f;
} else {
intensity = 1.0 - sSoundBanks[bank][soundIndex].distance / maxSoundDistance;
intensity = 1.0 - (sSoundBanks[bank][soundIndex].distance / maxSoundDistance);
}
#else
s32 div = (bank < 3) ? 2 : 3;
// Intensity linearly lowers from 1 at the camera to 1 - volumeRange at maxSoundDistance,
// then it goes from 1 - volumeRange at maxSoundDistance to 0 at AUDIO_MAX_DISTANCE
if (sSoundBanks[bank][soundIndex].distance > AUDIO_MAX_DISTANCE) {
intensity = 0.0f;
} else {
maxSoundDistance = sLevelAcousticReaches[gCurrLevelNum] / div;
f32 maxSoundDistance = sLevelAcousticReaches[gCurrLevelNum] / div;
if (maxSoundDistance < sSoundBanks[bank][soundIndex].distance) {
intensity = ((AUDIO_MAX_DISTANCE - sSoundBanks[bank][soundIndex].distance)
/ (AUDIO_MAX_DISTANCE - maxSoundDistance))
@@ -1197,15 +1089,8 @@ static f32 get_sound_volume(u8 bank, u8 soundIndex, f32 volumeRange) {
#endif
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)
#endif
{
intensity -= (f32)(gAudioRandom & 0xf) / US_FLOAT(192.0);
if (intensity >= 0.08f) {
intensity -= (f32)(gAudioRandom & 0xF) / 192.0f;
}
}
} else {
@@ -1213,7 +1098,7 @@ static f32 get_sound_volume(u8 bank, u8 soundIndex, f32 volumeRange) {
}
// Rise quadratically from 1 - volumeRange to 1
return volumeRange * intensity * intensity + 1.0f - volumeRange;
return volumeRange * sqr(intensity) + 1.0f - volumeRange;
}
/**
@@ -1225,7 +1110,7 @@ static f32 get_sound_freq_scale(u8 bank, u8 item) {
if (!(sSoundBanks[bank][item].soundBits & SOUND_CONSTANT_FREQUENCY)) {
amount = sSoundBanks[bank][item].distance / AUDIO_MAX_DISTANCE;
if (sSoundBanks[bank][item].soundBits & SOUND_VIBRATO) {
amount += (f32)(gAudioRandom & 0xff) / US_FLOAT(64.0);
amount += (f32)(gAudioRandom & 0xff) / 64.0f;
}
} else {
amount = 0.0f;
@@ -1233,39 +1118,35 @@ static f32 get_sound_freq_scale(u8 bank, u8 item) {
// Goes from 1 at the camera to 1 + 1/15 at AUDIO_MAX_DISTANCE (and continues rising
// farther than that)
return amount / US_FLOAT(15.0) + US_FLOAT(1.0);
return amount / 15.0f + 1.0f;
}
/**
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
static u8 get_sound_reverb(UNUSED u8 bank, UNUSED u8 soundIndex, u8 channelIndex) {
static u32 get_sound_reverb(UNUSED u8 bank, UNUSED u8 soundIndex, u8 channelIndex) {
u8 area;
u8 level;
u8 reverb;
#ifndef VERSION_JP
// Disable level reverb if NO_ECHO is set
if (sSoundBanks[bank][soundIndex].soundBits & SOUND_NO_ECHO) {
level = 0;
area = 0;
} else {
#endif
level = (gCurrLevelNum > LEVEL_MAX ? LEVEL_MAX : gCurrLevelNum);
area = gCurrAreaIndex - 1;
if (area > 2) {
area = 2;
}
#ifndef VERSION_JP
}
#endif
// reverb = reverb adjustment + level reverb + a volume-dependent value
// The volume-dependent value is 0 when volume is at maximum, and raises to
// LOW_VOLUME_REVERB when the volume is 0
reverb = (u8)((u8) gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[5]
reverb = (u8)(u8) gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->soundScriptIO[5]
+ sLevelAreaReverbs[level][area]
+ (US_FLOAT(1.0) - gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume)
+ ((1.0f - gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->volume)
* LOW_VOLUME_REVERB);
if (reverb > 0x7f) {
@@ -1274,9 +1155,6 @@ static u8 get_sound_reverb(UNUSED u8 bank, UNUSED u8 soundIndex, u8 channelIndex
return reverb;
}
static void noop_8031EEC8(void) {
}
/**
* Called from the game loop thread to inform the audio thread that a new game
* frame has started.
@@ -1288,7 +1166,6 @@ void audio_signal_game_loop_tick(void) {
#if defined(VERSION_EU) || defined(VERSION_SH)
maybe_tick_game_sound();
#endif
noop_8031EEC8();
}
/**
@@ -1376,25 +1253,21 @@ static void update_game_sound(void) {
if ((sSoundBanks[bank][soundIndex].soundBits & SOUNDARGS_MASK_SOUNDID)
== (SOUND_MOVING_FLYING & SOUNDARGS_MASK_SOUNDID)) {
#if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(
0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex)
+ ((f32) sSoundMovingSpeed[bank] / US_FLOAT(80.0)));
func_802ad728(0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex) + ((f32) sSoundMovingSpeed[bank] / 80.0f));
#else
value = get_sound_freq_scale(bank, soundIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
((f32) sSoundMovingSpeed[bank] / US_FLOAT(80.0)) + value;
((f32) sSoundMovingSpeed[bank] / 80.0f) + value;
#endif
} else {
#if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(
0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex)
+ ((f32) sSoundMovingSpeed[bank] / US_FLOAT(400.0)));
func_802ad728((x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex) + ((f32) sSoundMovingSpeed[bank] / 400.0f));
#else
value = get_sound_freq_scale(bank, soundIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
((f32) sSoundMovingSpeed[bank] / US_FLOAT(400.0)) + value;
((f32) sSoundMovingSpeed[bank] / 400.0f) + value;
#endif
}
#if defined(VERSION_EU) || defined(VERSION_SH)
@@ -1477,24 +1350,7 @@ static void update_game_sound(void) {
#endif
break;
}
}
#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;
delete_sound_from_bank(bank, soundIndex);
}
#else
else if (gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->layers[0] == NULL) {
} else if (gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->layers[0] == NULL) {
update_background_music_after_sound(bank, soundIndex);
sSoundBanks[bank][soundIndex].soundStatus = SOUND_STATUS_STOPPED;
delete_sound_from_bank(bank, soundIndex);
@@ -1505,7 +1361,6 @@ static void update_game_sound(void) {
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
@@ -1563,22 +1418,22 @@ static void update_game_sound(void) {
func_802ad728(
0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex)
+ ((f32) sSoundMovingSpeed[bank] / US_FLOAT(80.0)));
+ ((f32) sSoundMovingSpeed[bank] / 80.0f));
#else
value = get_sound_freq_scale(bank, soundIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
((f32) sSoundMovingSpeed[bank] / US_FLOAT(80.0)) + value;
((f32) sSoundMovingSpeed[bank] / 80.0f) + value;
#endif
} else {
#if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728(
0x04020000 | ((channelIndex & 0xff) << 8),
get_sound_freq_scale(bank, soundIndex)
+ ((f32) sSoundMovingSpeed[bank] / US_FLOAT(400.0)));
+ ((f32) sSoundMovingSpeed[bank] / 400.0f));
#else
value = get_sound_freq_scale(bank, soundIndex);
gSequencePlayers[SEQ_PLAYER_SFX].channels[channelIndex]->freqScale =
((f32) sSoundMovingSpeed[bank] / US_FLOAT(400.0)) + value;
((f32) sSoundMovingSpeed[bank] / 400.0f) + value;
#endif
}
#if defined(VERSION_EU) || defined(VERSION_SH)
@@ -1700,7 +1555,7 @@ static void seq_player_play_sequence(u8 player, u8 seqId, u16 arg2) {
if (player == SEQ_PLAYER_LEVEL) {
targetVolume = begin_background_music_fade(0);
if (targetVolume != 0xff) {
gSequencePlayers[SEQ_PLAYER_LEVEL].fadeVolumeScale = (f32) targetVolume / US_FLOAT(127.0);
gSequencePlayers[SEQ_PLAYER_LEVEL].fadeVolumeScale = (f32) targetVolume / 127.0f;
}
}
#else
@@ -1712,7 +1567,7 @@ static void seq_player_play_sequence(u8 player, u8 seqId, u16 arg2) {
targetVolume = begin_background_music_fade(0);
if (targetVolume != 0xff) {
gSequencePlayers[SEQ_PLAYER_LEVEL].state = SEQUENCE_PLAYER_STATE_4;
gSequencePlayers[SEQ_PLAYER_LEVEL].fadeVolume = (f32) targetVolume / US_FLOAT(127.0);
gSequencePlayers[SEQ_PLAYER_LEVEL].fadeVolume = (f32) targetVolume / 127.0f;
}
} else {
func_8031D690(player, arg2);
@@ -1761,7 +1616,7 @@ static void fade_channel_volume_scale(u8 player, u8 channelIndex, u8 targetScale
if (gSequencePlayers[player].channels[channelIndex] != &gSequenceChannelNone) {
temp = &D_80360928[player][channelIndex];
temp->remainingFrames = fadeDuration;
temp->velocity = ((f32)(targetScale / US_FLOAT(127.0))
temp->velocity = ((f32)(targetScale / 127.0f)
- gSequencePlayers[player].channels[channelIndex]->volumeScale)
/ fadeDuration;
temp->target = targetScale;
@@ -1788,12 +1643,9 @@ static void func_8031F96C(u8 player) {
#endif
D_80360928[player][i].remainingFrames--;
if (D_80360928[player][i].remainingFrames == 0) {
#if defined(VERSION_EU)
func_802ad728(0x01000000 | (player & 0xff) << 16 | (i & 0xff) << 8,
FLOAT_CAST(D_80360928[player][i].target) / 127.0);
#elif defined(VERSION_SH)
func_802ad728(0x01000000 | (player & 0xff) << 16 | (i & 0xff) << 8,
FLOAT_CAST(D_80360928[player][i].target) / 127.0f);
#if defined(VERSION_EU) || defined(VERSION_SH)
func_802ad728((0x01000000 | ((player & 0xFF) << 16) | ((i & 0xFF) << 8)),
(FLOAT_CAST(D_80360928[player][i].target) / 127.0f));
#else
gSequencePlayers[player].channels[i]->volumeScale =
D_80360928[player][i].target / 127.0f;
@@ -1807,9 +1659,7 @@ static void func_8031F96C(u8 player) {
* Called from threads: thread4_sound, thread5_game_loop (EU only)
*/
void process_level_music_dynamics(void) {
u32 conditionBits;
u16 tempBits;
u8 musicDynIndex;
u8 condIndex;
u8 i, j;
s16 conditionValues[8];
@@ -1830,8 +1680,8 @@ void process_level_music_dynamics(void) {
return;
}
conditionBits = sLevelDynamics[gCurrLevelNum][1] & 0xff00;
musicDynIndex = (u8) sLevelDynamics[gCurrLevelNum][1] & 0xff;
u32 conditionBits = sLevelDynamics[gCurrLevelNum][1] & 0xFF00;
u8 musicDynIndex = (u8) sLevelDynamics[gCurrLevelNum][1] & 0xFF;
i = 2;
while (conditionBits & 0xff00) {
j = 0;
@@ -1941,7 +1791,7 @@ void process_level_music_dynamics(void) {
}
}
void unused_8031FED0(u8 player, u32 bits, s8 arg2) {
UNUSED void unused_8031FED0(u8 player, u32 bits, s8 arg2) {
u8 i;
if (arg2 < 0) {
@@ -1950,13 +1800,12 @@ void unused_8031FED0(u8 player, u32 bits, s8 arg2) {
for (i = 0; i < CHANNELS_MAX; i++) {
if (gSequencePlayers[player].channels[i] != &gSequenceChannelNone) {
if ((bits & 3) == 0) {
if ((bits & 0x3) == 0) {
gSequencePlayers[player].channels[i]->volumeScale = 1.0f;
} else if ((bits & 1) != 0) {
gSequencePlayers[player].channels[i]->volumeScale = (f32) arg2 / US_FLOAT(127.0);
} else if ((bits & 0x1) != 0) {
gSequencePlayers[player].channels[i]->volumeScale = ((f32) arg2 / 127.0f);
} else {
gSequencePlayers[player].channels[i]->volumeScale =
US_FLOAT(1.0) - (f32) arg2 / US_FLOAT(127.0);
gSequencePlayers[player].channels[i]->volumeScale = (1.0f - ((f32) arg2 / 127.0f));
}
}
bits >>= 2;
@@ -2063,10 +1912,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
@@ -2077,8 +1927,7 @@ void set_audio_muted(u8 muted) {
* Called from threads: thread4_sound
*/
void sound_init(void) {
u8 i;
u8 j;
u8 i, j;
for (i = 0; i < SOUND_BANK_COUNT; i++) {
// Set each sound in the bank to STOPPED
@@ -2263,13 +2112,12 @@ void sound_banks_enable(UNUSED u8 player, u16 bankMask) {
}
}
u8 unused_803209D8(u8 player, u8 channelIndex, u8 arg2) {
u8 ret = 0;
UNUSED u32 unused_803209D8(u8 player, u8 channelIndex, u8 arg2) {
if (gSequencePlayers[player].channels[channelIndex] != &gSequenceChannelNone) {
gSequencePlayers[player].channels[channelIndex]->stopSomething2 = arg2;
ret = arg2;
return arg2;
}
return ret;
return 0;
}
/**
@@ -2303,12 +2151,12 @@ void play_dialog_sound(u8 dialogID) {
}
}
#ifndef VERSION_JP
// "You've stepped on the (Wing|Metal|Vanish) Cap Switch"
if (dialogID == DIALOG_010 || dialogID == DIALOG_011 || dialogID == DIALOG_012) {
if (dialogID == DIALOG_010
|| dialogID == DIALOG_011
|| dialogID == DIALOG_012) {
play_puzzle_jingle();
}
#endif
}
/**
@@ -2380,20 +2228,17 @@ void play_music(u8 player, u16 seqArgs, u16 fadeTimer) {
* Called from threads: thread5_game_loop
*/
void stop_background_music(u16 seqId) {
u8 foundIndex;
u8 i;
if (sBackgroundMusicQueueSize == 0) {
return;
}
// If sequence is not found, remove an empty queue item (the next empty
// queue slot).
foundIndex = sBackgroundMusicQueueSize;
u8 foundIndex = sBackgroundMusicQueueSize;
u8 i;
// Search for the sequence.
for (i = 0; i < sBackgroundMusicQueueSize; i++) {
if (sBackgroundMusicQueue[i].seqId == (u8)(seqId & 0xff)) {
if (sBackgroundMusicQueue[i].seqId == (u8)(seqId & SEQUENCE_NONE)) {
// Remove sequence from queue. If it was first, play the next one,
// or fade out the music.
sBackgroundMusicQueueSize--;
@@ -2424,7 +2269,7 @@ void stop_background_music(u16 seqId) {
* Called from threads: thread5_game_loop
*/
void fadeout_background_music(u16 seqId, u16 fadeOut) {
if (sBackgroundMusicQueueSize != 0 && sBackgroundMusicQueue[0].seqId == (u8)(seqId & 0xff)) {
if (sBackgroundMusicQueueSize != 0 && sBackgroundMusicQueue[0].seqId == (u8)(seqId & SEQUENCE_NONE)) {
seq_player_fade_out(SEQ_PLAYER_LEVEL, fadeOut);
}
}
@@ -2441,7 +2286,7 @@ void drop_queued_background_music(void) {
/**
* Called from threads: thread5_game_loop
*/
u16 get_current_background_music(void) {
u32 get_current_background_music(void) {
if (sBackgroundMusicQueueSize != 0) {
return (sBackgroundMusicQueue[0].priority << 8) + sBackgroundMusicQueue[0].seqId;
}
@@ -2482,7 +2327,8 @@ void func_80320ED8(void) {
* Called from threads: thread5_game_loop
*/
void play_secondary_music(u8 seqId, u8 bgMusicVolume, u8 volume, u16 fadeTimer) {
if (sCurrentBackgroundMusicSeqId == 0xff || sCurrentBackgroundMusicSeqId == SEQ_MENU_TITLE_SCREEN) {
if ((sCurrentBackgroundMusicSeqId == SEQUENCE_NONE)
|| (sCurrentBackgroundMusicSeqId == SEQ_MENU_TITLE_SCREEN)) {
return;
}
@@ -2607,10 +2453,7 @@ void play_star_fanfare(void) {
/**
* Called from threads: thread5_game_loop
*/
void play_power_star_jingle(u8 arg0) {
if (!arg0) {
sBackgroundMusicTargetVolume = 0;
}
void play_power_star_jingle(void) {
seq_player_play_sequence(SEQ_PLAYER_ENV, SEQ_EVENT_CUTSCENE_STAR_SPAWN, 0);
sBackgroundMusicMaxTargetVolume = TARGET_VOLUME_IS_PRESENT_FLAG | 20;
#if defined(VERSION_EU) || defined(VERSION_SH)
@@ -2647,11 +2490,9 @@ void play_toads_jingle(void) {
* Called from threads: thread5_game_loop
*/
void sound_reset(u8 presetId) {
#ifndef VERSION_JP
if (presetId >= 8) {
presetId = 0;
}
#endif
sGameLoopTicked = 0;
disable_all_sequence_players();
sound_init();
+16 -11
View File
@@ -8,15 +8,20 @@
// Sequence arguments, passed to seq_player_play_sequence. seqId may be bit-OR'ed with
// SEQ_VARIATION; this will load the same sequence, but set a variation
// bit which may be read by the sequence script.
#define SEQUENCE_ARGS(priority, seqId) ((priority << 8) | seqId)
#define SEQUENCE_ARGS(priority, seqId) (((priority) << 8) | (seqId))
#define SOUND_MODE_STEREO 0
#define SOUND_MODE_MONO 3
#define SOUND_MODE_HEADSET 1
enum SoundModes {
SOUND_MODE_STEREO,
SOUND_MODE_HEADSET,
SOUND_MODE_UNUSED,
SOUND_MODE_MONO,
};
#define SEQ_PLAYER_LEVEL 0 // Level background music
#define SEQ_PLAYER_ENV 1 // Misc music like the puzzle jingle
#define SEQ_PLAYER_SFX 2 // Sound effects
enum SequencePlayers {
SEQ_PLAYER_LEVEL, // Level background music
SEQ_PLAYER_ENV, // Misc music like the puzzle jingle
SEQ_PLAYER_SFX // Sound effects
};
struct SequenceQueueItem {
u8 seqId;
@@ -48,9 +53,9 @@ void set_sound_moving_speed(u8 bank, u8 speed);
void play_dialog_sound(u8 dialogID);
void play_music(u8 player, u16 seqArgs, u16 fadeTimer);
void stop_background_music(u16 seqId);
void fadeout_background_music(u16 arg0, u16 fadeOut);
void fadeout_background_music(u16 seqId, u16 fadeOut);
void drop_queued_background_music(void);
u16 get_current_background_music(void);
u32 get_current_background_music(void);
void play_secondary_music(u8 seqId, u8 bgMusicVolume, u8 volume, u16 fadeTimer);
void func_80321080(u16 fadeTimer);
void func_803210D4(u16 fadeOutTime);
@@ -58,11 +63,11 @@ void play_course_clear(void);
void play_peachs_jingle(void);
void play_puzzle_jingle(void);
void play_star_fanfare(void);
void play_power_star_jingle(u8 arg0);
void play_power_star_jingle(void);
void play_race_fanfare(void);
void play_toads_jingle(void);
void sound_reset(u8 presetId);
void audio_set_sound_mode(u8 arg0);
void audio_set_sound_mode(u8 soundMode);
void audio_init(void); // in load.c
+190 -303
View File
@@ -11,14 +11,6 @@
#include "game/vc_check.h"
#include "string.h"
#ifdef VERSION_EU
#define REVERB_WINDOW_SIZE_MAX 0x1000
#else
#define REVERB_WINDOW_SIZE_MAX 0x1000
#endif
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
struct PoolSplit {
u32 wantSeq;
u32 wantBank;
@@ -34,22 +26,24 @@ struct PoolSplit2 {
#if defined(VERSION_JP) || defined(VERSION_US)
s16 gVolume;
s8 gReverbDownsampleRate;
u8 sReverbDownsampleRateLog; // never read
#endif
struct SoundAllocPool gAudioSessionPool;
struct SoundAllocPool gAudioInitPool;
struct SoundAllocPool gNotesAndBuffersPool;
u8 sAudioHeapPad[0x20]; // probably two unused pools
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
struct SoundAllocPool gBetterReverbPool;
#endif
struct SoundAllocPool gSeqAndBankPool;
struct SoundAllocPool gPersistentCommonPool;
struct SoundAllocPool gTemporaryCommonPool;
struct SoundMultiPool gSeqLoadedPool;
struct SoundMultiPool gBankLoadedPool;
struct SoundMultiPool gUnusedLoadedPool;
#ifdef VERSION_SH
struct SoundMultiPool gUnusedLoadedPool;
struct Unk1Pool gUnkPool1;
struct UnkPool gUnkPool2;
struct UnkPool gUnkPool3;
@@ -90,8 +84,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;
@@ -99,20 +92,20 @@ f64 root_newton_step(f64 x, s32 k, f64 d)
f64 fx;
f64 deriv = deg8;
if (degree & 1) {
if (degree & (1 << 0)) {
deriv *= x;
}
if (degree & 2) {
if (degree & (1 << 1)) {
deriv *= deg2;
}
if (degree & 4) {
if (degree & (1 << 2)) {
deriv *= deg4;
}
if (degree & 8) {
if (degree & (1 << 3)) {
deriv *= deg8;
}
fx = deriv * x - d;
deriv = k * deriv;
deriv *= k;
return x - fx / deriv;
}
@@ -175,11 +168,11 @@ void build_vol_rampings_table(s32 UNUSED unused, s32 len) {
void reset_bank_and_seq_load_status(void) {
#ifdef VERSION_SH
bzero(&gBankLoadStatus, sizeof(gBankLoadStatus));
bzero(&gUnkLoadStatus, sizeof(gUnkLoadStatus));
bzero(&gSeqLoadStatus, sizeof(gBankLoadStatus));
bzero(&gUnkLoadStatus, sizeof(gUnkLoadStatus));
bzero(&gSeqLoadStatus, sizeof(gBankLoadStatus));
#else
bzero(&gBankLoadStatus, sizeof(gBankLoadStatus)); //Setting this array to zero is equivilent to SOUND_LOAD_STATUS_NOT_LOADED
bzero(&gSeqLoadStatus, sizeof(gSeqLoadStatus)); //Same dealio
bzero(&gBankLoadStatus, sizeof(gBankLoadStatus)); // Setting this array to zero is equivilent to SOUND_LOAD_STATUS_NOT_LOADED
bzero(&gSeqLoadStatus, sizeof(gSeqLoadStatus)); // Same dealio
#endif
}
@@ -246,10 +239,9 @@ void *soundAlloc(struct SoundAllocPool *pool, u32 size) {
pool->numAllocatedEntries++;
return start;
#else
u8 *start;
u32 alignedSize = ALIGN16(size);
start = pool->cur;
u8 *start = pool->cur;
if ((start + alignedSize <= pool->size + pool->start)) {
bzero(start, alignedSize);
pool->cur += alignedSize;
@@ -298,29 +290,37 @@ void temporary_pool_clear(struct TemporaryPool *temporary) {
temporary->pool.cur = temporary->pool.start;
temporary->nextSide = 0;
temporary->entries[0].ptr = temporary->pool.start;
#if defined(VERSION_EU) || defined(VERSION_SH)
temporary->entries[1].ptr = temporary->pool.start + temporary->pool.size;
#else
temporary->entries[1].ptr = temporary->pool.size + temporary->pool.start;
#endif
temporary->entries[0].id = -1; // should be at 1e not 1c
temporary->entries[1].id = -1;
}
void unused_803160F8(struct SoundAllocPool *pool) {
pool->numAllocatedEntries = 0;
pool->cur = pool->start;
void sound_init_main_pools(s32 sizeForAudioInitPool) {
sound_alloc_pool_init(&gAudioInitPool, gAudioHeap, sizeForAudioInitPool);
sound_alloc_pool_init(&gAudioSessionPool, (gAudioHeap + sizeForAudioInitPool), (gAudioHeapSize - sizeForAudioInitPool));
}
extern s32 D_SH_80315EE8;
void sound_init_main_pools(s32 sizeForAudioInitPool) {
sound_alloc_pool_init(&gAudioInitPool, gAudioHeap, sizeForAudioInitPool);
sound_alloc_pool_init(&gAudioSessionPool, gAudioHeap + sizeForAudioInitPool, gAudioHeapSize - sizeForAudioInitPool);
#if PUPPYPRINT_DEBUG
audioPool[0] = sizeForAudioInitPool;
audioPool[1] = gAudioHeapSize - sizeForAudioInitPool;
#endif
#if PUPPYPRINT_DEBUG
void puppyprint_get_allocated_pools(s32 *audioPoolList) {
u32 i, j;
const struct SoundAllocPool *pools[NUM_AUDIO_POOLS] = {
&gAudioInitPool,
&gNotesAndBuffersPool,
&gSeqLoadedPool.persistent.pool,
&gSeqLoadedPool.temporary.pool,
&gBankLoadedPool.persistent.pool,
&gBankLoadedPool.temporary.pool,
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
&gBetterReverbPool,
#endif
};
for (i = 0, j = 0; j < NUM_AUDIO_POOLS; i += 2, j++) {
audioPoolList[i ] = (s32) pools[j]->size;
audioPoolList[i + 1] = (s32) (pools[j]->cur - pools[j]->start);
}
}
#endif
#ifdef VERSION_SH
#define SOUND_ALLOC_FUNC sound_alloc_uninitialized
@@ -330,52 +330,45 @@ void sound_init_main_pools(s32 sizeForAudioInitPool) {
void session_pools_init(struct PoolSplit *a) {
gAudioSessionPool.cur = gAudioSessionPool.start;
sound_alloc_pool_init(&gNotesAndBuffersPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, a->wantSeq), a->wantSeq);
sound_alloc_pool_init(&gSeqAndBankPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, a->wantCustom), a->wantCustom);
#if PUPPYPRINT_DEBUG
audioPool[2] = a->wantSeq;
audioPool[3] = a->wantCustom;
#endif
sound_alloc_pool_init(&gNotesAndBuffersPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, a->wantSeq ), a->wantSeq );
sound_alloc_pool_init(&gSeqAndBankPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, a->wantCustom ), a->wantCustom );
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
sound_alloc_pool_init(&gBetterReverbPool, SOUND_ALLOC_FUNC(&gAudioSessionPool, BETTER_REVERB_SIZE), BETTER_REVERB_SIZE);
#endif
}
void seq_and_bank_pool_init(struct PoolSplit2 *a) {
gSeqAndBankPool.cur = gSeqAndBankPool.start;
sound_alloc_pool_init(&gPersistentCommonPool, SOUND_ALLOC_FUNC(&gSeqAndBankPool, a->wantPersistent), a->wantPersistent);
sound_alloc_pool_init(&gTemporaryCommonPool, SOUND_ALLOC_FUNC(&gSeqAndBankPool, a->wantTemporary), a->wantTemporary);
#if PUPPYPRINT_DEBUG
audioPool[4] = a->wantPersistent;
audioPool[5] = a->wantTemporary;
#endif
sound_alloc_pool_init (&gTemporaryCommonPool, SOUND_ALLOC_FUNC(&gSeqAndBankPool, a->wantTemporary ), a->wantTemporary );
}
void persistent_pools_init(struct PoolSplit *a) {
gPersistentCommonPool.cur = gPersistentCommonPool.start;
sound_alloc_pool_init(&gSeqLoadedPool.persistent.pool, SOUND_ALLOC_FUNC(&gPersistentCommonPool, a->wantSeq), a->wantSeq);
sound_alloc_pool_init( &gSeqLoadedPool.persistent.pool, SOUND_ALLOC_FUNC(&gPersistentCommonPool, a->wantSeq ), a->wantSeq );
sound_alloc_pool_init(&gBankLoadedPool.persistent.pool, SOUND_ALLOC_FUNC(&gPersistentCommonPool, a->wantBank), a->wantBank);
#ifdef VERSION_SH
sound_alloc_pool_init(&gUnusedLoadedPool.persistent.pool, SOUND_ALLOC_FUNC(&gPersistentCommonPool, a->wantUnused), a->wantUnused);
#if PUPPYPRINT_DEBUG
audioPool[6] = a->wantSeq;
audioPool[7] = a->wantBank;
audioPool[8] = a->wantUnused;
#endif
#endif
persistent_pool_clear(&gSeqLoadedPool.persistent);
persistent_pool_clear(&gBankLoadedPool.persistent);
#ifdef VERSION_SH
persistent_pool_clear(&gUnusedLoadedPool.persistent);
#endif
}
void temporary_pools_init(struct PoolSplit *a) {
gTemporaryCommonPool.cur = gTemporaryCommonPool.start;
sound_alloc_pool_init(&gSeqLoadedPool.temporary.pool, SOUND_ALLOC_FUNC(&gTemporaryCommonPool, a->wantSeq), a->wantSeq);
sound_alloc_pool_init( &gSeqLoadedPool.temporary.pool, SOUND_ALLOC_FUNC(&gTemporaryCommonPool, a->wantSeq ), a->wantSeq );
sound_alloc_pool_init(&gBankLoadedPool.temporary.pool, SOUND_ALLOC_FUNC(&gTemporaryCommonPool, a->wantBank), a->wantBank);
#ifdef VERSION_SH
sound_alloc_pool_init(&gUnusedLoadedPool.temporary.pool, SOUND_ALLOC_FUNC(&gTemporaryCommonPool, a->wantUnused), a->wantUnused);
#if PUPPYPRINT_DEBUG
audioPool[9] = a->wantSeq;
audioPool[10] = a->wantBank;
audioPool[11] = a->wantUnused;
#endif
#endif
temporary_pool_clear(&gSeqLoadedPool.temporary);
temporary_pool_clear(&gBankLoadedPool.temporary);
#ifdef VERSION_SH
temporary_pool_clear(&gUnusedLoadedPool.temporary);
#endif
}
#undef SOUND_ALLOC_FUNC
@@ -463,13 +456,13 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
#endif
#if defined(VERSION_JP) || defined(VERSION_US)
leftNotLoaded = (firstVal == SOUND_LOAD_STATUS_NOT_LOADED);
leftDiscardable = (firstVal == SOUND_LOAD_STATUS_DISCARDABLE);
leftAvail = (firstVal != SOUND_LOAD_STATUS_IN_PROGRESS);
rightNotLoaded = (secondVal == SOUND_LOAD_STATUS_NOT_LOADED);
leftNotLoaded = (firstVal == SOUND_LOAD_STATUS_NOT_LOADED );
leftDiscardable = (firstVal == SOUND_LOAD_STATUS_DISCARDABLE);
leftAvail = (firstVal != SOUND_LOAD_STATUS_IN_PROGRESS);
rightNotLoaded = (secondVal == SOUND_LOAD_STATUS_NOT_LOADED );
rightDiscardable = (secondVal == SOUND_LOAD_STATUS_DISCARDABLE);
rightAvail = (secondVal != SOUND_LOAD_STATUS_IN_PROGRESS);
bothDiscardable = (leftDiscardable && rightDiscardable);
rightAvail = (secondVal != SOUND_LOAD_STATUS_IN_PROGRESS);
bothDiscardable = (leftDiscardable && rightDiscardable);
if (leftNotLoaded) {
tp->nextSide = 0;
@@ -646,22 +639,14 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
// Throw out the entry on the other side if it doesn't fit.
// (possible @bug: what if it's currently being loaded?)
table[tp->entries[1].id] = SOUND_LOAD_STATUS_NOT_LOADED;
switch (isSound) {
case FALSE:
discard_sequence(tp->entries[1].id);
break;
case TRUE:
discard_bank(tp->entries[1].id);
break;
if (isSound) {
discard_bank(tp->entries[1].id);
} else {
discard_sequence(tp->entries[1].id);
}
tp->entries[1].id = (s32)nullID;
#if defined(VERSION_EU) || defined(VERSION_SH)
tp->entries[1].ptr = pool->start + pool->size;
#else
tp->entries[1].ptr = pool->size + pool->start;
#endif
}
ret = tp->entries[0].ptr;
@@ -670,10 +655,8 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
case 1:
#if defined(VERSION_SH)
tp->entries[1].ptr = (u8 *) ((uintptr_t) (pool->start + pool->size - size) & ~0x0f);
#elif defined(VERSION_EU)
tp->entries[1].ptr = pool->start + pool->size - size - 0x10;
#else
tp->entries[1].ptr = pool->size + pool->start - size - 0x10;
tp->entries[1].ptr = pool->start + pool->size - size - 0x10;
#endif
tp->entries[1].id = id;
tp->entries[1].size = size;
@@ -686,15 +669,11 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
table[tp->entries[0].id] = SOUND_LOAD_STATUS_NOT_LOADED;
switch (isSound) {
case FALSE:
discard_sequence(tp->entries[0].id);
break;
case TRUE:
discard_bank(tp->entries[0].id);
break;
if (isSound) {
discard_bank(tp->entries[0].id);
} else {
discard_sequence(tp->entries[0].id);
}
tp->entries[0].id = (s32)nullID;
pool->cur = pool->start;
}
@@ -722,13 +701,12 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
#endif
arg0->persistent.entries[arg0->persistent.numEntries].ptr = ret;
if (ret == NULL)
if (ret == NULL) {
#else
arg0->persistent.entries[arg0->persistent.numEntries].ptr = soundAlloc(&arg0->persistent.pool, arg1 * size);
arg0->persistent.entries[arg0->persistent.numEntries].ptr = soundAlloc(&arg0->persistent.pool, (arg1 * size));
if (arg0->persistent.entries[arg0->persistent.numEntries].ptr == NULL)
if (arg0->persistent.entries[arg0->persistent.numEntries].ptr == NULL) {
#endif
{
switch (arg3) {
case 2:
#if defined(VERSION_EU)
@@ -759,7 +737,8 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
#if defined(VERSION_EU) || defined(VERSION_SH)
return arg0->persistent.entries[arg0->persistent.numEntries++].ptr;
#else
arg0->persistent.numEntries++; return arg0->persistent.entries[arg0->persistent.numEntries - 1].ptr;
arg0->persistent.numEntries++;
return arg0->persistent.entries[arg0->persistent.numEntries - 1].ptr;
#endif
#ifdef VERSION_SH
#undef isSound
@@ -768,9 +747,7 @@ void *alloc_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 size, s32 arg
#ifdef VERSION_SH
void *get_bank_or_seq(s32 poolIdx, s32 arg1, s32 id) {
void *ret;
ret = unk_pool1_lookup(poolIdx, id);
void *ret = unk_pool1_lookup(poolIdx, id);
if (ret != NULL) {
return ret;
}
@@ -826,7 +803,6 @@ void *get_bank_or_seq_inner(s32 poolIdx, s32 arg1, s32 bankId) {
#ifndef VERSION_SH
void *get_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 id) {
u32 i;
UNUSED void *ret;
struct TemporaryPool *temporary = &arg0->temporary;
if (arg1 == 0) {
@@ -850,14 +826,7 @@ void *get_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 id) {
}
if (arg1 == 2) {
#if defined(VERSION_EU) || defined(VERSION_SH)
return get_bank_or_seq(arg0, 0, id);
#else
// Prevent tail call optimization by using a temporary.
// Either copt or -Wo,-notail.
ret = get_bank_or_seq(arg0, 0, id);
return ret;
#endif
}
return NULL;
}
@@ -865,7 +834,7 @@ void *get_bank_or_seq(struct SoundMultiPool *arg0, s32 arg1, s32 id) {
#endif
#if defined(VERSION_EU) || defined(VERSION_SH)
void func_eu_802e27e4_unused(f32 arg0, f32 arg1, u16 *arg2) {
UNUSED void func_eu_802e27e4_unused(f32 arg0, f32 arg1, u16 *arg2) {
s32 i;
f32 tmp[16];
@@ -945,16 +914,16 @@ void decrease_reverb_gain(void) {
#if defined(VERSION_EU)
s32 i;
for (i = 0; i < gNumSynthesisReverbs; i++) {
gSynthesisReverbs[i].reverbGain -= gSynthesisReverbs[i].reverbGain / 8;
gSynthesisReverbs[i].reverbGain -= (gSynthesisReverbs[i].reverbGain / 8);
}
#elif defined(VERSION_JP) || defined(VERSION_US)
gSynthesisReverb.reverbGain -= gSynthesisReverb.reverbGain / 4;
gSynthesisReverb.reverbGain -= (gSynthesisReverb.reverbGain / 4);
#else
s32 i, j;
s32 v0 = gAudioBufferParameters.presetUnk4 == 2 ? 2 : 1;
s32 v0 = ((gAudioBufferParameters.presetUnk4 == 2) ? 2 : 1);
for (i = 0; i < gNumSynthesisReverbs; i++) {
for (j = 0; j < v0; j++) {
gSynthesisReverbs[i].reverbGain -= gSynthesisReverbs[i].reverbGain / 3;
gSynthesisReverbs[i].reverbGain -= (gSynthesisReverbs[i].reverbGain / 3);
}
}
#endif
@@ -962,8 +931,7 @@ void decrease_reverb_gain(void) {
#if defined(VERSION_EU) || defined(VERSION_SH)
s32 audio_shut_down_and_reset_step(void) {
s32 i;
s32 j;
s32 i, j;
switch (gAudioResetStatus) {
case 5:
@@ -997,10 +965,7 @@ s32 audio_shut_down_and_reset_step(void) {
bzero(&gAiBuffers[0][0], (AIBUFFER_LEN * NUMAIBUFFERS));
gAudioResetStatus = 0;
}
if (gAudioResetStatus < 3) {
return 0;
}
return 1;
return (gAudioResetStatus < 3);
}
#else
/**
@@ -1009,9 +974,9 @@ s32 audio_shut_down_and_reset_step(void) {
void wait_for_audio_frames(s32 frames) {
// VC emulator stubs this function because busy loops are not supported
// Technically we can put infinite loop that _looks_ like -O0 for emu but this is cleaner
//if (gIsVC)
//if (gIsVC) {
return;
//}
gAudioFrameCount = 0;
// Sound thread will update gAudioFrameCount
while (gAudioFrameCount < frames) {
@@ -1021,10 +986,9 @@ void wait_for_audio_frames(s32 frames) {
#endif
u8 sAudioFirstBoot = 0;
//Separate the reverb settings into their own func. Bit unstable currently, so still only runs at boot.
// Separate the reverb settings into their own func. Bit unstable currently, so still only runs at boot.
#if defined(VERSION_EU) || defined(VERSION_SH)
void init_reverb_eu(void)
{
void init_reverb_eu(void) {
s16 *mem;
struct AudioSessionSettingsEU *preset = &gAudioSessionPresets[0];
struct SynthesisReverb *reverb;
@@ -1032,43 +996,40 @@ void init_reverb_eu(void)
s32 i, j;
// This is called 4 times for numReverbs to work at higher values. This does eat up some memory though.
for (j = 0; j < 4; j++)
{
for (j = 0; j < 4; j++) {
gSynthesisReverbs[j].useReverb = 0;
// Both left and right channels are allocated/cleared together, then separated based on the reverb window size
if (!sAudioFirstBoot)
if (!sAudioFirstBoot) {
gSynthesisReverbs[j].ringBuffer.left = soundAlloc(&gNotesAndBuffersPool, REVERB_WINDOW_SIZE_MAX * 4);
}
}
gNumSynthesisReverbs = preset->numReverbs;
for (j = 0; j < gNumSynthesisReverbs; j++)
{
for (j = 0; j < gNumSynthesisReverbs; j++) {
reverb = &gSynthesisReverbs[j];
reverbSettings = &sReverbSettings[MIN(gAudioResetPresetIdToLoad+j, (sizeof(sReverbSettings) / sizeof(struct ReverbSettingsEU))-1)];
reverb->windowSize = reverbSettings->windowSize * 0x40;
reverbSettings = &sReverbSettings[MIN((gAudioResetPresetIdToLoad + j), (sizeof(sReverbSettings) / sizeof(struct ReverbSettingsEU)) - 1)];
reverb->windowSize = (reverbSettings->windowSize * 0x40);
reverb->downsampleRate = reverbSettings->downsampleRate;
reverb->reverbGain = reverbSettings->gain;
reverb->useReverb = 8;
if (reverb->windowSize > REVERB_WINDOW_SIZE_MAX)
if (reverb->windowSize > REVERB_WINDOW_SIZE_MAX) {
reverb->windowSize = REVERB_WINDOW_SIZE_MAX;
if (sAudioFirstBoot) {
bzero(reverb->ringBuffer.left, REVERB_WINDOW_SIZE_MAX * 4);
}
else {
reverb->resampleRate = 0x8000 / reverb->downsampleRate;
reverb->resampleStateLeft = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
reverb->resampleStateRight = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
reverb->unk24 = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
reverb->unk28 = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
for (i = 0; i < gAudioBufferParameters.updatesPerFrame; i++)
{
if (sAudioFirstBoot) {
bzero(reverb->ringBuffer.left, (REVERB_WINDOW_SIZE_MAX * 4));
} else {
reverb->resampleRate = (0x8000 / reverb->downsampleRate);
reverb->resampleStateLeft = soundAlloc(&gNotesAndBuffersPool, (16 * sizeof(s16)));
reverb->resampleStateRight = soundAlloc(&gNotesAndBuffersPool, (16 * sizeof(s16)));
reverb->unk24 = soundAlloc(&gNotesAndBuffersPool, (16 * sizeof(s16)));
reverb->unk28 = soundAlloc(&gNotesAndBuffersPool, (16 * sizeof(s16)));
for (i = 0; i < gAudioBufferParameters.updatesPerFrame; i++) {
mem = soundAlloc(&gNotesAndBuffersPool, DEFAULT_LEN_2CH);
reverb->items[0][i].toDownsampleLeft = mem;
reverb->items[0][i].toDownsampleRight = mem + DEFAULT_LEN_1CH / sizeof(s16);
reverb->items[0][i].toDownsampleLeft = mem;
reverb->items[0][i].toDownsampleRight = (mem + (DEFAULT_LEN_1CH / sizeof(s16)));
mem = soundAlloc(&gNotesAndBuffersPool, DEFAULT_LEN_2CH);
reverb->items[1][i].toDownsampleLeft = mem;
reverb->items[1][i].toDownsampleRight = mem + DEFAULT_LEN_1CH / sizeof(s16);
reverb->items[1][i].toDownsampleLeft = mem;
reverb->items[1][i].toDownsampleRight = (mem + (DEFAULT_LEN_1CH / sizeof(s16)));
}
}
@@ -1079,23 +1040,21 @@ void init_reverb_eu(void)
reverb->bufSizePerChannel = reverb->windowSize;
reverb->framesLeftToIgnore = 2;
if (reverb->downsampleRate != 1) {
reverb->resampleRate = 0x8000 / reverb->downsampleRate;
reverb->resampleRate = (0x8000 / reverb->downsampleRate);
if (sAudioFirstBoot) {
bzero(reverb->resampleStateLeft, 16 * sizeof(s16));
bzero(reverb->resampleStateRight, 16 * sizeof(s16));
bzero(reverb->unk24, 16 * sizeof(s16));
bzero(reverb->unk28, 16 * sizeof(s16));
bzero(reverb->resampleStateLeft, (16 * sizeof(s16)));
bzero(reverb->resampleStateRight, (16 * sizeof(s16)));
bzero(reverb->unk24, (16 * sizeof(s16)));
bzero(reverb->unk28, (16 * sizeof(s16)));
// All reverb downsample buffers are adjacent in memory, so clear them all in a single call
bzero(reverb->items[0][0].toDownsampleLeft, DEFAULT_LEN_1CH * 4 * gAudioBufferParameters.updatesPerFrame);
bzero(reverb->items[0][0].toDownsampleLeft, (DEFAULT_LEN_1CH * 4 * gAudioBufferParameters.updatesPerFrame));
}
}
}
}
#else
void init_reverb_us(s32 presetId)
{
s32 reverbWindowSize;
void init_reverb_us(s32 presetId) {
s16 *mem;
s32 i;
#ifdef BETTER_REVERB
@@ -1103,117 +1062,96 @@ void init_reverb_us(s32 presetId)
s32 bufOffset = 0;
#endif
reverbWindowSize = gReverbSettings[presetId].windowSize;
s32 reverbWindowSize = gReverbSettings[presetId].windowSize;
gReverbDownsampleRate = gReverbSettings[presetId].downsampleRate;
#ifdef BETTER_REVERB
if (gIsConsole)
if (gIsConsole) {
reverbConsole = betterReverbDownsampleConsole; // Console!
else
} else {
reverbConsole = betterReverbDownsampleEmulator; // Setting this to 1 is REALLY slow, please use sparingly!
}
if (reverbConsole <= 0) {
reverbConsole = 1;
toggleBetterReverb = FALSE;
}
else {
} else {
toggleBetterReverb = TRUE;
}
if (toggleBetterReverb && betterReverbWindowsSize >= 0)
if (toggleBetterReverb && betterReverbWindowsSize >= 0) {
reverbWindowSize = betterReverbWindowsSize;
if (gReverbDownsampleRate < (1 << (reverbConsole - 1)))
gReverbDownsampleRate = (1 << (reverbConsole - 1));
reverbWindowSize /= gReverbDownsampleRate;
if (reverbWindowSize < DEFAULT_LEN_2CH) // Minimum window size to not overflow
reverbWindowSize = DEFAULT_LEN_2CH;
#endif
switch (gReverbDownsampleRate) {
case 1:
sReverbDownsampleRateLog = 0;
break;
case 2:
sReverbDownsampleRateLog = 1;
break;
case 4:
sReverbDownsampleRateLog = 2;
break;
case 8:
sReverbDownsampleRateLog = 3;
break;
case 16:
sReverbDownsampleRateLog = 4;
break;
default:
sReverbDownsampleRateLog = 0;
}
if (gReverbDownsampleRate < (1 << (reverbConsole - 1))) {
gReverbDownsampleRate = (1 << (reverbConsole - 1));
}
reverbWindowSize /= gReverbDownsampleRate;
if (reverbWindowSize < DEFAULT_LEN_2CH) { // Minimum window size to not overflow
reverbWindowSize = DEFAULT_LEN_2CH;
}
#endif
if (reverbWindowSize == 0) {
gSynthesisReverb.useReverb = 0;
} else {
gSynthesisReverb.useReverb = 8;
if (reverbWindowSize > REVERB_WINDOW_SIZE_MAX)
if (reverbWindowSize > REVERB_WINDOW_SIZE_MAX) {
reverbWindowSize = REVERB_WINDOW_SIZE_MAX;
}
// Both left and right channels are allocated/cleared together, then separated based on the reverb window size
if (!sAudioFirstBoot) {
gSynthesisReverb.ringBuffer.left = soundAlloc(&gNotesAndBuffersPool, REVERB_WINDOW_SIZE_MAX * 2 * sizeof(s16));
gSynthesisReverb.ringBuffer.left = soundAlloc(&gNotesAndBuffersPool, REVERB_WINDOW_SIZE_MAX * 2 * sizeof(s16));
gSynthesisReverb.resampleStateLeft = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
gSynthesisReverb.resampleStateRight = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
gSynthesisReverb.unk24 = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
gSynthesisReverb.unk28 = soundAlloc(&gNotesAndBuffersPool, 16 * sizeof(s16));
gSynthesisReverb.resampleStateLeft = soundAlloc(&gNotesAndBuffersPool, (16 * sizeof(s16)));
gSynthesisReverb.resampleStateRight = soundAlloc(&gNotesAndBuffersPool, (16 * sizeof(s16)));
gSynthesisReverb.unk24 = soundAlloc(&gNotesAndBuffersPool, (16 * sizeof(s16)));
gSynthesisReverb.unk28 = soundAlloc(&gNotesAndBuffersPool, (16 * sizeof(s16)));
for (i = 0; i < gAudioUpdatesPerFrame; i++) {
mem = soundAlloc(&gNotesAndBuffersPool, DEFAULT_LEN_2CH);
gSynthesisReverb.items[0][i].toDownsampleLeft = mem;
gSynthesisReverb.items[0][i].toDownsampleRight = mem + DEFAULT_LEN_1CH / sizeof(s16);
gSynthesisReverb.items[0][i].toDownsampleLeft = mem;
gSynthesisReverb.items[0][i].toDownsampleRight = (mem + (DEFAULT_LEN_1CH / sizeof(s16)));
mem = soundAlloc(&gNotesAndBuffersPool, DEFAULT_LEN_2CH);
gSynthesisReverb.items[1][i].toDownsampleLeft = mem;
gSynthesisReverb.items[1][i].toDownsampleRight = mem + DEFAULT_LEN_1CH / sizeof(s16);
gSynthesisReverb.items[1][i].toDownsampleLeft = mem;
gSynthesisReverb.items[1][i].toDownsampleRight = (mem + (DEFAULT_LEN_1CH / sizeof(s16)));
}
}
else {
bzero(gSynthesisReverb.ringBuffer.left, REVERB_WINDOW_SIZE_MAX * 2 * sizeof(s16));
#ifdef BETTER_REVERB
delayBufsL = (s32**) soundAlloc(&gBetterReverbPool, BETTER_REVERB_PTR_SIZE);
delayBufsR = &delayBufsL[NUM_ALLPASS];
delayBufsL[0] = (s32*) soundAlloc(&gBetterReverbPool, BETTER_REVERB_SIZE - BETTER_REVERB_PTR_SIZE);
#endif
} else {
bzero(gSynthesisReverb.ringBuffer.left, (REVERB_WINDOW_SIZE_MAX * 2 * sizeof(s16)));
}
gSynthesisReverb.ringBuffer.right = &gSynthesisReverb.ringBuffer.left[reverbWindowSize];
gSynthesisReverb.ringBuffer.right = &gSynthesisReverb.ringBuffer.left[reverbWindowSize];
gSynthesisReverb.nextRingBufferPos = 0;
gSynthesisReverb.unkC = 0;
gSynthesisReverb.curFrame = 0;
gSynthesisReverb.unkC = 0;
gSynthesisReverb.curFrame = 0;
gSynthesisReverb.bufSizePerChannel = reverbWindowSize;
gSynthesisReverb.reverbGain = gReverbSettings[presetId].gain;
gSynthesisReverb.framesLeftToIgnore = 2;
if (gReverbDownsampleRate != 1) {
gSynthesisReverb.resampleFlags = A_INIT;
gSynthesisReverb.resampleRate = 0x8000 / gReverbDownsampleRate;
gSynthesisReverb.resampleRate = (0x8000 / gReverbDownsampleRate);
if (sAudioFirstBoot) {
bzero(gSynthesisReverb.resampleStateLeft, 16 * sizeof(s16));
bzero(gSynthesisReverb.resampleStateRight, 16 * sizeof(s16));
bzero(gSynthesisReverb.unk24, 16 * sizeof(s16));
bzero(gSynthesisReverb.unk28, 16 * sizeof(s16));
bzero(gSynthesisReverb.resampleStateLeft, (16 * sizeof(s16)));
bzero(gSynthesisReverb.resampleStateRight, (16 * sizeof(s16)));
bzero(gSynthesisReverb.unk24, (16 * sizeof(s16)));
bzero(gSynthesisReverb.unk28, (16 * sizeof(s16)));
// All reverb downsample buffers are adjacent in memory, so clear them all in a single call
bzero(gSynthesisReverb.items[0][0].toDownsampleLeft, DEFAULT_LEN_1CH * 4 * gAudioUpdatesPerFrame);
bzero(gSynthesisReverb.items[0][0].toDownsampleLeft, (DEFAULT_LEN_1CH * 4 * gAudioUpdatesPerFrame));
}
}
// This does not have to be reset after being initialized for the first time, which would speed up load times dramatically.
// However, reseting this allows for proper clearing of the reverb buffers, as well as dynamic customization of the delays array.
// This does not have to be reset after being initialized for the first time, which would speed up load times dramatically.
// However, reseting this allows for proper clearing of the reverb buffers, as well as dynamic customization of the delays array.
#ifdef BETTER_REVERB
if (toggleBetterReverb) {
if (!sAudioFirstBoot) {
delayBufsL = (s32**) soundAlloc(&gAudioSessionPool, NUM_ALLPASS * sizeof(s32*));
delayBufsR = (s32**) soundAlloc(&gAudioSessionPool, NUM_ALLPASS * sizeof(s32*));
delayBufsL[0] = (s32*) soundAlloc(&gAudioSessionPool, ALIGN16(BETTER_REVERB_SIZE - 0x80));
}
else {
bzero(delayBufsL[0], ALIGN16(BETTER_REVERB_SIZE - 0x80)); // Can maybe be simplified to clear only the previous allocation size
}
if (sAudioFirstBoot) {
bzero(delayBufsL[0], (BETTER_REVERB_SIZE - BETTER_REVERB_PTR_SIZE));
}
for (i = 0; i < NUM_ALLPASS; ++i) {
delaysL[i] = delaysBaselineL[i] / gReverbDownsampleRate;
delaysR[i] = delaysBaselineR[i] / gReverbDownsampleRate;
delaysL[i] = (delaysBaselineL[i] / gReverbDownsampleRate);
delaysR[i] = (delaysBaselineR[i] / gReverbDownsampleRate);
delayBufsL[i] = (s32*) &delayBufsL[0][bufOffset];
bufOffset += delaysL[i];
delayBufsR[i] = (s32*) &delayBufsL[0][bufOffset]; // L and R buffers are interpolated adjacently in memory; not a bug
@@ -1228,45 +1166,36 @@ void init_reverb_us(s32 presetId)
#if defined(VERSION_JP) || defined(VERSION_US)
void audio_reset_session(struct AudioSessionSettings *preset, s32 presetId) {
if (sAudioFirstBoot)
{
if (sAudioFirstBoot) {
bzero(&gAiBuffers[0][0], (AIBUFFER_LEN * NUMAIBUFFERS));
gAudioSessionPool.cur = gAudioSessionPool.start;
gSeqAndBankPool.cur = gSeqAndBankPool.start;
gPersistentCommonPool.cur = gPersistentCommonPool.start;
gTemporaryCommonPool.cur = gTemporaryCommonPool.start;
persistent_pool_clear(&gSeqLoadedPool.persistent);
persistent_pool_clear(&gBankLoadedPool.persistent);
persistent_pool_clear(&gUnusedLoadedPool.persistent);
temporary_pool_clear(&gSeqLoadedPool.temporary);
temporary_pool_clear(&gBankLoadedPool.temporary);
temporary_pool_clear(&gUnusedLoadedPool.temporary);
temporary_pool_clear( &gSeqLoadedPool.temporary);
temporary_pool_clear( &gBankLoadedPool.temporary);
reset_bank_and_seq_load_status();
init_reverb_us(presetId);
bzero(&gAiBuffers[0][0], (AIBUFFER_LEN * NUMAIBUFFERS));
gAudioFrameCount = 0;
if (!gIsVC)
if (!gIsVC) {
while (gAudioFrameCount < 1) {
// spin
}
}
bzero(&gAiBuffers[0][0], (AIBUFFER_LEN * NUMAIBUFFERS));
return;
}
#else
void audio_reset_session(void) {
if (sAudioFirstBoot)
{
gAudioSessionPool.cur = gAudioSessionPool.start;
gSeqAndBankPool.cur = gSeqAndBankPool.start;
gPersistentCommonPool.cur = gPersistentCommonPool.start;
gTemporaryCommonPool.cur = gTemporaryCommonPool.start;
if (sAudioFirstBoot) {
persistent_pool_clear(&gSeqLoadedPool.persistent);
persistent_pool_clear(&gBankLoadedPool.persistent);
persistent_pool_clear(&gUnusedLoadedPool.persistent);
temporary_pool_clear(&gSeqLoadedPool.temporary);
temporary_pool_clear(&gBankLoadedPool.temporary);
#ifdef VERSION_SH
persistent_pool_clear(&gUnusedLoadedPool.persistent);
temporary_pool_clear(&gUnusedLoadedPool.temporary);
#endif
reset_bank_and_seq_load_status();
init_reverb_eu();
@@ -1399,8 +1328,7 @@ void audio_reset_session(void) {
gVolume = preset->volume;
gMinAiBufferLength = gSamplesPerFrameTarget - 0x10;
updatesPerFrame = gSamplesPerFrameTarget / 160 + 1;
gAudioUpdatesPerFrame = gSamplesPerFrameTarget / 160 + 1;
gAudioUpdatesPerFrame = updatesPerFrame = gSamplesPerFrameTarget / 160 + 1;
// Compute conversion ratio from the internal unit tatums/tick to the
// external beats/minute (JP) or tatums/minute (US). In practice this is
@@ -1424,7 +1352,7 @@ void audio_reset_session(void) {
temporaryMem = DOUBLE_SIZE_ON_64_BIT(preset->temporaryBankMem + preset->temporarySeqMem);
#endif
totalMem = persistentMem + temporaryMem;
wantMisc = gAudioSessionPool.size - totalMem - 0x100 - BETTER_REVERB_SIZE;
wantMisc = gAudioSessionPool.size - totalMem - BETTER_REVERB_SIZE;
sSessionPoolSplit.wantSeq = wantMisc;
sSessionPoolSplit.wantCustom = totalMem;
session_pools_init(&sSessionPoolSplit);
@@ -1515,11 +1443,8 @@ void *unk_pool1_lookup(s32 poolIdx, s32 id) {
}
void *unk_pool1_alloc(s32 poolIndex, s32 arg1, u32 size) {
void *ret;
s32 pos;
pos = gUnkPool1.pool.numAllocatedEntries;
ret = sound_alloc_uninitialized(&gUnkPool1.pool, size);
s32 pos = gUnkPool1.pool.numAllocatedEntries;
void *ret = sound_alloc_uninitialized(&gUnkPool1.pool, size);
gUnkPool1.entries[pos].ptr = ret;
if (ret == NULL) {
return NULL;
@@ -1532,9 +1457,7 @@ void *unk_pool1_alloc(s32 poolIndex, s32 arg1, u32 size) {
}
u8 *func_sh_802f1d40(u32 size, s32 bank, u8 *arg2, s8 medium) {
struct UnkEntry *ret;
ret = func_sh_802f1ec4(size);
struct UnkEntry *ret = func_sh_802f1ec4(size);
if (ret != NULL) {
ret->bankId = bank;
ret->dstAddr = arg2;
@@ -1543,10 +1466,9 @@ u8 *func_sh_802f1d40(u32 size, s32 bank, u8 *arg2, s8 medium) {
}
return NULL;
}
u8 *func_sh_802f1d90(u32 size, s32 bank, u8 *arg2, s8 medium) {
struct UnkEntry *ret;
ret = unk_pool2_alloc(size);
struct UnkEntry *ret = unk_pool2_alloc(size);
if (ret != NULL) {
ret->bankId = bank;
ret->dstAddr = arg2;
@@ -1555,22 +1477,9 @@ u8 *func_sh_802f1d90(u32 size, s32 bank, u8 *arg2, s8 medium) {
}
return NULL;
}
u8 *func_sh_802f1de0(u32 size, s32 bank, u8 *arg2, s8 medium) { // duplicated function?
struct UnkEntry *ret;
ret = unk_pool2_alloc(size);
if (ret != NULL) {
ret->bankId = bank;
ret->dstAddr = arg2;
ret->medium = medium;
return ret->srcAddr;
}
return NULL;
}
void unk_pools_init(u32 size1, u32 size2) {
void *mem;
mem = sound_alloc_uninitialized(&gPersistentCommonPool, size1);
void *mem = sound_alloc_uninitialized(&gPersistentCommonPool, size1);
if (mem == NULL) {
gUnkPool2.pool.size = 0;
} else {
@@ -1589,13 +1498,9 @@ void unk_pools_init(u32 size1, u32 size2) {
}
struct UnkEntry *func_sh_802f1ec4(u32 size) {
u8 *temp_s2;
u8 *phi_s3;
u8 *memLocation;
u8 *cur;
s32 i;
s32 chosenIndex;
struct UnkStructSH8034EC88 *unkStruct;
struct UnkPool *pool = &gUnkPool3;
@@ -1603,8 +1508,8 @@ struct UnkEntry *func_sh_802f1ec4(u32 size) {
u8 *itemStart;
u8 *itemEnd;
phi_s3 = pool->pool.cur;
memLocation = sound_alloc_uninitialized(&pool->pool, size);
u8 *phi_s3 = pool->pool.cur;
u8 *memLocation = sound_alloc_uninitialized(&pool->pool, size);
if (memLocation == NULL) {
cur = pool->pool.cur;
pool->pool.cur = pool->pool.start;
@@ -1615,9 +1520,9 @@ struct UnkEntry *func_sh_802f1ec4(u32 size) {
}
phi_s3 = pool->pool.start;
}
temp_s2 = pool->pool.cur;
u8 *temp_s2 = pool->pool.cur;
chosenIndex = -1;
s32 chosenIndex = -1;
for (i = 0; i < D_SH_8034F68C; i++) {
unkStruct = &D_SH_8034EC88[i];
if (unkStruct->isFree == FALSE) {
@@ -1641,7 +1546,7 @@ struct UnkEntry *func_sh_802f1ec4(u32 size) {
continue;
}
itemStart = pool->entries[i].srcAddr;
itemEnd = itemStart + pool->entries[i].size - 1;
itemEnd = ((itemStart + pool->entries[i].size) - 1);
if (itemEnd < phi_s3 && itemStart < phi_s3) {
continue;
@@ -1670,10 +1575,8 @@ struct UnkEntry *func_sh_802f1ec4(u32 size) {
void func_sh_802f2158(struct UnkEntry *entry) {
s32 idx;
s32 seqCount;
s32 bankId1;
s32 bankId2;
s32 instId;
s32 drumId;
s32 bankId1, bankId2;
s32 instId, drumId;
struct Drum *drum;
struct Instrument *inst;
@@ -1683,7 +1586,7 @@ void func_sh_802f2158(struct UnkEntry *entry) {
bankId2 = gCtlEntries[idx].bankId2;
if ((bankId1 != 0xff && entry->bankId == bankId1) || (bankId2 != 0xff && entry->bankId == bankId2) || entry->bankId == 0) {
if (get_bank_or_seq(1, 2, idx) != NULL) {
if (IS_BANK_LOAD_COMPLETE(idx) != FALSE) {
if (IS_BANK_LOAD_COMPLETE(idx)) {
for (instId = 0; instId < gCtlEntries[idx].numInstruments; instId++) {
inst = get_instrument_inner(idx, instId);
if (inst != NULL) {
@@ -1733,13 +1636,10 @@ struct UnkEntry *unk_pool2_alloc(u32 size) {
}
void func_sh_802f23ec(void) {
s32 i;
s32 idx;
s32 i, idx;
s32 seqCount;
s32 bankId1;
s32 bankId2;
s32 instId;
s32 drumId;
s32 bankId1, bankId2;
s32 instId, drumId;
struct Drum *drum;
struct Instrument *inst;
struct UnkEntry *entry = NULL; //! @bug: not initialized but nevertheless used
@@ -1750,7 +1650,7 @@ void func_sh_802f23ec(void) {
bankId2 = gCtlEntries[idx].bankId2;
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) {
if (IS_BANK_LOAD_COMPLETE(idx)) {
for (i = 0; i < gUnkPool2.numEntries; i++) {
entry = &gUnkPool2.entries[i];
for (instId = 0; instId < gCtlEntries[idx].numInstruments; instId++) {
@@ -1778,16 +1678,3 @@ void func_sh_802f23ec(void) {
}
}
#endif
#ifdef VERSION_EU
u8 audioString22[] = "SFrame Sample %d %d %d\n";
u8 audioString23[] = "AHPBASE %x\n";
u8 audioString24[] = "AHPCUR %x\n";
u8 audioString25[] = "HeapTop %x\n";
u8 audioString26[] = "SynoutRate %d / %d \n";
u8 audioString27[] = "FXSIZE %d\n";
u8 audioString28[] = "FXCOMP %d\n";
u8 audioString29[] = "FXDOWN %d\n";
u8 audioString30[] = "WaveCacheLen: %d\n";
u8 audioString31[] = "SpecChange Finished\n";
#endif
+18 -20
View File
@@ -5,18 +5,19 @@
#include "internal.h"
#define SOUND_LOAD_STATUS_NOT_LOADED 0
#define SOUND_LOAD_STATUS_IN_PROGRESS 1
#define SOUND_LOAD_STATUS_COMPLETE 2
#define SOUND_LOAD_STATUS_DISCARDABLE 3
#define SOUND_LOAD_STATUS_4 4
#define SOUND_LOAD_STATUS_5 5
enum SoundLoadStatus {
SOUND_LOAD_STATUS_NOT_LOADED,
SOUND_LOAD_STATUS_IN_PROGRESS,
SOUND_LOAD_STATUS_COMPLETE,
SOUND_LOAD_STATUS_DISCARDABLE,
SOUND_LOAD_STATUS_4,
SOUND_LOAD_STATUS_5
};
#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 +35,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 +58,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 +79,7 @@ struct UnkEntry
u32 size;
};
struct UnkPool
{
struct UnkPool {
/*0x00*/ struct SoundAllocPool pool;
/*0x10*/ struct UnkEntry entries[64];
/*0x510*/ s32 numEntries;
@@ -118,6 +113,9 @@ void *soundAlloc(struct SoundAllocPool *pool, u32 size);
void *sound_alloc_uninitialized(struct SoundAllocPool *pool, u32 size);
void sound_init_main_pools(s32 sizeForAudioInitPool);
void sound_alloc_pool_init(struct SoundAllocPool *pool, void *memAddr, u32 size);
#if PUPPYPRINT_DEBUG
void puppyprint_get_allocated_pools(s32 *audioPoolList);
#endif
#ifdef VERSION_SH
void *alloc_bank_or_seq(s32 poolIdx, s32 size, s32 arg3, s32 id);
void *get_bank_or_seq(s32 poolIdx, s32 arg1, s32 id);
+70 -93
View File
@@ -24,33 +24,38 @@
#define NO_LAYER ((struct SequenceChannelLayer *)(-1))
#define MUTE_BEHAVIOR_STOP_SCRIPT 0x80 // stop processing sequence/channel scripts
#define MUTE_BEHAVIOR_STOP_NOTES 0x40 // prevent further notes from playing
#define MUTE_BEHAVIOR_SOFTEN 0x20 // lower volume, by default to half
enum MuteBehaviors {
MUTE_BEHAVIOR_STOP_SCRIPT = (1 << 7), // 0x80 // stop processing sequence/channel scripts
MUTE_BEHAVIOR_STOP_NOTES = (1 << 6), // 0x40 // prevent further notes from playing
MUTE_BEHAVIOR_SOFTEN = (1 << 5), // 0x20 // lower volume, by default to half
};
#define SEQUENCE_PLAYER_STATE_0 0
#define SEQUENCE_PLAYER_STATE_FADE_OUT 1
#define SEQUENCE_PLAYER_STATE_2 2
#define SEQUENCE_PLAYER_STATE_3 3
#define SEQUENCE_PLAYER_STATE_4 4
enum SequencePlayerStates {
SEQUENCE_PLAYER_STATE_0,
SEQUENCE_PLAYER_STATE_FADE_OUT,
SEQUENCE_PLAYER_STATE_2,
SEQUENCE_PLAYER_STATE_3,
SEQUENCE_PLAYER_STATE_4
};
#define NOTE_PRIORITY_DISABLED 0
#define NOTE_PRIORITY_STOPPING 1
#define NOTE_PRIORITY_MIN 2
#define NOTE_PRIORITY_DEFAULT 3
enum NotePriority {
NOTE_PRIORITY_DISABLED,
NOTE_PRIORITY_STOPPING,
NOTE_PRIORITY_MIN,
NOTE_PRIORITY_DEFAULT
};
#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
enum Codecs {
CODEC_ADPCM,
CODEC_S8,
CODEC_SKIP
};
#define TEMPO_SCALE TATUMS_PER_BEAT
// TODO: US_FLOAT should probably be renamed to JP_DOUBLE since eu seems to use floats too
#define US_FLOAT(x) x ## f
// Convert u8 or u16 to f32. On JP, this uses a u32->f32 conversion,
// resulting in more bloated codegen, while on US it goes through s32.
// Since u8 and u16 fit losslessly in both, behavior is the same.
@@ -95,8 +100,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.
@@ -113,8 +117,7 @@ struct AudioListItem
struct NotePool *pool;
}; // size = 0x10
struct NotePool
{
struct NotePool {
struct AudioListItem disabled;
struct AudioListItem decaying;
struct AudioListItem releasing;
@@ -156,8 +159,7 @@ struct AdsrEnvelope {
s16 arg;
}; // size = 0x4
struct AdpcmLoop
{
struct AdpcmLoop {
u32 start;
u32 end;
u32 count;
@@ -165,15 +167,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;
@@ -192,14 +192,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;
@@ -210,8 +208,7 @@ struct Instrument
/*0x18*/ struct AudioBankSound highNotesSound;
}; // size = 0x20
struct Drum
{
struct Drum {
u8 releaseRate;
u8 pan;
u8 loaded;
@@ -219,14 +216,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
@@ -248,8 +243,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;
@@ -327,8 +321,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;
@@ -390,8 +383,7 @@ struct ReverbInfo {
s16 *filter;
};
struct NoteAttributes
{
struct NoteAttributes {
u8 reverbVol;
#ifdef VERSION_SH
u8 synthesisVolume; // UQ4.4, although 0 <= x < 1 is rounded up to 1
@@ -414,8 +406,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;
@@ -497,8 +488,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;
@@ -556,8 +546,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;
@@ -572,8 +561,7 @@ struct NoteSynthesisState
/*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;
@@ -593,20 +581,19 @@ struct NotePlaybackState
/*0x74, 0x4C, */ struct Portamento portamento;
/*0x84, 0x5C, */ struct VibratoState vibratoState;
};
struct NoteSubEu
{
/*0x00*/ volatile u8 enabled : 1;
/*0x00*/ u8 needsInit : 1;
/*0x00*/ u8 finished : 1;
/*0x00*/ u8 envMixerNeedsInit : 1;
/*0x00*/ u8 stereoStrongRight : 1;
/*0x00*/ u8 stereoStrongLeft : 1;
/*0x00*/ u8 stereoHeadsetEffects : 1;
struct NoteSubEu {
/*0x00*/ volatile u8 enabled : 1;
/*0x00*/ u8 needsInit : 1;
/*0x00*/ u8 finished : 1;
/*0x00*/ u8 envMixerNeedsInit : 1;
/*0x00*/ u8 stereoStrongRight : 1;
/*0x00*/ u8 stereoStrongLeft : 1;
/*0x00*/ u8 stereoHeadsetEffects : 1;
/*0x00*/ u8 usesHeadsetPanEffects : 1;
/*0x01*/ u8 reverbIndex : 3;
/*0x01*/ u8 bookOffset : 3;
/*0x01*/ u8 isSyntheticWave : 1;
/*0x01*/ u8 hasTwoAdpcmParts : 1;
/*0x01*/ u8 reverbIndex : 3;
/*0x01*/ u8 bookOffset : 3;
/*0x01*/ u8 isSyntheticWave : 1;
/*0x01*/ u8 hasTwoAdpcmParts : 1;
#ifdef VERSION_EU
/*0x02*/ u8 bankId;
#else
@@ -614,8 +601,8 @@ struct NoteSubEu
#endif
/*0x03*/ u8 headsetPanRight;
/*0x04*/ u8 headsetPanLeft;
/*0x05*/ u8 reverbVol; // UQ0.7 (EU Q1.7)
/*0x06*/ u16 targetVolLeft; // UQ0.12 (EU UQ0.10)
/*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 {
@@ -626,8 +613,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;
@@ -662,22 +648,20 @@ 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;
/*0x00*/ u8 restart : 1;
/*0x00*/ u8 finished : 1;
/*0x00*/ u8 envMixerNeedsInit : 1;
/*0x00*/ u8 stereoStrongRight : 1;
/*0x00*/ u8 stereoStrongLeft : 1;
/*0x00*/ u8 enabled : 1;
/*0x00*/ u8 needsInit : 1;
/*0x00*/ u8 restart : 1;
/*0x00*/ u8 finished : 1;
/*0x00*/ u8 envMixerNeedsInit : 1;
/*0x00*/ u8 stereoStrongRight : 1;
/*0x00*/ u8 stereoStrongLeft : 1;
/*0x00*/ u8 stereoHeadsetEffects : 1;
/*0x01*/ u8 usesHeadsetPanEffects;
/*0x02*/ u8 unk2;
@@ -719,8 +703,7 @@ struct Note
}; // size = 0xC0
#endif
struct NoteSynthesisBuffers
{
struct NoteSynthesisBuffers {
s16 adpcmdecState[0x10];
s16 finalResampleState[0x10];
#ifdef VERSION_SH
@@ -739,21 +722,18 @@ struct NoteSynthesisBuffers
};
#ifdef VERSION_EU
struct ReverbSettingsEU
{
struct ReverbSettingsEU {
u8 downsampleRate;
u8 windowSize; // To be multiplied by 64
u16 gain;
};
#else
struct ReverbSettingsUS
{
struct ReverbSettingsUS {
u8 downsampleRate;
u16 windowSize;
u16 gain;
};
struct ReverbSettingsEU
{
struct ReverbSettingsEU {
u8 downsampleRate; // always 1
u8 windowSize; // To be multiplied by 16
u16 gain;
@@ -766,8 +746,7 @@ struct ReverbSettingsEU
};
#endif
struct AudioSessionSettingsEU
{
struct AudioSessionSettingsEU {
/* 0x00 */ u32 frequency;
/* 0x04 */ u8 unk1; // always 1
/* 0x05 */ u8 maxSimultaneousNotes;
@@ -790,8 +769,7 @@ struct AudioSessionSettingsEU
#endif
}; // 0x30 on shindou
struct AudioSessionSettings
{
struct AudioSessionSettings {
/*0x00*/ u32 frequency;
/*0x04*/ u8 maxSimultaneousNotes;
/*0x05*/ u8 reverbDownsampleRate; // always 1
@@ -882,7 +860,6 @@ struct UnkStruct80343D00 {
};
// in external.c
extern s32 D_SH_80343CF0;
extern struct UnkStruct80343D00 D_SH_80343D00;
#endif
+75 -138
View File
@@ -100,7 +100,7 @@ extern u8 gSoundDataRaw[]; // sound_data.tbl
extern u8 gMusicData[]; // sequences.s
extern u8 gBankSetsData[]; // bank_sets.s
ALSeqFile *get_audio_file_header(s32 arg0);
ALSeqFile *get_audio_file_header(s32 poolIdx);
/**
* Performs an immediate DMA copy
@@ -137,14 +137,14 @@ u8 audioString49[] = "BANK LOAD MISS! FOR %d\n";
* Performs an asynchronus (normal priority) DMA copy
*/
void audio_dma_copy_async(uintptr_t devAddr, void *vAddr, size_t nbytes, OSMesgQueue *queue, OSIoMesg *mesg) {
#if PUPPYPRINT_DEBUG
#if PUPPYPRINT_DEBUG
OSTime first = osGetTime();
#endif
#endif
osInvalDCache(vAddr, nbytes);
osPiStartDma(mesg, OS_MESG_PRI_NORMAL, OS_READ, devAddr, vAddr, nbytes, queue);
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += osGetTime()-first;
#endif
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += (osGetTime() - first);
#endif
}
/**
@@ -152,22 +152,18 @@ void audio_dma_copy_async(uintptr_t devAddr, void *vAddr, size_t nbytes, OSMesgQ
* to 0x1000 bytes transfer at once.
*/
void audio_dma_partial_copy_async(uintptr_t *devAddr, u8 **vAddr, ssize_t *remaining, OSMesgQueue *queue, OSIoMesg *mesg) {
#if PUPPYPRINT_DEBUG
#if PUPPYPRINT_DEBUG
OSTime first = osGetTime();
#endif
#if defined(VERSION_EU)
ssize_t transfer = (*remaining >= 0x1000 ? 0x1000 : *remaining);
#else
ssize_t transfer = (*remaining < 0x1000 ? *remaining : 0x1000);
#endif
ssize_t transfer = MIN(*remaining, 0x1000);
*remaining -= transfer;
osInvalDCache(*vAddr, transfer);
osPiStartDma(mesg, OS_MESG_PRI_NORMAL, OS_READ, *devAddr, *vAddr, transfer, queue);
*devAddr += transfer;
*vAddr += transfer;
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += osGetTime()-first;
#endif
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += (osGetTime() - first);
#endif
}
void decrease_sample_dma_ttls() {
@@ -212,9 +208,9 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) {
u32 i;
u32 dmaIndex;
ssize_t bufferPos;
#if PUPPYPRINT_DEBUG
#if PUPPYPRINT_DEBUG
OSTime first = osGetTime();
#endif
#endif
if (arg2 != 0 || *dmaIndexRef >= sSampleDmaListSize1) {
for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) {
@@ -239,15 +235,12 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) {
}
dma->ttl = 60;
*dmaIndexRef = (u8) i;
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += (osGetTime() - first);
#endif
#if defined(VERSION_EU)
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += osGetTime()-first;
#endif
return &dma->buffer[(devAddr - dma->source)];
#else
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += osGetTime()-first;
#endif
return (devAddr - dma->source) + dma->buffer;
#endif
}
@@ -284,14 +277,14 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) {
}
dma->ttl = 2;
#if defined(VERSION_EU)
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += osGetTime()-first;
#endif
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += (osGetTime() - first);
#endif
return dma->buffer + (devAddr - dma->source);
#else
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += osGetTime()-first;
#endif
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += (osGetTime() - first);
#endif
return (devAddr - dma->source) + dma->buffer;
#endif
}
@@ -317,18 +310,18 @@ void *dma_sample_data(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) {
osPiStartDma(&gCurrAudioFrameDmaIoMesgBufs[gCurrAudioFrameDmaCount++], OS_MESG_PRI_NORMAL,
OS_READ, dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue);
*dmaIndexRef = dmaIndex;
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += osGetTime()-first;
#endif
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += (osGetTime() - first);
#endif
return (devAddr - dmaDevAddr) + dma->buffer;
#else
gCurrAudioFrameDmaCount++;
osPiStartDma(&gCurrAudioFrameDmaIoMesgBufs[gCurrAudioFrameDmaCount - 1], OS_MESG_PRI_NORMAL,
OS_READ, dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue);
*dmaIndexRef = dmaIndex;
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += osGetTime()-first;
#endif
#if PUPPYPRINT_DEBUG
dmaAudioTime[perfIteration] += (osGetTime() - first);
#endif
return dma->buffer + (devAddr - dmaDevAddr);
#endif
}
@@ -349,11 +342,10 @@ void init_sample_dma_buffers(UNUSED s32 arg0) {
#endif
#if defined(VERSION_EU)
for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++)
for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++) {
#else
for (i = 0; i < gMaxSimultaneousNotes * 3; i++)
for (i = 0; i < gMaxSimultaneousNotes * 3; i++) {
#endif
{
sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, sDmaBufSize);
if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) {
#if defined(VERSION_EU)
@@ -436,7 +428,6 @@ UNUSED static
void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED u8 *offsetBase) {
struct AudioBankSample *sample;
void *patched;
UNUSED u8 *mem; // unused on US
#define PATCH(x, base) (patched = (void *)((uintptr_t) (x) + (uintptr_t) base))
@@ -451,7 +442,7 @@ void patch_sound(UNUSED struct AudioBankSound *sound, UNUSED u8 *memBase, UNUSED
#if defined(VERSION_EU)
else if (sample->loaded == 0x80) {
PATCH(sample->sampleAddr, offsetBase);
mem = soundAlloc(&gNotesAndBuffersPool, sample->sampleSize);
u8 *mem = soundAlloc(&gNotesAndBuffersPool, sample->sampleSize); // TODO: Memory leak!
if (mem == NULL) {
sample->sampleAddr = patched;
sample->loaded = 1;
@@ -502,97 +493,60 @@ void patch_audio_bank(struct AudioBank *mem, u8 *offset, u32 numInstruments, u32
struct Instrument *instrument;
struct Instrument **itInstrs;
struct Instrument **end;
struct AudioBank *temp;
u32 i;
void *patched;
struct Drum *drum;
struct Drum **drums;
#if defined(VERSION_EU)
u32 numDrums2;
#endif
#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_JP) || defined(VERSION_US)
#define BASE_OFFSET(x, base) BASE_OFFSET_REAL(x, base)
#else
#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
numDrums2 = numDrums;
struct Drum **drums = mem->drums;
u32 numDrums2 = numDrums;
if (drums != NULL && numDrums2 > 0) {
mem->drums = PATCH(drums, mem);
for (i = 0; i < numDrums2; i++) {
#endif
patched = mem->drums[i];
if (patched != NULL) {
drum = PATCH(patched, mem);
mem->drums[i] = drum;
if (drum->loaded == 0) {
#if defined(VERSION_JP) || defined(VERSION_US)
//! copt replaces drum with 'patched' for these two lines
PATCH_SOUND(&(*(struct Drum *)patched).sound, mem, offset);
patched = (*(struct Drum *)patched).envelope;
#else
if (!drum->loaded) {
patch_sound(&drum->sound, (u8 *) mem, offset);
patched = drum->envelope;
#endif
drum->envelope = BASE_OFFSET(mem, patched);
drum->loaded = 1;
drum->loaded = TRUE;
}
}
}
}
//! Doesn't affect EU, but required for US/JP
temp = &*mem;
#if defined(VERSION_JP) || defined(VERSION_US)
if (numInstruments >= 1)
#endif
if (numInstruments > 0) {
//! Doesn't affect EU, but required for US/JP
struct Instrument **tempInst;
itInstrs = temp->instruments;
tempInst = temp->instruments;
end = numInstruments + tempInst;
#if defined(VERSION_JP) || defined(VERSION_US)
l2:
if (numInstruments >= 1) {
#else
do {
if (numInstruments > 0) {
#endif
itInstrs = mem->instruments;
end = numInstruments + itInstrs;
do {
if (*itInstrs != NULL) {
*itInstrs = BASE_OFFSET(*itInstrs, mem);
instrument = *itInstrs;
if (instrument->loaded == 0) {
PATCH_SOUND(&instrument->lowNotesSound, (u8 *) mem, offset);
if (!instrument->loaded) {
PATCH_SOUND(&instrument->lowNotesSound, (u8 *) mem, offset);
PATCH_SOUND(&instrument->normalNotesSound, (u8 *) mem, offset);
PATCH_SOUND(&instrument->highNotesSound, (u8 *) mem, offset);
PATCH_SOUND(&instrument->highNotesSound, (u8 *) mem, offset);
patched = instrument->envelope;
instrument->envelope = BASE_OFFSET(mem, patched);
instrument->loaded = 1;
instrument->loaded = TRUE;
}
}
itInstrs++;
#if defined(VERSION_JP) || defined(VERSION_US)
//! goto generated by copt, required to match US/JP
if (end != itInstrs) {
goto l2;
}
#else
} while (end != itInstrs);
#endif
}
#undef PATCH_MEM
#undef PATCH
@@ -603,25 +557,21 @@ l2:
struct AudioBank *bank_load_immediate(s32 bankId, s32 arg1) {
u32 buf[4];
u32 numInstruments, numDrums;
struct AudioBank *ret;
u8 *ctlData;
s32 alloc;
// (This is broken if the length is 1 (mod 16), but that never happens --
// it's always divisible by 4.)
alloc = gAlCtlHeader->seqArray[bankId].len + 0xf;
s32 alloc = gAlCtlHeader->seqArray[bankId].len + 0xf;
alloc = ALIGN16(alloc);
alloc -= 0x10;
ctlData = gAlCtlHeader->seqArray[bankId].offset;
ret = alloc_bank_or_seq(&gBankLoadedPool, 1, alloc, arg1, bankId);
u8 *ctlData = gAlCtlHeader->seqArray[bankId].offset;
struct AudioBank *ret = alloc_bank_or_seq(&gBankLoadedPool, 1, alloc, arg1, bankId);
if (ret == NULL) {
return NULL;
}
audio_dma_copy_immediate((uintptr_t) ctlData, buf, 0x10);
numInstruments = buf[0];
numDrums = buf[1];
u32 numInstruments = buf[0];
u32 numDrums = buf[1];
audio_dma_copy_immediate((uintptr_t)(ctlData + 0x10), ret, alloc);
patch_audio_bank(ret, gAlTbl->seqArray[bankId].offset, numInstruments, numDrums);
gCtlEntries[bankId].numInstruments = (u8) numInstruments;
@@ -633,25 +583,20 @@ struct AudioBank *bank_load_immediate(s32 bankId, s32 arg1) {
}
struct AudioBank *bank_load_async(s32 bankId, s32 arg1, struct SequencePlayer *seqPlayer) {
u32 numInstruments, numDrums;
u32 buf[4];
size_t alloc;
struct AudioBank *ret;
u8 *ctlData;
OSMesgQueue *mesgQueue;
alloc = gAlCtlHeader->seqArray[bankId].len + 0xf;
size_t alloc = gAlCtlHeader->seqArray[bankId].len + 0xf;
alloc = ALIGN16(alloc);
alloc -= 0x10;
ctlData = gAlCtlHeader->seqArray[bankId].offset;
ret = alloc_bank_or_seq(&gBankLoadedPool, 1, alloc, arg1, bankId);
u8 *ctlData = gAlCtlHeader->seqArray[bankId].offset;
struct AudioBank *ret = alloc_bank_or_seq(&gBankLoadedPool, 1, alloc, arg1, bankId);
if (ret == NULL) {
return NULL;
}
audio_dma_copy_immediate((uintptr_t) ctlData, buf, 0x10);
numInstruments = buf[0];
numDrums = buf[1];
u32 numInstruments = buf[0];
u32 numDrums = buf[1];
seqPlayer->loadingBankId = (u8) bankId;
#if defined(VERSION_EU)
gCtlEntries[bankId].numInstruments = numInstruments;
@@ -669,7 +614,7 @@ struct AudioBank *bank_load_async(s32 bankId, s32 arg1, struct SequencePlayer *s
seqPlayer->bankDmaCurrDevAddr = (uintptr_t)(ctlData + 0x10);
seqPlayer->bankDmaRemaining = alloc;
#endif
mesgQueue = &seqPlayer->bankDmaMesgQueue;
OSMesgQueue *mesgQueue = &seqPlayer->bankDmaMesgQueue;
osCreateMesgQueue(mesgQueue, &seqPlayer->bankDmaMesg, 1);
#if defined(VERSION_JP) || defined(VERSION_US)
seqPlayer->bankDmaMesg = NULL;
@@ -734,7 +679,7 @@ void *sequence_dma_async(s32 seqId, s32 arg1, struct SequencePlayer *seqPlayer)
return ptr;
}
u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) {
u32 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) {
void *temp;
u32 bankId;
u16 offset;
@@ -754,7 +699,7 @@ u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) {
bankId = gAlBankSets[offset - 1];
#endif
if (IS_BANK_LOAD_COMPLETE(bankId) == TRUE) {
if (IS_BANK_LOAD_COMPLETE(bankId)) {
#if defined(VERSION_EU)
temp = get_bank_or_seq(&gBankLoadedPool, 2, bankId);
#else
@@ -778,10 +723,9 @@ u8 get_missing_bank(u32 seqId, s32 *nonNullCount, s32 *nullCount) {
struct AudioBank *load_banks_immediate(s32 seqId, u8 *outDefaultBank) {
void *ret = NULL;
u32 bankId = 0;
u16 offset;
u8 i;
offset = ((u16 *) gAlBankSets)[seqId];
u16 offset = ((u16 *) gAlBankSets)[seqId];
#ifdef VERSION_EU
for (i = gAlBankSets[offset++]; i != 0; i--) {
bankId = gAlBankSets[offset++];
@@ -792,7 +736,7 @@ struct AudioBank *load_banks_immediate(s32 seqId, u8 *outDefaultBank) {
bankId = gAlBankSets[offset - 1];
#endif
if (IS_BANK_LOAD_COMPLETE(bankId) == TRUE) {
if (IS_BANK_LOAD_COMPLETE(bankId)) {
#ifdef VERSION_EU
ret = get_bank_or_seq(&gBankLoadedPool, 2, bankId);
#else
@@ -824,8 +768,7 @@ void preload_sequence(u32 seqId, u8 preloadMask) {
}
if (preloadMask & PRELOAD_SEQUENCE) {
// @bug should be IS_SEQ_LOAD_COMPLETE
if (IS_SEQ_LOAD_COMPLETE(seqId) == TRUE) {
if (IS_SEQ_LOAD_COMPLETE(seqId)) {
eu_stubbed_printf_1("SEQ %d ALREADY CACHED\n", seqId);
sequenceData = get_bank_or_seq(&gSeqLoadedPool, 2, seqId);
} else {
@@ -917,25 +860,17 @@ void load_sequence_internal(u32 player, u32 seqId, s32 loadAsync) {
// (void) must be omitted from parameters to fix stack with -framepointer
void audio_init() {
#if defined(VERSION_JP) || defined(VERSION_US)
#if defined(VERSION_JP) || defined(VERSION_US) || defined(VERSION_EU)
u8 buf[0x10];
#endif
s32 i, /*j,*/ k;
UNUSED s32 lim1; // lim1 unused in EU
#if defined(VERSION_EU)
UNUSED u8 buf[0x10];
s32 UNUSED lim2, lim3;
#else
s32 lim2, lim3;
#endif
UNUSED u32 size;
UNUSED u64 *ptr64;
void *data;
gAudioLoadLock = AUDIO_LOCK_UNINITIALIZED;
#if defined(VERSION_JP) || defined(VERSION_US)
lim2 = gAudioHeapSize;
s32 lim2 = gAudioHeapSize;
for (i = 0; i <= lim2 / 8 - 1; i++) {
((u64 *) gAudioHeap)[i] = 0;
}
@@ -943,8 +878,8 @@ void audio_init() {
#ifdef TARGET_N64
// It seems boot.s doesn't clear the .bss area for audio, so do it here.
i = 0;
lim3 = ((uintptr_t) &gAudioGlobalsEndMarker - (uintptr_t) &gAudioGlobalsStartMarker) / 8;
ptr64 = &gAudioGlobalsStartMarker;
s32 lim3 = ((uintptr_t) &gAudioGlobalsEndMarker - (uintptr_t) &gAudioGlobalsStartMarker) / 8;
u64 *ptr64 = &gAudioGlobalsStartMarker;
for (k = lim3; k >= 0; k--) {
ptr64[i] = 0;
i++;
@@ -958,8 +893,8 @@ void audio_init() {
#ifdef TARGET_N64
// It seems boot.s doesn't clear the .bss area for audio, so do it here.
lim3 = ((uintptr_t) &gAudioGlobalsEndMarker - (uintptr_t) &gAudioGlobalsStartMarker) / 8;
ptr64 = &gAudioGlobalsStartMarker;
s32 lim3 = ((uintptr_t) &gAudioGlobalsEndMarker - (uintptr_t) &gAudioGlobalsStartMarker) / 8;
u64 *ptr64 = &gAudioGlobalsStartMarker;
for (k = lim3; k >= 0; k--) {
*ptr64++ = 0;
}
@@ -972,7 +907,8 @@ void audio_init() {
#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
@@ -982,7 +918,7 @@ void audio_init() {
eu_stubbed_printf_1("AudioHeap is %x\n", gAudioHeapSize);
for (i = 0; i < NUMAIBUFFERS; i++) {
gAiBufferLengths[i] = 10;
gAiBufferLengths[i] = 0xa0;
}
gAudioFrameCount = 0;
@@ -1027,12 +963,8 @@ void audio_init() {
data = gMusicData;
audio_dma_copy_immediate((uintptr_t) data, gSeqFileHeader, 0x10);
gSequenceCount = gSeqFileHeader->seqCount;
#if defined(VERSION_EU)
size = gSequenceCount * sizeof(ALSeqData) + 4;
size = ALIGN16(size);
#else
size = ALIGN16(gSequenceCount * sizeof(ALSeqData) + 4);
#endif
gSeqFileHeader = soundAlloc(&gAudioInitPool, size);
audio_dma_copy_immediate((uintptr_t) data, gSeqFileHeader, size);
alSeqFileNew(gSeqFileHeader, data);
@@ -1058,8 +990,13 @@ void audio_init() {
alSeqFileNew(gAlTbl, gSoundDataRaw);
// Load bank sets for each sequence
#ifdef EXPAND_AUDIO_HEAP
gAlBankSets = soundAlloc(&gAudioInitPool, 0x400);
audio_dma_copy_immediate((uintptr_t) gBankSetsData, gAlBankSets, 0x400);
#else
gAlBankSets = soundAlloc(&gAudioInitPool, 0x100);
audio_dma_copy_immediate((uintptr_t) gBankSetsData, gAlBankSets, 0x100);
#endif
init_sequence_players();
gAudioLoadLock = AUDIO_LOCK_NOT_LOADING;
+5 -2
View File
@@ -7,8 +7,11 @@
#define AUDIO_FRAME_DMA_QUEUE_SIZE 0x40
#define PRELOAD_BANKS 2
#define PRELOAD_SEQUENCE 1
enum Preloads {
PRELOAD_NONE,
PRELOAD_SEQUENCE,
PRELOAD_BANKS,
};
#define IS_SEQUENCE_CHANNEL_VALID(ptr) ((uintptr_t)(ptr) != (uintptr_t)&gSequenceChannelNone)
+53 -100
View File
@@ -26,6 +26,8 @@ void *func_802f3f08(s32 poolIdx, s32 idx, s32 numChunks, s32 arg3, OSMesgQueue *
struct Note *gNotes;
UNUSED static u32 pad;
struct SequencePlayer gSequencePlayers[SEQUENCE_PLAYERS];
struct SequenceChannel gSequenceChannels[SEQUENCE_CHANNELS];
struct SequenceChannelLayer gSequenceLayers[SEQUENCE_LAYERS];
@@ -107,10 +109,10 @@ extern u8 gSoundDataADSR[]; // ctl
extern u8 gSoundDataRaw[]; // tbl
extern u8 gMusicData[]; // sequences
ALSeqFile *get_audio_file_header(s32 arg0);
ALSeqFile *get_audio_file_header(s32 poolIdx);
void *func_sh_802f3688(s32 bankId);
void *get_bank_or_seq_wrapper(s32 arg0, s32 arg1);
void *get_bank_or_seq_wrapper(s32 poolIdx, s32 id);
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,
@@ -127,8 +129,6 @@ void func_sh_802f517c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3);
void 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);
@@ -246,8 +246,7 @@ void init_sample_dma_buffers(UNUSED s32 arg0) {
sSampleDmas = sound_alloc_uninitialized(&gNotesAndBuffersPool,
gMaxSimultaneousNotes * 4 * sizeof(struct SharedDma) * gAudioBufferParameters.presetUnk4);
for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++)
{
for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++) {
if ((sSampleDmas[gSampleDmaNumListItems].buffer = sound_alloc_uninitialized(&gNotesAndBuffersPool, sDmaBufSize)) == NULL) {
break;
}
@@ -375,14 +374,12 @@ s32 func_sh_802f3024(s32 bankId, s32 instId, s32 arg2) {
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;
}
return 0;
}
@@ -572,11 +569,9 @@ void *func_sh_802f3688(s32 bankId) {
patchInfo.baseAddr2 = NULL;
}
if ((ret = func_sh_802f3764(1, bankId, &sp38)) == NULL) {
return NULL;
}
ret = func_sh_802f3764(1, bankId, &sp38)
if (sp38 == 1) {
if (ret != NULL && sp38 == 1) {
func_sh_802f5310(bankId, ret, &patchInfo, 0);
}
@@ -584,29 +579,22 @@ void *func_sh_802f3688(s32 bankId) {
}
void *func_sh_802f3764(s32 poolIdx, s32 idx, s32 *arg2) {
s32 size;
ALSeqFile *f;
void *vAddr;
s32 medium;
u8 *devAddr;
s8 loadStatus;
s32 sp18;
vAddr = get_bank_or_seq_wrapper(poolIdx, idx);
void *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;
ALSeqFile *f = get_audio_file_header(poolIdx);
s32 size = f->seqArray[idx].len;
size = ALIGN16(size);
medium = f->seqArray[idx].medium;
sp18 = f->seqArray[idx].magic;
devAddr = f->seqArray[idx].offset;
s32 medium = f->seqArray[idx].medium;
s32 sp18 = f->seqArray[idx].magic;
u8 *devAddr = f->seqArray[idx].offset;
switch (sp18)
{
switch (sp18) {
case 0:
vAddr = unk_pool1_alloc(poolIdx, idx, size);
if (vAddr == NULL) {
@@ -677,9 +665,7 @@ void *func_sh_802f3764(s32 poolIdx, s32 idx, s32 *arg2) {
}
s32 canonicalize_index(s32 poolIdx, s32 idx) {
ALSeqFile *f;
f = get_audio_file_header(poolIdx);
ALSeqFile *f = get_audio_file_header(poolIdx);
if (f->seqArray[idx].len == 0) {
idx = (s32) (uintptr_t) f->seqArray[idx].offset;
}
@@ -687,9 +673,7 @@ s32 canonicalize_index(s32 poolIdx, s32 idx) {
}
void *get_bank_or_seq_wrapper(s32 poolIdx, s32 id) {
void *ret;
ret = unk_pool1_lookup(poolIdx, id);
void *ret = unk_pool1_lookup(poolIdx, id);
if (ret != NULL) {
return ret;
}
@@ -721,21 +705,18 @@ ALSeqFile *get_audio_file_header(s32 poolIdx) {
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;
s32 numDrums = gCtlEntries[bankId].numDrums;
s32 numInstruments = gCtlEntries[bankId].numInstruments;
void **itInstrs = (void **) mem->drums;
if (itInstrs != NULL && numDrums != 0) {
mem->drums = PATCH(itInstrs, mem);
for (i = 0; i < numDrums; i++) {
@@ -793,18 +774,20 @@ 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;
}
while (TRUE) {
if (gAudioLoadLockSH != 0) {
continue;
}
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 >= 0x400U) {
func_sh_802f3dd0(&gAudioDmaIoMesg, 1, 0, devAddr, vAddr, 0x400, &gAudioDmaMesgQueue, medium, shindouDebugPrint81);
osRecvMesg(&gAudioDmaMesgQueue, NULL, 1);
nbytes -= 0x400;
devAddr += 0x400;
vAddr = (u8*)vAddr + 0x400;
continue;
}
break;
}
if (nbytes != 0) {
@@ -814,11 +797,8 @@ again:
}
void func_sh_802f3d78(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) {
uintptr_t sp1C;
sp1C = devAddr;
uintptr_t 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) {
@@ -846,56 +826,43 @@ s32 func_sh_802f3dd0(OSIoMesg *m, s32 pri, s32 direction, uintptr_t devAddr, voi
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:
case 0: // sequence
if (gSeqLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) {
return 0;
}
break;
case 1:
case 1: // bank
if (gBankLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) {
return 0;
}
break;
case 2:
case 2: // unknown
if (gUnkLoadStatus[idx] == SOUND_LOAD_STATUS_IN_PROGRESS) {
return 0;
}
break;
}
vAddr = get_bank_or_seq_wrapper(poolIdx, idx);
void *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;
ALSeqFile *f = get_audio_file_header(poolIdx);
s32 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;
s32 medium = f->seqArray[idx].medium;
s32 sp18 = f->seqArray[idx].magic;
uintptr_t devAddr = (uintptr_t) f->seqArray[idx].offset;
loadStatus = 2;
switch (sp18) {
@@ -933,19 +900,19 @@ void *func_802f3f08(s32 poolIdx, s32 idx, s32 numChunks, s32 arg3, OSMesgQueue *
}
switch (poolIdx) {
case 0:
case 0: // sequence
if (gSeqLoadStatus[idx] != SOUND_LOAD_STATUS_5) {
gSeqLoadStatus[idx] = loadStatus;
}
break;
case 1:
case 1: // bank
if (gBankLoadStatus[idx] != SOUND_LOAD_STATUS_5) {
gBankLoadStatus[idx] = loadStatus;
}
break;
case 2:
case 2: // unknown
if (gUnkLoadStatus[idx] != SOUND_LOAD_STATUS_5) {
gUnkLoadStatus[idx] = loadStatus;
}
@@ -1007,7 +974,8 @@ void audio_init() {
port_eu_init();
#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
@@ -1201,11 +1169,8 @@ void func_sh_802f4bd8(struct PendingDmaSample *arg0, s32 len) { // len must be s
}
void func_sh_802f4c5c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) {
uintptr_t sp1C;
sp1C = devAddr;
uintptr_t 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) {
@@ -1285,12 +1250,6 @@ void func_sh_802f4e50(struct PendingDmaAudioBank *audioBank, s32 audioResetStatu
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)) {
@@ -1361,11 +1320,8 @@ void func_sh_802f50ec(struct PendingDmaAudioBank *arg0, size_t len) {
void func_sh_802f517c(uintptr_t devAddr, void *vAddr, size_t nbytes, s32 arg3) {
uintptr_t sp1C;
sp1C = devAddr;
uintptr_t 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) {
@@ -1413,8 +1369,6 @@ void func_sh_802f5310(s32 bankId, struct AudioBank *mem, struct PatchStruct *pat
sp4C = 0;
if (D_SH_8034F68C != 0) {
sp4C = 1;
} else {
D_SH_80343CF0 = 0;
}
D_SH_8034F688 = 0;
patch_audio_bank(bankId, mem, patchInfo);
@@ -1511,13 +1465,12 @@ s32 func_sh_802f573c(s32 audioResetStatus) {
if (D_SH_8034F68C > 0) {
if (audioResetStatus != 0) {
if (osRecvMesg(&gUnkQueue2, (OSMesg *) &idx, OS_MESG_NOBLOCK)){
}
osRecvMesg(&gUnkQueue2, (OSMesg *) &idx, OS_MESG_NOBLOCK);
D_SH_8034F68C = 0;
return 0;
return FALSE;
}
if (osRecvMesg(&gUnkQueue2, (OSMesg *) &idx, OS_MESG_NOBLOCK) == -1) {
return 0;
return FALSE;
}
idx >>= 0x18;
if (D_SH_8034EC88[idx].isFree == FALSE) {
@@ -1552,7 +1505,7 @@ next:
unk, &gUnkQueue2, D_SH_8034EC88[D_SH_8034F68C - 1].encodedInfo);
}
}
return 1;
return TRUE;
}
s32 func_sh_802f5900(struct AudioBankSample *sample, s32 numLoaded, struct AudioBankSample *arg2[]) {
+21 -27
View File
@@ -13,11 +13,10 @@ void note_set_resampling_rate(struct Note *note, f32 resamplingRateInput);
#if defined(VERSION_EU) || defined(VERSION_SH)
#ifdef VERSION_SH
void note_set_vel_pan_reverb(struct Note *note, struct ReverbInfo *reverbInfo)
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 reverbVol)
void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbVol) {
#endif
{
struct NoteSubEu *sub = &note->noteSubEu;
f32 volRight, volLeft;
u8 strongRight;
@@ -133,9 +132,9 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbV
stubbed_printf("Audio: setvol: volume minus %f\n", velocity);
velocity = 0.0f;
}
if (velocity > 32767.f) {
if (velocity > 32767.0f) {
stubbed_printf("Audio: setvol: volume overflow %f\n", velocity);
velocity = 32767.f;
velocity = 32767.0f;
}
sub->targetVolLeft = ((s32) (velocity * volLeft) & 0xffff) >> 5;
@@ -153,11 +152,7 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, u8 pan, u8 reverbV
return;
}
if (sub->needsInit) {
sub->envMixerNeedsInit = TRUE;
} else {
sub->envMixerNeedsInit = FALSE;
}
sub->envMixerNeedsInit = sub->needsInit;
}
#ifdef VERSION_SH
@@ -177,7 +172,7 @@ void note_set_resampling_rate(struct Note *note, f32 resamplingRateInput) {
}
#endif
if (resamplingRateInput < 2.0f) {
tempSub->hasTwoAdpcmParts = 0;
tempSub->hasTwoAdpcmParts = FALSE;
if (MIN_RESAMPLING_RATE < resamplingRateInput) {
resamplingRate = MIN_RESAMPLING_RATE;
@@ -186,7 +181,7 @@ void note_set_resampling_rate(struct Note *note, f32 resamplingRateInput) {
}
} else {
tempSub->hasTwoAdpcmParts = 1;
tempSub->hasTwoAdpcmParts = TRUE;
if (2 * MIN_RESAMPLING_RATE < resamplingRateInput) {
resamplingRate = MIN_RESAMPLING_RATE;
} else {
@@ -212,7 +207,7 @@ struct AudioBankSound *instrument_get_audio_bank_sound(struct Instrument *instru
struct Instrument *get_instrument_inner(s32 bankId, s32 instId) {
struct Instrument *inst;
if (IS_BANK_LOAD_COMPLETE(bankId) == FALSE) {
if (!IS_BANK_LOAD_COMPLETE(bankId)) {
stubbed_printf("Audio: voiceman: No bank error %d\n", bankId);
gAudioErrorFlags = bankId + 0x10000000;
return NULL;
@@ -254,7 +249,7 @@ struct Drum *get_drum(s32 bankId, s32 drumId) {
struct Drum *drum;
#ifdef VERSION_SH
if (IS_BANK_LOAD_COMPLETE(bankId) == FALSE) {
if (!IS_BANK_LOAD_COMPLETE(bankId)) {
stubbed_printf("Audio: voiceman: No bank error %d\n", bankId);
gAudioErrorFlags = bankId + 0x10000000;
return NULL;
@@ -602,7 +597,7 @@ void process_notes(void) {
frequency *= note->vibratoFreqScale * note->portamentoFreqScale;
cap = 3.99992f;
if (gAiFrequency != 32006) {
frequency *= US_FLOAT(32000.0) / (f32) gAiFrequency;
frequency *= (32000.0f / (f32) gAiFrequency);
}
frequency = (frequency < cap ? frequency : cap);
scale *= 4.3498e-5f; // ~1 / 23000
@@ -633,7 +628,7 @@ struct AudioBankSound *instrument_get_audio_bank_sound(struct Instrument *instru
struct Instrument *get_instrument_inner(s32 bankId, s32 instId) {
struct Instrument *inst;
if (IS_BANK_LOAD_COMPLETE(bankId) == FALSE) {
if (!IS_BANK_LOAD_COMPLETE(bankId)) {
gAudioErrorFlags = bankId + 0x10000000;
return NULL;
}
@@ -655,7 +650,7 @@ struct Instrument *get_instrument_inner(s32 bankId, s32 instId) {
struct Drum *get_drum(s32 bankId, s32 drumId) {
struct Drum *drum;
if (IS_BANK_LOAD_COMPLETE(bankId) == FALSE) {
if (!IS_BANK_LOAD_COMPLETE(bankId)) {
gAudioErrorFlags = bankId + 0x10000000;
return NULL;
}
@@ -848,21 +843,21 @@ void build_synthetic_wave(struct Note *note, struct SequenceChannelLayer *seqLay
u8 lim;
u8 origSampleCount = note->sampleCount;
if (seqLayer->freqScale < US_FLOAT(1.0)) {
if (seqLayer->freqScale < 1.0f) {
note->sampleCount = 64;
seqLayer->freqScale *= US_FLOAT(1.0465);
seqLayer->freqScale *= 1.0465f;
stepSize = 1;
} else if (seqLayer->freqScale < US_FLOAT(2.0)) {
} else if (seqLayer->freqScale < 2.0f) {
note->sampleCount = 32;
seqLayer->freqScale *= US_FLOAT(0.52325);
seqLayer->freqScale *= 0.52325f;
stepSize = 2;
} else if (seqLayer->freqScale < US_FLOAT(4.0)) {
} else if (seqLayer->freqScale < 4.0f) {
note->sampleCount = 16;
seqLayer->freqScale *= US_FLOAT(0.26263);
seqLayer->freqScale *= 0.26263f;
stepSize = 4;
} else {
note->sampleCount = 8;
seqLayer->freqScale *= US_FLOAT(0.13081);
seqLayer->freqScale *= 0.13081f;
stepSize = 8;
}
@@ -1008,8 +1003,7 @@ void note_pool_clear(struct NotePool *pool) {
}
void note_pool_fill(struct NotePool *pool, s32 count) {
s32 i;
s32 j;
s32 i, j;
struct Note *note;
struct AudioListItem *source;
struct AudioListItem *dest;
@@ -1157,7 +1151,7 @@ s32 note_init_for_layer(struct Note *note, struct SequenceChannelLayer *seqLayer
note->prevParentLayer = NO_LAYER;
note->parentLayer = seqLayer;
note->priority = seqLayer->seqChannel->notePriority;
if (IS_BANK_LOAD_COMPLETE(seqLayer->seqChannel->bankId) == FALSE) {
if (!IS_BANK_LOAD_COMPLETE(seqLayer->seqChannel->bankId)) {
return TRUE;
}
+6 -4
View File
@@ -11,10 +11,12 @@
// which *is* orthogonal to the other. SEQ implicitly includes CHANNEL.
// If none of the CHANNEL/SEQ/GLOBAL_FREELIST bits are set, all three locations
// are tried.
#define NOTE_ALLOC_LAYER 1
#define NOTE_ALLOC_CHANNEL 2
#define NOTE_ALLOC_SEQ 4
#define NOTE_ALLOC_GLOBAL_FREELIST 8
enum NoteAlloc {
NOTE_ALLOC_LAYER = (1 << 0), // 0x1
NOTE_ALLOC_CHANNEL = (1 << 1), // 0x2
NOTE_ALLOC_SEQ = (1 << 2), // 0x4
NOTE_ALLOC_GLOBAL_FREELIST = (1 << 3), // 0x8
};
void process_notes(void);
void seq_channel_layer_note_decay(struct SequenceChannelLayer *seqLayer);
+78 -91
View File
@@ -4,6 +4,7 @@
#include "data.h"
#include "seqplayer.h"
#include "synthesis.h"
#include "engine/math_util.h"
#ifdef VERSION_EU
@@ -21,11 +22,7 @@
#define SAMPLES_TO_OVERPRODUCE 0x10
#define EXTRA_BUFFERED_AI_SAMPLES_TARGET 0x40
#ifdef VERSION_JP
typedef u16 FadeT;
#else
typedef s32 FadeT;
#endif
extern volatile u8 gAudioResetStatus;
extern u8 gAudioResetPresetIdToLoad;
@@ -36,7 +33,7 @@ void func_8031D690(s32 player, FadeT fadeInTime);
void seq_player_fade_to_zero_volume(s32 player, FadeT fadeOutTime);
void decrease_sample_dma_ttls(void);
s32 audio_shut_down_and_reset_step(void);
void func_802ad7ec(u32);
void func_802ad7ec(u32 arg0);
struct SPTask *create_next_audio_frame_task(void) {
u32 samplesRemainingInAI;
@@ -95,12 +92,8 @@ struct SPTask *create_next_audio_frame_task(void) {
gAiBufferLengths[index] = ((gAudioBufferParameters.samplesPerFrameTarget - samplesRemainingInAI +
EXTRA_BUFFERED_AI_SAMPLES_TARGET) & ~0xf) + SAMPLES_TO_OVERPRODUCE;
if (gAiBufferLengths[index] < gAudioBufferParameters.minAiBufferLength) {
gAiBufferLengths[index] = gAudioBufferParameters.minAiBufferLength;
}
if (gAiBufferLengths[index] > gAudioBufferParameters.maxAiBufferLength) {
gAiBufferLengths[index] = gAudioBufferParameters.maxAiBufferLength;
}
gAiBufferLengths[index] = CLAMP(gAiBufferLengths[index], gAudioBufferParameters.minAiBufferLength,
gAudioBufferParameters.maxAiBufferLength);
if (osRecvMesg(OSMesgQueues[1], &sp2C, OS_MESG_NOBLOCK) != -1) {
func_802ad7ec((u32) sp2C);
@@ -139,49 +132,46 @@ 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) {
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;
}
}
const char undefportcmd[] = "Undefined Port Command %d\n";
extern OSMesgQueue *OSMesgQueues[];
extern u8 D_EU_80302010;
extern u8 D_EU_80302014;
@@ -261,58 +251,55 @@ void func_802ad7ec(u32 arg0) {
seqPlayer = &gSequencePlayers[cmd->u.s.arg1];
if ((cmd->u.s.op & 0x80) != 0) {
eu_process_audio_cmd(cmd);
}
else if ((cmd->u.s.op & 0x40) != 0) {
} 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) {
} 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->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;
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;
}
}
}
+121 -130
View File
@@ -152,74 +152,73 @@ void eu_process_audio_cmd(struct EuAudioCmd *cmd) {
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:
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) {
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 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 = &note->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 = &note->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;
}
}
@@ -344,74 +343,73 @@ void func_802ad7ec(u32 arg0) {
}
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->reverbVol != cmd->u2.as_u8) {
chan->reverbVol = cmd->u2.as_u8;
}
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:
if (chan->reverbVol != cmd->u2.as_u8) {
chan->reverbVol = cmd->u2.as_u8;
}
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;
}
}
}
@@ -432,24 +430,19 @@ u32 func_sh_802f6878(s32 *arg0) {
return sp1C >> 0x18;
}
u8 *func_sh_802f68e0(u32 index, u32 *a1) {
UNUSED u8 *func_sh_802f68e0(u32 index, u32 *a1) {
return func_sh_802f3220(index, a1);
}
s32 func_sh_802f6900(void) {
s32 ret;
UNUSED s32 func_sh_802f6900(void) {
s32 sp18;
ret = osRecvMesg(D_SH_80350FA8, (OSMesg *) &sp18, 0);
s32 ret = osRecvMesg(D_SH_80350FA8, (OSMesg *) &sp18, 0);
if (ret == -1) {
return 0;
}
if (sp18 != gAudioResetPresetIdToLoad) {
return 0;
} else {
return 1;
return FALSE;
}
return sp18 == gAudioResetPresetIdToLoad;
}
// TODO: (Scrub C)
@@ -470,11 +463,9 @@ void func_sh_802f69cc(void) {
gAudioResetStatus = 0;
}
s32 func_sh_802f6a08(s32 playerIndex, s32 channelIndex, s32 soundScriptIOIndex) {
UNUSED s32 func_sh_802f6a08(s32 playerIndex, s32 channelIndex, s32 soundScriptIOIndex) {
struct SequenceChannel *seqChannel;
struct SequencePlayer *player;
player = &gSequencePlayers[playerIndex];
struct SequencePlayer *player = &gSequencePlayers[playerIndex];
if (player->enabled) {
seqChannel = player->channels[channelIndex];
if (IS_SEQUENCE_CHANNEL_VALID(seqChannel)) {
@@ -484,7 +475,7 @@ s32 func_sh_802f6a08(s32 playerIndex, s32 channelIndex, s32 soundScriptIOIndex)
return -1;
}
s8 func_sh_802f6a6c(s32 playerIndex, s32 index) {
UNUSED s32 func_sh_802f6a6c(s32 playerIndex, s32 index) {
return gSequencePlayers[playerIndex].seqVariationEu[index];
}
+40 -70
View File
@@ -7,14 +7,6 @@
#include "load.h"
#include "seqplayer.h"
#define PORTAMENTO_IS_SPECIAL(x) ((x).mode & 0x80)
#define PORTAMENTO_MODE(x) ((x).mode & ~0x80)
#define PORTAMENTO_MODE_1 1
#define PORTAMENTO_MODE_2 2
#define PORTAMENTO_MODE_3 3
#define PORTAMENTO_MODE_4 4
#define PORTAMENTO_MODE_5 5
#ifdef VERSION_SH
void seq_channel_layer_process_script_part1(struct SequenceChannelLayer *layer);
s32 seq_channel_layer_process_script_part2(struct SequenceChannelLayer *layer);
@@ -24,8 +16,8 @@ s32 seq_channel_layer_process_script_part5(struct SequenceChannelLayer *layer, s
#endif
void seq_channel_layer_process_script(struct SequenceChannelLayer *layer);
void sequence_channel_process_script(struct SequenceChannel *seqChannel);
u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrument **instOut,
struct AdsrSettings *adsr);
u32 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrument **instOut,
struct AdsrSettings *adsr);
void sequence_channel_init(struct SequenceChannel *seqChannel) {
s32 i;
@@ -232,11 +224,7 @@ void sequence_player_init_channels(struct SequencePlayer *seqPlayer, u16 channel
seqChannel->noteAllocPolicy = seqPlayer->noteAllocPolicy;
}
}
#if defined(VERSION_EU) || defined(VERSION_SH)
channelBits = channelBits >> 1;
#else
channelBits >>= 1;
#endif
}
}
@@ -263,11 +251,7 @@ void sequence_player_disable_channels(struct SequencePlayer *seqPlayer, u16 chan
seqPlayer->channels[i] = &gSequenceChannelNone;
}
}
#if defined(VERSION_EU) || defined(VERSION_SH)
channelBits = channelBits >> 1;
#else
channelBits >>= 1;
#endif
}
}
@@ -397,7 +381,7 @@ void init_layer_freelist(void) {
}
}
u8 m64_read_u8(struct M64ScriptState *state) {
u32 m64_read_u8(struct M64ScriptState *state) {
#if defined(VERSION_EU) || defined(VERSION_SH)
return *(state->pc++);
#else
@@ -406,13 +390,13 @@ u8 m64_read_u8(struct M64ScriptState *state) {
#endif
}
s16 m64_read_s16(struct M64ScriptState *state) {
s32 m64_read_s16(struct M64ScriptState *state) {
s16 ret = *(state->pc++) << 8;
ret = *(state->pc++) | ret;
return ret;
}
u16 m64_read_compressed_u16(struct M64ScriptState *state) {
u32 m64_read_compressed_u16(struct M64ScriptState *state) {
u16 ret = *(state->pc++);
if (ret & 0x80) {
ret = (ret << 8) & 0x7f00;
@@ -423,9 +407,7 @@ u16 m64_read_compressed_u16(struct M64ScriptState *state) {
#if defined(VERSION_SH)
void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
s32 cmd;
if (layer->enabled == FALSE) {
if (!layer->enabled) {
return;
}
@@ -439,7 +421,7 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
}
seq_channel_layer_process_script_part1(layer);
cmd = seq_channel_layer_process_script_part2(layer);
s32 cmd = seq_channel_layer_process_script_part2(layer);
if (cmd != -1) {
cmd = seq_channel_layer_process_script_part3(layer, cmd);
if (cmd != -1) {
@@ -468,9 +450,9 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
s32 temp_a0_5;
#ifdef VERSION_EU
u16 sp3A;
s32 sameSound;
s32 sameSound = TRUE;
#else
u8 sameSound;
u8 sameSound = TRUE;
#endif
u8 cmd;
UNUSED u8 cmdSemitone;
@@ -487,7 +469,6 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
f32 temp_f12;
f32 temp_f2;
sameSound = TRUE;
if (layer->enabled == FALSE) {
return;
}
@@ -580,7 +561,7 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
#if defined(VERSION_EU) || defined(VERSION_SH)
layer->pan = temp_a0_5;
#else
layer->pan = (f32) temp_a0_5 / US_FLOAT(128.0);
layer->pan = (f32) temp_a0_5 / 128.0f;
#endif
}
break;
@@ -800,7 +781,7 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
layer->pan = drum->pan;
}
#else
layer->pan = FLOAT_CAST(drum->pan) / US_FLOAT(128.0);
layer->pan = FLOAT_CAST(drum->pan) / 128.0f;
#endif
layer->sound = &drum->sound;
layer->freqScale = layer->sound->tuning;
@@ -880,15 +861,15 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
#if defined(VERSION_EU) || defined(VERSION_SH)
portamento->extent = temp_f2 / freqScale - 1.0f;
#else
portamento->extent = sp24 / freqScale - US_FLOAT(1.0);
portamento->extent = sp24 / freqScale - 1.0f;
#endif
if (PORTAMENTO_IS_SPECIAL(layer->portamento)) {
portamento->speed = US_FLOAT(32512.0) * FLOAT_CAST(seqPlayer->tempo)
portamento->speed = 32512.0f * FLOAT_CAST(seqPlayer->tempo)
/ ((f32) layer->delay * (f32) gTempoInternalToExternal
* FLOAT_CAST(layer->portamentoTime));
} else {
portamento->speed = US_FLOAT(127.0) / FLOAT_CAST(layer->portamentoTime);
portamento->speed = 127.0f / FLOAT_CAST(layer->portamentoTime);
}
portamento->cur = 0.0f;
layer->freqScale = freqScale;
@@ -950,11 +931,6 @@ void seq_channel_layer_process_script(struct SequenceChannelLayer *layer) {
}
}
#ifdef VERSION_EU
u8 audioString106[] = "Audio: Note:Velocity Error %d\n";
u8 audioString107[] = "Error: Your assignchannel is stolen.\n";
#endif
#else
// US/JP version with macros to simulate inlining by copt. Edit if you dare.
#include "copt/seq_channel_layer_process_script_copt.inc.c"
@@ -1281,11 +1257,11 @@ s32 seq_channel_layer_process_script_part4(struct SequenceChannelLayer *layer, s
portamento->extent = sp24 / freqScale - 1.0f;
if (PORTAMENTO_IS_SPECIAL(layer->portamento)) {
portamento->speed = US_FLOAT(32512.0) * FLOAT_CAST(seqPlayer->tempo)
portamento->speed = 32512.0f * FLOAT_CAST(seqPlayer->tempo)
/ ((f32) layer->delay * (f32) gTempoInternalToExternal
* FLOAT_CAST(layer->portamentoTime));
} else {
portamento->speed = US_FLOAT(127.0) / FLOAT_CAST(layer->portamentoTime);
portamento->speed = 127.0f / FLOAT_CAST(layer->portamentoTime);
}
portamento->cur = 0.0f;
layer->freqScale = freqScale;
@@ -1374,8 +1350,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;
}
@@ -1384,7 +1359,7 @@ s32 seq_channel_layer_process_script_part3(struct SequenceChannelLayer *layer, s
}
#endif
u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrument **instOut, struct AdsrSettings *adsr) {
u32 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrument **instOut, struct AdsrSettings *adsr) {
struct Instrument *inst;
#if defined(VERSION_EU) || defined(VERSION_SH)
inst = get_instrument_inner(seqChannel->bankId, instId);
@@ -1398,6 +1373,8 @@ u8 get_instrument(struct SequenceChannel *seqChannel, u8 instId, struct Instrume
instId++;
return instId;
#else
UNUSED u32 pad;
if (instId >= gCtlEntries[seqChannel->bankId].numInstruments) {
instId = gCtlEntries[seqChannel->bankId].numInstruments;
if (instId == 0) {
@@ -1463,7 +1440,7 @@ void set_instrument(struct SequenceChannel *seqChannel, u8 instId) {
}
void sequence_channel_set_volume(struct SequenceChannel *seqChannel, u8 volume) {
seqChannel->volume = FLOAT_CAST(volume) / US_FLOAT(127.0);
seqChannel->volume = FLOAT_CAST(volume) / 127.0f;
}
void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
@@ -1505,25 +1482,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;
}
@@ -1703,7 +1676,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
break;
case 0xe0: // chan_setvolscale
seqChannel->volumeScale = FLOAT_CAST(m64_read_u8(state)) / US_FLOAT(128.0);
seqChannel->volumeScale = FLOAT_CAST(m64_read_u8(state)) / 128.0f;
#if defined(VERSION_EU) || defined(VERSION_SH)
seqChannel->changes.as_bitfields.volume = TRUE;
#endif
@@ -1711,7 +1684,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
case 0xde: // chan_freqscale; pitch bend using raw frequency multiplier N/2^15 (N is u16)
sp5A = m64_read_s16(state);
seqChannel->freqScale = FLOAT_CAST(sp5A) / US_FLOAT(32768.0);
seqChannel->freqScale = FLOAT_CAST(sp5A) / 32768.0f;
#if defined(VERSION_EU) || defined(VERSION_SH)
seqChannel->changes.as_bitfields.freqScale = TRUE;
#endif
@@ -1743,7 +1716,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
seqChannel->newPan = m64_read_u8(state);
seqChannel->changes.as_bitfields.pan = TRUE;
#else
seqChannel->pan = FLOAT_CAST(m64_read_u8(state)) / US_FLOAT(128.0);
seqChannel->pan = FLOAT_CAST(m64_read_u8(state)) / 128.0f;
#endif
break;
@@ -1752,7 +1725,7 @@ void sequence_channel_process_script(struct SequenceChannel *seqChannel) {
seqChannel->panChannelWeight = m64_read_u8(state);
seqChannel->changes.as_bitfields.pan = TRUE;
#else
seqChannel->panChannelWeight = FLOAT_CAST(m64_read_u8(state)) / US_FLOAT(128.0);
seqChannel->panChannelWeight = FLOAT_CAST(m64_read_u8(state)) / 128.0f;
#endif
break;
@@ -2283,12 +2256,12 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
#endif
// If discarded, bail out.
if (IS_SEQ_LOAD_COMPLETE(seqPlayer->seqId) == FALSE
if (!IS_SEQ_LOAD_COMPLETE(seqPlayer->seqId)
|| (
#ifdef VERSION_SH
seqPlayer->defaultBank[0] != 0xff &&
#endif
IS_BANK_LOAD_COMPLETE(seqPlayer->defaultBank[0]) == FALSE)) {
!IS_BANK_LOAD_COMPLETE(seqPlayer->defaultBank[0]))) {
eu_stubbed_printf_1("Disappear Sequence or Bank %d\n", seqPlayer->seqId);
sequence_player_disable(seqPlayer);
return;
@@ -2328,8 +2301,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;
@@ -2341,14 +2313,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;
}
@@ -2468,7 +2438,7 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
seqPlayer->tempo = gTempoInternalToExternal;
}
//if (cmd){}
//if (cmd) {}
if ((s16) seqPlayer->tempo < 0) {
seqPlayer->tempo = 0;
@@ -2526,18 +2496,18 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
switch (seqPlayer->state) {
case SEQUENCE_PLAYER_STATE_2:
if (seqPlayer->fadeRemainingFrames != 0) {
f32 targetVolume = FLOAT_CAST(cmd) / US_FLOAT(127.0);
f32 targetVolume = FLOAT_CAST(cmd) / 127.0f;
seqPlayer->fadeVelocity = (targetVolume - seqPlayer->fadeVolume)
/ FLOAT_CAST(seqPlayer->fadeRemainingFrames);
break;
}
// fallthrough
case SEQUENCE_PLAYER_STATE_0:
seqPlayer->fadeVolume = FLOAT_CAST(cmd) / US_FLOAT(127.0);
seqPlayer->fadeVolume = FLOAT_CAST(cmd) / 127.0f;
break;
case SEQUENCE_PLAYER_STATE_FADE_OUT:
case SEQUENCE_PLAYER_STATE_4:
seqPlayer->volume = FLOAT_CAST(cmd) / US_FLOAT(127.0);
seqPlayer->volume = FLOAT_CAST(cmd) / 127.0f;
break;
}
break;
@@ -2545,7 +2515,7 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
case 0xda: // seq_changevol
temp = m64_read_u8(state);
seqPlayer->fadeVolume =
seqPlayer->fadeVolume + (f32)(s8) temp / US_FLOAT(127.0);
seqPlayer->fadeVolume + (f32)(s8) temp / 127.0f;
break;
#endif
@@ -2568,7 +2538,7 @@ void sequence_player_process_sequence(struct SequencePlayer *seqPlayer) {
case 0xd5: // seq_setmutescale
temp = m64_read_u8(state);
seqPlayer->muteVolumeScale = (f32)(s8) temp / US_FLOAT(127.0);
seqPlayer->muteVolumeScale = (f32)(s8) temp / 127.0f;
break;
case 0xd4: // seq_mute
+11
View File
@@ -6,6 +6,17 @@
#include "internal.h"
#include "playback.h"
#define PORTAMENTO_IS_SPECIAL(x) ((x).mode & 0x80)
#define PORTAMENTO_MODE(x) ((x).mode & ~0x80)
enum PortamentoModes {
PORTAMENTO_MODE_0,
PORTAMENTO_MODE_1,
PORTAMENTO_MODE_2,
PORTAMENTO_MODE_3,
PORTAMENTO_MODE_4,
PORTAMENTO_MODE_5
};
void seq_channel_layer_disable(struct SequenceChannelLayer *seqPlayer);
void sequence_channel_disable(struct SequenceChannel *seqPlayer);
void sequence_player_disable(struct SequencePlayer* seqPlayer);
-1
View File
@@ -6,7 +6,6 @@ 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";
+95 -144
View File
@@ -9,6 +9,7 @@
#include "internal.h"
#include "external.h"
#include "game/game_init.h"
#include "engine/math_util.h"
#define DMEM_ADDR_TEMP 0x0
@@ -28,7 +29,7 @@
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)))
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); \
@@ -57,6 +58,9 @@
* Depending on the violating parameters chosen, you probably won't ever experience s32 overflow, but s16 overflow still isn't a pleasant experience.
* Checks to prevent this have not been implemented to maximize performance potential, so choose your parameters wisely. The current defaults are unlikely to have this problem.
* Generally speaking, a sound that doesn't seem to be fading at a natural rate is a parameter red flag (also known as feedback).
*
* This is also known to cause severe lag on emulators that have counter factor set to 2 or greater.
* Be sure either you alert the user in advance, or check for and set betterReverbDownsampleEmulator to -1 if it's detected the user isn't using good settings.
*/
@@ -67,7 +71,7 @@
s8 betterReverbDownsampleConsole = 3;
// Most emulators can handle a default value of 2, but 3 may be advisable in some cases if targeting older emulators (e.g. PJ64 1.6). Setting this to -1 also uses vanilla reverb.
// Using a value of 1 is not recommended except in very specific situations. If you do decide to use 1 here, you must adjust BETTER_REVERB_SIZE appropriately.
// Using a value of 1 is not recommended on emulator unless reducing other parameters to compensate. If you do decide to use 1 here, you must adjust BETTER_REVERB_SIZE appropriately.
// You can change this value before audio_reset_session gets called if different levels can tolerate the demand better than others or just have different reverb goals.
// A higher downsample value hits the game's frequency limit sooner, which can cause the reverb sometimes to be off pitch. This is a vanilla level issue (and also counter intuitive).
// Higher downsample values also result in slightly shorter reverb decay times.
@@ -77,7 +81,7 @@ s8 betterReverbDownsampleEmulator = 2;
// Filter count should always be a multiple of 3. Never ever set this value to be greater than NUM_ALLPASS.
// Setting it to anything less than 3 will disable reverb outright.
// This can be changed at any time, but is best set when calling audio_reset_session.
u32 reverbFilterCountConsole = NUM_ALLPASS - 6;
u32 reverbFilterCountConsole = (NUM_ALLPASS - 6);
// This value represents the number of filters to use with the reverb. This can be decreased to improve performance, but at the cost of a lesser presence of reverb in the final audio.
// Filter count should always be a multiple of 3. Never ever set this value to be greater than NUM_ALLPASS.
@@ -104,7 +108,7 @@ s32 betterReverbWindowsSize = -1;
// These are set to defines rather than variables to increase performance. Change these to s32 if you want them to be configurable in-game. (Maybe extern them in synthesis.h)
// Setting these to values larger than 0xFF (255) or less than 0 may cause issues and is not recommended.
#define REVERB_REV_INDEX 0x60 // Affects decay time mostly (large values can cause terrible feedback!); can be messed with at any time
#define REVERB_REV_INDEX 0x60 // Affects decay time mostly (large values can cause terrible feedback!); can be messed with at any time
#define REVERB_GAIN_INDEX 0xA0 // Affects signal immediately retransmitted back into buffers (mid-high values yield the strongest effect); can be messed with at any time
#define REVERB_WET_SIGNAL 0xE8 // Amount of reverb specific output in final signal (also affects decay); can be messed with at any time, also very easy to control
@@ -123,11 +127,11 @@ s32 delaysL[NUM_ALLPASS] = {
1080, 1352, 1200,
1200, 1232, 1432,
1384, 1048, 1352,
928, 1504, 1512
928, 1504, 1512
};
s32 delaysR[NUM_ALLPASS] = {
1384, 1352, 1048,
928, 1512, 1504,
928, 1512, 1504,
1080, 1200, 1352,
1200, 1432, 1232
};
@@ -139,11 +143,11 @@ const s32 delaysBaselineL[NUM_ALLPASS] = {
1080, 1352, 1200,
1200, 1232, 1432,
1384, 1048, 1352,
928, 1504, 1512
928, 1504, 1512
};
const s32 delaysBaselineR[NUM_ALLPASS] = {
1384, 1352, 1048,
928, 1512, 1504,
928, 1512, 1504,
1080, 1200, 1352,
1200, 1432, 1232
};
@@ -156,14 +160,14 @@ s32 reverbMultsR[NUM_ALLPASS / 3] = {0xCF, 0x73, 0x38, 0x1F};
/* -----------------------------------------------------------------------END REVERB PARAMETERS----------------------------------------------------------------------- */
// Do not touch these values manually, unless you want potential for problems.
s32 reverbFilterCount = NUM_ALLPASS;
s32 reverbFilterCountm1 = NUM_ALLPASS - 1;
s32 reverbFilterCount = NUM_ALLPASS;
s32 reverbFilterCountm1 = (NUM_ALLPASS - 1);
u8 monoReverb = FALSE;
u8 toggleBetterReverb = TRUE;
s32 allpassIdxL[NUM_ALLPASS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
s32 allpassIdxR[NUM_ALLPASS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
s32 tmpBufL[NUM_ALLPASS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
s32 tmpBufR[NUM_ALLPASS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
s32 allpassIdxL[NUM_ALLPASS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
s32 allpassIdxR[NUM_ALLPASS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
s32 tmpBufL[NUM_ALLPASS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
s32 tmpBufR[NUM_ALLPASS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
s32 **delayBufsL;
s32 **delayBufsR;
#endif
@@ -203,23 +207,14 @@ u8 sAudioSynthesisPad[0x20];
#endif
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
static inline s16 clamp16(s32 x) {
if (x >= 32767)
return 32767;
if (x <= -32768)
return -32768;
return (s16) x;
}
static inline void reverb_samples(s16 *outSampleL, s16 *outSampleR, s32 inSampleL, s32 inSampleR) {
s32 i = 0;
s32 j = 0;
s32 k = 0;
s32 outTmpL = 0;
s32 outTmpR = 0;
s32 tmpCarryoverL = ((tmpBufL[reverbFilterCountm1] * REVERB_REV_INDEX) / 256) + inSampleL;
s32 tmpCarryoverR = ((tmpBufR[reverbFilterCountm1] * REVERB_REV_INDEX) / 256) + inSampleR;
s32 tmpCarryoverL = (((tmpBufL[reverbFilterCountm1] * REVERB_REV_INDEX) / 256) + inSampleL);
s32 tmpCarryoverR = (((tmpBufR[reverbFilterCountm1] * REVERB_REV_INDEX) / 256) + inSampleR);
for (; i != reverbFilterCount; ++i, ++j) {
tmpBufL[i] = delayBufsL[i][allpassIdxL[i]];
@@ -227,30 +222,28 @@ static inline void reverb_samples(s16 *outSampleL, s16 *outSampleR, s32 inSample
if (j == 2) {
j = -1;
outTmpL += (tmpBufL[i] * reverbMultsL[k]) / 256;
outTmpR += (tmpBufR[i] * reverbMultsR[k++]) / 256;
outTmpL += ((tmpBufL[i] * reverbMultsL[k ]) / 256);
outTmpR += ((tmpBufR[i] * reverbMultsR[k++]) / 256);
delayBufsL[i][allpassIdxL[i]] = tmpCarryoverL;
delayBufsR[i][allpassIdxR[i]] = tmpCarryoverR;
if (i != reverbFilterCountm1) {
tmpCarryoverL = (tmpBufL[i] * REVERB_REV_INDEX) / 256;
tmpCarryoverR = (tmpBufR[i] * REVERB_REV_INDEX) / 256;
tmpCarryoverL = ((tmpBufL[i] * REVERB_REV_INDEX) / 256);
tmpCarryoverR = ((tmpBufR[i] * REVERB_REV_INDEX) / 256);
}
}
else {
delayBufsL[i][allpassIdxL[i]] = (tmpBufL[i] * (-REVERB_GAIN_INDEX)) / 256 + tmpCarryoverL;
delayBufsR[i][allpassIdxR[i]] = (tmpBufR[i] * (-REVERB_GAIN_INDEX)) / 256 + tmpCarryoverR;
tmpCarryoverL = (delayBufsL[i][allpassIdxL[i]] * REVERB_GAIN_INDEX) / 256 + tmpBufL[i];
tmpCarryoverR = (delayBufsR[i][allpassIdxR[i]] * REVERB_GAIN_INDEX) / 256 + tmpBufR[i];
} else {
delayBufsL[i][allpassIdxL[i]] = (((tmpBufL[i] * (-REVERB_GAIN_INDEX)) / 256) + tmpCarryoverL);
delayBufsR[i][allpassIdxR[i]] = (((tmpBufR[i] * (-REVERB_GAIN_INDEX)) / 256) + tmpCarryoverR);
tmpCarryoverL = (((delayBufsL[i][allpassIdxL[i]] * REVERB_GAIN_INDEX) / 256) + tmpBufL[i]);
tmpCarryoverR = (((delayBufsR[i][allpassIdxR[i]] * REVERB_GAIN_INDEX) / 256) + tmpBufR[i]);
}
if (++allpassIdxL[i] == delaysL[i])
allpassIdxL[i] = 0;
if (++allpassIdxR[i] == delaysR[i])
allpassIdxR[i] = 0;
if (++allpassIdxL[i] == delaysL[i]) allpassIdxL[i] = 0;
if (++allpassIdxR[i] == delaysR[i]) allpassIdxR[i] = 0;
}
*outSampleL = clamp16((outTmpL * REVERB_WET_SIGNAL/* + inSampleL * REVERB_DRY_SIGNAL*/) / 256);
*outSampleR = clamp16((outTmpR * REVERB_WET_SIGNAL/* + inSampleR * REVERB_DRY_SIGNAL*/) / 256);
s32 outUnclamped = ((outTmpL * REVERB_WET_SIGNAL/* + inSampleL * REVERB_DRY_SIGNAL*/) / 256);
*outSampleL = CLAMP_S16(outUnclamped);
outUnclamped = ((outTmpR * REVERB_WET_SIGNAL/* + inSampleL * REVERB_DRY_SIGNAL*/) / 256);
*outSampleR = CLAMP_S16(outUnclamped);
}
static inline void reverb_mono_sample(s16 *outSample, s32 inSample) {
@@ -258,28 +251,27 @@ static inline void reverb_mono_sample(s16 *outSample, s32 inSample) {
s32 j = 0;
s32 k = 0;
s32 outTmp = 0;
s32 tmpCarryover = ((tmpBufL[reverbFilterCountm1] * REVERB_REV_INDEX) / 256) + inSample;
s32 tmpCarryover = (((tmpBufL[reverbFilterCountm1] * REVERB_REV_INDEX) / 256) + inSample);
for (; i != reverbFilterCount; ++i, ++j) {
tmpBufL[i] = delayBufsL[i][allpassIdxL[i]];
if (j == 2) {
j = -1;
outTmp += (tmpBufL[i] * reverbMultsL[k++]) / 256;
outTmp += ((tmpBufL[i] * reverbMultsL[k++]) / 256);
delayBufsL[i][allpassIdxL[i]] = tmpCarryover;
if (i != reverbFilterCountm1)
tmpCarryover = (tmpBufL[i] * REVERB_REV_INDEX) / 256;
}
else {
delayBufsL[i][allpassIdxL[i]] = (tmpBufL[i] * (-REVERB_GAIN_INDEX)) / 256 + tmpCarryover;
tmpCarryover = (delayBufsL[i][allpassIdxL[i]] * REVERB_GAIN_INDEX) / 256 + tmpBufL[i];
tmpCarryover = ((tmpBufL[i] * REVERB_REV_INDEX) / 256);
} else {
delayBufsL[i][allpassIdxL[i]] = (((tmpBufL[i] * (-REVERB_GAIN_INDEX)) / 256) + tmpCarryover);
tmpCarryover = (((delayBufsL[i][allpassIdxL[i]] * REVERB_GAIN_INDEX) / 256) + tmpBufL[i]);
}
if (++allpassIdxL[i] == delaysL[i])
allpassIdxL[i] = 0;
}
*outSample = clamp16((outTmp * REVERB_WET_SIGNAL/* + inSample * REVERB_DRY_SIGNAL*/) / 256);
s32 outUnclamped = ((outTmp * REVERB_WET_SIGNAL/* + inSample * REVERB_DRY_SIGNAL*/) / 256);
*outSample = CLAMP_S16(outUnclamped);
}
#endif
@@ -306,8 +298,7 @@ u8 audioString2[] = "cont %x: delaybytes %d : olddelay %d\n";
void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex) {
struct ReverbRingBufferItem *item;
struct SynthesisReverb *reverb = &gSynthesisReverbs[reverbIndex];
s32 srcPos;
s32 dstPos;
s32 srcPos, dstPos;
s32 nSamples;
s32 excessiveSamples;
if (reverb->downsampleRate != 1) {
@@ -321,10 +312,8 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
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];
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];
@@ -356,10 +345,8 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
#else
void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) {
struct ReverbRingBufferItem *item;
s32 srcPos;
s32 dstPos;
s32 srcPos, dstPos;
s32 nSamples;
s32 numSamplesAfterDownsampling;
s32 excessiveSamples;
#ifdef BETTER_REVERB
@@ -377,10 +364,8 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) {
for (srcPos = 0, dstPos = 0; dstPos < item->lengthA / 2;
srcPos += gReverbDownsampleRate, dstPos++) {
gSynthesisReverb.ringBuffer.left[dstPos + item->startPos] =
item->toDownsampleLeft[srcPos];
gSynthesisReverb.ringBuffer.right[dstPos + item->startPos] =
item->toDownsampleRight[srcPos];
gSynthesisReverb.ringBuffer.left[dstPos + item->startPos] = item->toDownsampleLeft[srcPos];
gSynthesisReverb.ringBuffer.right[dstPos + item->startPos] = item->toDownsampleRight[srcPos];
}
for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += gReverbDownsampleRate, dstPos++) {
gSynthesisReverb.ringBuffer.left[dstPos] = item->toDownsampleLeft[srcPos];
@@ -394,38 +379,35 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) {
if (gSoundMode == SOUND_MODE_MONO || monoReverb) {
if (gReverbDownsampleRate != 1) {
osInvalDCache(item->toDownsampleLeft, DEFAULT_LEN_2CH);
for (srcPos = 0, dstPos = item->startPos; dstPos < item->lengthA / 2 + item->startPos; srcPos += gReverbDownsampleRate, dstPos++) {
for (srcPos = 0, dstPos = item->startPos; dstPos < ((item->lengthA / 2) + item->startPos); srcPos += gReverbDownsampleRate, dstPos++) {
reverb_mono_sample(&gSynthesisReverb.ringBuffer.left[dstPos], ((s32) item->toDownsampleLeft[srcPos] + (s32) item->toDownsampleRight[srcPos]) / 2);
gSynthesisReverb.ringBuffer.right[dstPos] = gSynthesisReverb.ringBuffer.left[dstPos];
}
for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += gReverbDownsampleRate, dstPos++) {
for (dstPos = 0; dstPos < (item->lengthB / 2); srcPos += gReverbDownsampleRate, dstPos++) {
reverb_mono_sample(&gSynthesisReverb.ringBuffer.left[dstPos], ((s32) item->toDownsampleLeft[srcPos] + (s32) item->toDownsampleRight[srcPos]) / 2);
gSynthesisReverb.ringBuffer.right[dstPos] = gSynthesisReverb.ringBuffer.left[dstPos];
}
}
else { // Too slow for practical use, not recommended most of the time.
for (dstPos = item->startPos; dstPos < item->lengthA / 2 + item->startPos; dstPos++) {
} else { // Too slow for practical use, not recommended most of the time.
for (dstPos = item->startPos; dstPos < ((item->lengthA / 2) + item->startPos); dstPos++) {
reverb_mono_sample(&gSynthesisReverb.ringBuffer.left[dstPos], ((s32) gSynthesisReverb.ringBuffer.left[dstPos] + (s32) gSynthesisReverb.ringBuffer.right[dstPos]) / 2);
gSynthesisReverb.ringBuffer.right[dstPos] = gSynthesisReverb.ringBuffer.left[dstPos];
}
for (dstPos = 0; dstPos < item->lengthB / 2; dstPos++) {
for (dstPos = 0; dstPos < (item->lengthB / 2); dstPos++) {
reverb_mono_sample(&gSynthesisReverb.ringBuffer.left[dstPos], ((s32) gSynthesisReverb.ringBuffer.left[dstPos] + (s32) gSynthesisReverb.ringBuffer.right[dstPos]) / 2);
gSynthesisReverb.ringBuffer.right[dstPos] = gSynthesisReverb.ringBuffer.left[dstPos];
}
}
}
else {
} else {
if (gReverbDownsampleRate != 1) {
osInvalDCache(item->toDownsampleLeft, DEFAULT_LEN_2CH);
for (srcPos = 0, dstPos = item->startPos; dstPos < item->lengthA / 2 + item->startPos; srcPos += gReverbDownsampleRate, dstPos++)
for (srcPos = 0, dstPos = item->startPos; dstPos < ((item->lengthA / 2) + item->startPos); srcPos += gReverbDownsampleRate, dstPos++)
reverb_samples(&gSynthesisReverb.ringBuffer.left[dstPos], &gSynthesisReverb.ringBuffer.right[dstPos], item->toDownsampleLeft[srcPos], item->toDownsampleRight[srcPos]);
for (dstPos = 0; dstPos < item->lengthB / 2; srcPos += gReverbDownsampleRate, dstPos++)
for (dstPos = 0; dstPos < (item->lengthB / 2); srcPos += gReverbDownsampleRate, dstPos++)
reverb_samples(&gSynthesisReverb.ringBuffer.left[dstPos], &gSynthesisReverb.ringBuffer.right[dstPos], item->toDownsampleLeft[srcPos], item->toDownsampleRight[srcPos]);
}
else { // Too slow for practical use, not recommended most of the time.
for (dstPos = item->startPos; dstPos < item->lengthA / 2 + item->startPos; dstPos++)
} else { // Too slow for practical use, not recommended most of the time.
for (dstPos = item->startPos; dstPos < ((item->lengthA / 2) + item->startPos); dstPos++)
reverb_samples(&gSynthesisReverb.ringBuffer.left[dstPos], &gSynthesisReverb.ringBuffer.right[dstPos], gSynthesisReverb.ringBuffer.left[dstPos], gSynthesisReverb.ringBuffer.right[dstPos]);
for (dstPos = 0; dstPos < item->lengthB / 2; dstPos++)
for (dstPos = 0; dstPos < (item->lengthB / 2); dstPos++)
reverb_samples(&gSynthesisReverb.ringBuffer.left[dstPos], &gSynthesisReverb.ringBuffer.right[dstPos], gSynthesisReverb.ringBuffer.left[dstPos], gSynthesisReverb.ringBuffer.right[dstPos]);
}
}
@@ -433,7 +415,7 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex) {
#endif
item = &gSynthesisReverb.items[gSynthesisReverb.curFrame][updateIndex];
numSamplesAfterDownsampling = chunkLen / gReverbDownsampleRate;
s32 numSamplesAfterDownsampling = chunkLen / gReverbDownsampleRate;
if (((numSamplesAfterDownsampling + gSynthesisReverb.nextRingBufferPos) - gSynthesisReverb.bufSizePerChannel) < 0) {
// There is space in the ring buffer before it wraps around
item->lengthA = numSamplesAfterDownsampling * 2;
@@ -541,13 +523,10 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) {
aiBufPtr = (u32 *) aiBuf;
for (i = gAudioBufferParameters.updatesPerFrame; i > 0; i--) {
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
chunkLen = bufLen;
leftVolRamp = gLeftVolRampings[nextVolRampTable];
rightVolRamp = gRightVolRampings[nextVolRampTable & 0xFFFFFFFF];
} else {
if (bufLen / i >= gAudioBufferParameters.samplesPerUpdateMax) {
chunkLen = gAudioBufferParameters.samplesPerUpdateMax; nextVolRampTable = 2; leftVolRamp = gLeftVolRampings[2]; rightVolRamp = gRightVolRampings[2];
@@ -593,16 +572,17 @@ u64 *synthesis_execute(u64 *cmdBuf, s32 *writtenCmds, s16 *aiBuf, s32 bufLen) {
if (gIsConsole) {
reverbFilterCount = (s32) reverbFilterCountConsole;
monoReverb = monoReverbConsole;
}
else {
} else {
reverbFilterCount = (s32) reverbFilterCountEmulator;
monoReverb = monoReverbEmulator;
}
if (reverbFilterCount > NUM_ALLPASS)
if (reverbFilterCount > NUM_ALLPASS) {
reverbFilterCount = NUM_ALLPASS;
reverbFilterCountm1 = reverbFilterCount - 1;
if (reverbFilterCount < 3)
}
reverbFilterCountm1 = (reverbFilterCount - 1);
if (reverbFilterCount < 3) {
reverbFilterCountm1 = 0;
}
#endif
for (i = gAudioUpdatesPerFrame; i > 0; i--) {
@@ -654,7 +634,7 @@ u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s1
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);
} else {
startPad = (item->startPos % 8u) * 2;
startPad = (item->startPos & 0x7) * 2
paddedLengthA = AUDIO_ALIGN(startPad + item->lengthA, 4);
cmd = synthesis_load_reverb_ring_buffer(cmd, DMEM_ADDR_RESAMPLED, (item->startPos - startPad / 2), DEFAULT_LEN_1CH, reverbIndex);
@@ -760,7 +740,7 @@ u64 *synthesis_do_one_audio_update(s16 *aiBuf, s32 bufLen, u64 *cmd, s32 updateI
}
for (; i < notePos; i++) {
temp = updateIndex * gMaxSimultaneousNotes;
if (IS_BANK_LOAD_COMPLETE(gNoteSubsEu[temp + noteIndices[i]].bankId) == TRUE) {
if (IS_BANK_LOAD_COMPLETE(gNoteSubsEu[temp + noteIndices[i]].bankId)) {
cmd = synthesis_process_note(&gNotes[noteIndices[i]],
&gNoteSubsEu[temp + noteIndices[i]],
&gNotes[noteIndices[i]].synthesisState,
@@ -924,9 +904,9 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
#ifdef VERSION_US
//! This function requires note->enabled to be volatile, but it breaks other functions like note_enable.
//! Casting to a struct with just the volatile bitfield works, but there may be a better way to match.
if (((struct vNote *)note)->enabled && IS_BANK_LOAD_COMPLETE(note->bankId) == FALSE) {
if (((struct vNote *)note)->enabled && !IS_BANK_LOAD_COMPLETE(note->bankId)) {
#else
if (IS_BANK_LOAD_COMPLETE(note->bankId) == FALSE) {
if (!IS_BANK_LOAD_COMPLETE(note->bankId)) {
#endif
gAudioErrorFlags = (note->bankId << 8) + noteIndex + 0x1000000;
} else if (((struct vNote *)note)->enabled) {
@@ -961,19 +941,19 @@ u64 *synthesis_process_notes(s16 *aiBuf, s32 bufLen, u64 *cmd) {
}
#ifndef VERSION_EU
if (note->frequency < US_FLOAT(2.0)) {
if (note->frequency < 2.0f) {
nParts = 1;
if (note->frequency > US_FLOAT(1.99996)) {
note->frequency = US_FLOAT(1.99996);
if (note->frequency > 1.99996f) {
note->frequency = 1.99996f;
}
resamplingRate = note->frequency;
} else {
// If frequency is > 2.0, the processing must be split into two parts
nParts = 2;
if (note->frequency >= US_FLOAT(3.99993)) {
note->frequency = US_FLOAT(3.99993);
if (note->frequency >= 3.99993f) {
note->frequency = 3.99993f;
}
resamplingRate = note->frequency * US_FLOAT(.5);
resamplingRate = note->frequency * 0.5f;
}
resamplingRateFixedPoint = (u16)(s32)(resamplingRate * 32768.0f);
@@ -1390,7 +1370,8 @@ u64 *final_resample(u64 *cmd, struct Note *note, s32 count, u16 pitch, u16 dmemI
#endif
#ifndef VERSION_EU
u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, s32 headsetPanSettings, UNUSED u32 flags) {
u64 *process_envelope(u64 *cmd, struct Note *note, s32 nSamples, u16 inBuf, s32 headsetPanSettings,
UNUSED u32 flags) {
struct VolumeChange vol;
vol.sourceLeft = note->curVolLeft;
vol.sourceRight = note->curVolRight;
@@ -1519,16 +1500,12 @@ u64 *process_envelope(u64 *cmd, struct NoteSubEu *note, struct NoteSynthesisStat
if (note->stereoStrongRight) {
aSetBuffer(cmd++, 0, 0, 0, nSamples * 2);
// 0x8000 is -100%, so subtract sound instead of adding...
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY,
/*out*/ DMEM_ADDR_LEFT_CH);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_WET,
/*out*/ DMEM_ADDR_WET_LEFT_CH);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY, /*out*/ DMEM_ADDR_LEFT_CH);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_WET, /*out*/ DMEM_ADDR_WET_LEFT_CH);
} else if (note->stereoStrongLeft) {
aSetBuffer(cmd++, 0, 0, 0, nSamples * 2);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY,
/*out*/ DMEM_ADDR_RIGHT_CH);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_WET,
/*out*/ DMEM_ADDR_WET_RIGHT_CH);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_DRY, /*out*/ DMEM_ADDR_RIGHT_CH);
aMix(cmd++, 0, /*gain*/ 0x8000, /*in*/ DMEM_ADDR_STEREO_STRONG_TEMP_WET, /*out*/ DMEM_ADDR_WET_RIGHT_CH);
}
} else {
#ifdef VERSION_EU
@@ -1605,11 +1582,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));
#ifdef VERSION_EU
pitch = (bufLen << 0xf) / (bufLen + panShift - prevPanShift + 8);
#else
pitch = (bufLen << 0xf) / (panShift + bufLen - prevPanShift + 8);
#endif
aSetBuffer(cmd++, 0, DMEM_ADDR_NOTE_PAN_TEMP + 8, DMEM_ADDR_TEMP, panShift + bufLen - prevPanShift);
aResample(cmd++, 0, pitch, VIRTUAL_TO_PHYSICAL2(note->synthesisBuffers->panResampleState));
} else {
@@ -1664,19 +1637,8 @@ void note_init_volume(struct Note *note) {
}
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
panIndex = (s32)(pan * 127.5f) & 127;
#endif
f32 volLeft, volRight;
s32 panIndex = (s32)(pan * 127.5f) & 127;
if (note->stereoHeadsetEffects && gSoundMode == SOUND_MODE_HEADSET) {
s8 smallPanIndex;
s8 temp = (s8)(pan * 10.0f);
@@ -1693,10 +1655,8 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb
volLeft = gHeadsetPanVolume[panIndex];
volRight = gHeadsetPanVolume[127 - panIndex];
} else if (note->stereoHeadsetEffects && gSoundMode == SOUND_MODE_STEREO) {
u8 strongLeft;
u8 strongRight;
strongLeft = FALSE;
strongRight = FALSE;
u8 strongLeft = FALSE;
u8 strongRight = FALSE;
note->headsetPanLeft = 0;
note->headsetPanRight = 0;
note->usesHeadsetPanEffects = FALSE;
@@ -1710,8 +1670,8 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb
note->stereoStrongRight = strongRight;
note->stereoStrongLeft = strongLeft;
} else if (gSoundMode == SOUND_MODE_MONO) {
volLeft = .707f;
volRight = .707f;
volLeft = 0.707f;
volRight = 0.707f;
} else {
volLeft = gDefaultPanVolume[panIndex];
volRight = gDefaultPanVolume[127 - panIndex];
@@ -1720,13 +1680,8 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb
if (velocity < 0) {
velocity = 0;
}
#ifdef VERSION_JP
note->targetVolLeft = (u16)(velocity * volLeft) & ~0x80FF; // 0x7F00, but that doesn't match
note->targetVolRight = (u16)(velocity * volRight) & ~0x80FF;
#else
note->targetVolLeft = (u16)(s32)(velocity * volLeft) & ~0x80FF;
note->targetVolRight = (u16)(s32)(velocity * volRight) & ~0x80FF;
#endif
if (note->targetVolLeft == 0) {
note->targetVolLeft++;
}
@@ -1740,11 +1695,7 @@ void note_set_vel_pan_reverb(struct Note *note, f32 velocity, f32 pan, u8 reverb
return;
}
if (note->needsInit) {
note->envMixerNeedsInit = TRUE;
} else {
note->envMixerNeedsInit = FALSE;
}
note->envMixerNeedsInit = note->needsInit;
}
void note_set_frequency(struct Note *note, f32 frequency) {
@@ -1766,10 +1717,10 @@ void note_enable(struct Note *note) {
}
void note_disable(struct Note *note) {
if (note->needsInit == TRUE) {
if (note->needsInit) {
note->needsInit = FALSE;
} else {
note_set_vel_pan_reverb(note, 0, .5, 0);
note_set_vel_pan_reverb(note, 0, 0.5f, 0);
}
note->priority = NOTE_PRIORITY_DISABLED;
note->enabled = FALSE;
+25 -12
View File
@@ -17,15 +17,19 @@
#define MAX_UPDATES_PER_FRAME 4
#endif
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
// Size determined by ((all delaysBaselineL/R values * 8) / (2 ^ Minimum Downsample Factor)) + array pointers (0x80).
// The default value can be increased or decreased in conjunction with the values in delaysBaselineL/R
#define BETTER_REVERB_SIZE 0xF200
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
// #define BETTER_REVERB_SIZE 0x7A00 // Default for use only with a downsampling value of 3 (i.e. double the emulator default)
// #define BETTER_REVERB_SIZE 0x1E200 // Default for use with a downsampling value of 1 (i.e. no downsampling at all)
#if defined(BETTER_REVERB) && (defined(VERSION_US) || defined(VERSION_JP))
#define NUM_ALLPASS 12 // Number of delay filters to use with better reverb; do not change this value if you don't know what you're doing.
#define BETTER_REVERB_PTR_SIZE ALIGN16(NUM_ALLPASS * sizeof(s32*) * 2) // Allocation space consumed by dynamically allocated pointers
// Size determined by (all delaysBaselineL/R values * 8) / (2 ^ Minimum Downsample Factor).
// The default value can be increased or decreased in conjunction with the values in delaysBaselineL/R
#define BETTER_REVERB_SIZE ALIGN16(0xF200 + BETTER_REVERB_PTR_SIZE)
// #define BETTER_REVERB_SIZE (0x7A00 + BETTER_REVERB_PTR_SIZE) // Default for use only with a downsampling value of 3 (i.e. double the emulator default)
// #define BETTER_REVERB_SIZE (0x1E200 + BETTER_REVERB_PTR_SIZE) // Default for use with a downsampling value of 1 (i.e. no downsampling at all)
extern s8 betterReverbDownsampleConsole;
extern s8 betterReverbDownsampleEmulator;
@@ -45,12 +49,23 @@ extern s32 **delayBufsL;
extern s32 **delayBufsR;
extern u8 toggleBetterReverb;
#define REVERB_WINDOW_SIZE_MAX 0x2000
#else
#define BETTER_REVERB_SIZE 0
#ifdef VERSION_EU
#define REVERB_WINDOW_SIZE_MAX 0x1000
#else
#define REVERB_WINDOW_SIZE_MAX 0x1000
#endif
struct ReverbRingBufferItem
{
#endif
#define REVERB_WINDOW_HEAP_SIZE (REVERB_WINDOW_SIZE_MAX * sizeof(s16) * 2)
struct ReverbRingBufferItem {
s16 numSamplesAfterDownsampling;
s16 chunkLen; // never read
s16 *toDownsampleLeft;
@@ -60,8 +75,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;
@@ -85,8 +99,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;
+18 -37
View File
@@ -25,7 +25,7 @@
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)))
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); \
@@ -62,12 +62,8 @@ struct NoteSubEu *gNoteSubsEu;
// 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 srcPos, dstPos;
if (reverb->downsampleRate != 1) {
if (reverb->framesLeftToIgnore == 0) {
// Now that the RSP has finished, downsample the samples produced two frames ago by skipping
@@ -79,10 +75,8 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
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];
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];
@@ -91,9 +85,9 @@ void prepare_reverb_ring_buffer(s32 chunkLen, u32 updateIndex, s32 reverbIndex)
}
}
item = &reverb->items[reverb->curFrame][updateIndex];
nSamples = chunkLen / reverb->downsampleRate;
excessiveSamples = (nSamples + reverb->nextRingBufferPos) - reverb->bufSizePerChannel;
struct ReverbRingBufferItem *item = &reverb->items[reverb->curFrame][updateIndex];
s32 nSamples = chunkLen / reverb->downsampleRate;
s32 excessiveSamples = (nSamples + reverb->nextRingBufferPos) - reverb->bufSizePerChannel;
if (excessiveSamples < 0) {
// There is space in the ring buffer before it wraps around
item->lengthA = nSamples * 2;
@@ -141,8 +135,7 @@ void func_sh_802ed644(s32 updateIndexStart, s32 noteIndex) {
}
void synthesis_load_note_subs_eu(s32 updateIndex) {
struct NoteSubEu *src;
struct NoteSubEu *dest;
struct NoteSubEu *src, *dest;
s32 i;
for (i = 0; i < gMaxSimultaneousNotes; i++) {
@@ -216,7 +209,7 @@ u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s1
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;
startPad = (item->startPos & 0x7) * 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);
@@ -243,11 +236,8 @@ u64 *synthesis_resample_and_mix_reverb(u64 *cmd, s32 bufLen, s16 reverbIndex, s1
}
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];
struct SynthesisReverb *reverb = &gSynthesisReverbs[reverbIndex];
struct ReverbRingBufferItem *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) {
@@ -258,9 +248,7 @@ u64 *synthesis_load_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) {
}
u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) {
struct ReverbRingBufferItem *item;
item = &gSynthesisReverbs[reverbIndex].items[gSynthesisReverbs[reverbIndex].curFrame][updateIndex];
struct ReverbRingBufferItem *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
@@ -283,11 +271,8 @@ u64 *synthesis_save_reverb_samples(u64 *cmd, s16 reverbIndex, s16 updateIndex) {
}
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];
struct SynthesisReverb *reverb = &gSynthesisReverbs[reverbIndex];
struct ReverbRingBufferItem *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) {
@@ -670,7 +655,7 @@ skip:
flags = A_INIT;
noteSubEu->needsInit = FALSE;
}
flags = flags | sp56;
flags |= sp56;
cmd = final_resample(cmd, synthesisState, bufLen * 2, resamplingRateFixedPoint,
noteSamplesDmemAddrBeforeResampling, flags);
if ((flags & 1) != 0) {
@@ -745,12 +730,9 @@ u64 *final_resample(u64 *cmd, struct NoteSynthesisState *synthesisState, s32 cou
}
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;
u16 sourceRight, sourceLeft;
u16 targetLeft, targetRight;
s16 rampLeft, rampRight;
s32 sourceReverbVol;
s16 rampReverb;
s32 reverbVolDiff = 0;
@@ -841,7 +823,6 @@ u64 *note_apply_headset_pan_effects(u64 *cmd, struct NoteSubEu *noteSubEu, struc
u16 pitch;
u8 prevPanShift;
u8 panShift;
UNUSED u8 unkDebug;
switch (leftRight) {
case 1:
+102 -83
View File
@@ -21,13 +21,15 @@
#include "game/puppylights.h"
// Message IDs
#define MESG_SP_COMPLETE 100
#define MESG_DP_COMPLETE 101
#define MESG_VI_VBLANK 102
#define MESG_START_GFX_SPTASK 103
#define MESG_NMI_REQUEST 104
enum MessageIDs {
MESG_SP_COMPLETE = 100,
MESG_DP_COMPLETE,
MESG_VI_VBLANK,
MESG_START_GFX_SPTASK,
MESG_NMI_REQUEST,
};
OSThread gUnkThread; // unused?
// OSThread gUnkThread; // unused?
OSThread gIdleThread;
OSThread gMainThread;
OSThread gGameLoopThread;
@@ -52,41 +54,41 @@ OSViMode VI;
struct Config gConfig;
struct VblankHandler *gVblankHandler1 = NULL;
struct VblankHandler *gVblankHandler2 = NULL;
struct VblankHandler *gVblankHandler3 = NULL;
struct SPTask *gActiveSPTask = NULL;
struct SPTask *sCurrentAudioSPTask = NULL;
struct SPTask *sCurrentDisplaySPTask = NULL;
struct SPTask *sNextAudioSPTask = NULL;
struct SPTask *sNextDisplaySPTask = NULL;
s8 sAudioEnabled = TRUE;
u32 gNumVblanks = 0;
s8 gResetTimer = 0;
s8 gNmiResetBarsTimer = 0;
#ifdef DEBUG_LEVEL_SELECT
s8 gDebugLevelSelect = TRUE;
#else
s8 gDebugLevelSelect = FALSE;
#endif
struct VblankHandler *gVblankHandler1 = NULL;
struct VblankHandler *gVblankHandler2 = NULL;
struct VblankHandler *gVblankHandler3 = NULL;
struct SPTask *gActiveSPTask = NULL;
struct SPTask *sCurrentAudioSPTask = NULL;
struct SPTask *sCurrentDisplaySPTask = NULL;
struct SPTask *sNextAudioSPTask = NULL;
struct SPTask *sNextDisplaySPTask = NULL;
s8 gAudioEnabled = TRUE;
u32 gNumVblanks = 0;
s8 gResetTimer = 0;
s8 gNmiResetBarsTimer = 0;
s8 gDebugLevelSelect = FALSE;
#ifdef VANILLA_DEBUG
s8 gShowDebugText = FALSE;
// unused
void handle_debug_key_sequences(void) {
static u16 sDebugTextKeySequence[] = { D_JPAD, D_JPAD, U_JPAD, U_JPAD,
L_JPAD, R_JPAD, L_JPAD, R_JPAD };
static s16 sDebugTextKey = 0;
UNUSED static u16 sDebugTextKeySequence[] = {
D_JPAD, D_JPAD, U_JPAD, U_JPAD, L_JPAD, R_JPAD, L_JPAD, R_JPAD
};
static s16 sDebugTextKey = 0;
UNUSED void handle_debug_key_sequences(void) {
if (gPlayer3Controller->buttonPressed != 0) {
if (sDebugTextKeySequence[sDebugTextKey++] == gPlayer3Controller->buttonPressed) {
if (sDebugTextKey == ARRAY_COUNT(sDebugTextKeySequence)) {
sDebugTextKey = 0, gShowDebugText ^= 1;
sDebugTextKey = 0;
gShowDebugText ^= 1;
}
} else {
sDebugTextKey = 0;
}
}
}
#endif
void setup_mesg_queues(void) {
osCreateMesgQueue(&gDmaMesgQueue, gDmaMesgBuf, ARRAY_COUNT(gDmaMesgBuf));
@@ -107,10 +109,10 @@ void alloc_pool(void) {
void *end = (void *) (SEG_POOL_START + POOL_SIZE);
main_pool_init(start, end);
gEffectsMemoryPool = mem_pool_init(0x4000, MEMORY_POOL_LEFT);
#ifdef PUPPYLIGHTS
gEffectsMemoryPool = mem_pool_init(EFFECTS_MEMORY_POOL, MEMORY_POOL_LEFT);
#ifdef PUPPYLIGHTS
gLightsPool = mem_pool_init(PUPPYLIGHTS_POOL, MEMORY_POOL_LEFT);
#endif
#endif
}
void create_thread(OSThread *thread, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri pri) {
@@ -140,8 +142,12 @@ void receive_new_tasks(void) {
while (osRecvMesg(&gSPTaskMesgQueue, (OSMesg *) &spTask, OS_MESG_NOBLOCK) != -1) {
spTask->state = SPTASK_STATE_NOT_STARTED;
switch (spTask->task.t.type) {
case 2: sNextAudioSPTask = spTask; break;
case 1: sNextDisplaySPTask = spTask; break;
case 2:
sNextAudioSPTask = spTask;
break;
case 1:
sNextDisplaySPTask = spTask;
break;
}
}
@@ -176,8 +182,9 @@ void interrupt_gfx_sptask(void) {
}
void start_gfx_sptask(void) {
if (gActiveSPTask == NULL && sCurrentDisplaySPTask != NULL
&& sCurrentDisplaySPTask->state == SPTASK_STATE_NOT_STARTED) {
if (gActiveSPTask == NULL
&& sCurrentDisplaySPTask != NULL
&& sCurrentDisplaySPTask->state == SPTASK_STATE_NOT_STARTED) {
#if PUPPYPRINT_DEBUG
rspDelta = osGetTime();
#endif
@@ -192,7 +199,6 @@ void pretend_audio_sptask_done(void) {
}
void handle_vblank(void) {
gNumVblanks++;
if (gResetTimer > 0 && gResetTimer < 100) {
gResetTimer++;
@@ -209,15 +215,16 @@ void handle_vblank(void) {
if (gActiveSPTask != NULL) {
interrupt_gfx_sptask();
} else {
if (sAudioEnabled) {
if (gAudioEnabled) {
start_sptask(M_AUDTASK);
} else {
pretend_audio_sptask_done();
}
}
} else {
if (gActiveSPTask == NULL && sCurrentDisplaySPTask != NULL
&& sCurrentDisplaySPTask->state != SPTASK_STATE_FINISHED) {
if (gActiveSPTask == NULL
&& sCurrentDisplaySPTask != NULL
&& sCurrentDisplaySPTask->state != SPTASK_STATE_FINISHED) {
#if PUPPYPRINT_DEBUG
rspDelta = osGetTime();
#endif
@@ -240,20 +247,19 @@ void handle_sp_complete(void) {
gActiveSPTask = NULL;
if (curSPTask->state == SPTASK_STATE_INTERRUPTED) {
// handle_vblank tried to start an audio task while there was already a
// gfx task running, so it had to interrupt the gfx task. That interruption
// just finished.
// handle_vblank tried to start an audio task while there was already a gfx task
// running, so it had to interrupt the gfx task. That interruption just finished.
if (osSpTaskYielded(&curSPTask->task) == 0) {
// The gfx task completed before we had time to interrupt it.
// Mark it finished, just like below.
curSPTask->state = SPTASK_STATE_FINISHED;
#if PUPPYPRINT_DEBUG
#if PUPPYPRINT_DEBUG
profiler_update(rspGenTime, rspDelta);
#endif
#endif
}
// Start the audio task, as expected by handle_vblank.
if (sAudioEnabled) {
if (gAudioEnabled) {
start_sptask(M_AUDTASK);
} else {
pretend_audio_sptask_done();
@@ -262,8 +268,8 @@ void handle_sp_complete(void) {
curSPTask->state = SPTASK_STATE_FINISHED;
if (curSPTask->task.t.type == M_AUDTASK) {
// After audio tasks come gfx tasks.
if (sCurrentDisplaySPTask != NULL
&& sCurrentDisplaySPTask->state != SPTASK_STATE_FINISHED) {
if ((sCurrentDisplaySPTask != NULL)
&& (sCurrentDisplaySPTask->state != SPTASK_STATE_FINISHED)) {
start_sptask(M_GFXTASK);
}
sCurrentAudioSPTask = NULL;
@@ -311,10 +317,10 @@ void thread3_main(UNUSED void *arg) {
osSyncPrintf("Linker : %s\n", __linker__);
#endif
create_thread(&gSoundThread, 4, thread4_sound, NULL, (gThread4Stack + 0x2000), 20);
create_thread(&gSoundThread, THREAD_4_SOUND, thread4_sound, NULL, gThread4Stack + 0x2000, 20);
osStartThread(&gSoundThread);
create_thread(&gGameLoopThread, 5, thread5_game_loop, NULL, (gThread5Stack + 0x2000), 10);
create_thread(&gGameLoopThread, THREAD_5_GAME_LOOP, thread5_game_loop, NULL, gThread5Stack + 0x2000, 10);
osStartThread(&gGameLoopThread);
while (TRUE) {
@@ -324,11 +330,21 @@ void thread3_main(UNUSED void *arg) {
#endif
osRecvMesg(&gIntrMesgQueue, &msg, OS_MESG_BLOCK);
switch ((uintptr_t) msg) {
case MESG_VI_VBLANK: handle_vblank(); break;
case MESG_SP_COMPLETE: handle_sp_complete(); break;
case MESG_DP_COMPLETE: handle_dp_complete(); break;
case MESG_START_GFX_SPTASK: start_gfx_sptask(); break;
case MESG_NMI_REQUEST: handle_nmi_request(); break;
case MESG_VI_VBLANK:
handle_vblank();
break;
case MESG_SP_COMPLETE:
handle_sp_complete();
break;
case MESG_DP_COMPLETE:
handle_dp_complete();
break;
case MESG_START_GFX_SPTASK:
start_gfx_sptask();
break;
case MESG_NMI_REQUEST:
handle_nmi_request();
break;
}
#if PUPPYPRINT_DEBUG
profiler_update(taskTime, first);
@@ -341,9 +357,15 @@ void set_vblank_handler(s32 index, struct VblankHandler *handler, OSMesgQueue *q
handler->msg = msg;
switch (index) {
case 1: gVblankHandler1 = handler; break;
case 2: gVblankHandler2 = handler; break;
case 3: gVblankHandler3 = handler; break;
case 1:
gVblankHandler1 = handler;
break;
case 2:
gVblankHandler2 = handler;
break;
case 3:
gVblankHandler3 = handler;
break;
}
}
@@ -353,7 +375,7 @@ void send_sp_task_message(OSMesg *msg) {
}
void dispatch_audio_sptask(struct SPTask *spTask) {
if (sAudioEnabled && spTask != NULL) {
if (gAudioEnabled && spTask != NULL) {
osWritebackDCacheAll();
osSendMesg(&gSPTaskMesgQueue, spTask, OS_MESG_NOBLOCK);
}
@@ -374,11 +396,11 @@ void exec_display_list(struct SPTask *spTask) {
}
void turn_on_audio(void) {
sAudioEnabled = TRUE;
gAudioEnabled = TRUE;
}
void turn_off_audio(void) {
sAudioEnabled = FALSE;
gAudioEnabled = FALSE;
while (sCurrentAudioSPTask != NULL) {
;
}
@@ -420,27 +442,23 @@ void get_audio_frequency(void) {
* Initialize hardware, start main thread, then idle.
*/
void thread1_idle(UNUSED void *arg) {
osCreateViManager(OS_PRIORITY_VIMGR);
switch ( osTvType ) {
case OS_TV_NTSC:
// NTSC
//osViSetMode(&osViModeTable[OS_VI_NTSC_LAN1]);
VI = osViModeTable[OS_VI_NTSC_LAN1];
gConfig.tvType = MODE_NTSC;
break;
case OS_TV_MPAL:
// MPAL
//osViSetMode(&osViModeTable[OS_VI_MPAL_LAN1]);
VI = osViModeTable[OS_VI_NTSC_LAN1];
gConfig.tvType = MODE_MPAL;
break;
case OS_TV_PAL:
// PAL
//osViSetMode(&osViModeTable[OS_VI_PAL_LAN1]);
VI = osViModeTable[OS_VI_NTSC_LAN1];
gConfig.tvType = MODE_PAL;
break;
switch (osTvType) {
case OS_TV_NTSC:
//osViSetMode(&osViModeTable[OS_VI_NTSC_LAN1]);
VI = osViModeTable[OS_VI_NTSC_LAN1];
gConfig.tvType = MODE_NTSC;
break;
case OS_TV_MPAL:
//osViSetMode(&osViModeTable[OS_VI_MPAL_LAN1]);
VI = osViModeTable[OS_VI_NTSC_LAN1];
gConfig.tvType = MODE_MPAL;
break;
case OS_TV_PAL:
//osViSetMode(&osViModeTable[OS_VI_PAL_LAN1]);
VI = osViModeTable[OS_VI_NTSC_LAN1];
gConfig.tvType = MODE_PAL;
break;
}
get_audio_frequency();
change_vi(&VI, SCREEN_WIDTH, SCREEN_HEIGHT);
@@ -449,7 +467,7 @@ void thread1_idle(UNUSED void *arg) {
osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON);
osViSetSpecialFeatures(OS_VI_GAMMA_OFF);
osCreatePiManager(OS_PRIORITY_PIMGR, &gPIMesgQueue, gPIMesgBuf, ARRAY_COUNT(gPIMesgBuf));
create_thread(&gMainThread, 3, thread3_main, NULL, gThread3Stack + 0x2000, 100);
create_thread(&gMainThread, THREAD_3_MAIN, thread3_main, NULL, gThread3Stack + 0x2000, 100);
osStartThread(&gMainThread);
osSetThreadPri(NULL, 0);
@@ -461,7 +479,8 @@ void thread1_idle(UNUSED void *arg) {
}
#if CLEARRAM
void ClearRAM(void) {
void ClearRAM(void)
{
bzero(_mainSegmentEnd, (size_t)osMemSize - (size_t)OS_K0_TO_PHYSICAL(_mainSegmentEnd));
}
#endif
@@ -490,6 +509,6 @@ void main_func(void) {
#ifdef ISVPRINT
osInitialize_fakeisv();
#endif
create_thread(&gIdleThread, 1, thread1_idle, NULL, gIdleThreadStack + 0x800, 100);
create_thread(&gIdleThread, THREAD_1_IDLE, thread1_idle, NULL, gIdleThreadStack + 0x800, 100);
osStartThread(&gIdleThread);
}
+59 -49
View File
@@ -2,8 +2,6 @@
#include "sm64.h"
#define INCLUDED_FROM_MEMORY_C
#include "buffers/buffers.h"
#include "slidec.h"
#include "game/game_init.h"
@@ -82,7 +80,7 @@ uintptr_t set_segment_base_addr(s32 segment, void *addr) {
return sSegmentTable[segment];
}
void *get_segment_base_addr(s32 segment) {
UNUSED void *get_segment_base_addr(s32 segment) {
return (void *) (sSegmentTable[segment] | 0x80000000);
}
@@ -96,6 +94,7 @@ void *segmented_to_virtual(const void *addr) {
void *virtual_to_segmented(u32 segment, const void *addr) {
size_t offset = ((uintptr_t) addr & 0x1FFFFFFF) - sSegmentTable[segment];
return (void *) ((segment << 24) + offset);
}
@@ -125,8 +124,8 @@ void move_segment_table_to_dmem(void) {
* freeing the object that was most recently allocated from a side.
*/
void main_pool_init(void *start, void *end) {
sPoolStart = ((u8 *) ALIGN16((uintptr_t) start) + 16);
sPoolEnd = ((u8 *) ALIGN16((uintptr_t) end - 15) - 16);
sPoolStart = (u8 *) ALIGN16((uintptr_t) start) + 16;
sPoolEnd = (u8 *) ALIGN16((uintptr_t) end - 15) - 16;
sPoolFreeSpace = sPoolEnd - sPoolStart;
sPoolListHeadL = (struct MainPoolBlock *) (sPoolStart - 16);
@@ -135,11 +134,16 @@ void main_pool_init(void *start, void *end) {
sPoolListHeadL->next = NULL;
sPoolListHeadR->prev = NULL;
sPoolListHeadR->next = NULL;
#if PUPPYPRINT_DEBUG
#if PUPPYPRINT_DEBUG
mempool = sPoolFreeSpace;
#endif
#endif
}
extern u8 _framebuffersSegmentBssStart[];
extern u8 _framebuffersSegmentBssEnd[];
extern u8 _zbufferSegmentBssStart[];
extern u8 _zbufferSegmentBssEnd[];
/**
* Allocate a block of memory from the pool of given size, and from the
* specified side of the pool (MEMORY_POOL_LEFT or MEMORY_POOL_RIGHT).
@@ -149,23 +153,29 @@ void *main_pool_alloc(u32 size, u32 side) {
struct MainPoolBlock *newListHead;
void *addr = NULL;
size = (ALIGN16(size) + 16);
size = ALIGN16(size) + 16;
if (size != 0 && sPoolFreeSpace >= size) {
sPoolFreeSpace -= size;
if (side == MEMORY_POOL_LEFT) {
newListHead = (struct MainPoolBlock *) ((u8 *) sPoolListHeadL + size);
if ((u32)newListHead >= (u32)&_framebuffersSegmentBssStart && (u32)newListHead <= (u32)&_framebuffersSegmentBssEnd) {
newListHead = (struct MainPoolBlock *)ALIGN16((u32)&_framebuffersSegmentBssEnd + 0x40);
}
if ((u32)newListHead >= (u32)&_zbufferSegmentBssStart && (u32)newListHead <= (u32)&_zbufferSegmentBssEnd) {
newListHead = (struct MainPoolBlock *)ALIGN16((u32)&_zbufferSegmentBssEnd + 0x40);
}
sPoolListHeadL->next = newListHead;
newListHead->prev = sPoolListHeadL;
newListHead->next = NULL;
addr = ((u8 *) sPoolListHeadL + 16);
sPoolListHeadL = newListHead;
newListHead->prev = sPoolListHeadL;
newListHead->next = NULL;
addr = (u8 *) sPoolListHeadL + 16;
sPoolListHeadL = newListHead;
} else {
newListHead = (struct MainPoolBlock *) ((u8 *) sPoolListHeadR - size);
sPoolListHeadR->prev = newListHead;
newListHead->next = sPoolListHeadR;
newListHead->prev = NULL;
sPoolListHeadR = newListHead;
addr = ((u8 *) sPoolListHeadR + 16);
newListHead->next = sPoolListHeadR;
newListHead->prev = NULL;
sPoolListHeadR = newListHead;
addr = (u8 *) sPoolListHeadR + 16;
}
}
return addr;
@@ -178,7 +188,7 @@ void *main_pool_alloc(u32 size, u32 side) {
* Return the amount of free space left in the pool.
*/
u32 main_pool_free(void *addr) {
struct MainPoolBlock *block = (struct MainPoolBlock *) ((u8 *) addr - 16);
struct MainPoolBlock *block = (struct MainPoolBlock *) ((u8 *) addr - 16);
struct MainPoolBlock *oldListHead = (struct MainPoolBlock *) ((u8 *) addr - 16);
if (oldListHead < sPoolListHeadL) {
@@ -260,9 +270,9 @@ u32 main_pool_pop_state(void) {
*/
void dma_read(u8 *dest, u8 *srcStart, u8 *srcEnd) {
u32 size = ALIGN16(srcEnd - srcStart);
#if PUPPYPRINT_DEBUG
#if PUPPYPRINT_DEBUG
OSTime first = osGetTime();
#endif
#endif
osInvalDCache(dest, size);
while (size != 0) {
@@ -276,9 +286,9 @@ void dma_read(u8 *dest, u8 *srcStart, u8 *srcEnd) {
srcStart += copySize;
size -= copySize;
}
#if PUPPYPRINT_DEBUG
dmaTime[perfIteration] += osGetTime()-first;
#endif
#if PUPPYPRINT_DEBUG
dmaTime[perfIteration] += (osGetTime() - first);
#endif
}
/**
@@ -286,43 +296,42 @@ void dma_read(u8 *dest, u8 *srcStart, u8 *srcEnd) {
* Return the destination address.
*/
void *dynamic_dma_read(u8 *srcStart, u8 *srcEnd, u32 side, u32 alignment, u32 bssLength) {
void *dest;
u32 size = ALIGN16(srcEnd - srcStart);
u32 offset = 0;
if (alignment && side == MEMORY_POOL_LEFT) {
offset = ALIGN((uintptr_t)sPoolListHeadL + 16, alignment) - ((uintptr_t)sPoolListHeadL + 16);
offset = ALIGN(((uintptr_t)sPoolListHeadL + 16), alignment) - ((uintptr_t)sPoolListHeadL + 16);
}
dest = main_pool_alloc(offset + size + bssLength, side);
void *dest = main_pool_alloc((offset + size + bssLength), side);
if (dest != NULL) {
dma_read((u8 *)dest + offset, srcStart, srcEnd);
dma_read(((u8 *)dest + offset), srcStart, srcEnd);
if (bssLength) {
bzero((u8 *)dest + offset + size, bssLength);
bzero(((u8 *)dest + offset + size), bssLength);
}
}
return dest;
}
#define TLB_PAGE_SIZE 4096 //Blocksize of TLB transfers. Larger values can be faster to transfer, but more wasteful of RAM.
#define TLB_PAGE_SIZE 4096 // Blocksize of TLB transfers. Larger values can be faster to transfer, but more wasteful of RAM.
s32 gTlbEntries = 0;
u8 gTlbSegments[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
u8 gTlbSegments[NUM_TLB_SEGMENTS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
void mapTLBPages(uintptr_t virtualAddress, uintptr_t physicalAddress, s32 length, s32 segment) {
while (length > 0) {
if (length > TLB_PAGE_SIZE) {
osMapTLB(gTlbEntries++, OS_PM_4K, (void *)virtualAddress, physicalAddress, physicalAddress + TLB_PAGE_SIZE, -1);
virtualAddress += TLB_PAGE_SIZE;
osMapTLB(gTlbEntries++, OS_PM_4K, (void *)virtualAddress, physicalAddress, (physicalAddress + TLB_PAGE_SIZE), -1);
virtualAddress += TLB_PAGE_SIZE;
physicalAddress += TLB_PAGE_SIZE;
length -= TLB_PAGE_SIZE;
length -= TLB_PAGE_SIZE;
gTlbSegments[segment]++;
} else {
osMapTLB(gTlbEntries++, OS_PM_4K, (void *)virtualAddress, physicalAddress, -1, -1);
gTlbSegments[segment]++;
}
virtualAddress += TLB_PAGE_SIZE;
virtualAddress += TLB_PAGE_SIZE;
physicalAddress += TLB_PAGE_SIZE;
length -= TLB_PAGE_SIZE;
length -= TLB_PAGE_SIZE;
}
}
@@ -334,12 +343,12 @@ void mapTLBPages(uintptr_t virtualAddress, uintptr_t physicalAddress, s32 length
void *load_segment(s32 segment, u8 *srcStart, u8 *srcEnd, u32 side, u8 *bssStart, u8 *bssEnd) {
void *addr;
if (bssStart != NULL && side == MEMORY_POOL_LEFT) {
addr = dynamic_dma_read(srcStart, srcEnd, side, TLB_PAGE_SIZE, (uintptr_t)bssEnd - (uintptr_t)bssStart);
if ((bssStart != NULL) && (side == MEMORY_POOL_LEFT)) {
addr = dynamic_dma_read(srcStart, srcEnd, side, TLB_PAGE_SIZE, ((uintptr_t)bssEnd - (uintptr_t)bssStart));
if (addr != NULL) {
u8 *realAddr = (u8 *)ALIGN((uintptr_t)addr, TLB_PAGE_SIZE);
set_segment_base_addr(segment, realAddr);
mapTLBPages(segment << 24, VIRTUAL_TO_PHYSICAL(realAddr), (srcEnd - srcStart) + ((uintptr_t)bssEnd - (uintptr_t)bssStart), segment);
mapTLBPages((segment << 24), VIRTUAL_TO_PHYSICAL(realAddr), ((srcEnd - srcStart) + ((uintptr_t)bssEnd - (uintptr_t)bssStart)), segment);
}
} else {
addr = dynamic_dma_read(srcStart, srcEnd, side, 0, 0);
@@ -347,9 +356,9 @@ void *load_segment(s32 segment, u8 *srcStart, u8 *srcEnd, u32 side, u8 *bssStart
set_segment_base_addr(segment, addr);
}
}
#if PUPPYPRINT_DEBUG
ramsizeSegment[segment+nameTable-2] = (s32)srcEnd- (s32)srcStart;
#endif
#if PUPPYPRINT_DEBUG
ramsizeSegment[(segment + nameTable) - 2] = ((s32)srcEnd - (s32)srcStart);
#endif
return addr;
}
@@ -384,6 +393,7 @@ void *load_to_fixed_pool_addr(u8 *destAddr, u8 *srcStart, u8 *srcEnd) {
*/
void *load_segment_decompress(s32 segment, u8 *srcStart, u8 *srcEnd) {
void *dest = NULL;
#ifdef GZIP
u32 compSize = (srcEnd - 4 - srcStart);
#else
@@ -423,14 +433,15 @@ void *load_segment_decompress(s32 segment, u8 *srcStart, u8 *srcEnd) {
main_pool_free(compressed);
}
}
#if PUPPYPRINT_DEBUG
ramsizeSegment[segment+nameTable-2] = (s32)srcEnd - (s32)srcStart;
#endif
#if PUPPYPRINT_DEBUG
ramsizeSegment[(segment + nameTable) - 2] = (s32)srcEnd - (s32)srcStart;
#endif
return dest;
}
void *load_segment_decompress_heap(u32 segment, u8 *srcStart, u8 *srcEnd) {
// UNUSED void *dest = NULL;
UNUSED void *dest = NULL;
#ifdef GZIP
u32 compSize = (srcEnd - 4 - srcStart);
#else
@@ -467,7 +478,7 @@ void *load_segment_decompress_heap(u32 segment, u8 *srcStart, u8 *srcEnd) {
void load_engine_code_segment(void) {
void *startAddr = (void *) _engineSegmentStart;
u32 totalSize = _engineSegmentEnd - _engineSegmentStart;
UNUSED u32 alignedSize = ALIGN16(_engineSegmentRomEnd - _engineSegmentRomStart);
// UNUSED u32 alignedSize = ALIGN16(_engineSegmentRomEnd - _engineSegmentRomStart);
bzero(startAddr, totalSize);
osWritebackDCacheAll();
@@ -630,7 +641,7 @@ void *alloc_display_list(u32 size) {
void *ptr = NULL;
size = ALIGN8(size);
if ((gGfxPoolEnd - size) >= (u8 *) gDisplayListHead) {
if (gGfxPoolEnd - size >= (u8 *) gDisplayListHead) {
gGfxPoolEnd -= size;
ptr = gGfxPoolEnd;
}
@@ -658,7 +669,6 @@ void setup_dma_table_list(struct DmaHandlerList *list, void *srcAddr, void *buff
}
s32 load_patchable_table(struct DmaHandlerList *list, s32 index) {
s32 ret = FALSE;
struct DmaTable *table = list->dmaTable;
if ((u32)index < table->count) {
@@ -668,8 +678,8 @@ s32 load_patchable_table(struct DmaHandlerList *list, s32 index) {
if (list->currentAddr != addr) {
dma_read(list->bufTarget, addr, addr + size);
list->currentAddr = addr;
ret = TRUE;
return TRUE;
}
}
return ret;
return FALSE;
}
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef SLIDEC_H
#define SLIDEC_H
void slidstart(unsigned char*, unsigned char *);
void slidstart(unsigned char *compress, unsigned char *decompress);
void decompress(void *mio0, void *dest);
+1 -1
View File
@@ -3,7 +3,7 @@
* Programmed By Melody-Yoshi *
******************************/
/* How to use this function.
void slidstart(unsigned char *,unsigned char *);
void slidstart(unsigned char *compress, unsigned char *decompress);
first argument is top address of compress data.(align 4)
next argument is top address of decompress.
*/
+5 -5
View File
@@ -1,10 +1,10 @@
/*
/*
* N64-HVQM2 library Sample program
*
*
* FILE : adpcmbuf.c
*
*
* Copyright (C) 1998,1999 NINTENDO Co.,Ltd.
*
*
*/
/* 1999-02-22 */
@@ -16,7 +16,7 @@
/*
* Buffer for audio records (ADPCM data) read from the HVQM2 data.
* (Note) Please locate at a 16byte aligned address with the spec file.
* (Note) Please locate at a 16byte aligned address with the spec file.
*/
ALIGNED16 u8 adpcmbuf[AUDIO_RECORD_SIZE_MAX];
+1 -1
View File
@@ -10,7 +10,7 @@
#include "audio/synthesis.h"
ALIGNED8 u8 gDecompressionHeap[0xD000];
ALIGNED16 u8 gAudioHeap[(DOUBLE_SIZE_ON_64_BIT(AUDIO_HEAP_SIZE + 0x100))];
ALIGNED16 u8 gAudioHeap[DOUBLE_SIZE_ON_64_BIT(AUDIO_HEAP_SIZE)];
ALIGNED8 u8 gIdleThreadStack[0x800];
ALIGNED8 u8 gThread3Stack[0x2000];
+2 -1
View File
@@ -1,6 +1,7 @@
#include <ultra64.h>
#include "config.h"
#include "framebuffers.h"
// 0x70800 bytes
u16 gFrameBuffers[3][SCREEN_WIDTH * SCREEN_HEIGHT];
RGBA16 gFramebuffers[3][SCREEN_WIDTH * SCREEN_HEIGHT];
+5 -4
View File
@@ -4,13 +4,14 @@
#include <PR/ultratypes.h>
#include "config.h"
#include "types.h"
// level_script.c assumes that the frame buffers are adjacent, while game.c's
// -g codegen implies that they are separate variables. This is impossible to
// reconcile without undefined behavior. Avoid that when possible.
extern u16 gFrameBuffers[3][SCREEN_WIDTH * SCREEN_HEIGHT];
#define gFrameBuffer0 gFrameBuffers[0]
#define gFrameBuffer1 gFrameBuffers[1]
#define gFrameBuffer2 gFrameBuffers[2]
extern RGBA16 gFramebuffers[3][SCREEN_WIDTH * SCREEN_HEIGHT];
#define gFramebuffer0 gFramebuffers[0]
#define gFramebuffer1 gFramebuffers[1]
#define gFramebuffer2 gFramebuffers[2]
#endif // FRAMEBUFFERS_H
+5 -5
View File
@@ -1,10 +1,10 @@
/*
/*
* N64-HVQM2 library Sample program
*
*
* FILE : hvqbuf.c
*
*
* Copyright (C) 1998,1999 NINTENDO Co.,Ltd.
*
*
*/
/* 1999-02-22 */
@@ -15,7 +15,7 @@
#include <hvqm/hvqm.h>
/*
* Buffer for video records (HVQM2 compressed data) read from
* Buffer for video records (HVQM2 compressed data) read from
* the HVQM2 data.
* (Note) Please locate at a 16byte aligned address with the spec file.
*/
+4 -4
View File
@@ -1,10 +1,10 @@
/*
/*
* N64-HVQM2 library Sample program
*
*
* FILE : hvqmwork.c
*
*
* Copyright (C) 1998,1999 NINTENDO Co.,Ltd.
*
*
*/
/* 1999-02-12 */
+135 -225
View File
@@ -30,58 +30,12 @@
#define BHV_CMD_GET_ADDR_OF_CMD(index) (uintptr_t)(&gCurBhvCommand[index])
static u16 gRandomSeed16;
// Unused function that directly jumps to a behavior command and resets the object's stack index.
UNUSED static void goto_behavior_unused(const BehaviorScript *bhvAddr) {
gCurBhvCommand = segmented_to_virtual(bhvAddr);
gCurrentObject->bhvStackIndex = 0;
}
// Generate a pseudorandom integer from 0 to 65535 from the random seed, and update the seed.
u16 random_u16(void) {
u16 temp1, temp2;
if (gRandomSeed16 == 22026) {
gRandomSeed16 = 0;
}
temp1 = (gRandomSeed16 & 0x00FF) << 8;
temp1 = temp1 ^ gRandomSeed16;
gRandomSeed16 = ((temp1 & 0x00FF) << 8) + ((temp1 & 0xFF00) >> 8);
temp1 = ((temp1 & 0x00FF) << 1) ^ gRandomSeed16;
temp2 = (temp1 >> 1) ^ 0xFF80;
if ((temp1 & 1) == 0) {
if (temp2 == 43605) {
gRandomSeed16 = 0;
} else {
gRandomSeed16 = temp2 ^ 0x1FF4;
}
} else {
gRandomSeed16 = temp2 ^ 0x8180;
}
return gRandomSeed16;
}
// Generate a pseudorandom float in the range [0, 1).
f32 random_float(void) {
f32 rnd = random_u16();
return rnd / (double) 0x10000;
}
// Return either -1 or 1 with a 50:50 chance.
s32 random_sign(void) {
if (random_u16() >= 0x7FFF) {
return 1;
} else {
return -1;
}
}
// Update an object's graphical position and rotation to match its real position and rotation.
void obj_update_gfx_pos_and_angle(struct Object *obj) {
vec3_copy_y_off(obj->header.gfx.pos, &obj->oPosVec, obj->oGraphYOffset);
@@ -91,43 +45,31 @@ void obj_update_gfx_pos_and_angle(struct Object *obj) {
}
#ifdef OBJ_OPACITY_BY_CAM_DIST
#define OBJ_OPACITY_NEAR 128.0f
#define OBJ_OPACITY_LENGTH 512.0f
void obj_set_opacity_from_cam_dist(struct Object *obj) {
f32 dist; //! Should this be done via LOD's instead?
Vec3f d;
if (obj->header.gfx.node.flags & GRAPH_RENDER_BILLBOARD) {
d[0] = (obj->oPosX - gCamera->pos[0]);
d[2] = (obj->oPosZ - gCamera->pos[2]);
dist = (sqr(d[0]) + sqr(d[2]));
} else {
vec3_diff(d, &obj->oPosVec, gCamera->pos);
dist = (sqr(d[0]) + sqr(d[1]) + sqr(d[2]));
s32 opacityDist = ((-obj->header.gfx.cameraToObject[2] - OBJ_OPACITY_NEAR) * (256.0f / OBJ_OPACITY_LENGTH));
#ifdef OBJECTS_REJ
if (opacityDist > 0) {
obj->header.gfx.ucode = GRAPH_NODE_UCODE_REJ;
}
if (dist > 0.0f) {
obj->header.gfx.node.flags &= ~GRAPH_RENDER_UCODE_REJ;
}
#ifdef PUPPYCAM
s32 opacityDist = ((gPuppyCam.zoom > 0) ? ((dist / sqr(gPuppyCam.zoom)) * 255.0f) : 255);
#else
s32 opacityDist = (dist * (255.0f / sqr(1024.0f)));
#endif
obj->oOpacity = CLAMP(opacityDist, 0x00, 0xFF);
}
#undef OBJ_OPACITY_NEAR
#undef OBJ_OPACITY_LENGTH
#endif
// Push the address of a behavior command to the object's behavior stack.
static void cur_obj_bhv_stack_push(uintptr_t bhvAddr) {
gCurrentObject->bhvStack[gCurrentObject->bhvStackIndex] = bhvAddr;
gCurrentObject->bhvStackIndex++;
o->bhvStack[o->bhvStackIndex] = bhvAddr;
o->bhvStackIndex++;
}
// Retrieve the last behavior command address from the object's behavior stack.
static uintptr_t cur_obj_bhv_stack_pop(void) {
uintptr_t bhvAddr;
gCurrentObject->bhvStackIndex--;
bhvAddr = gCurrentObject->bhvStack[gCurrentObject->bhvStackIndex];
return bhvAddr;
o->bhvStackIndex--;
return o->bhvStack[o->bhvStackIndex];
}
// Command 0x22: Hides the current object.
@@ -160,7 +102,7 @@ static s32 bhv_cmd_billboard(void) {
// Command 0x1B: Sets the current model ID of the object.
// Usage: SET_MODEL(modelID)
static s32 bhv_cmd_set_model(void) {
s32 modelID = BHV_CMD_GET_2ND_S16(0);
ModelID32 modelID = BHV_CMD_GET_2ND_S16(0);
gCurrentObject->header.gfx.sharedChild = gLoadedGraphNodes[modelID];
@@ -171,7 +113,7 @@ static s32 bhv_cmd_set_model(void) {
// Command 0x1C: Spawns a child object with the specified model and behavior.
// Usage: SPAWN_CHILD(modelID, behavior)
static s32 bhv_cmd_spawn_child(void) {
u32 model = BHV_CMD_GET_U32(1);
ModelID32 model = BHV_CMD_GET_U32(1);
const BehaviorScript *behavior = BHV_CMD_GET_VPTR(2);
struct Object *child = spawn_object_at_origin(gCurrentObject, 0, model, behavior);
@@ -184,7 +126,7 @@ static s32 bhv_cmd_spawn_child(void) {
// Command 0x2C: Spawns a new object with the specified model and behavior.
// Usage: SPAWN_OBJ(modelID, behavior)
static s32 bhv_cmd_spawn_obj(void) {
u32 model = BHV_CMD_GET_U32(1);
ModelID32 model = BHV_CMD_GET_U32(1);
const BehaviorScript *behavior = BHV_CMD_GET_VPTR(2);
struct Object *object = spawn_object_at_origin(gCurrentObject, 0, model, behavior);
@@ -200,7 +142,7 @@ static s32 bhv_cmd_spawn_obj(void) {
// Usage: SPAWN_CHILD_WITH_PARAM(bhvParam, modelID, behavior)
static s32 bhv_cmd_spawn_child_with_param(void) {
u32 bhvParam = BHV_CMD_GET_2ND_S16(0);
u32 modelID = BHV_CMD_GET_U32(1);
ModelID32 modelID = BHV_CMD_GET_U32(1);
const BehaviorScript *behavior = BHV_CMD_GET_VPTR(2);
struct Object *child = spawn_object_at_origin(gCurrentObject, 0, modelID, behavior);
@@ -317,8 +259,7 @@ static s32 bhv_cmd_begin_repeat(void) {
// Command 0x06: Marks the end of a repeating loop.
// Usage: END_REPEAT()
static s32 bhv_cmd_end_repeat(void) {
u32 count = cur_obj_bhv_stack_pop(); // Retrieve loop count from the stack.
count--;
u32 count = cur_obj_bhv_stack_pop() - 1; // Retrieve loop count from the stack.
if (count != 0) {
gCurBhvCommand = (const BehaviorScript *) cur_obj_bhv_stack_pop(); // Jump back to the first command in the loop
@@ -337,8 +278,7 @@ static s32 bhv_cmd_end_repeat(void) {
// Command 0x07: Also marks the end of a repeating loop, but continues executing commands following the loop on the same frame.
// Usage: END_REPEAT_CONTINUE()
static s32 bhv_cmd_end_repeat_continue(void) {
u32 count = cur_obj_bhv_stack_pop();
count--;
u32 count = cur_obj_bhv_stack_pop() - 1;
if (count != 0) {
gCurBhvCommand = (const BehaviorScript *) cur_obj_bhv_stack_pop(); // Jump back to the first command in the loop
@@ -562,11 +502,7 @@ static s32 bhv_cmd_animate(void) {
// Command 0x1E: Finds the floor triangle directly under the object and moves the object down to it.
// Usage: DROP_TO_FLOOR()
static s32 bhv_cmd_drop_to_floor(void) {
f32 x = gCurrentObject->oPosX;
f32 y = gCurrentObject->oPosY;
f32 z = gCurrentObject->oPosZ;
f32 floor = find_floor_height(x, y + 200.0f, z);
f32 floor = find_floor_height(gCurrentObject->oPosX, gCurrentObject->oPosY + 200.0f, gCurrentObject->oPosZ);
gCurrentObject->oPosY = floor;
gCurrentObject->oMoveFlags |= OBJ_MOVE_ON_GROUND;
@@ -682,48 +618,14 @@ static s32 bhv_cmd_nop_4(void) {
// Has some special behavior for certain objects.
// Usage: BEGIN(objList)
static s32 bhv_cmd_begin(void) {
// These objects were likely very early objects, which is why this code is here
// instead of in the respective behavior scripts.
// Initiate the room if the object is a haunted chair or the mad piano.
if (cur_obj_has_behavior(bhvHauntedChair)) {
bhv_init_room();
}
if (cur_obj_has_behavior(bhvMadPiano)) {
bhv_init_room();
}
// Set collision distance if the object is a message panel.
if (cur_obj_has_behavior(bhvMessagePanel)) {
gCurrentObject->oCollisionDistance = 150.0f;
}
gCurBhvCommand++;
return BHV_PROC_CONTINUE;
}
// An unused, incomplete behavior command that does not have an entry in the lookup table, and so no command number.
// 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.
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;
// This for loop would not work as intended at all...
for (i = 0; i <= tableSize / 2; i += 2) {
table[i] = BHV_CMD_GET_1ST_S16(i + 1);
table[i + 1] = BHV_CMD_GET_2ND_S16(i + 1);
}
cur_obj_set_int(field, table[(s32)(tableSize * random_float())]);
// Does not increment gCurBhvCommand or return a bhv status
}
/**
// Command 0x??: Sets the specified field to a random entry in the given table, up to size 16.
// Bytes: ?? FF SS SS V1 V1 V2 V2 V3 V3 V4 V4... ...V15 V15 V16 V16 (no macro exists)
// F -> field, S -> table size, V1, V2, etc. -> table entries (up to 16)
static s32 bhv_cmd_set_int_random_from_table(void) {
UNUSED static s32 bhv_cmd_set_int_random_from_table(void) {
u8 field = BHV_CMD_GET_2ND_U8(0);
// Retrieve tableSize from the bhv command instead of as a parameter.
s16 tableSize = BHV_CMD_GET_2ND_S16(0); // tableSize should not be greater than 16
@@ -732,7 +634,7 @@ static s32 bhv_cmd_set_int_random_from_table(void) {
// Construct the table from the behavior command.
for (i = 0; i <= tableSize; i += 2) {
table[i] = BHV_CMD_GET_1ST_S16((i / 2) + 1);
table[i + 0] = BHV_CMD_GET_1ST_S16((i / 2) + 1);
table[i + 1] = BHV_CMD_GET_2ND_S16((i / 2) + 1);
}
@@ -742,7 +644,6 @@ static s32 bhv_cmd_set_int_random_from_table(void) {
gCurBhvCommand += (tableSize / 2) + 1;
return BHV_PROC_CONTINUE;
}
**/
// Command 0x2A: Loads collision data for the object.
// Usage: LOAD_COLLISION_DATA(collisionData)
@@ -758,9 +659,7 @@ static s32 bhv_cmd_load_collision_data(void) {
// Command 0x2D: Sets the home position of the object to its current position.
// Usage: SET_HOME()
static s32 bhv_cmd_set_home(void) {
gCurrentObject->oHomeX = gCurrentObject->oPosX;
gCurrentObject->oHomeY = gCurrentObject->oPosY;
gCurrentObject->oHomeZ = gCurrentObject->oPosZ;
vec3f_copy(&o->oHomeVec, &o->oPosVec);
gCurBhvCommand++;
return BHV_PROC_CONTINUE;
@@ -821,7 +720,7 @@ static s32 bhv_cmd_parent_bit_clear(void) {
u8 field = BHV_CMD_GET_2ND_U8(0);
s32 value = BHV_CMD_GET_U32(1);
value = value ^ 0xFFFFFFFF;
value ^= 0xFFFFFFFF;
obj_and_int(gCurrentObject->parentObj, field, value);
gCurBhvCommand += 2;
@@ -856,121 +755,122 @@ static s32 bhv_cmd_animate_texture(void) {
typedef s32 (*BhvCommandProc)(void);
static BhvCommandProc BehaviorCmdTable[] = {
bhv_cmd_begin,
bhv_cmd_delay,
bhv_cmd_call,
bhv_cmd_return,
bhv_cmd_goto,
bhv_cmd_begin_repeat,
bhv_cmd_end_repeat,
bhv_cmd_end_repeat_continue,
bhv_cmd_begin_loop,
bhv_cmd_end_loop,
bhv_cmd_break,
bhv_cmd_break_unused,
bhv_cmd_call_native,
bhv_cmd_add_float,
bhv_cmd_set_float,
bhv_cmd_add_int,
bhv_cmd_set_int,
bhv_cmd_or_int,
bhv_cmd_bit_clear,
bhv_cmd_set_int_rand_rshift,
bhv_cmd_set_random_float,
bhv_cmd_set_random_int,
bhv_cmd_add_random_float,
bhv_cmd_add_int_rand_rshift,
bhv_cmd_nop_1,
bhv_cmd_nop_2,
bhv_cmd_nop_3,
bhv_cmd_set_model,
bhv_cmd_spawn_child,
bhv_cmd_deactivate,
bhv_cmd_drop_to_floor,
bhv_cmd_sum_float,
bhv_cmd_sum_int,
bhv_cmd_billboard,
bhv_cmd_hide,
bhv_cmd_set_hitbox,
bhv_cmd_nop_4,
bhv_cmd_delay_var,
bhv_cmd_begin_repeat_unused,
bhv_cmd_load_animations,
bhv_cmd_animate,
bhv_cmd_spawn_child_with_param,
bhv_cmd_load_collision_data,
bhv_cmd_set_hitbox_with_offset,
bhv_cmd_spawn_obj,
bhv_cmd_set_home,
bhv_cmd_set_hurtbox,
bhv_cmd_set_interact_type,
bhv_cmd_set_obj_physics,
bhv_cmd_set_interact_subtype,
bhv_cmd_scale,
bhv_cmd_parent_bit_clear,
bhv_cmd_animate_texture,
bhv_cmd_disable_rendering,
bhv_cmd_set_int_unused,
bhv_cmd_spawn_water_droplet,
/*BHV_CMD_BEGIN */ bhv_cmd_begin,
/*BHV_CMD_DELAY */ bhv_cmd_delay,
/*BHV_CMD_CALL */ bhv_cmd_call,
/*BHV_CMD_RETURN */ bhv_cmd_return,
/*BHV_CMD_GOTO */ bhv_cmd_goto,
/*BHV_CMD_BEGIN_REPEAT */ bhv_cmd_begin_repeat,
/*BHV_CMD_END_REPEAT */ bhv_cmd_end_repeat,
/*BHV_CMD_END_REPEAT_CONTINUE */ bhv_cmd_end_repeat_continue,
/*BHV_CMD_BEGIN_LOOP */ bhv_cmd_begin_loop,
/*BHV_CMD_END_LOOP */ bhv_cmd_end_loop,
/*BHV_CMD_BREAK */ bhv_cmd_break,
/*BHV_CMD_BREAK_UNUSED */ bhv_cmd_break_unused,
/*BHV_CMD_CALL_NATIVE */ bhv_cmd_call_native,
/*BHV_CMD_ADD_FLOAT */ bhv_cmd_add_float,
/*BHV_CMD_SET_FLOAT */ bhv_cmd_set_float,
/*BHV_CMD_ADD_INT */ bhv_cmd_add_int,
/*BHV_CMD_SET_INT */ bhv_cmd_set_int,
/*BHV_CMD_OR_INT */ bhv_cmd_or_int,
/*BHV_CMD_BIT_CLEAR */ bhv_cmd_bit_clear,
/*BHV_CMD_SET_INT_RAND_RSHIFT */ bhv_cmd_set_int_rand_rshift,
/*BHV_CMD_SET_RANDOM_FLOAT */ bhv_cmd_set_random_float,
/*BHV_CMD_SET_RANDOM_INT */ bhv_cmd_set_random_int,
/*BHV_CMD_ADD_RANDOM_FLOAT */ bhv_cmd_add_random_float,
/*BHV_CMD_ADD_INT_RAND_RSHIFT */ bhv_cmd_add_int_rand_rshift,
/*BHV_CMD_NOP_1 */ bhv_cmd_nop_1,
/*BHV_CMD_NOP_2 */ bhv_cmd_nop_2,
/*BHV_CMD_NOP_3 */ bhv_cmd_nop_3,
/*BHV_CMD_SET_MODEL */ bhv_cmd_set_model,
/*BHV_CMD_SPAWN_CHILD */ bhv_cmd_spawn_child,
/*BHV_CMD_DEACTIVATE */ bhv_cmd_deactivate,
/*BHV_CMD_DROP_TO_FLOOR */ bhv_cmd_drop_to_floor,
/*BHV_CMD_SUM_FLOAT */ bhv_cmd_sum_float,
/*BHV_CMD_SUM_INT */ bhv_cmd_sum_int,
/*BHV_CMD_BILLBOARD */ bhv_cmd_billboard,
/*BHV_CMD_HIDE */ bhv_cmd_hide,
/*BHV_CMD_SET_HITBOX */ bhv_cmd_set_hitbox,
/*BHV_CMD_NOP_4 */ bhv_cmd_nop_4,
/*BHV_CMD_DELAY_VAR */ bhv_cmd_delay_var,
/*BHV_CMD_BEGIN_REPEAT_UNUSED */ bhv_cmd_begin_repeat_unused,
/*BHV_CMD_LOAD_ANIMATIONS */ bhv_cmd_load_animations,
/*BHV_CMD_ANIMATE */ bhv_cmd_animate,
/*BHV_CMD_SPAWN_CHILD_WITH_PA */ bhv_cmd_spawn_child_with_param,
/*BHV_CMD_LOAD_COLLISION_DATA */ bhv_cmd_load_collision_data,
/*BHV_CMD_SET_HITBOX_WITH_OFF */ bhv_cmd_set_hitbox_with_offset,
/*BHV_CMD_SPAWN_OBJ */ bhv_cmd_spawn_obj,
/*BHV_CMD_SET_HOME */ bhv_cmd_set_home,
/*BHV_CMD_SET_HURTBOX */ bhv_cmd_set_hurtbox,
/*BHV_CMD_SET_INTERACT_TYPE */ bhv_cmd_set_interact_type,
/*BHV_CMD_SET_OBJ_PHYSICS */ bhv_cmd_set_obj_physics,
/*BHV_CMD_SET_INTERACT_SUBTYPE */ bhv_cmd_set_interact_subtype,
/*BHV_CMD_SCALE */ bhv_cmd_scale,
/*BHV_CMD_PARENT_BIT_CLEAR */ bhv_cmd_parent_bit_clear,
/*BHV_CMD_ANIMATE_TEXTURE */ bhv_cmd_animate_texture,
/*BHV_CMD_DISABLE_RENDERING */ bhv_cmd_disable_rendering,
/*BHV_CMD_SET_INT_UNUSED */ bhv_cmd_set_int_unused,
/*BHV_CMD_SPAWN_WATER_DROPLET */ bhv_cmd_spawn_water_droplet,
};
// Execute the behavior script of the current object, process the object flags, and other miscellaneous code for updating objects.
void cur_obj_update(void) {
u32 objFlags = gCurrentObject->oFlags;
u32 objFlags = o->oFlags;
f32 distanceFromMario;
BhvCommandProc bhvCmdProc;
s32 bhvProcResult;
s32 objListIndex = OBJ_LIST_PLAYER;
// Calculate the distance from the object to Mario.
if (objFlags & OBJ_FLAG_COMPUTE_DIST_TO_MARIO) {
gCurrentObject->oDistanceToMario = dist_between_objects(gCurrentObject, gMarioObject);
distanceFromMario = gCurrentObject->oDistanceToMario;
o->oDistanceToMario = dist_between_objects(o, gMarioObject);
distanceFromMario = o->oDistanceToMario;
} else {
distanceFromMario = 0.0f;
}
// Calculate the angle from the object to Mario.
if (objFlags & OBJ_FLAG_COMPUTE_ANGLE_TO_MARIO) {
gCurrentObject->oAngleToMario = obj_angle_to_object(gCurrentObject, gMarioObject);
o->oAngleToMario = obj_angle_to_object(o, gMarioObject);
}
// If the object's action has changed, reset the action timer.
if (gCurrentObject->oAction != gCurrentObject->oPrevAction) {
(void) (gCurrentObject->oTimer = 0, gCurrentObject->oSubAction = 0,
gCurrentObject->oPrevAction = gCurrentObject->oAction);
if (o->oAction != o->oPrevAction) {
o->oTimer = 0;
o->oSubAction = 0;
o->oPrevAction = o->oAction;
}
// Execute the behavior script.
gCurBhvCommand = gCurrentObject->curBhvCommand;
gCurBhvCommand = o->curBhvCommand;
do {
bhvCmdProc = BehaviorCmdTable[*gCurBhvCommand >> 24];
bhvProcResult = bhvCmdProc();
} while (bhvProcResult == BHV_PROC_CONTINUE);
gCurrentObject->curBhvCommand = gCurBhvCommand;
o->curBhvCommand = gCurBhvCommand;
// Increment the object's timer.
if (gCurrentObject->oTimer < 0x3FFFFFFF) {
gCurrentObject->oTimer++;
if (o->oTimer < 0x3FFFFFFF) {
o->oTimer++;
}
// If the object's action has changed, reset the action timer.
if (gCurrentObject->oAction != gCurrentObject->oPrevAction) {
(void) (gCurrentObject->oTimer = 0, gCurrentObject->oSubAction = 0,
gCurrentObject->oPrevAction = gCurrentObject->oAction);
if (o->oAction != o->oPrevAction) {
o->oTimer = 0;
o->oSubAction = 0;
o->oPrevAction = o->oAction;
}
// Execute various code based on object flags.
objFlags = gCurrentObject->oFlags;
objFlags = o->oFlags;
if (objFlags & OBJ_FLAG_SET_FACE_ANGLE_TO_MOVE_ANGLE) {
obj_set_face_angle_to_move_angle(gCurrentObject);
vec3i_copy(&o->oFaceAngleVec, &o->oMoveAngleVec);
}
if (objFlags & OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW) {
gCurrentObject->oFaceAngleYaw = gCurrentObject->oMoveAngleYaw;
o->oFaceAngleYaw = o->oMoveAngleYaw;
}
if (objFlags & OBJ_FLAG_MOVE_XZ_USING_FVEL) {
@@ -982,55 +882,65 @@ void cur_obj_update(void) {
}
if (objFlags & OBJ_FLAG_TRANSFORM_RELATIVE_TO_PARENT) {
obj_build_transform_relative_to_parent(gCurrentObject);
obj_build_transform_relative_to_parent(o);
}
if (objFlags & OBJ_FLAG_SET_THROW_MATRIX_FROM_TRANSFORM) {
obj_set_throw_matrix_from_transform(gCurrentObject);
obj_set_throw_matrix_from_transform(o);
}
if (objFlags & OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE) {
obj_update_gfx_pos_and_angle(gCurrentObject);
obj_update_gfx_pos_and_angle(o);
}
COND_BIT((!(objFlags & OBJ_FLAG_UCODE_LARGE )), gCurrentObject->header.gfx.node.flags, GRAPH_RENDER_UCODE_REJ );
COND_BIT(( objFlags & OBJ_FLAG_SILHOUETTE ), gCurrentObject->header.gfx.node.flags, GRAPH_RENDER_SILHOUETTE );
COND_BIT(( objFlags & OBJ_FLAG_OCCLUDE_SILHOUETTE ), gCurrentObject->header.gfx.node.flags, GRAPH_RENDER_OCCLUDE_SILHOUETTE);
BehaviorScript *bhvScript = segmented_to_virtual(gCurrentObject->behavior);
#if SILHOUETTE
COND_BIT(( objFlags & OBJ_FLAG_SILHOUETTE ), o->header.gfx.node.flags, GRAPH_RENDER_SILHOUETTE );
COND_BIT(( objFlags & OBJ_FLAG_OCCLUDE_SILHOUETTE ), o->header.gfx.node.flags, GRAPH_RENDER_OCCLUDE_SILHOUETTE);
#endif
#ifdef OBJECTS_REJ
s32 objListIndex = OBJ_LIST_PLAYER;
BehaviorScript *bhvScript = segmented_to_virtual(o->behavior);
if ((bhvScript[0] >> 24) == 0) {
objListIndex = (bhvScript[0] >> 16) & 0xFFFF;
}
if (objListIndex == OBJ_LIST_SURFACE && !(objFlags & OBJ_FLAG_UCODE_SMALL)) {
gCurrentObject->header.gfx.node.flags &= ~GRAPH_RENDER_UCODE_REJ;
gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_UCODE_ZEX;
objListIndex = ((bhvScript[0] >> 16) & 0xFFFF);
}
if (objFlags & OBJ_FLAG_UCODE_SMALL) {
o->header.gfx.ucode = GRAPH_NODE_UCODE_REJ;
}
else {
o->header.gfx.ucode = GRAPH_NODE_UCODE_DEFAULT;
}
#endif
#ifdef OBJ_OPACITY_BY_CAM_DIST
if (objFlags & OBJ_FLAG_OPACITY_FROM_CAMERA_DIST) {
obj_set_opacity_from_cam_dist(gCurrentObject);
obj_set_opacity_from_cam_dist(o);
}
#endif
#ifdef PUPPYLIGHTS
puppylights_object_emit(gCurrentObject);
puppylights_object_emit(o);
#endif
// Handle visibility of object
if (gCurrentObject->oRoom != -1) {
if (o->oRoom != -1) {
// If the object is in a room, only show it when Mario is in the room.
cur_obj_enable_rendering_if_mario_in_room();
} else if ((objFlags & OBJ_FLAG_COMPUTE_DIST_TO_MARIO) && gCurrentObject->collisionData == NULL) {
if (!(objFlags & OBJ_FLAG_ACTIVE_FROM_AFAR)) {
// If the object has a render distance, check if it should be shown.
if (distanceFromMario > gCurrentObject->oDrawingDistance) {
// Out of render distance, hide the object.
gCurrentObject->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
gCurrentObject->activeFlags |= ACTIVE_FLAG_FAR_AWAY;
} else if (gCurrentObject->oHeldState == HELD_FREE) {
// In render distance (and not being held), show the object.
gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE;
gCurrentObject->activeFlags &= ~ACTIVE_FLAG_FAR_AWAY;
}
} else if (
o->collisionData == NULL
&& (objFlags & OBJ_FLAG_COMPUTE_DIST_TO_MARIO)
&& !(objFlags & OBJ_FLAG_ACTIVE_FROM_AFAR)
) {
// If the object has a render distance, check if it should be shown.
if (distanceFromMario > o->oDrawingDistance) {
// Out of render distance, hide the object.
o->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE;
o->activeFlags |= ACTIVE_FLAG_FAR_AWAY;
} else if (o->oHeldState == HELD_FREE) {
// In render distance (and not being held), show the object.
o->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE;
o->activeFlags &= ~ACTIVE_FLAG_FAR_AWAY;
}
}
}
+4 -6
View File
@@ -3,8 +3,10 @@
#include <PR/ultratypes.h>
#define BHV_PROC_CONTINUE 0
#define BHV_PROC_BREAK 1
enum BhvProc {
BHV_PROC_CONTINUE,
BHV_PROC_BREAK
};
#define cur_obj_get_int(offset) gCurrentObject->OBJECT_FIELD_S32(offset)
#define cur_obj_get_float(offset) gCurrentObject->OBJECT_FIELD_F32(offset)
@@ -19,10 +21,6 @@
#define obj_and_int(object, offset, value) object->OBJECT_FIELD_S32(offset) &= (s32)(value)
u16 random_u16(void);
float random_float(void);
s32 random_sign(void);
void cur_obj_update(void);
#endif // BEHAVIOR_SCRIPT_H
+172
View File
@@ -0,0 +1,172 @@
// Functions for editing colors & textures (Arceveti)
#include <PR/ultratypes.h>
#include "math_util.h"
#include "colors.h"
// ColorRGB
void rgba16_to_colorRGB(ColorRGB dst, RGBA16 src) {
dst[0] = COMPOSITE_TO_COLOR(src, MSK_RGBA16_C, IDX_RGBA16_R);
dst[1] = COMPOSITE_TO_COLOR(src, MSK_RGBA16_C, IDX_RGBA16_G);
dst[2] = COMPOSITE_TO_COLOR(src, MSK_RGBA16_C, IDX_RGBA16_B);
}
void rgba16_to_colorRGBA(ColorRGBA dst, RGBA16 src) {
rgba16_to_colorRGB(dst, src);
dst[3] = COMPOSITE_TO_COLOR(src, MSK_RGBA16_A, IDX_RGBA16_A);
}
void rgba32_to_colorRGB(ColorRGBA dst, RGBA32 src) {
dst[0] = COMPOSITE_TO_COLOR(src, MSK_RGBA32_C, IDX_RGBA32_R);
dst[1] = COMPOSITE_TO_COLOR(src, MSK_RGBA32_C, IDX_RGBA32_G);
dst[2] = COMPOSITE_TO_COLOR(src, MSK_RGBA32_C, IDX_RGBA32_B);
}
void rgba32_to_colorRGBA(ColorRGBA dst, RGBA32 src) {
rgba32_to_colorRGB(dst, src);
dst[3] = COMPOSITE_TO_COLOR(src, MSK_RGBA32_A, IDX_RGBA32_A);
}
RGBA16Return32 colorRGB_to_rgba16(ColorRGB src) {
return (COLOR_TO_COMPOSITE(src[0], MSK_RGBA16_C, IDX_RGBA16_R)
| COLOR_TO_COMPOSITE(src[1], MSK_RGBA16_C, IDX_RGBA16_G)
| COLOR_TO_COMPOSITE(src[2], MSK_RGBA16_C, IDX_RGBA16_B)
| MSK_RGBA16_A);
}
RGBA16Return32 colorRGBA_to_rgba16(ColorRGBA src) {
return (COLOR_TO_COMPOSITE(src[0], MSK_RGBA16_C, IDX_RGBA16_R)
| COLOR_TO_COMPOSITE(src[1], MSK_RGBA16_C, IDX_RGBA16_G)
| COLOR_TO_COMPOSITE(src[2], MSK_RGBA16_C, IDX_RGBA16_B)
| COLOR_TO_COMPOSITE(src[2], MSK_RGBA16_A, IDX_RGBA16_A));
}
RGBA32 colorRGB_to_rgba32(ColorRGB src) {
return (COLOR_TO_COMPOSITE(src[0], MSK_RGBA32_C, IDX_RGBA32_R)
| COLOR_TO_COMPOSITE(src[1], MSK_RGBA32_C, IDX_RGBA32_G)
| COLOR_TO_COMPOSITE(src[2], MSK_RGBA32_C, IDX_RGBA32_B)
| MSK_RGBA32_A);
}
RGBA32 colorRGBA_to_rgba32(ColorRGBA src) {
return (COLOR_TO_COMPOSITE(src[0], MSK_RGBA32_C, IDX_RGBA32_R)
| COLOR_TO_COMPOSITE(src[1], MSK_RGBA32_C, IDX_RGBA32_G)
| COLOR_TO_COMPOSITE(src[2], MSK_RGBA32_C, IDX_RGBA32_B)
| COLOR_TO_COMPOSITE(src[2], MSK_RGBA32_A, IDX_RGBA32_A));
}
// ColorRGBf
void rgba16_to_colorRGBf(ColorRGBf dst, RGBA16 src) {
dst[0] = COMPOSITE_TO_COLORF(src, MSK_RGBA16_C, IDX_RGBA16_R);
dst[1] = COMPOSITE_TO_COLORF(src, MSK_RGBA16_C, IDX_RGBA16_G);
dst[2] = COMPOSITE_TO_COLORF(src, MSK_RGBA16_C, IDX_RGBA16_B);
}
void rgba16_to_colorRGBAf(ColorRGBAf dst, RGBA16 src) {
rgba16_to_colorRGBf(dst, src);
dst[3] = COMPOSITE_TO_COLORF(src, MSK_RGBA16_A, IDX_RGBA16_A);
}
void rgba32_to_colorRGBf(ColorRGBf dst, RGBA32 src) {
dst[0] = COMPOSITE_TO_COLORF(src, MSK_RGBA32_C, IDX_RGBA32_R);
dst[1] = COMPOSITE_TO_COLORF(src, MSK_RGBA32_C, IDX_RGBA32_G);
dst[2] = COMPOSITE_TO_COLORF(src, MSK_RGBA32_C, IDX_RGBA32_B);
}
void rgba32_to_colorRGBAf(ColorRGBAf dst, RGBA32 src) {
rgba32_to_colorRGBf(dst, src);
dst[3] = COMPOSITE_TO_COLORF(src, MSK_RGBA32_A, IDX_RGBA32_A);
}
void colorRGB_to_colorRGBf(ColorRGBf dst, ColorRGB src) { vec3_quot_val(dst, src, 255.0f); }
void colorRGBf_to_colorRGB(ColorRGB dst, ColorRGBf src) { vec3_prod_val(dst, src, 255.0f); }
RGBA16Return32 colorRGBf_to_rgba16(ColorRGBf src) {
return (COLORF_TO_COMPOSITE(src[0], MSK_RGBA16_C, IDX_RGBA16_R)
| COLORF_TO_COMPOSITE(src[1], MSK_RGBA16_C, IDX_RGBA16_G)
| COLORF_TO_COMPOSITE(src[2], MSK_RGBA16_C, IDX_RGBA16_B)
| MSK_RGBA16_A);
}
RGBA16Return32 colorRGBAf_to_rgba16(ColorRGBAf src) {
return (COLORF_TO_COMPOSITE(src[0], MSK_RGBA16_C, IDX_RGBA16_R)
| COLORF_TO_COMPOSITE(src[1], MSK_RGBA16_C, IDX_RGBA16_G)
| COLORF_TO_COMPOSITE(src[2], MSK_RGBA16_C, IDX_RGBA16_B)
| COLORF_TO_COMPOSITE(src[2], MSK_RGBA16_A, IDX_RGBA16_A));
}
RGBA32 colorRGBf_to_rgba32(ColorRGBf src) {
return (COLORF_TO_COMPOSITE(src[0], MSK_RGBA32_C, IDX_RGBA32_R)
| COLORF_TO_COMPOSITE(src[1], MSK_RGBA32_C, IDX_RGBA32_G)
| COLORF_TO_COMPOSITE(src[2], MSK_RGBA32_C, IDX_RGBA32_B)
| MSK_RGBA32_A);
}
RGBA32 colorRGBAf_to_rgba32(ColorRGBAf src) {
return (COLORF_TO_COMPOSITE(src[0], MSK_RGBA32_C, IDX_RGBA32_R)
| COLORF_TO_COMPOSITE(src[1], MSK_RGBA32_C, IDX_RGBA32_G)
| COLORF_TO_COMPOSITE(src[2], MSK_RGBA32_C, IDX_RGBA32_B)
| COLORF_TO_COMPOSITE(src[2], MSK_RGBA32_A, IDX_RGBA32_A));
}
Bool32 colorRGBA_average_2(ColorRGBA dst, ColorRGBA c1, ColorRGBA c2) {
if ((dst[3] = (c1[3] + c2[3])) > 0) {
s32 i;
for (i = 0; i < 3; i++) {
dst[i] = (((c1[i] * c1[3]) + (c2[i] * c2[3])) / dst[3]);
}
return TRUE;
}
return FALSE;
}
Bool32 colorRGBA_average_3(ColorRGBA dst, ColorRGBA c1, ColorRGBA c2, ColorRGBA c3) {
if ((dst[3] = (c1[3] + c2[3] + c3[3])) > 0) {
s32 i;
for (i = 0; i < 3; i++) {
dst[i] = (((c1[i] * c1[3]) + (c2[i] * c2[3]) + (c3[i] * c3[3])) / dst[3]);
}
return TRUE;
}
return FALSE;
}
RGBA16Return32 rgba16_make_grayscale(RGBA16 rgba) {
ColorRGBf color;
rgba16_to_colorRGBf(color, rgba);
ColorF avg = vec3_average(color);
vec3_same(color, avg);
return colorRGBf_to_rgba16(color);
}
void colorRGB_add_hue(ColorRGB color, Color hueAdd, Color s) {
f32 hue = 0.0f;
if ((color[0] < color[1]) || (color[0] < color[2])) {
if (color[1] < color[2]) {
hue = (4.0f + (color[0] - color[1]) / (f32)(color[2] - MIN(color[0], color[1]))); // blue
} else {
hue = (2.0f + (color[2] - color[0]) / (f32)(color[1] - MIN(color[0], color[2]))); // green
}
} else {
hue = (0.0f + (color[1] - color[2]) / (f32)(color[0] - MIN(color[1], color[2]))); // red
}
if (hue < 0.0f) hue += 6.0f;
// this is the algorithm to convert from RGB to HSV:
Color h = (((u8)((hue * (128.0f / 3.0f)) + hueAdd) >> 2) * 3); // needs to u8 cycle before multiplying. 0..191
Color i = (h >> 5); // 0..5
Color f = ((h & 0x1F) << 3); // 'fractional' part of 'i' 0..248 in jumps
Color pv = (0xFF - s ); // pv will be in range 0..255
Color qv = (0xFF - ((s * f ) >> 8));
Color tv = (0xFF - ((s * (0xFF - f)) >> 8));
switch (i) {
case 0: color[0] = 0xFF; color[1] = tv; color[2] = pv; break;
case 1: color[0] = qv; color[1] = 0xFF; color[2] = pv; break;
case 2: color[0] = pv; color[1] = 0xFF; color[2] = tv; break;
case 3: color[0] = pv; color[1] = qv; color[2] = 0xFF; break;
case 4: color[0] = tv; color[1] = pv; color[2] = 0xFF; break;
case 5: color[0] = 0xFF; color[1] = pv; color[2] = qv; break;
}
}
+137
View File
@@ -0,0 +1,137 @@
#pragma once
#include <PR/ultratypes.h>
#include <PR/gbi.h>
#include "types.h"
#include "math_util.h"
// I4
#define SIZ_I4 0x4
#define MSK_I4 BITMASK(SIZ_I4)
// I8
#define SIZ_I8 0x8
#define MSK_I8 BITMASK(SIZ_I8)
// IA4
#define SIZ_IA4_I 0x3
#define MSK_IA4_I BITMASK(SIZ_IA4_I)
#define IDX_IA4_I ((SIZ_IA4_I * 0) + 1)
#define IA4_I(c) (((c) >> IDX_IA4_I) & MSK_IA4_I)
#define I_IA4(c) (((c) & MSK_IA4_I) << IDX_IA4_I)
#define SIZ_IA4_A 0x1
#define MSK_IA4_A BITMASK(SIZ_IA4_A)
#define IDX_IA4_A ((SIZ_IA4_A * 0) + 0)
#define IA4_A(c) (((c) >> IDX_IA4_A) & MSK_IA4_A)
#define A_IA4(c) (((c) & MSK_IA4_A) << IDX_IA4_A)
// IA8
#define SIZ_IA8_C 0x4
#define MSK_IA8_C BITMASK(SIZ_IA8_C)
#define IDX_IA8_I ((SIZ_IA8_C * 1) + 0)
#define IDX_IA8_A ((SIZ_IA8_C * 0) + 0)
#define IA8_I(c) (((c) >> IDX_IA8_I) & MSK_IA8_C)
#define IA8_A(c) (((c) >> IDX_IA8_A) & MSK_IA8_C)
#define I_IA8(c) (((c) & MSK_IA8_C) << IDX_IA8_I)
#define A_IA8(c) (((c) & MSK_IA8_C) << IDX_IA8_A)
// IA16
#define SIZ_IA16_C 0x8
#define MSK_IA16_C BITMASK(SIZ_IA16_C)
#define IDX_IA16_I ((SIZ_IA16_C * 1) + 0)
#define IDX_IA16_A ((SIZ_IA16_C * 0) + 0)
#define IA16_I(c) (((c) >> IDX_IA16_I) & MSK_IA16_C)
#define IA16_A(c) (((c) >> IDX_IA16_A) & MSK_IA16_C)
#define I_IA16(c) (((c) & MSK_IA16_C) << IDX_IA16_I)
#define A_IA16(c) (((c) & MSK_IA16_C) << IDX_IA16_A)
// RGBA16
#define SIZ_RGBA16_C 0x5
#define MSK_RGBA16_C BITMASK(SIZ_RGBA16_C)
#define IDX_RGBA16_R ((SIZ_RGBA16_C * 2) + 1)
#define IDX_RGBA16_G ((SIZ_RGBA16_C * 1) + 1)
#define IDX_RGBA16_B ((SIZ_RGBA16_C * 0) + 1)
#define RGBA16_R(c) (((c) >> IDX_RGBA16_R) & MSK_RGBA16_C)
#define RGBA16_G(c) (((c) >> IDX_RGBA16_G) & MSK_RGBA16_C)
#define RGBA16_B(c) (((c) >> IDX_RGBA16_B) & MSK_RGBA16_C)
#define R_RGBA16(c) (((c) & MSK_RGBA16_C) << IDX_RGBA16_R)
#define G_RGBA16(c) (((c) & MSK_RGBA16_C) << IDX_RGBA16_G)
#define B_RGBA16(c) (((c) & MSK_RGBA16_C) << IDX_RGBA16_B)
#define SIZ_RGBA16_A 0x1
#define MSK_RGBA16_A BITMASK(SIZ_RGBA16_A)
#define IDX_RGBA16_A ((SIZ_RGBA16_A * 0) + 0)
#define RGBA16_A(c) (((c) >> IDX_RGBA16_A) & MSK_RGBA16_A)
#define A_RGBA16(c) (((c) & MSK_RGBA16_A) << IDX_RGBA16_A)
// RGBA32
#define SIZ_RGBA32_C 0x8
#define MSK_RGBA32_C BITMASK(SIZ_RGBA32_C)
#define IDX_RGBA32_R ((SIZ_RGBA32_C * 3) + 0)
#define IDX_RGBA32_G ((SIZ_RGBA32_C * 2) + 0)
#define IDX_RGBA32_B ((SIZ_RGBA32_C * 1) + 0)
#define IDX_RGBA32_A ((SIZ_RGBA32_C * 0) + 0)
#define RGBA32_R(c) (((c) >> IDX_RGBA32_R) & MSK_RGBA32_C)
#define RGBA32_G(c) (((c) >> IDX_RGBA32_G) & MSK_RGBA32_C)
#define RGBA32_B(c) (((c) >> IDX_RGBA32_B) & MSK_RGBA32_C)
#define RGBA32_A(c) (((c) >> IDX_RGBA32_A) & MSK_RGBA32_C)
#define R_RGBA32(c) (((c) & MSK_RGBA32_C) << IDX_RGBA32_R)
#define G_RGBA32(c) (((c) & MSK_RGBA32_C) << IDX_RGBA32_G)
#define B_RGBA32(c) (((c) & MSK_RGBA32_C) << IDX_RGBA32_B)
#define A_RGBA32(c) (((c) & MSK_RGBA32_A) << IDX_RGBA32_A)
#define SIZ_RGBA32_A SIZ_RGBA32_C
#define MSK_RGBA32_A MSK_RGBA32_C
// CI4
#define SIZ_CI4 0x4
#define MSK_CI4 BITMASK(SIZ_CI4)
// CI8
#define SIZ_CI8 0x8
#define MSK_CI8 BITMASK(SIZ_CI8)
// Direct format conversions:
#define I4_TO_RGBA16_C(c) (((c) << (SIZ_RGBA16_C - SIZ_I4)) & MSK_RGBA16_C)
#define I8_TO_RGBA16_C(c) (((c) >> (SIZ_I8 - SIZ_RGBA16_C)) & MSK_RGBA16_C)
#define RGBA16_COMPOSITE(r, g, b, a) (R_RGBA16(r) | G_RGBA16(g) | B_RGBA16(b) | A_RGBA16(a))
#define RGBA16_COMPOSITE_GRAYSCALE(val, alpha) RGBA16_COMPOSITE((val), (val), (val), (alpha))
#define COMPOSITE_TO_COLOR(src, bitmask, index) (((((src) >> (index)) & (bitmask)) * 255.0f) / (bitmask))
#define COLOR_TO_COMPOSITE(src, bitmask, index) (((CompositeColor)(((src) * (bitmask)) / 255.0f) & (bitmask)) << (index))
#define COMPOSITE_TO_COLORF(src, bitmask, index) ((ColorF)(((src) >> (index)) & (bitmask)) / (bitmask))
#define COLORF_TO_COMPOSITE(src, bitmask, index) (((CompositeColor)((src) * (bitmask)) & (bitmask)) << (index))
#define COLORRGB_TO_COLORRGBF( dst, src) vec3_quot_val((dst), (src), 255.0f)
#define COLORRGBF_TO_COLORRGB( dst, src) vec3_prod_val((dst), (src), 255.0f)
#define COLORRGBA_TO_COLORRGBAF(dst, src) vec4_quot_val((dst), (src), 255.0f)
#define COLORRGBAF_TO_COLORRGBA(dst, src) vec4_prod_val((dst), (src), 255.0f)
#define colorRGB_set( dst, r, g, b) vec3_set( (dst), (r), (g), (b))
#define colorRGB_copy( dst, src ) vec3_copy((dst), (src) )
#define colorRGB_to_vec3(dst, src ) vec3_copy((dst), (src) )
#define vec3_to_colorRGB(dst, src ) vec3_copy((dst), (src) )
#define RGBA32_TO_COLORRGB(dst, src) { \
(dst)[0] = RGBA32_R(src); \
(dst)[1] = RGBA32_G(src); \
(dst)[2] = RGBA32_B(src); \
}
#define RGBA32_TO_COLORRGBA(dst, src) { \
(dst)[0] = RGBA32_R(src); \
(dst)[1] = RGBA32_G(src); \
(dst)[2] = RGBA32_B(src); \
(dst)[3] = RGBA32_A(src); \
}
#define COLORRGB0_TO_RGBA32(src) (R_RGBA32((src)[0]) | G_RGBA32((src)[1]) | B_RGBA32((src)[2]))
#define COLORRGB1_TO_RGBA32(src) (R_RGBA32((src)[0]) | G_RGBA32((src)[1]) | B_RGBA32((src)[2]) | MSK_RGBA32_A))
#define COLORRGBA_TO_RGBA32(src) (R_RGBA32((src)[0]) | G_RGBA32((src)[1]) | B_RGBA32((src)[2]) | A_RGBA32((src)[3]))
#include "color_presets.h"
Bool32 colorRGBA_average_2(ColorRGBA dst, ColorRGBA c1, ColorRGBA c2);
Bool32 colorRGBA_average_3(ColorRGBA dst, ColorRGBA c1, ColorRGBA c2, ColorRGBA c3);
void colorRGB_add_hue(ColorRGB color, Color hueAdd, Color s);
-70
View File
@@ -1,70 +0,0 @@
#ifndef __EXTENDED_BOUNDS_H__
#define __EXTENDED_BOUNDS_H__
/*
Better Extended Bounds by anonymous_moose
Thanks to someone2639 for the shiftable segments patch
Thanks to Wiseguy for the Surface Pool Full error code and 4x bounds fix
0: Regular bounds
Same as vanilla sm64, boundaries are (-8192 to 8191)
16x16 collision cells.
1: 2x extended bounds
level boundaries are twice as big (-16384 to 16383)
Collision calculations remain as fast as vanilla, at the cost of using more RAM.
32x32 collision cells.
2: Regular bounds (performance)
Same boundaries as vanilla (-8192 to 8191), but with twice the amount of collision cells
Trades more RAM usage for faster collision calculations.
32x32 collision cells.
3: 4x extended bounds
level boundaries are 4 times as big (-32768 to 32767)
Collision calculations remain as fast as vanilla, at the cost of using far more RAM (16 times vanilla).
64x64 collision cells.
If you see "SURFACE POOL FULL" or "SURFACE NODE POOL FULL" in game, you should increase
SURFACE_POOL_SIZE or SURFACE_NODE_POOL_SIZE, respectively, or reduce the amount of
collision surfaces in your level.
*/
// For the static assert macro
#include "macros.h"
// Set this to the extended bounds mode you want, then do "make clean".
#define EXTENDED_BOUNDS_MODE 1
// Don't touch the stuff past this point unless you know what you're doing!
#if EXTENDED_BOUNDS_MODE == 0 // 1x, normal cell size
#define LEVEL_BOUNDARY_MAX 0x2000L // 8192
#define CELL_SIZE 0x400 // 1024, NUM_CELLS = 16
#elif EXTENDED_BOUNDS_MODE == 1 // 2x, normal cell size
#define LEVEL_BOUNDARY_MAX 0x4000L // 16384
#define CELL_SIZE 0x400 // 1024, NUM_CELLS = 32
#elif EXTENDED_BOUNDS_MODE == 2 // 1x, smaller cell size
#define LEVEL_BOUNDARY_MAX 0x2000L // 8192
#define CELL_SIZE 0x200 // 512, NUM_CELLS = 32
#elif EXTENDED_BOUNDS_MODE == 3 // 4x, normal cell size
#define LEVEL_BOUNDARY_MAX 0x8000L // 32768
#define CELL_SIZE 0x400 // 1024, NUM_CELLS = 64
#endif
STATIC_ASSERT((EXTENDED_BOUNDS_MODE >= 0 && EXTENDED_BOUNDS_MODE <= 3), "You must set a valid extended bounds mode!");
// The amount of cells in each axis in an area.
#define NUM_CELLS (2 * LEVEL_BOUNDARY_MAX / CELL_SIZE)
// The maximum amount of collision surfaces (static and dynamic combined)
#define SURFACE_POOL_SIZE (LEVEL_BOUNDARY_MAX / 2) // Vanilla: 2300. Modes: 0: 4096, 1: 8192, 2: 8192, 3: 16384
// How many SurfaceNodes can fit in Surface. This is done so that the maximum sizes for both can contain the same amount.
#define SURFACE_NODE_STRUCT_DIFF 3.5 // = (56 / 16) = (sizeof(struct Surface) / sizeof(struct SurfaceNode))
// The maximum amount of SurfaceNodes (static and dynamic combined)
#define SURFACE_NODE_POOL_SIZE (s32)(SURFACE_POOL_SIZE * SURFACE_NODE_STRUCT_DIFF) // Vanilla: 7000. Modes: 0: 14336, 1: 28672, 2: 28672, 3: 57344
// Flags for error messages
#define NOT_ENOUGH_ROOM_FOR_SURFACES (1 << 0)
#define NOT_ENOUGH_ROOM_FOR_NODES (1 << 1)
// Use this to convert game units to cell coordinates
#define GET_CELL_COORD(p) ((((p) + LEVEL_BOUNDARY_MAX) / CELL_SIZE) & (NUM_CELLS - 1));
#endif // __EXTENDED_BOUNDS_H__
+67 -79
View File
@@ -9,39 +9,40 @@
typedef void (*GeoLayoutCommandProc)(void);
GeoLayoutCommandProc GeoLayoutJumpTable[] = {
geo_layout_cmd_branch_and_link,
geo_layout_cmd_end,
geo_layout_cmd_branch,
geo_layout_cmd_return,
geo_layout_cmd_open_node,
geo_layout_cmd_close_node,
geo_layout_cmd_assign_as_view,
geo_layout_cmd_update_node_flags,
geo_layout_cmd_node_root,
geo_layout_cmd_node_ortho_projection,
geo_layout_cmd_node_perspective,
geo_layout_cmd_node_start,
geo_layout_cmd_node_master_list,
geo_layout_cmd_node_level_of_detail,
geo_layout_cmd_node_switch_case,
geo_layout_cmd_node_camera,
geo_layout_cmd_node_translation_rotation,
geo_layout_cmd_node_translation,
geo_layout_cmd_node_rotation,
geo_layout_cmd_node_animated_part,
geo_layout_cmd_node_billboard,
geo_layout_cmd_node_display_list,
geo_layout_cmd_node_shadow,
geo_layout_cmd_node_object_parent,
geo_layout_cmd_node_generated,
geo_layout_cmd_node_background,
geo_layout_cmd_nop,
geo_layout_cmd_copy_view,
geo_layout_cmd_node_held_obj,
geo_layout_cmd_node_scale,
geo_layout_cmd_nop2,
geo_layout_cmd_nop3,
geo_layout_cmd_node_culling_radius,
/*GEO_CMD_BRANCH_AND_LINK */ geo_layout_cmd_branch_and_link,
/*GEO_CMD_END */ geo_layout_cmd_end,
/*GEO_CMD_BRANCH */ geo_layout_cmd_branch,
/*GEO_CMD_RETURN */ geo_layout_cmd_return,
/*GEO_CMD_OPEN_NODE */ geo_layout_cmd_open_node,
/*GEO_CMD_CLOSE_NODE */ geo_layout_cmd_close_node,
/*GEO_CMD_ASSIGN_AS_VIEW */ geo_layout_cmd_assign_as_view,
/*GEO_CMD_UPDATE_NODE_FLAGS */ geo_layout_cmd_update_node_flags,
/*GEO_CMD_NODE_ROOT */ geo_layout_cmd_node_root,
/*GEO_CMD_NODE_ORTHO_PROJECTION */ geo_layout_cmd_node_ortho_projection,
/*GEO_CMD_NODE_PERSPECTIVE */ geo_layout_cmd_node_perspective,
/*GEO_CMD_NODE_START */ geo_layout_cmd_node_start,
/*GEO_CMD_NODE_MASTER_LIST */ geo_layout_cmd_node_master_list,
/*GEO_CMD_NODE_LEVEL_OF_DETAIL */ geo_layout_cmd_node_level_of_detail,
/*GEO_CMD_NODE_SWITCH_CASE */ geo_layout_cmd_node_switch_case,
/*GEO_CMD_NODE_CAMERA */ geo_layout_cmd_node_camera,
/*GEO_CMD_NODE_TRANSLATION_ROTATION */ geo_layout_cmd_node_translation_rotation,
/*GEO_CMD_NODE_TRANSLATION */ geo_layout_cmd_node_translation,
/*GEO_CMD_NODE_ROTATION */ geo_layout_cmd_node_rotation,
/*GEO_CMD_NODE_ANIMATED_PART */ geo_layout_cmd_node_animated_part,
/*GEO_CMD_NODE_BILLBOARD */ geo_layout_cmd_node_billboard,
/*GEO_CMD_NODE_DISPLAY_LIST */ geo_layout_cmd_node_display_list,
/*GEO_CMD_NODE_SHADOW */ geo_layout_cmd_node_shadow,
/*GEO_CMD_NODE_OBJECT_PARENT */ geo_layout_cmd_node_object_parent,
/*GEO_CMD_NODE_GENERATED */ geo_layout_cmd_node_generated,
/*GEO_CMD_NODE_BACKGROUND */ geo_layout_cmd_node_background,
/*GEO_CMD_NOP_1A */ geo_layout_cmd_nop,
/*GEO_CMD_COPY_VIEW */ geo_layout_cmd_copy_view,
/*GEO_CMD_NODE_HELD_OBJ */ geo_layout_cmd_node_held_obj,
/*GEO_CMD_NODE_SCALE */ geo_layout_cmd_node_scale,
/*GEO_CMD_NOP_1E */ geo_layout_cmd_nop2,
/*GEO_CMD_NOP_1F */ geo_layout_cmd_nop3,
/*GEO_CMD_NODE_CULLING_RADIUS */ geo_layout_cmd_node_culling_radius,
/*GEO_CMD_NODE_BONE */ geo_layout_cmd_bone,
};
struct GraphNode gObjParentGraphNode;
@@ -172,9 +173,15 @@ void geo_layout_cmd_update_node_flags(void) {
u16 flagBits = cur_geo_cmd_s16(0x02);
switch (operation) {
case GEO_CMD_FLAGS_RESET: gCurGraphNodeList[gCurGraphNodeIndex]->flags = flagBits; break;
case GEO_CMD_FLAGS_SET: gCurGraphNodeList[gCurGraphNodeIndex]->flags |= flagBits; break;
case GEO_CMD_FLAGS_CLEAR: gCurGraphNodeList[gCurGraphNodeIndex]->flags &= ~flagBits; break;
case GEO_CMD_FLAGS_RESET:
gCurGraphNodeList[gCurGraphNodeIndex]->flags = flagBits;
break;
case GEO_CMD_FLAGS_SET:
gCurGraphNodeList[gCurGraphNodeIndex]->flags |= flagBits;
break;
case GEO_CMD_FLAGS_CLEAR:
gCurGraphNodeList[gCurGraphNodeIndex]->flags &= ~flagBits;
break;
}
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
@@ -238,16 +245,16 @@ void geo_layout_cmd_node_ortho_projection(void) {
0x0A: Create camera frustum scene graph node
cmd+0x01: u8 if nonzero, enable frustumFunc field
cmd+0x02: s16 field of view
cmd+0x04: s16 near
cmd+0x06: s16 far
cmd+0x04: u16 near
cmd+0x06: u16 far
[cmd+0x08: GraphNodeFunc frustumFunc]
*/
void geo_layout_cmd_node_perspective(void) {
struct GraphNodePerspective *graphNode;
GraphNodeFunc frustumFunc = NULL;
s16 fov = cur_geo_cmd_s16(0x02);
s16 near = cur_geo_cmd_s16(0x04);
u16 far = cur_geo_cmd_s16(0x06);
u16 near = cur_geo_cmd_u16(0x04);
u16 far = cur_geo_cmd_u16(0x06);
if (cur_geo_cmd_u8(0x01) != 0) {
// optional asm function
@@ -267,9 +274,7 @@ void geo_layout_cmd_node_perspective(void) {
additional functionality
*/
void geo_layout_cmd_node_start(void) {
struct GraphNodeStart *graphNode;
graphNode = init_graph_node_start(gGraphNodePool, NULL);
struct GraphNodeStart *graphNode = init_graph_node_start(gGraphNodePool, NULL);
register_scene_graph_node(&graphNode->node);
@@ -282,13 +287,11 @@ 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) {
struct GraphNodeMasterList *graphNode;
graphNode = init_graph_node_master_list(gGraphNodePool, NULL, cur_geo_cmd_u8(0x01));
struct GraphNodeMasterList *graphNode = init_graph_node_master_list(gGraphNodePool, NULL, cur_geo_cmd_u8(0x01));
register_scene_graph_node(&graphNode->node);
@@ -302,11 +305,11 @@ void geo_layout_cmd_node_master_list(void) {
cmd+0x06: s16 maxDistance
*/
void geo_layout_cmd_node_level_of_detail(void) {
struct GraphNodeLevelOfDetail *graphNode;
s16 minDistance = cur_geo_cmd_s16(0x04);
s16 maxDistance = cur_geo_cmd_s16(0x06);
graphNode = init_graph_node_render_range(gGraphNodePool, NULL, minDistance, maxDistance);
struct GraphNodeLevelOfDetail *graphNode =
init_graph_node_render_range(gGraphNodePool, NULL, minDistance, maxDistance);
register_scene_graph_node(&graphNode->node);
@@ -322,9 +325,7 @@ void geo_layout_cmd_node_level_of_detail(void) {
Used for animating coins, blinking, color selection, etc.
*/
void geo_layout_cmd_node_switch_case(void) {
struct GraphNodeSwitchCase *graphNode;
graphNode =
struct GraphNodeSwitchCase *graphNode =
init_graph_node_switch_case(gGraphNodePool, NULL,
cur_geo_cmd_s16(0x02), // case which is initially selected
0,
@@ -406,7 +407,7 @@ void geo_layout_cmd_node_translation_rotation(void) {
Vec3s translation, rotation;
void *displayList = NULL;
s16 drawingLayer = 0;
s16 drawingLayer = LAYER_FIRST;
s16 params = cur_geo_cmd_u8(0x01);
s16 *cmdPos = (s16 *) gGeoLayoutCommand;
@@ -426,7 +427,7 @@ void geo_layout_cmd_node_translation_rotation(void) {
break;
case 3:
vec3s_copy(translation, gVec3sZero);
vec3s_set(rotation, 0, (cmdPos[1] << 15) / 180, 0);
vec3s_set(rotation, 0, (cmdPos[1] << 15) / 180, 0); // degrees
cmdPos += 2 << CMD_SIZE_SHIFT;
break;
}
@@ -459,7 +460,7 @@ void geo_layout_cmd_node_translation(void) {
Vec3s translation;
s16 drawingLayer = 0;
s16 drawingLayer = LAYER_FIRST;
s16 params = cur_geo_cmd_u8(0x01);
s16 *cmdPos = (s16 *) gGeoLayoutCommand;
void *displayList = NULL;
@@ -495,7 +496,7 @@ void geo_layout_cmd_node_rotation(void) {
Vec3s angle;
s16 drawingLayer = 0;
s16 drawingLayer = LAYER_FIRST;
s16 params = cur_geo_cmd_u8(0x01);
s16 *cmdPos = (s16 *) gGeoLayoutCommand;
void *displayList = NULL;
@@ -526,7 +527,7 @@ void geo_layout_cmd_node_rotation(void) {
void geo_layout_cmd_node_scale(void) {
struct GraphNodeScale *graphNode;
s16 drawingLayer = 0;
s16 drawingLayer = LAYER_FIRST;
s16 params = cur_geo_cmd_u8(0x01);
f32 scale = cur_geo_cmd_u32(0x04) / 65536.0f;
void *displayList = NULL;
@@ -587,7 +588,7 @@ void geo_layout_cmd_node_animated_part(void) {
void geo_layout_cmd_node_billboard(void) {
struct GraphNodeBillboard *graphNode;
Vec3s translation;
s16 drawingLayer = 0;
s16 drawingLayer = LAYER_FIRST;
s16 params = cur_geo_cmd_u8(0x01);
s16 *cmdPos = (s16 *) gGeoLayoutCommand;
void *displayList = NULL;
@@ -645,9 +646,7 @@ void geo_layout_cmd_node_shadow(void) {
// 0x17: Create scene graph node that manages the group of all object nodes
void geo_layout_cmd_node_object_parent(void) {
struct GraphNodeObjectParent *graphNode;
graphNode = init_graph_node_object_parent(gGraphNodePool, NULL, &gObjParentGraphNode);
struct GraphNodeObjectParent *graphNode = init_graph_node_object_parent(gGraphNodePool, NULL, &gObjParentGraphNode);
register_scene_graph_node(&graphNode->node);
@@ -660,11 +659,10 @@ void geo_layout_cmd_node_object_parent(void) {
cmd+0x04: GraphNodeFunc func
*/
void geo_layout_cmd_node_generated(void) {
struct GraphNodeGenerated *graphNode;
graphNode = init_graph_node_generated(gGraphNodePool, NULL,
(GraphNodeFunc) cur_geo_cmd_ptr(0x04), // asm function
cur_geo_cmd_s16(0x02)); // parameter
struct GraphNodeGenerated *graphNode =
init_graph_node_generated(gGraphNodePool, NULL,
(GraphNodeFunc) cur_geo_cmd_ptr(0x04), // asm function
cur_geo_cmd_s16(0x02)); // parameter
register_scene_graph_node(&graphNode->fnNode.node);
@@ -677,9 +675,7 @@ void geo_layout_cmd_node_generated(void) {
cmd+0x04: GraphNodeFunc backgroundFunc
*/
void geo_layout_cmd_node_background(void) {
struct GraphNodeBackground *graphNode;
graphNode = init_graph_node_background(
struct GraphNodeBackground *graphNode = init_graph_node_background(
gGraphNodePool, NULL,
cur_geo_cmd_s16(0x02), // background ID, or RGBA5551 color if asm function is null
(GraphNodeFunc) cur_geo_cmd_ptr(0x04), // asm function
@@ -750,8 +746,7 @@ void geo_layout_cmd_node_held_obj(void) {
cmd+0x02: s16 cullingRadius
*/
void geo_layout_cmd_node_culling_radius(void) {
struct GraphNodeCullingRadius *graphNode;
graphNode = init_graph_node_culling_radius(gGraphNodePool, NULL, cur_geo_cmd_s16(0x02));
struct GraphNodeCullingRadius *graphNode = init_graph_node_culling_radius(gGraphNodePool, NULL, cur_geo_cmd_s16(0x02));
register_scene_graph_node(&graphNode->node);
gGeoLayoutCommand += 0x04 << CMD_SIZE_SHIFT;
}
@@ -801,14 +796,7 @@ struct GraphNode *process_geo_layout(struct AllocOnlyPool *pool, void *segptr) {
gGeoLayoutStack[1] = 0;
while (gGeoLayoutCommand != NULL) {
// Custom geo commands can be a part of the switch-case, otherwise use GeoLayoutJumpTable
switch (gGeoLayoutCommand[0x00]) {
case GEO_BONE_ID:
geo_layout_cmd_bone();
break;
default:
GeoLayoutJumpTable[gGeoLayoutCommand[0x00]]();
}
GeoLayoutJumpTable[gGeoLayoutCommand[0x00]]();
}
return gCurRootGraphNode;
+11 -3
View File
@@ -7,9 +7,11 @@
#include "macros.h"
#include "types.h"
#define GEO_CMD_FLAGS_RESET 0
#define GEO_CMD_FLAGS_SET 1
#define GEO_CMD_FLAGS_CLEAR 2
enum GeoCommandFlags {
GEO_CMD_FLAGS_RESET,
GEO_CMD_FLAGS_SET,
GEO_CMD_FLAGS_CLEAR
};
#define CMD_SIZE_SHIFT (sizeof(void *) >> 3)
#define CMD_PROCESS_OFFSET(offset) (((offset) & 3) | (((offset) & ~3) << CMD_SIZE_SHIFT))
@@ -20,12 +22,18 @@
#define cur_geo_cmd_s16(offset) \
(*(s16 *) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)])
#define cur_geo_cmd_u16(offset) \
(*(u16 *) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)])
#define cur_geo_cmd_s32(offset) \
(*(s32 *) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)])
#define cur_geo_cmd_u32(offset) \
(*(u32 *) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)])
#define cur_geo_cmd_f32(offset) \
(*(f32 *) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)])
#define cur_geo_cmd_ptr(offset) \
(*(void **) &gGeoLayoutCommand[CMD_PROCESS_OFFSET(offset)])
+27 -29
View File
@@ -70,7 +70,7 @@ init_graph_node_ortho_projection(struct AllocOnlyPool *pool, struct GraphNodeOrt
*/
struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *pool,
struct GraphNodePerspective *graphNode,
f32 fov, s16 near, u16 far,
f32 fov, u16 near, u16 far,
GraphNodeFunc nodeFunc, s32 unused) {
if (pool != NULL) {
graphNode = alloc_only_pool_alloc(pool, sizeof(struct GraphNodePerspective));
@@ -429,6 +429,15 @@ struct GraphNodeShadow *init_graph_node_shadow(struct AllocOnlyPool *pool,
}
if (graphNode != NULL) {
#ifdef LEGACY_SHADOW_IDS
if (shadowType == 1 || shadowType == 2 || shadowType == 99) {
shadowType = SHADOW_CIRCLE;
} else if (shadowType == 11 || shadowType == 12) {
shadowType = SHADOW_SQUARE;
} else if (shadowType == 10) {
shadowType = SHADOW_SQUARE_PERMANENT;
}
#endif
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_SHADOW);
graphNode->shadowScale = shadowScale;
graphNode->shadowSolidity = shadowSolidity;
@@ -566,11 +575,8 @@ struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *chil
* gets thrown out when changing areas.
*/
struct GraphNode *geo_remove_child(struct GraphNode *graphNode) {
struct GraphNode *parent;
struct GraphNode **firstChild;
parent = graphNode->parent;
firstChild = &parent->children;
struct GraphNode *parent = graphNode->parent;
struct GraphNode **firstChild = &parent->children;
// Remove link with siblings
graphNode->prev->next = graphNode->next;
@@ -596,18 +602,14 @@ struct GraphNode *geo_remove_child(struct GraphNode *graphNode) {
* is independent from processing group order, where Mario is not first.)
*/
struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild) {
struct GraphNode *lastSibling;
struct GraphNode *parent;
struct GraphNode **firstChild;
parent = newFirstChild->parent;
firstChild = &parent->children;
struct GraphNode *parent = newFirstChild->parent;
struct GraphNode **firstChild = &parent->children;
if (*firstChild != newFirstChild) {
if ((*firstChild)->prev != newFirstChild) {
newFirstChild->prev->next = newFirstChild->next;
newFirstChild->next->prev = newFirstChild->prev;
lastSibling = (*firstChild)->prev;
struct GraphNode *lastSibling = (*firstChild)->prev;
newFirstChild->prev = lastSibling;
newFirstChild->next = *firstChild;
(*firstChild)->prev = newFirstChild;
@@ -619,17 +621,16 @@ struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild) {
return parent;
}
#ifndef DISABLE_GRAPH_NODE_TYPE_FUNCTIONAL
/**
* Helper function for geo_call_global_function_nodes that recursively
* traverses the scene graph and calls the functions of global nodes.
*/
void geo_call_global_function_nodes_helper(struct GraphNode *graphNode, s32 callContext) {
struct GraphNode **globalPtr;
struct GraphNode *curNode;
struct GraphNode *curNode = graphNode;
struct FnGraphNode *asFnNode;
curNode = graphNode;
do {
asFnNode = (struct FnGraphNode *) curNode;
@@ -689,6 +690,7 @@ void geo_call_global_function_nodes(struct GraphNode *graphNode, s32 callContext
gCurGraphNodeRoot = 0;
}
}
#endif
/**
* When objects are cleared, this is called on all object nodes (loaded or unloaded).
@@ -704,7 +706,7 @@ void geo_reset_object_node(struct GraphNodeObject *graphNode) {
* Initialize an object node using the given parameters
*/
void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f pos, Vec3s angle) {
vec3f_set(graphNode->scale, 1.0f, 1.0f, 1.0f);
vec3_same(graphNode->scale, 1.0f);
vec3f_copy(graphNode->pos, pos);
vec3s_copy(graphNode->angle, angle);
@@ -723,16 +725,14 @@ void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f po
* Initialize and object node using the given SpawnInfo struct
*/
void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo *spawn) {
vec3f_set(graphNode->scale, 1.0f, 1.0f, 1.0f);
vec3_same(graphNode->scale, 1.0f);
vec3s_copy(graphNode->angle, spawn->startAngle);
graphNode->pos[0] = (f32) spawn->startPos[0];
graphNode->pos[1] = (f32) spawn->startPos[1];
graphNode->pos[2] = (f32) spawn->startPos[2];
vec3s_to_vec3f(graphNode->pos, spawn->startPos);
graphNode->areaIndex = spawn->areaIndex;
graphNode->activeAreaIndex = spawn->activeAreaIndex;
graphNode->sharedChild = spawn->modelNode;
graphNode->sharedChild = spawn->model;
graphNode->spawnInfo = spawn;
graphNode->throwMatrix = NULL;
graphNode->animInfo.curAnim = 0;
@@ -802,11 +802,9 @@ s32 retrieve_animation_index(s32 frame, u16 **attributes) {
* whether it plays forwards or backwards, and whether it stops or loops at
* the end etc.
*/
s16 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist) {
s32 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_NO_ACCEL) {
if (accelAssist != NULL) {
@@ -817,7 +815,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;
@@ -861,7 +859,7 @@ s16 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist) {
* currently happens in-line in geo_process_shadow where it also accounts for
* animations without lateral translation.
*/
void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f position) {
UNUSED void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f position) {
struct Animation *animation = obj->animInfo.curAnim;
if (animation != NULL) {
@@ -886,7 +884,7 @@ void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f posit
* Unused function to find the root of the geo node tree, which should be a
* GraphNodeRoot. If it is not for some reason, null is returned.
*/
struct GraphNodeRoot *geo_find_root(struct GraphNode *graphNode) {
UNUSED struct GraphNodeRoot *geo_find_root(struct GraphNode *graphNode) {
struct GraphNodeRoot *resGraphNode = NULL;
while (graphNode->parent != NULL) {
+170 -160
View File
@@ -9,65 +9,118 @@
#include "geo_commands.h"
#include "game/memory.h"
#define GRAPH_RENDER_ACTIVE (1 << 0) // 0x0001
#define GRAPH_RENDER_CHILDREN_FIRST (1 << 1) // 0x0002
#define GRAPH_RENDER_BILLBOARD (1 << 2) // 0x0004
#define GRAPH_RENDER_Z_BUFFER (1 << 3) // 0x0008
#define GRAPH_RENDER_INVISIBLE (1 << 4) // 0x0010
#define GRAPH_RENDER_HAS_ANIMATION (1 << 5) // 0x0020
#define GRAPH_RENDER_SILHOUETTE (1 << 6) // 0x0040
#define GRAPH_RENDER_OCCLUDE_SILHOUETTE (1 << 7) // 0x0080
#define GRAPH_RENDER_UCODE_REJ (1 << 8) // 0x0100
#define GRAPH_RENDER_UCODE_ZEX (1 << 9) // 0x0200
// UCode indices for listHeads & listTails
enum GraphNodeUCodes {
GRAPH_NODE_UCODE_DEFAULT,
#ifdef OBJECTS_REJ
GRAPH_NODE_UCODE_REJ,
#endif
GRAPH_NODE_NUM_UCODES,
};
// The amount of bits to use for the above flags out of a s16 variable.
// The remaining bits to the left are used for the render layers.
// The vanilla value is 8, allowing for 8 flags and 255 layers.
#define GRAPH_RENDER_FLAGS_SIZE 12
enum GraphRenderFlags {
GRAPH_RENDER_ACTIVE = (1 << 0), // 0x0001
GRAPH_RENDER_CHILDREN_FIRST = (1 << 1), // 0x0002
GRAPH_RENDER_BILLBOARD = (1 << 2), // 0x0004
GRAPH_RENDER_Z_BUFFER = (1 << 3), // 0x0008
GRAPH_RENDER_INVISIBLE = (1 << 4), // 0x0010
GRAPH_RENDER_HAS_ANIMATION = (1 << 5), // 0x0020
GRAPH_RENDER_SILHOUETTE = (1 << 6), // 0x0040
GRAPH_RENDER_OCCLUDE_SILHOUETTE = (1 << 7), // 0x0080
};
#define GRAPH_RENDER_LAYERS_MASK (BITMASK(16 - GRAPH_RENDER_FLAGS_SIZE) << GRAPH_RENDER_FLAGS_SIZE) // 8:0xFF00 12:0xF000
#define GRAPH_RENDER_FLAGS_MASK BITMASK(GRAPH_RENDER_FLAGS_SIZE) // 8:0x00FF 12:0x0FFF
#define SET_GRAPH_NODE_LAYER(flags, layer) ((flags) = ((flags) & GRAPH_RENDER_FLAGS_MASK) | (((layer) << GRAPH_RENDER_FLAGS_SIZE) & GRAPH_RENDER_LAYERS_MASK))
#define GET_GRAPH_NODE_LAYER(flags ) ((flags & GRAPH_RENDER_LAYERS_MASK) >> GRAPH_RENDER_FLAGS_SIZE)
/**
* The amount of bits to use for the above flags out of an s16 variable.
* The remaining bits to the left are used for the render layers.
* The vanilla value is 8, allowing for 8 flags and 255 layers.
*/
#define GRAPH_RENDER_FLAGS_SIZE 8
// 0xFF00 when GRAPH_RENDER_FLAGS_SIZE is 8
#define GRAPH_RENDER_LAYERS_MASK (BITMASK(16 - GRAPH_RENDER_FLAGS_SIZE) << GRAPH_RENDER_FLAGS_SIZE)
// 0x00FF when GRAPH_RENDER_FLAGS_SIZE is 8
#define GRAPH_RENDER_FLAGS_MASK BITMASK(GRAPH_RENDER_FLAGS_SIZE)
#if GRAPH_RENDER_FLAGS_SIZE == 8
// Optimize the vanilla values
#define SET_GRAPH_NODE_LAYER(flags, layer) ((flags) = ((flags) & GRAPH_RENDER_FLAGS_MASK) | ((layer) << GRAPH_RENDER_FLAGS_SIZE))
#define GET_GRAPH_NODE_LAYER(flags) (flags >> GRAPH_RENDER_FLAGS_SIZE)
#else
#define SET_GRAPH_NODE_LAYER(flags, layer) ((flags) = ((flags) & GRAPH_RENDER_FLAGS_MASK) | (((layer) << GRAPH_RENDER_FLAGS_SIZE) & GRAPH_RENDER_LAYERS_MASK))
#define GET_GRAPH_NODE_LAYER(flags) ((flags & GRAPH_RENDER_LAYERS_MASK) >> GRAPH_RENDER_FLAGS_SIZE)
#endif
#ifdef DISABLE_GRAPH_NODE_TYPE_FUNCTIONAL
// The discriminant for different types of geo nodes
enum GraphNodeTypes {
GRAPH_NODE_TYPE_ORTHO_PROJECTION,
GRAPH_NODE_TYPE_PERSPECTIVE,
GRAPH_NODE_TYPE_MASTER_LIST,
GRAPH_NODE_TYPE_LEVEL_OF_DETAIL,
GRAPH_NODE_TYPE_SWITCH_CASE,
GRAPH_NODE_TYPE_CAMERA,
GRAPH_NODE_TYPE_TRANSLATION_ROTATION,
GRAPH_NODE_TYPE_TRANSLATION,
GRAPH_NODE_TYPE_ROTATION,
GRAPH_NODE_TYPE_OBJECT,
GRAPH_NODE_TYPE_ANIMATED_PART,
GRAPH_NODE_TYPE_BONE,
GRAPH_NODE_TYPE_BILLBOARD,
GRAPH_NODE_TYPE_DISPLAY_LIST,
GRAPH_NODE_TYPE_SCALE,
GRAPH_NODE_TYPE_SHADOW,
GRAPH_NODE_TYPE_OBJECT_PARENT,
GRAPH_NODE_TYPE_GENERATED_LIST,
GRAPH_NODE_TYPE_BACKGROUND,
GRAPH_NODE_TYPE_HELD_OBJ,
GRAPH_NODE_TYPE_CULLING_RADIUS,
GRAPH_NODE_TYPE_ROOT,
GRAPH_NODE_TYPE_START,
};
#else
// Whether the node type has a function pointer of type GraphNodeFunc
#define GRAPH_NODE_TYPE_FUNCTIONAL 0x100
#define GRAPH_NODE_TYPE_FUNCTIONAL (1 << 8)
// The discriminant for different types of geo nodes
#define GRAPH_NODE_TYPE_ROOT 0x001
#define GRAPH_NODE_TYPE_ORTHO_PROJECTION 0x002
#define GRAPH_NODE_TYPE_PERSPECTIVE (0x003 | GRAPH_NODE_TYPE_FUNCTIONAL)
#define GRAPH_NODE_TYPE_MASTER_LIST 0x004
#define GRAPH_NODE_TYPE_START 0x00A
#define GRAPH_NODE_TYPE_LEVEL_OF_DETAIL 0x00B
#define GRAPH_NODE_TYPE_SWITCH_CASE (0x00C | GRAPH_NODE_TYPE_FUNCTIONAL)
#define GRAPH_NODE_TYPE_CAMERA (0x014 | GRAPH_NODE_TYPE_FUNCTIONAL)
#define GRAPH_NODE_TYPE_TRANSLATION_ROTATION 0x015
#define GRAPH_NODE_TYPE_TRANSLATION 0x016
#define GRAPH_NODE_TYPE_ROTATION 0x017
#define GRAPH_NODE_TYPE_OBJECT 0x018
#define GRAPH_NODE_TYPE_ANIMATED_PART 0x019
#define GRAPH_NODE_TYPE_BONE GEO_BONE_ID
#define GRAPH_NODE_TYPE_BILLBOARD 0x01A
#define GRAPH_NODE_TYPE_DISPLAY_LIST 0x01B
#define GRAPH_NODE_TYPE_SCALE 0x01C
#define GRAPH_NODE_TYPE_SHADOW 0x028
#define GRAPH_NODE_TYPE_OBJECT_PARENT 0x029
#define GRAPH_NODE_TYPE_GENERATED_LIST (0x02A | GRAPH_NODE_TYPE_FUNCTIONAL)
#define GRAPH_NODE_TYPE_BACKGROUND (0x02C | GRAPH_NODE_TYPE_FUNCTIONAL)
#define GRAPH_NODE_TYPE_HELD_OBJ (0x02E | GRAPH_NODE_TYPE_FUNCTIONAL)
#define GRAPH_NODE_TYPE_CULLING_RADIUS 0x02F
enum GraphNodeTypes {
GRAPH_NODE_TYPE_ROOT = 0x01,
GRAPH_NODE_TYPE_ORTHO_PROJECTION = 0x02,
GRAPH_NODE_TYPE_PERSPECTIVE = (0x03 | GRAPH_NODE_TYPE_FUNCTIONAL),
GRAPH_NODE_TYPE_MASTER_LIST = 0x04,
GRAPH_NODE_TYPE_START = 0x0A,
GRAPH_NODE_TYPE_LEVEL_OF_DETAIL = 0x0B,
GRAPH_NODE_TYPE_SWITCH_CASE = (0x0C | GRAPH_NODE_TYPE_FUNCTIONAL),
GRAPH_NODE_TYPE_CAMERA = (0x14 | GRAPH_NODE_TYPE_FUNCTIONAL),
GRAPH_NODE_TYPE_TRANSLATION_ROTATION = 0x15,
GRAPH_NODE_TYPE_TRANSLATION = 0x16,
GRAPH_NODE_TYPE_ROTATION = 0x17,
GRAPH_NODE_TYPE_OBJECT = 0x18,
GRAPH_NODE_TYPE_ANIMATED_PART = 0x19,
GRAPH_NODE_TYPE_BONE = 0x1A,
GRAPH_NODE_TYPE_BILLBOARD = 0x1B,
GRAPH_NODE_TYPE_DISPLAY_LIST = 0x1C,
GRAPH_NODE_TYPE_SCALE = 0x1D,
GRAPH_NODE_TYPE_SHADOW = 0x28,
GRAPH_NODE_TYPE_OBJECT_PARENT = 0x29,
GRAPH_NODE_TYPE_GENERATED_LIST = (0x2A | GRAPH_NODE_TYPE_FUNCTIONAL),
GRAPH_NODE_TYPE_BACKGROUND = (0x2C | GRAPH_NODE_TYPE_FUNCTIONAL),
GRAPH_NODE_TYPE_HELD_OBJ = (0x2E | GRAPH_NODE_TYPE_FUNCTIONAL),
GRAPH_NODE_TYPE_CULLING_RADIUS = 0x2F,
#define GRAPH_NODE_TYPES_MASK 0x0FF
GRAPH_NODE_TYPES_MASK = 0xFF,
};
#endif
// Passed as first argument to a GraphNodeFunc to give information about in
// which context it was called and what it is expected to do.
#define GEO_CONTEXT_CREATE 0 // called when node is created from a geo command
#define GEO_CONTEXT_RENDER 1 // called from rendering_graph_node.c
#define GEO_CONTEXT_AREA_UNLOAD 2 // called when unloading an area
#define GEO_CONTEXT_AREA_LOAD 3 // called when loading an area
#define GEO_CONTEXT_AREA_INIT 4 // called when initializing the 8 areas
#define GEO_CONTEXT_HELD_OBJ 5 // called when processing a GraphNodeHeldObj
enum GeoContext {
GEO_CONTEXT_CREATE, // called when node is created from a geo command
GEO_CONTEXT_RENDER, // called from rendering_graph_node.c
GEO_CONTEXT_AREA_UNLOAD, // called when unloading an area
GEO_CONTEXT_AREA_LOAD, // called when loading an area
GEO_CONTEXT_AREA_INIT, // called when initializing the 8 areas
GEO_CONTEXT_HELD_OBJ // called when processing a GraphNodeHeldObj
};
// The signature for a function stored in a geo node
// The context argument depends on the callContext:
@@ -80,16 +133,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; // ?
@@ -104,8 +155,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;
};
@@ -114,20 +164,18 @@ 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
/*0x20*/ s16 near; // near clipping plane
/*0x20*/ u16 near; // near clipping plane
/*0x22*/ u16 far; // far clipping plane
};
/** 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;
@@ -138,18 +186,16 @@ 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[2][LAYER_COUNT];
/*0x34*/ struct DisplayListNode *listTails[2][LAYER_COUNT];
/*0x14*/ struct DisplayListNode *listHeads[GRAPH_NODE_NUM_UCODES][LAYER_COUNT];
/*0x34*/ struct DisplayListNode *listTails[GRAPH_NODE_NUM_UCODES][LAYER_COUNT];
};
/** Simply used as a parent to group multiple children.
* Does not have any additional functionality.
*/
struct GraphNodeStart
{
struct GraphNodeStart {
/*0x00*/ struct GraphNode node;
};
@@ -159,8 +205,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;
@@ -171,8 +216,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;
@@ -183,8 +227,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.
@@ -207,8 +250,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;
@@ -219,12 +261,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.
@@ -232,12 +273,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
@@ -247,15 +287,13 @@ 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;
};
struct GraphNodeBone
{
struct GraphNodeBone {
struct GraphNode node;
void *displayList;
Vec3s translation;
@@ -267,8 +305,7 @@ struct GraphNodeBone
* 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;
@@ -277,8 +314,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;
};
@@ -291,20 +327,18 @@ 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;
};
/** GraphNode that draws a shadow under an object.
* Every object starts with a shadow node.
* Almost every object starts with a shadow node.
* 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
@@ -314,8 +348,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;
};
@@ -328,8 +361,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
};
@@ -337,8 +369,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
@@ -346,8 +377,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;
@@ -359,17 +389,16 @@ 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;
extern struct GraphNodeMasterList *gCurGraphNodeMasterList;
extern struct GraphNodePerspective *gCurGraphNodeCamFrustum;
extern struct GraphNodeCamera *gCurGraphNodeCamera;
extern struct GraphNodeHeldObject *gCurGraphNodeHeldObject;
extern struct GraphNodeCamera *gCurGraphNodeCamera;
extern struct GraphNodeHeldObject *gCurGraphNodeHeldObject;
extern u16 gAreaUpdateCounter;
extern struct GraphNode *gCurRootGraphNode;
@@ -379,73 +408,54 @@ extern s16 gCurGraphNodeIndex;
void init_scene_graph_node_links(struct GraphNode *graphNode, s32 type);
struct GraphNodeRoot *init_graph_node_root(struct AllocOnlyPool *pool, struct GraphNodeRoot *graphNode,
s16 areaIndex, s16 x, s16 y, s16 width, s16 height);
struct GraphNodeOrthoProjection *init_graph_node_ortho_projection(struct AllocOnlyPool *pool, struct GraphNodeOrthoProjection *graphNode, f32 scale);
struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *pool, struct GraphNodePerspective *graphNode,
f32 fov, s16 near, u16 far, GraphNodeFunc nodeFunc, s32 unused);
struct GraphNodeStart *init_graph_node_start(struct AllocOnlyPool *pool, struct GraphNodeStart *graphNode);
struct GraphNodeMasterList *init_graph_node_master_list(struct AllocOnlyPool *pool, struct GraphNodeMasterList *graphNode, s16 on);
struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct AllocOnlyPool *pool, struct GraphNodeLevelOfDetail *graphNode,
s16 minDistance, s16 maxDistance);
struct GraphNodeSwitchCase *init_graph_node_switch_case(struct AllocOnlyPool *pool, struct GraphNodeSwitchCase *graphNode,
s16 numCases, s16 selectedCase, GraphNodeFunc nodeFunc, s32 unused);
struct GraphNodeCamera *init_graph_node_camera(struct AllocOnlyPool *pool, struct GraphNodeCamera *graphNode,
f32 *pos, f32 *focus, GraphNodeFunc func, s32 mode);
struct GraphNodeTranslationRotation *init_graph_node_translation_rotation(struct AllocOnlyPool *pool, struct GraphNodeTranslationRotation *graphNode,
s32 drawingLayer, void *displayList, Vec3s translation, Vec3s rotation);
struct GraphNodeTranslation *init_graph_node_translation(struct AllocOnlyPool *pool, struct GraphNodeTranslation *graphNode,
s32 drawingLayer, void *displayList, Vec3s translation);
struct GraphNodeRotation *init_graph_node_rotation(struct AllocOnlyPool *pool, struct GraphNodeRotation *graphNode,
s32 drawingLayer, void *displayList, Vec3s rotation);
struct GraphNodeScale *init_graph_node_scale(struct AllocOnlyPool *pool, struct GraphNodeScale *graphNode,
s32 drawingLayer, void *displayList, f32 scale);
struct GraphNodeObject *init_graph_node_object(struct AllocOnlyPool *pool, struct GraphNodeObject *graphNode,
struct GraphNode *sharedChild, Vec3f pos, Vec3s angle, Vec3f scale);
struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct AllocOnlyPool *pool, struct GraphNodeCullingRadius *graphNode, s16 radius);
struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct AllocOnlyPool *pool, struct GraphNodeAnimatedPart *graphNode,
s32 drawingLayer, void *displayList, Vec3s translation);
struct GraphNodeBone *init_graph_node_bone(struct AllocOnlyPool *pool, struct GraphNodeBone *graphNode,
s32 drawingLayer, void *displayList, Vec3s translation, Vec3s rotation);
struct GraphNodeBillboard *init_graph_node_billboard(struct AllocOnlyPool *pool, struct GraphNodeBillboard *graphNode,
s32 drawingLayer, void *displayList, Vec3s translation);
struct GraphNodeDisplayList *init_graph_node_display_list(struct AllocOnlyPool *pool, struct GraphNodeDisplayList *graphNode,
s32 drawingLayer, void *displayList);
struct GraphNodeShadow *init_graph_node_shadow(struct AllocOnlyPool *pool, struct GraphNodeShadow *graphNode,
s16 shadowScale, u8 shadowSolidity, u8 shadowType);
struct GraphNodeObjectParent *init_graph_node_object_parent(struct AllocOnlyPool *pool, struct GraphNodeObjectParent *graphNode,
struct GraphNode *sharedChild);
struct GraphNodeGenerated *init_graph_node_generated(struct AllocOnlyPool *pool, struct GraphNodeGenerated *graphNode,
GraphNodeFunc gfxFunc, s32 parameter);
struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *pool, struct GraphNodeBackground *graphNode,
u16 background, GraphNodeFunc backgroundFunc, s32 zero);
struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *pool, struct GraphNodeHeldObject *graphNode,
struct Object *objNode, Vec3s translation,
GraphNodeFunc nodeFunc, s32 playerIndex);
struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *childNode);
struct GraphNode *geo_remove_child(struct GraphNode *graphNode);
struct GraphNodeRoot *init_graph_node_root (struct AllocOnlyPool *pool, struct GraphNodeRoot *graphNode, s16 areaIndex, s16 x, s16 y, s16 width, s16 height);
struct GraphNodeOrthoProjection *init_graph_node_ortho_projection (struct AllocOnlyPool *pool, struct GraphNodeOrthoProjection *graphNode, f32 scale);
struct GraphNodePerspective *init_graph_node_perspective (struct AllocOnlyPool *pool, struct GraphNodePerspective *graphNode, f32 fov, u16 near, u16 far, GraphNodeFunc nodeFunc, s32 unused);
struct GraphNodeStart *init_graph_node_start (struct AllocOnlyPool *pool, struct GraphNodeStart *graphNode);
struct GraphNodeMasterList *init_graph_node_master_list (struct AllocOnlyPool *pool, struct GraphNodeMasterList *graphNode, s16 on);
struct GraphNodeLevelOfDetail *init_graph_node_render_range (struct AllocOnlyPool *pool, struct GraphNodeLevelOfDetail *graphNode, s16 minDistance, s16 maxDistance);
struct GraphNodeSwitchCase *init_graph_node_switch_case (struct AllocOnlyPool *pool, struct GraphNodeSwitchCase *graphNode, s16 numCases, s16 selectedCase, GraphNodeFunc nodeFunc, s32 unused);
struct GraphNodeCamera *init_graph_node_camera (struct AllocOnlyPool *pool, struct GraphNodeCamera *graphNode, f32 *pos, f32 *focus, GraphNodeFunc func, s32 mode);
struct GraphNodeTranslationRotation *init_graph_node_translation_rotation(struct AllocOnlyPool *pool, struct GraphNodeTranslationRotation *graphNode, s32 drawingLayer, void *displayList, Vec3s translation, Vec3s rotation);
struct GraphNodeTranslation *init_graph_node_translation (struct AllocOnlyPool *pool, struct GraphNodeTranslation *graphNode, s32 drawingLayer, void *displayList, Vec3s translation);
struct GraphNodeRotation *init_graph_node_rotation (struct AllocOnlyPool *pool, struct GraphNodeRotation *graphNode, s32 drawingLayer, void *displayList, Vec3s rotation);
struct GraphNodeScale *init_graph_node_scale (struct AllocOnlyPool *pool, struct GraphNodeScale *graphNode, s32 drawingLayer, void *displayList, f32 scale);
struct GraphNodeObject *init_graph_node_object (struct AllocOnlyPool *pool, struct GraphNodeObject *graphNode, struct GraphNode *sharedChild, Vec3f pos, Vec3s angle, Vec3f scale);
struct GraphNodeCullingRadius *init_graph_node_culling_radius (struct AllocOnlyPool *pool, struct GraphNodeCullingRadius *graphNode, s16 radius);
struct GraphNodeAnimatedPart *init_graph_node_animated_part (struct AllocOnlyPool *pool, struct GraphNodeAnimatedPart *graphNode, s32 drawingLayer, void *displayList, Vec3s translation);
struct GraphNodeBone *init_graph_node_bone (struct AllocOnlyPool *pool, struct GraphNodeBone *graphNode, s32 drawingLayer, void *displayList, Vec3s translation, Vec3s rotation);
struct GraphNodeBillboard *init_graph_node_billboard (struct AllocOnlyPool *pool, struct GraphNodeBillboard *graphNode, s32 drawingLayer, void *displayList, Vec3s translation);
struct GraphNodeDisplayList *init_graph_node_display_list (struct AllocOnlyPool *pool, struct GraphNodeDisplayList *graphNode, s32 drawingLayer, void *displayList);
struct GraphNodeShadow *init_graph_node_shadow (struct AllocOnlyPool *pool, struct GraphNodeShadow *graphNode, s16 shadowScale, u8 shadowSolidity, u8 shadowType);
struct GraphNodeObjectParent *init_graph_node_object_parent (struct AllocOnlyPool *pool, struct GraphNodeObjectParent *graphNode, struct GraphNode *sharedChild);
struct GraphNodeGenerated *init_graph_node_generated (struct AllocOnlyPool *pool, struct GraphNodeGenerated *graphNode, GraphNodeFunc gfxFunc, s32 parameter);
struct GraphNodeBackground *init_graph_node_background (struct AllocOnlyPool *pool, struct GraphNodeBackground *graphNode, u16 background, GraphNodeFunc backgroundFunc, s32 zero);
struct GraphNodeHeldObject *init_graph_node_held_object (struct AllocOnlyPool *pool, struct GraphNodeHeldObject *graphNode, struct Object *objNode, Vec3s translation, GraphNodeFunc nodeFunc, s32 playerIndex);
struct GraphNode *geo_add_child (struct GraphNode *parent, struct GraphNode *childNode);
struct GraphNode *geo_remove_child (struct GraphNode *graphNode);
struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild);
#ifndef DISABLE_GRAPH_NODE_TYPE_FUNCTIONAL
void geo_call_global_function_nodes_helper(struct GraphNode *graphNode, s32 callContext);
void geo_call_global_function_nodes(struct GraphNode *graphNode, s32 callContext);
void geo_call_global_function_nodes (struct GraphNode *graphNode, s32 callContext);
#endif
void geo_reset_object_node(struct GraphNodeObject *graphNode);
void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f pos, Vec3s angle);
void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo *spawn);
void geo_obj_init_animation(struct GraphNodeObject *graphNode, struct Animation **animPtrAddr);
void geo_obj_init_animation_accel(struct GraphNodeObject *graphNode, struct Animation **animPtrAddr, u32 animAccel);
s32 retrieve_animation_index(s32 frame, u16 **attributes);
s32 retrieve_animation_index(s32 frame, u16 **attributes);
s16 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist);
s32 geo_update_animation_frame(struct AnimInfo *obj, s32 *accelAssist);
void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f position);
struct GraphNodeRoot *geo_find_root(struct GraphNode *graphNode);
// graph_node_manager
s16 *read_vec3s_to_vec3f(Vec3f, s16 *src);
s16 *read_vec3s(Vec3s dst, s16 *src);
s16 *read_vec3s_angle(Vec3s dst, s16 *src);
s16 *read_vec3s_to_vec3f(Vec3f dst, s16 *src);
s16 *read_vec3s( Vec3s dst, s16 *src);
s16 *read_vec3s_angle( Vec3s dst, s16 *src);
void register_scene_graph_node(struct GraphNode *graphNode);
#endif // GRAPH_NODE_H
+171 -176
View File
@@ -31,6 +31,8 @@
#include "config.h"
#define NUM_PAINTINGS 45
#define CMD_GET(type, offset) (*(type *) (CMD_PROCESS_OFFSET(offset) + (u8 *) sCurrentCmd))
// These are equal
@@ -43,9 +45,13 @@ struct LevelCommand {
/*02*/ // variable sized argument data
};
enum ScriptStatus { SCRIPT_RUNNING = 1, SCRIPT_PAUSED = 0, SCRIPT_PAUSED2 = -1 };
enum ScriptStatus {
SCRIPT_RUNNING = 1,
SCRIPT_PAUSED = 0,
SCRIPT_PAUSED2 = -1
};
static uintptr_t sStack[32];
static uintptr_t sStack[NUM_TLB_SEGMENTS];
static struct AllocOnlyPool *sLevelPool = NULL;
@@ -62,7 +68,7 @@ static s32 sRegister;
static struct LevelCommand *sCurrentCmd;
static s32 eval_script_op(s8 op, s32 arg) {
s32 result = 0;
s32 result = FALSE;
switch (op) {
case 0:
@@ -188,7 +194,7 @@ static void level_cmd_loop_begin(void) {
}
static void level_cmd_loop_until(void) {
if (eval_script_op(CMD_GET(u8, 2), CMD_GET(s32, 4)) != 0) {
if (eval_script_op(CMD_GET(u8, 2), CMD_GET(s32, 4))) {
sCurrentCmd = CMD_NEXT;
sStackTop -= 2;
} else {
@@ -197,7 +203,7 @@ static void level_cmd_loop_until(void) {
}
static void level_cmd_jump_if(void) {
if (eval_script_op(CMD_GET(u8, 2), CMD_GET(s32, 4)) != 0) {
if (eval_script_op(CMD_GET(u8, 2), CMD_GET(s32, 4))) {
sCurrentCmd = segmented_to_virtual(CMD_GET(void *, 8));
} else {
sCurrentCmd = CMD_NEXT;
@@ -205,7 +211,7 @@ static void level_cmd_jump_if(void) {
}
static void level_cmd_jump_and_link_if(void) {
if (eval_script_op(CMD_GET(u8, 2), CMD_GET(s32, 4)) != 0) {
if (eval_script_op(CMD_GET(u8, 2), CMD_GET(s32, 4))) {
*sStackTop++ = (uintptr_t) NEXT_CMD;
sCurrentCmd = segmented_to_virtual(CMD_GET(void *, 8));
} else {
@@ -214,10 +220,10 @@ static void level_cmd_jump_and_link_if(void) {
}
static void level_cmd_skip_if(void) {
if (eval_script_op(CMD_GET(u8, 2), CMD_GET(s32, 4)) == 0) {
if (!eval_script_op(CMD_GET(u8, 2), CMD_GET(s32, 4))) {
do {
sCurrentCmd = CMD_NEXT;
} while (sCurrentCmd->type == 0x0F || sCurrentCmd->type == 0x10);
} while (sCurrentCmd->type == LEVEL_CMD_SKIP || sCurrentCmd->type == LEVEL_CMD_SKIPPABLE_NOP);
}
sCurrentCmd = CMD_NEXT;
@@ -226,7 +232,7 @@ static void level_cmd_skip_if(void) {
static void level_cmd_skip(void) {
do {
sCurrentCmd = CMD_NEXT;
} while (sCurrentCmd->type == 0x10);
} while (sCurrentCmd->type == LEVEL_CMD_SKIPPABLE_NOP);
sCurrentCmd = CMD_NEXT;
}
@@ -293,7 +299,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));
}
@@ -327,26 +333,25 @@ static void level_cmd_init_level(void) {
}
extern s32 gTlbEntries;
extern u8 gTlbSegments[32];
extern u8 gTlbSegments[NUM_TLB_SEGMENTS];
//This clears all the temporary bank TLB maps. group0, common1 and behavourdata are always loaded,
//and they're also loaded first, so that means we just leave the first 3 indexes mapped.
void unmap_tlbs(void)
{
// This clears all the temporary bank TLB maps. group0, common1 and behavourdata are always loaded,
// and they're also loaded first, so that means we just leave the first 3 indexes mapped.
void unmap_tlbs(void) {
s32 i;
for (i = 0; i < 32; i++)
{
if (gTlbSegments[i] && i != 0x17 && i != 0x16 && i != 0x13)
{
while (gTlbSegments[i] > 0)
{
osUnmapTLB(gTlbEntries);
gTlbSegments[i]--;
gTlbEntries--;
for (i = 0; i < NUM_TLB_SEGMENTS; i++) {
if (gTlbSegments[i]) {
if (i != SEGMENT_GROUP0_GEO && i != SEGMENT_COMMON1_GEO && i != SEGMENT_BEHAVIOR_DATA) {
while (gTlbSegments[i] > 0) {
osUnmapTLB(gTlbEntries);
gTlbSegments[i]--;
gTlbEntries--;
}
} else {
gTlbEntries -= gTlbSegments[i];
gTlbSegments[i] = 0;
}
}
}
}
@@ -438,22 +443,16 @@ static void level_cmd_load_model_from_geo(void) {
}
static void level_cmd_23(void) {
union {
s32 i;
f32 f;
} arg2;
ModelID16 model = CMD_GET(s16, 2) & 0x0FFF;
s16 arg0H = ((u16)CMD_GET(s16, 2)) >> 12;
void *arg1 = CMD_GET(void *, 4);
// load an f32, but using an integer load instruction for some reason (hence the union)
arg2.i = CMD_GET(s32, 8);
ModelID16 model = (CMD_GET(ModelID16, 2) & 0x0FFF);
s16 layer = (((u16)CMD_GET(s16, 2)) >> 12);
void *dl = CMD_GET(void *, 4);
s32 scale = CMD_GET(s32, 8);
if (model < MODEL_ID_COUNT) {
// GraphNodeScale has a GraphNode at the top. This
// is being stored to the array, so cast the pointer.
gLoadedGraphNodes[model] =
(struct GraphNode *) init_graph_node_scale(sLevelPool, 0, arg0H, arg1, arg2.f);
(struct GraphNode *) init_graph_node_scale(sLevelPool, 0, layer, dl, scale);
}
sCurrentCmd = CMD_NEXT;
@@ -467,35 +466,34 @@ static void level_cmd_init_mario(void) {
gMarioSpawnInfo->areaIndex = 0;
gMarioSpawnInfo->behaviorArg = CMD_GET(u32, 4);
gMarioSpawnInfo->behaviorScript = CMD_GET(void *, 8);
gMarioSpawnInfo->modelNode = gLoadedGraphNodes[CMD_GET(ModelID16, 0x2)];
gMarioSpawnInfo->model = gLoadedGraphNodes[CMD_GET(ModelID16, 0x2)]; // u8, 3?
gMarioSpawnInfo->next = NULL;
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_place_object(void) {
u8 val7 = 1 << (gCurrActNum - 1);
u16 model;
struct SpawnInfo *spawnInfo;
if (
sCurrAreaIndex != -1
&& ((CMD_GET(u8, 2) & (1 << (gCurrActNum - 1))) || (CMD_GET(u8, 2) == 0x1F))
) {
ModelID16 model = CMD_GET(u32, 0x18);
struct SpawnInfo *spawnInfo = alloc_only_pool_alloc(sLevelPool, sizeof(struct SpawnInfo));
if (sCurrAreaIndex != -1 && ((CMD_GET(u8, 2) & val7) || CMD_GET(u8, 2) == 0x1F)) {
model = CMD_GET(u32, 0x18);
spawnInfo = alloc_only_pool_alloc(sLevelPool, sizeof(struct SpawnInfo));
vec3s_set(spawnInfo->startPos, CMD_GET(s16, 4),
CMD_GET(s16, 6),
CMD_GET(s16, 8));
spawnInfo->startPos[0] = CMD_GET(s16, 4);
spawnInfo->startPos[1] = CMD_GET(s16, 6);
spawnInfo->startPos[2] = CMD_GET(s16, 8);
spawnInfo->startAngle[0] = CMD_GET(s16, 10) * 0x8000 / 180;
spawnInfo->startAngle[1] = CMD_GET(s16, 12) * 0x8000 / 180;
spawnInfo->startAngle[2] = CMD_GET(s16, 14) * 0x8000 / 180;
vec3s_set(spawnInfo->startAngle, DEGREES(CMD_GET(s16, 10)),
DEGREES(CMD_GET(s16, 12)),
DEGREES(CMD_GET(s16, 14)));
spawnInfo->areaIndex = sCurrAreaIndex;
spawnInfo->activeAreaIndex = sCurrAreaIndex;
spawnInfo->behaviorArg = CMD_GET(u32, 16);
spawnInfo->behaviorScript = CMD_GET(void *, 20);
spawnInfo->modelNode = gLoadedGraphNodes[model];
spawnInfo->model = gLoadedGraphNodes[model];
spawnInfo->next = gAreas[sCurrAreaIndex].objectSpawnInfos;
gAreas[sCurrAreaIndex].objectSpawnInfos = spawnInfo;
@@ -530,7 +528,7 @@ static void level_cmd_create_instant_warp(void) {
if (sCurrAreaIndex != -1) {
if (gAreas[sCurrAreaIndex].instantWarps == NULL) {
gAreas[sCurrAreaIndex].instantWarps =
alloc_only_pool_alloc(sLevelPool, 4 * sizeof(struct InstantWarp));
alloc_only_pool_alloc(sLevelPool, INSTANT_WARP_INDEX_STOP * sizeof(struct InstantWarp));
for (i = INSTANT_WARP_INDEX_START; i < INSTANT_WARP_INDEX_STOP; i++) {
gAreas[sCurrAreaIndex].instantWarps[i].id = 0;
@@ -542,9 +540,9 @@ static void level_cmd_create_instant_warp(void) {
warp[0].id = 1;
warp[0].area = CMD_GET(u8, 3);
warp[0].displacement[0] = CMD_GET(s16, 4);
warp[0].displacement[1] = CMD_GET(s16, 6);
warp[0].displacement[2] = CMD_GET(s16, 8);
vec3s_set(warp[0].displacement, CMD_GET(s16, 4),
CMD_GET(s16, 6),
CMD_GET(s16, 8));
}
sCurrentCmd = CMD_NEXT;
@@ -565,9 +563,9 @@ static void level_cmd_create_painting_warp_node(void) {
if (sCurrAreaIndex != -1) {
if (gAreas[sCurrAreaIndex].paintingWarpNodes == NULL) {
gAreas[sCurrAreaIndex].paintingWarpNodes =
alloc_only_pool_alloc(sLevelPool, 45 * sizeof(struct WarpNode));
alloc_only_pool_alloc(sLevelPool, NUM_PAINTINGS * sizeof(struct WarpNode));
for (i = 0; i < 45; i++) {
for (i = 0; i < NUM_PAINTINGS; i++) {
gAreas[sCurrAreaIndex].paintingWarpNodes[i].id = 0;
}
}
@@ -587,8 +585,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));
}
@@ -608,8 +606,10 @@ static void level_cmd_create_whirlpool(void) {
s32 beatBowser2 =
(save_file_get_flags() & (SAVE_FLAG_HAVE_KEY_2 | SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR)) != 0;
if (CMD_GET(u8, 3) == 0 || (CMD_GET(u8, 3) == 1 && !beatBowser2)
|| (CMD_GET(u8, 3) == 2 && beatBowser2) || (CMD_GET(u8, 3) == 3 && gCurrActNum >= 2)) {
if (CMD_GET(u8, 3) == WHIRLPOOL_COND_ALWAYS
|| (CMD_GET(u8, 3) == WHIRLPOOL_COND_BOWSER2_NOT_BEATEN && !beatBowser2)
|| (CMD_GET(u8, 3) == WHIRLPOOL_COND_BOWSER2_BEATEN && beatBowser2)
|| (CMD_GET(u8, 3) == WHIRLPOOL_COND_AT_LEAST_SECOND_STAR && gCurrActNum >= 2)) {
if (sCurrAreaIndex != -1 && index < 2) {
if ((whirlpool = gAreas[sCurrAreaIndex].whirlpools[index]) == NULL) {
whirlpool = alloc_only_pool_alloc(sLevelPool, sizeof(struct Whirlpool));
@@ -639,12 +639,9 @@ static void level_cmd_set_terrain_data(void) {
#ifndef NO_SEGMENTED_MEMORY
gAreas[sCurrAreaIndex].terrainData = segmented_to_virtual(CMD_GET(void *, 4));
#else
Collision *data;
u32 size;
// The game modifies the terrain data and must be reset upon level reload.
data = segmented_to_virtual(CMD_GET(void *, 4));
size = get_area_terrain_size(data) * sizeof(Collision);
Collision *data = segmented_to_virtual(CMD_GET(void *, 4));
u32 size = get_area_terrain_size(data) * sizeof(Collision);
gAreas[sCurrAreaIndex].terrainData = alloc_only_pool_alloc(sLevelPool, size);
memcpy(gAreas[sCurrAreaIndex].terrainData, data, size);
#endif
@@ -705,12 +702,12 @@ static void level_cmd_set_mario_start_pos(void) {
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_2C(void) {
static void level_cmd_unload_mario_area(void) {
unload_mario_area();
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_2D(void) {
static void level_cmd_update_objects(void) {
area_update_objects();
sCurrentCmd = CMD_NEXT;
}
@@ -748,7 +745,7 @@ static void level_cmd_set_menu_music(void) {
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_38(void) {
static void level_cmd_fadeout_music(void) {
fadeout_music(CMD_GET(s16, 2));
sCurrentCmd = CMD_NEXT;
}
@@ -795,50 +792,50 @@ static void level_cmd_get_or_set_var(void) {
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_puppyvolume(void)
{
static void level_cmd_puppyvolume(void) {
#ifdef PUPPYCAM
if ((sPuppyVolumeStack[gPuppyVolumeCount] = mem_pool_alloc(gPuppyMemoryPool,sizeof(struct sPuppyVolume))) == NULL)
{
if ((sPuppyVolumeStack[gPuppyVolumeCount] = mem_pool_alloc(gPuppyMemoryPool, sizeof(struct sPuppyVolume))) == NULL) {
sCurrentCmd = CMD_NEXT;
gPuppyError |= PUPPY_ERROR_POOL_FULL;
#if PUPPYPRINT_DEBUG
#if PUPPYPRINT_DEBUG
append_puppyprint_log("Puppycamera volume allocation failed.");
#endif
#endif
return;
}
sPuppyVolumeStack[gPuppyVolumeCount]->pos[0] = CMD_GET(s16, 2);
sPuppyVolumeStack[gPuppyVolumeCount]->pos[1] = CMD_GET(s16, 4);
sPuppyVolumeStack[gPuppyVolumeCount]->pos[2] = CMD_GET(s16, 6);
vec3s_set(sPuppyVolumeStack[gPuppyVolumeCount]->pos, CMD_GET(s16, 2),
CMD_GET(s16, 4),
CMD_GET(s16, 6));
sPuppyVolumeStack[gPuppyVolumeCount]->radius[0] = CMD_GET(s16, 8);
sPuppyVolumeStack[gPuppyVolumeCount]->radius[1] = CMD_GET(s16, 10);
sPuppyVolumeStack[gPuppyVolumeCount]->radius[2] = CMD_GET(s16, 12);
vec3s_set(sPuppyVolumeStack[gPuppyVolumeCount]->radius, CMD_GET(s16, 8),
CMD_GET(s16, 10),
CMD_GET(s16, 12));
sPuppyVolumeStack[gPuppyVolumeCount]->rot = CMD_GET(s16, 14);
sPuppyVolumeStack[gPuppyVolumeCount]->func = CMD_GET(void *, 16);
sPuppyVolumeStack[gPuppyVolumeCount]->func = CMD_GET(void *, 16);
sPuppyVolumeStack[gPuppyVolumeCount]->angles = segmented_to_virtual(CMD_GET(void *, 20));
sPuppyVolumeStack[gPuppyVolumeCount]->flagsAdd = CMD_GET(s32, 24);
sPuppyVolumeStack[gPuppyVolumeCount]->flagsAdd = CMD_GET(s32, 24);
sPuppyVolumeStack[gPuppyVolumeCount]->flagsRemove = CMD_GET(s32, 28);
sPuppyVolumeStack[gPuppyVolumeCount]->flagPersistance = CMD_GET(u8, 32);
sPuppyVolumeStack[gPuppyVolumeCount]->shape = CMD_GET(u8, 33);
sPuppyVolumeStack[gPuppyVolumeCount]->room = CMD_GET(s16, 34);
sPuppyVolumeStack[gPuppyVolumeCount]->area = sCurrAreaIndex;
sPuppyVolumeStack[gPuppyVolumeCount]->shape = CMD_GET(u8, 33);
sPuppyVolumeStack[gPuppyVolumeCount]->room = CMD_GET(s16, 34);
sPuppyVolumeStack[gPuppyVolumeCount]->fov = CMD_GET(u8, 36);
sPuppyVolumeStack[gPuppyVolumeCount]->area = sCurrAreaIndex;
gPuppyVolumeCount++;
#endif
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_puppylight_environment(void)
{
static void level_cmd_puppylight_environment(void) {
#ifdef PUPPYLIGHTS
Lights1 temp = gdSPDefLights1(CMD_GET(u8, 2), CMD_GET(u8, 3), CMD_GET(u8, 4), CMD_GET(u8, 5), CMD_GET(u8, 6), CMD_GET(u8, 7), CMD_GET(u8, 8), CMD_GET(u8, 9), CMD_GET(u8, 10));
Lights1 temp = gdSPDefLights1(CMD_GET(u8, 2), CMD_GET(u8, 3), CMD_GET(u8, 4),
CMD_GET(u8, 5), CMD_GET(u8, 6), CMD_GET(u8, 7),
CMD_GET(u8, 8), CMD_GET(u8, 9), CMD_GET(u8, 10));
memcpy(&gLevelLight, &temp, sizeof(Lights1));
levelAmbient = TRUE;
@@ -846,11 +843,10 @@ static void level_cmd_puppylight_environment(void)
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_puppylight_node(void)
{
static void level_cmd_puppylight_node(void) {
#ifdef PUPPYLIGHTS
if ((gPuppyLights[gNumLights] = mem_pool_alloc(gLightsPool, sizeof(struct PuppyLight))) == NULL)
{
gPuppyLights[gNumLights] = mem_pool_alloc(gLightsPool, sizeof(struct PuppyLight));
if (gPuppyLights[gNumLights] == NULL) {
#if PUPPYPRINT_DEBUG
append_puppyprint_log("Puppylight allocation failed.");
#endif
@@ -858,25 +854,24 @@ static void level_cmd_puppylight_node(void)
return;
}
gPuppyLights[gNumLights]->rgba[0] = CMD_GET(u8, 2);
gPuppyLights[gNumLights]->rgba[1] = CMD_GET(u8, 3);
gPuppyLights[gNumLights]->rgba[2] = CMD_GET(u8, 4);
gPuppyLights[gNumLights]->rgba[3] = CMD_GET(u8, 5);
vec4_set(gPuppyLights[gNumLights]->rgba, CMD_GET(u8, 2),
CMD_GET(u8, 3),
CMD_GET(u8, 4),
CMD_GET(u8, 5));
gPuppyLights[gNumLights]->pos[0][0] = CMD_GET(s16, 6);
gPuppyLights[gNumLights]->pos[0][1] = CMD_GET(s16, 8);
gPuppyLights[gNumLights]->pos[0][2] = CMD_GET(s16, 10);
vec3s_set(gPuppyLights[gNumLights]->pos[0], CMD_GET(s16, 6),
CMD_GET(s16, 8),
CMD_GET(s16, 10));
gPuppyLights[gNumLights]->pos[1][0] = CMD_GET(s16, 12);
gPuppyLights[gNumLights]->pos[1][1] = CMD_GET(s16, 14);
gPuppyLights[gNumLights]->pos[1][2] = CMD_GET(s16, 16);
gPuppyLights[gNumLights]->yaw = CMD_GET(s16, 18);
gPuppyLights[gNumLights]->epicentre = CMD_GET(u8, 20);
gPuppyLights[gNumLights]->flags = CMD_GET(u8, 21);
gPuppyLights[gNumLights]->active = TRUE;
gPuppyLights[gNumLights]->area = sCurrAreaIndex;
gPuppyLights[gNumLights]->room = CMD_GET(s16, 22);
vec3s_set(gPuppyLights[gNumLights]->pos[1], CMD_GET(s16, 12),
CMD_GET(s16, 14),
CMD_GET(s16, 16));
gPuppyLights[gNumLights]->yaw = CMD_GET(s16, 18);
gPuppyLights[gNumLights]->epicentre = CMD_GET(u8, 20);
gPuppyLights[gNumLights]->flags = CMD_GET(u8, 21);
gPuppyLights[gNumLights]->active = TRUE;
gPuppyLights[gNumLights]->area = sCurrAreaIndex;
gPuppyLights[gNumLights]->room = CMD_GET(s16, 22);
gNumLights++;
@@ -885,71 +880,71 @@ static void level_cmd_puppylight_node(void)
}
static void (*LevelScriptJumpTable[])(void) = {
/*00*/ level_cmd_load_and_execute,
/*01*/ level_cmd_exit_and_execute,
/*02*/ level_cmd_exit,
/*03*/ level_cmd_sleep,
/*04*/ level_cmd_sleep2,
/*05*/ level_cmd_jump,
/*06*/ level_cmd_jump_and_link,
/*07*/ level_cmd_return,
/*08*/ level_cmd_jump_and_link_push_arg,
/*09*/ level_cmd_jump_repeat,
/*0A*/ level_cmd_loop_begin,
/*0B*/ level_cmd_loop_until,
/*0C*/ level_cmd_jump_if,
/*0D*/ level_cmd_jump_and_link_if,
/*0E*/ level_cmd_skip_if,
/*0F*/ level_cmd_skip,
/*10*/ level_cmd_skippable_nop,
/*11*/ level_cmd_call,
/*12*/ level_cmd_call_loop,
/*13*/ level_cmd_set_register,
/*14*/ level_cmd_push_pool_state,
/*15*/ level_cmd_pop_pool_state,
/*16*/ level_cmd_load_to_fixed_address,
/*17*/ level_cmd_load_raw,
/*18*/ level_cmd_load_yay0,
/*19*/ level_cmd_load_mario_head,
/*1A*/ level_cmd_load_yay0_texture,
/*1B*/ level_cmd_init_level,
/*1C*/ level_cmd_clear_level,
/*1D*/ level_cmd_alloc_level_pool,
/*1E*/ level_cmd_free_level_pool,
/*1F*/ level_cmd_begin_area,
/*20*/ level_cmd_end_area,
/*21*/ level_cmd_load_model_from_dl,
/*22*/ level_cmd_load_model_from_geo,
/*23*/ level_cmd_23,
/*24*/ level_cmd_place_object,
/*25*/ level_cmd_init_mario,
/*26*/ level_cmd_create_warp_node,
/*27*/ level_cmd_create_painting_warp_node,
/*28*/ level_cmd_create_instant_warp,
/*29*/ level_cmd_load_area,
/*2A*/ level_cmd_unload_area,
/*2B*/ level_cmd_set_mario_start_pos,
/*2C*/ level_cmd_2C,
/*2D*/ level_cmd_2D,
/*2E*/ level_cmd_set_terrain_data,
/*2F*/ level_cmd_set_rooms,
/*30*/ level_cmd_show_dialog,
/*31*/ level_cmd_set_terrain_type,
/*32*/ level_cmd_nop,
/*33*/ level_cmd_set_transition,
/*34*/ level_cmd_set_blackout,
/*35*/ level_cmd_set_gamma,
/*36*/ level_cmd_set_music,
/*37*/ level_cmd_set_menu_music,
/*38*/ level_cmd_38,
/*39*/ level_cmd_set_macro_objects,
/*3A*/ level_cmd_3A,
/*3B*/ level_cmd_create_whirlpool,
/*3C*/ level_cmd_get_or_set_var,
/*3D*/ level_cmd_puppyvolume,
/*3E*/ level_cmd_change_area_skybox,
/*3F*/ level_cmd_puppylight_environment,
/*40*/ level_cmd_puppylight_node,
/*LEVEL_CMD_LOAD_AND_EXECUTE */ level_cmd_load_and_execute,
/*LEVEL_CMD_EXIT_AND_EXECUTE */ level_cmd_exit_and_execute,
/*LEVEL_CMD_EXIT */ level_cmd_exit,
/*LEVEL_CMD_SLEEP */ level_cmd_sleep,
/*LEVEL_CMD_SLEEP2 */ level_cmd_sleep2,
/*LEVEL_CMD_JUMP */ level_cmd_jump,
/*LEVEL_CMD_JUMP_AND_LINK */ level_cmd_jump_and_link,
/*LEVEL_CMD_RETURN */ level_cmd_return,
/*LEVEL_CMD_JUMP_AND_LINK_PUSH_ARG */ level_cmd_jump_and_link_push_arg,
/*LEVEL_CMD_JUMP_REPEAT */ level_cmd_jump_repeat,
/*LEVEL_CMD_LOOP_BEGIN */ level_cmd_loop_begin,
/*LEVEL_CMD_LOOP_UNTIL */ level_cmd_loop_until,
/*LEVEL_CMD_JUMP_IF */ level_cmd_jump_if,
/*LEVEL_CMD_JUMP_AND_LINK_IF */ level_cmd_jump_and_link_if,
/*LEVEL_CMD_SKIP_IF */ level_cmd_skip_if,
/*LEVEL_CMD_SKIP */ level_cmd_skip,
/*LEVEL_CMD_SKIPPABLE_NOP */ level_cmd_skippable_nop,
/*LEVEL_CMD_CALL */ level_cmd_call,
/*LEVEL_CMD_CALL_LOOP */ level_cmd_call_loop,
/*LEVEL_CMD_SET_REGISTER */ level_cmd_set_register,
/*LEVEL_CMD_PUSH_POOL_STATE */ level_cmd_push_pool_state,
/*LEVEL_CMD_POP_POOL_STATE */ level_cmd_pop_pool_state,
/*LEVEL_CMD_LOAD_TO_FIXED_ADDRESS */ level_cmd_load_to_fixed_address,
/*LEVEL_CMD_LOAD_RAW */ level_cmd_load_raw,
/*LEVEL_CMD_LOAD_YAY0 */ level_cmd_load_yay0,
/*LEVEL_CMD_LOAD_MARIO_HEAD */ level_cmd_load_mario_head,
/*LEVEL_CMD_LOAD_YAY0_TEXTURE */ level_cmd_load_yay0_texture,
/*LEVEL_CMD_INIT_LEVEL */ level_cmd_init_level,
/*LEVEL_CMD_CLEAR_LEVEL */ level_cmd_clear_level,
/*LEVEL_CMD_ALLOC_LEVEL_POOL */ level_cmd_alloc_level_pool,
/*LEVEL_CMD_FREE_LEVEL_POOL */ level_cmd_free_level_pool,
/*LEVEL_CMD_BEGIN_AREA */ level_cmd_begin_area,
/*LEVEL_CMD_END_AREA */ level_cmd_end_area,
/*LEVEL_CMD_LOAD_MODEL_FROM_DL */ level_cmd_load_model_from_dl,
/*LEVEL_CMD_LOAD_MODEL_FROM_GEO */ level_cmd_load_model_from_geo,
/*LEVEL_CMD_23 */ level_cmd_23,
/*LEVEL_CMD_PLACE_OBJECT */ level_cmd_place_object,
/*LEVEL_CMD_INIT_MARIO */ level_cmd_init_mario,
/*LEVEL_CMD_CREATE_WARP_NODE */ level_cmd_create_warp_node,
/*LEVEL_CMD_CREATE_PAINTING_WARP_NODE */ level_cmd_create_painting_warp_node,
/*LEVEL_CMD_CREATE_INSTANT_WARP */ level_cmd_create_instant_warp,
/*LEVEL_CMD_LOAD_AREA */ level_cmd_load_area,
/*LEVEL_CMD_UNLOAD_AREA */ level_cmd_unload_area,
/*LEVEL_CMD_SET_MARIO_START_POS */ level_cmd_set_mario_start_pos,
/*LEVEL_CMD_UNLOAD_MARIO_AREA */ level_cmd_unload_mario_area,
/*LEVEL_CMD_UPDATE_OBJECTS */ level_cmd_update_objects,
/*LEVEL_CMD_SET_TERRAIN_DATA */ level_cmd_set_terrain_data,
/*LEVEL_CMD_SET_ROOMS */ level_cmd_set_rooms,
/*LEVEL_CMD_SHOW_DIALOG */ level_cmd_show_dialog,
/*LEVEL_CMD_SET_TERRAIN_TYPE */ level_cmd_set_terrain_type,
/*LEVEL_CMD_NOP */ level_cmd_nop,
/*LEVEL_CMD_SET_TRANSITION */ level_cmd_set_transition,
/*LEVEL_CMD_SET_BLACKOUT */ level_cmd_set_blackout,
/*LEVEL_CMD_SET_GAMMA */ level_cmd_set_gamma,
/*LEVEL_CMD_SET_MUSIC */ level_cmd_set_music,
/*LEVEL_CMD_SET_MENU_MUSIC */ level_cmd_set_menu_music,
/*LEVEL_CMD_FADEOUT_MUSIC */ level_cmd_fadeout_music,
/*LEVEL_CMD_SET_MACRO_OBJECTS */ level_cmd_set_macro_objects,
/*LEVEL_CMD_3A */ level_cmd_3A,
/*LEVEL_CMD_CREATE_WHIRLPOOL */ level_cmd_create_whirlpool,
/*LEVEL_CMD_GET_OR_SET_VAR */ level_cmd_get_or_set_var,
/*LEVEL_CMD_PUPPYVOLUME */ level_cmd_puppyvolume,
/*LEVEL_CMD_CHANGE_AREA_SKYBOX */ level_cmd_change_area_skybox,
/*LEVEL_CMD_PUPPYLIGHT_ENVIRONMENT */ level_cmd_puppylight_environment,
/*LEVEL_CMD_PUPPYLIGHT_NODE */ level_cmd_puppylight_node,
};
struct LevelCommand *level_script_execute(struct LevelCommand *cmd) {
+771 -471
View File
File diff suppressed because it is too large. Load diff
+132 -59
View File
@@ -8,6 +8,8 @@
#define NEAR_ZERO __FLT_EPSILON__
#define NEAR_ONE (1.0f - __FLT_EPSILON__)
#define FLOAT_ONE 0x3F800000
extern Vec3f gVec3fX;
extern Vec3f gVec3fY;
extern Vec3f gVec3fZ;
@@ -24,7 +26,9 @@ extern Vec3s gVec3sOne;
* Converts an angle in degrees to sm64's s16 angle units. For example, DEGREES(90) == 0x4000
* This should be used mainly to make camera code clearer at first glance.
*/
#define DEGREES(x) ((x) * 0x10000 / 360)
// #define DEGREES(x) ((x) * 0x10000 / 360)
#define DEGREES(x) ((x) * 0x2000 / 45)
// #define DEGREES(x) (((x) << 13) / 45)
/*
* The sine and cosine tables overlap, but "#define gCosineTable (gSineTable +
@@ -41,12 +45,14 @@ extern Vec3s gVec3sOne;
extern f32 gSineTable[];
#define gCosineTable (gSineTable + 0x400)
#define sins(x) gSineTable[(u16) (x) >> 4]
#define sins(x) gSineTable[ (u16) (x) >> 4]
#define coss(x) gCosineTable[(u16) (x) >> 4]
#define tans(x) (sins(x) / coss(x))
#define cots(x) (coss(x) / sins(x))
#define atans(x) gArctanTable[(s32)((((x) * 1024) + 0.5f))] // is this correct? used for atan2_lookup
#define DEG_PER_RAD 57.29577950560105
#define RAD_PER_DEG (1.0 / DEG_PER_RAD)
#define RAD_PER_DEG (M_PI / 180.0f)
#define DEG_PER_RAD (180.0f / M_PI)
#define angle_to_degrees( x) (f32)(((Angle)(x) / 65536.0f) * 360.0f)
#define degrees_to_angle( x) (Angle)(((f32)(x) * 0x10000 ) / 360 )
@@ -55,17 +61,10 @@ extern f32 gSineTable[];
#define degrees_to_radians(x) (f32)( (f32)(x) * RAD_PER_DEG )
#define radians_to_degrees(x) (f32)( (f32)(x) * DEG_PER_RAD )
#define ABSF(x) ((x) > 0.0f ? (x) : -(x))
#define ABSI(x) ((x) > 0 ? (x) : -(x))
#define ABS(x) ABSF((x))
// #define absf(x) ABSF((x))
#define absi(x) ABSI((x))
#define abs(x) ABS((x))
#define signum_positive(x) ((x < 0) ? -1 : 1)
#define min(a, b) MIN((a), (b)) // ((a) < (b) ? (a) : (b))
#define max(a, b) MAX((a), (b)) // ((a) > (b) ? (a) : (b))
// #define min(a, b) MIN((a), (b)) // ((a) < (b) ? (a) : (b))
// #define max(a, b) MAX((a), (b)) // ((a) > (b) ? (a) : (b))
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
// from limits.h
@@ -144,6 +143,16 @@ extern f32 gSineTable[];
(dst)[2] = (((a)[0] * (b)[1]) - ((a)[1] * (b)[0])); \
}
/**
* Set 'dest' the normal vector of a triangle with vertices a, b and c.
* Equivalent to cross((c-b), (c-a)).
*/
#define find_vector_perpendicular_to_plane(dest, a, b, c) { \
(dest)[0] = ((b)[1] - (a)[1]) * ((c)[2] - (b)[2]) - ((c)[1] - (b)[1]) * ((b)[2] - (a)[2]); \
(dest)[1] = ((b)[2] - (a)[2]) * ((c)[0] - (b)[0]) - ((c)[2] - (b)[2]) * ((b)[0] - (a)[0]); \
(dest)[2] = ((b)[0] - (a)[0]) * ((c)[1] - (b)[1]) - ((c)[0] - (b)[0]) * ((b)[1] - (a)[1]); \
}
/**
* | ? ? ? 0 |
* | ? ? ? 0 |
@@ -159,7 +168,7 @@ extern f32 gSineTable[];
}
#define linear_mtxf_mul_vec3_and_translate(mtx, dstV, srcV) { \
linear_mtxf_mul_vec3f((mtx), (dstV), (srcV)); \
linear_mtxf_mul_vec3((mtx), (dstV), (srcV)); \
vec3_add((dstV), (mtx)[3]); \
}
@@ -417,29 +426,20 @@ extern f32 gSineTable[];
MAT4_DOT_PROD((R), (A), (B), 3, 3); \
}
#define MTXF_END(mtx) { \
(mtx)[0][3] = 0.0f; \
(mtx)[1][3] = 0.0f; \
(mtx)[2][3] = 0.0f; \
(mtx)[3][3] = 1.0f; \
#define MTXF_END(mtx) { \
(mtx)[0][3] = (mtx)[1][3] = (mtx)[2][3] = 0;\
((u32 *)(mtx))[15] = FLOAT_ONE; \
}
#define NAME_INVMAG(v) v##_invmag
/// Scale vector 'v' so it has length 1
/// Scale vector 'v' so it has length 1
#define vec3_normalize(v) { \
register f32 NAME_INVMAG(v) = vec3_mag((v)); \
NAME_INVMAG(v) = (1.0f / MAX(NAME_INVMAG(v), NEAR_ZERO)); \
vec3_mul_val((v), NAME_INVMAG(v)); \
}
/// Scale vector 'v' so it has length -1
#define vec3_normalize_negative(v) { \
register f32 v##_invmag = vec3_mag((v)); \
v##_invmag = -(1.0f / MAX(v##_invmag, NEAR_ZERO)); \
vec3_mul_val((v), v##_invmag); \
}
#define vec3_normalize_max(v, max) { \
register f32 v##_mag = vec3_mag(v); \
v##_mag = MAX(v##_mag, NEAR_ZERO); \
@@ -449,45 +449,118 @@ extern f32 gSineTable[];
} \
}
f32 roundf(f32 x);
f32 absf(f32 x);
s32 min_3i(s32 a0, s32 a1, s32 a2);
f32 min_3f(f32 a0, f32 a1, f32 a2);
s32 max_3i(s32 a0, s32 a1, s32 a2);
f32 max_3f(f32 a0, f32 a1, f32 a2);
void vec3f_copy(Vec3f dest, Vec3f src);
void vec3f_set(Vec3f dest, f32 x, f32 y, f32 z);
void vec3f_add(Vec3f dest, Vec3f a);
void vec3f_sum(Vec3f dest, Vec3f a, Vec3f b);
void vec3s_copy(Vec3s dest, Vec3s src);
void vec3s_set(Vec3s dest, s16 x, s16 y, s16 z);
void vec3s_add(Vec3s dest, Vec3s a);
void vec3s_sum(Vec3s dest, Vec3s a, Vec3s b);
void vec3s_sub(Vec3s dest, Vec3s a);
void vec3f_sub(Vec3f dest, Vec3f src);
void vec3f_diff(Vec3f dest, Vec3f a, Vec3f b);
void vec3f_to_vec3s(Vec3s dest, Vec3f a);
void find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c);
f32 vec3f_dot(Vec3f a, Vec3f b);
void vec3f_cross(Vec3f dest, Vec3f a, Vec3f b);
#define ABS(x) (((x) > 0) ? (x) : -(x))
/// From Wiseguy
ALWAYS_INLINE s32 roundf(f32 in) {
f32 tmp;
s32 out;
__asm__("round.w.s %0,%1" : "=f" (tmp) : "f" (in ));
__asm__("mfc1 %0,%1" : "=r" (out) : "f" (tmp));
return out;
}
// backwards compatibility
#define round_float(in) roundf(in)
/// Absolute value
ALWAYS_INLINE f32 absf(f32 in) {
f32 out;
__asm__("abs.s %0,%1" : "=f" (out) : "f" (in));
return out;
}
ALWAYS_INLINE s32 absi(s32 in) {
return ABS(in);
}
#define abss absi
#define FLT_IS_NONZERO(x) (absf(x) > NEAR_ZERO)
u32 random_u16(void);
f32 random_float(void);
s32 random_sign(void);
f32 min_3f( f32 a, f32 b, f32 c);
s32 min_3i( s32 a, s32 b, s32 c);
s32 min_3s( s16 a, s16 b, s16 c);
f32 max_3f( f32 a, f32 b, f32 c);
s32 max_3i( s32 a, s32 b, s32 c);
s32 max_3s( s16 a, s16 b, s16 c);
void min_max_3f(f32 a, f32 b, f32 c, f32 *min, f32 *max);
void min_max_3i(s32 a, s32 b, s32 c, s32 *min, s32 *max);
void min_max_3s(s16 a, s16 b, s16 c, s16 *min, s16 *max);
void vec3f_copy (Vec3f dest, const Vec3f src);
void vec3i_copy (Vec3i dest, const Vec3i src);
void vec3s_copy (Vec3s dest, const Vec3s src);
void vec3s_to_vec3i(Vec3i dest, const Vec3s src);
void vec3s_to_vec3f(Vec3f dest, const Vec3s src);
void vec3i_to_vec3s(Vec3s dest, const Vec3i src);
void vec3i_to_vec3f(Vec3f dest, const Vec3i src);
void vec3f_to_vec3s(Vec3s dest, const Vec3f src);
void vec3f_to_vec3i(Vec3i dest, const Vec3f src);
void vec3f_copy_y_off(Vec3f dest, Vec3f src, f32 yOff);
void surface_normal_to_vec3f(Vec3f dest, struct Surface *surf);
void vec3f_set(Vec3f dest, const f32 x, const f32 y, const f32 z);
void vec3i_set(Vec3i dest, const s32 x, const s32 y, const s32 z);
void vec3s_set(Vec3s dest, const s16 x, const s16 y, const s16 z);
void vec3f_add (Vec3f dest, const Vec3f a );
void vec3i_add (Vec3i dest, const Vec3i a );
void vec3s_add (Vec3s dest, const Vec3s a );
void vec3f_sum (Vec3f dest, const Vec3f a, const Vec3f b);
void vec3i_sum (Vec3i dest, const Vec3i a, const Vec3i b);
void vec3s_sum (Vec3s dest, const Vec3s a, const Vec3s b);
void vec3f_sub (Vec3f dest, const Vec3f a );
void vec3i_sub (Vec3i dest, const Vec3i a );
void vec3s_sub (Vec3s dest, const Vec3s a );
void vec3f_diff(Vec3f dest, const Vec3f a, const Vec3f b);
void vec3i_diff(Vec3i dest, const Vec3i a, const Vec3i b);
void vec3s_diff(Vec3s dest, const Vec3s a, const Vec3s b);
void vec3f_mul (Vec3f dest, const Vec3f a );
void vec3i_mul (Vec3i dest, const Vec3i a );
void vec3s_mul (Vec3s dest, const Vec3s a );
void vec3f_prod(Vec3f dest, const Vec3f a, const Vec3f b);
void vec3i_prod(Vec3i dest, const Vec3i a, const Vec3i b);
void vec3s_prod(Vec3s dest, const Vec3s a, const Vec3s b);
void vec3f_div (Vec3f dest, const Vec3f a );
void vec3i_div (Vec3i dest, const Vec3i a );
void vec3s_div (Vec3s dest, const Vec3s a );
void vec3f_quot(Vec3f dest, const Vec3f a, const Vec3f b);
void vec3i_quot(Vec3i dest, const Vec3i a, const Vec3i b);
void vec3s_quot(Vec3s dest, const Vec3s a, const Vec3s b);
f32 vec3f_dot( const Vec3f a, const Vec3f b);
void vec3f_cross(Vec3f dest, const Vec3f a, const Vec3f b);
void vec3f_normalize(Vec3f dest);
void mtxf_copy(Mat4 dest, Mat4 src);
void mtxf_identity(Mat4 mtx);
void mtxf_translate(Mat4 dest, Vec3f b);
void mtxf_lookat(Mat4 mtx, Vec3f from, Vec3f to, s32 roll);
void mtxf_rotate_zxy_and_translate(Mat4 dest, Vec3f translate, Vec3s rotate);
void mtxf_rotate_xyz_and_translate(Mat4 dest, Vec3f b, Vec3s c);
void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s32 angle);
void mtxf_rotate_zxy_and_translate(Mat4 dest, Vec3f trans, Vec3s rot);
void mtxf_rotate_xyz_and_translate(Mat4 dest, Vec3f trans, Vec3s rot);
void mtxf_rotate_zxy_and_translate_and_mul(Vec3s rot, Vec3f trans, Mat4 dest, Mat4 src);
void mtxf_rotate_xyz_and_translate_and_mul(Vec3s rot, Vec3f trans, Mat4 dest, Mat4 src);
void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, Vec3f scale, s32 angle);
void mtxf_shadow(Mat4 dest, Mat4 src, Vec3f upDir, Vec3f pos, Vec3f scale, s32 yaw);
void mtxf_align_terrain_normal(Mat4 dest, Vec3f upDir, Vec3f pos, s32 yaw);
void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s32 yaw, f32 radius);
void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b);
void mtxf_scale_vec3f(Mat4 dest, Mat4 mtx, Vec3f s);
void mtxf_mul_vec3s(Mat4 mtx, Vec3s b);
extern void mtxf_to_mtx_asm(register void *dest, register void *src);
inline void mtxf_to_mtx(register void *dest, register void *src) {
mtxf_to_mtx_asm(dest, src);
extern void mtxf_to_mtx_fast(register s16 *dest, register float *src);
ALWAYS_INLINE void mtxf_to_mtx(register void *dest, register void *src) {
mtxf_to_mtx_fast((s16*)dest, (float*)src);
// guMtxF2L(src, dest);
}
void mtxf_rotate_xy(Mtx *mtx, s32 angle);
void linear_mtxf_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v);
void linear_mtxf_mul_vec3f_and_translate(Mat4 m, Vec3f dst, Vec3f v);
void linear_mtxf_transpose_mul_vec3f(Mat4 m, Vec3f dst, Vec3f v);
void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx);
void vec2f_get_lateral_dist( Vec2f from, Vec2f to, f32 *lateralDist );
@@ -503,8 +576,9 @@ void vec3f_get_lateral_dist_and_pitch( Vec3f from, Vec3f to,
void vec3f_get_lateral_dist_and_yaw( Vec3f from, Vec3f to, f32 *lateralDist, Angle *yaw);
void vec3f_get_lateral_dist_and_angle( Vec3f from, Vec3f to, f32 *lateralDist, Angle *pitch, Angle *yaw);
void vec3f_get_dist_and_lateral_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, f32 *lateralDist, Angle *pitch, Angle *yaw);
void vec3s_get_dist_and_angle( Vec3s from, Vec3s to, s16 *dist, Angle *pitch, Angle *yaw);
void vec3f_get_dist_and_angle( Vec3f from, Vec3f to, f32 *dist, Angle *pitch, Angle *yaw);
void vec3s_get_dist_and_angle( Vec3s from, Vec3s to, s16 *dist, Angle *pitch, Angle *yaw);
void vec3f_to_vec3s_get_dist_and_angle( Vec3f from, Vec3s to, f32 *dist, Angle *pitch, Angle *yaw);
void vec3s_set_dist_and_angle( Vec3s from, Vec3s to, s16 dist, Angle32 pitch, Angle32 yaw);
void vec3f_set_dist_and_angle( Vec3f from, Vec3f to, f32 dist, Angle32 pitch, Angle32 yaw);
@@ -527,13 +601,12 @@ s32 approach_f32_asymptotic_bool(f32 *current, f32 target, f32 multiplier);
f32 approach_f32_asymptotic(f32 current, f32 target, f32 multiplier);
s32 approach_s16_asymptotic_bool(s16 *current, s16 target, s16 divisor);
s32 approach_s16_asymptotic(s16 current, s16 target, s16 divisor);
s16 abs_angle_diff(s16 a0, s16 a1);
s16 atan2s(f32 y, f32 x);
s32 abs_angle_diff(s16 a0, s16 a1);
s32 atan2s(f32 y, f32 x);
f32 atan2f(f32 a, f32 b);
void spline_get_weights(Vec4f result, f32 t, UNUSED s32 c);
void anim_spline_init(Vec4s *keyFrames);
s32 anim_spline_poll(Vec3f result);
void mtxf_rot_trans_mul(Vec3s rot, Vec3f trans, Mat4 dest, Mat4 src);
s32 anim_spline_poll(Vec3f result);
void find_surface_on_ray(Vec3f orig, Vec3f dir, struct Surface **hit_surface, Vec3f hit_pos, s32 flags);
#endif // MATH_UTIL_H
+303 -221
View File
@@ -15,7 +15,7 @@
**************************************************/
#define CALC_OFFSET(vert, next_step) { \
if ((vert)[1] != 0.0f) { \
if (FLT_IS_NONZERO((vert)[1])) { \
v = (v2[1] / (vert)[1]); \
if ((v < 0.0f) || (v > 1.0f)) next_step;\
d00 = (((vert)[0] * v) - v2[0]); \
@@ -37,105 +37,133 @@ static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode, struc
register struct Surface *surf;
register f32 offset;
register f32 radius = data->radius;
register Vec3f pos = { data->x, data->y + data->offsetY, data->z };
register Vec3f v0, v1, v2;
Vec3f pos = { data->x, data->y + data->offsetY, data->z };
Vec3f v0, v1, v2;
register f32 d00, d01, d11, d20, d21;
register f32 invDenom;
register f32 v, w;
register f32 margin_radius = (radius - 1.0f);
register TerrainData type = SURFACE_DEFAULT;
s32 numCols = 0;
// Max collision radius = 200
if (radius > 200.0f) {
radius = 200.0f;
if (radius > 200) {
radius = 200;
}
f32 margin_radius = radius - 1.0f;
// Stay in this loop until out of walls.
while (surfaceNode != NULL) {
surf = surfaceNode->surface;
surfaceNode = surfaceNode->next;
type = surf->type;
// Exclude a large number of walls immediately to optimize.
if (SURFACE_IS_NEW_WATER(type)) continue;
if (pos[1] < surf->lowerY || pos[1] > surf->upperY) continue;
// Determine if checking for the camera or not.
if (gCheckingSurfaceCollisionsForCamera) {
if (gCollisionFlags & COLLISION_FLAG_CAMERA) {
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) continue;
} else {
// Ignore camera only surfaces.
if (type == SURFACE_CAMERA_BOUNDARY) continue;
// If an object can pass through a vanish cap wall, pass through.
if (type == SURFACE_VANISH_CAP_WALLS && gCurrentObject != NULL) {
if (type == SURFACE_VANISH_CAP_WALLS && o != NULL) {
// If an object can pass through a vanish cap wall, pass through.
if (gCurrentObject->activeFlags & ACTIVE_FLAG_MOVE_THROUGH_GRATE) continue;
if (o->activeFlags & ACTIVE_FLAG_MOVE_THROUGH_GRATE) continue;
// If Mario has a vanish cap, pass through the vanish cap wall.
if (gCurrentObject == gMarioObject && (gMarioState->flags & MARIO_VANISH_CAP)) continue;
if (o == gMarioObject && gMarioState->flags & MARIO_VANISH_CAP) continue;
}
}
if (pos[1] < surf->lowerY || pos[1] > surf->upperY) continue;
// Dot of normal and pos, + origin offset
offset = (surf->normal.x * pos[0]) + (surf->normal.y * pos[1]) + (surf->normal.z * pos[2]) + surf->originOffset;
// Exclude surfaces outside of the radius.
if (offset < -radius || offset > radius) continue;
vec3_diff(v0, surf->vertex2, surf->vertex1);
vec3_diff(v1, surf->vertex3, surf->vertex1);
vec3_diff(v2, pos, surf->vertex1);
// Face
d00 = vec3_dot(v0, v0);
d01 = vec3_dot(v0, v1);
d11 = vec3_dot(v1, v1);
d20 = vec3_dot(v2, v0);
d21 = vec3_dot(v2, v1);
invDenom = 1.0f / ((d00 * d11) - (d01 * d01));
invDenom = (d00 * d11) - (d01 * d01);
if (FLT_IS_NONZERO(invDenom)) invDenom = 1.0f / invDenom;
v = ((d11 * d20) - (d01 * d21)) * invDenom;
if (v < 0.0f || v > 1.0f) goto edge_1_2;
w = ((d00 * d21) - (d01 * d20)) * invDenom;
if (w < 0.0f || w > 1.0f || v + w > 1.0f) goto edge_1_2;
pos[0] += surf->normal.x * (radius - offset);
pos[2] += surf->normal.z * (radius - offset);
goto hasCollision;
edge_1_2:
if (offset < 0) continue;
CALC_OFFSET(v0, goto edge_1_3);
edge_1_3:
CALC_OFFSET(v1, goto edge_2_3);
edge_2_3:
vec3_diff(v1, surf->vertex3, surf->vertex2);
vec3_diff(v2, pos, surf->vertex2);
CALC_OFFSET(v1, continue);
check_collision:
invDenom = offset / invDenom;
if (FLT_IS_NONZERO(invDenom)) invDenom = (offset / invDenom);
pos[0] += (d00 *= invDenom);
pos[2] += (d01 *= invDenom);
margin_radius += 0.01f;
if ((d00 * surf->normal.x) + (d01 * surf->normal.z) < (corner_threshold * offset)) continue;
hasCollision:
// (Unreferenced Walls) Since this only returns the first MAX_REFEREMCED_WALLS walls,
// this can lead to wall interaction being missed. Typically unreferenced walls
// come from only using one wall, however.
if (data->numWalls < MAX_REFEREMCED_WALLS) {
if (data->numWalls < MAX_REFERENCED_WALLS) {
data->walls[data->numWalls++] = surf;
}
numCols++;
if (gCollisionFlags & COLLISION_FLAG_RETURN_FIRST) {
break;
}
}
data->x = pos[0];
data->z = pos[2];
return numCols;
}
#undef CALC_OFFSET
/**
* Formats the position and wall search for find_wall_collisions.
*/
s32 f32_find_wall_collision(f32 *xPtr, f32 *yPtr, f32 *zPtr, f32 offsetY, f32 radius) {
struct WallCollisionData collision;
s32 numCollisions = 0;
collision.offsetY = offsetY;
collision.radius = radius;
collision.x = *xPtr;
collision.y = *yPtr;
collision.z = *zPtr;
collision.offsetY = offsetY;
collision.radius = radius;
collision.x = *xPtr;
collision.y = *yPtr;
collision.z = *zPtr;
collision.numWalls = 0;
numCollisions = find_wall_collisions(&collision);
*xPtr = collision.x;
*yPtr = collision.y;
*zPtr = collision.z;
s32 numCollisions = find_wall_collisions(&collision);
*xPtr = collision.x;
*yPtr = collision.y;
*zPtr = collision.z;
return numCollisions;
}
@@ -144,7 +172,6 @@ s32 f32_find_wall_collision(f32 *xPtr, f32 *yPtr, f32 *zPtr, f32 offsetY, f32 ra
*/
s32 find_wall_collisions(struct WallCollisionData *colData) {
struct SurfaceNode *node;
s32 cellX, cellZ;
s32 numCollisions = 0;
s32 x = colData->x;
s32 z = colData->z;
@@ -155,24 +182,31 @@ s32 find_wall_collisions(struct WallCollisionData *colData) {
colData->numWalls = 0;
if (is_outside_level_bounds(x, z)) {
#if PUPPYPRINT_DEBUG
collisionTime[perfIteration] += osGetTime() - first;
#endif
return numCollisions;
}
// World (level) consists of a 16x16 grid. Find where the collision is on the grid (round toward -inf)
cellX = GET_CELL_COORD(x);
cellZ = GET_CELL_COORD(z);
s32 cellX = GET_CELL_COORD(x);
s32 cellZ = GET_CELL_COORD(z);
// Check for surfaces belonging to objects.
node = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WALLS].next;
numCollisions += find_wall_collisions_from_list(node, colData);
if (!(gCollisionFlags & COLLISION_FLAG_EXCLUDE_DYNAMIC)) {
// Check for surfaces belonging to objects.
node = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WALLS].next;
numCollisions += find_wall_collisions_from_list(node, colData);
}
// Check for surfaces that are a part of level geometry.
node = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WALLS].next;
numCollisions += find_wall_collisions_from_list(node, colData);
gCollisionFlags &= ~(COLLISION_FLAG_RETURN_FIRST | COLLISION_FLAG_EXCLUDE_DYNAMIC | COLLISION_FLAG_INCLUDE_INTANGIBLE);
#ifdef VANILLA_DEBUG
// Increment the debug tracker.
gNumCalls.wall++;
#endif
#if PUPPYPRINT_DEBUG
collisionTime[perfIteration] += osGetTime() - first;
#endif
@@ -202,61 +236,86 @@ void resolve_and_return_wall_collisions(Vec3f pos, f32 offset, f32 radius, struc
**************************************************/
void add_ceil_margin(s32 *x, s32 *z, Vec3s target1, Vec3s target2, f32 margin) {
register f32 diff_x, diff_z, invDenom;
diff_x = target1[0] - *x + target2[0] - *x;
diff_z = target1[2] - *z + target2[2] - *z;
invDenom = margin / sqrtf(sqr(diff_x) + sqr(diff_z));
register f32 diff_x = target1[0] - *x + target2[0] - *x;
register f32 diff_z = target1[2] - *z + target2[2] - *z;
register f32 invDenom = margin / sqrtf(sqr(diff_x) + sqr(diff_z));
*x += diff_x * invDenom;
*z += diff_z * invDenom;
}
static s32 check_within_ceil_triangle_bounds(s32 x, s32 z, struct Surface *surf, f32 margin) {
s32 addMargin = surf->type != SURFACE_HANGABLE && !FLT_IS_NONZERO(margin);
Vec3i vx, vz;
vx[0] = surf->vertex1[0];
vz[0] = surf->vertex1[2];
if (addMargin) add_ceil_margin(&vx[0], &vz[0], surf->vertex2, surf->vertex3, margin);
vx[1] = surf->vertex2[0];
vz[1] = surf->vertex2[2];
if (addMargin) add_ceil_margin(&vx[1], &vz[1], surf->vertex3, surf->vertex1, margin);
// Checking if point is in bounds of the triangle laterally.
if (((vz[0] - z) * (vx[1] - vx[0]) - (vx[0] - x) * (vz[1] - vz[0])) > 0) return FALSE;
// Slight optimization by checking these later.
vx[2] = surf->vertex3[0];
vz[2] = surf->vertex3[2];
if (addMargin) add_ceil_margin(&vx[2], &vz[2], surf->vertex1, surf->vertex2, margin);
if (((vz[1] - z) * (vx[2] - vx[1]) - (vx[1] - x) * (vz[2] - vz[1])) > 0) return FALSE;
if (((vz[2] - z) * (vx[0] - vx[2]) - (vx[2] - x) * (vz[0] - vz[2])) > 0) return FALSE;
return TRUE;
}
/**
* Iterate through the list of ceilings and find the first ceiling over a given point.
*/
static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, s32 x, s32 y, s32 z, f32 *pheight) {
const f32 margin = 1.5f;
register struct Surface *surf, *ceil = NULL;
Vec3i vx, vz;
f32 height;
s16 type;
register f32 height;
SurfaceType type = SURFACE_DEFAULT;
*pheight = CELL_HEIGHT_LIMIT;
// Stay in this loop until out of ceilings.
while (surfaceNode != NULL) {
surf = surfaceNode->surface;
surfaceNode = surfaceNode->next;
type = surf->type;
// Determine if checking for the camera or not.
if (SURFACE_IS_NEW_WATER(type)) continue;
if (gCheckingSurfaceCollisionsForCamera) {
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) continue;
// Exclude all ceilings below the point
if (y > surf->upperY) continue;
// Determine if checking for the camera or not
if (gCollisionFlags & COLLISION_FLAG_CAMERA) {
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) {
continue;
}
} else if (type == SURFACE_CAMERA_BOUNDARY) {
// Ignore camera only surfaces.
// Ignore camera only surfaces
continue;
}
if (y > surf->upperY) continue;
vx[0] = surf->vertex1[0];
vz[0] = surf->vertex1[2];
if (surf->type != SURFACE_HANGABLE) add_ceil_margin(&vx[0], &vz[0], surf->vertex2, surf->vertex3, margin);
vx[1] = surf->vertex2[0];
vz[1] = surf->vertex2[2];
if (surf->type != SURFACE_HANGABLE) add_ceil_margin(&vx[1], &vz[1], surf->vertex3, surf->vertex1, margin);
// Checking if point is in bounds of the triangle laterally.
if ((vz[0] - z) * (vx[1] - vx[0]) - (vx[0] - x) * (vz[1] - vz[0]) > 0) continue;
// Slight optimization by checking these later.
vx[2] = surf->vertex3[0];
vz[2] = surf->vertex3[2];
if (surf->type != SURFACE_HANGABLE) add_ceil_margin(&vx[2], &vz[2], surf->vertex1, surf->vertex2, margin);
if ((vz[1] - z) * (vx[2] - vx[1]) - (vx[1] - x) * (vz[2] - vz[1]) > 0) continue;
if ((vz[2] - z) * (vx[0] - vx[2]) - (vx[2] - x) * (vz[0] - vz[2]) > 0) continue;
// Find the ceil height at the specific point.
// Check that the point is within the triangle bounds
if (!check_within_ceil_triangle_bounds(x, z, surf, 1.5f)) continue;
// Find the height of the ceil at the given location
height = get_surface_height_at_location(x, z, surf);
// Exclude ceilings above the previous lowest ceiling
if (height > *pheight) continue;
// Checks for ceiling interaction
if (y > height) continue;
if (y >= surf->upperY) continue;
// Use the current ceiling
*pheight = height;
ceil = surf;
if (height == y) break;
// Exit the loop if it's not possible for another ceiling to be closer
// to the original point, or if COLLISION_FLAG_RETURN_FIRST.
if (height == y || (gCollisionFlags & COLLISION_FLAG_RETURN_FIRST)) break;
}
return ceil;
}
@@ -265,46 +324,61 @@ static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, s32
* Find the lowest ceiling above a given position and return the height.
*/
f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct Surface **pceil) {
s32 cellZ, cellX;
struct Surface *ceil, *dynamicCeil;
struct SurfaceNode *surfaceList;
f32 height = CELL_HEIGHT_LIMIT;
f32 height = CELL_HEIGHT_LIMIT;
f32 dynamicHeight = CELL_HEIGHT_LIMIT;
s32 x, y, z;
#if PUPPYPRINT_DEBUG
OSTime first = osGetTime();
#endif
x = posX;
y = posY;
z = posZ;
s32 x = posX;
s32 y = posY;
s32 z = posZ;
*pceil = NULL;
if (is_outside_level_bounds(x, z)) {
#if PUPPYPRINT_DEBUG
collisionTime[perfIteration] += (osGetTime() - first);
#endif
return height;
}
// Each level is split into cells to limit load, find the appropriate cell.
cellX = GET_CELL_COORD(x);
cellZ = GET_CELL_COORD(z);
s32 cellX = GET_CELL_COORD(x);
s32 cellZ = GET_CELL_COORD(z);
// Check for surfaces belonging to objects.
surfaceList = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_CEILS].next;
dynamicCeil = find_ceil_from_list(surfaceList, x, y, z, &dynamicHeight);
struct SurfaceNode *surfaceList;
struct Surface *ceil = NULL;
struct Surface *dynamicCeil = NULL;
s32 includeDynamic = !(gCollisionFlags & COLLISION_FLAG_EXCLUDE_DYNAMIC);
if (includeDynamic) {
// Check for surfaces belonging to objects.
surfaceList = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_CEILS].next;
dynamicCeil = find_ceil_from_list(surfaceList, x, y, z, &dynamicHeight);
// In the next check, only check for ceilings lower than the previous check.
height = dynamicHeight;
}
// Check for surfaces that are a part of level geometry.
surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_CEILS].next;
ceil = find_ceil_from_list(surfaceList, x, y, z, &height);
if (dynamicHeight < height) {
ceil = dynamicCeil;
// Use the lower ceiling.
if (includeDynamic && height >= dynamicHeight) {
ceil = dynamicCeil;
height = dynamicHeight;
}
*pceil = ceil;
// To prevent accidentally leaving the floor tangible, stop checking for it.
gCollisionFlags &= ~(COLLISION_FLAG_RETURN_FIRST | COLLISION_FLAG_EXCLUDE_DYNAMIC | COLLISION_FLAG_INCLUDE_INTANGIBLE);
// Return the ceiling.
*pceil = ceil;
#ifdef VANILLA_DEBUG
// Increment the debug tracker.
gNumCalls.ceil++;
#endif
#if PUPPYPRINT_DEBUG
collisionTime[perfIteration] += osGetTime() - first;
#endif
@@ -316,12 +390,21 @@ f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct Surface **pceil) {
* FLOORS *
**************************************************/
/**
* Find the height of the highest floor below an object.
*/
f32 unused_obj_find_floor_height(struct Object *obj) {
struct Surface *floor;
return find_floor(obj->oPosX, obj->oPosY, obj->oPosZ, &floor);
static s32 check_within_floor_triangle_bounds(s32 x, s32 z, struct Surface *surf) {
Vec3i vx, vz;
vx[0] = surf->vertex1[0];
vz[0] = surf->vertex1[2];
vx[1] = surf->vertex2[0];
vz[1] = surf->vertex2[2];
if (((vz[0] - z) * (vx[1] - vx[0]) - (vx[0] - x) * (vz[1] - vz[0])) < 0) return FALSE;
vx[2] = surf->vertex3[0];
vz[2] = surf->vertex3[2];
if (((vz[1] - z) * (vx[2] - vx[1]) - (vx[1] - x) * (vz[2] - vz[1])) < 0) return FALSE;
if (((vz[2] - z) * (vx[0] - vx[2]) - (vx[2] - x) * (vz[0] - vz[2])) < 0) return FALSE;
return TRUE;
}
/**
@@ -329,62 +412,61 @@ f32 unused_obj_find_floor_height(struct Object *obj) {
*/
static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 x, s32 y, s32 z, f32 *pheight) {
register struct Surface *surf, *floor = NULL;
register Vec3i vx, vz;
f32 height;
s16 type = SURFACE_DEFAULT;
*pheight = FLOOR_LOWER_LIMIT;
register SurfaceType type = SURFACE_DEFAULT;
register f32 height;
register s32 bufferY = y + FIND_FLOOR_BUFFER;
// Iterate through the list of floors until there are no more floors.
while (surfaceNode != NULL) {
surf = surfaceNode->surface;
surfaceNode = surfaceNode->next;
type = surf->type;
// To prevent the Merry-Go-Round room from loading when Mario passes above the hole that leads
// there, SURFACE_INTANGIBLE is used. This prevent the wrong room from loading, but can also allow
// Mario to pass through.
if (!gFindFloorIncludeSurfaceIntangible && (type == SURFACE_INTANGIBLE)) continue;
if (!(gCollisionFlags & COLLISION_FLAG_INCLUDE_INTANGIBLE) && (type == SURFACE_INTANGIBLE)) {
continue;
}
// Determine if we are checking for the camera or not.
if (gCheckingSurfaceCollisionsForCamera) {
if ((surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) || SURFACE_IS_NEW_WATER(type)) continue;
} else if (surf->type == SURFACE_CAMERA_BOUNDARY) {
if (gCollisionFlags & COLLISION_FLAG_CAMERA) {
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) {
continue;
}
} else if (type == SURFACE_CAMERA_BOUNDARY) {
continue; // If we are not checking for the camera, ignore camera only floors.
}
if (y < (surf->lowerY - 30)) continue;
vx[0] = surf->vertex1[0];
vz[0] = surf->vertex1[2];
vx[1] = surf->vertex2[0];
vz[1] = surf->vertex2[2];
// Exclude all floors above the point.
if (bufferY < surf->lowerY) continue;
// Check that the point is within the triangle bounds.
if ((vz[0] - z) * (vx[1] - vx[0]) - (vx[0] - x) * (vz[1] - vz[0]) < 0) continue;
// To slightly save on computation time, set this later.
vx[2] = surf->vertex3[0];
vz[2] = surf->vertex3[2];
if ((vz[1] - z) * (vx[2] - vx[1]) - (vx[1] - x) * (vz[2] - vz[1]) < 0) continue;
if ((vz[2] - z) * (vx[0] - vx[2]) - (vx[2] - x) * (vz[0] - vz[2]) < 0) continue;
// Find the height of the floor at a given location.
if (!check_within_floor_triangle_bounds(x, z, surf)) continue;
// Get the height of the floor under the current location.
height = get_surface_height_at_location(x, z, surf);
// Exclude floors lower than the previous highest floor.
if (height < *pheight) continue;
// Checks for floor interaction with a 78 unit buffer.
if (y < (height - 78.0f)) continue;
// Checks for floor interaction with a FIND_FLOOR_BUFFER unit buffer.
if (bufferY < height) continue;
// Use the current floor
*pheight = height;
floor = surf;
if ((height - 78.0f) == y) break;
// Exit the loop if it's not possible for another floor to be closer
// to the original point, or if COLLISION_FLAG_RETURN_FIRST.
if ((height == bufferY) || (gCollisionFlags & COLLISION_FLAG_RETURN_FIRST)) break;
}
return floor;
}
static s16 check_within_triangle_bounds(s32 x, s32 z, struct Surface *surf) {
register Vec3i vx, vz;
vx[0] = surf->vertex1[0];
vz[0] = surf->vertex1[2];
vx[1] = surf->vertex2[0];
vz[1] = surf->vertex2[2];
if ((vz[0] - z) * (vx[1] - vx[0]) - (vx[0] - x) * (vz[1] - vz[0]) < 0) return FALSE;
vx[2] = surf->vertex3[0];
vz[2] = surf->vertex3[2];
if ((vz[1] - z) * (vx[2] - vx[1]) - (vx[1] - x) * (vz[2] - vz[1]) < 0) return FALSE;
if ((vz[2] - z) * (vx[0] - vx[2]) - (vx[2] - x) * (vz[0] - vz[2]) < 0) return FALSE;
return TRUE;
// Generic triangle bounds func
ALWAYS_INLINE static s32 check_within_bounds_y_norm(s32 x, s32 z, struct Surface *surf) {
if (surf->normal.y >= NORMAL_FLOOR_THRESHOLD) return check_within_floor_triangle_bounds(x, z, surf);
return check_within_ceil_triangle_bounds(x, z, surf, 0);
}
/**
@@ -396,29 +478,41 @@ struct Surface *find_water_floor_from_list(struct SurfaceNode *surfaceNode, s32
struct SurfaceNode *topSurfaceNode = surfaceNode;
struct SurfaceNode *bottomSurfaceNode = surfaceNode;
f32 height = FLOOR_LOWER_LIMIT;
f32 curHeight = FLOOR_LOWER_LIMIT;
f32 bottomHeight = FLOOR_LOWER_LIMIT;
f32 curBottomHeight = FLOOR_LOWER_LIMIT;
f32 buffer = FIND_FLOOR_BUFFER;
// Iterate through the list of water floors until there are no more water floors.
// SURFACE_NEW_WATER_BOTTOM
while (bottomSurfaceNode != NULL) {
f32 curBottomHeight = FLOOR_LOWER_LIMIT;
surf = bottomSurfaceNode->surface;
bottomSurfaceNode = bottomSurfaceNode->next;
if (surf->type != SURFACE_NEW_WATER_BOTTOM || !check_within_triangle_bounds(x, z, surf)) continue;
// skip wall angled water
if (surf->type != SURFACE_NEW_WATER_BOTTOM || absf(surf->normal.y) < NORMAL_FLOOR_THRESHOLD) continue;
if (!check_within_bounds_y_norm(x, z, surf)) continue;
curBottomHeight = get_surface_height_at_location(x, z, surf);
if (curBottomHeight < y - 78.0f) continue;
if (curBottomHeight >= y - 78.0f) bottomHeight = curBottomHeight;
if (curBottomHeight < y + buffer) {
continue;
} else {
bottomHeight = curBottomHeight;
}
}
// Iterate through the list of water tops until there are no more water tops.
// SURFACE_NEW_WATER
while (topSurfaceNode != NULL) {
f32 curHeight = FLOOR_LOWER_LIMIT;
surf = topSurfaceNode->surface;
topSurfaceNode = topSurfaceNode->next;
if ((surf->type == SURFACE_NEW_WATER_BOTTOM) || !check_within_triangle_bounds(x, z, surf)) continue;
// skip water tops or wall angled water bottoms
if (surf->type == SURFACE_NEW_WATER_BOTTOM || absf(surf->normal.y) < NORMAL_FLOOR_THRESHOLD) continue;
if (!check_within_bounds_y_norm(x, z, surf)) continue;
curHeight = get_surface_height_at_location(x, z, surf);
@@ -447,8 +541,6 @@ f32 find_floor_height(f32 x, f32 y, f32 z) {
* and dynamic floors were checked separately.
*/
f32 unused_find_dynamic_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor) {
struct SurfaceNode *surfaceList;
struct Surface *floor;
f32 floorHeight = FLOOR_LOWER_LIMIT;
// Would normally cause PUs, but dynamic floors unload at that range.
@@ -460,10 +552,9 @@ f32 unused_find_dynamic_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfl
s32 cellX = GET_CELL_COORD(x);
s32 cellZ = GET_CELL_COORD(z);
surfaceList = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
floor = find_floor_from_list(surfaceList, x, y, z, &floorHeight);
struct SurfaceNode *surfaceList = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
*pfloor = floor;
*pfloor = find_floor_from_list(surfaceList, x, y, z, &floorHeight);
return floorHeight;
}
@@ -472,20 +563,16 @@ f32 unused_find_dynamic_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfl
* Find the highest floor under a given position and return the height.
*/
f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor) {
s32 cellZ, cellX;
#if PUPPYPRINT_DEBUG
OSTime first = osGetTime();
#endif
struct Surface *floor, *dynamicFloor;
struct SurfaceNode *surfaceList;
f32 height = FLOOR_LOWER_LIMIT;
f32 height = FLOOR_LOWER_LIMIT;
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.)
s32 x = xPos;
s32 y = yPos;
s32 z = zPos;
@@ -494,46 +581,60 @@ f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor) {
if (is_outside_level_bounds(x, z)) {
#if PUPPYPRINT_DEBUG
collisionTime[perfIteration] += osGetTime() - first;
collisionTime[perfIteration] += (osGetTime() - first);
#endif
return height;
}
// Each level is split into cells to limit load, find the appropriate cell.
cellX = GET_CELL_COORD(x);
cellZ = GET_CELL_COORD(z);
// Check for surfaces that are a part of level geometry.
surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
floor = find_floor_from_list(surfaceList, x, y, z, &height);
if (!gFindFloorExcludeDynamic) {
// In the next check, only check for floors higher than the previous check
dynamicHeight = height;
s32 cellX = GET_CELL_COORD(x);
s32 cellZ = GET_CELL_COORD(z);
struct SurfaceNode *surfaceList;
struct Surface *floor = NULL;
struct Surface *dynamicFloor = NULL;
s32 includeDynamic = !(gCollisionFlags & COLLISION_FLAG_EXCLUDE_DYNAMIC);
if (includeDynamic) {
// Check for surfaces belonging to objects.
surfaceList = gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
dynamicFloor = find_floor_from_list(surfaceList, x, y, z, &dynamicHeight);
if (dynamicHeight > height) {
floor = dynamicFloor;
height = dynamicHeight;
}
// In the next check, only check for floors higher than the previous check.
height = dynamicHeight;
}
// Check for surfaces that are a part of level geometry.
surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
floor = find_floor_from_list(surfaceList, x, y, z, &height);
// Use the higher floor.
if (includeDynamic && height <= dynamicHeight) {
floor = dynamicFloor;
height = dynamicHeight;
}
// To prevent accidentally leaving the floor tangible, stop checking for it.
gFindFloorIncludeSurfaceIntangible = FALSE;
gFindFloorExcludeDynamic = FALSE;
gCollisionFlags &= ~(COLLISION_FLAG_RETURN_FIRST | COLLISION_FLAG_EXCLUDE_DYNAMIC | COLLISION_FLAG_INCLUDE_INTANGIBLE);
// If a floor was missed, increment the debug counter.
if (floor == NULL) {
gNumFindFloorMisses++;
}
// Return the floor.
*pfloor = floor;
#ifdef VANILLA_DEBUG
// Increment the debug tracker.
gNumCalls.floor++;
#endif
#if PUPPYPRINT_DEBUG
collisionTime[perfIteration] += osGetTime() - first;
collisionTime[perfIteration] += (osGetTime() - first);
#endif
return height;
}
f32 find_room_floor(f32 x, f32 y, f32 z, struct Surface **pfloor) {
gFindFloorIncludeSurfaceIntangible = TRUE;
gFindFloorExcludeDynamic = TRUE;
gCollisionFlags |= (COLLISION_FLAG_RETURN_FIRST | COLLISION_FLAG_EXCLUDE_DYNAMIC | COLLISION_FLAG_INCLUDE_INTANGIBLE);
return find_floor(x, y, z, pfloor);
}
@@ -541,11 +642,6 @@ f32 find_room_floor(f32 x, f32 y, f32 z, struct Surface **pfloor) {
* Find the highest water floor under a given position and return the height.
*/
f32 find_water_floor(s32 xPos, s32 yPos, s32 zPos, struct Surface **pfloor) {
s32 cellZ, cellX;
struct Surface *floor = NULL;
struct SurfaceNode *surfaceList;
f32 height = FLOOR_LOWER_LIMIT;
s32 x = xPos;
@@ -555,19 +651,22 @@ f32 find_water_floor(s32 xPos, s32 yPos, s32 zPos, struct Surface **pfloor) {
if (is_outside_level_bounds(x, z)) return height;
// Each level is split into cells to limit load, find the appropriate cell.
cellX = GET_CELL_COORD(x);
cellZ = GET_CELL_COORD(z);
s32 cellX = GET_CELL_COORD(x);
s32 cellZ = GET_CELL_COORD(z);
// Check for surfaces that are a part of level geometry.
surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WATER].next;
floor = find_water_floor_from_list(surfaceList, x, y, z, &height);
struct SurfaceNode *surfaceList = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_WATER].next;
struct Surface *floor = find_water_floor_from_list(surfaceList, x, y, z, &height);
if (floor == NULL) {
height = FLOOR_LOWER_LIMIT;
} else {
*pfloor = floor;
}
#ifdef VANILLA_DEBUG
// Increment the debug tracker.
gNumCalls.floor++;
#endif
return height;
}
@@ -578,23 +677,20 @@ f32 find_water_floor(s32 xPos, s32 yPos, s32 zPos, struct Surface **pfloor) {
/**
* Finds the height of water at a given location.
*/
s32 find_water_level_and_floor(s32 x, s32 z, struct Surface **pfloor) {
s32 i;
s32 numRegions;
s32 find_water_level_and_floor(s32 x, s32 y, s32 z, struct Surface **pfloor) {
s32 val;
s32 loX, hiX, loZ, hiZ;
s32 waterLevel = FLOOR_LOWER_LIMIT;
TerrainData *p = gEnvironmentRegions;
struct Surface *floor = NULL;
#if PUPPYPRINT_DEBUG
OSTime first = osGetTime();
#endif
waterLevel = find_water_floor(x, (gCheckingSurfaceCollisionsForCamera ? gLakituState.pos[1] : gMarioState->pos[1]), z, &floor);
s32 waterLevel = find_water_floor(x, y, z, &floor);
if (p != NULL && waterLevel == FLOOR_LOWER_LIMIT) {
numRegions = *p++;
s32 numRegions = *p++;
for (i = 0; i < numRegions; i++) {
for (s32 i = 0; i < numRegions; i++) {
val = *p++;
loX = *p++;
loZ = *p++;
@@ -615,7 +711,7 @@ s32 find_water_level_and_floor(s32 x, s32 z, struct Surface **pfloor) {
}
#if PUPPYPRINT_DEBUG
collisionTime[perfIteration] += osGetTime() - first;
collisionTime[perfIteration] += (osGetTime() - first);
#endif
return waterLevel;
}
@@ -623,28 +719,20 @@ s32 find_water_level_and_floor(s32 x, s32 z, struct Surface **pfloor) {
/**
* Finds the height of water at a given location.
*/
s32 find_water_level(s32 x, s32 z) {
s32 i;
s32 numRegions;
s32 find_water_level(s32 x, s32 z) { // TODO: Allow y pos
s32 val;
s32 loX, hiX, loZ, hiZ;
s32 waterLevel = FLOOR_LOWER_LIMIT;
TerrainData *p = gEnvironmentRegions;
struct Surface *floor;
#if PUPPYPRINT_DEBUG
struct Surface *floor = NULL;
#if PUPPYPRINT_DEBUG
OSTime first = osGetTime();
#endif
#endif
s32 waterLevel = find_water_floor(x, ((gCollisionFlags & COLLISION_FLAG_CAMERA) ? gLakituState.pos[1] : gMarioState->pos[1]), z, &floor);
if (gCheckingSurfaceCollisionsForCamera) {
waterLevel = find_water_floor(x, gLakituState.pos[1], z, &floor);
} else {
waterLevel = find_water_floor(x, gMarioState->pos[1], z, &floor);
}
if ((p != NULL) && (waterLevel == FLOOR_LOWER_LIMIT)) {
s32 numRegions = *p++;
if (p != NULL && waterLevel == FLOOR_LOWER_LIMIT) {
numRegions = *p++;
for (i = 0; i < numRegions; i++) {
for (s32 i = 0; i < numRegions; i++) {
val = *p++;
loX = *p++;
loZ = *p++;
@@ -673,8 +761,6 @@ s32 find_water_level(s32 x, s32 z) {
* Finds the height of the poison gas (used only in HMC) at a given location.
*/
s32 find_poison_gas_level(s32 x, s32 z) {
s32 i;
s32 numRegions;
s32 val;
s32 loX, hiX, loZ, hiZ;
s32 gasLevel = FLOOR_LOWER_LIMIT;
@@ -684,9 +770,9 @@ s32 find_poison_gas_level(s32 x, s32 z) {
#endif
if (p != NULL) {
numRegions = *p++;
s32 numRegions = *p++;
for (i = 0; i < numRegions; i++) {
for (s32 i = 0; i < numRegions; i++) {
val = *p;
if (val >= 50) {
@@ -719,6 +805,7 @@ s32 find_poison_gas_level(s32 x, s32 z) {
* DEBUG *
**************************************************/
#ifdef VANILLA_DEBUG
/**
* Finds the length of a surface list for debug purposes.
*/
@@ -738,13 +825,11 @@ static s32 surface_list_length(struct SurfaceNode *list) {
void debug_surface_list_info(f32 xPos, f32 zPos) {
struct SurfaceNode *list;
s32 numFloors = 0;
s32 numWalls = 0;
s32 numCeils = 0;
s32 x = xPos;
s32 z = zPos;
s32 numWalls = 0;
s32 numCeils = 0;
s32 cellX = GET_CELL_COORD(x);
s32 cellZ = GET_CELL_COORD(z);
s32 cellX = GET_CELL_COORD(xPos);
s32 cellZ = GET_CELL_COORD(zPos);
list = gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_FLOORS].next;
numFloors += surface_list_length(list);
@@ -782,12 +867,13 @@ void debug_surface_list_info(f32 xPos, f32 zPos) {
// listal- List Allocated?, statbg- Static Background?, movebg- Moving Background?
print_debug_top_down_mapinfo("listal %d", gSurfaceNodesAllocated);
print_debug_top_down_mapinfo("statbg %d", gNumStaticSurfaces);
print_debug_top_down_mapinfo("movebg %d", gSurfacesAllocated - gNumStaticSurfaces);
print_debug_top_down_mapinfo("movebg %d", (gSurfacesAllocated - gNumStaticSurfaces));
gNumCalls.floor = 0;
gNumCalls.ceil = 0;
gNumCalls.wall = 0;
}
#endif
/**
* An unused function that finds and interacts with any type of surface.
@@ -795,11 +881,9 @@ void debug_surface_list_info(f32 xPos, f32 zPos) {
*/
s32 unused_resolve_floor_or_ceil_collisions(s32 checkCeil, f32 *px, f32 *py, f32 *pz, f32 radius,
struct Surface **psurface, f32 *surfaceHeight) {
f32 nx, ny, nz, oo;
f32 x = *px;
f32 y = *py;
f32 z = *pz;
f32 offset, distance;
*psurface = NULL;
@@ -809,23 +893,21 @@ s32 unused_resolve_floor_or_ceil_collisions(s32 checkCeil, f32 *px, f32 *py, f32
*surfaceHeight = find_floor(x, y, z, psurface);
}
if (*psurface == NULL) {
return -1;
}
if (*psurface == NULL) return -1;
nx = (*psurface)->normal.x;
ny = (*psurface)->normal.y;
nz = (*psurface)->normal.z;
oo = (*psurface)->originOffset;
f32 nx = (*psurface)->normal.x;
f32 ny = (*psurface)->normal.y;
f32 nz = (*psurface)->normal.z;
f32 oo = (*psurface)->originOffset;
offset = (nx * x) + (ny * y) + (nz * z) + oo;
distance = offset >= 0 ? offset : -offset;
f32 offset = absf((nx * x) + (ny * y) + (nz * z) + oo);
// Interesting surface interaction that should be surf type independent.
if (distance < radius) {
*px += nx * (radius - offset);
*py += ny * (radius - offset);
*pz += nz * (radius - offset);
if (offset < radius) {
offset = (radius - offset);
*px += (nx * offset);
*py += (ny * offset);
*pz += (nz * offset);
return 1;
}
+31 -16
View File
@@ -5,46 +5,61 @@
#include "types.h"
#include "engine/extended_bounds.h"
#include "config/config_world.h"
#define CELL_HEIGHT_LIMIT 20000
// The y coord is moved upward by this amount when finding floors.
// Vanilla value is 78.
#define FIND_FLOOR_BUFFER 78
#define CELL_HEIGHT_LIMIT 20000
#define FLOOR_LOWER_LIMIT -11000
#define FLOOR_LOWER_LIMIT_MISC (FLOOR_LOWER_LIMIT + 1000)
// same as FLOOR_LOWER_LIMIT_MISC, explicitly for shadow.c
#define FLOOR_LOWER_LIMIT_SHADOW (FLOOR_LOWER_LIMIT + 1000)
#define is_outside_level_bounds(xPos, zPos) (((xPos) <= -LEVEL_BOUNDARY_MAX) || ((xPos) >= LEVEL_BOUNDARY_MAX) || ((zPos) <= -LEVEL_BOUNDARY_MAX) || ((zPos) >= LEVEL_BOUNDARY_MAX))
#define is_outside_level_bounds(xPos, zPos) \
(((xPos) <= -LEVEL_BOUNDARY_MAX) || \
((xPos) >= LEVEL_BOUNDARY_MAX) || \
((zPos) <= -LEVEL_BOUNDARY_MAX) || \
((zPos) >= LEVEL_BOUNDARY_MAX))
#define get_surface_height_at_location(xPos, zPos, surf) (-((xPos) * (surf)->normal.x + (surf)->normal.z * (zPos) + (surf)->originOffset) / (surf)->normal.y)
#define get_surface_height_at_location(xPos, zPos, surf) (-(((xPos) * (surf)->normal.x) + ((zPos) * (surf)->normal.z) + (surf)->originOffset) / (surf)->normal.y)
#define SURFACE_YAW(s) (atan2s(((s)->normal.z), ((s)->normal.x)))
#define RAYCAST_FIND_FLOOR (1 << 0)
#define RAYCAST_FIND_WALL (1 << 1)
#define RAYCAST_FIND_CEIL (1 << 2)
#define RAYCAST_FIND_WATER (1 << 3)
#define RAYCAST_FIND_ALL (0xFFFFFFFF)
enum RaycastFlags {
RAYCAST_FIND_FLOOR = (1 << 0),
RAYCAST_FIND_WALL = (1 << 1),
RAYCAST_FIND_CEIL = (1 << 2),
RAYCAST_FIND_WATER = (1 << 3),
RAYCAST_FIND_ALL = (0xFFFFFFFF)
};
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[MAX_REFEREMCED_WALLS];
/*0x18*/ struct Surface *walls[MAX_REFERENCED_WALLS];
};
s32 f32_find_wall_collision(f32 *xPtr, f32 *yPtr, f32 *zPtr, f32 offsetY, f32 radius);
s32 find_wall_collisions(struct WallCollisionData *colData);
void resolve_and_return_wall_collisions(Vec3f pos, f32 offset, f32 radius, struct WallCollisionData *collisionData);
f32 find_ceil(f32 posX, f32 posY, f32 posZ, struct Surface **pceil);
// Finds the ceiling from a vec3f and a minimum height (with 3 unit vertical buffer).
ALWAYS_INLINE f32 find_mario_ceil(Vec3f pos, f32 height, struct Surface **ceil) {
return find_ceil(pos[0], MAX(height, pos[1]) + 3.0f, pos[2], ceil);
}
f32 find_floor_height(f32 x, f32 y, f32 z);
f32 find_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor);
f32 find_room_floor(f32 x, f32 y, f32 z, struct Surface **pfloor);
s32 find_water_level_and_floor(s32 x, s32 z, struct Surface **pfloor);
s32 find_water_level_and_floor(s32 x, s32 y, s32 z, struct Surface **pfloor);
s32 find_water_level(s32 x, s32 z);
s32 find_poison_gas_level(s32 x, s32 z);
#ifdef VANILLA_DEBUG
void debug_surface_list_info(f32 xPos, f32 zPos);
#endif
#endif // SURFACE_COLLISION_H
+106 -173
View File
@@ -1,7 +1,5 @@
#include <PR/ultratypes.h>
#include "prevent_bss_reordering.h"
#include "sm64.h"
#include "game/ingame_menu.h"
#include "graph_node.h"
@@ -33,22 +31,26 @@ struct SurfaceNode *sSurfaceNodePool;
struct Surface *sSurfacePool;
/**
* The size of the surface pool (2300).
* The size of the surface node pool (SURFACE_NODE_POOL_SIZE).
*/
s16 sSurfacePoolSize;
s32 sSurfaceNodePoolSize = SURFACE_NODE_POOL_SIZE;
u8 gSurfacePoolError = 0;
/**
* The size of the surface pool (SURFACE_POOL_SIZE).
*/
s32 sSurfacePoolSize = SURFACE_POOL_SIZE;
u8 gSurfacePoolError = 0x0;
/**
* Allocate the part of the surface node pool to contain a surface node.
*/
static struct SurfaceNode *alloc_surface_node(void) {
struct SurfaceNode *node = &sSurfaceNodePool[gSurfaceNodesAllocated];
gSurfaceNodesAllocated++;
struct SurfaceNode *node = &sSurfaceNodePool[gSurfaceNodesAllocated++];
node->next = NULL;
if (gSurfaceNodesAllocated >= SURFACE_NODE_POOL_SIZE) {
if (gSurfaceNodesAllocated >= sSurfaceNodePoolSize) {
gSurfacePoolError |= NOT_ENOUGH_ROOM_FOR_NODES;
}
@@ -61,16 +63,15 @@ static struct SurfaceNode *alloc_surface_node(void) {
*/
static struct Surface *alloc_surface(void) {
struct Surface *surface = &sSurfacePool[gSurfacesAllocated];
gSurfacesAllocated++;
struct Surface *surface = &sSurfacePool[gSurfacesAllocated++];
if (gSurfacesAllocated >= sSurfacePoolSize) {
gSurfacePoolError |= NOT_ENOUGH_ROOM_FOR_SURFACES;
}
surface->type = 0;
surface->type = SURFACE_DEFAULT;
surface->force = 0;
surface->flags = 0;
surface->flags = SURFACE_FLAGS_NONE;
surface->room = 0;
surface->object = NULL;
@@ -81,7 +82,7 @@ static struct Surface *alloc_surface(void) {
* Iterates through the entire partition, clearing the surfaces.
*/
static void clear_spatial_partition(SpatialPartitionCell *cells) {
register s32 i = NUM_CELLS * NUM_CELLS;
register s32 i = sqr(NUM_CELLS);
while (i--) {
(*cells)[SPATIAL_PARTITION_FLOORS].next = NULL;
@@ -108,18 +109,16 @@ static void clear_static_surfaces(void) {
* @param surface The surface to add
*/
static void add_surface_to_cell(s32 dynamic, s32 cellX, s32 cellZ, struct Surface *surface) {
struct SurfaceNode *newNode = alloc_surface_node();
struct SurfaceNode *list;
s32 surfacePriority;
s32 priority;
s32 sortDir;
s32 sortDir = 1; // highest to lowest, then insertion order (water and floors)
s32 listIndex;
s32 isWater = SURFACE_IS_NEW_WATER(surface->type);
if (surface->normal.y > 0.01) {
listIndex = isWater ? SPATIAL_PARTITION_WATER : SPATIAL_PARTITION_FLOORS;
sortDir = 1; // highest to lowest, then insertion order
} else if (surface->normal.y < -0.01) {
if (SURFACE_IS_NEW_WATER(surface->type)) {
listIndex = SPATIAL_PARTITION_WATER;
} else if (surface->normal.y > NORMAL_FLOOR_THRESHOLD) {
listIndex = SPATIAL_PARTITION_FLOORS;
} else if (surface->normal.y < NORMAL_CEIL_THRESHOLD) {
listIndex = SPATIAL_PARTITION_CEILS;
sortDir = -1; // lowest to highest, then insertion order
} else {
@@ -127,8 +126,9 @@ static void add_surface_to_cell(s32 dynamic, s32 cellX, s32 cellZ, struct Surfac
sortDir = 0; // insertion order
}
surfacePriority = surface->upperY * sortDir;
s32 surfacePriority = surface->upperY * sortDir;
struct SurfaceNode *newNode = alloc_surface_node();
newNode->surface = surface;
if (dynamic) {
@@ -158,30 +158,24 @@ static void add_surface_to_cell(s32 dynamic, s32 cellX, s32 cellZ, struct Surfac
* @param coord The coordinate to test
*/
static s32 lower_cell_index(s32 coord) {
s32 index;
// Move from range [-0x2000, 0x2000) to [0, 0x4000)
// Move from range [-LEVEL_BOUNDARY_MAX, LEVEL_BOUNDARY_MAX) to [0, 2 * LEVEL_BOUNDARY_MAX)
coord += LEVEL_BOUNDARY_MAX;
if (coord < 0) {
coord = 0;
}
// [0, 16)
index = coord / CELL_SIZE;
// [0, NUM_CELLS)
s32 index = coord / CELL_SIZE;
// Include extra cell if close to boundary
//! 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) {
index = 0;
}
// Potentially > 15, but since the upper index is <= 15, not exploitable
return index;
// Potentially > NUM_CELLS - 1, but since the upper index is <= NUM_CELLS - 1, not exploitable
return MAX(0, index);
}
/**
@@ -190,30 +184,24 @@ static s32 lower_cell_index(s32 coord) {
* @param coord The coordinate to test
*/
static s32 upper_cell_index(s32 coord) {
s32 index;
// Move from range [-0x2000, 0x2000) to [0, 0x4000)
// Move from range [-LEVEL_BOUNDARY_MAX, LEVEL_BOUNDARY_MAX) to [0, 2 * LEVEL_BOUNDARY_MAX)
coord += LEVEL_BOUNDARY_MAX;
if (coord < 0) {
coord = 0;
}
// [0, 16)
index = coord / CELL_SIZE;
// [0, NUM_CELLS)
s32 index = coord / CELL_SIZE;
// Include extra cell if close to boundary
//! 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;
}
if (index > (NUM_CELLS - 1)) {
index = (NUM_CELLS - 1);
index++;
}
// Potentially < 0, but since lower index is >= 0, not exploitable
return index;
return MIN((NUM_CELLS - 1), index);
}
/**
@@ -224,21 +212,16 @@ static s32 upper_cell_index(s32 coord) {
* @param dynamic Boolean determining whether the surface is static or dynamic
*/
static void add_surface(struct Surface *surface, s32 dynamic) {
s32 minX, minZ, maxX, maxZ;
s32 minCellX, minCellZ, maxCellX, maxCellZ;
s32 cellZ, cellX;
s32 minX, maxX, minZ, maxZ;
minX = min_3i(surface->vertex1[0], surface->vertex2[0], surface->vertex3[0]);
minZ = min_3i(surface->vertex1[2], surface->vertex2[2], surface->vertex3[2]);
maxX = max_3i(surface->vertex1[0], surface->vertex2[0], surface->vertex3[0]);
maxZ = max_3i(surface->vertex1[2], surface->vertex2[2], surface->vertex3[2]);
min_max_3i(surface->vertex1[0], surface->vertex2[0], surface->vertex3[0], &minX, &maxX);
min_max_3i(surface->vertex1[2], surface->vertex2[2], surface->vertex3[2], &minZ, &maxZ);
minCellX = lower_cell_index(minX);
maxCellX = upper_cell_index(maxX);
minCellZ = lower_cell_index(minZ);
maxCellZ = upper_cell_index(maxZ);
s32 minCellX = lower_cell_index(minX);
s32 maxCellX = upper_cell_index(maxX);
s32 minCellZ = lower_cell_index(minZ);
s32 maxCellZ = upper_cell_index(maxZ);
for (cellZ = minCellZ; cellZ <= maxCellZ; cellZ++) {
for (cellX = minCellX; cellX <= maxCellX; cellX++) {
@@ -253,58 +236,36 @@ static void add_surface(struct Surface *surface, s32 dynamic) {
* @param vertexIndices Helper which tells positions in vertexData to start reading vertices
*/
static struct Surface *read_surface_data(TerrainData *vertexData, TerrainData **vertexIndices) {
struct Surface *surface;
register s32 x1, y1, z1;
register s32 x2, y2, z2;
register s32 x3, y3, z3;
Vec3t v[3];
Vec3f n;
s32 offset1, offset2, offset3;
Vec3t offset;
s16 min, max;
offset1 = (3 * (*vertexIndices)[0]);
offset2 = (3 * (*vertexIndices)[1]);
offset3 = (3 * (*vertexIndices)[2]);
vec3_prod_val(offset, (*vertexIndices), 3);
x1 = *(vertexData + offset1 + 0);
y1 = *(vertexData + offset1 + 1);
z1 = *(vertexData + offset1 + 2);
vec3s_copy(v[0], (vertexData + offset[0]));
vec3s_copy(v[1], (vertexData + offset[1]));
vec3s_copy(v[2], (vertexData + offset[2]));
x2 = *(vertexData + offset2 + 0);
y2 = *(vertexData + offset2 + 1);
z2 = *(vertexData + offset2 + 2);
x3 = *(vertexData + offset3 + 0);
y3 = *(vertexData + offset3 + 1);
z3 = *(vertexData + offset3 + 2);
// (v2 - v1) x (v3 - v2)
n[0] = ((y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2));
n[1] = ((z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2));
n[2] = ((x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2));
find_vector_perpendicular_to_plane(n, v[0], v[1], v[2]);
vec3f_normalize(n);
surface = alloc_surface();
struct Surface *surface = alloc_surface();
surface->vertex1[0] = x1;
surface->vertex2[0] = x2;
surface->vertex3[0] = x3;
surface->vertex1[1] = y1;
surface->vertex2[1] = y2;
surface->vertex3[1] = y3;
surface->vertex1[2] = z1;
surface->vertex2[2] = z2;
surface->vertex3[2] = z3;
vec3s_copy(surface->vertex1, v[0]);
vec3s_copy(surface->vertex2, v[1]);
vec3s_copy(surface->vertex3, v[2]);
surface->normal.x = n[0];
surface->normal.y = n[1];
surface->normal.z = n[2];
surface->originOffset = -(n[0] * x1 + n[1] * y1 + n[2] * z1);
surface->originOffset = -vec3_dot(n, v[0]);
surface->lowerY = (min_3i(y1, y2, y3) - 5);
surface->upperY = (max_3i(y1, y2, y3) + 5);
min_max_3s(v[0][1], v[1][1], v[2][1], &min, &max);
surface->lowerY = (min - SURFACE_VERTICAL_BUFFER);
surface->upperY = (max + SURFACE_VERTICAL_BUFFER);
return surface;
}
@@ -340,7 +301,7 @@ static s32 surface_has_force(s32 surfaceType) {
* SURFACE_FLAG_NO_CAM_COLLISION flag.
*/
static s32 surf_has_no_cam_collision(s32 surfaceType) {
s32 flags = 0;
s32 flags = SURFACE_FLAGS_NONE;
switch (surfaceType) {
case SURFACE_NO_CAM_COLLISION:
@@ -363,28 +324,25 @@ static s32 surf_has_no_cam_collision(s32 surfaceType) {
*/
static void load_static_surfaces(TerrainData **data, TerrainData *vertexData, s32 surfaceType, RoomData **surfaceRooms) {
s32 i;
s32 numSurfaces;
struct Surface *surface;
s32 room = 0;
RoomData room = 0;
#ifndef ALL_SURFACES_HAVE_FORCE
s16 hasForce = surface_has_force(surfaceType);
#endif
s32 flags = surf_has_no_cam_collision(surfaceType);
numSurfaces = *(*data);
*data += 1;
s32 numSurfaces = *(*data)++;
for (i = 0; i < numSurfaces; i++) {
if (*surfaceRooms != NULL) {
room = *(*surfaceRooms);
*surfaceRooms += 1;
room = *(*surfaceRooms)++;
}
surface = read_surface_data(vertexData, data);
if (surface != NULL) {
surface->room = room;
surface->type = surfaceType;
surface->flags = (s8) flags;
surface->flags = flags;
#ifdef ALL_SURFACES_HAVE_FORCE
surface->force = *(*data + 3);
@@ -404,7 +362,7 @@ static void load_static_surfaces(TerrainData **data, TerrainData *vertexData, s3
#else
*data += 3;
if (hasForce) {
*data += 1;
(*data)++;
}
#endif
}
@@ -414,13 +372,9 @@ static void load_static_surfaces(TerrainData **data, TerrainData *vertexData, s3
* Read the data for vertices for reference by triangles.
*/
static TerrainData *read_vertex_data(TerrainData **data) {
s32 numVertices;
TerrainData *vertexData;
s32 numVertices = *(*data)++;
numVertices = *(*data);
(*data)++;
vertexData = *data;
TerrainData *vertexData = *data;
*data += 3 * numVertices;
return vertexData;
@@ -445,11 +399,10 @@ static void load_environmental_regions(TerrainData **data) {
* Allocate some of the main pool for surfaces (2300 surf) and for surface nodes (7000 nodes).
*/
void alloc_surface_pools(void) {
sSurfacePoolSize = SURFACE_POOL_SIZE;
sSurfaceNodePool = main_pool_alloc(SURFACE_NODE_POOL_SIZE * sizeof(struct SurfaceNode), MEMORY_POOL_LEFT);
sSurfaceNodePool = main_pool_alloc(sSurfaceNodePoolSize * sizeof(struct SurfaceNode), MEMORY_POOL_LEFT);
sSurfacePool = main_pool_alloc(sSurfacePoolSize * sizeof(struct Surface), MEMORY_POOL_LEFT);
gCCMEnteredSlide = 0;
gCCMEnteredSlide = FALSE;
reset_red_coins_collected();
}
@@ -532,8 +485,7 @@ void load_area_terrain(s32 index, TerrainData *data, RoomData *surfaceRooms, s16
// are prefixed by a terrain "type." This type is reused for surfaces as the surface
// type.
while (TRUE) {
terrainLoadType = *data;
data++;
terrainLoadType = *data++;
if (TERRAIN_LOAD_IS_SURFACE_TYPE_LOW(terrainLoadType)) {
load_static_surfaces(&data, vertexData, terrainLoadType, &surfaceRooms);
@@ -588,56 +540,43 @@ void clear_dynamic_surfaces(void) {
* Applies an object's transformation to the object's vertices.
*/
void transform_object_vertices(TerrainData **data, TerrainData *vertexData) {
register TerrainData *vertices;
register f32 vx, vy, vz;
register s32 numVertices;
Mat4 *objectTransform = &o->transform;
Mat4 *objectTransform;
Mat4 m;
register s32 numVertices = *(*data)++;
objectTransform = &gCurrentObject->transform;
register TerrainData *vertices = *data;
numVertices = *(*data);
(*data)++;
vertices = *data;
if (gCurrentObject->header.gfx.throwMatrix == NULL) {
gCurrentObject->header.gfx.throwMatrix = objectTransform;
obj_build_transform_from_pos_and_angle(gCurrentObject, O_POS_INDEX, O_FACE_ANGLE_INDEX);
if (o->header.gfx.throwMatrix == NULL) {
o->header.gfx.throwMatrix = objectTransform;
obj_build_transform_from_pos_and_angle(o, O_POS_INDEX, O_FACE_ANGLE_INDEX);
}
obj_apply_scale_to_matrix(gCurrentObject, m, *objectTransform);
Mat4 transform;
mtxf_scale_vec3f(transform, *objectTransform, o->header.gfx.scale);
// Go through all vertices, rotating and translating them to transform the object.
Vec3f pos;
while (numVertices--) {
vx = *(vertices++);
vy = *(vertices++);
vz = *(vertices++);
vec3s_to_vec3f(pos, vertices);
vertices += 3;
//! No bounds check on vertex data
*vertexData++ = (TerrainData)(vx * m[0][0] + vy * m[1][0] + vz * m[2][0] + m[3][0]);
*vertexData++ = (TerrainData)(vx * m[0][1] + vy * m[1][1] + vz * m[2][1] + m[3][1]);
*vertexData++ = (TerrainData)(vx * m[0][2] + vy * m[1][2] + vz * m[2][2] + m[3][2]);
linear_mtxf_mul_vec3_and_translate(transform, vertexData, pos);
vertexData += 3;
}
*data = vertices;
}
/**
* Load in the surfaces for the gCurrentObject. This includes setting the flags, exertion, and room.
* Load in the surfaces for the o. This includes setting the flags, exertion, and room.
*/
void load_object_surfaces(TerrainData **data, TerrainData *vertexData) {
s32 surfaceType;
s32 i;
s32 numSurfaces;
s32 room;
surfaceType = *(*data);
(*data)++;
numSurfaces = *(*data);
(*data)++;
s32 surfaceType = *(*data)++;
s32 numSurfaces = *(*data)++;
#ifndef ALL_SURFACES_HAVE_FORCE
TerrainData hasForce = surface_has_force(surfaceType);
@@ -647,17 +586,13 @@ void load_object_surfaces(TerrainData **data, TerrainData *vertexData) {
// The DDD warp is initially loaded at the origin and moved to the proper
// position in paintings.c and doesn't update its room, so set it here.
if (gCurrentObject->behavior == segmented_to_virtual(bhvDddWarp)) {
room = 5;
} else {
room = 0;
}
RoomData room = (o->behavior == segmented_to_virtual(bhvDddWarp)) ? 5 : 0;
for (i = 0; i < numSurfaces; i++) {
struct Surface *surface = read_surface_data(vertexData, data);
if (surface != NULL) {
surface->object = gCurrentObject;
surface->object = o;
surface->type = surfaceType;
#ifdef ALL_SURFACES_HAVE_FORCE
@@ -671,7 +606,7 @@ void load_object_surfaces(TerrainData **data, TerrainData *vertexData) {
#endif
surface->flags |= flags;
surface->room = (s8) room;
surface->room = room;
add_surface(surface, TRUE);
}
@@ -688,21 +623,16 @@ void load_object_surfaces(TerrainData **data, TerrainData *vertexData) {
}
#ifdef AUTO_COLLISION_DISTANCE
// From Kaze
static void get_optimal_coll_dist(struct Object *obj) {
register f32 thisVertDist, maxDist = 0.0f;
Vec3f v;
TerrainData *collisionData = gCurrentObject->collisionData;
TerrainData *collisionData = o->collisionData;
obj->oFlags |= OBJ_FLAG_DONT_CALC_COLL_DIST;
collisionData++;
register u32 vertsLeft = *(collisionData);
collisionData++;
// vertices = *data;
register u32 vertsLeft = *(collisionData)++;
while (vertsLeft) {
v[0] = *(collisionData + 0) * obj->header.gfx.scale[0];
v[1] = *(collisionData + 1) * obj->header.gfx.scale[1];
v[2] = *(collisionData + 2) * obj->header.gfx.scale[2];
thisVertDist = (sqr(v[0]) + sqr(v[1]) + sqr(v[2]));
vec3_prod(v, collisionData, obj->header.gfx.scale);
thisVertDist = vec3_sumsq(v);
if (thisVertDist > maxDist) maxDist = thisVertDist;
collisionData += 3;
vertsLeft--;
@@ -720,30 +650,33 @@ void load_object_collision_model(void) {
OSTime first = osGetTime();
#endif
TerrainData *collisionData = gCurrentObject->collisionData;
f32 marioDist = gCurrentObject->oDistanceToMario;
TerrainData *collisionData = o->collisionData;
f32 marioDist = o->oDistanceToMario;
// On an object's first frame, the distance is set to 19000.0f.
// If the distance hasn't been updated, update it now.
if (gCurrentObject->oDistanceToMario == 19000.0f) {
marioDist = dist_between_objects(gCurrentObject, gMarioObject);
if (o->oDistanceToMario == 19000.0f) {
marioDist = dist_between_objects(o, gMarioObject);
}
#ifdef AUTO_COLLISION_DISTANCE
if (!(gCurrentObject->oFlags & OBJ_FLAG_DONT_CALC_COLL_DIST)) {
get_optimal_coll_dist(gCurrentObject);
if (!(o->oFlags & OBJ_FLAG_DONT_CALC_COLL_DIST)) {
get_optimal_coll_dist(o);
}
#endif
// If the object collision is supposed to be loaded more than the
// drawing distance, extend the drawing range.
if (gCurrentObject->oCollisionDistance > gCurrentObject->oDrawingDistance) {
gCurrentObject->oDrawingDistance = gCurrentObject->oCollisionDistance;
if (o->oCollisionDistance > o->oDrawingDistance) {
o->oDrawingDistance = o->oCollisionDistance;
}
// Update if no Time Stop, in range, and in the current room.
if (!(gTimeStopState & TIME_STOP_ACTIVE) && (marioDist < gCurrentObject->oCollisionDistance)
&& !(gCurrentObject->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)) {
if (
!(gTimeStopState & TIME_STOP_ACTIVE)
&& (marioDist < o->oCollisionDistance)
&& !(o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM)
) {
collisionData++;
transform_object_vertices(&collisionData, vertexData);
@@ -752,8 +685,8 @@ void load_object_collision_model(void) {
load_object_surfaces(&collisionData, vertexData);
}
}
COND_BIT((marioDist < gCurrentObject->oDrawingDistance), gCurrentObject->header.gfx.node.flags, GRAPH_RENDER_ACTIVE);
COND_BIT((marioDist < o->oDrawingDistance), o->header.gfx.node.flags, GRAPH_RENDER_ACTIVE);
#if PUPPYPRINT_DEBUG
collisionTime[perfIteration] += osGetTime()-first;
collisionTime[perfIteration] += osGetTime() - first;
#endif
}
+13 -8
View File
@@ -6,35 +6,40 @@
#include "surface_collision.h"
#include "types.h"
#define SURFACE_VERTICAL_BUFFER 5
#define NORMAL_FLOOR_THRESHOLD 0.01f
#define NORMAL_CEIL_THRESHOLD -NORMAL_FLOOR_THRESHOLD
extern u8 gSurfacePoolError;
struct SurfaceNode
{
struct SurfaceNode {
struct SurfaceNode *next;
struct Surface *surface;
};
enum
{
enum SpatialPartitions {
SPATIAL_PARTITION_FLOORS,
SPATIAL_PARTITION_CEILS,
SPATIAL_PARTITION_WALLS,
SPATIAL_PARTITION_WATER
SPATIAL_PARTITION_WATER,
NUM_SPATIAL_PARTITIONS
};
typedef struct SurfaceNode SpatialPartitionCell[4];
typedef struct SurfaceNode SpatialPartitionCell[NUM_SPATIAL_PARTITIONS];
extern SpatialPartitionCell gStaticSurfacePartition[NUM_CELLS][NUM_CELLS];
extern SpatialPartitionCell gDynamicSurfacePartition[NUM_CELLS][NUM_CELLS];
extern struct SurfaceNode *sSurfaceNodePool;
extern struct Surface *sSurfacePool;
extern s16 sSurfacePoolSize;
extern s32 sSurfaceNodePoolSize;
extern s32 sSurfacePoolSize;
void alloc_surface_pools(void);
#ifdef NO_SEGMENTED_MEMORY
u32 get_area_terrain_size(TerrainData *data);
#endif
void load_area_terrain(s32 index, TerrainData *data, RoomData *surfaceRooms, s16 *macroObjects);
void load_area_terrain(s32 index, TerrainData *data, RoomData *surfaceRooms, MacroObject *macroObjects);
void clear_dynamic_surfaces(void);
void load_object_collision_model(void);
+2 -2
View File
@@ -5,8 +5,8 @@
#define BUFF_LEN 0x20
static s16 _Ldunscale(s16 *, printf_struct *);
static void _Genld(printf_struct *, u8, u8 *, s16, s16);
static s16 _Ldunscale(s16 *pex, printf_struct *px);
static void _Genld(printf_struct *px, u8 code, u8 *p, s16 nsig, s16 xexp);
const double D_80338670[] = { 10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L, 10e127L, 10e255L };
+1 -1
View File
@@ -30,7 +30,7 @@ const u32 flags_arr[] = { FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAG
char _spaces[] = " ";
char _zeroes[] = "00000000000000000000000000000000";
static void _Putfld(printf_struct *, va_list *, u8, u8 *);
static void _Putfld(printf_struct *a0, va_list *args, u8 type, u8 *buf);
s32 _Printf(char *(*prout)(char *, const char *, size_t), char *dst, const char *fmt, va_list args) {
printf_struct sp78;
+67 -52
View File
@@ -1,7 +1,6 @@
#include <PR/ultratypes.h>
#include "config.h"
#include "prevent_bss_reordering.h"
#include "area.h"
#include "sm64.h"
#include "gfx_dimensions.h"
@@ -25,10 +24,11 @@
#include "dialog_ids.h"
#include "puppyprint.h"
#include "debug_box.h"
#include "engine/colors.h"
struct SpawnInfo gPlayerSpawnInfos[1];
struct GraphNode *gGraphNodePointers[MODEL_ID_COUNT];
struct Area gAreaData[8];
struct Area gAreaData[AREA_COUNT];
struct WarpTransition gWarpTransition;
@@ -44,14 +44,15 @@ struct GraphNode **gLoadedGraphNodes = gGraphNodePointers;
struct Area *gAreas = gAreaData;
struct Area *gCurrentArea = NULL;
struct CreditsEntry *gCurrCreditsEntry = NULL;
Vp *gViewportOverride = NULL;
Vp *gViewportClip = NULL;
s16 gWarpTransDelay = 0;
u32 gFBSetColor = 0;
u32 gWarpTransFBSetColor = 0;
u8 gWarpTransRed = 0;
u8 gWarpTransGreen = 0;
u8 gWarpTransBlue = 0;
RGBA16FILL gFBSetColor = 0;
RGBA16FILL gWarpTransFBSetColor = 0;
Color gWarpTransRed= 0;
Color gWarpTransGreen = 0;
Color gWarpTransBlue = 0;
s16 gCurrSaveFileNum = 1;
s16 gCurrLevelNum = LEVEL_MIN;
@@ -71,8 +72,8 @@ const BehaviorScript *sWarpBhvSpawnTable[] = {
};
u8 sSpawnTypeFromWarpBhv[] = {
MARIO_SPAWN_DOOR_WARP, MARIO_SPAWN_UNKNOWN_02, MARIO_SPAWN_UNKNOWN_03, MARIO_SPAWN_UNKNOWN_03,
MARIO_SPAWN_UNKNOWN_03, MARIO_SPAWN_TELEPORT, MARIO_SPAWN_INSTANT_ACTIVE, MARIO_SPAWN_AIRBORNE,
MARIO_SPAWN_DOOR_WARP, MARIO_SPAWN_IDLE, MARIO_SPAWN_PIPE, MARIO_SPAWN_PIPE,
MARIO_SPAWN_PIPE, MARIO_SPAWN_TELEPORT, MARIO_SPAWN_INSTANT_ACTIVE, MARIO_SPAWN_AIRBORNE,
MARIO_SPAWN_HARD_AIR_KNOCKBACK, MARIO_SPAWN_SPIN_AIRBORNE_CIRCLE, MARIO_SPAWN_DEATH, MARIO_SPAWN_SPIN_AIRBORNE,
MARIO_SPAWN_FLYING, MARIO_SPAWN_SWIMMING, MARIO_SPAWN_PAINTING_STAR_COLLECT, MARIO_SPAWN_PAINTING_DEATH,
MARIO_SPAWN_AIRBORNE_STAR_COLLECT, MARIO_SPAWN_AIRBORNE_DEATH, MARIO_SPAWN_LAUNCH_STAR_COLLECT, MARIO_SPAWN_LAUNCH_DEATH,
@@ -83,7 +84,7 @@ Vp gViewport = { {
{ 640, 480, 511, 0 },
} };
#ifdef VERSION_EU
#if MULTILANG
const char *gNoControllerMsg[] = {
"NO CONTROLLER",
"MANETTE DEBRANCHEE",
@@ -91,16 +92,16 @@ const char *gNoControllerMsg[] = {
};
#endif
void override_viewport_and_clip(Vp *vpOverride, Vp *vpClip, u8 red, u8 green, u8 blue) {
u16 color = ((red >> 3) << 11) | ((green >> 3) << 6) | ((blue >> 3) << 1) | 1;
void override_viewport_and_clip(Vp *vpOverride, Vp *vpClip, Color red, Color green, Color blue) {
RGBA16 color = ((red >> 3) << IDX_RGBA16_R) | ((green >> 3) << IDX_RGBA16_G) | ((blue >> 3) << IDX_RGBA16_B) | MSK_RGBA16_A;
gFBSetColor = (color << 16) | color;
gViewportOverride = vpOverride;
gViewportClip = vpClip;
}
void set_warp_transition_rgb(u8 red, u8 green, u8 blue) {
u16 warpTransitionRGBA16 = ((red >> 3) << 11) | ((green >> 3) << 6) | ((blue >> 3) << 1) | 1;
void set_warp_transition_rgb(Color red, Color green, Color blue) {
RGBA16 warpTransitionRGBA16 = ((red >> 3) << IDX_RGBA16_R) | ((green >> 3) << IDX_RGBA16_G) | ((blue >> 3) << IDX_RGBA16_B) | MSK_RGBA16_A;
gWarpTransFBSetColor = (warpTransitionRGBA16 << 16) | warpTransitionRGBA16;
gWarpTransRed = red;
@@ -109,15 +110,15 @@ void set_warp_transition_rgb(u8 red, u8 green, u8 blue) {
}
void print_intro_text(void) {
#ifdef VERSION_EU
#if MULTILANG
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]);
#if MULTILANG
print_text_centered(SCREEN_CENTER_X, 20, gNoControllerMsg[language]);
#else
print_text_centered(SCREEN_WIDTH / 2, 20, "NO CONTROLLER");
print_text_centered(SCREEN_CENTER_X, 20, "NO CONTROLLER");
#endif
} else {
#ifdef VERSION_EU
@@ -132,14 +133,14 @@ void print_intro_text(void) {
u32 get_mario_spawn_type(struct Object *obj) {
s32 i;
const BehaviorScript *behavior = virtual_to_segmented(0x13, obj->behavior);
const BehaviorScript *behavior = virtual_to_segmented(SEGMENT_BEHAVIOR_DATA, obj->behavior);
for (i = 0; i < 20; i++) {
if (sWarpBhvSpawnTable[i] == behavior) {
return sSpawnTypeFromWarpBhv[i];
}
}
return 0;
return MARIO_SPAWN_NONE;
}
struct ObjectWarpNode *area_get_warp_node(u8 id) {
@@ -154,7 +155,7 @@ struct ObjectWarpNode *area_get_warp_node(u8 id) {
}
struct ObjectWarpNode *area_get_warp_node_from_params(struct Object *obj) {
return area_get_warp_node((obj->oBehParams & 0x00FF0000) >> 16);
return area_get_warp_node(GET_BPARAM2(obj->oBehParams));
}
void load_obj_warp_nodes(void) {
@@ -182,10 +183,10 @@ void clear_areas(void) {
gWarpTransition.pauseRendering = FALSE;
gMarioSpawnInfo->areaIndex = -1;
for (i = 0; i < 8; i++) {
for (i = 0; i < AREA_COUNT; i++) {
gAreaData[i].index = i;
gAreaData[i].flags = 0;
gAreaData[i].terrainType = 0;
gAreaData[i].flags = AREA_FLAG_UNLOAD;
gAreaData[i].terrainType = TERRAIN_GRASS;
gAreaData[i].graphNode = NULL;
gAreaData[i].terrainData = NULL;
gAreaData[i].surfaceRooms = NULL;
@@ -195,7 +196,7 @@ 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] = DIALOG_NONE;
@@ -209,14 +210,18 @@ void clear_area_graph_nodes(void) {
s32 i;
if (gCurrentArea != NULL) {
#ifndef DISABLE_GRAPH_NODE_TYPE_FUNCTIONAL
geo_call_global_function_nodes(&gCurrentArea->graphNode->node, GEO_CONTEXT_AREA_UNLOAD);
#endif
gCurrentArea = NULL;
gWarpTransition.isActive = FALSE;
}
for (i = 0; i < 8; i++) {
for (i = 0; i < AREA_COUNT; i++) {
if (gAreaData[i].graphNode != NULL) {
#ifndef DISABLE_GRAPH_NODE_TYPE_FUNCTIONAL
geo_call_global_function_nodes(&gAreaData[i].graphNode->node, GEO_CONTEXT_AREA_INIT);
#endif
gAreaData[i].graphNode = NULL;
}
}
@@ -237,14 +242,18 @@ void load_area(s32 index) {
}
load_obj_warp_nodes();
#ifndef DISABLE_GRAPH_NODE_TYPE_FUNCTIONAL
geo_call_global_function_nodes(&gCurrentArea->graphNode->node, GEO_CONTEXT_AREA_LOAD);
#endif
}
}
void unload_area(void) {
if (gCurrentArea != NULL) {
unload_objects_from_area(0, gCurrentArea->index);
#ifndef DISABLE_GRAPH_NODE_TYPE_FUNCTIONAL
geo_call_global_function_nodes(&gCurrentArea->graphNode->node, GEO_CONTEXT_AREA_UNLOAD);
#endif
gCurrentArea->flags = AREA_FLAG_UNLOAD;
gCurrentArea = NULL;
@@ -260,14 +269,16 @@ void load_mario_area(void) {
gCurrentArea->flags |= AREA_FLAG_LOAD;
spawn_objects_from_info(0, gMarioSpawnInfo);
}
if (gAreaSkyboxStart[gCurrAreaIndex - 1]) {
load_segment_decompress(0x0A, gAreaSkyboxStart[gCurrAreaIndex - 1], gAreaSkyboxEnd[gCurrAreaIndex - 1]);
load_segment_decompress(SEGMENT_SKYBOX, gAreaSkyboxStart[gCurrAreaIndex - 1], gAreaSkyboxEnd[gCurrAreaIndex - 1]);
}
}
void unload_mario_area(void) {
if (gCurrentArea != NULL && (gCurrentArea->flags & AREA_FLAG_LOAD)) {
if ((gCurrentArea != NULL) && (gCurrentArea->flags & AREA_FLAG_LOAD)) {
unload_objects_from_area(0, gMarioSpawnInfo->activeAreaIndex);
gCurrentArea->flags &= ~AREA_FLAG_LOAD;
if (gCurrentArea->flags == AREA_FLAG_UNLOAD) {
unload_area();
@@ -283,10 +294,10 @@ void change_area(s32 index) {
load_area(index);
gCurrentArea->flags = areaFlags;
gMarioObject->oActiveParticleFlags = 0;
gMarioObject->oActiveParticleFlags = ACTIVE_PARTICLE_NONE;
}
if (areaFlags & 0x01) {
if (areaFlags & AREA_FLAG_LOAD) {
gMarioObject->header.gfx.areaIndex = index, gMarioSpawnInfo->areaIndex = index;
}
}
@@ -300,7 +311,7 @@ void area_update_objects(void) {
* Sets up the information needed to play a warp transition, including the
* transition type, time in frames, and the RGB color that will fill the screen.
*/
void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue) {
void play_transition(s16 transType, s16 time, Color red, Color green, Color blue) {
#ifndef L3DEX2_ALONE
gWarpTransition.isActive = TRUE;
gWarpTransition.type = transType;
@@ -308,13 +319,13 @@ void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue) {
gWarpTransition.pauseRendering = FALSE;
// The lowest bit of transType determines if the transition is fading in or out.
if (transType & 1) {
if (transType & WARP_TRANSITION_FADE_INTO) {
set_warp_transition_rgb(red, green, blue);
} else {
red = gWarpTransRed, green = gWarpTransGreen, blue = gWarpTransBlue;
}
if (transType < 8) { // if transition is RGB
if (transType < WARP_TRANSITION_TYPE_STAR) { // if transition is WARP_TRANSITION_TYPE_COLOR
gWarpTransition.data.red = red;
gWarpTransition.data.green = green;
gWarpTransition.data.blue = blue;
@@ -327,24 +338,22 @@ void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue) {
// If you really wanted to, you could place the start at one corner and the end at
// the opposite corner. This will make the transition image look like it is moving
// across the screen.
gWarpTransition.data.startTexX = SCREEN_WIDTH / 2;
gWarpTransition.data.startTexY = SCREEN_HEIGHT / 2;
gWarpTransition.data.endTexX = SCREEN_WIDTH / 2;
gWarpTransition.data.endTexY = SCREEN_HEIGHT / 2;
gWarpTransition.data.startTexX = SCREEN_CENTER_X;
gWarpTransition.data.startTexY = SCREEN_CENTER_Y;
gWarpTransition.data.endTexX = SCREEN_CENTER_X;
gWarpTransition.data.endTexY = SCREEN_CENTER_Y;
gWarpTransition.data.texTimer = 0;
if (transType & 1) // Is the image fading in?
{
if (transType & WARP_TRANSITION_FADE_INTO) { // Is the image fading in?
gWarpTransition.data.startTexRadius = GFX_DIMENSIONS_FULL_RADIUS;
if (transType >= 0x0F) {
if (transType >= WARP_TRANSITION_FADES_INTO_LARGE) {
gWarpTransition.data.endTexRadius = 16;
} else {
gWarpTransition.data.endTexRadius = 0;
}
} else // The image is fading out. (Reverses start & end circles)
{
if (transType >= 0x0E) {
} else { // The image is fading out. (Reverses start & end circles)
if (transType >= WARP_TRANSITION_FADES_FROM_LARGE) {
gWarpTransition.data.startTexRadius = 16;
} else {
gWarpTransition.data.startTexRadius = 0;
@@ -366,6 +375,10 @@ void play_transition_after_delay(s16 transType, s16 time, u8 red, u8 green, u8 b
}
void render_game(void) {
#if PUPPYPRINT_DEBUG
OSTime first = osGetTime();
OSTime colTime = collisionTime[perfIteration];
#endif
if (gCurrentArea != NULL && !gWarpTransition.pauseRendering) {
if (gCurrentArea->graphNode) {
geo_process_root(gCurrentArea->graphNode, gViewportOverride, gViewportClip, gFBSetColor);
@@ -400,7 +413,7 @@ void render_game(void) {
gWarpTransition.isActive = !render_screen_transition(0, gWarpTransition.type, gWarpTransition.time,
&gWarpTransition.data);
if (!gWarpTransition.isActive) {
if (gWarpTransition.type & 1) {
if (gWarpTransition.type & WARP_TRANSITION_FADE_INTO) {
gWarpTransition.pauseRendering = TRUE;
} else {
set_warp_transition_rgb(0, 0, 0);
@@ -415,15 +428,17 @@ void render_game(void) {
if (gViewportClip != NULL) {
clear_viewport(gViewportClip, gWarpTransFBSetColor);
} else {
clear_frame_buffer(gWarpTransFBSetColor);
clear_framebuffer(gWarpTransFBSetColor);
}
}
#if PUPPYPRINT_DEBUG
puppyprint_render_profiler();
#endif
gViewportOverride = NULL;
gViewportClip = NULL;
gViewportClip = NULL;
#if PUPPYPRINT_DEBUG
profiler_update(graphTime, first);
graphTime[perfIteration] -= (collisionTime[perfIteration] - colTime);
// graphTime[perfIteration] -= profilerTime[perfIteration]; //! Graph time is inaccurate and wrongly reaches 0 sometimes
puppyprint_render_profiler();
#endif
}
+45 -32
View File
@@ -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 *modelNode;
/*0x18*/ struct GraphNode *model;
/*0x1C*/ struct SpawnInfo *next;
};
struct UnusedArea28
{
struct UnusedArea28 {
/*0x00*/ s16 unk00;
/*0x02*/ s16 unk02;
/*0x04*/ s16 unk04;
@@ -54,17 +49,17 @@ struct UnusedArea28
/*0x08*/ s16 unk08;
};
struct Whirlpool
{
struct Whirlpool {
/*0x00*/ Vec3s pos;
/*0x03*/ s16 strength;
};
#define AREA_FLAG_UNLOAD 0x0
#define AREA_FLAG_LOAD 0x1
enum AreaFlags {
AREA_FLAG_UNLOAD,
AREA_FLAG_LOAD
};
struct Area
{
struct Area {
/*0x00*/ s8 index;
/*0x01*/ s8 flags; // Only has 1 flag: 0x01 = Is this the active area?
/*0x02*/ TerrainData terrainType; // default terrain of the level (set from level script cmd 0x31)
@@ -77,7 +72,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;
@@ -85,8 +80,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;
@@ -101,19 +95,38 @@ struct WarpTransitionData
/*0x10*/ s16 texTimer; // always 0, does seems to affect transition when disabled
};
#define WARP_TRANSITION_FADE_FROM_COLOR 0x00
#define WARP_TRANSITION_FADE_INTO_COLOR 0x01
#define WARP_TRANSITION_FADE_FROM_STAR 0x08
#define WARP_TRANSITION_FADE_INTO_STAR 0x09
#define WARP_TRANSITION_FADE_FROM_CIRCLE 0x0A
#define WARP_TRANSITION_FADE_INTO_CIRCLE 0x0B
#define WARP_TRANSITION_FADE_FROM_MARIO 0x10
#define WARP_TRANSITION_FADE_INTO_MARIO 0x11
#define WARP_TRANSITION_FADE_FROM_BOWSER 0x12
#define WARP_TRANSITION_FADE_INTO_BOWSER 0x13
enum WarpTransitionFadeDirections {
WARP_TRANSITION_FADE_FROM,
WARP_TRANSITION_FADE_INTO
};
struct WarpTransition
{
enum WarpTransitionTypes {
WARP_TRANSITION_TYPE_COLOR = 0x00,
WARP_TRANSITION_TYPE_STAR = 0x08,
WARP_TRANSITION_TYPE_CIRCLE = 0x0A,
WARP_TRANSITION_TYPES_LARGE = 0x0E,
WARP_TRANSITION_TYPE_MARIO = 0x10,
WARP_TRANSITION_TYPE_BOWSER = 0x12,
WARP_TRANSITION_TYPES_MASK = 0x1E
};
enum WarpTransitions {
WARP_TRANSITION_FADE_FROM_COLOR = (WARP_TRANSITION_TYPE_COLOR | WARP_TRANSITION_FADE_FROM), // 0x00
WARP_TRANSITION_FADE_INTO_COLOR = (WARP_TRANSITION_TYPE_COLOR | WARP_TRANSITION_FADE_INTO), // 0x01
WARP_TRANSITION_FADE_FROM_STAR = (WARP_TRANSITION_TYPE_STAR | WARP_TRANSITION_FADE_FROM), // 0x08
WARP_TRANSITION_FADE_INTO_STAR = (WARP_TRANSITION_TYPE_STAR | WARP_TRANSITION_FADE_INTO), // 0x09
WARP_TRANSITION_FADE_FROM_CIRCLE = (WARP_TRANSITION_TYPE_CIRCLE | WARP_TRANSITION_FADE_FROM), // 0x0A
WARP_TRANSITION_FADE_INTO_CIRCLE = (WARP_TRANSITION_TYPE_CIRCLE | WARP_TRANSITION_FADE_INTO), // 0x0B
WARP_TRANSITION_FADES_FROM_LARGE = (WARP_TRANSITION_TYPES_LARGE | WARP_TRANSITION_FADE_FROM), // 0x0E
WARP_TRANSITION_FADES_INTO_LARGE = (WARP_TRANSITION_TYPES_LARGE | WARP_TRANSITION_FADE_INTO), // 0x0F
WARP_TRANSITION_FADE_FROM_MARIO = (WARP_TRANSITION_TYPE_MARIO | WARP_TRANSITION_FADE_FROM), // 0x10
WARP_TRANSITION_FADE_INTO_MARIO = (WARP_TRANSITION_TYPE_MARIO | WARP_TRANSITION_FADE_INTO), // 0x11
WARP_TRANSITION_FADE_FROM_BOWSER = (WARP_TRANSITION_TYPE_BOWSER | WARP_TRANSITION_FADE_FROM), // 0x12
WARP_TRANSITION_FADE_INTO_BOWSER = (WARP_TRANSITION_TYPE_BOWSER | WARP_TRANSITION_FADE_INTO), // 0x13
};
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)
+28 -13
View File
@@ -65,13 +65,27 @@
#include "behaviors/white_puff_explode.inc.c"
// not in behavior file
struct SpawnParticlesInfo sMistParticles = { 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) {
sMistParticles.sizeBase = size;
sMistParticles.sizeRange = size / 20.0f;
sMistParticles.offsetY = offsetY;
if (count == 0) {
sMistParticles.count = 20;
} else if (count > 20) {
@@ -79,6 +93,7 @@ void spawn_mist_particles_variable(s32 count, s32 offsetY, f32 size) {
} else {
sMistParticles.count = 4;
}
cur_obj_spawn_particles(&sMistParticles);
}
@@ -110,7 +125,6 @@ void spawn_mist_particles_variable(s32 count, s32 offsetY, f32 size) {
#include "behaviors/piranha_bubbles.inc.c"
#include "behaviors/purple_switch.inc.c"
#include "behaviors/metal_box.inc.c"
#include "behaviors/switch_hidden_objects.inc.c"
#include "behaviors/breakable_box.inc.c"
// not sure what this is doing here. not in a behavior file.
@@ -125,6 +139,7 @@ Gfx *geo_move_mario_part_from_parent(s32 callContext, UNUSED struct GraphNode *n
obj_set_gfx_pos_from_pos(obj->prevObj);
}
}
return NULL;
}
@@ -135,19 +150,19 @@ Gfx *geo_move_mario_part_from_parent(s32 callContext, UNUSED struct GraphNode *n
#include "behaviors/jumping_box.inc.c"
#include "behaviors/boo_cage.inc.c"
static s16 sSpawnSparkleParticleAngle = 0x0;
// not in behavior file
// n is the number of objects to spawn, r if the rate of change of phase (frequency?)
void spawn_sparkle_particles(s32 n, s32 radius, s32 height, s32 r) {
static s16 spawnSparkleParticleAngle = 0x0;
s32 i;
s16 separation = 0x10000 / n; // Evenly spread around a circle
for (i = 0; i < n; i++) {
spawn_object_relative(0, sins(sSpawnSparkleParticleAngle + i * separation) * radius, (i + 1) * height,
coss(sSpawnSparkleParticleAngle + i * separation) * radius, o, MODEL_NONE, bhvSparkleSpawn);
spawn_object_relative(OBJ_BP_NONE, sins(spawnSparkleParticleAngle + i * separation) * radius, (i + 1) * height,
coss(spawnSparkleParticleAngle + i * separation) * radius, o, MODEL_NONE, bhvSparkleSpawn);
}
sSpawnSparkleParticleAngle += r * 0x100;
spawnSparkleParticleAngle += r * 0x100;
}
#include "behaviors/beta_boo_key.inc.c"
@@ -178,15 +193,15 @@ void spawn_sparkle_particles(s32 n, s32 radius, s32 height, s32 r) {
#include "behaviors/piranha_plant.inc.c"
#include "behaviors/bowser_puzzle_piece.inc.c"
s32 set_obj_anim_with_accel_and_sound(s16 frame1, s16 frame2, s32 sound) {
f32 range;
if ((range = o->header.gfx.animInfo.animAccel / (f32) 0x10000) == 0)
range = 1.0f;
void set_obj_anim_with_accel_and_sound(s16 frame1, s16 frame2, s32 sound) {
s32 range = o->header.gfx.animInfo.animAccel / 0x10000;
if (range == 0) {
range = 1;
}
if (cur_obj_check_anim_frame_in_range(frame1, range) || cur_obj_check_anim_frame_in_range(frame2, range)) {
cur_obj_play_sound_2(sound);
return TRUE;
}
return FALSE;
}
#include "behaviors/tuxie.inc.c"
+13 -14
View File
@@ -2,28 +2,28 @@
#define BEHAVIOR_ACTIONS_H
void spawn_mist_particles_variable(s32 count, s32 offsetY, f32 size);
void bhv_spawn_star_no_level_exit(u32);
void bhv_star_door_loop_2(void);
void bhv_spawn_star_no_level_exit(u32 params);
void bhv_door_rendering_loop(void);
void spawn_triangle_break_particles(s16 numTris, s16 triModel, f32 triSize, s16 triAnimState);
void spawn_mist_from_global(void);
void clear_particle_flags(u32 flags);
void spawn_wind_particles(s16 pitch, s16 yaw);
s32 check_if_moving_over_floor(f32 a0, f32 a1);
s32 check_if_moving_over_floor(f32 maxDist, f32 offset);
s32 arc_to_goal_pos(Vec3f a0, Vec3f a1, f32 yVel, f32 gravity);
void tox_box_move(f32 forwardVel, f32 a1, s16 deltaPitch, s16 deltaRoll);
void play_penguin_walking_sound(s32 walk);
s32 update_angle_from_move_flags(s32 *angle);
void cur_obj_spawn_strong_wind_particles(s32 windSpread, f32 scale, f32 relPosX, f32 relPosY, f32 relPosZ);
//! Lots of these are duplicates
void bhv_cap_switch_loop(void);
void bhv_tiny_star_particles_init(void);
void bhv_grindel_thwomp_loop(void);
void bhv_koopa_shell_underwater_loop(void);
void bhv_door_init(void);
void bhv_door_loop(void);
void bhv_star_door_loop(void);
void bhv_mr_i_loop(void);
void bhv_mr_i_iris_loop(void);
void bhv_mr_i_body_loop(void);
void bhv_mr_i_particle_loop(void);
void bhv_piranha_particle_loop(void);
@@ -67,8 +67,8 @@ void bhv_spawned_star_loop(void);
void bhv_coin_init(void);
void bhv_coin_loop(void);
void bhv_coin_inside_boo_loop(void);
void bhv_coin_formation_spawned_coin_loop(void);
void bhv_coin_formation_init(void);
void bhv_coin_formation_spawn_loop(void);
void bhv_coin_formation_loop(void);
void bhv_temp_coin_loop(void);
void bhv_coin_sparkles_loop(void);
@@ -202,11 +202,10 @@ void bhv_wdw_express_elevator_loop(void);
void bhv_bub_spawner_loop(void);
void bhv_bub_loop(void);
void bhv_exclamation_box_loop(void);
void bhv_rotating_exclamation_box_loop(void);
void bhv_rotating_exclamation_mark_loop(void);
void bhv_sound_spawner_init(void);
void bhv_bowsers_sub_loop(void);
void bhv_sushi_shark_loop(void);
void bhv_sushi_shark_collision_loop(void);
void bhv_jrb_sliding_box_loop(void);
void bhv_ship_part_3_loop(void);
void bhv_sunken_ship_part_loop(void);
@@ -488,8 +487,8 @@ void bhv_ttc_spinner_update(void);
void bhv_mr_blizzard_init(void);
void bhv_mr_blizzard_update(void);
void bhv_mr_blizzard_snowball(void);
void bhv_sliding_plat_2_init(void);
void bhv_sliding_plat_2_loop(void);
void bhv_sliding_platform_init(void);
void bhv_sliding_platform_loop(void);
void bhv_rotating_octagonal_plat_init(void);
void bhv_rotating_octagonal_plat_loop(void);
void bhv_animates_on_floor_switch_press_init(void);
@@ -512,9 +511,9 @@ void bhv_haunted_bookshelf_manager_loop(void);
void bhv_book_switch_loop(void);
void bhv_fire_piranha_plant_init(void);
void bhv_fire_piranha_plant_update(void);
void bhv_small_piranha_flame_loop(void);
void bhv_moving_flame_loop(void);
void bhv_moving_flame_particle_loop(void);
void bhv_fire_spitter_update(void);
void bhv_fly_guy_flame_loop(void);
void bhv_snufit_loop(void);
void bhv_snufit_balls_loop(void);
void bhv_horizontal_grindel_init(void);
@@ -565,8 +564,8 @@ Gfx *geo_switch_tuxie_mother_eyes(s32 callContext, struct GraphNode *node, UNUSE
Gfx *geo_update_held_mario_pos(s32 callContext, UNUSED struct GraphNode *node, Mat4 mtx);
// Snufit
Gfx *geo_snufit_move_mask(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
Gfx *geo_snufit_scale_body(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c);
Gfx *geo_snufit_move_mask(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx);
Gfx *geo_snufit_scale_body(s32 callContext, struct GraphNode *node, UNUSED Mat4 *mtx);
// Bowser key cutscene
Gfx *geo_scale_bowser_key(s32 callContext, struct GraphNode *node, UNUSED Mat4 mtx);
+14 -18
View File
@@ -1,3 +1,4 @@
/**
* Behavior for bhvActivatedBackAndForthPlatform.
* There are only 2 of these in the game; the BitFS gray elevator
@@ -16,23 +17,24 @@
* 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[] = {
/* 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
static Collision const *sActivatedBackAndForthPlatformCollisionModels[] = {
/* ACTIVATED_BF_PLAT_TYPE_BITS_ARROW_PLAT */ bits_seg7_collision_arrow_platform,
/* ACTIVATED_BF_PLAT_TYPE_BITFS_MESH_PLAT */ bitfs_seg7_collision_platform_on_track,
/* ACTIVATED_BF_PLAT_TYPE_BITFS_ELEVATOR */ bitfs_seg7_collision_elevator
};
/**
* Activated back-and-forth platform initialization function.
*/
//! TODO: Param names
void bhv_activated_back_and_forth_platform_init(void) {
// Equivalent to the first behavior param byte & 3 (last 2 bits of the byte).
s32 platformType = ((u16)(o->oBehParams >> 16) & 0x0300) >> 8;
s32 platformType = GET_BPARAM1(o->oBehParams) & ACTIVATED_BF_PLAT_TYPES_MASK;
// The BitS arrow platform should flip 180º (0x8000 angle units), but
// there is no reason for the other platforms to flip.
if (platformType != ACTIVATED_BF_PLAT_TYPE_BITS_ARROW_PLAT) {
o->oActivatedBackAndForthPlatformFlipRotation = 0;
o->oActivatedBackAndForthPlatformFlipRotation = 0x0000;
} else {
o->oActivatedBackAndForthPlatformFlipRotation = 0x8000;
}
@@ -44,7 +46,7 @@ void bhv_activated_back_and_forth_platform_init(void) {
// Equivalent to 50 * (oBehParams2ndByte & 0x7F), i.e. 50 * (oBehParams2ndByte % 128).
// The maximum possible value of this is 50 * 127 = 6350.
// It's 50 * 97 = 4850 in BitS and 50 * 31 = 1550 in BitFS.
o->oActivatedBackAndForthPlatformMaxOffset = 50.0f * ((u16)(o->oBehParams >> 16) & 0x007F);
o->oActivatedBackAndForthPlatformMaxOffset = 50.0f * (GET_BPARAM2(o->oBehParams) & 0x7F);
if (platformType == ACTIVATED_BF_PLAT_TYPE_BITFS_ELEVATOR) {
o->oActivatedBackAndForthPlatformMaxOffset -= 12.0f;
@@ -52,7 +54,7 @@ void bhv_activated_back_and_forth_platform_init(void) {
// Truthy/falsy value that determines the direction of movement.
// Equivalent to oBehParams2ndByte & 0x80, i.e. the most significant bit of oBehParams2ndByte.
o->oActivatedBackAndForthPlatformVertical = (u16)(o->oBehParams >> 16) & 0x0080;
o->oActivatedBackAndForthPlatformVertical = GET_BPARAM2(o->oBehParams) & 0x80;
o->oActivatedBackAndForthPlatformStartYaw = o->oFaceAngleYaw;
}
@@ -63,11 +65,7 @@ void bhv_activated_back_and_forth_platform_init(void) {
void bhv_activated_back_and_forth_platform_update(void) {
// oVelY is used for vertical platforms' movement and also for
// horizontal platforms' dipping up/down when Mario gets on/off them
if (gMarioObject->platform == o) {
o->oVelY = -6.0f;
} else {
o->oVelY = 6.0f;
}
o->oVelY = (gMarioObject->platform == o) ? -6.0f : 6.0f;
// If the platform's velocity is set...
if (o->oActivatedBackAndForthPlatformVel != 0.0f) {
@@ -76,7 +74,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.
@@ -87,9 +85,8 @@ void bhv_activated_back_and_forth_platform_update(void) {
// or Mario is over 3000 units away, the platform will reset the wait timer and flip around.
if (clamp_f32(&o->oActivatedBackAndForthPlatformOffset, 0.0f,
o->oActivatedBackAndForthPlatformMaxOffset)
||
// The platform will not reset if Mario goes far away and it's travelling backwards
(o->oActivatedBackAndForthPlatformVel > 0.0f && o->oDistanceToMario > 3000.0f)) {
|| ((o->oActivatedBackAndForthPlatformVel > 0.0f) && (o->oDistanceToMario > 3000.0f))) {
// Reset the wait timer
o->oActivatedBackAndForthPlatformCountdown = 20;
@@ -128,8 +125,7 @@ void bhv_activated_back_and_forth_platform_update(void) {
// ...set its position to its original position + the offset.
o->oPosY = o->oHomeY + o->oActivatedBackAndForthPlatformOffset;
} else {
// Otherwise, dip down 20 units if Mario gets on the horizontal platform, and undo if he gets
// off.
// Otherwise, dip down 20 units if Mario gets on the horizontal platform, and undo if he gets off.
o->oPosY += o->oVelY;
clamp_f32(&o->oPosY, o->oHomeY - 20.0f, o->oHomeY);
+19 -29
View File
@@ -1,3 +1,4 @@
/**
* Behavior for bhvHomingAmp and bhvCirclingAmp.
* These are distinct objects; one chases (homes in on) Mario,
@@ -21,8 +22,8 @@ static struct ObjectHitbox sAmpHitbox = {
* Homing amp initialization function.
*/
void bhv_homing_amp_init(void) {
vec3_copy(&o->oHomeVec, &o->oPosVec);
o->oGravity = 0;
vec3f_copy(&o->oHomeVec, &o->oPosVec);
o->oGravity = 0.0f;
o->oFriction = 1.0f;
o->oBuoyancy = 1.0f;
o->oHomingAmpAvgY = o->oHomeY;
@@ -45,18 +46,12 @@ static void check_amp_attack(void) {
obj_set_hitbox(o, &sAmpHitbox);
if (o->oInteractStatus & INT_STATUS_INTERACTED) {
// Unnecessary if statement, maybe caused by a macro for
// 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,
// AMP_ACT_ATTACK_COOLDOWN == HOMING_AMP_ACT_ATTACK_COOLDOWN
o->oAction = AMP_ACT_ATTACK_COOLDOWN;
}
// This function is used for both normal amps and homing amps,
// AMP_ACT_ATTACK_COOLDOWN == HOMING_AMP_ACT_ATTACK_COOLDOWN
o->oAction = AMP_ACT_ATTACK_COOLDOWN;
// Clear interact status
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
}
}
@@ -86,7 +81,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;
@@ -119,7 +114,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 {
@@ -127,7 +122,7 @@ static void homing_amp_chase_loop(void) {
// while curving towards him.
o->oForwardVel = 10.0f;
obj_turn_toward_object(o, gMarioObject, 16, 0x400);
obj_turn_toward_object(o, gMarioObject, O_MOVE_ANGLE_YAW_INDEX, 0x400);
// The amp's average Y will approach Mario's graphical Y position + 250
// at a rate of 10 units per frame. Interestingly, this is different from
@@ -156,15 +151,13 @@ 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;
o->oPosZ = o->oHomeZ;
vec3f_copy(&o->oPosVec, &o->oHomeVec);
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;
}
}
@@ -175,15 +168,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;
@@ -231,9 +224,7 @@ void bhv_homing_amp_loop(void) {
* Circling amp initialization function.
*/
void bhv_circling_amp_init(void) {
o->oHomeX = o->oPosX;
o->oHomeY = o->oPosY;
o->oHomeZ = o->oPosZ;
vec3f_copy(&o->oHomeVec, &o->oPosVec);
o->oAnimState = 1;
// Determine the radius of the circling amp's circle
@@ -268,11 +259,11 @@ void bhv_circling_amp_init(void) {
static void fixed_circling_amp_idle_loop(void) {
// Turn towards Mario, in both yaw and pitch.
f32 xToMario = gMarioObject->header.gfx.pos[0] - o->oPosX;
f32 yToMario = gMarioObject->header.gfx.pos[1] + 120.0f - o->oPosY;
f32 yToMario = gMarioObject->header.gfx.pos[1] - o->oPosY + 120.0f;
f32 zToMario = gMarioObject->header.gfx.pos[2] - o->oPosZ;
s16 vAngleToMario = atan2s(sqrtf(xToMario * xToMario + zToMario * zToMario), -yToMario);
obj_turn_toward_object(o, gMarioObject, 19, 0x1000);
obj_turn_toward_object(o, gMarioObject, O_FACE_ANGLE_YAW_INDEX, 0x1000);
o->oFaceAnglePitch = approach_s16_symmetric(o->oFaceAnglePitch, vAngleToMario, 0x1000);
// Oscillate 40 units up and down.
@@ -330,7 +321,6 @@ void bhv_circling_amp_loop(void) {
} else {
circling_amp_idle_loop();
}
break;
case AMP_ACT_ATTACK_COOLDOWN:
@@ -1,7 +1,7 @@
// animated_floor_switch.inc.c
struct FloorSwitchTriggeredAnimationFrame {
const void *collisionDataPtr;
const Collision *collision;
ModelID16 model;
};
@@ -63,7 +63,7 @@ void bhv_animates_on_floor_switch_press_loop(void) {
}
if (o->oFloorSwitchPressAnimationDoubleFrame < 9) {
o->oFloorSwitchPressAnimationDoubleFrame += 1;
o->oFloorSwitchPressAnimationDoubleFrame++;
}
} else if ((o->oFloorSwitchPressAnimationDoubleFrame -= 2) < 0) {
o->oFloorSwitchPressAnimationDoubleFrame = 0;
@@ -71,7 +71,7 @@ void bhv_animates_on_floor_switch_press_loop(void) {
}
o->collisionData = segmented_to_virtual(
sFloorSwitchTriggeredAnimationFrames[o->oBehParams2ndByte][o->oFloorSwitchPressAnimationDoubleFrame / 2].collisionDataPtr);
sFloorSwitchTriggeredAnimationFrames[o->oBehParams2ndByte][o->oFloorSwitchPressAnimationDoubleFrame / 2].collision);
cur_obj_set_model(sFloorSwitchTriggeredAnimationFrames[o->oBehParams2ndByte][o->oFloorSwitchPressAnimationDoubleFrame / 2].model);
}
+1
View File
@@ -1,3 +1,4 @@
/**
* Behavior for WDW arrow lifts.
* When a player stands on an arrow lift, it starts moving between
@@ -1,3 +1,4 @@
/**
* Behavior for bhvHauntedBookshelf.
* This is the bookshelf that recedes after solving the puzzle of the haunted books.
@@ -25,10 +26,11 @@ void bhv_haunted_bookshelf_loop(void) {
}
break;
case HAUNTED_BOOKSHELF_ACT_RECEDE:
// Move the bookshelf and play the sound
o->oPosX += 5.0f;
cur_obj_play_sound_1(SOUND_ENV_ELEVATOR4_2);
cur_obj_play_sound_1(SOUND_ENV_HAUNTED_BOOKSHELF_RECEDE);
// Delete the object after 102 frames
if (o->oTimer > 101) {
@@ -36,6 +38,7 @@ void bhv_haunted_bookshelf_loop(void) {
}
break;
default:
break;
}
+3 -4
View File
@@ -1,3 +1,4 @@
/**
* Behavior for bhvMerryGoRound.
* This is the merry-go-round in BBH.
@@ -21,13 +22,11 @@ static void handle_merry_go_round_music(void) {
}
} else {
// Get Mario's floor and floor surface type
struct Surface *marioFloor;
struct Surface *marioFloor = gMarioState->floor;
u16 marioFloorType;
find_floor(gMarioObject->oPosX, gMarioObject->oPosY, gMarioObject->oPosZ, &marioFloor);
if (marioFloor == NULL) {
marioFloorType = 0;
marioFloorType = SURFACE_DEFAULT;
} else {
marioFloorType = marioFloor->type;
}
+4 -3
View File
@@ -1,3 +1,4 @@
/**
* Behavior for bhvBbhTiltingTrapPlatform.
* This is the tilting platform trap in the upper floor of BBH
@@ -8,7 +9,7 @@
* Update function for bhvBbhTiltingTrapPlatform.
*/
void bhv_bbh_tilting_trap_platform_loop(void) {
// 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.
@@ -22,14 +23,14 @@ void bhv_bbh_tilting_trap_platform_loop(void) {
o->oAngleVelPitch = (s32)(o->oDistanceToMario * coss(o->oAngleToMario));
o->oFaceAnglePitch += o->oAngleVelPitch;
} else
// 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)) {
// Make the platform return to the horizontal at a speed of
// 200 angle units/frame, and clamp it to 0 if it's within 200 units of 0.
o->oAngleVelPitch = 0;
+7 -3
View File
@@ -1,3 +1,4 @@
/**
* Behavior for bhvAlphaBooKey and bhvBetaBooKey.
* They were apparently intended to be a key that would be contained in boos
@@ -94,7 +95,7 @@ static void beta_boo_key_dropped_loop(void) {
// 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 = TRUE;
o->parentObj->oInteractStatus = TRUE; //! Note: Not a flag, treated as a TRUE/FALSE statement
// 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 ObjActionFunc sBetaBooKeyActions[] = {
beta_boo_key_inside_boo_loop,
beta_boo_key_drop,
beta_boo_key_dropped_loop,
};
/**
* Update function for bhvBetaBooKey.
+4 -3
View File
@@ -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);
}
+4 -2
View File
@@ -1,3 +1,4 @@
/**
* Behavior for bhvBetaChestBottom and bhvBetaChestLid.
* These are apparently the beta versions of chests.
@@ -49,11 +50,12 @@ 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.
spawn_object_relative(0, 0, -80, 120, o, MODEL_BUBBLE, bhvWaterAirBubble);
play_sound(SOUND_GENERAL_CLAM_SHELL1, o->header.gfx.cameraToObject);
play_sound(SOUND_GENERAL_OPEN_CHEST_WATER, o->header.gfx.cameraToObject);
}
// Rotate the lid 0x400 (1024) angle units per frame backwards.
@@ -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;
}
@@ -1,3 +1,4 @@
/**
* Behavior for bhvBetaFishSplashSpawner.
* This is a now non-functional fish splash object found in WF
@@ -12,5 +13,5 @@
* Update function for bhvBetaFishSplashSpawner.
*/
void bhv_beta_fish_splash_spawner_loop(void) {
// UNUSED f32 water_level = find_water_level(o->oPosX, o->oPosZ);
// UNUSED f32 waterLevel = find_water_level(o->oPosX, o->oPosZ);
}
@@ -1,3 +1,4 @@
/**
* Behavior for bhvBetaHoldableObject.
* This is a simple implementation of a holdable object, probably used
@@ -11,7 +12,7 @@
* Just sets various physics constants for the object.
*/
void bhv_beta_holdable_object_init(void) {
o->oGravity = 2.5f;
o->oGravity = 2.5f;
o->oFriction = 0.8f;
o->oBuoyancy = 1.3f;
}
@@ -27,17 +28,14 @@ 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;
}
/**
* Throw the object.
*/
static void beta_holdable_object_throw(void) {
// cur_obj_enable_rendering_2 just calls cur_obj_enable_rendering and does
// nothing else; it's useless here. Maybe it originally did more?
cur_obj_enable_rendering_2();
cur_obj_enable_rendering();
o->oHeldState = HELD_FREE;
@@ -47,7 +45,7 @@ static void beta_holdable_object_throw(void) {
// Set initial velocity
o->oForwardVel = 40.0f;
o->oVelY = 20.0f;
o->oVelY = 20.0f;
}
/**
+3 -1
View File
@@ -1,3 +1,4 @@
/**
* Behavior for bhvBetaTrampolineTop and bhvBetaTrampolineSpring.
* This was a trampoline that was never finished. The model and collision
@@ -28,7 +29,8 @@ void bhv_beta_trampoline_spring_loop(void) {
// scale the spring by (the displacement)/10 + 1.
// For this to work correctly, the arbitrary value of 10
// must be replaced with 150 (the height of the trampoline).
if ((yDisplacement = o->oPosY - o->oHomeY) >= 0) {
yDisplacement = o->oPosY - o->oHomeY;
if (yDisplacement >= 0) {
yScale = yDisplacement / 150.0f + 1.0f;
} else {
// Otherwise (if the trampoline is compressed),
+1
View File
@@ -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
+11 -6
View File
@@ -1,3 +1,4 @@
/**
* Behavior for bhvHiddenBlueCoin and bhvBlueCoinSwitch.
* bhvHiddenBlueCoin are the stationary blue coins that appear when
@@ -20,19 +21,21 @@ void bhv_hidden_blue_coin_loop(void) {
o->oHiddenBlueCoinSwitch = cur_obj_nearest_object_with_behavior(bhvBlueCoinSwitch);
if (o->oHiddenBlueCoinSwitch != NULL) {
o->oAction++;
o->oAction = HIDDEN_BLUE_COIN_ACT_WAITING;
}
break;
case HIDDEN_BLUE_COIN_ACT_WAITING:
// Wait until the blue coin switch starts ticking to activate.
blueCoinSwitch = o->oHiddenBlueCoinSwitch;
if (blueCoinSwitch->oAction == BLUE_COIN_SWITCH_ACT_TICKING) {
o->oAction++; // Set to HIDDEN_BLUE_COIN_ACT_ACTIVE
o->oAction = HIDDEN_BLUE_COIN_ACT_ACTIVE;
}
break;
case HIDDEN_BLUE_COIN_ACT_ACTIVE:
// Become tangible
cur_obj_enable_rendering();
@@ -60,7 +63,7 @@ void bhv_hidden_blue_coin_loop(void) {
break;
}
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
}
/**
@@ -80,10 +83,10 @@ void bhv_blue_coin_switch_loop(void) {
o->oAction = BLUE_COIN_SWITCH_ACT_RECEDING;
#ifdef BLUE_COIN_SWITCH_RETRY
// Recede at a rate of 16 units/frame.
o->oVelY = -16.0f;
o->oVelY = -16.0f;
#else
// Recede at a rate of 20 units/frame.
o->oVelY = -20.0f;
o->oVelY = -20.0f;
#endif
// Set gravity to 0 so it doesn't accelerate when receding.
o->oGravity = 0.0f;
@@ -96,6 +99,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
@@ -113,7 +117,7 @@ void bhv_blue_coin_switch_loop(void) {
o->oVelY = 0.0f;
o->oGravity = 0.0f;
#else
o->oPosY = (gMarioObject->oPosY - 40.0f);
o->oPosY = gMarioObject->oPosY - 40.0f;
#endif
// Spawn particles. There's a function that calls this same function
@@ -127,6 +131,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) {
+7 -1
View File
@@ -1,3 +1,4 @@
/**
* @file blue_fish.inc.c
* Implements behaviour and spawning for bhvBlueFish located in the castle aquarium outside of SA.
@@ -8,6 +9,7 @@
*/
void bhv_blue_fish_movement_loop(void) {
f32 randomSwitch;
switch (o->oAction) {
// Initial dive phase after spawning
case BLUE_FISH_ACT_DIVE:
@@ -15,7 +17,7 @@ void bhv_blue_fish_movement_loop(void) {
// 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;
@@ -44,6 +46,7 @@ void bhv_blue_fish_movement_loop(void) {
// 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);
@@ -52,6 +55,7 @@ void bhv_blue_fish_movement_loop(void) {
o->oAction++;
}
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);
@@ -68,6 +72,7 @@ void bhv_blue_fish_movement_loop(void) {
o->oFaceAnglePitch += o->oAngleVelPitch;
}
break;
// Animates and turns fish around
case BLUE_FISH_ACT_TURN_BACK:
cur_obj_init_animation_with_accel_and_sound(0, 2.0f);
@@ -97,6 +102,7 @@ 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) {
+98 -80
View File
@@ -1,4 +1,4 @@
// bobomb.c.inc
// bobomb.inc.c
static struct ObjectHitbox sBobombHitbox = {
/* interactType: */ INTERACT_GRABBABLE,
@@ -13,90 +13,89 @@ static struct ObjectHitbox sBobombHitbox = {
};
void bhv_bobomb_init(void) {
o->oGravity = 2.5f;
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 (!(GET_BPARAM3(o->oBehParams) & RESPAWN_INFO_TYPE_NORMAL)) {
obj_spawn_yellow_coins(o, 1);
o->oBehParams = 0x100;
set_object_respawn_info_bits(o, RESPAWN_INFO_TYPE_32);
SET_FULL_BPARAM3(o->oBehParams, RESPAWN_INFO_TYPE_NORMAL);
set_object_respawn_info_bits(o, RESPAWN_INFO_TYPE_NORMAL);
}
}
void bobomb_act_explode(void) {
struct Object *explosion;
if (o->oTimer < 5)
cur_obj_scale(1.0f + (f32) o->oTimer / 5.0f);
else {
explosion = spawn_object(o, MODEL_EXPLOSION, bhvExplosion);
if (o->oTimer < 5) {
cur_obj_scale(1.0f + ((f32) o->oTimer / 5.0f));
} 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_KNOCKBACK_DMG) != 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.0f;
o->oVelY = 30.0f;
o->oAction = BOBOMB_ACT_LAUNCHED;
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;
o->oInteractStatus = INT_STATUS_NONE;
}
if (obj_attack_collided_from_other_object(o) == 1)
if (obj_attack_collided_from_other_object(o)) {
o->oAction = BOBOMB_ACT_EXPLODE;
}
}
void bobomb_act_patrol(void) {
s16 collisionFlags;
o->oForwardVel = 5.0f;
collisionFlags = object_step();
if ((obj_return_home_if_safe(o, o->oHomeX, o->oHomeY, o->oHomeZ, 400) == 1)
&& (obj_check_if_facing_toward_angle(o->oMoveAngleYaw, o->oAngleToMario, 0x2000) == TRUE)) {
o->oBobombFuseLit = 1;
s16 collisionFlags = object_step();
if (obj_return_home_if_safe(o, o->oHomeX, o->oHomeY, o->oHomeZ, 400)
&& obj_check_if_facing_toward_angle(o->oMoveAngleYaw, o->oAngleToMario, 0x2000)) {
o->oBobombFuseLit = TRUE;
o->oAction = BOBOMB_ACT_CHASE_MARIO;
}
obj_check_floor_death(collisionFlags, sObjFloor);
}
void bobomb_act_chase_mario(void) {
s16 animFrame, collisionFlags;
s16 animFrame = ++o->header.gfx.animInfo.animFrame;
animFrame = ++o->header.gfx.animInfo.animFrame;
o->oForwardVel = 20.0f;
s16 collisionFlags = object_step();
collisionFlags = object_step();
if (animFrame == 5 || animFrame == 16)
if (animFrame == 5 || animFrame == 16) {
cur_obj_play_sound_2(SOUND_OBJ_BOBOMB_WALK);
}
obj_turn_toward_object(o, gMarioObject, 16, 0x800);
obj_turn_toward_object(o, gMarioObject, O_MOVE_ANGLE_YAW_INDEX, 0x800);
obj_check_floor_death(collisionFlags, sObjFloor);
}
void bobomb_act_launched(void) {
s16 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) {
@@ -118,8 +117,9 @@ void generic_bobomb_free_loop(void) {
break;
case OBJ_ACT_LAVA_DEATH:
if (obj_lava_death() == 1)
if (obj_lava_death()) {
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000);
}
break;
case OBJ_ACT_DEATH_PLANE_DEATH:
@@ -130,8 +130,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) {
@@ -145,8 +146,9 @@ void stationary_bobomb_free_loop(void) {
break;
case OBJ_ACT_LAVA_DEATH:
if (obj_lava_death() == 1)
if (obj_lava_death()) {
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000);
}
break;
case OBJ_ACT_DEATH_PLANE_DEATH:
@@ -157,24 +159,26 @@ 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) {
o->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE;
cur_obj_init_animation(1);
cur_obj_set_pos_relative(gMarioObject, 0, 60.0f, 100.0f);
cur_obj_init_animation(BOBOMB_ANIM_HELD);
cur_obj_set_pos_relative(gMarioObject, 0.0f, 60.0f, 100.0f);
o->oBobombFuseLit = 1;
if (o->oBobombFuseTimer >= 151) {
o->oBobombFuseLit = TRUE;
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.
@@ -187,25 +191,23 @@ void bobomb_dropped_loop(void) {
cur_obj_get_dropped();
o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
cur_obj_init_animation(0);
cur_obj_init_animation(BOBOMB_ANIM_WALKING);
o->oHeldState = 0;
o->oHeldState = HELD_FREE;
o->oAction = BOBOMB_ACT_PATROL;
}
void bobomb_thrown_loop(void) {
cur_obj_enable_rendering_2();
cur_obj_enable_rendering();
o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
o->oHeldState = 0;
o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; /* bit 3 */
o->oHeldState = HELD_FREE;
o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW;
o->oForwardVel = 25.0f;
o->oVelY = 20.0f;
o->oAction = BOBOMB_ACT_LAUNCHED;
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) {
@@ -214,11 +216,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;
}
@@ -227,7 +234,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();
@@ -248,15 +256,17 @@ void bhv_bobomb_loop(void) {
curr_obj_random_blink(&o->oBobombBlinkTimer);
if (o->oBobombFuseLit == 1) {
if (o->oBobombFuseTimer >= 121)
if (o->oBobombFuseLit) {
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);
@@ -273,7 +283,7 @@ void bhv_bobomb_fuse_smoke_init(void) {
}
void bhv_bobomb_buddy_init(void) {
o->oGravity = 2.5f;
o->oGravity = 2.5f;
o->oFriction = 0.8f;
o->oBuoyancy = 1.3f;
o->oInteractionSubtype = INT_SUBTYPE_NPC;
@@ -282,20 +292,21 @@ void bhv_bobomb_buddy_init(void) {
void bobomb_buddy_act_idle(void) {
s16 animFrame = o->header.gfx.animInfo.animFrame;
o->oBobombBuddyPosXCopy = o->oPosX;
o->oBobombBuddyPosYCopy = o->oPosY;
o->oBobombBuddyPosZCopy = o->oPosZ;
// vec3f_copy(&o->oBobombBuddyPosCopyVec, &o->oPosVec);
object_step();
if ((animFrame == 5) || (animFrame == 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;
}
}
/**
@@ -313,27 +324,30 @@ 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:
@@ -341,7 +355,7 @@ void bobomb_buddy_cannon_dialog(s16 dialogFirstText, s16 dialogSecondText) {
o->activeFlags &= ~ACTIVE_FLAG_INITIATED_TIME_STOP;
o->oBobombBuddyHasTalkedToMario = BOBOMB_BUDDY_HAS_TALKED;
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
o->oAction = BOBOMB_BUDDY_ACT_IDLE;
o->oBobombBuddyCannonStatus = BOBOMB_BUDDY_CANNON_OPENED;
break;
@@ -360,7 +374,7 @@ void bobomb_buddy_act_talk(void) {
o->activeFlags &= ~ACTIVE_FLAG_INITIATED_TIME_STOP;
o->oBobombBuddyHasTalkedToMario = BOBOMB_BUDDY_HAS_TALKED;
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
o->oAction = BOBOMB_BUDDY_ACT_IDLE;
}
break;
@@ -378,12 +392,16 @@ void bobomb_buddy_act_talk(void) {
void bobomb_buddy_act_turn_to_talk(void) {
s16 animFrame = o->header.gfx.animInfo.animFrame;
if ((animFrame == 5) || (animFrame == 16))
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);
}
@@ -411,5 +429,5 @@ void bhv_bobomb_buddy_loop(void) {
curr_obj_random_blink(&o->oBobombBuddyBlinkTimer);
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
}
+13 -13
View File
@@ -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,34 +18,34 @@ 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) {
o->oAction = BOMP_ACT_EXTEND;
o->oForwardVel = 40.0f;
cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2);
cur_obj_play_sound_2(SOUND_OBJ_BOMP_SLIDE);
}
break;
case BOMP_ACT_EXTEND:
if (o->oPosX > 3830.0f) {
o->oPosX = 3830.0f;
o->oForwardVel = 0;
o->oForwardVel = 0.0f;
}
if (o->oTimer == 60) {
o->oAction = BOMP_ACT_RETRACT;
o->oForwardVel = 10.0f;
o->oMoveAngleYaw -= 0x8000;
cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2);
cur_obj_play_sound_2(SOUND_OBJ_BOMP_SLIDE);
}
break;
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,34 +74,34 @@ 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) {
o->oAction = BOMP_ACT_EXTEND;
o->oForwardVel = 10.0f;
cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2);
cur_obj_play_sound_2(SOUND_OBJ_BOMP_SLIDE);
}
break;
case BOMP_ACT_EXTEND:
if (o->oPosX > 3830.0f) {
o->oPosX = 3830.0f;
o->oForwardVel = 0;
o->oForwardVel = 0.0f;
}
if (o->oTimer == 60) {
o->oAction = BOMP_ACT_RETRACT;
o->oForwardVel = 10.0f;
o->oMoveAngleYaw -= 0x8000;
cur_obj_play_sound_2(SOUND_OBJ_UNKNOWN2);
cur_obj_play_sound_2(SOUND_OBJ_BOMP_SLIDE);
}
break;
case BOMP_ACT_RETRACT:
if (o->oPosX < 3330.0f) {
o->oPosX = 3330.0f;
o->oForwardVel = 0;
o->oForwardVel = 0.0f;
}
if (o->oTimer == 90) {
+93 -104
View File
@@ -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,24 +82,19 @@ static s32 boo_should_be_active(void) {
void bhv_courtyard_boo_triplet_init(void) {
s32 i;
struct Object *boo;
#ifndef UNLOCK_ALL
if (gHudDisplay.stars < 12) {
if (gHudDisplay.stars < SPAWN_CASTLE_BOO_STAR_REQUIREMENT) {
obj_mark_for_deletion(o);
} else
#endif
{
for (i = 0; i < 3; i++) {
boo = spawn_object_relative(
0x01,
struct Object *boo = spawn_object_relative( BOO_BP_NORMAL,
sCourtyardBooTripletPositions[i][0],
sCourtyardBooTripletPositions[i][1],
sCourtyardBooTripletPositions[i][2],
o,
MODEL_BOO,
bhvGhostHuntBoo
);
o, MODEL_BOO, bhvGhostHuntBoo );
OR_BPARAM1(boo->oBehParams, COIN_INSIDE_BOO_BP_YELLOW_COIN);
boo->oMoveAngleYaw = random_u16();
}
}
@@ -126,16 +119,16 @@ static void boo_approach_target_opacity_and_update_scale(void) {
}
}
scale = (o->oOpacity / 255.0f * 0.4f + 0.6f) * 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) {
o->header.gfx.scale[0] = sins(o->oBooOscillationTimer) * 0.08f + o->oBooBaseScale;
o->header.gfx.scale[1] = -sins(o->oBooOscillationTimer) * 0.08f + o->oBooBaseScale;
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];
o->oGravity = sins(o->oBooOscillationTimer) * o->oBooBaseScale;
o->oBooOscillationTimer += 0x400;
@@ -147,15 +140,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);
@@ -177,9 +168,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);
@@ -187,9 +178,16 @@ static void boo_set_move_yaw_for_during_hit(s32 hurt) {
}
// Boo Roll
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 };
static Angle sBooHitRotations[] = {
0x179F, 0x1620, 0x14AC, 0x1346,
0x11EB, 0x109E, 0x0B75, 0x0E28,
0x0D01, 0x0BE6, 0x0AD7, 0x09D5,
0x08DF, 0x07F7, 0x071A, 0x064B,
0x0588, 0x04D1, 0x0427, 0x038A,
0x02F9, 0x0275, 0x01FD, 0x0192,
0x0134, 0x00E2, 0x009D, 0x0064,
0x0038, 0x0019, 0x0004, 0x0000
};
static void boo_move_during_hit(s32 roll, f32 fVel) {
// Boos seem to have been supposed to oscillate up then down then back again
@@ -203,7 +201,7 @@ static void boo_move_during_hit(s32 roll, f32 fVel) {
o->oVelY = coss(oscillationVel);
o->oMoveAngleYaw = o->oBooMoveYawDuringHit;
if (roll != FALSE) {
if (roll) {
o->oFaceAngleYaw += sBooHitRotations[o->oTimer];
o->oFaceAngleRoll += sBooHitRotations[o->oTimer];
}
@@ -218,7 +216,7 @@ static void big_boo_shake_after_hit(void) {
static void boo_reset_after_hit(void) {
o->oMoveAngleYaw = o->oBooMoveYawBeforeHit;
o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW;
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
}
// called iff boo/big boo/cage boo is in action 2, which only occurs if it was non-attack-ly interacted with/bounced on?
@@ -230,11 +228,12 @@ static s32 boo_update_after_bounced_on(f32 a0) {
}
if (o->oTimer < 32) {
boo_move_during_hit(FALSE, sBooHitRotations[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;
}
@@ -250,13 +249,12 @@ static s32 big_boo_update_during_nonlethal_hit(f32 a0) {
}
if (o->oTimer < 32) {
boo_move_during_hit(TRUE, sBooHitRotations[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;
@@ -268,8 +266,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;
@@ -285,7 +281,7 @@ 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;
if (!cur_obj_has_behavior(bhvBoo)) {
parentBigBoo->oBigBooNumMinionBoosKilled++;
@@ -304,21 +300,18 @@ static s32 boo_update_during_death(void) {
}
static s32 obj_has_attack_type(u32 attackType) {
if ((o->oInteractStatus & INT_STATUS_ATTACK_MASK) == attackType) {
return TRUE;
} else {
return FALSE;
}
return (o->oInteractStatus & INT_STATUS_ATTACK_MASK) == attackType;
}
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;
o->oInteractStatus = INT_STATUS_NONE;
cur_obj_play_sound_2(SOUND_OBJ_BOO_LAUGH_SHORT);
@@ -326,7 +319,7 @@ static s32 boo_get_attack_status(void) {
} else {
cur_obj_play_sound_2(SOUND_OBJ_BOO_BOUNCE_TOP);
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
attackStatus = BOO_BOUNCED_ON;
}
@@ -337,11 +330,10 @@ static s32 boo_get_attack_status(void) {
// boo idle/chasing movement?
static void boo_chase_mario(f32 minDY, s16 yawIncrement, f32 mul) {
f32 dy;
s16 targetYaw;
if (boo_vanish_or_appear()) {
o->oInteractType = 0x8000;
o->oInteractType = INTERACT_BOUNCE_TOP;
if (cur_obj_lateral_dist_from_mario_to_home() > 1500.0f) {
targetYaw = cur_obj_angle_to_home();
@@ -352,10 +344,10 @@ static void boo_chase_mario(f32 minDY, s16 yawIncrement, f32 mul) {
cur_obj_rotate_yaw_toward(targetYaw, yawIncrement);
o->oVelY = 0.0f;
if (mario_is_in_air_action() == 0) {
dy = o->oPosY - gMarioObject->oPosY;
if (minDY < dy && dy < 500.0f) {
o->oVelY = increment_velocity_toward_range(o->oPosY, gMarioObject->oPosY + 50.0f, 10.f, 2.0f);
if (!mario_is_in_air_action()) {
f32 dy = o->oPosY - gMarioObject->oPosY;
if ((minDY < dy) && (dy < 500.0f)) {
o->oVelY = increment_velocity_toward_range(o->oPosY, gMarioObject->oPosY + 50.0f, 10.0f, 2.0f);
}
}
@@ -383,7 +375,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 +409,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()) {
@@ -474,30 +467,29 @@ static void boo_act_4(void) {
}
}
static void (*sBooActions[])(void) = {
static ObjActionFunc sBooActions[] = {
boo_act_0,
boo_act_1,
boo_act_2,
boo_act_3,
boo_act_4,
boo_act_5
boo_act_5,
};
void bhv_boo_loop(void) {
//PARTIAL_UPDATE
// PARTIAL_UPDATE
cur_obj_update_floor_and_walls();
cur_obj_call_action_function(sBooActions);
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;
o->oInteractStatus = INT_STATUS_NONE;
}
static void big_boo_act_0(void) {
@@ -510,7 +502,7 @@ static void big_boo_act_0(void) {
o->oBooParentBigBoo = NULL;
if (boo_should_be_active() && gDebugInfo[5][0] + 5 <= o->oBigBooNumMinionBoosKilled) {
if (boo_should_be_active() && o->oBigBooNumMinionBoosKilled >= gDebugInfo[DEBUG_PAGE_ENEMYINFO][0] + 5) {
o->oAction = 1;
cur_obj_set_pos_to_home();
@@ -518,7 +510,7 @@ static void big_boo_act_0(void) {
cur_obj_unhide();
o->oBooTargetOpacity = 0xFF;
o->oBooTargetOpacity = 255;
o->oBooBaseScale = 3.0f;
o->oHealth = 3;
@@ -532,7 +524,6 @@ static void big_boo_act_0(void) {
}
static void big_boo_act_1(void) {
s32 attackStatus;
s16 yawIncrement;
f32 mul;
@@ -546,7 +537,7 @@ static void big_boo_act_1(void) {
boo_chase_mario(-100.0f, yawIncrement, mul);
attackStatus = boo_get_attack_status();
s32 attackStatus = boo_get_attack_status();
// redundant; this check is in boo_should_be_stopped
if (cur_obj_has_behavior(bhvMerryGoRoundBigBoo)) {
@@ -563,9 +554,6 @@ static void big_boo_act_1(void) {
if (attackStatus == BOO_ATTACKED) {
o->oAction = 3;
}
if (attackStatus == 1) {
create_sound_spawner(SOUND_OBJ_THWOMP);
}
}
@@ -649,12 +637,12 @@ static void big_boo_act_4(void) {
}
}
static void (*sBooGivingStarActions[])(void) = {
static ObjActionFunc sBooGivingStarActions[] = {
big_boo_act_0,
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) {
@@ -669,12 +657,12 @@ void bhv_big_boo_loop(void) {
cur_obj_move_standard(78);
boo_approach_target_opacity_and_update_scale();
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
}
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);
@@ -718,27 +706,25 @@ static void boo_with_cage_act_3(void) {
}
void bhv_boo_with_cage_init(void) {
struct Object* cage;
#ifndef UNLOCK_ALL
if (gHudDisplay.stars < 12) {
if (gHudDisplay.stars < SPAWN_CASTLE_BOO_STAR_REQUIREMENT) {
obj_mark_for_deletion(o);
} else
#endif
{
cage = spawn_object(o, MODEL_HAUNTED_CAGE, bhvBooCage);
struct Object *cage = spawn_object(o, MODEL_HAUNTED_CAGE, bhvBooCage);
cage->oBehParams = o->oBehParams;
}
}
static void (*sBooWithCageActions[])(void) = {
static ObjActionFunc sBooWithCageActions[] = {
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();
@@ -746,7 +732,7 @@ void bhv_boo_with_cage_loop(void)
cur_obj_move_standard(78);
boo_approach_target_opacity_and_update_scale();
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
}
void bhv_merry_go_round_boo_manager_loop(void) {
@@ -755,7 +741,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++;
}
@@ -764,27 +751,25 @@ 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);
o->oAction = 2;
#ifndef VERSION_JP
play_puzzle_jingle();
#else
play_sound(SOUND_GENERAL2_RIGHT_ANSWER, gGlobalSoundSource);
#endif
}
}
break;
case 1:
if (o->oTimer > 60) {
o->oAction = 0;
}
break;
case 2:
break;
}
@@ -806,7 +791,7 @@ void bhv_boo_in_castle_loop(void) {
if (o->oAction == 0) {
cur_obj_hide();
#ifndef UNLOCK_ALL
if (gHudDisplay.stars < 12) {
if (gHudDisplay.stars < SPAWN_CASTLE_BOO_STAR_REQUIREMENT) {
obj_mark_for_deletion(o);
}
#endif
@@ -859,10 +844,12 @@ void bhv_boo_in_castle_loop(void) {
cur_obj_move_using_fvel_and_gravity();
}
static s8 sBbhStairJiggleOffsets[] = { -8, 8, -4, 4 };
static s8 sBbhStairJiggleOffsets[] = {
-8, 8, -4, 4
};
s32 jiggle_bbh_stair(s32 index) {
if (index >= 4 || index < 0) {
if ((index >= 4) || (index < 0)) {
return TRUE;
}
@@ -885,7 +872,7 @@ void bhv_boo_staircase(void) {
break;
}
switch(o->oAction) {
switch (o->oAction) {
case 0:
o->oPosY = o->oHomeY - 620.0f;
o->oAction++;
@@ -900,9 +887,10 @@ void bhv_boo_staircase(void) {
}
break;
case 2:
if (o->oTimer == 0) {
cur_obj_play_sound_2(SOUND_GENERAL_UNKNOWN4_LOWPRIO);
cur_obj_play_sound_2(SOUND_GENERAL_ELEVATOR_WOBBLE_LOWPRIO);
}
if (jiggle_bbh_stair(o->oTimer)) {
@@ -910,6 +898,7 @@ void bhv_boo_staircase(void) {
}
break;
case 3:
if (o->oTimer == 0 && o->oBehParams2ndByte == 1) {
play_puzzle_jingle();
+19 -15
View File
@@ -1,3 +1,4 @@
/**
* Behavior for bhvBooCage.
* This is the cage inside the big boo in the castle courtyard
@@ -10,15 +11,15 @@
* 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,
};
/**
@@ -40,7 +41,7 @@ void bhv_boo_cage_loop(void) {
// give the cage an initial Y velocity of 60 units/frame, and play the puzzle jingle.
// Otherwise, stay inside the boo.
if (o->parentObj->oBooDeathStatus != BOO_DEATH_STATUS_ALIVE) {
o->oAction++;
o->oAction = BOO_CAGE_ACT_FALLING;
o->oVelY = 60.0f;
play_puzzle_jingle();
} else {
@@ -48,6 +49,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?
@@ -63,19 +65,19 @@ void bhv_boo_cage_loop(void) {
// When the cage lands/bounces, play a landing/bouncing sound.
if (o->oMoveFlags & OBJ_MOVE_LANDED) {
cur_obj_play_sound_2(SOUND_GENERAL_SOFT_LANDING);
cur_obj_play_sound_2(SOUND_GENERAL_BOO_CAGE_SOFT_LANDING);
}
// Once the cage stops bouncing and settles on the ground,
// set the action to BOO_CAGE_ACT_ON_GROUND.
// This is the only use of the OBJ_MOVE_AT_WATER_SURFACE flag in the game.
// It seems to serve no purpose here.
if (o->oMoveFlags
& (OBJ_MOVE_UNDERWATER_ON_GROUND | OBJ_MOVE_AT_WATER_SURFACE | OBJ_MOVE_ON_GROUND)) {
o->oAction++;
if (o->oMoveFlags & (OBJ_MOVE_UNDERWATER_ON_GROUND | OBJ_MOVE_AT_WATER_SURFACE | OBJ_MOVE_ON_GROUND)) {
o->oAction = BOO_CAGE_ACT_ON_GROUND;
}
break;
case BOO_CAGE_ACT_ON_GROUND:
// Allow Mario to enter the cage once it's still on the ground.
cur_obj_become_tangible();
@@ -85,20 +87,22 @@ void bhv_boo_cage_loop(void) {
// Set the action to BOO_CAGE_ACT_MARIO_JUMPING_IN when Mario jumps in.
if (obj_check_if_collided_with_object(o, gMarioObject)) {
o->oAction++;
o->oAction = BOO_CAGE_ACT_MARIO_JUMPING_IN;
}
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,
// which does nothing. By extension, this action is also useless.
if (o->oTimer > 100) {
o->oAction++;
o->oAction = BOO_CAGE_ACT_USELESS;
}
break;
case BOO_CAGE_ACT_USELESS:
break;
}
+16 -10
View File
@@ -1,9 +1,7 @@
// boulder.c.inc
// boulder.inc.c
void bhv_big_boulder_init(void) {
o->oHomeX = o->oPosX;
o->oHomeY = o->oPosY;
o->oHomeZ = o->oPosZ;
vec3f_copy(&o->oHomeVec, &o->oPosVec);
o->oGravity = 8.0f;
o->oFriction = 0.999f;
@@ -12,21 +10,26 @@ void bhv_big_boulder_init(void) {
void boulder_act_1(void) {
s16 collisionFlags = object_step_without_floor_orient();
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.0f)
if (o->oForwardVel > 70.0f) {
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;
@@ -36,7 +39,7 @@ void bhv_big_boulder_loop(void) {
case 1:
boulder_act_1();
adjust_rolling_face_pitch(1.5f);
cur_obj_play_sound_1(SOUND_ENV_UNKNOWN2);
cur_obj_play_sound_1(SOUND_ENV_BOWLING_BALL_ROLL);
break;
}
@@ -45,20 +48,23 @@ void bhv_big_boulder_loop(void) {
void bhv_big_boulder_generator_loop(void) {
struct Object *boulderObj;
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)) {
boulderObj = spawn_object(o, MODEL_HMC_ROLLING_ROCK, bhvBigBoulder);
boulderObj->oMoveAngleYaw = random_float() * 4096.0f;
}
} else {
if ((o->oTimer & 0x7F) == 0) {
if (!(o->oTimer & 0x7F)) {
boulderObj = spawn_object(o, MODEL_HMC_ROLLING_ROCK, bhvBigBoulder);
boulderObj->oMoveAngleYaw = random_float() * 4096.0f;
}
+33 -11
View File
@@ -1,54 +1,76 @@
// bouncing_fireball.c.inc
// bouncing_fireball.inc.c
void bhv_bouncing_fireball_flame_loop(void) {
o->activeFlags |= ACTIVE_FLAG_IGNORE_ENV_BOXES;
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;
o->oInteractStatus = INT_STATUS_NONE;
}
void bhv_bouncing_fireball_spawner_loop(void) {
struct Object *flameObj;
f32 scale;
switch (o->oAction) {
case 0:
if (o->oDistanceToMario < 2000.0f)
if (o->oDistanceToMario < 2000.0f) {
o->oAction = 1;
}
break;
case 1:
flameObj = spawn_object(o, MODEL_RED_FLAME, bhvBouncingFireballFlame);
scale = (10 - o->oTimer) * 0.5f;
obj_scale_xyz(flameObj, scale, scale, scale);
if (o->oTimer == 0)
obj_scale(flameObj, scale);
if (o->oTimer == 0) {
obj_become_tangible(flameObj);
if (o->oTimer > 10)
}
if (o->oTimer > 10) {
o->oAction++;
}
break;
case 2:
if (o->oTimer == 0)
if (o->oTimer == 0) {
o->oBouncingFireBallSpawnerRandomCooldown = random_float() * 100.0f;
if (o->oBouncingFireBallSpawnerRandomCooldown + 100 < o->oTimer)
}
if (o->oBouncingFireBallSpawnerRandomCooldown + 100 < o->oTimer) {
o->oAction = 0;
}
break;
}
}
+44 -55
View File
@@ -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)
o->oInteractStatus = 0;
if (o->oInteractStatus & INT_STATUS_INTERACTED) {
o->oInteractStatus = INT_STATUS_NONE;
}
}
void bowling_ball_set_waypoints(void) {
@@ -77,14 +78,10 @@ void bowling_ball_set_waypoints(void) {
}
void bhv_bowling_ball_roll_loop(void) {
s16 collisionFlags;
s32 pathResult = 0;
bowling_ball_set_waypoints();
collisionFlags = object_step();
s16 collisionFlags = object_step();
//! Uninitialzed parameter, but the parameter is unused in the called function
pathResult = cur_obj_follow_path(pathResult);
s32 followStatus = cur_obj_follow_path();
o->oBowlingBallTargetYaw = o->oPathedTargetYaw;
o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, o->oBowlingBallTargetYaw, 0x400);
@@ -94,7 +91,7 @@ void bhv_bowling_ball_roll_loop(void) {
bowling_ball_set_hitbox();
if (pathResult == -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 +100,15 @@ 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 pathResult = 0;
void bhv_bowling_ball_initialize_loop(void) {
bowling_ball_set_waypoints();
//! Uninitialzed parameter, but the parameter is unused in the called function
pathResult = cur_obj_follow_path(pathResult);
cur_obj_follow_path();
o->oMoveAngleYaw = o->oPathedTargetYaw;
@@ -146,7 +141,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 +149,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 +176,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.5f) == 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;
}
}
}
@@ -227,16 +220,14 @@ void bhv_bob_pit_bowling_ball_init(void) {
}
void bhv_bob_pit_bowling_ball_loop(void) {
struct Surface *floor;
object_step();
find_floor(o->oPosX, o->oPosY, o->oPosZ, &floor);
if ((floor->normal.x == 0) && (floor->normal.z == 0))
if ((o->oFloor != NULL) && (o->oFloor->normal.x == 0) && (o->oFloor->normal.z == 0)) {
o->oForwardVel = 28.0f;
}
bowling_ball_set_hitbox();
set_camera_shake_from_point(SHAKE_POS_BOWLING_BALL, o->oPosX, o->oPosY, o->oPosZ);
cur_obj_play_sound_1(SOUND_ENV_UNKNOWN2);
cur_obj_play_sound_1(SOUND_ENV_BOWLING_BALL_ROLL);
set_object_visibility(o, 3000);
}
@@ -244,33 +235,30 @@ void bhv_free_bowling_ball_init(void) {
o->oGravity = 5.5f;
o->oFriction = 1.0f;
o->oBuoyancy = 2.0f;
o->oHomeX = o->oPosX;
o->oHomeY = o->oPosY;
o->oHomeZ = o->oPosZ;
vec3f_copy(&o->oHomeVec, &o->oPosVec);
o->oForwardVel = 0;
o->oMoveAngleYaw = 0;
}
void bhv_free_bowling_ball_roll_loop(void) {
/*s16 collisionFlags = */object_step();
object_step();
bowling_ball_set_hitbox();
if (o->oForwardVel > 10.0f) {
set_camera_shake_from_point(SHAKE_POS_BOWLING_BALL, o->oPosX, o->oPosY, o->oPosZ);
cur_obj_play_sound_1(SOUND_ENV_UNKNOWN2);
cur_obj_play_sound_1(SOUND_ENV_BOWLING_BALL_ROLL);
}
/* Always false, commented out to suppress compiler warnings */
// if ((collisionFlags & OBJ_COL_FLAG_GROUNDED) && !(collisionFlags & OBJ_COL_FLAGS_LANDED))
/* Always false, commented out to suppress compiler warnings. */
// 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;
cur_obj_become_intangible();
o->oPosX = o->oHomeX;
o->oPosY = o->oHomeY;
o->oPosZ = o->oHomeZ;
vec3f_copy(&o->oPosVec, &o->oHomeVec);
bhv_free_bowling_ball_init();
o->oAction = FREE_BBALL_ACT_RESET;
}
@@ -293,8 +281,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;
}
}
File diff suppressed because it is too large. Load diff
+12 -9
View File
@@ -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,11 +18,10 @@ 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.0f + 1.0f);
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;
@@ -32,20 +30,25 @@ void bhv_bowser_bomb_explosion_loop(void) {
if (o->oTimer % 2 == 0) {
o->oAnimState++;
}
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.0f + 1.0f);
if (o->oTimer % 2 == 0)
cur_obj_scale((f32) o->oTimer / 14.0f * 9.0 + 1.0);
if (o->oTimer % 2 == 0) {
o->oAnimState++;
}
o->oOpacity -= 10;
if (o->oOpacity < 10) {
o->oOpacity = 0;
}
o->oPosY += o->oVelY;
if (o->oTimer == 28) {
@@ -1,3 +1,5 @@
// bowser_falling_platform.inc.c
struct BowserFallingPlatformData {
const Collision *collision;
s16 posX;
@@ -16,69 +18,80 @@ struct BowserFallingPlatformData sBowserFallingPlatform[] = {
{ 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 }
{ 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 != 0)
if (o->oBitsPlatformBowser != NULL) {
o->oAction = BOWSER_BITS_PLAT_ACT_CHECK;
}
}
void falling_bowser_plat_act_check(void) {
struct Object *bowser = o->oBitsPlatformBowser;
if (bowser->platform == o) {
if (bowser->oAction == BOWSER_ACT_BIG_JUMP && bowser->oBowserStatus & BOWSER_STATUS_BIG_JUMP) {
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)) {
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[4][6] + 20) * (o->oBehParams2ndByte - 1) < o->oBitsPlatformTimer)
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);
cur_obj_play_sound_2(SOUND_GENERAL_BOWSER_PLATFORM_FALL);
}
if (o->oTimer < 22) {
set_environmental_camera_shake(SHAKE_ENV_FALLING_BITS_PLAT);
o->oVelY = 8.0f;
o->oGravity = 0.0f;
} else
} else {
o->oGravity = -4.0f;
if ((o->oTimer & 1) == 0 && o->oTimer < 14) {
angle = sBowserFallingPlatform[o->oBehParams2ndByte].angle + (gDebugInfo[4][1] << 8);
val = -(o->oTimer / 2) * 290 + 1740;
}
if (!(o->oTimer & 1) && o->oTimer < 14) {
s16 angle = sBowserFallingPlatform[o->oBehParams2ndByte].angle
+ (gDebugInfo[DEBUG_PAGE_EFFECTINFO][1] << 8);
f32 val = -(o->oTimer / 2) * 290 + 1740;
Vec3f pos;
vec3f_copy(pos, &o->oPosVec);
o->oPosX = sBowserFallingPlatform[o->oBehParams2ndByte].posX + sins(angle + 0x14B0) * val;
o->oPosZ = sBowserFallingPlatform[o->oBehParams2ndByte].posZ + coss(angle + 0x14B0) * val;
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;
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(&o->oPosVec, pos);
}
cur_obj_move_using_fvel_and_gravity();
if (o->oTimer > 300) {
obj_mark_for_deletion(o);
}
}
void (*sFallingBowserPlatformActions[])(void) = {
ObjActionFunc sFallingBowserPlatformActions[] = {
falling_bowser_plat_act_start,
falling_bowser_plat_act_check,
falling_bowser_plat_act_fall,
+58 -23
View File
@@ -1,25 +1,27 @@
// bowser_flame.inc.c
struct ObjectHitbox sGrowingBowserFlameHitbox = {
/* interactType: */ INTERACT_FLAME,
/* downOffset: */ 20,
/* interactType: */ INTERACT_FLAME,
/* downOffset: */ 20,
/* damageOrCoinValue: */ 1,
/* health: */ 0,
/* numLootCoins: */ 0,
/* radius: */ 10,
/* height: */ 40,
/* hurtboxRadius: */ 0,
/* hurtboxHeight: */ 0,
/* health: */ 0,
/* numLootCoins: */ 0,
/* radius: */ 10,
/* height: */ 40,
/* hurtboxRadius: */ 0,
/* hurtboxHeight: */ 0,
};
struct ObjectHitbox sBowserFlameHitbox = {
/* interactType: */ INTERACT_FLAME,
/* downOffset: */ 0,
/* interactType: */ INTERACT_FLAME,
/* downOffset: */ 0,
/* damageOrCoinValue: */ 1,
/* health: */ 0,
/* numLootCoins: */ 0,
/* radius: */ 10,
/* height: */ 40,
/* hurtboxRadius: */ 0,
/* hurtboxHeight: */ 0,
/* health: */ 0,
/* numLootCoins: */ 0,
/* radius: */ 10,
/* height: */ 40,
/* hurtboxRadius: */ 0,
/* hurtboxHeight: */ 0,
};
void bowser_flame_despawn(void) {
@@ -31,14 +33,25 @@ void bowser_flame_despawn(void) {
}
s32 bowser_flame_should_despawn(s32 maxTime) {
if (maxTime < o->oTimer) {
return TRUE;
}
// Flames should despawn if they fall off the arena.
return ((maxTime < o->oTimer) || (o->oFloorType == SURFACE_BURNING) || (o->oFloorType == SURFACE_DEATH_PLANE));
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.2f) ? 80.0f : 20.0f);
o->oVelY = random_float() < 0.2f ? 80.0f : 20.0f;
o->oForwardVel = 10.0f;
o->oGravity = -1.0f;
o->oFlameScale = random_float() + 1.0f;
@@ -53,8 +66,7 @@ void bhv_flame_large_burning_out_init(void) {
}
void bowser_flame_move(void) {
s32 timer;
timer = ((o->oFlameSpeedTimerOffset + gGlobalTimer) & 0x3F) << 10;
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;
}
@@ -62,12 +74,15 @@ void bowser_flame_move(void) {
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)) {
@@ -81,6 +96,7 @@ void bhv_flame_bowser_loop(void) {
}
} else {
cur_obj_become_tangible();
if (o->oTimer > o->oFlameScale * 10 + 5.0f) {
o->oFlameScale -= 0.15f;
if (o->oFlameScale <= 0) {
@@ -88,6 +104,7 @@ void bhv_flame_bowser_loop(void) {
}
}
}
cur_obj_scale(o->oFlameScale);
o->oGraphYOffset = o->header.gfx.scale[1] * 14.0f;
obj_set_hitbox(o, &sBowserFlameHitbox);
@@ -104,14 +121,18 @@ void bhv_flame_moving_forward_growing_loop(void) {
obj_set_hitbox(o, &sGrowingBowserFlameHitbox);
o->oFlameScale = o->oFlameScale + 0.5f;
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;
spawn_object(o, MODEL_RED_FLAME, bhvFlameBowser);
@@ -138,12 +159,15 @@ void bhv_flame_floating_landing_loop(void) {
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);
@@ -152,6 +176,7 @@ void bhv_flame_floating_landing_loop(void) {
}
obj_mark_for_deletion(o);
}
o->oGraphYOffset = o->header.gfx.scale[1] * 14.0f;
}
@@ -168,14 +193,18 @@ void bhv_blue_bowser_flame_init(void) {
void bhv_blue_bowser_flame_loop(void) {
s32 i;
obj_set_hitbox(o, &sGrowingBowserFlameHitbox);
if (o->oFlameScale < 16.0f) {
o->oFlameScale = o->oFlameScale + 0.5f;
}
cur_obj_scale(o->oFlameScale);
cur_obj_update_floor_and_walls();
cur_obj_move_standard(78);
if (o->oTimer > 0x14) {
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,
@@ -201,9 +230,11 @@ void bhv_flame_bouncing_init(void) {
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;
@@ -211,9 +242,11 @@ void bhv_flame_bouncing_loop(void) {
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) {
@@ -226,15 +259,17 @@ void bhv_flame_bouncing_loop(void) {
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) {
if (!(o->oTimer & 1)) {
for (i = 0; i < 3; i++) {
flame = spawn_object(o, MODEL_BLUE_FLAME, bhvFlameBouncing);
flame->oMoveAngleYaw += i * 0x5555;
flame->oMoveAngleYaw += i * DEGREES(120);
flame->header.gfx.scale[0] = o->oBlueFlameNextScale;
}
o->oBlueFlameNextScale -= 0.5f;
+25 -20
View File
@@ -1,44 +1,49 @@
// 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)
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
if (o->oMoveFlags & OBJ_MOVE_ON_GROUND) {
o->oAction = 1;
} else if (o->oMoveFlags & OBJ_MOVE_LANDED) {
cur_obj_play_sound_2(SOUND_GENERAL_BOWSER_KEY_LAND);
}
} else {
obj_set_hitbox(o, &sBowserKeyHitbox);
if (o->oInteractStatus & INT_STATUS_INTERACTED) {
obj_mark_for_deletion(o);
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
}
}
}
+32 -24
View File
@@ -1,47 +1,55 @@
// bowser_key_cutscene.inc.c
Gfx *geo_scale_bowser_key(s32 run, struct GraphNode *node, UNUSED Mat4 mtx) {
struct Object *nodeObj;
if (run == TRUE) {
nodeObj = (struct Object *) gCurGraphNodeObject;
Gfx *geo_scale_bowser_key(s32 callContext, struct GraphNode *node, UNUSED Mat4 mtx) {
if (callContext == GEO_CONTEXT_RENDER) {
struct Object *nodeObj = (struct Object *) gCurGraphNodeObject;
((struct GraphNodeScale *) node->next)->scale = nodeObj->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.2f; // 0.11875f?
else if (animTimer < 59)
} else if (animFrame < 58) {
o->oBowserKeyScale = (animFrame - 53) * 0.11875f + 0.2f; // 0.11875f?
} 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) * (3.0f / 70.0f) + 0.2f;
else if (animTimer < 94)
} else if (animFrame < 52) {
o->oBowserKeyScale = (animFrame - 42) * (3.0f / 70.0f) + 0.2f;
} else if (animFrame < 94) {
o->oBowserKeyScale = 0.8f;
else if (animTimer < 101)
o->oBowserKeyScale = (101 - animTimer) * (6.0f / 70.0f) + 0.2f;
else
} else if (animFrame < 101) {
o->oBowserKeyScale = (101 - animFrame) * (6.0f / 70.0f) + 0.2f;
} else {
o->oBowserKeyScale = 0.2f;
if (o->oTimer > 138)
}
if (o->oTimer > 138) {
obj_mark_for_deletion(o);
}
}
+74 -85
View File
@@ -1,3 +1,4 @@
/**
* Behavior for the sliding Bowser puzzle in Lethal Lava Land.
*/
@@ -12,41 +13,41 @@
*
* Note that pieces 11 and 14 do not move.
*/
static s8 sPieceActions01[] = { 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, -1 };
static s8 sPieceActions02[] = { 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, -1 };
static s8 sPieceActions05[] = { 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 6, 2, 2, 2, -1 };
static s8 sPieceActions06[] = { 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, -1 };
static s8 sPieceActions10[] = { 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 6, 2, 2, 2, 2, 2, -1 };
static s8 sPieceActions09[] = { 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, -1 };
static s8 sPieceActions13[] = { 2, 2, 2, 2, 2, 2, 2, 5, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 6, 2, 2, 2, 2, 2, 2, 2, -1 };
static s8 sPieceActions12[] = { 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 2,
2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, -1 };
static s8 sPieceActions08[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 2, 2, 2, 2,
2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1 };
static s8 sPieceActions07[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2,
2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1 };
static s8 sPieceActions03[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 6, 2, 2,
5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1 };
static s8 sPieceActions04[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1 };
static s8 sPieceActions11[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1 };
static s8 sPieceActions14[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1 };
static ObjAction8 sPieceActions01[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_LEFT, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_RIGHT, BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions02[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_LEFT, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_RIGHT, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions05[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_UP , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_DOWN , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions06[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_LEFT, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_RIGHT, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions10[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_UP , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_DOWN , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions09[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_RIGHT, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_LEFT, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions13[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_UP , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_DOWN, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions12[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_RIGHT, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_LEFT, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions08[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_DOWN , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_UP , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions07[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_RIGHT, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_LEFT, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions03[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_DOWN, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_UP , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions04[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_LEFT, BOWSER_PUZZLE_PIECE_ACT_RIGHT,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions11[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
static ObjAction8 sPieceActions14[] = { BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE ,
BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE, BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE , BOWSER_PUZZLE_PIECE_ACT_IDLE, -1 };
struct BowserPuzzlePiece {
u8 model;
ModelID8 model;
s8 xOffset;
s8 zOffset;
s8 initialAction;
s8 *actionList;
ObjAction8 initialAction;
ObjAction8 *actionList;
};
/*
@@ -84,9 +85,9 @@ static struct BowserPuzzlePiece sBowserPuzzlePieces[] = {
/**
* Spawn a single puzzle piece.
*/
void bhv_lll_bowser_puzzle_spawn_piece(s16 model, const BehaviorScript *behavior,
void bhv_lll_bowser_puzzle_spawn_piece(ModelID16 model, const BehaviorScript *behavior,
f32 xOffset, f32 zOffset,
s8 initialAction, s8 *actionList) {
ObjAction8 initialAction, ObjAction8 *actionList) {
struct Object *puzzlePiece = spawn_object(o, model, behavior);
puzzlePiece->oPosX += xOffset;
puzzlePiece->oPosY += 50.0f;
@@ -103,15 +104,16 @@ 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++;
o->oAction = BOWSER_PUZZLE_ACT_WAIT_FOR_COMPLETE;
}
/*
@@ -119,56 +121,46 @@ void bhv_lll_bowser_puzzle_spawn_pieces(f32 pieceWidth) {
*/
void bhv_lll_bowser_puzzle_loop(void) {
s32 i;
UNUSED struct Object *coinObj;
switch (o->oAction) {
case BOWSER_PUZZLE_ACT_SPAWN_PIECES:
bhv_lll_bowser_puzzle_spawn_pieces(480.0f);
bhv_lll_bowser_puzzle_spawn_pieces(512.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) {
if ((o->oBowserPuzzleCompletionFlags == (BOWSER_PUZZLE_COMPLETION_FLAG_MARIO_ON_PLATFORM | BOWSER_PUZZLE_COMPLETION_FLAG_PUZZLE_COMPLETE)) && (o->oDistanceToMario < 1000.0f)) {
// Spawn 5 coins.
for (i = 0; i < 5; i++)
coinObj = spawn_object(o, MODEL_YELLOW_COIN, bhvSingleCoinGetsSpawned);
for (i = 0; i < 5; i++) {
spawn_object(o, MODEL_YELLOW_COIN, bhvSingleCoinGetsSpawned);
}
// Reset completion flags (even though they never get checked again).
o->oBowserPuzzleCompletionFlags = 0;
o->oBowserPuzzleCompletionFlags = BOWSER_PUZZLE_COMPLETION_FLAGS_NONE;
// Go to next action so we don't spawn 5 coins ever again.
o->oAction++;
o->oAction = BOWSER_PUZZLE_ACT_DONE;
}
break;
case BOWSER_PUZZLE_ACT_DONE:
break;
}
}
/*
* Action 0 is never executed since it is not defined in any action lists.
*/
void bhv_lll_bowser_puzzle_piece_action_0(void) {
}
/*
* Action 1 is never executed since it is not defined in any action lists.
*/
void bhv_lll_bowser_puzzle_piece_action_1(void) {
o->oPosY += 50.0f;
o->oAction = 3;
}
/*
* Update the puzzle piece.
*/
void bhv_lll_bowser_puzzle_piece_update(void) {
s8 *nextAction = o->oBowserPuzzlePieceNextAction;
ObjAction8 *nextAction = o->oBowserPuzzlePieceNextAction;
// If Mario is standing on this puzzle piece, set a flag in the parent.
if (gMarioObject->platform == o)
o->parentObj->oBowserPuzzleCompletionFlags = 1;
if (gMarioObject->platform == o) {
o->parentObj->oBowserPuzzleCompletionFlags = BOWSER_PUZZLE_COMPLETION_FLAG_MARIO_ON_PLATFORM;
}
// If we should advance to the next action...
if (o->oBowserPuzzlePieceContinuePerformingAction == 0) {
if (!o->oBowserPuzzlePieceContinuePerformingAction) {
// Start doing the next action.
cur_obj_change_action(*nextAction);
@@ -179,28 +171,26 @@ void bhv_lll_bowser_puzzle_piece_update(void) {
// If we're at the end of the list...
if (*nextAction == -1) {
// Set the other completion flag in the parent.
o->parentObj->oBowserPuzzleCompletionFlags |= 2;
o->parentObj->oBowserPuzzleCompletionFlags |= BOWSER_PUZZLE_COMPLETION_FLAG_PUZZLE_COMPLETE;
// The next action is the first action in the list again.
o->oBowserPuzzlePieceNextAction = o->oBowserPuzzlePieceActionList;
}
// Keep doing this action until it's complete.
o->oBowserPuzzlePieceContinuePerformingAction = 1;
o->oBowserPuzzlePieceContinuePerformingAction = TRUE;
}
}
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)
o->oBowserPuzzlePieceOffsetY = 0.0f;
else
o->oBowserPuzzlePieceOffsetY = -6.0f;
o->oBowserPuzzlePieceOffsetY = o->oTimer & 0x1 ? 0.0f : -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,9 +198,9 @@ 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.
o->oAction = 2;
// cur_obj_change_action is going to be called before the
// next action is performed anyway.
o->oAction = BOWSER_PUZZLE_PIECE_ACT_IDLE;
// Advance to the next action.
o->oBowserPuzzlePieceContinuePerformingAction = 0;
@@ -221,39 +211,38 @@ void bhv_lll_bowser_puzzle_piece_move(f32 xOffset, f32 zOffset, s32 duration, UN
void bhv_lll_bowser_puzzle_piece_idle(void) {
// For the first 24 frames, do nothing.
// Then advance to the next action.
if (o->oTimer >= 24)
o->oBowserPuzzlePieceContinuePerformingAction = 0;
if (o->oTimer >= 24) {
o->oBowserPuzzlePieceContinuePerformingAction = FALSE;
}
}
void bhv_lll_bowser_puzzle_piece_move_left(void) {
bhv_lll_bowser_puzzle_piece_move(-120.0f, 0.0f, 4, 4);
bhv_lll_bowser_puzzle_piece_move(-128.0f, 0.0f, 4, 4);
}
void bhv_lll_bowser_puzzle_piece_move_right(void) {
bhv_lll_bowser_puzzle_piece_move(120.0f, 0.0f, 4, 5);
bhv_lll_bowser_puzzle_piece_move(128.0f, 0.0f, 4, 5);
}
void bhv_lll_bowser_puzzle_piece_move_up(void) {
bhv_lll_bowser_puzzle_piece_move(0.0f, -120.0f, 4, 6);
bhv_lll_bowser_puzzle_piece_move(0.0f, -128.0f, 4, 6);
}
void bhv_lll_bowser_puzzle_piece_move_down(void) {
bhv_lll_bowser_puzzle_piece_move(0.0f, 120.0f, 4, 3);
bhv_lll_bowser_puzzle_piece_move(0.0f, 128.0f, 4, 3);
}
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
ObjActionFunc sBowserPuzzlePieceActions[] = {
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) {
bhv_lll_bowser_puzzle_piece_update();
cur_obj_call_action_function(sBowserPuzzlePieceActions);
o->oPosX = o->oBowserPuzzlePieceOffsetX + o->oHomeX;
o->oPosY = o->oBowserPuzzlePieceOffsetY + o->oHomeY;
o->oPosZ = o->oBowserPuzzlePieceOffsetZ + o->oHomeZ;
vec3f_sum(&o->oPosVec, &o->oBowserPuzzlePieceOffsetVec, &o->oHomeVec);
}
+4 -1
View File
@@ -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,6 +12,7 @@ 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 == MODEL_DIRT_ANIMATION || triModel == MODEL_SL_CRACKED_ICE_CHUNK) {
triangle->oAngleVelPitch = 0xF00;
triangle->oAngleVelYaw = 0x500;
@@ -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);
}
}
+105 -6
View File
@@ -1,12 +1,111 @@
// breakable_box.c.inc
// breakable_box.inc.c
struct ObjectHitbox sBreakableBoxHitbox = {
/* interactType: */ INTERACT_BREAKABLE,
/* downOffset: */ 20,
/* damageOrCoinValue: */ 0,
/* health: */ 1,
/* numLootCoins: */ 0,
/* radius: */ 150,
/* height: */ 200,
/* hurtboxRadius: */ 150,
/* hurtboxHeight: */ 200,
};
void breakable_box_init(void) {
o->oHiddenObjectSwitchObj = NULL;
o->oAnimState = BREAKABLE_BOX_ANIM_STATE_CORK_BOX;
switch (o->oBehParams2ndByte) {
case BREAKABLE_BOX_BP_NO_COINS: o->oNumLootCoins = 0; break;
case BREAKABLE_BOX_BP_3_COINS: o->oNumLootCoins = 3; break;
case BREAKABLE_BOX_BP_5_COINS: o->oNumLootCoins = 5; break;
case BREAKABLE_BOX_BP_LARGE: cur_obj_scale(1.5f); break;
}
}
void hidden_breakable_box_actions(void) {
struct Object *switchObj;
obj_set_hitbox(o, &sBreakableBoxHitbox);
cur_obj_set_model(MODEL_BREAKABLE_BOX);
switch (o->oAction) {
case BREAKABLE_BOX_ACT_HIDDEN:
cur_obj_disable_rendering();
cur_obj_become_intangible();
if (o->oTimer == 0) {
breakable_box_init();
}
if (o->oHiddenObjectSwitchObj == NULL) {
o->oHiddenObjectSwitchObj = cur_obj_nearest_object_with_behavior(bhvFloorSwitchHiddenObjects);
}
switchObj = o->oHiddenObjectSwitchObj;
if ((switchObj != NULL) && (switchObj->oAction == PURPLE_SWITCH_ACT_TICKING)) {
o->oAction = BREAKABLE_BOX_ACT_ACTIVE;
cur_obj_enable_rendering();
cur_obj_unhide();
}
break;
case BREAKABLE_BOX_ACT_ACTIVE:
cur_obj_become_tangible();
if (cur_obj_wait_then_blink(360, 20)) o->oAction = BREAKABLE_BOX_ACT_HIDDEN;
if (cur_obj_was_attacked_or_ground_pounded()) {
spawn_mist_particles();
spawn_triangle_break_particles(30, MODEL_DIRT_ANIMATION, 3.0f, TINY_DIRT_PARTICLE_ANIM_STATE_YELLOW);
o->oAction = BREAKABLE_BOX_ACT_BROKEN;
cur_obj_play_sound_2(SOUND_GENERAL_BREAK_BOX);
}
load_object_collision_model();
break;
case BREAKABLE_BOX_ACT_BROKEN:
cur_obj_become_intangible();
cur_obj_disable_rendering();
o->oInteractStatus = INT_STATUS_NONE;
switchObj = o->oHiddenObjectSwitchObj;
if ((switchObj != NULL) && (switchObj->oAction == PURPLE_SWITCH_ACT_IDLE)) {
o->oAction = BREAKABLE_BOX_ACT_HIDDEN;
}
break;
}
}
void hidden_unbreakable_box_actions(void) {
struct Object *switchObj;
obj_set_collision_data(o, wdw_seg7_collision_hidden_platform);
switch (o->oAction) {
case BREAKABLE_BOX_ACT_HIDDEN:
cur_obj_disable_rendering();
cur_obj_become_intangible();
if (o->oHiddenObjectSwitchObj == NULL) {
o->oHiddenObjectSwitchObj = cur_obj_nearest_object_with_behavior(bhvFloorSwitchHiddenObjects);
}
switchObj = o->oHiddenObjectSwitchObj;
if ((switchObj != NULL) && (switchObj->oAction == PURPLE_SWITCH_ACT_TICKING)) {
o->oAction = BREAKABLE_BOX_ACT_ACTIVE;
cur_obj_enable_rendering();
cur_obj_unhide();
}
break;
case BREAKABLE_BOX_ACT_ACTIVE:
cur_obj_become_tangible();
if (cur_obj_wait_then_blink(360, 20)) o->oAction = BREAKABLE_BOX_ACT_HIDDEN;
load_object_collision_model();
break;
}
}
void bhv_hidden_object_loop(void) {
if (o->oBehParams2ndByte == BREAKABLE_BOX_BP_NO_COINS) {
hidden_breakable_box_actions();
} else {
hidden_unbreakable_box_actions();
}
}
void bhv_breakable_box_loop(void) {
obj_set_hitbox(o, &sBreakableBoxHitbox);
cur_obj_set_model(MODEL_BREAKABLE_BOX_SMALL);
if (o->oTimer == 0)
breakable_box_init();
if (cur_obj_was_attacked_or_ground_pounded() != 0) {
obj_explode_and_spawn_coins(46.0f, 1);
cur_obj_set_model(MODEL_BREAKABLE_BOX);
if (o->oTimer == 0) breakable_box_init();
if (cur_obj_was_attacked_or_ground_pounded()) {
obj_explode_and_spawn_coins(46.0f, COIN_TYPE_YELLOW);
create_sound_spawner(SOUND_GENERAL_BREAK_BOX);
}
}
+25 -21
View File
@@ -1,4 +1,4 @@
// breakable_box.c.inc
// breakable_box.inc.c
struct ObjectHitbox sBreakableBoxSmallHitbox = {
/* interactType: */ INTERACT_GRABBABLE,
@@ -18,7 +18,7 @@ void bhv_breakable_box_small_init(void) {
o->oBuoyancy = 1.4f;
cur_obj_scale(0.4f);
obj_set_hitbox(o, &sBreakableBoxSmallHitbox);
o->oAnimState = 1;
o->oAnimState = BREAKABLE_BOX_ANIM_STATE_CORK_BOX;
o->activeFlags |= ACTIVE_FLAG_DESTRUCTIVE_OBJ_DONT_DESTROY;
}
@@ -32,8 +32,11 @@ void small_breakable_box_act_move(void) {
s16 collisionFlags = object_step();
obj_attack_collided_from_other_object(o);
if (collisionFlags == OBJ_COL_FLAG_GROUNDED)
cur_obj_play_sound_2(SOUND_GENERAL_BOX_LANDING_2);
if (collisionFlags == OBJ_COL_FLAG_GROUNDED) {
cur_obj_play_sound_2(SOUND_GENERAL_SMALL_BOX_LANDING);
}
if (collisionFlags & OBJ_COL_FLAG_GROUNDED) {
if (o->oForwardVel > 20.0f) {
cur_obj_play_sound_2(SOUND_ENV_SLIDING);
@@ -57,34 +60,35 @@ void breakable_box_small_released_loop(void) {
// Begin flashing
if (o->oBreakableBoxSmallFramesSinceReleased > 810) {
COND_BIT((o->oBreakableBoxSmallFramesSinceReleased & 0X1), o->header.gfx.node.flags, GRAPH_RENDER_INVISIBLE);
COND_BIT((o->oBreakableBoxSmallFramesSinceReleased & 0x1), o->header.gfx.node.flags, GRAPH_RENDER_INVISIBLE);
}
// Despawn, and create a corkbox respawner
if (o->oBreakableBoxSmallFramesSinceReleased > 900) {
create_respawner(MODEL_BREAKABLE_BOX_SMALL, bhvBreakableBoxSmall, 3000);
create_respawner(MODEL_BREAKABLE_BOX, bhvBreakableBoxSmall, 3000);
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
}
}
void breakable_box_small_idle_loop(void) {
switch (o->oAction) {
case 0:
case BREAKABLE_BOX_SMALL_ACT_MOVE:
small_breakable_box_act_move();
break;
case 100:
case OBJ_ACT_LAVA_DEATH:
obj_lava_death();
break;
case 101:
case OBJ_ACT_DEATH_PLANE_DEATH:
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
create_respawner(MODEL_BREAKABLE_BOX_SMALL, bhvBreakableBoxSmall, 3000);
create_respawner(MODEL_BREAKABLE_BOX, bhvBreakableBoxSmall, 3000);
break;
}
if (o->oBreakableBoxSmallReleased == 1)
if (o->oBreakableBoxSmallReleased == TRUE) {
breakable_box_small_released_loop();
}
}
void breakable_box_small_get_dropped(void) {
@@ -92,44 +96,44 @@ void breakable_box_small_get_dropped(void) {
cur_obj_enable_rendering();
cur_obj_get_dropped();
o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
o->oHeldState = 0;
o->oBreakableBoxSmallReleased = 1;
o->oHeldState = HELD_FREE;
o->oBreakableBoxSmallReleased = TRUE;
o->oBreakableBoxSmallFramesSinceReleased = 0;
}
void breakable_box_small_get_thrown(void) {
cur_obj_become_tangible();
cur_obj_enable_rendering_2();
cur_obj_enable_rendering();
o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
o->oHeldState = 0;
o->oHeldState = HELD_FREE;
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_DESTRUCTIVE_OBJ_DONT_DESTROY;
}
void bhv_breakable_box_small_loop(void) {
switch (o->oHeldState) {
case 0:
case HELD_FREE:
breakable_box_small_idle_loop();
break;
case 1:
case HELD_HELD:
cur_obj_disable_rendering();
cur_obj_become_intangible();
break;
case 2:
case HELD_THROWN:
breakable_box_small_get_thrown();
break;
case 3:
case HELD_DROPPED:
breakable_box_small_get_dropped();
break;
}
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
}
+12 -6
View File
@@ -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) {
if (gMarioState->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);
obj_explode_and_spawn_coins(80.0f, COIN_TYPE_NONE);
}
} else
} else {
cur_obj_become_intangible();
}
}
+99 -64
View File
@@ -1,35 +1,40 @@
// bub.c.inc
// bub.inc.c
// NOTE: These first set of functions spawn a school of bub depending on objF4's
// NOTE: These first set of functions spawn a school of bub depending on oCheepCheepSpawnerSpawnAmount'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.
void bub_spawner_act_0(void) {
void bub_spawner_act_spawn_bubs(void) {
s32 i;
s32 amt = o->oCheepCheepSpawnerSpawnAmount;
if (o->oDistanceToMario < 1500.0f) {
for (i = 0; i < amt; i++) {
spawn_object(o, MODEL_BUB, bhvBub);
}
o->oAction = 1;
o->oAction = BUB_SPAWNER_ACT_IDLE;
}
}
void bub_spawner_act_1(void) {
if (gMarioObject->oPosY - o->oPosY > 2000.0f)
o->oAction = 2;
void bub_spawner_act_idle(void) {
if ((gMarioObject->oPosY - o->oPosY) > 2000.0f) {
o->oAction = BUB_SPAWNER_ACT_REMOVE_BUBS;
}
}
void bub_spawner_act_2(void) {
o->oAction = 3;
void bub_spawner_act_remove_bubs(void) {
o->oAction = BUB_SPAWNER_ACT_RESET;
}
void bub_spawner_act_3(void) {
o->oAction = 0;
void bub_spawner_act_reset(void) {
o->oAction = BUB_SPAWNER_ACT_SPAWN_BUBS;
}
void (*sBirdChirpChirpActions[])(void) = { bub_spawner_act_0, bub_spawner_act_1,
bub_spawner_act_2, bub_spawner_act_3 };
ObjActionFunc sBirdChirpChirpActions[] = {
bub_spawner_act_spawn_bubs,
bub_spawner_act_idle,
bub_spawner_act_remove_bubs,
bub_spawner_act_reset,
};
void bhv_bub_spawner_loop(void) {
cur_obj_call_action_function(sBirdChirpChirpActions);
@@ -37,86 +42,116 @@ void bhv_bub_spawner_loop(void) {
void bub_move_vertically(s32 ySpeed) {
f32 parentY = o->parentObj->oPosY;
if (parentY - 100.0f - o->oCheepCheepMaxYOffset < o->oPosY && o->oPosY < parentY + 1000.0f + o->oCheepCheepMaxYOffset) {
if (
parentY - 100.0f - o->oCheepCheepMaxYOffset < o->oPosY
&& o->oPosY < parentY + 1000.0f + o->oCheepCheepMaxYOffset
) {
o->oPosY = approach_f32_symmetric(o->oPosY, o->oCheepCheepTargetY, ySpeed);
}
}
void bub_act_0(void) {
void bub_act_init(void) {
o->oCheepCheepTargetYOffset = random_float() * 100.0f;
o->oCheepCheepMaxYOffset = random_float() * 300.0f;
o->oAction = 1;
o->oCheepCheepMaxYOffset = random_float() * 300.0f;
o->oAction = BUB_ACT_SWIMMING_TOWARDS_MARIO;
}
void bub_act_1(void) {
f32 dy;
void bub_act_swimming_towards_mario(void) {
if (o->oTimer == 0) {
o->oForwardVel = random_float() * 2 + 2;
o->oCheepCheepRandomSwimAway = random_float();
}
dy = o->oPosY - gMarioObject->oPosY;
f32 dy = o->oPosY - gMarioObject->oPosY;
if (o->oPosY < o->oCheepCheepWaterLevel - 50.0f) {
if (dy < 0.0f)
dy = 0.0f - dy;
if (dy < 500.0f)
if (absf(dy) < 500.0f) {
bub_move_vertically(1);
else
} else {
bub_move_vertically(4);
}
} else {
o->oPosY = o->oCheepCheepWaterLevel - 50.0f;
if (dy > 300.0f)
o->oPosY = o->oPosY - 1.0f;
}
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->oCheepCheepRandomSwimAway < 0.5f)
o->oAction = 2;
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)
spawn_object(o, MODEL_WHITE_PARTICLE_SMALL, bhvSmallParticleSnow);
} else
o->oInteractStatus = 0;
if (o->oTimer == 0)
cur_obj_play_sound_2(SOUND_GENERAL_MOVING_WATER);
if (o->oForwardVel == 0.0f)
o->oForwardVel = 6.0f;
dy = o->oPosY - gMarioObject->oPosY;
if (o->oPosY < o->oCheepCheepWaterLevel - 50.0f) {
if (dy < 0.0f)
dy = 0.0f - dy;
if (dy < 500.0f)
bub_move_vertically(2);
else
bub_move_vertically(4);
} else {
o->oPosY = o->oCheepCheepWaterLevel - 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 (800.0f < cur_obj_lateral_dist_from_mario_to_home()) {
o->oAngleToMario = cur_obj_angle_to_home();
cur_obj_rotate_yaw_toward(o->oAngleToMario + 0x8000, 0x400);
if (o->oTimer > 200 && o->oDistanceToMario > 600.0f)
o->oAction = 1;
}
cur_obj_rotate_yaw_toward(o->oAngleToMario, 0x100);
if (o->oDistanceToMario < 200.0f && o->oCheepCheepRandomSwimAway < 0.5f) {
o->oAction = BUB_ACT_SWIMMING_AWAY_FROM_MARIO;
}
if (o->oInteractStatus & INT_STATUS_INTERACTED) {
o->oAction = BUB_ACT_SWIMMING_AWAY_FROM_MARIO;
}
}
void (*sCheepCheepActions[])(void) = { bub_act_0, bub_act_1, bub_act_2 };
void bub_act_swimming_away_from_mario(void) {
if (o->oTimer < 20) {
if (o->oInteractStatus & INT_STATUS_INTERACTED) {
spawn_object(o, MODEL_WHITE_PARTICLE_SMALL, bhvSmallParticleSnow);
}
} else {
o->oInteractStatus = INT_STATUS_NONE;
}
if (o->oTimer == 0) {
cur_obj_play_sound_2(SOUND_GENERAL_MOVING_WATER);
}
if (o->oForwardVel == 0.0f) {
o->oForwardVel = 6.0f;
}
f32 dy = o->oPosY - gMarioObject->oPosY;
if (o->oPosY < o->oCheepCheepWaterLevel - 50.0f) {
if (absf(dy) < 500.0f) {
bub_move_vertically(2);
} else {
bub_move_vertically(4);
}
} else {
o->oPosY = o->oCheepCheepWaterLevel - 50.0f;
if (dy > 300.0f) {
o->oPosY -= 1.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) {
o->oAction = BUB_ACT_SWIMMING_TOWARDS_MARIO;
}
}
ObjActionFunc sCheepCheepActions[] = {
bub_act_init,
bub_act_swimming_towards_mario,
bub_act_swimming_away_from_mario,
};
void bhv_bub_loop(void) {
o->oCheepCheepWaterLevel = find_water_level(o->oPosX, o->oPosZ);
o->oCheepCheepTargetY = gMarioObject->oPosY + o->oCheepCheepTargetYOffset;
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 == BUB_SPAWNER_ACT_REMOVE_BUBS) {
obj_mark_for_deletion(o);
}
}
+16 -14
View File
@@ -12,7 +12,7 @@ static struct ObjectHitbox sBubbaHitbox = {
/* hurtboxHeight: */ 200,
};
void bubba_act_0(void) {
void bubba_act_idle(void) {
f32 lateralDistToHome = cur_obj_lateral_dist_to_home();
treat_far_home_as_mario(2000.0f);
o->oAnimState = 0;
@@ -31,12 +31,12 @@ void bubba_act_0(void) {
o->oBubbaRandomTimer = random_linear_offset(20, 30);
}
if ((o->oBubbaHitWall = o->oMoveFlags & OBJ_MOVE_HIT_WALL) != 0) {
if ((o->oBubbaHitWall = o->oMoveFlags) & OBJ_MOVE_HIT_WALL) {
o->oBubbaTargetYaw = cur_obj_reflect_move_angle_off_wall();
} else if (o->oTimer > 30 && o->oDistanceToMario < 2000.0f) {
} else if ((o->oTimer > 30) && (o->oDistanceToMario < 2000.0f)) {
o->oAction = 1;
} else if (o->oBubbaRandomTimer != 0) {
o->oBubbaRandomTimer -= 1;
o->oBubbaRandomTimer--;
} else {
o->oBubbaTargetYaw = obj_random_fixed_turn(0x2000);
o->oBubbaRandomTimer = random_linear_offset(100, 100);
@@ -44,8 +44,9 @@ void bubba_act_0(void) {
}
}
void bubba_act_1(void) {
void bubba_act_attack(void) {
treat_far_home_as_mario(2500.0f);
if (o->oDistanceToMario > 2500.0f) {
o->oAction = 0;
} else if (o->oBubbaLungeTimer != 0) {
@@ -83,9 +84,9 @@ void bubba_act_1(void) {
o->oBubbaTargetPitch = o->oBubbaNextTargetPitchTowardMario;
if (obj_is_near_to_and_facing_mario(500.0f, 3000)
&& abs_angle_diff(o->oBubbaTargetPitch, o->oMoveAnglePitch) < 3000) {
&& abs_angle_diff(o->oBubbaTargetPitch, o->oMoveAnglePitch) < 3000) {
o->oBubbaLungeTimer = 30;
o->oBubbaMovePitch = 0;
o->oBubbaMovePitch = 0;
o->oAnimState = 1;
} else {
approach_f32_ptr(&o->oBubbaMovePitch, 20.0f, 0.5f);
@@ -111,11 +112,11 @@ void bhv_bubba_loop(void) {
cur_obj_update_floor_and_walls();
switch (o->oAction) {
case 0:
bubba_act_0();
case BUBBA_ACT_IDLE:
bubba_act_idle();
break;
case 1:
bubba_act_1();
case BUBBA_ACT_ATTACK:
bubba_act_attack();
break;
}
@@ -130,10 +131,11 @@ void bhv_bubba_loop(void) {
o->oBubbaJumpHeight = 0.0f;
} else {
approach_f32_ptr(&o->oBubbaAirVelY, 0.0f, 4.0f);
if ((o->oBubbaJumpHeight -= o->oBubbaAirVelY) > 1.0f) {
o->oBubbaJumpHeight -= o->oBubbaAirVelY;
if (o->oBubbaJumpHeight > 1.0f) {
s16 rand = random_u16();
o->oBubbaJumpHeight -= 1.0f;
spawn_object_relative(0, 150.0f * coss(rand), 0x64, 150.0f * sins(rand), o,
spawn_object_relative(OBJ_BP_NONE, 150.0f * coss(rand), 0x64, 150.0f * sins(rand), o,
MODEL_WHITE_PARTICLE_SMALL, bhvSmallParticleSnow);
}
}
@@ -142,7 +144,7 @@ void bhv_bubba_loop(void) {
obj_smooth_turn(&o->oBubbaYawVel, &o->oMoveAngleYaw, o->oBubbaTargetYaw, 0.05f, 10, 50, 2000);
obj_compute_vel_from_move_pitch(o->oBubbaMovePitch);
} else {
o->oBubbaMovePitch = sqrtf(o->oForwardVel * o->oForwardVel + o->oVelY * o->oVelY);
o->oBubbaMovePitch = sqrtf(sqr(o->oForwardVel) + sqr(o->oVelY));
o->oMoveAnglePitch = obj_get_pitch_from_vel();
obj_face_pitch_approach(o->oMoveAnglePitch, 400);
o->oBubbaPitchVel = 0;
+2 -2
View File
@@ -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;
+31 -15
View File
@@ -1,8 +1,7 @@
// bullet_bill.inc.c
// bullet bill smoke
void bhv_white_puff_smoke_init(void) {
cur_obj_scale(random_float() * 2.0f + 2.0f);
cur_obj_scale(random_float() * 2 + 2.0);
}
void bhv_bullet_bill_init(void) {
@@ -15,36 +14,44 @@ void bullet_bill_act_0(void) {
o->oMoveAngleYaw = o->oBulletBillInitialMoveYaw;
o->oFaceAnglePitch = 0;
o->oFaceAngleRoll = 0;
o->oMoveFlags = 0;
o->oMoveFlags = OBJ_MOVE_NONE;
cur_obj_set_pos_to_home();
o->oAction = 1;
}
void bullet_bill_act_1(void) {
s16 dYaw = abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw);
if (dYaw < 0x2000 && 400.0f < o->oDistanceToMario && o->oDistanceToMario < 1500.0f)
s16 sp1E = abs_angle_diff(o->oAngleToMario, o->oMoveAngleYaw);
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 };
ObjActionFunc sBulletBillActions[] = {
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;
}
}
+58 -59
View File
@@ -1,4 +1,4 @@
// bully.c.inc
// bully.inc.c
static struct ObjectHitbox sSmallBullyHitbox = {
/* interactType: */ INTERACT_BULLY,
@@ -26,11 +26,9 @@ static struct ObjectHitbox sBigBullyHitbox = {
void bhv_small_bully_init(void) {
cur_obj_init_animation(0);
o->oHomeX = o->oPosX;
o->oHomeZ = o->oPosZ;
vec3f_copy(&o->oHomeVec, &o->oPosVec);
o->oBehParams2ndByte = BULLY_BP_SIZE_SMALL;
o->oGravity = 4.0f;
o->oGravity = 4.0f;
o->oFriction = 0.91f;
o->oBuoyancy = 1.3f;
@@ -39,9 +37,9 @@ void bhv_small_bully_init(void) {
void bhv_big_bully_init(void) {
cur_obj_init_animation(0);
vec3_copy(&o->oHomeVec, &o->oPosVec);
vec3f_copy(&o->oHomeVec, &o->oPosVec);
o->oBehParams2ndByte = BULLY_BP_SIZE_BIG;
o->oGravity = 5.0f;
o->oGravity = 5.0f;
o->oFriction = 0.93f;
o->oBuoyancy = 1.3f;
@@ -50,14 +48,15 @@ void bhv_big_bully_init(void) {
void bully_check_mario_collision(void) {
if (o->oAction != OBJ_ACT_LAVA_DEATH && o->oAction != OBJ_ACT_DEATH_PLANE_DEATH && o->oInteractStatus & INT_STATUS_INTERACTED) {
if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL)
cur_obj_play_sound_2(SOUND_OBJ2_BULLY_ATTACKED);
else
if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) {
cur_obj_play_sound_2(SOUND_OBJ2_SMALL_BULLY_ATTACKED);
} else {
cur_obj_play_sound_2(SOUND_OBJ2_LARGE_BULLY_ATTACKED);
}
o->oInteractStatus &= ~INT_STATUS_INTERACTED;
o->oAction = BULLY_ACT_KNOCKBACK;
o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; /* bit 3 */
o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW;
cur_obj_init_animation(3);
o->oBullyMarioCollisionAngle = o->oMoveAngleYaw;
}
@@ -70,15 +69,17 @@ void bully_act_chase_mario(void) {
if (o->oTimer < 10) {
o->oForwardVel = 3.0f;
obj_turn_toward_object(o, gMarioObject, 16, 4096);
obj_turn_toward_object(o, gMarioObject, O_MOVE_ANGLE_YAW_INDEX, 0x1000);
} else if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) {
o->oForwardVel = 20.0f;
if (o->oTimer >= 31)
if (o->oTimer > 30) {
o->oTimer = 0;
}
} else {
o->oForwardVel = 30.0f;
if (o->oTimer >= 36)
if (o->oTimer > 35) {
o->oTimer = 0;
}
}
if (!is_point_within_radius_of_mario(homeX, posY, homeZ, 1000)) {
@@ -91,11 +92,12 @@ void bully_act_knockback(void) {
if (o->oForwardVel < 10.0f && (s32) o->oVelY == 0) {
o->oForwardVel = 1.0f;
o->oBullyKBTimerAndMinionKOCounter++;
o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; /* 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, O_MOVE_ANGLE_YAW_INDEX, 1280);
} else {
o->header.gfx.animInfo.animFrame = 0;
}
if (o->oBullyKBTimerAndMinionKOCounter == 18) {
o->oAction = BULLY_ACT_CHASE_MARIO;
@@ -106,7 +108,7 @@ void bully_act_knockback(void) {
void bully_act_back_up(void) {
if (o->oTimer == 0) {
o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; /* bit 3 */
o->oFlags &= ~OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW;
o->oMoveAngleYaw += 0x8000;
}
@@ -121,14 +123,13 @@ void bully_act_back_up(void) {
if (o->oTimer == 15) {
o->oMoveAngleYaw = o->oFaceAngleYaw;
o->oFlags |= OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW; /* 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 & OBJ_COL_FLAG_NO_Y_VEL) && 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;
@@ -137,50 +138,50 @@ void bully_backup_check(s16 collisionFlags) {
void bully_play_stomping_sound(void) {
s16 animFrame = o->header.gfx.animInfo.animFrame;
switch (o->oAction) {
case BULLY_ACT_PATROL:
if (animFrame == 0 || animFrame == 12) {
if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL)
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALK);
else
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALKING);
if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) {
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALK_SMALL);
} else {
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALK_LARGE);
}
}
break;
case BULLY_ACT_CHASE_MARIO:
case BULLY_ACT_BACK_UP:
if (animFrame == 0 || animFrame == 5) {
if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL)
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALK);
else
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALKING);
if (o->oBehParams2ndByte == BULLY_BP_SIZE_SMALL) {
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALK_SMALL);
} else {
cur_obj_play_sound_2(SOUND_OBJ_BULLY_WALK_LARGE);
}
}
break;
}
}
void bully_step(void) {
s16 collisionFlags = 0;
collisionFlags = object_step();
s16 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 = OBJ_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;
@@ -188,29 +189,28 @@ 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);
}
}
}
}
void bhv_bully_loop(void) {
o->oBullyPrevX = o->oPosX;
o->oBullyPrevY = o->oPosY;
o->oBullyPrevZ = o->oPosZ;
vec3f_copy(&o->oBullyPrevVec, &o->oPosVec);
//! Because this function runs no matter what, Mario is able to interrupt the bully's
// death action by colliding with it. Since the bully hitbox is tall enough to collide
@@ -222,7 +222,7 @@ void bhv_bully_loop(void) {
case BULLY_ACT_PATROL:
o->oForwardVel = 5.0f;
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);
}
@@ -257,9 +257,9 @@ void bhv_bully_loop(void) {
set_object_visibility(o, 3000);
}
void big_bully_spawn_minion(s32 x, s32 y, s32 z, s16 ry) {
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, x, y, z, 0, ry, 0);
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;
}
@@ -277,18 +277,15 @@ 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);
}
}
void bhv_big_bully_with_minions_loop(void) {
s16 collisionFlags;
o->oBullyPrevX = o->oPosX;
o->oBullyPrevY = o->oPosY;
o->oBullyPrevZ = o->oPosZ;
s16 collisionFlags = 0;
vec3f_copy(&o->oBullyPrevVec, &o->oPosVec);
bully_check_mario_collision();
@@ -296,7 +293,7 @@ void bhv_big_bully_with_minions_loop(void) {
case BULLY_ACT_PATROL:
o->oForwardVel = 5.0f;
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);
}
@@ -327,15 +324,17 @@ 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 & OBJ_COL_FLAGS_LANDED) == OBJ_COL_FLAGS_LANDED) /* bits 0 and 3 */
if ((collisionFlags & OBJ_COL_FLAGS_LANDED) == OBJ_COL_FLAGS_LANDED) {
o->oAction = BULLY_ACT_PATROL;
}
if (collisionFlags == OBJ_COL_FLAG_GROUNDED) {
cur_obj_play_sound_2(SOUND_OBJ_THWOMP);
+33 -33
View File
@@ -1,13 +1,10 @@
// butterfly.c.inc
// butterfly.inc.c
void bhv_butterfly_init(void) {
cur_obj_init_animation(1);
cur_obj_init_animation(BUTTERFLY_ANIM_RESTING);
o->oButterflyYPhase = random_float() * 100.0f;
o->header.gfx.animInfo.animFrame = random_float() * 7.0f;
o->oHomeX = o->oPosX;
o->oHomeY = o->oPosY;
o->oHomeZ = o->oPosZ;
vec3f_copy(&o->oHomeVec, &o->oPosVec);
}
void butterfly_step(s32 speed) {
@@ -23,36 +20,40 @@ void butterfly_step(s32 speed) {
o->oPosX += o->oVelX;
o->oPosZ += o->oVelZ;
if (o->oAction == BUTTERFLY_ACT_FOLLOW_MARIO)
o->oPosY -= o->oVelY + coss((s32)(yPhase * 655.36)) * 20.0f / 4;
else
if (o->oAction == BUTTERFLY_ACT_FOLLOW_MARIO) {
o->oPosY -= o->oVelY + coss((s32)(yPhase * 655.36f)) * 5.0f; // * 20.0f / 4;
} else {
o->oPosY -= o->oVelY;
}
floorY = find_floor_height(o->oPosX, o->oPosY, o->oPosZ);
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) {
gMarioObject->oPosX += 5 * o->oButterflyYPhase / 4;
gMarioObject->oPosZ += 5 * o->oButterflyYPhase / 4;
obj_turn_toward_object(o, gMarioObject, 16, 0x300);
gMarioObject->oPosX -= 5 * o->oButterflyYPhase / 4;
gMarioObject->oPosZ -= 5 * o->oButterflyYPhase / 4;
gMarioObject->oPosY += (5 * o->oButterflyYPhase + 0x100) / 4;
obj_turn_toward_object(o, gMarioObject, 15, 0x500);
gMarioObject->oPosY -= (5 * o->oButterflyYPhase + 0x100) / 4;
s32 yPhase = 5 * o->oButterflyYPhase / 4;
gMarioObject->oPosX += yPhase;
gMarioObject->oPosZ += yPhase;
obj_turn_toward_object(o, gMarioObject, O_MOVE_ANGLE_YAW_INDEX, 0x300);
gMarioObject->oPosX -= yPhase;
gMarioObject->oPosZ -= yPhase;
yPhase = (5 * o->oButterflyYPhase + 0x100) / 4;
gMarioObject->oPosY += yPhase;
obj_turn_toward_object(o, gMarioObject, O_MOVE_ANGLE_PITCH_INDEX, 0x500);
gMarioObject->oPosY -= yPhase;
}
void butterfly_act_rest(void) {
if (is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, 1000)) {
cur_obj_init_animation(0);
cur_obj_init_animation(BUTTERFLY_ANIM_FLYING);
o->oAction = BUTTERFLY_ACT_FOLLOW_MARIO;
o->oMoveAngleYaw = gMarioObject->header.gfx.angle[1];
@@ -64,29 +65,28 @@ 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) {
f32 homeDistX = o->oHomeX - o->oPosX;
f32 homeDistY = o->oHomeY - o->oPosY;
f32 homeDistZ = o->oHomeZ - o->oPosZ;
s16 hAngleToHome = atan2s(homeDistZ, homeDistX);
s16 vAngleToHome = atan2s(sqrtf(homeDistX * homeDistX + homeDistZ * homeDistZ), -homeDistY);
Vec3f homeDist;
vec3f_diff(homeDist, &o->oHomeVec, &o->oPosVec);
f32 homeDistXSq = sqr(homeDist[0]);
f32 homeDistZSq = sqr(homeDist[2]);
s16 hAngleToHome = atan2s(homeDist[2], homeDist[0]);
s16 vAngleToHome = atan2s(sqrtf(homeDistXSq + homeDistZSq), -homeDist[1]);
o->oMoveAngleYaw = approach_s16_symmetric(o->oMoveAngleYaw, hAngleToHome, 0x800);
o->oMoveAnglePitch = approach_s16_symmetric(o->oMoveAnglePitch, vAngleToHome, 0x50);
butterfly_step(7);
if (homeDistX * homeDistX + homeDistY * homeDistY + homeDistZ * homeDistZ < 144.0f) {
cur_obj_init_animation(1);
if ((homeDistXSq + sqr(homeDist[1]) + homeDistZSq) < 144.0f) {
cur_obj_init_animation(BUTTERFLY_ANIM_RESTING);
o->oAction = BUTTERFLY_ACT_RESTING;
o->oPosX = o->oHomeX;
o->oPosY = o->oHomeY;
o->oPosZ = o->oHomeZ;
vec3f_copy(&o->oPosVec, &o->oHomeVec);
}
}
+12 -13
View File
@@ -28,8 +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) {
if (gMarioObject->oPosX > -544.0f
&& gMarioObject->oPosX < 545.0f
&& gMarioObject->oPosY > 800.0f
&& gMarioObject->oPosZ > -2000.0f
&& gMarioObject->oPosZ < -177.0f) {
if (set_mario_npc_dialog(MARIO_DIALOG_LOOK_UP) == MARIO_DIALOG_STATUS_START) {
o->oAction = CAMERA_LAKITU_INTRO_ACT_SPAWN_CLOUD;
}
@@ -59,8 +62,8 @@ static void camera_lakitu_intro_act_spawn_cloud(void) {
* Circle down to mario, show the dialog, then fly away.
*/
static void camera_lakitu_intro_act_show_dialog(void) {
s16 targetMovePitch = 0;
s16 targetMoveYaw = 0;
s16 targetMovePitch = 0x0;
s16 targetMoveYaw = 0x0;
cur_obj_play_sound_1(SOUND_AIR_LAKITU_FLY);
@@ -102,13 +105,11 @@ static void camera_lakitu_intro_act_show_dialog(void) {
o->oCameraLakituIntroMusicPlayed = TRUE;
}
#endif
// Once within 1000 units, slow down
approach_f32_ptr(&o->oCameraLakituSpeed, 20.0f, 1.0f);
if (o->oDistanceToMario < 500.0f
&& abs_angle_diff(gMarioObject->oFaceAngleYaw, o->oFaceAngleYaw) > 0x7000) {
// Once within 500 units and facing toward mario, come
// to a stop
// Once within 500 units and facing toward mario, come to a stop
approach_f32_ptr(&o->oCameraLakituSpeed, 0.0f, 5.0f);
}
}
@@ -119,10 +120,10 @@ static void camera_lakitu_intro_act_show_dialog(void) {
}
}
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,14 +152,12 @@ void bhv_camera_lakitu_update(void) {
}
} else {
f32 mirroredX = CASTLE_MIRROR_X - gLakituState.curPos[0];
if (gLakituState.curPos[0] < 1700.0f || mirroredX < 0.0f) {
cur_obj_hide();
} else {
cur_obj_unhide();
o->oPosX = gLakituState.curPos[0];
o->oPosY = gLakituState.curPos[1];
o->oPosZ = gLakituState.curPos[2];
vec3f_copy(&o->oPosVec, gLakituState.curPos);
o->oHomeX = gLakituState.curFocus[0];
o->oHomeZ = gLakituState.curFocus[2];
+59 -42
View File
@@ -1,65 +1,71 @@
// cannon.c.inc
// cannon.inc.c
void bhv_cannon_base_unused_loop(void) {
o->oPosY += o->oVelY;
}
void opened_cannon_act_0(void) {
void opened_cannon_act_idle(void) { // act 0
if (o->oTimer == 0) {
o->oInteractStatus = 0;
o->oPosX = o->oHomeX;
o->oPosY = o->oHomeY;
o->oPosZ = o->oHomeZ;
o->oInteractStatus = INT_STATUS_NONE;
vec3f_copy(&o->oPosVec, &o->oHomeVec);
o->oMoveAnglePitch = 0;
o->oMoveAngleYaw = (s16)(o->oBehParams2ndByte << 8);
o->oCannonAngle = 0;
o->oCannonIsActive = 0;
o->oMoveAngleYaw = (s16)(o->oBehParams2ndByte << 8);
o->oCannonAngle = 0;
o->oCannonIsActive = FALSE;
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->oCannonIsActive = 1;
o->oCannonIsActive = TRUE;
o->oCannonTimeSinceActivated = 1;
} else
o->oInteractStatus = 0;
} else {
o->oInteractStatus = INT_STATUS_NONE;
}
} else {
cur_obj_become_intangible();
cur_obj_disable_rendering();
o->oCannonIsActive = 0;
o->oCannonIsActive = FALSE;
}
}
void opened_cannon_act_4(void) {
if (o->oTimer == 0)
cur_obj_play_sound_2(SOUND_OBJ_CANNON1);
void opened_cannon_act_rising(void) { // act 4
if (o->oTimer == 0) {
cur_obj_play_sound_2(SOUND_OBJ_CANNON_RISE);
}
o->oPosY += 5.0f;
o->oPosX += (f32)((o->oTimer / 2 & 1) - 0.5) * 2;
o->oPosZ += (f32)((o->oTimer / 2 & 1) - 0.5) * 2;
f32 horizontalVel = (f32)(((o->oTimer / 2) & 0x1) - 0.5f) * 2;
o->oPosX += horizontalVel;
o->oPosZ += horizontalVel;
if (o->oTimer > 67) {
o->oPosX += (f32)((o->oTimer / 2 & 1) - 0.5) * 4;
o->oPosZ += (f32)((o->oTimer / 2 & 1) - 0.5) * 4;
horizontalVel *= 2;
o->oPosX += horizontalVel;
o->oPosZ += horizontalVel;
o->oAction = 6;
}
}
void opened_cannon_act_6(void) {
if (o->oTimer == 0)
cur_obj_play_sound_2(SOUND_OBJ_CANNON2);
void opened_cannon_act_turning_yaw(void) { // act 6
if (o->oTimer == 0) {
cur_obj_play_sound_2(SOUND_OBJ_CANNON_TURN);
}
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;
f32 horizontalVel = ((f32)(((o->oTimer / 2) & 0x1) - 0.5f) * 4.0f);
o->oPosX += horizontalVel;
o->oPosZ += horizontalVel;
} else {
if (o->oTimer >= 6) {
if (o->oTimer < 22) {
o->oMoveAngleYaw =
sins(o->oCannonAngle) * 0x4000 + ((s16)(o->oBehParams2ndByte << 8));
((sins(o->oCannonAngle) * 0x4000) + ((s16)(o->oBehParams2ndByte << 8)));
o->oCannonAngle += 0x400;
} else if (o->oTimer >= 26) {
o->oCannonAngle = 0;
@@ -69,50 +75,61 @@ void opened_cannon_act_6(void) {
}
}
void opened_cannon_act_5(void) {
if (o->oTimer == 0)
cur_obj_play_sound_2(SOUND_OBJ_CANNON3);
void opened_cannon_act_pitch_up(void) { // act 5
if (o->oTimer == 0) {
cur_obj_play_sound_2(SOUND_OBJ_CANNON_BARREL_PITCH);
}
if (o->oTimer >= 4) {
if (o->oTimer < 20) {
o->oCannonAngle += 0x400;
o->oMoveAnglePitch = sins(o->oCannonAngle) * 0x2000;
o->oMoveAnglePitch = (sins(o->oCannonAngle) * 0x2000);
} else if (o->oTimer >= 25) {
o->oAction = 1;
}
}
}
void opened_cannon_act_1(void) {
void opened_cannon_act_ready(void) { // act 1
cur_obj_become_intangible();
cur_obj_disable_rendering();
o->oCannonIsActive = 0;
gMarioShotFromCannon = 1;
o->oCannonIsActive = FALSE;
gMarioShotFromCannon = TRUE;
}
void opened_cannon_act_2(void) {
void opened_cannon_act_shoot(void) { // act 2
o->oAction = 3;
}
void opened_cannon_act_3(void) {
void opened_cannon_act_resetting(void) { // act 3
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 };
ObjActionFunc sOpenedCannonActions[] = {
opened_cannon_act_idle,
opened_cannon_act_ready,
opened_cannon_act_shoot,
opened_cannon_act_resetting,
opened_cannon_act_rising,
opened_cannon_act_pitch_up,
opened_cannon_act_turning_yaw,
};
void bhv_cannon_base_loop(void) {
cur_obj_call_action_function(sOpenedCannonActions);
if (o->oCannonTimeSinceActivated) {
o->oCannonTimeSinceActivated++;
}
o->oInteractStatus = 0;
o->oInteractStatus = INT_STATUS_NONE;
}
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);
+14 -13
View File
@@ -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;
+51 -44
View File
@@ -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;
o->oInteractStatus = INT_STATUS_NONE;
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:
@@ -41,25 +43,25 @@ void cap_check_quicksand(void) {
case SURFACE_SHALLOW_QUICKSAND:
case SURFACE_DEEP_QUICKSAND:
case SURFACE_QUICKSAND:
o->oAction = 10;
o->oAction = CAP_ACT_QUICKSAND;
o->oForwardVel = 0.0f;
break;
case SURFACE_DEEP_MOVING_QUICKSAND:
case SURFACE_SHALLOW_MOVING_QUICKSAND:
case SURFACE_MOVING_QUICKSAND:
o->oAction = 11;
o->oAction = CAP_ACT_MOVING_QUICKSAND;
o->oMoveAngleYaw = (sObjFloor->force & 0xFF) << 8;
o->oForwardVel = 8 + 2 * (0 - ((sObjFloor->force & 0xFF00) >> 8));
break;
case SURFACE_INSTANT_QUICKSAND:
o->oAction = 12;
o->oAction = CAP_ACT_INSTANT_QUICKSAND;
o->oForwardVel = 0.0f;
break;
case SURFACE_INSTANT_MOVING_QUICKSAND:
o->oAction = 13;
o->oAction = CAP_ACT_INSTANT_MOVING_QUICKSAND;
o->oMoveAngleYaw = (sObjFloor->force & 0xFF) << 8;
o->oForwardVel = 8 + 2 * (0 - ((sObjFloor->force & 0xFF00) >> 8));
break;
@@ -68,32 +70,32 @@ void cap_check_quicksand(void) {
void cap_sink_quicksand(void) {
switch (o->oAction) {
case 10:
case CAP_ACT_QUICKSAND:
if (o->oTimer < 10) {
o->oGraphYOffset += -1.0f;
o->oFaceAnglePitch = 0x2000;
}
break;
case 11:
if (o->oTimer < 10)
case CAP_ACT_MOVING_QUICKSAND:
if (o->oTimer < 10) {
o->oGraphYOffset += -3.0f;
}
o->oFaceAnglePitch = 0x2000;
break;
case 12:
case CAP_ACT_INSTANT_QUICKSAND:
o->oGraphYOffset += -1.0f;
if (o->oTimer >= 21)
if (o->oTimer > 20) {
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
}
break;
case 13:
case CAP_ACT_INSTANT_MOVING_QUICKSAND:
o->oGraphYOffset += -6.0f;
if (o->oTimer >= 21)
if (o->oTimer > 20) {
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
}
o->oFaceAnglePitch = 0x2000;
break;
}
@@ -113,30 +115,29 @@ void cap_scale_vertically(void) {
o->header.gfx.scale[1] = coss(o->oCapScaleAngle) * 0.3f + 0.7f;
if (o->oCapScaleAngle == 0x10000) {
o->oCapScaleAngle = 0;
o->oCapDoScaleVertically = 2;
o->oCapDoScaleVertically = FALSE;
}
}
void wing_vanish_cap_act_0(void) {
s16 collisionFlags;
o->oFaceAngleYaw += o->oForwardVel * 128.0f;
collisionFlags = object_step();
s16 collisionFlags = object_step();
if (collisionFlags & OBJ_COL_FLAG_GROUNDED) {
cap_check_quicksand();
if (o->oVelY != 0.0f) {
o->oCapDoScaleVertically = 1;
o->oCapDoScaleVertically = TRUE;
o->oVelY = 0.0f;
}
}
if (o->oCapDoScaleVertically == 1)
if (o->oCapDoScaleVertically) {
cap_scale_vertically();
}
}
void bhv_wing_vanish_cap_loop(void) {
switch (o->oAction) {
case 0:
case CAP_ACT_MOVE:
wing_vanish_cap_act_0();
break;
@@ -146,8 +147,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,21 +159,22 @@ 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 collisionFlags;
o->oFaceAngleYaw += (o->oForwardVel * 128.0f);
o->oFaceAngleYaw += o->oForwardVel * 128.0f;
collisionFlags = object_step();
if (collisionFlags & OBJ_COL_FLAG_GROUNDED)
s16 collisionFlags = object_step();
if (collisionFlags & OBJ_COL_FLAG_GROUNDED) {
cap_check_quicksand();
}
}
void bhv_metal_cap_loop(void) {
switch (o->oAction) {
case 0:
case CAP_ACT_MOVE:
metal_cap_act_0();
break;
@@ -181,8 +184,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 +196,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,28 +224,28 @@ void normal_cap_set_save_flags(void) {
}
void normal_cap_act_0(void) {
s16 collisionFlags;
o->oFaceAngleYaw += o->oForwardVel * 128.0f;
o->oFaceAnglePitch += o->oForwardVel * 80.0f;
collisionFlags = object_step();
s16 collisionFlags = object_step();
if (collisionFlags & OBJ_COL_FLAG_GROUNDED) {
cap_check_quicksand();
if (o->oVelY != 0.0f) {
o->oCapDoScaleVertically = 1;
o->oCapDoScaleVertically = TRUE;
o->oVelY = 0.0f;
o->oFaceAnglePitch = 0;
}
}
if (o->oCapDoScaleVertically == 1)
if (o->oCapDoScaleVertically) {
cap_scale_vertically();
}
}
void bhv_normal_cap_loop(void) {
switch (o->oAction) {
case 0:
case CAP_ACT_MOVE:
normal_cap_act_0();
break;
@@ -251,14 +255,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) {
Loaded 100 of 924 files, more files were not shown because too many files have changed in this diff. Show more