Multi-User MIDP Game Designfivedots.coe.psu.ac.th/Software.coe/J2ME/Nokia Articles/Multi... · 2 ©...

38
1 © NOKIA Multi-User MIDP Game Design Price/Salomaa Multi-User MIDP Game Design David Price, Principal Software Engineer Jyri Salomaa, Program Manager, Games Nokia Research Center, Helsinki

Transcript of Multi-User MIDP Game Designfivedots.coe.psu.ac.th/Software.coe/J2ME/Nokia Articles/Multi... · 2 ©...

1 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Multi-User MIDP Game Design

David Price, Principal Software EngineerJyri Salomaa, Program Manager, Games

Nokia Research Center, Helsinki

2 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Contents

• Examples of Multi-Player Games

• MIDP 1.0 Multi-Player Game Communication Technologies

• MIDP 2.0 Multi-Player Game Communication Technologies

• MIDP “Optional Package” Game Communication Technologies

• Resulting Game Design Options

• Community-Building Features

• Conclusions

• Resources

• Q&A

3 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Examples of Multi-Player GamesOffline• Card games: Poker, Bridge, Rummy, Uno…

• generally 2..4+ players, turn-based• Board games: Monopoly, Scrabble, …

• generally 2..6+ players, turn-based• Sports: Football (all kinds ☺), Ultimate Frisbee, Athletics

• 2..many players, often teams• generally continuous activity• sometimes measured individual activity (e.g. time-trials)• often long-term scoring: leagues etc.

Online• Competitions: Quake, Racing Simulations

• discrete games, often leagues, sometimes virtual teams• Virtual Worlds: Everquest™, Ultima Online™

• continuous simulation, new ‘win’ criteria

4 © NOKIA Multi-User MIDP Game Design Price/Salomaa

MIDP 1.0 Multi-Player Game Communication Technologies

• Phone sharing

• HTTP

5 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Phone Sharing

• I.e. pass one phone between players

• Supports many players, but only one plays at once

• Reliable support in every phone!

6 © NOKIA Multi-User MIDP Game Design Price/Salomaa

HTTP

MobileNetwork Internet

HTTPServer

• Many players at once (client-server only)

• Supported already in MIDP 1.0, but considerations with e.g. mobile gateway conversions

• Server-side: use Servlets, JSP, ASP, CGI, …

7 © NOKIA Multi-User MIDP Game Design Price/Salomaa

HTTP: Latency & Bandwidth

• Latency (round-trip time) is typically a couple of seconds, but can vary greatly

• Bandwidth depends on the networking technology:

2G GSM 14.4 kbps1990s D-AMPS, PDC 9.6 kbps2.5G GPRS up to 50 kbpstoday HSCSD up to 43 kbps

cdmaOne up to 64 kbpsCDMA 1XRTT up to 144 kbps

3G EDGE up to 473 kbpscoming WCDMA up to 2 Mbps

8 © NOKIA Multi-User MIDP Game Design Price/Salomaa

HTTP: IP or Gateways?

HTTP

IPWireless Wireless

Wireless IP RouterTCP

Wired

HTTPTCPIP

Wired

ServerMIDlet

WSP

WDPWireless

WSP

WDPWireless

HTTPTCPIP

WAP Gateway

WTP WTP

Wired

HTTPTCPIP

Wired

ServerMIDlet

WAP 1.x

• Don’t rely on ‘HTTP streaming’, delayed response ‘tricks’

9 © NOKIA Multi-User MIDP Game Design Price/Salomaa

MIDP 2.0 Multi-Player Game Communication Technologies

• All of MIDP 1.0 technologies, plus:

• HTTPS (secure HTTP)

• Optionally:• UDP datagrams• TCP sockets• TLS secure sockets• serial cable• infra-red

10 © NOKIA Multi-User MIDP Game Design Price/Salomaa

HTTPS

• Only new mandatory networking protocol in MIDP 2.0

• From programming point of view, no difference to using HTTP

• May be useful for games involving money, e.g. gambling games

• Server-side: use Servlets, JSP, ASP, CGI, etc…

11 © NOKIA Multi-User MIDP Game Design Price/Salomaa

UDP

MobileNetwork Internet

UDPServer

• Lightweight, unreliable datagram protocol

• Many players at once (client-server only, due to considerations with NATs)

• Wide support likely

• Server-side: use J2SE, write your own server (consider NIO), or buy a third-party server

12 © NOKIA Multi-User MIDP Game Design Price/Salomaa

UDP Latency over GPRS

• Depends on network technology, operator, time of day, …

• Results above were made using a GPRS connection with a local operator in Helsinki, during office hours

