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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - HUM4N

Pages: [1]
1
Graphics / Re: sf::VertexArray with multiple sf::TriangeFans
« on: April 13, 2023, 06:28:45 pm »
Alright I gotcha. So what should my takeaway from this be? I'm not quite sure.

2
Graphics / Re: sf::VertexArray with multiple sf::TriangeFans
« on: April 12, 2023, 08:56:35 pm »
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?

3
Graphics / Re: sf::VertexArray with multiple sf::TriangeFans
« on: April 12, 2023, 01:47:59 pm »
class EnemyVertexArray : public sf::Drawable, sf::Transformable
{
public:
        EnemyVertexArray(const std::vector<Enemy>& enemies)
        {
                vertices.setPrimitiveType(sf::Triangles);
                vertices.resize(enemies.size() * 30 * 3);

                while(endIndex < enemies.size() * 30 * 3)
                {
                        for (size_t i = startIndex; i < endIndex; i += 3)
                        {
                                vertices[i].position = enemies[enemy].getPosition();
                                vertices[i + 1].position = vertices[i].position + sf::Vector2f{ cosf(angle) * 10.f, sinf(angle) * 10.f };
                                angle += ANGLE_INCREASE_RADIAN;
                                vertices[i + 2].position = vertices[i].position + sf::Vector2f{ cosf(angle) * 10.f, sinf(angle) * 10.f };
                        }

                        startIndex = endIndex;
                        endIndex = startIndex + 90;
                        enemy++;
                }
        }
private:
        virtual void draw(sf::RenderTarget& rt, sf::RenderStates states) const
        {
                states.transform *= getTransform();
                rt.draw(vertices, states);
        }

        size_t startIndex = 0;
        size_t endIndex = startIndex + 90;
        const float ANGLE_INCREASE_RADIAN = 0.22439947525510914f;
        float angle = 0.f;
        size_t enemy = 0;
        sf::VertexArray vertices;
};
 

It's constructed every frame because I need to check for collisions with bullets. I know it probably can be done better but I wanted something that works for now, but the performance is horrible.

4
Graphics / Re: sf::VertexArray with multiple sf::TriangeFans
« on: April 12, 2023, 11:53:58 am »
I did just that, performance got even worse. Why? I thought draw calls are expensive?

5
Graphics / sf::VertexArray with multiple sf::TriangeFans
« on: April 12, 2023, 02:33:11 am »
Hi!
I want to draw a VertexArray of TriangleFan(s), I kinda got it to work but it does not behave as I would want it to. It connects every TriangleFan with another. First picture shows how it's done with 1000 draw calls.  Second shows how it behaves using VertexArray. Is it possible to do so that they are not connected?
Thank you for help.

Pages: [1]
anything