A few months ago on the Google code blog, they demonstrated a port of Quake II to GWT, and had it running in a browser. That's right, a 3D real time game running in a browser without any plugins (not even Flash). HTML5 which is semi-supported by Chrome, Safari, and Firefox includes WebGL which is based on OpenGL. WebGL is a canvas based drawing/rendering system that exposes a JavaScript API for creating 2D and 3D graphics. I had some interest in this, as I still have parts of a 3D networked multiplayer that could make use of this.
My scope for my research was pretty simple: could I create a very simple Maven/GWT project that would create a simple 3D webapp. I started with a basic Maven/GWT webapp project from an archetype I was able to follow the instruction, although I added the step of temporarily removing my local repository mirror since I was dealing with a foreign repository, and I didn't want the mirror to interfere. From there I went to the GwtGL site, which is basic GWT bindings for the WebGL interface. It had two section, how to add what you need to your webapp project to use GwtGL and a sample web app that just displays a white triangle in a black square.
Adding GwtGL was pretty straight forward. Add a div tag to be your canvas, inherit the library in the GWT project descriptor and include the library (and source) in your classpath. Before I could do anything, I needed to download the GwtGL source and binaries and install it in my local repository, as it's not on Maven Central yet. I'm using Sonatype Nexus as a repository manager, and it has a nice artifact upload interface. The standard setup for Nexus includes a 3rd party repository for uploading 3rd party artifacts that have yet to make it to Maven Central. In the zip file download from GwtGL is the binary, source and javadoc jar plus the POM file, and I uploaded all of them to Nexus. For some reason the groupId is com.cooglecode, I'm not sure what that's about. Then I added to the main.html the div tag:
<div id="gwtGL"'></div>
The inheritance tag goes in the GWT project descriptor:
<inherits name='com.googlecode.gwtgl.binding'/>
And finally the binary and source jars need to be added to the dependencies:
<dependency>
<groupId>com.cooglecode.gwtgl</groupId>
<artifactId>gwtgl</artifactId>
<version>0.3</version>
</dependency>
<dependency>
<groupId>com.cooglecode.gwtgl</groupId>
<artifactId>gwtgl</artifactId>
<classifier>sources</classifier>
<version>0.3</version>
</dependency>
The sample code had one issue, it would appear that a class name has changed, but the sample code wasn't updated. After a bit of poking around, I discovered the updated class name for WebGLFloatArray was Float32Array. A quick compile, and run and I had a browser with a black square with a white triangle. Maybe next weekend I'll look at what it will take to convert the 3D game client to run in a browser.
Today I spent some time making an export and import API for the static objects in my factory model. I wanted to be able to import and export to XML all of the parts and build steps, shops and stockrooms that comprise what I call the 'factory matrix'. This is everything that has a static description which isn't supposed to change, and so would probably loaded once into a database and rarely changed. In order to be able to do this with JAXB, I needed to break any cyclic links or bi-directional references. I decided to use the parent/child reference technique where I set the parent reference to transient with the XMLTransient annotation, so it's not set in the initial traversal, but set later on with a callback called afterUnmarshal. The only issue I had was that the XMLTransient annotation needs to go on the bean getter, not on the field itself. I had it on the field, and was still getting cyclic reference exceptions when marshaling the factory matrix. Putting it on the getter, and I was back to 'build success' which always makes my heart happy. In addition to the import and export function, I added a lot of unit tests, hopefully my code coverage reports won't look so dismal tomorrow after new reports are generated.
No comments:
Post a Comment