NXEngine v1.0.0.6
[NXEngine.git] / common / InitList.cpp
blob8744ce67b6ee20a731b20ee621ecfb8f800e3a48
2 // this is a combination of some C++ and preprocessor magic which allows a
3 // group of initilization functions to be declared across many different
4 // source files and then at the appropriate time all can be called at once.
5 // The "trick" is that it automatically works for all modules linked to the
6 // program so you don't have to keep a handmade list anywhere of the names
7 // of the initilization functions. This is used by the AI functions to initilize
8 // all the function pointers etc for the various creatures.
9 #include "InitList.h"
10 #include "InitList.fdh"
12 void InitList::AddFunction(void (*func)(void))
14 AddFunction((void *)func);
17 void InitList::AddFunction(bool (*func)(void))
19 AddFunction((void *)func);
22 void InitList::AddFunction(void *func)
24 //stat("AddFunction (void)%08x [%d]", func, fCount);
25 if (fCount >= MAX_INIT_RECORDS)
26 return;
28 fFunctions[fCount++] = (void *)func;
32 void c------------------------------() {}
35 bool InitList::CallFunctions()
37 int i;
39 if (fCount >= MAX_INIT_RECORDS)
41 stat("InitList::CallFunctions(%08x): too many initializers", this);
42 return 1;
45 stat("InitList::CallFunctions(%08x): executing %d functions...", this, fCount);
47 for(i=0;i<fCount;i++)
49 void (*func)(void) = (void (*)())fFunctions[i];
50 (*func)();
53 return 0;