mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 11:07:07 +02:00
Merge branch 'WorkingEnergy'
This commit is contained in:
commit
786400eb53
3 changed files with 21 additions and 19 deletions
|
@ -56,11 +56,7 @@ function energyChanged(newValue) {
|
||||||
function debitAvatarEnergy(value) {
|
function debitAvatarEnergy(value) {
|
||||||
MyAvatar.energy = MyAvatar.energy - value;
|
MyAvatar.energy = MyAvatar.energy - value;
|
||||||
}
|
}
|
||||||
function calculateCost(mass, oldVelocity, newVelocity) {
|
Entities.costMultiplier = 0.002;
|
||||||
return mass * (newVelocity - oldVelocity);
|
|
||||||
}
|
|
||||||
|
|
||||||
Entities.addCostFunction(calculateCost);
|
|
||||||
Entities.debitEnergySource.connect(debitAvatarEnergy);
|
Entities.debitEnergySource.connect(debitAvatarEnergy);
|
||||||
MyAvatar.energyChanged.connect(energyChanged);
|
MyAvatar.energyChanged.connect(energyChanged);
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
|
|
|
@ -126,7 +126,7 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties
|
||||||
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);
|
double cost = calculateCost(density*volume, 0, newVelocity);
|
||||||
cost *= ENTITY_MANIPULATION_MULTIPLIER; //try this as a constant for now
|
cost *= costMultiplier;
|
||||||
|
|
||||||
if(cost > _currentAvatarEnergy) {
|
if(cost > _currentAvatarEnergy) {
|
||||||
return QUuid();
|
return QUuid();
|
||||||
|
@ -231,7 +231,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
|
||||||
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);
|
double cost = calculateCost(density*volume, 0, newVelocity);
|
||||||
cost *= ENTITY_MANIPULATION_MULTIPLIER;
|
cost *= costMultiplier;
|
||||||
|
|
||||||
if(cost > _currentAvatarEnergy) {
|
if(cost > _currentAvatarEnergy) {
|
||||||
return QUuid();
|
return QUuid();
|
||||||
|
@ -351,7 +351,7 @@ void EntityScriptingInterface::deleteEntity(QUuid id) {
|
||||||
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);
|
double cost = calculateCost(density*volume, velocity, 0);
|
||||||
cost *= ENTITY_MANIPULATION_MULTIPLIER;
|
cost *= costMultiplier;
|
||||||
|
|
||||||
if(cost > _currentAvatarEnergy) {
|
if(cost > _currentAvatarEnergy) {
|
||||||
return;
|
return;
|
||||||
|
@ -1037,11 +1037,7 @@ QStringList EntityScriptingInterface::getJointNames(const QUuid& entityID) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityScriptingInterface::addCostFunction(QScriptValue costFunction) {
|
float EntityScriptingInterface::calculateCost(float mass, float oldVelocity,float newVelocity) {
|
||||||
_costFunction = &costFunction;
|
|
||||||
}
|
|
||||||
|
|
||||||
double EntityScriptingInterface::calculateCost(float mass, float oldVelocity,float newVelocity) {
|
|
||||||
return std::abs(mass * (newVelocity - oldVelocity));
|
return std::abs(mass * (newVelocity - oldVelocity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1049,3 +1045,11 @@ void EntityScriptingInterface::setCurrentAvatarEnergy(float energy) {
|
||||||
// qCDebug(entities) << "NEW AVATAR ENERGY IN ENTITY SCRIPTING INTERFACE: " << energy;
|
// qCDebug(entities) << "NEW AVATAR ENERGY IN ENTITY SCRIPTING INTERFACE: " << energy;
|
||||||
_currentAvatarEnergy = energy;
|
_currentAvatarEnergy = energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float EntityScriptingInterface::getCostMultiplier() {
|
||||||
|
return costMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityScriptingInterface::setCostMultiplier(float value) {
|
||||||
|
costMultiplier = value;
|
||||||
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ class EntityScriptingInterface : public OctreeScriptingInterface, public Depende
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(float currentAvatarEnergy READ getCurrentAvatarEnergy WRITE setCurrentAvatarEnergy)
|
Q_PROPERTY(float currentAvatarEnergy READ getCurrentAvatarEnergy WRITE setCurrentAvatarEnergy)
|
||||||
|
Q_PROPERTY(float costMultiplier READ getCostMultiplier WRITE setCostMultiplier)
|
||||||
public:
|
public:
|
||||||
EntityScriptingInterface();
|
EntityScriptingInterface();
|
||||||
|
|
||||||
|
@ -71,8 +72,7 @@ public:
|
||||||
void setEntityTree(EntityTreePointer modelTree);
|
void setEntityTree(EntityTreePointer modelTree);
|
||||||
EntityTreePointer getEntityTree() { return _entityTree; }
|
EntityTreePointer getEntityTree() { return _entityTree; }
|
||||||
void setEntitiesScriptEngine(EntitiesScriptEngineProvider* engine) { _entitiesScriptEngine = engine; }
|
void setEntitiesScriptEngine(EntitiesScriptEngineProvider* engine) { _entitiesScriptEngine = engine; }
|
||||||
double calculateCost(float mass, float oldVelocity, float newVelocity);
|
float calculateCost(float mass, float oldVelocity, float newVelocity);
|
||||||
Q_INVOKABLE void addCostFunction(QScriptValue costFunction);
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
// returns true if the DomainServer will allow this Node/Avatar to make changes
|
// returns true if the DomainServer will allow this Node/Avatar to make changes
|
||||||
|
@ -194,7 +194,7 @@ signals:
|
||||||
void deletingEntity(const EntityItemID& entityID);
|
void deletingEntity(const EntityItemID& entityID);
|
||||||
void addingEntity(const EntityItemID& entityID);
|
void addingEntity(const EntityItemID& entityID);
|
||||||
void clearingEntities();
|
void clearingEntities();
|
||||||
void debitEnergySource(double value);
|
void debitEnergySource(float value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool actionWorker(const QUuid& entityID, std::function<bool(EntitySimulation*, EntityItemPointer)> actor);
|
bool actionWorker(const QUuid& entityID, std::function<bool(EntitySimulation*, EntityItemPointer)> actor);
|
||||||
|
@ -212,11 +212,13 @@ private:
|
||||||
|
|
||||||
EntityTreePointer _entityTree;
|
EntityTreePointer _entityTree;
|
||||||
EntitiesScriptEngineProvider* _entitiesScriptEngine = nullptr;
|
EntitiesScriptEngineProvider* _entitiesScriptEngine = nullptr;
|
||||||
QScriptValue* _costFunction = nullptr;
|
float _currentAvatarEnergy = { FLT_MAX };
|
||||||
float _currentAvatarEnergy;
|
|
||||||
float getCurrentAvatarEnergy() { return _currentAvatarEnergy; }
|
float getCurrentAvatarEnergy() { return _currentAvatarEnergy; }
|
||||||
void setCurrentAvatarEnergy(float energy);
|
void setCurrentAvatarEnergy(float energy);
|
||||||
float ENTITY_MANIPULATION_MULTIPLIER = { 0.01f };
|
|
||||||
|
float costMultiplier = { 0.01f };
|
||||||
|
float getCostMultiplier();
|
||||||
|
void setCostMultiplier(float value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_EntityScriptingInterface_h
|
#endif // hifi_EntityScriptingInterface_h
|
||||||
|
|
Loading…
Reference in a new issue