As the Derydoca engine has been fleshed out, there was one aspect of the engine I have been putting off until it was necessary. Serialization of game assets is necessary to keep a sensible codebase. It is very unwieldy and unmaintainable to hard-code your levels and game assets. I have been doing just that to get me by, but eventually the codebase got too crazy to maintain that I decided to tackle the issue.

The approach I am taking is similar to how Unity is structured. You will have a project folder full of assets that the engine needs to make sense of. Unity keeps track of files by maintaining metadata about the source assets. This metadata can either be stored in a hidden database, or alongside the files themselves. I personally prefer the metadata files being alongside the asset files because you can move both files through any external file management software without breaking references. Another added benefit of having the separate meta files is that they are stored in easy to read YAML format that any text editor can open. For these reasons I decided to follow the same pattern for my engine.

In the Derydoca engine, I have already been using the YAML format for an engine configuration file. It only makes sense for me to use the same formatting for my metadata files. For those of you curious, I am using the library yaml-cpp to parse and create YAML formatted files. The library is pretty straight forward and appears to be well rounded to do pretty much anything you need with YAML files.

I am using the extension of *.derymeta for my metadata files. Currently they contain a single globally unique ID which allows easy linking between files. If a material needs access to a specific texture, all it needs is an ID and the engine will search the asset library for it. In the near future I am planning on adding more fields such as date generated (for refreshing assets that have been modified) and adding the ability for the metadata to specify multiple objects. Assets such as 3D asset files can contain multiple meshes, textures, animations and more which is why the metadata will need to be able to define multiple objects.

At the start of the engine, it will recursively search in a specific directory and create meta files for each non derymeta file that exists in the directory. Then each of these meta objects are loaded into memory. When a scene or object references a particular object by ID, the engine will find that object, load it into memory, and link the two objects together. Currently there is still plenty of work needed for this to be considered complete, but I am working towards that goal.

As always, feel free to check out the project’s code on GitHub and leave a comment below. If you have tackled this problem before and come up with another solution, I’d be glad to hear what it was and why you chose it.