libgdx javadocs nightlies

I finally came around modifying the build scripts in the CI server a little so that you have browsable online javadocs. The ones in SVN are pretty out of date, so i figured we should build them each day and serve them from the same host as the nightlies themselves. You can find them at http://libgdx.l33tlabs.org/docs/api/

Note: each release/nightly comes with an offline version of the docs! You can also add the gdx-sources.jar to your project so you have the javadocs in Eclipse/Netbeans/Idea.

lightweight xml parser

I have added a lightweight XML parser to the utils package. Yes, I realize writing a new XML parser is a little crazy, but I had a hunch I could come up with something small and fast, and it was a good exercise of my Ragel skills.

The Xml class parses using SAX-like events and builds a DOM by default. It supports a subset of XML features: elements, attributes, text, predefined entities, CDATA, mixed content. Namespaces are parsed as part of the element or attribute name. Prologs and doctypes are ignored. Only 8-bit character encodings are supported. Input is assumed to be well formed.

So, how does it perform? I compared it to javax.xml.parsers.DocumentBuilder on both the desktop and Android. On the desktop, it is slightly faster for small (1MB) XML documents, and slightly slower for very large (100MB) documents. On Android it is much faster on small documents. Android choked on the 100MB file, so I couldn’t test it. Here are the benchmark results, in seconds:

Android, 1MB:

Java: 1.010742206
Nate: 0.149536137

Desktop, 1MB:

Java: 0.057415785
Nate: 0.044828239

Desktop, 100MB:

Java: 2.189287045
Nate: 3.054689226

The entire XML parser was written in 251 lines of code using Ragel, a FSM compiler. Here is the core of the grammar:

attribute = ^(space | ‘/’ | ‘>’ | ‘=’)+ >buffer %attributeName space* ‘=’ space*
((‘\” ^’\”* >buffer %attribute ‘\”) | (‘”‘ ^'”‘* >buffer %attribute ‘”‘));
element = ‘<' space* ^(space | '/' | '>‘)+ >buffer %elementStart (space+ attribute)*
:>> (space* (‘/’ %elementEndSingle)? space* ‘>’ @element);
elementBody := space* <: ((^'<'+ >buffer %text) <: space*)? element? :>> (‘<' space* '/' ^'>‘+ ‘>’ @elementEnd);
main := space* element space*;

It’s similar to writing regex, except the names like “buffer” and “attribute” are named snippets of Java code that get executed during various FSM state changes. These snippets collect pieces of input, build the DOM, etc.

Ragel is really cool! Now that I’ve used it for TableLayout and this XML parser, I feel comfortable using it to quickly whip up DSLs.

-Nate

BatteryTech by Battery Powered Games!

Check this out. Robert, our dear friend from Battery Powered Games released the first version of BatteryTech, a cross-platform C/C++ game dev framework for Windows, Mac, IOS and Android. Think SDL, but for OpenGL ES. Great stuff. Here’s the introductionary video:

You can find out more at http://www.batterypoweredgames.com/batterytech. It’s a commercial product, 250$ for indies (or game dev companies with < 5 people), 1000$ for bigger studios. Both are one-time fees. Go check it out, it's nice!