// // Created by Bradley Austin Davis on 2015/05/12 // Copyright 2013 High Fidelity, Inc. // Copyright 2020 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "WebEntityItem.h" #include #include #include #include #include #include #include #include "EntitiesLogging.h" #include "EntityItemProperties.h" #include "EntityTree.h" #include "EntityTreeElement.h" const QString WebEntityItem::DEFAULT_SOURCE_URL = NetworkingConstants::WEB_ENTITY_DEFAULT_SOURCE_URL; const QString WebEntityItem::DEFAULT_USER_AGENT = NetworkingConstants::WEB_ENTITY_DEFAULT_USER_AGENT; const uint8_t WebEntityItem::DEFAULT_MAX_FPS = 10; EntityItemPointer WebEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { std::shared_ptr entity(new WebEntityItem(entityID), [](WebEntityItem* ptr) { ptr->deleteLater(); }); entity->setProperties(properties); return entity; } WebEntityItem::WebEntityItem(const EntityItemID& entityItemID) : EntityItem(entityItemID) { // this initialzation of localSafeContext is reading a thread-local variable and that is depends on // the ctor being executed on the same thread as the script, assuming it's being create by a script _localSafeContext = hifi::scripting::isLocalAccessSafeThread(); _type = EntityTypes::Web; } void WebEntityItem::setUnscaledDimensions(const glm::vec3& value) { // NOTE: Web Entities always have a "depth" of 1cm. const float WEB_ENTITY_ITEM_FIXED_DEPTH = 0.01f; EntityItem::setUnscaledDimensions(glm::vec3(value.x, value.y, WEB_ENTITY_ITEM_FIXED_DEPTH)); } EntityItemProperties WebEntityItem::getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const { EntityItemProperties properties = EntityItem::getProperties(desiredProperties, allowEmptyDesiredProperties); // get the properties from our base class @Web_ENTITY_COPY_TO@ return properties; } bool WebEntityItem::setSubClassProperties(const EntityItemProperties& properties) { bool somethingChanged = false; @Web_ENTITY_SET_FROM@ return somethingChanged; } EntityPropertyFlags WebEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); @Web_REQUESTED_PROPS@ return requestedProperties; } void WebEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData, EntityPropertyFlags& requestedProperties, EntityPropertyFlags& propertyFlags, EntityPropertyFlags& propertiesDidntFit, int& propertyCount, OctreeElement::AppendState& appendState) const { bool successPropertyFits = true; @Web_ENTITY_APPEND@ } int WebEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args, EntityPropertyFlags& propertyFlags, bool overwriteLocalData, bool& somethingChanged) { int bytesRead = 0; const unsigned char* dataAt = data; @Web_ENTITY_READ@ return bytesRead; } void WebEntityItem::debugDump() const { qCDebug(entities) << "WebEntityItem id:" << getEntityItemID() << "---------------------------------------------"; qCDebug(entities) << " name:" << _name; qCDebug(entities) << " position:" << debugTreeVector(getWorldPosition()); qCDebug(entities) << " dimensions:" << debugTreeVector(getScaledDimensions()); qCDebug(entities) << " editedAgo:" << debugTime(getLastEdited(), usecTimestampNow()); qCDebug(entities) << " pointer:" << this; @Web_ENTITY_DEBUG@ } bool WebEntityItem::getLocalSafeContext() const { return resultWithReadLock([&] { return _localSafeContext; }); } void WebEntityItem::setScriptURL(const QString& value) { auto newURL = QUrl::fromUserInput(value); if (!newURL.isValid()) { qCDebug(entities) << "Not setting web entity script URL since" << value << "cannot be parsed to a valid URL."; return; } auto urlString = newURL.toDisplayString(); withWriteLock([&] { _needsRenderUpdate |= _scriptURL != urlString; _scriptURL = urlString; }); } QString WebEntityItem::getScriptURL() const { return resultWithReadLock([&] { return _scriptURL; }); } PulsePropertyGroup WebEntityItem::getPulseProperties() const { return resultWithReadLock([&] { return _pulseProperties; }); }