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

Author Topic: Problem Calculating Step Movement by Time  (Read 1159 times)

0 Members and 1 Guest are viewing this topic.

MOP

  • Newbie
  • *
  • Posts: 19
  • Expect the progress
    • View Profile
Problem Calculating Step Movement by Time
« on: November 10, 2017, 08:39:01 pm »
Hi people,

actually i got some problems by timestep calculation (for sfView Movement).
I get for my Snake a block-wise movement, cause block-wise setup for it. Iam using bigger "tilemaps" for an level. So i decided to create some custom view. Actually, the view is moved also block-wise. But imo i could be possible to make the View move smoother. Since the snake setup is block-wise, it couldnt be make a smooth movement.

I build up a central "managment" for time things, in which i set a SecondTick and SnakeTick flag.
SecondTick is just for update my score "+1".
SecondTick release every second, and SnakeTick release "1 Second / Snake Speed".

My Handle Items, Snake Movement is updated every SnakeTick. And Rendering Stuff has no time limit.
(my Movement to the View is actually inserted in the Snake Handle). So the View Move is also block-wise.

(I Call my Update Functions HandleXXXX, dont be confused for the terminology ).

Okay thats was the background.

Now i tried some calculations.

sfView Movement per Tick: 25.0f (x or y depent on direction)
Actually my SnakeTick is: 1 Second / 3 Speed = 333ms
If we have SnakeTick: 1 Second / 4 Speed = 250ms
and so on..

So at 333ms the View must be moved by 25.0f
And at 1 Second the View must be moved by 75.0f

TestValue shall be the Value to be Moved.
The Exactly Frame Move is similar. The Sum into a Full SnakeTick must be exactly.

My Idea which i test:
(its C)
Code: [Select]
TestValue += (GameClock.GC_DeltaTime * 25.0f * GameSnake.S_Speed);

    if(GameClock.GC_SnakeTick)
    {
        printf("TestValue must be 25.0f: %f\n", TestValue);
        TestValue_Extended += TestValue;
        TestValue = 0.0f;
    }

    if(GameClock.GC_SecondTick)
    {
        printf("TestValue_Extended must be 75.0f: %f\n", TestValue_Extended);
        TestValue_Extended = 0.0f;
    }


But i get the following Output:
Code: [Select]
...
TestValue must be 25.0f: 25.320147
TestValue must be 25.0f: 25.297354
TestValue must be 25.0f: 25.276875
TestValue_Extended must be 75.0f: 75.894379
TestValue must be 25.0f: 25.344891
TestValue must be 25.0f: 25.220773
TestValue must be 25.0f: 25.210583
TestValue_Extended must be 75.0f: 75.776245
...

As you see, i cant actually the "right value".

The Movement by a frame is similar. But the Sum to a full SnakeTick have to be exactly 25.0f, otherwise it will definitly lead to crazy bugs.

Do you have an idea, what can i do?

Thanks in advance

Greetz MOP.





My Github Repo:
Snake
Deep Deep Deep in Development

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: Problem Calculating Step Movement by Time
« Reply #1 on: November 10, 2017, 08:46:35 pm »
Quote
Do you have an idea, what can i do?

Yes. Learn math.
You ask SFML forum to check your NOT sfml related code and give too few information about what's going on in your code