| 
									
										
										
										
											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-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
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | e2d::EApp::EApp() | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	: m_bEnd(false) | 
					
						
							|  |  |  |  | 	, m_bPaused(false) | 
					
						
							|  |  |  |  | 	, m_bManualPaused(false) | 
					
						
							|  |  |  |  | 	, m_bTransitional(false) | 
					
						
							|  |  |  |  | 	, m_bTopMost(false) | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 	, m_bShowConsole(false) | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 	, nAnimationInterval(17LL) | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  |  | 	, m_ClearColor(EColor::BLACK) | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 	, m_pCurrentScene(nullptr) | 
					
						
							|  |  |  |  | 	, m_pNextScene(nullptr) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 	ASSERT(s_pInstance == nullptr, "EApp instance already exists!"); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	s_pInstance = this;		// <20><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 	CoInitialize(NULL); | 
					
						
							| 
									
										
										
										
											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-17 21:22:25 +08:00
										 |  |  |  | 	// <20>ͷ<EFBFBD><CDB7><EFBFBD>Դ
 | 
					
						
							| 
									
										
										
										
											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-10-17 21:22:25 +08:00
										 |  |  |  | 	CoUninitialize(); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 23:34:13 +08:00
										 |  |  |  | e2d::EApp * e2d::EApp::get() | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-14 01:07:34 +08:00
										 |  |  |  | 	ASSERT(s_pInstance != nullptr, "Nonexistent EApp instance."); | 
					
						
							| 
									
										
										
										
											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-10-31 17:19:13 +08:00
										 |  |  |  | bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 	return init(title, width, height, EWindowStyle()); | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-10-15 02:46:24 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height, EWindowStyle wStyle) | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	HRESULT hr; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-10-24 09:27:15 +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><E6B4B0><EFBFBD>Ƿ<EFBFBD><C7B7>ö<EFBFBD><C3B6><EFBFBD>ʾ
 | 
					
						
							|  |  |  |  | 	m_bTopMost = wStyle.m_bTopMost; | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD>洰<EFBFBD><E6B4B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	m_sTitle = title; | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	GetHWnd() = CreateWindow( | 
					
						
							|  |  |  |  | 		L"Easy2DApp", | 
					
						
							|  |  |  |  | 		m_sTitle.c_str(), | 
					
						
							|  |  |  |  | 		dwStyle, | 
					
						
							|  |  |  |  | 		0, | 
					
						
							|  |  |  |  | 		0, | 
					
						
							|  |  |  |  | 		width, | 
					
						
							|  |  |  |  | 		height, | 
					
						
							|  |  |  |  | 		NULL, | 
					
						
							|  |  |  |  | 		NULL, | 
					
						
							|  |  |  |  | 		HINST_THISCOMPONENT, | 
					
						
							|  |  |  |  | 		this | 
					
						
							|  |  |  |  | 	); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	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>뷨
 | 
					
						
							|  |  |  |  | 		this->setKeyboardLayoutEnable(false); | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>С
 | 
					
						
							|  |  |  |  | 		this->setWindowSize(width, height); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		UnregisterClass(L"E2DApp", 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-10-20 00:59:26 +08:00
										 |  |  |  | void e2d::EApp::pause() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	EApp::get()->m_bManualPaused = true; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::EApp::resume() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	if (isPaused()) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		EApp::get()->m_bPaused = false; | 
					
						
							|  |  |  |  | 		EApp::get()->m_bManualPaused = false; | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  |  | 		// ˢ<>µ<EFBFBD>ǰʱ<C7B0><CAB1>
 | 
					
						
							|  |  |  |  | 		GetNow() = steady_clock::now(); | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD><EFBFBD>Ͷ<EFBFBD>ʱ<EFBFBD><CAB1>
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 		EActionManager::_resetAllActions(); | 
					
						
							|  |  |  |  | 		ETimerManager::_resetAllTimers(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | bool e2d::EApp::isPaused() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	return s_pInstance->m_bPaused || s_pInstance->m_bManualPaused; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	EApp::get()->m_bShowConsole = show; | 
					
						
							|  |  |  |  | 	// <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-12 02:44:44 +08:00
										 |  |  |  | // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ
 | 
					
						
							|  |  |  |  | void e2d::EApp::run() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 	ASSERT(GetHWnd() != nullptr, "Cannot find Game Window."); | 
					
						
							| 
									
										
										
										
											2017-10-13 11:42:36 +08:00
										 |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	_enterNextScene(); | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 	// <20>رտ<D8B1><D5BF><EFBFBD>̨
 | 
					
						
							|  |  |  |  | 	if (!m_bShowConsole) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		showConsole(false); | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 	// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	ShowWindow(GetHWnd(), SW_SHOWNORMAL); | 
					
						
							|  |  |  |  | 	UpdateWindow(GetHWnd()); | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	// <20><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD>ö<EFBFBD>
 | 
					
						
							|  |  |  |  | 	if (m_bTopMost) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		SetWindowPos(GetHWnd(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-17 23:50:02 +08:00
										 |  |  |  | 	// <20><>¼<EFBFBD><C2BC>ʼʱ<CABC><CAB1>
 | 
					
						
							|  |  |  |  | 	s_tStart = steady_clock::now(); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 	MSG msg; | 
					
						
							| 
									
										
										
										
											2017-10-10 01:14:03 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	while (!m_bEnd) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							|  |  |  |  | 		while (PeekMessage(&msg, GetHWnd(), 0, 0, PM_REMOVE)) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 			TranslateMessage(&msg); | 
					
						
							|  |  |  |  | 			DispatchMessage(&msg); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 		// ִ<><D6B4><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>
 | 
					
						
							|  |  |  |  | 		_mainLoop(); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-15 02:46:24 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 	// <20>رտ<D8B1><D5BF><EFBFBD>̨
 | 
					
						
							|  |  |  |  | 	EApp::showConsole(false); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::EApp::setFPS(UINT32 fps) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	fps = min(max(fps, 30), 120); | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	s_pInstance->nAnimationInterval = 1000 / fps; | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | bool e2d::EApp::onActivate() | 
					
						
							| 
									
										
										
										
											2017-10-17 23:50:02 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											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-10-18 22:13:20 +08:00
										 |  |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											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
										 |  |  |  | 	// ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	static LONGLONG nInterval = 0LL; | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
 | 
					
						
							|  |  |  |  | 	static LONGLONG nWaitMS = 0L; | 
					
						
							| 
									
										
										
										
											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>㹻
 | 
					
						
							|  |  |  |  | 	if (nInterval >= nAnimationInterval) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-18 01:15:25 +08:00
										 |  |  |  | 		// <20><>¼<EFBFBD><C2BC>ǰʱ<C7B0><CAB1>
 | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  |  | 		tLast += microseconds(nAnimationInterval); | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 		// <20><>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		_onControl(); | 
					
						
							|  |  |  |  | 		// ˢ<><CBA2><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		_onRender(); | 
					
						
							| 
									
										
										
										
											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>
 | 
					
						
							|  |  |  |  | 		nWaitMS = nAnimationInterval - nInterval - 1; | 
					
						
							|  |  |  |  | 		// <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-10-12 02:44:44 +08:00
										 |  |  |  | void e2d::EApp::_onControl() | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											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>
 | 
					
						
							|  |  |  |  | 	if (m_bTransitional) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  |  | 		EActionManager::ActionProc(); | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
 | 
					
						
							|  |  |  |  | 		if (m_bTransitional) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			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-10-20 00:59:26 +08:00
										 |  |  |  | void e2d::EApp::_onRender() | 
					
						
							| 
									
										
										
										
											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-10-31 17:19:13 +08:00
										 |  |  |  | 		m_pCurrentScene->_onRender(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	// <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	if (m_bTransitional && m_pNextScene) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		m_pNextScene->_onRender(); | 
					
						
							| 
									
										
										
										
											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>
 | 
					
						
							|  |  |  |  | 	SetWindowText(GetHWnd(), title.c_str()); | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD>浱ǰ<E6B5B1><C7B0><EFBFBD>⣬<EFBFBD><E2A3AC><EFBFBD><EFBFBD><EFBFBD>Ĵ<DEB8><C4B4>ڴ<EFBFBD>Сʱ<D0A1>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-10-14 01:07:34 +08:00
										 |  |  |  | 	get()->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-10-14 01:07:34 +08:00
										 |  |  |  | 	return get()->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-10-20 00:59:26 +08:00
										 |  |  |  | void e2d::EApp::enterScene(EScene * scene, bool saveCurrentScene /* = true */) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	enterScene(scene, nullptr, saveCurrentScene); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::EApp::enterScene(EScene * scene, ETransition * transition, bool saveCurrentScene /* = true */) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	scene->retain(); | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
 | 
					
						
							| 
									
										
										
										
											2017-10-14 01:07:34 +08:00
										 |  |  |  | 	get()->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-10-14 18:43:32 +08:00
										 |  |  |  | 	if (get()->m_pCurrentScene) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 		get()->m_pCurrentScene->m_bWillSave = saveCurrentScene; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	if (transition) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		get()->m_bTransitional = true; | 
					
						
							|  |  |  |  | 		transition->_setTarget( | 
					
						
							|  |  |  |  | 			get()->m_pCurrentScene,  | 
					
						
							|  |  |  |  | 			get()->m_pNextScene,  | 
					
						
							|  |  |  |  | 			get()->m_bTransitional | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		get()->m_bTransitional = false; | 
					
						
							| 
									
										
										
										
											2017-10-14 18:43:32 +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-10-14 01:07:34 +08:00
										 |  |  |  | 	get()->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-10-14 18:43:32 +08:00
										 |  |  |  | 	if (get()->m_pCurrentScene) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		get()->m_pCurrentScene->m_bWillSave = false; | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		get()->m_bTransitional = true; | 
					
						
							|  |  |  |  | 		transition->_setTarget( | 
					
						
							|  |  |  |  | 			get()->m_pCurrentScene,  | 
					
						
							|  |  |  |  | 			get()->m_pNextScene,  | 
					
						
							|  |  |  |  | 			get()->m_bTransitional | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ false<73><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡<D2BB><D6A1><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 		get()->m_bTransitional = false; | 
					
						
							|  |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											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-10-12 23:34:13 +08:00
										 |  |  |  | e2d::EScene * e2d::EApp::getCurrentScene() | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-14 01:07:34 +08:00
										 |  |  |  | 	return get()->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-10-31 17:19:13 +08:00
										 |  |  |  | 	get()->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-10-31 17:19:13 +08:00
										 |  |  |  | 	if (get()->m_sAppName.empty()) | 
					
						
							|  |  |  |  | 		get()->m_sAppName = get()->m_sTitle; | 
					
						
							|  |  |  |  | 	return get()->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-10-14 01:07:34 +08:00
										 |  |  |  | 	get()->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-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::quit() | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 	get()->m_bEnd = true; | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 23:34:13 +08:00
										 |  |  |  | void e2d::EApp::end() | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 	EApp::quit(); | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +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-10-12 02:44:44 +08:00
										 |  |  |  | LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 	// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 	LRESULT result = 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (message == WM_CREATE) | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 		// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> WM_CREATE <20><>Ϣ<EFBFBD><CFA2> EApp ʵ<><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
 | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 		LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam; | 
					
						
							| 
									
										
										
										
											2017-10-13 11:42:36 +08:00
										 |  |  |  | 		e2d::EApp *pEApp = (e2d::EApp *)pcs->lpCreateParams; | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 		// <20><><EFBFBD><EFBFBD> EApp ָ<>뵽 GWLP_USERDATA <20>ֶ<EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 		::SetWindowLongPtrW( | 
					
						
							| 
									
										
										
										
											2017-10-13 11:42:36 +08:00
										 |  |  |  | 			hWnd, | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 			GWLP_USERDATA, | 
					
						
							|  |  |  |  | 			PtrToUlong(pEApp) | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		result = 1; | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 		// <20><> GWLP_USERDATA <20>ֶ<EFBFBD>ȡ<EFBFBD><C8A1> EApp ָ<><D6B8>
 | 
					
						
							| 
									
										
										
										
											2017-10-13 11:42:36 +08:00
										 |  |  |  | 		e2d::EApp *pEApp = reinterpret_cast<e2d::EApp *>(static_cast<LONG_PTR>( | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 			::GetWindowLongPtrW( | 
					
						
							| 
									
										
										
										
											2017-10-13 11:42:36 +08:00
										 |  |  |  | 				hWnd, | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 				GWLP_USERDATA | 
					
						
							|  |  |  |  | 			))); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		bool wasHandled = false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		if (pEApp) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 			switch (message) | 
					
						
							|  |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 			// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							| 
									
										
										
										
											2017-10-13 11:42:36 +08:00
										 |  |  |  | 			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: | 
					
						
							|  |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 				// ִ<>г<EFBFBD><D0B3><EFBFBD><EFBFBD>л<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  |  | 				if (!pEApp->m_bTransitional && !pEApp->m_pNextScene) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 				{ | 
					
						
							|  |  |  |  | 					EMsgManager::MouseProc(message, wParam, lParam); | 
					
						
							|  |  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-10-13 17:14:00 +08:00
										 |  |  |  | 			} | 
					
						
							|  |  |  |  | 			result = 0; | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 			wasHandled = true; | 
					
						
							| 
									
										
										
										
											2017-10-13 17:14:00 +08:00
										 |  |  |  | 			break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 			// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							| 
									
										
										
										
											2017-10-13 17:14:00 +08:00
										 |  |  |  | 			case WM_KEYDOWN: | 
					
						
							|  |  |  |  | 			case WM_KEYUP: | 
					
						
							|  |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 				// ִ<>г<EFBFBD><D0B3><EFBFBD><EFBFBD>л<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ΰ<EFBFBD><CEB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  |  | 				if (!pEApp->m_bTransitional && !pEApp->m_pNextScene) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 				{ | 
					
						
							|  |  |  |  | 					EMsgManager::KeyboardProc(message, wParam, lParam); | 
					
						
							|  |  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-10-13 11:42:36 +08:00
										 |  |  |  | 			} | 
					
						
							|  |  |  |  | 			result = 0; | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 			wasHandled = true; | 
					
						
							| 
									
										
										
										
											2017-10-13 11:42:36 +08:00
										 |  |  |  | 			break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 			// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>С<EFBFBD>仯<EFBFBD><E4BBAF>Ϣ
 | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 			case WM_SIZE: | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				UINT width = LOWORD(lParam); | 
					
						
							|  |  |  |  | 				UINT height = HIWORD(lParam); | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 				// <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)); | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 			} | 
					
						
							|  |  |  |  | 			result = 0; | 
					
						
							|  |  |  |  | 			wasHandled = true; | 
					
						
							|  |  |  |  | 			break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 			// <20><><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ʱ仯<CAB1><E4BBAF>Ϣ
 | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 			case WM_DISPLAYCHANGE: | 
					
						
							|  |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 				// <20>ػ<EFBFBD><D8BB>ͻ<EFBFBD><CDBB><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-10-13 11:42:36 +08:00
										 |  |  |  | 				InvalidateRect(hWnd, NULL, FALSE); | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 			} | 
					
						
							|  |  |  |  | 			result = 0; | 
					
						
							|  |  |  |  | 			wasHandled = true; | 
					
						
							|  |  |  |  | 			break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 			// <20>ػ洰<D8BB><E6B4B0>
 | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 			case WM_PAINT: | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				pEApp->_onRender(); | 
					
						
							| 
									
										
										
										
											2017-10-13 11:42:36 +08:00
										 |  |  |  | 				ValidateRect(hWnd, NULL); | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 			} | 
					
						
							|  |  |  |  | 			result = 0; | 
					
						
							|  |  |  |  | 			wasHandled = true; | 
					
						
							|  |  |  |  | 			break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 23:50:02 +08:00
										 |  |  |  | 			// <20><><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD>Ϣ
 | 
					
						
							|  |  |  |  | 			case WM_ACTIVATE: | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				if (LOWORD(wParam) == WA_INACTIVE) | 
					
						
							|  |  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  |  | 					if (pEApp->getCurrentScene() &&  | 
					
						
							|  |  |  |  | 						pEApp->getCurrentScene()->onInactive() && | 
					
						
							| 
									
										
										
										
											2017-10-18 22:13:20 +08:00
										 |  |  |  | 						pEApp->onInactive()) | 
					
						
							|  |  |  |  | 					{ | 
					
						
							|  |  |  |  | 						pEApp->m_bPaused = true; | 
					
						
							|  |  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-10-17 23:50:02 +08:00
										 |  |  |  | 				} | 
					
						
							|  |  |  |  | 				else | 
					
						
							|  |  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  |  | 					if (pEApp->getCurrentScene() &&  | 
					
						
							|  |  |  |  | 						pEApp->getCurrentScene()->onActivate() && | 
					
						
							| 
									
										
										
										
											2017-10-20 00:59:26 +08:00
										 |  |  |  | 						pEApp->onActivate()) | 
					
						
							|  |  |  |  | 					{ | 
					
						
							|  |  |  |  | 						pEApp->m_bPaused = false; | 
					
						
							|  |  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-10-17 23:50:02 +08:00
										 |  |  |  | 				} | 
					
						
							|  |  |  |  | 			} | 
					
						
							|  |  |  |  | 			result = 1; | 
					
						
							|  |  |  |  | 			wasHandled = true; | 
					
						
							|  |  |  |  | 			break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 			// <20><><EFBFBD>ڹر<DAB9><D8B1><EFBFBD>Ϣ
 | 
					
						
							|  |  |  |  | 			case WM_CLOSE: | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  |  | 				if (!pEApp->getCurrentScene()) | 
					
						
							| 
									
										
										
										
											2017-10-14 01:07:34 +08:00
										 |  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2017-10-21 19:09:31 +08:00
										 |  |  |  | 					if (pEApp->onCloseWindow()) | 
					
						
							|  |  |  |  | 					{ | 
					
						
							|  |  |  |  | 						DestroyWindow(hWnd); | 
					
						
							|  |  |  |  | 					} | 
					
						
							|  |  |  |  | 				} | 
					
						
							|  |  |  |  | 				else  | 
					
						
							|  |  |  |  | 				{ | 
					
						
							|  |  |  |  | 					if (pEApp->getCurrentScene()->onCloseWindow() && | 
					
						
							|  |  |  |  | 						pEApp->onCloseWindow()) | 
					
						
							|  |  |  |  | 					{ | 
					
						
							|  |  |  |  | 						DestroyWindow(hWnd); | 
					
						
							|  |  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-10-14 01:07:34 +08:00
										 |  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-10-17 21:22:25 +08:00
										 |  |  |  | 			} | 
					
						
							|  |  |  |  | 			result = 1; | 
					
						
							|  |  |  |  | 			wasHandled = true; | 
					
						
							|  |  |  |  | 			break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			// <20><><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 			case WM_DESTROY: | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				// <20>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 				pEApp->quit(); | 
					
						
							|  |  |  |  | 				// <20><><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3><EFBFBD>Ϣ
 | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 				PostQuitMessage(0); | 
					
						
							|  |  |  |  | 			} | 
					
						
							|  |  |  |  | 			result = 1; | 
					
						
							|  |  |  |  | 			wasHandled = true; | 
					
						
							|  |  |  |  | 			break; | 
					
						
							|  |  |  |  | 			} | 
					
						
							|  |  |  |  | 		} | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-31 17:19:13 +08:00
										 |  |  |  | 		// <20>Ե<EFBFBD>ǰ<EFBFBD><C7B0>Ϣû<CFA2><C3BB><EFBFBD>ض<EFBFBD><D8B6>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ִ<EFBFBD><D6B4>Ĭ<EFBFBD>ϵĴ<CFB5><C4B4>ں<EFBFBD><DABA><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 		if (!wasHandled) | 
					
						
							|  |  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-10-13 11:42:36 +08:00
										 |  |  |  | 			result = DefWindowProc(hWnd, message, wParam, lParam); | 
					
						
							| 
									
										
										
										
											2017-10-12 02:44:44 +08:00
										 |  |  |  | 		} | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	return result; | 
					
						
							| 
									
										
										
										
											2017-09-10 23:56:52 +08:00
										 |  |  |  | } |