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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Dr_Asik

Pages: [1]
1
Graphics / Sprites rendered approximately
« on: November 05, 2009, 08:35:52 am »
Thanks for the follow-up.

What confused me is that left/top are included, but bottom/right are excluded. The only way I could figure that out was through experimentation, and I was lucky to be using very small sprites, I might not have noticed a one pixel difference with larger ones.

Either have bottom/right included, or do it like XNA, IMO you can't go wrong with how XNA does things.  :)

2
Graphics / Sprites rendered approximately
« on: November 05, 2009, 03:10:39 am »
Oh, thanks, wouldn't have guessed that.

By the way, the behavior for specifying the sub rectangle is a bit non-intuitive. When I type

sprite.SetSubRect(IntRect(

Intellisense tells me that the four parameters are:

LeftCoord, TopCoord, RightCoord, BottomCoord

So having a sprite in my spritesheet at [0-7], [0-7], I wrote:

sprite.SetSubRect(IntRect(0, 0, 7, 7));

But then it seemed I was missing a pixel right and one bottom. So I actually have to write this:

sprite.SetSubRect(IntRect(0, 0, 8, 8 ));

Which describes my sprite's sub rectangle as
[0-8[, [0-8[

A bit weird IMO. XNA was fool-proof:

Code: [Select]
public Rectangle (
         int x,
         int y,
         int width,
         int height
)

3
Graphics / Sprites rendered approximately
« on: November 05, 2009, 02:50:11 am »
I am coding a remake of Space Invaders, and my artwork is consequently very low-res. I need it to be drawn with pixel perfect accuracy.

I am using the Sprite class to draw my artwork to the screen, unfortunately, they appear blurry, even if I don't scale/rotate them. Is this a known issue with SFML?

4
General / Basic game loop question
« on: November 04, 2009, 08:35:15 am »
Damn, just found out one big mistake with the code I posted:

Code: [Select]
float timeBetweenFrames = 1000.0f / (float)updatesPerSecond_;

This will lead to a timeBetweenFrames 1000 times too large. :lol:  Should be:

Code: [Select]
float timeBetweenFrames = 1.0f / (float)updatesPerSecond_;

This explains the non-responsiveness of my first code example. So apparently it has nothing to do with polling for events only once per loop.

So, uh, problem fixed I guess.  :)

While we're at it, I have a question about the following article on
http://dewitters.koonsolo.com/gameloop.html

Here is the part I don't get:

Quote
Our first solution, FPS dependent on Constant Game Speed, has a problem when running on slow hardware. Both the game speed and the framerate will drop in that case. A possible solution for this could be to keep updating the game at that rate, but reduce the rendering framerate. This can be done using following game loop:

   
Code: [Select]
   const int TICKS_PER_SECOND = 50;
    const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
    const int MAX_FRAMESKIP = 10;
       
    DWORD next_game_tick = GetTickCount();
    int loops;
   
    bool game_is_running = true;
    while( game_is_running ) {

        loops = 0;
        while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) {
            update_game();
           
            next_game_tick += SKIP_TICKS;
            loops++;
        }
       
        display_game();
    }

The game will be updated at a steady 50 times per second, and rendering is done as fast as possible. Remark that when rendering is done more than 50 times per second, some subsequent frames will be the same, so actual visual frames will be dispayed at a maximum of 50 frames per second. When running on slow hardware, the framerate can drop until the game update loop will reach MAX_FRAMESKIP. In practice this means that when our render FPS drops below 5 (= FRAMES_PER_SECOND / MAX_FRAMESKIP), the actual game will slow down.


He says "The game will be updated at a steady 50 times per second, and rendering is done as fast as possible." However, looking at that code, it seems display_game() is called a maximum of once per loop, while update_game() may be called several times being in that inner while loop. In other words it looks like it is the contrary of what he's saying: the game will be updated as often as possible, while the rendering will take place a fixed number of times per second.

Am I right (I hope not)?

5
General / Basic game loop question
« on: November 04, 2009, 06:15:04 am »
Hello, I am coding my first non-XNA game and using SFML in C++. XNA took care of the game loop but now I have to code my own.

I have come up with this:

Code: [Select]
   Clock clock;
    float timeBetweenFrames = 1000.0f / (float)updatesPerSecond_;

    while (app_.GetEvent(event)) {
        if (event.Type == Event::Closed) {
            app_.Close();
        }
    }

    while (app_.IsOpened()) {
        clock.Reset();
        Event event;

        update(timeBetweenFrames);
        draw(timeBetweenFrames);

        while (clock.GetElapsedTime() < timeBetweenFrames) {
            sf::Sleep(0.0005f);
        }
    }
(Where app_ is a RenderWindow and updatesPerSecond_ is an int, here 60.)

The problem here is that the window becomes non-responsive. I don't really get it as events will still get processed [updatesPerSecond_] times per second (in my case 60). Do I really need to be constantly polling for events? In that case, wouldn't a dedicated thread be more appropriate?

In any case, I "fixed" the problem by removing the call to sleep and replacing it with constant polling of events.

Code: [Select]
   Clock clock;
    float timeBetweenFrames = 1000.0f / (float)updatesPerSecond_;


    while (app_.IsOpened()) {
        clock.Reset();
        Event event;

        update(timeBetweenFrames);
        draw(timeBetweenFrames);

        while (clock.GetElapsedTime() < timeBetweenFrames) {
            while (app_.GetEvent(event)) {
                if (event.Type == Event::Closed) {
                    app_.Close();
                }
            }
        }
    }


This is responsive, and draw and update should be called [updatesPerSecond_] times per second.

Still, I'm a bit lost. What if some part of my game needs to be updated as often as possible? For instance, the audio engine, or even just the graphics. Anytime I'm doing some game processing, I am not polling events, so will the window become non-responsive again?

Pages: [1]