Something went wrong. Try again.
the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
Something went wrong. Try again.
4.3 kB · 245 lines
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245#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::DEGRAD = PI / 180.0f;const float Mth::RADDEG = 180.0f / PI;const float Mth::RAD_TO_GRAD = PI / 180.0f;
float *Mth::_sin = NULL;
const float Mth::sinScale = 65536.0f / (float) (PI * 2);
// 4J - added - was in static constructorvoid Mth::init(){ _sin = new float[65536]; for (int i = 0; i < 65536; i++) { _sin[i] = (float) ::sin(i * PI * 2 / 65536.0f); }}
float Mth::sin(float i){ if(_sin == NULL) init(); // 4J - added return _sin[(int) (i * sinScale) & 65535];}
float Mth::cos(float i){ if(_sin == NULL) init(); // 4J - added return _sin[(int) (i * sinScale + 65536 / 4) & 65535];}
float Mth::sqrt(float x){ return (float) ::sqrt(x);}
float Mth::sqrt(double x){ return (float) ::sqrt(x);}
int Mth::floor(float v){ 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;}
int Mth::fastFloor(double x){ return (int) (x + BIG_ENOUGH_FLOAT) - BIG_ENOUGH_INT;}
int Mth::floor(double v){ int i = (int) v; return v < i ? i - 1 : i;}
int Mth::absFloor(double v){ return (int) (v >= 0 ? v : -v + 1);}
float Mth::abs(float v){ return v >= 0 ? v : -v;}
int Mth::abs(int v){ return v >= 0 ? v : -v;}
int Mth::ceil(float v){ int i = (int) v; return v > i ? i + 1 : i;}
int Mth::clamp(int value, int min, int max){ if (value < min) { return min; } if (value > max) { return max; } return value;}
float Mth::clamp(float value, float min, float max){ if (value < min) { return min; } if (value > max) { return max; } return value;}
double Mth::asbMax(double a, double 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;}
int Mth::nextInt(Random *random, int minInclusive, int maxInclusive){ if (minInclusive >= maxInclusive) { 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){ //input %= 360; while (input >= 180) { input -= 360; } while (input < -180) { input += 360; } return input;}
double Mth::wrapDegrees(double input){ //input %= 360; while (input >= 180) { input -= 360; } while (input < -180) { input += 360; } return input;}
int Mth::getInt(const wstring &input, int def){ int result = def;
result = _fromString<int>(input);
return result;}
int Mth::getInt(const wstring &input, int def, int min){ int result = def;
result = _fromString<int>(input);
if (result < min) result = min; return result;}
double Mth::getDouble(const wstring &input, double def){ double result = def;
result = _fromString<double>(input);
return result;}
double Mth::getDouble(const wstring &input, double def, double min){ double result = def;
result = _fromString<double>(input);
if (result < min) result = min; return result;}
// 4J Changed this to remove the use of the actuall UUID typewstring 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 Addedbool Mth::almostEquals( double double1, double double2, double precision){ return (std::abs(double1 - double2) <= precision);}