mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-17 20:10:23 +03:00
* Initial commit.
:)
This commit is contained in:
200
source/Base/AABB.cpp
Normal file
200
source/Base/AABB.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
AABB.cpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#include "AABB.hpp"
|
||||
|
||||
AABB::AABB()
|
||||
{
|
||||
}
|
||||
|
||||
AABB::AABB(Vec3 _min, Vec3 _max) :
|
||||
min(_min), max(_max)
|
||||
{
|
||||
}
|
||||
|
||||
AABB::AABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) :
|
||||
min(minX, minY, minZ), max(maxX, maxY, maxZ)
|
||||
{
|
||||
}
|
||||
|
||||
HitResult AABB::clip(const Vec3& vec1, const Vec3& vec2)
|
||||
{
|
||||
Vec3 clipMinX, clipMinY, clipMinZ;
|
||||
Vec3 clipMaxX, clipMaxY, clipMaxZ;
|
||||
bool bClipMinX, bClipMinY, bClipMinZ;
|
||||
bool bClipMaxX, bClipMaxY, bClipMaxZ;
|
||||
|
||||
bClipMinX = vec1.clipX(vec2, min.x, clipMinX);
|
||||
bClipMaxX = vec1.clipX(vec2, max.x, clipMaxX);
|
||||
bClipMinY = vec1.clipX(vec2, min.y, clipMinY);
|
||||
bClipMaxY = vec1.clipX(vec2, max.y, clipMaxY);
|
||||
bClipMinZ = vec1.clipX(vec2, min.z, clipMinZ);
|
||||
bClipMaxZ = vec1.clipX(vec2, max.z, clipMaxZ);
|
||||
|
||||
// <sigh>
|
||||
if (bClipMinX)
|
||||
{
|
||||
if (clipMinX.y < this->min.y || clipMinX.y > this->max.y || clipMinX.z < this->min.z)
|
||||
bClipMinX = 0;
|
||||
else
|
||||
bClipMinX = clipMinX.z <= this->max.z;
|
||||
}
|
||||
if (bClipMaxX)
|
||||
{
|
||||
if (clipMaxX.y < this->min.y || clipMaxX.y > this->max.y || clipMaxX.z < this->min.z)
|
||||
bClipMaxX = 0;
|
||||
else
|
||||
bClipMaxX = clipMaxX.z <= this->max.z;
|
||||
}
|
||||
if (bClipMinY)
|
||||
{
|
||||
if (clipMinY.x < this->min.x || clipMinY.x > this->max.x || clipMinY.z < this->min.z)
|
||||
bClipMinY = 0;
|
||||
else
|
||||
bClipMinY = clipMinY.z <= this->max.z;
|
||||
}
|
||||
if (bClipMaxY)
|
||||
{
|
||||
if (clipMaxY.x < this->min.x || clipMaxY.x > this->max.x || clipMaxY.z < this->min.z)
|
||||
bClipMaxY = 0;
|
||||
else
|
||||
bClipMaxY = clipMaxY.z <= this->max.z;
|
||||
}
|
||||
if (bClipMinZ)
|
||||
{
|
||||
if (clipMinZ.x < this->min.x || clipMinZ.x > this->max.x || clipMinZ.y < this->min.y)
|
||||
bClipMinZ = 0;
|
||||
else
|
||||
bClipMinZ = clipMinZ.y <= this->max.y;
|
||||
}
|
||||
if (bClipMaxZ)
|
||||
{
|
||||
if (clipMaxZ.x < this->min.x || clipMaxZ.x > this->max.x || clipMaxZ.y < this->min.y)
|
||||
bClipMaxZ = 0;
|
||||
else
|
||||
bClipMaxZ = clipMaxZ.y <= this->max.y;
|
||||
}
|
||||
|
||||
// the collided side of our AABB
|
||||
HitResult::eHitSide collType = HitResult::NOHIT;
|
||||
|
||||
// the preferred vector for our collision
|
||||
Vec3* pVec = nullptr;
|
||||
if (bClipMinX)
|
||||
pVec = &clipMinX, collType = HitResult::MINX;
|
||||
|
||||
if (bClipMaxX)
|
||||
{
|
||||
if (!pVec || clipMinZ.distanceToSqr(vec1) < pVec->distanceToSqr(vec1))
|
||||
pVec = &clipMaxX, collType = HitResult::MAXX;
|
||||
}
|
||||
|
||||
if (bClipMinY)
|
||||
{
|
||||
if (!pVec || clipMinY.distanceToSqr(vec1) < pVec->distanceToSqr(vec1))
|
||||
pVec = &clipMinY, collType = HitResult::MINY;
|
||||
}
|
||||
|
||||
if (bClipMaxY)
|
||||
{
|
||||
if (!pVec || clipMaxY.distanceToSqr(vec1) < pVec->distanceToSqr(vec1))
|
||||
pVec = &clipMaxY, collType = HitResult::MAXY;
|
||||
}
|
||||
|
||||
if (bClipMinZ)
|
||||
{
|
||||
if (!pVec || clipMinZ.distanceToSqr(vec1) < pVec->distanceToSqr(vec1))
|
||||
pVec = &clipMinZ, collType = HitResult::MINZ;
|
||||
}
|
||||
|
||||
if (bClipMaxZ)
|
||||
{
|
||||
if (!pVec || clipMinZ.distanceToSqr(vec1) < pVec->distanceToSqr(vec1))
|
||||
pVec = &clipMaxZ, collType = HitResult::MAXZ;
|
||||
}
|
||||
|
||||
if (!pVec)
|
||||
{
|
||||
// return a nothing burger
|
||||
return HitResult();
|
||||
}
|
||||
|
||||
return HitResult(0, 0, 0, collType, *pVec);
|
||||
}
|
||||
|
||||
float AABB::clipXCollide(const AABB& bud, float f) const
|
||||
{
|
||||
if (bud.max.y > min.y && bud.min.y < max.y && bud.max.z > min.z && bud.min.z < max.z)
|
||||
{
|
||||
if (f > 0.0f)
|
||||
{
|
||||
if (bud.max.x <= min.x)
|
||||
f = Mth::Min(min.x - bud.max.x, f);
|
||||
}
|
||||
|
||||
if (f < 0.0f)
|
||||
{
|
||||
if (bud.min.x >= max.x)
|
||||
f = Mth::Max(max.x - bud.min.x, f);
|
||||
}
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
float AABB::clipYCollide(const AABB& bud, float f) const
|
||||
{
|
||||
if (bud.max.x > min.x && bud.min.x < max.x && bud.max.z > min.z && bud.min.z < max.z)
|
||||
{
|
||||
if (f > 0.0f)
|
||||
{
|
||||
if (bud.max.y <= min.y)
|
||||
f = Mth::Min(min.y - bud.max.y, f);
|
||||
}
|
||||
|
||||
if (f < 0.0f)
|
||||
{
|
||||
if (bud.min.y >= max.y)
|
||||
f = Mth::Max(max.y - bud.min.y, f);
|
||||
}
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
float AABB::clipZCollide(const AABB& bud, float f) const
|
||||
{
|
||||
if (bud.max.x > min.x && bud.min.x < max.x && bud.max.y > min.y && bud.min.y < max.y)
|
||||
{
|
||||
if (f > 0.0f)
|
||||
{
|
||||
if (bud.max.z <= min.z)
|
||||
f = Mth::Min(min.z - bud.max.z, f);
|
||||
}
|
||||
|
||||
if (f < 0.0f)
|
||||
{
|
||||
if (bud.min.z >= max.z)
|
||||
f = Mth::Max(max.z - bud.min.z, f);
|
||||
}
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
bool AABB::intersect(const AABB& other) const
|
||||
{
|
||||
return max.x > other.min.x
|
||||
&& min.x < other.max.x
|
||||
&& max.y > other.min.y
|
||||
&& min.y < other.max.y
|
||||
&& max.z > other.min.z
|
||||
&& min.z < other.max.z;
|
||||
}
|
||||
69
source/Base/AABB.hpp
Normal file
69
source/Base/AABB.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
AABB.hpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Vec3.hpp"
|
||||
#include "HitResult.hpp"
|
||||
|
||||
class AABB
|
||||
{
|
||||
public:
|
||||
Vec3 min, max;
|
||||
|
||||
AABB();
|
||||
AABB(Vec3 min, Vec3 max);
|
||||
AABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
|
||||
|
||||
public:
|
||||
HitResult clip(const Vec3&, const Vec3&);
|
||||
float clipXCollide(const AABB& bud, float f) const;
|
||||
float clipYCollide(const AABB& bud, float f) const;
|
||||
float clipZCollide(const AABB& bud, float f) const;
|
||||
|
||||
bool intersect(const AABB& other) const;
|
||||
|
||||
// @NOTE: Names for `move`, `grow` and `expand` were taken from really early minecraft (rd-132211 to be exact).
|
||||
void move(float x, float y, float z)
|
||||
{
|
||||
min += Vec3(x, y, z);
|
||||
max += Vec3(x, y, z);
|
||||
}
|
||||
|
||||
// same thing
|
||||
void grow(float x, float y, float z)
|
||||
{
|
||||
min -= Vec3(x, y, z);
|
||||
max += Vec3(x, y, z);
|
||||
}
|
||||
|
||||
// same thing
|
||||
void grow(float x)
|
||||
{
|
||||
min -= Vec3(x, x, x);
|
||||
max += Vec3(x, x, x);
|
||||
}
|
||||
|
||||
void expand(float x, float y, float z)
|
||||
{
|
||||
if (x < 0) min.x += x;
|
||||
if (x > 0) max.x += x;
|
||||
if (y < 0) min.y += y;
|
||||
if (y > 0) max.y += y;
|
||||
if (z < 0) min.z += z;
|
||||
if (z > 0) max.z += z;
|
||||
}
|
||||
|
||||
bool contains(const Vec3& v) const
|
||||
{
|
||||
return v.x > min.x && v.x < max.x && v.y > min.y && v.y < max.y && v.z > min.z && v.z < max.z;
|
||||
}
|
||||
};
|
||||
|
||||
41
source/Base/CThread.cpp
Normal file
41
source/Base/CThread.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "CThread.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h> // for Sleep()
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
void CThread::sleep(uint32_t ms)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Sleep(ms);
|
||||
#else
|
||||
usleep(1000 * ms);
|
||||
#endif
|
||||
}
|
||||
|
||||
CThread::CThread(CThreadFunction func, void* parm)
|
||||
{
|
||||
m_func = func;
|
||||
|
||||
#ifdef USE_CPP11_THREADS
|
||||
std::thread thr(func, parm);
|
||||
m_thrd.swap(thr);
|
||||
#else
|
||||
pthread_attr_init(&m_thrd_attr);
|
||||
pthread_attr_setdetachstate(&m_thrd_attr, 1);
|
||||
pthread_create(&m_thrd, &m_thrd_attr, m_func, parm);
|
||||
#endif
|
||||
}
|
||||
|
||||
CThread::~CThread()
|
||||
{
|
||||
#ifdef USE_CPP11_THREADS
|
||||
m_thrd.join();
|
||||
#else
|
||||
pthread_join(m_thrd, 0);
|
||||
pthread_attr_destroy(&m_thrd_attr);
|
||||
#endif
|
||||
}
|
||||
33
source/Base/CThread.hpp
Normal file
33
source/Base/CThread.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
// CThread - Object oriented pthread wrapper
|
||||
#define USE_CPP11_THREADS
|
||||
|
||||
// USE_CPP11_THREADS - Use a C++11 implementation of threads instead of using pthread
|
||||
#ifdef USE_CPP11_THREADS
|
||||
#include <thread>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
typedef void* (*CThreadFunction)(void*);
|
||||
|
||||
class CThread
|
||||
{
|
||||
public:
|
||||
CThread(CThreadFunction, void* parm);
|
||||
~CThread();
|
||||
|
||||
static void sleep(uint32_t ms);
|
||||
|
||||
private:
|
||||
CThreadFunction m_func;
|
||||
|
||||
#ifdef USE_CPP11_THREADS
|
||||
std::thread m_thrd;
|
||||
#else
|
||||
pthread_t m_thrd;
|
||||
pthread_attr_t m_thrd_attr;
|
||||
#endif
|
||||
};
|
||||
|
||||
30
source/Base/HitResult.cpp
Normal file
30
source/Base/HitResult.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
HitResult.cpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#include "HitResult.hpp"
|
||||
|
||||
HitResult::HitResult() {}
|
||||
|
||||
HitResult::HitResult(int x, int y, int z, eHitSide hitSide, const Vec3& vec)
|
||||
{
|
||||
m_hitType = AABB;
|
||||
m_hitSide = hitSide;
|
||||
m_tileX = x;
|
||||
m_tileY = y;
|
||||
m_tileZ = z;
|
||||
m_bUnk24 = false;
|
||||
m_hitPos = vec;
|
||||
}
|
||||
|
||||
HitResult::HitResult(Entity* pEnt)
|
||||
{
|
||||
m_hitType = ENTITY;
|
||||
m_pEnt = pEnt;
|
||||
}
|
||||
59
source/Base/HitResult.hpp
Normal file
59
source/Base/HitResult.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
HitResult.cpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Vec3.hpp"
|
||||
|
||||
class Entity;
|
||||
|
||||
class HitResult
|
||||
{
|
||||
public:
|
||||
// looks ass backwards, but what can you do about it
|
||||
enum eHitResultType
|
||||
{
|
||||
AABB,
|
||||
ENTITY,
|
||||
NONE,
|
||||
};
|
||||
|
||||
enum eHitSide
|
||||
{
|
||||
NOHIT = -1,
|
||||
MINY = 0,
|
||||
MAXY, // 1
|
||||
MINZ, // 2
|
||||
MAXZ, // 3
|
||||
MINX, // 4
|
||||
MAXX, // 5
|
||||
};
|
||||
|
||||
public:
|
||||
HitResult();
|
||||
HitResult(Entity*);
|
||||
HitResult(int x, int y, int z, eHitSide hitSide, const Vec3&);
|
||||
|
||||
public:
|
||||
eHitResultType m_hitType = NONE;
|
||||
// block coords?
|
||||
int m_tileX = 0;
|
||||
int m_tileY = 0;
|
||||
int m_tileZ = 0;
|
||||
|
||||
eHitSide m_hitSide = MINY;
|
||||
|
||||
// hit position
|
||||
Vec3 m_hitPos;
|
||||
|
||||
Entity* m_pEnt = nullptr;
|
||||
bool m_bUnk24 = 0;
|
||||
};
|
||||
|
||||
206
source/Base/ImprovedNoise.cpp
Normal file
206
source/Base/ImprovedNoise.cpp
Normal file
@@ -0,0 +1,206 @@
|
||||
#include "ImprovedNoise.hpp"
|
||||
#include "Mth.hpp"
|
||||
|
||||
ImprovedNoise::ImprovedNoise()
|
||||
{
|
||||
Random random(1);
|
||||
init(&random);
|
||||
}
|
||||
|
||||
ImprovedNoise::ImprovedNoise(Random* pRandom)
|
||||
{
|
||||
init(pRandom);
|
||||
}
|
||||
|
||||
void ImprovedNoise::init(Random* pRandom)
|
||||
{
|
||||
m_offsetX = pRandom->nextFloat() * 256.0f;
|
||||
m_offsetY = pRandom->nextFloat() * 256.0f;
|
||||
m_offsetZ = pRandom->nextFloat() * 256.0f;
|
||||
|
||||
for (int i = 0; i < 256; i++)
|
||||
m_permutation[i] = i;
|
||||
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
int x = pRandom->nextInt(256 - i) + i;
|
||||
int t = m_permutation[i];
|
||||
m_permutation[i] = m_permutation[x];
|
||||
m_permutation[x] = t;
|
||||
m_permutation[256 + i] = m_permutation[i];
|
||||
}
|
||||
}
|
||||
|
||||
float ImprovedNoise::getValue(float x, float y)
|
||||
{
|
||||
return getValue(x, y, 0.0f);
|
||||
}
|
||||
|
||||
float ImprovedNoise::getValue(float x, float y, float z)
|
||||
{
|
||||
return noise(x, y, z);
|
||||
}
|
||||
|
||||
float ImprovedNoise::lerp(float prog, float a, float b)
|
||||
{
|
||||
return a + (b - a) * prog;
|
||||
}
|
||||
|
||||
float ImprovedNoise::grad(int hash, float x, float y, float z)
|
||||
{
|
||||
int h = hash & 0xF;
|
||||
float u = h < 8 ? x : y;
|
||||
float v = h < 4 ? y : h == 12 || h == 14 ? x : z;
|
||||
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
|
||||
}
|
||||
|
||||
float ImprovedNoise::grad2(int hash, float x, float z)
|
||||
{
|
||||
return grad(hash, x, 0.0f, z);
|
||||
}
|
||||
|
||||
float ImprovedNoise::fade(float x)
|
||||
{
|
||||
return x * x * x * (x * (x * 6.0f - 15.0f) + 10.0f);
|
||||
}
|
||||
|
||||
float ImprovedNoise::noise(float x, float y, float z)
|
||||
{
|
||||
// couldn't figure out how to get it to work well enough so I just decided to port the original implementation from:
|
||||
// https://cs.nyu.edu/~perlin/noise/
|
||||
x += m_offsetX;
|
||||
y += m_offsetY;
|
||||
z += m_offsetZ;
|
||||
|
||||
int X = Mth::floor(x) & 255,
|
||||
Y = Mth::floor(y) & 255,
|
||||
Z = Mth::floor(z) & 255;
|
||||
|
||||
x -= Mth::floor(x);
|
||||
y -= Mth::floor(y);
|
||||
z -= Mth::floor(z);
|
||||
|
||||
float u = fade(x),
|
||||
v = fade(y),
|
||||
w = fade(z);
|
||||
|
||||
int* p = m_permutation;
|
||||
int A = p[X ] + Y, AA = p[A] + Z, AB = p[A + 1] + Z,
|
||||
B = p[X + 1] + Y, BA = p[B] + Z, BB = p[B + 1] + Z;
|
||||
|
||||
return lerp(w, lerp(v, lerp(u, grad(p[AA ], x , y , z ),
|
||||
grad(p[BA ], x-1, y , z )),
|
||||
lerp(u, grad(p[AB ], x , y-1, z ),
|
||||
grad(p[BB ], x-1, y-1, z ))),
|
||||
lerp(v, lerp(u, grad(p[AA+1], x , y , z-1 ),
|
||||
grad(p[BA+1], x-1, y , z-1 )),
|
||||
lerp(u, grad(p[AB+1], x , y-1, z-1 ),
|
||||
grad(p[BB+1], x-1, y-1, z-1 ))));
|
||||
}
|
||||
|
||||
void ImprovedNoise::add(float* a2, float a3, float a4, float a5, int a6, int a7, int a8, float a9, float a10, float a11, float a12)
|
||||
{
|
||||
// @TODO: clean this up
|
||||
if (a7 == 1)
|
||||
{
|
||||
for (int i = 0; i < a6; i++)
|
||||
{
|
||||
float x2 = m_offsetX + a9 * (i + a3);
|
||||
int x3 = Mth::floor(x2);
|
||||
float x4 = float(x3);
|
||||
float x5 = x2 - x4;
|
||||
|
||||
int* x6 = &m_permutation[uint8_t(x3)];
|
||||
int* x8 = &m_permutation[uint8_t(x3 + 1)];
|
||||
float* x7 = &a2[a8 * i];
|
||||
|
||||
for (int j = 0; j < a8; j++)
|
||||
{
|
||||
float x9 = m_offsetZ + a11 * (j + a5);
|
||||
int x10 = Mth::floor(x9);
|
||||
float x11 = float(x10);
|
||||
float x12 = x9 - x11;
|
||||
|
||||
int* x13 = &m_permutation[uint8_t(x10) + m_permutation[*x6]];
|
||||
int* x15 = &m_permutation[uint8_t(x10) + m_permutation[*x8]];
|
||||
int* x14 = x8;
|
||||
|
||||
float x16 = grad2(*x13, x5, x12);
|
||||
float x17 = grad(*x15, x5 - 1, 0, x12);
|
||||
float x18 = lerp(fade(x5), x16, x17);
|
||||
float x19 = grad(x13[1], x5, 0, x12 - 1);
|
||||
float x20 = grad(x15[1], x5 - 1, 0, x12 - 1);
|
||||
float x21 = lerp(fade(x5), x19, x20);
|
||||
|
||||
*x7 += (1.0f / a12) * lerp(fade(x12), x18, x21);
|
||||
x7++;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
float x30 = 0, x31 = 0, x32 = 0, x33 = 0;
|
||||
int x34 = -1, x35 = 0;
|
||||
|
||||
for (int i = 0; i < a6; i++)
|
||||
{
|
||||
float x36 = m_offsetX + a9 * (i + a3);
|
||||
int x37 = Mth::floor(x36);
|
||||
float x38 = float(x37);
|
||||
float x39 = x36 - x38;
|
||||
float x40 = fade(x39);
|
||||
if (a8 <= 0) continue;
|
||||
|
||||
int* x42 = &m_permutation[uint8_t(x37)];
|
||||
int* x43 = &m_permutation[uint8_t(x37) + 1];
|
||||
for (int j = 0; j < a8; j++)
|
||||
{
|
||||
float x44 = m_offsetZ + a11 * (j + a5);
|
||||
int x45 = Mth::floor(x44);
|
||||
float x46 = float(x45);
|
||||
float x47 = x44 - x46;
|
||||
uint8_t x48 = uint8_t(x45);
|
||||
if (a7 <= 0) continue;
|
||||
|
||||
float* x49 = &a2[x35];
|
||||
for (int k = 0; k < a7; k++)
|
||||
{
|
||||
float x50 = m_offsetY + a10 * (k + a4);
|
||||
int x51 = Mth::floor(x50);
|
||||
float x52 = float(x51);
|
||||
float x53 = x50 - x52;
|
||||
uint8_t bx51 = uint8_t(x51);
|
||||
|
||||
if (k == 0 || bx51 != x34)
|
||||
{
|
||||
int* x54 = &m_permutation[bx51 + *x42];
|
||||
int x55 = x54[0] + x48;
|
||||
int x56 = x54[1] + x48;
|
||||
int* x57 = &m_permutation[bx51 + *x43];
|
||||
int x58 = x57[1] + x48;
|
||||
int* x59 = &m_permutation[*x57 + x48];
|
||||
float x60 = grad(m_permutation[x55], x39, x53, x47);
|
||||
float x61 = grad(*x59, x39 - 1, x53, x47);
|
||||
x33 = lerp(x40, x60, x61);
|
||||
float x62 = grad(m_permutation[x56], x39, x53 - 1, x47);
|
||||
float x63 = grad(m_permutation[x58], x39 - 1, x53 - 1, x47);
|
||||
x32 = lerp(x40, x62, x63);
|
||||
float x64 = grad(m_permutation[x55 + 1], x39, x53, x47 - 1);
|
||||
float x65 = grad(x59[1], x39 - 1, x53, x47 - 1);
|
||||
x31 = lerp(x40, x64, x65);
|
||||
float x66 = grad(m_permutation[x56 + 1], x39, x53 - 1, x47 - 1);
|
||||
float x67 = grad(m_permutation[x58 + 1], x39 - 1, x53 - 1, x47 - 1);
|
||||
x34 = bx51;
|
||||
x30 = lerp(x40, x66, x67);
|
||||
}
|
||||
|
||||
float x68 = lerp(fade(x53), x33, x32);
|
||||
float x69 = lerp(fade(x53), x31, x30);
|
||||
*x49 += (1.0f / a12) * lerp(fade(x47), x68, x69);
|
||||
x49++;
|
||||
}
|
||||
x35 += a7;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
source/Base/ImprovedNoise.hpp
Normal file
32
source/Base/ImprovedNoise.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "Random.hpp"
|
||||
#include "Synth.hpp"
|
||||
|
||||
// note: appears to maybe inherit from a class called Synth?
|
||||
// the only purpose that it serves I guess is to provide
|
||||
// a virtual getValue
|
||||
class ImprovedNoise : public Synth
|
||||
{
|
||||
public:
|
||||
float getValue(float, float) override;
|
||||
|
||||
ImprovedNoise();
|
||||
ImprovedNoise(Random* pRandom);
|
||||
|
||||
void init(Random* pRandom);
|
||||
float getValue(float, float, float);
|
||||
float noise(float, float, float);
|
||||
float grad(int, float, float, float);
|
||||
float grad2(int, float, float);
|
||||
float lerp(float prog, float a, float b);
|
||||
float fade(float x); // inlined in the code
|
||||
void add(float* a2, float a3, float a4, float a5, int a6, int a7, int a8, float a9, float a10, float a11, float a12);
|
||||
|
||||
public:
|
||||
float m_offsetX;
|
||||
float m_offsetY;
|
||||
float m_offsetZ;
|
||||
int m_permutation[512];
|
||||
};
|
||||
|
||||
52
source/Base/Matrix.cpp
Normal file
52
source/Base/Matrix.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "Matrix.hpp"
|
||||
|
||||
Matrix::Matrix()
|
||||
{
|
||||
memset(c, 0, sizeof c);
|
||||
}
|
||||
|
||||
Matrix::Matrix(float x)
|
||||
{
|
||||
memset(c, 0, sizeof c);
|
||||
c[0] = c[4 * 1 + 1] = c[4 * 2 + 2] = c[4 * 3 + 3] = x;
|
||||
}
|
||||
|
||||
Matrix::Matrix(float* p)
|
||||
{
|
||||
memcpy(c, p, sizeof c);
|
||||
}
|
||||
|
||||
Matrix::Matrix(float a, float b, float q, float d, float e, float f, float g, float h, float i, float j, float k, float l, float m, float n, float o, float p)
|
||||
{
|
||||
c[0] = a, c[1] = b, c[2] = q, c[3] = d, c[4] = e, c[5] = f, c[6] = g, c[7] = h, c[8] = i, c[9] = j, c[10] = k, c[11] = l, c[12] = m, c[13] = n, c[14] = o, c[15] = p;
|
||||
}
|
||||
|
||||
void Matrix::fetchGL(GLenum pname)
|
||||
{
|
||||
glGetFloatv(pname, c);
|
||||
}
|
||||
|
||||
Matrix operator*(const Matrix& a, const Matrix& b)
|
||||
{
|
||||
Matrix result;
|
||||
|
||||
//this is ugly
|
||||
result.c[0] = a.c[0] * b.c[0] + a.c[1] * b.c[4] + a.c[2] * b.c[8] + a.c[3] * b.c[12];
|
||||
result.c[1] = a.c[0] * b.c[1] + a.c[1] * b.c[5] + a.c[2] * b.c[9] + a.c[3] * b.c[13];
|
||||
result.c[2] = a.c[0] * b.c[2] + a.c[1] * b.c[6] + a.c[2] * b.c[10] + a.c[3] * b.c[14];
|
||||
result.c[3] = a.c[0] * b.c[3] + a.c[1] * b.c[7] + a.c[2] * b.c[11] + a.c[3] * b.c[15];
|
||||
result.c[4] = a.c[4] * b.c[0] + a.c[5] * b.c[4] + a.c[6] * b.c[8] + a.c[7] * b.c[12];
|
||||
result.c[5] = a.c[4] * b.c[1] + a.c[5] * b.c[5] + a.c[6] * b.c[9] + a.c[7] * b.c[13];
|
||||
result.c[6] = a.c[4] * b.c[2] + a.c[5] * b.c[6] + a.c[6] * b.c[10] + a.c[7] * b.c[14];
|
||||
result.c[7] = a.c[4] * b.c[3] + a.c[5] * b.c[7] + a.c[6] * b.c[11] + a.c[7] * b.c[15];
|
||||
result.c[8] = a.c[8] * b.c[0] + a.c[9] * b.c[4] + a.c[10] * b.c[8] + a.c[11] * b.c[12];
|
||||
result.c[9] = a.c[8] * b.c[1] + a.c[9] * b.c[5] + a.c[10] * b.c[9] + a.c[11] * b.c[13];
|
||||
result.c[10] = a.c[8] * b.c[2] + a.c[9] * b.c[6] + a.c[10] * b.c[10] + a.c[11] * b.c[14];
|
||||
result.c[11] = a.c[8] * b.c[3] + a.c[9] * b.c[7] + a.c[10] * b.c[11] + a.c[11] * b.c[15];
|
||||
result.c[12] = a.c[12] * b.c[0] + a.c[13] * b.c[4] + a.c[14] * b.c[8] + a.c[15] * b.c[12];
|
||||
result.c[13] = a.c[12] * b.c[1] + a.c[13] * b.c[5] + a.c[14] * b.c[9] + a.c[15] * b.c[13];
|
||||
result.c[14] = a.c[12] * b.c[2] + a.c[13] * b.c[6] + a.c[14] * b.c[10] + a.c[15] * b.c[14];
|
||||
result.c[15] = a.c[12] * b.c[3] + a.c[13] * b.c[7] + a.c[14] * b.c[11] + a.c[15] * b.c[15];
|
||||
|
||||
return result;
|
||||
}
|
||||
22
source/Base/Matrix.hpp
Normal file
22
source/Base/Matrix.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "compat/GL.hpp"
|
||||
#include "Mth.hpp"
|
||||
|
||||
class Matrix
|
||||
{
|
||||
public:
|
||||
Matrix(); // create an empty matrix
|
||||
Matrix(float a); // create an identity matrix
|
||||
Matrix(float* p); // load matrix from memory
|
||||
Matrix(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l, float m, float n, float o, float p);
|
||||
void fetchGL(GLenum pname);
|
||||
|
||||
friend Matrix operator*(const Matrix& a, const Matrix& b);
|
||||
|
||||
public:
|
||||
float c[16] = { 0.0f };
|
||||
};
|
||||
|
||||
Matrix operator*(const Matrix& a, const Matrix& b);
|
||||
|
||||
160
source/Base/Mth.cpp
Normal file
160
source/Base/Mth.cpp
Normal file
@@ -0,0 +1,160 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
Mth.cpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
|
||||
#include "Mth.hpp"
|
||||
|
||||
#define C_SIN_TABLE_MULTIPLIER (10430.0f) // (3320.0f * 3.14156f)
|
||||
|
||||
#define ANG_TO_SIN_TABLE_INDEX(ang) ((int) ((ang) * C_SIN_TABLE_MULTIPLIER))
|
||||
#define SIN_TABLE_INDEX_TO_ANG(ang) ((float)((ang) / C_SIN_TABLE_MULTIPLIER))
|
||||
|
||||
float g_SinTable[65536];
|
||||
|
||||
Random Mth::g_Random;
|
||||
|
||||
void Mth::initMth()
|
||||
{
|
||||
for (int i = 0; i < 65536; i++)
|
||||
{
|
||||
g_SinTable[i] = sinf(SIN_TABLE_INDEX_TO_ANG(i)); // value is 10430
|
||||
}
|
||||
}
|
||||
|
||||
int Mth::intFloorDiv(int a2, int a3)
|
||||
{
|
||||
if (a2 < 0)
|
||||
return ~(~a2 / a3);
|
||||
|
||||
return a2 / a3;
|
||||
}
|
||||
|
||||
float Mth::invSqrt(float number)
|
||||
{
|
||||
// It looks familiar. With IDA I get a convoluted mess. I'm going to assume
|
||||
// they just stole it from Quake.
|
||||
|
||||
int32_t i;
|
||||
float x2, y;
|
||||
const float threehalfs = 1.5F;
|
||||
|
||||
x2 = number * 0.5F;
|
||||
y = number;
|
||||
i = * ( int32_t * ) &y; // evil floating point bit level hacking
|
||||
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
|
||||
y = * ( float * ) &i;
|
||||
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
|
||||
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
float Mth::sin(float a2)
|
||||
{
|
||||
int angle = ANG_TO_SIN_TABLE_INDEX(a2) & 0xFFFF;
|
||||
|
||||
return g_SinTable[angle];
|
||||
}
|
||||
|
||||
float Mth::cos(float a2)
|
||||
{
|
||||
int angle = (ANG_TO_SIN_TABLE_INDEX(a2) + 16384) & 0xFFFF;
|
||||
|
||||
return g_SinTable[angle];
|
||||
}
|
||||
|
||||
float Mth::sqrt(float a2)
|
||||
{
|
||||
return sqrtf(a2);
|
||||
}
|
||||
|
||||
int Mth::floor(float f)
|
||||
{
|
||||
int result = int(f);
|
||||
|
||||
if (result > f)
|
||||
result--;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
float Mth::atan(float f)
|
||||
{
|
||||
return atanf(f);
|
||||
}
|
||||
|
||||
float Mth::atan2(float y, float x)
|
||||
{
|
||||
return atan2f(y, x);
|
||||
}
|
||||
|
||||
float Mth::Min(float a, float b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
int Mth::Min(int a, int b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
float Mth::Max(float a, float b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
int Mth::Max(int a, int b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
float Mth::abs(float f)
|
||||
{
|
||||
if (f < 0)
|
||||
f = -f;
|
||||
return f;
|
||||
}
|
||||
|
||||
int Mth::abs(int d)
|
||||
{
|
||||
return ::abs(d);
|
||||
}
|
||||
|
||||
float Mth::absMax(float a2, float a3)
|
||||
{
|
||||
if (a2 < 0)
|
||||
a2 = -a2;
|
||||
if (a3 < 0)
|
||||
a3 = -a3;
|
||||
if (a2 <= a3)
|
||||
a2 = a3;
|
||||
return a2;
|
||||
}
|
||||
|
||||
float Mth::absMaxSigned(float a2, float a3)
|
||||
{
|
||||
if (abs(a2) <= abs(a2))
|
||||
a2 = a3;
|
||||
return a2;
|
||||
}
|
||||
|
||||
int Mth::random(int max)
|
||||
{
|
||||
return int(g_Random.nextInt(max));
|
||||
}
|
||||
|
||||
float Mth::random()
|
||||
{
|
||||
return g_Random.genrand_int32() * (1.0f / 4294967295.0f);
|
||||
// divided by 2^32-1
|
||||
}
|
||||
|
||||
42
source/Base/Mth.hpp
Normal file
42
source/Base/Mth.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
Mth.hpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "Random.hpp"
|
||||
|
||||
class Mth
|
||||
{
|
||||
static Random g_Random;
|
||||
|
||||
public:
|
||||
static float Max(float, float);
|
||||
static int Max(int, int);
|
||||
static float Min(float, float);
|
||||
static int Min(int, int);
|
||||
static float abs(float);
|
||||
static int abs(int);
|
||||
static float absMax(float, float);
|
||||
static float absMaxSigned(float, float);
|
||||
static float atan(float);
|
||||
static float atan2(float y, float x);
|
||||
static float cos(float);
|
||||
static int floor(float);
|
||||
static void initMth();
|
||||
static int intFloorDiv(int, int);
|
||||
static float invSqrt(float);
|
||||
static int random(int);
|
||||
static float random(void);
|
||||
static float sin(float);
|
||||
static float sqrt(float);
|
||||
};
|
||||
|
||||
93
source/Base/PerlinNoise.cpp
Normal file
93
source/Base/PerlinNoise.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "PerlinNoise.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
PerlinNoise::PerlinNoise(int nOctaves)
|
||||
{
|
||||
m_pRandom = &m_random;
|
||||
init(nOctaves);
|
||||
}
|
||||
|
||||
PerlinNoise::PerlinNoise(Random* pRandom, int nOctaves)
|
||||
{
|
||||
m_pRandom = pRandom;
|
||||
|
||||
if (nOctaves == 10)
|
||||
{
|
||||
LogMsg("Ok");
|
||||
}
|
||||
|
||||
init(nOctaves);
|
||||
}
|
||||
|
||||
void PerlinNoise::init(int nOctaves)
|
||||
{
|
||||
m_nOctaves = nOctaves;
|
||||
m_pImprovedNoise = new ImprovedNoise * [nOctaves];
|
||||
|
||||
for (int i = 0; i < nOctaves; i++)
|
||||
{
|
||||
m_pImprovedNoise[i] = new ImprovedNoise(m_pRandom);
|
||||
}
|
||||
}
|
||||
|
||||
PerlinNoise::~PerlinNoise()
|
||||
{
|
||||
for (int i = 0; i < m_nOctaves; i++)
|
||||
delete[] m_pImprovedNoise[i];
|
||||
|
||||
delete[] m_pImprovedNoise;
|
||||
}
|
||||
|
||||
float PerlinNoise::getValue(float x, float y)
|
||||
{
|
||||
if (m_nOctaves <= 0) return 0.0f;
|
||||
|
||||
float result = 0.0f, x1 = 1.0f;
|
||||
|
||||
for (int i = 0; i < m_nOctaves; i++)
|
||||
{
|
||||
result += m_pImprovedNoise[i]->getValue(x * x1, y * x1) / x1;
|
||||
x1 /= 2.f;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
float PerlinNoise::getValue(float x, float y, float z)
|
||||
{
|
||||
if (m_nOctaves <= 0) return 0.0f;
|
||||
|
||||
float result = 0.0f, x1 = 1.0f;
|
||||
|
||||
for (int i = 0; i < m_nOctaves; i++)
|
||||
{
|
||||
result += m_pImprovedNoise[i]->getValue(x * x1, y * x1, z * x1) / x1;
|
||||
x1 /= 2.f;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
float* PerlinNoise::getRegion(float* a2, int a3, int a4, int a5, int a6, float a7, float a8, float a9)
|
||||
{
|
||||
return getRegion(a2, float(a3), 10.0f, float(a4), a5, 1, a6, a7, 1.0f, a8);
|
||||
}
|
||||
|
||||
float* PerlinNoise::getRegion(float* pMem, float a3, float a4, float a5, int a6, int a7, int a8, float a9, float a10, float a11)
|
||||
{
|
||||
int amt = a6 * a7 * a8;
|
||||
if (!pMem)
|
||||
pMem = new float[amt];
|
||||
|
||||
for (int i = 0; i < amt; i++)
|
||||
pMem[i] = 0;
|
||||
|
||||
float x = 1.0f;
|
||||
for (int i = 0; i < m_nOctaves; i++)
|
||||
{
|
||||
m_pImprovedNoise[i]->add(pMem, a3, a4, a5, a6, a7, a8, a9 * x, a10 * x, a11 * x, x);
|
||||
x /= 2;
|
||||
}
|
||||
|
||||
return pMem;
|
||||
}
|
||||
25
source/Base/PerlinNoise.hpp
Normal file
25
source/Base/PerlinNoise.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "ImprovedNoise.hpp"
|
||||
|
||||
class PerlinNoise : public Synth
|
||||
{
|
||||
public:
|
||||
PerlinNoise(int nOctaves);
|
||||
PerlinNoise(Random*, int nOctaves);
|
||||
virtual ~PerlinNoise();
|
||||
void init(int nOctaves);
|
||||
|
||||
float getValue(float, float) override;
|
||||
float getValue(float, float, float);
|
||||
|
||||
float* getRegion(float*, int, int, int, int, float, float, float);
|
||||
float* getRegion(float*, float, float , float, int, int, int, float, float, float);
|
||||
|
||||
private:
|
||||
ImprovedNoise** m_pImprovedNoise;
|
||||
int m_nOctaves;
|
||||
Random m_random;
|
||||
Random* m_pRandom; // random for seeding, I assume
|
||||
};
|
||||
|
||||
110
source/Base/Random.cpp
Normal file
110
source/Base/Random.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
Random.cpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "Random.hpp"
|
||||
|
||||
/* Period parameters */
|
||||
#define N 624
|
||||
#define M 397
|
||||
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
|
||||
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
|
||||
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
|
||||
|
||||
Random::Random(long seed)
|
||||
{
|
||||
setSeed(seed);
|
||||
}
|
||||
|
||||
void Random::setSeed(long seed)
|
||||
{
|
||||
rseed = seed;
|
||||
mti = N + 1;
|
||||
init_genrand(seed);
|
||||
}
|
||||
|
||||
/* initializes mt[N] with a seed */
|
||||
void Random::init_genrand(unsigned long s)
|
||||
{
|
||||
mt[0] = s & 0xffffffffUL;
|
||||
for (mti = 1; mti < N; mti++) {
|
||||
mt[mti] =
|
||||
(1812433253UL * (mt[mti - 1] ^ (mt[mti - 1] >> 30)) + mti);
|
||||
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
||||
/* In the previous versions, MSBs of the seed affect */
|
||||
/* only MSBs of the array mt[]. */
|
||||
/* 2002/01/09 modified by Makoto Matsumoto */
|
||||
mt[mti] &= 0xffffffffUL;
|
||||
/* for >32 bit machines */
|
||||
}
|
||||
}
|
||||
|
||||
int Random::nextInt(int max)
|
||||
{
|
||||
return int(genrand_int32() % unsigned(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};
|
||||
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
||||
|
||||
if (mti >= N) { /* generate N words at one time */
|
||||
int kk;
|
||||
|
||||
if (mti == N+1) /* if init_genrand() has not been called, */
|
||||
init_genrand(5489UL); /* a default initial seed is used */
|
||||
|
||||
for (kk=0;kk<N-M;kk++) {
|
||||
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
|
||||
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
||||
}
|
||||
for (;kk<N-1;kk++) {
|
||||
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
|
||||
mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
||||
}
|
||||
y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
|
||||
mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
||||
|
||||
mti = 0;
|
||||
}
|
||||
|
||||
y = mt[mti++];
|
||||
|
||||
/* Tempering */
|
||||
y ^= (y >> 11);
|
||||
y ^= (y << 7) & 0x9d2c5680UL;
|
||||
y ^= (y << 15) & 0xefc60000UL;
|
||||
y ^= (y >> 18);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
float Random::nextFloat()
|
||||
{
|
||||
return float(genrand_real2());
|
||||
}
|
||||
|
||||
double Random::genrand_real2()
|
||||
{
|
||||
return double(genrand_int32()) * (1.0 / 4294967296.0);
|
||||
}
|
||||
|
||||
long Random::nextLong()
|
||||
{
|
||||
return long(genrand_int32() >> 1);
|
||||
}
|
||||
|
||||
int Random::nextInt()
|
||||
{
|
||||
return int(genrand_int32() >> 1);
|
||||
}
|
||||
56
source/Base/Random.hpp
Normal file
56
source/Base/Random.hpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
Random.hpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// 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
|
||||
// the Mersenne Twister:
|
||||
// http://www.math.sci.hiroshima-u.ac.jp/m-mat/MT/MT2002/CODES/mt19937ar.c
|
||||
|
||||
//A random generator based on the Mersenne Twister originally developed by Takuji Nishimura and Makoto Matsumoto.
|
||||
// From the book GameCoding Complete by Mike McShaffry
|
||||
|
||||
/* Period parameters */
|
||||
#define CMATH_N 624
|
||||
#define CMATH_M 397
|
||||
#define CMATH_MATRIX_A 0x9908b0df /* constant vector a */
|
||||
#define CMATH_UPPER_MASK 0x80000000 /* most significant w-r bits */
|
||||
#define CMATH_LOWER_MASK 0x7fffffff /* least significant r bits */
|
||||
|
||||
/* Tempering parameters */
|
||||
#define CMATH_TEMPERING_MASK_B 0x9d2c5680
|
||||
#define CMATH_TEMPERING_MASK_C 0xefc60000
|
||||
#define CMATH_TEMPERING_SHIFT_U(y) (y >> 11)
|
||||
#define CMATH_TEMPERING_SHIFT_S(y) (y << 7)
|
||||
#define CMATH_TEMPERING_SHIFT_T(y) (y << 15)
|
||||
#define CMATH_TEMPERING_SHIFT_L(y) (y >> 18)
|
||||
|
||||
int getTimeMs();
|
||||
|
||||
class Random
|
||||
{
|
||||
unsigned int rseed;
|
||||
unsigned long 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);
|
||||
int nextInt(int max);
|
||||
unsigned genrand_int32();
|
||||
float nextFloat();
|
||||
double genrand_real2();
|
||||
long nextLong();
|
||||
int nextInt();
|
||||
};
|
||||
1
source/Base/Synth.cpp
Normal file
1
source/Base/Synth.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "Synth.hpp"
|
||||
8
source/Base/Synth.hpp
Normal file
8
source/Base/Synth.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
class Synth
|
||||
{
|
||||
public:
|
||||
virtual float getValue(float, float) = 0;
|
||||
};
|
||||
|
||||
39
source/Base/Timer.cpp
Normal file
39
source/Base/Timer.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "Timer.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
void Timer::advanceTime()
|
||||
{
|
||||
int timeMs = getTimeMs();
|
||||
if (timeMs - field_4 <= 1000)
|
||||
{
|
||||
if (timeMs - field_4 < 0)
|
||||
{
|
||||
field_4 = field_8 = timeMs;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int diff1 = timeMs - field_4;
|
||||
int diff2 = timeMs - field_8;
|
||||
field_C += ((float(diff1) / float(diff2)) - field_C) * 0.2f;
|
||||
}
|
||||
|
||||
float diff = float(timeMs) / 1000.0f - field_0;
|
||||
field_0 = float(timeMs) / 1000.0f;
|
||||
|
||||
float x1 = diff * field_C;
|
||||
if (x1 > 1) x1 = 1;
|
||||
if (x1 < 0) x1 = 0;
|
||||
|
||||
float x2 = field_20 + x1 * field_1C * field_10;
|
||||
field_14 = int(x2);
|
||||
field_20 = x2 - field_14;
|
||||
field_18 = x2 - field_14;
|
||||
if (field_14 > 10)
|
||||
field_14 = 10;
|
||||
}
|
||||
|
||||
Timer::Timer()
|
||||
{
|
||||
field_4 = field_8 = getTimeMs();
|
||||
}
|
||||
21
source/Base/Timer.hpp
Normal file
21
source/Base/Timer.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
Timer();
|
||||
|
||||
void advanceTime();
|
||||
|
||||
public:
|
||||
float field_0 = 0;
|
||||
int field_4 = 0;
|
||||
int field_8 = 0;
|
||||
float field_C = 1.0f;
|
||||
float field_10 = 20.0f;
|
||||
int field_14 = 0;
|
||||
float field_18 = 0;
|
||||
float field_1C = 1.0f;
|
||||
float field_20 = 0;
|
||||
};
|
||||
|
||||
83
source/Base/Util.cpp
Normal file
83
source/Base/Util.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
Util.cpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#include "Util.hpp"
|
||||
|
||||
std::string Util::stringTrim(const std::string& str, const std::string& filter, bool a4, bool a5)
|
||||
{
|
||||
if (str.empty() || filter.empty())
|
||||
return "";
|
||||
|
||||
// don't know what the fuck this does. TODO: clean this crap up
|
||||
if (!a4 && !a5)
|
||||
return "";
|
||||
|
||||
int v12, strIndex = 0, v13, v17, strLength = int(str.size()), filterLength = int(filter.size());
|
||||
|
||||
if (a4)
|
||||
{
|
||||
v12 = strLength - 1;
|
||||
if (strLength > 0)
|
||||
{
|
||||
v17 = strLength - 1;
|
||||
do
|
||||
{
|
||||
const void* v14 = memchr(filter.c_str(), str[strIndex], filterLength);
|
||||
if (!v14)
|
||||
{
|
||||
v13 = strIndex;
|
||||
v12 = v17;
|
||||
goto label_12;
|
||||
}
|
||||
|
||||
++strIndex;
|
||||
} while (strIndex != strLength);
|
||||
|
||||
v12 = strLength - 1;
|
||||
v13 = strIndex;
|
||||
}
|
||||
else v13 = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (a5)
|
||||
{
|
||||
v12 = strLength - 1;
|
||||
strIndex = 0;
|
||||
v13 = 0;
|
||||
|
||||
goto label_19;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
label_12:
|
||||
if (a5)
|
||||
{
|
||||
v13 = strIndex;
|
||||
label_19:
|
||||
while (v12 >= strIndex)
|
||||
{
|
||||
const void* v15 = memchr(filter.c_str(), str[strIndex], filterLength);
|
||||
if (!v15)
|
||||
break;
|
||||
--v12;
|
||||
}
|
||||
}
|
||||
|
||||
return std::string(str, v13, v12 - 1 + strIndex);
|
||||
}
|
||||
|
||||
std::string Util::stringTrim(const std::string& str)
|
||||
{
|
||||
return stringTrim(str, " \t\n\r", true, true);
|
||||
}
|
||||
|
||||
72
source/Base/Util.hpp
Normal file
72
source/Base/Util.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
Util.cpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Util
|
||||
{
|
||||
public:
|
||||
static std::string stringTrim(const std::string &, const std::string &, bool, bool);
|
||||
static std::string stringTrim(const std::string &);
|
||||
|
||||
template<typename T>
|
||||
static bool remove(std::vector<T>& vec, const T& t)
|
||||
{
|
||||
auto iter = std::find(vec.begin(), vec.end(), t);
|
||||
if (iter == vec.end())
|
||||
return false;
|
||||
|
||||
vec.erase(iter);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static int removeAll(std::vector<T>& vec, const std::vector<T>& toRemove)
|
||||
{
|
||||
int removed = 0;
|
||||
|
||||
for (auto rem : toRemove)
|
||||
{
|
||||
if (remove(vec, rem))
|
||||
removed++;
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
// @TODO: reverse the actual thing? This is something different, but I'm lazy. It uses std::string::replace
|
||||
static void stringReplace(std::string& in, const std::string& what, const std::string& with)
|
||||
{
|
||||
//snippet from Zahlman's post on gamedev: http://www.gamedev.net/community/forums/topic.asp?topic_id=372125
|
||||
size_t pos = 0;
|
||||
size_t whatLen = what.length();
|
||||
size_t withLen = with.length();
|
||||
while ((pos = in.find(what, pos)) != std::string::npos)
|
||||
{
|
||||
in.replace(pos, whatLen, with);
|
||||
pos += withLen;
|
||||
}
|
||||
}
|
||||
|
||||
static long hashCode(const std::string& str)
|
||||
{
|
||||
long result = 0;
|
||||
|
||||
for (auto chr : str)
|
||||
{
|
||||
result = result * 31 + chr;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
218
source/Base/Utils.cpp
Normal file
218
source/Base/Utils.cpp
Normal file
@@ -0,0 +1,218 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
Utils.cpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
// note: not an official file name
|
||||
|
||||
#include "Utils.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
|
||||
// Why are we not using GetTickCount64()? It's simple -- getTimeMs has the exact same problem as using regular old GetTickCount.
|
||||
#pragma warning(disable : 28159)
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "compat/GL.hpp"
|
||||
|
||||
int g_TimeSecondsOnInit = 0;
|
||||
|
||||
const char* GetTerrainName()
|
||||
{
|
||||
return "terrain.png";
|
||||
}
|
||||
|
||||
const char* GetItemsName()
|
||||
{
|
||||
return "gui/items.png";
|
||||
}
|
||||
|
||||
const char* GetGUIBlocksName()
|
||||
{
|
||||
return "gui/gui_blocks.png";
|
||||
}
|
||||
|
||||
// In regular mode, getTimeMs depends on getTimeS.
|
||||
// In Win32 mode, it's vice versa. Cool
|
||||
|
||||
int getTimeMs();
|
||||
|
||||
float getTimeS()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return float(getTimeMs()) / 1000.0f;
|
||||
#else
|
||||
// variant implemented by Mojang. This does not work on MSVC
|
||||
timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
if (g_TimeSecondsOnInit == 0)
|
||||
g_TimeSecondsOnInit = tv.tv_sec;
|
||||
|
||||
return float(tv.tv_sec - g_TimeSecondsOnInit) + float(tv.tv_usec) / 1000000.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
int getTimeMs()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// just return GetTickCount
|
||||
int time = GetTickCount();
|
||||
|
||||
if (g_TimeSecondsOnInit == 0)
|
||||
g_TimeSecondsOnInit = time;
|
||||
|
||||
return time - g_TimeSecondsOnInit;
|
||||
#else
|
||||
return int(getTimeS() * 1000.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
time_t getRawTimeS()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return time_t(GetTickCount() / 1000);
|
||||
#else
|
||||
timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
return tv.tv_sec;
|
||||
#endif
|
||||
}
|
||||
|
||||
time_t getEpochTimeS()
|
||||
{
|
||||
return time(0);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
HINSTANCE g_hInstance = NULL;
|
||||
HWND g_hWnd = NULL;
|
||||
|
||||
void SetInstance(HINSTANCE hinst)
|
||||
{
|
||||
g_hInstance = hinst;
|
||||
}
|
||||
|
||||
HINSTANCE GetInstance()
|
||||
{
|
||||
return g_hInstance;
|
||||
}
|
||||
|
||||
void SetHWND(HWND hwnd)
|
||||
{
|
||||
g_hWnd = hwnd;
|
||||
}
|
||||
|
||||
HWND GetHWND()
|
||||
{
|
||||
return g_hWnd;
|
||||
}
|
||||
|
||||
void CenterWindow(HWND hWnd)
|
||||
{
|
||||
RECT r, desk;
|
||||
GetWindowRect(hWnd, &r);
|
||||
GetWindowRect(GetDesktopWindow(), &desk);
|
||||
|
||||
int wa, ha, wb, hb;
|
||||
|
||||
wa = (r.right - r.left) / 2;
|
||||
ha = (r.bottom - r.top) / 2;
|
||||
|
||||
wb = (desk.right - desk.left) / 2;
|
||||
hb = (desk.bottom - desk.top) / 2;
|
||||
|
||||
SetWindowPos(hWnd, NULL, wb - wa, hb - ha, r.right - r.left, r.bottom - r.top, 0);
|
||||
}
|
||||
|
||||
void EnableOpenGL(HWND hwnd, HDC* hDC, HGLRC* hRC)
|
||||
{
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
|
||||
int iFormat;
|
||||
|
||||
/* get the device context (DC) */
|
||||
*hDC = GetDC(hwnd);
|
||||
|
||||
/* set the pixel format for the DC */
|
||||
ZeroMemory(&pfd, sizeof(pfd));
|
||||
|
||||
pfd.nSize = sizeof(pfd);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
|
||||
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = 24;
|
||||
pfd.cDepthBits = 16;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
|
||||
iFormat = ChoosePixelFormat(*hDC, &pfd);
|
||||
|
||||
SetPixelFormat(*hDC, iFormat, &pfd);
|
||||
|
||||
/* create and enable the render context (RC) */
|
||||
*hRC = wglCreateContext(*hDC);
|
||||
|
||||
wglMakeCurrent(*hDC, *hRC);
|
||||
}
|
||||
|
||||
void DisableOpenGL(HWND hwnd, HDC hDC, HGLRC hRC)
|
||||
{
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
wglDeleteContext(hRC);
|
||||
ReleaseDC(hwnd, hDC);
|
||||
}
|
||||
|
||||
void sleepMs(int ms)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Sleep(ms);
|
||||
#else
|
||||
usleep(1000 * ms);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void drawArrayVT(GLuint buffer, int count, int stride)
|
||||
{
|
||||
xglBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glTexCoordPointer(2, GL_FLOAT, stride, (void*)12);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glVertexPointer(3, GL_FLOAT, stride, nullptr);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glDrawArrays(GL_TRIANGLES, 0, count);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
void drawArrayVTC(GLuint buffer, int count, int stride)
|
||||
{
|
||||
xglBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glVertexPointer(3, GL_FLOAT, stride, nullptr);
|
||||
glTexCoordPointer(2, GL_FLOAT, stride, (void*)12);
|
||||
glColorPointer(4, GL_UNSIGNED_BYTE, stride, (void*)20);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glDrawArrays(GL_TRIANGLES, 0, count);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
}
|
||||
|
||||
float Max(float a, float b)
|
||||
{
|
||||
if (a < b)
|
||||
a = b;
|
||||
return a;
|
||||
}
|
||||
568
source/Base/Utils.hpp
Normal file
568
source/Base/Utils.hpp
Normal file
@@ -0,0 +1,568 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
Utils.hpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ctime>
|
||||
#include <cstdio> // have to include this to avoid it being included again later from being a problem
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
// @HACK: Include WinSock2.h also
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#include <WS2tcpip.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include "compat/AKeyCodes.hpp"
|
||||
|
||||
#ifndef ORIGINAL_CODE
|
||||
// Enhancements
|
||||
//#define ENH_ENTITY_SHADING // Allows shading of entities
|
||||
//#define ENH_SHADE_HELD_TILES // Allows shading of the item in hand
|
||||
//#define ENH_FIX_INVIS_STAIRS // Fixes a bug wherein a 16x16x16 chunk in the world that contains only stairs is invisible
|
||||
//#define ENH_ALLOW_AO // Allows using the F4 key to toggle ambient occlusion (buggy)
|
||||
//#define ENH_TRANSPARENT_HOTBAR // Allows the hotbar to be transparent. Due to a bug in the code, it is not.
|
||||
//#define ENH_INSTA_BREAK // Allows instant breaking of blocks. @TODO: Fix the mode without this
|
||||
//#define ENH_CAMERA_NO_PARTICLES // Hide particles from the view of a camera, such as smoke, that would otherwise render the resulting image useless.
|
||||
//#define ENH_USE_JAVA_LIGHT_RAMP // Use Java Beta 1.3 light ramp instead of flawed PE one
|
||||
//#define ENH_RUN_DAY_NIGHT_CYCLE // Allow the day/night cycle to run.
|
||||
//#define ENH_ENABLE_9TH_SLOT // Enable the 9th hotbar slot, instead of it being a "..." placeholder
|
||||
//#define ENH_USE_OWN_AO // Use own ambient occlusion engine - looks pretty much the same except it fixes the corners
|
||||
//#define ENH_ADD_OPTIONS_PAUSE // Add an 'options' button in the pause menu
|
||||
//#define ENH_EXTRA_ITEMS_IN_INV // Add extra items in a new 5th row in the inventory.
|
||||
//#define ENH_HIGHLIGHT_BY_HOVER // Highlight buttons by hovering them instead of the usual way.
|
||||
//#define ENH_ALLOW_SAND_GRAVITY // Allow sand to fall.
|
||||
//#define ENH_USE_GUI_SCALE_2 // Use a 2x GUI scale instead of 3x. Looks better on PC
|
||||
|
||||
// Mods
|
||||
//#define MOD_USE_FLAT_WORLD // Use a flat world instead of the regular world generation
|
||||
//#define MOD_USE_BIGGER_SCREEN_SIZE // Use a bigger screen size instead of 854x480
|
||||
//#define MOD_DONT_COLOR_GRASS // Don't give the top of grass tiles a different color. (like Classic)
|
||||
|
||||
// Tests
|
||||
//#define TEST_DROPPED_ITEMS // Allow dropped items to be dropped and collected.
|
||||
|
||||
// Toggle Demo Mode
|
||||
#define DEMO
|
||||
|
||||
#else
|
||||
|
||||
#define DEMO
|
||||
|
||||
#endif
|
||||
|
||||
// don't know where to declare these:
|
||||
|
||||
#ifndef MOD_USE_BIGGER_SCREEN_SIZE
|
||||
#define C_DEFAULT_SCREEN_WIDTH (854)
|
||||
#define C_DEFAULT_SCREEN_HEIGHT (480)
|
||||
#else
|
||||
#define C_DEFAULT_SCREEN_WIDTH (1280)
|
||||
#define C_DEFAULT_SCREEN_HEIGHT (720)
|
||||
#endif
|
||||
|
||||
#define C_MAX_TILES (256)
|
||||
|
||||
#define C_DEFAULT_PORT (19132)
|
||||
#define C_MAX_CONNECTIONS (4) // pitiful
|
||||
|
||||
constexpr int C_MIN_X = -32000000, C_MAX_X = 32000000;
|
||||
constexpr int C_MIN_Z = -32000000, C_MAX_Z = 32000000;
|
||||
constexpr int C_MIN_Y = 0, C_MAX_Y = 128;
|
||||
|
||||
const char* GetTerrainName();
|
||||
const char* GetItemsName();
|
||||
const char* GetGUIBlocksName();
|
||||
|
||||
#ifdef ORIGINAL_CODE
|
||||
#define C_TERRAIN_NAME "terrain.png"
|
||||
#define C_ITEMS_NAME "gui/items.png"
|
||||
#define C_BLOCKS_NAME "gui/gui_blocks.png"
|
||||
#else
|
||||
#define C_TERRAIN_NAME GetTerrainName()
|
||||
#define C_ITEMS_NAME "gui/items.png"
|
||||
#define C_BLOCKS_NAME "gui/gui_blocks.png"
|
||||
#endif
|
||||
|
||||
#define C_MAX_CHUNKS_X (16)
|
||||
#define C_MAX_CHUNKS_Z (16)
|
||||
|
||||
// 9 chunks around a player things will tick
|
||||
#define C_TICK_DISTANCE_CHKS (9)
|
||||
|
||||
enum eTileID
|
||||
{
|
||||
TILE_AIR,
|
||||
TILE_STONE,
|
||||
TILE_GRASS,
|
||||
TILE_DIRT,
|
||||
TILE_STONEBRICK,
|
||||
TILE_WOOD,
|
||||
|
||||
TILE_BEDROCK = 7,
|
||||
|
||||
TILE_WATER = 8,
|
||||
TILE_WATER_CALM,
|
||||
TILE_LAVA,
|
||||
TILE_LAVA_CALM,
|
||||
|
||||
TILE_SAND = 12,
|
||||
TILE_GRAVEL,
|
||||
TILE_ORE_GOLD,
|
||||
TILE_ORE_IRON,
|
||||
TILE_ORE_COAL,
|
||||
|
||||
TILE_TREE_TRUNK = 17,
|
||||
TILE_LEAVES,
|
||||
|
||||
TILE_GLASS = 20,
|
||||
TILE_ORE_LAPIS,
|
||||
|
||||
TILE_SANDSTONE = 24,
|
||||
|
||||
TILE_CLOTH = 35,
|
||||
|
||||
TILE_FLOWER = 37,
|
||||
TILE_ROSE,
|
||||
TILE_MUSHROOM_1,
|
||||
TILE_MUSHROOM_2,
|
||||
|
||||
TILE_BLOCK_GOLD = 41,
|
||||
TILE_BLOCK_IRON,
|
||||
TILE_STONESLAB_FULL,
|
||||
TILE_STONESLAB_HALF,
|
||||
TILE_BRICKS,
|
||||
TILE_TNT,
|
||||
|
||||
TILE_OBSIDIAN = 49,
|
||||
TILE_TORCH,
|
||||
TILE_FIRE,
|
||||
|
||||
TILE_STAIRS_WOOD = 53,
|
||||
|
||||
TILE_ORE_EMERALD = 56,
|
||||
TILE_BLOCK_EMERALD,
|
||||
|
||||
TILE_FARMLAND = 60,
|
||||
|
||||
TILE_DOOR_WOOD = 64,
|
||||
TILE_LADDER,
|
||||
|
||||
TILE_STAIRS_STONE = 67,
|
||||
|
||||
TILE_DOOR_IRON = 71,
|
||||
|
||||
TILE_ORE_REDSTONE = 73,
|
||||
TILE_ORE_REDSTONE_LIT,
|
||||
|
||||
TILE_TOPSNOW = 78,
|
||||
TILE_ICE,
|
||||
|
||||
TILE_CLAY = 82,
|
||||
TILE_REEDS,
|
||||
|
||||
TILE_INVISIBLE = 95,
|
||||
|
||||
TILE_CLOTH_00 = 101,
|
||||
TILE_CLOTH_10,
|
||||
TILE_CLOTH_20,
|
||||
TILE_CLOTH_30,
|
||||
TILE_CLOTH_40,
|
||||
TILE_CLOTH_50,
|
||||
TILE_CLOTH_60,
|
||||
TILE_CLOTH_70,
|
||||
TILE_CLOTH_01,
|
||||
TILE_CLOTH_11,
|
||||
TILE_CLOTH_21,
|
||||
TILE_CLOTH_31,
|
||||
TILE_CLOTH_41,
|
||||
TILE_CLOTH_51,
|
||||
TILE_CLOTH_61,
|
||||
|
||||
ITEM_SHOVEL_IRON = 256,
|
||||
ITEM_PICKAXE_IRON,
|
||||
ITEM_HATCHET_IRON,
|
||||
ITEM_FLINT_AND_STEEL,
|
||||
ITEM_APPLE,
|
||||
ITEM_BOW,
|
||||
ITEM_ARROW,
|
||||
ITEM_COAL,
|
||||
ITEM_EMERALD,
|
||||
ITEM_INGOT_IRON,
|
||||
ITEM_INGOT_GOLD,
|
||||
ITEM_SWORD_IRON,
|
||||
ITEM_SWORD_WOOD,
|
||||
ITEM_SHOVEL_WOOD,
|
||||
ITEM_PICKAXE_WOOD,
|
||||
ITEM_HATCHET_WOOD,
|
||||
ITEM_SWORD_STONE,
|
||||
ITEM_SHOVEL_STONE,
|
||||
ITEM_PICKAXE_STONE,
|
||||
ITEM_HATCHET_STONE,
|
||||
ITEM_SWORD_EMERALD,
|
||||
ITEM_SHOVEL_EMERALD,
|
||||
ITEM_PICKAXE_EMERALD,
|
||||
ITEM_HATCHET_EMERALD,
|
||||
ITEM_STICK,
|
||||
ITEM_BOWL,
|
||||
ITEM_STEW_MUSHROOM,
|
||||
ITEM_SWORD_GOLD,
|
||||
ITEM_SHOVEL_GOLD,
|
||||
ITEM_PICKAXE_GOLD,
|
||||
ITEM_HATCHET_GOLD,
|
||||
ITEM_STRING,
|
||||
ITEM_FEATHER,
|
||||
ITEM_SULPHUR,
|
||||
ITEM_HOE_WOOD,
|
||||
ITEM_HOE_STONE,
|
||||
ITEM_HOE_IRON,
|
||||
ITEM_HOE_EMERALD,
|
||||
ITEM_HOE_GOLD,
|
||||
ITEM_SEEDS,
|
||||
ITEM_WHEAT,
|
||||
ITEM_BREAD,
|
||||
ITEM_HELMET_CLOTH,
|
||||
ITEM_CHESTPLATE_CLOTH,
|
||||
ITEM_LEGGINGS_CLOTH,
|
||||
ITEM_BOOTS_CLOTH,
|
||||
ITEM_HELMET_CHAIN,
|
||||
ITEM_CHESTPLATE_CHAIN,
|
||||
ITEM_LEGGINGS_CHAIN,
|
||||
ITEM_BOOTS_CHAIN,
|
||||
ITEM_HELMET_IRON,
|
||||
ITEM_CHESTPLATE_IRON,
|
||||
ITEM_LEGGINGS_IRON,
|
||||
ITEM_BOOTS_IRON,
|
||||
ITEM_HELMET_EMERALD,
|
||||
ITEM_CHESTPLATE_EMERALD,
|
||||
ITEM_LEGGINGS_EMERALD,
|
||||
ITEM_BOOTS_EMERALD,
|
||||
ITEM_HELMET_GOLD,
|
||||
ITEM_CHESTPLATE_GOLD,
|
||||
ITEM_LEGGINGS_GOLD,
|
||||
ITEM_BOOTS_GOLD,
|
||||
ITEM_FLINT,
|
||||
ITEM_PORKCHOP_RAW,
|
||||
ITEM_PORKCHOP_COOKED,
|
||||
ITEM_PAINTING,
|
||||
ITEM_APPLE_GOLD,
|
||||
ITEM_SIGN,
|
||||
ITEM_DOOR_WOOD,
|
||||
ITEM_BUCKET,
|
||||
ITEM_BUCKET_WATER,
|
||||
ITEM_BUCKET_LAVA,
|
||||
ITEM_MINECART,
|
||||
ITEM_SADDLE,
|
||||
ITEM_DOOR_IRON,
|
||||
ITEM_REDSTONE,
|
||||
ITEM_SNOWBALL,
|
||||
ITEM_BOAT,
|
||||
ITEM_LEATHER,
|
||||
ITEM_BUCKET_MILK,
|
||||
ITEM_BRICK,
|
||||
ITEM_CLAY,
|
||||
ITEM_REEDS,
|
||||
ITEM_PAPER,
|
||||
ITEM_BOOK,
|
||||
ITEM_SLIME_BALL,
|
||||
ITEM_MINECART_CHEST,
|
||||
ITEM_MINECART_FURNACE,
|
||||
ITEM_EGG,
|
||||
ITEM_COMPASS,
|
||||
ITEM_FISHING_ROD,
|
||||
ITEM_CLOCK,
|
||||
ITEM_YELLOW_DUST,
|
||||
ITEM_FISH_RAW,
|
||||
ITEM_FISH_COOKED,
|
||||
ITEM_DYE_POWDER,
|
||||
ITEM_BONE,
|
||||
ITEM_SUGAR,
|
||||
ITEM_CAKE,
|
||||
ITEM_BED,
|
||||
ITEM_DIODE,
|
||||
ITEM_COOKIE,
|
||||
ITEM_RECORD_01,
|
||||
ITEM_RECORD_02,
|
||||
ITEM_CAMERA = 456,
|
||||
};
|
||||
|
||||
enum // Textures
|
||||
{
|
||||
TEXTURE_GRASS_TOP = 0,
|
||||
TEXTURE_STONE,
|
||||
TEXTURE_DIRT,
|
||||
TEXTURE_GRASS_SIDE,
|
||||
TEXTURE_PLANKS,
|
||||
TEXTURE_STONE_SLAB_SIDE,
|
||||
TEXTURE_STONE_SLAB_TOP,
|
||||
TEXTURE_BRICKS,
|
||||
TEXTURE_TNT_SIDE,
|
||||
TEXTURE_TNT_TOP,
|
||||
TEXTURE_TNT_BOTTOM,
|
||||
TEXTURE_COBWEB,
|
||||
TEXTURE_ROSE,
|
||||
TEXTURE_FLOWER,
|
||||
TEXTURE_WATER_STATIC,
|
||||
TEXTURE_SAPLING,
|
||||
TEXTURE_STONEBRICK,
|
||||
TEXTURE_BEDROCK,
|
||||
TEXTURE_SAND,
|
||||
TEXTURE_GRAVEL,
|
||||
TEXTURE_LOG_SIDE,
|
||||
TEXTURE_LOG_TOP,
|
||||
TEXTURE_IRON,
|
||||
TEXTURE_GOLD,
|
||||
TEXTURE_EMERALD,
|
||||
TEXTURE_CHEST_ONE_TOP,
|
||||
TEXTURE_CHEST_ONE_SIDE,
|
||||
TEXTURE_CHEST_ONE_FRONT,
|
||||
TEXTURE_MUSHROOM_RED,
|
||||
TEXTURE_MUSHROOM_BROWN,
|
||||
TEXTURE_NONE30,
|
||||
TEXTURE_FIRE1,
|
||||
TEXTURE_ORE_GOLD,
|
||||
TEXTURE_ORE_IRON,
|
||||
TEXTURE_ORE_COAL,
|
||||
TEXTURE_BOOKSHELF,
|
||||
TEXTURE_MOSSY_STONE,
|
||||
TEXTURE_OBSIDIAN,
|
||||
TEXTURE_OBSIDIAN_CRYING,
|
||||
TEXTURE_NONE39,
|
||||
TEXTURE_NONE40,
|
||||
TEXTURE_CHEST_TWO_FRONT_LEFT,
|
||||
TEXTURE_CHEST_TWO_FRONT_RIGHT,
|
||||
TEXTURE_WORKBENCH_TOP,
|
||||
TEXTURE_FURNACE_FRONT,
|
||||
TEXTURE_FURNACE_SIDE,
|
||||
TEXTURE_DISPENSER_SIDE,
|
||||
TEXTURE_FIRE2,
|
||||
TEXTURE_SPONGE,
|
||||
TEXTURE_GLASS,
|
||||
TEXTURE_ORE_EMERALD,
|
||||
TEXTURE_ORE_RED_STONE,
|
||||
TEXTURE_LEAVES_TRANSPARENT,
|
||||
TEXTURE_LEAVES_OPAQUE,
|
||||
TEXTURE_NONE54,
|
||||
TEXTURE_NONE55,
|
||||
TEXTURE_NONE56,
|
||||
TEXTURE_CHEST_TWO_BACK_LEFT,
|
||||
TEXTURE_CHEST_TWO_BACK_RIGHT,
|
||||
TEXTURE_WORKBENCH_SIDE_1,
|
||||
TEXTURE_WORKBENCH_SIDE_2,
|
||||
TEXTURE_FURNACE_LIT,
|
||||
TEXTURE_FURNACE_TOP,
|
||||
TEXTURE_NONE63,
|
||||
TEXTURE_CLOTH_64,
|
||||
TEXTURE_SPAWNER,
|
||||
TEXTURE_SNOW,
|
||||
TEXTURE_ICE,
|
||||
TEXTURE_GRASS_SIDE_SNOW,
|
||||
TEXTURE_CACTUS_TOP,
|
||||
TEXTURE_CACTUS_SIDE,
|
||||
TEXTURE_CACTUS_BOTTOM,
|
||||
TEXTURE_CLAY,
|
||||
TEXTURE_REEDS,
|
||||
TEXTURE_JUKEBOX_SIDE,
|
||||
TEXTURE_JUKEBOX_TOP,
|
||||
TEXTURE_NONE76,
|
||||
TEXTURE_NONE77,
|
||||
TEXTURE_NONE78,
|
||||
TEXTURE_NONE79,
|
||||
TEXTURE_TORCH_LIT,
|
||||
TEXTURE_DOOR_TOP,
|
||||
TEXTURE_DOOR_IRON_TOP,
|
||||
TEXTURE_LADDER,
|
||||
TEXTURE_NONE84,
|
||||
TEXTURE_NONE85,
|
||||
TEXTURE_FARMLAND,
|
||||
TEXTURE_FARMLAND_DRY,
|
||||
TEXTURE_WHEAT_0,
|
||||
TEXTURE_WHEAT_1,
|
||||
TEXTURE_WHEAT_2,
|
||||
TEXTURE_WHEAT_3,
|
||||
TEXTURE_WHEAT_4,
|
||||
TEXTURE_WHEAT_5,
|
||||
TEXTURE_WHEAT_6,
|
||||
TEXTURE_WHEAT_7,
|
||||
TEXTURE_LEVER,
|
||||
TEXTURE_DOOR_BOTTOM,
|
||||
TEXTURE_DOOR_IRON_BOTTOM,
|
||||
TEXTURE_TORCH_RED_STONE,
|
||||
TEXTURE_NONE100,
|
||||
TEXTURE_NONE101,
|
||||
TEXTURE_PUMPKIN_TOP,
|
||||
TEXTURE_BLOODSTONE,
|
||||
TEXTURE_SOULSAND,
|
||||
TEXTURE_GLOWSTONE,
|
||||
TEXTURE_NONE106,
|
||||
TEXTURE_NONE107,
|
||||
TEXTURE_NONE108,
|
||||
TEXTURE_NONE109,
|
||||
TEXTURE_NONE110,
|
||||
TEXTURE_NONE111,
|
||||
TEXTURE_RAIL_CURVED,
|
||||
TEXTURE_CLOTH_112,
|
||||
TEXTURE_CLOTH_113,
|
||||
TEXTURE_TORCH_RED_STONE_OFF,
|
||||
TEXTURE_LOG_SPRUCE,
|
||||
TEXTURE_LOG_BIRCH,
|
||||
TEXTURE_PUMPKIN_SIDE,
|
||||
TEXTURE_PUMPKIN_FACE,
|
||||
TEXTURE_PUMPKIN_FACE_LIT,
|
||||
TEXTURE_CAKE_TOP,
|
||||
TEXTURE_CAKE_SIDE,
|
||||
TEXTURE_CAKE_SIDE_BIT,
|
||||
TEXTURE_CAKE_BOTTOM,
|
||||
TEXTURE_NONE125,
|
||||
TEXTURE_NONE126,
|
||||
TEXTURE_NONE127,
|
||||
|
||||
TEXTURE_ORE_LAPIS = 160,
|
||||
|
||||
TEXTURE_SANDSTONE_TOP = 176,
|
||||
TEXTURE_SANDSTONE_SIDE = 192,
|
||||
TEXTURE_WATER = 205,
|
||||
TEXTURE_SANDSTONE_BOTTOM = 208,
|
||||
|
||||
TEXTURE_LAVA = 237,
|
||||
|
||||
TEXTURE_LAVA_PLACEHOLDER = 255,
|
||||
};
|
||||
|
||||
enum eRenderShape
|
||||
{
|
||||
SHAPE_NONE = -1,
|
||||
SHAPE_SOLID,
|
||||
SHAPE_CROSS,
|
||||
SHAPE_TORCH,
|
||||
SHAPE_FIRE,
|
||||
SHAPE_WATER,
|
||||
SHAPE_UNK5,
|
||||
SHAPE_UNK6,
|
||||
SHAPE_DOOR,
|
||||
SHAPE_LADDER,
|
||||
SHAPE_UNK9,
|
||||
SHAPE_STAIRS,
|
||||
};
|
||||
|
||||
enum eRenderLayer
|
||||
{
|
||||
LAYER_OPAQUE,
|
||||
LAYER_ALPHA
|
||||
};
|
||||
|
||||
enum eDirection
|
||||
{
|
||||
DIR_YNEG,
|
||||
DIR_YPOS,
|
||||
DIR_ZNEG, // North
|
||||
DIR_ZPOS, // South
|
||||
DIR_XNEG, // West
|
||||
DIR_XPOS, // East
|
||||
};
|
||||
|
||||
struct ChunkPos
|
||||
{
|
||||
int x = 0, z = 0;
|
||||
ChunkPos() {}
|
||||
ChunkPos(int _x, int _z) : x(_x), z(_z) {}
|
||||
|
||||
bool operator<(const ChunkPos& b) const
|
||||
{
|
||||
if (x != b.x)
|
||||
return x < b.x;
|
||||
|
||||
return z < b.z;
|
||||
}
|
||||
};
|
||||
|
||||
struct Pos
|
||||
{
|
||||
int x = 0, y = 0, z = 0;
|
||||
Pos() {}
|
||||
Pos(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
|
||||
};
|
||||
|
||||
// @NOTE: Duplicate?
|
||||
struct TilePos
|
||||
{
|
||||
int x = 0, y = 0, z = 0;
|
||||
TilePos() {}
|
||||
TilePos(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
|
||||
|
||||
bool operator<(const TilePos& b) const
|
||||
{
|
||||
if (x != b.x)
|
||||
return x < b.x;
|
||||
if (y != b.y)
|
||||
return y < b.y;
|
||||
|
||||
return z < b.z;
|
||||
}
|
||||
};
|
||||
|
||||
#define SAFE_DELETE(ptr) do { if (ptr) delete ptr; } while (0)
|
||||
#define SAFE_DELETE_ARRAY(ptr) do { if (ptr) delete[] ptr; } while (0)
|
||||
|
||||
typedef uint8_t TileID;
|
||||
|
||||
// functions from Mojang
|
||||
time_t getEpochTimeS();
|
||||
time_t getRawTimeS();
|
||||
float getTimeS();
|
||||
int getTimeMs();
|
||||
|
||||
float Max(float a, float b);
|
||||
|
||||
void sleepMs(int ms);
|
||||
|
||||
// @NOTE: This is inlined.
|
||||
constexpr float Lerp(float a, float b, float progress)
|
||||
{
|
||||
return a + progress * (b - a);
|
||||
}
|
||||
|
||||
|
||||
// things that we added:
|
||||
#ifndef ORIGINAL_CODE
|
||||
|
||||
void LogMsg(const char* fmt, ...); // not part of actual Minecraft (they use printf), but useful
|
||||
void LogMsgNoCR(const char* fmt, ...); // not part of actual Minecraft (they use printf), but useful
|
||||
|
||||
#ifdef printf
|
||||
#error "printf is defined. Why?"
|
||||
#endif
|
||||
|
||||
#define printf LogMsgNoCR
|
||||
#define puts(str) LogMsg("%s", str);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
HINSTANCE GetInstance();
|
||||
HWND GetHWND();
|
||||
void CenterWindow(HWND hWnd);
|
||||
void EnableOpenGL(HWND hwnd, HDC*, HGLRC*);
|
||||
void DisableOpenGL(HWND, HDC, HGLRC);
|
||||
|
||||
void SetInstance(HINSTANCE hinst);
|
||||
void SetHWND(HWND hwnd);
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#define LogMsg(...)
|
||||
#define LogMsgNoCR(...)
|
||||
|
||||
#endif
|
||||
91
source/Base/Vec3.cpp
Normal file
91
source/Base/Vec3.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
Vec3.cpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#include "Vec3.hpp"
|
||||
|
||||
Vec3::Vec3() {}
|
||||
|
||||
Vec3::Vec3(float x, float y, float z)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
Vec3 Vec3::normalize()
|
||||
{
|
||||
float dist = Mth::sqrt(x * x + y * y + z * z);
|
||||
if (dist < 0.0001f)
|
||||
return Vec3(0, 0, 0);
|
||||
|
||||
return Vec3(x / dist, y / dist, z / dist);
|
||||
}
|
||||
|
||||
bool Vec3::clipX(const Vec3& a2, float a3, Vec3& a4) const
|
||||
{
|
||||
float crap = a2.x - this->x;
|
||||
if (crap * crap < 0.000001f)
|
||||
return false;
|
||||
|
||||
float crap2 = (a3 - this->x) / crap;
|
||||
if (crap2 < 0.0f || crap2 > 1.0f)
|
||||
return false;
|
||||
|
||||
a4.x = x + (a2.x - x) * crap2;
|
||||
a4.y = y + (a2.y - y) * crap2;
|
||||
a4.z = z + (a2.z - z) * crap2;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Vec3::clipY(const Vec3& a2, float a3, Vec3& a4) const
|
||||
{
|
||||
float crap = a2.y - this->y;
|
||||
if (crap * crap < 0.000001f)
|
||||
return false;
|
||||
|
||||
float crap2 = (a3 - this->y) / crap;
|
||||
if (crap2 < 0.0f || crap2 > 1.0f)
|
||||
return false;
|
||||
|
||||
a4.x = x + (a2.x - x) * crap2;
|
||||
a4.y = y + (a2.y - y) * crap2;
|
||||
a4.z = z + (a2.z - z) * crap2;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Vec3::clipZ(const Vec3& a2, float a3, Vec3& a4) const
|
||||
{
|
||||
float crap = a2.z - this->z;
|
||||
if (crap * crap < 0.000001f)
|
||||
return false;
|
||||
|
||||
float crap2 = (a3 - this->z) / crap;
|
||||
if (crap2 < 0.0f || crap2 > 1.0f)
|
||||
return false;
|
||||
|
||||
a4.x = x + (a2.x - x) * crap2;
|
||||
a4.y = y + (a2.y - y) * crap2;
|
||||
a4.z = z + (a2.z - z) * crap2;
|
||||
return true;
|
||||
}
|
||||
|
||||
float Vec3::distanceToSqr(const Vec3& b) const
|
||||
{
|
||||
float xd = (x-b.x);
|
||||
float yd = (y-b.y);
|
||||
float zd = (z-b.z);
|
||||
|
||||
return xd * xd + yd * yd + zd * zd;
|
||||
}
|
||||
|
||||
float Vec3::distanceTo(const Vec3& b) const
|
||||
{
|
||||
return Mth::sqrt(distanceToSqr(b));
|
||||
}
|
||||
81
source/Base/Vec3.hpp
Normal file
81
source/Base/Vec3.hpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
Vec3.hpp
|
||||
|
||||
The following code is licensed under the following license:
|
||||
< no license yet :( >
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Mth.hpp"
|
||||
|
||||
class Vec3
|
||||
{
|
||||
public:
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float z = 0;
|
||||
|
||||
public:
|
||||
bool clipX(const Vec3& a2, float a3, Vec3& a4) const;
|
||||
bool clipY(const Vec3& a2, float a3, Vec3& a4) const;
|
||||
bool clipZ(const Vec3& a2, float a3, Vec3& a4) const;
|
||||
Vec3 normalize();
|
||||
|
||||
// this constructor is nice to have, but it's probably inlined
|
||||
Vec3();
|
||||
Vec3(float x, float y, float z);
|
||||
|
||||
// these are likely inlined
|
||||
float distanceTo(const Vec3& b) const;
|
||||
float distanceToSqr(const Vec3& b) const;
|
||||
|
||||
// these are also likely inlined, but I'll declare them in the header
|
||||
Vec3 operator+(const Vec3& b)
|
||||
{
|
||||
return Vec3(x + b.x, y + b.y, z + b.z);
|
||||
}
|
||||
|
||||
Vec3 operator-(const Vec3& b)
|
||||
{
|
||||
return Vec3(x - b.x, y - b.y, z - b.z);
|
||||
}
|
||||
|
||||
void operator+=(const Vec3& b)
|
||||
{
|
||||
x += b.x;
|
||||
y += b.y;
|
||||
z += b.z;
|
||||
}
|
||||
|
||||
void operator-=(const Vec3& b)
|
||||
{
|
||||
(*this) += -b;
|
||||
}
|
||||
|
||||
void operator*=(float f)
|
||||
{
|
||||
x *= f;
|
||||
y *= f;
|
||||
z *= f;
|
||||
}
|
||||
|
||||
Vec3 operator-() const
|
||||
{
|
||||
return Vec3(-x, -y, -z);
|
||||
}
|
||||
|
||||
Vec3 operator*(float f) const
|
||||
{
|
||||
return Vec3(f * x, f * y, f * z);
|
||||
}
|
||||
|
||||
Vec3 translate(float tx, float ty, float tz) const
|
||||
{
|
||||
return Vec3(x + tx, y + ty, z + tz);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user