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

Outline vertices are only updated if there is an outline. #925

Closed
wants to merge 2 commits into from

Conversation

tylerellis21
Copy link

@tylerellis21 tylerellis21 commented Jul 15, 2015

SFML Tasks

  • Create new branch
  • Add optimization back in
  • Create new pull request

Improved the logic of the shape class so that the outline vertices are only updated if they exist.

@tylerellis21
Copy link
Author

Also I have been doing some testing on the change it seems to help a lot on my system.
I have cut out some of the undeeded methods to show the Shape::updateOutline since that was my focus and the only difference between the two tests was my change.
The tool used for the performance test was: http://oprofile.sourceforge.net/
Ran on Ubuntu 14.04.

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.

@Bromeon
Copy link
Member

Bromeon commented Jul 15, 2015

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 sf:: prefix and many comments that don't add any information), and the case differentiation in Shape::updateOutline is very convoluted. A simple

// 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 master rather than the 2.3.x branch, which is for critical patches (you can't change that, but I'll write it as a note to the one who may merge it).

If you want to prove anything with your performance test, you should show us the code. Ideally, it is minimal (a single main() function) and contains nothing that's not SFML-related.

@tylerellis21
Copy link
Author

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
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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 😉

@zsbzsb
Copy link
Member

zsbzsb commented Jul 16, 2015

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?

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.

@tylerellis21
Copy link
Author

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.

@Bromeon
Copy link
Member

Bromeon commented Jul 17, 2015

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?

This is the code:

    // Render the outline
    if (m_outlineThickness != 0.f)
    {
        states.texture = NULL;
        target.draw(m_outlineVertices, states);
    }

states is only a parameter, the texture is reset so that the outline is not textured. If m_outlineVertices is empty, nothing will be done, see here. There may however be additional virtual function calls; leaving the if statement is probably cheaper -- but then it's purely an optimization and should be commented as such.

@eXpl0it3r
Copy link
Member

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)
Copy link
Member

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.

@Bromeon
Copy link
Member

Bromeon commented Oct 2, 2015

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.

@tylerellis21
Copy link
Author

@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;

Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No 😀

@zsbzsb
Copy link
Member

zsbzsb commented Oct 3, 2015

Other than the thing @Bromeon suggested and what I mentioned (new blank line) the PR looks good to me 👍

@tylerellis21
Copy link
Author

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!

@zsbzsb
Copy link
Member

zsbzsb commented Oct 4, 2015

Looks great 👍 (much better squishing than what I have seen some people do 😉)

@binary1248
Copy link
Member

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.

@eXpl0it3r
Copy link
Member

So should the if be added back again?

@Bromeon
Copy link
Member

Bromeon commented Oct 25, 2015

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.

@eXpl0it3r
Copy link
Member

So should we? Should we not? Do we need a poll?

@Bromeon
Copy link
Member

Bromeon commented Nov 10, 2015

I stated what we can do in my opinion:

  • Omit the micro-optimization
  • Leave it with an expressive comment

I.e. I don't care. I really hope we don't need a poll for every tiny decision... :)

@binary1248
Copy link
Member

Bump. Still for keeping the diff minimal.

@eXpl0it3r
Copy link
Member

Any takers? Do we need a poll?

@eXpl0it3r eXpl0it3r modified the milestones: 2.5, 2.4 Jul 7, 2016
@eXpl0it3r
Copy link
Member

@tylerellis21 Can you add the optimization back in, so we can get this PR finally merged? 😄

@eXpl0it3r
Copy link
Member

@tylerellis21 Bump! Needs updating and as mentioned adjusting.

@tylerellis21 tylerellis21 deleted the 2.3.x branch November 8, 2016 08:59
@eXpl0it3r
Copy link
Member

Did you intentionally close this and deleted your branch of it, @tylerellis21?

@Foaly
Copy link
Contributor

Foaly commented Jan 26, 2018

Should I write a new PR for this?

@eXpl0it3r
Copy link
Member

Please do so! 🙂

@eXpl0it3r
Copy link
Member

Superseded by #1356

@eXpl0it3r eXpl0it3r moved this from WIP to Merged / Superseded in SFML 2.5.0 Jan 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.5.0
  
Merged / Superseded
Development

Successfully merging this pull request may close these issues.

None yet

6 participants