本篇是创建游戏内核(2)【OO改良版】的续篇,关于该内核的细节说明请参阅创建游戏内核(3)。
接口与实现与创建游戏内核(2)【OO改良版】相同,这里只给出测试代码:
/*****************************************************************************
PURPOSE:
    Test for class manager stack.
*****************************************************************************/
#include "core_common.h"
#include "core_framework.h"
#include "core_manager.h"
class APP : public FRAMEWORK
{
public:
    static void func2(void* data, long purpose)
    {       
        if(purpose == INIT_PURPOSE)
            MessageBox(g_hwnd, "Process2 - init", "Message", MB_OK);
        else if(purpose == FRAME_PURPOSE)
            MessageBox(g_hwnd, "Process2 - frame", "Message", MB_OK);
        else if(purpose == SHUTDOWN_PURPOSE)
            MessageBox(NULL, "Process2 - shutdown", "Message", MB_OK); 
    }
    static void func1(void* data, long purpose)
    {
        if(purpose == INIT_PURPOSE)
            MessageBox(g_hwnd, "Process1 - init", "Message", MB_OK);
        else if(purpose == FRAME_PURPOSE)
            MessageBox(g_hwnd, "Process1 - frame", "Message", MB_OK);
        else if(purpose == SHUTDOWN_PURPOSE)
            MessageBox(NULL, "Process1 - shutdown", "Message", MB_OK); 
    }    
    BOOL init()
    {
        m_manager.push(func1, NULL);
        m_manager.push(func2, NULL);
        m_manager.process_all(NULL);
        return TRUE;
    }
    
private:
    MANAGER m_manager;
};
//--------------------------------------------------------------------------------
// Main function, routine entry.
//--------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE inst, HINSTANCE pre_inst, LPSTR cmd_line, int cmd_show)
{
    APP app;
    if(! build_window(inst, "MainClass", "MainWindow", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480))
        return -1;
    
    app.run();
    return 0;
}