mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-10 17:23:15 +02:00
Renaming the PendingChanges
This commit is contained in:
parent
2ed7aae8d5
commit
3893dff94f
2 changed files with 24 additions and 24 deletions
|
@ -12,21 +12,21 @@
|
|||
|
||||
using namespace render;
|
||||
|
||||
void Scene::ChangeBatch::resetItem(ID id, PayloadPointer& payload) {
|
||||
void Scene::PendingChanges::resetItem(ID id, PayloadPointer& payload) {
|
||||
_resetItems.push_back(id);
|
||||
_resetPayloads.push_back(payload);
|
||||
}
|
||||
|
||||
void Scene::ChangeBatch::removeItem(ID id) {
|
||||
void Scene::PendingChanges::removeItem(ID id) {
|
||||
_removedItems.push_back(id);
|
||||
}
|
||||
|
||||
void Scene::ChangeBatch::moveItem(ID id) {
|
||||
void Scene::PendingChanges::moveItem(ID id) {
|
||||
_movedItems.push_back(id);
|
||||
}
|
||||
|
||||
|
||||
void Scene::ChangeBatch::mergeBatch(ChangeBatch& newBatch) {
|
||||
void Scene::PendingChanges::mergeBatch(PendingChanges& newBatch) {
|
||||
_resetItems.insert(_resetItems.end(), newBatch._resetItems.begin(), newBatch._resetItems.end());
|
||||
_resetPayloads.insert(_resetPayloads.end(), newBatch._resetPayloads.begin(), newBatch._resetPayloads.end());
|
||||
_removedItems.insert(_removedItems.end(), newBatch._removedItems.begin(), newBatch._removedItems.end());
|
||||
|
@ -44,24 +44,24 @@ Item::ID Scene::allocateID() {
|
|||
}
|
||||
|
||||
/// Enqueue change batch to the scene
|
||||
void Scene::enqueueChangeBatch(const ChangeBatch& changeBatch) {
|
||||
void Scene::enqueuePendingChanges(const PendingChanges& pendingChanges) {
|
||||
_changeQueueMutex.lock();
|
||||
_changeQueue.push(changeBatch);
|
||||
_changeQueue.push(pendingChanges);
|
||||
_changeQueueMutex.unlock();
|
||||
}
|
||||
|
||||
void consolidateChangeQueue(Scene::ChangeBatchQueue& queue, Scene::ChangeBatch& singleBatch) {
|
||||
void consolidateChangeQueue(Scene::PendingChangesQueue& queue, Scene::PendingChanges& singleBatch) {
|
||||
while (!queue.empty()) {
|
||||
auto changeBatch = queue.front();
|
||||
singleBatch.mergeBatch(changeBatch);
|
||||
auto pendingChanges = queue.front();
|
||||
singleBatch.mergeBatch(pendingChanges);
|
||||
queue.pop();
|
||||
};
|
||||
}
|
||||
|
||||
void Scene::processChangeBatchQueue() {
|
||||
void Scene::processPendingChangesQueue() {
|
||||
_changeQueueMutex.lock();
|
||||
ChangeBatch consolidatedChangeBatch;
|
||||
consolidateChangeQueue(_changeQueue, consolidatedChangeBatch);
|
||||
PendingChanges consolidatedPendingChanges;
|
||||
consolidateChangeQueue(_changeQueue, consolidatedPendingChanges);
|
||||
_changeQueueMutex.unlock();
|
||||
|
||||
_itemsMutex.lock();
|
||||
|
@ -72,10 +72,10 @@ void Scene::processChangeBatchQueue() {
|
|||
_items.resize(maxID + 100); // allocate the maxId and more
|
||||
}
|
||||
// Now we know for sure that we have enough items in the array to
|
||||
// capture anything coming from the changeBatch
|
||||
resetItems(consolidatedChangeBatch._resetItems, consolidatedChangeBatch._resetPayloads);
|
||||
removeItems(consolidatedChangeBatch._removedItems);
|
||||
moveItems(consolidatedChangeBatch._movedItems);
|
||||
// capture anything coming from the pendingChanges
|
||||
resetItems(consolidatedPendingChanges._resetItems, consolidatedPendingChanges._resetPayloads);
|
||||
removeItems(consolidatedPendingChanges._removedItems);
|
||||
moveItems(consolidatedPendingChanges._movedItems);
|
||||
|
||||
// ready to go back to rendering activities
|
||||
_itemsMutex.unlock();
|
||||
|
|
|
@ -161,16 +161,16 @@ public:
|
|||
typedef std::shared_ptr< Observer > ObserverPointer;
|
||||
typedef std::vector< ObserverPointer > Observers;
|
||||
|
||||
class ChangeBatch {
|
||||
class PendingChanges {
|
||||
public:
|
||||
ChangeBatch() {}
|
||||
~ChangeBatch();
|
||||
PendingChanges() {}
|
||||
~PendingChanges();
|
||||
|
||||
void resetItem(ID id, PayloadPointer& payload);
|
||||
void removeItem(ID id);
|
||||
void moveItem(ID id);
|
||||
|
||||
void mergeBatch(ChangeBatch& newBatch);
|
||||
void mergeBatch(PendingChanges& newBatch);
|
||||
|
||||
Payloads _resetPayloads;
|
||||
ItemIDs _resetItems;
|
||||
|
@ -179,7 +179,7 @@ public:
|
|||
|
||||
protected:
|
||||
};
|
||||
typedef std::queue<ChangeBatch> ChangeBatchQueue;
|
||||
typedef std::queue<PendingChanges> PendingChangesQueue;
|
||||
|
||||
Scene();
|
||||
~Scene() {}
|
||||
|
@ -188,7 +188,7 @@ public:
|
|||
ID allocateID();
|
||||
|
||||
/// Enqueue change batch to the scene
|
||||
void enqueueChangeBatch(const ChangeBatch& changeBatch);
|
||||
void enqueuePendingChanges(const PendingChanges& pendingChanges);
|
||||
|
||||
/// Scene Observer listen to any change and get notified
|
||||
void registerObserver(ObserverPointer& observer);
|
||||
|
@ -198,7 +198,7 @@ protected:
|
|||
// Thread safe elements that can be accessed from anywhere
|
||||
std::atomic<unsigned int> _IDAllocator;
|
||||
std::mutex _changeQueueMutex;
|
||||
ChangeBatchQueue _changeQueue;
|
||||
PendingChangesQueue _changeQueue;
|
||||
|
||||
// The actual database
|
||||
// database of items is protected for editing by a mutex
|
||||
|
@ -206,7 +206,7 @@ protected:
|
|||
Items _items;
|
||||
ItemLists _buckets;
|
||||
|
||||
void processChangeBatchQueue();
|
||||
void processPendingChangesQueue();
|
||||
void resetItems(const ItemIDs& ids, Payloads& payloads);
|
||||
void removeItems(const ItemIDs& ids);
|
||||
void moveItems(const ItemIDs& ids);
|
||||
|
|
Loading…
Reference in a new issue