mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Avoid creating temporaries when dealing with objects list maps in HTML5 games
This commit is contained in:
@@ -14,8 +14,7 @@
|
||||
*/
|
||||
gdjs.EventsContext = function()
|
||||
{
|
||||
if (this._eventsObjectsMap !== undefined) this._eventsObjectsMap.clear();
|
||||
else this._eventsObjectsMap = new Hashtable();
|
||||
this._objectsMapCache = [];
|
||||
|
||||
this._onceTriggers = {};
|
||||
this._lastFrameOnceTrigger = {};
|
||||
@@ -34,18 +33,20 @@ gdjs.EventsContext.prototype.startNewFrame = function() {
|
||||
delete this._onceTriggers[k];
|
||||
}
|
||||
}
|
||||
|
||||
this._currentObjectsMap = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Used by "Trigger once" conditions: Return true only if
|
||||
* Used by "Trigger once" conditions: return true only if
|
||||
* this method was not called with the same identifier during the last frame.
|
||||
* @param triggerId The identifier of the "Trigger once" condition.
|
||||
* @method triggerOnce
|
||||
*/
|
||||
gdjs.EventsContext.prototype.triggerOnce = function(triggerId) {
|
||||
this._onceTriggers[triggerId] = true;
|
||||
this._onceTriggers[triggerId] = true;
|
||||
|
||||
return !this._lastFrameOnceTrigger.hasOwnProperty(triggerId);
|
||||
return !this._lastFrameOnceTrigger.hasOwnProperty(triggerId);
|
||||
};
|
||||
|
||||
gdjs.EventsContext.prototype.clearObject = function(obj) {
|
||||
@@ -61,7 +62,10 @@ gdjs.EventsContext.prototype.clearObject = function(obj) {
|
||||
* @method clearEventsObjectsMap
|
||||
*/
|
||||
gdjs.EventsContext.prototype.clearEventsObjectsMap = function() {
|
||||
this._eventsObjectsMap.clear();
|
||||
if (this._currentObjectsMap === this._objectsMapCache.length)
|
||||
this._objectsMapCache.push(new Hashtable());
|
||||
|
||||
this._objectsMapCache[this._currentObjectsMap].clear();
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -70,7 +74,7 @@ gdjs.EventsContext.prototype.clearEventsObjectsMap = function() {
|
||||
* @method addObjectsToEventsMap
|
||||
*/
|
||||
gdjs.EventsContext.prototype.addObjectsToEventsMap = function(name, objectList) {
|
||||
this._eventsObjectsMap.put(name, objectList);
|
||||
this._objectsMapCache[this._currentObjectsMap].put(name, objectList);
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -79,5 +83,5 @@ gdjs.EventsContext.prototype.addObjectsToEventsMap = function(name, objectList)
|
||||
* @method getEventsObjectsMap
|
||||
*/
|
||||
gdjs.EventsContext.prototype.getEventsObjectsMap = function() {
|
||||
return this._eventsObjectsMap.clone();
|
||||
return this._objectsMapCache[this._currentObjectsMap++];
|
||||
};
|
||||
|
@@ -766,8 +766,8 @@ gdjs.RuntimeObject.prototype.getAABB = function() {
|
||||
gdjs.RuntimeObject.prototype.updateAABB = function() {
|
||||
this.aabb.min[0] = this.getDrawableX();
|
||||
this.aabb.min[1] = this.getDrawableY();
|
||||
this.aabb.max[0] = this.getDrawableX()+this.getWidth();
|
||||
this.aabb.max[1] = this.getDrawableY()+this.getHeight();
|
||||
this.aabb.max[0] = this.aabb.min[0] + this.getWidth();
|
||||
this.aabb.max[1] = this.aabb.min[1] + this.getHeight();
|
||||
};
|
||||
|
||||
//Behaviors:
|
||||
|
Reference in New Issue
Block a user