tjhancocks / kestrel-development-kit

A Development Kit for the Kestrel Game Engine
MIT License
13 stars 1 forks source link

Update Assembler #3

Closed tjhancocks closed 4 years ago

tjhancocks commented 4 years ago

This introduces a more sophisticated and featured final assembler into kas. This assembler is responsible for taking a kdk::resource object (which contains all of the information specified in the input KDL source) and builds a binary data object that represents the resource Kestrel would expect to use.


Current Limitations

At present file reference types have not been implemented, due to the type mechanism not being fully fleshed out. This will need to wait for a type mechanism to be devised so that the assembler knows what resource type the file contents should be stored with in. This mechanism will also need to a mechanism for determining appropriate Resource ID's.

Usage

Resource Type Assemblers are implemented as distinct classes that inherit from the kdk::assembler base class. The base class provides the guts and workings of the assembler, whilst the subclass should define the general structure of the binary data for the resource.

class foo : public assembler
{
public:
    using assembler::assembler;
    rsrc::data assemble();
}

The binary data structure is defined in the kdk::sprite_animation::assemble() function, progressively, as the assembler operates.

Take the following KDL

declare Foo {
     new(id = #128) {
        bar = 5 "Hello";
    }
}

We could define this field in the foo type assembler like so:

rsrc::data kdk::foo::assemble()
{
     assembler::assemble(
         kdk::assembler::field::named("bar").set_required(true).set_values({
               kdk::assembler::field::value::expect("count", kdk::assembler::field::value::type::integer, 0, 2),
               kdk::assembler::field::value::expect("note", kdk::assembler::field::value::type::string, 2, 32),
        })
    );

    return assembler::assemble();
}

Further documentation will follow with a subsequent piece of work once things have been further fleshed out.