don't save default values in json file

This commit is contained in:
Seth Alves 2015-04-30 11:28:27 -07:00
parent 5e76e01b20
commit f75b599288
12 changed files with 115 additions and 51 deletions

View file

@ -66,7 +66,7 @@ DialogBase {
// our close function performs the same way as the OffscreenUI class: // our close function performs the same way as the OffscreenUI class:
// don't do anything but manipulate the enabled flag and let the other // don't do anything but manipulate the enabled flag and let the other
// mechanisms decide if the window should be destoryed after the close // mechanisms decide if the window should be destroyed after the close
// animation completes // animation completes
function close() { function close() {
if (destroyOnCloseButton) { if (destroyOnCloseButton) {

View file

@ -295,20 +295,23 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
return changedProperties; return changedProperties;
} }
QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) const { QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool skipDefaults) const {
QScriptValue properties = engine->newObject(); QScriptValue properties = engine->newObject();
EntityItemProperties defaultEntityProperties;
if (_idSet) { if (_idSet) {
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(id, _id.toString()); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(id, _id.toString());
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(isKnownID, (_id != UNKNOWN_ENTITY_ID)); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(isKnownID, (_id != UNKNOWN_ENTITY_ID));
} else { } else {
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(isKnownID, false); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(isKnownID, false);
} }
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(type, EntityTypes::getEntityTypeName(_type)); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(type, EntityTypes::getEntityTypeName(_type));
COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(position); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(position);
COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(dimensions); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(dimensions);
COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(naturalDimensions); // gettable, but not settable if (!skipDefaults) {
COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(naturalDimensions); // gettable, but not settable
}
COPY_PROPERTY_TO_QSCRIPTVALUE_QUAT(rotation); COPY_PROPERTY_TO_QSCRIPTVALUE_QUAT(rotation);
COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(velocity); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(velocity);
COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(gravity); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(gravity);
@ -316,8 +319,10 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
COPY_PROPERTY_TO_QSCRIPTVALUE(damping); COPY_PROPERTY_TO_QSCRIPTVALUE(damping);
COPY_PROPERTY_TO_QSCRIPTVALUE(density); COPY_PROPERTY_TO_QSCRIPTVALUE(density);
COPY_PROPERTY_TO_QSCRIPTVALUE(lifetime); COPY_PROPERTY_TO_QSCRIPTVALUE(lifetime);
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(age, getAge()); // gettable, but not settable if (!skipDefaults) {
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(ageAsText, formatSecondsElapsed(getAge())); // gettable, but not settable COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(age, getAge()); // gettable, but not settable
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(ageAsText, formatSecondsElapsed(getAge())); // gettable, but not settable
}
COPY_PROPERTY_TO_QSCRIPTVALUE(script); COPY_PROPERTY_TO_QSCRIPTVALUE(script);
COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(registrationPoint); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(registrationPoint);
COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(angularVelocity); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(angularVelocity);
@ -369,31 +374,37 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
COPY_PROPERTY_TO_QSCRIPTVALUE(stageHour); COPY_PROPERTY_TO_QSCRIPTVALUE(stageHour);
// Sitting properties support // Sitting properties support
QScriptValue sittingPoints = engine->newObject(); if (!skipDefaults) {
for (int i = 0; i < _sittingPoints.size(); ++i) { QScriptValue sittingPoints = engine->newObject();
QScriptValue sittingPoint = engine->newObject(); for (int i = 0; i < _sittingPoints.size(); ++i) {
sittingPoint.setProperty("name", _sittingPoints.at(i).name); QScriptValue sittingPoint = engine->newObject();
sittingPoint.setProperty("position", vec3toScriptValue(engine, _sittingPoints.at(i).position)); sittingPoint.setProperty("name", _sittingPoints.at(i).name);
sittingPoint.setProperty("rotation", quatToScriptValue(engine, _sittingPoints.at(i).rotation)); sittingPoint.setProperty("position", vec3toScriptValue(engine, _sittingPoints.at(i).position));
sittingPoints.setProperty(i, sittingPoint); sittingPoint.setProperty("rotation", quatToScriptValue(engine, _sittingPoints.at(i).rotation));
sittingPoints.setProperty(i, sittingPoint);
}
sittingPoints.setProperty("length", _sittingPoints.size());
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(sittingPoints, sittingPoints); // gettable, but not settable
} }
sittingPoints.setProperty("length", _sittingPoints.size());
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(sittingPoints, sittingPoints); // gettable, but not settable
AABox aaBox = getAABox(); if (!skipDefaults) {
QScriptValue boundingBox = engine->newObject(); AABox aaBox = getAABox();
QScriptValue bottomRightNear = vec3toScriptValue(engine, aaBox.getCorner()); QScriptValue boundingBox = engine->newObject();
QScriptValue topFarLeft = vec3toScriptValue(engine, aaBox.calcTopFarLeft()); QScriptValue bottomRightNear = vec3toScriptValue(engine, aaBox.getCorner());
QScriptValue center = vec3toScriptValue(engine, aaBox.calcCenter()); QScriptValue topFarLeft = vec3toScriptValue(engine, aaBox.calcTopFarLeft());
QScriptValue boundingBoxDimensions = vec3toScriptValue(engine, aaBox.getDimensions()); QScriptValue center = vec3toScriptValue(engine, aaBox.calcCenter());
boundingBox.setProperty("brn", bottomRightNear); QScriptValue boundingBoxDimensions = vec3toScriptValue(engine, aaBox.getDimensions());
boundingBox.setProperty("tfl", topFarLeft); boundingBox.setProperty("brn", bottomRightNear);
boundingBox.setProperty("center", center); boundingBox.setProperty("tfl", topFarLeft);
boundingBox.setProperty("dimensions", boundingBoxDimensions); boundingBox.setProperty("center", center);
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(boundingBox, boundingBox); // gettable, but not settable boundingBox.setProperty("dimensions", boundingBoxDimensions);
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(boundingBox, boundingBox); // gettable, but not settable
}
QString textureNamesList = _textureNames.join(",\n"); QString textureNamesList = _textureNames.join(",\n");
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(originalTextures, textureNamesList); // gettable, but not settable if (!skipDefaults) {
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(originalTextures, textureNamesList); // gettable, but not settable
}
return properties; return properties;
} }
@ -467,7 +478,11 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
} }
QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties) { QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties) {
return properties.copyToScriptValue(engine); return properties.copyToScriptValue(engine, false);
}
QScriptValue EntityItemNonDefaultPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties) {
return properties.copyToScriptValue(engine, true);
} }
void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties) { void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties) {

View file

@ -159,7 +159,7 @@ public:
EntityTypes::EntityType getType() const { return _type; } EntityTypes::EntityType getType() const { return _type; }
void setType(EntityTypes::EntityType type) { _type = type; } void setType(EntityTypes::EntityType type) { _type = type; }
virtual QScriptValue copyToScriptValue(QScriptEngine* engine) const; virtual QScriptValue copyToScriptValue(QScriptEngine* engine, bool skipDefaults) const;
virtual void copyFromScriptValue(const QScriptValue& object); virtual void copyFromScriptValue(const QScriptValue& object);
// editing related features supported by all entities // editing related features supported by all entities
@ -307,6 +307,7 @@ private:
}; };
Q_DECLARE_METATYPE(EntityItemProperties); Q_DECLARE_METATYPE(EntityItemProperties);
QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties); QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties);
QScriptValue EntityItemNonDefaultPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties);
void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties); void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemProperties& properties);

