日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Delta3d角色注册机制

發(fā)布時(shí)間:2024/8/23 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Delta3d角色注册机制 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

角色注冊(cè)主要通過(guò)繼承自類dtDAL::ActorPluginRegistry類來(lái)實(shí)現(xiàn),重寫(xiě)其中的RegisterActorTypes()即可;在對(duì)象工廠ObjectFactory中保存了“角色類型到負(fù)責(zé)創(chuàng)建角色對(duì)象的全局函數(shù)”的Map;

關(guān)鍵函數(shù)有:

dtCore::RefPtr<BaseActorObject> ActorPluginRegistry::CreateActor(const ActorType& type){dtCore::RefPtr<BaseActorObject> proxy = mActorFactory->CreateObject(dtCore::RefPtr<const ActorType>(&type));proxy->Init(type);proxy->InitDefaults();return proxy;}void XXGameActorsRegistry::RegisterActorTypes() { XXActorType = new dtDAL::ActorType("XX","TutorialActors", "Simple tank that moves and acts like a basic hover craft."); mActorFactory->RegisterType<XXActorProxy>(XXActorType. get()); }

在動(dòng)態(tài)鏈接庫(kù)Dll中導(dǎo)出全局函數(shù):

extern "C" TUTORIAL_HOVER_EXPORT dtDAL::ActorPluginRegistry* CreatePluginRegistry() { return new TutorialGameActorsRegistry(); } / // extern "C" TUTORIAL_HOVER_EXPORT void DestroyPluginRegistry(dtDAL::ActorPluginRegistry *registry) { delete registry; }


核心了對(duì)象工廠實(shí)現(xiàn)代碼如下:

template<typename BaseType, typename DerivedType>BaseType *construct(){return new DerivedType();}/*** This class is a template object factory. It allows one to* create any type of object as long as there is a common base* class. The common base class is defined on a per-factory* basis using the templated parameter <code>BaseType</code>.* @note* The ObjectFactory implementation only supports objects with* a default constructor. It will not work with objects that* only have named constructors.*/template<typename UniqueIdTypeClass,typename BaseTypeClass,typename ltCmpClass=std::less<UniqueIdTypeClass> >class ObjectFactory : public osg::Referenced{public:typedef UniqueIdTypeClass UniqueIdType;typedef BaseTypeClass BaseType;typedef ltCmpClass ltCmp;typedef BaseType *(*createObjectFunc)(); /// Function pointer type for functions creating objects.typedef std::map<UniqueIdType,createObjectFunc,ltCmp> ObjectMap;typedef typename ObjectMap::iterator ObjTypeItor;typedef typename ObjectMap::const_iterator ObjTypeItorConst;ObjectFactory() {} // constructorprotected:virtual ~ObjectFactory() {}public:/*** Registers a new type of object with the factory.* @return false if the type is a duplicate.*/template<typename DerivedType>bool RegisterType(UniqueIdType id){if (this->objectTypeMap.find(id) != this->objectTypeMap.end()){return false;}this->objectTypeMap[id] = &construct<BaseType,DerivedType>;return true;}/*** Removes an existing object type from the factory's known list* of object types.*/void RemoveType(UniqueIdType id) {this->objectTypeMap.erase(id);}/*** Checks to see if the factory can create objects of the given type.* @param id The type of object to check for.* @return True if the type is supported, false otherwise.*/bool IsTypeSupported(UniqueIdType id) const{ObjTypeItorConst itor(this->objectTypeMap.find(id));if (itor != this->objectTypeMap.end()){return true;}else{return false;}}/*** Gets a list of types that this factory knows how to create.*/void GetSupportedTypes(std::vector<UniqueIdType> &types) const{types.clear();for (ObjTypeItorConst itor=this->objectTypeMap.begin();itor != this->objectTypeMap.end(); ++itor){types.push_back(itor->first);}}/*** Creates a new object.* @param id - Type of object to create.* @return Returns a pointer to the newly created object or NULL if the given id has not been registered.* @throw Exception is thrown if the factory does not know how to create* the requested type.*/BaseType* CreateObject(const UniqueIdType id) const{ObjTypeItorConst itor(this->objectTypeMap.find(id));// We cannot create a new object if we do not know what type it is// so throw an exception.if (itor == this->objectTypeMap.end()){return NULL;}return (itor->second)();}const ObjectMap& GetMap() const { return objectTypeMap; }private:///Maps a unique id to a function pointer that when called creates an///object of the appropriate type.ObjectMap objectTypeMap;};

總結(jié)

以上是生活随笔為你收集整理的Delta3d角色注册机制的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。