ogre分析之设计模式二mythma_第1页
ogre分析之设计模式二mythma_第2页
ogre分析之设计模式二mythma_第3页
ogre分析之设计模式二mythma_第4页
ogre分析之设计模式二mythma_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

:Apdater模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。当使用第工具包时候,这种模式经常用到。OGRE使用了其他的几个开源项目,如Cg数。为了处理压缩文件和普通文件使用相同的接口,就需要Adapter。OGRE中处理文件使用Ogre::Archive,zzipZZIP_DIR来表示压缩文件目OGRE使用的是对象适配器。可以看出,Adapter模式与Factory模式可以实现相同的效果——让别的接口兼容(回顾一下用FactoryRenderSystem),但是两者的区别在于FactoryAdapter没有创建别的对象的GoF把FactoryAdapter在结构型模式中。可以发现,这两种模式,OGRE的文件系统都使用了。Bridge的意图是使得抽象部分与它的实现部分分离,这样就使得两部分都可以独立变可以看到序列化Mesh文件的Serializer既有Ogre::MeshSerializer又有Ogre::MeshSerializerImpl。OGRE在读写Mesh文件的时候使用的是 以及它的子类,而Ogre::MeshSerializer Ogre::MeshSerializerImpl系列对外的“接口”,但二者是平辈关系。再看一下MeshSerializer的实现一切将会 {//SetupmapnewMeshSerializerImpl_v1_1()));shSerializer_v1.20]",newMeshSerializerImpl_v1_2()));e(msCurrentVersion,newMeshSerializerImpl()));}{ torimpl=mImplementations.find(msCurrentVersion);if(impl==mImplementations.end()){}} 六、为其他对象提供一种以控制对该对象的。GoF提到四种常见的情况:Romote,Virtual、Protection以及SmartReference。在这里我只分析一下SmartReference。SmartPointer在STL中有std::auto_ptr,在BOOST中有boost::shared_ptr、 、boost::scoped_ptr boost::weak_ptroost::intrusive_ptr在Loki中则有Loki::SmartPtr各种SmartPointer都有不同的功能,适用的地方又各不相同。加上有的SmartPointer的行为又有点诡异,尤其是std::auto_ptr,所以实际应用中一向对之退而却步。ThisisastandardsharedpointerimplementationwhichusesareferencecountThisisastandardsharedpointerimplementationwhichusesareferencecounttoworkoutwhentodeletetheobject.OGREdoesnotusethisclassveryoften,becauseitisusuallymoreefficienttomakethedestructionofobjectsmoreintentional(inblocks,say).Howeverinsomecasesyoureallycannotlhowmanypeopleareusinganobject,andthisapproachisworthwhile(e.g.ControllerValue)附上Ogre::SharedPtr的实现: te<classT>classT*unsignedint*pUseCount;OGRE_AUTO_SHARED_MUTEX//publictoallowexternal/**Constructor,doesnotinitialisetheSharedPtr.<b>Dangerous!</b>Youhavetocallbind()beforeusingtheSharedPtr():pRep(0),pUseCount(0)explicitSharedPtr(T*rep):pRep(rep),pUseCount(newunsigned{}{//lock©othermutexpointerpRep=pUseCount=//HandlezeropointergracefullytomanageSTLcontainers{}}{if(pRep==r.pRep)return*this;//lock©othermutexpointerpRep=pUseCount=r.pUseCount;if(pUseCount){}return}{}inlineT&operator*()const{assert(pRep);return*pRep;}inlineT*operator->()const{assert(pRep);returnpRep;}inlineT*get()const{returnpRep;}/**BindsreptotheSharedPtr.AssumesthattheSharedPtrisvoidbind(T*{assert(!pRep&&!pUseCount);pUseCount=newunsignedint(1);pRep=rep;}inlineboolunique()const{assert(pUseCount);OGRE_LOCK_AUTO_SHARED_MUTEXreturn*pUseCount==1;}inlineunsignedintuseCount()const{assert(pUseCount);OGRE_LOCK_AUTO_SHARED_MUTEXreturn*pUseCount;}inlineunsignedint*useCountPointer()const{returnpUseCount;}inlineT*getPointer()const{returnpRep;}inlineboolisNull(void)const{returnpRep==0;inlinevoid{if{//can'tscopelockmutexbeforereleaseincasedeletedpRep=pUseCount=0;}}inlinevoid{booldestroyThis={//lockownmutexinlimitedscope(mustunlockbeforeif{if(--(*pUseCount)=={destroyThis=}}}}virtualvoid{//IFYOUGETACRASHHERE,YOUFORGOT UP//BEFORESHUTTINGOGRE//UsesetNull()beforeshutdownormakesureyourpointer//outofscopebeforeOGREshutsdowntoavoiddeletepRep;deletepRep;} te

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论