ogre 脚本 载入 序列化

()找到类名去google搜就能得到类关系图了 不用在ogre里扒拉着找了
meshSerializer 功能分析
AllocatedObject :
  new delet
Serializer:
  这里有对二进制文件的处理
     This class provides a number of useful methods for exporting / importing data    
     from stream-oriented binary files (e.g. .mesh and .skeleton).    */
   class _OgreExport Serializer : public SerializerAlloc
  endian 按字节顺序
  实现序列化功能所需的基本方法write read之类的
MeshSerializer:
@remarks
This
class allows exporters to write OGRE .mesh files easily, and allows the
OGRE engine to import .mesh files into instantiated OGRE Meshes.
Note that a .mesh file can include not only the Mesh, but also definitions of
any Materials it uses (although
this is optional, the .mesh can rely on the
Material being loaded from another source, especially useful
if you want to
take advantage of OGRE
's advanced Material properties which may not be available
in your modeller).
@par
To export a Mesh:
<OL>
<LI>Use the MaterialManager methods to create any dependent Material objects, 
 if you want
to export them with the Mesh.
</LI>
<LI>Create a Mesh object and populate it using it's methods.</LI>
<LI>Call the exportMesh method</LI>
</OL>
@par
It
's important to realise that this exporter uses OGRE terminology. In this context,
'Mesh' means a top-level mesh structure which can actually contain many SubMeshes, each
of which has only one Material. Modelling packages may refer to these differently,
for
example
in Milkshape, it says 'Model' instead of 'Mesh' and 'Mesh' instead of 'SubMesh',
but the theory
is the same.
*/
class _OgreExport MeshSerializer : public Serializer
   做importmesh exportmesh之类的事情 setListener
  这里面有个放了meshSerializerImpl的map
    具体improt export的时候 调用了 meshSerializerImpl的import exprot
MeshSerializerImpl:
  /** Internal implementation of Mesh reading / writing for the latest version of the    .mesh format.
  read write calculate thing.具体对mesh的操作都是它实现的
  MeshSerializerImpl_v1_4:mesh各版本兼容
所以下面分析下meshSerializerImpl的exportmesh
判endianMode
fileopen
  meshwrite()这里调用此类的其他write各部分的成员方法
fileclose
外面要实现此功能的类 的调用:
 3 mesh类里有loadimpl方法 调用MeshSerializer的importmesh
   2  (manual模式   在resource的load里调用了loadResource方法    ManualResourceLoader的 loadResource是个虚方法 实现多态
      ManualResourceLoader的派生类有font 和meshmanager
     看meshmanager的loadResource方法)
  (非manual模式 在resource里load调用loadImple方法 resource的loadaimple是虚方法
    派生类包括 Compositor Font GpuProgram Maaterial Mesh Skeleton Texture 他们都重写了loadImple)
1 loadResourceGroup里调用resource的load
脚本解析 功能分析
  脚本这里, 在程序一开始加载的时候,调用initialiseAllResourceGroups里面有parseResourceGroupScripts
parseResourceGroupScripts里面是按照scriptLoaderOrderMap把里面的脚本按照 pattern全部加载到list里
用DataStreamPtr stream=fii->arhive->open(name);把list里的file读出来的
之后在对stream执行 parse 。。。这是按照scriploader这个接口做的。

序列化 从对象到stream 
ogre里面的serilizer看起来不是个序列化 或者说不是传统意义。。不是我从网上g到的序列化的意义。仅是stream到binaryfile的read和write

ogre的文件系统
  涉及resource manager 
archive datastream
stricpt加载

每个东西加载都有个scriptloader 在resourcemanager里有对 各种loader的管理 注册之类的  这些loader都放在ScriptLoaderOrderMap里
在初始化脚本的时候 遍历map解析
各资源的manager 比如particlemanager里面调用注册粒子解析脚本的方法 在构造函数里
实现:
类a继承于scriptloader
类b里有类a的parse的具体实现的方法

类a 在resource中注册scriptloader(自己)
 并在构造函数中声明扩展名

在root中 实例化类a
initializeResourceGroup的时候parse会自动执行



ogre的资源加载 是在一开始的时候 initialresourceGroup的时候 把 resources.cfg里面所列的 所有的扩展名符合的 资源 都全部加
参考:
http://wiki.ogrecn.com/wiki/index.php?title=%E6%96%87%E6%A1%A3:%E6%95%99%E7%A8%8B:%E4%B8%AD%E7%BA%A7%E6%95%99%E7%A8%8B:%E4%B8%AD%E7%BA%A7%E6%95%99%E7%A8%8B%E4%B8%83
  
  1.  创建Root对象。
   2.  重复调用ResourceGroupManager::addResourceLocation,直到你已经添加了所有的资源位置。
   3.  创建所有自定义的ResourceManager对象,并通过调用ResourceGroupManager::_registerResourceManager注册它们。你可能还要注册ScriptLoader对象,通过调用ResourceGroupManager::_registerScriptLoader方法。
   4.  手动声明你要的任何资源,通过ResourceGroupManager::declareResource函数。
   5.  为你的资源组调用适当的初始化方法。对于单个组,调用ResourceGroupManager::initialiseResourceGroup,或者ResourceGroupManager::initialiseAllResourceGroups一口气初始化所有的。

  ------------------
下面关注的就是每个scriptloader的具体实现过程了,脚本的结构是重点
  particle
      确定一个存储结构 照此结构write read
//////////////////////////////////////////////////////////////////////////
// binary particle file format
// -----------------------------
// filehead
// particle num(uint32):N
// -----------------------------
// ps1:
// psname(String),emitter num(uint32),affector num(uint32),
// -------------------------------
// psparameter, psrenderparameter
// ------------------------
// emitter list,(typename, datas)
// ----------------------
// affector list,(typename, datas)
// -----------------------------
// ps2:
// -----------------------------
// ...
// -----------------------------
// psN
// -----------------------------
//////////////////////////////////////////////////////////////////////////


  material
原文地址:https://www.cnblogs.com/minggoddess/p/1963951.html