Cleanup evtmgr

This commit is contained in:
Seeky 2021-06-25 14:55:21 +01:00
parent a5bf3f4fa4
commit 98921495a7
3 changed files with 414 additions and 340 deletions

View File

@ -19,83 +19,84 @@ typedef s32 EvtScriptCode;
#define EVT_FLAG_PAUSED (1 << 1)
typedef struct _EvtEntry {
s64 lifetime;
u8 flags; // bit flags, see defines above
u8 curDataLength; // number of pieces of data (4 bytes each) belonging to the current instruction
u8 curOpcode; // see evtmgr_cmd.h for opcodes
u8 priority;
u8 type;
s8 blocked;
s8 dowhileDepth; // number of do-while loops the current instruction is nested into
s8 unknown_0xf;
EvtScriptCode * pCurInstruction;
EvtScriptCode * pCurData;
s8 labelIds[MAX_EVT_JMPTBL]; // each correspond to an address in the jump table
void * jumptable[MAX_EVT_JMPTBL]; // addresses for each label
struct _EvtEntry * parent;
struct _EvtEntry * childEntry;
struct _EvtEntry * brotherEntry;
union {
s32 tempS[3];
u32 tempU[3];
};
u8 unknown_0x80[0x94 - 0x80];
user_func * userFunc; // Function set & called by the user_func opcode
s32 lw[16];
u32 lf[3];
void * dowhileStartPtrs[8]; // pointer to do opcodes
s32 dowhileCounters[8];
u8 unknown_0x124[0x150 - 0x124];
s32 * uw;
u32 * uf;
s32 id;
float speed;
float unknown_0x160;
s32 unknown_0x164;
u32 unknown_0x168;
u8 unknown_0x16c[0x170 - 0x16c];
s32 unknown_0x170;
s32 unknown_0x174;
s32 unknown_0x178;
f32 unknown_0x17c;
f32 unknown_0x180;
f32 unknown_0x184;
s32 unknown_0x188;
u8 unknown_0x18c[0x198 - 0x18c];
EvtScriptCode * scriptStart;
char * name; // debug thing, unused?
void * pPrevInstruction;
u8 unknown_0x1a4[0x1a8 - 0x1a4];
s64 lifetime;
u8 flags; // bit flags, see defines above
u8 curDataLength; // number of pieces of data (4 bytes each) belonging to the current instruction
u8 curOpcode; // see evtmgr_cmd.h for opcodes
u8 priority;
u8 type;
s8 blocked;
s8 dowhileDepth; // number of do-while loops the current instruction is nested into
s8 switchDepth; // number of switches the current instruction is nested into
EvtScriptCode * pCurInstruction;
EvtScriptCode * pCurData;
s8 labelIds[MAX_EVT_JMPTBL]; // each correspond to an address in the jump table
void * jumptable[MAX_EVT_JMPTBL]; // addresses for each label
struct _EvtEntry * parent;
struct _EvtEntry * childEntry;
struct _EvtEntry * brotherEntry;
union {
s32 tempS[3];
u32 tempU[3];
};
u8 unknown_0x80[0x94 - 0x80];
user_func * userFunc; // Function set & called by the user_func opcode
s32 lw[16];
u32 lf[3];
void * dowhileStartPtrs[8]; // pointer to do opcodes
s32 dowhileCounters[8];
u8 unknown_0x124[0x14c - 0x124];
s32 * readAddr;
s32 * uw;
u32 * uf;
s32 id;
float speed;
float unknown_0x160;
s32 casedrvId;
void * ownerNPC;
void * ownerMOBJ;
s32 unknown_0x170;
s32 msgWindowId;
s32 unknown_0x178;
f32 unknown_0x17c;
f32 unknown_0x180;
f32 unknown_0x184;
s32 msgPri;
u8 unknown_0x18c[0x198 - 0x18c];
EvtScriptCode * scriptStart;
char * name; // debug thing, unused?
void * pPrevInstruction;
u8 unknown_0x1a4[0x1a8 - 0x1a4];
} EvtEntry;
typedef struct {
s32 entryCount;
s32 gw[32];
u32 gf[3];
EvtEntry * entries;
u8 unknown_0x94[0x98 - 0x94];
s64 time;
s32 entryCount;
s32 gw[32];
u32 gf[3];
EvtEntry * entries;
u8 unknown_0x94[0x98 - 0x94];
s64 time;
} EvtWork;
extern s32 evtMax; // 805ae8d8
/*
Returns pointer to the EvtWork struct
Returns pointer to the EvtWork struct
*/
EvtWork * evtGetWork(); // 800d87e4
/*
Allocates memories for entries and zeros global evt variables
Allocates memories for entries and zeros global evt variables
*/
void evtmgrInit(); // 800d8a88
/*
Zeros all entries
Zeros all entries
*/
void evtmgrReInit(); // 800d8b2c
/*
Starts execution of a script
Starts execution of a script
*/
EvtEntry * evtEntry(EvtScriptCode * script, u8 priority, u8 flags); // 800d8b88
EvtEntry * evtEntryType(EvtScriptCode * script, s32 param_2, s32 param_3, s32 param_4); // 800d8df4
@ -103,92 +104,92 @@ EvtEntry * evtChildEntry(EvtEntry * entry, EvtScriptCode * script, u8 flags); //
EvtEntry * evtBrotherEntry(EvtEntry * entry, EvtScriptCode * script, u8 flags); // 800d9370
/*
Restarts a entry
Restarts a entry
*/
EvtEntry * evtRestart(EvtEntry * entry); // 800d9634
/*
Sets up entry executions, called every frame
Sets up entry executions, called every frame
*/
void evtmgrMain(); // 800d9764
/*
Terminates a entry and all its children & brothers
Terminates a entry and all its children & brothers
*/
void evtDelete(EvtEntry * entry); // 800d9944
/*
Terminates a entry by id and all its children & brothers
Terminates a entry by id and all its children & brothers
*/
void evtDeleteID(s32 id); // 800d9b00
/*
Checks if a entry is running by id
Checks if a entry is running by id
*/
bool evtCheckID(s32 id); // 800d9b88
/*
Sets the execution priority of a entry
Sets the execution priority of a entry
*/
void evtSetPri(EvtEntry * entry, u8 pri); // 800d9bd4
/*
Sets the execution speed of a entry
Sets the execution speed of a entry
*/
void evtSetSpeed(EvtEntry * entry, f32 multiplier); // 800d9bdc
/*
Sets the type mask of a entry
Sets the type mask of a entry
*/
void evtSetType(EvtEntry * entry, u8 type); // 800d9bec
/*
Pauses execution a entry and all its children & brothers with types included in the mask
Pauses execution a entry and all its children & brothers with types included in the mask
*/
void evtStop(EvtEntry * entry, u8 mask); // 800d9bf4
/*
Resumes execution of a entry and all its children & brothers with types included in the mask
Resumes execution of a entry and all its children & brothers with types included in the mask
*/
void evtStart(EvtEntry * entry, u8 mask); // 800d9c98
/*
Pauses execution of a entry by id and all its children & brothers
Pauses execution of a entry by id and all its children & brothers
*/
void evtStopID(s32 id); // 800d9d3c
/*
Resumes execution of a entry by id and all its children & brothers
Resumes execution of a entry by id and all its children & brothers
*/
void evtStartID(s32 id); // 800d9dc8
/*
Pauses execution of all entries with types included in the mask
Pauses execution of all entries with types included in the mask
*/
void evtStopAll(u8 mask); // 800d9e54
/*
Resumes execution of all entries with types included in the mask
Resumes execution of all entries with types included in the mask
*/
void evtStartAll(u8 mask); // 800d9ed4
/*
Pauses execution of all entries with types included in the mask other than one specific entry
Pauses execution of all entries with types included in the mask other than one specific entry
*/
void evtStopOther(EvtEntry * entry, u8 mask); // 800d9f54
/*
Resumes execution of all entries with types included in the mask other than one specific entry
Resumes execution of all entries with types included in the mask other than one specific entry
*/
void evtStartOther(EvtEntry * entry, u8 mask); // 800d9fc8
/*
Gets an entry by its index into the array of entries
Gets an entry by its index into the array of entries
*/
EvtEntry * evtGetPtr(s32 index); // 800da03c
/*
Gets an entry by its id
Gets an entry by its id
*/
EvtEntry * evtGetPtrID(s32 id); // 800da064

