I'm in the way to create my own object factory implementation, and i need it to access it for Lua (OOLUA) and external DLL's, for my game engine based in Ogre so my current implementation is this:
Code: Select all
#ifndef GAMEOBJECTFACTORY_H
#define GAMEOBJECTFACTORY_H
#include "GameObject.hpp"
#include <memory>
#include <string>
#include <map>
#include <functional>
namespace Core {
class RegisterObjectHelper {
RegisterObjectHelper(std::string className, function<GameObject* (void)> objectFactoryFunction);
};
#define REGISTER_OBJECT(NAME, TYPE) static RegisterObjectHelper regObj(NAME, [](void)-> GameObject * {return new TYPE();});
class GameObjectFactory
{GameObjectFactory
public:
static GameObjectFactory *getSingleInstance();
void registerFactoryFunction(std::string name, function<GameObject* (void)> objectFactoryFunction); //NON LUA BINDABLE!, i think.
void registerFactory(std::string name, GameObject*);
std::shared_ptr<GameObject> create(std::string name);
private:
GameObjectFactory();
std::map<std::string, function<GameObject* (void)>> factoryFunctionRegistry;
};
}
#endif
GameObject class is a simple empty C++ class for now, but do you think is good for scalibility?, and OOLua friendly?, since i'm looking if OOLua support and external DLL, that kind of parameters (i'm talking about the function<GameObject* (void)> parameter and std::shared_ptr (i will gonna replace it with my own implementation) ) can affect the OOLua scripting o i need to look an C++11 compatible binding helpers?.
Thanks.