60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
#include "ecs_memorypool.h"
|
|
|
|
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();
|
|
}
|