Firsteval look at the screenshots.
http://oi39.tinypic.com/15mzev5.jpg
http://oi44.tinypic.com/23j4s9c.jpg
Ok so this is normal platform game but additionally you can draw something on a screen with your mouse and you can use it as a landing, shield, barrier, etc. On the screens you can see that you can jump on it.
The problem is algorithm which do that lines. Every line contains hundred of points which are done with sf::Shape:
Image[BarrierCounter] = new Shape(sf::Color::Black, 3, 3);
Of course Shape is my own Class which has sf::Shape in it.
As I said every line contains on average two hundred of 3px:3px points (of course you can do a line or circle or what you want with thousand points for example but I want to describe a problem). It means that if I have array with 2000 elements I can draw ~10 lines. Of course I want to make that amount bigger. And now there is a problem because I can't do array with bigger amount because there is a problem with graphic card memory, I think. I read that this is connected with many calls of draw function.
So what should I do to avoid it, to make possible creating a lot of lines. VertexArray? Or what?
You can draw quads too, if all you want is just drawing tons of points there is no need for anything else. Don't actually use vertex array because it's dynamic, just use C array or std::array of vertices that is like 400 or 800 or other multiple of amount of vertices you have per point.
Super messy pseudocode, you can make offsets up to left and right constants and access .x and .y of vertices directly and set color to all black beforehand.
for each point in points:
if not point in screen skip
vertices[i++].position=point+offset_up_left;
vertices[i++].position=point+offset_down_left;
vertices[i++].position=point+offset_down_right;
vertices[i++].position=point+offset_up_right;
if i==vertices size draw_quads_and_set_i_to_0
but don't forget to draw last partially filled array too.
Edit: Like this: i should be zero before the loop and half_radius should be half of your desired radius like 1.5f if you want 3x3 squares for points.
for(auto it=points.begin();it!=points.end();++it)
{
vertices[i].position.x=it->x-half_radius;
vertices[i++].position.y=it->y-half_radius;
vertices[i].position.x=it->x-half_radius;
vertices[i++].position.y=it->y+half_radius;
vertices[i].position.x=it->x+half_radius;
vertices[i++].position.y=it->y+half_radius;
vertices[i].position.x=it->x+half_radius;
vertices[i++].position.y=it->y-half_radius;
if(i==vertices.size())
{
render_window.draw(vertices,i,sf::Quads);
i=0;
}
}
render_window.draw(vertices,i,sf::Quads);//last partially fileld batch
This should be much faster and much much less memory consuming than what you're doing now, because sf::Transform in shape is not checking for being ready, there are no hundreds of virtual calls and draw calls, there is no operating on pointers and the vertices object is a linear array so cache misses are minimal probably, there is just tiny bit of float subtraction and addition.