Horde3D随笔1
基于 OpenGL, FLGW 框架
1,封装一个Application类,用于接受主循环及相应的消息响应。
2.Modules-模块类:其属于一个静态类内含 EngineConfig,EngineLog,StatManager,SceneManager,ResourceManager,RenderDevice,Renderer,ExtensionManager。这些类以后可以一个一个的研究。
h3dAddResource函数用于向ResourceManager添加资源(具体实现是Modules::resMan().addResource), 其中addResource函数的原形如下:
ResHandle ResourceManager::addResurce(int type, const string &name, int flags, bool useCall)
{
//省略...
map<int, ResourceRegEntry>::iterator itr = _registry.find(type);
if (itr != _registry.end()) resource = (*itr->second.factoryFunc(name, flags);
//省略...
}
通过上面的代码可以看出,_registry表则是类型列表,此列表可以动态的增减。对进来的资源文件根据不同的类型返回不同的资源类型对像。
ResourceRegEntry的声明如下:
struct ResourceRegEntry
{
std::string typeString;
ResTypeInitializationFunc initializationFunc; // Called when type is registered
ResTypeReleaseFunc releaseFunc; // Called when type is unregistered
ResTypeFactoryFunc factoryFunc; // Factory to create resource object
};
factoryFunc函数的结构如下:
typedef Resource *(*ResTypeFactoryFunc)( const std::string &name, int flags );
_registry表的数据是通过Modules::init()函数被调用时添加的,当然也可以在其它时机发生。
resMan().registerType( ResourceTypes::SceneGraph, "SceneGraph", 0x0, 0x0, SceneGraphResource::factoryFunc );
class SceneGraphResource : public Resource
{
public:
static Resource *factoryFunc( const std::string &name, int flags )
{ return new SceneGraphResource( name, flags ); }
...
}

浙公网安备 33010602011771号