* Change long to TLong.

This allows a potential linux port to become reality much easier.
This commit is contained in:
iProgramInCpp
2023-07-31 21:08:31 +03:00
parent 47f9b45ac4
commit 5884302836
24 changed files with 82 additions and 48 deletions

8
source/Base/LongHack.hpp Normal file
View 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

View File

@@ -8,8 +8,9 @@
#pragma once
#include "compat/GL.hpp"
#include <cstring>
#include "Mth.hpp"
#include "compat/GL.hpp"
class Matrix
{

View File

@@ -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()

View File

@@ -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();
};

View File

@@ -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)
{

View File

@@ -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"

View File

@@ -9,6 +9,7 @@
#pragma once
#include <string>
#include "LongHack.hpp"
#include "RakNetTypes.h"
#include "BitStream.h"
#include "MessageIdentifiers.h"
@@ -78,7 +79,7 @@ public:
void write(RakNet::BitStream*);
void read(RakNet::BitStream*);
public:
long field_4;
TLong field_4;
int field_8;
int field_C;
float field_10;
@@ -165,7 +166,7 @@ class RemoveBlockPacket : public Packet
{
public:
RemoveBlockPacket() {}
RemoveBlockPacket(int id, int x, int y, int z) :m_playerID(id), m_x(x), m_y(uint8_t(y)), m_z(z) {}
RemoveBlockPacket(int id, int x, int y, int z) :m_playerID(id), m_x(x), m_z(z), m_y(uint8_t(y)) {}
void handle(const RakNet::RakNetGUID&, NetEventCallback* pCallback) override;
void write(RakNet::BitStream*);

View File

@@ -64,7 +64,7 @@ float* Dimension::getSunriseColor(float a, float b)
return m_sunriseColor;
}
float Dimension::getTimeOfDay(long l, float f)
float Dimension::getTimeOfDay(TLong l, float f)
{
#ifndef ENH_RUN_DAY_NIGHT_CYCLE
//@QUIRK: This is a constant.

View File

@@ -27,7 +27,7 @@ public:
virtual bool isValidSpawn(int x, int z);
float* getSunriseColor(float, float);
float getTimeOfDay(long, float);
float getTimeOfDay(TLong, float);
void init(Level* pLevel);
void updateLightRamp();

View File

@@ -157,7 +157,7 @@ LABEL_31:
while (field_E8 - field_EC >= 180.0f)
field_EC += 360.0f;
while (m_pitch - field_60 < -180.0f);
while (m_pitch - field_60 < -180.0f)
field_60 -= 360.0f;
while (m_pitch - field_60 >= 180.0f)

View File

@@ -8,6 +8,7 @@
#pragma once
#include <cstring>
#include "ChunkSource.hpp"
#include "ChunkStorage.hpp"
class Level;

View File

@@ -8,6 +8,7 @@
#pragma once
#include <cstring>
#include "ChunkSource.hpp"
class Level;

View File

@@ -14,7 +14,7 @@ const float RandomLevelSource::SNOW_SCALE = 0.3f;
float g_timeSpentInPostProcessing = 0;
RandomLevelSource::RandomLevelSource(Level* level, long seed, int x) :
RandomLevelSource::RandomLevelSource(Level* level, TLong seed, int x) :
m_random(seed),
m_perlinNoise1(&m_random, 16),
m_perlinNoise2(&m_random, 16),
@@ -334,13 +334,13 @@ void RandomLevelSource::postProcess(ChunkSource* src, int x, int z)
int x16 = x * 16, z16 = z * 16;
Biome* pBiome = m_pLevel->getBiomeSource()->getBiome(x16 + 16, z16 + 16);
long seed = m_pLevel->getSeed();
TLong seed = m_pLevel->getSeed();
int xo, yo, zo;
m_random.setSeed(seed);
long x1 = 1 + 2 * (m_random.nextInt() / 2);
long x2 = 1 + 2 * (m_random.nextInt() / 2);
m_random.setSeed((long(x) * x1 + long(z) * x2) ^ seed);
TLong x1 = 1 + 2 * (m_random.nextInt() / 2);
TLong x2 = 1 + 2 * (m_random.nextInt() / 2);
m_random.setSeed((TLong(x) * x1 + TLong(z) * x2) ^ seed);
// @NOTE: I can't put the random calls _in_ the argument list - args are evaluated right to left I believe

View File

@@ -22,7 +22,7 @@
class RandomLevelSource : public ChunkSource
{
public:
RandomLevelSource(Level*, long seed, int);
RandomLevelSource(Level*, TLong seed, int);
int tick() override;
bool shouldSave() override;
bool hasChunk(int x, int z) override;

View File

@@ -8,6 +8,7 @@
#pragma once
#include <cstring>
#include "Utils.hpp"
#include "ChunkSource.hpp"
class Level;

View File

@@ -12,14 +12,14 @@
#include "Explosion.hpp"
#include "Region.hpp"
Level::Level(LevelStorage* pStor, const std::string& str, long seed, int x) :
Level::Level(LevelStorage* pStor, const std::string& str, TLong seed, int x) :
field_38(1), // initialize with a seed of 1
m_pLevelStorage(pStor)
{
_init(str, seed, x, nullptr);
}
Level::Level(LevelStorage* pStor, const std::string& str, long seed, int x, Dimension *pDimension) :
Level::Level(LevelStorage* pStor, const std::string& str, TLong seed, int x, Dimension *pDimension) :
field_38(1), // initialize with a seed of 1
m_pLevelStorage(pStor)
{
@@ -37,7 +37,7 @@ Level::~Level()
m_entities.clear();
}
void Level::_init(const std::string& str, long seed, int x, Dimension* pDimension)
void Level::_init(const std::string& str, TLong seed, int x, Dimension* pDimension)
{
field_12 = 0;
@@ -221,12 +221,12 @@ int Level::getSeed()
return m_levelData.m_seed;
}
long Level::getTime()
TLong Level::getTime()
{
return m_levelData.field_10;
}
void Level::setTime(long time)
void Level::setTime(TLong time)
{
m_levelData.field_10 = time;
}

View File

@@ -33,8 +33,8 @@ typedef std::vector<AABB> AABBVector;
class Level : public LevelSource
{
public:
Level(LevelStorage*, const std::string&, long seed, int);
Level(LevelStorage*, const std::string&, long seed, int, Dimension*);
Level(LevelStorage*, const std::string&, TLong seed, int);
Level(LevelStorage*, const std::string&, TLong seed, int, Dimension*);
~Level();
// TODO
@@ -44,7 +44,7 @@ public:
Material* getMaterial(int x, int y, int z) override;
bool isSolidTile(int x, int y, int z) override;
void _init(const std::string& str, long seed, int x, Dimension* pDimension);
void _init(const std::string& str, TLong seed, int x, Dimension* pDimension);
ChunkSource* getChunkSource();
ChunkSource* createChunkSource();
LevelChunk* getChunk(int x, int z);
@@ -55,7 +55,7 @@ public:
void setBrightness(const LightLayer&, int x, int y, int z, int bright);
int getSeaLevel();
int getSeed();
long getTime();
TLong getTime();
int getHeightmap(int x, int z);
bool isDay();
bool isSkyLit(int x, int y, int z);
@@ -139,7 +139,7 @@ public:
int getLightDepth(int x, int z);
float getStarBrightness(float f);
float getSunAngle(float f);
void setTime(long time);
void setTime(TLong time);
void swap(int x1, int y1, int z1, int x2, int y2, int z2);
HitResult clip(const Vec3& a, const Vec3& b);

View File

@@ -10,6 +10,13 @@
bool LevelChunk::touchedSky = false;
LevelChunk::~LevelChunk()
{
SAFE_DELETE(m_lightBlk);
SAFE_DELETE(m_lightSky);
SAFE_DELETE(m_tileData);
}
constexpr int MakeBlockDataIndex (int x, int y, int z)
{
return (x << 11) | (z << 7) | y;
@@ -894,7 +901,7 @@ int LevelChunk::getBlocksAndData(uint8_t* pData, int a3, int a4, int a5, int a6,
return a9;
}
Random LevelChunk::getRandom(long l)
Random LevelChunk::getRandom(TLong l)
{
Random random;

View File

@@ -8,7 +8,9 @@
#pragma once
#include <cstring>
#include <vector>
#include <algorithm>
#include "AABB.hpp"
#include "Utils.hpp"
#include "LightLayer.hpp"
@@ -21,6 +23,7 @@ class LevelChunk
public:
LevelChunk(Level*, int x, int z);
LevelChunk(Level*, TileID* pBlockData, int x, int z);
virtual ~LevelChunk();
void init();
@@ -57,7 +60,7 @@ public:
virtual void setBlocks(uint8_t* pData, int y);
virtual int getBlocksAndData(uint8_t* pData, int, int, int, int, int, int, int);
virtual int setBlocksAndData(uint8_t* pData, int, int, int, int, int, int, int);
virtual Random getRandom(long l);
virtual Random getRandom(TLong l);
virtual void recalcHeight(int, int, int);
virtual bool isEmpty();
//...

View File

@@ -12,7 +12,7 @@ LevelData::LevelData()
{
}
LevelData::LevelData(long seed, const std::string& name, int x)
LevelData::LevelData(TLong seed, const std::string& name, int x)
{
m_seed = seed;
field_20 = x;

View File

@@ -32,11 +32,11 @@ struct PlayerData
struct LevelData
{
LevelData();
LevelData(long seed, const std::string&, int);
LevelData(TLong seed, const std::string&, int);
long m_seed = 0;
TLong m_seed = 0;
Pos m_spawnPos;
long field_10 = 0;
TLong field_10 = 0;
int field_14 = 0;
int field_18 = 0;
int field_1C = 0;

View File

@@ -47,7 +47,7 @@ bool TickNextTickData::operator==(const TickNextTickData& other) const
field_10 == other.field_10;
}
void TickNextTickData::setDelay(long l)
void TickNextTickData::setDelay(TLong l)
{
m_delay = l;
}

View File

@@ -7,6 +7,7 @@
********************************************************************/
#pragma once
#include "LongHack.hpp"
struct TickNextTickData
{
@@ -16,13 +17,13 @@ struct TickNextTickData
int hashCode() const;
bool operator<(const TickNextTickData& other) const;
bool operator==(const TickNextTickData& other) const;
void setDelay(long);
void setDelay(TLong);
int m_ID;
int field_4;
int field_8;
int field_C;
int field_10;
long m_delay;
TLong m_delay;
};

View File

@@ -40,7 +40,7 @@ int LiquidTileDynamic::getSlopeDistance(Level* level, int x, int y, int z, int d
for (int i = 0; i < 4; i++)
{
if (i == 0 && a7 == 1 || i == 1 && a7 == 0 || i == 2 && a7 == 3 || i == 3 && a7 == 2)
if ((i == 0 && a7 == 1) || (i == 1 && a7 == 0) || (i == 2 && a7 == 3) || (i == 3 && a7 == 2))
continue;
int checkX = x, checkY = y, checkZ = z;