hsh vector type implicit casts

This commit is contained in:
Jack Andersen 2020-09-28 10:53:49 -10:00
parent 6c46735ab1
commit e64b7c4d17
9 changed files with 115 additions and 20 deletions

View File

@ -62,5 +62,10 @@ if(TARGET athena-core)
target_compile_definitions(zeus PUBLIC ZE_ATHENA_TYPES=1)
endif()
if(TARGET hsh)
target_link_libraries(zeus PUBLIC hsh)
target_compile_definitions(zeus PUBLIC ZE_HSH_TYPES=1)
endif()
add_subdirectory(test)

View File

@ -124,6 +124,15 @@ public:
writer.writeUByte(atUint8(f[3] * 255));
}
#endif
#if ZE_HSH_TYPES
operator hsh::float4() const {
simd_floats floats(mSimd);
return hsh::float4{floats[0], floats[1], floats[2], floats[3]};
}
#endif
[[nodiscard]] bool operator==(const CColor& rhs) const {

View File

@ -67,6 +67,16 @@ public:
return ret;
}
#endif
#if ZE_HSH_TYPES
operator hsh::float3x3() const {
return hsh::float3x3{hsh::float3(m[0]), hsh::float3(m[1]), hsh::float3(m[2])};
}
constexpr CMatrix3f(const hsh::float3x3& vec) : m{vec.cols[0], vec.cols[1], vec.cols[2]} {}
#endif
CMatrix3f(const CQuaternion& quat);

View File

@ -49,6 +49,16 @@ public:
m[3].mSimd = CVector4f(0.f, 0.f, 0.f, 1.0f).mSimd;
}
#if ZE_HSH_TYPES
operator hsh::float4x4() const {
return hsh::float4x4{hsh::float4(m[0]), hsh::float4(m[1]), hsh::float4(m[2]), hsh::float4(m[3])};
}
constexpr CMatrix4f(const hsh::float4x4& vec) : m{vec.cols[0], vec.cols[1], vec.cols[2], vec.cols[3]} {}
#endif
constexpr CMatrix4f& operator=(const CMatrix4f& other) = default;
[[nodiscard]] CVector4f operator*(const CVector4f& other) const {

View File

@ -39,6 +39,17 @@ public:
return ret;
}
#endif
#if ZE_HSH_TYPES
operator hsh::float2() const {
simd_floats floats(mSimd);
return hsh::float2{floats[0], floats[1]};
}
constexpr CVector2f(const hsh::float2& vec) : mSimd(vec.x, vec.y) {}
#endif
explicit constexpr CVector2f(float xy) : mSimd(xy) {}

View File

@ -47,6 +47,17 @@ public:
return ret;
}
#endif
#if ZE_HSH_TYPES
operator hsh::float3() const {
simd_floats floats(mSimd);
return hsh::float3{floats[0], floats[1], floats[2]};
}
constexpr CVector3f(const hsh::float3& vec) : mSimd(vec.x, vec.y, vec.z) {}
#endif
inline CVector3f(const CVector3d& vec);

View File

@ -40,6 +40,17 @@ public:
mSimd.copy_from(f);
}
#endif
#if ZE_HSH_TYPES
operator hsh::float4() const {
simd_floats floats(mSimd);
return hsh::float4{floats[0], floats[1], floats[2], floats[3]};
}
constexpr CVector4f(const hsh::float4& vec) : mSimd(vec.x, vec.y, vec.z, vec.w) {}
#endif
explicit constexpr CVector4f(float xyzw) : mSimd(xyzw) {}

View File

