Re: Reflection in game engine (c++)

Tinco Andringa <[email protected]> Thu, 14 Mar 2013 19:36:21 +0100
Newsgroups gmane.games.devel.sweng
Message-ID <CAGW=8RqPSn_yPX7ChH1xYGvn04x1QPoi5+HBaVP1puCVaRmhfg@mail.gmail.com>
Hi Gabriel,

In an effort to make C/C++ more like C# I did a bit of research into
adding type/signature information to binaries using clang. A downside
of this approach is that you're restricted to the clang compiler, but
in return you get a lot of power over the compilation process.

The idea is rather simple, the compiler visits all nodes in the C++
AST, you can write a clang module that hooks into that process and
record type information and then at the end store it in a section of
the binary. Then in your code you can simply refer to that section and
read it to get type information.

But that being said, it's a rather ambitious project and I don't
really see how going on such a quest is a wise time investment for
your game pipeline.

Some of the things you mention (serializing, streaming) can be done by
having a neat data model and a good serialization protocol. For
example if your game uses a CES architecture you just need a
serialization for the data structure of each component. Together with
the id's of the components and the objects you could stream in or out
any aspect of the game without ever needing reflection.

I imagine you could even dynamically load/replace components sent over
the network, enabling some sort of hot code swapping :)

Is your game architected in such a way that that would be possible?
Perhaps if your codebase is very large already it's not feasible to
rearchitect to such an extent, though I've heard some studios switched
to CES in the middle of their dev process. It is possible to gradually
migrate from hierarchical architecture to CES (I'm doing so for my own
project atm too).

Hope this is useful.

Kind regards,
Tinco


On Thu, Mar 14, 2013 at 7:09 PM, Gabriel Sassone <[email protected]> wrote:
> Hello gents,
>    I wanted to experiment with reflection and I found different way to
> obtain it:
>
>   1) Invasive macro based registration
>   2) Reflection visitor pattern
>   3) Parsing pdb/clang stuff and create a manual table of what you want/need
>   4) c++ custom parser that uses tags to create reflection informations
> (like a comment near a member, ...) (exuberant ctags???)
>   5) create serializable/reflected classes in a data format, then run a tool
> that generates headers and cpps
>
> I am trying to figure out flaws and merits of each kind, and even if there
> are other solutions.
> I love the idea to have the possibility to serialize in and out structures,
> access fields and change values, stream in/out stuff from network ,and maybe
> link with scripting.
>
> My goal is to have fast iteration times, both artists and programmers, and I
> achieved it for rendering programmers already with having json binarized
> configurable rendering, but still there are code stuff that are not easy to
> achieve.
>
> Here are my thoughts, but I would like to hear your ideas and experiences!
>
> 1) Very precise on what you can register/serialize, but painful to maintain
> or plug into an existing codebase
> 2) Less precise but you just need one method per class, that you can use to
> serialize/reflect. Still bad in maintaining, but better in plugging in.
> 3) You make the compiler do the work, then translate the informations you
> need in your format. Easy to maintain, to plug...maybe slow in parsing? Slow
> your build pipeline?
> 4) maybe easier than using pdbs, but less powerful (you cannot invoke
> methods on objects). should be faster than 3.
> 5) crazy idea. requires generation of code from outside...powerful like 4,
> so data reflection, but you cannot invoke methods if you want.
>
> What are your experiences/thoughts?
>
> Thanks to everyone that read this mail!
>
>     Gabriel
>
>
> _______________________________________________
> Sweng-Gamedev mailing list
> [email protected]
> http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com
>
_______________________________________________
Sweng-Gamedev mailing list
[email protected]
http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com