TIMESTEPS and DELTA TIME | Game Engine series

Поділитися
Вставка
  • Опубліковано 21 вер 2024

КОМЕНТАРІ • 73

  • @venumspyder
    @venumspyder 5 років тому +85

    You can also update your game state at a FIXED time step very much like a physics engine. This will give you consistent updates as well as reproducible results if you are debugging certain types of time related issues. With a simple time step, if your frame rate drops to 30 fps you will miss frame updates which could lead to problems and gives inconsistent game updates. Now if you update the game at a FIXED time step, the game updates independent of the frame rate. So if you update at a fixed time step of 60 fps, and the frame rate drops to 30 fps, then for that frame you will update the game state TWICE (fixed time step is (1/ 60)). This depending on implementation and update rate will create choppy or stuttering as characters move through the game. One solution (which I have seen in many games) is they update at a very high time step (say 1/120) so that the time interval is very small and this reduces the stuttering. I save the previous position and current position of an object and then use that to interpolate what is displayed on the screen between fixed time step intervals. This eliminates any stuttering and I don't have to update at such a high fixed time step but introduces some very slight lag with what is displayed on screen.
    If anyone is interested in researching this further google: Fix Your Time Step.

    • @zonkle
      @zonkle 5 років тому +11

      This. Fixed timestep with interpolated rendering is absolutely the best way to structure your main loop. Every other method has issues. Too many people are fooled into using delta time in their gameplay code, when it's actually a complete waste of time if you want high precision deterministic gameplay.

    • @rift1067
      @rift1067 4 роки тому +1

      Came to the comments section looking for this. I think the reason Yan didn't do it like that is because he hasn't created an entity component system yet. I'm hoping he'll build an alternate timestep system as you suggested in the future once he does set up an ECS, if not replace this method implementation entirely.
      I'd also like to add, to avoid misinterpretations, that this suggestion is not the same as what Yan was talking about at 08:18 as he was still referring to the RENDERING time instead of a time increment measured on the basis of an arbitrary engine state.
      EDIT: I actually don't know if both methods can work in conjunction. If that is the case, then a replacement won't be necessary.

    • @catalinvasile9081
      @catalinvasile9081 4 роки тому +1

      +1. Basically the update has to be sampled at a fixed timestep to guarantee predictable and reproductible results. Not doing this assumes that the whole update is is 'linear' which is not the case for pretty much all the games. A much better strategy is to sample at a fixed timestep - and eventually add protection for a max number of steps (like never more than X update steps per frame) to account for bid delta time jumps (due to freezes etc). What to do in those cases depends on the game: you can either skip updates and 'lose' time or clamp the sampling and go into slomo.

    • @asmonull
      @asmonull 4 роки тому +1

      For anyone interested: DirectX UWP template has a fixed timestep timer implementation (named StepTimer) included/generated, quite well commented and documented - worth looking at even as a reference for making your own implmentation.

    • @Clouds095
      @Clouds095 3 роки тому

      @venumspyders Have you got any code you can share for this? I've read Fix Your Time Step numerous times but still can't grasp it.

  • @RitobanRoyChowdhury
    @RitobanRoyChowdhury 5 років тому +16

    One critical thing that I think you missed is that adding delta time is a problem if you need exact reproducibility from a certain game state. If you're running at 30 FPS, as opposed to 60 FPS, not only is it not being rendered at those in-between frames, but calculations are also not happening. At low framerates, this can lead to artifacts like teleporting through walls, or even more minor things, like rounding errors compounding over time. While this won't matter for most games, like FPS, it does matter for some situations. If you're writing a physics simulation, reproducibility is probably more important than looking roughly the same regardless of framerate. Similarly, factorio doesn't implement this, instead choosing to slow the entire game down, for this reason -- it's really important that from a certain game state, you can find the game state at some point in the future, regardless of what system your on. This is how it manages it's multiplayer, where it just has the input being sent to all the players, so every player can independently run the game, yet still know that their copy is the same as everyone else's.

    • @zoltankurti
      @zoltankurti 4 роки тому

      @M. de k. if yoh want exact reproducibility you have to use fixed time step in your updates.

    • @KingKrouch
      @KingKrouch 3 роки тому

      Doesn't engines like UE4 run physics simulations in a fixed timestep with substepping as an option, while other stuff uses Delta Time?

  • @trapido0230
    @trapido0230 5 років тому +14

    3 videos, one week. God damn your good! Keep it up!

  • @regbot4432
    @regbot4432 3 роки тому

    Exactly what i was looking for. Again, Thanks cherno for these videos. I really like these quick explanations, with like school board and stuff. You are good a teacher.

  • @Tremah2
    @Tremah2 3 роки тому +2

    You're just so good at explaining things.
    Thanks for the incredible amount of content you put out!

  • @arini40
    @arini40 3 роки тому

    Thank you! I was looking for a mathematical explanation for this. Now it makes sense.

  • @marcklein1390
    @marcklein1390 5 років тому +12

    Great video. For camera movement this variable time step is fine but if you use it for physics your calculations will get non deterministic. That's why in that case a fixed time step would be better.

    • @esben181
      @esben181 5 років тому +1

      I was thinking the same thing

    • @AlexanderSartonCozzi
      @AlexanderSartonCozzi 4 роки тому

      Most game engines use another method such as fixed time stepping for physics. But this is something that shouldn't be linked to the delta time in your game logic. You don't have to use the same method for both and you shouldn't.

    • @zoltankurti
      @zoltankurti 4 роки тому

      @@AlexanderSartonCozzi it surely is tied to time. The time spent since the beginning of the loop determines how many fixed time updates need to be carried out.

  • @giladreich810
    @giladreich810 5 років тому +3

    Very informative video! Thank you for the extra uploads this week, much appreciated! :)

  • @fenril6685
    @fenril6685 4 роки тому +5

    I wonder if the method of locking the Update callback to 60 executions per second that you mentioned, is akin to the notorious Physics issues in Bethesda's games. It's been a long standing issue with their games built with the Creation Engine (and it's previous incarnations), to have tons of physics bugs when the game runs significantly faster than 60 fps.

    • @zhulikkulik
      @zhulikkulik Рік тому

      It is and Bethesda isn't the worst case I know.
      If you for some reason decide to run vanilla GTA San Andreas on a modern PC - DON'T uncheck the frame limiter.
      If you know the anti-piracy measures from gta4, when on pirated copy of the game cars would never stop driving and get on fire after some time - this is exactly what happens in GTA SA, but because of frame rate. Physics is x times stronger, so cars get pushed into the ground. And so is momentum. You release the W, but your car won't stop rolling. And it also doesn't want to turn.
      But it seems like traffic is done differently because it's only the cars you drive that get affected by this if I remember correctly.

  • @zxuiji
    @zxuiji 2 роки тому

    I was just thinking, the fps restraint can double as velocity e.g:
    pos += (global_fps * object_fps.current * move_distance);
    object_fps -= (object_fps.current - object_fps.restrain) ? object_fps.revert : 0;
    Might actually give a natural blur effect like you see films depict superman & the flash as being when they move.

  • @useronuralp
    @useronuralp 3 роки тому +2

    Just a quick thought:
    If you feed this delta time to every moving object in a scene like characters, particles, cameras and etc., in theory, you should be able to create a slow motion effect by gradually tuning the delta time down and up at specific times of your game, right?

    • @nullbeyondo
      @nullbeyondo 3 роки тому +11

      Don't ever, ever tune the delta time. Just multiply every entity's velocity with another variable that's 1 by default and tune it as you like if you want slowmo.

    • @AlexDicy
      @AlexDicy 2 місяці тому

      @@nullbeyondo is there any reason apart from "it's morally wrong"?

  • @obligatoryfail9550
    @obligatoryfail9550 5 років тому +4

    Great video, keep it up!

  • @sam_is_people1170
    @sam_is_people1170 2 роки тому

    thanks!!

  • @aleksandarstanisic1848
    @aleksandarstanisic1848 5 років тому +1

    Ty ty ty

  • @diligencehumility6971
    @diligencehumility6971 2 роки тому

    Would you gain any performance from running the game loop in the GPU instead?

  • @diligencehumility6971
    @diligencehumility6971 2 роки тому

    I don't understand how setting glfw swap interval (vsync) on/off would effect your update rate? Your update rate will run at max no matter what, you only limit the amount of frames drawn to 60 with vsync, right?

  • @pastasawce
    @pastasawce 10 місяців тому

    Im having problems with box2d objects moving VERY slowly with vsync on

  • @daniel_8
    @daniel_8 Рік тому

    what about acceleration? how do I make that not depend on the frame rate? is it the same case of just multiplying by delta time?

  • @liankerlopes240
    @liankerlopes240 3 роки тому

    Amazing color Theme, what is it?

  • @unsafecast3636
    @unsafecast3636 4 роки тому

    I just want to clarify that, while allocating objects on the heap, java allocations are way more efficient. That's because it preallocates a whole bunch of memory from the start of the program. So instead of calling malloc on every allocation, it calls it once at start and then again when you run out of memory.
    And that diminishes the problem where you have your memory everywhere.

  • @dacracking5768
    @dacracking5768 3 роки тому

    so the movement is consistent even if your framerate fluctuates.

  • @gabrielfonsec
    @gabrielfonsec 5 років тому +1

    what will happen if I overload the operator float and the operator +
    and I try to do "Some Class" + "number.f". What function will be called.

    • @yogxoth1959
      @yogxoth1959 4 роки тому +1

      What happens will be what you define in the operator overload function. Exemple: void operator+(int num) { my_int_field += num; }

  • @jdp_man1924
    @jdp_man1924 5 років тому

    i might actually use this since ive been watching you create it

  • @artyombabich9429
    @artyombabich9429 5 років тому

    i assume you know your time step of the last frame and applying this value to some action in the current one. But can you actually know your timestep of the current frame and apply this value to actions?

  • @wreckless_-jl6uu
    @wreckless_-jl6uu 5 років тому +2

    Videos are really good and informative but just one thing... *SLOW DOWN* thanks for all the work you do!!!

  • @cmdlp4178
    @cmdlp4178 5 років тому

    I used to do that fixed 60fps vsync thing, i noticed that some drivers even do not implement vsync (correctly). On such platforms you just warp through the world :D

  • @AnythingSoupVODS
    @AnythingSoupVODS 2 місяці тому

    running on 165 hz, 6 ms per frame

  • @minhquannguyen3605
    @minhquannguyen3605 3 роки тому

    The VSync doesn't work with me :(

  • @richardlighthouse5328
    @richardlighthouse5328 5 років тому +3

    Waiting for model loading episode.

  • @stanleythehandsome5402
    @stanleythehandsome5402 4 роки тому +2

    Left.

  • @stargazerch.3605
    @stargazerch.3605 3 роки тому +1

    Why not use std::chrono?

  • @changgeng4700
    @changgeng4700 5 років тому

    I have a question, how to render things on the window which i created by imgui or move things from default window to imgui window

  • @RandomGuyyy
    @RandomGuyyy 5 років тому +1

    I guess the next step would be to add a global time dilation term

  • @syne1456
    @syne1456 5 років тому

    HEYYY

  • @angelcepeda9945
    @angelcepeda9945 3 роки тому

    Hi cherno, i want to change the render engine of an actual game (MuOnline)and it has opengl, because the existing one is 12 years old, and resource hungry. I have basic knowledge with c++, i viewed your opengl series first videos, my question is, from where should i start to achieve it?

  • @sbn0671
    @sbn0671 5 років тому

    Guys, what do you think about Rust programming language? Will it replace C++ for future game dev?

    • @richardlighthouse5328
      @richardlighthouse5328 5 років тому

      Well yes but actually no.

    • @osere6432
      @osere6432 5 років тому

      Absolutely not, ever

    • @zonkle
      @zonkle 5 років тому +2

      The only language that can possibly replace C++ for game development without compromise is Jai.

    • @zonkle
      @zonkle 5 років тому

      @Artem Katerynych It's still in development. You can follow Jonathan Blow on twitch and youtube if you're interested.

    • @sbn0671
      @sbn0671 5 років тому

      @@zonkle Can you please explain that to me? Jai has very similar syntax like Rust. Both are non-garbage collected and very fast languages. BTW Rust is available for public and Jai not. So please explain me the biggest differences about these two languages. Why should I wait Jai's release date instead of doing game dev with Rust now? IMO both are very similar or maybe Rust is little bit better than this language because it comes with his safety and very well explained compiler errors. I'm not against to Jai. I just want to know the differences.

  • @user-autoanima
    @user-autoanima 4 роки тому

    thank you , your signature phrase is "right" , maybe don't use that word too much.

  • @Light-wz6tq
    @Light-wz6tq 5 років тому

    Yo

  • @monomere
    @monomere 5 років тому

    12 minutes ago, wow

  • @mrbee8336
    @mrbee8336 5 років тому

    Can you please start a series for java programming

    • @bnosam
      @bnosam 5 років тому +1

      Look at ThinMatrix's videos on UA-cam.