@ -7,6 +7,10 @@
#include "simd/simd.hpp"
#endif
#if ZE_HSH_TYPES
#include "hsh/hsh.h"
#endif
namespace zeus {
#if ZE_ATHENA_TYPES
template <typename T>

View File

@ -718,54 +718,78 @@ public:
return *this;
}
__simd_reference operator++() && { return std::move(*this) = __ptr_->__get(__index_) + 1; }
__simd_reference operator++() && { return std::move(*this) = _Vp(*this) + 1; }
_Vp operator++(int) && {
auto __val = __ptr_->__get(__index_);
auto __val = _Vp(*this);
__ptr_->__set(__index_, __val + 1);
return __val;
}
__simd_reference operator--() && { return std::move(*this) = __ptr_->__get(__index_) - 1; }
__simd_reference operator--() && { return std::move(*this) = _Vp(*this) - 1; }
_Vp operator--(int) && {
auto __val = __ptr_->__get(__index_);
auto __val = _Vp(*this);
__ptr_->__set(__index_, __val - 1);
return __val;
}
__simd_reference operator+=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) + __value; }
__simd_reference operator+=(_Vp __value) && { return std::move(*this) = _Vp(*this) + __value; }
__simd_reference operator-=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) - __value; }
__simd_reference operator-=(_Vp __value) && { return std::move(*this) = _Vp(*this) - __value; }
__simd_reference operator*=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) * __value; }
__simd_reference operator*=(_Vp __value) && { return std::move(*this) = _Vp(*this) * __value; }
__simd_reference operator/=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) / __value; }
__simd_reference operator/=(_Vp __value) && { return std::move(*this) = _Vp(*this) / __value; }
__simd_reference operator%=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) % __value; }
__simd_reference operator%=(_Vp __value) && { return std::move(*this) = _Vp(*this) % __value; }
__simd_reference operator>>=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) >> __value; }
__simd_reference operator>>=(_Vp __value) && { return std::move(*this) = _Vp(*this) >> __value; }
__simd_reference operator<<=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) << __value; }
__simd_reference operator<<=(_Vp __value) && { return std::move(*this) = _Vp(*this) << __value; }
__simd_reference operator&=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) & __value; }
__simd_reference operator&=(_Vp __value) && { return std::move(*this) = _Vp(*this) & __value; }
__simd_reference operator|=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) | __value; }
__simd_reference operator|=(_Vp __value) && { return std::move(*this) = _Vp(*this) | __value; }
__simd_reference operator^=(_Vp __value) && { return std::move(*this) = __ptr_->__get(__index_) ^ __value; }
__simd_reference operator^=(_Vp __value) && { return std::move(*this) = _Vp(*this) ^ __value; }
bool operator<(_Vp __value) const { return __ptr_->__get(__index_) < __value; }
bool operator<(const __simd_reference& __value) const { return _Vp(*this) < _Vp(__value); }
bool operator<=(_Vp __value) const { return __ptr_->__get(__index_) <= __value; }
bool operator<=(const __simd_reference& __value) const { return _Vp(*this) <= _Vp(__value); }
bool operator>(_Vp __value) const { return __ptr_->__get(__index_) > __value; }
bool operator>(const __simd_reference& __value) const { return _Vp(*this) > _Vp(__value); }
bool operator>=(_Vp __value) const { return __ptr_->__get(__index_) >= __value; }
bool operator>=(const __simd_reference& __value) const { return _Vp(*this) >= _Vp(__value); }
bool operator==(_Vp __value) const { return __ptr_->__get(__index_) == __value; }
bool operator==(const __simd_reference& __value) const { return _Vp(*this) == _Vp(__value); }
bool operator!=(_Vp __value) const { return __ptr_->__get(__index_) != __value; }
bool operator!=(const __simd_reference& __value) const { return _Vp(*this) != _Vp(__value); }
bool operator<(_Vp __value) const { return _Vp(*this) < __value; }
bool operator<=(_Vp __value) const { return _Vp(*this) <= __value; }
bool operator>(_Vp __value) const { return _Vp(*this) > __value; }
bool operator>=(_Vp __value) const { return _Vp(*this) >= __value; }
bool operator==(_Vp __value) const { return _Vp(*this) == __value; }
bool operator!=(_Vp __value) const { return _Vp(*this) != __value; }
};
template <class _Vp, class _Tp, class _Abi>
inline bool operator<(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a < _Vp(b); }
template <class _Vp, class _Tp, class _Abi>
inline bool operator<=(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a <= _Vp(b); }
template <class _Vp, class _Tp, class _Abi>
inline bool operator>(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a > _Vp(b); }
template <class _Vp, class _Tp, class _Abi>
inline bool operator>=(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a >= _Vp(b); }
template <class _Vp, class _Tp, class _Abi>
inline bool operator==(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a == _Vp(b); }
template <class _Vp, class _Tp, class _Abi>
inline bool operator!=(_Vp a, const __simd_reference<_Vp, _Tp, _Abi>& b) { return a != _Vp(b); }
template <class _Tp, class _Abi>
class __simd_mask_reference {