History

Remove Entities.currentAvatarEnergy and related from the API

David Rowe committed 8 years ago

Commit 3b900781 parent a76b4b12 files · +2 −75Browse files

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

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+2−57
@@ -258,12 +258,6 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 257 unmodified lines
258 float volume = dimensions.x * dimensions.y * dimensions.z;258 float volume = dimensions.x * dimensions.y * dimensions.z;
259 auto density = propertiesWithSimID.getDensity();259 auto density = propertiesWithSimID.getDensity();
260 auto newVelocity = propertiesWithSimID.getVelocity().length();260 auto newVelocity = propertiesWithSimID.getVelocity().length();
261 float cost = calculateCost(density * volume, 0, newVelocity);
262 cost *= costMultiplier;
263
264 if (cost > _currentAvatarEnergy) {
265 return QUuid();
266 }
267 261
268 EntityItemID id = EntityItemID(QUuid::createUuid());262 EntityItemID id = EntityItemID(QUuid::createUuid());
269 263
@@ -295,9 +289,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 25 unmodified lines
295 289
296 // queue the packet290 // queue the packet
297 if (success) {291 if (success) {
298 emit debitEnergySource(cost);
299 queueEntityMessage(PacketType::EntityAdd, id, propertiesWithSimID);292 queueEntityMessage(PacketType::EntityAdd, id, propertiesWithSimID);
300
301 return id;293 return id;
302 } else {294 } else {
303 return QUuid();295 return QUuid();
@@ -387,18 +379,6 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 83 unmodified lines
387 EntityItemID entityID(id);379 EntityItemID entityID(id);
388 if (!_entityTree) {380 if (!_entityTree) {
389 queueEntityMessage(PacketType::EntityEdit, entityID, properties);381 queueEntityMessage(PacketType::EntityEdit, entityID, properties);
390
391 //if there is no local entity entity tree, no existing velocity, use 0.
392 float cost = calculateCost(density * volume, oldVelocity, newVelocity);
393 cost *= costMultiplier;
394
395 if (cost > _currentAvatarEnergy) {
396 return QUuid();
397 } else {
398 //debit the avatar energy and continue
399 emit debitEnergySource(cost);
400 }
401
402 return id;382 return id;
403 }383 }
404 // If we have a local entity tree set, then also update it.384 // If we have a local entity tree set, then also update it.
@@ -442,23 +422,11 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 37 unmodified lines
442 properties.setClientOnly(entity->getClientOnly());422 properties.setClientOnly(entity->getClientOnly());
443 properties.setOwningAvatarID(entity->getOwningAvatarID());423 properties.setOwningAvatarID(entity->getOwningAvatarID());
444 properties = convertPropertiesFromScriptSemantics(properties, properties.getScalesWithParent());424 properties = convertPropertiesFromScriptSemantics(properties, properties.getScalesWithParent());
445 425 updatedEntity = _entityTree->updateEntity(entityID, properties);
446 float cost = calculateCost(density * volume, oldVelocity, newVelocity);
447 cost *= costMultiplier;
448
449 if (cost > _currentAvatarEnergy) {
450 updatedEntity = false;
451 } else {
452 //debit the avatar energy and continue
453 updatedEntity = _entityTree->updateEntity(entityID, properties);
454 if (updatedEntity) {
455 emit debitEnergySource(cost);
456 }
457 }
458 });426 });
459 427
460 // FIXME: We need to figure out a better way to handle this. Allowing these edits to go through potentially428 // FIXME: We need to figure out a better way to handle this. Allowing these edits to go through potentially
461 // breaks avatar energy and entities that are parented.429 // breaks entities that are parented.
462 //430 //
463 // To handle cases where a script needs to edit an entity with a _known_ entity id but doesn't exist431 // To handle cases where a script needs to edit an entity with a _known_ entity id but doesn't exist
464 // in the local entity tree, we need to allow those edits to go through to the server.432 // in the local entity tree, we need to allow those edits to go through to the server.
@@ -581,16 +549,6 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { · 116 unmodified lines
581 float volume = dimensions.x * dimensions.y * dimensions.z;549 float volume = dimensions.x * dimensions.y * dimensions.z;
582 auto density = entity->getDensity();550 auto density = entity->getDensity();
583 auto velocity = entity->getWorldVelocity().length();551 auto velocity = entity->getWorldVelocity().length();
584 float cost = calculateCost(density * volume, velocity, 0);
585 cost *= costMultiplier;
586
587 if (cost > _currentAvatarEnergy) {
588 shouldDelete = false;
589 return;
590 } else {
591 //debit the avatar energy and continue
592 emit debitEnergySource(cost);
593 }
594 552
595 if (entity->getLocked()) {553 if (entity->getLocked()) {
596 shouldDelete = false;554 shouldDelete = false;
@@ -1816,19 +1774,6 @@ float EntityScriptingInterface::calculateCost(float mass, float oldVelocity, flo · 1219 unmodified lines
1816 return std::abs(mass * (newVelocity - oldVelocity));1774 return std::abs(mass * (newVelocity - oldVelocity));
1817}1775}
1818 1776
1819void EntityScriptingInterface::setCurrentAvatarEnergy(float energy) {
1820 // qCDebug(entities) << "NEW AVATAR ENERGY IN ENTITY SCRIPTING INTERFACE: " << energy;
1821 _currentAvatarEnergy = energy;
1822}
1823
1824float EntityScriptingInterface::getCostMultiplier() {
1825 return costMultiplier;
1826}
1827
1828void EntityScriptingInterface::setCostMultiplier(float value) {
1829 costMultiplier = value;
1830}
1831
1832// TODO move this someplace that makes more sense...1777// TODO move this someplace that makes more sense...
1833bool EntityScriptingInterface::AABoxIntersectsCapsule(const glm::vec3& low, const glm::vec3& dimensions,1778bool EntityScriptingInterface::AABoxIntersectsCapsule(const glm::vec3& low, const glm::vec3& dimensions,
1834 const glm::vec3& start, const glm::vec3& end, float radius) {1779 const glm::vec3& start, const glm::vec3& end, float radius) {