From 3d802ef86b4a1ed29fd444b1af4b8d0ae8eea6a3 Mon Sep 17 00:00:00 2001 From: GabsPuNs Date: Wed, 20 May 2026 16:40:07 -0400 Subject: [PATCH] Fix Vsync --- .../UI/IUIScene_AbstractContainerMenu.cpp | 22 ++- .../UI/IUIScene_AbstractContainerMenu.h | 2 + .../Common/UI/UIControl_PlayerSkinPreview.cpp | 140 +++----------- Minecraft.Client/Gui.cpp | 14 +- Minecraft.Client/Windows64/Windows64_App.cpp | 108 ++++++++++- Minecraft.Client/Windows64/Windows64_App.h | 1 + .../Windows64/Windows64_Minecraft.cpp | 182 +++++------------- 7 files changed, 212 insertions(+), 257 deletions(-) diff --git a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp index 871a261e..1a4904b8 100644 --- a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp +++ b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp @@ -30,6 +30,7 @@ IUIScene_AbstractContainerMenu::IUIScene_AbstractContainerMenu() m_pointerPos.y = 0.0f; m_bPointerDrivenByMouse = false; + m_iLastMouseTickTimeNs = -1; } IUIScene_AbstractContainerMenu::~IUIScene_AbstractContainerMenu() @@ -267,6 +268,20 @@ void IUIScene_AbstractContainerMenu::UpdateTooltips() void IUIScene_AbstractContainerMenu::onMouseTick() { + // Frame-rate independent cursor input, normalized to a 60Hz reference frame. + constexpr int64_t kMinDeltaNs = 1000000LL; // 1 ms + constexpr int64_t kMaxDeltaNs = 100000000LL; // 100 ms + + int64_t iNowNs = System::nanoTime(); + float fFrameScale = 1.0f; + + if ( m_iLastMouseTickTimeNs > 0 ) + { + int64_t iDeltaNs = std::clamp(iNowNs - m_iLastMouseTickTimeNs, kMinDeltaNs, kMaxDeltaNs); + fFrameScale = static_cast(iDeltaNs) * 60.0f / 1000000000.0f; + } + m_iLastMouseTickTimeNs = iNowNs; + Minecraft *pMinecraft = Minecraft::GetInstance(); if( pMinecraft->localgameModes[getPad()] != nullptr) { @@ -423,8 +438,8 @@ void IUIScene_AbstractContainerMenu::onMouseTick() // The SD/splitscreen scenes are approximately 0.6 times the size of the fullscreen on if(!RenderManager.IsHiDef() || app.GetLocalPlayerCount() > 1) fInputScale *= 0.6f; - fInputX *= fInputScale; - fInputY *= fInputScale; + fInputX *= fInputScale * fFrameScale; + fInputY *= fInputScale * fFrameScale; #ifdef USE_POINTER_ACCEL m_fPointerAccelX += fInputX / 50.0f; @@ -1269,7 +1284,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick() // Offset back to image top left. vPointerPos.x -= m_fPointerImageOffsetX; vPointerPos.y -= m_fPointerImageOffsetY; - +/* // Update pointer position. // 4J-PB - do not allow sub pixel positions or we get broken lines in box edges @@ -1300,6 +1315,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick() vPointerPos.x = static_cast(floor(vPointerPos.x + 0.5f)); vPointerPos.y = static_cast(floor(vPointerPos.y + 0.5f)); +*/ m_pointerPos = vPointerPos; adjustPointerForSafeZone(); diff --git a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.h b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.h index 6710e18f..4a4700f9 100644 --- a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.h +++ b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.h @@ -145,6 +145,8 @@ protected: int m_iConsectiveInputTicks; + int64_t m_iLastMouseTickTimeNs; + // Used for detecting quick "taps" in a direction, should jump cursor to next slot. enum ETapState { diff --git a/Minecraft.Client/Common/UI/UIControl_PlayerSkinPreview.cpp b/Minecraft.Client/Common/UI/UIControl_PlayerSkinPreview.cpp index b8c439b1..ab8c8328 100644 --- a/Minecraft.Client/Common/UI/UIControl_PlayerSkinPreview.cpp +++ b/Minecraft.Client/Common/UI/UIControl_PlayerSkinPreview.cpp @@ -102,7 +102,26 @@ void UIControl_PlayerSkinPreview::tick() } } } + + if( m_currentAnimation == e_SkinPreviewAnimation_Attacking ) + { + m_swingTime += 2; + if (m_swingTime >= (Player::SWING_DURATION * 3) ) + m_swingTime = 0; + } } + +#ifdef SKIN_PREVIEW_BOB_ANIM + m_bobTick += 2; + if(m_bobTick >= 360*2) + m_bobTick = 0; +#endif + +#ifdef SKIN_PREVIEW_WALKING_ANIM + m_walkAnimSpeedO = m_walkAnimSpeed; + m_walkAnimSpeed += (0.1f - m_walkAnimSpeed) * 0.4f * 2.0f; + m_walkAnimPos += m_walkAnimSpeed * 2.0f; +#endif } void UIControl_PlayerSkinPreview::SetTexture(const wstring &url, TEXTURE_NAME backupTexture) @@ -259,11 +278,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou HumanoidModel *model = static_cast(renderer->getModel()); - //getAttackAnim(mob, a); - //if (armor != nullptr) armor->attackTime = model->attackTime; - //model->riding = mob->isRiding(); - //if (armor != nullptr) armor->riding = model->riding; - // 4J Stu - Remember to reset these values once the rendering is done if you add another one model->attackTime = 0; model->sneaking = false; @@ -287,11 +301,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou break; case e_SkinPreviewAnimation_Attacking: model->holdingRightHand = true; - m_swingTime++; - if (m_swingTime >= (Player::SWING_DURATION * 3) ) - { - m_swingTime = 0; - } model->attackTime = m_swingTime / static_cast(Player::SWING_DURATION * 3); break; default: @@ -299,10 +308,9 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou }; } - - float bodyRot = m_yRot; //(mob->yBodyRotO + (mob->yBodyRot - mob->yBodyRotO) * a); - float headRot = m_yRot; //(mob->yRotO + (mob->yRot - mob->yRotO) * a); - float headRotx = 0; //(mob->xRotO + (mob->xRot - mob->xRotO) * a); + float bodyRot = m_yRot; + float headRot = m_yRot; + float headRotx = 0; //setupPosition(mob, x, y, z); // is equivalent to @@ -311,9 +319,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou //float bob = getBob(mob, a); #ifdef SKIN_PREVIEW_BOB_ANIM float bob = (m_bobTick + a)/2; - - ++m_bobTick; - if(m_bobTick>=360*2) m_bobTick = 0; #else float bob = 0.0f; #endif @@ -339,9 +344,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou #endif #ifdef SKIN_PREVIEW_WALKING_ANIM - m_walkAnimSpeedO = m_walkAnimSpeed; - m_walkAnimSpeed += (0.1f - m_walkAnimSpeed) * 0.4f; - m_walkAnimPos += m_walkAnimSpeed; float ws = m_walkAnimSpeedO + (m_walkAnimSpeed - m_walkAnimSpeedO) * a; float wp = m_walkAnimPos - m_walkAnimSpeed * (1 - a); #else @@ -349,114 +351,35 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou float wp = 0; #endif - if (ws > 1) ws = 1; + if (ws > 1) + ws = 1; MemSect(31); bindTexture(m_customTextureUrl, m_backupTexture); MemSect(0); glEnable(GL_ALPHA_TEST); - //model->prepareMobModel(mob, wp, ws, a); model->render(nullptr, wp, ws, bob, headRot - bodyRot, headRotx, _scale, true); - /*for (int i = 0; i < MAX_ARMOR_LAYERS; i++) - { - if (prepareArmor(mob, i, a)) - { - armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, true); - glDisable(GL_BLEND); - glEnable(GL_ALPHA_TEST); - } - }*/ - //additionalRendering(mob, a); if (bindTexture(m_capeTextureUrl, L"" )) { glPushMatrix(); glTranslatef(0, 0, 2 / 16.0f); - double xd = 0;//(mob->xCloakO + (mob->xCloak - mob->xCloakO) * a) - (mob->xo + (mob->x - mob->xo) * a); - double yd = 0;//(mob->yCloakO + (mob->yCloak - mob->yCloakO) * a) - (mob->yo + (mob->y - mob->yo) * a); - double zd = 0;//(mob->zCloakO + (mob->zCloak - mob->zCloakO) * a) - (mob->zo + (mob->z - mob->zo) * a); + float flap = 0.0f; - float yr = 1;//mob->yBodyRotO + (mob->yBodyRot - mob->yBodyRotO) * a; - - double xa = sin(yr * PI / 180); - double za = -cos(yr * PI / 180); - - float flap = static_cast(yd) * 10; - if (flap < -6) flap = -6; - if (flap > 32) flap = 32; - float lean = static_cast(xd * xa + zd * za) * 100; - float lean2 = static_cast(xd * za - zd * xa) * 100; - if (lean < 0) lean = 0; - - //float pow = 1;//mob->oBob + (bob - mob->oBob) * a; - - flap += 1;//sin((mob->walkDistO + (mob->walkDist - mob->walkDistO) * a) * 6) * 32 * pow; + flap += 1.0f; if (model->sneaking) - { - flap += 25; - } + flap += 25.0f; - glRotatef(6.0f + lean / 2 + flap, 1, 0, 0); - glRotatef(lean2 / 2, 0, 0, 1); - glRotatef(-lean2 / 2, 0, 1, 0); - glRotatef(180, 0, 1, 0); + glRotatef(6.0f + flap, 1, 0, 0); + glRotatef(0, 0, 0, 1); + glRotatef(0, 0, 1, 0); + glRotatef(180.0f, 0, 1, 0); model->renderCloak(1 / 16.0f,true); glPopMatrix(); } - /* - float br = mob->getBrightness(a); - int overlayColor = getOverlayColor(mob, br, a); - if (((overlayColor >> 24) & 0xff) > 0 || mob->hurtTime > 0 || mob->deathTime > 0) - { - glDisable(GL_TEXTURE_2D); - glDisable(GL_ALPHA_TEST); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDepthFunc(GL_EQUAL); - - // 4J - changed these renders to not use the compiled version of their models, because otherwise the render states set - // about (in particular the depth & alpha test) don't work with our command buffer versions - if (mob->hurtTime > 0 || mob->deathTime > 0) - { - glColor4f(br, 0, 0, 0.4f); - model->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); - for (int i = 0; i < MAX_ARMOR_LAYERS; i++) - { - if (prepareArmorOverlay(mob, i, a)) - { - glColor4f(br, 0, 0, 0.4f); - armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); - } - } - } - - if (((overlayColor >> 24) & 0xff) > 0) - { - float r = ((overlayColor >> 16) & 0xff) / 255.0f; - float g = ((overlayColor >> 8) & 0xff) / 255.0f; - float b = ((overlayColor) & 0xff) / 255.0f; - float aa = ((overlayColor >> 24) & 0xff) / 255.0f; - glColor4f(r, g, b, aa); - model->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); - for (int i = 0; i < MAX_ARMOR_LAYERS; i++) - { - if (prepareArmorOverlay(mob, i, a)) - { - glColor4f(r, g, b, aa); - armor->render(wp, ws, bob, headRot - bodyRot, headRotx, _scale, false); - } - } - } - - glDepthFunc(GL_LEQUAL); - glDisable(GL_BLEND); - glEnable(GL_ALPHA_TEST); - glEnable(GL_TEXTURE_2D); - } - */ glDisable(GL_RESCALE_NORMAL); glEnable(GL_CULL_FACE); @@ -464,7 +387,6 @@ void UIControl_PlayerSkinPreview::render(EntityRenderer *renderer, double x, dou glPopMatrix(); MemSect(31); - //renderName(mob, x, y, z); MemSect(0); // Reset the model values to stop the changes we made here affecting anything in game (like the player hand render) diff --git a/Minecraft.Client/Gui.cpp b/Minecraft.Client/Gui.cpp index 898de197..ec943997 100644 --- a/Minecraft.Client/Gui.cpp +++ b/Minecraft.Client/Gui.cpp @@ -1012,16 +1012,16 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) if (true) { // Real window dimensions updated on every WM_SIZE — always current - extern int g_rScreenWidth; - extern int g_rScreenHeight; + extern int g_iScreenWidth; + extern int g_iScreenHeight; // Set up a fresh projection using physical pixel coordinates so the debug // text is never distorted regardless of aspect ratio, splitscreen layout, // or menu state. 1 coordinate unit = 1 physical pixel. // Compute the actual viewport dimensions for this player's screen section. // glOrtho must match the viewport exactly for 1 unit = 1 physical pixel. - int vpW = g_rScreenWidth; - int vpH = g_rScreenHeight; + int vpW = g_iScreenWidth; + int vpH = g_iScreenHeight; switch (minecraft->player->m_iScreenSection) { case C4JRender::VIEWPORT_TYPE_SPLIT_TOP: @@ -1055,8 +1055,8 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) // Font was designed for guiScale px/unit; scale up so characters appear // at the same physical size as the rest of the HUD at 0.5x. const float fontScale = static_cast(guiScale) * 1.0f; - const float scaleWidth = (g_rScreenWidth / 1920.0f); - const float scaleHeight = (g_rScreenHeight / 1080.0f); + const float scaleWidth = (g_iScreenWidth / 1920.0f); + const float scaleHeight = (g_iScreenHeight / 1080.0f); const int debugLeft = 1; const int debugTop = 1; @@ -1145,7 +1145,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) wfeature[eTerrainFeature_Ravine] = L"Ravine: "; // maxW in font units: physical width divided by font scale - float maxW = (static_cast(g_rScreenWidth) - debugLeft - 8) / fontScale; + float maxW = (static_cast(g_iScreenWidth) - debugLeft - 8) / fontScale; float maxWForContent = maxW - static_cast(font->width(L"...")); bool truncated[eTerrainFeature_Count] = {}; diff --git a/Minecraft.Client/Windows64/Windows64_App.cpp b/Minecraft.Client/Windows64/Windows64_App.cpp index 024051f5..924ad159 100644 --- a/Minecraft.Client/Windows64/Windows64_App.cpp +++ b/Minecraft.Client/Windows64/Windows64_App.cpp @@ -24,7 +24,107 @@ void CConsoleMinecraftApp::ExitGame() { m_bShutdown = true; } -void CConsoleMinecraftApp::FatalLoadError() {} + +void CConsoleMinecraftApp::FatalLoadError() +{ + ExitGame(); +} + +LONG WINAPI CConsoleMinecraftApp::UnhandledExceptionFilter(EXCEPTION_POINTERS* pExceptionInfo) +{ +/* + SYSTEMTIME st; + GetLocalTime(&st); + + char exeName[MAX_PATH]; + GetModuleFileNameA(nullptr, exeName, MAX_PATH); + PathStripPath(exeName); + PathRemoveExtension(exeName); + + char dumpFilePath[MAX_PATH]; + sprintf(dumpFilePath, "%s_crash_%02d_%02d_%04d_%02d_%02d_%02d.dmp", exeName, st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond); + + HANDLE hDumpFile = CreateFile(dumpFilePath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + if (hDumpFile != INVALID_HANDLE_VALUE) + { + MINIDUMP_EXCEPTION_INFORMATION mei{}; + mei.ThreadId = GetCurrentThreadId(); + mei.ExceptionPointers = pExceptionInfo; + mei.ClientPointers = FALSE; + + MINIDUMP_TYPE dumpType = +#ifdef _DEBUG + MiniDumpWithFullMemory; +#else + (MINIDUMP_TYPE)(MiniDumpWithDataSegs | MiniDumpWithHandleData | MiniDumpWithThreadInfo); +#endif + + MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, dumpType, pExceptionInfo ? &mei : nullptr, nullptr, nullptr); + CloseHandle(hDumpFile); + } + + auto ExceptionName = [](DWORD code) -> const wchar_t* + { + switch (code) + { + case EXCEPTION_ACCESS_VIOLATION: + return L"Access Violation"; + + case EXCEPTION_STACK_OVERFLOW: + return L"Stack Overflow"; + + case EXCEPTION_INT_DIVIDE_BY_ZERO: + return L"Integer Divide by Zero"; + + case EXCEPTION_ILLEGAL_INSTRUCTION: + return L"Illegal Instruction"; + + case EXCEPTION_IN_PAGE_ERROR: + return L"In-Page Error"; + + case EXCEPTION_BREAKPOINT: + return L"Breakpoint"; + + default: + return L"Unknown Exception Name"; + } + }; + + char logPath[MAX_PATH]; + sprintf_s(logPath, "%s_crash_%02d_%02d_%04d_%02d_%02d_%02d.txt", exeName, st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond); + + HANDLE hLogFile = CreateFile(logPath, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + if (hLogFile != INVALID_HANDLE_VALUE) + { + char buf[1024]; + int len = sprintf_s(buf, "Exception Code: 0x%08X (%ls)\nException Address: 0x%p", pExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionName(pExceptionInfo->ExceptionRecord->ExceptionCode), pExceptionInfo->ExceptionRecord->ExceptionAddress); + + DWORD written; + WriteFile(hLogFile, buf, len, &written, nullptr); + CloseHandle(hLogFile); + } + + char msg[1024]; + + if (pExceptionInfo && pExceptionInfo->ExceptionRecord) + { + DWORD code = pExceptionInfo->ExceptionRecord->ExceptionCode; + void* addr = pExceptionInfo->ExceptionRecord->ExceptionAddress; + + sprintf_s(msg, "%s has run into a fatal error and must be closed.\n\nException: 0x%08X (%s)\nAddress: 0x%p\n\nA crash dump and log file have been written.", exeName, code, ExceptionName(code), addr); + } + else + { + sprintf_s(msg, "%s has run into a fatal error and must be closed.\n\nNo exception information was available.\n", exeName); + } + + char title[1024]; + sprintf_s(title, "%s - Fatal Error", exeName); + MessageBox(nullptr, msg, title, MB_OK | MB_ICONERROR); + + return EXCEPTION_EXECUTE_HANDLER; +*/ +} void CConsoleMinecraftApp::CaptureSaveThumbnail() { @@ -50,7 +150,11 @@ void CConsoleMinecraftApp::GetSaveThumbnail(PBYTE *pbData,DWORD *pdwSize) if (pdwSize) *pdwSize = 0; } } -void CConsoleMinecraftApp::ReleaseSaveThumbnail() {} +void CConsoleMinecraftApp::ReleaseSaveThumbnail() +{ + if (m_ThumbnailBuffer.Allocated()) + m_ThumbnailBuffer.Release(); +} void CConsoleMinecraftApp::GetScreenshot(int iPad,PBYTE *pbData,DWORD *pdwSize) {} diff --git a/Minecraft.Client/Windows64/Windows64_App.h b/Minecraft.Client/Windows64/Windows64_App.h index 503c39a3..d3a43801 100644 --- a/Minecraft.Client/Windows64/Windows64_App.h +++ b/Minecraft.Client/Windows64/Windows64_App.h @@ -12,6 +12,7 @@ public: virtual void StoreLaunchData(); virtual void ExitGame(); virtual void FatalLoadError(); + static LONG WINAPI UnhandledExceptionFilter(EXCEPTION_POINTERS* pExceptionInfo); virtual void CaptureSaveThumbnail(); virtual void GetSaveThumbnail(PBYTE*,DWORD*); diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 33736968..d57a76de 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -47,7 +47,6 @@ extern "C" } HINSTANCE hMyInst; -LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam); char chGlobalText[256]; uint16_t ui16GlobalText[256]; @@ -56,15 +55,7 @@ uint16_t ui16GlobalText[256]; #define NUM_PROFILE_SETTINGS 4 DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]= { -#ifdef _XBOX - XPROFILE_OPTION_CONTROLLER_VIBRATION, - XPROFILE_GAMER_YAXIS_INVERSION, - XPROFILE_GAMER_CONTROL_SENSITIVITY, - XPROFILE_GAMER_ACTION_MOVEMENT_CONTROL, - XPROFILE_TITLE_SPECIFIC1, -#else 0,0,0,0,0 -#endif }; // Screen resolution — auto-detected from the monitor at startup. @@ -74,13 +65,8 @@ DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]= int g_iScreenWidth = 1920; int g_iScreenHeight = 1080; -// Real window dimensions — updated on every WM_SIZE so the 3D perspective -// always matches the current window, even after a resize. -int g_rScreenWidth = 1920; -int g_rScreenHeight = 1080; static bool f3ComboUsed = false; -float g_iAspectRatio = static_cast(g_iScreenWidth) / g_iScreenHeight; static bool g_bResizeReady = false; char g_Win64Username[17] = { 0 }; @@ -90,12 +76,6 @@ wchar_t g_Win64UsernameW[17] = { 0 }; static bool g_isFullscreen = false; static WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) }; -struct Win64LaunchOptions -{ - int screenMode; - bool fullscreen; -}; - // ---------- Persistent options (options.txt next to exe) ---------- static void GetOptionsFilePath(char *out, size_t outSize) { @@ -294,59 +274,12 @@ void DefineActions(void) InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN); } -#if 0 -HRESULT InitD3D( IDirect3DDevice9 **ppDevice, - D3DPRESENT_PARAMETERS *pd3dPP ) -{ - IDirect3D9 *pD3D; - - pD3D = Direct3DCreate9( D3D_SDK_VERSION ); - - // Set up the structure used to create the D3DDevice - // Using a permanent 1280x720 backbuffer now no matter what the actual video resolution.right Have also disabled letterboxing, - // which would letterbox a 1280x720 output if it detected a 4:3 video source - we're doing an anamorphic squash in this - // mode so don't need this functionality. - - ZeroMemory( pd3dPP, sizeof(D3DPRESENT_PARAMETERS) ); - XVIDEO_MODE VideoMode; - XGetVideoMode( &VideoMode ); - g_bWidescreen = VideoMode.fIsWideScreen; - pd3dPP->BackBufferWidth = 1280; - pd3dPP->BackBufferHeight = 720; - pd3dPP->BackBufferFormat = D3DFMT_A8R8G8B8; - pd3dPP->BackBufferCount = 1; - pd3dPP->EnableAutoDepthStencil = TRUE; - pd3dPP->AutoDepthStencilFormat = D3DFMT_D24S8; - pd3dPP->SwapEffect = D3DSWAPEFFECT_DISCARD; - pd3dPP->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - //pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; - //ERR[D3D]: Can't set D3DPRESENTFLAG_NO_LETTERBOX when wide-screen is enabled - // in the launcher/dashboard. - if(g_bWidescreen) - pd3dPP->Flags=0; - else - pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; - - // Create the device. - return pD3D->CreateDevice( - 0, - D3DDEVTYPE_HAL, - nullptr, - D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_BUFFER_2_FRAMES, - pd3dPP, - ppDevice ); -} -#endif -//#define MEMORY_TRACKING - #ifdef MEMORY_TRACKING void ResetMem(); void DumpMem(); void MemPixStuff(); #else -void MemSect(int sect) -{ -} +void MemSect(int sect) {} #endif HINSTANCE g_hInst = nullptr; @@ -408,7 +341,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) break; default: - return DefWindowProcW(hWnd, message, wParam, lParam); + return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: @@ -443,21 +376,30 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) int vk = static_cast(wParam); if ((lParam & 0x40000000) && vk != VK_LEFT && vk != VK_RIGHT && vk != VK_BACK) break; -#ifdef _WINDOWS64 + const Minecraft* pm = Minecraft::GetInstance(); ChatScreen* chat = pm && pm->screen ? dynamic_cast(pm->screen) : nullptr; if (chat) { if (vk == 'V' && (GetKeyState(VK_CONTROL) & 0x8000)) - { chat->handlePasteRequest(); break; } - if ((vk == VK_UP || vk == VK_DOWN) && !(lParam & 0x40000000)) - { if (vk == VK_UP) chat->handleHistoryUp(); else chat->handleHistoryDown(); break; } - if (vk >= '1' && vk <= '9') // Prevent hotkey conflicts + { + chat->handlePasteRequest(); break; + } + + if ((vk == VK_UP || vk == VK_DOWN) && !(lParam & 0x40000000)) + { + if (vk == VK_UP) + chat->handleHistoryUp(); + else + chat->handleHistoryDown(); + break; + } + if (vk == VK_SHIFT) break; } -#endif + if (vk == VK_SHIFT) vk = (MapVirtualKey((lParam >> 16) & 0xFF, MAPVK_VSC_TO_VK_EX) == VK_RSHIFT) ? VK_RSHIFT : VK_LSHIFT; else if (vk == VK_CONTROL) @@ -465,7 +407,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) else if (vk == VK_MENU) vk = (lParam & (1 << 24)) ? VK_RMENU : VK_LMENU; g_KBMInput.OnKeyDown(vk); - return DefWindowProcW(hWnd, message, wParam, lParam); + return DefWindowProc(hWnd, message, wParam, lParam); } case WM_KEYUP: case WM_SYSKEYUP: @@ -565,7 +507,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } break; default: - return DefWindowProcW(hWnd, message, wParam, lParam); + return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } @@ -577,23 +519,23 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) // ATOM MyRegisterClass(HINSTANCE hInstance) { - WNDCLASSEXW wcex; + WNDCLASSEX wcex; - wcex.cbSize = sizeof(WNDCLASSEXW); + wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; - wcex.hIcon = LoadIconW(hInstance, L"Minecraft"); + wcex.hIcon = LoadIcon(hInstance, "Minecraft"); wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = L"Minecraft"; - wcex.lpszClassName = L"MinecraftClass"; - wcex.hIconSm = LoadIconW(wcex.hInstance, MAKEINTRESOURCEW(IDI_MINECRAFTWINDOWS)); + wcex.lpszMenuName = "Minecraft"; + wcex.lpszClassName = "MinecraftClass"; + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_MINECRAFTWINDOWS)); - return RegisterClassExW(&wcex); + return RegisterClassEx(&wcex); } // @@ -610,11 +552,11 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { g_hInst = hInstance; // Store instance handle in our global variable - RECT wr = {0, 0, g_rScreenWidth, g_rScreenHeight}; // set the size, but not the position + RECT wr = {0, 0, g_iScreenWidth, g_iScreenHeight}; // set the size, but not the position AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE); // adjust the size - g_hWnd = CreateWindowW( L"MinecraftClass", - L"Minecraft", + g_hWnd = CreateWindow( "MinecraftClass", + "Minecraft", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, @@ -654,34 +596,6 @@ uint16_t *GetGlobalText() } return ui16GlobalText; } -void SeedEditBox() -{ - DialogBox(hMyInst, MAKEINTRESOURCE(IDD_SEED), - g_hWnd, reinterpret_cast(DlgProc)); -} - -//--------------------------------------------------------------------------- -LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam) -{ - switch(Msg) - { - case WM_INITDIALOG: - return TRUE; - - case WM_COMMAND: - switch(wParam) - { - case IDOK: - // Set the text - GetDlgItemText(hWndDlg,IDC_EDIT,chGlobalText,256); - EndDialog(hWndDlg, 0); - return TRUE; - } - break; - } - - return FALSE; -} //-------------------------------------------------------------------------------------- // Create Direct3D device and swap chain @@ -690,9 +604,9 @@ HRESULT InitDevice() { HRESULT hr = S_OK; - UINT width = g_rScreenWidth; - UINT height = g_rScreenHeight; -//app.DebugPrintf("width: %d, height: %d\n", width, height); + UINT width = g_iScreenWidth; + UINT height = g_iScreenHeight; + app.DebugPrintf("width: %d, height: %d\n", width, height); UINT createDeviceFlags = 0; #ifdef _DEBUG @@ -803,7 +717,6 @@ HRESULT InitDevice() vp.TopLeftY = 0; g_pImmediateContext->RSSetViewports( 1, &vp ); - RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); PostProcesser::GetInstance().Init(); return S_OK; @@ -879,8 +792,8 @@ static bool ResizeD3D(int newW, int newH) *pRM_BBWidth, *pRM_BBHeight, oldScDesc.BufferDesc.Width, oldScDesc.BufferDesc.Height); } - RenderManager.Suspend(); TrimMem(); + RenderManager.Suspend(); while (!RenderManager.Suspended()) Sleep(1); @@ -1025,8 +938,8 @@ static bool ResizeD3D(int newW, int newH) ui.updateScreenSize(bbW, bbH); // Track actual backbuffer dimensions for the rest of the engine - g_rScreenWidth = bbW; - g_rScreenHeight = bbH; + g_iScreenWidth = bbW; + g_iScreenHeight = bbH; success = true; @@ -1075,17 +988,17 @@ postReset: // If it's the NEW one (partial failure after swap), update to new dims. if (g_pSwapChain != pOldSwapChain) { - g_rScreenWidth = recW; - g_rScreenHeight = recH; + g_iScreenWidth = recW; + g_iScreenHeight = recH; ui.updateScreenSize(recW, recH); } - app.DebugPrintf("[RESIZE] FAILED but recovered views at %dx%d\n", g_rScreenWidth, g_rScreenHeight); + app.DebugPrintf("[RESIZE] FAILED but recovered views at %dx%d\n", g_iScreenWidth, g_iScreenHeight); } g_pImmediateContext->Flush(); gdraw_D3D11_PostReset(); - gdraw_D3D11_SetRendertargetSize(g_rScreenWidth, g_rScreenHeight); + gdraw_D3D11_SetRendertargetSize(g_iScreenWidth, g_iScreenHeight); if (success) IggyFlushInstalledFonts(); @@ -1175,10 +1088,10 @@ static Minecraft* InitialiseMinecraftRuntime() { app.loadMediaArchive(); -// RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); + RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); app.loadStringTable(); - ui.init(g_pd3dDevice, g_pImmediateContext, g_pRenderTargetView, g_pDepthStencilView, g_rScreenWidth, g_rScreenHeight); + ui.init(g_pd3dDevice, g_pImmediateContext, g_pRenderTargetView, g_pDepthStencilView, g_iScreenWidth, g_iScreenHeight); InputManager.Initialise(1, 3, MINECRAFT_ACTION_MAX, ACTION_MAX_MENU); g_KBMInput.Init(); @@ -1238,8 +1151,8 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { - UNREFERENCED_PARAMETER(hPrevInstance); - UNREFERENCED_PARAMETER(lpCmdLine); + // Init our exception handler + //SetUnhandledExceptionFilter(CConsoleMinecraftApp::UnhandledExceptionFilter); // 4J-Win64: set CWD to exe dir so asset paths resolve correctly { @@ -1251,12 +1164,9 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, // Declare DPI awareness so GetSystemMetrics returns physical pixels SetProcessDPIAware(); - // Use the native monitor resolution for the window and swap chain, - // but keep g_iScreenWidth/Height at 1920x1080 for logical resolution - // (SWF selection, ortho projection, game logic). The real window - // dimensions are tracked by g_rScreenWidth/g_rScreenHeight. - g_rScreenWidth = GetSystemMetrics(SM_CXSCREEN); - g_rScreenHeight = GetSystemMetrics(SM_CYSCREEN); + // Use the native monitor resolution for the window and swap chain + g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN); + g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN); // Load username from username.txt char exePath[MAX_PATH] = {};