SFML community forums

General => Feature requests => Topic started by: cheeseboy on November 04, 2014, 03:06:07 am

Title: sf::VerArray.erase
Post by: cheeseboy on November 04, 2014, 03:06:07 am
I need to erase a vertex from a vertexarray. There is no erase function. Please add one.
Title: Re: sf::VerArray.erase
Post by: G. on November 04, 2014, 03:57:21 am
You can use an std::vector<sf::Vertex> instead.
Title: Re: sf::VerArray.erase
Post by: cheeseboy on November 04, 2014, 04:11:35 am
or it could have an erase function because that'd make sense.
Title: Re: sf::VerArray.erase
Post by: G. on November 04, 2014, 05:23:29 am
I'm sure your tons of arguments will make them change their mind (http://en.sfml-dev.org/forums/index.php?topic=7404). ;)
Title: Re: sf::VerArray.erase
Post by: cheeseboy on November 04, 2014, 10:06:50 am
by that logic: sfml is just a convenience library i should use opengl... makes no sense
Title: Re: sf::VerArray.erase
Post by: eXpl0it3r on November 04, 2014, 10:16:52 am
As G. pointed out, this has been discussed many, many times and the answer is: no.

SFML provides some classes for convenience such as sf::Sprite or sf::VertexArray. If you want functionalities beyond that, you better go one abstraction deeper (for sf::Sprite that would be sf::Transformable & sf::Drawable, for sf::VertexArray that would be std::vector<sf::Vertex>). Of course if that abstraction still isn't enough, SFML won't stand in your way and you can simply drop the whole sfml-graphics module and run your own OpenGL code with sfml-window alone. ;)

Again, the reason why there won't be an erease function for sf::VertexArray is, that the class is a very thin wrapper on top of std::vector<sf::Vertex> and adding all vector features to the vertex array class doesn't make sense. If you want vector like access, use the vector directly without the thin wrapper.
Title: Re: sf::VerArray.erase
Post by: Kojay on November 04, 2014, 05:52:29 pm
Suppose an erase() is implemented (presumably by index). But then, you decide to be fancy and get rid of a whole bunch with an erase-remove; sf::VertexArray is useless once again.

Of course sf::VertexArray has a reason for existing, it is a way of pairing the vertices with the primitive into a sf::Drawable, rather than throwing them around willy-nilly. Which begs the question, why the 'encapsulation' that effectively makes sf::VertexArray a handicapped vector? Why isn't sf::VertexArray exactly what's its meant to be - a struct comprising of a public vector of vertices and a primitive, with a draw function? As it is, it's a recurring joke.
Title: Re: sf::VerArray.erase
Post by: binary1248 on November 04, 2014, 06:25:21 pm
std::vector<sf::Vertex> vertices;
// Fill it up somewhere around here
// Erase stuff around here
renderTarget.draw(vertices.data(), vertices.size(), thePrimitiveType);
Because... you can...

Maybe instead of asking why sf::VertexArray doesn't have .erase() you should ask why even keep it at all? At the moment, sf::VertexArray is nothing more than a data structure containing said vector, a saved primitive type and a (more or less helpful) way of getting the bounds of the contained vertices. The last part could be implemented using std::for_each.

Who knows... maybe it might get discarded in SFML 3... maybe not. I don't really have an opinion on this. You just use the right tool for the right job.