TIMESTEPS and DELTA TIME | Game Engine series

  Рет қаралды 48,663

The Cherno

The Cherno

Күн бұрын

Пікірлер
@venumspyder
@venumspyder 5 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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. 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 жыл бұрын
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 жыл бұрын
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 жыл бұрын
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.
@arini40
@arini40 4 жыл бұрын
Thank you! I was looking for a mathematical explanation for this. Now it makes sense.
@Tremah2
@Tremah2 4 жыл бұрын
You're just so good at explaining things. Thanks for the incredible amount of content you put out!
@obligatoryfail9550
@obligatoryfail9550 5 жыл бұрын
Great video, keep it up!
@giladreich810
@giladreich810 5 жыл бұрын
Very informative video! Thank you for the extra uploads this week, much appreciated! :)
@ChrisM541
@ChrisM541 5 күн бұрын
What about the impact from external sources e.g. system interrupts? How do game studios control things here so that the OS/etc doesn't cause stutters etc?
@marcklein1390
@marcklein1390 5 жыл бұрын
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 жыл бұрын
I was thinking the same thing
@AlexanderSartonCozzi
@AlexanderSartonCozzi 5 жыл бұрын
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.
@fenril6685
@fenril6685 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.
@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?
@zxuiji
@zxuiji 3 жыл бұрын
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.
@sam_is_people1170
@sam_is_people1170 3 жыл бұрын
thanks!!
@useronuralp
@useronuralp 3 жыл бұрын
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 жыл бұрын
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 6 ай бұрын
@@nullbeyondo is there any reason apart from "it's morally wrong"?
@w花b
@w花b 2 ай бұрын
​@@AlexDicy Probably because other things might use it that don't need to be slowed down or sped up. I guess it's like the backbone of you game which is pretty much a physics simulation in a way so changing it would be losing all point of reference or foundation? Just a guess though, you wouldn't make your software change your computer clock just to simulate something with time right? That would be the same idea here. Take it with a grain of salt.
@diligencehumility6971
@diligencehumility6971 2 жыл бұрын
Would you gain any performance from running the game loop in the GPU instead?
@pastasawce
@pastasawce Жыл бұрын
Im having problems with box2d objects moving VERY slowly with vsync on
@gabrielfonsec
@gabrielfonsec 5 жыл бұрын
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 5 жыл бұрын
What happens will be what you define in the operator overload function. Exemple: void operator+(int num) { my_int_field += num; }
@aleksandarstanisic1848
@aleksandarstanisic1848 5 жыл бұрын
Ty ty ty
@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?
@comodinoh
@comodinoh 15 күн бұрын
Setting the swap interval to 1 effectively makes OpenGL pause the thread it's rendering in (In this case the rendering is happening on the main thread where we're updating too) when it's ahead of the monitor's refresh rate (eg. 60 fps for 60 hz monitors).
@liankerlopes240
@liankerlopes240 3 жыл бұрын
Amazing color Theme, what is it?
@jdp_man1924
@jdp_man1924 5 жыл бұрын
i might actually use this since ive been watching you create it
@dacracking5768
@dacracking5768 4 жыл бұрын
so the movement is consistent even if your framerate fluctuates.
@nauq302
@nauq302 4 жыл бұрын
The VSync doesn't work with me :(
@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?
@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
@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.
@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
@stargazerch.3605
@stargazerch.3605 4 жыл бұрын
Why not use std::chrono?
@wreckless_-jl6uu
@wreckless_-jl6uu 5 жыл бұрын
Videos are really good and informative but just one thing... *SLOW DOWN* thanks for all the work you do!!!
@richardlighthouse5328
@richardlighthouse5328 5 жыл бұрын
Waiting for model loading episode.
@stanleythehandsome5402
@stanleythehandsome5402 5 жыл бұрын
Left.
@AnythingSoupVODS
@AnythingSoupVODS 6 ай бұрын
running on 165 hz, 6 ms per frame
@angelcepeda9945
@angelcepeda9945 4 жыл бұрын
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?
@RandomGuyyy
@RandomGuyyy 5 жыл бұрын
I guess the next step would be to add a global time dilation term
@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 жыл бұрын
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.
@syne1456
@syne1456 5 жыл бұрын
HEYYY
@Light-wz6tq
@Light-wz6tq 5 жыл бұрын
Yo
@user-autoanima
@user-autoanima 4 жыл бұрын
thank you , your signature phrase is "right" , maybe don't use that word too much.
@monomere
@monomere 5 жыл бұрын
12 minutes ago, wow
@mrbee8336
@mrbee8336 5 жыл бұрын
Can you please start a series for java programming
@bnosam
@bnosam 5 жыл бұрын
Look at ThinMatrix's videos on KZbin.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 781 М.
Layers | Game Engine series
22:59
The Cherno
Рет қаралды 78 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
Logging | Game Engine Series
30:05
The Cherno
Рет қаралды 186 М.
A Simpler Way to See Results
19:17
Logan Smith
Рет қаралды 119 М.
Understanding framerate independence and deltatime
29:22
Clear Code
Рет қаралды 43 М.
Andrew Kelley   Practical Data Oriented Design (DoD)
46:40
ChimiChanga
Рет қаралды 153 М.
Time Does Not Exist. Let me explain with a graph.
16:07
Astrum
Рет қаралды 5 МЛН
Math for Game Developers - Jumping and Gravity (Time Delta, Game Loop)
9:49
BLENDING | Game Engine series
19:21
The Cherno
Рет қаралды 23 М.
Vertex Buffer Layouts | Game Engine series
49:16
The Cherno
Рет қаралды 43 М.
Dependency Injection | Prime Reacts
28:34
ThePrimeTime
Рет қаралды 364 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН