Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: ConcaveShape  (Read 2139 times)

0 Members and 1 Guest are viewing this topic.

Zabarovka

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
ConcaveShape
« on: September 02, 2016, 12:48:35 pm »
Hi all. I just wrote some class for concave shapes, but because of being pretty new to SFML and even C++ (this is only my second project with SFML),so I decided to ask you if it is ok and ask you for some advices, and thank you for your time  :)

ConcaveShape.hpp
(click to show/hide)

ConcaveShape.cpp
(click to show/hide)

Usage example
(click to show/hide)

I created it for displaying some charts, so there are few examples:
(click to show/hide)
(click to show/hide)
(click to show/hide)
« Last Edit: October 25, 2016, 09:47:20 am by Zabarovka »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: ConcaveShape
« Reply #1 on: September 02, 2016, 02:21:49 pm »
Just a couple of points that I could see with a quick look:

1) Instead of:
if (texture!=nullptr) {states.texture=texture;}
you can just use:
states.texture = texture;
as nullptr is a valid value for states.texture

2) This is just a question. Why do you attempt to delete the external texture that is used when the object is destroyed? This texture may be used elsewhere.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Zabarovka

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: ConcaveShape
« Reply #2 on: September 02, 2016, 02:46:45 pm »
Just a couple of points that I could see with a quick look:

1) Instead of:
if (texture!=nullptr) {states.texture=texture;}
you can just use:
states.texture = texture;
as nullptr is a valid value for states.texture

2) This is just a question. Why do you attempt to delete the external texture that is used when the object is destroyed? This texture may be used elsewhere.
1) Done  :)
2) ...nevermind- just forgot to remove "delete"...

Thanks ^^
« Last Edit: September 02, 2016, 03:33:34 pm by Zabarovka »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: ConcaveShape
« Reply #3 on: September 02, 2016, 03:02:39 pm »
Quote
1) Instead of:
if (texture!=nullptr) {states.texture=texture;}
you can just use:
states.texture = texture;
as nullptr is a valid value for states.texture
This is not equivalent. The first version uses the states' texture by default unless there's one in the shape. The second one always uses the shape's texture and ignores the states one.
« Last Edit: September 02, 2016, 03:04:49 pm by Laurent »
Laurent Gomila - SFML developer

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: ConcaveShape
« Reply #4 on: September 02, 2016, 06:50:31 pm »
This is not equivalent.
This is true. It's not exactly equivalent.
It's equivalent for most standard cases but doesn't allow passing another texture in the states call to draw, if that's what you need.
I would argue, though, that being stricter about which texture is being used (by only allowing it to be specified in the actual class) is more predictable.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: ConcaveShape
« Reply #5 on: September 02, 2016, 09:34:44 pm »
I just wanted to point out that changing this code would slightly change the behaviour of the class. I didn't mean that one was better than the other ;)
Laurent Gomila - SFML developer

Zabarovka

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: ConcaveShape
« Reply #6 on: October 25, 2016, 09:47:44 am »
Minor updates.
« Last Edit: October 25, 2016, 09:50:29 am by Zabarovka »