History

EnitityItem smart pointers

ZappoMan committed 11 years ago

Commit 8b78fc41 parent 603528e69 files · +354 −302Browse files

Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 69 files). Show all

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+13−10
@@ -78,7 +78,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 77 unmodified lines
78 bool success = true;78 bool success = true;
79 if (_entityTree) {79 if (_entityTree) {
80 _entityTree->lockForWrite();80 _entityTree->lockForWrite();
81 EntityItem* entity = _entityTree->addEntity(id, propertiesWithSimID);81 EntityItemPointer entity = _entityTree->addEntity(id, propertiesWithSimID);
82 if (entity) {82 if (entity) {
83 entity->setLastBroadcast(usecTimestampNow());83 entity->setLastBroadcast(usecTimestampNow());
84 // This Node is creating a new object. If it's in motion, set this Node as the simulator.84 // This Node is creating a new object. If it's in motion, set this Node as the simulator.
@@ -102,7 +102,9 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 17 unmodified lines
102 EntityItemProperties results;102 EntityItemProperties results;
103 if (_entityTree) {103 if (_entityTree) {
104 _entityTree->lockForRead();104 _entityTree->lockForRead();
105 EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(EntityItemID(identity)));105
106 // FIX ME!!
107 EntityItemPointer entity = nullptr; // const_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(EntityItemID(identity)));
106 108
107 if (entity) {109 if (entity) {
108 results = entity->getProperties();110 results = entity->getProperties();
@@ -137,7 +139,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 28 unmodified lines
137 139
138 // make sure the properties has a type, so that the encode can know which properties to include140 // make sure the properties has a type, so that the encode can know which properties to include
139 if (properties.getType() == EntityTypes::Unknown) {141 if (properties.getType() == EntityTypes::Unknown) {
140 EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID);142 EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
141 if (entity) {143 if (entity) {
142 // we need to change the outgoing properties, so we make a copy, modify, and send.144 // we need to change the outgoing properties, so we make a copy, modify, and send.
143 EntityItemProperties modifiedProperties = properties;145 EntityItemProperties modifiedProperties = properties;
@@ -161,7 +163,8 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { · 17 unmodified lines
161 if (_entityTree) {163 if (_entityTree) {
162 _entityTree->lockForWrite();164 _entityTree->lockForWrite();
163 165
164 EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(entityID));166 // FIX ME!!
167 EntityItemPointer entity = nullptr; // const_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
165 if (entity) {168 if (entity) {
166 if (entity->getLocked()) {169 if (entity->getLocked()) {
167 shouldDelete = false;170 shouldDelete = false;
@@ -183,7 +186,7 @@ QUuid EntityScriptingInterface::findClosestEntity(const glm::vec3& center, float · 15 unmodified lines
183 EntityItemID result; 186 EntityItemID result;
184 if (_entityTree) {187 if (_entityTree) {
185 _entityTree->lockForRead();188 _entityTree->lockForRead();
186 const EntityItem* closestEntity = _entityTree->findClosestEntity(center, radius);189 EntityItemPointer closestEntity = _entityTree->findClosestEntity(center, radius);
187 _entityTree->unlock();190 _entityTree->unlock();
188 if (closestEntity) {191 if (closestEntity) {
189 result = closestEntity->getEntityItemID();192 result = closestEntity->getEntityItemID();
@@ -205,11 +208,11 @@ QVector<QUuid> EntityScriptingInterface::findEntities(const glm::vec3& center, f · 15 unmodified lines
205 QVector<QUuid> result;208 QVector<QUuid> result;
206 if (_entityTree) {209 if (_entityTree) {
207 _entityTree->lockForRead();210 _entityTree->lockForRead();
208 QVector<const EntityItem*> entities;211 QVector<EntityItemPointer> entities;
209 _entityTree->findEntities(center, radius, entities);212 _entityTree->findEntities(center, radius, entities);
210 _entityTree->unlock();213 _entityTree->unlock();
211 214
212 foreach (const EntityItem* entity, entities) {215 foreach (EntityItemPointer entity, entities) {
213 result << entity->getEntityItemID();216 result << entity->getEntityItemID();
214 }217 }
215 }218 }
@@ -221,11 +224,11 @@ QVector<QUuid> EntityScriptingInterface::findEntitiesInBox(const glm::vec3& corn · 5 unmodified lines
221 if (_entityTree) {224 if (_entityTree) {
222 _entityTree->lockForRead();225 _entityTree->lockForRead();
223 AABox box(corner, dimensions);226 AABox box(corner, dimensions);
224 QVector<EntityItem*> entities;227 QVector<EntityItemPointer> entities;
225 _entityTree->findEntities(box, entities);228 _entityTree->findEntities(box, entities);
226 _entityTree->unlock();229 _entityTree->unlock();
227 230
228 foreach (const EntityItem* entity, entities) {231 foreach (EntityItemPointer entity, entities) {
229 result << entity->getEntityItemID();232 result << entity->getEntityItemID();
230 }233 }
231 }234 }
@@ -248,7 +251,7 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke · 16 unmodified lines
248 RayToEntityIntersectionResult result;251 RayToEntityIntersectionResult result;
249 if (_entityTree) {252 if (_entityTree) {
250 OctreeElement* element;253 OctreeElement* element;
251 EntityItem* intersectedEntity = NULL;254 EntityItemPointer intersectedEntity = NULL;
252 result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face, 255 result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face,
253 (void**)&intersectedEntity, lockType, &result.accurate, 256 (void**)&intersectedEntity, lockType, &result.accurate,
254 precisionPicking);257 precisionPicking);