From 579aec71184ca4682ea250d2bd0722513525ea01 Mon Sep 17 00:00:00 2001 From: "nissim.hadar" Date: Sat, 6 Jan 2018 01:37:23 -0800 Subject: [PATCH 1/3] Only check for zone fields. --- libraries/entities/src/EntityTree.cpp | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index ff1b65db15..a0eaefd43e 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -2281,22 +2281,24 @@ bool EntityTree::readFromMap(QVariantMap& map) { properties.setOwningAvatarID(myNodeID); } - // TEMPORARY fix for older content not containing these fields - if (!entityMap.contains("keyLightMode")) { - properties.setKeyLightMode(COMPONENT_MODE_ENABLED); - } - - if (!entityMap.contains("skyboxMode")) { - if (entityMap.contains("backgroundMode") && properties.getBackgroundModeAsString() == "inherit") { - // The content creator has set the combo to NOTHING - this is actually inherit - properties.setSkyboxMode(COMPONENT_MODE_INHERIT); - } else { - properties.setSkyboxMode(COMPONENT_MODE_ENABLED); + // TEMPORARY fix for older content not containing these fields in the zones + if (properties.getType() == EntityTypes::EntityType::Zone) { + if (!entityMap.contains("keyLightMode")) { + properties.setKeyLightMode(COMPONENT_MODE_ENABLED); } - } - if (!entityMap.contains("ambientLightMode")) { - properties.setAmbientLightMode(COMPONENT_MODE_ENABLED); + if (!entityMap.contains("skyboxMode")) { + if (entityMap.contains("backgroundMode") && properties.getBackgroundModeAsString() == "inherit") { + // The content creator has set the combo to NOTHING - this is actually inherit + properties.setSkyboxMode(COMPONENT_MODE_INHERIT); + } else { + properties.setSkyboxMode(COMPONENT_MODE_ENABLED); + } + } + + if (!entityMap.contains("ambientLightMode")) { + properties.setAmbientLightMode(COMPONENT_MODE_ENABLED); + } } EntityItemPointer entity = addEntity(entityItemID, properties); From d2ac27f1b883a528190ae68ceaea0c83a9e5e2de Mon Sep 17 00:00:00 2001 From: "nissim.hadar" Date: Sat, 6 Jan 2018 01:48:58 -0800 Subject: [PATCH 2/3] Code clean-up --- .../entities/src/EntityItemProperties.cpp | 63 +++++++------------ libraries/entities/src/EntityItemProperties.h | 11 ++++ 2 files changed, 33 insertions(+), 41 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 0a53f96a59..cfbfdd0274 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -208,20 +208,18 @@ void EntityItemProperties::setBackgroundModeFromString(const QString& background } } -using ComponentPair = std::pair; -const std::array COMPONENT_MODES = { { - ComponentPair{ COMPONENT_MODE_INHERIT,{ "inherit" } }, - ComponentPair{ COMPONENT_MODE_DISABLED,{ "disabled" } }, - ComponentPair{ COMPONENT_MODE_ENABLED,{ "enabled" } } -} }; - -QString EntityItemProperties::getHazeModeAsString() const { - // return "inherit" if _hazeMode is not valid - if (_hazeMode < COMPONENT_MODE_ITEM_COUNT) { - return COMPONENT_MODES[_hazeMode].second; +QString EntityItemProperties::getComponentModeAsString(uint32_t mode) { + // return "inherit" if mode is not valid + if (mode < COMPONENT_MODE_ITEM_COUNT) { + return COMPONENT_MODES[mode].second; } else { return COMPONENT_MODES[COMPONENT_MODE_INHERIT].second; } + +} + +QString EntityItemProperties::getHazeModeAsString() const { + return getComponentModeAsString(_hazeMode); } QString EntityItemProperties::getComponentModeString(uint32_t mode) { @@ -233,10 +231,14 @@ QString EntityItemProperties::getComponentModeString(uint32_t mode) { } } -void EntityItemProperties::setHazeModeFromString(const QString& hazeMode) { - auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { - return (pair.second == hazeMode); +std::array::const_iterator EntityItemProperties::findComponent(const QString& mode) { + return std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { + return (pair.second == mode); }); +} + +void EntityItemProperties::setHazeModeFromString(const QString& hazeMode) { + auto result = findComponent(hazeMode); if (result != COMPONENT_MODES.end()) { _hazeMode = result->first; @@ -245,18 +247,11 @@ void EntityItemProperties::setHazeModeFromString(const QString& hazeMode) { } QString EntityItemProperties::getKeyLightModeAsString() const { - // return "enabled" if _keyLightMode is not valid - if (_keyLightMode < COMPONENT_MODE_ITEM_COUNT) { - return COMPONENT_MODES[_keyLightMode].second; - } else { - return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; - } + return getComponentModeAsString(_keyLightMode); } void EntityItemProperties::setKeyLightModeFromString(const QString& keyLightMode) { - auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { - return (pair.second == keyLightMode); - }); + auto result = findComponent(keyLightMode); if (result != COMPONENT_MODES.end()) { _keyLightMode = result->first; @@ -265,18 +260,11 @@ void EntityItemProperties::setKeyLightModeFromString(const QString& keyLightMode } QString EntityItemProperties::getAmbientLightModeAsString() const { - // return "enabled" if _ambientLightMode is not valid - if (_ambientLightMode < COMPONENT_MODE_ITEM_COUNT) { - return COMPONENT_MODES[_ambientLightMode].second; - } else { - return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; - } + return getComponentModeAsString(_ambientLightMode); } void EntityItemProperties::setAmbientLightModeFromString(const QString& ambientLightMode) { - auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { - return (pair.second == ambientLightMode); - }); + auto result = findComponent(ambientLightMode); if (result != COMPONENT_MODES.end()) { _ambientLightMode = result->first; @@ -285,18 +273,11 @@ void EntityItemProperties::setAmbientLightModeFromString(const QString& ambientL } QString EntityItemProperties::getSkyboxModeAsString() const { - // return "enabled" if _skyboxMode is not valid - if (_skyboxMode < COMPONENT_MODE_ITEM_COUNT) { - return COMPONENT_MODES[_skyboxMode].second; - } else { - return COMPONENT_MODES[COMPONENT_MODE_ENABLED].second; - } + return getComponentModeAsString(_skyboxMode); } void EntityItemProperties::setSkyboxModeFromString(const QString& skyboxMode) { - auto result = std::find_if(COMPONENT_MODES.begin(), COMPONENT_MODES.end(), [&](const ComponentPair& pair) { - return (pair.second == skyboxMode); - }); + auto result = findComponent(skyboxMode); if (result != COMPONENT_MODES.end()) { _skyboxMode = result->first; diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 587b9189a1..0240cee44a 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -47,6 +47,13 @@ const quint64 UNKNOWN_CREATED_TIME = 0; +using ComponentPair = std::pair; +const std::array COMPONENT_MODES = { { + ComponentPair { COMPONENT_MODE_INHERIT, { "inherit" } }, + ComponentPair { COMPONENT_MODE_DISABLED, { "disabled" } }, + ComponentPair { COMPONENT_MODE_ENABLED, { "enabled" } } +} }; + /// A collection of properties of an entity item used in the scripting API. Translates between the actual properties of an /// entity and a JavaScript style hash/QScriptValue storing a set of properties. Used in scripting to set/get the complete /// set of entity item properties via JavaScript hashes/QScriptValues @@ -255,7 +262,11 @@ public: DEFINE_PROPERTY_REF(PROP_SERVER_SCRIPTS, ServerScripts, serverScripts, QString, ENTITY_ITEM_DEFAULT_SERVER_SCRIPTS); static QString getBackgroundModeString(BackgroundMode mode); + static QString getComponentModeString(uint32_t mode); + static QString getComponentModeAsString(uint32_t mode); + + std::array::const_iterator findComponent(const QString& mode); public: float getMaxDimension() const { return glm::compMax(_dimensions); } From 33cc17a52f89b00e232e3b3a5cb215a3636e9fe2 Mon Sep 17 00:00:00 2001 From: "nissim.hadar" Date: Sat, 6 Jan 2018 02:27:49 -0800 Subject: [PATCH 3/3] Removing unused Background mode. --- libraries/entities/src/EntityTree.cpp | 12 +++++------- libraries/entities/src/ZoneEntityItem.cpp | 3 --- libraries/entities/src/ZoneEntityItem.h | 2 -- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index a0eaefd43e..1efbe3ae0c 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -2287,13 +2287,11 @@ bool EntityTree::readFromMap(QVariantMap& map) { properties.setKeyLightMode(COMPONENT_MODE_ENABLED); } - if (!entityMap.contains("skyboxMode")) { - if (entityMap.contains("backgroundMode") && properties.getBackgroundModeAsString() == "inherit") { - // The content creator has set the combo to NOTHING - this is actually inherit - properties.setSkyboxMode(COMPONENT_MODE_INHERIT); - } else { - properties.setSkyboxMode(COMPONENT_MODE_ENABLED); - } + if (entityMap.contains("backgroundMode") && properties.getBackgroundModeAsString() == "skybox") { + properties.setSkyboxMode(COMPONENT_MODE_ENABLED); + } else { + // The content creator has set the combo to NOTHING - this is actually inherit + properties.setSkyboxMode(COMPONENT_MODE_INHERIT); } if (!entityMap.contains("ambientLightMode")) { diff --git a/libraries/entities/src/ZoneEntityItem.cpp b/libraries/entities/src/ZoneEntityItem.cpp index f2fb480353..38401de82e 100644 --- a/libraries/entities/src/ZoneEntityItem.cpp +++ b/libraries/entities/src/ZoneEntityItem.cpp @@ -42,8 +42,6 @@ ZoneEntityItem::ZoneEntityItem(const EntityItemID& entityItemID) : EntityItem(en _shapeType = DEFAULT_SHAPE_TYPE; _compoundShapeURL = DEFAULT_COMPOUND_SHAPE_URL; - - _backgroundMode = BACKGROUND_MODE_INHERIT; } EntityItemProperties ZoneEntityItem::getProperties(EntityPropertyFlags desiredProperties) const { @@ -285,7 +283,6 @@ void ZoneEntityItem::debugDump() const { qCDebug(entities) << " position:" << debugTreeVector(getWorldPosition()); qCDebug(entities) << " dimensions:" << debugTreeVector(getScaledDimensions()); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); - qCDebug(entities) << " _backgroundMode:" << EntityItemProperties::getBackgroundModeString(_backgroundMode); qCDebug(entities) << " _hazeMode:" << EntityItemProperties::getComponentModeString(_hazeMode); qCDebug(entities) << " _keyLightMode:" << EntityItemProperties::getComponentModeString(_keyLightMode); qCDebug(entities) << " _ambientLightMode:" << EntityItemProperties::getComponentModeString(_ambientLightMode); diff --git a/libraries/entities/src/ZoneEntityItem.h b/libraries/entities/src/ZoneEntityItem.h index aca7a0fd1b..6aae7bfbc3 100644 --- a/libraries/entities/src/ZoneEntityItem.h +++ b/libraries/entities/src/ZoneEntityItem.h @@ -128,8 +128,6 @@ protected: ShapeType _shapeType = DEFAULT_SHAPE_TYPE; QString _compoundShapeURL; - BackgroundMode _backgroundMode { BACKGROUND_MODE_INHERIT }; - // The following 3 values are the defaults for zone creation uint32_t _keyLightMode { COMPONENT_MODE_INHERIT }; uint32_t _skyboxMode { COMPONENT_MODE_INHERIT };