The Myths (and Truths) of Java Games Programming Andrew Davison Dept. of Computer Engineering Prince of Songkla University Hat Yai, Songkhla 90112 Thailand [email protected] Myths.

Download Report

Transcript The Myths (and Truths) of Java Games Programming Andrew Davison Dept. of Computer Engineering Prince of Songkla University Hat Yai, Songkhla 90112 Thailand [email protected] Myths.

The Myths (and Truths) of Java
Games Programming
Andrew Davison
Dept. of Computer Engineering
Prince of Songkla University
Hat Yai, Songkhla 90112
Thailand
[email protected]
Myths
1
In a Nutshell
 Java
for games programming: are you
joking?
 No,
Java is a great games programming
language.
Myths
2
The Familiar Advantages
 The
object-oriented paradigm.
 Cross-platform support.
 Code reuse.
 Ease of development.
 Tool availability.
 Reliability and stability.
Myths
continued
3
 Good
documentation.
 Support from Sun Microsystems.
 Low development costs.
 The ability to use legacy code (e.g. C, C++)
 Increased programmer productivity.
 It's
Myths
fun, especially for games programming.
4
Java Bashing
1.
2.
3.
4.
5.
6.
7.
Myths

Java is too slow for games programming.
Java has memory leaks.
Java is too high-level.
Java application installation is a nightmare.
Java isn't supported on games consoles.
No one uses Java to write 'real' games.
Sun Microsystems isn't interested in supporting
Java gaming.
Almost all of these are substantially wrong.
5
Wake up, it's 2006
 These
objections had more
validity in the late 1990s
– the language and its libraries
were less sophisticated and
slower
– lots of hype led to lots of disappointment
Myths
6
1. Java Is Too Slow For
Games Programming
 Or
"Java is slow compared to C and
C++, the dominant languages for
games programming at the moment."
 JDK
1.0 (1996): 20 to 40 times slower than
C++
 J2SE 5: only 1.1 times slower
 Java SE 6 is about 20% faster than J2SE 5
Myths
continued
7
 Speed
depends on the application
and coding style
– Java programmers must be good programmers
 Jack
Shirazi's Java Performance Tuning site
– http://www.javaperformancetuning.com/
Myths
8
The Hotspot Compiler
 Introduced
in J2SE 1.3.
 The run-time system identifies areas of code
that are utilized many times, and
aggressively compiles them.
 Program
execution is often slow at the
beginning until the code has been analyzed
and compiled
– splash screens API in Java SE 6
Myths
9
Slow-Moan 1: Swing is Slow
 Swing
GUI components don't use
the OS much
– portability, controllablilty
– extra layer of processing above OS
 Some
games applications use the older,
lower-level AWT GUI libraries.
Myths
continued
10
 J2SE
5/6 Swing uses OpenGL/DirectX
more directly
 Most
games don't require complex GUIs
– full-screen game play with mouse and keyboard
controls is the norm
– mouse and keyboard processing is dealt with by
the AWT
– full-screen mode
Myths
11
Slow-Moan 2: my Program is Slow
(because of Java)
 Where
to lay the blame?
– graphics rendering: OpenGL or DirectX
– network games: the network
Myths
12
2. Java Has Memory Leaks
 Uhh?
– Java doesn't offer pointer arithmetic
– out-of-bounds array accesses are caught
Myths
13
Possible Meaning 1
 Defunct
objects are not
being garbage collected.
 Due
to bad programming style
– the garbage collector can only do its job when
an object is completely dereferenced
Myths
14
Possible Meaning 2
 Garbage
collector is executing at
poorly timed intervals.
 The
JVM comes with several different
garbage collectors
– can be selected/fine-tuned from the command
line
Myths
15
Profiling Tools
 Java
SE 6: jps, jstat, jhat, and jstack
 Many
third-party tools
– e.g. JProfiler
Myths
16
3. Java Is Too High-level
 Abstraction
–
–
–
–
versus speed and control
C++ is too high-level
C is too high-level
assembler is too high-level
ICs are too high-level
– an abacus is sufficient
for all our computing
needs
Myths
17
Historical Observation
 The
gaming community used to think that C
and C++ were too high-level. Until:
– Doom and Dungeon Master, mid 1980s
– cross-platform development tools
 e.g.
RenderWare,
Gamebryo
Myths
18
High-level Moan 1
 Java’s
use of classes, objects,
and inheritance add too much
overhead without enough coding benefit.
 Class
libraries are essential:
– high-speed I/O, advanced 2D and 3D graphics,
networking, etc.
 Object-oriented
Myths
design (UML)
19
High-level Moan 2
 Low-level,
fast operations -- such as direct
Video RAM I/O -- are impossible.
 Full-screen
mode
– page flipping
– control over the screen's resolution and image
depth
 Graphics
rendering using OpenGL and
DirectX.
Myths
20
High-level Moan 3
 Java
can't use game peripherals
– e.g. joysticks and game pads
 Yes
it can:
– JNI, the Java Native Interface
– JInput, the game devices API
 https://jinput.dev.java.net/
Myths
21
4. Installation Is A Nightmare
1. Java has to be on the machine before the
application will run.
2. Code bloat
–
even small programs require a 16 MB JRE
3. Frequently changing JVMs.
4. Non-standard components are often
required (e.g. Java 3D).
Myths
continued
22
5.
6.
7.

