From b3feddfef372618c8a9d7a0abcaf18cfad866c18 Mon Sep 17 00:00:00 2001 From: daoge <3523206925@qq.com> Date: Tue, 3 Mar 2026 03:04:10 +0800 Subject: feat: TU19 (Dec 2014) Features & Content (#155) * try to resolve merge conflict * feat: TU19 (Dec 2014) Features & Content (#32) * December 2014 files * Working release build * Fix compilation issues * Add sound to Windows64Media * Add DLC content and force Tutorial DLC * Revert "Add DLC content and force Tutorial DLC" This reverts commit 97a43994725008e35fceb984d5549df9c8cea470. * Disable broken light packing * Disable breakpoint during DLC texture map load Allows DLC loading but the DLC textures are still broken * Fix post build not working * ... * fix vs2022 build * fix cmake build --------- Co-authored-by: Loki --- Minecraft.World/Mth.cpp | 131 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 102 insertions(+), 29 deletions(-) (limited to 'Minecraft.World/Mth.cpp') diff --git a/Minecraft.World/Mth.cpp b/Minecraft.World/Mth.cpp index eccd828e..ab990e6c 100644 --- a/Minecraft.World/Mth.cpp +++ b/Minecraft.World/Mth.cpp @@ -1,12 +1,13 @@ #include "stdafx.h" #include "Mth.h" #include "Random.h" +#include "StringHelpers.h" const int Mth::BIG_ENOUGH_INT = 1024; const float Mth::BIG_ENOUGH_FLOAT = BIG_ENOUGH_INT; -const float Mth::RAD_TO_GRAD = PI / 180.0f; const float Mth::DEGRAD = PI / 180.0f; const float Mth::RADDEG = 180.0f / PI; +const float Mth::RAD_TO_GRAD = PI / 180.0f; float *Mth::_sin = NULL; @@ -15,11 +16,11 @@ const float Mth::sinScale = 65536.0f / (float) (PI * 2); // 4J - added - was in static constructor void Mth::init() { - _sin = new float[65536]; - for (int i = 0; i < 65536; i++) + _sin = new float[65536]; + for (int i = 0; i < 65536; i++) { - _sin[i] = (float) ::sin(i * PI * 2 / 65536.0f); - } + _sin[i] = (float) ::sin(i * PI * 2 / 65536.0f); + } } float Mth::sin(float i) @@ -46,14 +47,14 @@ float Mth::sqrt(double x) int Mth::floor(float v) { - int i = (int) v; - return v < i ? i - 1 : i; + int i = (int) v; + return v < i ? i - 1 : i; } __int64 Mth::lfloor(double v) { - __int64 i = (__int64) v; - return v < i ? i - 1 : i; + __int64 i = (__int64) v; + return v < i ? i - 1 : i; } int Mth::fastFloor(double x) @@ -63,8 +64,8 @@ int Mth::fastFloor(double x) int Mth::floor(double v) { - int i = (int) v; - return v < i ? i - 1 : i; + int i = (int) v; + return v < i ? i - 1 : i; } int Mth::absFloor(double v) @@ -84,21 +85,21 @@ int Mth::abs(int v) int Mth::ceil(float v) { - int i = (int) v; - return v > i ? i + 1 : i; + int i = (int) v; + return v > i ? i + 1 : i; } int Mth::clamp(int value, int min, int max) { - if (value < min) + if (value < min) { - return min; - } - if (value > max) + return min; + } + if (value > max) { - return max; - } - return value; + return max; + } + return value; } float Mth::clamp(float value, float min, float max) @@ -116,25 +117,37 @@ float Mth::clamp(float value, float min, float max) double Mth::asbMax(double a, double b) { - if (a < 0) a = -a; - if (b < 0) b = -b; - return a > b ? a : b; + if (a < 0) a = -a; + if (b < 0) b = -b; + return a > b ? a : b; } int Mth::intFloorDiv(int a, int b) { - if (a < 0) return -((-a - 1) / b) - 1; - return a / b; + if (a < 0) return -((-a - 1) / b) - 1; + return a / b; } int Mth::nextInt(Random *random, int minInclusive, int maxInclusive) { - if (minInclusive >= maxInclusive) + if (minInclusive >= maxInclusive) { - return minInclusive; - } - return random->nextInt(maxInclusive - minInclusive + 1) + minInclusive; + return minInclusive; + } + return random->nextInt(maxInclusive - minInclusive + 1) + minInclusive; +} + +float Mth::nextFloat(Random *random, float min, float max) +{ + if (min >= max) return min; + return (random->nextFloat() * (max - min)) + min; +} + +double Mth::nextDouble(Random *random, double min, double max) +{ + if (min >= max) return min; + return (random->nextDouble() * (max - min)) + min; } float Mth::wrapDegrees(float input) @@ -165,6 +178,66 @@ double Mth::wrapDegrees(double input) return input; } +int Mth::getInt(const wstring &input, int def) +{ + int result = def; + + result = _fromString(input); + + return result; +} + +int Mth::getInt(const wstring &input, int def, int min) +{ + int result = def; + + result = _fromString(input); + + if (result < min) result = min; + return result; +} + +double Mth::getDouble(const wstring &input, double def) +{ + double result = def; + + result = _fromString(input); + + return result; +} + +double Mth::getDouble(const wstring &input, double def, double min) +{ + double result = def; + + result = _fromString(input); + + if (result < min) result = min; + return result; +} + +// 4J Changed this to remove the use of the actuall UUID type +wstring Mth::createInsecureUUID(Random *random) +{ + wchar_t output[33]; + output[32] = 0; + __int64 high = (random->nextLong() & ~UUID_VERSION) | UUID_VERSION_TYPE_4; + __int64 low = (random->nextLong() & ~UUID_VARIANT) | UUID_VARIANT_2; + for(int i = 0; i < 16; i++ ) + { + wchar_t nybbleHigh = high & 0xf; + wchar_t nybbleLow = low & 0xf; + nybbleHigh = (nybbleHigh > 9 ) ? ( nybbleHigh + (L'a'-10) ) : ( nybbleHigh + L'0' ); + nybbleLow = (nybbleLow > 9 ) ? ( nybbleLow + (L'a'-10) ) : ( nybbleLow + L'0' ); + high >>= 4; + low >>= 4; + output[31 - i] = nybbleLow; + output[15 - i] = nybbleHigh; + } + return wstring(output); +} + + // 4J Added bool Mth::almostEquals( double double1, double double2, double precision) { -- cgit v1.2.3