游戏.状态管理器
来源:互联网 发布:混凝土计算软件 编辑:程序博客网 时间:2024/05/21 08:38
/**************************************************
WinMain.cpp
游戏状态管理器
Cblog:
http://blog.csdn.net/chinayaosir
**************************************************/
// Include files
#include <windows.h>
#include <stdio.h>
class cStateManager
{
// A structure that stores a function pointer and linked list
typedef struct sState {
void (*Function)();
sState *Next;
} sState;
protected:
sState *m_StateParent; // The top state in the stack
// (the head of the stack)
public:
cStateManager() { m_StateParent = NULL; }
~cStateManager()
{
sState *StatePtr;
// Remove all states from the stack
while((StatePtr = m_StateParent) != NULL) {
m_StateParent = StatePtr->Next;
delete StatePtr;
}
}
// Push a function on to the stack
void Push(void (*Function)())
{
// Don't push a NULL value
if(Function != NULL) {
// Allocate a new state and push it on stack
sState *StatePtr = new sState;
StatePtr->Next = m_StateParent;
m_StateParent = StatePtr;
StatePtr->Function = Function;
}
}
BOOL Pop()
{
sState *StatePtr = m_StateParent;
// Remove the head of stack (if any)
if(StatePtr != NULL) {
m_StateParent = StatePtr->Next;
delete StatePtr;
}
// return TRUE if more states exist, FALSE otherwise
if(m_StateParent == NULL)
return FALSE;
return TRUE;
}
BOOL Process()
{
// return an error if no more states
if(m_StateParent == NULL)
return FALSE;
// Process the top-most state (if any)
m_StateParent->Function();
return TRUE;
}
};
cStateManager g_StateManager;
// Function prototypes
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, /
LPSTR szCmdLine, int nCmdShow);
// Macro to ease the use of MessageBox function
#define MB(s) MessageBox(NULL, s, s, MB_OK);
// State function prototypes - must follow this prototype!
void Func1() { MB("func1"); g_StateManager.Pop(); }
void Func2() { MB("func2"); g_StateManager.Pop(); }
void Func3() { MB("func3"); g_StateManager.Pop(); }
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, /
LPSTR szCmdLine, int nCmdShow)
{
g_StateManager.Push(Func1);
g_StateManager.Push(Func2);
g_StateManager.Push(Func3);
while(g_StateManager.Process() == TRUE);
return 0;
}
- 游戏.状态管理器
- 游戏管理器
- 游戏程序流、状态处理机、进程管理器、数据包系统的实现
- 游戏.消息管理器
- 游戏管理器(1)
- 游戏管理器(2)
- 游戏中时间管理器
- 游戏状态
- 游戏及学习控制管理器
- 巧用Windows 7游戏管理器
- 巧用Windows 7游戏管理器
- 游戏对象数据存储管理器
- ODBC驱动程序管理器无效的游标状态
- Redux 入门教程,应用的状态管理器
- 页面状态管理器,让布局飞起来
- RTX2009管理器服务运行状态空白
- 初始化游戏状态数据
- 状态模式--游戏开发
- Delphi COM接口編程(ActiveX Library)(二)
- sql中的order by
- 联想ThinkPad SL、R、T三系列的区别希望能帮助大家
- About autoDiscover job hunted
- SQL script to undeploy rules/vocabularies
- 游戏.状态管理器
- SQL script to undeploy rules/vocabularies
- SQL script to undeploy rules/vocabularies
- WinCE下调用本地的.exe程序
- 9款网页绘图javascript框架
- 一个好用的日期时间类(c++)
- 表及字段描述信息处理示例
- oracle9i 和10g安装在同一系统下的TNS: 协议适配器错误的解决方法
- C++信号槽使用方法