I Wanted Orange (The machine would not make a mistake.)


Codec decorators in Preon: The right way

Here's the wrong way to use decorators in Preon. They'll only work on the first level, and won't apply to nested Preon objects.

final DefaultCodecFactory fact = new DefaultCodecFactory();
Codec<MyFileType> codec = fact.create(MyFileType.class);
final LoggingDecorator ld = new LoggingDecorator(new CustomLogger());
codec = ld.decorate(codec,null,MyFileType.class,null);
// Resulting codec only does outermost-level logging.

The right way appears to be:

final DefaultCodecFactory fact = new DefaultCodecFactory();
final CodecDecorator[] decorators = new CodecDecorator[]{
    new LoggingDecorator(new CustomLogger())
final Codec<MyFileType> codec = fact.create(null, MyFileType.class, new CodecFactory[]{},decorators);
I haven't found any other way to alter the decorator-chain yet.
Tagged as: Comments Off

Working on Hl2Parse: Learning Git, working with Preon

Working on Hl2Parse this week. I want to release it at some point, but I don't really want to stick with my own hodgepodge of code for reading binary files. Sure, it works, it's customizable, but I still think something could be better. Preon caught my eye a while back, and I'm going to try to rewrite my code to use it.

As a bonus, this offers me an opportunity to experiment with Git, which I've been meaning to learn for a while after being used to Subversion. It also offers some interesting possibilities when it comes to synchronizing work I might do on different computers.

Once I get existing binary file functionality (BSP, MDL, PHY, Clientregistry.blob, etc.) translated into Preon annotations, I can see about adding more detail to the MDLs and parsing PCF dependencies.


Binary parsing in Java

Well, PackBSP 2.0.4 may be delayed a bit due to extra complications in parsing the MDL files... In addition, I'm revisiting the idea of using Preon to more-easily program in the parsing rules. I tried it out a few months ago but decided to avoid it due to some blocking bugs. Now, however, with it getting a bit more activity and I want to see if it can replace some of my serviceable but-not-that-pretty code.

Here's a quick (incomplete) bit of sample code for MDL parsing. The Java class is being annotated so that the Preon framework can semi-magically shove data into it.

public class Mdl {

    @BoundString(match = "IDST", size = "4")
    protected String magicHeader;
    protected int version;
    protected int checksum;
    @BoundString(size = "64")
    protected String modelName;
    protected int dataLength;
    protected Vector3f eyePosition;
    protected Vector3f illumposition;
    protected Vector3f hull_min;
    protected Vector3f hull_max;
    protected Vector3f view_bbmin;
    protected Vector3f view_bbmax;

    protected byte[] flags; //FIXME: Use boolean or bitset

    protected int boneCount;
    protected int boneIndex;

    protected Bone[] bones;
Tagged as: , 1 Comment