diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index 03dcc620..1ba15bb8 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -54,36 +54,28 @@ void e2d::Game::start() Window::getInstance()->poll(); // 开始游戏 - Duration interval; int wait = 0; - + Duration interval; + _quit = false; _last = _now = Time::now(); while (!_quit) { _now = Time::now(); + interval = _now - _last; - if (_config.isVSyncEnabled()) + if (_config.isVSyncEnabled() || _frameInterval < interval) { + _last += _frameInterval; __update(); } else { - interval = _now - _last; - - if (_frameInterval < interval) + wait = (_frameInterval - interval).milliseconds() - 1; + if (wait > 1) { - _last = _now; - __update(); - } - else - { - wait = (_frameInterval - interval).milliseconds() - 1; - if (wait > 1) - { - std::this_thread::sleep_for(milliseconds(wait)); - } + std::this_thread::sleep_for(milliseconds(wait)); } } } @@ -139,6 +131,7 @@ void e2d::Game::setConfig(const Config& config) if (_config.isVSyncEnabled() != config.isVSyncEnabled()) { Renderer::getInstance()->discardDeviceResources(); + _last = _now; } _config = config; diff --git a/core/Base/Window.cpp b/core/Base/Window.cpp index 6635a379..c19ea1be 100644 --- a/core/Base/Window.cpp +++ b/core/Base/Window.cpp @@ -219,6 +219,11 @@ void e2d::Window::setSize(int width, int height) this->_size = Size(width, height); if (_hWnd) { + float dpiScaleX = 0.f, dpiScaleY = 0.f; + Renderer::getFactory()->GetDesktopDpi(&dpiScaleX, &dpiScaleY); + + width = static_cast(ceil(width * dpiScaleX / 96.f)); + height = static_cast(ceil(height * dpiScaleY / 96.f)); // 计算窗口大小 DWORD dwStyle = WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX &~WS_THICKFRAME; RECT wr = { 0, 0, static_cast(width), static_cast(height) }; @@ -426,8 +431,8 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar if (wParam == SIZE_RESTORED) { - UINT ret = ::GetDpiForWindow(hWnd); - _instance->_size = Size(width * 96.0 / ret, height * 96.0 / ret); + UINT dpi = ::GetDpiForWindow(hWnd); + _instance->_size = Size(width * 96.0 / dpi, height * 96.0 / dpi); } // 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染