mirror of
https://github.com/overte-org/overte.git
synced 2025-07-26 02:12:14 +02:00
adjust avatar-energy code to avoid editing local tree and then not telling the entity-server about it
This commit is contained in:
parent
784dc2b538
commit
af1640ac4e
1 changed files with 19 additions and 18 deletions
|
@ -133,11 +133,8 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
|
||||||
float cost = calculateCost(density * volume, 0, newVelocity);
|
float cost = calculateCost(density * volume, 0, newVelocity);
|
||||||
cost *= costMultiplier;
|
cost *= costMultiplier;
|
||||||
|
|
||||||
if(cost > _currentAvatarEnergy) {
|
if (cost > _currentAvatarEnergy) {
|
||||||
return QUuid();
|
return QUuid();
|
||||||
} else {
|
|
||||||
//debit the avatar energy and continue
|
|
||||||
emit debitEnergySource(cost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityItemID id = EntityItemID(QUuid::createUuid());
|
EntityItemID id = EntityItemID(QUuid::createUuid());
|
||||||
|
@ -173,6 +170,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
|
||||||
|
|
||||||
// queue the packet
|
// queue the packet
|
||||||
if (success) {
|
if (success) {
|
||||||
|
emit debitEnergySource(cost);
|
||||||
queueEntityMessage(PacketType::EntityAdd, id, propertiesWithSimID);
|
queueEntityMessage(PacketType::EntityAdd, id, propertiesWithSimID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +230,7 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit
|
||||||
|
|
||||||
QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& scriptSideProperties) {
|
QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& scriptSideProperties) {
|
||||||
EntityItemProperties properties = scriptSideProperties;
|
EntityItemProperties properties = scriptSideProperties;
|
||||||
|
|
||||||
auto dimensions = properties.getDimensions();
|
auto dimensions = properties.getDimensions();
|
||||||
float volume = dimensions.x * dimensions.y * dimensions.z;
|
float volume = dimensions.x * dimensions.y * dimensions.z;
|
||||||
auto density = properties.getDensity();
|
auto density = properties.getDensity();
|
||||||
|
@ -242,18 +240,18 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
|
||||||
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.
|
//if there is no local entity entity tree, no existing velocity, use 0.
|
||||||
float cost = calculateCost(density * volume, oldVelocity, newVelocity);
|
float cost = calculateCost(density * volume, oldVelocity, newVelocity);
|
||||||
cost *= costMultiplier;
|
cost *= costMultiplier;
|
||||||
|
|
||||||
if(cost > _currentAvatarEnergy) {
|
if (cost > _currentAvatarEnergy) {
|
||||||
return QUuid();
|
return QUuid();
|
||||||
} else {
|
} else {
|
||||||
//debit the avatar energy and continue
|
//debit the avatar energy and continue
|
||||||
emit debitEnergySource(cost);
|
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.
|
||||||
|
@ -268,8 +266,8 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//existing entity, retrieve old velocity for check down below
|
//existing entity, retrieve old velocity for check down below
|
||||||
oldVelocity = entity->getVelocity().length();
|
oldVelocity = entity->getVelocity().length();
|
||||||
|
|
||||||
if (!scriptSideProperties.parentIDChanged()) {
|
if (!scriptSideProperties.parentIDChanged()) {
|
||||||
properties.setParentID(entity->getParentID());
|
properties.setParentID(entity->getParentID());
|
||||||
}
|
}
|
||||||
|
@ -284,16 +282,18 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
properties = convertLocationFromScriptSemantics(properties);
|
properties = convertLocationFromScriptSemantics(properties);
|
||||||
updatedEntity = _entityTree->updateEntity(entityID, properties);
|
|
||||||
|
|
||||||
float cost = calculateCost(density * volume, oldVelocity, newVelocity);
|
float cost = calculateCost(density * volume, oldVelocity, newVelocity);
|
||||||
cost *= costMultiplier;
|
cost *= costMultiplier;
|
||||||
|
|
||||||
if(cost > _currentAvatarEnergy) {
|
if (cost > _currentAvatarEnergy) {
|
||||||
updatedEntity = false;
|
updatedEntity = false;
|
||||||
} else {
|
} else {
|
||||||
//debit the avatar energy and continue
|
//debit the avatar energy and continue
|
||||||
emit debitEnergySource(cost);
|
updatedEntity = _entityTree->updateEntity(entityID, properties);
|
||||||
|
if (updatedEntity) {
|
||||||
|
emit debitEnergySource(cost);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -370,15 +370,16 @@ void EntityScriptingInterface::deleteEntity(QUuid id) {
|
||||||
_entityTree->withWriteLock([&] {
|
_entityTree->withWriteLock([&] {
|
||||||
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
|
EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
|
||||||
if (entity) {
|
if (entity) {
|
||||||
|
|
||||||
auto dimensions = entity->getDimensions();
|
auto dimensions = entity->getDimensions();
|
||||||
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();
|
||||||
float cost = calculateCost(density * volume, velocity, 0);
|
float cost = calculateCost(density * volume, velocity, 0);
|
||||||
cost *= costMultiplier;
|
cost *= costMultiplier;
|
||||||
|
|
||||||
if(cost > _currentAvatarEnergy) {
|
if (cost > _currentAvatarEnergy) {
|
||||||
|
shouldDelete = false;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
//debit the avatar energy and continue
|
//debit the avatar energy and continue
|
||||||
|
|
Loading…
Reference in a new issue