Exposed energy cost multiplier to scripting.

- field: costMultiplier
This commit is contained in:
Babiuch, Ryan Nicholas 2016-02-03 13:29:42 -06:00
parent 7dd5bca17f
commit 3cb2f9c4b7
3 changed files with 17 additions and 5 deletions

View file

@ -56,7 +56,7 @@ function energyChanged(newValue) {
function debitAvatarEnergy(value) {
MyAvatar.energy = MyAvatar.energy - value;
}
Entities.costMultiplier = 0.002;
Entities.debitEnergySource.connect(debitAvatarEnergy);
MyAvatar.energyChanged.connect(energyChanged);
Script.update.connect(update);

View file

@ -126,7 +126,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
auto density = propertiesWithSimID.getDensity();
auto newVelocity = propertiesWithSimID.getVelocity().length();
double cost = calculateCost(density*volume, 0, newVelocity);
cost *= ENTITY_MANIPULATION_MULTIPLIER; //try this as a constant for now
cost *= costMultiplier;
if(cost > _currentAvatarEnergy) {
return QUuid();
@ -231,7 +231,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
auto density = properties.getDensity();
auto newVelocity = properties.getVelocity().length();
double cost = calculateCost(density*volume, 0, newVelocity);
cost *= ENTITY_MANIPULATION_MULTIPLIER;
cost *= costMultiplier;
if(cost > _currentAvatarEnergy) {
return QUuid();
@ -351,7 +351,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) {
auto density = entity->getDensity();
auto velocity = entity->getVelocity().length();
double cost = calculateCost(density*volume, velocity, 0);
cost *= ENTITY_MANIPULATION_MULTIPLIER;
cost *= costMultiplier;
if(cost > _currentAvatarEnergy) {
return;
@ -1045,3 +1045,11 @@ void EntityScriptingInterface::setCurrentAvatarEnergy(float energy) {
// qCDebug(entities) << "NEW AVATAR ENERGY IN ENTITY SCRIPTING INTERFACE: " << energy;
_currentAvatarEnergy = energy;
}
float EntityScriptingInterface::getCostMultiplier() {
return costMultiplier;
}
void EntityScriptingInterface::setCostMultiplier(float value) {
costMultiplier = value;
}

View file

@ -61,6 +61,7 @@ class EntityScriptingInterface : public OctreeScriptingInterface, public Depende
Q_OBJECT
Q_PROPERTY(float currentAvatarEnergy READ getCurrentAvatarEnergy WRITE setCurrentAvatarEnergy)
Q_PROPERTY(float costMultiplier READ getCostMultiplier WRITE setCostMultiplier)
public:
EntityScriptingInterface();
@ -214,7 +215,10 @@ private:
float _currentAvatarEnergy = { FLT_MAX };
float getCurrentAvatarEnergy() { return _currentAvatarEnergy; }
void setCurrentAvatarEnergy(float energy);
float ENTITY_MANIPULATION_MULTIPLIER = { 0.01f };
float costMultiplier = { 0.01f };
float getCostMultiplier();
void setCostMultiplier(float value);
};
#endif // hifi_EntityScriptingInterface_h