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

Author Topic: sf::VerArray.erase  (Read 4899 times)

0 Members and 1 Guest are viewing this topic.

cheeseboy

  • Newbie
  • *
  • Posts: 36
    • View Profile
sf::VerArray.erase
« 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.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: sf::VerArray.erase
« Reply #1 on: November 04, 2014, 03:57:21 am »
You can use an std::vector<sf::Vertex> instead.

cheeseboy

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: sf::VerArray.erase
« Reply #2 on: November 04, 2014, 04:11:35 am »
or it could have an erase function because that'd make sense.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: sf::VerArray.erase
« Reply #3 on: November 04, 2014, 05:23:29 am »
I'm sure your tons of arguments will make them change their mind. ;)

cheeseboy

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: sf::VerArray.erase
« Reply #4 on: November 04, 2014, 10:06:50 am »
by that logic: sfml is just a convenience library i should use opengl... makes no sense

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sf::VerArray.erase
« Reply #5 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kojay

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: sf::VerArray.erase
« Reply #6 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.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: sf::VerArray.erase
« Reply #7 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.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).