RTTI: Changes for better

As some of you may know White Rabbit Engine use it's own Run Time Type Information system. And well like with everything else sometimes come time when you need to upgrade stuff. Recently I had another occasion to do iteration over this system.

In this post I will try to give you a little bit insight how m RTTI look is engine, what changed and what are plans for future. But well let's start from begin.

Beginning 

When I was designing own RTTI one of most important aspect was simplicity of use. When you adding RTTI to class it should be straight forward. Minimal amount of code you need to add and simple syntax. I think that in the end I achieve the goal but I won't say that it was like that right away. But well decide yourselves:

* Header

* Source

Later you could use it for dynamic cast::

   // (1) Casting example
   // CRttiObject* rttiObjectClass
   CMyRttiClass* object = WR_RTTI_CAST_PTR(CMyRttiClass, rttiObjectClass);

Or use serialization of attributes that are added in declaration.

In above code all RTT_xyz are macros. They unwrap in meantime of compilation and sadly recently there was problem with parsing them by Visual Assist. It's intellisense stopped working in all my *.cpp with RTTI declarations which made me rally sad :(.

Occasion to changes for better

This was the moment for changes:] For some time I planed to switch part of RTTI on offline generated code. So I took my python project generator and added extra step. It parsing headers file in project where RTTI is enabled and generate from it "rtti_*.cpp" containing RTTI implementation . 

* RttiGenerator.py

Above script is copy-paste from script I use. I think that comments in it tell most of the stuff about usage so I will skip duplicating it. So process works and allow me to do a lot more than before. There is only one issue: right now this step is done in meantime of project generation. So it not update when file change. Because of that I have already plan to include it in building process but well I will do it when I will find some time.

Even more nice changes

Other things I changed is style of casting. You probably don't remember it from above. I also had sometimes problems with remembering it's syntax :D So recently I decided to change it on something more intuitive :

   // (2) Casting example
   // CRttiObject* rttiObjectClass
   CMyRttiClass* object = CMyRttiClass::from(rttiObjectClass);

This may not look like a big change but it's making stuff easier. Comfort of code writing is one of things we always need to take into account. If you think twice how to use something then it's mean that maybe something is wrong with it.

Plans for future

Right now except adding RTTI generation as building step I plan to move even more RTTI code from macros to generated *.cpp. There is also incoming revision of code :/ This maybe not be the funniest part but I want to check if all comments in it are still up to date and clarify few stuff there for behavior of system.

Greg

Comments

Popular posts from this blog

Query commands execution

W.U. 0x20

Lets play : Good code / Bad code