490 likes | 689 Views
The Myths (and Truths) of Java Games Programming. Andrew Davison Dept. of Computer Engineering Prince of Songkla University Hat Yai, Songkhla 90112 Thailand ad@fivedots.coe.psu.ac.th. In a Nutshell. Java for games programming: are you joking? No, Java is a great games programming language.
E N D
The Myths (and Truths) of Java Games Programming Andrew Davison Dept. of Computer EngineeringPrince of Songkla UniversityHat Yai, Songkhla 90112Thailand ad@fivedots.coe.psu.ac.th
In a Nutshell • Java for games programming: are you joking? • No, Java is a great games programming language.
The Familiar Advantages • The object-oriented paradigm. • Cross-platform support. • Code reuse. • Ease of development. • Tool availability. • Reliability and stability. continued
Good documentation. • Support from Sun Microsystems. • Low development costs. • The ability to use legacy code (e.g. C, C++) • Increased programmer productivity. • It's fun, especially for games programming.
Java Bashing • 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.
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
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 continued
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/
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
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. continued
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
Slow-Moan 2: my Program is Slow (because of Java) • Where to lay the blame? • graphics rendering: OpenGL or DirectX • network games: the network
2. Java Has Memory Leaks • Uhh? • Java doesn't offer pointer arithmetic • out-of-bounds array accesses are caught
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
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
Profiling Tools • Java SE 6: jps, jstat, jhat, and jstack • Many third-party tools • e.g. JProfiler
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 sufficientfor all our computingneeds
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
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 design (UML)
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.
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/
4. Installation Is A Nightmare • Java has to be on the machine before the application will run. • Code bloat • even small programs require a 16 MB JRE • Frequently changing JVMs. • Non-standard components are often required (e.g. Java 3D). continued
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
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
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
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
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 continued
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
Java on the PS3? Probably Not • Basic/premium 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
Blu-ray Drives • Support a version of Java called BD-J for: • interactive menus, GUIs • networking applications
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 cards, RAM, internet connections • more exciting game play • many more PC games, particularly in the area of multiplayer online games continued
Mobile gaming • sales rising to US$ 2.5 billion in 2007 • thought to be around 250 million Java-enabled phones • Java ME
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, ... continued
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.
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/ continued
The Java Games factory • http://javagamesfactory.org/ • Works-in-progress • https://games-forge.dev.java.net/ • JavaGaming forums • http://www.javagaming.org/
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
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
Books continued
due out in May 2007 http://fivedots.coe.psu.ac.th/~ad/jg
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 in client/server multiplayer games continued
Version 5.0 • nanosecond timer • Java extension libraries, e.g. • Java 3D • JMF (the Java Media Framework) • the Java Communications API • JAXP (Java’s peer-to-peer API) continued
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/
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
8. In a Nutshell • Java for games programming: are you joking? • No, Java is a great games programming language.