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 <SoundCache.h>
#include "EntityTreeRenderer.h"
#include "RenderableEntityItem.h"
#include "RenderableBoxEntityItem.h"
#include "RenderableLightEntityItem.h"
#include "RenderableModelEntityItem.h"
@ -92,6 +95,9 @@ void EntityTreeRenderer::clear() {
}
OctreeRenderer::clear();
_entityScripts.clear();
qDebug() << "EntityTreeRenderer::clear() need to clear the scene... _viewState->getMain3DScene():" << _viewState->getMain3DScene().get();
}
void EntityTreeRenderer::init() {
@ -1048,10 +1054,39 @@ void EntityTreeRenderer::deletingEntity(const EntityItemID& entityID) {
checkAndCallUnload(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) {
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) {

View file

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

View file

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

View file

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

View file

@ -15,6 +15,9 @@
#include <glm/glm.hpp>
#include <functional>
#include <render/Scene.h>
#include <render/Engine.h>
#include <QtGlobal>
class Transform;
@ -60,6 +63,10 @@ public:
virtual void postLambdaEvent(std::function<void()> f) = 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 void setInstance(AbstractViewStateInterface* instance);
};

View file

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

View file

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