mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-11 20:11:18 +03:00
* Change long to TLong.
This allows a potential linux port to become reality much easier.
This commit is contained in:
8
source/Base/LongHack.hpp
Normal file
8
source/Base/LongHack.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
// Have to do this because GCC on 64-bit targets makes longs 64-bit.
|
||||
#ifdef ORIGINAL_CODE
|
||||
#define TLong long
|
||||
#else
|
||||
#define TLong int
|
||||
#endif
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "compat/GL.hpp"
|
||||
#include <cstring>
|
||||
#include "Mth.hpp"
|
||||
#include "compat/GL.hpp"
|
||||
|
||||
class Matrix
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
SPDX-License-Identifier: BSD-1-Clause
|
||||
********************************************************************/
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "Random.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
/* Period parameters */
|
||||
#define N 624
|
||||
@@ -16,12 +16,12 @@
|
||||
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
|
||||
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
|
||||
|
||||
Random::Random(long seed)
|
||||
Random::Random(TLong seed)
|
||||
{
|
||||
setSeed(seed);
|
||||
}
|
||||
|
||||
void Random::setSeed(long seed)
|
||||
void Random::setSeed(TLong seed)
|
||||
{
|
||||
rseed = seed;
|
||||
mti = N + 1;
|
||||
@@ -29,7 +29,7 @@ void Random::setSeed(long seed)
|
||||
}
|
||||
|
||||
/* initializes mt[N] with a seed */
|
||||
void Random::init_genrand(unsigned long s)
|
||||
void Random::init_genrand(unsigned TLong s)
|
||||
{
|
||||
mt[0] = s & 0xffffffffUL;
|
||||
for (mti = 1; mti < N; mti++) {
|
||||
@@ -52,8 +52,8 @@ int Random::nextInt(int max)
|
||||
// Returns a number from 0 to n (excluding n)
|
||||
unsigned int Random::genrand_int32()
|
||||
{
|
||||
unsigned long y;
|
||||
static unsigned long mag01[2]={0x0UL, MATRIX_A};
|
||||
unsigned TLong y;
|
||||
static unsigned TLong mag01[2]={0x0UL, MATRIX_A};
|
||||
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
||||
|
||||
if (mti >= N) { /* generate N words at one time */
|
||||
@@ -97,9 +97,9 @@ double Random::genrand_real2()
|
||||
return double(genrand_int32()) * (1.0 / 4294967296.0);
|
||||
}
|
||||
|
||||
long Random::nextLong()
|
||||
TLong Random::nextTLong()
|
||||
{
|
||||
return long(genrand_int32() >> 1);
|
||||
return TLong(genrand_int32() >> 1);
|
||||
}
|
||||
|
||||
int Random::nextInt()
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include "LongHack.hpp"
|
||||
|
||||
// This appears to be VERY similar to https://github.com/SethRobinson/proton/blob/master/shared/util/CRandom.h#L10
|
||||
// It turns out, RTsoft, Mojang, and the author of Game Coding Complete used the same reference implementation of
|
||||
@@ -38,17 +39,17 @@ int getTimeMs();
|
||||
class Random
|
||||
{
|
||||
unsigned int rseed;
|
||||
unsigned long mt[CMATH_N]; // the array for the state vector
|
||||
unsigned TLong mt[CMATH_N]; // the array for the state vector
|
||||
int mti; // mti==N+1 means mt[N] is not initialized
|
||||
|
||||
public:
|
||||
Random(long seed = getTimeMs());
|
||||
void setSeed(long seed);
|
||||
void init_genrand(unsigned long);
|
||||
Random(TLong seed = getTimeMs());
|
||||
void setSeed(TLong seed);
|
||||
void init_genrand(unsigned TLong);
|
||||
int nextInt(int max);
|
||||
unsigned genrand_int32();
|
||||
float nextFloat();
|
||||
double genrand_real2();
|
||||
long nextLong();
|
||||
TLong nextTLong();
|
||||
int nextInt();
|
||||
};
|
||||
|
||||
@@ -8,8 +8,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "LongHack.hpp"
|
||||
|
||||
class Util
|
||||
{
|
||||
@@ -56,9 +59,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static long hashCode(const std::string& str)
|
||||
static TLong hashCode(const std::string& str)
|
||||
{
|
||||
long result = 0;
|
||||
TLong result = 0;
|
||||
|
||||
for (auto chr : str)
|
||||
{
|
||||
|
||||
@@ -11,15 +11,21 @@
|
||||
#include <ctime>
|
||||
#include <cstdio> // have to include this to avoid it being included again later from being a problem
|
||||
#include <cstdint>
|
||||
#include <cstdarg>
|
||||
#include <cassert>
|
||||
#include <climits>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
// @HACK: Include WinSock2.h also
|
||||
// @HACK: Include WinSock2.h also
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#include <WS2tcpip.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include "compat/AKeyCodes.hpp"
|
||||
|
||||
Reference in New Issue
Block a user