Sun Java Solaris Communities My SDN Account Join SDN
 
Article

Professional Java Game Development Tutorial: From the Game Developers Conference, 2004

 
By Dana Nourie, April 2004  
Game Developer's Conference The Game Developers Conference(GDC) attracts over 10,000 attendees, exclusively for the game development professionals driving the $9 billion video game industry. Developers have more than 300 lectures, tutorials and roundtable discussions available to them, covering all aspects of game development across all genres and platforms.

The GDC is held at the Convention Center in San Jose, California every year. I attended the all day Professional Java Game Tutorial with speakers Shawn Kendall, who teaches at Full Sail and has developed Java 3D based game technology demos for both Full Sail and Sun Microsystems, Syrus Mesdagh, who also teaches AI courses at Full Sail and has developed cutting edge game technology for both Full Sail and Sun Microsystems, and Dustin Clingman, professor of Game Design and Development at Full Sail Real World Education and President of the game studio Zeitgeist Games, Inc. In addition, two guest speakers from Sun Microsystems took the podium: Jeff Kesselman, and Doug Twilleager.

Shawn Kendall opened by asking how many Java developers were in the room. About 20 people raised their hands, and when he asked how many people wanted to use Java technologies in game development, all 30 + hands rose. There seemed to be less concern this year about the speed or efficiency when using Java technologies in games, and most of the attendees seemed more concerned with finding out which Java technologies were useful in game development, including the mobile platform. The focus in this tutorial was on networked multiplayer games, which satisfied most the attendees in the room.

Shawn explained that they would cover the newest Java API out for game development, including pros, cons, and issues. Each speaker used slides, which in addition to major points, also included many code samples. The tutorial was loosely organized into the following sections:
  • New IO (NIO)
  • Java Native Interface (JNI)
  • Java Open AL (JOAL)
  • Networking
  • Java 3D
  • Java Open GL (JOGL)
Shawn Kendall explained that for last year's tutorial, he had defined some problems in using Java for game development, and was glad to announce that J2SE 4.x had resolved all of those issues. You can also develop a multiplayer network game almost entirely in Java now because of the new API, and performance is no longer an issue like it used to be. There are many commercial games on the market that were developed using Java technologies, like Star Wars, and one of them using 100% Java, Law & Order.
New IO (NIO)
Syrus Mesdagh opened his presentation with details about the various types of buffering, mainly disk drive, system memory, and application buffers. In addition he explained the differences between buffers and direct buffers, and how buffers are used to cache data to speed up performance. But drives with large buffers can actually slow performance as can intermediate buffers. He then went on to give example code, showing how the Java platform handles buffering.

Next, the biggest benefits of NIO were covered:
  • High Performance file IO
  • Character sets for more robust conversions
  • Scalable Network NIO
  • Channels & Buffers
NIO provides new features and improved performance in the areas of buffer management, scalable network and file I/O, character-set support, and regular expression matching.

After discussing the Java heap versus system memory, MappedByteBuffer, the performance of various Java methods, and how to use the force method to write data, Syrus brought up a slide with benchmarks, comparing copying a file using the Java programming language versus using C. With a buffer size of 16K, Java had copied 100% while native was at 78%. Cyrus also talked about the advantages and benefits of using direct buffers versus non-direct buffers.

No one in the room seemed to need further convincing for performance comparisons, but there were more questions regarding specifics on writing the code. More code examples were shown with detailed discussion.
 
Java Native Interface (JNI)
Each of the speakers stated that you can almost write a game entirely in the Java programming language, but not quite. There are instances where you're likely going to have to make some native function calls. These are sometimes system independent calls and the like. To accomplish this the Java Native Interface (JNI) API are used. JNI enables the integration of code written in the Java programming language with code written in other languages such as C and C++. It allows you to take full advantage of the Java platform without having to abandon your investment in legacy code.

JNI is not used as heavily as it has been in the past, and that need is lessening with each new Java platform release. Use JNI when you need to perform tasks not supported by the Java platform.
 
Java Open AL (JOAL)
Open AL is an open source, cross-platform 3D audio API appropriate for use with gaming applications and many other types of audio applications. Java Open AL is an API with Java bindings layered on the existing Open AL API and provides hardware support and spatialized audio for games written with Java technologies.

Dustin Clingman explained that if you know how to use Open AL, then using Java Open AL (JOAL) is a snap. Even if you're not familiar with this API, learning it is fairly easy, though there are still some problems with implementing into games.

Dustin asked if anyone was currently using the JavaSound API, but no one said they were. He then went onto explain that JOAL competes directly with JavaSound. JavaSound and is good for many types of applications, but it doesn't take advantage of the hardware, such as sound cards, the way JOAL does.

Core classes discussed in Open AL:
  • Alut Class -- Simplifies initialization
  • Buffer Class -- Caches audio data that you want to play back
  • Source Class -- Contains information about a sound not directly related to audio sound, but contains controls for starting and stopping
Open AL is extensible and currently supports EAX, AC3, and Ogg Vorbis. JOAL is expanding EAX and additional support, and is solid for standard playback. The source trees for the Java bindings are open for custom implementation as needed.
 
