mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 12:42:34 +01:00
Cleanup.
This commit is contained in:
@@ -124,19 +124,19 @@ namespace bx
|
||||
|
||||
/// Creates a directory named `_filePath`.
|
||||
///
|
||||
bool make(const FilePath& _filePath, Error* _err = bx::ErrorIgnore{});
|
||||
bool make(const FilePath& _filePath, Error* _err = ErrorIgnore{});
|
||||
|
||||
/// Creates a directory named `_filePath` along with all necessary parents.
|
||||
///
|
||||
bool makeAll(const FilePath& _filePath, Error* _err = bx::ErrorIgnore{});
|
||||
bool makeAll(const FilePath& _filePath, Error* _err = ErrorIgnore{});
|
||||
|
||||
/// Removes file or directory.
|
||||
///
|
||||
bool remove(const FilePath& _filePath, Error* _err = bx::ErrorIgnore{});
|
||||
bool remove(const FilePath& _filePath, Error* _err = ErrorIgnore{});
|
||||
|
||||
/// Removes file or directory recursively.
|
||||
///
|
||||
bool removeAll(const FilePath& _filePath, Error* _err = bx::ErrorIgnore{});
|
||||
bool removeAll(const FilePath& _filePath, Error* _err = ErrorIgnore{});
|
||||
|
||||
} // namespace bx
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace bx
|
||||
{
|
||||
const uintptr_t addr = bitCast<uintptr_t>(_ptr);
|
||||
const uintptr_t unaligned = addr + _extra; // space for header
|
||||
const uintptr_t aligned = bx::alignUp(unaligned, int32_t(_align) );
|
||||
const uintptr_t aligned = alignUp(unaligned, int32_t(_align) );
|
||||
|
||||
return bitCast<void*>(aligned);
|
||||
}
|
||||
|
||||
@@ -96,13 +96,13 @@ namespace bx
|
||||
template<typename Ty>
|
||||
inline constexpr Ty max()
|
||||
{
|
||||
return bx::LimitsT<Ty>::max;
|
||||
return LimitsT<Ty>::max;
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
inline constexpr Ty min()
|
||||
{
|
||||
return bx::LimitsT<Ty>::min;
|
||||
return LimitsT<Ty>::min;
|
||||
}
|
||||
|
||||
template<typename Ty>
|
||||
|
||||
@@ -103,14 +103,14 @@ namespace bx
|
||||
|
||||
inline HandleAlloc* createHandleAlloc(AllocatorI* _allocator, uint16_t _maxHandles)
|
||||
{
|
||||
uint8_t* ptr = (uint8_t*)bx::alloc(_allocator, sizeof(HandleAlloc) + 2*_maxHandles*sizeof(uint16_t) );
|
||||
uint8_t* ptr = (uint8_t*)alloc(_allocator, sizeof(HandleAlloc) + 2*_maxHandles*sizeof(uint16_t) );
|
||||
return BX_PLACEMENT_NEW(ptr, HandleAlloc)(_maxHandles);
|
||||
}
|
||||
|
||||
inline void destroyHandleAlloc(AllocatorI* _allocator, HandleAlloc* _handleAlloc)
|
||||
{
|
||||
_handleAlloc->~HandleAlloc();
|
||||
bx::free(_allocator, _handleAlloc);
|
||||
free(_allocator, _handleAlloc);
|
||||
}
|
||||
|
||||
template <uint16_t MaxHandlesT>
|
||||
|
||||
@@ -366,12 +366,12 @@ namespace bx
|
||||
return countTrailingZeros<unsigned long long>(_val);
|
||||
}
|
||||
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(uint8_t _val) { return bx::min<uint8_t>(8, countTrailingZeros<uint32_t>(_val) ); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int8_t _val) { return countTrailingZeros<uint8_t >(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(uint16_t _val) { return bx::min<uint8_t>(16, countTrailingZeros<uint32_t>(_val) ); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int16_t _val) { return countTrailingZeros<uint16_t>(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int32_t _val) { return countTrailingZeros<uint32_t>(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int64_t _val) { return countTrailingZeros<uint64_t>(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(uint8_t _val) { return min<uint8_t>(8, countTrailingZeros<uint32_t>(_val) ); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int8_t _val) { return countTrailingZeros<uint8_t >(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(uint16_t _val) { return min<uint8_t>(16, countTrailingZeros<uint32_t>(_val) ); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int16_t _val) { return countTrailingZeros<uint16_t>(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int32_t _val) { return countTrailingZeros<uint32_t>(_val); }
|
||||
template<> inline BX_CONSTEXPR_FUNC uint8_t countTrailingZeros(int64_t _val) { return countTrailingZeros<uint64_t>(_val); }
|
||||
|
||||
template<typename Ty>
|
||||
inline BX_CONSTEXPR_FUNC uint8_t findFirstSet(Ty _val)
|
||||
@@ -536,9 +536,29 @@ namespace bx
|
||||
return rcp(copySign(max(kFloatSmallest, abs(_a) ), _a) );
|
||||
}
|
||||
|
||||
inline BX_CONSTEXPR_FUNC float div(float _a, float _b)
|
||||
{
|
||||
return mul(_a, rcp(_b) );
|
||||
}
|
||||
|
||||
inline BX_CONSTEXPR_FUNC float divSafe(float _a, float _b)
|
||||
{
|
||||
return mul(_a, rcpSafe(_b) );
|
||||
}
|
||||
|
||||
inline BX_CONSTEXPR_FUNC float ceilDiv(float _a, float _b)
|
||||
{
|
||||
return div(_a + _b - 1, _b);
|
||||
}
|
||||
|
||||
inline BX_CONSTEXPR_FUNC float ceilDivSafe(float _a, float _b)
|
||||
{
|
||||
return divSafe(_a + _b - 1, _b);
|
||||
}
|
||||
|
||||
inline BX_CONSTEXPR_FUNC float mod(float _a, float _b)
|
||||
{
|
||||
return _a - _b * floor(mul(_a, rcp(_b) ) );
|
||||
return _a - _b * floor(div(_a, _b) );
|
||||
}
|
||||
|
||||
inline BX_CONSTEXPR_FUNC bool isEqual(float _a, float _b, float _epsilon)
|
||||
@@ -900,8 +920,8 @@ namespace bx
|
||||
|
||||
inline BX_CONST_FUNC Vec3 normalize(const Vec3 _a)
|
||||
{
|
||||
const float invLen = rcpSafe(length(_a) );
|
||||
const Vec3 result = mul(_a, invLen);
|
||||
const float len = length(_a);
|
||||
const Vec3 result = divSafe(_a, len);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace bx
|
||||
|
||||
inline MemoryBlock::~MemoryBlock()
|
||||
{
|
||||
bx::free(m_allocator, m_data);
|
||||
free(m_allocator, m_data);
|
||||
}
|
||||
|
||||
inline void* MemoryBlock::more(uint32_t _size)
|
||||
@@ -75,7 +75,7 @@ namespace bx
|
||||
if (0 < _size)
|
||||
{
|
||||
m_size += _size;
|
||||
m_data = bx::realloc(m_allocator, m_data, m_size);
|
||||
m_data = realloc(m_allocator, m_data, m_size);
|
||||
}
|
||||
|
||||
return m_data;
|
||||
@@ -404,9 +404,9 @@ namespace bx
|
||||
inline int32_t peek(ReaderSeekerI* _reader, void* _data, int32_t _size, Error* _err)
|
||||
{
|
||||
BX_ERROR_SCOPE(_err);
|
||||
int64_t offset = bx::seek(_reader);
|
||||
int64_t offset = seek(_reader);
|
||||
int32_t size = _reader->read(_data, _size, _err);
|
||||
bx::seek(_reader, offset, bx::Whence::Begin);
|
||||
seek(_reader, offset, Whence::Begin);
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -421,12 +421,12 @@ namespace bx
|
||||
inline int32_t align(ReaderSeekerI* _reader, uint32_t _alignment, Error* _err)
|
||||
{
|
||||
BX_ERROR_SCOPE(_err);
|
||||
const int64_t current = bx::seek(_reader);
|
||||
const int64_t current = seek(_reader);
|
||||
const int64_t aligned = ( (current + _alignment-1)/_alignment) * _alignment;
|
||||
const int32_t size = int32_t(aligned - current);
|
||||
if (0 != size)
|
||||
{
|
||||
const int64_t offset = bx::seek(_reader, size);
|
||||
const int64_t offset = seek(_reader, size);
|
||||
if (offset != aligned)
|
||||
{
|
||||
BX_ERROR_SET(_err, kErrorReaderWriterWrite, "Align: read truncated.");
|
||||
@@ -440,7 +440,7 @@ namespace bx
|
||||
inline int32_t align(WriterSeekerI* _writer, uint32_t _alignment, Error* _err)
|
||||
{
|
||||
BX_ERROR_SCOPE(_err);
|
||||
const int64_t current = bx::seek(_writer);
|
||||
const int64_t current = seek(_writer);
|
||||
const int64_t aligned = ( (current + _alignment-1)/_alignment) * _alignment;
|
||||
const int32_t size = int32_t(aligned - current);
|
||||
if (0 != size)
|
||||
|
||||
@@ -56,11 +56,11 @@ namespace bx
|
||||
template <typename Rng>
|
||||
inline float frndh(Rng* _rng)
|
||||
{
|
||||
return 2.0f * bx::frnd(_rng) - 1.0f;
|
||||
return 2.0f * frnd(_rng) - 1.0f;
|
||||
}
|
||||
|
||||
template <typename Rng>
|
||||
inline bx::Vec3 randUnitCircle(Rng* _rng)
|
||||
inline Vec3 randUnitCircle(Rng* _rng)
|
||||
{
|
||||
const float angle = frnd(_rng) * kPi2;
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace bx
|
||||
}
|
||||
|
||||
template <typename Rng>
|
||||
inline bx::Vec3 randUnitSphere(Rng* _rng)
|
||||
inline Vec3 randUnitSphere(Rng* _rng)
|
||||
{
|
||||
const float rand0 = frnd(_rng) * 2.0f - 1.0f;
|
||||
const float rand1 = frnd(_rng) * kPi2;
|
||||
@@ -88,14 +88,14 @@ namespace bx
|
||||
}
|
||||
|
||||
template <typename Ty>
|
||||
inline bx::Vec3 randUnitHemisphere(Ty* _rng, const bx::Vec3& _normal)
|
||||
inline Vec3 randUnitHemisphere(Ty* _rng, const Vec3& _normal)
|
||||
{
|
||||
const bx::Vec3 dir = randUnitSphere(_rng);
|
||||
const float ddotn = bx::dot(dir, _normal);
|
||||
const Vec3 dir = randUnitSphere(_rng);
|
||||
const float ddotn = dot(dir, _normal);
|
||||
|
||||
if (0.0f > ddotn)
|
||||
{
|
||||
return bx::neg(dir);
|
||||
return neg(dir);
|
||||
}
|
||||
|
||||
return dir;
|
||||
@@ -142,7 +142,7 @@ namespace bx
|
||||
for (uint32_t ii = 0, num = _num-1; ii < num; ++ii)
|
||||
{
|
||||
uint32_t jj = ii + 1 + _rng->gen() % (num - ii);
|
||||
bx::swap(_array[ii], _array[jj]);
|
||||
swap(_array[ii], _array[jj]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace bx
|
||||
{
|
||||
Node* node = m_first;
|
||||
m_first = node->m_next;
|
||||
bx::deleteObject(m_allocator, node);
|
||||
deleteObject(m_allocator, node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace bx
|
||||
{
|
||||
Node* node = m_first;
|
||||
m_first = m_first->m_next;
|
||||
bx::deleteObject(m_allocator, node);
|
||||
deleteObject(m_allocator, node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ namespace bx
|
||||
return m_0terminated;
|
||||
}
|
||||
|
||||
template<bx::AllocatorI** AllocatorT>
|
||||
template<AllocatorI** AllocatorT>
|
||||
inline StringT<AllocatorT>::StringT()
|
||||
: StringView()
|
||||
, m_capacity(0)
|
||||
@@ -195,7 +195,7 @@ namespace bx
|
||||
clear();
|
||||
}
|
||||
|
||||
template<bx::AllocatorI** AllocatorT>
|
||||
template<AllocatorI** AllocatorT>
|
||||
inline StringT<AllocatorT>::StringT(const StringT<AllocatorT>& _rhs)
|
||||
: StringView()
|
||||
, m_capacity(0)
|
||||
@@ -203,7 +203,7 @@ namespace bx
|
||||
set(_rhs);
|
||||
}
|
||||
|
||||
template<bx::AllocatorI** AllocatorT>
|
||||
template<AllocatorI** AllocatorT>
|
||||
inline StringT<AllocatorT>::StringT(const StringView& _rhs)
|
||||
: StringView()
|
||||
, m_capacity(0)
|
||||
@@ -211,27 +211,27 @@ namespace bx
|
||||
set(_rhs);
|
||||
}
|
||||
|
||||
template<bx::AllocatorI** AllocatorT>
|
||||
template<AllocatorI** AllocatorT>
|
||||
inline StringT<AllocatorT>::~StringT()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
template<bx::AllocatorI** AllocatorT>
|
||||
template<AllocatorI** AllocatorT>
|
||||
inline StringT<AllocatorT>& StringT<AllocatorT>::operator=(const StringT<AllocatorT>& _rhs)
|
||||
{
|
||||
set(_rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<bx::AllocatorI** AllocatorT>
|
||||
template<AllocatorI** AllocatorT>
|
||||
inline void StringT<AllocatorT>::set(const StringView& _str)
|
||||
{
|
||||
clear();
|
||||
append(_str);
|
||||
}
|
||||
|
||||
template<bx::AllocatorI** AllocatorT>
|
||||
template<AllocatorI** AllocatorT>
|
||||
inline void StringT<AllocatorT>::append(const StringView& _str)
|
||||
{
|
||||
if (0 != _str.getLength() )
|
||||
@@ -244,7 +244,7 @@ namespace bx
|
||||
if (len+1 > m_capacity)
|
||||
{
|
||||
const int32_t capacity = alignUp(len+1, 256);
|
||||
ptr = (char*)bx::realloc(*AllocatorT, 0 != m_capacity ? ptr : NULL, capacity);
|
||||
ptr = (char*)realloc(*AllocatorT, 0 != m_capacity ? ptr : NULL, capacity);
|
||||
|
||||
*const_cast<char**>(&m_ptr) = ptr;
|
||||
m_capacity = capacity;
|
||||
@@ -255,27 +255,27 @@ namespace bx
|
||||
}
|
||||
}
|
||||
|
||||
template<bx::AllocatorI** AllocatorT>
|
||||
template<AllocatorI** AllocatorT>
|
||||
inline void StringT<AllocatorT>::append(const char* _ptr, const char* _term)
|
||||
{
|
||||
append(StringView(_ptr, _term) );
|
||||
}
|
||||
|
||||
template<bx::AllocatorI** AllocatorT>
|
||||
template<AllocatorI** AllocatorT>
|
||||
inline void StringT<AllocatorT>::clear()
|
||||
{
|
||||
m_0terminated = true;
|
||||
|
||||
if (0 != m_capacity)
|
||||
{
|
||||
bx::free(*AllocatorT, const_cast<char*>(m_ptr) );
|
||||
free(*AllocatorT, const_cast<char*>(m_ptr) );
|
||||
|
||||
StringView::clear();
|
||||
m_capacity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<bx::AllocatorI** AllocatorT>
|
||||
template<AllocatorI** AllocatorT>
|
||||
inline const char* StringT<AllocatorT>::getCPtr() const
|
||||
{
|
||||
return getPtr();
|
||||
@@ -286,7 +286,7 @@ namespace bx
|
||||
return StringView(_str, _start, _len);
|
||||
}
|
||||
|
||||
inline LineReader::LineReader(const bx::StringView& _str)
|
||||
inline LineReader::LineReader(const StringView& _str)
|
||||
: m_str(_str)
|
||||
{
|
||||
reset();
|
||||
@@ -305,7 +305,7 @@ namespace bx
|
||||
++m_line;
|
||||
|
||||
StringView curr(m_curr);
|
||||
m_curr = bx::strFindNl(m_curr);
|
||||
m_curr = strFindNl(m_curr);
|
||||
|
||||
StringView line(curr.getPtr(), m_curr.getPtr() );
|
||||
|
||||
|
||||
@@ -364,6 +364,22 @@ namespace bx
|
||||
///
|
||||
BX_CONSTEXPR_FUNC float rcpSafe(float _a);
|
||||
|
||||
/// Returns result of division (_a / _b).
|
||||
///
|
||||
BX_CONSTEXPR_FUNC float div(float _a, float _b);
|
||||
|
||||
/// Returns result of division (_a / _b). Avoids divide by zero.
|
||||
///
|
||||
BX_CONSTEXPR_FUNC float divSafe(float _a, float _b);
|
||||
|
||||
/// Returns result of division (_a / _b), and rounds upwards.
|
||||
///
|
||||
BX_CONSTEXPR_FUNC float ceilDiv(float _a, float _b);
|
||||
|
||||
/// Returns result of division (_a / _b), and rounds upwards. Avoids divide by zero.
|
||||
///
|
||||
BX_CONSTEXPR_FUNC float ceilDivSafe(float _a, float _b);
|
||||
|
||||
/// Returns the floating-point remainder of the division operation _a/_b.
|
||||
///
|
||||
BX_CONSTEXPR_FUNC float mod(float _a, float _b);
|
||||
|
||||
@@ -57,15 +57,15 @@ namespace bx
|
||||
|
||||
/// Generate random point on unit circle.
|
||||
template <typename Rng>
|
||||
bx::Vec3 randUnitCircle(Rng* _rng);
|
||||
Vec3 randUnitCircle(Rng* _rng);
|
||||
|
||||
/// Generate random point on unit sphere.
|
||||
template <typename Rng>
|
||||
bx::Vec3 randUnitSphere(Rng* _rng);
|
||||
Vec3 randUnitSphere(Rng* _rng);
|
||||
|
||||
/// Generate random point on unit hemisphere.
|
||||
template <typename Ty>
|
||||
bx::Vec3 randUnitHemisphere(Ty* _rng, const bx::Vec3& _normal);
|
||||
Vec3 randUnitHemisphere(Ty* _rng, const Vec3& _normal);
|
||||
|
||||
/// Sampling with Hammersley and Halton Points.
|
||||
void generateSphereHammersley(void* _data, uint32_t _stride, uint32_t _num, float _scale = 1.0f);
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace bx
|
||||
};
|
||||
|
||||
/// ASCII string
|
||||
template<bx::AllocatorI** AllocatorT>
|
||||
template<AllocatorI** AllocatorT>
|
||||
class StringT : public StringView
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user