mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 10:17:40 +02:00
Consider existing velocity in calculating energy costs when editing entities.
This commit is contained in:
parent
dca7ff967c
commit
0069849da3
1 changed files with 28 additions and 12 deletions
|
@ -126,7 +126,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
|
||||||
float volume = dimensions.x * dimensions.y * dimensions.z;
|
float volume = dimensions.x * dimensions.y * dimensions.z;
|
||||||
auto density = propertiesWithSimID.getDensity();
|
auto density = propertiesWithSimID.getDensity();
|
||||||
auto newVelocity = propertiesWithSimID.getVelocity().length();
|
auto newVelocity = propertiesWithSimID.getVelocity().length();
|
||||||
double cost = calculateCost(density * volume, 0, newVelocity);
|
float cost = calculateCost(density * volume, 0, newVelocity);
|
||||||
cost *= costMultiplier;
|
cost *= costMultiplier;
|
||||||
|
|
||||||
if(cost > _currentAvatarEnergy) {
|
if(cost > _currentAvatarEnergy) {
|
||||||
|
@ -136,7 +136,6 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
|
||||||
emit debitEnergySource(cost);
|
emit debitEnergySource(cost);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EntityItemID id = EntityItemID(QUuid::createUuid());
|
EntityItemID id = EntityItemID(QUuid::createUuid());
|
||||||
|
|
||||||
// If we have a local entity tree set, then also update it.
|
// If we have a local entity tree set, then also update it.
|
||||||
|
@ -234,19 +233,23 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
|
||||||
float volume = dimensions.x * dimensions.y * dimensions.z;
|
float volume = dimensions.x * dimensions.y * dimensions.z;
|
||||||
auto density = properties.getDensity();
|
auto density = properties.getDensity();
|
||||||
auto newVelocity = properties.getVelocity().length();
|
auto newVelocity = properties.getVelocity().length();
|
||||||
double cost = calculateCost(density * volume, 0, newVelocity);
|
float oldVelocity = { 0.0f };
|
||||||
cost *= costMultiplier;
|
|
||||||
|
|
||||||
if(cost > _currentAvatarEnergy) {
|
|
||||||
return QUuid();
|
|
||||||
} else {
|
|
||||||
//debit the avatar energy and continue
|
|
||||||
emit debitEnergySource(cost);
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityItemID entityID(id);
|
EntityItemID entityID(id);
|
||||||
if (!_entityTree) {
|
if (!_entityTree) {
|
||||||
queueEntityMessage(PacketType::EntityEdit, entityID, properties);
|
queueEntityMessage(PacketType::EntityEdit, entityID, properties);
|
||||||
|
|
||||||
|
//if there is no local entity entity tree, no existing velocity, use 0.
|
||||||
|
float cost = calculateCost(density * volume, oldVelocity, newVelocity);
|
||||||
|
cost *= costMultiplier;
|
||||||
|
|
||||||
|
if(cost > _currentAvatarEnergy) {
|
||||||
|
return QUuid();
|
||||||
|
} else {
|
||||||
|
//debit the avatar energy and continue
|
||||||
|
emit debitEnergySource(cost);
|
||||||
|
}
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
// If we have a local entity tree set, then also update it.
|
// If we have a local entity tree set, then also update it.
|
||||||
|
@ -260,6 +263,9 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//existing entity, retrieve old velocity for check down below
|
||||||
|
oldVelocity = entity->getVelocity().length();
|
||||||
|
|
||||||
if (!scriptSideProperties.parentIDChanged()) {
|
if (!scriptSideProperties.parentIDChanged()) {
|
||||||
properties.setParentID(entity->getParentID());
|
properties.setParentID(entity->getParentID());
|
||||||
}
|
}
|
||||||
|
@ -275,6 +281,16 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
|
||||||
}
|
}
|
||||||
properties = convertLocationFromScriptSemantics(properties);
|
properties = convertLocationFromScriptSemantics(properties);
|
||||||
updatedEntity = _entityTree->updateEntity(entityID, properties);
|
updatedEntity = _entityTree->updateEntity(entityID, properties);
|
||||||
|
|
||||||
|
float cost = calculateCost(density * volume, oldVelocity, newVelocity);
|
||||||
|
cost *= costMultiplier;
|
||||||
|
|
||||||
|
if(cost > _currentAvatarEnergy) {
|
||||||
|
updatedEntity = false;
|
||||||
|
} else {
|
||||||
|
//debit the avatar energy and continue
|
||||||
|
emit debitEnergySource(cost);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!updatedEntity) {
|
if (!updatedEntity) {
|
||||||
|
@ -354,7 +370,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) {
|
||||||
float volume = dimensions.x * dimensions.y * dimensions.z;
|
float volume = dimensions.x * dimensions.y * dimensions.z;
|
||||||
auto density = entity->getDensity();
|
auto density = entity->getDensity();
|
||||||
auto velocity = entity->getVelocity().length();
|
auto velocity = entity->getVelocity().length();
|
||||||
double cost = calculateCost(density * volume, velocity, 0);
|
float cost = calculateCost(density * volume, velocity, 0);
|
||||||
cost *= costMultiplier;
|
cost *= costMultiplier;
|
||||||
|
|
||||||
if(cost > _currentAvatarEnergy) {
|
if(cost > _currentAvatarEnergy) {
|
||||||
|
|
Loading…
Reference in a new issue