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
Outline • Student Presentations • Handling User Input • Multiplayer Games • Networking Basics • Client-Server Architectures • Peer-to-Peer Architectures • Client-side Prediction • Project Discussion
Outline • Student Presentations • Handling User Input • Multiplayer Games • Networking Basics • Client-Server Architectures • Peer-to-Peer Architectures • Client-side Prediction • Project Discussion
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”
Outline • Student Presentations • Handling User Input • Multiplayer Games • Networking Basics • Client-Server Architectures • Peer-to-Peer Architectures • Client-side Prediction • Project Discussion
Game Engine Architecture Game Specific Game Engine Functionalities Game Dependencies Resource Management Engine Utility Layer Platform Independence Layer SDKs OS DRIVERS HARDWARE
Game Engine Architecture Online Artificial Scripting Multiplayer Intelligence Gameplay Foundations (Game Loop) Rendering Engine Animation Audio Physics Engine Subsystem Profiling & Collisions Debugging
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.
Trivial Way (Do NOT do this!) boolean cycle() { … If (key_pressed[SPACE] || joystick_button(BUTTON1) || bouse_button_pressed(BUTTON1)) { fireBullet(); } … }
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. }
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?
Handling User Input: The “Input Map” User Input: Game Actions: Move Right Fire ? … Switch weapon
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)
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(); }
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.
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.
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(); }
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.
Handling User Input Input Online Network AI Map Multiplayer Game Actions Rest of the game engine
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
Outline • Student Presentations • Handling User Input • Multiplayer Games • Networking Basics • Client-Server Architectures • Peer-to-Peer Architectures • Client-side Prediction • Project Discussion
Example Networked Multiplayer Games • Multi-User Dungeons • Early predecessors of today’s MMOs (used a client-server architecture) • Unbounded number of players
Example Networked Multiplayer Games • MUDs have survived, and there are many modern ones:
Example Networked Multiplayer Games • Bolo (1987) • (relatively unknown) Mac-only game, one of the earliest network games ever
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)
Example Networked Multiplayer Games • Quake (1996)
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”
Example Networked Multiplayer Games • MMOs, e.g.: RuneScape • network of servers
Outline • Student Presentations • Handling User Input • Multiplayer Games • Networking Basics • Client-Server Architectures • Peer-to-Peer Architectures • Client-side Prediction • Project Discussion
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