mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 18:44:00 +02:00
incorporate code review feedback
This commit is contained in:
parent
c90ca4b425
commit
bed37ef49a
7 changed files with 69 additions and 56 deletions
|
@ -9,6 +9,8 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <VariantMapToScriptValue.h>
|
||||
|
||||
#include "EntityScriptingInterface.h"
|
||||
#include "EntityTree.h"
|
||||
#include "LightEntityItem.h"
|
||||
|
@ -383,39 +385,3 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra
|
|||
vec3FromScriptValue(intersection, value.intersection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// XXX why can't I find a call that does this?
|
||||
QScriptValue variantMapToQScriptValue(QVariantMap& variantMap, QScriptEngine& scriptEngine) {
|
||||
QScriptValue scriptValue = scriptEngine.newObject();
|
||||
|
||||
for (QVariantMap::const_iterator iter = variantMap.begin(); iter != variantMap.end(); ++iter) {
|
||||
QString key = iter.key();
|
||||
QVariant qValue = iter.value();
|
||||
|
||||
switch(qValue.type()) {
|
||||
case QVariant::Bool:
|
||||
scriptValue.setProperty(key, qValue.toBool());
|
||||
break;
|
||||
case QVariant::Int:
|
||||
scriptValue.setProperty(key, qValue.toInt());
|
||||
break;
|
||||
case QVariant::Double:
|
||||
scriptValue.setProperty(key, qValue.toDouble());
|
||||
break;
|
||||
case QVariant::String: {
|
||||
scriptValue.setProperty(key, scriptEngine.newVariant(qValue));
|
||||
break;
|
||||
}
|
||||
case QVariant::Map: {
|
||||
QVariantMap childMap = qValue.toMap();
|
||||
scriptValue.setProperty(key, variantMapToQScriptValue(childMap, scriptEngine));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qDebug() << "unhandled QScript type" << qValue.type();
|
||||
}
|
||||
}
|
||||
|
||||
return scriptValue;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@ Q_DECLARE_METATYPE(RayToEntityIntersectionResult)
|
|||
|
||||
QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, const RayToEntityIntersectionResult& results);
|
||||
void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, RayToEntityIntersectionResult& results);
|
||||
QScriptValue variantMapToQScriptValue(QVariantMap& variantMap, QScriptEngine& scriptEngine);
|
||||
|
||||
|
||||
/// handles scripting of Entity commands from JS passed to assigned clients
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "EntityTree.h"
|
||||
#include "EntitySimulation.h"
|
||||
#include "EntityScriptingInterface.h"
|
||||
#include "VariantMapToScriptValue.h"
|
||||
|
||||
#include "AddEntityOperator.h"
|
||||
#include "MovingEntitiesOperator.h"
|
||||
|
@ -1091,7 +1091,7 @@ bool EntityTree::readFromMap(QVariantMap& map) {
|
|||
foreach (QVariant entityVariant, entitiesQList) {
|
||||
// QVariantMap --> QScriptValue --> EntityItemProperties --> Entity
|
||||
QVariantMap entityMap = entityVariant.toMap();
|
||||
QScriptValue entityScriptValue = variantMapToQScriptValue(entityMap, scriptEngine);
|
||||
QScriptValue entityScriptValue = variantMapToScriptValue(entityMap, scriptEngine);
|
||||
EntityItemProperties properties;
|
||||
EntityItemPropertiesFromScriptValue(entityScriptValue, properties);
|
||||
|
||||
|
|
|
@ -43,22 +43,7 @@ bool RecurseOctreeToMapOperator::postRecursion(OctreeElement* element) {
|
|||
|
||||
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);
|
||||
|
||||
QScriptValue qScriptValues = EntityItemPropertiesToScriptValue(_engine, properties);
|
||||
entitiesQList << qScriptValues.toVariant();
|
||||
}
|
||||
_map["Entities"] = entitiesQList;
|
||||
|
|
|
@ -148,7 +148,7 @@ bool OctreePersistThread::process() {
|
|||
qDebug() << "Loading Octree... lock file removed:" << lockFileName;
|
||||
}
|
||||
|
||||
persistantFileRead = _tree->readFromFile(_filename.toLocal8Bit().constData());
|
||||
persistantFileRead = _tree->readFromFile(qPrintable(_filename.toLocal8Bit()));
|
||||
_tree->pruneTree();
|
||||
}
|
||||
_tree->unlock();
|
||||
|
|
47
libraries/shared/src/VariantMapToScriptValue.cpp
Normal file
47
libraries/shared/src/VariantMapToScriptValue.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
//
|
||||
// VariantMapToScriptValue.cpp
|
||||
// libraries/shared/src/
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/6/13.
|
||||
// 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 <QDebug>
|
||||
#include "VariantMapToScriptValue.h"
|
||||
|
||||
QScriptValue variantMapToScriptValue(QVariantMap& variantMap, QScriptEngine& scriptEngine) {
|
||||
QScriptValue scriptValue = scriptEngine.newObject();
|
||||
|
||||
for (QVariantMap::const_iterator iter = variantMap.begin(); iter != variantMap.end(); ++iter) {
|
||||
QString key = iter.key();
|
||||
QVariant qValue = iter.value();
|
||||
|
||||
switch(qValue.type()) {
|
||||
case QVariant::Bool:
|
||||
scriptValue.setProperty(key, qValue.toBool());
|
||||
break;
|
||||
case QVariant::Int:
|
||||
scriptValue.setProperty(key, qValue.toInt());
|
||||
break;
|
||||
case QVariant::Double:
|
||||
scriptValue.setProperty(key, qValue.toDouble());
|
||||
break;
|
||||
case QVariant::String: {
|
||||
scriptValue.setProperty(key, scriptEngine.newVariant(qValue));
|
||||
break;
|
||||
}
|
||||
case QVariant::Map: {
|
||||
QVariantMap childMap = qValue.toMap();
|
||||
scriptValue.setProperty(key, variantMapToScriptValue(childMap, scriptEngine));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qDebug() << "unhandled QScript type" << qValue.type();
|
||||
}
|
||||
}
|
||||
|
||||
return scriptValue;
|
||||
}
|
16
libraries/shared/src/VariantMapToScriptValue.h
Normal file
16
libraries/shared/src/VariantMapToScriptValue.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
//
|
||||
// VariantMapToScriptValue.h
|
||||
// libraries/shared/src/
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 12/6/13.
|
||||
// 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 <QVariant>
|
||||
#include <QScriptValue>
|
||||
#include <QScriptEngine>
|
||||
|
||||
QScriptValue variantMapToScriptValue(QVariantMap& variantMap, QScriptEngine& scriptEngine);
|
Loading…
Reference in a new issue