CPlusEngine Linking Objects

Added a new linked object class to the type of game objects that can be used.  The base class can hold a list of UGameObjects so that it can manage the position of all children in the linked object.  Moving a group of objects is now easy, just create a LinkObject from the ObjectFactory and your done.  Here is the example code on creating a linked object:

_sprite = Factory()->CreateSprite(Graphics()->LoadImage(spriteFile), rect, false);
// … Sprite settings
_camera = Factory()->CreateClampCamera(0.0f, 0.0f, 12544.0f, 5500.0f, false);
// … Camera settings
_light = Factory()->CreateDUObject(Graphics()->LoadImage(goboFile), false);
// … Light settings

// At this time the factory doesn’t support drawable objects so we need to add them ourselves
World()->Add(static_cast(_sprite));
// Yes we need to add the light at this time to make it work
World()->Add(static_cast(_light));

_player = Factory()->CreteLinkObject(static_cast<UGameObject*>(_camera),
    static_cast<UGameObject*>(_sprite),
    static_cast<UGameObject*>(_light), nullptr);

Note: This code could be cleaned up with a couple macros so it makes it easier to maintain. I removed these for clearity.

Note: Omitted code to help keep this example easier to follow and stay on topic about linking objects.

In this code we first have the factory create all the base objects but tell it to not add it to the game world by passing the second parameter as false.  This allows the magic of the factory to properly build our game object but then skip the last step of adding it to the world data structure.

Once all the objects have been created we pass them all back to the factory so it can create the LinkObject which ties all the updatable object together.  As of now the last parameter needs to be set as a nullptr based on the crappy examples I found for variadic functions.  It was either require a first parameter that describes what is being passed into the function or use a nullptr to terminate the arguments array.  I don’t like either method but the second one of the two evils seemed to work.

In the Demo Side Scroller project this is being used right now to move a sprite around a tile map.  To accomplish this I tied the camera to the demo sprite and linked the new object to the input controller.  The really nice thing about doing it this way is now when we scroll around the map and hit map boundaries there is no need to have a special case to test whether we need to move the sprite or the game world.  This is all taken care of by the Clamping Camera.

Right now the interface for the ObjectFactory is a little clunky and will be refactor as I learn more about Variadic functions.  You can always create the object on your own but I don’t recommend this due to the tight integration this feature has with the world system.