sorry for this lengthy post, but i really could use some help on this......
the factory scans the object DLL directory and finds all of the dll's that contain objects. it then uses the list to allow me to create any object simply by name. this all works great, allowing me to drop in object dll files during runtime and the game automatically detects them and makes them available for use. so far all of this works as expected....
unfortunately, I decided to allow objects to have children, and as always, the children make things difficult.
originally, all objects were accessed by their ID values. Since the objectmanager maintains the list of objects, anytime i need an object that has been created, i simply call the getobjectpointer() function....
Code: Select all
int id = getFactory()->createObjectByType("IrrObject_Box")
IrrObject* obj = getFactory()->getObjectPointer( id );
if (obj)
{
obj->setScale(vector3df(10,10,10));
obj->setPosition(vector);
obj->setRotation(vector);
obj->setVariable(L"Health", 10);
etc....
}
unfortunately, now that i want to add children to the objects, I would like to return not only the assigned ID from the createObject() function, but also store the actual object address. that is why I am trying to use the IrrObject** variable..........but it is not working for me. the stored object is not valid upon return.... i will need to do more testing i think. I am not sure if the DLL scheme is the trouble or not, but all objects classes are defined in their own DLL file, which also has a createObject() function. Since the object is created in the DLL using new(), maybe I have some issue with assigning that memory location to the main program variable? i dont know.... sigh.....
as for the create function, you can have objects named the same and residing in different dll's if you want. if you do, you need to call createobjectbytypeanddll() otherwise it will find the first instance and use that dll...
Code: Select all
int IrrObjectFactory::createObjectByType(core::stringw type, IrrObject **obj, bool addtomanager)
{
IRR_CHECK_INT(m_ClassManager,L"IrrObjectFactory::CreateObjectByType() - ClassManager is not valid");
IRR_CHECK_INT(m_ObjectManager,L"IrrObjectFactory::CreateObjectByType() - ObjectManager is not valid");
IrrObjectData* data = m_ClassManager->findClassInfo(type);
IRR_CHECK_INT(data,L"IrrObjectFactory::AddObjectByType() - unable to locate class definition");
return createObjectByTypeAndDLL(data->DLLName,data->ObjectName, obj, addtomanager);
}