12 #ifndef hifi_workload_Transaction_h
13 #define hifi_workload_Transaction_h
19 #include <glm/glm.hpp>
26 namespace indexed_container {
28 using Index = int32_t;
29 const Index MAXIMUM_INDEX{ 1 << 30 };
30 const Index INVALID_INDEX{ -1 };
31 using Indices = std::vector< Index >;
33 template <Index MaxNumElements = MAXIMUM_INDEX>
38 Index _nextNewIndex{ 0 };
40 bool checkIndex(Index index)
const {
return ((index >= 0) && (index < _nextNewIndex)); }
41 Index getNumLiveIndices()
const {
return _nextNewIndex - (Index)_freeIndices.size(); }
42 Index getNumFreeIndices()
const {
return (Index)_freeIndices.size(); }
43 Index getNumAllocatedIndices()
const {
return _nextNewIndex; }
45 Index allocateIndex() {
46 if (_freeIndices.empty()) {
47 Index index = _nextNewIndex;
48 if (index >= MaxNumElements) {
59 Index index = _freeIndices.back();
60 _freeIndices.pop_back();
65 void freeIndex(Index index) {
66 if (checkIndex(index)) {
67 _freeIndices.push_back(index);
79 using Index = indexed_container::Index;
80 using IndexVector = indexed_container::Indices;
82 using ProxyID = Index;
83 const ProxyID INVALID_PROXY_ID{ indexed_container ::INVALID_INDEX };
96 using ProxyPayload = Sphere;
98 using Reset = std::tuple<ProxyID, ProxyPayload, Owner>;
99 using Remove = ProxyID;
100 using Update = std::tuple<ProxyID, ProxyPayload>;
102 using Resets = std::vector<Reset>;
103 using Removes = std::vector<Remove>;
104 using Updates = std::vector<Update>;
110 void reset(ProxyID
id,
const ProxyPayload& sphere,
const Owner& owner);
111 void reset(
const Resets& resets);
112 void remove(ProxyID
id);
113 void remove(
const Removes& removes);
114 bool hasRemovals()
const {
return !_removedItems.empty(); }
116 void update(ProxyID
id,
const ProxyPayload& sphere);
117 void update(
const Updates& updates);
119 void reserve(
const std::vector<Transaction>& transactionContainer);
120 void merge(
const std::vector<Transaction>& transactionContainer);
121 void merge(std::vector<Transaction>&& transactionContainer);
122 void merge(
const Transaction& transaction);
123 void merge(Transaction&& transaction);
130 Removes _removedItems;
131 Updates _updatedItems;
133 typedef std::vector<Transaction> TransactionQueue;
138 virtual ~Collection();
140 virtual void clear();
143 ProxyID allocateID();
146 bool isAllocatedID(
const ProxyID&
id)
const;
149 Index getNumAllocatedProxies()
const {
return _IDAllocator.getNumAllocatedIndices(); }
152 void enqueueTransaction(
const Transaction& transaction);
155 void enqueueTransaction(Transaction&& transaction);
158 uint32_t enqueueFrame();
161 virtual void processTransactionQueue();
166 indexed_container::Allocator<> _IDAllocator;
168 std::mutex _transactionQueueMutex;
169 TransactionQueue _transactionQueue;
172 std::mutex _transactionFramesMutex;
173 using TransactionFrames = std::vector<Transaction>;
174 TransactionFrames _transactionFrames;
175 uint32_t _transactionFrameNumber{ 0 };
178 virtual void processTransactionFrame(
const Transaction& transaction) = 0;