Original Post
I really love to fiddle with engine core design and that includes some very interesting ways of creating flexibility. Yesterday a thing popped up in my head: what if my engine isn't too flexible to work in a large-scale project? 10 minutes lates the answer to that question was something I called "constructor functions". It means that any resource-based constructor only takes one argument and that is a function pointer. Example of my basic texture class: With this constructor and the boost::bind I can allow the user to pass in any function that returns an IDirect3DDevice9* to my texture constructor before I start to implement these constructor functions in the rest of my engine, is this a way that you'd like to work or is it just plain stupid? edit: perhaps this should be placed in the game programming section, but since the code contains directx code I though it might fit better here edit2: changed the subject name edit3+ tried to format the code
[source lang = "cpp"]
Texture::Texture( boost::function < IDirect3DTexture9 () > constructor )
{
IDirect3DTexure9* texture = constructor();
// Error checking
m_texture = boost::intrusive_ptr < IDirect3DTexure9 >( texture, false );
}
[source lang = "cpp"]
IDirect3DTexture9* CreateFromFile( std::string const& source, IDirect3DDevice9 device )
{
IDirect3DTexture9* texture = 0;
RESULT result = D3DXCreateTextureFromFile( device, source.c_str(), &texture );
// Error checking
return texture;
}
IDirect3DDevice9* device = renderer->get_IDirect3DDevice9();
typedef boost::shared_ptr < Texture > TexturePtr;
TexturePtr texture( new Texture( boost::bind( CreateFromFile, "file.dds", device ) ) );