Overte C++ Documentation
EntityDynamicInterface.h
1 //
2 // EntityDynamicInterface.h
3 // libraries/entities/src
4 //
5 // Created by Seth Alves on 2015-6-2
6 // Copyright 2015 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_EntityDynamicInterface_h
13 #define hifi_EntityDynamicInterface_h
14 
15 #include <memory>
16 
17 #include <glm/glm.hpp>
18 
19 #include <QUuid>
20 #include <QVariantMap>
21 
22 class EntityItem;
23 class EntityItemID;
24 class EntitySimulation;
25 using EntityItemPointer = std::shared_ptr<EntityItem>;
26 using EntityItemWeakPointer = std::weak_ptr<EntityItem>;
27 class EntitySimulation;
28 using EntitySimulationPointer = std::shared_ptr<EntitySimulation>;
29 
30 enum EntityDynamicType {
31  // keep these synchronized with dynamicTypeFromString and dynamicTypeToString
32  DYNAMIC_TYPE_NONE = 0,
33  DYNAMIC_TYPE_OFFSET = 1000,
34  DYNAMIC_TYPE_SPRING = 2000,
35  DYNAMIC_TYPE_TRACTOR = 2100,
36  DYNAMIC_TYPE_HOLD = 3000,
37  DYNAMIC_TYPE_TRAVEL_ORIENTED = 4000,
38  DYNAMIC_TYPE_HINGE = 5000,
39  DYNAMIC_TYPE_FAR_GRAB = 6000,
40  DYNAMIC_TYPE_SLIDER = 7000,
41  DYNAMIC_TYPE_BALL_SOCKET = 8000,
42  DYNAMIC_TYPE_CONE_TWIST = 9000
43 };
44 
45 
46 class EntityDynamicInterface {
47 public:
48  EntityDynamicInterface(EntityDynamicType type, const QUuid& id) : _id(id), _type(type) { }
49  virtual ~EntityDynamicInterface() { }
50  const QUuid& getID() const { return _id; }
51  EntityDynamicType getType() const { return _type; }
52 
53  virtual void removeFromOwner() { }
54 
55  virtual void remapIDs(QHash<EntityItemID, EntityItemID>& map) = 0;
56 
57  virtual bool isAction() const { return false; }
58  virtual bool isConstraint() const { return false; }
59  virtual bool isReadyForAdd() const { return true; }
60 
61  bool isActive() { return _active; }
62  void deactivate() { _active = false; }
63 
64  virtual void removeFromSimulation(EntitySimulationPointer simulation) const = 0;
65  virtual EntityItemWeakPointer getOwnerEntity() const = 0;
66  virtual void setOwnerEntity(const EntityItemPointer ownerEntity) = 0;
67  virtual bool updateArguments(QVariantMap arguments) = 0;
68  virtual QVariantMap getArguments() = 0;
69 
70  virtual QByteArray serialize() const = 0;
71  virtual void deserialize(QByteArray serializedArguments) = 0;
72 
73  static EntityDynamicType dynamicTypeFromString(QString dynamicTypeString);
74  static QString dynamicTypeToString(EntityDynamicType dynamicType);
75 
76  virtual bool lifetimeIsOver() { return false; }
77  virtual quint64 getExpires() { return 0; }
78 
79  virtual bool isMine() { return _isMine; }
80  virtual void setIsMine(bool value) { _isMine = value; }
81 
82  virtual bool shouldSuppressLocationEdits() { return false; }
83 
84  virtual void prepareForPhysicsSimulation() { }
85 
86  // these look in the arguments map for a named argument. if it's not found or isn't well formed,
87  // ok will be set to false (note that it's never set to true -- set it to true before calling these).
88  // if required is true, failure to extract an argument will cause a warning to be printed.
89  static glm::vec3 extractVec3Argument (QString objectName, QVariantMap arguments,
90  QString argumentName, bool& ok, bool required = true);
91  static glm::quat extractQuatArgument (QString objectName, QVariantMap arguments,
92  QString argumentName, bool& ok, bool required = true);
93  static float extractFloatArgument(QString objectName, QVariantMap arguments,
94  QString argumentName, bool& ok, bool required = true);
95  static int extractIntegerArgument(QString objectName, QVariantMap arguments,
96  QString argumentName, bool& ok, bool required = true);
97  static QString extractStringArgument(QString objectName, QVariantMap arguments,
98  QString argumentName, bool& ok, bool required = true);
99  static bool extractBooleanArgument(QString objectName, QVariantMap arguments,
100  QString argumentName, bool& ok, bool required = true);
101 
102 protected:
103  QUuid _id;
104  EntityDynamicType _type;
105  bool _active { false };
106  bool _isMine { false }; // did this interface create / edit this dynamic?
107 };
108 
109 
110 typedef std::shared_ptr<EntityDynamicInterface> EntityDynamicPointer;
111 
112 QDataStream& operator<<(QDataStream& stream, const EntityDynamicType& entityDynamicType);
113 QDataStream& operator>>(QDataStream& stream, EntityDynamicType& entityDynamicType);
114 
115 QString serializedDynamicsToDebugString(QByteArray data);
116 
117 #endif // hifi_EntityDynamicInterface_h
Definition: EntityItem.h:82
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28