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

Author Topic: inconsistent fps  (Read 3034 times)

0 Members and 1 Guest are viewing this topic.

ColdMist

  • Newbie
  • *
  • Posts: 5
    • View Profile
inconsistent fps
« on: November 25, 2013, 01:40:47 am »
when running the program in the initial 2-10 sec the frame rate is around 10
but then jumps to 60
but sometimes it doesn't jump up to 60 fps
forcing me to restart the program
now my 4th loop is no different from 5th loop or the 30th loop
which is why i don't think this is a code problem
also checking windows task manager when it is running at 10 fps the cpu usage is around 100%
but when its around 60 fps the cpu usage is way less then 30%
so basically i have no clue what the problem is
language is c++
os windows 7



any help is appreciated =)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: inconsistent fps
« Reply #1 on: November 25, 2013, 08:33:53 am »
Although it might not seem like an issue with your code, you should still provide a minimal and complete example, that way we can confirm, that's not related to the code.

For instance if you're mixing setFramerateLimit and VSync you can get odd issues. Regarding that, are you limiting your framerate somehow?
Do you have an anti-virus running?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ColdMist

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: inconsistent fps
« Reply #2 on: November 25, 2013, 05:17:15 pm »
well i am using window.setFramerateLimit(60) but commenting it out doesn't seem to do anything

my program has over 700 lines of code so i wouldn't know what to show

in the initial loop

what it does is it takes bunch of images of my computer and rescales them

after that it doesn't do much



eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: inconsistent fps
« Reply #3 on: November 25, 2013, 05:21:06 pm »
Well you don't just show what you think is important, but you either start with a empty file and copy code in that will compile and does reproduce the issue OR you start with the current code base and take away part, while still compiling and reproducing the issue. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Josh_M

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: inconsistent fps
« Reply #4 on: November 26, 2013, 07:29:18 am »
You could try running the code through a profiler for the slow period, then you can see which calls are taking a really long time initially.



ColdMist

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: inconsistent fps
« Reply #5 on: November 30, 2013, 08:32:41 pm »
sorry for late respond :/

i figured out the code that made it slow
it goes something like this

        sf::RectangleShape Grect;
        sf::RectangleShape Brect;
        Brect.setSize(sf::Vector2f(50,50));
        Brect.setFillColor(sf::Color::Color(0,0,150));

        Grect.setSize(sf::Vector2f(50,50));
        Grect.setFillColor(sf::Color::Color(0,200,0));
void drawrect()
{
for(int i=0; i<900; i++)
{



        Brect.setPosition(x(i),y(i));
        Grect.setPosition(x(i),y(i));
        window.draw(Brect);
        window.draw(Grect);

}
}
 

so basically it just draws the same square multiple times at different positions
its kinda weird that it only slows it down initially given that i am always running this code
but any way is there any better way of doing this ?
« Last Edit: November 30, 2013, 10:40:14 pm by ColdMist »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: inconsistent fps
« Reply #6 on: November 30, 2013, 10:39:30 pm »
Probably some caching is happening somewhere, thus the fps goes up after a bit.

For such "static" objects you're best off using a VertexArray, which will only need one draw call, thus accelerating things very quickly.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ColdMist

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: inconsistent fps
« Reply #7 on: December 01, 2013, 12:04:03 am »
hmm i tried to read up on it and played around with it but could only make it work with lines  :-\
sf::VertexArray lines(sf::LinesStrip, 4);
        lines[0].color=sf::Color(255,33,33);
        lines[0].position = sf::Vector2f(10, 0);
        lines[1].position = sf::Vector2f(20, 0);
        lines[2].position = sf::Vector2f(30, 5);
        lines[3].position = sf::Vector2f(40, 2);
        window.draw(lines);
 

but couldn't really get it to work with rectangles i tried
sf::VertexArray squares(sf::RectangleShape, 4);
and stuff like that
so i was wondering how do i do it ?
« Last Edit: December 01, 2013, 12:12:43 am by ColdMist »

ColdMist

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: inconsistent fps
« Reply #8 on: December 01, 2013, 01:18:23 am »
nvm found out how to do it just a little tired btw thx allot =)

 

anything