OGRE资源相关分析 + OGRE 启动详解 + 实体的加载与显示

本文深入探讨了OGRE图形引擎中的资源管理,包括资源加载、存储和更新。同时,详细阐述了OGRE启动过程,并讲解了如何加载和显示游戏实体,为3D应用开发提供关键指导。
摘要由CSDN通过智能技术生成

 

OGRE 资源相关分析
Resource
 
Resource的类继承体系如下:
   
Resource代表着一类可以被载入的资源,比如Mesh,Texture等。每个资源有其唯一的Name,根据Name可以定位到某个资源,这样也确保了资源只能被载入一次。并且Resource必须在一段时间不使用的时候要被删除。
要实现为Resource子类有以下要求:
1. 构造函数和Resorce有相同的参数。子类构造函数不允许有其它的参数传入,如果需要设置其它成员变量可以通过Set函数。
2.实现Resource中的纯虚函数loadImpl和unloadImpl。而且mSize必须在loadImpl调用后设置。
3. StringInterface ParamCommand and ParamDictionary setups in order to allow setting of core parameters (prior to load)through a generic interface.
 
资源有两种载入的方法,一个是通过解析脚本文件自动载入,另一种是手工载入。手工载入的好处是:由于某些意外原因导致资源unload,这时就不能通过Resource的reload重新载入,因为是意外原因所以mIsLoaded就仍然为true。通过使用手工载入就可以预防这个问题。
 
ResourceManager
ResourceManager的类继承体系如下:
 
 
和Resource对比我们可以得出ResourceManager和Resource是一一对应的。其实一个具体类型的ResourceManager就是管理管理这个类型资源的资源池。通过ResourceManager可以可以索引这些资源,查找资源,载入和销毁资源。
ResourceManager还有一些其它功能,比如它保存着它所掌管类型的资源的载入,卸载优先顺序。这样载入资源的时候可以一种一种的载入,节省了时间。ResourceManager自己定义了内存预算,我们载入/卸载的时候都会通知该变这个内存预算值,这样我们就可以得知我们使用了多少内存。另外,要注意的一点是资源可以通过Resource类被载入和卸载,但只能使用ResourceManager来创建和删除。
 
ResourceGroupManager
与这个类声明所在的.h文件中有一个ResourceGroupListener类的声明,这个类定义了如下几种事件接口,它们在操作资源的不同时候被调用。
· resourceGroupScriptingStarted
· scriptParseStarted (*)
· scriptParseEnded (*)
· resourceGroupScriptingEnded
· resourceGroupLoadStarted
· resourceLoadStarted (*)
· resourceLoadEnded (*)
· worldGeometryStageStarted (*)
· worldGeometryStageEnded (*)
· resourceGroupLoadEnded
 
ResourceGroupManager把资源分成一个个的组,通过调用资源对应的ResourceManager(注:通过ResourceManagerMap使得string sourceType和ResourceManager挂钩)来加载或卸载组中的资源。此外如果一个ResourceManager支持通过脚本来定义资源,那么这个类就会找到脚本的位置然后告诉ResourceManager来解析它们。在ResourceGroupManager中,资源可以看成有4种状态:Undefined,Declared,Unloaded,Loaded。
ResourceGroupManager可以让你把一系列资源看成是一个单元来载入和卸载。比如一个资源组可以是游戏中一个关卡的所有资源。OGRE中有一个预先定义的资源组: DEFAULT_RESOURCE_GROUP_NAME,它所控制的资源只有到了程序退出时才会被释放。
    一旦你创建了自己的资源组,你可以通过以下3种途径为这个资源组载入资源:
1.   调用declareResource()。
2. 通过使用脚本;ResourceManager的一些子类型拥有特定的脚本类型比如:.material,.overlay等。
3. 调用ResourceManager::create。
如果你使用前面两种方法必须确保调用initialiseResourceGroup。
通过 void createResourceGroup(const String& name)方法我们可以创建一个资源组。
创建好一个资源组后我们就可以为这个资源组增加搜索路径,我们将在这些路径中查找我们需要的资源。通过以下函数我们可以为一个资源组添加搜索路径:

void ResourceGroupManager::addResourceLocation(const String& name,
 const String& locType,const String& resGroup,bool recursive)
name 
The name of the resource location; probably a directory, zip file, URL etc.
locType 
The codename for the resource type, which must correspond to the Archive factory which is providing the implementation.
resGroup 
The name of the resource group for which this location is to apply. ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME is the default group which always exists, and can be used for resources which are unlikely to be unloaded until application shutdown. Otherwise it must be the name of a group; if it has not already been created with createResourceGroup then it is created automatically.
recursive 
Whether subdirectories will be searched for files when using a pattern match (such as *.material), and whether subdirectories will be indexed. This can slow down initial loading of the archive and searches. When opening a resource you still need to use the fully qualified name, this allows duplicate names in alternate p
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值