History

more model naming cleanup and fixing example scripts

ZappoMan committed 12 years ago

Commit 3e140101 parent 5b8be784 files · +39 −38Browse files

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

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+23−24
@@ -1,6 +1,6 @@
1//1//
2// EntityScriptingInterface.cpp2// EntityScriptingInterface.cpp
3// libraries/models/src3// libraries/entities/src
4//4//
5// Created by Brad Hefta-Gaub on 12/6/13.5// Created by Brad Hefta-Gaub on 12/6/13.
6// Copyright 2013 High Fidelity, Inc.6// Copyright 2013 High Fidelity, Inc.
@@ -19,7 +19,6 @@ EntityScriptingInterface::EntityScriptingInterface() : · 12 unmodified lines
19{19{
20}20}
21 21
22
23void EntityScriptingInterface::queueEntityMessage(PacketType packetType,22void EntityScriptingInterface::queueEntityMessage(PacketType packetType,
24 EntityItemID entityID, const EntityItemProperties& properties) {23 EntityItemID entityID, const EntityItemProperties& properties) {
25 getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties);24 getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties);
@@ -35,7 +34,7 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro · 9 unmodified lines
35 // queue the packet34 // queue the packet
36 queueEntityMessage(PacketTypeEntityAddOrEdit, id, properties);35 queueEntityMessage(PacketTypeEntityAddOrEdit, id, properties);
37 36
38 // If we have a local model tree set, then also update it.37 // If we have a local entity tree set, then also update it.
39 if (_entityTree) {38 if (_entityTree) {
40 _entityTree->lockForWrite();39 _entityTree->lockForWrite();
41 _entityTree->addEntity(id, properties);40 _entityTree->addEntity(id, properties);
@@ -93,20 +92,20 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID · 51 unmodified lines
93EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) {92EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) {
94 EntityItemID actualID = entityID;93 EntityItemID actualID = entityID;
95 94
96 // if the model is unknown, attempt to look it up95 // if the entity is unknown, attempt to look it up
97 if (!entityID.isKnownID) {96 if (!entityID.isKnownID) {
98 actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID);97 actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID);
99 }98 }
100 99
101 // if at this point, we know the id, send the update to the model server100 // if at this point, we know the id, send the update to the entity server
102 if (actualID.id != UNKNOWN_ENTITY_ID) {101 if (actualID.id != UNKNOWN_ENTITY_ID) {
103 entityID.id = actualID.id;102 entityID.id = actualID.id;
104 entityID.isKnownID = true;103 entityID.isKnownID = true;
105 queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties);104 queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties);
106 }105 }
107 106
108 // If we have a local model tree set, then also update it. We can do this even if we don't know107 // If we have a local entity tree set, then also update it. We can do this even if we don't know
109 // the actual id, because we can edit out local models just with creatorTokenID108 // the actual id, because we can edit out local entities just with creatorTokenID
110 if (_entityTree) {109 if (_entityTree) {
111 _entityTree->lockForWrite();110 _entityTree->lockForWrite();
112 _entityTree->updateEntity(entityID, properties);111 _entityTree->updateEntity(entityID, properties);
@@ -119,19 +118,19 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { · 6 unmodified lines
119 118
120 EntityItemID actualID = entityID;119 EntityItemID actualID = entityID;
121 120
122 // if the model is unknown, attempt to look it up121 // if the entity is unknown, attempt to look it up
123 if (!entityID.isKnownID) {122 if (!entityID.isKnownID) {
124 actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID);123 actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID);
125 }124 }
126 125
127 // if at this point, we know the id, send the update to the model server126 // if at this point, we know the id, send the update to the entity server
128 if (actualID.id != UNKNOWN_ENTITY_ID) {127 if (actualID.id != UNKNOWN_ENTITY_ID) {
129 entityID.id = actualID.id;128 entityID.id = actualID.id;
130 entityID.isKnownID = true;129 entityID.isKnownID = true;
131 getEntityPacketSender()->queueEraseEntityMessage(entityID);130 getEntityPacketSender()->queueEraseEntityMessage(entityID);
132 }131 }
133 132
134 // If we have a local model tree set, then also update it.133 // If we have a local entity tree set, then also update it.
135 if (_entityTree) {134 if (_entityTree) {
136 _entityTree->lockForWrite();135 _entityTree->lockForWrite();
137 _entityTree->deleteEntity(entityID);136 _entityTree->deleteEntity(entityID);
@@ -167,12 +166,12 @@ QVector<EntityItemID> EntityScriptingInterface::findEntities(const glm::vec3& ce · 29 unmodified lines
167 QVector<EntityItemID> result;166 QVector<EntityItemID> result;
168 if (_entityTree) {167 if (_entityTree) {
169 _entityTree->lockForRead();168 _entityTree->lockForRead();
170 QVector<const EntityItem*> models;169 QVector<const EntityItem*> entities;
171 _entityTree->findEntities(center/(float)TREE_SCALE, radius/(float)TREE_SCALE, models);170 _entityTree->findEntities(center/(float)TREE_SCALE, radius/(float)TREE_SCALE, entities);
172 _entityTree->unlock();171 _entityTree->unlock();
173 172
174 foreach (const EntityItem* model, models) {173 foreach (const EntityItem* entity, entities) {
175 EntityItemID thisEntityItemID(model->getID(), UNKNOWN_ENTITY_TOKEN, true);174 EntityItemID thisEntityItemID(entity->getID(), UNKNOWN_ENTITY_TOKEN, true);
176 result << thisEntityItemID;175 result << thisEntityItemID;
177 }176 }
178 }177 }
@@ -219,11 +218,11 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c · 40 unmodified lines
219 QScriptValue obj = engine->newObject();218 QScriptValue obj = engine->newObject();
220 obj.setProperty("intersects", value.intersects);219 obj.setProperty("intersects", value.intersects);
221 obj.setProperty("accurate", value.accurate);220 obj.setProperty("accurate", value.accurate);
222 QScriptValue modelItemValue = EntityItemIDtoScriptValue(engine, value.entityID);221 QScriptValue entityItemValue = EntityItemIDtoScriptValue(engine, value.entityID);
223 obj.setProperty("entityID", modelItemValue);222 obj.setProperty("entityID", entityItemValue);
224 223
225 QScriptValue modelPropertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties);224 QScriptValue propertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties);
226 obj.setProperty("properties", modelPropertiesValue);225 obj.setProperty("properties", propertiesValue);
227 226
228 obj.setProperty("distance", value.distance);227 obj.setProperty("distance", value.distance);
229 228
@@ -262,13 +261,13 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c · 32 unmodified lines
262void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, RayToEntityIntersectionResult& value) {261void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, RayToEntityIntersectionResult& value) {
263 value.intersects = object.property("intersects").toVariant().toBool();262 value.intersects = object.property("intersects").toVariant().toBool();
264 value.accurate = object.property("accurate").toVariant().toBool();263 value.accurate = object.property("accurate").toVariant().toBool();
265 QScriptValue modelIDValue = object.property("entityID");264 QScriptValue entityIDValue = object.property("entityID");
266 if (modelIDValue.isValid()) {265 if (entityIDValue.isValid()) {
267 EntityItemIDfromScriptValue(modelIDValue, value.entityID);266 EntityItemIDfromScriptValue(entityIDValue, value.entityID);
268 }267 }
269 QScriptValue modelPropertiesValue = object.property("properties");268 QScriptValue entityPropertiesValue = object.property("properties");
270 if (modelPropertiesValue.isValid()) {269 if (entityPropertiesValue.isValid()) {
271 EntityItemPropertiesFromScriptValue(modelPropertiesValue, value.properties);270 EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties);
272 }271 }
273 value.distance = object.property("distance").toVariant().toFloat();272 value.distance = object.property("distance").toVariant().toFloat();
274 273