Yeah I have a similar system to yours Seppuku, but slightly different. Using the singleton model I used up there means you don't have to use up extra space for every object pointing to the allocator. Also, if you use inheritance you can automatically get an object id in the 'object' constructor, and then in the 'cube' class constructor make the cube. The 'object' constructor will be called before the 'cube' constructor anyway so the id will be ready.
Again, untested:
class Object
{
protected:
int _id;
public:
Object()
{
_id = Allocator::GetInstance()->FreeObject();
}
// Destructor is called presumably when the object is deleted, so
// delete the object and reclaim it's id
~Object()
{
if (dbObjectExist(_id))
dbDeleteObject(_id);
Allocator::GetInstance()->DeleteObject(_id);
}
int GetId() { return _id; }
void Position(Vector3 pos)
{
dbPositionObject(_id, pos.X, pos.Y, pos.Z);
}
};
class Cube : public Object
{
public:
Cube()
{
dbMakeObjectCube(_id, 100);
}
};
So the 'Object' constructor creates the id and the 'Cube' constructor creates the actual cube after returning from the 'Object' constructor. Notice also the destructor will automatically delete the object and reclaim the id for next time.
Here's how it might be used:
Object * obj = new Cube(); // I don't recommend using value types because as soon as it goes out of scope the object will be deleted
obj->Position(other->GetPosition() + Vector3(0, 100, 0));
// delete object (both the object in memory and the DGDK object, also take the id back)
delete obj;
"everyone forgets a semi-colon sometimes." - Phaelax