From c58c1bd9d207b262f48a4db3f578e586b5db7f13 Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Fri, 10 Apr 2026 17:09:25 -0700 Subject: [PATCH] fix: MSVC build fixes --- targets/app/common/UI/UIController.h | 4 +- targets/minecraft/client/Minecraft.cpp | 20 ++++------ .../client/gui/SelectWorldScreen.cpp | 16 ++++---- .../gui/achievement/AchievementPopup.cpp | 1 + .../minecraft/client/model/HumanoidModel.cpp | 40 +++++++++---------- .../ConsoleSaveFileSplit.cpp | 25 ++++++------ targets/platform/renderer/gl/gl_compat.h | 5 +++ targets/util/Timer.h | 1 - 8 files changed, 57 insertions(+), 55 deletions(-) diff --git a/targets/app/common/UI/UIController.h b/targets/app/common/UI/UIController.h index b44e3b873..90b08f3dc 100644 --- a/targets/app/common/UI/UIController.h +++ b/targets/app/common/UI/UIController.h @@ -36,7 +36,7 @@ class UIScene; // 4jcraft, used to be D3D11_RECT. // This was the only class that used it, so it's here now. -struct RECT { +struct 4J_RECT { long left; long top; long right; @@ -190,7 +190,7 @@ private: int m_accumulatedTicks; uint64_t m_lastUiSfx; // Tracks time (ms) of last UI sound effect - RECT m_customRenderingClearRect; + 4J_RECT m_customRenderingClearRect; std::unordered_map m_registeredCallbackScenes; // A collection of scenes and unique id's diff --git a/targets/minecraft/client/Minecraft.cpp b/targets/minecraft/client/Minecraft.cpp index efecfa163..4f93d8d04 100644 --- a/targets/minecraft/client/Minecraft.cpp +++ b/targets/minecraft/client/Minecraft.cpp @@ -1119,21 +1119,15 @@ void Minecraft::run_middle() { #if !defined(_CONTENT_PACKAGE) { // print the time - auto now_tp = std::chrono:: - system_clock::now(); - std::time_t now_tt = std::chrono:: - system_clock::to_time_t(now_tp); - std::tm utcTime{}; -#if defined(_WIN32) - gmtime_s(&utcTime, &now_tt); -#else - gmtime_r(&now_tt, &utcTime); -#endif + auto now = std::chrono::system_clock::now(); + auto dp = std::chrono::floor(now); + std::chrono::hh_mm_ss hms{std::chrono::floor(now - dp)}; Log::info("%02d:%02d:%02d\n", - utcTime.tm_hour, - utcTime.tm_min, - utcTime.tm_sec); + (int)hms.hours().count(), + (int)hms.minutes().count(), + (int)hms.seconds().count()); + } #endif } else { diff --git a/targets/minecraft/client/gui/SelectWorldScreen.cpp b/targets/minecraft/client/gui/SelectWorldScreen.cpp index cc78b1386..b73c00162 100644 --- a/targets/minecraft/client/gui/SelectWorldScreen.cpp +++ b/targets/minecraft/client/gui/SelectWorldScreen.cpp @@ -268,15 +268,17 @@ void SelectWorldScreen::WorldSelectionList::renderItem(int i, int x, int y, levelSummary->getLastPlayed() - kFileTimeEpochToUnixEpochMs; const auto tp = std::chrono::system_clock::time_point{ std::chrono::milliseconds{lastPlayedUnixMs}}; - time_t lastPlayedTime = std::chrono::system_clock::to_time_t(tp); - std::tm utc; - gmtime_r(&lastPlayedTime, &utc); + auto dp = std::chrono::floor(tp); + std::chrono::year_month_day ymd{dp}; + std::chrono::hh_mm_ss hms{ + std::chrono::floor(tp - dp)}; - char buffer[20]; // 4J Stu - Currently shows years as 4 digits, where java only showed 2 - snprintf(buffer, 20, "%d/%d/%d %d:%02d", utc.tm_mday, utc.tm_mon + 1, - utc.tm_year + 1900, utc.tm_hour, - utc.tm_min); // 4J - TODO Localise this + // 4J - TODO Localise this + id += std::format(" ({}/{}/{} {}:{:02d}", (unsigned)ymd.day(), + (unsigned)ymd.month(), (int)ymd.year(), + (int)hms.hours().count(), (int)hms.minutes().count()); + id = id + " (" + buffer; int64_t size = levelSummary->getSizeOnDisk(); diff --git a/targets/minecraft/client/gui/achievement/AchievementPopup.cpp b/targets/minecraft/client/gui/achievement/AchievementPopup.cpp index 789c06100..62ac5def1 100644 --- a/targets/minecraft/client/gui/achievement/AchievementPopup.cpp +++ b/targets/minecraft/client/gui/achievement/AchievementPopup.cpp @@ -8,6 +8,7 @@ #include "minecraft/client/renderer/entity/ItemRenderer.h" #include "minecraft/locale/I18n.h" #include "minecraft/stats/Achievement.h" +#include "minecraft/SharedConstants.h" #include "platform/renderer/renderer.h" #include "platform/stubs.h" diff --git a/targets/minecraft/client/model/HumanoidModel.cpp b/targets/minecraft/client/model/HumanoidModel.cpp index 355e0a9b0..f21e2f572 100644 --- a/targets/minecraft/client/model/HumanoidModel.cpp +++ b/targets/minecraft/client/model/HumanoidModel.cpp @@ -218,8 +218,8 @@ void HumanoidModel::setupAnim(float time, float r, float bob, float yRot, arm1->zRot = 0.0f; } else if (uiBitmaskOverrideAnim & (1 << eAnim_ArmsOutFront)) { - arm0->xRot = -M_PI_2; - arm1->xRot = -M_PI_2; + arm0->xRot = -(std::numbers::pi / 2.0); + arm1->xRot = -(std::numbers::pi / 2.0); arm0->zRot = 0.0f; arm1->zRot = 0.0f; } else if (uiBitmaskOverrideAnim & (1 << eAnim_SingleArms)) { @@ -256,23 +256,23 @@ void HumanoidModel::setupAnim(float time, float r, float bob, float yRot, if (riding) { if ((uiBitmaskOverrideAnim & (1 << eAnim_SmallModel)) == 0) { - arm0->xRot += -M_PI_2 * 0.4f; - arm1->xRot += -M_PI_2 * 0.4f; - leg0->xRot = -M_PI_2 * 0.8f; - leg1->xRot = -M_PI_2 * 0.8f; - leg0->yRot = M_PI_2 * 0.2f; - leg1->yRot = -M_PI_2 * 0.2f; + arm0->xRot += -(std::numbers::pi / 2.0) * 0.4f; + arm1->xRot += -(std::numbers::pi / 2.0) * 0.4f; + leg0->xRot = -(std::numbers::pi / 2.0) * 0.8f; + leg1->xRot = -(std::numbers::pi / 2.0) * 0.8f; + leg0->yRot = (std::numbers::pi / 2.0) * 0.2f; + leg1->yRot = -(std::numbers::pi / 2.0) * 0.2f; } else { - arm0->xRot += -M_PI_2 * 0.4f; - arm1->xRot += -M_PI_2 * 0.4f; - leg0->xRot = -M_PI_2 * 0.4f; - leg1->xRot = -M_PI_2 * 0.4f; + arm0->xRot += -(std::numbers::pi / 2.0) * 0.4f; + arm1->xRot += -(std::numbers::pi / 2.0) * 0.4f; + leg0->xRot = -(std::numbers::pi / 2.0) * 0.4f; + leg1->xRot = -(std::numbers::pi / 2.0) * 0.4f; } } else if (idle && !sneaking) { - leg0->xRot = -M_PI_2; - leg1->xRot = -M_PI_2; - leg0->yRot = M_PI_2 * 0.2f; - leg1->yRot = -M_PI_2 * 0.2f; + leg0->xRot = -(std::numbers::pi / 2.0); + leg1->xRot = -(std::numbers::pi / 2.0); + leg0->yRot = (std::numbers::pi / 2.0) * 0.2f; + leg1->yRot = -(std::numbers::pi / 2.0) * 0.2f; } else if (uiBitmaskOverrideAnim & (1 << eAnim_NoLegAnim)) { leg0->xRot = 0.0f; leg0->zRot = 0.0f; @@ -289,10 +289,10 @@ void HumanoidModel::setupAnim(float time, float r, float bob, float yRot, } if (holdingLeftHand != 0) { - arm1->xRot = arm1->xRot * 0.5f - M_PI_2 * 0.2f * holdingLeftHand; + arm1->xRot = arm1->xRot * 0.5f - (std::numbers::pi / 2.0) * 0.2f * holdingLeftHand; } if (holdingRightHand != 0) { - arm0->xRot = arm0->xRot * 0.5f - M_PI_2 * 0.2f * holdingRightHand; + arm0->xRot = arm0->xRot * 0.5f - (std::numbers::pi / 2.0) * 0.2f * holdingRightHand; } arm0->yRot = 0.0f; @@ -425,8 +425,8 @@ void HumanoidModel::setupAnim(float time, float r, float bob, float yRot, arm1->zRot = 0.0f; arm0->yRot = -(0.1f - attack2 * 0.6f) + head->yRot; arm1->yRot = +(0.1f - attack2 * 0.6f) + head->yRot + 0.4f; - arm0->xRot = -M_PI_2 + head->xRot; - arm1->xRot = -M_PI_2 + head->xRot; + arm0->xRot = -(std::numbers::pi / 2.0) + head->xRot; + arm1->xRot = -(std::numbers::pi / 2.0) + head->xRot; arm0->xRot -= attack2 * 1.2f - attack * 0.4f; arm1->xRot -= attack2 * 1.2f - attack * 0.4f; arm0->zRot += ((float)(cosf(bob * 0.09f)) * 0.05f + 0.05f); diff --git a/targets/minecraft/world/level/storage/ConsoleSaveFileIO/ConsoleSaveFileSplit.cpp b/targets/minecraft/world/level/storage/ConsoleSaveFileIO/ConsoleSaveFileSplit.cpp index 40fcd3baf..ee31dc710 100644 --- a/targets/minecraft/world/level/storage/ConsoleSaveFileIO/ConsoleSaveFileSplit.cpp +++ b/targets/minecraft/world/level/storage/ConsoleSaveFileIO/ConsoleSaveFileSplit.cpp @@ -1354,14 +1354,11 @@ void ConsoleSaveFileSplit::DebugFlushToFile( char* fileName = new char[XCONTENT_MAX_FILENAME_LENGTH + 1]; - auto now_tp = std::chrono::system_clock::now(); - std::time_t now_tt = std::chrono::system_clock::to_time_t(now_tp); - std::tm t{}; -#if defined(_WIN32) - gmtime_s(&t, &now_tt); -#else - gmtime_r(&now_tt, &t); -#endif + auto now = std::chrono::system_clock::now(); + auto dp = std::chrono::floor(now); + std::chrono::year_month_day ymd{dp}; + std::chrono::hh_mm_ss hms{ + std::chrono::floor(now - dp)}; // 14 chars for the digits // 11 chars for the separators + suffix @@ -1370,10 +1367,14 @@ void ConsoleSaveFileSplit::DebugFlushToFile( if (m_fileName.length() > XCONTENT_MAX_FILENAME_LENGTH - 25) { cutFileName = m_fileName.substr(0, XCONTENT_MAX_FILENAME_LENGTH - 25); } - snprintf(fileName, XCONTENT_MAX_FILENAME_LENGTH + 1, - "\\v%04d-%s%02d.%02d.%02d.%02d.%02d.mcs", VER_PRODUCTBUILD, - cutFileName.c_str(), t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, - t.tm_sec); + + auto result = + std::format("\\v{:04d}-{}{:02d}.{:02d}.{:02d}.{:02d}.{:02d}.mcs", + VER_PRODUCTBUILD, cutFileName, (unsigned)ymd.month(), + (unsigned)ymd.day(), (int)hms.hours().count(), + (int)hms.minutes().count(), (int)hms.seconds().count()); + + snprintf(fileName, XCONTENT_MAX_FILENAME_LENGTH + 1, "%s", result.c_str()); const std::string outputPath = targetFileDir.getPath() + std::string(fileName); diff --git a/targets/platform/renderer/gl/gl_compat.h b/targets/platform/renderer/gl/gl_compat.h index 658c6cd6b..296030895 100644 --- a/targets/platform/renderer/gl/gl_compat.h +++ b/targets/platform/renderer/gl/gl_compat.h @@ -257,6 +257,11 @@ #define GL_TRIANGLE_STRIP 0x0005 #endif +#ifndef GL_RESCALE_NORMAL +#define GL_RESCALE_NORMAL 0x803A +#endif + + // glCallList / display list macros #undef glNewList #define glNewList(_list, _mode) PlatformRenderer.CBuffStart(_list) diff --git a/targets/util/Timer.h b/targets/util/Timer.h index 60aee1338..915ae4768 100644 --- a/targets/util/Timer.h +++ b/targets/util/Timer.h @@ -3,7 +3,6 @@ #include #include #include -#include #include #include