Cogs.Core
ComponentDataPool.cpp
1#include "ComponentDataPool.h"
2
3#include <cassert>
4#include <cmath>
5#include <algorithm>
6
7Cogs::ComponentModel::ComponentDataPoolBase::ComponentDataPoolBase(SizeType capacity, size_t elementSize, MemBlockType memType)
8: store(capacity* elementSize, memType),
9 elementSize(elementSize),
10 capacity(capacity)
11{}
12
14{
15 ComponentIndex index = handle.index;
16
17 if (index >= capacity) {
18 const size_t newCapacity = std::min(static_cast<size_t>(std::numeric_limits<SizeType>::max()), static_cast<size_t>(std::round(static_cast<double>(capacity) * 1.55)));
19
20 store.resize(newCapacity * elementSize);
21
22 capacity = static_cast<SizeType>(newCapacity);
23 }
24
25 // The store is big enough to return a valid pointer when indexed.
26 assert(index < capacity);
27}
28
30{
31 // Noop
32}
COGSFOUNDATION_API void allocate(ComponentHandle handle)
Allocate a new data element in the pool at the index used by the given component handle.
COGSFOUNDATION_API ComponentDataPoolBase(SizeType capacity, size_t elementSize, MemBlockType memType=MemBlockType::Bucket)
Constructs a data pool with the given capacity and element size.
COGSFOUNDATION_API void deallocate(ComponentHandle handle)
Deallocate the data element in the pool at the index used by the given component handle.
uint32_t ComponentIndex
Type used to track component indexes in pools.
Definition: Component.h:16
ComponentIndex SizeType
Type used to track the size of pools.
Definition: Component.h:19
Handle to a Component instance.
Definition: Component.h:67