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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

编写Ogre插件的一般方法

發布時間:2025/4/14 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 编写Ogre插件的一般方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉載請注明出處!Pulas

?http://www.cnblogs.com/pulas/archive/2012/02/18/2357663.html

?

??????? Ogre的插件可以是動態鏈接庫,也可以是靜態鏈接庫。若是動態鏈接庫,則可通過在插件配置文件(默認為plugins.cfg)里添加插件名稱,然后在創建Root時,會在Root的構造函數里通過Root::loadPlugin(const String& pluginName)方法遍歷加載每一個插件。也可通過Root::loadPlugin(const String& pluginName)方法手動加載自定義插件。

??????? 當Root::loadPlugin(const String& pluginName)函數被調用時,Ogre將加載該插件的dll,并從中查找并調用名為dllStartPlugin()的導出函數。對應的,當Root::unloadPlugin(const String& pluginName)函數被調用時,Ogre將從該dll中調用dllStopPlugin()函數,并將該dll卸載。所以每個插件在實現的時候,都必須提供上述的兩個C導出函數。其中,dllStartPlugin()負責創建插件實例,并調用Root::installPlugin(),將創建好的插件指針傳遞給Root對象。在這里,dllStartPlugin()實際可以創建多個插件實例,并依次調用Root::installPlugin(),這樣我們就可以在一個dll中包含多個插件了。在dllStopPlugin()時,則需要調用 Root::uninstallPlugin(),并將插件dll中創建的plugin實例釋放掉。所以,若要實現一個四叉樹的場景管理器插件,則必須先實現這兩個C導出函數。

?

#include <OgreRoot.h> #include <QuadtreePlugin.h>#ifndef OGRE_STATIC_LIBnamespace Ogre { QuadtreePlugin* quadtreePlugin;extern "C" void _QuadtreePluginExport dllStartPlugin( void ) {// Create new scene managerquadtreePlugin = OGRE_NEW QuadtreePlugin();// RegisterRoot::getSingleton().installPlugin(quadtreePlugin); } extern "C" void _QuadtreePluginExport dllStopPlugin( void ) {Root::getSingleton().uninstallPlugin(quadtreePlugin);OGRE_DELETE quadtreePlugin; } }#endif

?

?

在上述dllStartPlugin( void )函數中創建自定義插件。Ogre定義了一個抽象的Plugin插件接口,每一個插件都必須實現該插件接口。

?

class _OgreExport Plugin : public PluginAlloc{public:Plugin() {}virtual ~Plugin() {}/** Get the name of the plugin. @remarks An implementation must be supplied for this method to uniquelyidentify the plugin.*/virtual const String& getName() const = 0;/** Perform the plugin initial installation sequence. @remarks An implementation must be supplied for this method. It must performthe startup tasks necessary to install any rendersystem customisations or anything else that is not dependent on system initialisation, ieonly dependent on the core of Ogre. It must not perform anyoperations that would create rendersystem-specific objects at this stage,that should be done in initialise().*/virtual void install() = 0;/** Perform any tasks the plugin needs to perform on full systeminitialisation.@remarks An implementation must be supplied for this method. It is called just after the system is fully initialised (either after Root::initialiseif a window is created then, or after the first window is created)and therefore all rendersystem functionality is available at thistime. You can use this hook to create any resources which are dependent on a rendersystem or have rendersystem-specific implementations.*/virtual void initialise() = 0;/** Perform any tasks the plugin needs to perform when the system is shut down.@remarks An implementation must be supplied for this method.This method is called just before key parts of the system are unloaded, such as rendersystems being shut down. You should use this hook to free up resources and decouple custom objects from the OGRE system, whilst all theinstances of other plugins (e.g. rendersystems) still exist.*/virtual void shutdown() = 0;/** Perform the final plugin uninstallation sequence. @remarks An implementation must be supplied for this method. It must performthe cleanup tasks which haven't already been performed in shutdown()(e.g. final deletion of custom instances, if you kept them around incasethe system was reinitialised). At this stage you cannot be sure what otherplugins are still loaded or active. It must therefore not perform anyoperations that would reference any rendersystem-specific objects - thoseshould have been sorted out in the 'shutdown' method.*/virtual void uninstall() = 0;};

?

Root::getSingleton().installPlugin(plugin)會負責調用插件的install()操作,并將插件的指針存放起來,以備卸載時使用。Root::initialise()會負責調用插件的initialise()操作。

Plugin::install()以及Plugin::initialise()則分別負責創建OgreMain提供擴展功能接口的實例,以及將創建好的對象掛載到應用程序當中。

Root:: shutdown()會負責調用插件的shutdown()操作。Root::getSingleton().uninstallPlugin(plugin)會負責調用插件的uninstall()操作。

?

使用插件時幾個需要注意的地方:

1. 調用插件DLL方法創建的對象需要交由插件DLL釋放。(因為不同的鏈接單元可能具有不同的內存管理上下文環境,此處的new與彼處的new在語義上未必等同)

2. 調用插件DLL方法獲取的插件內對象的引用或指針,在插件DLL卸載之后就是無效的,必須保證不再使用。(比較容易引發問題的一個典型例子是從插件中傳遞回一個引用計數字符串,當DLL被卸載后,字符串內指向實際數據的指針已經無效,但是在該對象析構時,仍需要訪問該指針)

