fixed bugs.

This commit is contained in:
Nomango 2018-02-01 09:38:25 +08:00
parent c79ba16d29
commit 71b39a8149
5 changed files with 52 additions and 98 deletions

View File

@ -1,8 +1,5 @@
#include "..\ebase.h" #include "..\ebase.h"
#include "..\emanagers.h" #include "..\emanagers.h"
#include "..\enodes.h"
#include "..\etransitions.h"
#include "..\etools.h"
// 控制游戏终止 // 控制游戏终止
@ -15,7 +12,7 @@ static bool s_bInitialized = false;
static e2d::EString s_sAppName; static e2d::EString s_sAppName;
bool e2d::EGame::init(LPCTSTR sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIconID, bool bNoClose, bool bNoMiniSize, bool bTopMost) bool e2d::EGame::init(LPCTSTR sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIconID, LPCTSTR sAppname)
{ {
if (s_bInitialized) if (s_bInitialized)
{ {
@ -30,16 +27,22 @@ bool e2d::EGame::init(LPCTSTR sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIc
if (ERenderer::__createDeviceIndependentResources()) if (ERenderer::__createDeviceIndependentResources())
{ {
// 初始化窗口 // 初始化窗口
if (EWindow::__init(sTitle, nWidth, nHeight, pIconID, bNoClose, bNoMiniSize, bTopMost)) if (EWindow::__init(sTitle, nWidth, nHeight, pIconID))
{ {
// 创建设备相关资源 // 创建设备相关资源
if (ERenderer::__createDeviceResources()) if (ERenderer::__createDeviceResources())
{ {
// 重设 Client 大小 // 重设 Client 大小
EWindow::setSize(nWidth, nHeight); EWindow::setSize(nWidth, nHeight);
// 设置默认 AppName // 设置 AppName
if (s_sAppName.isEmpty()) if (sAppname)
{
s_sAppName = sAppname;
}
else
{
s_sAppName = EWindow::getTitle(); s_sAppName = EWindow::getTitle();
}
// 标志初始化成功 // 标志初始化成功
s_bInitialized = true; s_bInitialized = true;
} }
@ -65,7 +68,7 @@ int e2d::EGame::run()
// 进入第一个场景 // 进入第一个场景
ESceneManager::__enterNextScene(); ESceneManager::__enterNextScene();
// 显示窗口 // 显示窗口
EWindow::showWindow(); ::ShowWindow(EWindow::getHWnd(), SW_SHOWNORMAL);
// 刷新窗口内容 // 刷新窗口内容
::UpdateWindow(EWindow::getHWnd()); ::UpdateWindow(EWindow::getHWnd());
// 处理窗口消息 // 处理窗口消息
@ -74,9 +77,6 @@ int e2d::EGame::run()
ETime::__updateNow(); ETime::__updateNow();
ETime::__updateLast(); ETime::__updateLast();
// 挂起时长
int nWaitMS = 0;
while (!s_bEndGame) while (!s_bEndGame)
{ {
// 处理窗口消息 // 处理窗口消息
@ -87,8 +87,9 @@ int e2d::EGame::run()
// 判断是否达到了刷新状态 // 判断是否达到了刷新状态
if (ETime::getDeltaTime() >= 17) if (ETime::getDeltaTime() >= 17)
{ {
ETime::__updateLast(); ETime::__updateLast(); // 刷新时间信息
EGame::__update(); EGame::__update(); // 更新游戏内容
ERenderer::__render(); // 渲染游戏画面
} }
else else
{ {
@ -144,20 +145,13 @@ void e2d::EGame::uninit()
void e2d::EGame::__update() void e2d::EGame::__update()
{ {
EInput::__updateDeviceState(); // 获取用户输入 if (s_bPaused)
return;
if (!s_bPaused) EInput::__updateDeviceState(); // 获取用户输入
{ ETimerManager::__update(); // 定时器管理器执行程序
ETimerManager::__update(); // 定时器管理器执行程序 EActionManager::__update(); // 动作管理器执行程序
EActionManager::__update(); // 动作管理器执行程序 ESceneManager::__update(); // 更新游戏内容
ESceneManager::__update(); // 更新游戏内容
ERenderer::__render(); // 渲染游戏画面
}
}
void e2d::EGame::setAppName(const EString &appname)
{
s_sAppName = appname;
} }
e2d::EString e2d::EGame::getAppName() e2d::EString e2d::EGame::getAppName()

View File

@ -17,7 +17,7 @@ bool e2d::ERenderer::__createDeviceIndependentResources()
&s_pDirect2dFactory &s_pDirect2dFactory
); );
ASSERT(SUCCEEDED(hr), "Create Device Independent Resources Failed!"); ASSERT(SUCCEEDED(hr), "Create ID2D1Factory Failed!");
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
@ -29,7 +29,7 @@ bool e2d::ERenderer::__createDeviceIndependentResources()
IID_IWICImagingFactory, IID_IWICImagingFactory,
reinterpret_cast<void**>(&s_pIWICFactory) reinterpret_cast<void**>(&s_pIWICFactory)
); );
ASSERT(SUCCEEDED(hr), "Create WICImagingFactory Failed!"); ASSERT(SUCCEEDED(hr), "Create IWICImagingFactory Failed!");
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
@ -40,7 +40,7 @@ bool e2d::ERenderer::__createDeviceIndependentResources()
__uuidof(IDWriteFactory), __uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&s_pDWriteFactory) reinterpret_cast<IUnknown**>(&s_pDWriteFactory)
); );
ASSERT(SUCCEEDED(hr), "Create DirectWrite Factory Failed!"); ASSERT(SUCCEEDED(hr), "Create IDWriteFactory Failed!");
} }
return SUCCEEDED(hr); return SUCCEEDED(hr);
@ -73,18 +73,19 @@ bool e2d::ERenderer::__createDeviceResources()
&s_pRenderTarget &s_pRenderTarget
); );
ASSERT(SUCCEEDED(hr), "Create Render Target Failed!"); ASSERT(SUCCEEDED(hr), "Create ID2D1HwndRenderTarget Failed!");
}
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
// ´´½¨»­Ë¢ // ´´½¨»­Ë¢
hr = s_pRenderTarget->CreateSolidColorBrush( hr = s_pRenderTarget->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::White), D2D1::ColorF(D2D1::ColorF::White),
&s_pSolidBrush &s_pSolidBrush
); );
ASSERT(SUCCEEDED(hr), "Create Solid Color Brush Failed!"); ASSERT(SUCCEEDED(hr), "Create ID2D1SolidColorBrush Failed!");
}
} }
return SUCCEEDED(hr); return SUCCEEDED(hr);
} }

