Hello, First of all sorry for my english.
So I've got gaming project to do for my university. I'm studying Computer Science and i chose SFML library.
Here's my topic. I have to write something like Worms (Simple ofc, it don't have to be AAA game ^^) but in real time with simple map editor. It's hot-seat game, map has got size of screen resolution, each of players has 30 seconds to draw his half of map and then they're shooting to each other. Map is destructible.
I've got some problems. I've got 2 versions of drawing map but both sucks.
First version and problem: efficiency
void Level::Render(sf::RenderWindow &gamewindow)
{
for (int i = 0; i < mapelements.size(); i++)
{
mapElement a = mapelements[i];
gamewindow.draw(a.circle);
}
p1.Render(gamewindow);
}
void Level::handleInput(sf::RenderWindow& gamewindow) {
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
mapElement circle;
circle.setPosition(mouse.getPosition(gamewindow).x, mouse.getPosition(gamewindow).y);
mapelements.push_back(circle);
}
...
mapElement is a circle with some methods. This version really sucks in efficiency. If there are 500+ circles there's huge fps drop. If collision is off i can draw about 700+ circles
Second version
I've got transparent RenderTexture (Screen Resolution size, e.g 1366x768) on which i draw circles and then i remove circles from vector so there's no efficiency problems but i can't handle with collision cause it's one big texture...
I don't have other ideas, i'm new in SFML but i tried. Maybe you can help me with ideas of mine or you've got other ideas.
Thanks ;)
mapElement a = mapelements[i];
gamewindow.draw(a.circle);
You're doing un unecessary copy/destruction of each map element every time you draw them. And you're probably doing it also in other parts of your code (collision detection, ...). Remove all these copies and see if things get better.
I've got transparent RenderTexture (Screen Resolution size, e.g 1366x768) on which i draw circles and then i remove circles from vector so there's no efficiency problems but i can't handle with collision cause it's one big texture...
You can reconstruct collision information from transparent parts of the texture. Or keep a separate representation of your map for collision detection (ie. every time you draw or erase something to/from the render-texture, add/remove a corresponding entry in the physical description of your map); should be easy if it's just a set of circles.