cs 480 680 game engine programming input and networking
play

CS 480/680: GAME ENGINE PROGRAMMING INPUT AND NETWORKING 2/7/2013 - PowerPoint PPT Presentation

CS 480/680: GAME ENGINE PROGRAMMING INPUT AND NETWORKING 2/7/2013 Santiago Ontan santi@cs.drexel.edu https://www.cs.drexel.edu/~santi/teaching/2013/CS480-680/intro.html Outline Student Presentations Handling User Input


  1. CS 480/680: GAME ENGINE PROGRAMMING INPUT AND NETWORKING 2/7/2013 Santiago Ontañón santi@cs.drexel.edu https://www.cs.drexel.edu/~santi/teaching/2013/CS480-680/intro.html

  2. Outline • Student Presentations • Handling User Input • Multiplayer Games • Networking Basics • Client-Server Architectures • Peer-to-Peer Architectures • Client-side Prediction • Project Discussion

  3. Outline • Student Presentations • Handling User Input • Multiplayer Games • Networking Basics • Client-Server Architectures • Peer-to-Peer Architectures • Client-side Prediction • Project Discussion

  4. Student Presentations • Sean Bluestein: • “An Extensible Trigger System for AI Agents, Objects and Quests” • Kevin Burdick: • “The 2009 Mario AI Competition” • Mateusz Stankiewicz: • “Convincing-Looking Glass for Games” • Binggang Wo • “Octree Construction”

  5. Outline • Student Presentations • Handling User Input • Multiplayer Games • Networking Basics • Client-Server Architectures • Peer-to-Peer Architectures • Client-side Prediction • Project Discussion

  6. Game Engine Architecture Game Specific Game Engine Functionalities Game Dependencies Resource Management Engine Utility Layer Platform Independence Layer SDKs OS DRIVERS HARDWARE

  7. Game Engine Architecture Online Artificial Scripting Multiplayer Intelligence Gameplay Foundations (Game Loop) Rendering Engine Animation Audio Physics Engine Subsystem Profiling & Collisions Debugging

  8. Handling User Input • User Input: • Keyboard presses • Mouse movements • Joystick • Touch surfaces • Cameras • Microphones • Remote input (from another computer over the network) • Etc. • Game Engine should process user input, and react accordingly: • Trigger character movements, etc.

  9. Trivial Way (Do NOT do this!) boolean cycle() { … If (key_pressed[SPACE] || joystick_button(BUTTON1) || bouse_button_pressed(BUTTON1)) { fireBullet(); } … }

  10. Trivial Way (Do NOT do this!) boolean cycle() { … Problem 1: If (key_pressed[ SPACE ] || Hard-coding input joystick_button( BUTTON1 ) || mapping. bouse_button_pressed( BUTTON1 )) { If we want to change the fireBullet(); fire key to “m”, we have to } look in the code for all … instances of this. }

  11. Trivial Way (Do NOT do this!) boolean cycle() { … Problem 1: If ( key_pressed [ SPACE ] || Hard-coding input joystick_button ( BUTTON1 ) || mapping. bouse_button_pressed ( BUTTON1 )) { If we want to change the fireBullet(); fire key to “m”, we have to Problem 2: } look in the code for all Hard-coding input … instances of this. devices. } What if we want to have a player in a remote computer over the network? What if we want to make our game work on a tablet?

  12. Handling User Input: The “Input Map” User Input: Game Actions: Move Right Fire ? … Switch weapon

  13. Handling User Input: The “Input Map” • The “input map” is a table, or module that: • Encodes the translation from user input to game actions/events • Can be provided by the game engine • Typically only used for in-game input (i.e. controlling player character). • But it could also be used to handle input for the game menus, GUI, etc. (with a proper design)

  14. Handling User Input: The “Input Map” • Input Map example API: Class InputMap { public: void addKeyboardMap(int key, GameAction ga); void addKeyboardComboMap(List<int> keys, GameAction ga); void addKeySequenceMap(List<int> keys, GameAction ga); void addMouseButtonMap(int button, GameAction ga); void addJoystickMap(int koystickEvent, GameAction ga); etc. GameInput getInput(); }

  15. Handling User Input: The “Input Map” • Input Map example API: Class GameAction { Class InputMap { Class GameActions { int actionCode; public: List<CharacterActions> controllers; int characterID; } void addKeyboardMap(int key, GameAction ga); } void addKeyboardComboMap(List<int> keys, GameAction ga); void addKeySequenceMap(List<int> keys, GameAction ga); void addMouseButtonMap(int button, GameAction ga); The “CharacterActions” class is void addJoystickMap(int koystickEvent, GameAction ga); an abstraction that stores all the Class CharacterActions { possible actions supported by bool left, right, jump, crouch; your game engine (this example is } etc. oversimplistic, you might need a more complex structure), and GameInput getInput(); whether the player triggered that } action or not.

  16. Handling User Input: The “Input Map” • Input Map example API: For example, for an “analogous” Class GameAction { Class InputMap { control engine (e.g. Nintendo Wii), Class GameActions { int actionCode; public: you might want to include desired List<CharacterActions> controllers; int characterID; weapon rotation, etc. } void addKeyboardMap(int key, GameAction ga); } void addKeyboardComboMap(List<int> keys, GameAction ga); void addKeySequenceMap(List<int> keys, GameAction ga); void addMouseButtonMap(int button, GameAction ga); The “CharacterActions” class is void addJoystickMap(int koystickEvent, GameAction ga); an abstraction that stores all the Class CharacterActions { possible actions supported by bool left, right, jump, crouch; your game engine (this example is } etc. oversimplistic, you might need a more complex structure), and GameInput getInput(); whether the player triggered that } action or not.

  17. Handling User Input: The “Input Map” • Input Map example API: Class GameAction { Class InputMap { Class GameActions { int actionCode; public: List<CharacterActions> controllers; int characterID; } void addKeyboardMap(int key, GameAction ga); } void addKeyboardComboMap(List<int> keys, GameAction ga); void addKeySequenceMap(List<int> keys, GameAction ga); void addMouseButtonMap(int button, GameAction ga); void addJoystickMap(int koystickEvent, GameAction ga); Class CharacterActions { The GameActions class is just a bool left, right, jump, crouch; list with all the input given to all } etc. the characters in the game (either by local players, AIs, or remote players). GameInput getInput(); }

  18. Handling User Input while(!quit) { I = InputMap.getinput (&quit); The game loop calls the input handler to translate user input G.updateAI(&I); to game actions G.updatePhysics(I); G.render(); FPScontrol(); The AI controls characters also by generating game actions } (identical data structure than user input) Physics/animation, etc. do not know if a player is controller by a player, or by an AI.

  19. Handling User Input Input Online Network AI Map Multiplayer Game Actions Rest of the game engine

  20. Handling User Input Although depending on the multiplayer implementation, your game engine might not need to know the actions executed remotely. Input Online Network AI Map Multiplayer Game Actions Rest of the game engine

  21. Outline • Student Presentations • Handling User Input • Multiplayer Games • Networking Basics • Client-Server Architectures • Peer-to-Peer Architectures • Client-side Prediction • Project Discussion

  22. Example Networked Multiplayer Games • Multi-User Dungeons • Early predecessors of today’s MMOs (used a client-server architecture) • Unbounded number of players

  23. Example Networked Multiplayer Games • MUDs have survived, and there are many modern ones:

  24. Example Networked Multiplayer Games • Bolo (1987) • (relatively unknown) Mac-only game, one of the earliest network games ever

  25. Example Networked Multiplayer Games • DOOM (1993) • 4 players over local network (IPX protocol) • Peer-to-peer: deterministic game, sharing actions over network (numbered, to detect lost packets) • Peers used broadcasts • (saturated the network)

  26. Example Networked Multiplayer Games • Quake (1996)

  27. Example Networked Multiplayer Games • Quake (1996) • Featured permanent servers, where players could meet and play (before Quake, you had to coordinate in the real world on a time to play, and share your IP via phone with friends to play! • Client-Server over the internet (not just LAN!) • A new problem appeared (unknown till then): latency! • QuakeWorld: update to Quake just to address latency. Introduced a key idea called “client-side prediction”

  28. Example Networked Multiplayer Games • MMOs, e.g.: RuneScape • network of servers

  29. Outline • Student Presentations • Handling User Input • Multiplayer Games • Networking Basics • Client-Server Architectures • Peer-to-Peer Architectures • Client-side Prediction • Project Discussion

  30. Networking 101 (for Games) • Node : a computer/device in the network • IP : Address of a node (e.g. 194.26.4.80) • Packet : a piece of information transferred from one node to another • Typically a packet is sent to: (IP, port) • IP: address of destination • Port: (1-65535) identifies the service that should respond to this packet • Server : a node that offers some services • Client : a node that requests a service from a server

Recommend


More recommend