Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Created by Phil Banks (@emirpprime)

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Experimentation Rawkets is a graduate from my lab

Slide 6

Slide 6 text

What is Rawkets? Rawkes, WebSockets, and Rockets

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Technology Some of the tech involved in Web gaming

Slide 11

Slide 11 text

Canvas 2D graphics platform

Slide 12

Slide 12 text

Flash audio Sound effects and background music

Slide 13

Slide 13 text

WebSockets Multiplayer communication

Slide 14

Slide 14 text

Node.js Game logic and network communication

Slide 15

Slide 15 text

Issues Making games can be a challenge

Slide 16

Slide 16 text

Networking Not as easy as I thought

Slide 17

Slide 17 text

Message protocol Structured and short communication

Slide 18

Slide 18 text

types = { PING: 1, SYNC: 2, SYNC_COMPLETED: 3, NEW_PLAYER: 4, UPDATE_PLAYER: 5, UPDATE_INPUT: 6, REMOVE_PLAYER: 7 }; Enumeration

Slide 19

Slide 19 text

{ z: 1, id: 1234567890, t: 1316763202872, s: { x: 5, y: 34, v: 3, a: 0.46 } } Message package

Slide 20

Slide 20 text

Compression Reducing data as much as possible

Slide 21

Slide 21 text

Rate limiting Cutting down on communication

Slide 22

Slide 22 text

1 1 MESSAGES IN 1 MESSAGES OUT 1

Slide 23

Slide 23 text

1 2 2 1 MESSAGES IN 2 MESSAGES OUT 4

Slide 24

Slide 24 text

1 4 4 1 1 4 4 1 MESSAGES IN 4 MESSAGES OUT 16

Slide 25

Slide 25 text

MESSAGES IN 30 MESSAGES OUT 900 1 30 30 1 1 30 30 1

Slide 26

Slide 26 text

MESSAGES IN 100 MESSAGES OUT 10000 1 100 100 1 1 100 100 1

Slide 27

Slide 27 text

Intelligence Letting the game prioritise messages

Slide 28

Slide 28 text

Respecting TCP WebSockets uses TCP. Deal with it

Slide 29

Slide 29 text

Obey the order You can’t do much about it

Slide 30

Slide 30 text

Use Socket.IO It intelligently drops messages

Slide 31

Slide 31 text

Cheaters A blessing and a curse

Slide 32

Slide 32 text

Globals and closures Keeping code wide open is bad

Slide 33

Slide 33 text

(function() { var rawkets = rawkets || {}, r = rawkets; rawkets.namespace = function(namespace_str) { var parts = namespace_str.split("."), parent = rawkets, i; if (parts[0] === "rawkets") { parts = parts.slice(1); }; for (i = 0; i < parts.length; i++) { if (typeof parent[parts[i]] === "undefined") { parent[parts[i]] = {}; }; parent = parent[parts[i]]; }; return parent; }; window.rawkets = window.r = rawkets; })(window);

Slide 34

Slide 34 text

Client authority Power isn’t always a good thing

Slide 35

Slide 35 text

Server authority Relinquish that power

Slide 36

Slide 36 text

Input Move Update +0 +40 +80 40ms 40ms 80ms total round-trip Inherent latency

Slide 37

Slide 37 text

Client prediction Server authority isn’t enough

Slide 38

Slide 38 text

Prediction happens here Input Move Update +0 +40 +80 40ms 40ms Instant movement

Slide 39

Slide 39 text

Correction When prediction goes wrong

Slide 40

Slide 40 text

var correction = function(time, state, input, entity, rk4) { ... if (Math.abs(state.x - lastMove.state.x) > 2) { ... var currentTime = time, currentInput = input; entity.setState(state); // Rewind entity state var move, // Current move frameTime; // Time between correction and stored move for (m = 0; m < moveCount; m++) { move = moves[m]; frameTime = (move.time - currentTime) / 1000; // Update physics based on corrected time, input and state ... currentTime = move.time; currentInput = move.input; move.state = entity.getState(); }; }; };

Slide 41

Slide 41 text

Stability Keeping the game running

Slide 42

Slide 42 text

mmonit.com/monit

Slide 43

Slide 43 text

check host rawkets.com with address 127.0.0.1 start program = "/etc/init.d/rawkets start" stop program = "/etc/init.d/rawkets stop" if failed port 8000 type tcp for 2 times within 3 cycles then restart Monit script

Slide 44

Slide 44 text

#!/bin/sh case "$1" in start) cd /rawkets /usr/local/bin/node rawkets.js 2>&1 >> /var/log/node.log & exit 1 ;; stop) /usr/bin/pkill -f 'node rawkets.js' exit 1 ;; esac exit 1 Init.d script

Slide 45

Slide 45 text

github.com/indexzero/forever

Slide 46

Slide 46 text

forever start rawkets.js Forever

Slide 47

Slide 47 text

github.com/hookio/hook.io

Slide 48

Slide 48 text

Why Flash audio? HTML5 Audio isn’t quite ready yet

Slide 49

Slide 49 text

Loads more HTML5 games teach you a lot

Slide 50

Slide 50 text

The future What I’d like to see in JavaScript gaming

Slide 51

Slide 51 text

Something fun I’ve been working on a little tool

Slide 52

Slide 52 text

Game profiler

Slide 53

Slide 53 text

Webkit timeline-like

Slide 54

Slide 54 text

Rob Hawkes Rawkets.com HTML5 & WebSockets game Twitter sentiment analysis Delving into your soul RECENT PROJECTS Rawkes.com Personal website and blog MORE COOL STUFF ExplicitWeb.co.uk Web development podcast Rawket Scientist Technical Evangelist at Mozilla @robhawkes

Slide 55

Slide 55 text

Become a canvas master RAWKES.COM/FOUNDATIONCANVAS Out now Paperback and digital formats Learn how to animate Make two cool space games Foundation HTML5 Canvas

Slide 56

Slide 56 text

November is HTML5 canvas Every month Next month is CSS Media Queries Win prizes (like an Android) DEVELOPER.MOZILLA.ORG/EN-US/DEMOS/DEVDERBY Mozilla Dev Derby

Slide 57

Slide 57 text

Hand-picked experts @ASKMDN & #ASKMDN ON TWITTER One hour every fortnight Web development topics Great discussions Ask MDN ASKMDN onGameStart special (hopefully)

Slide 58

Slide 58 text

No content