First off, thanks for the quick response.
After running it through a profiler, the program spends 89.02 % of the time in this function, 62.1 % of which on the "if" line:
void region::drawRegions(std::vector<region>*& regions, sf::RenderWindow& window)
{
window.setView(worldView);
sf::Vector2f viewCenter = worldView.getCenter();
for (std::vector<region>::iterator i = regions->begin(); i != regions->end(); ++i)
{
for (std::vector<sf::ConvexShape>::iterator j = i->_region.begin(); j != i->_region.end(); ++j)
{
sf::FloatRect buffer = j->getGlobalBounds();
//This checks if the object is within the visible area (monitor)
if (buffer.left + buffer.width >= viewCenter.x - viewWidth / 2.00 && buffer.left <= viewCenter.x + viewWidth / 2.00 && buffer.top + buffer.height >= worldViewTopBounds && buffer.top <= worldViewBottomBounds)window.draw(*j);
}
}
}
Thus my next question would be, how would I go about turning this vector of triangles into an sf::VertexArray?
@Nexus, I did write those functions myself, didn't know what you posted was available. I'll have to check it out.
void region::drawRegions(std::vector<region>*& regions, sf::RenderWindow& window)
Why the reference to a pointer? Also, you don't modify regions, so make it const. I'd say "const std::vector<region>& regions" should do the trick.
{
window.setView(worldView);
sf::Vector2f viewCenter = worldView.getCenter();
I'd make the variable const since you use it as a constant.
for (std::vector<region>::iterator i = regions->begin(); i != regions->end(); ++i)
{
for (std::vector<sf::ConvexShape>::iterator j = i->_region.begin(); j != i->_region.end(); ++j)
Why not use range-based for loops here? They are potentially faster (only evaluate end() once and modern compilers try hard to vectorize them) and they are certainly a lot easier to read.
{
sf::FloatRect buffer = j->getGlobalBounds();
const?
Personally I'd probably rewrite the function roughly like this:
void region::drawRegions(const std::vector<region>& regions, sf::RenderWindow& window)
{
window.setView(worldView);
const auto viewCenter = worldView.getCenter();
for (const auto& region : regions) {
for (const auto polygon& : region) {
const auto buffer = polygon.getGlobalBounds();
//This checks if the object is within the visible area (monitor)
if (buffer.left + buffer.width >= viewCenter.x - viewWidth / 2.00 &&
buffer.left <= viewCenter.x + viewWidth / 2.00 &&
buffer.top + buffer.height >= worldViewTopBounds &&
buffer.top <= worldViewBottomBounds) {
window.draw(*j);
}
}
}
}
But, as others have said, a solution involving VertexArray will probably perform better. Just wanted to provide some feedback/suggestions :)