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

+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);