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

Author Topic: GetFrameTime returns values in the order of 0.15 seconds  (Read 2349 times)

0 Members and 1 Guest are viewing this topic.

NordCoder

  • Newbie
  • *
  • Posts: 6
    • View Profile
GetFrameTime returns values in the order of 0.15 seconds
« on: November 05, 2010, 09:22:40 pm »
Hi all,

First up, I would like to congratulate the creators of SFML on a very good job!

This is my first time using SFML. I have had experience with SDL (+OpenGL) and C#/XNA. I am using MSVC++ 2008 on a laptop (Graphics: Mobile Intel(R) 965 Express Chipset Family and Processor: Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz)

Anyways, I tried creating a small intro to a space shooter (with logos fading in and out etc.). I create 4 images and 4 sprites and set each image to their respective sprite. The code was taken from another project of mine.

I ran the program and saw that it was running very slowly. I printed out the values returned by RenderWindow::GetFrameTime() and they were in the order of ~0.15 seconds. I tried running it in Release mode, but only got a small improvement at ~0.13-0.14 seconds. I then tried copying the executable to my gaming computer and the values were on the order of ~0.001 (that computer just broke down just now though :( but I'm pretty sure it was around those values).

It seems my computer is too slow, but I can run games like WC3 and SDL + OpenGL projects without issues. Maybe there is another problem?

I tried commenting out my draw code and the speed went up to the order of running in Release mode. Here is my drawing code (I used to pass a reference to my render window, but that is now public/static for global access):

Code: [Select]

if(currentLogo == 1)
Game::renderWindow.Draw(StormGamesLogoSprite);
else if(currentLogo == 2)
Game::renderWindow.Draw(SfmlLogoSprite);
else
Game::renderWindow.Draw(LuaLogoSprite);

Game::renderWindow.Draw(FaderSprite);

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
GetFrameTime returns values in the order of 0.15 seconds
« Reply #1 on: November 05, 2010, 10:03:33 pm »
How are you making the logos fade in and out? Could be that you are remaking/copying an entire image each frame.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

NordCoder

  • Newbie
  • *
  • Posts: 6
    • View Profile
GetFrameTime returns values in the order of 0.15 seconds
« Reply #2 on: November 05, 2010, 10:17:33 pm »
Hi Groogy,

One of the images is just black and I simply change its alpha value. I tried commenting out the update function which changes the alpha value, but it did not improve. If it has any relevance, I'm changing the alpha value with the following call:

Code: [Select]

FaderSprite.SetColor(sf::Color(255, 255, 255, alpha * 255));

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
GetFrameTime returns values in the order of 0.15 seconds
« Reply #3 on: November 05, 2010, 10:20:48 pm »
Quote from: "NordCoder"
Hi Groogy,

One of the images is just black and I simply change its alpha value. I tried commenting out the update function which changes the alpha value, but it did not improve. If it has any relevance, I'm changing the alpha value with the following call:

Code: [Select]

FaderSprite.SetColor(sf::Color(255, 255, 255, alpha * 255));


Well obviously not there. The thing I'm thinking is that you are copying images every frame or doing some unnecessary work every frame which should be done only once since it's going so slow. It's a common mistake, I think... I've done it at least.

Your sure your not somehow copying an image by mistake? Is it possible for you to summarize your rendering/frame/main loop? Or even provide the code for it?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

NordCoder

  • Newbie
  • *
  • Posts: 6
    • View Profile
GetFrameTime returns values in the order of 0.15 seconds
« Reply #4 on: November 06, 2010, 11:21:50 am »
I checked my code again and I don't see that I am copying images anywhere.

Here's the updating and drawing part of my Game class:

Code: [Select]

void Game::Think()
{
if(States.back())
States.back()->Update(renderWindow.GetFrameTime());
}


Code: [Select]

void Game::Draw()
{
renderWindow.Clear();

if(States.back())
{
if(States.back()->IsPopup() && States.size() > 1)
{
if(States[States.size() - 2])
States[States.size() - 2]->Draw();
}

States.back()->Draw();
}

renderWindow.Display();
}


and the loading of the IntroState class (checked that it is only called once):

Code: [Select]

bool IntroState::Load()
{
if(!Fader.LoadFromFile("./Graphics/Images/Fader.png"))
return false;

if(!StormGamesLogo.LoadFromFile("./Graphics/Images/StormGamesLogo.png"))
return false;

if(!SfmlLogo.LoadFromFile("./Graphics/Images/SDLlogo.png"))
return false;

if(!LuaLogo.LoadFromFile("./Graphics/Images/StormGamesLogo.png"))
return false;

FaderSprite.SetImage(Fader);
StormGamesLogoSprite.SetImage(StormGamesLogo);
SfmlLogoSprite.SetImage(SfmlLogo);
LuaLogoSprite.SetImage(LuaLogo);

FaderSprite.SetColor(sf::Color(255, 255, 255, alpha * 255));

return true;
}


I'm using a type of state management where each state is a mini-application. The Game class manages a std::vector<GameState*> container. Hope it all makes sense :)

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
GetFrameTime returns values in the order of 0.15 seconds
« Reply #5 on: November 06, 2010, 11:55:39 am »
Yeah, nothing there looks weird. But you've done wrong somewhere, just needs to find it. I made a similar system in Ruby with Rubygame which is slower than C++ and SFML so SFML isn't doing this. We'll need to find what you've missed.

Your IntroState isn't doing anything else each frame? For instance what do it do in Update?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

NordCoder

  • Newbie
  • *
  • Posts: 6
    • View Profile
GetFrameTime returns values in the order of 0.15 seconds
« Reply #6 on: November 06, 2010, 10:18:08 pm »
It's just updating which images should be drawn and so on. I already tried commenting out the Update function without any success. I am beginning to think the problem maybe lies in the versions of OpenGL (no idea..)/SFML (1.6)?

I will continue to look through the code and test it out.

Thanks for your input so far :)

 

anything