Merge branch 'team-teaching' of https://github.com/highfidelity/hifi into punk

This commit is contained in:
Sam Gateau 2015-05-31 23:20:49 -07:00
commit c10384f91b
7 changed files with 140 additions and 20 deletions

View file

@ -119,6 +119,8 @@
#include "gpu/Context.h"
#include "gpu/GLBackend.h"
#include "RenderDeferredTask.h"
#include "scripting/AccountScriptingInterface.h"
#include "scripting/AudioDeviceScriptingInterface.h"
#include "scripting/ClipboardScriptingInterface.h"
@ -372,7 +374,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_runningScriptsWidget = new RunningScriptsWidget(_window);
_renderEngine->buildStandardTaskPipeline();
_renderEngine->addTask(render::TaskPointer(new RenderDeferredTask()));
_renderEngine->registerScene(_main3DScene);
// start the nodeThread so its event loop is running
@ -3168,6 +3170,7 @@ public:
typedef render::Payload<WorldBoxRenderData> Payload;
typedef Payload::DataPointer Pointer;
int _val = 0;
static render::ItemID _item; // unique WorldBoxRenderData
};
@ -3402,6 +3405,14 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
WorldBoxRenderData::_item = _main3DScene->allocateID();
pendingChanges.resetItem(WorldBoxRenderData::_item, worldBoxRenderPayload);
} else {
pendingChanges.updateItem<WorldBoxRenderData>(WorldBoxRenderData::_item,
[](WorldBoxRenderData& payload) {
payload._val++;
// A test Update to proof the concept is woking
// qCDebug(interfaceapp, "MyFirst update message!!!!! %u", payload._val);
});
}
{

View file

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

View file

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

View file

@ -0,0 +1,40 @@
//
// RenderDeferredTask.cpp
// render-utils/src/
//
// Created by Sam Gateau on 5/29/15.
// Copyright 20154 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "RenderDeferredTask.h"
using namespace render;
RenderDeferredTask::RenderDeferredTask() : Task() {
_jobs.push_back(Job(DrawOpaque()));
_jobs.push_back(Job(DrawLight()));
_jobs.push_back(Job(DrawTransparent()));
}
RenderDeferredTask::~RenderDeferredTask() {
}
void RenderDeferredTask::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
// sanity checks
assert(sceneContext);
if (!sceneContext->_scene) {
return;
}
// Is it possible that we render without a viewFrustum ?
if (!(renderContext->args && renderContext->args->_viewFrustum)) {
return;
}
for (auto job : _jobs) {
job.run(sceneContext, renderContext);
}
};

View file

@ -0,0 +1,31 @@
//
// RenderDeferredTask.h
// render-utils/src/
//
// Created by Sam Gateau on 5/29/15.
// Copyright 20154 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_RenderDeferredTask_h
#define hifi_RenderDeferredTask_h
#include "render/DrawTask.h"
class RenderDeferredTask : public render::Task {
public:
RenderDeferredTask();
~RenderDeferredTask();
render::Jobs _jobs;
virtual void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext);
};
#endif // hifi_RenderDeferredTask_h

View file

@ -66,10 +66,6 @@ void Item::kill() {
_key._flags.reset();
}
void Item::move() {
}
void PendingChanges::resetItem(ItemID id, const PayloadPointer& payload) {
_resetItems.push_back(id);
_resetPayloads.push_back(payload);
@ -79,8 +75,9 @@ void PendingChanges::removeItem(ItemID id) {
_removedItems.push_back(id);
}
void PendingChanges::moveItem(ItemID id) {
_movedItems.push_back(id);
void PendingChanges::updateItem(ItemID id, const UpdateFunctorPointer& functor) {
_updatedItems.push_back(id);
_updateFunctors.push_back(functor);
}
@ -88,7 +85,8 @@ void PendingChanges::merge(PendingChanges& changes) {
_resetItems.insert(_resetItems.end(), changes._resetItems.begin(), changes._resetItems.end());
_resetPayloads.insert(_resetPayloads.end(), changes._resetPayloads.begin(), changes._resetPayloads.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() {
@ -133,7 +131,7 @@ void Scene::processPendingChangesQueue() {
// capture anything coming from the pendingChanges
resetItems(consolidatedPendingChanges._resetItems, consolidatedPendingChanges._resetPayloads);
removeItems(consolidatedPendingChanges._removedItems);
moveItems(consolidatedPendingChanges._movedItems);
updateItems(consolidatedPendingChanges._updatedItems, consolidatedPendingChanges._updateFunctors);
// ready to go back to rendering activities
_itemsMutex.unlock();
@ -159,9 +157,11 @@ void Scene::removeItems(const ItemIDs& ids) {
}
}
void Scene::moveItems(const ItemIDs& ids) {
for (auto movedID :ids) {
_items[movedID].move();
void Scene::updateItems(const ItemIDs& ids, UpdateFunctors& functors) {
auto updateID = ids.begin();
auto updateFunctor = functors.begin();
for (;updateID != ids.end(); updateID++, updateFunctor++) {
_items[(*updateID)].update((*updateFunctor));
}
}

View file

@ -177,6 +177,7 @@ inline QDebug operator<<(QDebug debug, const ItemFilter& me) {
return debug;
}
class Item {
public:
typedef std::vector<Item> Vector;
@ -194,6 +195,13 @@ public:
int _firstFrame;
};
// Update Functor
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:
@ -201,18 +209,23 @@ public:
virtual const Bound getBound() const = 0;
virtual void render(RenderArgs* args) = 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 move();
// Check heuristic key
const ItemKey& getKey() const { return _key; }
@ -220,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;
@ -228,12 +242,26 @@ protected:
friend class Scene;
};
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) {
debug << "[Item: _key:" << item.getKey() << ", bounds:" << item.getBound() << "]";
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"
@ -245,11 +273,14 @@ 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 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 UpdateFunctorPointer& functor) { static_cast<Updater*>(functor.get())->_func((*_data)); }
Payload(const DataPointer& data) : _data(data) {}
protected:
DataPointer _data;
@ -315,6 +346,7 @@ public:
class Engine;
class Observer;
class PendingChanges {
public:
PendingChanges() {}
@ -322,14 +354,20 @@ public:
void resetItem(ItemID id, const PayloadPointer& payload);
void removeItem(ItemID id);
void moveItem(ItemID id);
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);
Payloads _resetPayloads;
ItemIDs _resetItems;
ItemIDs _removedItems;
ItemIDs _movedItems;
ItemIDs _updatedItems;
UpdateFunctors _updateFunctors;
protected:
};
@ -413,7 +451,7 @@ protected:
void resetItems(const ItemIDs& ids, Payloads& payloads);
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