Yes! Your suggestion definitely has given performance increase. I rewrote entire class so now it looks like this(can adjust radius and number of sides):
class EnemyVertexArrayOptimized : public sf::Drawable, public sf::Transformable
{
public:
explicit EnemyVertexArrayOptimized(float radius, int sides) : RADIUS{ radius }, SIDES{ sides }, ANGLE_INCREASE_RADIAN{ 360.f / sides * PI / 180.f }
{
vertices.setPrimitiveType(sf::Triangles);
for (size_t i = 0; i < SIDES+1; i++)
{
points.push_back({ cosf(ANGLE_INCREASE_RADIAN * i) * RADIUS, sinf(ANGLE_INCREASE_RADIAN * i) * RADIUS });
}
}
void update(const std::vector<Enemy>& enemies)
{
vertices.clear();
for (const Enemy& enemy : enemies)
{
const sf::Vector2f enemyPos = enemy.getPosition();
for (int i = 0; i < SIDES; i++)
{
sf::Vertex v1(enemyPos, sf::Color::Green);
sf::Vertex v2(enemyPos + points[i], sf::Color::Green);
sf::Vertex v3(enemyPos + points[i+1], sf::Color::Green);
vertices.append(v1);
vertices.append(v2);
vertices.append(v3);
}
}
}
private:
virtual void draw(sf::RenderTarget& rt, sf::RenderStates states) const
{
states.transform *= getTransform();
rt.draw(vertices, states);
}
std::vector<sf::Vector2f> points;
const float ANGLE_INCREASE_RADIAN;
const float RADIUS;
const int SIDES;
sf::VertexArray vertices;
};
Is there anything else I can do to squeeze more performance out of it?