Skip to content
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

Fix for FlxStrip when drawDebug is true #2904 #2906

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

UncertainProd
Copy link
Contributor

Fixes #2904, I tested it on html5 and windows

@Geokureli
Copy link
Member

Sweet! I'll try this out later today

@Geokureli Geokureli merged commit 5e563ad into HaxeFlixel:dev Aug 29, 2023
16 checks passed
@Geokureli
Copy link
Member

Thanks! this probably saves me days of debugging

@UncertainProd UncertainProd deleted the fix-flxstrip-drawdebug branch August 29, 2023 08:22
@Geokureli
Copy link
Member

Geokureli commented Aug 29, 2023

@UncertainProd do you know what this line actually does? commenting it out seems to change nothing, and I still get bad performance when drawDebug is enabled and FlxStrips are displayed, even in ignoreDrawDebug is enabled for them

regardless, things are better with your fix, but I'm left with many more questions

@UncertainProd
Copy link
Contributor Author

Honestly, even I'm not too sure. It looks like it's meant to draw some extra stuff when drawDebug is enabled but I don't see anything different being drawn either way

@UncertainProd
Copy link
Contributor Author

UncertainProd commented Aug 30, 2023

Update: I found that if you add the following 2 lines in the update() method of PlayState in the FlxClothSprite demo, then it shows you the vertices used in the cloth sprite (which also uses drawTriangles)
Code to add:

if (FlxG.keys.justPressed.SPACE)
{
    FlxG.debugger.drawDebug = !FlxG.debugger.drawDebug;
}

This results in:
debugflxstrip

Turns out FlxClothSprite overrides it's drawDebugOnCamera method to achieve this. Maybe something like this was the intended effect in FlxStrip but drawTriangles doesn't seem to work with lineStyles like the other openfl drawing commands.

@Geokureli
Copy link
Member

I may have discovered the source of my performance issues, I talk about it here

Turns out FlxClothSprite overrides it's drawDebugOnCamera method to achieve this. Maybe something like this was the intended effect in FlxStrip but drawTriangles doesn't seem to work with lineStyles like the other openfl drawing commands

yeah maybe they wanted this kind of wireframe drawing on all triangles, rather than having each FlxStrip implementing their own version, but the one in FlxDrawTrianglesItem broke, or only worked in flash and no one noticed. Then, when FlxClothSprite was introduced they unknowingly reinvented the broken wheel?

@UncertainProd
Copy link
Contributor Author

Yeah, I think so

@Geokureli
Copy link
Member

Geokureli commented Aug 30, 2023

Update: I found that if you add the following 2 lines in the update() method of PlayState in the FlxClothSprite demo, then it shows you the vertices used in the cloth sprite (which also uses drawTriangles):

does this wireframe show up even if you comment out these lines: https://github.com/UncertainProd/flixel/blob/dev/flixel/graphics/tile/FlxDrawTrianglesItem.hx#L91-L98

If so, I think we should just remove them or maybe put #if !flash

@UncertainProd
Copy link
Contributor Author

does this wireframe show up even if you comment out these lines: https://github.com/UncertainProd/flixel/blob/dev/flixel/graphics/tile/FlxDrawTrianglesItem.hx#L91-L98

Yeah the wireframe shows up even after commenting it out

@UncertainProd
Copy link
Contributor Author

UncertainProd commented Aug 30, 2023

Also, when I replace those lines with the following in FlxDrawTrianglesItem, it does outline the triangles being drawn:

if (FlxG.debugger.drawDebug)
{
			var gfx:Graphics = camera.debugLayer.graphics;
			gfx.lineStyle(1, FlxColor.BLUE, 0.5);
                        // draw a triangle path for each triangle in the drawitem
			var i = 0;
			while (i < indices.length)
			{
				var indexToPoint = (idx:Int) ->
				{
					return [vertices[idx * 2], vertices[idx * 2 + 1]];
				};
				var pt1 = indexToPoint(indices[i]);
				var pt2 = indexToPoint(indices[i + 1]);
				var pt3 = indexToPoint(indices[i + 2]);
				gfx.drawPath(Vector.ofArray([MOVE_TO, LINE_TO, LINE_TO, LINE_TO]), Vector.ofArray([
					pt1[0], pt1[1],
					pt2[0], pt2[1],
					pt3[0], pt3[1],
					pt1[0], pt1[1],
				]));
				i += 3;
			}
}

@Geokureli
Copy link
Member

Also, when I replace those lines with the following in FlxDrawTrianglesItem, it does outline the triangles being drawn:

Nice! I didn't know global vertex drawing was that easy, however I feel like this feature should be tied to some flag on the FlxStrip, something like strip.debugDrawWireFrame and/or ignoreDrawDebug rather than relying solely on FlxG.drawDebug

@UncertainProd
Copy link
Contributor Author

I didn't know global vertex drawing was that easy

Yeah although it did take me a bit of searching to understand how that (and drawTriangles in general) worked 😅

I feel like this feature should be tied to some flag on the FlxStrip, something like strip.debugDrawWireFrame and/or ignoreDrawDebug rather than relying solely on FlxG.drawDebug

True

@Geokureli
Copy link
Member

... it did take me a bit of searching to understand how that (and drawTriangles in general) worked 😅

I'm in the same boat, thanks for all you've done!

@UncertainProd
Copy link
Contributor Author

No problem!

swordcube added a commit to swordcube/flixel that referenced this pull request Sep 22, 2023
@Geokureli Geokureli added this to the 5.4.0 milestone Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FlxStrips appear full black when debugDraw is enabled
2 participants