-
-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
- Add `draw time` to debug panel - Add dirty rects in reverse order (ensures debug panel is drawn last) - Do not use `drawManage.makeAllDirty()` when `me.sys.dirtyRegion = true` - Add rectangle information to TMX layers - Small optimization in `TMXRenderer` - Support `Infinity` dimensions in `me.Rect`
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -876,6 +876,8 @@ var me = me || {}; | |
// list of object to redraw | ||
// only valid for visible and update object | ||
var dirtyObjects = []; | ||
|
||
var drawTime = 0; | ||
|
||
var drawCount = 0; | ||
|
||
|
@@ -916,9 +918,9 @@ var me = me || {}; | |
if (oldRect) { | ||
// merge both rect, and add it to the list | ||
// directly pass object, since anyway it inherits from rect | ||
dirtyRects.push(oldRect.union(obj)); | ||
dirtyRects.unshift(oldRect.union(obj)); | ||
} else if (obj.getRect) { | ||
dirtyRects.push(obj.getRect()); | ||
dirtyRects.unshift(obj.getRect()); | ||
} | ||
} | ||
} | ||
|
@@ -971,18 +973,26 @@ var me = me || {}; | |
return drawCount; | ||
}; | ||
|
||
/** | ||
* return the time when drawing started | ||
*/ | ||
api.getDrawTime = function() { | ||
return drawTime; | ||
}, | ||
|
||
/** | ||
* draw all dirty objects/regions | ||
*/ | ||
api.draw = function(context) { | ||
if (me.debug.displayDrawTime) | ||
drawTime = Date.now(); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
This comment has been minimized.
Sorry, something went wrong.
melonjs
Collaborator
|
||
// if feature disable, we only have one dirty rect (the viewport area) | ||
for ( var r = dirtyRects.length, rect; r--, rect = dirtyRects[r];) { | ||
for (var r = dirtyRects.length, rect; r--, rect = dirtyRects[r];) { | ||
// parse all objects | ||
for ( var o = dirtyObjects.length, obj; o--, | ||
obj = dirtyObjects[o];) { | ||
for (var o = dirtyObjects.length, obj; o--, obj = dirtyObjects[o];) { | ||
// if dirty region enabled, make sure the object is in the area to be refreshed | ||
if (me.sys.dirtyRegion && obj.isSprite | ||
&& !obj.overlaps(rect)) { | ||
if (me.sys.dirtyRegion && !obj.getRect().overlaps(rect)) { | ||
continue; | ||
} | ||
// draw the object using the dirty area to be updated | ||
|
@@ -1323,16 +1333,27 @@ var me = me || {}; | |
|
||
/** | ||
* returns the amount of object being draw per frame<br> | ||
* @name me.game#getEntityCount | ||
* @name me.game#getDrawCount | ||
* @protected | ||
* @function | ||
* @return {Number} the amount of object entities | ||
* @return {Number} the amount of draws | ||
*/ | ||
api.getDrawCount = function() | ||
{ | ||
return drawManager.getDrawCount(); | ||
}; | ||
|
||
/** | ||
* returns the time when the last frame draw started<br> | ||
* @name me.game#getDrawTime | ||
* @protected | ||
* @function | ||
* @return {Number} the time of frame draw start in milliseconds | ||
*/ | ||
api.getDrawTime = function() { | ||
return drawManager.getDrawTime(); | ||
}, | ||
|
||
|
||
/** | ||
* return the entity corresponding to the specified GUID<br> | ||
|
@@ -1419,7 +1440,7 @@ var me = me || {}; | |
drawManager.makeDirty(obj, updated, updated ? oldRect : null); | ||
} | ||
// update the camera/viewport | ||
if (api.viewport.update(drawManager.isDirty)) { | ||
if (api.viewport.update(drawManager.isDirty) && !me.sys.dirtyRegion) { | ||
drawManager.makeAllDirty(); | ||
} | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,8 +64,8 @@ | |
var start = this.pixelToTileCoords(viewport.x + rect.pos.x, | ||
viewport.y + rect.pos.y).floorSelf(); | ||
|
||
var end = this.pixelToTileCoords(viewport.x + rect.pos.x + rect.width + this.tilewidth, | ||
viewport.y + rect.pos.y + rect.height + this.tileheight).ceilSelf(); | ||
var end = this.pixelToTileCoords(viewport.x + rect.pos.x + rect.width, | ||
viewport.y + rect.pos.y + rect.height).ceilSelf(); | ||
This comment has been minimized.
Sorry, something went wrong.
melonjs
Collaborator
|
||
|
||
//ensure we are in the valid tile range | ||
end.x = end.x > this.width ? this.width : end.x; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -293,7 +293,7 @@ | |
*/ | ||
Object.defineProperty(this, "right", { | ||
get : function() { | ||
return this.pos.x + this.width; | ||
return (this.pos.x + this.width) || Infinity; | ||
}, | ||
configurable : true | ||
}); | ||
|
@@ -319,7 +319,7 @@ | |
*/ | ||
Object.defineProperty(this, "bottom", { | ||
get : function() { | ||
return this.pos.y + this.height; | ||
return (this.pos.y + this.height) || Infinity; | ||
}, | ||
configurable : true | ||
}); | ||
|
@@ -401,7 +401,7 @@ | |
if (this.right !== this.pos.x + this.colPos.x + this.width) { | ||
Object.defineProperty(this, "right", { | ||
get : function() { | ||
return this.pos.x + this.colPos.x + this.width; | ||
return (this.pos.x + this.colPos.x + this.width) || Infinity; | ||
}, | ||
configurable : true | ||
}); | ||
|
@@ -425,7 +425,7 @@ | |
if (this.bottom !== this.pos.y + this.colPos.y + this.height) { | ||
Object.defineProperty(this, "bottom", { | ||
get : function() { | ||
return this.pos.y + this.colPos.y + this.height; | ||
return (this.pos.y + this.colPos.y + this.height) || Infinity; | ||
}, | ||
configurable : true | ||
}); | ||
This comment has been minimized.
Sorry, something went wrong.
melonjs
Collaborator
|
||
|
I wa wondering : since the debug panel is the last object to be updated and also to be drawn, instead of adding an if statement in the draw method here, do you think we could achieve the same thing by taking the start "date" from the panel update function (since it's in theory the last update function called), and then check the delta once the panel draw function is called . (since it's the last draw function called as well) ?