Overte C++ Documentation
EntityItem.h
1 //
2 // EntityItem.h
3 // libraries/entities/src
4 //
5 // Created by Brad Hefta-Gaub on 12/4/13.
6 // Copyright 2013 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_EntityItem_h
13 #define hifi_EntityItem_h
14 
15 #include <memory>
16 #include <stdint.h>
17 
18 #include <glm/glm.hpp>
19 
20 #include <QtGui/QWindow>
21 #include <QSet>
22 
23 #include <Octree.h> // for EncodeBitstreamParams class
24 #include <OctreeElement.h> // for OctreeElement::AppendState
25 #include <OctreePacketData.h>
26 #include <PhysicsCollisionGroups.h>
27 #include <SimulationFlags.h>
28 #include <ShapeInfo.h>
29 #include <Transform.h>
30 #include <SpatiallyNestable.h>
31 #include <Interpolate.h>
32 
33 #include "EntityItemID.h"
34 #include "EntityItemPropertiesDefaults.h"
35 #include "EntityPropertyFlags.h"
36 #include "EntityTypes.h"
37 #include "SimulationOwner.h"
38 #include "EntityDynamicInterface.h"
39 #include "GrabPropertyGroup.h"
40 
41 class EntitySimulation;
42 using EntitySimulationPointer = std::shared_ptr<EntitySimulation>;
43 class EntityTreeElement;
44 class EntityTreeElementExtraEncodeData;
45 class EntityDynamicInterface;
47 class EntityTree;
48 class btCollisionShape;
49 typedef std::shared_ptr<EntityTree> EntityTreePointer;
50 typedef std::shared_ptr<EntityDynamicInterface> EntityDynamicPointer;
51 typedef std::shared_ptr<EntityTreeElement> EntityTreeElementPointer;
52 using EntityTreeElementExtraEncodeDataPointer = std::shared_ptr<EntityTreeElementExtraEncodeData>;
53 using SetOfEntities = QSet<EntityItemPointer>;
54 
55 #define DONT_ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() = 0;
56 #define ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() override { };
57 
58 #define debugTime(T, N) qPrintable(QString("%1 [ %2 ago]").arg(T, 16, 10).arg(formatUsecTime(N - T), 15))
59 #define debugTimeOnly(T) qPrintable(QString("%1").arg(T, 16, 10))
60 #define debugTreeVector(V) V << "[" << V << " in meters ]"
61 
62 const uint64_t MAX_OUTGOING_SIMULATION_UPDATE_PERIOD = 9 * USECS_PER_SECOND;
63 const uint64_t MAX_INCOMING_SIMULATION_UPDATE_PERIOD = MAX_OUTGOING_SIMULATION_UPDATE_PERIOD + USECS_PER_SECOND;
64 
65 class MeshProxyList;
66 
67 #ifdef DOMAIN
68 #undef DOMAIN
69 #endif
70 
71 namespace entity {
72 enum class HostType {
73  DOMAIN = 0,
74  AVATAR,
75  LOCAL
76 };
77 }
78 
82 class EntityItem : public QObject, public SpatiallyNestable, public ReadWriteLockable {
83  Q_OBJECT
84  // These two classes manage lists of EntityItem pointers and must be able to cleanup pointers when an EntityItem is deleted.
85  // To make the cleanup robust each EntityItem has backpointers to its manager classes (which are only ever set/cleared by
86  // the managers themselves, hence they are fiends) whose NULL status can be used to determine which managers still need to
87  // do cleanup.
88  friend class EntityTreeElement;
89  friend class EntitySimulation;
90 public:
91 
92  DONT_ALLOW_INSTANTIATION // This class can not be instantiated directly
93 
94  EntityItem(const EntityItemID& entityItemID);
95  virtual ~EntityItem();
96 
97  inline EntityItemPointer getThisPointer() const {
98  return std::static_pointer_cast<EntityItem>(std::const_pointer_cast<SpatiallyNestable>(shared_from_this()));
99  }
100 
101  EntityItemID getEntityItemID() const { return EntityItemID(_id); }
102 
103  // methods for getting/setting all properties of an entity
104  virtual EntityItemProperties getProperties(const EntityPropertyFlags& desiredProperties = EntityPropertyFlags(), bool allowEmptyDesiredProperties = false) const;
105 
107  // This function calls setSubClass properties and detects if any property changes value.
108  // If something changed then the "somethingChangedNotification" calls happens
109  virtual bool setProperties(const EntityItemProperties& properties);
110 
111  // Set properties for sub class so they can add their own properties
112  // it does nothing in the root class
113  // This function is called by setProperties which then can detects if any property changes value in the SubClass (see aboe comment on setProperties)
114  virtual bool setSubClassProperties(const EntityItemProperties& properties) { return false; }
115 
116  // Update properties with empty parent id and globalized/absolute values (applying offset), and apply (non-empty) log template to args id, name-or-type, parent id.
117  void globalizeProperties(EntityItemProperties& properties, const QString& messageTemplate = QString(), const glm::vec3& offset = glm::vec3(0.0f)) const;
118 
119  void recordCreationTime(); // set _created to 'now'
120  quint64 getLastSimulated() const;
121  void setLastSimulated(quint64 now);
122 
124  quint64 getLastEdited() const;
125  void setLastEdited(quint64 lastEdited);
126  float getEditedAgo() const
127  { return (float)(usecTimestampNow() - getLastEdited()) / (float)USECS_PER_SECOND; }
128 
130  quint64 getLastBroadcast() const { return _lastBroadcast; }
131  void setLastBroadcast(quint64 lastBroadcast) { _lastBroadcast = lastBroadcast; }
132 
133  void markAsChangedOnServer();
134  quint64 getLastChangedOnServer() const;
135 
136  virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const;
137 
138  virtual OctreeElement::AppendState appendEntityData(OctreePacketData* packetData, EncodeBitstreamParams& params,
139  EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData,
140  const bool destinationNodeCanGetAndSetPrivateUserData = false) const;
141 
142  virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
143  EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData,
144  EntityPropertyFlags& requestedProperties,
145  EntityPropertyFlags& propertyFlags,
146  EntityPropertyFlags& propertiesDidntFit,
147  int& propertyCount,
148  OctreeElement::AppendState& appendState) const { /* do nothing*/ };
149 
150  static EntityItemID readEntityItemIDFromBuffer(const unsigned char* data, int bytesLeftToRead,
151  ReadBitstreamToTreeParams& args);
152 
153  int readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args);
154 
155  virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
156  ReadBitstreamToTreeParams& args,
157  EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
158  bool& somethingChanged)
159  { somethingChanged = false; return 0; }
160  static int expectedBytes();
161 
162  static void adjustEditPacketForClockSkew(QByteArray& buffer, qint64 clockSkew);
163 
164  // perform update
165  virtual void update(const quint64& now);
166  quint64 getLastUpdated() const;
167 
168  // perform linear extrapolation for SimpleEntitySimulation
169  void simulate(const quint64& now);
170  bool stepKinematicMotion(float timeElapsed); // return 'true' if moving
171 
172  virtual bool needsToCallUpdate() const { return false; }
173 
174  virtual void debugDump() const;
175 
176  virtual bool supportsDetailedIntersection() const { return false; }
177  virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
178  const glm::vec3& viewFrustumPos, OctreeElementPointer& element, float& distance,
179  BoxFace& face, glm::vec3& surfaceNormal,
180  QVariantMap& extraInfo, bool precisionPicking) const { return true; }
181  virtual bool findDetailedParabolaIntersection(const glm::vec3& origin, const glm::vec3& velocity,
182  const glm::vec3& acceleration, const glm::vec3& viewFrustumPos, OctreeElementPointer& element,
183  float& parabolicDistance, BoxFace& face, glm::vec3& surfaceNormal,
184  QVariantMap& extraInfo, bool precisionPicking) const { return true; }
185 
186  // attributes applicable to all entity types
187  EntityTypes::EntityType getType() const { return _type; }
188 
189  inline glm::vec3 getCenterPosition(bool& success) const { return getTransformToCenter(success).getTranslation(); }
190  void setCenterPosition(const glm::vec3& position);
191 
192  const Transform getTransformToCenter(bool& success) const;
193  const Transform getTransformToCenterWithOnlyLocalRotation(bool& success) const;
194 
195  void requiresRecalcBoxes();
196 
197  // Hyperlink related getters and setters
198  QString getHref() const;
199  void setHref(QString value);
200 
201  QString getDescription() const;
202  void setDescription(const QString& value);
203 
205  virtual glm::vec3 getScaledDimensions() const;
206  virtual void setScaledDimensions(const glm::vec3& value);
207 
208  virtual glm::vec3 getPivot() const { return glm::vec3(0.0f); } // pivot offset for positioning, mainly for model entities
209 
210  glm::vec3 getUnscaledDimensions() const;
211  virtual void setUnscaledDimensions(const glm::vec3& value);
212 
213  void setDensity(float density);
214  float computeMass() const;
215  void setMass(float mass);
216 
217  float getDensity() const;
218 
219  bool hasVelocity() const { return getWorldVelocity() != ENTITY_ITEM_ZERO_VEC3; }
220  bool hasLocalVelocity() const { return getLocalVelocity() != ENTITY_ITEM_ZERO_VEC3; }
221 
222  glm::vec3 getGravity() const;
223  void setGravity(const glm::vec3& value);
224  bool hasGravity() const { return getGravity() != ENTITY_ITEM_ZERO_VEC3; }
225 
226  glm::vec3 getAcceleration() const;
227  void setAcceleration(const glm::vec3& value);
228  bool hasAcceleration() const { return getAcceleration() != ENTITY_ITEM_ZERO_VEC3; }
229 
230  float getDamping() const;
231  void setDamping(float value);
232 
233  float getRestitution() const;
234  void setRestitution(float value);
235 
236  float getFriction() const;
237  void setFriction(float value);
238 
239  // lifetime related properties.
240  float getLifetime() const;
241  void setLifetime(float value);
242 
243  quint64 getCreated() const;
244  void setCreated(quint64 value);
245 
247  bool isImmortal() const { return getLifetime() == ENTITY_ITEM_IMMORTAL_LIFETIME; }
248 
250  bool isMortal() const { return getLifetime() != ENTITY_ITEM_IMMORTAL_LIFETIME; }
251 
253  float getAge() const { return (float)(usecTimestampNow() - getCreated()) / (float)USECS_PER_SECOND; }
254  bool lifetimeHasExpired() const;
255  quint64 getExpiry() const;
256 
257  // position, size, and bounds related helpers
258  virtual AACube getMaximumAACube(bool& success) const override;
259  AACube getMinimumAACube(bool& success) const;
260  virtual AABox getAABox(bool& success) const;
261 
262  using SpatiallyNestable::getQueryAACube;
263  virtual AACube getQueryAACube(bool& success) const override;
264  virtual bool shouldPuffQueryAACube() const override;
265 
266  QString getScript() const;
267  void setScript(const QString& value);
268 
269  quint64 getScriptTimestamp() const;
270  void setScriptTimestamp(const quint64 value);
271 
272  QString getServerScripts() const;
273  void setServerScripts(const QString& serverScripts);
274 
275  QString getCollisionSoundURL() const;
276  void setCollisionSoundURL(const QString& value);
277 
278  glm::vec3 getRegistrationPoint() const;
280  virtual void setRegistrationPoint(const glm::vec3& value); // FIXME: this is suspicious!
281 
282  bool hasAngularVelocity() const { return getWorldAngularVelocity() != ENTITY_ITEM_ZERO_VEC3; }
283  bool hasLocalAngularVelocity() const { return getLocalAngularVelocity() != ENTITY_ITEM_ZERO_VEC3; }
284 
285  virtual void setAngularVelocity(const glm::vec3& angularVelocity);
286 
287  float getAngularDamping() const;
288  void setAngularDamping(float value);
289 
290  virtual QString getName() const override;
291  void setName(const QString& value);
292  QString getDebugName();
293 
294  bool getVisible() const;
295  void setVisible(bool value);
296 
297  bool isVisibleInSecondaryCamera() const;
298  void setIsVisibleInSecondaryCamera(bool value);
299 
300  RenderLayer getRenderLayer() const;
301  void setRenderLayer(RenderLayer value);
302 
303  PrimitiveMode getPrimitiveMode() const;
304  void setPrimitiveMode(PrimitiveMode value);
305 
306  bool getIgnorePickIntersection() const;
307  void setIgnorePickIntersection(bool value);
308 
309  bool getCanCastShadow() const;
310  void setCanCastShadow(bool value);
311 
312  bool getCullWithParent() const;
313  void setCullWithParent(bool value);
314 
315  void setCauterized(bool value);
316  bool getCauterized() const;
317 
318  inline bool isVisible() const { return getVisible(); }
319  inline bool isInvisible() const { return !getVisible(); }
320 
321  bool isChildOfMyAvatar() const;
322 
323  bool getCollisionless() const;
324  void setCollisionless(bool value);
325 
326  uint16_t getCollisionMask() const;
327  void setCollisionMask(uint16_t value);
328 
329  void computeCollisionGroupAndFinalMask(int32_t& group, int32_t& mask) const;
330 
331  bool getDynamic() const;
332  void setDynamic(bool value);
333 
334  virtual bool shouldBePhysical() const { return !isDead() && getShapeType() != SHAPE_TYPE_NONE && !isLocalEntity(); }
335  bool isVisuallyReady() const { return _visuallyReady; }
336 
337  bool getLocked() const;
338  void setLocked(bool value);
339 
340  QString getUserData() const;
341  virtual void setUserData(const QString& value); // FIXME: This is suspicious
342 
343  QString getPrivateUserData() const;
344  void setPrivateUserData(const QString& value);
345 
346  // FIXME not thread safe?
347  const SimulationOwner& getSimulationOwner() const { return _simulationOwner; }
348  void setSimulationOwner(const QUuid& id, uint8_t priority);
349  void setSimulationOwner(const SimulationOwner& owner);
350 
351  uint8_t getSimulationPriority() const { return _simulationOwner.getPriority(); }
352  QUuid getSimulatorID() const { return _simulationOwner.getID(); }
353  void clearSimulationOwnership();
354 
355  // TODO: move this "ScriptSimulationPriority" and "PendingOwnership" stuff into EntityMotionState
356  // but first would need to do some other cleanup. In the meantime these live here as "scratch space"
357  // to allow libs that don't know about each other to communicate.
358  void upgradeScriptSimulationPriority(uint8_t priority);
359  void clearScriptSimulationPriority();
360  uint8_t getScriptSimulationPriority() const { return _scriptSimulationPriority; }
361  void setPendingOwnershipPriority(uint8_t priority);
362  uint8_t getPendingOwnershipPriority() const { return _pendingOwnershipPriority; }
363  bool pendingRelease(uint64_t timestamp) const;
364  bool stillWaitingToTakeOwnership(uint64_t timestamp) const;
365 
366  bool getCloneable() const;
367  void setCloneable(bool value);
368  float getCloneLifetime() const;
369  void setCloneLifetime(float value);
370  float getCloneLimit() const;
371  void setCloneLimit(float value);
372  bool getCloneDynamic() const;
373  void setCloneDynamic(bool value);
374  bool getCloneAvatarEntity() const;
375  void setCloneAvatarEntity(bool value);
376  const QUuid getCloneOriginID() const;
377  void setCloneOriginID(const QUuid& value);
378 
379  // TODO: get rid of users of getRadius()...
380  float getRadius() const;
381 
382  virtual void adjustShapeInfoByRegistration(ShapeInfo& info, bool includePivot = true) const;
383  virtual bool contains(const glm::vec3& point) const;
384 
385  virtual bool isReadyToComputeShape() const { return !isDead(); }
386  virtual void computeShapeInfo(ShapeInfo& info);
387  virtual float getVolumeEstimate() const;
388 
390  virtual ShapeType getShapeType() const { return SHAPE_TYPE_NONE; }
391 
392  void setPosition(const glm::vec3& value);
393  virtual void setParentID(const QUuid& parentID) override;
394  virtual void setShapeType(ShapeType type) { /* do nothing */ }
395 
396  void setRotation(glm::quat orientation);
397  void setVelocity(const glm::vec3& velocity);
398 
399  uint32_t getDirtyFlags() const;
400  void markDirtyFlags(uint32_t mask);
401  void clearDirtyFlags(uint32_t mask = 0x0000ffff);
402 
403  uint32_t getSpecialFlags() const;
404  void markSpecialFlags(uint32_t mask);
405  void clearSpecialFlags(uint32_t mask = 0xffff0000);
406 
407  bool isMoving() const;
408  bool isMovingRelativeToParent() const;
409 
410  bool isSimulated() const { return _simulated; }
411 
412  bool isInPhysicsSimulation() const { return (bool)(_flags & Simulation::SPECIAL_FLAG_IN_PHYSICS_SIMULATION); }
413 
414  void* getPhysicsInfo() const { return _physicsInfo; }
415  void setPhysicsInfo(void* data) { _physicsInfo = data; }
416 
417  EntityTreeElementPointer getElement() const { return _element; }
418  EntityTreePointer getTree() const;
419  virtual SpatialParentTree* getParentTree() const override;
420  bool wantTerseEditLogging() const;
421 
422  glm::mat4 getEntityToWorldMatrix() const;
423  glm::mat4 getWorldToEntityMatrix() const;
424  glm::vec3 worldToEntity(const glm::vec3& point) const;
425  glm::vec3 entityToWorld(const glm::vec3& point) const;
426 
427  quint64 getLastEditedFromRemote() const { return _lastEditedFromRemote; }
428  void updateLastEditedFromRemote() { _lastEditedFromRemote = usecTimestampNow(); }
429 
430  void getTransformAndVelocityProperties(EntityItemProperties& properties) const;
431 
432  void flagForMotionStateChange() { _flags |= Simulation::DIRTY_MOTION_TYPE; }
433 
434  QString actionsToDebugString();
435  bool addAction(EntitySimulationPointer simulation, EntityDynamicPointer action);
436  bool updateAction(EntitySimulationPointer simulation, const QUuid& actionID, const QVariantMap& arguments);
437  bool removeAction(EntitySimulationPointer simulation, const QUuid& actionID);
438  bool clearActions(EntitySimulationPointer simulation);
439  void setDynamicData(QByteArray dynamicData);
440  const QByteArray getDynamicData() const;
441  bool hasActions() const { return !_objectActions.empty() || !_grabActions.empty(); }
442  QList<QUuid> getActionIDs() const { return _objectActions.keys(); }
443  QVariantMap getActionArguments(const QUuid& actionID) const;
444  void deserializeActions();
445 
446  void setDynamicDataDirty(bool value) const { _dynamicDataDirty = value; }
447  bool dynamicDataDirty() const { return _dynamicDataDirty; }
448 
449  void setDynamicDataNeedsTransmit(bool value) const { _dynamicDataNeedsTransmit = value; }
450  bool dynamicDataNeedsTransmit() const { return _dynamicDataNeedsTransmit; }
451  void setTransitingWithAvatar(bool value) { _transitingWithAvatar = value; }
452  bool getTransitingWithAvatar() { return _transitingWithAvatar; }
453 
454  bool shouldSuppressLocationEdits() const;
455 
456  void setSourceUUID(const QUuid& sourceUUID) { _sourceUUID = sourceUUID; }
457  const QUuid& getSourceUUID() const { return _sourceUUID; }
458  bool matchesSourceUUID(const QUuid& sourceUUID) const { return _sourceUUID == sourceUUID; }
459 
460  QList<EntityDynamicPointer> getActionsOfType(EntityDynamicType typeToGet) const;
461 
462  // these are in the frame of this object
463  virtual glm::quat getAbsoluteJointRotationInObjectFrame(int index) const override { return glm::quat(); }
464  virtual glm::vec3 getAbsoluteJointTranslationInObjectFrame(int index) const override { return glm::vec3(0.0f); }
465  virtual int getJointParent(int index) const override { return -1; }
466 
467  virtual bool setLocalJointRotation(int index, const glm::quat& rotation) override { return false; }
468  virtual bool setLocalJointTranslation(int index, const glm::vec3& translation) override { return false; }
469 
470  virtual int getJointIndex(const QString& name) const { return -1; }
471  virtual QStringList getJointNames() const { return QStringList(); }
472 
473  virtual void loader() {} // called indirectly when urls for geometry are updated
474 
483  bool shouldPreloadScript() const;
484  void scriptHasPreloaded();
485  void scriptHasUnloaded();
486  void setScriptHasFinishedPreload(bool value);
487  bool isScriptPreloadFinished();
488  virtual bool isWearable() const;
489  bool isDomainEntity() const { return _hostType == entity::HostType::DOMAIN; }
490  bool isAvatarEntity() const { return _hostType == entity::HostType::AVATAR; }
491  bool isMyAvatarEntity() const;
492  bool isLocalEntity() const { return _hostType == entity::HostType::LOCAL; }
493  entity::HostType getEntityHostType() const { return _hostType; }
494  virtual void setEntityHostType(entity::HostType hostType) { _hostType = hostType; }
495 
496  // if this entity is an avatar entity, which avatar is it associated with?
497  QUuid getOwningAvatarID() const { return _owningAvatarID; }
498  QUuid getOwningAvatarIDForProperties() const;
499  void setOwningAvatarID(const QUuid& owningAvatarID);
500 
501  virtual bool wantsHandControllerPointerEvents() const { return false; }
502  virtual bool wantsKeyboardFocus() const { return false; }
503  virtual void setProxyWindow(QWindow* proxyWindow) {}
504  virtual QObject* getEventHandler() { return nullptr; }
505 
506  QUuid getLastEditedBy() const { return _lastEditedBy; }
507  void setLastEditedBy(QUuid value) { _lastEditedBy = value; }
508 
509  virtual bool matchesJSONFilters(const QJsonObject& jsonFilters) const;
510 
511  virtual bool getMeshes(MeshProxyList& result) { return true; }
512 
513  virtual void locationChanged(bool tellPhysics = true, bool tellChildren = true) override;
514 
515  virtual bool getScalesWithParent() const override;
516 
517  using ChangeHandlerCallback = std::function<void(const EntityItemID&)>;
518  using ChangeHandlerId = QUuid;
519  ChangeHandlerId registerChangeHandler(const ChangeHandlerCallback& handler);
520  void deregisterChangeHandler(const ChangeHandlerId& changeHandlerId);
521 
522  void collectChildrenForDelete(std::vector<EntityItemPointer>& entitiesToDelete, const QUuid& sessionID) const;
523 
524  float getBoundingRadius() const { return _boundingRadius; }
525  void setSpaceIndex(int32_t index);
526  int32_t getSpaceIndex() const { return _spaceIndex; }
527 
528  virtual void preDelete();
529  virtual void postParentFixup() {}
530 
531  void setSimulationOwnershipExpiry(uint64_t expiry) { _simulationOwnershipExpiry = expiry; }
532  uint64_t getSimulationOwnershipExpiry() const { return _simulationOwnershipExpiry; }
533 
534  void addCloneID(const QUuid& cloneID);
535  void removeCloneID(const QUuid& cloneID);
536  const QVector<QUuid> getCloneIDs() const;
537  void setCloneIDs(const QVector<QUuid>& cloneIDs);
538  void setVisuallyReady(bool visuallyReady) { _visuallyReady = visuallyReady; }
539 
540  const GrabPropertyGroup& getGrabProperties() const { return _grabProperties; }
541 
542  void prepareForSimulationOwnershipBid(EntityItemProperties& properties, uint64_t now, uint8_t priority);
543 
544  virtual void addGrab(GrabPointer grab) override;
545  virtual void removeGrab(GrabPointer grab) override;
546  virtual void disableGrab(GrabPointer grab) override;
547 
548  bool stillHasMyGrab() const;
549 
550  bool needsRenderUpdate() const { return _needsRenderUpdate; }
551  void setNeedsRenderUpdate(bool needsRenderUpdate) { _needsRenderUpdate = needsRenderUpdate; }
552 
553  void setRenderWithZones(const QVector<QUuid>& renderWithZones);
554  QVector<QUuid> getRenderWithZones() const;
555  bool needsZoneOcclusionUpdate() const { return _needsZoneOcclusionUpdate; }
556  void resetNeedsZoneOcclusionUpdate() { withWriteLock([&] { _needsZoneOcclusionUpdate = false; }); }
557 
558  void setBillboardMode(BillboardMode value);
559  BillboardMode getBillboardMode() const;
560  virtual bool getRotateForPicking() const { return false; }
561 
562 signals:
563  void spaceUpdate(std::pair<int32_t, glm::vec4> data);
564 
565 protected:
566  QHash<ChangeHandlerId, ChangeHandlerCallback> _changeHandlers;
567 
568  void somethingChangedNotification();
569 
570  void setSimulated(bool simulated) { _simulated = simulated; }
571 
572  const QByteArray getDynamicDataInternal() const;
573  bool stillHasGrab() const;
574  void setDynamicDataInternal(QByteArray dynamicData);
575 
576  virtual void dimensionsChanged() override;
577 
578  glm::vec3 _unscaledDimensions { ENTITY_ITEM_DEFAULT_DIMENSIONS };
579  EntityTypes::EntityType _type { EntityTypes::Unknown };
580  quint64 _lastSimulated { 0 }; // last time this entity called simulate(), this includes velocity, angular velocity,
581  // and physics changes
582  quint64 _lastUpdated { 0 }; // last time this entity called update(), this includes animations and non-physics changes
583  quint64 _lastEdited { 0 }; // last official local or remote edit time
584  QUuid _lastEditedBy { ENTITY_ITEM_DEFAULT_LAST_EDITED_BY }; // id of last editor
585  quint64 _lastBroadcast; // the last time we sent an edit packet about this entity
586 
587  quint64 _lastEditedFromRemote { 0 }; // last time we received and edit from the server
588  quint64 _lastEditedFromRemoteInRemoteTime { 0 }; // last time we received an edit from the server (in server-time-frame)
589  quint64 _created { 0 };
590  quint64 _changedOnServer { 0 };
591 
592  mutable AABox _cachedAABox;
593  mutable AACube _maxAACube;
594  mutable AACube _minAACube;
595  mutable bool _recalcAABox { true };
596  mutable bool _recalcMinAACube { true };
597  mutable bool _recalcMaxAACube { true };
598 
599  float _density { ENTITY_ITEM_DEFAULT_DENSITY }; // kg/m^3
600  // NOTE: _volumeMultiplier is used to allow some mass properties code exist in the EntityItem base class
601  // rather than in all of the derived classes. If we ever collapse these classes to one we could do it a
602  // different way.
603  float _volumeMultiplier { 1.0f };
604  glm::vec3 _gravity { ENTITY_ITEM_DEFAULT_GRAVITY };
605  glm::vec3 _acceleration { ENTITY_ITEM_DEFAULT_ACCELERATION };
606  float _damping { ENTITY_ITEM_DEFAULT_DAMPING };
607  float _restitution { ENTITY_ITEM_DEFAULT_RESTITUTION };
608  float _friction { ENTITY_ITEM_DEFAULT_FRICTION };
609  float _lifetime { ENTITY_ITEM_DEFAULT_LIFETIME };
610 
611  QString _script { ENTITY_ITEM_DEFAULT_SCRIPT };
612  QString _loadedScript;
613  quint64 _scriptTimestamp { ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP };
614  bool _scriptPreloadFinished { false };
615 
616  QString _serverScripts;
618  quint64 _serverScriptsChangedTimestamp { ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP };
619 
621  // NOTE: on construction we want this to be different from _scriptTimestamp so we intentionally bump it
622  quint64 _loadedScriptTimestamp { ENTITY_ITEM_DEFAULT_SCRIPT_TIMESTAMP + 1 };
623 
624  QString _collisionSoundURL { ENTITY_ITEM_DEFAULT_COLLISION_SOUND_URL };
625  glm::vec3 _registrationPoint { ENTITY_ITEM_DEFAULT_REGISTRATION_POINT };
626  float _angularDamping { ENTITY_ITEM_DEFAULT_ANGULAR_DAMPING };
627  bool _visible { ENTITY_ITEM_DEFAULT_VISIBLE };
628  bool _isVisibleInSecondaryCamera { ENTITY_ITEM_DEFAULT_VISIBLE_IN_SECONDARY_CAMERA };
629  RenderLayer _renderLayer { RenderLayer::WORLD };
630  PrimitiveMode _primitiveMode { PrimitiveMode::SOLID };
631  bool _canCastShadow{ ENTITY_ITEM_DEFAULT_CAN_CAST_SHADOW };
632  bool _ignorePickIntersection { false };
633  bool _collisionless { ENTITY_ITEM_DEFAULT_COLLISIONLESS };
634  uint16_t _collisionMask { ENTITY_COLLISION_MASK_DEFAULT };
635  bool _dynamic { ENTITY_ITEM_DEFAULT_DYNAMIC };
636  bool _locked { ENTITY_ITEM_DEFAULT_LOCKED };
637  QString _userData { ENTITY_ITEM_DEFAULT_USER_DATA };
638  QString _privateUserData{ ENTITY_ITEM_DEFAULT_PRIVATE_USER_DATA };
639  SimulationOwner _simulationOwner;
640  bool _shouldHighlight { false };
641  QString _name { ENTITY_ITEM_DEFAULT_NAME };
642  QString _href; //Hyperlink href
643  QString _description; //Hyperlink description
644 
645 
646  // NOTE: Damping is applied like this: v *= pow(1 - damping, dt)
647  //
648  // Hence the damping coefficient must range from 0 (no damping) to 1 (immediate stop).
649  // Each damping value relates to a corresponding exponential decay timescale as follows:
650  //
651  // timescale = -1 / ln(1 - damping)
652  //
653  // damping = 1 - exp(-1 / timescale)
654  //
655 
656  // DirtyFlags are set whenever a property changes that the EntitySimulation needs to know about.
657  std::atomic_uint _flags { 0 }; // things that have changed from EXTERNAL changes (via script or packet) but NOT from simulation
658 
659  // these backpointers are only ever set/cleared by friends:
660  EntityTreeElementPointer _element; // set by EntityTreeElement
661  void* _physicsInfo { nullptr }; // set by EntitySimulation
662  bool _simulated { false }; // set by EntitySimulation
663  bool _visuallyReady { true };
664 
665  void enableNoBootstrap();
666  void disableNoBootstrap();
667 
668  bool addActionInternal(EntitySimulationPointer simulation, EntityDynamicPointer action);
669  bool removeActionInternal(const QUuid& actionID, EntitySimulationPointer simulation = nullptr);
670  void deserializeActionsInternal();
671  void serializeActions(bool& success, QByteArray& result) const;
672  QHash<QUuid, EntityDynamicPointer> _objectActions;
673 
674  static int _maxActionsDataSize;
675  mutable QByteArray _allActionsDataCache;
676 
677  // when an entity-server starts up, EntityItem::setDynamicData is called before the entity-tree is
678  // ready. This means we can't find our EntityItemPointer or add the action to the simulation. These
679  // are used to keep track of and work around this situation.
680  void checkWaitingToRemove(EntitySimulationPointer simulation = nullptr);
681  mutable QSet<QUuid> _actionsToRemove;
682  mutable bool _dynamicDataDirty { false };
683  mutable bool _dynamicDataNeedsTransmit { false };
684  // _previouslyDeletedActions is used to avoid an action being re-added due to server round-trip lag
685  static quint64 _rememberDeletedActionTime;
686  mutable QHash<QUuid, quint64> _previouslyDeletedActions;
687 
688  QUuid _sourceUUID;
689 
690  entity::HostType _hostType { entity::HostType::DOMAIN };
691  bool _transitingWithAvatar{ false };
692  QUuid _owningAvatarID;
693 
694  // physics related changes from the network to suppress any duplicates and make
695  // sure redundant applications are idempotent
696  glm::vec3 _lastUpdatedPositionValue;
697  glm::quat _lastUpdatedRotationValue;
698  glm::vec3 _lastUpdatedVelocityValue;
699  glm::vec3 _lastUpdatedAngularVelocityValue;
700  glm::vec3 _lastUpdatedAccelerationValue;
701  AACube _lastUpdatedQueryAACubeValue;
702 
703  quint64 _lastUpdatedPositionTimestamp { 0 };
704  quint64 _lastUpdatedRotationTimestamp { 0 };
705  quint64 _lastUpdatedVelocityTimestamp { 0 };
706  quint64 _lastUpdatedAngularVelocityTimestamp { 0 };
707  quint64 _lastUpdatedAccelerationTimestamp { 0 };
708  quint64 _lastUpdatedQueryAACubeTimestamp { 0 };
709  uint64_t _simulationOwnershipExpiry { 0 };
710 
711  float _boundingRadius { 0.0f };
712  int32_t _spaceIndex { -1 }; // index to proxy in workload::Space
713 
714  // TODO: move this "scriptSimulationPriority" and "pendingOwnership" stuff into EntityMotionState
715  // but first would need to do some other cleanup. In the meantime these live here as "scratch space"
716  // to allow libs that don't know about each other to communicate.
717  uint64_t _pendingOwnershipTimestamp { 0 }; // timestamp of last owenership change request
718  uint8_t _pendingOwnershipPriority { 0 }; // priority of last ownership change request
719  uint8_t _pendingOwnershipState { 0 }; // TAKE or RELEASE
720  uint8_t _scriptSimulationPriority { 0 }; // target priority based on script operations
721 
722  bool _cauterized { false }; // if true, don't draw because it would obscure 1st-person camera
723 
724  bool _cloneable { ENTITY_ITEM_DEFAULT_CLONEABLE };
725  float _cloneLifetime { ENTITY_ITEM_DEFAULT_CLONE_LIFETIME };
726  float _cloneLimit { ENTITY_ITEM_DEFAULT_CLONE_LIMIT };
727  bool _cloneDynamic { ENTITY_ITEM_DEFAULT_CLONE_DYNAMIC };
728  bool _cloneAvatarEntity { ENTITY_ITEM_DEFAULT_CLONE_AVATAR_ENTITY };
729  QUuid _cloneOriginID;
730  QVector<QUuid> _cloneIDs;
731 
732  GrabPropertyGroup _grabProperties;
733 
734  QHash<QUuid, EntityDynamicPointer> _grabActions;
735 
736  QVector<QUuid> _renderWithZones;
737  mutable bool _needsZoneOcclusionUpdate { false };
738 
739  BillboardMode _billboardMode { BillboardMode::NONE };
740 
741  bool _cullWithParent { false };
742 
743  mutable bool _needsRenderUpdate { false };
744 };
745 
746 #endif // hifi_EntityItem_h
Definition: EntityItem.h:82
bool hasAcceleration() const
acceleration in meters/second/second
Definition: EntityItem.h:228
bool isMortal() const
is this entity mortal, in that it has a lifetime set, and will automatically be deleted when that lif...
Definition: EntityItem.h:250
quint64 getLastEdited() const
Last edited time of this entity universal usecs.
Definition: EntityItem.cpp:2717
bool isImmortal() const
set the created-time in useconds for the entity
Definition: EntityItem.h:247
virtual AACube getMaximumAACube(bool &success) const override
Definition: EntityItem.cpp:1610
void setLastSimulated(quint64 now)
Last simulated time of this entity universal usecs.
Definition: EntityItem.cpp:2711
void setCreated(quint64 value)
get the created-time in useconds for the entity
Definition: EntityItem.cpp:2096
entity::HostType _hostType
the server node UUID we came from
Definition: EntityItem.h:690
void setAcceleration(const glm::vec3 &value)
get acceleration in meters/second/second
Definition: EntityItem.cpp:2808
quint64 _serverScriptsChangedTimestamp
keep track of time when _serverScripts property was last changed
Definition: EntityItem.h:618
quint64 getCreated() const
set the lifetime in seconds for the entity
Definition: EntityItem.cpp:2847
quint64 _scriptTimestamp
the value of _script when the last preload signal was sent
Definition: EntityItem.h:613
quint64 _loadedScriptTimestamp
the value of _scriptTimestamp when the last preload signal was sent
Definition: EntityItem.h:622
virtual void setRegistrationPoint(const glm::vec3 &value)
registration point as ratio of entity
Definition: EntityItem.cpp:1806
virtual bool setProperties(const EntityItemProperties &properties)
returns true if something changed
Definition: EntityItem.cpp:1468
void setGravity(const glm::vec3 &value)
get gravity in meters
Definition: EntityItem.cpp:1983
QString _loadedScript
the value of the script property
Definition: EntityItem.h:612
AACube getMinimumAACube(bool &success) const
Definition: EntityItem.cpp:1638
virtual glm::vec3 getScaledDimensions() const
Dimensions in meters (0.0 - TREE_SCALE)
Definition: EntityItem.cpp:1910
void setLifetime(float value)
get the lifetime in seconds for the entity
Definition: EntityItem.cpp:2087
virtual ShapeType getShapeType() const
return preferred shape type (actual physical shape may differ)
Definition: EntityItem.h:390
bool _scriptPreloadFinished
the script loaded property used for forced reload
Definition: EntityItem.h:614
quint64 getLastBroadcast() const
Last time we sent out an edit packet for this entity.
Definition: EntityItem.h:130
bool shouldPreloadScript() const
Definition: EntityItem.cpp:3357
bool hasGravity() const
gravity in meters
Definition: EntityItem.h:224
float getAge() const
age of this entity in seconds
Definition: EntityItem.h:253
float getEditedAgo() const
Elapsed seconds since this entity was last edited.
Definition: EntityItem.h:126
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28
Definition: EntityItemProperties.h:106
Handles packing of the data portion of PacketType_OCTREE_DATA messages.
Definition: OctreePacketData.h:93