scummvm/scummvm — pull request #409 by lordhoto (2013-10-23 22:23:04+00:00)
Title: Enable RTTI and clean up the code by exploiting the availability of dynamic_cast.

This pull request enables RTTI (Run-Time Type Information) again and also exploits its availability in one case to clean up our code. For this, I made SdlGraphicsManager (virtually) inherit from GraphicsManager to reflect the actual conceptional inheritance tree. Additionaly, I moved activateManager/deactivateManager to SdlGraphicsManager since it's only used for subclasses of it. This would not have been possible without RTTI, because we can only do downcasts from GraphicsManager to SdlGraphicsManager, which are needed in the SDL code, in this case with dynamic_cast. The changes in SDL are not the only possible use where RTTI would be beneficial for code cleanness. For example, clone2727 wanted to use it in the WAV audio stream code (or some client) AFAIK.

In the past we disabled RTTI because of binary size [1] (and incorrectly assumed per object dynamic size increase [2]). I made some quick check of commit 092d36f39204df71038a1567c0d4d55bf854b523 with gcc 4.8.2 and -O2 on Linux/amd64 to review the actual code size impact. The results for the stripped binaries are the following:
-fno-rtti, -O2: 25214544 bytes
with rtti, -O2: 25241872 bytes
As you can see the difference is "only" 27328 bytes which is roughly only 0.1% of the actual binary size! Thus, I think we can live with the additional static overhead and thereby gain a useful working dynamic_cast.

Any thoughts on this would be appreciated.

[1]: http://wiki.scummvm.org/index.php/Coding_Conventions#Language_features
[2]: http://wiki.scummvm.org/index.php?title=Coding_Conventions&diff=16774&oldid=16175