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 - nameless_987

Pages: [1]
1
Graphics / Re: unefficient drawing
« on: February 08, 2022, 01:08:44 am »
The Sleep(1); is sleeping for 1 millisecond it's because i didn' set a limit to the framerate (I think) when the pc goes too fast throught the loop : dt = 0 so the Sleep(1); gets the value of dt to at least 1.
And thank you to fallahn it works perfectly.

2
Graphics / unefficient drawing
« on: February 05, 2022, 05:46:52 am »
Hello,
I am working on a random project where i need to have a code as efficient as possible so i tried to check if the way I draw is efficient enough but it isn't.
I saw people how draw millions of points whie still having a decent amount of FPS but I can't draw more than around 200000 points.
I tried with circles, recangles, convexs, rectangles with the size of a pixel but it never gets better.
If you have a solution I would be happy to here it.
Here is the code :

    while(window.isOpen()){
        window.clear();
        while(window.pollEvent(event)){
            if((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Enter) && (!fullscreen)) {
                                fullscreen = true;
                                window.create(VideoMode(1920, 1080), nameProject, (fullscreen ? Style::Fullscreen : Style::Resize|Style::Close));
                        }
            else if((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Escape) && (fullscreen)) {
                                fullscreen = false;
                                window.create(VideoMode(1920, 1080), nameProject, (fullscreen ? Style::Fullscreen : Style::Resize|Style::Close));
                        }
            if((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Space) && (fullscreen)) {
                pause = !pause;
                        }
            if(event.type == Event::Closed){
                window.close();
            }
        }

        float dt = gameClock.getElapsedTime().asSeconds();
        gameClock.restart();

        for(int i=0; i<player.size(); i++){
            if(fullscreen && !pause){
                player[i].x+=player[i].vx*dt;
                player[i].y+=player[i].vy*dt;

                if(player[i].x < player[i].r){
                    player[i].x += 2*(player[i].r-player[i].x);
                    player[i].vx *= -1;
                }
                else if(player[i].x > window.getSize().x-player[i].r){
                    player[i].x += 2*(window.getSize().x-player[i].r-player[i].x);
                    player[i].vx *= -1;
                }
                if(player[i].y < player[i].r){
                    player[i].y += 2*(player[i].r-player[i].y);
                    player[i].vy *= -1;
                }
                else if(player[i].y > window.getSize().y-player[i].r){
                    player[i].y += 2*(window.getSize().y-player[i].r-player[i].y);
                    player[i].vy *= -1;
                }
            }
            if(fullscreen){
                player[i].body.setPosition(player[i].x-player[i].r, player[i].y-player[i].r);
                window.draw(player[i].body);
            }
        }

        window.display();
        Sleep(1);
    }

3
Graphics / SFML how to draw a line
« on: January 24, 2022, 07:49:27 pm »
Hello, I had a problem to draw a line so I made a function with convex and I thought maybe you coul add this feature, here is the code :
// a = x1 ; b = y1 ; c = x2 ; d = y2 ; e = thickness
void line(float a, float b, float c, float d, float e){
    ConvexShape convex;
    convex.setPointCount(4);
    if(c-a == 0){
        convex.setPoint(0, Vector2f(a-e/2, b));
        convex.setPoint(1, Vector2f(a+e/2, b));
        convex.setPoint(2, Vector2f(c+e/2, d));
        convex.setPoint(3, Vector2f(c-e/2, d));
    }
    else{
        float alpha = atan((d-b)/(c-a));
        convex.setPoint(0, Vector2f(a-(e/2)*sin(alpha), b+(e/2)*cos(alpha)));
        convex.setPoint(1, Vector2f(a+(e/2)*sin(alpha), b-(e/2)*cos(alpha)));
        convex.setPoint(2, Vector2f(c+(e/2)*sin(alpha), d-(e/2)*cos(alpha)));
        convex.setPoint(3, Vector2f(c-(e/2)*sin(alpha), d+(e/2)*cos(alpha)));
    }
   
    window.draw(convex);
}

Pages: [1]