View File

@ -71,126 +71,126 @@
Opcodes
*/
enum {
EVT_OPC_NEXT,
EVT_OPC_END_SCRIPT,
EVT_OPC_END_EVT,
EVT_OPC_LBL,
EVT_OPC_GOTO,
EVT_OPC_DO,
EVT_OPC_WHILE,
EVT_OPC_DO_BREAK,
EVT_OPC_DO_CONTINUE,
EVT_OPC_WAIT_FRM,
EVT_OPC_WAIT_MSEC,
EVT_OPC_HALT,
EVT_OPC_IF_STR_EQUAL,
EVT_OPC_IF_STR_NOT_EQUAL,
EVT_OPC_IF_STR_SMALL,
EVT_OPC_IF_STR_LARGE,
EVT_OPC_IF_STR_SMALL_EQUAL,
EVT_OPC_IF_STR_LARGE_EQUAL,
EVT_OPC_IFF_EQUAL,
EVT_OPC_IFF_NOT_EQUAL,
EVT_OPC_IFF_SMALL,
EVT_OPC_IFF_LARGE,
EVT_OPC_IFF_SMALL_EQUAL,
EVT_OPC_IFF_LARGE_EQUAL,
EVT_OPC_IF_EQUAL,
EVT_OPC_IF_NOT_EQUAL,
EVT_OPC_IF_SMALL,
EVT_OPC_IF_LARGE,
EVT_OPC_IF_SMALL_EQUAL,
EVT_OPC_IF_LARGE_EQUAL,
EVT_OPC_IF_FLAG,
EVT_OPC_IF_NOT_FLAG,
EVT_OPC_ELSE,
EVT_OPC_END_IF,
EVT_OPC_SWITCH,
EVT_OPC_SWITCHI,
EVT_OPC_CASE_EQUAL,
EVT_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PC_SET_TYPE,
EVT_OPC_STOP_ALL,
EVT_OPC_START_ALL,
EVT_OPC_STOP_OTHER,
EVT_OPC_START_OTHER,
EVT_OPC_STOP_ID,
EVT_OPC_START_ID,
EVT_OPC_CHK_EVT,
EVT_OPC_INLINE_EVT,
EVT_OPC_INLINE_EVT_ID,
EVT_OPC_END_INLINE,
EVT_OPC_BROTHER_EVT,
EVT_OPC_BROTHER_EVT_ID,
EVT_OPC_END_BROTHER,
EVT_OPC_DEBUG_PUT_MSG,
EVT_OPC_DEBUG_MSG_CLEAR,
EVT_OPC_DEBUG_PUT_REG,
EVT_OPC_DEBUG_NAME,
EVT_OPC_DEBUG_REM,
EVT_OPC_DEBUG_BP
};
// Script instruction functions, 800da0b0 - 800ddd5b
@ -314,74 +314,72 @@ int evt_debug_rem(EvtEntry * entry);
int evt_debug_bp(EvtEntry * entry);
/*
Executes an entry's script until it pauses or finishes
Executes an entry's script until it pauses or finishes
*/
s32 evtmgrCmd(EvtEntry * entry); // 800ddd5c
/*
Gets the value of an evt variable
Gets the value of an evt variable
*/
s32 evtGetValue(EvtEntry * entry, s32 data); // 800de594
// evtGetNumber (inlined / unused)
/*
Sets the value of an evt variable
Sets the value of an evt variable
*/
s32 evtSetValue(EvtEntry * entry, s32 variable, s32 value); // 800de9b8
/*
Gets the value of a float evt variable
Gets the value of a float evt variable
*/
f32 evtGetFloat(EvtEntry * entry, s32 data); // 800dedb8
/*
Sets the value of a float evt variable
Sets the value of a float evt variable
*/
f32 evtSetFloat(EvtEntry * entry, s32, f32); // 800df1fc
// TODO: search functions probably static?
/*
Returns a pointer to the instruction after the specified label
in an entry's script
Returns a pointer to the instruction after the specified label
in an entry's script
*/
EvtScriptCode * evtSearchLabel(EvtEntry * entry, int id); // inlined
/*
Returns a pointer to the instruction after the next else on the
current if else depth in an entry's script
Returns a pointer to the instruction after the next else on the
current if else depth in an entry's script
*/
EvtScriptCode * evtSearchElse(EvtEntry * entry); // 800df55c
/*
Returns a pointer to the instruction after the next end if on the
current if else depth in an entry's script
Returns a pointer to the instruction after the next end if on the
current if else depth in an entry's script
*/
EvtScriptCode * evtSearchEndIf(EvtEntry * entry); // 800df620
/*
Returns a pointer to the the next end switch on the current switch
depth in an entry's script
Returns a pointer to the the next end switch on the current switch
depth in an entry's script
*/
EvtScriptCode * evtSearchEndSwitch(EvtEntry * entry); // 800df6d8
/*
Returns a pointer to the next case or end switch on the current
switch depth in an entry's script
Returns a pointer to the next case or end switch on the current
switch depth in an entry's script
*/
EvtScriptCode * evtSearchCase(EvtEntry * entry); // 800df780
/*
Returns a pointer to the instruction after the next while on the
current do while depth in an entry's script
Returns a pointer to the instruction after the next while on the
current do while depth in an entry's script
*/
EvtScriptCode * evtSearchWhile(EvtEntry * entry); // 800df84c
/*
Returns a pointer to the next while instruction on the current do
while depth in an entry's script
Returns a pointer to the next while instruction on the current do
while depth in an entry's script
*/
EvtScriptCode * evtSearchJustBeforeWhile(EvtEntry * entry); // 800df8f8
#endif
#endif

