Overte C++ Documentation
EntityTypes.h
1 //
2 // EntityTypes.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_EntityTypes_h
13 #define hifi_EntityTypes_h
14 
15 #include <memory>
16 
17 #include <QHash>
18 #include <QString>
19 
20 #include "EntitiesLogging.h"
21 
22 class EntityItem;
23 using EntityItemPointer = std::shared_ptr<EntityItem>;
24 using EntityItemWeakPointer = std::weak_ptr<EntityItem>;
25 
26 inline uint qHash(const EntityItemPointer& a, uint seed) {
27  return qHash(a.get(), seed);
28 }
29 
30 class EntityItemID;
32 class ReadBitstreamToTreeParams;
33 
34 typedef EntityItemPointer (*EntityTypeFactory)(const EntityItemID& entityID, const EntityItemProperties& properties);
35 
36 class EntityTypes {
37 public:
38  /*@jsdoc
39  * <p>An entity may be one of the following types:</p>
40  * <table>
41  * <thead>
42  * <tr><th>Value</th><th>Description</th><th>Properties</th></tr>
43  * </thead>
44  * <tbody>
45  * <tr><td><code>"Shape"</code></td><td>A basic entity such as a cube.
46  * See also, the <code>"Box"</code> and <code>"Sphere"</code> entity types.</td>
47  * <td>{@link Entities.EntityProperties-Shape|EntityProperties-Shape}</td></tr>
48  * <tr><td><code>"Box"</code></td><td>A rectangular prism. This is a synonym of <code>"Shape"</code> for the case
49  * where the entity's <code>shape</code> property value is <code>"Cube"</code>.
50  * <p>If an entity is created with its <code>type</code>
51  * set to <code>"Box"</code> it will always be created with a <code>shape</code> property value of
52  * <code>"Cube"</code>. If an entity of type <code>Shape</code> or <code>Sphere</code> has its <code>shape</code> set
53  * to <code>"Cube"</code> then its <code>type</code> will be reported as <code>"Box"</code>.</p></td>
54  * <td>{@link Entities.EntityProperties-Box|EntityProperties-Box}</td></tr>
55  * <tr><td><code>"Sphere"</code></td><td>A sphere. This is a synonym of <code>"Shape"</code> for the case
56  * where the entity's <code>shape</code> property value is <code>"Sphere"</code>.
57  * <p>If an entity is created with its <code>type</code>
58  * set to <code>"Sphere"</code> it will always be created with a <code>shape</code> property value of
59  * <code>"Sphere"</code>. If an entity of type <code>Box</code> or <code>Shape</code> has its <code>shape</code> set
60  * to <code>"Sphere"</code> then its <code>type</code> will be reported as <code>"Sphere"</code>.</td>
61  * <td>{@link Entities.EntityProperties-Sphere|EntityProperties-Sphere}</td></tr>
62  * <tr><td><code>"Model"</code></td><td>A mesh model from a glTF, FBX, or OBJ file.</td>
63  * <td>{@link Entities.EntityProperties-Model|EntityProperties-Model}</td></tr>
64  * <tr><td><code>"Text"</code></td><td>A pane of text oriented in space.</td>
65  * <td>{@link Entities.EntityProperties-Text|EntityProperties-Text}</td></tr>
66  * <tr><td><code>"Image"</code></td><td>An image oriented in space.</td>
67  * <td>{@link Entities.EntityProperties-Image|EntityProperties-Image}</td></tr>
68  * <tr><td><code>"Web"</code></td><td>A browsable web page.</td>
69  * <td>{@link Entities.EntityProperties-Web|EntityProperties-Web}</td></tr>
70  * <tr><td><code>"ParticleEffect"</code></td><td>A particle system that can be used to simulate things such as fire,
71  * smoke, snow, magic spells, etc.</td>
72  * <td>{@link Entities.EntityProperties-ParticleEffect|EntityProperties-ParticleEffect}</td></tr>
73  * <tr><td><code>"Line"</code></td><td>A sequence of one or more simple straight lines.</td>
74  * <td>{@link Entities.EntityProperties-Line|EntityProperties-Line}</td></tr>
75  * <tr><td><code>"PolyLine"</code></td><td>A sequence of one or more textured straight lines.</td>
76  * <td>{@link Entities.EntityProperties-PolyLine|EntityProperties-PolyLine}</td></tr>
77  * <tr><td><code>"PolyVox"</code></td><td>A set of textured voxels.</td>
78  * <td>{@link Entities.EntityProperties-PolyVox|EntityProperties-PolyVox}</td></tr>
79  * <tr><td><code>"Grid"</code></td><td>A grid of lines in a plane.</td>
80  * <td>{@link Entities.EntityProperties-Grid|EntityProperties-Grid}</td></tr>
81  * <tr><td><code>"Gizmo"</code></td><td>A gizmo intended for UI.</td>
82  * <td>{@link Entities.EntityProperties-Gizmo|EntityProperties-Gizmo}</td></tr>
83  * <tr><td><code>"Light"</code></td><td>A local lighting effect.</td>
84  * <td>{@link Entities.EntityProperties-Light|EntityProperties-Light}</td></tr>
85  * <tr><td><code>"Zone"</code></td><td>A volume of lighting effects and avatar permissions.</td>
86  * <td>{@link Entities.EntityProperties-Zone|EntityProperties-Zone}</td></tr>
87  * <tr><td><code>"Material"</code></td><td>Modifies the existing materials on entities and avatars.</td>
88  * <td>{@link Entities.EntityProperties-Material|EntityProperties-Material}</td></tr>
89  * </tbody>
90  * </table>
91  * @typedef {string} Entities.EntityType
92  */
93  typedef enum EntityType_t {
94  Unknown,
95  Box,
96  Sphere,
97  Shape,
98  Model,
99  Text,
100  Image,
101  Web,
102  ParticleEffect,
103  Line,
104  PolyLine,
105  PolyVox,
106  Grid,
107  Gizmo,
108  Light,
109  Zone,
110  Material,
111  NUM_TYPES
112  } EntityType;
113 
114  static bool typeIsValid(EntityType type);
115  static const QString& getEntityTypeName(EntityType entityType);
116  static EntityTypes::EntityType getEntityTypeFromName(const QString& name);
117  static bool registerEntityType(EntityType entityType, const char* name, EntityTypeFactory factoryMethod);
118  static void extractEntityTypeAndID(const unsigned char* data, int dataLength, EntityTypes::EntityType& typeOut, QUuid& idOut);
119  static EntityItemPointer constructEntityItem(EntityType entityType, const EntityItemID& entityID, const EntityItemProperties& properties);
120  static EntityItemPointer constructEntityItem(const unsigned char* data, int bytesToRead);
121  static EntityItemPointer constructEntityItem(const QUuid& id, const EntityItemProperties& properties);
122 
123 private:
124  static QMap<EntityType, QString> _typeToNameMap;
125  static QMap<QString, EntityTypes::EntityType> _nameToTypeMap;
126  static EntityTypeFactory _factories[NUM_TYPES];
127  static bool _factoriesInitialized;
128 };
129 
130 
134 // static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
135 #define REGISTER_ENTITY_TYPE(x) bool x##Registration = \
136  EntityTypes::registerEntityType(EntityTypes::x, #x, x##EntityItem::factory);
137 
138 
139 struct EntityRegistrationChecker {
140  EntityRegistrationChecker(bool result, const char* debugMessage) {
141  if (!result) {
142  qCDebug(entities) << debugMessage;
143  }
144  }
145 };
146 
151 // static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
152 #define REGISTER_ENTITY_TYPE_WITH_FACTORY(x,y) static bool x##Registration = \
153  EntityTypes::registerEntityType(EntityTypes::x, #x, y); \
154  EntityRegistrationChecker x##RegistrationChecker( \
155  x##Registration, \
156  "UNEXPECTED: REGISTER_ENTITY_TYPE_WITH_FACTORY(" #x "," #y ") FAILED.!");
157 
158 
159 #endif // hifi_EntityTypes_h
Definition: EntityItem.h:82
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28
Definition: EntityItemProperties.h:106
A generic 3D model displaying geometry loaded from a URL.
Definition: Model.h:84
@ Unknown
Socket type unknown or not set.