mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-26 02:55:25 +02:00
Trying to find a good solution for update message & data
This commit is contained in:
parent
7bde81e95f
commit
ddec8fd26f
3 changed files with 45 additions and 15 deletions
|
@ -3404,6 +3404,13 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
|
||||||
WorldBoxRenderData::_item = _main3DScene->allocateID();
|
WorldBoxRenderData::_item = _main3DScene->allocateID();
|
||||||
|
|
||||||
pendingChanges.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload);
|
pendingChanges.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
pendingChanges.updateItem(WorldBoxRenderData::_item,
|
||||||
|
render::UpdateFunctor(
|
||||||
|
[](WorldBoxRenderData& payload) {
|
||||||
|
qCDebug(interfaceapp, "MyFirst update message!!!!!");
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,8 +66,8 @@ void Item::kill() {
|
||||||
_key._flags.reset();
|
_key._flags.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::move() {
|
void Item::update(const UpdateFunctor& functor) {
|
||||||
|
_payload->update(functor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PendingChanges::resetItem(ItemID id, const PayloadPointer& payload) {
|
void PendingChanges::resetItem(ItemID id, const PayloadPointer& payload) {
|
||||||
|
@ -79,8 +79,9 @@ void PendingChanges::removeItem(ItemID id) {
|
||||||
_removedItems.push_back(id);
|
_removedItems.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PendingChanges::moveItem(ItemID id) {
|
void PendingChanges::updateItem(ItemID id, const UpdateFunctor& functor) {
|
||||||
_movedItems.push_back(id);
|
_updatedItems.push_back(id);
|
||||||
|
_updateFunctors.push_back(functor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +89,8 @@ void PendingChanges::merge(PendingChanges& changes) {
|
||||||
_resetItems.insert(_resetItems.end(), changes._resetItems.begin(), changes._resetItems.end());
|
_resetItems.insert(_resetItems.end(), changes._resetItems.begin(), changes._resetItems.end());
|
||||||
_resetPayloads.insert(_resetPayloads.end(), changes._resetPayloads.begin(), changes._resetPayloads.end());
|
_resetPayloads.insert(_resetPayloads.end(), changes._resetPayloads.begin(), changes._resetPayloads.end());
|
||||||
_removedItems.insert(_removedItems.end(), changes._removedItems.begin(), changes._removedItems.end());
|
_removedItems.insert(_removedItems.end(), changes._removedItems.begin(), changes._removedItems.end());
|
||||||
_movedItems.insert(_movedItems.end(), changes._movedItems.begin(), changes._movedItems.end());
|
_updatedItems.insert(_updatedItems.end(), changes._updatedItems.begin(), changes._updatedItems.end());
|
||||||
|
_updateFunctors.insert(_updateFunctors.end(), changes._updateFunctors.begin(), changes._updateFunctors.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
Scene::Scene() {
|
Scene::Scene() {
|
||||||
|
@ -133,7 +135,7 @@ void Scene::processPendingChangesQueue() {
|
||||||
// capture anything coming from the pendingChanges
|
// capture anything coming from the pendingChanges
|
||||||
resetItems(consolidatedPendingChanges._resetItems, consolidatedPendingChanges._resetPayloads);
|
resetItems(consolidatedPendingChanges._resetItems, consolidatedPendingChanges._resetPayloads);
|
||||||
removeItems(consolidatedPendingChanges._removedItems);
|
removeItems(consolidatedPendingChanges._removedItems);
|
||||||
moveItems(consolidatedPendingChanges._movedItems);
|
updateItems(consolidatedPendingChanges._updatedItems, consolidatedPendingChanges._updateFunctors);
|
||||||
|
|
||||||
// ready to go back to rendering activities
|
// ready to go back to rendering activities
|
||||||
_itemsMutex.unlock();
|
_itemsMutex.unlock();
|
||||||
|
@ -159,9 +161,11 @@ void Scene::removeItems(const ItemIDs& ids) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::moveItems(const ItemIDs& ids) {
|
void Scene::updateItems(const ItemIDs& ids, UpdateFunctors& functors) {
|
||||||
for (auto movedID :ids) {
|
auto updateID = ids.begin();
|
||||||
_items[movedID].move();
|
auto updateFunctor = functors.begin();
|
||||||
|
for (;updateID != ids.end(); updateID++, updateFunctor++) {
|
||||||
|
_items[(*updateID)].update((*updateFunctor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,11 @@ public:
|
||||||
int _firstFrame;
|
int _firstFrame;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Update Functor
|
||||||
|
struct UpdateFunctor {
|
||||||
|
void* _something;
|
||||||
|
};
|
||||||
|
|
||||||
// Payload is whatever is in this Item and implement the Payload Interface
|
// Payload is whatever is in this Item and implement the Payload Interface
|
||||||
class PayloadInterface {
|
class PayloadInterface {
|
||||||
public:
|
public:
|
||||||
|
@ -201,18 +206,21 @@ public:
|
||||||
virtual const Bound getBound() const = 0;
|
virtual const Bound getBound() const = 0;
|
||||||
virtual void render(RenderArgs* args) = 0;
|
virtual void render(RenderArgs* args) = 0;
|
||||||
|
|
||||||
|
virtual void update(const UpdateFunctor& functor) = 0;
|
||||||
|
|
||||||
~PayloadInterface() {}
|
~PayloadInterface() {}
|
||||||
protected:
|
protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<PayloadInterface> PayloadPointer;
|
typedef std::shared_ptr<PayloadInterface> PayloadPointer;
|
||||||
|
|
||||||
|
|
||||||
Item() {}
|
Item() {}
|
||||||
~Item() {}
|
~Item() {}
|
||||||
|
|
||||||
void resetPayload(const PayloadPointer& payload);
|
void resetPayload(const PayloadPointer& payload);
|
||||||
void kill();
|
void kill();
|
||||||
void move();
|
void update(const UpdateFunctor& updateFunctor);
|
||||||
|
|
||||||
// Check heuristic key
|
// Check heuristic key
|
||||||
const ItemKey& getKey() const { return _key; }
|
const ItemKey& getKey() const { return _key; }
|
||||||
|
@ -228,6 +236,10 @@ protected:
|
||||||
friend class Scene;
|
friend class Scene;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef Item::UpdateFunctor UpdateFunctor;
|
||||||
|
typedef std::vector<UpdateFunctor> UpdateFunctors;
|
||||||
|
|
||||||
|
|
||||||
inline QDebug operator<<(QDebug debug, const Item& item) {
|
inline QDebug operator<<(QDebug debug, const Item& item) {
|
||||||
debug << "[Item: _key:" << item.getKey() << ", bounds:" << item.getBound() << "]";
|
debug << "[Item: _key:" << item.getKey() << ", bounds:" << item.getBound() << "]";
|
||||||
return debug;
|
return debug;
|
||||||
|
@ -245,11 +257,14 @@ template <class T> void payloadRender(const std::shared_ptr<T>& payloadData, Ren
|
||||||
template <class T> class Payload : public Item::PayloadInterface {
|
template <class T> class Payload : public Item::PayloadInterface {
|
||||||
public:
|
public:
|
||||||
typedef std::shared_ptr<T> DataPointer;
|
typedef std::shared_ptr<T> DataPointer;
|
||||||
|
typedef std::function<void(T&)> Updator;
|
||||||
|
|
||||||
virtual const ItemKey getKey() const { return payloadGetKey<T>(_data); }
|
virtual const ItemKey getKey() const { return payloadGetKey<T>(_data); }
|
||||||
virtual const Item::Bound getBound() const { return payloadGetBound<T>(_data); }
|
virtual const Item::Bound getBound() const { return payloadGetBound<T>(_data); }
|
||||||
virtual void render(RenderArgs* args) { payloadRender<T>(_data, args); }
|
virtual void render(RenderArgs* args) { payloadRender<T>(_data, args); }
|
||||||
|
|
||||||
|
virtual void update(const UpdateFunctor& functor) { functor._f((*_data)); }
|
||||||
|
|
||||||
Payload(const DataPointer& data) : _data(data) {}
|
Payload(const DataPointer& data) : _data(data) {}
|
||||||
protected:
|
protected:
|
||||||
DataPointer _data;
|
DataPointer _data;
|
||||||
|
@ -315,6 +330,7 @@ public:
|
||||||
class Engine;
|
class Engine;
|
||||||
class Observer;
|
class Observer;
|
||||||
|
|
||||||
|
|
||||||
class PendingChanges {
|
class PendingChanges {
|
||||||
public:
|
public:
|
||||||
PendingChanges() {}
|
PendingChanges() {}
|
||||||
|
@ -322,14 +338,17 @@ public:
|
||||||
|
|
||||||
void resetItem(ItemID id, const PayloadPointer& payload);
|
void resetItem(ItemID id, const PayloadPointer& payload);
|
||||||
void removeItem(ItemID id);
|
void removeItem(ItemID id);
|
||||||
void moveItem(ItemID id);
|
|
||||||
|
template <class T> void updateItem(ItemID id, std::function<void(T&)>) { updateItem_(id, std::weak_ptr<std::function<void(T&)>
|
||||||
|
void updateItem_(ItemID id, const UpdateFunctor& functor);
|
||||||
|
|
||||||
void merge(PendingChanges& changes);
|
void merge(PendingChanges& changes);
|
||||||
|
|
||||||
Payloads _resetPayloads;
|
Payloads _resetPayloads;
|
||||||
ItemIDs _resetItems;
|
ItemIDs _resetItems;
|
||||||
ItemIDs _removedItems;
|
ItemIDs _removedItems;
|
||||||
ItemIDs _movedItems;
|
ItemIDs _updatedItems;
|
||||||
|
UpdateFunctors _updateFunctors;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
};
|
};
|
||||||
|
@ -413,7 +432,7 @@ protected:
|
||||||
|
|
||||||
void resetItems(const ItemIDs& ids, Payloads& payloads);
|
void resetItems(const ItemIDs& ids, Payloads& payloads);
|
||||||
void removeItems(const ItemIDs& ids);
|
void removeItems(const ItemIDs& ids);
|
||||||
void moveItems(const ItemIDs& ids);
|
void updateItems(const ItemIDs& ids, UpdateFunctors& functors);
|
||||||
|
|
||||||
|
|
||||||
// The scene context listening for any change to the database
|
// The scene context listening for any change to the database
|
||||||
|
|
Loading…
Reference in a new issue