• We saw no out-of-order packets, and only 2 lost out of 4000

00.020.040.060.080.10.120.140.16

500

700

900

1100

1300

1500

1700

1900

2100

2300

2500

Round-trip Latency (ms)

Prop

ortio

n of

tota

l

13 © NOKIA Multi-User MIDP Game Design Price/Salomaa

TCP

MobileNetwork Internet

TCPServer

• Reliable, bi-directional connection-oriented protocol• Many players at once (client-server only, due to

considerations with NATs)• Wide support likely• Server-side: use J2SE, write your own server (consider NIO), or

buy a third-party server

14 © NOKIA Multi-User MIDP Game Design Price/Salomaa

TCP Latency over GPRS

0

0.02

0.04

0.06

0.08

0.1

0.12

800

1000

1200

1400

1600

1800

2000

2200

2400

2600

2800

3000

3200

3400

3600

3800

Round-trip Latency (ms)

Prop

ortio

n of

tota

l

• Depends on network technology, operator, time of day, …• Results above were made using a GPRS connection with a

local operator in Helsinki, during office hours• Similar to UDP, long ‘tail’ due to rare lost packet

15 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Game Design for Latency

• Latency is a fact of life – there is no magic solution

• Design your game so that it is not affected by latency

• Don’t try to do ‘mobile multi-player Quake’ – it won’t work over mobile networks

• Some strategies:• slow action games (e.g. Napoleonic ship battle)• make latency part of the game (e.g. remote-controlled

machines)• make players’ actions unaffected by others’ actions (see

example later)• server is master, but clients predict movement and update

predictions when info arrives from server

16 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Network Address Translators / Firewalls

MobileNetwork Internet

TCP/UDPServer

NAT

Phone Mapped Server

a1:p1

a1:p2

a2:p1

nat:q1

nat:q2

nat:q3

b1:r1

b1:r2

b1:r1

• Mapping contains both client & server: {a1:p1, b1:r1 ↔ q1}

17 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Network Address Translators / Firewalls (2)

• May not allow incoming TCP connections

• May not allow incoming UDP packets, except from hosts (& ports) who’ve been sent packets recently

• May discard UDP mappings after just a minute or so

18 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Example: ChatWorld Proto

• Multi-user ‘graphical MUD’ (eventually)

• Client-side is MIDP 2.0 MIDlet

• Server-side ‘gamelet’ deployed into generic ‘gamelet container’

• Client-server protocol is a combination of:• TCP sockets for things that must be

reliable (e.g. logging in)• UDP datagrams for messages that can

be unreliable (e.g. move, face left)

• Caveats:• Work in progress!• not yet tested on phones• not yet tested on real networks

19 © NOKIA Multi-User MIDP Game Design Price/Salomaa

ChatWorld Protocol

Client 1 Server Client 2

open

login(username/pw)TCP

login-ok(session-id,avatar, level) arrive(avatar, x, y, dir)

nop(session-id)UDP

move(avatar-name, x, y, dir)move(session-id, x, y, dir)

close leave(avatar-name)

UDP

TCP

20 © NOKIA Multi-User MIDP Game Design Price/Salomaa

TLS

• Secure sockets (TLS is based on SSL)

• Relevance to games may depend on whether encrypting slows things down too much

• No data yet…

• Server-side: ?

21 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Serial Cable

• Two-player games• Optionally supported in MIDP 2.0 through

SerialPortConnection• Phone-phone cables generally not available though• Probably not a practical option

22 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Infra-Red

• Two-player games• Sensitive to phone orientation

• Also IR port placement differs between models• Optionally supported in MIDP 2.0 through

SerialPortConnection• Trading collectible cards etc.• Probably not a practical option for rapidly interactive gaming

23 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Optional Package Multi-Player Game Communication Technologies

• Bluetooth (JSR-82, Java APIs for Bluetooth)

• SMS (JSR-120, Wireless Messaging API 1.0)

• MMS (JSR-205, Wireless Messaging API 2.0)

• SIP (JSR-180, SIP API for J2ME)

24 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Bluetooth (JSR-82)

• Several players at once (8 max)• Short-range radio, up to about 10 metres• Bandwidth up to ~700kbps, latency about 50ms• No known products support JSR-82 yet

25 © NOKIA Multi-User MIDP Game Design Price/Salomaa

SMS (JSR-120)

MobileNetwork

GameServer

SMSC

• Several players at once (peer-peer or client-server)

• Latency: several seconds..24 hours

• Mandatory in JTWI 1.0

• Too expensive for rapidly interactive games, but ‘play-by-mail’ turns OK?

• Server-side can use SAMS API (JSR-212) in future

26 © NOKIA Multi-User MIDP Game Design Price/Salomaa

MMS (JSR-205)

• Multi-media equivalent of SMS: include pictures and/or audio clips

• MMS is “under the cover” a combination of SMS & HTTP

• MIDP games probably should just use SMS or HTTP directly

• Server-side can use SAMS API (JSR-212) in future

27 © NOKIA Multi-User MIDP Game Design Price/Salomaa

SIP (JSR-180)

• SIP is Session Initiation Protocol

• Could be used for initiating peer-to-peer games

• See:• BOF-1847: “Building MIDlets with SIP API for Java”,

Thursday 9:30-10:20pm, Metropolitan III• TS-1846: “SIP API for J2ME”, Friday 12:15-1:15pm, Room

121

28 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Resulting Game Design Options

• We’ll use the categories Greg Costikyan defined in Introduction to Mobile Game Development [Forum Nokia]:

• Multi-Player Solo-Play Games

• Turn-Based Games• Round-Robin Games• Simultaneous Movement Games

• ‘Act Whenever’ Games

• Slow Update Games

29 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Multi-Player Solo-Play Games

• During a round, each player plays a single-player game, then their scores are compared at the end of the round

• No networking during play, so play can be fast and interactive

• HTTP is mostly enough, if you accept a little polling to see whether the other players have finished

• SMS works fine

• Client-server TCP is ideal

• Bluetooth allows local peer-to-peer

30 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Turn-Based: Round-Robin Games

• Like Chess, Poker, Bridge: players take turns to play

• Some games (e.g. Chess) can be done just by sharing a phone

• Using HTTP requires polling: “is it my turn yet?”

• SMS works fine, but can be expensive if there are lots of turns

• Client-server TCP is ideal

• Bluetooth allows local peer-to-peer

• What happens if one player loses their connection?

31 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Turn-Based: Simultaneous Movement

• Players all take their turn at the same time, e.g. Stone, Paper,Scissors

• Same implementation issues as round-robin

32 © NOKIA Multi-User MIDP Game Design Price/Salomaa

‘Act Whenever’ Games

• Game runs continuously over a long period, continuously simulated ‘world’

• User can enter the game any time and perform some actions

• If no real-time action (e.g. stock-market game), HTTP is suitable

• If actions are infrequent, SMS may be suitable

• If real-time action (e.g. massively multiplayer on-line game), TCP and/or UDP are best, but mobile network latencies still present problems

33 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Slow Update Games

• Again continuous, but in these the player’s agent in the game plays continuously (e.g. resource-management games)

• Player can log in any time, view the game status, and change the agent’s behaviour

• HTTP is probably sufficient, as latency is not typically a factor

34 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Community-Building Features

• Leader boards

• Tournaments

• Chat (slow with phone keyboards, but remember success of SMS)

• Item trading (on-line or via infra-red)

• User-created levels (using MIDlet, or web application?)

35 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Conclusions

• Client-server games can be built today (using HTTP, SMS)

• Peer-to-peer games can be built today (using SMS)

• Rapid, interactive client-server games are coming (using UDP, TCP)

• Rapid, interactive peer-to-peer games are coming (using Bluetooth, SIP)

• Future mobile network technologies (e.g. 3G) will reduce network latencies

• Mobile phones are communication devices – multi-player is the future of mobile games

36 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Resources: Internet

• java.net game section (http://community.java.net/games)• Sun’s game developer site, active discussion groups

• Gamasutra.com (http://www.gamasutra.com)• General game developer site

• Forum Nokia Game Section (http://www.forum.nokia.com/games)

• Articles, example code, discussion groups, support, …

• Greg Costikyan’s site (http://www.costik.com)• Articles on game design, blog, links

37 © NOKIA Multi-User MIDP Game Design Price/Salomaa

Resources: Books• Micro Java Game Development

David Fox & Roman VerhovsekAddison-Wesley, 2002; ISBN: 0672323427

• still the only MIDP game book available, covers MIDP 1.0

• Wireless Java: Developing with J2ME, Second EditionJonathan KnudsenApress, 2003; ISBN: 1590590775

• covers MIDP 2.0, including its new game API

• Networked Virtual EnvironmentsSandeep Singhal & Michael ZydaAddison-Wesley, 1999; ISBN: 0-201-32557-8

• great practical book on technologies for networked virtual reality

• Java Network Programming, 2nd EditionElliote Rusty HaroldO’Reilly, 2000; ISBN: 1-56592-870-9

• great practical Java networking book, but doesn’t cover NIO

38 © NOKIA Multi-User MIDP Game Design Price/Salomaa