Myths
It's not possible to compile the application
for a specific platform.
The .jar extension is hijacked by other
software
The JRE is slower to start up compared to
a native compiled application.
Solved with good installation software
–
except for 2 and 7
23
Many Installation Options
 Applets
 Java
SE 6 plug-in
– for Internet Explorer
 Java
Web Start (JWS)
– improved significantly since J2SE 1.4.
 Third-party
installers
– e.g. install4j
Myths
24
Code Bloat
 Increasingly
irrelevant
– many games weighing in at over 100 MB
– many graphics and sound card drivers are larger
than 15 MB
 Network
speeds are a problem, especially
overseas
– broadband usage is growing rapidly
Myths
25
Others
 Sun
Microsystems estimates that around
70% of all new PC's come with a JRE
pre-installed.
 Slow
start-up time, but
– better in Java SE 6
– fairly negligible compared to the total running
time
– Java SE 6's splash screen API
Myths
26
5. Java Isn't Supported On Games
Consoles
 This
criticism has some justification.
 Two
important games platforms:
– the PS2 and Windows
– Java isn't available on the PS2
Myths
continued
27
 Actually
it is possible to run Java on the
PS2 using Sony's version of Linux, but:
– the OS requires the PS2 to have a hard disk
– only limited access to hardware
 Two
trends that may help Java:
– consoles are mutating into home media devices
– the rise of online gaming
Myths
28
Java on the PS3?
 Basic/premium
Probably Not
PS3 versions will have
– 512 MB of RAM, a large hard drive,
Linux support, OpenGL
 Casual
games programming on the PS3
– development kits in Spring 2007
– support for an object-oriented language
 probably
C++/C
– virtual machine utilizes JIT technology
Myths
29
Blu-ray Drives
 Support
a version of Java called BD-J for:
– interactive menus, GUIs
– networking applications
Myths
30
Other Markets
 The
PC market is far from miniscule
– US$ 953 million by the end of 2008
– over a billion in 2009
 Games
on PCs
– superior, modern hardware
 video
Myths
cards, RAM, internet connections
– more exciting game play
– many more PC games, particularly in the area
of multiplayer online games
continued
31
 Mobile
gaming
– sales rising to US$ 2.5 billion in 2007
– thought to be around 250 million Java-enabled
phones
– Java ME
Myths
32
6. No One Uses Java To Write Real
Games
 The
number of commercial Java games is
small, but growing
– won awards and bestsellers
– e.g. Tribal Trouble, Puzzle Pirates, Call of
Juarez, Chrome, Titan Attacks, Star Wars
Galaxies, Runescape, Alien Flux, Kingdom of
Wars, Law and Order II, Ultratron, Roboforge,
IL-2 Sturmovik, Galactic Village, Wurm
Online, ...
Myths
continued
33
Myths
34
Myths
35
Myths
36
Myths
37
Casual Gaming Market
 Java
is used widely in the casual gaming
market
–
–
–
–
game play is more innovative
implementation timelines are shorter
budgets smaller
less man-power needed
 By
2008, the casual games market will
surpass US$2 billion in the US.
Myths
38
Many Java Gaming Sites
 Sun
Microsystems showcase
– http://www.java.com/en/games/
 Community
pages
– http://community.java.net/games/
 Open-source
gaming tools
– https://games.dev.java.net/
Myths
continued
39
 The
Java Games factory
– http://javagamesfactory.org/
 Works-in-progress
– https://games-forge.dev.java.net/
 JavaGaming
forums
– http://www.javagaming.org/
Myths
40
JavaGaming.org
 Best
source of
technical advice
– over 9000 highly opinionated registered users
 Discussion
topics
– Java 3D, Java 2D, Java Sound, J2ME,
networking, online games development,
performance tuning, JOGL, JOAL, JInput, and
more
Myths
41
Open-source Gaming Tools
https://games.dev.java.net/
 JOGL,
a Java binding for OpenGL
 JOAL, a binding for OpenAL (a 3D audio
library)
 JInput, a game devices API
 games-middleware and games-forge
sections
Myths
42
Books
Myths
continued
43
due out in May 2007
http://fivedots.coe.psu.ac.th/~ad/jg
Myths
44
7. Sun Isn't Interested
 J2SE
1.3
– improved graphics and audio capabilities
 Version
1.4
– full-screen mode and page flipping in hardware
– faster I/O, memory mapping
– support for non-block sockets
 useful
Myths
in client/server multiplayer games
continued
45
 Version
5.0
– nanosecond timer
 Java
–
–
–
–
Myths
extension libraries, e.g.
Java 3D
JMF (the Java Media Framework)
the Java Communications API
JAXP (Java’s peer-to-peer API)
continued
46
 Java
SE 6
– improved graphics rendering speeds
– splash screen API, scripting, desktop API
 Sun-sponsored
websites
– http://www.javagaming.org
– http://www.java.net
– http://community.java.net/games/
Myths
47
Sun's Project DarkStar
http://games-darkstar.dev.java.net
 Tools
for supporting massive multi-player
online games.
– server side: Sun Game Server (SGS)
– client APIs for C++,
Java SE, and Java ME
Myths
48
8. In a Nutshell
 Java
for games programming: are you
joking?
 No,
Java is a great games programming
language.
Myths
49