-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of debug drawing #3168
base: dev
Are you sure you want to change the base?
Changes from 1 commit
74b45b6
be93dda
6ec694b
cdd1e8e
d1c0985
cad7993
2e5577d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1292,11 +1292,11 @@ class FlxObject extends FlxBasic | |
|
||
var rect = getBoundingBox(camera); | ||
var gfx:Graphics = beginDrawDebug(camera); | ||
drawDebugBoundingBox(gfx, rect, allowCollisions, immovable); | ||
drawDebugBoundingBox(gfx, rect, allowCollisions, immovable, camera.zoom); | ||
endDrawDebug(camera); | ||
} | ||
|
||
function drawDebugBoundingBox(gfx:Graphics, rect:FlxRect, allowCollisions:Int, partial:Bool) | ||
function drawDebugBoundingBox(gfx:Graphics, rect:FlxRect, allowCollisions:Int, partial:Bool, ?zoom:Float = 1.0) | ||
{ | ||
// Find the color to use | ||
var color:Null<Int> = debugBoundingBoxColor; | ||
|
@@ -1313,8 +1313,13 @@ class FlxObject extends FlxBasic | |
} | ||
|
||
// fill static graphics object with square shape | ||
gfx.lineStyle(1, color, 0.75); | ||
gfx.drawRect(rect.x + 0.5, rect.y + 0.5, rect.width - 1.0, rect.height - 1.0); | ||
gfx.beginFill(color, 0.5); | ||
var size = Math.max(1 / zoom, 1); | ||
|
||
gfx.drawRect(rect.x - size, rect.y - size, size, rect.height + size); | ||
gfx.drawRect(rect.x, rect.y - size, rect.width + size, size); | ||
gfx.drawRect(rect.x + rect.width, rect.y, size, rect.height - size); | ||
gfx.drawRect(rect.x, rect.y + rect.height - size, rect.width + size, size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will these have stronger color in the overlapping corners? Rather than drawing 4 rects could we specify 8 points to make a hollow rect shape? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, this won't have stronger color cos they're not overlapping, they're drawn in a specific way so they don't touch, that's why all the weird math between the positions and the sizes lol The alpha was set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
inline function beginDrawDebug(camera:FlxCamera):Graphics | ||
|
@@ -1334,6 +1339,8 @@ class FlxObject extends FlxBasic | |
{ | ||
if (FlxG.renderBlit) | ||
camera.buffer.draw(FlxSpriteUtil.flashGfxSprite); | ||
else if (FlxG.renderTile) | ||
camera.debugLayer.graphics.endFill(); | ||
} | ||
#end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to simply use a size of 0.5 like it has been, in fact, there's benefits to having this not perfectly align with the camera's pixel resolution, as it more discernible, plus adding new args may break overriding classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... I don't think you would want that, I didn't want to do it either, but without doing a "zoom" variable, this is what it looks like:
Compared to this:
This is normal btw, this is OpenGL doing its shenanigans and sometimes its not 100% accurate to display stuff in exchange of performance.
One thing that I tried as possible to make it not break a lot, is adding a "Nulled" already set variable at the end, so people with older code and trying to port it could use this function and would not give an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to omit the zoom arg, without missing lines (I didn't see any at zoom = 0.3, but I see a little at zoom=0.2, which I'm okay with)
rather than drawing the rect at ±.5 from the rect, I draw a rect where the outer rect matches the given rect, and the inner rect is 1px smaller, this aligns them more with the actual pixels and more closely matches the old behavior