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 - Sythical

Pages: [1]
1
General / Few questions about using fix timestep for physics
« on: July 13, 2013, 11:16:14 am »
Hello, I've been trying to implement the fix time-step technique and I'm having trouble understanding a couple of thing. I've listed the two issues separately so that they make more sense.

i) To interpolate between the old and the new state, I'm using two variables called old_pos_x and new_pos_x. Originally, I would copy new_pos_x to old_pos_x after rendering each time. This makes more sense to me since I want to interpolate between the circle on the screen and the one I'll be drawing next. However, this makes the animation stutter if I don't update the physics at 60 or 120 hertz (multiples of my refresh rate).

When I moved the copy statement inside the physics loop, the stutter goes away and I have no idea why. I would have thought that this will make the game stutter a lot more, especially when the the frame rate is lower than the update rate. Why does this work?

ii) I added Sleep(5) after the render bit in order to decrease the FPS to about 200 so that I can see how it works at low rates. The animation becomes very jumpy and not smooth at all. I understand that Sleep() isn't accurate but surely that shouldn't matter as long as the frame rate is above 60 FPS because of the monitor's refresh rate.

I've written a smaller version of the program which replicates the issue(s) so that it's easier to read. It's just a circle that moves horizontally. The code is still a bit long, sorry about that.

unsigned screen_width = 1200, screen_height = 800;
int old_pos_x = 100, new_pos_x = 100, velocity_x = 0;
LARGE_INTEGER counter, frequency;

LONGLONG
    accumulator = 0, accumulator_max, physics_delta,
    time_difference, new_time, previous_time;

sf::RenderWindow window(sf::VideoMode(screen_width, screen_height), "Example", sf::Style::Titlebar | sf::Style::Close);

sf::CircleShape graphics(15.f);
graphics.setFillColor(sf::Color(255, 255, 255));

QueryPerformanceFrequency(&frequency);
physics_delta = frequency.QuadPart / 50;
accumulator_max = physics_delta * 5;

QueryPerformanceCounter(&counter);
previous_time = counter.QuadPart;

while(window.isOpen()) {
    QueryPerformanceCounter(&counter);

    new_time = counter.QuadPart;
    time_difference = new_time - previous_time;
    previous_time = new_time;
    accumulator += time_difference;

    if(accumulator > accumulator_max) {
        accumulator = accumulator_max;
    }

    while(accumulator >= physics_delta) {
        if(new_pos_x > 1000) velocity_x = -8;
        else if(new_pos_x < 200) velocity_x = 8;

        // if I copy the new state (position) to the old state here instead the animation is much more smooth
        // but I don't understand why this is the case, I would have thought that this is more likely to cause stutter
        // especially if the frame rate is lower than the game update rate

        // old_pos_x = new_pos_x; // copy the current state to the old one
        new_pos_x += velocity_x; // update the current state

        accumulator -= physics_delta;
    }

    double interpolation_val = accumulator / (double) physics_delta;
    graphics.setPosition(new_pos_x * interpolation_val + old_pos_x * (1 - interpolation_val), 400.f);

    window.clear();
    window.draw(graphics);
    window.display();

    // this is where I was originally copying the new state (position) to the old state
    // this makes more sense to be because I want to interpolate between the last drawn circle
    // and the current circle

    old_pos_x = new_pos_x;

    // Sleep(5);
}

I'd be very grateful if someone can have a read through the code. Thank you  :)



2
Graphics / Re: Are off-screen objects rendered?
« on: July 02, 2013, 03:19:09 am »
Okay, that does make sense. Thank you for your help!

3
Graphics / Re: Are off-screen objects rendered?
« on: July 02, 2013, 03:04:19 am »
Thank you for your answer :)

Sorry, yes I meant processed instead of rendered. Doesn't this mean that using sf::View is a bad idea, since in larger maps a lot of unnecessary stuff will be drawn? Or are the graphics cards good enough that I shouldn't be worrying about this when making 2D games?

4
Graphics / Are off-screen objects rendered?
« on: July 02, 2013, 02:37:57 am »
Hello, let's say if I draw a 50 by 50 rectangle at (-200, -200), will SFML actually draw the rectangle or simply ignore it since the rectangle won't be visible on the screen. I'm asking this because at the moment I am only drawing sprites that will be visible but now I'm not sure if there is any point in checking.

Thank you :)

5
Graphics / Re: Suggestion for displaying text
« on: June 19, 2013, 09:18:52 pm »
@Polyfructol
Thank you, your response is very helpful. I tried the fonts you suggested and the text is pretty crisp now so I'll use them. An interesting thing I noticed is that the text is much clearer when I use Arial size 32 and scale it by half instead of just using Arial size 16.

I'll have a look at the Font.cpp file later on, I wonder is there is anything planned for fonts in 2.1 ^^

Thank you once again :)

6
Graphics / Suggestion for displaying text
« on: June 19, 2013, 07:07:17 pm »
Hello, in the game I'm making I need to display small text (around size 10) on the screen. The problem I'm having is that the text displayed by SFML is a bit blurry. I've searched the forums and from what I can tell, there is no easy solution available so I was wondering how do people get around this issue. Are there any other methods to display text in the SFML window?

Thank you

7
General discussions / Re: A new logo for SFML
« on: April 22, 2013, 04:10:45 pm »
But maybe kerning between l and icon should be the same as between letters.

Yes you're right, not sure why I didn't adjust the spacing.

What typeface is this?

I font I used is Segoe UI.

8
General discussions / Re: A new logo for SFML
« on: April 22, 2013, 06:53:27 am »
Thank you for the kind words Ricky :)

I used lower case because they seem 'cleaner'. The larger triangle was me trying to add an arrow in to the logo and I then decided to add another triangle to make a compound shape (showing shapes can be broken down into triangles). Slightly larger version without the version number:


9
General discussions / Re: A new logo for SFML
« on: April 22, 2013, 12:06:39 am »
Just a random logo I drew in paint, not good at image editing.


Pages: [1]