Merge pull request #1376 from mc-server/static_cast
Use static casts instead of C casts, add floor-cast functions
This commit is contained in:
commit
ae5d311609
@ -27,9 +27,9 @@
|
|||||||
return super::GetClass(); \
|
return super::GetClass(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define POSX_TOINT (int)floor(GetPosX())
|
#define POSX_TOINT FloorC(GetPosX())
|
||||||
#define POSY_TOINT (int)floor(GetPosY())
|
#define POSY_TOINT FloorC(GetPosY())
|
||||||
#define POSZ_TOINT (int)floor(GetPosZ())
|
#define POSZ_TOINT FloorC(GetPosZ())
|
||||||
#define POS_TOINT Vector3i(POSXTOINT, POSYTOINT, POSZTOINT)
|
#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; }
|
#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); if ((ChunkVarName == NULL) || !ChunkVarName->IsValid()) { return; }
|
||||||
|
@ -226,10 +226,10 @@ template class SizeChecker<UInt16, 2>;
|
|||||||
|
|
||||||
// CRT stuff:
|
// CRT stuff:
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <assert.h>
|
#include <cassert>
|
||||||
#include <stdio.h>
|
#include <cstdio>
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
#include <stdarg.h>
|
#include <cstdarg>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -400,6 +400,24 @@ 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, typename T>
|
||||||
|
typename std::enable_if<std::is_arithmetic<T>::value, C>::type FloorC(T a_Value)
|
||||||
|
{
|
||||||
|
return static_cast<C>(std::floor(a_Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Ceils a value, then casts it to C (an int by default) */
|
||||||
|
template <typename C = int, typename T>
|
||||||
|
typename std::enable_if<std::is_arithmetic<T>::value, C>::type CeilC(T a_Value)
|
||||||
|
{
|
||||||
|
return static_cast<C>(std::ceil(a_Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef TOLUA_TEMPLATE_BIND
|
#ifndef TOLUA_TEMPLATE_BIND
|
||||||
#define TOLUA_TEMPLATE_BIND(x)
|
#define TOLUA_TEMPLATE_BIND(x)
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
|
|
||||||
#define _USE_MATH_DEFINES // Enable non-standard math defines (MSVC)
|
#define _USE_MATH_DEFINES // Enable non-standard math defines (MSVC)
|
||||||
#include <math.h>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -29,9 +28,9 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
// Hardcoded copy constructors (tolua++ does not support function templates .. yet)
|
// 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<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((T) a_Rhs.x), y((T) a_Rhs.y), z((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((T) a_Rhs.x), y((T) a_Rhs.y), z((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
|
// tolua_end
|
||||||
@ -53,9 +52,9 @@ public:
|
|||||||
{
|
{
|
||||||
double Len = 1.0 / Length();
|
double Len = 1.0 / Length();
|
||||||
|
|
||||||
x = (T)(x * Len);
|
x = static_cast<T>(x * Len);
|
||||||
y = (T)(y * Len);
|
y = static_cast<T>(y * Len);
|
||||||
z = (T)(z * Len);
|
z = static_cast<T>(z * Len);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vector3<T> NormalizeCopy(void) const
|
inline Vector3<T> NormalizeCopy(void) const
|
||||||
@ -63,9 +62,9 @@ public:
|
|||||||
double Len = 1.0 / Length();
|
double Len = 1.0 / Length();
|
||||||
|
|
||||||
return Vector3<T>(
|
return Vector3<T>(
|
||||||
(T)(x * Len),
|
static_cast<T>(x * Len),
|
||||||
(T)(y * Len),
|
static_cast<T>(y * Len),
|
||||||
(T)(z * Len)
|
static_cast<T>(z * Len)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,15 +73,15 @@ public:
|
|||||||
double Len = 1.0 / Length();
|
double Len = 1.0 / Length();
|
||||||
|
|
||||||
a_Rhs.Set(
|
a_Rhs.Set(
|
||||||
(T)(x * Len),
|
static_cast<T>(x * Len),
|
||||||
(T)(y * Len),
|
static_cast<T>(y * Len),
|
||||||
(T)(z * Len)
|
static_cast<T>(z * Len)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double Length(void) const
|
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
|
inline double SqrLength(void) const
|
||||||
@ -138,9 +137,9 @@ public:
|
|||||||
inline Vector3<int> Floor(void) const
|
inline Vector3<int> Floor(void) const
|
||||||
{
|
{
|
||||||
return Vector3<int>(
|
return Vector3<int>(
|
||||||
(int)floor(x),
|
FloorC(x),
|
||||||
(int)floor(y),
|
FloorC(y),
|
||||||
(int)floor(z)
|
FloorC(z)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user