124 votes
Accepted

What is the point of update independent rendering in a game loop?

There's a long history of how we arrived at this common convention, with lots of fascinating challenges along the way, so I'll try to motivate it in stages: 1. Problem: Devices run at different ...
DMGregory's user avatar
  • 133k
40 votes
Accepted

Game loop isn't performing well enough, so my frame rate is too low (Windows Form + GDI+)

TLDR: Get DirectBitmap from https://stackoverflow.com/a/34801225 and add ...
PTwr's user avatar
  • 516
33 votes
Accepted

Fixed timestep game loop, why interpolation

Some games do indeed extrapolate. An advantage of extrapolation is that you can do it with just the single most recent state and a rate of change (like velocity, angular velocity, etc.) rather than ...
DMGregory's user avatar
  • 133k
17 votes

OpenGL - How come drawing sprites takes so much performance

Your GPU can probably render even 100k sprites without issues, but you need to do it smart. Sprites and other geometry must be supplied to a GPU in batches grouped by the same texture, shader and ...
HankMoody's user avatar
  • 308
17 votes

Game loop isn't performing well enough, so my frame rate is too low (Windows Form + GDI+)

When things bog down, check your inner loop. That's the code being run the most often, so even a small inefficiency there stacks up. Here we see: ...
DMGregory's user avatar
  • 133k
13 votes

How can City-sim simulate hundreds of characters?

Like so much of gamedev, the answer to how city sim games accomplish this seemingly-impossible feat is: they probably don't. They're just faking it well. ;) Sims like these will typically operate on a ...
DMGregory's user avatar
  • 133k
8 votes

What is the point of update independent rendering in a game loop?

The other answers are good and talk about why the game loop exists and should be seperate from the render loop. However, as for the specific example of "Why render a frame when there hasn't been any ...
Waddles's user avatar
  • 201
8 votes
Accepted

Can I always assume that fixed time step in Unity is reliable?

I've done some tests simulating low framerate conditions, and empirically confirmed that the deltaTime value for each FixedUpdate step does indeed stay consistent. ...
DMGregory's user avatar
  • 133k
8 votes
Accepted

Who 'owns' the components in an ECS?

In an actual ECS, entities are just IDs, they don't own the components. Components are usually registered into a container that represents the scene/world the game is currently in. The reason is ...
starikcetin's user avatar
  • 5,265
7 votes
Accepted

Game Loop design that is speed hack proof

You can't. Whatever code runs on the computer owned by the user is under the users control. Anything you program can be circumvented or patched by a determined enough hacker. The only solution to ...
Philipp's user avatar
  • 119k
7 votes
Accepted

Game Loop getting 58-62 FPS. Why not exactly 60FPS? (SDL/C++/OSX)

SDL_Delay() doesn't really have fidelity of any sort; it puts your main thread to sleep, and once your thread is sleeping it's up to the OS to decide when to wake ...
Trevor Powell's user avatar
7 votes

How and when should I update events occuring after a while?

Store your birthday and calculate your age on demand. When I buy alcohol the shopkeeper sometimes checks my ID to make sure I am not underage. However, my ID card doesn't have my actual age, and I ...
congusbongus's user avatar
  • 14.8k
7 votes
Accepted

C++ Object management/deletion

You're using a std::vector<Bullet>. This has the advantage of keeping data contiguous in memory, so iterating over it is fast (it has something to do with ...
Vaillancourt's user avatar
  • 16.3k
6 votes

What is the point of update independent rendering in a game loop?

Rendering is usually the slowest process in the game loop. Humans don't easily notice a difference in a frame rate faster than 60, so it often less important to waste time on rendering faster than ...
tyjkenn's user avatar
  • 2,576
6 votes
Accepted

How and when should I update events occuring after a while?

Another approach for handling events on a larger time scale is using a Heap. In short, a Heap is a binary tree that always brings the largest or smallest item to the top. If you maintain a min-heap (...
CLo's user avatar
  • 1,330
6 votes
Accepted

Java Game Loop Efficiency

Comparison of the three versions First version The first version of the code, there is no measure of the elapsed time since last update. That would usually make the game frame rate dependent. It is ...
Theraot's user avatar
  • 26.2k
5 votes

The most efficient and accurate game loop?

well this is the game loop for minecraft, hope it helps!Also, I modified it a bit so it matches with your methods (originally it was tick();) :D ...
Roland's user avatar
  • 51
5 votes

Using an interpolated game loop (such as Gaffer's final game loop), will the frame be rendered out of sync?

Firstly, on the subject of teleportation: most interpolation systems will simply disable interpolation for an object on a frame where it's teleported. You can see this for example in Unity, when using ...
DMGregory's user avatar
  • 133k
5 votes
Accepted

Two Gameloops instead of one, wouldn't it be better?

That's an interesting idea, however... With multi-threading, you lose your advantage because you have to stop the update thread when you update your graphics. Think about it: if you render at the ...
Vaillancourt's user avatar
  • 16.3k
5 votes
Accepted

SDL2 mouse motion event keeps occurring

You're not checking the return value of SDL_PollEvent to see if there's a new event, which means that regardless of whether there is an event to handle, you're ...
wizzwizz4's user avatar
  • 165
5 votes
Accepted

How to handle player input with fixed rate variable fps time step?

I most often encounter this in the context of Unity, which has the following attributes: Input is checked once per displayed frame, before any of that frame's fixed/variable timestep updates Input ...
DMGregory's user avatar
  • 133k
5 votes

What causes some web game engines work in "slow mo" mode instead of reducing FPS but continuing to show the true time/tick state of things?

One simple way to get this slow-mo effect is if you have a variable rate update and no delta time correction to make it "framerate independent". For example if each update you say: ...
DMGregory's user avatar
  • 133k
4 votes

What is the point of update independent rendering in a game loop?

A construction like the one in your question can make sense if the rendering subsystem has some notion of "elapsed time since last render". Consider, for instance, an approach in which the position ...
Thomas's user avatar
  • 1,209
4 votes

What is the point of update independent rendering in a game loop?

In addition to other answers... Checking for change of state requires significant processing. If it takes similar (or more!) processing time to check for changes, compared to actually doing the ...
Graham's user avatar
  • 222
4 votes

Game loop with multithreading

First of all, heed the warning by DMGregory in the comments to the question. Multithreading is an evil source of weird, randomly appearing and impossible to reproduce bugs. Do not use it unless you ...
Philipp's user avatar
  • 119k
4 votes
Accepted

Is single/double frame allocator suitable only for POD datas?

You have 2 options, keep track of destructors that need to be called and call them on clear Make sure that any object stored in the stack will only allocate from a allocator that will be cleared ...
ratchet freak's user avatar
4 votes
Accepted

Fixed Timestep with Interpolation | Blurry & Choppy

Your lerps and slerps are backwards: lerp(current, previous, alpha) should be lerp(previous, current, alpha) ie. ...
DMGregory's user avatar
  • 133k
4 votes
Accepted

How does a game like Minecraft handle block and entity updates?

Don't run updates more frequently than necessary. Many of the things you mentioned don't need to be updated every single game tick. The plant growing mechanic, for example, is something where you can ...
Philipp's user avatar
  • 119k

Only top scored, non community-wiki answers of a minimum length are eligible