1/4/2014 ove näslund java gaming an overview. 2 1/4/2014 ove näslund 2 content demos some game...
TRANSCRIPT
04/10/23
Ove Näslund
Java Gaming
An overview
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
04/10/23
Ove Näslund 33
Some other reading….
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
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
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!
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
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
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)
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
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
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
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 }}
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..
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
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
04/10/23
Ove Näslund 1717
A* path finding
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
04/10/23
Ove Näslund 1919
Some 3D Game effects & algorithms
Particle systemsFlockingGrowing treesLevel of detail
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
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/
04/10/23
Ove Näslund 2222
JME Game picture
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
04/10/23
Ove Näslund 2424
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…
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
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
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…
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)
04/10/23
Ove Näslund 3030
Packaging and Distribution
Java WebStartInstall4J