provide defaults for anything entity properties read from a map

This commit is contained in:
Seth Alves 2015-03-12 11:19:47 -07:00
parent 898b9f4af3
commit 4aa7b0eb0f
10 changed files with 66 additions and 62 deletions

View file

@ -77,6 +77,7 @@ bool ToolWindow::eventFilter(QObject* sender, QEvent* event) {
default:
break;
}
return false;
}

View file

@ -115,5 +115,5 @@ void BoxEntityItem::writeSubTypeToMap(QVariantMap& map) {
void BoxEntityItem::readFromMap(QVariantMap& map) {
qListtoRgbColor(map["color"], _color);
qListtoRgbColor(map.value("color", QVariantList() << 255 << 255 << 255), _color);
}

View file

@ -1148,9 +1148,6 @@ QVariantMap EntityItem::writeToMap() {
result["created"] = _created;
result["last-edited"] = getLastEdited();
result["last-updated"] = _lastUpdated;
// result["animation-update-delta"] = getLastUpdated() <= getLastEdited() ? 0 : getLastUpdated() - getLastEdited();
// result["simulation-update-delta"] = getLastSimulated() <= getLastEdited() ? 0 : getLastSimulated() - getLastEdited();
result["position"] = glmToQList(getPosition());
result["dimensions"] = glmToQList(getDimensions());
result["rotation"] = glmToQList(getRotation());
@ -1167,10 +1164,9 @@ QVariantMap EntityItem::writeToMap() {
result["ignore-for-collisions"] = getIgnoreForCollisions();
result["collisions-will-move"] = getCollisionsWillMove();
result["locked"] = getLocked();
result["userData"] = getUserData();
result["user-data"] = getUserData();
result["glow-level"] = getGlowLevel();
writeSubTypeToMap(result);
return result;
}

View file

@ -33,6 +33,7 @@ const glm::vec3 ENTITY_ITEM_DEFAULT_REGISTRATION_POINT = glm::vec3(0.5f, 0.5f, 0
const float ENTITY_ITEM_IMMORTAL_LIFETIME = -1.0f; /// special lifetime which means the entity lives for ever
const float ENTITY_ITEM_DEFAULT_LIFETIME = ENTITY_ITEM_IMMORTAL_LIFETIME;
const glm::vec3 ENTITY_ITEM_DEFAULT_POSITION = glm::vec3(100);
const glm::quat ENTITY_ITEM_DEFAULT_ROTATION;
const float ENTITY_ITEM_DEFAULT_WIDTH = 0.1f;
const glm::vec3 ENTITY_ITEM_DEFAULT_DIMENSIONS = glm::vec3(ENTITY_ITEM_DEFAULT_WIDTH);

View file

@ -10,6 +10,7 @@
//
#include <PerfStat.h>
#include <QDateTime>
#include "EntityTree.h"
#include "EntitySimulation.h"
@ -1105,32 +1106,40 @@ bool EntityTree::readFromMap(QVariantMap& map) {
entityItemID = EntityItemID(QUuid::createUuid());
}
properties.setCreated(entityMap["created"].toULongLong());
QString typeString = entityMap["type"].toString();
if (!entityMap.contains("type")) {
// forget it.
return false;
}
QString typeString = entityMap.value("type").toString();
QByteArray typeByteArray = typeString.toLocal8Bit();
const char *typeCString = typeByteArray.data();
properties.setType(EntityTypes::getEntityTypeFromName(typeCString));
properties.setPosition(qListToGlmVec3(entityMap["position"]));
properties.setDimensions(qListToGlmVec3(entityMap["dimensions"]));
properties.setRotation(qListToGlmQuat(entityMap["rotation"]));
properties.setDensity(entityMap["density"].toFloat());
properties.setVelocity(qListToGlmVec3(entityMap["angular-velocity"]));
properties.setGravity(qListToGlmVec3(entityMap["gravity"]));
properties.setDamping(entityMap["damping"].toFloat());
properties.setLifetime(entityMap["lifetime"].toFloat());
properties.setScript(entityMap["script"].toString());
properties.setRegistrationPoint(qListToGlmVec3(entityMap["registration-point"]));
properties.setAngularVelocity(qListToGlmVec3(entityMap["angular-velocity"]));
properties.setAngularDamping(entityMap["angular-damping"].toFloat());
properties.setGlowLevel(entityMap["glow"].toFloat());
properties.setLocalRenderAlpha(entityMap["alpha"].toFloat());
properties.setVisible(entityMap["visible"].toBool());
properties.setIgnoreForCollisions(entityMap["ignore-for-collisions"].toBool());
properties.setCollisionsWillMove(entityMap["collisions-will-move"].toBool());
properties.setLocked(entityMap["locked"].toBool());
properties.setUserData(entityMap["userData"].toString());
properties.setCreated(entityMap.value("created", usecTimestampNow()).toULongLong());
properties.setPosition(qListToGlmVec3(entityMap.value("position", glmToQList(ENTITY_ITEM_DEFAULT_POSITION))));
properties.setDimensions(qListToGlmVec3(entityMap.value("dimensions", glmToQList(ENTITY_ITEM_DEFAULT_DIMENSIONS))));
properties.setRotation(qListToGlmQuat(entityMap.value("rotation", glmToQList(ENTITY_ITEM_DEFAULT_ROTATION))));
properties.setDensity(entityMap.value("density", 1.0).toFloat());
properties.setVelocity(qListToGlmVec3(entityMap.value("velocity", glmToQList(ENTITY_ITEM_DEFAULT_VELOCITY))));
properties.setGravity(qListToGlmVec3(entityMap.value("gravity", glmToQList(ENTITY_ITEM_DEFAULT_GRAVITY))));
properties.setDamping(entityMap.value("damping", ENTITY_ITEM_DEFAULT_DAMPING).toFloat());
properties.setLifetime(entityMap.value("lifetime", ENTITY_ITEM_DEFAULT_LIFETIME).toFloat());
properties.setScript(entityMap.value("script", ENTITY_ITEM_DEFAULT_SCRIPT).toString());
properties.setRegistrationPoint(qListToGlmVec3(entityMap.value("registration-point",
glmToQList(ENTITY_ITEM_DEFAULT_REGISTRATION_POINT))));
properties.setAngularVelocity(qListToGlmVec3(entityMap.value("angular-velocity",
glmToQList(ENTITY_ITEM_DEFAULT_ANGULAR_VELOCITY))));
properties.setAngularDamping(entityMap.value("angular-damping", ENTITY_ITEM_DEFAULT_ANGULAR_DAMPING).toFloat());
properties.setGlowLevel(entityMap.value("glow", ENTITY_ITEM_DEFAULT_GLOW_LEVEL).toFloat());
properties.setLocalRenderAlpha(entityMap.value("alpha", ENTITY_ITEM_DEFAULT_LOCAL_RENDER_ALPHA).toFloat());
properties.setVisible(entityMap.value("visible", ENTITY_ITEM_DEFAULT_VISIBLE).toBool());
properties.setIgnoreForCollisions(entityMap.value("ignore-for-collisions",
ENTITY_ITEM_DEFAULT_IGNORE_FOR_COLLISIONS).toBool());
properties.setCollisionsWillMove(entityMap.value("collisions-will-move",
ENTITY_ITEM_DEFAULT_COLLISIONS_WILL_MOVE).toBool());
properties.setLocked(entityMap.value("locked", ENTITY_ITEM_DEFAULT_LOCKED).toBool());
properties.setUserData(entityMap.value("user-data", ENTITY_ITEM_DEFAULT_USER_DATA).toString());
EntityItem* entity = addEntity(entityItemID, properties);

View file

@ -161,8 +161,8 @@ void LightEntityItem::writeSubTypeToMap(QVariantMap& map) {
}
void LightEntityItem::readFromMap(QVariantMap& map) {
qListtoRgbColor(map["color"], _color);
_intensity = map["intensity"].toFloat();
_exponent = map["exponent"].toFloat();
_cutoff = map["cutoff"].toFloat();
qListtoRgbColor(map.value("color", QVariantList() << 255 << 255 << 255), _color);
_intensity = map.value("intensity", 1.0f).toFloat();
_exponent = map.value("exponent", 0.0f).toFloat();
_cutoff = map.value("cutoff", PI).toFloat();
}

View file

@ -428,14 +428,13 @@ void ModelEntityItem::writeSubTypeToMap(QVariantMap& map) {
void ModelEntityItem::readFromMap(QVariantMap& map) {
qListtoRgbColor(map["color"], _color);
_modelURL = map["model-url"].toString();
_animationURL = map["animation-url"].toString();
setAnimationFPS(map["animation-fps"].toFloat());
setAnimationFrameIndex(map["animation-frame-index"].toFloat());
setAnimationIsPlaying(map["animation-is-playing"].toBool());
_textures = map["textures"].toString();
setAnimationSettings(map["animation-settings"].toString());
_shapeType = (ShapeType)(map["shape-type"].toInt());
qListtoRgbColor(map.value("color", QVariantList() << 255 << 255 << 255), _color);
_modelURL = map.value("model-url", "").toString();
_animationURL = map.value("animation-url", "").toString();
setAnimationFPS(map.value("animation-fps", 0.0f).toFloat());
setAnimationFrameIndex(map.value("animation-frame-index", 0.0f).toFloat());
setAnimationIsPlaying(map.value("animation-is-playing", false).toBool());
_textures = map.value("textures", "").toString();
setAnimationSettings(map.value("animation-settings", "").toString());
_shapeType = (ShapeType)(map.value("shape-type", SHAPE_TYPE_NONE).toInt());
}

View file

@ -523,24 +523,23 @@ void ParticleEffectEntityItem::writeSubTypeToMap(QVariantMap& map) {
map["local-gravity"] = _localGravity;
map["particle-radius"] = _particleRadius;
map["last-animatged"] = _lastAnimated;
// XXX animation-loop
map["animation-last"] = getAnimationLoop();
map["animation-settings"] = _animationSettings;
map["shape-type"] = _shapeType;
}
void ParticleEffectEntityItem::readFromMap(QVariantMap& map) {
qListtoRgbColor(map["color"], _color);
_maxParticles = map["max-particles"].toFloat();
_lifespan = map["lifespan"].toFloat();
_emitRate = map["emit-rate"].toFloat();
_emitDirection = qListToGlmVec3(map["emit-direction"]);
_emitStrength = map["emit-strength"].toFloat();
_localGravity = map["local-gravity"].toFloat();
_particleRadius = map["particle-radius"].toFloat();
_lastAnimated = map["last-animated"].toULongLong();
// XXX animation-loop
_animationSettings = map["animation-settings"].toString();
_shapeType = (ShapeType)(map["shape-type"].toInt());
qListtoRgbColor(map.value("color", QVariantList() << 255 << 255 << 255), _color);
_maxParticles = map.value("max-particles", DEFAULT_MAX_PARTICLES).toFloat();
_lifespan = map.value("lifespan", DEFAULT_LIFESPAN).toFloat();
_emitRate = map.value("emit-rate", DEFAULT_EMIT_RATE).toFloat();
_emitDirection = qListToGlmVec3(map.value("emit-direction", glmToQList(DEFAULT_EMIT_DIRECTION)));
_emitStrength = map.value("emit-strength", DEFAULT_EMIT_STRENGTH).toFloat();
_localGravity = map.value("local-gravity", DEFAULT_LOCAL_GRAVITY).toFloat();
_particleRadius = map.value("particle-radius", DEFAULT_PARTICLE_RADIUS).toFloat();
_lastAnimated = map.value("last-animated", usecTimestampNow()).toULongLong();
setAnimationLoop (map.value("animation-loop", true).toBool());
_animationSettings = map.value("animation-settings", "").toString();
_shapeType = (ShapeType)(map.value("shape-type", SHAPE_TYPE_NONE).toInt());
}

View file

@ -136,5 +136,5 @@ void SphereEntityItem::writeSubTypeToMap(QVariantMap& map) {
void SphereEntityItem::readFromMap(QVariantMap& map) {
qListtoRgbColor(map["color"], _color);
qListtoRgbColor(map.value("color", QVariantList() << 255 << 255 << 255), _color);
}

View file

@ -180,10 +180,9 @@ void TextEntityItem::writeSubTypeToMap(QVariantMap& map) {
map["background-color"] = rgbColorToQList(_backgroundColor);
}
void TextEntityItem::readFromMap(QVariantMap& map) {
_text = map["text"].toString();
_lineHeight = map["line-height"].toFloat();
qListtoRgbColor(map["text-color"], _textColor);
qListtoRgbColor(map["background-color"], _backgroundColor);
_text = map.value("text", "").toString();
_lineHeight = map.value("line-height", TextEntityItem::DEFAULT_LINE_HEIGHT).toFloat();
qListtoRgbColor(map.value("text-color", QVariantList() << 255 << 255 << 255), _textColor);
qListtoRgbColor(map.value("background-color", QVariantList() << 0 << 0 << 0), _backgroundColor);
}