summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-11-09 23:59:31 +0100
committerTreeki <treeki@gmail.com>2012-11-09 23:59:31 +0100
commit22915e16efa62f3169227f6121326cb5af5315ba (patch)
treee26ce2cfbfd06c58fdca5e5d2cbcec3a9f2ccae9
parenta7ed95b8c0e30aca3b6e713792449a77d4150501 (diff)
downloadkamek-22915e16efa62f3169227f6121326cb5af5315ba.tar.gz
kamek-22915e16efa62f3169227f6121326cb5af5315ba.zip
sprite spawner rewritten
Diffstat (limited to '')
-rw-r--r--spritespawner.yaml13
-rwxr-xr-xsrc/spritespawner.cpp145
2 files changed, 60 insertions, 98 deletions
diff --git a/spritespawner.yaml b/spritespawner.yaml
index 8c630eb..ce274e1 100644
--- a/spritespawner.yaml
+++ b/spritespawner.yaml
@@ -3,13 +3,8 @@
source_files: [../src/spritespawner.cpp]
hooks:
- - name: SpriteSpawner_Create
+ - name: BuildSpriteSpawner
type: add_func_pointer
- src_addr_pal: 0x80ADEA18
- target_func: 'SpriteSpawner_Create(SpriteSpawner *)'
-
- - name: SpriteSpawner_Execute
- type: add_func_pointer
- src_addr_pal: 0x80ADEA30
- target_func: 'SpriteSpawner_Execute(SpriteSpawner *)'
-
+ src_addr_pal: 0x80ADEA00
+ target_func: 'dSpriteSpawner_c::build(void)'
+
diff --git a/src/spritespawner.cpp b/src/spritespawner.cpp
index 47dbf13..c9bc5ae 100755
--- a/src/spritespawner.cpp
+++ b/src/spritespawner.cpp
@@ -1,113 +1,80 @@
-#include <common.h>
#include <game.h>
-struct SpriteSpawner {
- u32 id; // 0x00
- u32 settings; // 0x04
- u16 name; // 0x08
- u8 _0A[6]; // 0x0A
- u8 _10[0x9C]; // 0x10
- float x; // 0xAC
- float y; // 0xB0
- float z; // 0xB4
- u8 _B8[0x318]; // 0xB8
- // Any variables you add to the class go here; starting at offset 0x3D0
- u64 eventFlag; // 0x3D0
- u16 type; // 0x3D4
- u32 inheritSet; // 0x3D6
- u8 lastEvState; // 0x3DA
- u32 createdActor;
- u8 respawn;
-};
-
+class dSpriteSpawner_c : public dStageActor_c {
+ public:
+ static dSpriteSpawner_c *build();
+ u64 classicEventOverride;
+ Actors profileID;
+ bool respawn;
+ u32 childSettings;
+ u32 childID;
-struct VEC {
- float x;
- float y;
- float z;
+ int onCreate();
+ int onExecute();
};
+/*****************************************************************************/
+// Glue Code
+dSpriteSpawner_c *dSpriteSpawner_c::build() {
+ void *buffer = AllocFromGameHeap1(sizeof(dSpriteSpawner_c));
+ dSpriteSpawner_c *c = new(buffer) dSpriteSpawner_c;
+ return c;
+}
-void SpriteSpawner_Update(SpriteSpawner *self);
-
-#define ACTIVATE 1
-#define DEACTIVATE 0
-
-
-
+int dSpriteSpawner_c::onCreate() {
+ char classicEventNum = (settings >> 28) & 0xF;
+ classicEventOverride = (classicEventNum == 0) ? 0 : ((u64)1 << (classicEventNum - 1));
-bool SpriteSpawner_Create(SpriteSpawner *self) {
+ profileID = (Actors)((settings >> 16) & 0x7FF);
+ respawn = (settings >> 27) & 1;
- char eventNum = (self->settings >> 28) & 0xF;
+ u16 tempSet = settings & 0xFFFF;
+ childSettings =
+ (tempSet & 3) | ((tempSet & 0xC) << 2) |
+ ((tempSet & 0x30) << 4) | ((tempSet & 0xC0) << 6) |
+ ((tempSet & 0x300) << 8) | ((tempSet & 0xC00) << 10) |
+ ((tempSet & 0x3000) << 12) | ((tempSet & 0xC000) << 14);
- self->eventFlag = (u64)1 << (eventNum - 1);
- self->createdActor = 0;
- self->type = (self->settings >> 16) & 0x7FF;
- self->respawn = (self->settings >> 27) & 0x1;
-
- short tempSet = self->settings & 0xFFFF;
- self->inheritSet = (tempSet & 3) | ((tempSet & 0xC) << 2) | ((tempSet & 0x30) << 4) | ((tempSet & 0xC0) << 6) | ((tempSet & 0x300) << 8) | ((tempSet & 0xC00) << 10) | ((tempSet & 0x3000) << 12) | ((tempSet & 0xC000) << 14);
-
- SpriteSpawner_Update(self);
-
return true;
}
-bool SpriteSpawner_Execute(SpriteSpawner *self) {
- SpriteSpawner_Update(self);
- return true;
-}
+int dSpriteSpawner_c::onExecute() {
+ u64 effectiveFlag = classicEventOverride | spriteFlagMask;
-void SpriteSpawner_Update(SpriteSpawner *self) {
-
- // If the event is active...
- if (dFlagMgr_c::instance->flags & self->eventFlag) {
-
- // And if the spawner hasn't spawned anything...
- if (self->createdActor == 0)
- {
- Vec pos;
- pos.x = self->x;
- pos.y = self->y;
- pos.z = self->z;
-
-
- dStageActor_c *spawned = CreateActor(self->type, self->inheritSet, pos, 0, 0);
- self->createdActor = spawned->id;
- }
+ if (dFlagMgr_c::instance->flags & effectiveFlag) {
+ if (!childID) {
+ dStageActor_c *newAc = dStageActor_c::create(profileID, childSettings, &pos, 0, 0);
+ childID = newAc->id;
+ }
+ } else {
+ if (respawn)
+ return true;
+
+ if (childID) {
+ dStageActor_c *ac = (dStageActor_c*)fBase_c::search(childID);
+ if (ac) {
+ pos = ac->pos;
+ ac->Delete(1);
+ }
+ childID = 0;
+ }
}
- else {
- if (self->respawn) { return; }
- if (self->createdActor != 0) {
- dStageActor_c *spawned = Actor_SearchByID(self->createdActor);
- if (spawned != 0) {
- self->x = spawned->pos.x;
- self->y = spawned->pos.y;
- self->z = spawned->pos.z;
+ if (respawn) {
+ if (childID) {
+ dStageActor_c *ac = (dStageActor_c*)fBase_c::search(childID);
- spawned->Delete(1);
+ if (!ac) {
+ dStageActor_c *newAc = dStageActor_c::create(profileID, childSettings, &pos, 0, 0);
+ childID = newAc->id;
}
- self->createdActor = 0;
}
}
- if (self->respawn) {
- if (self->createdActor != 0) {
- dStageActor_c *spawned = Actor_SearchByID(self->createdActor);
- if (spawned == 0) {
- Vec pos;
- pos.x = self->x;
- pos.y = self->y;
- pos.z = self->z;
-
-
- dStageActor_c *spawned = CreateActor(self->type, self->inheritSet, pos, 0, 0);
- self->createdActor = spawned->id;
- }
- }
- }
+ return true;
+
}
+