fix bugs caused by interpolating the frame an object spawns (#36)

This commit is contained in:
Isaac0-dev 2024-05-11 08:28:20 +10:00 committed by GitHub
parent 8845b3ef0c
commit 1e4e1f8e75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 18 additions and 3 deletions

View File

@ -794,6 +794,7 @@
--- @field public areaIndex integer
--- @field public cameraToObject Vec3f
--- @field public disableAutomaticShadowPos boolean
--- @field public inited boolean
--- @field public node GraphNode
--- @field public pos Vec3f
--- @field public prevAngle Vec3s

View File

@ -1085,6 +1085,7 @@
| areaIndex | `integer` | |
| cameraToObject | [Vec3f](structs.md#Vec3f) | read-only |
| disableAutomaticShadowPos | `boolean` | |
| inited | `boolean` | |
| node | [GraphNode](structs.md#GraphNode) | read-only |
| pos | [Vec3f](structs.md#Vec3f) | read-only |
| prevAngle | [Vec3s](structs.md#Vec3s) | read-only |

View File

@ -176,6 +176,8 @@ struct GraphNodeObject
/*0x54*/ Vec3f cameraToObject;
u32 skipInterpolationTimestamp;
bool skipInViewCheck;
bool inited;
};
struct ObjectNode

View File

@ -27,6 +27,8 @@ void stub_behavior_script_2(void);
void cur_obj_update(void);
void obj_update_gfx_pos_and_angle(struct Object *obj);
u16 position_based_random_u16(void);
f32 position_based_random_float_position(void);
u8 cur_obj_is_last_nat_update_per_frame(void);

View File

@ -1212,6 +1212,13 @@ static void geo_process_object(struct Object *node) {
// Sanity check our stack index, If we above or equal to our stack size. Return to prevent OOB\.
if ((gMatStackIndex + 1) >= MATRIX_STACK_SIZE) { LOG_ERROR("Preventing attempt to exceed the maximum size %i for our matrix stack with size of %i.", MATRIX_STACK_SIZE - 1, gMatStackIndex); return; }
if (!node->header.gfx.inited) {
node->header.gfx.inited = true;
obj_update_gfx_pos_and_angle(node);
vec3f_copy(node->header.gfx.prevPos, node->header.gfx.pos);
vec3s_copy(node->header.gfx.prevAngle, node->header.gfx.angle);
}
if (node->hookRender) {
smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_RENDER, node);
}
@ -1335,7 +1342,7 @@ static void geo_process_object(struct Object *node) {
if (node->header.gfx.animInfo.curAnim != NULL) {
dynos_gfx_swap_animations(node);
geo_set_animation_globals(&node->header.gfx.animInfo, hasAnimation);
smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_ANIM_UPDATE, node);
if (node->hookRender) smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_ANIM_UPDATE, node);
dynos_gfx_swap_animations(node);
}
if (obj_is_in_view(&node->header.gfx, gMatStack[gMatStackIndex])) {
@ -1458,7 +1465,7 @@ void geo_process_held_object(struct GraphNodeHeldObject *node) {
if (node->objNode->header.gfx.animInfo.curAnim != NULL) {
dynos_gfx_swap_animations(node->objNode);
geo_set_animation_globals(&node->objNode->header.gfx.animInfo, hasAnimation);
smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_ANIM_UPDATE, node->objNode);
if (node->objNode->hookRender) smlua_call_event_hooks_object_param(HOOK_ON_OBJECT_ANIM_UPDATE, node->objNode);
dynos_gfx_swap_animations(node->objNode);
}

View File

@ -324,6 +324,7 @@ struct Object *allocate_object(struct ObjectNode *objList) {
obj->header.gfx.angle[0] = 0;
obj->header.gfx.angle[1] = 0;
obj->header.gfx.angle[2] = 0;
obj->header.gfx.inited = false;
obj->coopFlags = 0;
obj->hookRender = 0;

View File

@ -883,7 +883,7 @@ static struct LuaObjectField sGraphNodeFields[LUA_GRAPH_NODE_FIELD_COUNT] = {
{ "type", LVT_S16, offsetof(struct GraphNode, type), true, LOT_NONE },
};
#define LUA_GRAPH_NODE_OBJECT_FIELD_COUNT 26
#define LUA_GRAPH_NODE_OBJECT_FIELD_COUNT 27
static struct LuaObjectField sGraphNodeObjectFields[LUA_GRAPH_NODE_OBJECT_FIELD_COUNT] = {
{ "activeAreaIndex", LVT_S8, offsetof(struct GraphNodeObject, activeAreaIndex), false, LOT_NONE },
{ "angle", LVT_COBJECT, offsetof(struct GraphNodeObject, angle), true, LOT_VEC3S },
@ -891,6 +891,7 @@ static struct LuaObjectField sGraphNodeObjectFields[LUA_GRAPH_NODE_OBJECT_FIELD_
{ "areaIndex", LVT_S8, offsetof(struct GraphNodeObject, areaIndex), false, LOT_NONE },
{ "cameraToObject", LVT_COBJECT, offsetof(struct GraphNodeObject, cameraToObject), true, LOT_VEC3F },
{ "disableAutomaticShadowPos", LVT_BOOL, offsetof(struct GraphNodeObject, disableAutomaticShadowPos), false, LOT_NONE },
{ "inited", LVT_BOOL, offsetof(struct GraphNodeObject, inited), false, LOT_NONE },
{ "node", LVT_COBJECT, offsetof(struct GraphNodeObject, node), true, LOT_GRAPHNODE },
{ "pos", LVT_COBJECT, offsetof(struct GraphNodeObject, pos), true, LOT_VEC3F },
{ "prevAngle", LVT_COBJECT, offsetof(struct GraphNodeObject, prevAngle), true, LOT_VEC3S },