Resources are data objects that must be loaded and managed throughout an application. A resource might be a mesh, a texture, or any other piece of data - the key thing is that they must be identified by a name which is unique, must be loaded only once, must be managed efficiently in terms of retrieval, and they may also be unloadable to free memory up when they have not been used for a while and the memory budget is under stress.
Ogre::Resource::LoadingState描述的是资源的加载状态。创建一个Rersource并不会立即加载资源内容,只有显式的进行load后,资源才会被真正加载。从设计上讲,Rersource更像一个轻量级的常驻资源代理(让人想起WeakReference)。资源内容可以随时被卸载并在有必要的情况下重新加载,而资源会以更持久的方式存在。对用户来讲,只要应用Resource的概念就可以了,资源内容和底层Archive就不用费神了。这种轻量级代理的方式也使异步加载更为方便。
A resource manager is responsible for managing a pool of resources of a particular type. It must index them, look them up, load and destroy them. It may also need to stay within a defined memory budget, and temporarily unload some resources if it needs to to stay within this budget.
Resource managers use a priority system to determine what can be unloaded, and a Least Recently Used (LRU) policy within resources of the same priority.
Resources can be loaded using the generalised load interface, and they can be unloaded and removed. In addition, each subclass of ResourceManager will likely define custom 'load' methods which take explicit parameters depending on the kind of resource being created.
ResourceManager是某种特定Resource的管理器,负责该类型资源的创建和销毁。Resource和ResourceManager这种关系是抽象工厂(Abstract Factory)模式的典型体现。Resource是产品,ResourceManager是工厂,不同的工厂来制造相应类型的产品。
ResourceGroupManager, this singleton class manages the list of resource groups, and notifying the various resource managers of their obligations to load / unload resources in a group.
It also provides facilities to monitor resource loading per group (to do progress bars etc), provided the resources that are required are pre-registered.
Archive组件提供了抽象文件的访问能力。Resource组件建立在Archive系统之上,提供灵活的资源加载方式,保证资源不会被重复加载,并能在适当的时候回收资源。Resource组件将底层面向文件系统的Archive提升到面向应用的资源。
Resource和DataStream的层次有点类似,都代表最终的实用产品;ResourceManager和Archive有点类似,管理一系列有共同性质的东西;ResourceGroupManager则和ArchiveManager有点类似,在各自组件的中心管理器。
推荐阅读:
评论