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

Author Topic: Sigvatr's Newbie Thread  (Read 21280 times)

0 Members and 1 Guest are viewing this topic.

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« on: September 03, 2009, 11:41:27 am »
I figured I'd make a thread for this in general because I have a lot of questions to ask all the time that sometimes go into separate sub-forums, so I figured I'd just save space by keeping all of my questions in one thread.

Today's question: Does SetFramerateLimit apply only to graphics rendering or to code that runs in a Window in general? Is there an easy way to distinguish the rendering code from the logic code, say if I want some code to run at unlimited FPS and have the screen update at a rate of 6fps?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sigvatr's Newbie Thread
« Reply #1 on: September 03, 2009, 01:44:06 pm »
Quote
I figured I'd make a thread for this in general because I have a lot of questions to ask all the time that sometimes go into separate sub-forums, so I figured I'd just save space by keeping all of my questions in one thread.

Well, it's not a matter of saving space (it's all virtual space ;)), it's more important to get topics properly categorized / entitled so that other people can easily know what you're talking about, or find relevant informations.

But anyway, it's ok if you prefer doing things like this.

Quote
Does SetFramerateLimit apply only to graphics rendering or to code that runs in a Window in general?

The framerate limit applies to the thread in which window.Display() is called. No matter what was done before, when call window.Display() your current thread will sleep for a while in order to adapt to the framerate limit.

Quote
Is there an easy way to distinguish the rendering code from the logic code, say if I want some code to run at unlimited FPS and have the screen update at a rate of 6fps?

You have to handle it yourself. Usually, threads are used to create separate flows that can run at their own speed. But they introduce a complexity in your program that you probably don't want.
Laurent Gomila - SFML developer

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #2 on: September 04, 2009, 05:34:03 pm »
Alright, the way I've been thinking of making this work is as follows.

This is how an ordinary application with both a 60fps logic and rendering code would go:

Code: [Select]
SYS.SetFramerateLimit(60);
while(SYS.IsOpened())
{
    // All of the game logic here

    // Render code here
}


What I want to do is have some parts of my logic to run at 60fps and some of it to run as fast as the machine can go.

So would I be able to do something like this?

Code: [Select]
SYS.SetFramerateLimit(60);
bool gameRunning = true;
while( gameRunning = true )
{
    // Machine speed game logic here

    if(SYS.IsOpened())
    {
        // 60fps game logic here

        // Render code here
    }
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sigvatr's Newbie Thread
« Reply #3 on: September 04, 2009, 05:40:47 pm »
No, the execution flow is sequential so anything which is in the same thread will be affected by the FPS limit.

And "SYS.IsOpened()" will always evaluate to true until you close your application so there's absolutely no difference between your two loops.

You must use threads to have separate flows of execution.
Laurent Gomila - SFML developer

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #4 on: September 04, 2009, 05:42:16 pm »
So basically all of the code that runs in my int main() is going to run at the frame limit unless I make threads?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sigvatr's Newbie Thread
« Reply #5 on: September 04, 2009, 05:50:16 pm »
Your loop looks like this:
Code: [Select]
while (running)
{
   ...

   sleep(x); // stops for a while

   ...
}


So yes, everything inside will be affected by the pause.
Laurent Gomila - SFML developer

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #6 on: September 04, 2009, 06:03:43 pm »
Basically what I am trying to do is provide my own built in music tracking format (which supports randomly generated music in game). All instruments are loopable, but they don't necessarily loop back to the beginning of the sample but to a predefined position in the sound file that I have to specify manually so that the looping is smooth and has no clicks or fuzz in them. Because of the very precise time scales that this looping requires (in some cases 0.001 of a second or less) I have deduced that running the music code in the frame limited game code won't allow me those very precise time specifications for the looping to sound right.

Do you have any other ideas that might over come this, or do you think that threading is necessary for this to work properly? I don't have a problem with figuring out threads if I need to do so, since this is a multiplayer game I am going to have to get around to threading eventually anyway.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Sigvatr's Newbie Thread
« Reply #7 on: September 04, 2009, 06:34:04 pm »
Using a separate thread for audio-specific stuff sounds good, and I think there's no other solution anyway.
Laurent Gomila - SFML developer

Meltra Bour

  • Newbie
  • *
  • Posts: 28
    • View Profile
Sigvatr's Newbie Thread
« Reply #8 on: September 04, 2009, 08:11:32 pm »
hmm, just thinking out loud here. Way not something like ...

Code: [Select]
sf::Window win;
sf::Clock drawTimer;

while( win.IsOpened() )
{
    // Machine speed game logic here

    if(drawTimer.GetElapsedTime() > 0.016666)
    {
        drawTimer.Reset();

        // 60fps game logic here
        // Render code here
    }
}


If you need 0.001 timers you need to make sure your render/logic loop never takes longer then that. That said, separate threads sound like a better solution but this could do the trick if you don't wane mess with threads yet.

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #9 on: September 06, 2009, 12:54:46 am »
I have a few new questions.

No matter what I am setting my Framerate Limit to, I am always getting incorrect readings, and they vary depending on the system I am using.

When I run the app on my laptop (Vista, dual core), my FPS counter states a much higher frame rate per second than should actually be happening, up to 1.6 times higher than I have set it.

When I run the app on my PC (XP, quad core), my FPS counter states a much lower frame rate, around half of what it should be.

They both have a refresh rate of 60hz.

I am using the same code on both computers, and the FPS code I am using is exactly the same as the one in the timing tutorial.

Anyone know what could be screwing this up?

My second question is about the render window not displaying when my app goes out of sync. If my computer changes screen resolutions or alt tabs another application over my app and then back, the window will not update, it just appears either black or an empty window, period.

Anyone know what is wrong?

phear-

  • Jr. Member
  • **
  • Posts: 64
    • MSN Messenger - LOApokalypse@hotmail.com
    • View Profile
    • http://gtproductions.org
Sigvatr's Newbie Thread
« Reply #10 on: September 06, 2009, 02:35:15 am »
If your trying to limit your FPS to 60, then turn v-sync on. Although its wierd because at times on my windows 7 desktop i get bursts of frames up to 13k even though it mostly stays at 60fps, while on my vista laptop it always stays at 60
Eugene Alfonso
GTP | Twitter

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #11 on: September 06, 2009, 10:05:25 am »
I'm trying to set FPS to 320 for some logic code.

Is it possible to set threads to run at a specified speed?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Sigvatr's Newbie Thread
« Reply #12 on: September 06, 2009, 11:46:43 am »
You can manage the speed of your loops yourself : use sleep function to not go too fast.

PS : is the above sentence grammatically correct ?
SFML / OS X developer

Sigvatr

  • Newbie
  • *
  • Posts: 32
    • MSN Messenger - msn@sigvatr.com
    • AOL Instant Messenger - SigvatrAIM
    • View Profile
    • http://www.sigvatr.com
Sigvatr's Newbie Thread
« Reply #13 on: September 06, 2009, 01:37:49 pm »
Can anyone point me towards anything that will explain to me how to use bitmap fonts?

I want to import my font from a graphical image and not a TTF.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Sigvatr's Newbie Thread
« Reply #14 on: September 06, 2009, 03:25:40 pm »
google, but why don't you want to use ttf files ?
SFML / OS X developer