summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorarchshift <admin@archshift.com>2014-09-04 01:12:43 +0200
committerarchshift <admin@archshift.com>2014-09-04 01:12:43 +0200
commit472efa8174626a00ffdf5b39e1a44ac419cd3698 (patch)
treebd4a6bf77cf92aaa2529ead260cda91455e9ad09 /src
parentChunkGenerator: Log world seed when creating a new one. (diff)
downloadcuberite-472efa8174626a00ffdf5b39e1a44ac419cd3698.tar
cuberite-472efa8174626a00ffdf5b39e1a44ac419cd3698.tar.gz
cuberite-472efa8174626a00ffdf5b39e1a44ac419cd3698.tar.bz2
cuberite-472efa8174626a00ffdf5b39e1a44ac419cd3698.tar.lz
cuberite-472efa8174626a00ffdf5b39e1a44ac419cd3698.tar.xz
cuberite-472efa8174626a00ffdf5b39e1a44ac419cd3698.tar.zst
cuberite-472efa8174626a00ffdf5b39e1a44ac419cd3698.zip
Diffstat (limited to 'src')
-rw-r--r--src/Entities/Entity.h6
-rw-r--r--src/Globals.h40
-rw-r--r--src/Mobs/SnowGolem.cpp12
-rw-r--r--src/Vector3.h33
4 files changed, 62 insertions, 29 deletions
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index b9c280b6b..73e8a0d8b 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -27,9 +27,9 @@
return super::GetClass(); \
}
-#define POSX_TOINT (int)floor(GetPosX())
-#define POSY_TOINT (int)floor(GetPosY())
-#define POSZ_TOINT (int)floor(GetPosZ())
+#define POSX_TOINT FloorD(GetPosX())
+#define POSY_TOINT FloorD(GetPosY())
+#define POSZ_TOINT FloorD(GetPosZ())
#define POS_TOINT Vector3i(POSXTOINT, POSYTOINT, POSZTOINT)
#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); if ((ChunkVarName == NULL) || !ChunkVarName->IsValid()) { return; }
diff --git a/src/Globals.h b/src/Globals.h
index de1024010..a782de325 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -217,10 +217,10 @@ template class SizeChecker<UInt16, 2>;
// CRT stuff:
#include <sys/stat.h>
-#include <assert.h>
-#include <stdio.h>
-#include <math.h>
-#include <stdarg.h>
+#include <cassert>
+#include <cstdio>
+#include <cmath>
+#include <cstdarg>
@@ -370,6 +370,38 @@ T Clamp(T a_Value, T a_Min, T a_Max)
+/** Floors a_Value, then casts it to C (an int by default) */
+template <typename C = int>
+C FloorD(double a_Value)
+{
+ return static_cast<C>(std::floor(a_Value));
+}
+
+/** Floors a_Value, then casts it to C (an int by default) */
+template <typename C = int>
+C FloorF(double a_Value)
+{
+ return static_cast<C>(std::floorf(a_Value));
+}
+
+/** Ciels a_Value, then casts it to C (an int by default) */
+template <typename C = int>
+C CeilD(double a_Value)
+{
+ return static_cast<C>(std::ceil(a_Value));
+}
+
+/** Ciels a_Value, then casts it to C (an int by default) */
+template <typename C = int>
+C CeilF(double a_Value)
+{
+ return static_cast<C>(std::ceilf(a_Value));
+}
+
+
+
+
+
#ifndef TOLUA_TEMPLATE_BIND
#define TOLUA_TEMPLATE_BIND(x)
#endif
diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp
index 76334d970..43ce16ee4 100644
--- a/src/Mobs/SnowGolem.cpp
+++ b/src/Mobs/SnowGolem.cpp
@@ -30,17 +30,19 @@ void cSnowGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cSnowGolem::Tick(float a_Dt, cChunk & a_Chunk)
{
super::Tick(a_Dt, a_Chunk);
- if (IsBiomeNoDownfall(m_World->GetBiomeAt((int) floor(GetPosX()), (int) floor(GetPosZ()))))
+ if (IsBiomeNoDownfall(m_World->GetBiomeAt(POSX_TOINT, POSZ_TOINT)))
{
TakeDamage(*this);
}
else
{
- BLOCKTYPE BlockBelow = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()) - 1, (int) floor(GetPosZ()));
- BLOCKTYPE Block = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ()));
- if (Block == E_BLOCK_AIR && cBlockInfo::IsSolid(BlockBelow))
+ BLOCKTYPE BlockBelow = m_World->GetBlock(POSX_TOINT, POSY_TOINT - 1, POSZ_TOINT);
+ BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT);
+ if (Block == E_BLOCK_AIR
+ && cBlockInfo::IsSolid(BlockBelow)
+ && GetPosY() >= 64) // Must be at at least 64Y for snow to form
{
- m_World->SetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ()), E_BLOCK_SNOW, 0);
+ m_World->SetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT, E_BLOCK_SNOW, 0);
}
}
}
diff --git a/src/Vector3.h b/src/Vector3.h
index 1dcb38f64..782b0d1c9 100644
--- a/src/Vector3.h
+++ b/src/Vector3.h
@@ -4,7 +4,6 @@
#define _USE_MATH_DEFINES // Enable non-standard math defines (MSVC)
-#include <math.h>
#include <list>
#include <vector>
@@ -29,9 +28,9 @@ public:
// Hardcoded copy constructors (tolua++ does not support function templates .. yet)
- Vector3(const Vector3<float> & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {}
- Vector3(const Vector3<double> & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {}
- Vector3(const Vector3<int> & a_Rhs) : x((T) a_Rhs.x), y((T) a_Rhs.y), z((T) a_Rhs.z) {}
+ Vector3(const Vector3<float> & a_Rhs) : x(static_cast<T>(a_Rhs.x)), y(static_cast<T>(a_Rhs.y)), z(static_cast<T>(a_Rhs.z)) {}
+ Vector3(const Vector3<double> & a_Rhs) : x(static_cast<T>(a_Rhs.x)), y(static_cast<T>(a_Rhs.y)), z(static_cast<T>(a_Rhs.z)) {}
+ Vector3(const Vector3<int> & a_Rhs) : x(static_cast<T>(a_Rhs.x)), y(static_cast<T>(a_Rhs.y)), z(static_cast<T>(a_Rhs.z)) {}
// tolua_end
@@ -53,9 +52,9 @@ public:
{
double Len = 1.0 / Length();
- x = (T)(x * Len);
- y = (T)(y * Len);
- z = (T)(z * Len);
+ x = static_cast<T>(x * Len);
+ y = static_cast<T>(y * Len);
+ z = static_cast<T>(z * Len);
}
inline Vector3<T> NormalizeCopy(void) const
@@ -63,9 +62,9 @@ public:
double Len = 1.0 / Length();
return Vector3<T>(
- (T)(x * Len),
- (T)(y * Len),
- (T)(z * Len)
+ static_cast<T>(x * Len),
+ static_cast<T>(y * Len),
+ static_cast<T>(z * Len)
);
}
@@ -74,15 +73,15 @@ public:
double Len = 1.0 / Length();
a_Rhs.Set(
- (T)(x * Len),
- (T)(y * Len),
- (T)(z * Len)
+ static_cast<T>(x * Len),
+ static_cast<T>(y * Len),
+ static_cast<T>(z * Len)
);
}
inline double Length(void) const
{
- return sqrt((double)(x * x + y * y + z * z));
+ return sqrt(static_cast<double>(x * x + y * y + z * z));
}
inline double SqrLength(void) const
@@ -138,9 +137,9 @@ public:
inline Vector3<int> Floor(void) const
{
return Vector3<int>(
- (int)floor(x),
- (int)floor(y),
- (int)floor(z)
+ static_cast<int>(floor(x)),
+ static_cast<int>(floor(y)),
+ static_cast<int>(floor(z))
);
}