Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 1 file). Show all
Unified · Split
| @@ -126,7 +126,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 125 unmodified lines | ||
| 126 | 126 | float volume = dimensions.x * dimensions.y * dimensions.z; |
| 127 | 127 | auto density = propertiesWithSimID.getDensity(); |
| 128 | 128 | auto newVelocity = propertiesWithSimID.getVelocity().length(); |
| 129 | − double cost = calculateCost(density * volume, 0, newVelocity); | |
| 129 | + float cost = calculateCost(density * volume, 0, newVelocity); | |
| 130 | 130 | cost *= costMultiplier; |
| 131 | 131 | |
| 132 | 132 | if(cost > _currentAvatarEnergy) { |
| @@ -136,7 +136,6 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 3 unmodified lines | ||
| 136 | 136 | emit debitEnergySource(cost); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | − | |
| 140 | 139 | EntityItemID id = EntityItemID(QUuid::createUuid()); |
| 141 | 140 | |
| 142 | 141 | // If we have a local entity tree set, then also update it. |
| @@ -234,19 +233,23 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 91 unmodified lines | ||
| 234 | 233 | float volume = dimensions.x * dimensions.y * dimensions.z; |
| 235 | 234 | auto density = properties.getDensity(); |
| 236 | 235 | auto newVelocity = properties.getVelocity().length(); |
| 237 | − double cost = calculateCost(density * volume, 0, newVelocity); | |
| 238 | − cost *= costMultiplier; | |
| 239 | − | |
| 240 | − if(cost > _currentAvatarEnergy) { | |
| 241 | − return QUuid(); | |
| 242 | − } else { | |
| 243 | − //debit the avatar energy and continue | |
| 244 | − emit debitEnergySource(cost); | |
| 245 | − } | |
| 236 | + float oldVelocity = { 0.0f }; | |
| 246 | 237 | |
| 247 | 238 | EntityItemID entityID(id); |
| 248 | 239 | if (!_entityTree) { |
| 249 | 240 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); |
| 241 | + | |
| 242 | + //if there is no local entity entity tree, no existing velocity, use 0. | |
| 243 | + float cost = calculateCost(density * volume, oldVelocity, newVelocity); | |
| 244 | + cost *= costMultiplier; | |
| 245 | + | |
| 246 | + if(cost > _currentAvatarEnergy) { | |
| 247 | + return QUuid(); | |
| 248 | + } else { | |
| 249 | + //debit the avatar energy and continue | |
| 250 | + emit debitEnergySource(cost); | |
| 251 | + } | |
| 252 | + | |
| 250 | 253 | return id; |
| 251 | 254 | } |
| 252 | 255 | // If we have a local entity tree set, then also update it. |
| @@ -260,6 +263,9 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 7 unmodified lines | ||
| 260 | 263 | if (!entity) { |
| 261 | 264 | return; |
| 262 | 265 | } |
| 266 | + //existing entity, retrieve old velocity for check down below | |
| 267 | + oldVelocity = entity->getVelocity().length(); | |
| 268 | + | |
| 263 | 269 | if (!scriptSideProperties.parentIDChanged()) { |
| 264 | 270 | properties.setParentID(entity->getParentID()); |
| 265 | 271 | } |
| @@ -275,6 +281,16 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 9 unmodified lines | ||
| 275 | 281 | } |
| 276 | 282 | properties = convertLocationFromScriptSemantics(properties); |
| 277 | 283 | updatedEntity = _entityTree->updateEntity(entityID, properties); |
| 284 | + | |
| 285 | + float cost = calculateCost(density * volume, oldVelocity, newVelocity); | |
| 286 | + cost *= costMultiplier; | |
| 287 | + | |
| 288 | + if(cost > _currentAvatarEnergy) { | |
| 289 | + updatedEntity = false; | |
| 290 | + } else { | |
| 291 | + //debit the avatar energy and continue | |
| 292 | + emit debitEnergySource(cost); | |
| 293 | + } | |
| 278 | 294 | }); |
| 279 | 295 | |
| 280 | 296 | if (!updatedEntity) { |
| @@ -354,7 +370,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { · 73 unmodified lines | ||
| 354 | 370 | float volume = dimensions.x * dimensions.y * dimensions.z; |
| 355 | 371 | auto density = entity->getDensity(); |
| 356 | 372 | auto velocity = entity->getVelocity().length(); |
| 357 | − double cost = calculateCost(density * volume, velocity, 0); | |
| 373 | + float cost = calculateCost(density * volume, velocity, 0); | |
| 358 | 374 | cost *= costMultiplier; |
| 359 | 375 | |
| 360 | 376 | if(cost > _currentAvatarEnergy) { |