more hacking

This commit is contained in:
ZappoMan 2015-05-27 13:23:59 -07:00
parent 007aed7a0a
commit 8c9cf480f3
7 changed files with 71 additions and 12 deletions

View file

@ -29,8 +29,11 @@
#include <TextureCache.h> #include <TextureCache.h>
#include <SoundCache.h> #include <SoundCache.h>
#include "EntityTreeRenderer.h" #include "EntityTreeRenderer.h"
#include "RenderableEntityItem.h"
#include "RenderableBoxEntityItem.h" #include "RenderableBoxEntityItem.h"
#include "RenderableLightEntityItem.h" #include "RenderableLightEntityItem.h"
#include "RenderableModelEntityItem.h" #include "RenderableModelEntityItem.h"
@ -92,6 +95,9 @@ void EntityTreeRenderer::clear() {
} }
OctreeRenderer::clear(); OctreeRenderer::clear();
_entityScripts.clear(); _entityScripts.clear();
qDebug() << "EntityTreeRenderer::clear() need to clear the scene... _viewState->getMain3DScene():" << _viewState->getMain3DScene().get();
} }
void EntityTreeRenderer::init() { void EntityTreeRenderer::init() {
@ -1048,10 +1054,39 @@ void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) {
checkAndCallUnload(entityID); checkAndCallUnload(entityID);
} }
_entityScripts.remove(entityID); _entityScripts.remove(entityID);
// here's where we remove the entity payload from the scene
qDebug() << "deletingEntity() entityID:" << entityID << "_viewState->getMain3DScene():" << _viewState->getMain3DScene().get();
render::Scene::PendingChanges pendingChanges;
if (_entityToSceneItems.contains(entityID)) {
render::ItemID renderItem = _entityToSceneItems[entityID];
pendingChanges.removeItem(renderItem);
_viewState->getMain3DScene()->enqueuePendingChanges(pendingChanges);
}
} }
void EntityTreeRenderer::addingEntity(const EntityItemID& entityID) { void EntityTreeRenderer::addingEntity(const EntityItemID& entityID) {
checkAndCallPreload(entityID); checkAndCallPreload(entityID);
// here's where we add the entity payload to the scene
qDebug() << "addingEntity() entityID:" << entityID << "_viewState->getMain3DScene():" << _viewState->getMain3DScene().get();
render::Scene::PendingChanges pendingChanges;
render::ItemID renderItem = _viewState->getMain3DScene()->allocateID();
_entityToSceneItems[entityID] = renderItem;
EntityItemPointer entity = static_cast<EntityTree*>(_tree)->findEntityByID(entityID);
auto renderData = RenderableEntityItem::Pointer(new RenderableEntityItem(entity));
auto renderPayload = render::PayloadPointer(new RenderableEntityItem::Payload(renderData));
qDebug() << " renderItem:" << renderItem;
qDebug() << " renderPayload:" << renderPayload.get();
pendingChanges.resetItem(renderItem, renderPayload);
_viewState->getMain3DScene()->enqueuePendingChanges(pendingChanges);
_viewState->getMain3DScene()->processPendingChangesQueue();
} }
void EntityTreeRenderer::entitySciptChanging(const EntityItemID& entityID) { void EntityTreeRenderer::entitySciptChanging(const EntityItemID& entityID) {

View file

@ -187,6 +187,7 @@ private:
float _previousStageHour; float _previousStageHour;
int _previousStageDay; int _previousStageDay;
QHash<EntityItemID, render::ItemID> _entityToSceneItems;
}; };

View file

