May 12, 2009

G2Ext + zCWorldPerFrameCallback = *weee*


After playing a bit with Gothic's "per frame callback"-system, I implemented added a wrapper for the zCWorldPerFrame callback system into G2Ext. No more hooks (and their stupid limitations) needed to perform any actions in the main loop!
You just register your function in to the callback system and you're done! G2Ext does all the annoying stuff with zCWorldPerFrameCallback for you.^^

Lets make a short example:

// foobar() is the function which shall be registered
// and called each rendering cycle
void __stdcall foobar(void* world, void* camera)
{
MessageBox(0, L"hello world :)", 0, 0);
};

// a random init function which will be called at program start
void init(void)
{
// Register callback to function "foobar"
g_callback->registerPerFrameCallback("foobar", &foobar);
// Globally turn on rendering callbacks
g_callback->enableCallbacks();
};

// a random shutdown function which will be called when the program
// is being closed
void shutdown(void)
{
// remove "foobar" from the callback list
g_callback->unregisterPerFrameCallback("foobar");
// globally disable callbacks
g_callback->disableCallbacks();
};

By the way: callbacks can be registered at any time.

Another example for callback usage is on-screen output:

void __stdcall Callback(void* World, void* Camera)
{
// Get the zCView instance
zCView* screen = (zCView*)GetScreen();
// Create a zSTRING (actually a wrapped std::basic_string.....)
// with text
// Oh, how i hate zSTRINGS! They caused so much trouble...
zSTRING text("G2Ext Pre Alpha");
// Print everything on screen (x, y, text)
screen->Print(200, 200, text);
};