mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Renamed bx::init::* tags. Moved tags into common place.
This commit is contained in:
@@ -33,13 +33,6 @@
|
||||
#define BX_ALIGNED_NEW(_allocator, _type, _align) BX_PLACEMENT_NEW(BX_ALIGNED_ALLOC(_allocator, sizeof(_type), _align), _type)
|
||||
#define BX_PLACEMENT_NEW(_ptr, _type) ::new(bx::PlacementNew, _ptr) _type
|
||||
|
||||
namespace bx
|
||||
{
|
||||
struct PlacementNewTag {};
|
||||
constexpr PlacementNewTag PlacementNew;
|
||||
|
||||
} // namespace bx
|
||||
|
||||
void* operator new(size_t, bx::PlacementNewTag, void* _ptr);
|
||||
void operator delete(void*, bx::PlacementNewTag, void*) throw();
|
||||
|
||||
|
||||
@@ -13,53 +13,53 @@ namespace bx
|
||||
///
|
||||
struct Line
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Vec3 dir = init::None;
|
||||
Vec3 pos = InitNone;
|
||||
Vec3 dir = InitNone;
|
||||
};
|
||||
|
||||
///
|
||||
struct LineSegment
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Vec3 end = init::None;
|
||||
Vec3 pos = InitNone;
|
||||
Vec3 end = InitNone;
|
||||
};
|
||||
|
||||
///
|
||||
struct Aabb
|
||||
{
|
||||
Vec3 min = init::None;
|
||||
Vec3 max = init::None;
|
||||
Vec3 min = InitNone;
|
||||
Vec3 max = InitNone;
|
||||
};
|
||||
|
||||
///
|
||||
struct Capsule
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Vec3 end = init::None;
|
||||
Vec3 pos = InitNone;
|
||||
Vec3 end = InitNone;
|
||||
float radius;
|
||||
};
|
||||
|
||||
///
|
||||
struct Cone
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Vec3 end = init::None;
|
||||
Vec3 pos = InitNone;
|
||||
Vec3 end = InitNone;
|
||||
float radius;
|
||||
};
|
||||
|
||||
///
|
||||
struct Cylinder
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Vec3 end = init::None;
|
||||
Vec3 pos = InitNone;
|
||||
Vec3 end = InitNone;
|
||||
float radius;
|
||||
};
|
||||
|
||||
///
|
||||
struct Disk
|
||||
{
|
||||
Vec3 center = init::None;
|
||||
Vec3 normal = init::None;
|
||||
Vec3 center = InitNone;
|
||||
Vec3 normal = InitNone;
|
||||
float radius;
|
||||
};
|
||||
|
||||
@@ -72,30 +72,30 @@ namespace bx
|
||||
///
|
||||
struct Sphere
|
||||
{
|
||||
Vec3 center = init::None;
|
||||
Vec3 center = InitNone;
|
||||
float radius;
|
||||
};
|
||||
|
||||
///
|
||||
struct Triangle
|
||||
{
|
||||
Vec3 v0 = init::None;
|
||||
Vec3 v1 = init::None;
|
||||
Vec3 v2 = init::None;
|
||||
Vec3 v0 = InitNone;
|
||||
Vec3 v1 = InitNone;
|
||||
Vec3 v2 = InitNone;
|
||||
};
|
||||
|
||||
///
|
||||
struct Ray
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Vec3 dir = init::None;
|
||||
Vec3 pos = InitNone;
|
||||
Vec3 dir = InitNone;
|
||||
};
|
||||
|
||||
///
|
||||
struct Hit
|
||||
{
|
||||
Vec3 pos = init::None;
|
||||
Plane plane = init::None;
|
||||
Vec3 pos = InitNone;
|
||||
Plane plane = InitNone;
|
||||
};
|
||||
|
||||
///
|
||||
|
||||
@@ -36,8 +36,25 @@
|
||||
///
|
||||
#define BX_ENABLED(_x) BX_IGNORE_C4127(bx::isEnabled<!!(_x)>::value)
|
||||
|
||||
///
|
||||
#define BX_DECLARE_TAG(_name) \
|
||||
struct _name ## Tag {}; \
|
||||
constexpr _name ## Tag _name
|
||||
|
||||
namespace bx
|
||||
{
|
||||
/// Placement new tag.
|
||||
BX_DECLARE_TAG(PlacementNew);
|
||||
|
||||
/// Fields are left uninitialized.
|
||||
BX_DECLARE_TAG(InitNone);
|
||||
|
||||
/// Fields are initialized to zero.
|
||||
BX_DECLARE_TAG(InitZero);
|
||||
|
||||
/// Fields are initialized to identity value.
|
||||
BX_DECLARE_TAG(InitIdentity);
|
||||
|
||||
/// Arithmetic type `Ty` limits.
|
||||
template<typename Ty, bool SignT = isSigned<Ty>()>
|
||||
struct LimitsT;
|
||||
|
||||
@@ -390,7 +390,7 @@ namespace bx
|
||||
template<typename Ty>
|
||||
inline Ty load(const void* _ptr)
|
||||
{
|
||||
Ty result(init::None);
|
||||
Ty result(InitNone);
|
||||
memCopy(&result, _ptr, sizeof(Ty) );
|
||||
return result;
|
||||
}
|
||||
@@ -401,18 +401,18 @@ namespace bx
|
||||
memCopy(_ptr, &_a, sizeof(Ty) );
|
||||
}
|
||||
|
||||
inline Vec3::Vec3(init::NoneTag)
|
||||
inline Vec3::Vec3(InitNoneTag)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Vec3::Vec3(init::ZeroTag)
|
||||
constexpr Vec3::Vec3(InitZeroTag)
|
||||
: x(0.0f)
|
||||
, y(0.0f)
|
||||
, z(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Vec3::Vec3(init::IdentityTag)
|
||||
constexpr Vec3::Vec3(InitIdentityTag)
|
||||
: x(0.0f)
|
||||
, y(0.0f)
|
||||
, z(0.0f)
|
||||
@@ -433,18 +433,18 @@ namespace bx
|
||||
{
|
||||
}
|
||||
|
||||
inline Plane::Plane(init::NoneTag)
|
||||
: normal(init::None)
|
||||
inline Plane::Plane(InitNoneTag)
|
||||
: normal(InitNone)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Plane::Plane(init::ZeroTag)
|
||||
: normal(init::Zero)
|
||||
constexpr Plane::Plane(InitZeroTag)
|
||||
: normal(InitZero)
|
||||
, dist(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Plane::Plane(init::IdentityTag)
|
||||
constexpr Plane::Plane(InitIdentityTag)
|
||||
: normal(0.0f, 1.0f, 0.0f)
|
||||
, dist(0.0f)
|
||||
{
|
||||
@@ -456,11 +456,11 @@ namespace bx
|
||||
{
|
||||
}
|
||||
|
||||
inline Quaternion::Quaternion(init::NoneTag)
|
||||
inline Quaternion::Quaternion(InitNoneTag)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Quaternion::Quaternion(init::ZeroTag)
|
||||
constexpr Quaternion::Quaternion(InitZeroTag)
|
||||
: x(0.0f)
|
||||
, y(0.0f)
|
||||
, z(0.0f)
|
||||
@@ -468,7 +468,7 @@ namespace bx
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Quaternion::Quaternion(init::IdentityTag)
|
||||
constexpr Quaternion::Quaternion(InitIdentityTag)
|
||||
: x(0.0f)
|
||||
, y(0.0f)
|
||||
, z(0.0f)
|
||||
@@ -740,7 +740,7 @@ namespace bx
|
||||
|
||||
inline BX_CONST_FUNC Vec3 fromLatLong(float _u, float _v)
|
||||
{
|
||||
Vec3 result(init::None);
|
||||
Vec3 result(InitNone);
|
||||
const float phi = _u * kPi2;
|
||||
const float theta = _v * kPi;
|
||||
|
||||
@@ -1098,8 +1098,8 @@ namespace bx
|
||||
|
||||
inline void mtxFromNormal(float* _result, const Vec3& _normal, float _scale, const Vec3& _pos)
|
||||
{
|
||||
Vec3 tangent(init::None);
|
||||
Vec3 bitangent(init::None);
|
||||
Vec3 tangent(InitNone);
|
||||
Vec3 bitangent(InitNone);
|
||||
calcTangentFrame(tangent, bitangent, _normal);
|
||||
|
||||
store(&_result[ 0], mul(bitangent, _scale) );
|
||||
@@ -1117,8 +1117,8 @@ namespace bx
|
||||
|
||||
inline void mtxFromNormal(float* _result, const Vec3& _normal, float _scale, const Vec3& _pos, float _angle)
|
||||
{
|
||||
Vec3 tangent(init::None);
|
||||
Vec3 bitangent(init::None);
|
||||
Vec3 tangent(InitNone);
|
||||
Vec3 bitangent(InitNone);
|
||||
calcTangentFrame(tangent, bitangent, _normal, _angle);
|
||||
|
||||
store(&_result[0], mul(bitangent, _scale) );
|
||||
@@ -1183,7 +1183,7 @@ namespace bx
|
||||
|
||||
inline Vec3 mul(const Vec3& _vec, const float* _mat)
|
||||
{
|
||||
Vec3 result(init::None);
|
||||
Vec3 result(InitNone);
|
||||
result.x = _vec.x * _mat[0] + _vec.y * _mat[4] + _vec.z * _mat[ 8] + _mat[12];
|
||||
result.y = _vec.x * _mat[1] + _vec.y * _mat[5] + _vec.z * _mat[ 9] + _mat[13];
|
||||
result.z = _vec.x * _mat[2] + _vec.y * _mat[6] + _vec.z * _mat[10] + _mat[14];
|
||||
@@ -1192,7 +1192,7 @@ namespace bx
|
||||
|
||||
inline Vec3 mulXyz0(const Vec3& _vec, const float* _mat)
|
||||
{
|
||||
Vec3 result(init::None);
|
||||
Vec3 result(InitNone);
|
||||
result.x = _vec.x * _mat[0] + _vec.y * _mat[4] + _vec.z * _mat[ 8];
|
||||
result.y = _vec.x * _mat[1] + _vec.y * _mat[5] + _vec.z * _mat[ 9];
|
||||
result.z = _vec.x * _mat[2] + _vec.y * _mat[6] + _vec.z * _mat[10];
|
||||
|
||||
@@ -34,38 +34,19 @@ namespace bx
|
||||
};
|
||||
};
|
||||
|
||||
/// Structure initializer types.
|
||||
namespace init
|
||||
{
|
||||
/// Fields are left uninitialized.
|
||||
///
|
||||
struct NoneTag {};
|
||||
constexpr NoneTag None;
|
||||
|
||||
/// Fields are initialized to zero.
|
||||
///
|
||||
struct ZeroTag {};
|
||||
constexpr ZeroTag Zero;
|
||||
|
||||
/// Fields are initialized to identity value.
|
||||
///
|
||||
struct IdentityTag {};
|
||||
constexpr IdentityTag Identity;
|
||||
}
|
||||
|
||||
///
|
||||
struct Vec3
|
||||
{
|
||||
Vec3() = delete;
|
||||
|
||||
///
|
||||
Vec3(init::NoneTag);
|
||||
Vec3(InitNoneTag);
|
||||
|
||||
///
|
||||
constexpr Vec3(init::ZeroTag);
|
||||
constexpr Vec3(InitZeroTag);
|
||||
|
||||
///
|
||||
constexpr Vec3(init::IdentityTag);
|
||||
constexpr Vec3(InitIdentityTag);
|
||||
|
||||
///
|
||||
explicit constexpr Vec3(float _v);
|
||||
@@ -82,13 +63,13 @@ namespace bx
|
||||
Plane() = delete;
|
||||
|
||||
///
|
||||
Plane(init::NoneTag);
|
||||
Plane(InitNoneTag);
|
||||
|
||||
///
|
||||
constexpr Plane(init::ZeroTag);
|
||||
constexpr Plane(InitZeroTag);
|
||||
|
||||
///
|
||||
constexpr Plane(init::IdentityTag);
|
||||
constexpr Plane(InitIdentityTag);
|
||||
|
||||
///
|
||||
constexpr Plane(Vec3 _normal, float _dist);
|
||||
@@ -103,13 +84,13 @@ namespace bx
|
||||
Quaternion() = delete;
|
||||
|
||||
///
|
||||
Quaternion(init::NoneTag);
|
||||
Quaternion(InitNoneTag);
|
||||
|
||||
///
|
||||
constexpr Quaternion(init::ZeroTag);
|
||||
constexpr Quaternion(InitZeroTag);
|
||||
|
||||
///
|
||||
constexpr Quaternion(init::IdentityTag);
|
||||
constexpr Quaternion(InitIdentityTag);
|
||||
|
||||
///
|
||||
constexpr Quaternion(float _x, float _y, float _z, float _w);
|
||||
|
||||
Reference in New Issue
Block a user