Handmade Network»Forums
György Straub
3 posts
Hierarchical Data to C++ Aggregate
Edited by György Straub on Reason: Initial post
Hello Everyone,

Happy New Year! First post here; hopefully in the right place.

I wanted to share a technique that I have developed while working on my game-from-scratch. It facilitates working with data that comes from a hierarchical data file, which is compiled into a C++ aggregate offline, and populated in one go.

http://blog.nuclearheart.com/2021...hierarchical-data-to-c-aggregate/

This was actually inspired by another member's post, https://yave.handmade.network/blo...media_molecule_does_serialization

Feedback is most welcome. Thanks and see you around!
Simon Anciaux
1337 posts
Hierarchical Data to C++ Aggregate
I don't remember how it's called, but I've seen people using that technique to generate OpenGL function loader (the #define + #include + #undef part).

Did I understood correctly, that the data file (xson config) is the part that is parsed offline and will dictates what the actual structures will look like ?

In the past I used the opposite way: I defined the "config.inc" file ( XSON_VALUE(...), XSON_STRUCT(name) ... ) manually and use the macro to generate the default config file and parsing code. The other way doesn't make sens to me as adding fields using the config file isn't useful if the game code doesn't use it.

A side note: the code samples display on your site could be better. At the moment every line is gray and underline with gray.
György Straub
3 posts
Hierarchical Data to C++ Aggregate


Did I understood correctly, that the data file (xson config) is the part that is parsed offline and will dictates what the actual structures will look like ?


That's right.

In the past I used the opposite way: I defined the "config.inc" file ( XSON_VALUE(...), XSON_STRUCT(name) ... ) manually and use the macro to generate the default config file and parsing code. The other way doesn't make sens to me as adding fields using the config file isn't useful if the game code doesn't use it.


Ah, interesting. I suppose that works just as well, though I felt more comfortable writing the xon/json format than the macros (and so it didn't occur to me to do that way).

A side note: the code samples display on your site could be better. At the moment every line is gray and underline with gray.


Thank you, I wholeheartedly agree (and hate the template I'm using)... I'll see what I can do to improve it, though removing the damn underline should be easy enough.

György Straub
3 posts
Hierarchical Data to C++ Aggregate
I've updated the style. Took a bit of digging around.

Turns out, the underline was border-bottom. Class.