The Checkers3D Application


The Java 3D Components

To get BugRunner and Checkers3D to compile and run, you'll need to include relevant bits from Java 3D. On Windows, the OpenGL version of Java 3D consists of four JAR files and three DLLs. The JAR files are j3dcore.jar, j3daudio.jar, vecmath.jar, and j3dutils.jar in <JRE_DIR>\lib\ext\. The DLLs are J3D.dll, j3daudio.dll, and J3DUtils.dll in <JRE_DIR>\bin\. <JRE_DIR> is the directory holding the JRE, typically something like C:\Program Files\Java\j2re1.4.2_02\. If the Java 3D development kit is installed, the files will be found below the J2SE home directory, which is usually something like C:\j2sdk1.4.2_02 or C:\Program Files\Java\jdk1.5.0.

The OS level libraries will vary if the DirectX version of Java 3D is used or if the platform is Linux or the MacOS. The easiest way of finding out Java 3D's composition on your machine is to look through the Java 3D readme file, which is added to the J2SE home directory at installation time.

Java 3D Components for BugRunner

The BugRunner application uses only the J3DTimer, so which of the JAR and DLL files are required? The J3DTimer class is part of the com.sun.j3d.utils.timer package, which is stored in j3dutils.jar (confirm this by looking inside the JAR with a tool such as WinZip), as shown in Figure A-1.

The J3DTimer class (and its inner class) account for about 1 KB out of the 1.2-MB JAR.


A look at the decompiled J3DTimer class, using software such as the DJ Java decompiler (http://members.fortunecity.com/neshkov/dj.html), shows that a small amount of Java code calls J3DUtils.dll to do all the work (see Figure A-2).

For example, the Java method getValue( ) calls the J3DUtils.dll function getNativeTimer( ).

An alternative to decompiling the .class file is to download the original source, which is available from the Java 3D web site.

J3DUtils.dll can be examined with HT Editor, a file editor/viewer/analyzer for Windows executables, available from http://hte.sourceforge.net/ (shown in Figure A-3).

Figure A-1. A WinZip view of j3dutils.jar


Figure A-2. The DJ Java decompiler view of J3DTimer


Figure A-3. The HT editor view of J3DUtils.dll


getNativeTimer( ) uses the Windows kernel32.dll functions QueryPerformanceCounter( ) and QueryPerformanceFrequency( ).

In summary, the calls to J3DTimer require j3dutils.jar and J3DUtils.dll.

j3dutils.jar on a Diet

It may be worthwhile to separate the timer code from j3dutils.jar and put it into its own JAR, thereby saving about 1.2 MB of space. The technique involves un-JARing j3dutils.jar using WinZip or similar compression software. The result is two folders: com/ and meta-inf/. com/ holds the various classes in j3dutils, which can be deleted, aside from the two timer classes in com/sun/j3d/utils/timer/. meta-inf/ holds a manifest file, Manifest.mf, which should be pulled out of the directory and used in the re-JARing process:

     jar cvmf Manifest.mf j3dutils.jar com 

The size of the slimmed down j3dutils.jar is 2 KB, which is quite a difference.


The real drawback with this technique may be a legal one since a Sun-created JAR is being dismembered. Java 3D is open source with some provisos, which may make it okay to release modifications; license information can be found at https://java3d.dev.java.net/. In the rest of this appendix, I'll use the full version of j3dutils.jar to play it safe.



Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net