So sometimes scripts, particular AI scripts, can become very large and slow. and even then they're not very powerful, and it becomes quite tedious to add a zillion script events. for these reasons (and possibly more) I decided to try to take some AI and throw it all into the SDK with no script object at all. This wasn't such a hard thing to do, but one real issue I came across was the waitFrame() and sys.wait() script events. they halt the execution of the script and let the game continue what it's doing, and resumes at a later time. the SDK can't just stop execution, or "resume" into a function somewhere after returtning. and we can't just call gameLocal.RunFrame() because that'll cause all kinds of problems and concerns (I won't go into detail with my endeavors there)
So here's my solution - a working waitFrame() macro which utilizes computed goto()s. all you have to do is call evalWaits() before anything else in a function, make all the variables you're going to use after the waitFrame() static so they retain their values (which is a bit ugly, I admit), and add two small private member variables.
Here is a proof of concept:
Code:
// Zeroth
#include <stdio.h>
#include <cstring>
# define waitFrame( uniqueLabelName ) \
if ( labelJump == false ) { \
printf("waitFrame: Waiting A Frame\n"); \
labelName = &&uniqueLabelName; \
labelJump = true; \
return; \
} else { \
printf("waitFrame: Resuming Function"); \
uniqueLabelName: \
labelName = NULL; \
labelJump = false; \
}
# define evalWaits() if (labelJump) { goto *labelName; }
void * labelName;
bool labelJump;
void func( void ) {
evalWaits();
printf("Entity X'x Member Function: starting function\n");
waitFrame( someUniqueIdentifier );
printf("Entity X's Member Function: finishing function\n");
}
int main( void ) {
labelName=NULL;
printf("main: RunningFrame.\n");
func(); // some entite thinking
printf("main: RunningFrame.\n");
func(); // some entite thinking again
printf("main: RunningFrame.\n");
}