Networking
Jeffrey Kesselman, Server Architect with Sun Microsystems Game Technology Group, talked about the current format of network games, and that all are basically MUDs, like the Everquest game, and the problems with that model. He explained the differences between latency and bandwidth, and issues of reliability. How likely it is for a packet to make it to the other side? Which is more reliable, UDP or TCP/IP? You need to design games within the understanding of your communication environment.
 
Game Communication
TCP/IP is a more reliable connected protocol and likely what you'd use for your games. Players are playing in a frame-wise synchronized set of simulations. All input is resolved for each frame. The advantages of this are that everyone sees the same thing, packets can be small, and it's secure. The disadvantages are that updates are frequent, it ties everyone, and it's very latency-sensitive.

In an open loop asynchronous format, every player is running independent simulations, updates are periodic, and it's suitable for Wide Area Networks (WAN). Local Area Networks (LAN) are easier to work with if you are just learning to develop games.
 
Connection Types
Connection types among players are still varied, each with their own set of problems and reliability issues:
  • Analog modems: Slow, but still very common to players
  • DSL/Cable: Faster than modems with fewer issues
  • Satellite: Not as popular and not good for playing games because of high latency issues
  • Local Internet
 
Server Side Logic
After a bit of discussion on controller object state communication and client side logic, Jeffrey went into the details of server  side logic.

On the server end you need to consider how secure your data center is, what kind of connections players are using, latency issues, and scalability. In addition, you need to understand that most games use the MUD model. This means that region=room + geometry. Each region has its own server. Because players don't spread themselves evenly across regions, this going to mean that certain severs have more players than other servers. Server capacity may reach its limit for one region, while another region is fairly empty. This also causes problems for players who want to buddy or team up. Server architecture may separate them.

This discussion led into the announcement of the new Sun server technology.
 
The Sun Sim Server Technology
The Sun Sim Server Technology has several advantages over other servers for game playing:
  • CPU and memory is assigned to players, not spaces
  • Entire world state exists as data in a persistent, fault-tolerant data store
  • Reduces programming complexity
  • Processing layer is event-driven and totally stateless
  • Processors check out parts of the world as needed and then put them back
No date for release or availability was given.
 
Java 3D and Java Open GL (JOGL)
Java 3D API works well and is perfectly acceptable for game development. The Java 3D provides a set of object-oriented interfaces that support a simple, high-level programming model you can use to build, render, and control the behavior of 3D objects and visual environments. Shawn Kendall showed an example of a car racing game they had created for last year's tutorial that relied on Java 3D. It ran well and looked like any car racing game you've seen.

But in game development, Java 3D does have some limitations that will likely lead you to implementing Java Open GL, which allows you more control over your images. Java 3D is primarily a 3D scene graph API. It does demand a certain framework, but it is not a game framework.

JOGL is designed to provide hardware-supported 3D graphics to applications written in Java. It is part of a suite of open-source technologies initiated by the Game Technology Group at Sun Microsystems. JOGL provides full access to the API's in the OpenGL 1.4 specification as well as nearly all vendor extensions, and integrates with the AWT and Swing widget sets.
 
Wrapping it Up
Each speaker used detailed slides, gave thorough code examples, and provided lots of explanation. The listeners had questions about the code examples, asked for additional samples, which were provided, and seemed enthusiastic about Java technologies being used in game development. Many also had questions about what Sun had in store for further game technologies and where the Game Technology group was headed.

Doug Twilleager answered these questions and talked a bit about Sun's focus on the desktop, Java Desktop, and Looking Glass. The tutorial session went from 10 am until 6 pm, with breaks and lunch between. Many concepts and issues around game development with Java technologies were addressed, and it appears that this technology is becoming more popular in the game world and speed and efficiency are not the problem they used to be.
 
For More Information
  • Game Developers Conference -- Industry luminaries lead more than 300 lectures, tutorials, panels and roundtables covering all aspects of the industry for all platforms and all genres.
  • java.net -- The source for Java technology collaboration.
  • Java Native Interface (JNI) -- Java Native Interface (JNI) is a standard programming interface for writing Java native methods and embedding the Java virtual machine1 into native applications. The primary goal is binary compatibility of native method libraries across all Java virtual machine implementations on a given platform.
  • New IO (NIO) -- Defines buffers, which are containers for data, and provides an overview of the other NIO packages.
  • JOAL-- The JOAL Project hosts a reference implementation of the Java bindings for OpenAL API, and is designed to provide hardware-supported 3D spatialized audio for games written in Java.
  • JOGL -- JOGL provides full access to the APIs in the OpenGL 1.4 specification as well as nearly all vendor extensions, and integrates with the AWT and Swing widget sets.
  • Practical Java Game Programming (Game Development Series) by Dustin Clingman, Shawn Kendall, and Syrus Mesdaghi



1 As used on this web site, the terms "Java virtual machine" or "JVM" mean a virtual machine for the Java platform.
 

Reader Feedback
Excellent   Good   Fair   Poor  

If you have other comments or ideas for future technical content, please type them here:

Comments:

If you would like a reply to your comment, please submit your email address:
Note: We may not respond to all submitted comments.


Have a question about Java programming? Use Java Online Support.

Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.