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

Pages: [1]
1
General / Re: Fluent Movement
« on: October 05, 2016, 01:14:27 am »
I often try to understand what's happening by translating the code/varables into understandable statements.

This is what i get:
double t = 0.0; // time since beginning (useful for timed events/skill refresh/etc. would not work those times should be saved between sessions... then i don't get the point of know this
double dt = 0.01; // my fixed timegap for physics (0.01 seconds which basically means i have a tick rate of 100)

double currentTime = hires_time_in_seconds(); // used to calculate the actual timegap
double accumulator = 0.0; // used to accumulate time because the actual timegap is very often much lower then 0.01 seconds

State previous; // still don't get... why i'd need this here.. Probably abstraction
State current; // same as above

while ( !quit )
{
    double newTime = time(); // this is used to calculate the timegap
    double frameTime = newTime - currentTime; // this is the actual timegap
    if ( frameTime > 0.25 )  // why should we max it out to 0.25? If this happens, there's something strange...
        frameTime = 0.25;  // probably the only reason why this could happen if we have some heavy loading within the loop which should be avoided...
    currentTime = newTime; // this is used for the next timegap calculation clearly...

    accumulator += frameTime; accumulate timegap because it is often lower then 0.01

    while ( accumulator >= dt )
    {
        previousState = currentState; // still probably just some abstraction layer for states
        integrate( currentState, t, dt ); // why would the update method would need the current state.. the method should update the current state so it knows the current state or am i wrong here?
        t += dt; // accumulate t obiously
        accumulator -= dt; // so we had an actualy update gap so we have to lower the accumulator.. otherwise endless loop
    }

    const double alpha = accumulator / dt; // why?

    State state = currentState * alpha +
        previousState * ( 1.0 - alpha );  // why?

    render( state ); // rendering is "assuming" what will happen next with the currentState/Alpha/PreviousState thing.. this is a rather pretty complex task to do if you have ton's of informations going on here..
}
 

Maybe while i wrote this down i actually understand somewhat how this works..
Basically we try to do some assuming to what our next state will look like to interpolate the rendering.
Like if we move an object from 0 to 100 with a speed of 100 per second we can achive this fluently IF we have constant 0.01 timegap (ALWAYS).
Which is not the case so it could be, that we have, with any reason we don't now, accumulated about 0.05 timegap because of an update which just took more time... we would do 5 updates in the next loop which would lead to move the object 5 units with one step.

The whole problem is, if one update would tike 0.05 seconds, we would not even be able to draw in that time so the ball would always jump...
The only way to solve it, is to actually do the update not in the same thread as the drawing.
Because this code right obove, is in one thread, so if our update for example is doing a constant 30 fps because it takes so long, our drawing would take too 30 fps instead of 60 for example with VSync on a 60Hz monitor.

Please correct me if i understand something wrong here... I'm just confused.
The more i think about it the more sense does it make but in the same time it doesn't because of logic flaws in my head.

2
General / Re: Fluent Movement
« on: October 04, 2016, 07:39:50 pm »
Yeah i thought something like this could be the problem.
But i really don't get the pseudo code on the page. It seems like it's missing something and i don't get the idea behind it yet ...

Maybe i have to reread it a couple of times.

Why is t constantly increasing?
What's withing integrate( currentState, t, dt );? Is it the update function?
What's with that state things...

I'm not a native speaker, but state doesn't seem to fit in there...
I'll try to fiddle a bit with that "code" there.

3
General / Re: Fluent Movement
« on: October 04, 2016, 01:16:45 pm »
Hi Mario,

my Book covers exactly this "Fix your Timestep" thing.
So my updates are built exactly after your link's topic.

void Game::run()
{
        sf::Clock clock;
        sf::Time timeSinceLastUpdate = sf::Time::Zero;
        sf::Time cr = sf::Time::Zero;

        float secondsTimer = 0;
        float fps = 0;

        while (mWindow.isOpen())
        {
                cr = clock.restart();
                timeSinceLastUpdate += cr;
                secondsTimer += cr.asSeconds();
                fps = 1.f / cr.asSeconds();

                while (timeSinceLastUpdate > TimePerFrame)
                {
                        timeSinceLastUpdate -= TimePerFrame;
                        processEvents();
                        update(TimePerFrame);
                }

                if (secondsTimer > 1) {
                        mFps.setString(std::to_string(std::round(fps)));
                        secondsTimer = 0.f;
                }

                render();
        }
}

Greetings
Kami

4
General / Fluent Movement
« on: October 03, 2016, 12:10:37 pm »
Hello there,

I just started fiddling around with SFML and c++.
I already did some graphics programming with e.g. Andorra 2D, which was something similar to SFML but for pascal/Delphi.
I got the book: SFML Game Development from PACKT to guide me.

And now i'm stuck on a difficult topic...
I just love it if games are fluent and many games are. e.g. Stardew Valley.
But i can't get this level of smoothness to my circle with a black background.


I made a Video with different Settings (NoLimit + No VSync, NoLimit + VSync, 60 FPS, 240 FPS)
There are some tiny little differences and i'd like to emphasize on the first 15 Seconds where i show without limits and then with VSync on. You can clearly see, that the ball doesn't run as smooth as without limits.
So how do i manage to get a fluent movement like without limits?

PS:
http://en.sfml-dev.org/forums/index.php?topic=20677.0
I checked this thread but it doesn't seem to fit/solve my problem exactly..
Mabye i'm wrong but on my little laptop with a shitty intel card, i don't have this stutter. I can't even disable VSync because Intel is a b...

PPS:
I've made another video:

It's clearer to see what i mean with higher speed.

Thanks for any thoughts.
Kami

Pages: [1]
anything