@ -12,24 +12,30 @@
#include "RenderableEntityItem.h" #include "RenderableEntityItem.h"
// For Ubuntu, the compiler want's the Payload's functions to be specialized in the "render" namespace explicitely...
namespace render { namespace render {
template <> const ItemKey payloadGetKey(const RenderableEntityItem::Pointer& entity) { template <> const ItemKey payloadGetKey(const RenderableEntityItem::Pointer& payload) {
return ItemKey::Builder::opaqueShape(); qDebug() << "payloadGetKey()... for payload:" << payload.get();
ItemKey key = ItemKey::Builder::opaqueShape();
qDebug() << " key.isOpaque():" << key.isOpaque();
return key;
} }
template <> const Item::Bound payloadGetBound(const RenderableEntityItem::Pointer& entity) { template <> const Item::Bound payloadGetBound(const RenderableEntityItem::Pointer& payload) {
if (entity) { qDebug() << "payloadGetBound()... for payload:" << payload.get();
return entity->getAABox(); if (payload && payload->entity) {
return payload->entity->getAABox();
} }
return render::Item::Bound(); return render::Item::Bound();
} }
template <> void payloadRender(const RenderableEntityItem::Pointer& payload, RenderArgs* args) {
template <> void payloadRender(const RenderableEntityItem::Pointer& entity, RenderArgs* args) { qDebug() << "payloadRender()... for payload:" << payload.get();
if (args) { if (args) {
qDebug() << "rendering payload!! for payload:" << payload.get();
qDebug() << "rendering payload!! for entity:" << payload->entity.get();
args->_elementsTouched++; args->_elementsTouched++;
if (entity) { if (payload && payload->entity) {
entity->render(args); qDebug() << "rendering payload!! for entity:" << payload->entity->getEntityItemID();
payload->entity->render(args);
} }
} }
} }

View file

@ -15,11 +15,14 @@
#include <render/Scene.h> #include <render/Scene.h>
#include <EntityItem.h> #include <EntityItem.h>
class RenderableEntityItem { class RenderableEntityItem {
public: public:
RenderableEntityItem(EntityItemPointer entity) : entity(entity) { }
typedef render::Payload<RenderableEntityItem> Payload; typedef render::Payload<RenderableEntityItem> Payload;
typedef std::shared_ptr<render::Item::PayloadInterface> PayloadPointer; typedef Payload::DataPointer Pointer;
typedef EntityItemPointer Pointer;
EntityItemPointer entity;
}; };
#endif // hifi_RenderableEntityItem_h #endif // hifi_RenderableEntityItem_h

View file

@ -15,6 +15,9 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <functional> #include <functional>
#include <render/Scene.h>
#include <render/Engine.h>
#include <QtGlobal> #include <QtGlobal>
class Transform; class Transform;
@ -60,6 +63,10 @@ public:
virtual void postLambdaEvent(std::function<void()> f) = 0; virtual void postLambdaEvent(std::function<void()> f) = 0;
virtual qreal getDevicePixelRatio() = 0; virtual qreal getDevicePixelRatio() = 0;
virtual render::ScenePointer getMain3DScene() = 0;
virtual render::EnginePointer getRenderEngine() = 0;
// FIXME - we shouldn't assume that there's a single instance of an AbstractViewStateInterface
static AbstractViewStateInterface* instance(); static AbstractViewStateInterface* instance();
static void setInstance(AbstractViewStateInterface* instance); static void setInstance(AbstractViewStateInterface* instance);
}; };

View file

@ -32,8 +32,11 @@ void DrawSceneTask::run(const SceneContextPointer& sceneContext, const RenderCon
auto filter = ItemFilter::Builder::opaqueShape(); auto filter = ItemFilter::Builder::opaqueShape();
auto& opaqueShapeItems = itemBucketMap.at(filter); auto& opaqueShapeItems = itemBucketMap.at(filter);
qDebug() << "DrawSceneTask::run()";
for (auto id : opaqueShapeItems) { for (auto id : opaqueShapeItems) {
auto item = scene->getItem(id); auto item = scene->getItem(id);
qDebug() << " id:" << id;
item.render(args); item.render(args);
} }
}; };

View file

@ -115,6 +115,7 @@ void consolidateChangeQueue(Scene::PendingChangesQueue& queue, Scene::PendingCha
} }
void Scene::processPendingChangesQueue() { void Scene::processPendingChangesQueue() {
qDebug() << "Scene::processPendingChangesQueue()...";
_changeQueueMutex.lock(); _changeQueueMutex.lock();
PendingChanges consolidatedPendingChanges; PendingChanges consolidatedPendingChanges;
consolidateChangeQueue(_changeQueue, consolidatedPendingChanges); consolidateChangeQueue(_changeQueue, consolidatedPendingChanges);
@ -138,9 +139,12 @@ void Scene::processPendingChangesQueue() {
} }
void Scene::resetItems(const ItemIDs& ids, Payloads& payloads) { void Scene::resetItems(const ItemIDs& ids, Payloads& payloads) {
qDebug() << "Scene::resetItems()...";
auto resetID = ids.begin(); auto resetID = ids.begin();
auto resetPayload = payloads.begin(); auto resetPayload = payloads.begin();
for (;resetID != ids.end(); resetID++, resetPayload++) { for (;resetID != ids.end(); resetID++, resetPayload++) {
qDebug() << " resetID:" << *resetID;
auto& item = _items[(*resetID)]; auto& item = _items[(*resetID)];
auto oldKey = item.getKey(); auto oldKey = item.getKey();
item.resetPayload(*resetPayload); item.resetPayload(*resetPayload);