From f224f845d25e62f83d03c016838a4334b81aa0fe Mon Sep 17 00:00:00 2001 From: Fazana <52551480+FazanaJ@users.noreply.github.com> Date: Wed, 8 Sep 2021 14:54:02 +0100 Subject: [PATCH] Allocation fixes --- src/game/level_update.c | 4 ++++ src/game/object_helpers.c | 4 +++- src/game/puppylights.c | 4 ++++ src/game/spawn_object.c | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/game/level_update.c b/src/game/level_update.c index 64204b2d..110c899b 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -1128,6 +1128,10 @@ s32 play_mode_change_area(void) { set_play_mode(PLAY_MODE_NORMAL); } +#ifdef PUPPYLIGHTS + puppylights_allocate(); +#endif + return 0; } diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index eae57a85..84eb45fb 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -26,6 +26,7 @@ #include "rendering_graph_node.h" #include "spawn_object.h" #include "spawn_sound.h" +#include "puppylights.h" static s8 sBbhStairJiggleOffsets[] = { -8, 8, -4, 4 }; static s16 sPowersOfTwo[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; @@ -1057,7 +1058,7 @@ void cur_obj_set_y_vel_and_animation(f32 yVel, s32 animIndex) { void cur_obj_unrender_set_action_and_anim(s32 animIndex, s32 action) { cur_obj_become_intangible(); cur_obj_disable_rendering(); - + // only set animation if non-negative value if (animIndex >= 0) { cur_obj_init_animation_with_sound(animIndex); @@ -1139,6 +1140,7 @@ void obj_mark_for_deletion(struct Object *obj) { // setting it to 0 could potentially enable unexpected behavior. After an // object is marked for deletion, it still updates on that frame (I think), // so this is worth looking into. + obj_disable_light(obj); obj->activeFlags = ACTIVE_FLAG_DEACTIVATED; } diff --git a/src/game/puppylights.c b/src/game/puppylights.c index 68e5188c..adac9ec1 100644 --- a/src/game/puppylights.c +++ b/src/game/puppylights.c @@ -300,6 +300,8 @@ void cur_obj_enable_light(void) void cur_obj_disable_light(void) { gCurrentObject->oFlags &= ~OBJ_FLAG_EMIT_LIGHT; + if (gPuppyLights[gCurrentObject->oLightID] && gCurrentObject->oLightID != 0xFFFF) + gPuppyLights[gCurrentObject->oLightID]->active = FALSE; } void obj_enable_light(struct Object *obj) @@ -310,6 +312,8 @@ void obj_enable_light(struct Object *obj) void obj_disable_light(struct Object *obj) { obj->oFlags &= ~OBJ_FLAG_EMIT_LIGHT; + if (gPuppyLights[obj->oLightID] && obj->oLightID != 0xFFFF) + gPuppyLights[obj->oLightID]->active = FALSE; } #endif diff --git a/src/game/spawn_object.c b/src/game/spawn_object.c index 7176956b..04f2e7d8 100644 --- a/src/game/spawn_object.c +++ b/src/game/spawn_object.c @@ -12,6 +12,7 @@ #include "object_list_processor.h" #include "spawn_object.h" #include "types.h" +#include "puppylights.h" /** * An unused linked list struct that seems to have been replaced by ObjectNode. @@ -356,5 +357,6 @@ struct Object *create_object(const BehaviorScript *bhvScript) { */ void mark_obj_for_deletion(struct Object *obj) { //! Same issue as obj_mark_for_deletion + obj_disable_light(obj); obj->activeFlags = ACTIVE_FLAG_DEACTIVATED; }