View File

@ -9,7 +9,7 @@ static HWND s_HWnd = nullptr;
static bool s_bShowConsole = false; static bool s_bShowConsole = false;
bool e2d::EWindow::__init(LPCTSTR sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIconID /*= nullptr*/, bool bNoClose /*= false*/, bool bNoMiniSize /*= false*/, bool bTopMost /*= false*/) bool e2d::EWindow::__init(LPCTSTR sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR pIconID /*= nullptr*/)
{ {
// 注册窗口类 // 注册窗口类
WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; WNDCLASSEX wcex = { sizeof(WNDCLASSEX) };
@ -22,11 +22,6 @@ bool e2d::EWindow::__init(LPCTSTR sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR
wcex.lpszMenuName = NULL; wcex.lpszMenuName = NULL;
wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION); wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION);
wcex.lpszClassName = L"Easy2DApp"; wcex.lpszClassName = L"Easy2DApp";
// 设置窗口是否有关闭按钮
if (bNoClose)
{
wcex.style |= CS_NOCLOSE;
}
// 设置程序图标 // 设置程序图标
if (pIconID) if (pIconID)
{ {
@ -60,17 +55,11 @@ bool e2d::EWindow::__init(LPCTSTR sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR
nWidth = min(nWidth, screenWidth); nWidth = min(nWidth, screenWidth);
nHeight = min(nHeight, screenHeight); nHeight = min(nHeight, screenHeight);
// 创建窗口样式
DWORD dwStyle = WS_OVERLAPPED | WS_SYSMENU;
if (!bNoMiniSize)
{
dwStyle |= WS_MINIMIZEBOX;
}
// 创建窗口 // 创建窗口
s_HWnd = CreateWindow( s_HWnd = CreateWindow(
L"Easy2DApp", L"Easy2DApp",
sTitle, sTitle,
dwStyle, WS_OVERLAPPED | WS_SYSMENU,
0, 0, nWidth, nHeight, 0, 0, nWidth, nHeight,
NULL, NULL,
NULL, NULL,
@ -84,11 +73,6 @@ bool e2d::EWindow::__init(LPCTSTR sTitle, UINT32 nWidth, UINT32 nHeight, LPCTSTR
{ {
// 禁用输入法 // 禁用输入法
EWindow::setTypewritingEnable(false); EWindow::setTypewritingEnable(false);
// 设置窗口置顶
if (bTopMost)
{
::SetWindowPos(s_HWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
// 查找是否存在控制台 // 查找是否存在控制台
HWND hwnd = ::GetConsoleWindow(); HWND hwnd = ::GetConsoleWindow();
if (hwnd) if (hwnd)
@ -177,7 +161,7 @@ void e2d::EWindow::setSize(UINT32 width, UINT32 height)
void e2d::EWindow::setTitle(const EString &title) void e2d::EWindow::setTitle(const EString &title)
{ {
// 设置窗口标题 // 设置窗口标题
SetWindowText(s_HWnd, title); ::SetWindowText(s_HWnd, title);
} }
e2d::EString e2d::EWindow::getTitle() e2d::EString e2d::EWindow::getTitle()
@ -229,16 +213,6 @@ void e2d::EWindow::showConsole(bool show /* = true */)
} }
} }
void e2d::EWindow::hideWindow()
{
::ShowWindow(s_HWnd, SW_HIDE);
}
void e2d::EWindow::showWindow()
{
::ShowWindow(s_HWnd, SW_SHOWNORMAL);
}
void e2d::EWindow::setTypewritingEnable(bool bEnable) void e2d::EWindow::setTypewritingEnable(bool bEnable)
{ {
static HIMC hImc = nullptr; static HIMC hImc = nullptr;

View File

@ -8,10 +8,11 @@
DEFINE_KNOWN_FOLDER(FOLDERID_LocalAppData, 0xF1B32785, 0x6FBA, 0x4FCF, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91); DEFINE_KNOWN_FOLDER(FOLDERID_LocalAppData, 0xF1B32785, 0x6FBA, 0x4FCF, 0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91);
typedef HRESULT(WINAPI* pFunSHGetKnownFolderPath)(const GUID& rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath);
e2d::EString e2d::EFile::getLocalAppDataPath() e2d::EString e2d::EFile::getLocalAppDataPath()
{ {
typedef HRESULT(WINAPI* pFunSHGetKnownFolderPath)(const GUID& rfid, DWORD dwFlags, HANDLE hToken, PWSTR *ppszPath);
// 获取 AppData\Local 文件夹的路径 // 获取 AppData\Local 文件夹的路径
PWSTR pszPath = NULL; PWSTR pszPath = NULL;
HMODULE hModule = LoadLibrary(L"shell32.dll"); HMODULE hModule = LoadLibrary(L"shell32.dll");
@ -35,9 +36,9 @@ e2d::EString e2d::EFile::getTempPath()
// 创建临时文件目录 // 创建临时文件目录
e2d::EString tempFilePath = path + e2d::EGame::getAppName(); e2d::EString tempFilePath = path + e2d::EGame::getAppName();
if (_waccess(tempFilePath, 0) == -1) if (::_waccess(tempFilePath, 0) == -1)
{ {
_wmkdir(tempFilePath); ::_wmkdir(tempFilePath);
} }
return tempFilePath; return tempFilePath;
} }
@ -49,9 +50,9 @@ e2d::EString e2d::EFile::getDefaultSavePath()
path += L"\\" + EGame::getAppName(); path += L"\\" + EGame::getAppName();
if (_waccess(path, 0) == -1) if (::_waccess(path, 0) == -1)
{ {
_wmkdir(path); ::_wmkdir(path);
} }
path += L"\\DefaultData.ini"; path += L"\\DefaultData.ini";

View File

@ -18,9 +18,7 @@ public:
UINT32 nWidth, /* 窗口宽度 */ UINT32 nWidth, /* 窗口宽度 */
UINT32 nHeight, /* 窗口高度 */ UINT32 nHeight, /* 窗口高度 */
LPCTSTR pIconID = nullptr, /* 窗口图标 */ LPCTSTR pIconID = nullptr, /* 窗口图标 */
bool bNoClose = false, /* 禁用关闭按钮 */ LPCTSTR sAppname = nullptr /* AppName */
bool bNoMiniSize = false, /* 禁用最小化按钮 */
bool bTopMost = false /* 窗口置顶 */
); );
// 启动游戏 // 启动游戏
@ -44,11 +42,6 @@ public:
// 获取 AppName // 获取 AppName
static EString getAppName(); static EString getAppName();
// 设置 AppName
static void setAppName(
const EString &appname
);
private: private:
// 更新游戏内容 // 更新游戏内容
static void __update(); static void __update();
@ -78,26 +71,20 @@ public:
// 修改窗口大小 // 修改窗口大小
static void setSize( static void setSize(
UINT32 width, UINT32 nWidth,
UINT32 height UINT32 nHeight
); );
// 设置窗口标题 // 设置窗口标题
static void setTitle( static void setTitle(
const EString & title const EString & sTitle
); );
// 打开/隐藏控制台 // 打开/隐藏控制台
static void showConsole( static void showConsole(
bool show = true bool bShow = true
); );
// 隐藏主窗口
static void hideWindow();
// 显示主窗口
static void showWindow();
// 是否允许响应输入法 // 是否允许响应输入法
static void setTypewritingEnable( static void setTypewritingEnable(
bool bEnable bool bEnable
@ -106,13 +93,10 @@ public:
private: private:
// 初始化窗口 // 初始化窗口
static bool __init( static bool __init(
LPCTSTR sTitle, /* 窗口标题 */ LPCTSTR sTitle,
UINT32 nWidth, /* 窗口宽度 */ UINT32 nWidth,
UINT32 nHeight, /* 窗口高度 */ UINT32 nHeight,
LPCTSTR pIconID, /* 窗口图标 */ LPCTSTR pIconID
bool bNoClose, /* 禁用关闭按钮 */
bool bNoMiniSize, /* 禁用最小化按钮 */
bool bTopMost /* 窗口置顶 */
); );
// 重置窗口属性 // 重置窗口属性