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

Author Topic: animation drop frame rate from 60 to 10fps?  (Read 2162 times)

0 Members and 1 Guest are viewing this topic.

Fantasy

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
animation drop frame rate from 60 to 10fps?
« on: November 01, 2011, 07:29:06 pm »
Hello guys
what do you think of my animation? it works perfectly, but i though maybe someone has some comments on the code. is there a better way to code it. any advice you can give me is much appreciated.

[Added]
ok i have discovered something where if you use this code with a lot of images, the frame rate drops from 60fps to 10fps and the gpu usage go to 70-90%.

and i have a 5970 graphic card with two gpus !!
any idea how to solve this problem?


[Added last (New)]
very very weird problem. if i add this line of code the frame drop from 60FPS to 7FPS !!!!!

Code: [Select]

std::cout<< clock.GetElapsedTime()<< "\n";  //DROP FRAME RATE



feel free to use this code in your project.
Code: [Select]

#include <SFML\Graphics.hpp>
#include <iostream>

int main()
{
sf::Image image1, image2, image3, image4, image5;
sf::Sprite sprite1;

image1.LoadFromFile("water1.png");
image2.LoadFromFile("water2.png");
image3.LoadFromFile("water3.png");
image4.LoadFromFile("water4.png");
image5.LoadFromFile("water5.png");

sprite1.SetImage(image1);

sprite1.SetPosition(200,200);

    sf::RenderWindow window(sf::VideoMode(800, 600, 32), "sftool::animation sample");

sf::Clock clock;

    while (window.IsOpened())
    {
        sf::Event Event;
window.SetFramerateLimit(60);

        while (window.GetEvent(Event))
        {

        }

float time1 = clock.GetElapsedTime();
float time2 = clock.GetElapsedTime();
float time3 = clock.GetElapsedTime();
float time4 = clock.GetElapsedTime();
float time5 = clock.GetElapsedTime();

std::cout<<time1 << "\n";

        // Draw everything.
        window.Clear();

window.Draw(sprite1);

if(time1 >= 0.2)
{
sprite1.SetImage(image2);
window.Draw(sprite1);
}

if(time2 >= 0.6)
{
sprite1.SetImage(image3);
window.Draw(sprite1);
}

if(time3 >= 1.0)
{
sprite1.SetImage(image4);
window.Draw(sprite1);
}

if(time4 >= 1.4)
{
sprite1.SetImage(image5);
window.Draw(sprite1);
clock.Reset();
}

        window.Display();
    }
 
    return EXIT_SUCCESS;
}
[/code]

Haikarainen

  • Guest
animation drop frame rate from 60 to 10fps?
« Reply #1 on: November 02, 2011, 06:06:30 am »
std::cout is a heavy operation(belive it or not) and you should never use it every frame. Delete all std::cout lines and give us your framerate!

Edit; Also, why are you doing this:

Code: [Select]
     float time1 = clock.GetElapsedTime();
      float time2 = clock.GetElapsedTime();
      float time3 = clock.GetElapsedTime();
      float time4 = clock.GetElapsedTime();
      float time5 = clock.GetElapsedTime();

instead of just
Code: [Select]
     float time = clock.GetElapsedTime();
and
Code: [Select]
     if(time >= 1.0)
?

Fantasy

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
animation drop frame rate from 60 to 10fps?
« Reply #2 on: November 02, 2011, 08:32:42 am »
Quote from: "Haikarainen"
std::cout is a heavy operation(belive it or not) and you should never use it every frame. Delete all std::cout lines and give us your framerate!

Edit; Also, why are you doing this:

Code: [Select]
     float time1 = clock.GetElapsedTime();
      float time2 = clock.GetElapsedTime();
      float time3 = clock.GetElapsedTime();
      float time4 = clock.GetElapsedTime();
      float time5 = clock.GetElapsedTime();

instead of just
Code: [Select]
     float time = clock.GetElapsedTime();
and
Code: [Select]
     if(time >= 1.0)
?


Wow never thought that std::cout is a heavy operation.
i deleted std::cout and my frame rate went back to 60FPS.
the resone i did this
Code: [Select]
     float time1 = clock.GetElapsedTime();
      float time2 = clock.GetElapsedTime();
      float time3 = clock.GetElapsedTime();
      float time4 = clock.GetElapsedTime();
      float time5 = clock.GetElapsedTime();

hmm... to think of it again i really don't need all of this :D, i don't know what i was thinking LOL :D.
it was 3am in the morning and i was really tired, so that's why i did this i guess xD.

thanks

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
animation drop frame rate from 60 to 10fps?
« Reply #3 on: November 02, 2011, 03:09:58 pm »
Your doing one of the most common newbie mistakes when trying to make animations. I recommend that you take a look at the different animation classes available on the old wikipedia
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

 

anything