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

Author Topic: VertexArray begin() and end()  (Read 6325 times)

0 Members and 1 Guest are viewing this topic.

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
VertexArray begin() and end()
« on: August 23, 2015, 12:44:30 pm »
As VertexArray is a wrapper for std::vector<sf::Vertex>, I see no reason why it should not be able to be used in a range based for loop. However, because it has no begin() and end() functions, you either have to define your own ones using getVertexCount(), which seems unnecessary, or just stick with index based arrays, which I think should only be used if you need to know which element you are referring to. I think that having to define your own begin() and end() functions is not very user friendly and is just a hassle where it could just be done once in the library, and therefore as SFML aims to be as user friendly as possible, these functions should be added. It would also mean that you can pass VertexArray into functions that expect a vector easily be simply passing a starting and ending iterator.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: VertexArray begin() and end()
« Reply #1 on: August 23, 2015, 03:35:43 pm »
We've had similar discussions before. VertexArray is a simple wrapper and we like to keep it that way. If you want to use it like a vector, then use a std::vector<sf::Vertex>. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: VertexArray begin() and end()
« Reply #2 on: August 23, 2015, 03:41:31 pm »
Ah, I was unaware that you could pass a primitive type to draw(), so I thought it would be a lot harder to just use a vector rather than a VertexArray. Thanks.

edit: Although it did just occur to me that SFML is still C++03, which doesn't contain range based for loops and as such they are not a priority, when it moves to C++11 and therefore everyone who is using it will also be using C++11 and therefore will have the potential to use range based for loops, it seems pointless to withhold the feature.
« Last Edit: August 23, 2015, 03:59:36 pm by shadowmouse »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: VertexArray begin() and end()
« Reply #3 on: August 23, 2015, 08:07:17 pm »
I have been finding myself veering towards using manual vectors of sf::Vertex more than a vertex array recently. Seems to make more sense overall.
I wouldn't be surprised if VertexArray was replaced with VertexVector in SFML 3, but I'm 99.9% sure that it won't be considered before that (which is fine).

Although I have never actually tried or used this, I once spotted a page on the SFML Wiki that you may be interested in:
https://github.com/SFML/SFML/wiki/Source:-VertexVector
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: VertexArray begin() and end()
« Reply #4 on: August 23, 2015, 08:10:15 pm »
Thanks Hapax, that's really useful, I do hope something like that is used in SFML 3.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: VertexArray begin() and end()
« Reply #5 on: August 23, 2015, 08:23:41 pm »
You're welcome  :)

I do hope something like that is used in SFML 3.
I kinda don't. Mainly because it's directly inheriting from an STL container and I'm not convinced that doing that is "correct".
I do hope that the wrapper works like a standard vector, though  ;D
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: VertexArray begin() and end()
« Reply #6 on: August 23, 2015, 08:31:17 pm »
I meant I do hope that a class with that interface (emplace functions, range based for loop etc), basically something which has all the functionality of both std::vector and sf::VertexArray, rather than I hope there's a class that uses that exact implementation.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: VertexArray begin() and end()
« Reply #7 on: August 23, 2015, 08:35:13 pm »
I doubt that SFML will provide a full-fledged STL container in the future. As already mentioned, you can easily resort to std::vector<sf::Vertex> if you need advanced container features.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: VertexArray begin() and end()
« Reply #8 on: August 23, 2015, 08:40:47 pm »
I can't say how the future will look like, but I pretty sure we won't be writing an STL interface wrapper, just so people can keep using the "drawable inheritance effect" instead of passing the the vertex data directly.

I mean it's really just:

sf::VertexArray va;
//...
window.draw(va);
vs
std::vector<sf::Vertex> vv;
//..
window.draw(vv.data(), vv.size(), sf::Lines);

And if you do anything more advanced with vertices you'll have to create your own entity/tile class for keeping track of transformations etc. anyways, so having the primitive type not stored directly isn't a deal breaker either.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: VertexArray begin() and end()
« Reply #9 on: August 23, 2015, 08:53:09 pm »
Yeah, that all makes sense. It's easy enough to do without a wrapper once you realise the more control you can have over "draw".

window.draw(vv.data(), vv.size(), sf::Lines);
vv.data()
I've been using &vv[0] or &vv.front() but vv.data() looks nicer. I'm totally going to start using that from now on  ;)
« Last Edit: August 23, 2015, 08:57:09 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: VertexArray begin() and end()
« Reply #10 on: August 23, 2015, 09:08:05 pm »
vv.data()
I've been using &vv[0] or &vv.front() but vv.data() looks nicer. I'm totally going to start using that from now on  ;)
I assume you know this but just FYI std::vector<T>::data() is a C++11 feature. ;)
« Last Edit: August 23, 2015, 09:19:11 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: VertexArray begin() and end()
« Reply #11 on: August 23, 2015, 09:17:36 pm »
I assume you know this but just FYI std::vector<T>::data() is C++11 feature. ;)
I know that now  :P
I haven't learned everything. I like not knowing every thing. Gives me more chance to learn  ???
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything