Good day everyone.
Over the past couple of years I've worked, on and off, on a 2D game development framework using C# and Mono for cross-platform development. It's been a great learning experience and definitely useful. I've recently begun a new iteration in order to implement a number of lessons I've learned.
The current focus of my attention is implementing the game object model and transform hierarchy. Currently I have a Transform2D class which keeps track of local transform data (translation and rotation only for now) in addition to keeping track of its parent and children transformations. This is used to propagate 'dirtiness' as needed and to calculate the world matrix.
I am now implementing the GameObject class. Every GameObject has a transformation. GameObjects are similarly arranged in a hierarchy and this is where things get tricky. It seems highly problematic, on many levels, to manage two hierarchies. Furthermore, it is important that the GameObject hierarchy is the same as the GameObject's transformation hierarchy. That is to say, the GameObject's Transform's parent should be the same as the GameObject's parent's Transform. So, it seemed like a good idea to simply allow the Transform to dictate the hierarchy.
However, I also need the ability to use Transforms independently of GameObjects. That means that a Transform may, potentially, have no attached GameObject and this would introduce 'gaps' into the GameObject hierarchy. There are certainly ways to work around that problem, but most of them violate violate the contract offered by the Transform class. It has become quite apparent that I am trying to use one class for two distinct purposes, and that is a problem.
One solution is to drop the notion of a GameObject hierarchy entirely. Another is to create multiple types derived from Transform2D, but that hardly seems ideal. I could also make a GameObject's transform private and control parent-setting access, but that introduces a number of irritating properties to GameObject.
Anyway, I though I would ask if anyone can offer some insight on a good way to approach this problem or suggest an entirely different structure if necessary. The framework is not going to employ a pure entity-component model, but I'm looking to create shallow inheritance hierarchies with a good degree of composition.