Skip to content

Commit

Permalink
Update gdjs.RuntimeScene._updateObjects to apply forces as done in GDC++
Browse files Browse the repository at this point in the history
Could potentially change slightly the behavior of some game but it's now
consistent between GDJS and GDCpp.
This also avoid an extra iteration on all instances in GDJS.
  • Loading branch information
4ian committed Dec 31, 2016
1 parent 5281cd5 commit cdc3e3e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions GDJS/Runtime/runtimescene.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,24 @@ gdjs.RuntimeScene.prototype._updateObjectsPreEvents = function() {
gdjs.RuntimeScene.prototype._updateObjects = function() {
this._cacheOrClearRemovedInstances();

this.updateObjectsForces();

//It is *mandatory* to create and iterate on a external list of all objects, as the behaviors
//may delete the objects.
this._constructListOfAllInstances();
for( var i = 0, len = this._allInstancesList.length;i<len;++i) {
this._allInstancesList[i].update(this);
this._allInstancesList[i].stepBehaviorsPostEvents(this);
var obj = this._allInstancesList[i];

if (!obj.hasNoForces()) {
var averageForce = obj.getAverageForce();
var elapsedTimeInSeconds = obj.getElapsedTime(this) / 1000;

obj.setX(obj.getX() + averageForce.getX() * elapsedTimeInSeconds);
obj.setY(obj.getY() + averageForce.getY() * elapsedTimeInSeconds);
obj.update(this);
obj.updateForces(elapsedTimeInSeconds);
} else {
obj.update(this);
}
obj.stepBehaviorsPostEvents(this);
}

this._cacheOrClearRemovedInstances(); //Some behaviors may have request objects to be deleted.
Expand Down

0 comments on commit cdc3e3e

Please sign in to comment.