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

Author Topic: Why is my program using SFML so slow?  (Read 4745 times)

0 Members and 2 Guests are viewing this topic.

blindley

  • Newbie
  • *
  • Posts: 12
    • View Profile
Why is my program using SFML so slow?
« on: July 11, 2011, 10:39:46 pm »
I began developing a C++ wrapper over SDL here:

https://github.com/blindley/Zik-Multimedia-Library

I'm also working on a clone of Space Invaders to test it, here:

https://github.com/blindley/Space-Invaders

I was about to work on the input system, then I learned about SFML, which basically does everything I want in my library to do.  So I decided to branch my Space Invaders clone, but using SFML instead, here:

https://github.com/blindley/Space-Invaders/tree/use-sfml

However, when I compiled it, it was very choppy.  I reduced the number of aliens from 50 to 1, and it didn't help.  I added a frame counter(very convenient that a default font is included by the way) and it's at ~11-12 frames per second.

The only differences between the SDL version and the SFML version are the SpaceInvaders::PlayArea::draw function, here:

https://github.com/blindley/Space-Invaders/blob/use-sfml/source/PlayArea.cpp

And the SpaceInvaders::Main function, here:

https://github.com/blindley/Space-Invaders/blob/use-sfml/source/SpaceInvaders.cpp

Can anybody see anything I am doing inefficiently (SFML-wise) that could be causing this slowness?  My computer is not top of the line by any means, but there's no excuse for these framerates on such a simple program.  Right now, all it's doing is displaying a square going back and forth across the screen.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Why is my program using SFML so slow?
« Reply #1 on: July 11, 2011, 11:25:02 pm »
After skimming through those two functions, I haven't seen a fundamental mistake in your code. Have you tried to find out which parts are slow? You could do that by commenting out code and/or by measuring time.

By the way, nice that you already use that many C++11 features :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Why is my program using SFML so slow?
« Reply #2 on: July 11, 2011, 11:44:50 pm »
That's a stupid questions but... do you test in debug or release mode?
Laurent Gomila - SFML developer

blindley

  • Newbie
  • *
  • Posts: 12
    • View Profile
Why is my program using SFML so slow?
« Reply #3 on: July 11, 2011, 11:57:58 pm »
Okay.  Results not good.

I comment out the both the drawing and the updating of my playArea object. (That's pretty much the entire contents of the 'game' outside of the boilerplate stuff).  No improvement.

Then I comment out the updating and displaying of the frame counter, and replace it with console output so I can still see the framerate.  Slight improvement there, ~0.5-1.5 fps.  Mind you, all I have now is an 800x600 black screen refreshing at ~12.5 frames per second.

I comment out the clearing of the window, + ~1 fps.

Then the event handling, doesn't help.

Finally, I comment out window.Display(), and I get + ~1500 fps.

Obviously, I can't take that out.

@Laurent: Release mode.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Why is my program using SFML so slow?
« Reply #4 on: July 12, 2011, 12:04:04 am »
Did you link the correct SFML libraries? Are your configurations (debug/release, SFML static/dynamic link, CRT static/dynamic link) consistent with the way you built SFML?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Why is my program using SFML so slow?
« Reply #5 on: July 12, 2011, 12:06:27 am »
Seriously? Does it happen too with a minimal example (just a window, a loop and Display() inside)? What about the official examples (OpenGL, Window, Pong)?

Have you tried to use an external FPS counter (like FRAPS)?
Laurent Gomila - SFML developer

blindley

  • Newbie
  • *
  • Posts: 12
    • View Profile
Why is my program using SFML so slow?
« Reply #6 on: July 12, 2011, 12:13:08 am »
Okay.  I fixed the problem.  I may have wasted your guys' time.  Sorry.  I'm still confused though.  It seems I just had too many programs open.  So I closed them all, and the fps shot up to 300.

The thing that confuses me though, is now I've reopened all those programs, and the fps is still up around 300, they were mostly idle programs, nothing taxing.  Not really SFML's problem, I guess it's just something with my computer that I'll need to figure out.

Thanks for the quick replies anyway.

 

anything