?

若插件是靜態鏈接庫,則可在任何時候創建插件,然后在創建Root后,調用Root::installPlugin(plugin)安裝插件。手動調用Root::uninstallPlugin(plugin)卸載插件。

?

可以參考Ogre Wiki上的教程:

http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Creating+A+Plugin+DLL

Final Thoughts

??
It's up to you to do what you want inside the plugin, and keep in mind that it can be used to create plugins for your own game or application specific purposes. For example, in my game engine and editor most major pieces of functionality are loaded as plugins, including game objects, game systems, scene partitions, tool plugins for the editor, etc. All you need to do is have a clear set of base classes, a factory and a factory manager.

For example a simplified Factory system:

GameObject class in the plugin:

class GameObject {void tick(float deltaTime); };

??
Class factory that creates GameObjects?in the plugin:

class GameObjectFactory {virtual bool supportsGameObjectType(const String& objectType) = 0;virtual GameObject* createGameObject(const String& objectType) = 0; };

??
A manager class (in the game) that we can register factories with that will be used to create game objects:

class GameObjectFactoryManager : public Singleton<GameObjectFactoryManager> {void registerGameObjectFactory(GameObjectFactory* factory){//add factory to an array}void unregisterGameObjectFactory(GameObjectFactory* factory){//find and remove factory from mFactories}GameObject* createGameObject(const String& objectType){//find a factory that supports this object type and then call createGameObject() on it} };

??
You could now create new classes that derive from GameObject, such as MeshGameObject, and a factory that creates those objects such as MeshGameObjectFactory, and have your application create a GameObjectFactoryManager at startup. Then have a plugin that callsGameObjectFactoryManager::getSingleton().registerGameObjectFactory(meshGameObjectFactory)?during its?initialise()?call. Then from your game you can now create instances of new MeshGameObjects dynamically without ever having linked to the DLL.

?

轉載于:https://www.cnblogs.com/pulas/archive/2012/02/18/2357663.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的编写Ogre插件的一般方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 涩涩视频免费 | 99视屏| 国产精品日韩精品欧美精品 | 91官网在线 | 国产精品熟妇一区二区三区四区 | 国产成人久久精品麻豆二区 | 久久无码人妻丰满熟妇区毛片 | 国产午夜福利一区二区 | 美女综合网| v天堂中文在线 | 一区二区三区视频网站 | julia一区二区三区中文字幕 | 桃色一区二区 | 男同av在线观看一区二区三区 | 久久久久久久久久99精品 | 爆操老女人 | 精品在线第一页 | 我爱avav色aⅴ爱avav | 开心激情站 | 玖玖精品在线视频 | 天天射天天搞 | 三级黄色片网站 | 扩阴视频 | 手机看片福利永久 | 免费日韩欧美 | 精品人妻少妇一区二区三区 | 亚洲视频免费看 | 日本精品在线观看视频 | 无码少妇一区二区三区 | 欧美日韩三级 | 日日射夜夜操 | 一区二区三区视频在线免费观看 | 久久大香 | 永久免费看片在线观看 | 国产午夜一区二区 | 日韩电影三级 | 久久久成人精品 | 国产激情一区二区三区视频免樱桃 | 天堂成人在线观看 | 成人mv | 高潮毛片7777777毛片 | 色小姐综合网 | 永久久久久久 | 91在线观看网站 | 红猫大本营在线观看的 | 高潮白浆女日韩av免费看 | 中文字幕无码乱码人妻日韩精品 | 欧美18—19性高清hd4k | 国产超91| 在线观看三级网站 | 亚洲天堂久久 | 麻豆视频免费在线 | 国产精品剧情 | 999国产视频 | 欧美a视频 | 免费污片在线观看 | 欧美黄色录像视频 | 狠狠操在线视频 | 在线岛国 | 天天狠天天操 | 国产三级三级看三级 | 另类视频在线观看+1080p | 亚洲精品视频免费 | 丰满尤物白嫩啪啪少妇 | 18禁裸男晨勃露j毛免费观看 | 超碰97在线人人 | 久久久久99精品成人片我成大片 | 香港日本韩国三级网站 | www奇米影视com| 日本国产欧美 | 日本不卡视频 | 超碰人人爱 | 国产尤物在线 | 高清国产午夜精品久久久久久 | 久久激情婷婷 | 欧美黄色图片 | 特黄特色免费视频 | 俄罗斯女人裸体性做爰 | 亚洲yy | 欧美日韩一区二区区 | 国产精品久久久久久久天堂 | 乖女从小调教h尿便器小说 欧美韩一区二区 | 四川一级毛毛片 | 国产 丝袜 欧美中文 另类 | 中文亚洲av片不卡在线观看 | 18无码粉嫩小泬无套在线观看 | 国产又粗又猛又黄又爽视频 | 鲁鲁狠狠狠7777一区二区 | 鸥美毛片 | 黄色片播放器 | 玖玖爱这里只有精品 | 啪啪免费小视频 | 99久久精品无免国产免费 | 一级片免费在线播放 | 99精品久久精品一区二区 | 亚洲第一免费播放区 | 白又丰满大屁股bbbbb | 亚洲五月激情 | 亚洲av无码潮喷在线观看 |