1 / 12

ffo 的资源管理

ffo 的资源管理. ciceroma 2010-5-7. Pkg 包和虚拟文件系统. 资源访问的底层接口,只提供读写操作. vfile.h, vfile.cpp, package.h, package.cpp. Pkg 包. 资源文件太多,打到同一个包里,方便管理,同时降低 os 文件系统的负担. object map avatar magic …. 虚拟文件系统. 屏蔽 pkg 包内文件与磁盘文件的差异,向上层提供统一接口. 仿照 C 库函数,提供几个访问接口.

brandy
Download Presentation

ffo 的资源管理

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ffo的资源管理 ciceroma 2010-5-7

  2. Pkg包和虚拟文件系统 资源访问的底层接口,只提供读写操作 • vfile.h, • vfile.cpp, • package.h, • package.cpp

  3. Pkg包 资源文件太多,打到同一个包里,方便管理,同时降低os文件系统的负担 \object \map \avatar \magic …

  4. 虚拟文件系统 屏蔽pkg包内文件与磁盘文件的差异,向上层提供统一接口 仿照C库函数,提供几个访问接口 CVFile *vfopen( const char *path, const char *mode ) void vfclose( CVFile *fp ) int vfread( void *pbuffer, int size, int count, CVFile *fp ) int vfwrite( void *pbuffer, int size, int count, CVFile *fp ) int vfseek( CVFile *fp, long offset, int origin ) …

  5. header Data,data… 每个单独的文件使用zlib进行压缩 short namelen; char[namelen] name; int flags; int offset; int originsize; int packsize; Description Table … … Pkg包的结构 struct stPkgHeader { int version; int numfiles; int table_offset; int table_len; };

  6. 访问pkg的类 用于只读package 可以追加文件的package class CFlexPackage { bool Open( const char *); bool Close(); bool AddPackFile(); }; class CFixPackage { bool Open( const char *); void Close(); bool FindFirstFile( stPkgFile&); bool FindNextFile( stPkgFile&); bool GetFileData(); void *GetFilePackData(); int GetNumFiles(); int GetFileSize(); };

  7. 读入 Package类读入pkg包最后的描述表table,在内存中维护一个map,记录文件名对应的包里位置信息,调用vfopen的时候才读入内存

  8. CFixPackage CVFileMgr CVFile Stdio读写 CVDiskFile CVPackFile Vfile相关

  9. 图像资源的管理 class IImageLib { 异步装载资源, 区别于AddRef的同步装载方式 virtual ULONG Require(DWORD dwID) = 0; //引用某个影像资源 virtual ULONG AddRef(DWORD dwID) = 0; //获取某个资源当前的引用[add qjb 2005-4-30] virtual ULONG GetRef(DWORD dwID) = 0; //引用结束, 释放该资源的引用 virtual ULONG Release(DWORD dwID) = 0; //获得影像资源动画总的方向数目 virtual int GetTotalDirs(DWORD dwID) = 0; //获得影像资源包围盒的信息 virtual TBoundInfo *GetBoundInfo(DWORD dwID) = 0; virtual bool IsImageExist( DWORD dwID ) = 0; virtual void GarbageCollect() = 0; };

  10. 图像资源的管理 从磁盘加载文件的时候使用底层的vfile接口 Addref的时候,如果不存在则加载到内存,并把hotTick设为当前时间

  11. GarbageCollect 每秒钟进行一次垃圾收集 遍历所有维护的图像资源列表,如果hotTick与当前时间差值超过一定值,则从内存中卸载该资源

  12. The End  Thank you 

More Related