update 0927
This commit is contained in:
parent
6d6df7fa83
commit
b1705db60f
|
|
@ -3,3 +3,57 @@
|
||||||
ECSMemoryPool::ECSMemoryPool()
|
ECSMemoryPool::ECSMemoryPool()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChunkAccessIndex::ChunkAccessIndex(ElementControlBlock* ecb, uint64_t chunk_type_code)
|
||||||
|
:_element_bind(MemoryElement(ecb)), _chunk_type_code(chunk_type_code)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ChunkAccessIndex::ChunkAccessIndex(const ChunkAccessIndex& other) :_element_bind(other._element_bind),
|
||||||
|
_chunk_type_code(other._chunk_type_code),
|
||||||
|
_member_offset(other._member_offset)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t ChunkAccessIndex::chunkType() const
|
||||||
|
{
|
||||||
|
return _chunk_type_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t ChunkAccessIndex::chunkSize() const
|
||||||
|
{
|
||||||
|
return _element_bind.typeSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ChunkAccessIndex::contains(uint64_t type_code)
|
||||||
|
{
|
||||||
|
return _member_offset.find(type_code) != _member_offset.cend();
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t ChunkAccessIndex::setMember(uint64_t type_code, uint16_t offset, uint16_t size)
|
||||||
|
{
|
||||||
|
if (_element_bind.typeSize() <= offset + size) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
_member_offset[type_code] = std::make_pair(offset, size);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char* ChunkAccessIndex::getLockedDataPtr(uint64_t type_code)
|
||||||
|
{
|
||||||
|
auto index_offset = _member_offset.find(type_code);
|
||||||
|
if (index_offset == _member_offset.cend())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto raw_ptr = _element_bind.dataLock();
|
||||||
|
auto data_target_ptr = raw_ptr + index_offset->first;
|
||||||
|
return data_target_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChunkAccessIndex::releaseData()
|
||||||
|
{
|
||||||
|
_element_bind.release();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <map>
|
||||||
#include <memory_pages.h>
|
#include <memory_pages.h>
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
@ -21,7 +22,7 @@ concept CompenentType = requires(T t, T other, const QJsonObject & in, QJsonObje
|
||||||
template<typename T> class ComponentRefer : protected MemoryElement {
|
template<typename T> class ComponentRefer : protected MemoryElement {
|
||||||
public:
|
public:
|
||||||
ComponentRefer(ElementControlBlock* data) : MemoryElement(data) { referAdd(); }
|
ComponentRefer(ElementControlBlock* data) : MemoryElement(data) { referAdd(); }
|
||||||
ComponentRefer(const ComponentRefer<T> &other) :MemoryElement(other.data_ptr) { referAdd(); }
|
ComponentRefer(const ComponentRefer<T>& other) :MemoryElement(other.data_ptr) { referAdd(); }
|
||||||
virtual ~ComponentRefer() { referSub(); }
|
virtual ~ComponentRefer() { referSub(); }
|
||||||
|
|
||||||
T* dataLock() {
|
T* dataLock() {
|
||||||
|
|
@ -34,6 +35,26 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ECSMEMORYPOOL_EXPORT ChunkAccessIndex {
|
||||||
|
private:
|
||||||
|
MemoryElement _element_bind;
|
||||||
|
uint64_t _chunk_type_code;
|
||||||
|
std::map<uint64_t, std::pair<uint16_t, uint16_t>> _member_offset;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ChunkAccessIndex(ElementControlBlock* ecb, uint64_t chunk_type_code);
|
||||||
|
ChunkAccessIndex(const ChunkAccessIndex& other);
|
||||||
|
|
||||||
|
uint64_t chunkType() const;
|
||||||
|
uint16_t chunkSize() const;
|
||||||
|
bool contains(uint64_t type_code);
|
||||||
|
|
||||||
|
int8_t setMember(uint64_t type_code, uint16_t offset, uint16_t size);
|
||||||
|
unsigned char* getLockedDataPtr(uint64_t type_code);
|
||||||
|
void releaseData();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class ECSMEMORYPOOL_EXPORT ECSMemoryPool {
|
class ECSMEMORYPOOL_EXPORT ECSMemoryPool {
|
||||||
private:
|
private:
|
||||||
std::mutex _pool_protected_;
|
std::mutex _pool_protected_;
|
||||||
|
|
@ -55,7 +76,7 @@ public:
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <param name="one"></param>
|
/// <param name="one"></param>
|
||||||
template<CompenentType T> void registerComponent(const T &one) {
|
template<CompenentType T> void registerComponent(const T& one) {
|
||||||
std::lock_guard<std::mutex> lockx(_pool_protected_);
|
std::lock_guard<std::mutex> lockx(_pool_protected_);
|
||||||
|
|
||||||
auto ptr = new char[T::typeSize()];
|
auto ptr = new char[T::typeSize()];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue