30
07/02/22 Ove Näslund Java Gaming An overview

1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

Embed Size (px)

Citation preview

Page 1: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund

Java Gaming

An overview

Page 2: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 22

Content

DemosSome game typesJava as Game language Game building issuesAPI:s for 2D game developmentAPI:s for 3D game developmentAPI:s for Mobile game development Example of game enginesInstallation

Page 3: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 33

Some other reading….

Page 4: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 44

Some game types

Arcade games2D Games2D Side scroller

Isometric tile games3D games

FPS – First Person Shooter3D Mazes

Network games

Page 5: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 55

Why not Java?

To slow?Java isn’t slow anymore!Most of a graphic Game is handled by HW

Memory problems?Avoiding/ensuring GC is about programming style

To high level?C/C++ was that too!!High level OO helps design of complex gamesMany new API:s for game supportJni

Page 6: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 66

Why not Java?

Installation nightmareCode bloat of JVM – well most games today are > 100MBSlow startup – Yes, but is a small part of game time!Installation – Java Webstart & Install4j

SupportSun is more active to add API:s for gamesGame consoles doesn’t support Java! (80% market)But, modern mobile phones support Java!

Page 7: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 77

Game Framework

Game loopSprites, Animated sprites e.g explosionsCollision detectionPausing, exitImage repository (loading and sharing)Model repositorySound player & repository – (Midi, mp3 clips)Object manager – control the GCInput handling – mouse, keyboard, game pad etcBoards e.g. High score list

Page 8: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 88

It’s all about time

Update of screenNo flickerNo stops – hack in viewingSame update speed on all HW

Update of game stateMore important than update of screen

Page 9: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 99

Time Control

Keeping constant timeFPS – Frames Per SecondUPS – Updates Per Second

Normally 70-80 FPSUpper bound is the monitor refresh rate (70-90 Hz)

Page 10: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 1010

Measuring Time

Resolution of time – OS dependentSystem.currentTimeMillis() – resolution 1-60 msSystem.nanoTime() Java 5 – resolution 1-6 msJava.util.concurrent.TimeUnit Java 5 – ns resolutionJ3DTimer Java3D – resolution 200-900 ns

Other timersjavax.swing.Timer and java.utility.Timer – uses System.currentTimeMillis() and is hard to controlTimer in Java Media Framework JMFGame engines

Page 11: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 1111

Sleeping Better

Sleeping The Thread.sleep() accuracy is OS dependent (10%-20% error for a 1 ms sleep time)Oversleep must be handled

Page 12: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 1212

A game loop

Update game state

Render game state

End loop

Time calculations

Finished?

Sleep?

Sleep & calc over sleep

late?

Update game state

Yes

Yes

No

No

Yes

No

Page 13: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 1313

while(running) { // Game loop gameUpdate(); gameRender(); // render the game to a buffer paintScreen(); // draw the buffer on-screen afterTime = J3DTimer.getValue(); timeDiff = afterTime - beforeTime; sleepTime = (period - timeDiff) - overSleepTime; if (sleepTime > 0) { // some time left in this cycle try { Thread.sleep(sleepTime/1000000L); // nano -> ms } catch(InterruptedException ex){} overSleepTime = (J3DTimer.getValue() - afterTime) - sleepTime; } else { // sleepTime <= 0; the frame took longer than the period excess -= sleepTime; // store excess time value overSleepTime = 0L; if (++noDelays >= NO_DELAYS_PER_YIELD) { Thread.yield(); // give another thread a chance to run noDelays = 0; }} beforeTime = J3DTimer.getValue(); /* If frame animation is taking too long, update the game state without rendering it, to get the updates/sec nearer to the required FPS. */ int skips = 0; while((excess > period) && (skips < MAX_FRAME_SKIPS)) { excess -= period; skips++; gameUpdate(); // update state but don't render }}

Page 14: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 1414

A little about Collision Detection

Boundary checkComplex figures are approximated

Bit overlapOne step-aheadIn 3D it’s about vector mathematics

Sphere plane collisionBoundary box Ray tracing

And time Don’t forget large steps…

Finally what to doExplode, Bounce, Stop, Penetrate..

Page 15: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 1515

2D and Isometric Game issues

Choice of viewFSEM or Windows2D v.s. IsometricScreen size and resolution

Moving backgroundsPlanning time for loading and GCGraphic and sound

Background Event effects – sound synchronized

Choice of input

Page 16: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 1616

Some 2D and Isometric algorithms

Collision detectionMap creationPath finding

A* - find the “lowest cost” way from A to BD* - dynamic A*

Flocking

Page 17: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 1717

A* path finding

Page 18: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 1818

Some 3D Game issues

Scene graph – the world Floor, boundaries, Sky Creating and loading models

Combining 2D and 3DSprites, menu's etc

Viewer position and movementFirst person cameraHovering ”following” cameraGravity – ground follower, flyer

PickingLightningCollision detection

Page 19: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 1919

Some 3D Game effects & algorithms

Particle systemsFlockingGrowing treesLevel of detail

Page 20: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 2020

Desktop API:s for game development

BasicsJDK

GraphicsFSEM, Java 2D, Java 3D, (JOGL, LWJGL, GL4Java)

SoundJOAL / Sound 3D, JMF

ControlJInput

DistributionJava WebStart, Install4j

Other ODEJava

Page 21: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 2121

Some Free Game Engines

Free 2D game enginesMeat Fighter - http://meatfighter.comGAGE - http://java.dnsalias.comGTGE - http://goldenstudios.or.id/products/GTGE

Free 3D game enginesJake2 (Quake2) - http://bytonic.de/html/jake2.html JGE - https://jge.dev.java.netJME - http://www.jmonkeyengine.com/

Page 22: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 2222

JME Game picture

Page 23: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 2323

Building 3D worlds

Design tools3D Studio MaxMaya - AutodeskTerragenMonkey World 3DMany more…

Some file formatsDXF - AutodeskVRMLM3G – Mobile (JSR184)MD2 – QuakeII

Page 24: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 2424

Page 25: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 2525

Mobile Game issues

Small memoryLow processor speedLack of floating point calc HW supportSmall screens Inconsistent capability between phones

Configuration of screen, MIDP version, input etcDistribution of many configuration versions

More…

Page 26: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 2626

Mobile API:s for game development

BasicsMIDP1.0, MIDP2.0 - Java Game (JSR 134)

GraphicsJava Game (Sprites), Mobile Java 3D (JSR183), Java Bindings For OpenGL ES (JSR 239), Mascot Capsule Micro3D Engine

SoundJava Game, Mobile Media API (JSR 135)

ControlJava Game

NetworkingThreadsDistribution

Page 27: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 2727

Network games – topology

host5

host4

host2

host1

host3

host5

host4

host2

host1

host3

Server

host5

host4

host2

host1

host3

Ring

All-to-allPeer-to-Peer

Star

Page 28: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 2828

Network games - issues

Protocol - UDP, TCP, http, IP multicastingGame typeBandwidth, firewalls, robustness

Fat client vs. fat server logic Security

Transport Anonymous usersMore…

Page 29: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 2929

Java networking API:s

Plain sockets UDP/ TCP, Java Secure Sockets Extension - SSL TLS IP multicasting P2P – JXTA www.jxta.orgURL classJ2EE – ServletsApplets (Multicast ?)RMIService Architecture

JiniWebServices e.g Axis

Sun Project Darkstar MMORGP (Massive Multiplayer Online Roleplaying Game Platform)

Page 30: 1/4/2014 Ove Näslund Java Gaming An overview. 2 1/4/2014 Ove Näslund 2 Content Demos Some game types Java as Game language Game building issues API:s

04/10/23

Ove Näslund 3030

Packaging and Distribution

Java WebStartInstall4J