Gamecraft
0/462

World 14

The machine

Loops, clocks, collisions, searches and shaders: the words for what the computer is actually doing while you play.

A game is a program that has about a sixtieth of a second to do everything, again and again, for hours. Almost every odd thing a game does comes from that: a character who moves faster on a better computer, a bullet that passes through a wall, a guard who walks into a corner, a frame rate that collapses when the explosions start. You do not need to write these systems to name them, and naming them is what lets you ask for the right fix instead of describing the symptom.

  1. Game engineThe reusable software under a game: the parts that draw, play sound, read input, simulate physics and load files. The game itself is the rules and content built on top.
  2. Game loopThe circle at the centre of every game: read input, update the world, draw the picture, then do it again, usually dozens of times a second. One turn of it makes one frame.
  3. Frame budgetThe time one turn of the loop is allowed to take. At 60 frames a second that is 16.7 milliseconds, shared between everything: game logic, physics, AI, animation and drawing.
  4. Delta timeThe time the last frame took. Multiply every movement by it, and a character covers the same ground per second however fast the machine runs.
  5. Fixed timestepFrames vary, so bank the time they take, and spend it on game logic in equal slices such as a 120th of a second. The picture can run at any rate while the rules always step the same.
  6. Collision detectionWorking out which things are touching. Done in two passes: a broad phase that quickly throws out everything that is nowhere near, and a narrow phase that does the exact test on what is left.
  7. TunnellingA fast object moves so far in one physics step that it starts on one side of a wall and ends on the other, and the game never sees them touch. Collision was only checked at the two ends.
  8. Physics engineThe part of an engine that moves things under forces and keeps them from passing through each other. It solves joints and contacts approximately, by nudging them in several passes each step.
  9. RaycastAsking what a straight line from here in that direction hits first, and how far away it is. It is the most common question in a game engine.
  10. TweenMoving a value from A to B over a set time along a curve, so you only state the start, the end and the feel. The word comes from animators drawing the frames in between.
  11. Entity component systemA way of organising a game. An entity is only an id, components are plain data attached to it, and systems are loops that run over everything holding the components they care about.
  12. ScriptingWriting game behaviour in a simpler language that the engine reads and runs, while the fast, difficult parts stay in the engine.
  13. Hot reloadChanging code or data while the game keeps running, so the new version takes effect without restarting or losing your place.
  14. SerialisationTurning a live game's state into a flat stream of bytes that can go in a file or over a network, and back again. A save file is serialisation, and so is a network message.
  15. Object poolingKeeping a stock of finished objects, such as bullets, and reusing them rather than creating new ones and throwing old ones away.
  16. State machineA thing is in exactly one of a list of states, and a table says which event moves it to which state. An enemy might have Patrol, Chase and Flee, joined by events like "saw the player".
  17. Behaviour treeAI written as a tree of tests and actions, walked from the top. A selector tries its children until one works; a sequence runs them until one fails. So the top is the most urgent.
  18. Utility AIThe character gives every action it could take a score based on the situation, and does the one with the highest. How hungry am I, how far is the food, how much would it help.
  19. Goal-oriented action planningYou give the character goals and a list of actions, each with what it needs and what it causes. A search then finds the cheapest chain of actions that reaches the goal.
  20. PathfindingFinding a route through a map. A* is the standard: always explore the most promising spot, judged by distance so far plus a guess at what is left, which finds a shortest route quickly.
  21. Navigation meshA set of flat polygons covering every place a character can walk. Search runs over the polygons rather than thousands of squares, and the route is then pulled tight round corners.
  22. Steering and flockingEach creature follows simple local rules for its next movement. Craig Reynolds showed in 1987 that three are enough for a flock: keep apart, match your neighbours' heading, drift to their centre.
  23. AI directorA system above the enemies that watches how the players are doing, and decides when and where threats appear, to make the tension rise and fall.
  24. SeedThe one number a random generator starts from. Computers fake randomness with maths, so the same seed always gives the same sequence, and so the same world.
  25. Procedural generationContent made by an algorithm rather than by hand, at build time or as you play. The craft is in the rules around the randomness, since pure randomness rarely gives you a good level.
  26. Perlin noiseRandom numbers that change smoothly, made by Ken Perlin. Add several layers, called octaves, each twice as fine and half as strong, and you get something that looks like hills and rock.
  27. Wave function collapseFill a grid with tiles that have rules about what may sit next to them. Each cell starts as anything; pick the most certain, decide it, and let the rules narrow its neighbours. Repeat.
  28. ShaderA small program that runs on the graphics card, usually once for every pixel or corner of a model, in parallel. It decides position and colour, and that decides how everything looks.
  29. Draw callOne request from the game to the graphics card to draw a batch of triangles. Each one costs CPU time for setting things up, whatever the size of the thing being drawn.
  30. Level of detailUsing a simpler version of a model the further away it is. Done well, you never notice. Done badly, you see things change shape as you approach, which is called pop-in.
  31. CullingNot drawing what you can't see. Frustum culling skips things outside the camera's view. Occlusion culling skips things hidden behind something else, which is harder to work out.
  32. Dynamic resolutionThe game watches its own frame time and lowers the number of pixels it renders when things get heavy, then scales the picture up to fill the screen.

Name a word, or describe what you mean in everyday language.