DEVLOG 2023-07-22


This week in the adventure of prototyping MEGASTRUCTURES we hit some roadblocks. Last Wednesday in livestream after some debugging to fix a typically-C++-esque sequence of errors, we started looking at how in GDExtension/Godot to pass values to GDScript/Godot. You see the system in the model of our prototype relies on Events and Actions to be exchanged between the “model” part and the “view” part. So if the view is implemented in GDScript, it needs to be able to read the events and maybe also create and push actions when the player decides to do one (by clicking on something or using a keyboard key). Actions and Events are currently value-types categories which means every one of these types are very simple aggregate of data, for example the Move action contains just the id of who moves and where. This is a prototype so no need for fancy meta-information for now. The difficult part is that each Event or Action have it’s meaning embedded in it’s type, like Moved means someone moved, Waited means someone waited etc.. Event and Action are not actual type names, but concepts (C++ concepts) which helps check/categorize a bunch of types. Move is a type, Wait is another type, they are not related in any way other than they match the Action concept. This is super helpful in a lot of ways (correctness at compile-time, long-term maintenance, efficiency/performance and various other ways) but also means that when passing to another language, we need to “translate” every event and action type so that they can be read by that other language. To do that once and not have to make a serialization layer for every different language, there was a kind of library I was looking for similar to Boost.Serialization but simpler that was designed to help with this case. I couldnt find it again but it was not necessary for the protoyping to go on, we can just do the Godot version directly as other alternative view implementations will be in C++ directly.

Godot have a general type “Variant” which is a variant (a union) of any type possible. So in theory I can push in a Variant any event or action type and as long as there is the translation layer somewhere available the event or action will be readable in GDSCript, just not with a strong type. So it should be easy to pass these values around right?

Nope: Godot doesnt have a concept of a value-type (assignation copies, passing in functions copies by default, identity is in the value). After some research we found for example this thread proposing to add a struct type category, but it was posted the same day of the livestream, so the same day I was looking into that issue. Worst: it’s not really a value-type being proposed but something in-between. It could work for me though, but it will not be available (if people even agree on what it is) for a long time.

So what are my choices?

  1. Drive the whole view code with only C++. That’s not ideal nor practical as long as hot-reloading is not working for GDExtensions, but still doable.
  2. Just expose Events and Actions as “objects” which means they are not value-semantics anymore outside the boundaries of the model. Totally ineficient and bordeline incorrect, but acceptable in our prototype.
  3. Switch to one of the view implementation possibles which are more compatible with C++. Tempting!

I didnt decide yet but will through the weekend and hopefully some more progress will happen this coming week. I’m glad I decided to spend some time just checking my assumptions about this setup as it shows a lot of flaws I would have been sad about if I was working on the game proper.

Leave a comment

Log in with itch.io to leave a comment.