📄 asl_winapp.h
字号:
//-----------------------------------------------------------------------------
//
// ____ Azure Star Game Engine 蓝星游戏引擎 ____
//
// Copyright (c) 2006, 蓝星工作室
// All rights reserved.
//
// 文件名称: asl_winapp.h
// 摘 要: 应用程序框架类定义
//
// 当前版本: 1.0
// 作 者: 汤 祺
// 创建日期: 2006-7-23
//
//-----------------------------------------------------------------------------
#ifndef ASL_WINAPP_INCLUDE
#define ASL_WINAPP_INCLUDE
#pragma once
#include "asl_utils.h"
#include "asl_timer.h"
#include "asl_screen.h"
#include "asl_input.h"
#include "asl_audio.h"
#include "asl_gui.h"
//-----------------------------------------------------------------------------
namespace ASL
{
//-----------------------------------------------------------------------------
// 类名: ASLWinApp
// 功能: 应用程序框架类
// 本类提供了基本的应用程序框架, 封装了窗口创建, 程序运行, 消息处理等
// 函数开发者只需自行定义Init()函数和OnIdle()函数, 即可运行程序, 极大
// 的简化了开发过程.
//-----------------------------------------------------------------------------
class ASLWinApp
{
// 构造/析构函数
public:
ASLWinApp(void);
virtual ~ASLWinApp(void);
// 操作函数
public:
// 初始化应用程序
virtual void Init(void) = 0;
// 运行应用程序
void Run(void);
// 显示异常内容
inline void ShowException(const ASLException &e) const
{ MessageBox(m_hWnd, e.GetErrorMessage(), "错误", MB_OK | MB_ICONSTOP); }
// 退出程序
inline void Quit(void) { PostQuitMessage(0); }
// 锁定每秒帧速
inline void LockFPS(int fps)
{ m_dwFixedDelta = fps > 0 ? TIMER_PRECISION / fps : 0; }
// 取窗口句柄
inline HWND GetWindowHandle(void) const { return m_hWnd; }
// 取应用程序句柄
inline HINSTANCE GetInstanceHandle(void) const { return m_hInst; }
// 取每秒帧速
inline int GetFPS(void) const { return m_nFps; }
// 取帧间隔时间
inline float GetDelta(void) const { return m_fDelta; }
// 程序是否在活动状态
inline bool IsActive(void) const { return m_bActive; }
// 保护函数
protected:
// 消息处理回调函数
static LRESULT CALLBACK _WndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam);
// 创建应用程序
void Create(int width, int height, LPCSTR wndName, bool fullScreen = false,
bool showCursor = false, bool waitVSync = true, LPCSTR iconName = NULL);
// 空闲处理
virtual void OnIdle(void) {}
// 关闭前处理
virtual bool OnClose(void) { return true; }
// 激活/取消激活处理
virtual void OnActivate(bool bActive) {}
// 私有变量
private:
bool m_bActive; // 是否活动
bool m_bShowCursor; // 是否显示鼠标光标
HWND m_hWnd; // 主窗口句柄
HINSTANCE m_hInst; // 应用程序句柄
DWORD m_dwFixedDelta; // 设定的帧间隔
ASLTimer m_Timer; // 计时器
int m_nFps; // 实际每秒帧速
float m_fDelta; // 实际帧间隔
private:
static const int TIMER_PRECISION = 10000;
};
extern ASLWinApp *Application;
} // namespace ASL
#endif // ASL_WINAPP_INCLUDE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -