本篇是创建游戏内核(2)【C风格版】的续篇,关于该内核的细节说明请参考创建游戏内核(3)。
代码与创建游戏内核(2)【C风格版】相同,这里仅给出测试代码:
/*************************************************************************
PURPOSE:
Test for manager stack.
*************************************************************************/
#include "core_common.h"
#include "core_framework.h"
#include "core_manager.h"
MANAGER_PTR g_manager;
void func2(void_ptr data, long purpose)
{
if(purpose == INIT_PURPOSE)
MessageBox(NULL, "Process2 - init", "Message", MB_OK);
else if(purpose == FRAME_PURPOSE)
MessageBox(NULL, "Process2 - frame", "Message", MB_OK);
else if(purpose == SHUTDOWN_PURPOSE)
MessageBox(NULL, "Process2 - shutdown", "Message", MB_OK);
}
void func1(void_ptr data, long purpose)
{
if(purpose == INIT_PURPOSE)
MessageBox(NULL, "Process1 - init", "Message", MB_OK);
else if(purpose == FRAME_PURPOSE)
MessageBox(NULL, "Process1 - frame", "Message", MB_OK);
else if(purpose == SHUTDOWN_PURPOSE)
MessageBox(NULL, "Process1 - shutdown", "Message", MB_OK);
}
BOOL game_init()
{
push_manager(g_manager, func1, NULL);
push_manager(g_manager, func2, NULL);
process_all_manager(g_manager, NULL);
return TRUE;
}
BOOL game_frame()
{
return TRUE;
}
BOOL game_shutdown()
{
destroy_manager(g_manager, NULL);
return TRUE;
}
int WINAPI WinMain(HINSTANCE inst, HINSTANCE pre_inst, LPSTR cmd_line, int cmd_show)
{
if(! build_window(inst, "MainClass", "MainWindow", WS_OVERLAPPEDWINDOW, 0, 0, 800, 600))
return FALSE;
run_game(game_init, game_frame, game_shutdown);
return 0;
}