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 | float volume = dimensions.x * dimensions.y * dimensions.z; | 126 | float volume = dimensions.x * dimensions.y * dimensions.z; |
| 127 | auto density = propertiesWithSimID.getDensity(); | 127 | auto density = propertiesWithSimID.getDensity(); |
| 128 | auto newVelocity = propertiesWithSimID.getVelocity().length(); | 128 | auto newVelocity = propertiesWithSimID.getVelocity().length(); |
| 129 | double cost = calculateCost(density * volume, 0, newVelocity); | 129 | float cost = calculateCost(density * volume, 0, newVelocity); |
| 130 | cost *= costMultiplier; | 130 | cost *= costMultiplier; |
| 131 | 131 | ||
| 132 | if(cost > _currentAvatarEnergy) { | 132 | if(cost > _currentAvatarEnergy) { |
| @@ -136,7 +136,6 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 3 unmodified lines | |||
| 136 | emit debitEnergySource(cost); | 136 | emit debitEnergySource(cost); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | |||
| 140 | EntityItemID id = EntityItemID(QUuid::createUuid()); | 139 | EntityItemID id = EntityItemID(QUuid::createUuid()); |
| 141 | 140 | ||
| 142 | // If we have a local entity tree set, then also update it. | 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 | float volume = dimensions.x * dimensions.y * dimensions.z; | 233 | float volume = dimensions.x * dimensions.y * dimensions.z; |
| 235 | auto density = properties.getDensity(); | 234 | auto density = properties.getDensity(); |
| 236 | auto newVelocity = properties.getVelocity().length(); | 235 | auto newVelocity = properties.getVelocity().length(); |
| 237 | double cost = calculateCost(density * volume, 0, newVelocity); | 236 | float oldVelocity = { 0.0f }; |
| 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 | } | ||
| 246 | 237 | ||
| 247 | EntityItemID entityID(id); | 238 | EntityItemID entityID(id); |
| 248 | if (!_entityTree) { | 239 | if (!_entityTree) { |
| 249 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); | 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 | return id; | 253 | return id; |
| 251 | } | 254 | } |
| 252 | // If we have a local entity tree set, then also update it. | 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 | if (!entity) { | 263 | if (!entity) { |
| 261 | return; | 264 | return; |
| 262 | } | 265 | } |
| 266 | //existing entity, retrieve old velocity for check down below | ||
| 267 | oldVelocity = entity->getVelocity().length(); | ||
| 268 | |||
| 263 | if (!scriptSideProperties.parentIDChanged()) { | 269 | if (!scriptSideProperties.parentIDChanged()) { |
| 264 | properties.setParentID(entity->getParentID()); | 270 | properties.setParentID(entity->getParentID()); |
| 265 | } | 271 | } |
| @@ -275,6 +281,16 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 9 unmodified lines | |||
| 275 | } | 281 | } |
| 276 | properties = convertLocationFromScriptSemantics(properties); | 282 | properties = convertLocationFromScriptSemantics(properties); |
| 277 | updatedEntity = _entityTree->updateEntity(entityID, properties); | 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 | if (!updatedEntity) { | 296 | if (!updatedEntity) { |
| @@ -354,7 +370,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { · 73 unmodified lines | |||
| 354 | float volume = dimensions.x * dimensions.y * dimensions.z; | 370 | float volume = dimensions.x * dimensions.y * dimensions.z; |
| 355 | auto density = entity->getDensity(); | 371 | auto density = entity->getDensity(); |
| 356 | auto velocity = entity->getVelocity().length(); | 372 | auto velocity = entity->getVelocity().length(); |
| 357 | double cost = calculateCost(density * volume, velocity, 0); | 373 | float cost = calculateCost(density * volume, velocity, 0); |
| 358 | cost *= costMultiplier; | 374 | cost *= costMultiplier; |
| 359 | 375 | ||
| 360 | if(cost > _currentAvatarEnergy) { | 376 | if(cost > _currentAvatarEnergy) { |