mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 19:42:53 +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) {
|
function debitAvatarEnergy(value) {
|
||||||
MyAvatar.energy = MyAvatar.energy - value;
|
MyAvatar.energy = MyAvatar.energy - value;
|
||||||
}
|
}
|
||||||
function calculateCost(mass, oldVelocity, newVelocity) {
|
|
||||||
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);
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,8 +71,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 +193,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,8 +211,7 @@ 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 ENTITY_MANIPULATION_MULTIPLIER = { 0.01f };
|
||||||
|
|
Loading…
Reference in a new issue