mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-07-02 01:44:23 +00:00
chore: format Minecraft.World
This commit is contained in:
@@ -3,67 +3,50 @@
|
||||
#include "AABB.h"
|
||||
|
||||
unsigned int Vec3::tlsIdx = 0;
|
||||
Vec3::ThreadStorage *Vec3::tlsDefault = NULL;
|
||||
Vec3::ThreadStorage* Vec3::tlsDefault = NULL;
|
||||
|
||||
Vec3::ThreadStorage::ThreadStorage()
|
||||
{
|
||||
pool = new Vec3[POOL_SIZE];
|
||||
poolPointer = 0;
|
||||
Vec3::ThreadStorage::ThreadStorage() {
|
||||
pool = new Vec3[POOL_SIZE];
|
||||
poolPointer = 0;
|
||||
}
|
||||
|
||||
Vec3::ThreadStorage::~ThreadStorage()
|
||||
{
|
||||
delete [] pool;
|
||||
Vec3::ThreadStorage::~ThreadStorage() { delete[] pool; }
|
||||
|
||||
void Vec3::CreateNewThreadStorage() {
|
||||
ThreadStorage* tls = new ThreadStorage();
|
||||
if (tlsDefault == NULL) {
|
||||
tlsIdx = TlsAlloc();
|
||||
tlsDefault = tls;
|
||||
}
|
||||
TlsSetValue(tlsIdx, tls);
|
||||
}
|
||||
|
||||
void Vec3::CreateNewThreadStorage()
|
||||
{
|
||||
ThreadStorage *tls = new ThreadStorage();
|
||||
if(tlsDefault == NULL )
|
||||
{
|
||||
tlsIdx = TlsAlloc();
|
||||
tlsDefault = tls;
|
||||
}
|
||||
TlsSetValue(tlsIdx, tls);
|
||||
void Vec3::UseDefaultThreadStorage() { TlsSetValue(tlsIdx, tlsDefault); }
|
||||
|
||||
void Vec3::ReleaseThreadStorage() {
|
||||
ThreadStorage* tls = (ThreadStorage*)TlsGetValue(tlsIdx);
|
||||
if (tls == tlsDefault) return;
|
||||
|
||||
delete tls;
|
||||
}
|
||||
|
||||
void Vec3::UseDefaultThreadStorage()
|
||||
{
|
||||
TlsSetValue(tlsIdx, tlsDefault);
|
||||
}
|
||||
|
||||
void Vec3::ReleaseThreadStorage()
|
||||
{
|
||||
ThreadStorage *tls = (ThreadStorage *)TlsGetValue(tlsIdx);
|
||||
if( tls == tlsDefault ) return;
|
||||
|
||||
delete tls;
|
||||
}
|
||||
|
||||
Vec3 *Vec3::newPermanent(double x, double y, double z)
|
||||
{
|
||||
return new Vec3(x,y,z);
|
||||
Vec3* Vec3::newPermanent(double x, double y, double z) {
|
||||
return new Vec3(x, y, z);
|
||||
};
|
||||
|
||||
void Vec3::clearPool()
|
||||
{
|
||||
}
|
||||
void Vec3::clearPool() {}
|
||||
|
||||
void Vec3::resetPool()
|
||||
{
|
||||
}
|
||||
void Vec3::resetPool() {}
|
||||
|
||||
Vec3 *Vec3::newTemp(double x, double y, double z)
|
||||
{
|
||||
ThreadStorage *tls = (ThreadStorage *)TlsGetValue(tlsIdx);
|
||||
Vec3 *thisVec = &tls->pool[tls->poolPointer];
|
||||
thisVec->set(x, y, z);
|
||||
tls->poolPointer = ( tls->poolPointer + 1 ) % ThreadStorage::POOL_SIZE;
|
||||
Vec3* Vec3::newTemp(double x, double y, double z) {
|
||||
ThreadStorage* tls = (ThreadStorage*)TlsGetValue(tlsIdx);
|
||||
Vec3* thisVec = &tls->pool[tls->poolPointer];
|
||||
thisVec->set(x, y, z);
|
||||
tls->poolPointer = (tls->poolPointer + 1) % ThreadStorage::POOL_SIZE;
|
||||
return thisVec;
|
||||
}
|
||||
|
||||
Vec3::Vec3(double x, double y, double z)
|
||||
{
|
||||
Vec3::Vec3(double x, double y, double z) {
|
||||
if (x == -0.0) x = 0.0;
|
||||
if (y == -0.0) y = 0.0;
|
||||
if (z == -0.0) z = 0.0;
|
||||
@@ -72,17 +55,14 @@ Vec3::Vec3(double x, double y, double z)
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
Vec3 *Vec3::set(double x, double y, double z)
|
||||
{
|
||||
Vec3* Vec3::set(double x, double y, double z) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Vec3 *Vec3::interpolateTo(Vec3 *t, double p)
|
||||
{
|
||||
Vec3* Vec3::interpolateTo(Vec3* t, double p) {
|
||||
double xt = x + (t->x - x) * p;
|
||||
double yt = y + (t->y - y) * p;
|
||||
double zt = z + (t->z - z) * p;
|
||||
@@ -90,69 +70,53 @@ Vec3 *Vec3::interpolateTo(Vec3 *t, double p)
|
||||
return Vec3::newTemp(xt, yt, zt);
|
||||
}
|
||||
|
||||
Vec3 *Vec3::vectorTo(Vec3 *p)
|
||||
{
|
||||
return Vec3::newTemp(p->x - x, p->y - y, p->z - z);
|
||||
Vec3* Vec3::vectorTo(Vec3* p) {
|
||||
return Vec3::newTemp(p->x - x, p->y - y, p->z - z);
|
||||
}
|
||||
|
||||
Vec3 *Vec3::normalize()
|
||||
{
|
||||
double dist = (double) (sqrt(x * x + y * y + z * z));
|
||||
Vec3* Vec3::normalize() {
|
||||
double dist = (double)(sqrt(x * x + y * y + z * z));
|
||||
if (dist < 0.0001) return Vec3::newTemp(0, 0, 0);
|
||||
return Vec3::newTemp(x / dist, y / dist, z / dist);
|
||||
}
|
||||
|
||||
double Vec3::dot(Vec3 *p)
|
||||
{
|
||||
return x * p->x + y * p->y + z * p->z;
|
||||
double Vec3::dot(Vec3* p) { return x * p->x + y * p->y + z * p->z; }
|
||||
|
||||
Vec3* Vec3::cross(Vec3* p) {
|
||||
return Vec3::newTemp(y * p->z - z * p->y, z * p->x - x * p->z,
|
||||
x * p->y - y * p->x);
|
||||
}
|
||||
|
||||
Vec3 *Vec3::cross(Vec3 *p)
|
||||
{
|
||||
return Vec3::newTemp(y * p->z - z * p->y, z * p->x - x * p->z, x * p->y - y * p->x);
|
||||
Vec3* Vec3::add(double x, double y, double z) {
|
||||
return Vec3::newTemp(this->x + x, this->y + y, this->z + z);
|
||||
}
|
||||
|
||||
Vec3 *Vec3::add(double x, double y, double z)
|
||||
{
|
||||
return Vec3::newTemp(this->x + x, this->y + y, this->z + z);
|
||||
}
|
||||
|
||||
double Vec3::distanceTo(Vec3 *p)
|
||||
{
|
||||
double Vec3::distanceTo(Vec3* p) {
|
||||
double xd = p->x - x;
|
||||
double yd = p->y - y;
|
||||
double zd = p->z - z;
|
||||
return (double) sqrt(xd * xd + yd * yd + zd * zd);
|
||||
return (double)sqrt(xd * xd + yd * yd + zd * zd);
|
||||
}
|
||||
|
||||
double Vec3::distanceToSqr(Vec3 *p)
|
||||
{
|
||||
double Vec3::distanceToSqr(Vec3* p) {
|
||||
double xd = p->x - x;
|
||||
double yd = p->y - y;
|
||||
double zd = p->z - z;
|
||||
return xd * xd + yd * yd + zd * zd;
|
||||
}
|
||||
|
||||
double Vec3::distanceToSqr(double x2, double y2, double z2)
|
||||
{
|
||||
double Vec3::distanceToSqr(double x2, double y2, double z2) {
|
||||
double xd = x2 - x;
|
||||
double yd = y2 - y;
|
||||
double zd = z2 - z;
|
||||
return xd * xd + yd * yd + zd * zd;
|
||||
}
|
||||
|
||||
Vec3 *Vec3::scale(double l)
|
||||
{
|
||||
return Vec3::newTemp(x * l, y * l, z * l);
|
||||
}
|
||||
Vec3* Vec3::scale(double l) { return Vec3::newTemp(x * l, y * l, z * l); }
|
||||
|
||||
double Vec3::length()
|
||||
{
|
||||
return sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
double Vec3::length() { return sqrt(x * x + y * y + z * z); }
|
||||
|
||||
Vec3 *Vec3::clipX(Vec3 *b, double xt)
|
||||
{
|
||||
Vec3* Vec3::clipX(Vec3* b, double xt) {
|
||||
double xd = b->x - x;
|
||||
double yd = b->y - y;
|
||||
double zd = b->z - z;
|
||||
@@ -164,8 +128,7 @@ Vec3 *Vec3::clipX(Vec3 *b, double xt)
|
||||
return Vec3::newTemp(x + xd * d, y + yd * d, z + zd * d);
|
||||
}
|
||||
|
||||
Vec3 *Vec3::clipY(Vec3 *b, double yt)
|
||||
{
|
||||
Vec3* Vec3::clipY(Vec3* b, double yt) {
|
||||
double xd = b->x - x;
|
||||
double yd = b->y - y;
|
||||
double zd = b->z - z;
|
||||
@@ -177,8 +140,7 @@ Vec3 *Vec3::clipY(Vec3 *b, double yt)
|
||||
return Vec3::newTemp(x + xd * d, y + yd * d, z + zd * d);
|
||||
}
|
||||
|
||||
Vec3 *Vec3::clipZ(Vec3 *b, double zt)
|
||||
{
|
||||
Vec3* Vec3::clipZ(Vec3* b, double zt) {
|
||||
double xd = b->x - x;
|
||||
double yd = b->y - y;
|
||||
double zd = b->z - z;
|
||||
@@ -190,21 +152,20 @@ Vec3 *Vec3::clipZ(Vec3 *b, double zt)
|
||||
return Vec3::newTemp(x + xd * d, y + yd * d, z + zd * d);
|
||||
}
|
||||
|
||||
std::wstring Vec3::toString()
|
||||
{
|
||||
static wchar_t buf[128];
|
||||
swprintf(buf, 128, L"(%f,%f,%f)",x,y,z);
|
||||
return std::wstring(buf);
|
||||
std::wstring Vec3::toString() {
|
||||
static wchar_t buf[128];
|
||||
swprintf(buf, 128, L"(%f,%f,%f)", x, y, z);
|
||||
return std::wstring(buf);
|
||||
}
|
||||
|
||||
Vec3 *Vec3::lerp(Vec3 *v, double a)
|
||||
{
|
||||
return Vec3::newTemp(x + (v->x - x) * a, y + (v->y - y) * a, z + (v->z - z) * a);
|
||||
Vec3* Vec3::lerp(Vec3* v, double a) {
|
||||
return Vec3::newTemp(x + (v->x - x) * a, y + (v->y - y) * a,
|
||||
z + (v->z - z) * a);
|
||||
}
|
||||
|
||||
void Vec3::xRot(float degs)
|
||||
{
|
||||
double _cos = cos(degs); // 4J - cos/sin were floats but seems pointless wasting precision here
|
||||
void Vec3::xRot(float degs) {
|
||||
double _cos = cos(degs); // 4J - cos/sin were floats but seems pointless
|
||||
// wasting precision here
|
||||
double _sin = sin(degs);
|
||||
|
||||
double xx = x;
|
||||
@@ -216,9 +177,9 @@ void Vec3::xRot(float degs)
|
||||
this->z = zz;
|
||||
}
|
||||
|
||||
void Vec3::yRot(float degs)
|
||||
{
|
||||
double _cos = cos(degs); // 4J - cos/sin were floats but seems pointless wasting precision here
|
||||
void Vec3::yRot(float degs) {
|
||||
double _cos = cos(degs); // 4J - cos/sin were floats but seems pointless
|
||||
// wasting precision here
|
||||
double _sin = sin(degs);
|
||||
|
||||
double xx = x * _cos + z * _sin;
|
||||
@@ -230,9 +191,9 @@ void Vec3::yRot(float degs)
|
||||
this->z = zz;
|
||||
}
|
||||
|
||||
void Vec3::zRot(float degs)
|
||||
{
|
||||
double _cos = cos(degs); // 4J - cos/sin were floats but seems pointless wasting precision here
|
||||
void Vec3::zRot(float degs) {
|
||||
double _cos = cos(degs); // 4J - cos/sin were floats but seems pointless
|
||||
// wasting precision here
|
||||
double _sin = sin(degs);
|
||||
|
||||
double xx = x * _cos + y * _sin;
|
||||
@@ -246,20 +207,25 @@ void Vec3::zRot(float degs)
|
||||
|
||||
// Returns 0 if this point is within the box
|
||||
// Otherwise returns the distance to the box
|
||||
double Vec3::distanceTo(AABB *box)
|
||||
{
|
||||
if(box->contains(this)) return 0;
|
||||
double Vec3::distanceTo(AABB* box) {
|
||||
if (box->contains(this)) return 0;
|
||||
|
||||
double xd = 0, yd = 0, zd = 0;
|
||||
double xd = 0, yd = 0, zd = 0;
|
||||
|
||||
if(x < box->x0) xd = box->x0 - x;
|
||||
else if( x > box->x1) xd = x - box->x1;
|
||||
if (x < box->x0)
|
||||
xd = box->x0 - x;
|
||||
else if (x > box->x1)
|
||||
xd = x - box->x1;
|
||||
|
||||
if(y < box->y0) yd = box->y0 - y;
|
||||
else if( y > box->y1) yd = y - box->y1;
|
||||
if (y < box->y0)
|
||||
yd = box->y0 - y;
|
||||
else if (y > box->y1)
|
||||
yd = y - box->y1;
|
||||
|
||||
if(z < box->z0) zd = box->z0 - z;
|
||||
else if( z > box->z1) zd = z - box->z1;
|
||||
if (z < box->z0)
|
||||
zd = box->z0 - z;
|
||||
else if (z > box->z1)
|
||||
zd = z - box->z1;
|
||||
|
||||
return sqrt(xd * xd + yd * yd + zd * zd);
|
||||
return sqrt(xd * xd + yd * yd + zd * zd);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user