I have a fundamental #GameDev question that has been bugging me for ages.

I've tried developing my own games, but I always felt like I was missing something fundamental about #programming logic and everything I did felt "wrong" and inefficient.

Here goes.

At the most basic level, games run as endless loops, right? Every frame, something happens. The program goes through the same loop over and over again until something causes it to exit.

For example, in a simple Asteroids-like shoot-em-up, the game goes through the list of obstacles every frame and sets their position downward a bit. They therefore appear to be coming towards you over time.

But games are obviously complex and interactive, and therefore don't just do the same thing every frame. The game needs different things to happen each iteration of the loop, based on what's going on in the game.

For example, the Asteroids obstacle needs to be removed from the game once it exits the screen, or once it overlaps with the player.

The only way I know to check whether something happened is to add a conditional to the game loop. Every single frame, the game checks for every single obstacle whether its position is outside the boundaries, and if so, removes it.

A computer can't just "keep in mind" to watch for a certain event to make something happen, it needs to explicitly be reminded to check every frame.

Even if something is supposed to happen only every minute, you still need to count a number up every frame until you reach a minute's equivalent amount of frames, and then the counter gets reset to zero and the event happens.

I understand all this works.

But what I don't understand is the following:
This seems extremely wasteful and inefficient, right?

I understand that a computer can calculate and compare a bazillion things a second, and that this is perfectly fine for something as simple as Asteroids.

But what about more complex games?

  • Do Mario jump-and-run games genuinely check whether Mario touches the goal post every single frame of the game?
  • Does GTA V check every single frame whether the player is in a mission, and if so, which one they're in?
  • Do games like #Minecraft check every single frame, for every single animal, whether they're currently on fire?
  • Do games check every single frame whether they're paused, in a menu, or running?

If this is genuinely what's going on, how the hell do complex games even run? When I play Minecraft, does the computer really, 120 times a second, for every single animal in the world, check whether they're currently poisoned? And then also checks whether the game is paused, whether there is mouse input, whether it's raining, whether music is playing, whether a block state has changed, and so on and so on?!

What about something like #BindingOfIsaac? Does it really check every single frame for every one of the thousands of possible items and whether the player has them equipped?

I mean, I'm sure it's abstracted a bit in that the game adds an "event hook" or something whenever you pick up a new item, but underneath all that, surely the game still has to check every frame for every possible hook whether it is active or not?

If I finally understood the answer to this question, I'd understand way more about game development.

0

If you have a fediverse account, you can quote this note from your own instance. Search https://micro.webgarden.click/users/lianna/statuses/01KJ2WT27K1BM30KVMNXRWG8B5 on your instance and quote it. (Note that quoting is not supported in Mastodon.)