2017-10-12 23:34:13 +08:00
|
|
|
|
#include "..\ebase.h"
|
2017-10-10 01:14:03 +08:00
|
|
|
|
#include "..\Win\winbase.h"
|
2017-10-26 17:17:30 +08:00
|
|
|
|
#include "..\emanagers.h"
|
2017-10-17 21:22:25 +08:00
|
|
|
|
#include "..\enodes.h"
|
2017-10-20 00:59:26 +08:00
|
|
|
|
#include "..\etransitions.h"
|
2017-12-08 15:37:52 +08:00
|
|
|
|
#include "..\etools.h"
|
2017-10-10 01:14:03 +08:00
|
|
|
|
#include <stack>
|
|
|
|
|
|
#include <thread>
|
2017-10-26 17:17:30 +08:00
|
|
|
|
#include <imm.h>
|
2017-10-17 21:22:25 +08:00
|
|
|
|
#pragma comment (lib ,"imm32.lib")
|
|
|
|
|
|
|
2017-10-12 02:44:44 +08:00
|
|
|
|
using namespace std::this_thread;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
using namespace std::chrono;
|
2017-10-12 02:44:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
2017-10-17 21:22:25 +08:00
|
|
|
|
// Ψһʵ<D2BB><CAB5>ָ<EFBFBD><D6B8>
|
2017-10-18 22:13:20 +08:00
|
|
|
|
static e2d::EApp * s_pInstance = nullptr;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ջ
|
2017-10-18 22:13:20 +08:00
|
|
|
|
static std::stack<e2d::EScene*> s_SceneStack;
|
2017-10-17 23:50:02 +08:00
|
|
|
|
// <20><>Ϸ<EFBFBD><CFB7>ʼʱ<CABC><CAB1>
|
|
|
|
|
|
static steady_clock::time_point s_tStart;
|
2017-10-12 02:44:44 +08:00
|
|
|
|
|
2017-11-03 12:51:01 +08:00
|
|
|
|
|
2017-10-12 02:44:44 +08:00
|
|
|
|
e2d::EApp::EApp()
|
2017-10-20 00:59:26 +08:00
|
|
|
|
: m_bEnd(false)
|
|
|
|
|
|
, m_bPaused(false)
|
|
|
|
|
|
, m_bManualPaused(false)
|
2017-10-31 17:19:13 +08:00
|
|
|
|
, m_bShowConsole(false)
|
2017-11-03 12:51:01 +08:00
|
|
|
|
, m_nAnimationInterval(17LL)
|
2017-10-18 22:13:20 +08:00
|
|
|
|
, m_ClearColor(EColor::BLACK)
|
2017-12-09 15:27:11 +08:00
|
|
|
|
, m_pTransition(nullptr)
|
2017-10-12 02:44:44 +08:00
|
|
|
|
, m_pCurrentScene(nullptr)
|
|
|
|
|
|
, m_pNextScene(nullptr)
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 02:44:44 +08:00
|
|
|
|
e2d::EApp::~EApp()
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-10-20 00:59:26 +08:00
|
|
|
|
SafeReleaseInterface(&GetSolidColorBrush());
|
2017-10-12 02:44:44 +08:00
|
|
|
|
SafeReleaseInterface(&GetRenderTarget());
|
2017-10-17 21:22:25 +08:00
|
|
|
|
SafeReleaseInterface(&GetFactory());
|
2017-10-19 00:50:04 +08:00
|
|
|
|
SafeReleaseInterface(&GetImagingFactory());
|
|
|
|
|
|
SafeReleaseInterface(&GetDirectWriteFactory());
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-08 19:50:59 +08:00
|
|
|
|
e2d::EApp * e2d::EApp::getInstance()
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
if (!s_pInstance)
|
|
|
|
|
|
{
|
|
|
|
|
|
s_pInstance = new EApp();
|
|
|
|
|
|
}
|
2017-10-12 02:44:44 +08:00
|
|
|
|
return s_pInstance; // <20><>ȡ EApp <20><>Ψһʵ<D2BB><CAB5>
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-09 15:51:23 +08:00
|
|
|
|
bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height, const EWindowStyle &wStyle /* = nullptr */)
|
2017-10-12 02:44:44 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
CoInitialize(NULL);
|
|
|
|
|
|
|
2017-10-12 02:44:44 +08:00
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
2017-12-09 15:51:23 +08:00
|
|
|
|
// <20><><EFBFBD>洰<EFBFBD><E6B4B0><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
|
EApp::getInstance()->m_WindowStyle = wStyle;
|
|
|
|
|
|
// <20><><EFBFBD>洰<EFBFBD><E6B4B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
EApp::getInstance()->m_sTitle = title;
|
|
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// ע<>ᴰ<EFBFBD><E1B4B0><EFBFBD><EFBFBD>
|
|
|
|
|
|
WNDCLASSEX wcex = { sizeof(WNDCLASSEX) };
|
|
|
|
|
|
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
|
|
|
|
|
|
wcex.lpfnWndProc = EApp::WndProc;
|
|
|
|
|
|
wcex.cbClsExtra = 0;
|
|
|
|
|
|
wcex.cbWndExtra = sizeof(LONG_PTR);
|
|
|
|
|
|
wcex.hInstance = HINST_THISCOMPONENT;
|
|
|
|
|
|
wcex.hbrBackground = (HBRUSH)(GetStockObject(BLACK_BRUSH));
|
|
|
|
|
|
wcex.lpszMenuName = NULL;
|
|
|
|
|
|
wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION);
|
|
|
|
|
|
wcex.lpszClassName = L"Easy2DApp";
|
|
|
|
|
|
// <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>йرհ<D8B1>ť
|
|
|
|
|
|
if (wStyle.m_bNoClose)
|
2017-10-13 11:42:36 +08:00
|
|
|
|
{
|
2017-10-31 17:19:13 +08:00
|
|
|
|
wcex.style |= CS_NOCLOSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD>ó<EFBFBD><C3B3><EFBFBD>ͼ<EFBFBD><CDBC>
|
|
|
|
|
|
if (wStyle.m_pIconID)
|
|
|
|
|
|
{
|
|
|
|
|
|
wcex.hIcon = (HICON)::LoadImage(
|
|
|
|
|
|
GetModuleHandle(NULL),
|
|
|
|
|
|
wStyle.m_pIconID,
|
|
|
|
|
|
IMAGE_ICON,
|
|
|
|
|
|
0,
|
|
|
|
|
|
0,
|
|
|
|
|
|
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
|
|
|
|
|
|
}
|
2017-10-13 11:42:36 +08:00
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
RegisterClassEx(&wcex);
|
2017-10-13 11:42:36 +08:00
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// <20><>Ϊ CreateWindow <20><><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>ȡϵͳ<CFB5><CDB3> DPI <20><>ʹ<EFBFBD><CAB9>
|
|
|
|
|
|
// <20><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
FLOAT dpiX, dpiY;
|
2017-10-13 11:42:36 +08:00
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ǰ<EFBFBD><C7B0>ϵͳ DPI<50><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵҲ<D6B5><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
GetFactory()->GetDesktopDpi(&dpiX, &dpiY);
|
2017-10-13 11:42:36 +08:00
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
width = static_cast<UINT>(ceil(width * dpiX / 96.f));
|
|
|
|
|
|
height = static_cast<UINT>(ceil(height * dpiY / 96.f));
|
2017-10-17 21:22:25 +08:00
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>Ļ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>
|
|
|
|
|
|
UINT screenWidth = static_cast<UINT>(GetSystemMetrics(SM_CXSCREEN));
|
|
|
|
|
|
UINT screenHeight = static_cast<UINT>(GetSystemMetrics(SM_CYSCREEN));
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4>ڴ<EFBFBD>С<EFBFBD>ȷֱ<C8B7><D6B1>ʴ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
WARN_IF(screenWidth < width || screenHeight < height, "The window is larger than screen!");
|
|
|
|
|
|
// ȡ<><C8A1>Сֵ
|
|
|
|
|
|
width = min(width, screenWidth);
|
|
|
|
|
|
height = min(height, screenHeight);
|
2017-11-03 12:51:01 +08:00
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
|
DWORD dwStyle = WS_OVERLAPPED | WS_SYSMENU;
|
|
|
|
|
|
if (!wStyle.m_bNoMiniSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
dwStyle |= WS_MINIMIZEBOX;
|
|
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
GetHWnd() = CreateWindow(
|
|
|
|
|
|
L"Easy2DApp",
|
2017-12-11 18:17:24 +08:00
|
|
|
|
title,
|
2017-10-31 17:19:13 +08:00
|
|
|
|
dwStyle,
|
2017-12-08 15:37:52 +08:00
|
|
|
|
0, 0, width, height,
|
2017-10-31 17:19:13 +08:00
|
|
|
|
NULL,
|
|
|
|
|
|
NULL,
|
|
|
|
|
|
HINST_THISCOMPONENT,
|
2017-12-08 19:50:59 +08:00
|
|
|
|
NULL
|
2017-10-31 17:19:13 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
hr = GetHWnd() ? S_OK : E_FAIL;
|
2017-10-17 21:22:25 +08:00
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뷨
|
2017-12-08 19:50:59 +08:00
|
|
|
|
EApp::setKeyboardLayoutEnable(false);
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>С
|
2017-12-08 19:50:59 +08:00
|
|
|
|
EApp::setWindowSize(width, height);
|
2017-10-31 17:19:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-12-08 15:37:52 +08:00
|
|
|
|
UnregisterClass(L"Easy2DApp", HINST_THISCOMPONENT);
|
2017-10-12 02:44:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:34:13 +08:00
|
|
|
|
if (FAILED(hr))
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox(nullptr, L"Initialize Failed!", L"Error", MB_OK);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 02:44:44 +08:00
|
|
|
|
return SUCCEEDED(hr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-08 19:50:59 +08:00
|
|
|
|
int e2d::EApp::run()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (GetHWnd() == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox(nullptr, L"Invalid window handle!", L"Error", MB_OK);
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EApp * pApp = EApp::getInstance();
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
pApp->_enterNextScene();
|
|
|
|
|
|
// <20>رտ<D8B1><D5BF><EFBFBD>̨
|
|
|
|
|
|
if (!pApp->m_bShowConsole)
|
|
|
|
|
|
{
|
|
|
|
|
|
showConsole(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
|
|
|
|
|
|
ShowWindow(GetHWnd(), SW_SHOWNORMAL);
|
|
|
|
|
|
UpdateWindow(GetHWnd());
|
|
|
|
|
|
// <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD>ö<EFBFBD>
|
2017-12-09 15:51:23 +08:00
|
|
|
|
if (pApp->m_WindowStyle.m_bTopMost)
|
2017-12-08 19:50:59 +08:00
|
|
|
|
{
|
|
|
|
|
|
SetWindowPos(GetHWnd(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>¼<EFBFBD><C2BC>ʼʱ<CABC><CAB1>
|
|
|
|
|
|
s_tStart = steady_clock::now();
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
|
|
|
|
while (!pApp->m_bEnd)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
|
|
{
|
|
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
// ִ<><D6B4><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
|
|
|
|
|
|
pApp->_mainLoop();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20>رտ<D8B1><D5BF><EFBFBD>̨
|
|
|
|
|
|
EApp::showConsole(false);
|
|
|
|
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-20 00:59:26 +08:00
|
|
|
|
void e2d::EApp::pause()
|
|
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
EApp::getInstance()->m_bManualPaused = true;
|
2017-10-20 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EApp::resume()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isPaused())
|
|
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
EApp::getInstance()->m_bPaused = false;
|
|
|
|
|
|
EApp::getInstance()->m_bManualPaused = false;
|
|
|
|
|
|
EApp::getInstance()->_updateTime();
|
2017-10-20 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool e2d::EApp::isPaused()
|
|
|
|
|
|
{
|
|
|
|
|
|
return s_pInstance->m_bPaused || s_pInstance->m_bManualPaused;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-08 19:50:59 +08:00
|
|
|
|
void e2d::EApp::quit()
|
|
|
|
|
|
{
|
|
|
|
|
|
getInstance()->m_bEnd = true; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
void e2d::EApp::showConsole(bool show /* = true */)
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
static FILE * stdoutstream = nullptr;
|
|
|
|
|
|
static FILE * stdinstream = nullptr;
|
|
|
|
|
|
static FILE * stderrstream = nullptr;
|
2017-10-31 17:19:13 +08:00
|
|
|
|
|
2017-12-08 19:50:59 +08:00
|
|
|
|
EApp::getInstance()->m_bShowConsole = show;
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><D1B4>ڵĿ<DAB5><C4BF><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>
|
|
|
|
|
|
HWND hwnd = GetConsoleWindow();
|
2017-10-17 21:22:25 +08:00
|
|
|
|
// <20>رտ<D8B1><D5BF><EFBFBD>̨
|
|
|
|
|
|
if (show)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (hwnd)
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowWindow(hwnd, SW_SHOWNORMAL);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><>ʾһ<CABE><D2BB><EFBFBD>¿<EFBFBD><C2BF><EFBFBD>̨
|
|
|
|
|
|
if (AllocConsole())
|
|
|
|
|
|
{
|
|
|
|
|
|
freopen_s(&stdoutstream, "CONOUT$", "w+t", stdout);
|
|
|
|
|
|
freopen_s(&stderrstream, "CONOUT$", "w+t", stderr);
|
|
|
|
|
|
freopen_s(&stdinstream, "CONIN$", "r+t", stdin);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox(nullptr, L"Alloc Console Failed!", L"Error", MB_OK);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (hwnd)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (stdoutstream)
|
|
|
|
|
|
{
|
|
|
|
|
|
fclose(stdoutstream);
|
|
|
|
|
|
fclose(stdinstream);
|
|
|
|
|
|
fclose(stderrstream);
|
|
|
|
|
|
|
|
|
|
|
|
stdoutstream = stdinstream = stderrstream = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
FreeConsole();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-20 00:59:26 +08:00
|
|
|
|
bool e2d::EApp::onActivate()
|
2017-10-17 23:50:02 +08:00
|
|
|
|
{
|
2017-12-08 19:57:34 +08:00
|
|
|
|
return false;
|
2017-10-17 23:50:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-18 22:13:20 +08:00
|
|
|
|
bool e2d::EApp::onInactive()
|
2017-10-17 23:50:02 +08:00
|
|
|
|
{
|
2017-12-08 19:57:34 +08:00
|
|
|
|
return false;
|
2017-10-17 23:50:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool e2d::EApp::onCloseWindow()
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 02:44:44 +08:00
|
|
|
|
void e2d::EApp::_mainLoop()
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-10-12 02:44:44 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
|
static LONGLONG nWaitMS = 0L;
|
2017-11-03 12:51:01 +08:00
|
|
|
|
// ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
static LONGLONG nInterval;
|
2017-10-21 19:09:31 +08:00
|
|
|
|
// <20><>һ֡<D2BB><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
2017-10-17 21:22:25 +08:00
|
|
|
|
static steady_clock::time_point tLast = steady_clock::now();
|
|
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
// ˢ<>µ<EFBFBD>ǰʱ<C7B0><CAB1>
|
2017-10-17 21:22:25 +08:00
|
|
|
|
GetNow() = steady_clock::now();
|
2017-10-12 02:44:44 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-10-17 21:22:25 +08:00
|
|
|
|
nInterval = GetInterval(tLast);
|
2017-10-12 02:44:44 +08:00
|
|
|
|
// <20>жϼ<D0B6><CFBC><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>Ƿ<EFBFBD><C7B7>㹻
|
2017-11-03 12:51:01 +08:00
|
|
|
|
if (nInterval >= m_nAnimationInterval)
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-10-18 01:15:25 +08:00
|
|
|
|
// <20><>¼<EFBFBD><C2BC>ǰʱ<C7B0><CAB1>
|
2017-11-03 12:51:01 +08:00
|
|
|
|
tLast += microseconds(m_nAnimationInterval);
|
2017-10-20 00:59:26 +08:00
|
|
|
|
// <20><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-12-08 15:37:52 +08:00
|
|
|
|
_update();
|
2017-10-20 00:59:26 +08:00
|
|
|
|
// ˢ<><CBA2><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
|
2017-12-08 15:37:52 +08:00
|
|
|
|
_render();
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-10-12 02:44:44 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
2017-11-03 12:51:01 +08:00
|
|
|
|
nWaitMS = m_nAnimationInterval - nInterval - 1;
|
2017-10-12 02:44:44 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>̣߳<DFB3><CCA3>ͷ<EFBFBD> CPU ռ<><D5BC>
|
|
|
|
|
|
if (nWaitMS > 1LL)
|
|
|
|
|
|
{
|
2017-10-17 21:22:25 +08:00
|
|
|
|
sleep_for(milliseconds(nWaitMS));
|
2017-10-12 02:44:44 +08:00
|
|
|
|
}
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-08 15:37:52 +08:00
|
|
|
|
void e2d::EApp::_update()
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-12-04 10:03:14 +08:00
|
|
|
|
if (isPaused())
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ִ<EFBFBD>г<EFBFBD><D0B3><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
|
2017-12-09 15:27:11 +08:00
|
|
|
|
if (m_pTransition)
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-12-09 15:27:11 +08:00
|
|
|
|
m_pTransition->_update();
|
|
|
|
|
|
if (m_pTransition->isEnding())
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2017-12-09 15:27:11 +08:00
|
|
|
|
m_pTransition->release();
|
|
|
|
|
|
m_pTransition = nullptr;
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
|
|
|
|
|
_enterNextScene();
|
2017-12-12 12:18:28 +08:00
|
|
|
|
// ˢ<>¼<EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
|
_updateTime();
|
2017-10-21 19:09:31 +08:00
|
|
|
|
}
|
2017-12-09 15:27:11 +08:00
|
|
|
|
return;
|
2017-10-20 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
// <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ָ<EFBFBD>벻Ϊ<EBB2BB><CEAA>ʱ<EFBFBD><CAB1><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (m_pNextScene)
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
2017-10-21 19:09:31 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
|
|
|
|
|
_enterNextScene();
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
2017-10-20 00:59:26 +08:00
|
|
|
|
|
2017-09-10 23:56:52 +08:00
|
|
|
|
// <20><><EFBFBD>Ե<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>
|
2017-10-14 01:07:34 +08:00
|
|
|
|
ASSERT(m_pCurrentScene != nullptr, "Current scene NULL pointer exception.");
|
2017-09-10 23:56:52 +08:00
|
|
|
|
|
2017-10-29 23:48:32 +08:00
|
|
|
|
EObjectManager::__flush(); // ˢ<><CBA2><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>
|
2017-10-19 00:50:04 +08:00
|
|
|
|
ETimerManager::TimerProc(); // <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>г<EFBFBD><D0B3><EFBFBD>
|
|
|
|
|
|
EActionManager::ActionProc(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>г<EFBFBD><D0B3><EFBFBD>
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-08 15:37:52 +08:00
|
|
|
|
void e2d::EApp::_render()
|
2017-10-10 01:14:03 +08:00
|
|
|
|
{
|
2017-10-12 02:44:44 +08:00
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// <20><>ʼ<EFBFBD><CABC>ͼ
|
|
|
|
|
|
GetRenderTarget()->BeginDraw();
|
|
|
|
|
|
// ʹ<>ñ<EFBFBD><C3B1><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
|
|
|
|
|
|
GetRenderTarget()->Clear(D2D1::ColorF(m_ClearColor));
|
|
|
|
|
|
// <20><><EFBFBD>Ƶ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (m_pCurrentScene)
|
2017-10-10 01:14:03 +08:00
|
|
|
|
{
|
2017-12-08 15:37:52 +08:00
|
|
|
|
m_pCurrentScene->_render();
|
2017-10-31 17:19:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-12-09 15:27:11 +08:00
|
|
|
|
if (m_pTransition && m_pNextScene)
|
2017-10-31 17:19:13 +08:00
|
|
|
|
{
|
2017-12-08 15:37:52 +08:00
|
|
|
|
m_pNextScene->_render();
|
2017-10-12 02:44:44 +08:00
|
|
|
|
}
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// <20><>ֹ<EFBFBD><D6B9>ͼ
|
|
|
|
|
|
hr = GetRenderTarget()->EndDraw();
|
|
|
|
|
|
// ˢ<>½<EFBFBD><C2BD><EFBFBD>
|
|
|
|
|
|
UpdateWindow(GetHWnd());
|
2017-10-12 02:44:44 +08:00
|
|
|
|
|
|
|
|
|
|
if (hr == D2DERR_RECREATE_TARGET)
|
|
|
|
|
|
{
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> Direct3D <20>豸<EFBFBD><E8B1B8>ִ<EFBFBD>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD>ʱ<EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD>Դ
|
2017-10-12 02:44:44 +08:00
|
|
|
|
hr = S_OK;
|
2017-10-31 17:19:13 +08:00
|
|
|
|
SafeReleaseInterface(&GetRenderTarget());
|
2017-10-12 02:44:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-20 00:59:26 +08:00
|
|
|
|
if (FAILED(hr))
|
|
|
|
|
|
{
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// <20><>Ⱦʱ<C8BE><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ֪<CEB4>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD>Ϸ
|
2017-10-29 23:48:32 +08:00
|
|
|
|
MessageBox(GetHWnd(), L"Game rendering failed!", L"Error", MB_OK);
|
2017-10-20 00:59:26 +08:00
|
|
|
|
this->quit();
|
|
|
|
|
|
}
|
2017-09-27 17:56:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-17 21:22:25 +08:00
|
|
|
|
void e2d::EApp::setWindowSize(UINT32 width, UINT32 height)
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-09-12 12:53:34 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>Ļ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>
|
|
|
|
|
|
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
|
|
|
|
|
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ڴ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD>
|
2017-10-12 02:44:44 +08:00
|
|
|
|
tagRECT rcWindow;
|
2017-09-12 12:53:34 +08:00
|
|
|
|
GetWindowRect(GetHWnd(), &rcWindow);
|
|
|
|
|
|
// <20><>ȡ<EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>С
|
2017-10-12 02:44:44 +08:00
|
|
|
|
tagRECT rcClient;
|
2017-09-12 12:53:34 +08:00
|
|
|
|
GetClientRect(GetHWnd(), &rcClient);
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD><DFBF><EFBFBD>С
|
|
|
|
|
|
width += (rcWindow.right - rcWindow.left) - (rcClient.right - rcClient.left);
|
|
|
|
|
|
height += (rcWindow.bottom - rcWindow.top) - (rcClient.bottom - rcClient.top);
|
|
|
|
|
|
// <20>Ĵ<DEB8><C4B4>ڴ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>
|
2017-10-14 01:07:34 +08:00
|
|
|
|
MoveWindow(GetHWnd(), (screenWidth - width) / 2, (screenHeight - height) / 2, width, height, TRUE);
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-17 21:22:25 +08:00
|
|
|
|
void e2d::EApp::setWindowTitle(const EString &title)
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD>ô<EFBFBD><C3B4>ڱ<EFBFBD><DAB1><EFBFBD>
|
2017-12-11 18:17:24 +08:00
|
|
|
|
SetWindowText(GetHWnd(), title);
|
2017-09-10 23:56:52 +08:00
|
|
|
|
// <20><><EFBFBD>浱ǰ<E6B5B1><C7B0><EFBFBD>⣬<EFBFBD><E2A3AC><EFBFBD><EFBFBD><EFBFBD>Ĵ<DEB8><C4B4>ڴ<EFBFBD>Сʱ<D0A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>
|
2017-12-08 19:50:59 +08:00
|
|
|
|
getInstance()->m_sTitle = title;
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:34:13 +08:00
|
|
|
|
e2d::EString e2d::EApp::getTitle()
|
2017-09-20 14:52:50 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
return getInstance()->m_sTitle;
|
2017-09-20 14:52:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
float e2d::EApp::getWidth()
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-10-21 19:09:31 +08:00
|
|
|
|
return GetRenderTarget()->GetSize().width;
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
float e2d::EApp::getHeight()
|
2017-10-12 02:44:44 +08:00
|
|
|
|
{
|
2017-10-21 19:09:31 +08:00
|
|
|
|
return GetRenderTarget()->GetSize().height;
|
2017-10-12 02:44:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-11-03 12:51:01 +08:00
|
|
|
|
e2d::ESize e2d::EApp::getSize()
|
|
|
|
|
|
{
|
|
|
|
|
|
return ESize(GetRenderTarget()->GetSize().width, GetRenderTarget()->GetSize().height);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-09 15:27:11 +08:00
|
|
|
|
void e2d::EApp::enterScene(EScene * scene, ETransition * transition /* = nullptr */, bool saveCurrentScene /* = true */)
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
2017-12-09 15:27:11 +08:00
|
|
|
|
ASSERT(scene != nullptr, "Next scene NULL pointer exception!");
|
2017-10-20 00:59:26 +08:00
|
|
|
|
scene->retain();
|
2017-09-10 23:56:52 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
2017-12-08 19:50:59 +08:00
|
|
|
|
getInstance()->m_pNextScene = scene;
|
2017-09-10 23:56:52 +08:00
|
|
|
|
// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>Ƿ浱ǰ<E6B5B1><C7B0><EFBFBD><EFBFBD>
|
2017-12-08 19:50:59 +08:00
|
|
|
|
if (getInstance()->m_pCurrentScene)
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
getInstance()->m_pCurrentScene->m_bWillSave = saveCurrentScene;
|
2017-10-20 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (transition)
|
|
|
|
|
|
{
|
2017-12-09 15:27:11 +08:00
|
|
|
|
getInstance()->m_pTransition = transition;
|
|
|
|
|
|
transition->retain();
|
2017-10-20 00:59:26 +08:00
|
|
|
|
transition->_setTarget(
|
2017-12-08 19:50:59 +08:00
|
|
|
|
getInstance()->m_pCurrentScene,
|
2017-12-09 15:27:11 +08:00
|
|
|
|
getInstance()->m_pNextScene
|
2017-10-20 00:59:26 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
void e2d::EApp::backScene(ETransition * transition /* = nullptr */)
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
2017-10-31 17:19:13 +08:00
|
|
|
|
// ջΪ<D5BB><CEAA>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><C3B7>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
|
|
|
|
|
WARN_IF(s_SceneStack.size() == 0, "Scene stack now is empty!");
|
|
|
|
|
|
if (s_SceneStack.size() == 0) return;
|
2017-10-20 00:59:26 +08:00
|
|
|
|
|
2017-09-10 23:56:52 +08:00
|
|
|
|
// <20><>ջ<EFBFBD><D5BB>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>룬<EFBFBD><EBA3AC>Ϊ<EFBFBD><CEAA>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
2017-12-08 19:50:59 +08:00
|
|
|
|
getInstance()->m_pNextScene = s_SceneStack.top();
|
2017-10-14 18:43:32 +08:00
|
|
|
|
s_SceneStack.pop();
|
2017-10-31 17:19:13 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>浱ǰ<E6B5B1><C7B0><EFBFBD><EFBFBD>
|
2017-12-08 19:50:59 +08:00
|
|
|
|
if (getInstance()->m_pCurrentScene)
|
2017-10-14 18:43:32 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
getInstance()->m_pCurrentScene->m_bWillSave = false;
|
2017-10-14 18:43:32 +08:00
|
|
|
|
}
|
2017-10-31 17:19:13 +08:00
|
|
|
|
|
2017-10-20 00:59:26 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
if (transition)
|
|
|
|
|
|
{
|
2017-12-09 15:27:11 +08:00
|
|
|
|
getInstance()->m_pTransition = transition;
|
|
|
|
|
|
transition->retain();
|
2017-10-20 00:59:26 +08:00
|
|
|
|
transition->_setTarget(
|
2017-12-08 19:50:59 +08:00
|
|
|
|
getInstance()->m_pCurrentScene,
|
2017-12-09 15:27:11 +08:00
|
|
|
|
getInstance()->m_pNextScene
|
2017-10-20 00:59:26 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 02:44:44 +08:00
|
|
|
|
void e2d::EApp::clearScene()
|
2017-09-18 23:59:08 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD>ճ<EFBFBD><D5B3><EFBFBD>ջ
|
2017-10-10 01:14:03 +08:00
|
|
|
|
while (s_SceneStack.size())
|
2017-09-18 23:59:08 +08:00
|
|
|
|
{
|
2017-10-10 01:14:03 +08:00
|
|
|
|
auto temp = s_SceneStack.top();
|
2017-10-31 17:19:13 +08:00
|
|
|
|
SafeRelease(&temp);
|
2017-10-10 01:14:03 +08:00
|
|
|
|
s_SceneStack.pop();
|
2017-09-18 23:59:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-08 19:50:59 +08:00
|
|
|
|
void e2d::EApp::setFPS(UINT32 fps)
|
|
|
|
|
|
{
|
|
|
|
|
|
fps = min(max(fps, 30), 120);
|
|
|
|
|
|
s_pInstance->m_nAnimationInterval = 1000 / fps;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:34:13 +08:00
|
|
|
|
e2d::EScene * e2d::EApp::getCurrentScene()
|
2017-10-12 02:44:44 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
return getInstance()->m_pCurrentScene;
|
2017-10-12 23:34:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-17 21:22:25 +08:00
|
|
|
|
void e2d::EApp::setAppName(const EString &appname)
|
2017-09-20 14:52:50 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
getInstance()->m_sAppName = appname;
|
2017-09-20 14:52:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:34:13 +08:00
|
|
|
|
e2d::EString e2d::EApp::getAppName()
|
2017-09-20 14:52:50 +08:00
|
|
|
|
{
|
2017-12-11 18:17:24 +08:00
|
|
|
|
if (getInstance()->m_sAppName.isEmpty())
|
2017-12-08 19:50:59 +08:00
|
|
|
|
getInstance()->m_sAppName = getInstance()->m_sTitle;
|
|
|
|
|
|
return getInstance()->m_sAppName;
|
2017-09-20 14:52:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-26 17:17:30 +08:00
|
|
|
|
void e2d::EApp::setBkColor(UINT32 color)
|
2017-10-12 02:44:44 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
getInstance()->m_ClearColor = color;
|
2017-10-12 02:44:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-17 21:22:25 +08:00
|
|
|
|
void e2d::EApp::setKeyboardLayoutEnable(bool value)
|
|
|
|
|
|
{
|
|
|
|
|
|
static HIMC hImc = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (hImc != NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
ImmAssociateContext(GetHWnd(), hImc);
|
|
|
|
|
|
hImc = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (hImc == NULL)
|
|
|
|
|
|
{
|
|
|
|
|
|
hImc = ImmAssociateContext(GetHWnd(), NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HWND e2d::EApp::getHWnd()
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetHWnd();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-09 15:51:23 +08:00
|
|
|
|
e2d::EWindowStyle e2d::EApp::getWindowStyle()
|
|
|
|
|
|
{
|
|
|
|
|
|
return getInstance()->m_WindowStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-17 23:50:02 +08:00
|
|
|
|
LONGLONG e2d::EApp::getTotalDurationFromStart()
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetInterval(s_tStart);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EApp::hideWindow()
|
2017-10-12 02:44:44 +08:00
|
|
|
|
{
|
|
|
|
|
|
ShowWindow(GetHWnd(), SW_HIDE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-17 21:22:25 +08:00
|
|
|
|
void e2d::EApp::showWindow()
|
2017-09-12 12:53:34 +08:00
|
|
|
|
{
|
2017-10-17 21:22:25 +08:00
|
|
|
|
ShowWindow(GetHWnd(), SW_SHOWNORMAL);
|
2017-09-12 12:53:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:34:13 +08:00
|
|
|
|
void e2d::EApp::_enterNextScene()
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-10-20 00:59:26 +08:00
|
|
|
|
if (m_pNextScene == nullptr)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2017-10-17 23:50:02 +08:00
|
|
|
|
// ִ<>е<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD> onCloseWindow <20><><EFBFBD><EFBFBD>
|
2017-10-06 16:40:10 +08:00
|
|
|
|
if (m_pCurrentScene)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pCurrentScene->onExit();
|
2017-10-14 18:43:32 +08:00
|
|
|
|
|
|
|
|
|
|
if (m_pCurrentScene->m_bWillSave)
|
2017-10-06 16:40:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><>Ҫ<EFBFBD><D2AA><EFBFBD>浱ǰ<E6B5B1><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB>
|
2017-10-10 01:14:03 +08:00
|
|
|
|
s_SceneStack.push(m_pCurrentScene);
|
2017-10-06 16:40:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-10-31 17:19:13 +08:00
|
|
|
|
SafeRelease(&m_pCurrentScene);
|
2017-10-06 16:40:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-15 23:58:39 +08:00
|
|
|
|
// ִ<><D6B4><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> onEnter <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
m_pNextScene->onEnter();
|
2017-10-14 01:07:34 +08:00
|
|
|
|
|
2017-10-06 16:40:10 +08:00
|
|
|
|
m_pCurrentScene = m_pNextScene; // <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
m_pNextScene = nullptr; // <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD>
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-08 15:37:52 +08:00
|
|
|
|
void e2d::EApp::_updateTime()
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-12-08 15:37:52 +08:00
|
|
|
|
// ˢ<>µ<EFBFBD>ǰʱ<C7B0><CAB1>
|
|
|
|
|
|
GetNow() = steady_clock::now();
|
|
|
|
|
|
// <20><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ͷ<EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
|
EActionManager::_resetAllActions();
|
|
|
|
|
|
ETimerManager::_resetAllTimers();
|
|
|
|
|
|
}
|
2017-10-12 02:44:44 +08:00
|
|
|
|
|
2017-12-08 15:37:52 +08:00
|
|
|
|
LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (s_pInstance == nullptr)
|
2017-09-10 23:56:52 +08:00
|
|
|
|
{
|
2017-12-08 15:37:52 +08:00
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LRESULT result = 0;
|
|
|
|
|
|
|
2017-11-03 22:14:07 +08:00
|
|
|
|
switch (message)
|
2017-10-12 02:44:44 +08:00
|
|
|
|
{
|
2017-11-03 22:14:07 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
|
|
case WM_LBUTTONDBLCLK:
|
|
|
|
|
|
case WM_MBUTTONUP:
|
|
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
|
|
case WM_MBUTTONDBLCLK:
|
|
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
|
|
case WM_RBUTTONDBLCLK:
|
|
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
|
|
{
|
|
|
|
|
|
// ִ<>г<EFBFBD><D0B3><EFBFBD><EFBFBD>л<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
2017-12-09 15:27:11 +08:00
|
|
|
|
if (!s_pInstance->m_pTransition && !s_pInstance->m_pNextScene)
|
2017-10-13 11:42:36 +08:00
|
|
|
|
{
|
2017-11-03 22:14:07 +08:00
|
|
|
|
EMsgManager::MouseProc(message, wParam, lParam);
|
2017-10-13 17:14:00 +08:00
|
|
|
|
}
|
2017-11-03 22:14:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
break;
|
2017-10-13 17:14:00 +08:00
|
|
|
|
|
2017-11-03 22:14:07 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
|
|
case WM_KEYUP:
|
|
|
|
|
|
{
|
|
|
|
|
|
// ִ<>г<EFBFBD><D0B3><EFBFBD><EFBFBD>л<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
2017-12-09 15:27:11 +08:00
|
|
|
|
if (!s_pInstance->m_pTransition && !s_pInstance->m_pNextScene)
|
2017-10-13 17:14:00 +08:00
|
|
|
|
{
|
2017-11-03 22:14:07 +08:00
|
|
|
|
EMsgManager::KeyboardProc(message, wParam, lParam);
|
2017-10-13 11:42:36 +08:00
|
|
|
|
}
|
2017-11-03 22:14:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
break;
|
2017-10-13 11:42:36 +08:00
|
|
|
|
|
2017-11-03 22:14:07 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>С<EFBFBD>仯<EFBFBD><E4BBAF>Ϣ
|
|
|
|
|
|
case WM_SIZE:
|
|
|
|
|
|
{
|
|
|
|
|
|
UINT width = LOWORD(lParam);
|
|
|
|
|
|
UINT height = HIWORD(lParam);
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>һ<EFBFBD><D2BB> WM_SIZE <20><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ
|
|
|
|
|
|
// Ŀ<><C4BF><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܻ<EFBFBD><DCBB><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD>п<EFBFBD><D0BF>ܵ<EFBFBD>
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><CEB5><EFBFBD> EndDraw ʱ<><CAB1><EFBFBD><EFBFBD>
|
|
|
|
|
|
GetRenderTarget()->Resize(D2D1::SizeU(width, height));
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
2017-10-12 02:44:44 +08:00
|
|
|
|
|
2017-11-03 22:14:07 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ʱ仯<CAB1><E4BBAF>Ϣ
|
|
|
|
|
|
case WM_DISPLAYCHANGE:
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20>ػ<EFBFBD><D8BB>ͻ<EFBFBD><CDBB><EFBFBD>
|
|
|
|
|
|
InvalidateRect(hWnd, NULL, FALSE);
|
|
|
|
|
|
}
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
break;
|
2017-10-12 02:44:44 +08:00
|
|
|
|
|
2017-11-03 22:14:07 +08:00
|
|
|
|
// <20>ػ洰<D8BB><E6B4B0>
|
|
|
|
|
|
case WM_PAINT:
|
|
|
|
|
|
{
|
2017-12-08 15:37:52 +08:00
|
|
|
|
s_pInstance->_render();
|
2017-11-03 22:14:07 +08:00
|
|
|
|
ValidateRect(hWnd, NULL);
|
|
|
|
|
|
}
|
|
|
|
|
|
result = 0;
|
|
|
|
|
|
break;
|
2017-10-12 02:44:44 +08:00
|
|
|
|
|
2017-11-03 22:14:07 +08:00
|
|
|
|
// <20><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
|
case WM_ACTIVATE:
|
|
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
EScene * pCurrentScene = s_pInstance->getCurrentScene();
|
|
|
|
|
|
|
2017-11-03 22:14:07 +08:00
|
|
|
|
if (LOWORD(wParam) == WA_INACTIVE)
|
2017-10-17 23:50:02 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
if (pCurrentScene &&
|
|
|
|
|
|
pCurrentScene->onInactive() &&
|
2017-12-08 15:37:52 +08:00
|
|
|
|
s_pInstance->onInactive())
|
2017-10-17 23:50:02 +08:00
|
|
|
|
{
|
2017-12-08 15:37:52 +08:00
|
|
|
|
s_pInstance->m_bPaused = true;
|
2017-10-17 23:50:02 +08:00
|
|
|
|
}
|
2017-11-03 22:14:07 +08:00
|
|
|
|
}
|
2017-12-08 15:37:52 +08:00
|
|
|
|
else if (s_pInstance->m_bPaused)
|
2017-11-03 22:14:07 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
if (pCurrentScene &&
|
|
|
|
|
|
pCurrentScene->onActivate() &&
|
2017-12-08 15:37:52 +08:00
|
|
|
|
s_pInstance->onActivate())
|
2017-10-17 23:50:02 +08:00
|
|
|
|
{
|
2017-12-08 15:37:52 +08:00
|
|
|
|
s_pInstance->m_bPaused = false;
|
|
|
|
|
|
if (!s_pInstance->m_bManualPaused)
|
|
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
s_pInstance->_updateTime();
|
2017-12-08 15:37:52 +08:00
|
|
|
|
}
|
2017-10-17 23:50:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-11-03 22:14:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
result = 1;
|
|
|
|
|
|
break;
|
2017-10-17 23:50:02 +08:00
|
|
|
|
|
2017-11-03 22:14:07 +08:00
|
|
|
|
// <20><><EFBFBD>ڹر<DAB9><D8B1><EFBFBD>Ϣ
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
EScene * pCurrentScene = s_pInstance->getCurrentScene();
|
|
|
|
|
|
|
|
|
|
|
|
if (pCurrentScene)
|
2017-10-12 02:44:44 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
if (pCurrentScene->onCloseWindow() &&
|
|
|
|
|
|
s_pInstance->onCloseWindow())
|
2017-10-21 19:09:31 +08:00
|
|
|
|
{
|
2017-11-03 22:14:07 +08:00
|
|
|
|
DestroyWindow(hWnd);
|
2017-10-14 01:07:34 +08:00
|
|
|
|
}
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|
2017-11-03 22:14:07 +08:00
|
|
|
|
else
|
2017-10-17 21:22:25 +08:00
|
|
|
|
{
|
2017-12-08 19:50:59 +08:00
|
|
|
|
if (s_pInstance->onCloseWindow())
|
2017-11-03 22:14:07 +08:00
|
|
|
|
{
|
|
|
|
|
|
DestroyWindow(hWnd);
|
|
|
|
|
|
}
|
2017-10-12 02:44:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-11-03 22:14:07 +08:00
|
|
|
|
result = 1;
|
|
|
|
|
|
break;
|
2017-10-12 02:44:44 +08:00
|
|
|
|
|
2017-11-03 22:14:07 +08:00
|
|
|
|
// <20><><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
case WM_DESTROY:
|
2017-10-12 02:44:44 +08:00
|
|
|
|
{
|
2017-11-03 22:14:07 +08:00
|
|
|
|
// <20>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>
|
2017-12-08 15:37:52 +08:00
|
|
|
|
s_pInstance->quit();
|
2017-11-03 22:14:07 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD>Ϣ
|
|
|
|
|
|
PostQuitMessage(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
result = 1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
2017-10-13 11:42:36 +08:00
|
|
|
|
result = DefWindowProc(hWnd, message, wParam, lParam);
|
2017-10-12 02:44:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-08 15:37:52 +08:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
2017-09-10 23:56:52 +08:00
|
|
|
|
}
|