Dynamic collision fixes + actual OR_LONG (#648)

* Dynamic collision fixes + actual OR_LONG

Dynamic collision will now check Mario´s vertical distance seperately, this is done to implement a check for when mario is above an object, in which case the collision distance is expanded by 2000 units to avoid shadows not appearing.
Or long works correctly now, replaces the behaviour command NOP_1.

* Micro optimzation

Avoids sqrtf by using the squared lateral distance and squaring the the collision distance for the comparison.

* Requested changes

* minor change

* Re ordering

* How
This commit is contained in:
Lilaa3 authored and GitHub committed 2023-06-29 17:25:54 -05:00
1 parent 4dc17a32a2
commit 7c32cf8b63
3 files changed
+56 -39

No files matched your search

+21 -17
View File
@@ -359,7 +359,7 @@ static s32 bhv_cmd_set_int_unused(void) {
return BHV_PROC_CONTINUE;
}
// Command 0x14: Sets the specified field to a random float in the given range.
// Command 0x15: Sets the specified field to a random float in the given range.
// Usage: SET_RANDOM_FLOAT(field, min, range)
static s32 bhv_cmd_set_random_float(void) {
u8 field = BHV_CMD_GET_2ND_U8(0);
@@ -372,7 +372,7 @@ static s32 bhv_cmd_set_random_float(void) {
return BHV_PROC_CONTINUE;
}
// Command 0x15: Sets the specified field to a random integer in the given range.
// Command 0x16: Sets the specified field to a random integer in the given range.
// Usage: SET_RANDOM_INT(field, min, range)
static s32 bhv_cmd_set_random_int(void) {
u8 field = BHV_CMD_GET_2ND_U8(0);
@@ -385,7 +385,7 @@ static s32 bhv_cmd_set_random_int(void) {
return BHV_PROC_CONTINUE;
}
// Command 0x13: Gets a random short, right shifts it the specified amount and adds min to it, then sets the specified field to that value.
// Command 0x14: Gets a random short, right shifts it the specified amount and adds min to it, then sets the specified field to that value.
// Usage: SET_INT_RAND_RSHIFT(field, min, rshift)
static s32 bhv_cmd_set_int_rand_rshift(void) {
u8 field = BHV_CMD_GET_2ND_U8(0);
@@ -398,7 +398,7 @@ static s32 bhv_cmd_set_int_rand_rshift(void) {
return BHV_PROC_CONTINUE;
}
// Command 0x16: Adds a random float in the given range to the specified field.
// Command 0x17: Adds a random float in the given range to the specified field.
// Usage: ADD_RANDOM_FLOAT(field, min, range)
static s32 bhv_cmd_add_random_float(void) {
u8 field = BHV_CMD_GET_2ND_U8(0);
@@ -411,7 +411,7 @@ static s32 bhv_cmd_add_random_float(void) {
return BHV_PROC_CONTINUE;
}
// Command 0x17: Gets a random short, right shifts it the specified amount and adds min to it, then adds the value to the specified field. Unused.
// Command 0x18: Gets a random short, right shifts it the specified amount and adds min to it, then adds the value to the specified field. Unused.
// Usage: ADD_INT_RAND_RSHIFT(field, min, rshift)
static s32 bhv_cmd_add_int_rand_rshift(void) {
u8 field = BHV_CMD_GET_2ND_U8(0);
@@ -463,7 +463,20 @@ static s32 bhv_cmd_or_int(void) {
return BHV_PROC_CONTINUE;
}
// Command 0x12: Performs a bit clear with the specified short. Unused.
// Command 0x12: Performs a bitwise OR with the specified field and the given (32 bit) integer.
// Usually used to set an object's flags which use values above 16 bits.
// Usage: OR_LONG(field, value)
static s32 bhv_cmd_or_long(void) {
u8 field = BHV_CMD_GET_2ND_U8(0);
u32 value = BHV_CMD_GET_U32(1);
cur_obj_or_int(field, value);
gCurBhvCommand += 2;
return BHV_PROC_CONTINUE;
}
// Command 0x13: Performs a bit clear with the specified short. Unused.
// Usage: BIT_CLEAR(field, value)
static s32 bhv_cmd_bit_clear(void) {
u8 field = BHV_CMD_GET_2ND_U8(0);
@@ -510,7 +523,7 @@ static s32 bhv_cmd_drop_to_floor(void) {
return BHV_PROC_CONTINUE;
}
// Command 0x18: No operation. Unused.
// Command 0x19: No operation. Unused.
// Usage: CMD_NOP_1(field)
static s32 bhv_cmd_nop_1(void) {
UNUSED u8 field = BHV_CMD_GET_2ND_U8(0);
@@ -520,15 +533,6 @@ static s32 bhv_cmd_nop_1(void) {
}
// Command 0x1A: No operation. Unused.
// Usage: CMD_NOP_3(field)
static s32 bhv_cmd_nop_3(void) {
UNUSED u8 field = BHV_CMD_GET_2ND_U8(0);
gCurBhvCommand++;
return BHV_PROC_CONTINUE;
}
// Command 0x19: No operation. Unused.
// Usage: CMD_NOP_2(field)
static s32 bhv_cmd_nop_2(void) {
UNUSED u8 field = BHV_CMD_GET_2ND_U8(0);
@@ -773,6 +777,7 @@ static BhvCommandProc BehaviorCmdTable[] = {
/*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_OR_LONG */ bhv_cmd_or_long,
/*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,
@@ -781,7 +786,6 @@ static BhvCommandProc BehaviorCmdTable[] = {
/*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,