summaryrefslogtreecommitdiff
path: root/src/eventlooper.cpp
diff options
context:
space:
mode:
authorColin Noga <Tempus@Spectrum-Song.local>2011-06-10 15:50:13 -0500
committerColin Noga <Tempus@Spectrum-Song.local>2011-06-10 15:50:13 -0500
commit9df64c5f97992978fb7256e988233f23d039cc1d (patch)
treea9e86119500e792aacd19a8436d5adf07afcb8cd /src/eventlooper.cpp
parent209baabbc250ffecbb2d886e6fed9488c706d367 (diff)
downloadkamek-9df64c5f97992978fb7256e988233f23d039cc1d.tar.gz
kamek-9df64c5f97992978fb7256e988233f23d039cc1d.zip
Added stupid event looper that is not working to sprite 79
Diffstat (limited to '')
-rw-r--r--src/eventlooper.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/eventlooper.cpp b/src/eventlooper.cpp
new file mode 100644
index 0000000..3c1fe7d
--- /dev/null
+++ b/src/eventlooper.cpp
@@ -0,0 +1,104 @@
+#include <common.h>
+#include <game.h>
+
+struct EventLooper {
+ 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
+ u8 delay; // 0x3D4
+ u8 delayCount; // 0x3D7
+};
+
+struct EventTable_t {
+ u64 events;
+ // ...
+};
+
+extern EventTable_t *EventTable;
+
+void EventLooper_Update(EventLooper *self);
+
+
+
+bool EventLooper_Create(EventLooper *self) {
+ OSReport("Sprite Created");
+ char eventStart = (self->settings >> 24) & 0xFF;
+ char eventEnd = (self->settings >> 16) & 0xFF;
+
+ OSReport("Mark 1");
+
+ // Putting all the events into the flag
+ int i;
+ int q;
+ for(i=eventStart;i<eventEnd;i++)
+ q = q & ((u64)1 << (i - 1));
+
+ OSReport("Mark 2");
+
+ self->eventFlag = q;
+
+ self->delay = ((self->settings) & FF) * 10;
+ self->delayCount = 0;
+
+
+ OSReport("About to first update");
+
+ EventLooper_Update(self);
+
+ return true;
+}
+
+bool EventLooper_Execute(EventLooper *self) {
+ OSReport("Sprite Update");
+ EventLooper_Update(self);
+ return true;
+}
+
+
+void EventLooper_Update(EventLooper *self) {
+
+
+ // Waiting for the right moment
+ if (self->delayCount < self->delay)
+ {
+ OSReport("Delaying: %d\n", self->delayCount);
+
+ self->delayCount = self->delayCount + 1;
+ return;
+ }
+
+ OSReport("Event flag Start: %08x %08x\n", self->eventFlag >> 32, self->eventFlag & 0xFFFFFFFF);
+ OSReport("Event TableStart: %08x %08x\n", EventTable->events >> 32, EventTable->events & 0xFFFFFFFF);
+
+ // Find which event(s) is/are on
+ u64 evState = EventTable->events & self->eventFlag;
+
+ // Turn off the old events
+ EventTable->events & (~self->eventFlag);
+
+ // Shift them right if they can, if not, reset!
+ if (evState < eventFlag)
+ {
+ evState << 1;
+ EventTable->events = EventTable->events | evState;
+ }
+
+ else
+ {
+ char eventStart = (self->settings >> 24) & 0xFF;
+ evState = (u64)1 << (eventStart - 1);
+ EventTable->events = EventTable->events | evState;
+ }
+
+ OSReport("Event flag End: %08x %08x\n", self->eventFlag >> 32, self->eventFlag & 0xFFFFFFFF);
+ OSReport("Event Table End: %08x %08x\n", EventTable->events >> 32, EventTable->events & 0xFFFFFFFF);
+
+}