From dbf9b0378f1fea6232f9ee1bb64983590b6e1eba Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Sun, 29 Dec 2024 01:35:27 -0600 Subject: [PATCH] Added even more events --- src/engine/fox_enmy.c | 186 +++++++++++++++++++------------ src/port/hooks/Events.h | 1 + src/port/hooks/list/ActorEvent.h | 34 ++++++ src/port/mods/PortEnhancements.c | 16 ++- src/port/mods/PortEnhancements.h | 1 + 5 files changed, 166 insertions(+), 72 deletions(-) create mode 100644 src/port/hooks/list/ActorEvent.h diff --git a/src/engine/fox_enmy.c b/src/engine/fox_enmy.c index 9647c9ad..429a4366 100644 --- a/src/engine/fox_enmy.c +++ b/src/engine/fox_enmy.c @@ -2824,27 +2824,37 @@ void Actor_Update(Actor* this) { } switch (this->obj.status) { - case OBJ_INIT: - this->obj.status = OBJ_ACTIVE; - Object_Init(this->index, this->obj.id); - if (this->obj.id != OBJ_ACTOR_ZO_RADARBUOY) { + case OBJ_INIT: { + CALL_CANCELLABLE_EVENT(ObjectInitEvent, OBJECT_TYPE_ACTOR, this) { + this->obj.status = OBJ_ACTIVE; + Object_Init(this->index, this->obj.id); + if (this->obj.id != OBJ_ACTOR_ZO_RADARBUOY) { + Actor_Move(this); + } + } + break; + } + + case OBJ_ACTIVE: { + CALL_CANCELLABLE_EVENT(ObjectUpdateEvent, OBJECT_TYPE_ACTOR, this) { Actor_Move(this); + if ((this->obj.status != OBJ_FREE) && (this->info.action != NULL)) { + this->info.action(&this->obj); + } } break; + } - case OBJ_ACTIVE: - Actor_Move(this); - if ((this->obj.status != OBJ_FREE) && (this->info.action != NULL)) { - this->info.action(&this->obj); - } - break; - - case OBJ_DYING: - Actor_Move(this); - if (this->obj.status != OBJ_FREE) { - Object_Dying(this->index, this->obj.id); + case OBJ_DYING: { + CALL_CANCELLABLE_EVENT(ObjectDestroyEvent, OBJECT_TYPE_ACTOR, this) { + Actor_Move(this); + if (this->obj.status != OBJ_FREE) { + Object_Dying(this->index, this->obj.id); + } + break; } break; + } } } @@ -2872,25 +2882,34 @@ void Boss_Update(Boss* this) { } switch (this->obj.status) { - case OBJ_INIT: - this->obj.status = OBJ_ACTIVE; - Object_Init(this->index, this->obj.id); - Boss_Move(this); - break; - - case OBJ_ACTIVE: - Boss_Move(this); - if ((this->obj.status != OBJ_FREE) && (this->info.action != NULL)) { - this->info.action(&this->obj); + case OBJ_INIT: { + CALL_CANCELLABLE_EVENT(ObjectInitEvent, OBJECT_TYPE_BOSS, this) { + this->obj.status = OBJ_ACTIVE; + Object_Init(this->index, this->obj.id); + Boss_Move(this); } break; + } - case OBJ_DYING: - Boss_Move(this); - if (this->obj.status != OBJ_FREE) { - Object_Dying(this->index, this->obj.id); + case OBJ_ACTIVE: { + CALL_CANCELLABLE_EVENT(ObjectUpdateEvent, OBJECT_TYPE_BOSS, this) { + Boss_Move(this); + if ((this->obj.status != OBJ_FREE) && (this->info.action != NULL)) { + this->info.action(&this->obj); + } } break; + } + + case OBJ_DYING: { + CALL_CANCELLABLE_EVENT(ObjectDestroyEvent, OBJECT_TYPE_BOSS, this) { + Boss_Move(this); + if (this->obj.status != OBJ_FREE) { + Object_Dying(this->index, this->obj.id); + } + } + break; + } } } @@ -2900,40 +2919,54 @@ void Scenery_Update(Scenery* this) { } switch (this->obj.status) { - case OBJ_INIT: - this->obj.status = OBJ_ACTIVE; - Object_Init(this->index, this->obj.id); - Scenery_Move(this); - break; - - case OBJ_ACTIVE: - Scenery_Move(this); - if (this->info.action != NULL) { - this->info.action(&this->obj); + case OBJ_INIT: { + CALL_CANCELLABLE_EVENT(ObjectInitEvent, OBJECT_TYPE_SCENERY, this) { + this->obj.status = OBJ_ACTIVE; + Object_Init(this->index, this->obj.id); + Scenery_Move(this); } break; + } + + case OBJ_ACTIVE: { + CALL_CANCELLABLE_EVENT(ObjectUpdateEvent, OBJECT_TYPE_SCENERY, this) { + Scenery_Move(this); + if (this->info.action != NULL) { + this->info.action(&this->obj); + } + } + break; + } } } void Sprite_Update(Sprite* this) { switch (this->obj.status) { - case OBJ_INIT: - this->obj.status = OBJ_ACTIVE; - Object_Init(this->index, this->obj.id); - Sprite_Move(this); - break; - - case OBJ_ACTIVE: - Sprite_Move(this); - if (this->info.action != NULL) { - this->info.action(&this->obj); + case OBJ_INIT: { + CALL_CANCELLABLE_EVENT(ObjectInitEvent, OBJECT_TYPE_SPRITE, this) { + this->obj.status = OBJ_ACTIVE; + Object_Init(this->index, this->obj.id); + Sprite_Move(this); } break; - - case OBJ_DYING: - Sprite_Move(this); - Object_Dying(this->index, this->obj.id); + } + case OBJ_ACTIVE: { + CALL_CANCELLABLE_EVENT(ObjectUpdateEvent, OBJECT_TYPE_SPRITE, this) { + Sprite_Move(this); + if (this->info.action != NULL) { + this->info.action(&this->obj); + } + } break; + } + + case OBJ_DYING: { + CALL_CANCELLABLE_EVENT(ObjectDestroyEvent, OBJECT_TYPE_SPRITE, this) { + Sprite_Move(this); + Object_Dying(this->index, this->obj.id); + } + break; + } } } @@ -2946,18 +2979,24 @@ void Item_Update(Item* this) { } switch (this->obj.status) { - case OBJ_INIT: - this->obj.status = OBJ_ACTIVE; - Object_Init(this->index, this->obj.id); - Item_Move(this); - break; - - case OBJ_ACTIVE: - Item_Move(this); - if (this->info.action != NULL) { - this->info.action(&this->obj); + case OBJ_INIT: { + CALL_CANCELLABLE_EVENT(ObjectInitEvent, OBJECT_TYPE_ITEM, this) { + this->obj.status = OBJ_ACTIVE; + Object_Init(this->index, this->obj.id); + Item_Move(this); } break; + } + + case OBJ_ACTIVE: { + CALL_CANCELLABLE_EVENT(ObjectUpdateEvent, OBJECT_TYPE_ITEM, this) { + Item_Move(this); + if (this->info.action != NULL) { + this->info.action(&this->obj); + } + } + break; + } } } @@ -2967,16 +3006,23 @@ void Effect_Update(Effect* this) { } switch (this->obj.status) { - case OBJ_INIT: - this->obj.status = OBJ_ACTIVE; - Object_Init(this->index, this->obj.id); + case OBJ_INIT: { + CALL_CANCELLABLE_EVENT(ObjectInitEvent, OBJECT_TYPE_EFFECT, this) { + this->obj.status = OBJ_ACTIVE; + Object_Init(this->index, this->obj.id); + Effect_Move(this); + } /* fallthrough */ - case OBJ_ACTIVE: - Effect_Move(this); - if ((this->obj.status != OBJ_FREE) && (this->info.action != NULL)) { - this->info.action(&this->obj); + } + case OBJ_ACTIVE: { + CALL_CANCELLABLE_EVENT(ObjectUpdateEvent, OBJECT_TYPE_EFFECT, this) { + Effect_Move(this); + if ((this->obj.status != OBJ_FREE) && (this->info.action != NULL)) { + this->info.action(&this->obj); + } } break; + } } } diff --git a/src/port/hooks/Events.h b/src/port/hooks/Events.h index d4d26279..30afe9ec 100644 --- a/src/port/hooks/Events.h +++ b/src/port/hooks/Events.h @@ -1,4 +1,5 @@ #pragma once #include "list/EngineEvent.h" +#include "list/ActorEvent.h" #include "list/ItemEvent.h" \ No newline at end of file diff --git a/src/port/hooks/list/ActorEvent.h b/src/port/hooks/list/ActorEvent.h new file mode 100644 index 00000000..e08cfa7e --- /dev/null +++ b/src/port/hooks/list/ActorEvent.h @@ -0,0 +1,34 @@ +#pragma once + +#include "gfx.h" +#include "sf64object.h" +#include "port/hooks/impl/EventSystem.h" + +typedef enum { + OBJECT_TYPE_ACTOR, + OBJECT_TYPE_BOSS, + OBJECT_TYPE_SCENERY, + OBJECT_TYPE_SPRITE, + OBJECT_TYPE_ITEM, + OBJECT_TYPE_EFFECT, +} ObjectEventType; + +DEFINE_EVENT(ObjectInitEvent, + ObjectEventType type; + void* object; +); + +DEFINE_EVENT(ObjectUpdateEvent, + ObjectEventType type; + void* object; +); + +DEFINE_EVENT(ObjectDrawEvent, + ObjectEventType type; + void* object; +); + +DEFINE_EVENT(ObjectDestroyEvent, + ObjectEventType type; + void* object; +); \ No newline at end of file diff --git a/src/port/mods/PortEnhancements.c b/src/port/mods/PortEnhancements.c index 2b1cb672..b2559422 100644 --- a/src/port/mods/PortEnhancements.c +++ b/src/port/mods/PortEnhancements.c @@ -158,7 +158,15 @@ void OnGameUpdatePost(IEvent* event) { } void PortEnhancements_Init() { + PortEnhancements_Register(); + // Register event listeners + REGISTER_LISTENER(DisplayPreUpdateEvent, OnDisplayUpdatePre, EVENT_PRIORITY_NORMAL); + REGISTER_LISTENER(GamePostUpdateEvent, OnGameUpdatePost, EVENT_PRIORITY_NORMAL); +} + +void PortEnhancements_Register() { + // Register engine events REGISTER_EVENT(DisplayPreUpdateEvent); REGISTER_EVENT(DisplayPostUpdateEvent); @@ -177,10 +185,14 @@ void PortEnhancements_Init() { REGISTER_EVENT(DrawGlobalHUDPreEvent); REGISTER_EVENT(DrawGlobalHUDPostEvent); + // Register item events REGISTER_EVENT(ItemDropEvent); - REGISTER_LISTENER(DisplayPreUpdateEvent, OnDisplayUpdatePre, EVENT_PRIORITY_NORMAL); - REGISTER_LISTENER(GamePostUpdateEvent, OnGameUpdatePost, EVENT_PRIORITY_NORMAL); + // Register actor events + REGISTER_EVENT(ObjectInitEvent); + REGISTER_EVENT(ObjectUpdateEvent); + REGISTER_EVENT(ObjectDrawEvent); + REGISTER_EVENT(ObjectDestroyEvent); } void PortEnhancements_Exit() { diff --git a/src/port/mods/PortEnhancements.h b/src/port/mods/PortEnhancements.h index 6cdc6aaf..435c8da3 100644 --- a/src/port/mods/PortEnhancements.h +++ b/src/port/mods/PortEnhancements.h @@ -4,6 +4,7 @@ extern "C" { #endif +void PortEnhancements_Register(); void PortEnhancements_Init(); void PortEnhancements_Exit();