Magic_Game/core/modules/Game.cpp

625 lines
12 KiB
C++
Raw Normal View History

2018-10-03 22:02:46 +08:00
// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
2018-09-05 13:17:07 +08:00
#include "..\e2dmodule.h"
2018-09-06 23:26:32 +08:00
#include "..\e2dobject.h"
2018-10-03 18:04:04 +08:00
#include "..\e2dtool.h"
2018-08-15 23:30:23 +08:00
#include "..\e2dtransition.h"
#include <thread>
2018-09-30 14:54:43 +08:00
#include <imm.h>
#pragma comment (lib ,"imm32.lib")
2018-09-30 14:54:43 +08:00
#define WINDOW_STYLE WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME
#define REGISTER_CLASS L"Easy2DApp"
2018-01-30 16:45:38 +08:00
2018-08-28 00:06:10 +08:00
2018-10-16 14:13:15 +08:00
static easy2d::Game * instance = nullptr;
2018-08-28 00:06:10 +08:00
2018-10-16 14:13:15 +08:00
easy2d::Game * easy2d::Game::GetInstance()
2018-10-06 11:15:32 +08:00
{
return instance;
}
2018-10-16 14:13:15 +08:00
easy2d::Game::Game()
2018-09-30 14:54:43 +08:00
: hwnd_(nullptr)
, quit_(true)
2018-09-04 22:42:34 +08:00
, curr_scene_(nullptr)
, next_scene_(nullptr)
, transition_(nullptr)
2018-10-03 18:04:04 +08:00
, title_(L"Easy2D Game")
, width_(640)
, height_(480)
, icon_(0)
, debug_mode_(false)
2018-07-03 01:49:20 +08:00
{
2018-10-03 18:04:04 +08:00
if (instance)
{
throw RuntimeException("ͬʱֻ<EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸʵ<EFBFBD><EFBFBD>");
}
instance = this;
::CoInitialize(nullptr);
2018-07-03 01:49:20 +08:00
}
2018-10-16 14:13:15 +08:00
easy2d::Game::~Game()
{
2018-09-07 00:28:54 +08:00
SafeRelease(transition_);
SafeRelease(curr_scene_);
SafeRelease(next_scene_);
2018-10-03 18:04:04 +08:00
Image::ClearCache();
2018-10-06 10:25:29 +08:00
Player::ClearCache();
2018-10-03 18:04:04 +08:00
Device::Destroy();
2018-09-30 14:54:43 +08:00
if (hwnd_)
{
::DestroyWindow(hwnd_);
}
2018-10-03 18:04:04 +08:00
instance = nullptr;
::CoUninitialize();
}
2018-10-16 14:13:15 +08:00
void easy2d::Game::Run(const Options& options)
2018-09-30 14:54:43 +08:00
{
2018-10-03 18:04:04 +08:00
title_ = options.title;
width_ = options.width;
height_ = options.height;
icon_ = options.icon;
debug_mode_ = options.debug_mode;
2018-09-30 14:54:43 +08:00
2018-10-03 18:04:04 +08:00
// <20><>ʼ<EFBFBD><CABC>
Init();
2018-09-30 14:54:43 +08:00
2018-10-03 18:04:04 +08:00
// <20><>ʼ
Start();
2018-09-30 14:54:43 +08:00
2018-10-03 18:04:04 +08:00
// ˢ<>³<EFBFBD><C2B3><EFBFBD>
if (next_scene_)
{
next_scene_->OnEnter();
curr_scene_ = next_scene_;
next_scene_ = nullptr;
}
2018-10-03 18:04:04 +08:00
::ShowWindow(hwnd_, SW_SHOWNORMAL);
::UpdateWindow(hwnd_);
2018-10-03 18:04:04 +08:00
// <20><><EFBFBD><EFBFBD>
2018-09-30 14:54:43 +08:00
const int min_interval = 5;
2018-09-04 22:42:34 +08:00
Time last = Time::Now();
2018-09-30 14:54:43 +08:00
MSG msg = { 0 };
2018-08-02 00:27:45 +08:00
2018-09-04 22:42:34 +08:00
while (!quit_)
2018-01-30 16:45:38 +08:00
{
2018-09-04 22:42:34 +08:00
auto now = Time::Now();
2018-08-02 00:27:45 +08:00
auto dur = now - last;
2018-01-30 16:45:38 +08:00
2018-09-30 14:54:43 +08:00
if (dur.Milliseconds() > min_interval)
2018-01-30 16:45:38 +08:00
{
2018-10-06 09:45:28 +08:00
float dt = (now - last).Seconds();
2018-08-02 00:27:45 +08:00
last = now;
2018-08-19 15:11:20 +08:00
2018-10-06 09:45:28 +08:00
Device::GetInput()->Flush();
Update(dt);
UpdateScene(dt);
2018-09-04 22:42:34 +08:00
DrawScene();
2018-09-07 23:47:21 +08:00
2018-09-30 14:54:43 +08:00
while (::PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
2018-01-30 16:45:38 +08:00
}
else
{
// ID2D1HwndRenderTarget <20><><EFBFBD><EFBFBD><EFBFBD>˴<EFBFBD>ֱͬ<D6B1><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦʱ<C8BE><CAB1><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>ʾ<EFBFBD><CABE>ˢ<EFBFBD>£<EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˷dz<CBB7><C7B3>ȶ<EFBFBD><C8B6><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>Դ󲿷<D4B4>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳̽<DFB3><CCBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
// <20><><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һЩ<D2BB><D0A9><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><E7B4B0><EFBFBD><EFBFBD>С<EFBFBD><D0A1>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣߳<DFB3><CCA3><EFBFBD>ֹռ<D6B9>ù<EFBFBD><C3B9><EFBFBD> CPU <20><>
2018-09-30 14:54:43 +08:00
int wait = min_interval - dur.Milliseconds();
if (wait > 1)
{
std::this_thread::sleep_for(std::chrono::milliseconds(wait));
}
2018-01-30 16:45:38 +08:00
}
}
}
2018-10-16 14:13:15 +08:00
void easy2d::Game::Quit()
2018-01-30 16:45:38 +08:00
{
2018-09-04 22:42:34 +08:00
quit_ = true;
2018-01-30 16:45:38 +08:00
}
2018-10-16 14:13:15 +08:00
void easy2d::Game::EnterScene(Scene * scene, Transition * transition)
2018-01-30 16:45:38 +08:00
{
2018-09-10 15:28:19 +08:00
if (scene == nullptr)
{
E2D_WARNING("Next scene is null pointer!");
2018-08-15 23:30:23 +08:00
return;
2018-09-10 15:28:19 +08:00
}
if (next_scene_ != nullptr)
{
E2D_WARNING("Scene is transitioning...");
2018-09-10 15:28:19 +08:00
return;
}
2018-08-15 23:30:23 +08:00
2018-09-07 00:28:54 +08:00
if (next_scene_)
{
next_scene_->Release();
}
2018-09-04 22:42:34 +08:00
next_scene_ = scene;
next_scene_->Retain();
2018-08-15 23:30:23 +08:00
2018-09-10 15:28:19 +08:00
if (transition)
2018-08-15 23:30:23 +08:00
{
2018-09-10 15:28:19 +08:00
if (transition_)
{
transition_->Stop();
transition_->Release();
}
transition_ = transition;
transition_->Retain();
2018-08-15 23:30:23 +08:00
2018-10-03 18:04:04 +08:00
transition_->Init(curr_scene_, next_scene_, this);
2018-08-15 23:30:23 +08:00
}
}
2018-10-16 14:13:15 +08:00
easy2d::Scene * easy2d::Game::GetCurrentScene()
2018-08-15 23:30:23 +08:00
{
2018-09-04 22:42:34 +08:00
return curr_scene_;
2018-08-15 23:30:23 +08:00
}
2018-10-16 14:13:15 +08:00
bool easy2d::Game::IsTransitioning() const
2018-08-15 23:30:23 +08:00
{
2018-09-04 22:42:34 +08:00
return transition_ != nullptr;
2018-08-15 23:30:23 +08:00
}
2018-10-16 14:13:15 +08:00
void easy2d::Game::UpdateScene(float dt)
2018-08-15 23:30:23 +08:00
{
auto update = [&](Scene * scene) -> void
2018-10-06 09:45:28 +08:00
{
if (scene)
{
scene->Update(dt);
Node * root = scene->GetRoot();
if (root)
{
root->UpdateChildren(dt);
}
}
};
2018-10-06 09:45:28 +08:00
update(curr_scene_);
update(next_scene_);
2018-10-06 09:45:28 +08:00
2018-09-04 22:42:34 +08:00
if (transition_)
2018-08-15 23:30:23 +08:00
{
2018-09-04 22:42:34 +08:00
transition_->Update();
2018-08-15 23:30:23 +08:00
2018-09-04 22:42:34 +08:00
if (transition_->IsDone())
2018-08-15 23:30:23 +08:00
{
2018-09-04 22:42:34 +08:00
transition_->Release();
transition_ = nullptr;
2018-08-15 23:30:23 +08:00
}
else
{
return;
}
}
if (next_scene_)
{
if (curr_scene_)
{
curr_scene_->OnExit();
curr_scene_->Release();
}
next_scene_->OnEnter();
curr_scene_ = next_scene_;
next_scene_ = nullptr;
}
2018-08-15 23:30:23 +08:00
}
2018-10-16 14:13:15 +08:00
void easy2d::Game::DrawScene()
2018-08-15 23:30:23 +08:00
{
2018-10-03 18:04:04 +08:00
auto graphics = Device::GetGraphics();
2018-09-30 14:54:43 +08:00
graphics->BeginDraw();
if (transition_)
2018-08-15 23:30:23 +08:00
{
2018-09-30 14:54:43 +08:00
transition_->Draw();
}
else if (curr_scene_)
{
curr_scene_->Draw();
}
if (debug_mode_)
{
2018-10-03 18:04:04 +08:00
if (curr_scene_ && curr_scene_->GetRoot())
{
graphics->GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
graphics->GetSolidBrush()->SetOpacity(1.f);
curr_scene_->GetRoot()->DrawBorder();
}
if (next_scene_ && next_scene_->GetRoot())
{
graphics->GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
graphics->GetSolidBrush()->SetOpacity(1.f);
next_scene_->GetRoot()->DrawBorder();
}
2018-09-30 14:54:43 +08:00
graphics->DrawDebugInfo();
}
graphics->EndDraw();
}
2018-10-16 14:13:15 +08:00
void easy2d::Game::Init()
2018-09-30 14:54:43 +08:00
{
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpszClassName = REGISTER_CLASS;
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wcex.lpfnWndProc = Game::WndProc;
wcex.hIcon = nullptr;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = sizeof(LONG_PTR);
wcex.hInstance = HINST_THISCOMPONENT;
wcex.hbrBackground = nullptr;
wcex.lpszMenuName = nullptr;
wcex.hCursor = ::LoadCursor(nullptr, IDC_ARROW);
if (icon_ != 0)
{
wcex.hIcon = (HICON)::LoadImage(
HINST_THISCOMPONENT,
MAKEINTRESOURCE(icon_),
IMAGE_ICON,
0,
0,
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE
);
}
// ע<><EFBFBD><E1B4B0><EFBFBD><EFBFBD>
::RegisterClassEx(&wcex);
2018-09-30 14:54:43 +08:00
// <20><><EFBFBD><EFBFBD>ڴ<EFBFBD>С
Rect client_rect = Locate(width_, height_);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
hwnd_ = ::CreateWindowEx(
NULL,
REGISTER_CLASS,
(LPCTSTR)title_,
WINDOW_STYLE,
int(client_rect.origin.x),
int(client_rect.origin.y),
int(client_rect.size.width),
int(client_rect.size.height),
nullptr,
nullptr,
HINST_THISCOMPONENT,
this
);
2018-10-03 18:04:04 +08:00
if (hwnd_ == nullptr)
2018-09-30 14:54:43 +08:00
{
2018-10-03 18:04:04 +08:00
::UnregisterClass(REGISTER_CLASS, HINST_THISCOMPONENT);
throw RuntimeException("Create window failed");
return;
}
::SetWindowLongPtrW(
hwnd_,
GWLP_USERDATA,
PtrToUlong(this)
);
2018-10-03 18:04:04 +08:00
// <20><>ʼ<EFBFBD><CABC><EFBFBD>
Device::Init(hwnd_);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
::ImmAssociateContext(hwnd_, nullptr);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD>ģʽ<C4A3><CABD><EFBFBD>򿪿<EFBFBD><F2BFAABF><EFBFBD>̨
HWND console = ::GetConsoleWindow();
// <20>رտ<D8B1><D5BF><EFBFBD>̨
if (debug_mode_)
{
if (console)
2018-09-30 14:54:43 +08:00
{
2018-10-03 18:04:04 +08:00
::ShowWindow(console, SW_SHOWNORMAL);
}
else
{
// <20><>ʾһ<CABE><D2BB><EFBFBD>¿<EFBFBD><C2BF><EFBFBD>̨
if (::AllocConsole())
{
console = ::GetConsoleWindow();
// <20>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FILE * stdoutStream, *stdinStream, *stderrStream;
freopen_s(&stdoutStream, "conout$", "w+t", stdout);
freopen_s(&stdinStream, "conin$", "r+t", stdin);
freopen_s(&stderrStream, "conout$", "w+t", stderr);
// <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>̨<EFBFBD>رհ<D8B1>ť
HMENU hmenu = ::GetSystemMenu(console, FALSE);
::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
}
2018-09-30 14:54:43 +08:00
}
}
else
{
2018-10-03 18:04:04 +08:00
if (console)
{
::ShowWindow(console, SW_HIDE);
}
2018-09-30 14:54:43 +08:00
}
2018-10-03 18:04:04 +08:00
quit_ = false;
2018-09-30 14:54:43 +08:00
}
2018-10-16 14:13:15 +08:00
easy2d::Rect easy2d::Game::Locate(int width, int height)
2018-09-30 14:54:43 +08:00
{
int max_width = ::GetSystemMetrics(SM_CXSCREEN);
int max_height = ::GetSystemMetrics(SM_CYSCREEN);
2018-10-06 11:15:32 +08:00
float dpi = Graphics::GetDpi();
RECT rect = { 0, 0, LONG(ceil(width * dpi / 96.f)), LONG(ceil(height * dpi / 96.f)) };
2018-09-30 14:54:43 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵĴ<CAB5><C4B4>ڴ<EFBFBD>С
::AdjustWindowRectEx(&rect, WINDOW_STYLE, FALSE, NULL);
width = static_cast<int>(rect.right - rect.left);
height = static_cast<int>(rect.bottom - rect.top);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4>ڴ<EFBFBD>С<EFBFBD>ȷֱ<C8B7><D6B1>ʴ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
E2D_WARNING_IF(max_width < width || max_height < height, "The window Is larger than screen!");
2018-09-30 14:54:43 +08:00
width = std::min(width, max_width);
height = std::min(height, max_height);
Rect client_rect(
static_cast<float>((max_width - width) / 2),
static_cast<float>((max_height - height) / 2),
static_cast<float>(width),
static_cast<float>(height)
);
return std::move(client_rect);
}
2018-10-16 14:13:15 +08:00
int easy2d::Game::GetWidth() const
2018-09-30 14:54:43 +08:00
{
return width_;
}
2018-10-16 14:13:15 +08:00
int easy2d::Game::GetHeight() const
2018-09-30 14:54:43 +08:00
{
return height_;
}
2018-10-16 14:13:15 +08:00
easy2d::Size easy2d::Game::GetSize() const
2018-09-30 14:54:43 +08:00
{
2018-10-16 14:13:15 +08:00
easy2d::Size size(
2018-09-30 14:54:43 +08:00
static_cast<float>(width_),
static_cast<float>(height_)
);
return std::move(size);
}
2018-10-16 14:13:15 +08:00
HWND easy2d::Game::GetHWnd() const
2018-09-30 14:54:43 +08:00
{
return hwnd_;
}
2018-10-16 14:13:15 +08:00
const easy2d::String& easy2d::Game::GetTitle() const
2018-09-30 14:54:43 +08:00
{
return title_;
}
2018-10-16 14:13:15 +08:00
void easy2d::Game::SetSize(int width, int height)
2018-09-30 14:54:43 +08:00
{
if (width_ == width && height_ == height)
return;
width_ = width;
height_ = height;
2018-10-03 18:04:04 +08:00
if (hwnd_)
{
Rect rect = Locate(width, height);
::MoveWindow(
hwnd_,
int(rect.origin.x),
int(rect.origin.y),
int(rect.size.width),
int(rect.size.height),
TRUE
);
}
2018-09-30 14:54:43 +08:00
}
2018-10-16 14:13:15 +08:00
void easy2d::Game::SetTitle(const String& title)
2018-09-30 14:54:43 +08:00
{
title_ = title;
2018-10-03 18:04:04 +08:00
if (hwnd_)
{
::SetWindowText(hwnd_, (LPCWSTR)title);
}
2018-09-30 14:54:43 +08:00
}
2018-10-16 14:13:15 +08:00
void easy2d::Game::SetIcon(int resource_id)
2018-09-30 14:54:43 +08:00
{
icon_ = resource_id;
2018-10-03 18:04:04 +08:00
if (hwnd_)
{
HICON icon = (HICON)::LoadImage(
HINST_THISCOMPONENT,
MAKEINTRESOURCE(resource_id),
IMAGE_ICON,
0,
0,
LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE
);
::SendMessage(hwnd_, WM_SETICON, ICON_BIG, (LPARAM)icon);
::SendMessage(hwnd_, WM_SETICON, ICON_SMALL, (LPARAM)icon);
}
2018-09-30 14:54:43 +08:00
}
2018-10-16 14:13:15 +08:00
LRESULT easy2d::Game::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param)
2018-09-30 14:54:43 +08:00
{
LRESULT result = 0;
bool was_handled = false;
Game * game = reinterpret_cast<Game*>(
static_cast<LONG_PTR>(::GetWindowLongPtrW(hwnd, GWLP_USERDATA))
);
2018-09-30 14:54:43 +08:00
switch (msg)
2018-09-30 14:54:43 +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:
2018-09-30 14:54:43 +08:00
{
if (game->IsTransitioning())
break;
2018-09-30 14:54:43 +08:00
auto curr_scene = game->GetCurrentScene();
if (curr_scene)
2018-09-30 14:54:43 +08:00
{
curr_scene->Dispatch(MouseEvent(msg, w_param, l_param));
2018-09-30 14:54:43 +08:00
}
}
result = 0;
was_handled = true;
break;
2018-09-30 14:54:43 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
case WM_KEYDOWN:
case WM_KEYUP:
{
if (game->IsTransitioning())
break;
2018-09-30 14:54:43 +08:00
auto curr_scene = game->GetCurrentScene();
if (curr_scene)
2018-09-30 14:54:43 +08:00
{
curr_scene->Dispatch(KeyEvent(msg, w_param, l_param));
2018-08-15 23:30:23 +08:00
}
}
result = 0;
was_handled = true;
break;
2018-09-30 14:54:43 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>С<EFBFBD><EFBFBD><E4BBAF>Ϣ
case WM_SIZE:
{
UINT width = LOWORD(l_param);
UINT height = HIWORD(l_param);
2018-09-30 14:54:43 +08:00
if (w_param == SIZE_RESTORED)
2018-09-30 14:54:43 +08:00
{
float dpi = Graphics::GetDpi();
game->width_ = static_cast<int>(width * 96.f / dpi);
game->height_ = static_cast<int>(height * 96.f / dpi);
2018-09-30 14:54:43 +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>С<EFBFBD><D0A1><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>
auto render_target = Device::GetGraphics()->GetRenderTarget();
if (render_target)
2018-09-30 14:54:43 +08:00
{
render_target->Resize(D2D1::SizeU(width, height));
2018-09-30 14:54:43 +08:00
}
}
break;
2018-09-30 14:54:43 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><E4BBAF>Ϣ
case WM_SETTEXT:
{
game->title_ = (const wchar_t*)l_param;
}
break;
2018-09-30 14:54:43 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ʱ仯<CAB1><E4BBAF>Ϣ
case WM_DISPLAYCHANGE:
{
// <20>ػ<EFBFBD><D8BB>ͻ<EFBFBD><CDBB><EFBFBD>
::InvalidateRect(hwnd, nullptr, FALSE);
}
result = 0;
was_handled = true;
break;
2018-09-30 14:54:43 +08:00
// <20>ػ洰<D8BB><E6B4B0>
case WM_PAINT:
{
game->DrawScene();
::ValidateRect(hwnd, nullptr);
}
result = 0;
was_handled = true;
break;
2018-09-30 14:54:43 +08:00
// <20><><EFBFBD>ڹر<DAB9><D8B1><EFBFBD>Ϣ
case WM_CLOSE:
{
if (game->OnExit())
2018-08-15 23:30:23 +08:00
{
game->Quit();
2018-08-15 23:30:23 +08:00
}
}
result = 0;
was_handled = true;
break;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
case WM_DESTROY:
{
::PostQuitMessage(0);
}
result = 1;
was_handled = true;
break;
}
if (!was_handled)
{
result = ::DefWindowProc(hwnd, msg, w_param, l_param);
}
2018-09-30 14:54:43 +08:00
return result;
2018-01-30 16:45:38 +08:00
}