A fist update solution for the item

This commit is contained in:
Sam Gateau 2015-05-31 19:10:37 -07:00
parent ddec8fd26f
commit 33d397a440
5 changed files with 39 additions and 22 deletions

View file

@ -3170,6 +3170,7 @@ public:
typedef render::Payload<WorldBoxRenderData> Payload;
typedef Payload::DataPointer Pointer;
int _val = 0;
static render::ItemID _item; // unique WorldBoxRenderData
};
@ -3406,11 +3407,11 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
pendingChanges.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload);
} else {
pendingChanges.updateItem(WorldBoxRenderData::_item,
render::UpdateFunctor(
pendingChanges.updateItem<WorldBoxRenderData>(WorldBoxRenderData::_item,
[](WorldBoxRenderData& payload) {
qCDebug(interfaceapp, "MyFirst update message!!!!!");
}));
payload._val++;
qCDebug(interfaceapp, "MyFirst update message!!!!! %u", payload._val);
});
}
{

View file

@ -19,7 +19,7 @@
#include <EntityScriptingInterface.h> // for RayToEntityIntersectionResult
#include <MouseEvent.h>
#include <OctreeRenderer.h>
#include <render/Scene.h>
//#include <render/Scene.h>
#include <ScriptCache.h>
#include <AbstractAudioInterface.h>

View file

@ -41,3 +41,4 @@ namespace render {
}

View file

@ -66,10 +66,6 @@ void Item::kill() {
_key._flags.reset();
}
void Item::update(const UpdateFunctor& functor) {
_payload->update(functor);
}
void PendingChanges::resetItem(ItemID id, const PayloadPointer& payload) {
_resetItems.push_back(id);
_resetPayloads.push_back(payload);
@ -79,7 +75,7 @@ void PendingChanges::removeItem(ItemID 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);
_updateFunctors.push_back(functor);
}

View file

@ -177,6 +177,7 @@ inline QDebug operator<<(QDebug debug, const ItemFilter& me) {
return debug;
}
class Item {
public:
typedef std::vector<Item> Vector;
@ -195,10 +196,12 @@ public:
};
// Update Functor
struct UpdateFunctor {
void* _something;
class UpdateFunctorInterface {
public:
virtual ~UpdateFunctorInterface() {}
};
typedef std::shared_ptr<UpdateFunctorInterface> UpdateFunctorPointer;
// Payload is whatever is in this Item and implement the Payload Interface
class PayloadInterface {
public:
@ -206,21 +209,23 @@ public:
virtual const Bound getBound() const = 0;
virtual void render(RenderArgs* args) = 0;
virtual void update(const UpdateFunctor& functor) = 0;
virtual void update(const UpdateFunctorPointer& functor) = 0;
~PayloadInterface() {}
protected:
};
typedef std::shared_ptr<PayloadInterface> PayloadPointer;
Item() {}
~Item() {}
void resetPayload(const PayloadPointer& payload);
void kill();
void update(const UpdateFunctor& updateFunctor);
// Check heuristic key
const ItemKey& getKey() const { return _key; }
@ -228,6 +233,7 @@ public:
// Payload Interface
const Bound getBound() const { return _payload->getBound(); }
void render(RenderArgs* args) { _payload->render(args); }
void update(const UpdateFunctorPointer& updateFunctor) { _payload->update(updateFunctor); }
protected:
PayloadPointer _payload;
@ -236,8 +242,19 @@ protected:
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) {
@ -245,7 +262,6 @@ inline QDebug operator<<(QDebug debug, const Item& item) {
return debug;
}
// 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
// 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 {
public:
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 Item::Bound getBound() const { return payloadGetBound<T>(_data); }
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) {}
protected:
@ -339,8 +355,11 @@ public:
void resetItem(ItemID id, const PayloadPointer& payload);
void removeItem(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);
template <class T> void updateItem(ItemID id, std::function<void(T&)> func) {
updateItem(id, UpdateFunctorPointer(new UpdateFunctor<T>(func)));
}
void updateItem(ItemID id, const UpdateFunctorPointer& functor);
void merge(PendingChanges& changes);