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
Outline vertices are only updated if there is an outline. #925
Conversation
Also I have been doing some testing on the change it seems to help a lot on my system. https://gist.github.com/tylerellis21/f9a7663262feaf150a83 I ran the program for the same amount of time but the simulation wasn't 100% the same, but the results do speak for themselves. |
Thanks for the contribution. For the future, please read the contribution guidelines before just creating pull requests out of the blue. Your code makes several things worse (the // Return if there is no outline to build
if (outlineThickness == 0.f)
{
m_outlineVertices.clear();
m_bounds = m_insideBounds;
return;
} before anything else would have been much clearer. Obvious comments like m_outlineVertices.clear(); // Clear out any vertices that may remain from a previous outline size
return; // Return since there is no outline to build don't add any useful information, omit them entirely. Furthermore, if there is a check for zero outline thickness when creating the outline, there needn't be another one when drawing. Since this is not a bugfix but an optimization, it should target If you want to prove anything with your performance test, you should show us the code. Ideally, it is minimal (a single |
Sorry about the out of the blue push. I'm sorry I didn't see the contribution guide first and from now on I will definitely follow it down the the dot. I changed my logic so it's not as confusing, but I was wondering on the check for the outline draw. It sets the renderstates texture to null if there is an outline in that check. If that is removed would that cause any adverse affects? Thanks again and sorry for the inconvenience. |
@@ -204,7 +204,6 @@ void Shape::update() | |||
// Texture coordinates | |||
updateTexCoords(); | |||
|
|||
// Outline |
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.
Why was this comment removed?
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.
It seemed kinda redundant. Since the method it self is named updateOutline, but I can undo that If needed.
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.
True, but now it's inconsistent, because there's a comment above updateFillColors()
and updateTexCoords()
, but not above updateOutline()
. In general, I'd focus more on the issue and less on all the other existing code 😉
You mean if the texture assignment to null was removed? If that was removed then the user would see their texture being drawn inside the outline. I'm not even sure why you would want that assignment to be removed. |
I was talking about what Bromeon said "Furthermore, if there is a check for zero outline thickness when creating the outline, there needn't be another one when drawing". Was just trying to clarify that. It seems that we would still want that. |
This is the code: // Render the outline
if (m_outlineThickness != 0.f)
{
states.texture = NULL;
target.draw(m_outlineVertices, states);
}
|
Can someone review this? |
@@ -251,7 +248,16 @@ void Shape::updateTexCoords() | |||
//////////////////////////////////////////////////////////// | |||
void Shape::updateOutline() | |||
{ | |||
// Return if there is no outline to build. | |||
if (m_outlineThickness != 0.f) |
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.
Shouldn't that be ==
?
A single commit would also be nice.
What's the state of this? @tylerellis21, are you still willing to update the PR, or should somebody else take care of it? Also, further reviews would be nice. |
@Bromeon To be honest, I forgot about this PR, but I am willing to update it. I will get on it tonight and fix my dumb mistakes! |
std::size_t count = m_vertices.getVertexCount() - 2; | ||
|
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.
Do we also need a new blank line here with no new surrounding code?
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.
No 😀
Other than the thing @Bromeon suggested and what I mentioned (new blank line) the PR looks good to me 👍 |
In theory I squashed the commits into one. I also updated the logic to be correct and removed that extra line. I have never done a squash before, so I just want to make sure it looks good to you guys. Thanks everyone! |
Looks great 👍 (much better squishing than what I have seen some people do 😉) |
I would also leave in the optimization that @Bromeon was talking about. If it doesn't break anything, there is no need to get rid of it if it is already part of the existing code. |
So should the if be added back again? |
It makes the code a bit more difficult to understand, and it's not obvious why the line thickness is checked in two places, when one is enough. If we add it, I would at least write an expressive comment to state that it's a pure micro-optimization and not a behavioral necessity. |
So should we? Should we not? Do we need a poll? |
I stated what we can do in my opinion:
I.e. I don't care. I really hope we don't need a poll for every tiny decision... :) |
Bump. Still for keeping the diff minimal. |
Any takers? Do we need a poll? |
@tylerellis21 Can you add the optimization back in, so we can get this PR finally merged? 😄 |
@tylerellis21 Bump! Needs updating and as mentioned adjusting. |
Did you intentionally close this and deleted your branch of it, @tylerellis21? |
Should I write a new PR for this? |
Please do so! 🙂 |
Superseded by #1356 |
SFML Tasks
Improved the logic of the shape class so that the outline vertices are only updated if they exist.