+ - 0:00:00
Notes for current slide
Notes for next slide

Creación de Videojuegos

Game Engine Basics

1 / 29

Game Engines

2 / 29

What is a Game Engine

  • Games are typically split between an engine and content

  • The engine can usually support multiple different games (theoretically)

  • Extensions to the game don't require changes to the engine (ideally)

  • Engine provides components for loading content, rendering, physics, networking, AI, sound, etc.

3 / 29

Why?

  • Rendering, physics, etc. are reusable components

  • Good software engineering practice says they should be written separately

  • The game itself becomes smaller, and easier to change

  • It becomes easier to make more games

  • Game Engine can be licensed

4 / 29

How do I write a Game Engine?

Don't!

5 / 29

But let's talk about how you would

6 / 29

This is all you need (basically)

while (true)
{
foreach(GameObject go in scene)
{
go.Update();
}
scene.Render();
FrameSync();
}
7 / 29

What's this?

foreach(GameObject go in scene)
  • A GameObject is an entity in the game

    • Can be concrete, like an enemy

    • Or abstract, like physics, networking, input, ...

  • The Scene is the collection of GameObjects that is currently loaded/active

8 / 29

What's this?

go.Update();
  • Every GameObject has an Update method, which is called every frame

  • Can be used to move or animate the game object, run AI behavior, sound effects, etc.

9 / 29

Moving

public void Update()
{
position += new Vector3(3,0,0)*Time.deltaTime;
}
  • Every frame the game object is moved in x direction

  • Time.deltaTime represents the time since the last frame

  • The movement speed is 3 units per second

10 / 29

Are there any problems with doing everything in Update()?

11 / 29

Frames Per Second (FPS)

  • Ideally we want at least 25 FPS

  • That means we have 40 ms per frame

  • All Update() methods together need to need less than 40ms

  • We are also rendering things

  • What about slow calculations?

12 / 29

Threads

  • Idea: Run computationally expensive calculations in their own thread

  • Exchange information between threads using shared data structures

  • Access to data structures has to be synchronized to avoid consistency problems

  • What could possibly go wrong?

13 / 29

Synchronization problems

  • Thread A moves an object forward at a constant rate

  • Thread B calculates the route for the object, and then moves it onto that route

  • Which order are they going to be executed in?

  • How long does thread B need?

14 / 29

One solution: Messaging

  • Only one (main) thread is allowed to touch the object's location

  • Other threads can request movement by sending a message to the main thread

  • Can still do expensive computations in threads, but can not manipulate the scene

  • Main thread can rate-limit message processing

15 / 29

Fixed Updates

  • Some subsystems (like physics) benefit from a (pretty) fixed update rate

  • Instead of doing physics calculations every frame, they are just done every n milliseconds

  • In your main loop you check if the necessary time between updates has passed

  • May need to interrupt Update if it takes too long

16 / 29

Using a Game Engine

  • Programming in this setting is very different from regular programming

  • In most programs you have one main thread of execution

  • Now you have dozens of objects each with its own little routine to do things

  • Physics collisions cause events to happen

17 / 29

Using a Game Engine

  • When you get used to it, this way of coding is actually very nice

  • Consider each game object separately, and implement its behavior separately

  • If you need some global state, make one GameManager object or similar that stores it

  • Think of it in terms of "if x then y" (like in your GDD), for each game object

18 / 29

Scenes

19 / 29

Scenes

scene.Render();
  • Many game objects will have representations on screeen

  • 2D/3D graphics, GUI Elements, particle effects, etc.

  • Where do we actually get all of these things from?

20 / 29

Scene graph

  • Scene

    • Living Room

      • Fireplace
        • Wood
        • Fire
      • Carpet
      • Couch
      • Player
        • Avatar
        • Weapon
        • Pet
    • Hallway

      • Ceiling light
      • Coat hanger
21 / 29

Scene graph

  • Spatial (or logical) grouping of game objects

  • May load, move, manipulate entire sub-trees at once

  • For example: Moving the player also moves their weapon and pet

22 / 29

Building a scene graph

  • Load scene from file (e.g. XML)

  • Load 2D/3D models from model file

  • Supported formats determined by game engine

23 / 29

How do you ...

  • Shoot a bullet?
    • Create a Bullet Game Object
    • Update() moves the bullet forward
    • A physics collision removes the bullet from the scene
    • Or use a raycast
  • Detect collisions?
    • Physics subsystem calculates collisions
    • When a collision is found a message is sent to the objects involved
  • Make a multiplayer-game?
    • Networking runs in a thread
    • Other player moves: message is sent to GameObject representation of that player
  • Change levels?
    • Load a new scene
24 / 29

Game Engines

25 / 29

2D

  • PyGame

  • Ren'Py

  • GameMaker

  • RPGMaker

26 / 29

3D

  • id Tech

  • Ogre3D

  • CryEngine

  • Lumberyard

  • Unreal

27 / 29

2D and 3D: Unity

28 / 29

Game Engines

2 / 29
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow