[Scummvm-devel] About common code

Max Horn max at quendi.de
Fri Jan 21 11:08:10 CET 2011


Folks,

when you put stuff into common (or sound, graphics, etc.) then I would strongly advice that you always include a comment that explains what the code is good for, and which engine*s* use it. Our common/ dir is growing more and more, and it thus gets harder and harder to keep track of what stuff is good for what. Esp. when there are no comments, and there are only scarce hints in the commit message history of the file.

For the future, we may have to re-think our whole "common" code approach, I think. Common started out with some generic code that was really used by almost all engines resp. generic code in gui. Nowadays, it (and its siblings) contains more and more code which is relevant for only a few selected engines. Now, of course it is very much desirable to share code between engines. But it also increases the size of the main binary, which is a severe issue, esp. on low-end ports like the Nintendo DS. 

We started some time ago to tag some "common" code with checks of the "#ifdef ENGINE_FOOBAR_ENABLED" kind. But that, too, is problematic when doing plugin builds etc.
So, we should think about ways to mitigate this issue. In any case, I predict that the NDS port will get yet again a lot tougher to make for 1.3.0, which is not nice. We are bloating more and more!

Suggestions on what to do are welcome. One would be to move code which is only used by only a handful engines to a separate place(s). Come up with a good way to flag code clearly as to which engines need it and which don't. One that interacts reliably with our build system, too (right now we again and again get re-build issues after a configure run changed which engines are active).

In static build, only code that is *really* needed by the active engines gets compiled in. But we are very lax in enforcing this.

For plugin builds, we currently always compile in all common code. We could think about moving some of that out into plugins of their own, which then are only loaded when the relevant engines are loaded. That would, however, require us to declare dependencies between plugins, and makes things a lot more complicated.
An alternative to that would be to only modify the build system: If building in plugin mode, the code which is common to only a few engines is not linked into the main binary, but rather each relevant engine receives its own copy of it.  There are various ways to tackle this (even the ancient method of #including a .cpp file into another). 

Thoughts, and active contributions, as always are welcome. Sadly, it's unlikely that I will be able to push any of this, and so my hopes are not high. But I feel that I should at least raise the issue for discussion and to increase awareness of it.

Bye,
Max






More information about the Scummvm-devel mailing list