Skip to content

Commit

Permalink
Added even more events
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoDv committed Dec 29, 2024
1 parent fd0cd32 commit dbf9b03
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 62 deletions.
166 changes: 106 additions & 60 deletions src/engine/fox_enmy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Actor_Move(this);
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:
Actor_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_ACTOR, this) {
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;
}
}
}

Expand Down Expand Up @@ -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);
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_ACTIVE:
Boss_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_BOSS, this) {
Boss_Move(this);
if ((this->obj.status != OBJ_FREE) && (this->info.action != NULL)) {
this->info.action(&this->obj);
}
}
break;
}

case OBJ_DYING:
Boss_Move(this);
if (this->obj.status != OBJ_FREE) {
Object_Dying(this->index, this->obj.id);
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;
}
}
}

Expand All @@ -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);
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:
Scenery_Move(this);
if (this->info.action != NULL) {
this->info.action(&this->obj);
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);
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_ACTIVE:
Sprite_Move(this);
if (this->info.action != NULL) {
this->info.action(&this->obj);
}
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:
Sprite_Move(this);
Object_Dying(this->index, this->obj.id);
case OBJ_DYING: {
CALL_CANCELLABLE_EVENT(ObjectDestroyEvent, OBJECT_TYPE_SPRITE, this) {
Sprite_Move(this);
Object_Dying(this->index, this->obj.id);
}
break;
}
}
}

Expand All @@ -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);
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:
Item_Move(this);
if (this->info.action != NULL) {
this->info.action(&this->obj);
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;
}
}
}

Expand All @@ -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;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/port/hooks/Events.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#include "list/EngineEvent.h"
#include "list/ActorEvent.h"
#include "list/ItemEvent.h"
34 changes: 34 additions & 0 deletions src/port/hooks/list/ActorEvent.h
Original file line number Diff line number Diff line change
@@ -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;
);
16 changes: 14 additions & 2 deletions src/port/mods/PortEnhancements.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/port/mods/PortEnhancements.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
extern "C" {
#endif

void PortEnhancements_Register();
void PortEnhancements_Init();
void PortEnhancements_Exit();

Expand Down

0 comments on commit dbf9b03

Please sign in to comment.