View file

@ -198,26 +198,41 @@
#define COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(P) \ #define COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(P) \
QScriptValue P = vec3toScriptValue(engine, _##P); \ if (!skipDefaults || defaultEntityProperties._##P != _##P) { \
properties.setProperty(#P, P); QScriptValue P = vec3toScriptValue(engine, _##P); \
properties.setProperty(#P, P); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE_QUAT(P) \ #define COPY_PROPERTY_TO_QSCRIPTVALUE_QUAT(P) \
QScriptValue P = quatToScriptValue(engine, _##P); \ if (!skipDefaults || defaultEntityProperties._##P != _##P) { \
properties.setProperty(#P, P); QScriptValue P = quatToScriptValue(engine, _##P); \
properties.setProperty(#P, P); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR(P) \ #define COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR(P) \
QScriptValue P = xColorToScriptValue(engine, _##P); \ if (!skipDefaults || defaultEntityProperties._##P != _##P) { \
properties.setProperty(#P, P); QScriptValue P = xColorToScriptValue(engine, _##P); \
properties.setProperty(#P, P); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(P,G) \ #define COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(P,G) \
QScriptValue P = xColorToScriptValue(engine, G); \ if (!skipDefaults || defaultEntityProperties._##P != _##P) { \
properties.setProperty(#P, P); QScriptValue P = xColorToScriptValue(engine, G); \
properties.setProperty(#P, P); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(P, G) \ #define COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(P, G) \
properties.setProperty(#P, G); properties.setProperty(#P, G);
#define COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(P, G) \
if (!skipDefaults || defaultEntityProperties._##P != _##P) { \
properties.setProperty(#P, G); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE(P) \ #define COPY_PROPERTY_TO_QSCRIPTVALUE(P) \
properties.setProperty(#P, _##P); if (!skipDefaults || defaultEntityProperties._##P != _##P) { \
properties.setProperty(#P, _##P); \
}
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(P, S) \ #define COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(P, S) \
QScriptValue P = object.property(#P); \ QScriptValue P = object.property(#P); \

View file

@ -1137,10 +1137,10 @@ bool EntityTree::sendEntitiesOperation(OctreeElement* element, void* extraData)
return true; return true;
} }
bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElement* element) { bool EntityTree::writeToMap(QVariantMap& entityDescription, OctreeElement* element, bool skipDefaultValues) {
entityDescription["Entities"] = QVariantList(); entityDescription["Entities"] = QVariantList();
QScriptEngine scriptEngine; QScriptEngine scriptEngine;
RecurseOctreeToMapOperator theOperator(entityDescription, element, &scriptEngine); RecurseOctreeToMapOperator theOperator(entityDescription, element, &scriptEngine, skipDefaultValues);
recurseTreeWithOperator(&theOperator); recurseTreeWithOperator(&theOperator);
return true; return true;
} }

View file

@ -163,7 +163,7 @@ public:
bool wantEditLogging() const { return _wantEditLogging; } bool wantEditLogging() const { return _wantEditLogging; }
void setWantEditLogging(bool value) { _wantEditLogging = value; } void setWantEditLogging(bool value) { _wantEditLogging = value; }
bool writeToMap(QVariantMap& entityDescription, OctreeElement* element); bool writeToMap(QVariantMap& entityDescription, OctreeElement* element, bool skipDefaultValues);
bool readFromMap(QVariantMap& entityDescription); bool readFromMap(QVariantMap& entityDescription);
signals: signals:

View file

@ -12,11 +12,15 @@
#include "RecurseOctreeToMapOperator.h" #include "RecurseOctreeToMapOperator.h"
RecurseOctreeToMapOperator::RecurseOctreeToMapOperator(QVariantMap& map, OctreeElement *top, QScriptEngine *engine) : RecurseOctreeToMapOperator::RecurseOctreeToMapOperator(QVariantMap& map,
OctreeElement *top,
QScriptEngine *engine,
bool skipDefaultValues) :
RecurseOctreeOperator(), RecurseOctreeOperator(),
_map(map), _map(map),
_top(top), _top(top),
_engine(engine) _engine(engine),
_skipDefaultValues(skipDefaultValues)
{ {
// if some element "top" was given, only save information for that element and it's children. // if some element "top" was given, only save information for that element and it's children.
if (_top) { if (_top) {
@ -36,6 +40,8 @@ bool RecurseOctreeToMapOperator::preRecursion(OctreeElement* element) {
bool RecurseOctreeToMapOperator::postRecursion(OctreeElement* element) { bool RecurseOctreeToMapOperator::postRecursion(OctreeElement* element) {
EntityItemProperties defaultProperties;
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element); EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
const QList<EntityItem*>& entities = entityTreeElement->getEntities(); const QList<EntityItem*>& entities = entityTreeElement->getEntities();
@ -43,7 +49,12 @@ bool RecurseOctreeToMapOperator::postRecursion(OctreeElement* element) {
foreach (EntityItem* entityItem, entities) { foreach (EntityItem* entityItem, entities) {
EntityItemProperties properties = entityItem->getProperties(); EntityItemProperties properties = entityItem->getProperties();
QScriptValue qScriptValues = EntityItemPropertiesToScriptValue(_engine, properties); QScriptValue qScriptValues;
if (_skipDefaultValues) {
qScriptValues = EntityItemNonDefaultPropertiesToScriptValue(_engine, properties);
} else {
qScriptValues = EntityItemPropertiesToScriptValue(_engine, properties);
}
entitiesQList << qScriptValues.toVariant(); entitiesQList << qScriptValues.toVariant();
} }
_map["Entities"] = entitiesQList; _map["Entities"] = entitiesQList;

View file

@ -13,7 +13,7 @@
class RecurseOctreeToMapOperator : public RecurseOctreeOperator { class RecurseOctreeToMapOperator : public RecurseOctreeOperator {
public: public:
RecurseOctreeToMapOperator(QVariantMap& map, OctreeElement *top, QScriptEngine *engine); RecurseOctreeToMapOperator(QVariantMap& map, OctreeElement *top, QScriptEngine *engine, bool skipDefaultValues);
bool preRecursion(OctreeElement* element); bool preRecursion(OctreeElement* element);
bool postRecursion(OctreeElement* element); bool postRecursion(OctreeElement* element);
private: private:
@ -21,4 +21,5 @@ public:
OctreeElement *_top; OctreeElement *_top;
QScriptEngine *_engine; QScriptEngine *_engine;
bool _withinTop; bool _withinTop;
bool _skipDefaultValues;
}; };

View file

@ -203,6 +203,16 @@ public:
glm::quat rotation; // relative orientation glm::quat rotation; // relative orientation
}; };
inline bool operator==(const SittingPoint& lhs, const SittingPoint& rhs)
{
return (lhs.name == rhs.name) && (lhs.position == rhs.position) && (lhs.rotation == rhs.rotation);
}
inline bool operator!=(const SittingPoint& lhs, const SittingPoint& rhs)
{
return (lhs.name != rhs.name) || (lhs.position != rhs.position) || (lhs.rotation != rhs.rotation);
}
/// A set of meshes extracted from an FBX document. /// A set of meshes extracted from an FBX document.
class FBXGeometry { class FBXGeometry {
public: public:

View file

@ -2087,7 +2087,7 @@ void Octree::writeToJSONFile(const char* fileName, OctreeElement* element) {
QFile persistFile(fileName); QFile persistFile(fileName);
QVariantMap entityDescription; QVariantMap entityDescription;
qCDebug(octree, "Saving to file %s...", fileName); qCDebug(octree, "Saving JSON SVO to file %s...", fileName);
OctreeElement* top; OctreeElement* top;
if (element) { if (element) {
@ -2096,7 +2096,7 @@ void Octree::writeToJSONFile(const char* fileName, OctreeElement* element) {
top = _rootElement; top = _rootElement;
} }
bool entityDescriptionSuccess = writeToMap(entityDescription, top); bool entityDescriptionSuccess = writeToMap(entityDescription, top, true);
if (entityDescriptionSuccess && persistFile.open(QIODevice::WriteOnly)) { if (entityDescriptionSuccess && persistFile.open(QIODevice::WriteOnly)) {
persistFile.write(QJsonDocument::fromVariant(entityDescription).toJson()); persistFile.write(QJsonDocument::fromVariant(entityDescription).toJson());
} else { } else {
@ -2108,7 +2108,7 @@ void Octree::writeToSVOFile(const char* fileName, OctreeElement* element) {
std::ofstream file(fileName, std::ios::out|std::ios::binary); std::ofstream file(fileName, std::ios::out|std::ios::binary);
if(file.is_open()) { if(file.is_open()) {
qCDebug(octree, "Saving to file %s...", fileName); qCDebug(octree, "Saving binary SVO to file %s...", fileName);
PacketType expectedType = expectedDataPacketType(); PacketType expectedType = expectedDataPacketType();
PacketVersion expectedVersion = versionForPacketType(expectedType); PacketVersion expectedVersion = versionForPacketType(expectedType);

View file

@ -331,7 +331,7 @@ public:
void writeToFile(const char* filename, OctreeElement* element = NULL, QString persistAsFileType = "svo"); void writeToFile(const char* filename, OctreeElement* element = NULL, QString persistAsFileType = "svo");
void writeToJSONFile(const char* filename, OctreeElement* element = NULL); void writeToJSONFile(const char* filename, OctreeElement* element = NULL);
void writeToSVOFile(const char* filename, OctreeElement* element = NULL); void writeToSVOFile(const char* filename, OctreeElement* element = NULL);
virtual bool writeToMap(QVariantMap& entityDescription, OctreeElement* element) = 0; virtual bool writeToMap(QVariantMap& entityDescription, OctreeElement* element, bool skipDefaultValues) = 0;
// Octree importers // Octree importers
bool readFromFile(const char* filename); bool readFromFile(const char* filename);

View file

@ -43,6 +43,17 @@ inline QDebug& operator<<(QDebug& dbg, const xColor& c) {
return dbg; return dbg;
} }
inline bool operator==(const xColor& lhs, const xColor& rhs)
{
return (lhs.red == rhs.red) && (lhs.green == rhs.green) && (lhs.blue == rhs.blue);
}
inline bool operator!=(const xColor& lhs, const xColor& rhs)
{
return (lhs.red != rhs.red) || (lhs.green != rhs.green) || (lhs.blue != rhs.blue);
}
static const float ZERO = 0.0f; static const float ZERO = 0.0f;
static const float ONE = 1.0f; static const float ONE = 1.0f;
static const float ONE_HALF = 0.5f; static const float ONE_HALF = 0.5f;