History

Consider existing velocity in calculating energy costs when editing entities.

Babiuch, Ryan Nicholas committed 10 years ago

Commit 00698491 parent dca7ff91 file · +28 −12Browse files

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

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+28−12
@@ -126,7 +126,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 125 unmodified lines
126126 float volume = dimensions.x * dimensions.y * dimensions.z;
127127 auto density = propertiesWithSimID.getDensity();
128128 auto newVelocity = propertiesWithSimID.getVelocity().length();
129− double cost = calculateCost(density * volume, 0, newVelocity);
129+ float cost = calculateCost(density * volume, 0, newVelocity);
130130 cost *= costMultiplier;
131131
132132 if(cost > _currentAvatarEnergy) {
@@ -136,7 +136,6 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 3 unmodified lines
136136 emit debitEnergySource(cost);
137137 }
138138
139−
140139 EntityItemID id = EntityItemID(QUuid::createUuid());
141140
142141 // 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
234233 float volume = dimensions.x * dimensions.y * dimensions.z;
235234 auto density = properties.getDensity();
236235 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 };
246237
247238 EntityItemID entityID(id);
248239 if (!_entityTree) {
249240 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+
250253 return id;
251254 }
252255 // 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
260263 if (!entity) {
261264 return;
262265 }
266+ //existing entity, retrieve old velocity for check down below
267+ oldVelocity = entity->getVelocity().length();
268+
263269 if (!scriptSideProperties.parentIDChanged()) {
264270 properties.setParentID(entity->getParentID());
265271 }
@@ -275,6 +281,16 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 9 unmodified lines
275281 }
276282 properties = convertLocationFromScriptSemantics(properties);
277283 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+ }
278294 });
279295
280296 if (!updatedEntity) {
@@ -354,7 +370,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) { · 73 unmodified lines
354370 float volume = dimensions.x * dimensions.y * dimensions.z;
355371 auto density = entity->getDensity();
356372 auto velocity = entity->getVelocity().length();
357− double cost = calculateCost(density * volume, velocity, 0);
373+ float cost = calculateCost(density * volume, velocity, 0);
358374 cost *= costMultiplier;
359375
360376 if(cost > _currentAvatarEnergy) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t