initial commit, 4.5 stable
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
Some checks failed
🔗 GHA / 📊 Static checks (push) Has been cancelled
🔗 GHA / 🤖 Android (push) Has been cancelled
🔗 GHA / 🍏 iOS (push) Has been cancelled
🔗 GHA / 🐧 Linux (push) Has been cancelled
🔗 GHA / 🍎 macOS (push) Has been cancelled
🔗 GHA / 🏁 Windows (push) Has been cancelled
🔗 GHA / 🌐 Web (push) Has been cancelled
This commit is contained in:
74
thirdparty/jolt_physics/Jolt/Core/ByteBuffer.h
vendored
Normal file
74
thirdparty/jolt_physics/Jolt/Core/ByteBuffer.h
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
|
||||
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Jolt/Core/STLAlignedAllocator.h>
|
||||
|
||||
JPH_NAMESPACE_BEGIN
|
||||
|
||||
/// Underlying data type for ByteBuffer
|
||||
using ByteBufferVector = Array<uint8, STLAlignedAllocator<uint8, JPH_CACHE_LINE_SIZE>>;
|
||||
|
||||
/// Simple byte buffer, aligned to a cache line
|
||||
class ByteBuffer : public ByteBufferVector
|
||||
{
|
||||
public:
|
||||
/// Align the size to a multiple of inSize, returns the length after alignment
|
||||
size_t Align(size_t inSize)
|
||||
{
|
||||
// Assert power of 2
|
||||
JPH_ASSERT(IsPowerOf2(inSize));
|
||||
|
||||
// Calculate new size and resize buffer
|
||||
size_t s = AlignUp(size(), inSize);
|
||||
resize(s, 0);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Allocate block of data of inSize elements and return the pointer
|
||||
template <class Type>
|
||||
Type * Allocate(size_t inSize = 1)
|
||||
{
|
||||
// Reserve space
|
||||
size_t s = size();
|
||||
resize(s + inSize * sizeof(Type));
|
||||
|
||||
// Get data pointer
|
||||
Type *data = reinterpret_cast<Type *>(&at(s));
|
||||
|
||||
// Construct elements
|
||||
for (Type *d = data, *d_end = data + inSize; d < d_end; ++d)
|
||||
new (d) Type;
|
||||
|
||||
// Return pointer
|
||||
return data;
|
||||
}
|
||||
|
||||
/// Append inData to the buffer
|
||||
template <class Type>
|
||||
void AppendVector(const Array<Type> &inData)
|
||||
{
|
||||
size_t size = inData.size() * sizeof(Type);
|
||||
uint8 *data = Allocate<uint8>(size);
|
||||
memcpy(data, &inData[0], size);
|
||||
}
|
||||
|
||||
/// Get object at inPosition (an offset in bytes)
|
||||
template <class Type>
|
||||
const Type * Get(size_t inPosition) const
|
||||
{
|
||||
return reinterpret_cast<const Type *>(&at(inPosition));
|
||||
}
|
||||
|
||||
/// Get object at inPosition (an offset in bytes)
|
||||
template <class Type>
|
||||
Type * Get(size_t inPosition)
|
||||
{
|
||||
return reinterpret_cast<Type *>(&at(inPosition));
|
||||
}
|
||||
};
|
||||
|
||||
JPH_NAMESPACE_END
|
Reference in New Issue
Block a user