Renamed bx::init::* tags. Moved tags into common place.

This commit is contained in:
Бранимир Караџић
2023-04-22 22:22:17 -07:00
parent dd4c9427a4
commit be09f6970e
7 changed files with 98 additions and 107 deletions

View File

@@ -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();

View File

@@ -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;
};
///

View File

@@ -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;

View File

@@ -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];

View File

@@ -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);

View File

@@ -128,8 +128,8 @@ namespace bx
void toAabb(Aabb& _outAabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
{
Vec3 mn(init::None);
Vec3 mx(init::None);
Vec3 mn(InitNone);
Vec3 mx(InitNone);
uint8_t* vertex = (uint8_t*)_vertices;
mn = mx = load<Vec3>(vertex);
@@ -150,8 +150,8 @@ namespace bx
void toAabb(Aabb& _outAabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
{
Vec3 mn(init::None);
Vec3 mx(init::None);
Vec3 mn(InitNone);
Vec3 mx(InitNone);
uint8_t* vertex = (uint8_t*)_vertices;
mn = mx = mul(load<Vec3>(vertex), _mtx);
@@ -284,7 +284,7 @@ namespace bx
uint8_t* vertex = (uint8_t*)_vertices;
Vec3 center(init::None);
Vec3 center(InitNone);
float* position = (float*)&vertex[0];
center.x = position[0];
center.y = position[1];
@@ -592,8 +592,8 @@ namespace bx
return intersect(_ray, sphere, _hit);
}
Plane plane(init::None);
Vec3 pos(init::None);
Plane plane(InitNone);
Vec3 pos(InitNone);
if (0.0f >= height)
{
@@ -898,14 +898,14 @@ namespace bx
struct Srt
{
Quaternion rotation = init::Identity;
Vec3 translation = init::Zero;
Vec3 scale = init::Zero;
Quaternion rotation = InitIdentity;
Vec3 translation = InitZero;
Vec3 scale = InitZero;
};
Srt toSrt(const Aabb& _aabb)
{
return { init::Identity, getCenter(_aabb), getExtents(_aabb) };
return { InitIdentity, getCenter(_aabb), getExtents(_aabb) };
}
Srt toSrt(const void* _mtx)
@@ -1196,7 +1196,7 @@ namespace bx
Vec3 closestPoint(const Triangle& _triangle, const Vec3& _point)
{
Plane plane(init::None);
Plane plane(InitNone);
calcPlane(plane, _triangle);
const Vec3 pos = closestPoint(plane, _point);
@@ -1255,7 +1255,7 @@ namespace bx
return false;
}
Plane plane(init::None);
Plane plane(InitNone);
calcPlane(plane, _triangle);
if (!overlap(_aabb, plane) )
@@ -1314,7 +1314,7 @@ namespace bx
return false;
}
Plane plane(init::None);
Plane plane(InitNone);
calcPlane(plane, _disk.normal, _disk.center);
return overlap(_aabb, plane);
@@ -1366,10 +1366,10 @@ namespace bx
const Vec3 by = toYAxis(_srtB.rotation);
const Vec3 bz = toZAxis(_srtB.rotation);
Vec3 vertsA[8] = { init::None, init::None, init::None, init::None, init::None, init::None, init::None, init::None };
calcObbVertices(vertsA, ax, ay, az, init::Zero, _srtA.scale);
Vec3 vertsA[8] = { InitNone, InitNone, InitNone, InitNone, InitNone, InitNone, InitNone, InitNone };
calcObbVertices(vertsA, ax, ay, az, InitZero, _srtA.scale);
Vec3 vertsB[8] = { init::None, init::None, init::None, init::None, init::None, init::None, init::None, init::None };
Vec3 vertsB[8] = { InitNone, InitNone, InitNone, InitNone, InitNone, InitNone, InitNone, InitNone };
calcObbVertices(vertsB, bx, by, bz, sub(_srtB.translation, _srtA.translation), _srtB.scale);
return overlaps(ax, vertsA, vertsB)
@@ -1543,7 +1543,7 @@ namespace bx
bool overlap(const Disk& _disk, const Vec3& _pos)
{
Plane plane(init::None);
Plane plane(InitNone);
calcPlane(plane, _disk.normal, _disk.center);
if (!isNearZero(distance(plane, _pos) ) )
@@ -1556,7 +1556,7 @@ namespace bx
bool overlap(const Disk& _disk, const Plane& _plane)
{
Plane plane(init::None);
Plane plane(InitNone);
calcPlane(plane, _disk.normal, _disk.center);
if (!overlap(plane, _plane) )
@@ -1574,7 +1574,7 @@ namespace bx
return false;
}
Plane plane(init::None);
Plane plane(InitNone);
calcPlane(plane, _disk.normal, _disk.center);
return overlap(_capsule, plane);
@@ -1582,10 +1582,10 @@ namespace bx
bool overlap(const Disk& _diskA, const Disk& _diskB)
{
Plane planeA(init::None);
Plane planeA(InitNone);
calcPlane(planeA, _diskA.normal, _diskA.center);
Plane planeB(init::None);
Plane planeB(InitNone);
calcPlane(planeB, _diskB);
Line line;
@@ -1614,7 +1614,7 @@ namespace bx
return false;
}
Plane plane(init::None);
Plane plane(InitNone);
calcPlane(plane, _disk.normal, _disk.center);
return overlap(_obb, plane);
@@ -1744,7 +1744,7 @@ namespace bx
bool overlap(const Sphere& _sphere, const Triangle& _triangle)
{
Plane plane(init::None);
Plane plane(InitNone);
calcPlane(plane, _triangle);
if (!overlap(_sphere, plane) )
@@ -1782,7 +1782,7 @@ namespace bx
return false;
}
Plane plane(init::None);
Plane plane(InitNone);
calcPlane(plane, _disk.normal, _disk.center);
return overlap(_sphere, plane);
@@ -1852,7 +1852,7 @@ namespace bx
template<typename Ty>
bool overlap(const Triangle& _triangle, const Ty& _ty)
{
Plane plane(init::None);
Plane plane(InitNone);
calcPlane(plane, _triangle);
plane.normal = neg(plane.normal);
@@ -2011,7 +2011,7 @@ namespace bx
return false;
}
Plane plane(init::None);
Plane plane(InitNone);
calcPlane(plane, _disk.normal, _disk.center);
return overlap(_triangle, plane);

View File

@@ -346,11 +346,11 @@ TEST_CASE("quaternion", "")
float mtxQ[16];
float mtx[16];
bx::Quaternion quat = bx::init::Identity;
bx::Quaternion q2 = bx::init::None;
bx::Quaternion quat = bx::InitIdentity;
bx::Quaternion q2 = bx::InitNone;
bx::Vec3 axis = bx::init::None;
bx::Vec3 euler = bx::init::None;
bx::Vec3 axis = bx::InitNone;
bx::Vec3 euler = bx::InitNone;
float angle;
bx::mtxFromQuaternion(mtxQ, quat);