Hi guys,
I am interested in how people have glued Leadwerk's TEntity and their own codebase together. Right now I have a C++ class Entity that forms the base class for all my other objects. I had problems properly deleting the object and the actual TEntity it was wrapping. Imagine you have a Scene class that inherits from Entity. The scene class has a number of child TEntity's of which the corresponding C++ class has also been new'ed during the loading process. Now, if you delete the Scene, freeing the entity, the engine will automatically free the childs of that entity. The result is that the TEntities are properly deleted but the C++ objects remain because they never have had their destructor called. To solve this I added the free callback to my entities, calling the destructor of the TEntity's user data in the callback function. It is not hard to see this will end up in a loop and solved it like so:
void _stdcall FreeEntityCallback(TEntity entity) {
Entity* e = reinterpret_cast<Entity*> (GetEntityUserData(entity));
SetEntityUserData(entity, 0);
delete e;
}
Entity::~Entity() {
if (GetEntityUserData(_entity) != 0) {
SetEntityCallback(_entity, 0, ENTITYCALLBACK_FREE);
FreeEntity(_entity);
}
}
I am interested to hear how other people have solved this particular problem. How have you wrapped Leadwerk's TEntity?
Thanks!