mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-15 20:48:45 +02:00
A fist update solution for the item
This commit is contained in:
parent
ddec8fd26f
commit
33d397a440
5 changed files with 39 additions and 22 deletions
|
@ -3170,6 +3170,7 @@ public:
|
||||||
typedef render::Payload<WorldBoxRenderData> Payload;
|
typedef render::Payload<WorldBoxRenderData> Payload;
|
||||||
typedef Payload::DataPointer Pointer;
|
typedef Payload::DataPointer Pointer;
|
||||||
|
|
||||||
|
int _val = 0;
|
||||||
static render::ItemID _item; // unique WorldBoxRenderData
|
static render::ItemID _item; // unique WorldBoxRenderData
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3406,11 +3407,11 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
|
||||||
pendingChanges.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload);
|
pendingChanges.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
pendingChanges.updateItem(WorldBoxRenderData::_item,
|
pendingChanges.updateItem<WorldBoxRenderData>(WorldBoxRenderData::_item,
|
||||||
render::UpdateFunctor(
|
|
||||||
[](WorldBoxRenderData& payload) {
|
[](WorldBoxRenderData& payload) {
|
||||||
qCDebug(interfaceapp, "MyFirst update message!!!!!");
|
payload._val++;
|
||||||
}));
|
qCDebug(interfaceapp, "MyFirst update message!!!!! %u", payload._val);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include <EntityScriptingInterface.h> // for RayToEntityIntersectionResult
|
#include <EntityScriptingInterface.h> // for RayToEntityIntersectionResult
|
||||||
#include <MouseEvent.h>
|
#include <MouseEvent.h>
|
||||||
#include <OctreeRenderer.h>
|
#include <OctreeRenderer.h>
|
||||||
#include <render/Scene.h>
|
//#include <render/Scene.h>
|
||||||
#include <ScriptCache.h>
|
#include <ScriptCache.h>
|
||||||
#include <AbstractAudioInterface.h>
|
#include <AbstractAudioInterface.h>
|
||||||
|
|
||||||
|
|
|
@ -41,3 +41,4 @@ namespace render {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -66,10 +66,6 @@ void Item::kill() {
|
||||||
_key._flags.reset();
|
_key._flags.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
_resetItems.push_back(id);
|
_resetItems.push_back(id);
|
||||||
_resetPayloads.push_back(payload);
|
_resetPayloads.push_back(payload);
|
||||||
|
@ -79,7 +75,7 @@ void PendingChanges::removeItem(ItemID id) {
|
||||||
_removedItems.push_back(id);
|
_removedItems.push_back(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PendingChanges::updateItem(ItemID id, const UpdateFunctor& functor) {
|
void PendingChanges::updateItem(ItemID id, const UpdateFunctorPointer& functor) {
|
||||||
_updatedItems.push_back(id);
|
_updatedItems.push_back(id);
|
||||||
_updateFunctors.push_back(functor);
|
_updateFunctors.push_back(functor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,6 +177,7 @@ inline QDebug operator<<(QDebug debug, const ItemFilter& me) {
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Item {
|
class Item {
|
||||||
public:
|
public:
|
||||||
typedef std::vector<Item> Vector;
|
typedef std::vector<Item> Vector;
|
||||||
|
@ -195,9 +196,11 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update Functor
|
// Update Functor
|
||||||
struct UpdateFunctor {
|
class UpdateFunctorInterface {
|
||||||
void* _something;
|
public:
|
||||||
|
virtual ~UpdateFunctorInterface() {}
|
||||||
};
|
};
|
||||||
|
typedef std::shared_ptr<UpdateFunctorInterface> UpdateFunctorPointer;
|
||||||
|
|
||||||
// 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 {
|
||||||
|
@ -206,21 +209,23 @@ 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;
|
virtual void update(const UpdateFunctorPointer& 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 update(const UpdateFunctor& updateFunctor);
|
|
||||||
|
|
||||||
// Check heuristic key
|
// Check heuristic key
|
||||||
const ItemKey& getKey() const { return _key; }
|
const ItemKey& getKey() const { return _key; }
|
||||||
|
@ -228,6 +233,7 @@ public:
|
||||||
// Payload Interface
|
// Payload Interface
|
||||||
const Bound getBound() const { return _payload->getBound(); }
|
const Bound getBound() const { return _payload->getBound(); }
|
||||||
void render(RenderArgs* args) { _payload->render(args); }
|
void render(RenderArgs* args) { _payload->render(args); }
|
||||||
|
void update(const UpdateFunctorPointer& updateFunctor) { _payload->update(updateFunctor); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PayloadPointer _payload;
|
PayloadPointer _payload;
|
||||||
|
@ -236,8 +242,19 @@ protected:
|
||||||
friend class Scene;
|
friend class Scene;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Item::UpdateFunctor UpdateFunctor;
|
|
||||||
typedef std::vector<UpdateFunctor> UpdateFunctors;
|
typedef Item::UpdateFunctorInterface UpdateFunctorInterface;
|
||||||
|
typedef Item::UpdateFunctorPointer UpdateFunctorPointer;
|
||||||
|
typedef std::vector<UpdateFunctorPointer> UpdateFunctors;
|
||||||
|
|
||||||
|
template <class T> class UpdateFunctor : public Item::UpdateFunctorInterface {
|
||||||
|
public:
|
||||||
|
typedef std::function<void(T&)> Func;
|
||||||
|
Func _func;
|
||||||
|
|
||||||
|
UpdateFunctor(Func func): _func(func) {}
|
||||||
|
~UpdateFunctor() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
inline QDebug operator<<(QDebug debug, const Item& item) {
|
inline QDebug operator<<(QDebug debug, const Item& item) {
|
||||||
|
@ -245,7 +262,6 @@ inline QDebug operator<<(QDebug debug, const Item& item) {
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// THe Payload class is the real Payload to be used
|
// THe Payload class is the real Payload to be used
|
||||||
// THis allow anything to be turned into a Payload as long as the required interface functions are available
|
// THis allow anything to be turned into a Payload as long as the required interface functions are available
|
||||||
// When creating a new kind of payload from a new "stuff" class then you need to create specialized version for "stuff"
|
// When creating a new kind of payload from a new "stuff" class then you need to create specialized version for "stuff"
|
||||||
|
@ -257,13 +273,13 @@ 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;
|
typedef UpdateFunctor<T> Updater;
|
||||||
|
|
||||||
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)); }
|
virtual void update(const UpdateFunctorPointer& functor) { static_cast<Updater*>(functor.get())->_func((*_data)); }
|
||||||
|
|
||||||
Payload(const DataPointer& data) : _data(data) {}
|
Payload(const DataPointer& data) : _data(data) {}
|
||||||
protected:
|
protected:
|
||||||
|
@ -339,8 +355,11 @@ public:
|
||||||
void resetItem(ItemID id, const PayloadPointer& payload);
|
void resetItem(ItemID id, const PayloadPointer& payload);
|
||||||
void removeItem(ItemID id);
|
void removeItem(ItemID id);
|
||||||
|
|
||||||
template <class T> void updateItem(ItemID id, std::function<void(T&)>) { updateItem_(id, std::weak_ptr<std::function<void(T&)>
|
template <class T> void updateItem(ItemID id, std::function<void(T&)> func) {
|
||||||
void updateItem_(ItemID id, const UpdateFunctor& functor);
|
updateItem(id, UpdateFunctorPointer(new UpdateFunctor<T>(func)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateItem(ItemID id, const UpdateFunctorPointer& functor);
|
||||||
|
|
||||||
void merge(PendingChanges& changes);
|
void merge(PendingChanges& changes);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue