From ffa9dabc6b535da90b3cd8a7849079c546cacfbd Mon Sep 17 00:00:00 2001 From: Colin Noga Date: Wed, 20 Jul 2011 13:20:11 -0500 Subject: Fixed up sprite spawner (probably) --- src/spritespawner.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/spritespawner.cpp b/src/spritespawner.cpp index 911ae8a..1d6a071 100755 --- a/src/spritespawner.cpp +++ b/src/spritespawner.cpp @@ -16,7 +16,7 @@ struct SpriteSpawner { u16 type; // 0x3D4 u32 inheritSet; // 0x3D6 u8 lastEvState; // 0x3DA - dStageActor_c *createdActor; + u32 createdActor; }; struct EventTable_t { @@ -33,6 +33,7 @@ struct VEC { extern EventTable_t *EventTable; extern "C" dStageActor_c *CreateActor(u16 classID, int settings, VEC pos, char rot, char layer); +extern "C" dStageActor_c *Actor_SearchByID(u32 actorID); void SpriteSpawner_Update(SpriteSpawner *self); @@ -49,8 +50,8 @@ bool SpriteSpawner_Create(SpriteSpawner *self) { OSReport("Event to activate: %d", eventNum); self->eventFlag = (u64)1 << (eventNum - 1); - - self->type = (self->settings >> 16) & 0xFFF; + self->createdActor = 0; + self->type = (self->settings >> 16) & 0xFFF; 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); @@ -81,16 +82,22 @@ void SpriteSpawner_Update(SpriteSpawner *self) { OSReport("Spawning Sprite: %d at %f,%f,%f\n", self->type, pos.x, pos.y, pos.z); - self->createdActor = CreateActor(self->type, self->inheritSet, pos, 0, 0); + dStageActor_c *spawned = CreateActor(self->type, self->inheritSet, pos, 0, 0); + self->createdActor = spawned->id; } // EventTable->events = EventTable->events & ~self->eventFlag; } else { - self->x = self->createdActor->pos.x; - self->y = self->createdActor->pos.y; - self->z = self->createdActor->pos.z; - self->createdActor->Delete(); - self->createdActor = 0; + 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; + spawned->Delete(); + } + self->createdActor = 0; + } } } -- cgit v1.2.3