move to-map recurse operator class to its own file

This commit is contained in:
Seth Alves 2015-03-16 11:54:50 -07:00
parent 109271de3d
commit 2d4a95c634
3 changed files with 95 additions and 64 deletions

View file

@ -21,6 +21,7 @@
#include "MovingEntitiesOperator.h"
#include "UpdateEntityOperator.h"
#include "QVariantGLM.h"
#include "RecurseOctreeToMapOperator.h"
EntityTree::EntityTree(bool shouldReaverage) :
Octree(shouldReaverage),
@ -1042,73 +1043,10 @@ bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData)
return true;
}
class ToMapOperator : public RecurseOctreeOperator {
public:
ToMapOperator(QVariantMap& map, OctreeElement *top, QScriptEngine *engine) :
RecurseOctreeOperator(),
_map(map),
_top(top),
_engine(engine)
{
// if some element "top" was given, only save information for that element and it's children.
if (_top) {
_withinTop = false;
} else {
// top was NULL, export entire tree.
_withinTop = true;
}
};
bool preRecursion(OctreeElement* element) {
if (element == _top) {
_withinTop = true;
}
return true;
}
bool postRecursion(OctreeElement* element) {
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
const QList<EntityItem*>& entities = entityTreeElement->getEntities();
QVariantList entitiesQList = qvariant_cast<QVariantList>(_map["Entities"]);
foreach (EntityItem* entityItem, entities) {
EntityItemProperties properties = entityItem->getProperties();
// XXX this is copied out of EntityScriptingInterface::getEntityProperties
// is it needed here?
// if (entityItem->getType() == EntityTypes::Model) {
// const FBXGeometry* geometry = getGeometryForEntity(entityItem);
// if (geometry) {
// properties.setSittingPoints(geometry->sittingPoints);
// Extents meshExtents = geometry->getUnscaledMeshExtents();
// properties.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum);
// }
// }
QScriptValue qScriptValues =
EntityItemPropertiesToScriptValue(_engine, properties);
entitiesQList << qScriptValues.toVariant();
}
_map["Entities"] = entitiesQList;
if (element == _top) {
_withinTop = false;
}
return true;
}
private:
QVariantMap& _map;
OctreeElement *_top;
QScriptEngine *_engine;
bool _withinTop;
};
bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElement* element) {
entityDescription["Entities"] = QVariantList();
QScriptEngine scriptEngine;
ToMapOperator theOperator(entityDescription, element, &scriptEngine);
RecurseOctreeToMapOperator theOperator(entityDescription, element, &scriptEngine);
recurseTreeWithOperator(&theOperator);
return true;
}

View file

@ -0,0 +1,69 @@
//
// RecurseOctreeToMapOperator.cpp
// libraries/entities/src
//
// Created by Seth Alves on 3/6/15.
// Copyright 2013 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 "RecurseOctreeToMapOperator.h"
RecurseOctreeToMapOperator::RecurseOctreeToMapOperator(QVariantMap& map, OctreeElement *top, QScriptEngine *engine) :
RecurseOctreeOperator(),
_map(map),
_top(top),
_engine(engine)
{
// if some element "top" was given, only save information for that element and it's children.
if (_top) {
_withinTop = false;
} else {
// top was NULL, export entire tree.
_withinTop = true;
}
};
bool RecurseOctreeToMapOperator::preRecursion(OctreeElement* element) {
if (element == _top) {
_withinTop = true;
}
return true;
}
bool RecurseOctreeToMapOperator::postRecursion(OctreeElement* element) {
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
const QList<EntityItem*>& entities = entityTreeElement->getEntities();
QVariantList entitiesQList = qvariant_cast<QVariantList>(_map["Entities"]);
foreach (EntityItem* entityItem, entities) {
EntityItemProperties properties = entityItem->getProperties();
// XXX this is copied out of EntityScriptingInterface::getEntityProperties
// is it needed here?
// if (entityItem->getType() == EntityTypes::Model) {
// const FBXGeometry* geometry = getGeometryForEntity(entityItem);
// if (geometry) {
// properties.setSittingPoints(geometry->sittingPoints);
// Extents meshExtents = geometry->getUnscaledMeshExtents();
// properties.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum);
// }
// }
QScriptValue qScriptValues =
EntityItemPropertiesToScriptValue(_engine, properties);
entitiesQList << qScriptValues.toVariant();
}
_map["Entities"] = entitiesQList;
if (element == _top) {
_withinTop = false;
}
return true;
}

View file

@ -0,0 +1,24 @@
//
// RecurseOctreeToMapOperator.h
// libraries/entities/src
//
// Created by Seth Alves on 3/6/15.
// Copyright 2013 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 "EntityTree.h"
class RecurseOctreeToMapOperator : public RecurseOctreeOperator {
public:
RecurseOctreeToMapOperator(QVariantMap& map, OctreeElement *top, QScriptEngine *engine);
bool preRecursion(OctreeElement* element);
bool postRecursion(OctreeElement* element);
private:
QVariantMap& _map;
OctreeElement *_top;
QScriptEngine *_engine;
bool _withinTop;
};