View File

@ -19,11 +19,13 @@ static s32 runMainF; // 805ae8e0
static s32 evtId = 1; // 805ae018
static float evtSpd = 1.0f; // 805ae01c
EvtWork * evtGetWork() { // usually inlined in this file
EvtWork * evtGetWork() // usually inlined in this file
{
return &work;
}
static void make_pri_table() { // 800d87f0
static void make_pri_table() // 800d87f0
{
// Register usage didn't match otherwise
EvtWork * wp;
EvtEntry * entry;
@ -37,10 +39,13 @@ static void make_pri_table() { // 800d87f0
s32 idJ;
wp = evtGetWork();
entry = wp->entries;
priEntryCount = 0;
for (n = 0; n < wp->entryCount; n++, entry++) {
if (entry->flags & EVT_FLAG_IN_USE != 0) {
for (n = 0; n < wp->entryCount; n++, entry++)
{
if (entry->flags & EVT_FLAG_IN_USE != 0)
{
priTbl[priEntryCount] = n;
priIdTbl[priEntryCount] = entry->id;
priEntryCount++;
@ -49,11 +54,14 @@ static void make_pri_table() { // 800d87f0
priTblNum = priEntryCount;
// Bubble sort
for (i = 0; i < priEntryCount - 1; i++) {
for (j = i + 1; j < priEntryCount; j++) {
for (i = 0; i < priEntryCount - 1; i++)
{
for (j = i + 1; j < priEntryCount; j++)
{
slotJ = priTbl[j];
slotI = priTbl[i];
if (wp->entries[slotI].priority < wp->entries[slotJ].priority) {
if (wp->entries[slotI].priority < wp->entries[slotJ].priority)
{
idI = priIdTbl[i];
idJ = priIdTbl[j];
priTbl[i] = slotJ;
@ -66,15 +74,18 @@ static void make_pri_table() { // 800d87f0
}
// Not matching
static void make_jump_table(EvtEntry * entry) { // 800d890c
for (s32 i = 0; i < 16; i++) {
static void make_jump_table(EvtEntry * entry) // 800d890c
{
for (s32 i = 0; i < 16; i++)
{
entry->labelIds[i] = -1;
entry->jumptable[i] = 0;
}
s32 n = 0;
EvtScriptCode * pScriptHead = entry->pCurInstruction;
while (true) {
while (true)
{
s32 cmd = *pScriptHead & 0xffff;
s32 cmdn = *pScriptHead >> 16;
pScriptHead++;
@ -85,7 +96,8 @@ static void make_jump_table(EvtEntry * entry) { // 800d890c
s32 id = *pScriptHead;
pScriptHead += cmdn;
switch (cmd) {
switch (cmd)
{
case 1:
goto end;
case 3:
@ -99,7 +111,8 @@ static void make_jump_table(EvtEntry * entry) { // 800d890c
end: ; // didn't match when just using return
}
void evtmgrInit() {
void evtmgrInit()
{
work.entryCount = EVT_ENTRY_MAX;
work.entries = (EvtEntry *) __memAlloc(0, work.entryCount * sizeof(EvtEntry));
work.time = gp->time;
@ -109,29 +122,38 @@ void evtmgrInit() {
evtMax = 0;
priTblNum = 0;
runMainF = 0;
evt_msg_init();
}
void evtmgrReInit() {
void evtmgrReInit()
{
work.time = gp->time;
memset(work.entries, 0, work.entryCount * sizeof(EvtEntry));
evtMax = 0;
runMainF = 0;
evt_msg_init();
}
// Not matching, includes inline evtEntryRunCheck
EvtEntry * evtEntry(EvtScriptCode * script, u8 priority, u8 flags) {
EvtEntry * evtEntry(EvtScriptCode * script, u8 priority, u8 flags)
{
EvtEntry * entry = work.entries;
s32 i;
for (i = 0; i < work.entryCount; i++) {
if (entry->flags & EVT_FLAG_IN_USE == 0) break;
for (i = 0; i < work.entryCount; i++)
{
if (entry->flags & EVT_FLAG_IN_USE == 0)
break;
entry++;
}
if (i >= work.entryCount) {
if (i >= work.entryCount)
assert(0x108, 0, "EVTMGR:Pointer Table Overflow !![evtEntry]");
}
evtMax += 1;
memset(entry, 0, sizeof(EvtEntry));
entry->flags = (u8) (flags | EVT_FLAG_IN_USE);
entry->pCurInstruction = script;
@ -144,47 +166,54 @@ EvtEntry * evtEntry(EvtScriptCode * script, u8 priority, u8 flags) {
entry->priority = priority;
entry->id = evtId++;
entry->dowhileDepth = -1;
entry->unknown_0xf = -1;
entry->switchDepth = -1;
entry->type = 0xff;
entry->name = NULL;
entry->speed = 1.0f;
entry->unknown_0x160 = 0.0f;
entry->unknown_0x164 = -1;
entry->unknown_0x168 = 0;
entry->casedrvId = -1;
entry->ownerNPC = 0;
entry->lifetime = 0;
for (s32 j = 0; j < 16; j++) {
for (s32 j = 0; j < 16; j++)
entry->lw[i] = 0;
}
for (s32 j = 0; j < 3; j++) {
entry->lw[j] = 0;
}
for (s32 j = 0; j < 3; j++)
entry->lf[j] = 0;
make_jump_table(entry);
if ((runMainF != 0) && (entry->flags & 0x20 != 0)) {
if ((runMainF != 0) && ((entry->flags & 0x20) != 0))
{
priTbl[priTblNum] = i;
priIdTbl[priTblNum++] = entry->id;
}
if (_spmarioSystemLevel == 1) {
for (s32 i = 0; i < work.entryCount; i++) {
if (work.entries[i].flags & EVT_FLAG_IN_USE != 0) {
if (_spmarioSystemLevel == 1)
{
for (s32 i = 0; i < work.entryCount; i++)
{
if (work.entries[i].flags & EVT_FLAG_IN_USE != 0)
evtStop(&work.entries[i], 3);
}
}
}
else if (_spmarioSystemLevel > 0 && _spmarioSystemLevel < 3) {
for (s32 i = 0; i < work.entryCount; i++) {
if (work.entries[i].flags & EVT_FLAG_IN_USE != 0) {
else if ((_spmarioSystemLevel > 0) && (_spmarioSystemLevel < 3))
{
for (s32 i = 0; i < work.entryCount; i++)
{
if (work.entries[i].flags & EVT_FLAG_IN_USE != 0)
evtStop(&work.entries[i], 0xff);
}
}
}
if (evtId == 0) {
if (evtId == 0)
evtId = 1;
}
return entry;
}
// Unfinished, just for string pool
EvtEntry * evtEntryType(EvtScriptCode * script, s32 param_2, s32 param_3, s32 param_4) {
EvtEntry * evtEntryType(EvtScriptCode * script, s32 param_2, s32 param_3, s32 param_4)
{
(void) script;
(void) param_2;
(void) param_3;
@ -196,7 +225,8 @@ EvtEntry * evtEntryType(EvtScriptCode * script, s32 param_2, s32 param_3, s32 pa
}
// Unfinished, just for string pool
EvtEntry * evtChildEntry(EvtEntry * entry, EvtScriptCode * script, u8 flags) {
EvtEntry * evtChildEntry(EvtEntry * entry, EvtScriptCode * script, u8 flags)
{
(void) entry;
(void) script;
(void) flags;
@ -207,7 +237,8 @@ EvtEntry * evtChildEntry(EvtEntry * entry, EvtScriptCode * script, u8 flags) {
}
// Unfinished, just for string pool
EvtEntry * evtBrotherEntry(EvtEntry * entry, EvtScriptCode * script, u8 flags) {
EvtEntry * evtBrotherEntry(EvtEntry * entry, EvtScriptCode * script, u8 flags)
{
(void) entry;
(void) script;
(void) flags;
@ -220,227 +251,271 @@ EvtEntry * evtBrotherEntry(EvtEntry * entry, EvtScriptCode * script, u8 flags) {
// EvtEntry * evtRestart(EvtEntry * entry)
/* Unfinished
void evtmgrMain() {
void evtmgrMain()
{
EvtWork * wp = evtGetWork();
runMainF = 1;
s64 timeDif = gp->time - wp->time;
if (timeDif < 0) {
if (timeDif < 0)
{
timeDif = 0;
}
s64 ms = OSTicksToMilliseconds(gp->time);
if (ms > 500) {
if (ms > 500)
{
// this line is iffy
timeDif = (1000 / gp->unknown_0x4) * (OSClockSpeed / 1000);
}
wp->time = gp->time;
make_pri_table();
for (s32 i = 0; i < priTblNum; i++) {
for (s32 i = 0; i < priTblNum; i++)
{
EvtEntry * entry = &wp->entries[priTbl[i]];
if (entry->flags & EVT_FLAG_IN_USE && entry->id == priIdTbl[i] && entry->flags & 0x92) {
if (entry->flags & 4) {
if (entry->flags & EVT_FLAG_IN_USE && entry->id == priIdTbl[i] && entry->flags & 0x92)
{
if (entry->flags & 4)
entry->lifetime += ms;
}
entry->unknown_0x160 += 1.0f;
s32 shouldBreak = 0;
while (entry->unknown_0x160 >= 1.0f) {
while (entry->unknown_0x160 >= 1.0f)
{
entry->unknown_0x160 -= 1.0f;
s32 ret = evtmgrCmd(entry);
if (ret == 1) {
if (ret == 1)
{
shouldBreak = 1;
break;
}
if (ret == -1) break;
if (ret == -1)
break;
}
if (shouldBreak) break;
if (shouldBreak)
break;
}
}
runMainF = 0;
}
*/
void evtDelete(EvtEntry * entry) {
void evtDelete(EvtEntry * entry)
{
EvtWork * wp = evtGetWork();
if (entry->flags & EVT_FLAG_IN_USE != 0) {
if (entry->childEntry != NULL) {
if (entry->flags & EVT_FLAG_IN_USE != 0)
{
if (entry->childEntry != NULL)
evtDelete(entry->childEntry);
}
EvtEntry * curEntry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, curEntry++) {
if (curEntry->flags & 1 != 0 && curEntry->brotherEntry == entry) {
for (s32 i = 0; i < wp->entryCount; i++, curEntry++)
{
if (((curEntry->flags & 1) != 0) && (curEntry->brotherEntry == entry))
evtDelete(curEntry);
}
}
EvtEntry * parent = entry->parent;
if (parent != NULL) {
if (parent != NULL)
{
parent->flags &= ~0x10;
parent->childEntry = NULL;
for (s32 i = 0; i < 16; i++) {
for (s32 i = 0; i < 16; i++)
parent->lw[i] = entry->lw[i];
}
for (s32 i = 0; i < 3; i++) {
for (s32 i = 0; i < 3; i++)
parent->lf[i] = entry->lf[i];
}
parent->unknown_0x174 = entry->unknown_0x174; // might be some arrays w/ unrolling here
parent->msgWindowId = entry->msgWindowId;
parent->unknown_0x170 = entry->unknown_0x170;
parent->unknown_0x178 = entry->unknown_0x178;
parent->unknown_0x178 = entry->unknown_0x178; // might be some arrays w/ unrolling here
parent->unknown_0x17c = entry->unknown_0x17c;
parent->unknown_0x180 = entry->unknown_0x180;
parent->unknown_0x184 = entry->unknown_0x184;
parent->unknown_0x188 = entry->unknown_0x188;
parent->msgPri = entry->msgPri;
}
entry->flags &= ~EVT_FLAG_IN_USE;
memset(entry, 0, sizeof(EvtEntry));
evtMax -= 1;
}
}
void evtDeleteID(s32 id) {
void evtDeleteID(s32 id)
{
EvtWork * wp = evtGetWork();
EvtEntry * entry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, entry++) {
if (entry->flags & EVT_FLAG_IN_USE != 0 && entry->id == id) {
for (s32 i = 0; i < wp->entryCount; i++, entry++)
{
if (((entry->flags & EVT_FLAG_IN_USE) != 0) && (entry->id == id))
evtDelete(entry);
}
}
}
bool evtCheckID(s32 id) {
bool evtCheckID(s32 id)
{
EvtWork * wp = evtGetWork();
EvtEntry * entry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, entry++) {
if (entry->flags & EVT_FLAG_IN_USE != 0 && entry->id == id) {
for (s32 i = 0; i < wp->entryCount; i++, entry++)
{
if (((entry->flags & EVT_FLAG_IN_USE) != 0) && (entry->id == id))
return true;
}
}
return false;
}
void evtSetPri(EvtEntry * entry, u8 priority) {
void evtSetPri(EvtEntry * entry, u8 priority)
{
entry->priority = priority;
}
void evtSetSpeed(EvtEntry * entry, f32 multiplier) {
void evtSetSpeed(EvtEntry * entry, f32 multiplier)
{
entry->speed = multiplier * evtSpd;
}
void evtSetType(EvtEntry * entry, u8 type) {
void evtSetType(EvtEntry * entry, u8 type)
{
entry->type = type;
}
#pragma push
#pragma inline_max_auto_size(5)
void evtStop(EvtEntry * entry, u8 mask) {
void evtStop(EvtEntry * entry, u8 mask)
{
EvtWork * wp = evtGetWork();
if (entry->childEntry) {
if (entry->childEntry)
evtStop(entry->childEntry, mask);
}
EvtEntry * curEntry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, curEntry++) {
if (curEntry->flags & EVT_FLAG_IN_USE != 0 && curEntry->brotherEntry == entry) {
for (s32 i = 0; i < wp->entryCount; i++, curEntry++)
{
if (((curEntry->flags & EVT_FLAG_IN_USE) != 0) && (curEntry->brotherEntry == entry))
evtStop(curEntry, mask);
}
}
if (entry->type & mask) {
if (entry->type & mask)
entry->flags |= EVT_FLAG_PAUSED;
}
}
void evtStart(EvtEntry * entry, u8 mask) {
void evtStart(EvtEntry * entry, u8 mask)
{
EvtWork * wp = evtGetWork();
if (entry->childEntry) {
if (entry->childEntry)
evtStart(entry->childEntry, mask);
}
EvtEntry * curEntry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, curEntry++) {
if (curEntry->flags & EVT_FLAG_IN_USE != 0 && curEntry->brotherEntry == entry) {
for (s32 i = 0; i < wp->entryCount; i++, curEntry++)
{
if (((curEntry->flags & EVT_FLAG_IN_USE) != 0) && (curEntry->brotherEntry == entry))
evtStart(curEntry, mask);
}
}
if (entry->type & mask) {
if (entry->type & mask)
entry->flags &= ~EVT_FLAG_PAUSED;
}
}
#pragma pop
void evtStopID(s32 id) {
void evtStopID(s32 id)
{
EvtWork * wp = evtGetWork();
EvtEntry * entry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, entry++) {
if (entry->flags & EVT_FLAG_IN_USE != 0 && entry->id == id) {
for (s32 i = 0; i < wp->entryCount; i++, entry++)
{
if (((entry->flags & EVT_FLAG_IN_USE) != 0) && (entry->id == id))
evtStop(entry, 0xff);
}
}
}
void evtStartID(s32 id) {
void evtStartID(s32 id)
{
EvtWork * wp = evtGetWork();
EvtEntry * entry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, entry++) {
if (entry->flags & EVT_FLAG_IN_USE != 0 && entry->id == id) {
for (s32 i = 0; i < wp->entryCount; i++, entry++)
{
if (((entry->flags & EVT_FLAG_IN_USE) != 0) && (entry->id == id))
evtStart(entry, 0xff);
}
}
}
void evtStopAll(u8 mask) {
void evtStopAll(u8 mask)
{
EvtWork * wp = evtGetWork();
EvtEntry * entry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, entry++) {
if (entry->flags & EVT_FLAG_IN_USE != 0) {
for (s32 i = 0; i < wp->entryCount; i++, entry++)
{
if ((entry->flags & EVT_FLAG_IN_USE) != 0)
evtStop(entry, mask);
}
}
}
void evtStartAll(u8 mask) {
void evtStartAll(u8 mask)
{
EvtWork * wp = evtGetWork();
EvtEntry * entry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, entry++) {
if (entry->flags & EVT_FLAG_IN_USE != 0) {
for (s32 i = 0; i < wp->entryCount; i++, entry++)
{
if ((entry->flags & EVT_FLAG_IN_USE) != 0)
evtStart(entry, mask);
}
}
}
void evtStopOther(EvtEntry * entry, u8 mask) {
void evtStopOther(EvtEntry * entry, u8 mask)
{
EvtWork * wp = evtGetWork();
EvtEntry * curEntry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, curEntry++) {
if (curEntry->flags & EVT_FLAG_IN_USE != 0 && curEntry != entry) {
for (s32 i = 0; i < wp->entryCount; i++, curEntry++)
{
if (((curEntry->flags & EVT_FLAG_IN_USE) != 0) && (curEntry != entry))
evtStop(curEntry, mask);
}
}
}
void evtStartOther(EvtEntry * entry, u8 mask) {
void evtStartOther(EvtEntry * entry, u8 mask)
{
EvtWork * wp = evtGetWork();
EvtEntry * curEntry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, curEntry++) {
if (curEntry->flags & EVT_FLAG_IN_USE != 0 && curEntry != entry) {
for (s32 i = 0; i < wp->entryCount; i++, curEntry++)
{
if (((curEntry->flags & EVT_FLAG_IN_USE) != 0) && (curEntry != entry))
evtStart(curEntry, mask);
}
}
}
EvtEntry * evtGetPtr(s32 index) {
EvtEntry * evtGetPtr(s32 index)
{
EvtWork * wp = evtGetWork();
EvtEntry * entry = &wp->entries[index];
if (entry->flags & EVT_FLAG_IN_USE != 0) {
if ((entry->flags & EVT_FLAG_IN_USE) != 0)
{
return entry;
}
return 0;
}
EvtEntry * evtGetPtrID(s32 id) {
EvtEntry * evtGetPtrID(s32 id)
{
EvtWork * wp = evtGetWork();
EvtEntry * curEntry = wp->entries;
for (s32 i = 0; i < wp->entryCount; i++, curEntry++) {
if (curEntry->flags & EVT_FLAG_IN_USE != 0 && curEntry->id == id) {
for (s32 i = 0; i < wp->entryCount; i++, curEntry++)
{
if (curEntry->flags & EVT_FLAG_IN_USE != 0 && curEntry->id == id)
return curEntry;
}
}
return 0;
}