mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 16:55:07 +02:00
Bug fixes and debt reductions on energy calculations.
- removed superfluous code interfacing with scripts - favor floats over doubles in cost calculations - default avatar energy is maximum float value for cases where energy script is not loaded in order to still manipulate entities.
This commit is contained in:
parent
47f7d55e2c
commit
7dd5bca17f
3 changed files with 4 additions and 14 deletions
|
@ -56,11 +56,7 @@ function energyChanged(newValue) {
|
|||
function debitAvatarEnergy(value) {
|
||||
MyAvatar.energy = MyAvatar.energy - value;
|
||||
}
|
||||
function calculateCost(mass, oldVelocity, newVelocity) {
|
||||
return mass * (newVelocity - oldVelocity);
|
||||
}
|
||||
|
||||
Entities.addCostFunction(calculateCost);
|
||||
Entities.debitEnergySource.connect(debitAvatarEnergy);
|
||||
MyAvatar.energyChanged.connect(energyChanged);
|
||||
Script.update.connect(update);
|
||||
|
|
|
@ -1037,11 +1037,7 @@ QStringList EntityScriptingInterface::getJointNames(const QUuid& entityID) {
|
|||
return result;
|
||||
}
|
||||
|
||||
void EntityScriptingInterface::addCostFunction(QScriptValue costFunction) {
|
||||
_costFunction = &costFunction;
|
||||
}
|
||||
|
||||
double EntityScriptingInterface::calculateCost(float mass, float oldVelocity,float newVelocity) {
|
||||
float EntityScriptingInterface::calculateCost(float mass, float oldVelocity,float newVelocity) {
|
||||
return std::abs(mass * (newVelocity - oldVelocity));
|
||||
}
|
||||
|
||||
|
|
|
@ -71,8 +71,7 @@ public:
|
|||
void setEntityTree(EntityTreePointer modelTree);
|
||||
EntityTreePointer getEntityTree() { return _entityTree; }
|
||||
void setEntitiesScriptEngine(EntitiesScriptEngineProvider* engine) { _entitiesScriptEngine = engine; }
|
||||
double calculateCost(float mass, float oldVelocity, float newVelocity);
|
||||
Q_INVOKABLE void addCostFunction(QScriptValue costFunction);
|
||||
float calculateCost(float mass, float oldVelocity, float newVelocity);
|
||||
public slots:
|
||||
|
||||
// returns true if the DomainServer will allow this Node/Avatar to make changes
|
||||
|
@ -194,7 +193,7 @@ signals:
|
|||
void deletingEntity(const EntityItemID& entityID);
|
||||
void addingEntity(const EntityItemID& entityID);
|
||||
void clearingEntities();
|
||||
void debitEnergySource(double value);
|
||||
void debitEnergySource(float value);
|
||||
|
||||
private:
|
||||
bool actionWorker(const QUuid& entityID, std::function<bool(EntitySimulation*, EntityItemPointer)> actor);
|
||||
|
@ -212,8 +211,7 @@ private:
|
|||
|
||||
EntityTreePointer _entityTree;
|
||||
EntitiesScriptEngineProvider* _entitiesScriptEngine = nullptr;
|
||||
QScriptValue* _costFunction = nullptr;
|
||||
float _currentAvatarEnergy;
|
||||
float _currentAvatarEnergy = { FLT_MAX };
|
||||
float getCurrentAvatarEnergy() { return _currentAvatarEnergy; }
|
||||
void setCurrentAvatarEnergy(float energy);
|
||||
float ENTITY_MANIPULATION_MULTIPLIER = { 0.01f };
|
||||
|
|
Loading…
Reference in a new issue