杨德龙的专栏

这里分两部分说delta3d中的app类。主要是dtABC::BaseABC dtABC::Application 和 dtGame::Application

先从BaseABC说起

view plaincopy to clipboardprint?BaseABC ::BaseABC (const std ::string & name /*= “BaseABC”*/ ) : Base (name ) { RegisterInstance (this ); System * sys = &dtCore ::System ::GetInstance (); assert (sys ); AddSender (sys ); CreateDefaultView (); } BaseABC ::BaseABC (const std ::string & name /*= “BaseABC”*/ ) : Base (name ) { RegisterInstance (this ); System * sys = &dtCore ::System ::GetInstance (); assert (sys ); AddSender (sys ); CreateDefaultView ();}

在构造函数中该类完成了 1 注册实体 2 构造System 3 监听System消息 4 创建默认View 为其配置场景,窗口,摄像机等参数,并加载地图。

那么BaseABC具体监听了System中的那些消息呢 通过OnMessage()函数 我们可以看出其接受来自System的 MESSAGE_EVENT_TRAVERSALMESSAGE_PRE_FRAME MESSAGE_FRAME MESSAGE_POST_FRAME 并根据所接受到的不同消息调用对应的函数view plaincopy to clipboardprint?virtual void EventTraversal(const double deltaSimTime){}; virtual void PreFrame(const double deltaSimTime) = 0; virtual void Frame(const double deltaSimTime) = 0; virtual void PostFrame(const double deltaSimTime) = 0; virtual void EventTraversal(const double deltaSimTime){};virtual void PreFrame(const double deltaSimTime) = 0;virtual void Frame(const double deltaSimTime) = 0;virtual void PostFrame(const double deltaSimTime) = 0; dtABC::Application类中会实现上面四个接口。上述四个消息都是在帧循环中发出的,是App类必须要处理的消息。另外virtual void Config(); 转发了System中的Config()消息。并且在跳出应用程序后通过Quit()函数调用System中的Stop()函数

创建的View列表实现如下。view plaincopy to clipboardprint?typedef std::vector<dtCore::RefPtr<dtCore::View> > ViewList; ViewList mViewList; typedef std::vector<dtCore::RefPtr<dtCore::View> >ViewList; ViewList mViewList; 通过提供的相应接口实现对View的初始化,并管理View中的场景,需要绘制的对象,摄像机 ,键盘,鼠标。哦 对 还有一个重要的功能忘了说了,那就是在BaseABC中封装了地图的加载功能。void BaseABC::LoadMap(dtDAL::Map& map, bool addBillBoards)当然这个地图也是被加到View中Scene里的。其中addBillBoards的含义目前还不清楚 吼吼

关于BaseABC就说到这了,往下是Application。它继承自dtABC::BaseABC和 dtUtil::ConfigProperties的。其中dtUtil::ConfigProperties只是一个配置属性的接口。跟上面一样也是先说说Application实现的功能 1 注册键盘和鼠标回调 2 加载App属性列表 3 实现应用程序需要功能

先从教程中的一段小代码往下看你Application怎么运作的 view plaincopy to clipboardprint?Application *app = new Application(“Mydatafile.xml”); app->Config(); app->Run(); Application *app = new Application(“Mydatafile.xml”);app->Config();app->Run(); 首先是构造函数view plaincopy to clipboardprint?Application::Application(const std::string& configFilename, dtCore::DeltaWin* win) : BaseClass(“Application”) , mFirstFrame(true) , mKeyboardListener(new dtCore::GenericKeyboardListener()) , mMouseListener(new dtCore::GenericMouseListener()) { //注册该实例 RegisterInstance(this); //注册回调函数到对应监听器 mKeyboardListener->SetPressedCallback (dtCore::GenericKeyboardListener::CallbackType (this, &Application::KeyPressed)); //…… 剩下七七八八监听注册省略 //配置窗口 mWindow = win; //创建默认View实例 CreateInstances(); mStats = new dtCore::StatsHandler(*mCompositeViewer); if (!configFilename.empty()) { std::string foundPath = dtCore::FindFileInPathList(configFilename); //读取配置文件 ParseConfigFile(foundPath) } } Application::Application(const std::string& configFilename, dtCore::DeltaWin* win) : BaseClass(“Application”), mFirstFrame(true), mKeyboardListener(new dtCore::GenericKeyboardListener()), mMouseListener(new dtCore::GenericMouseListener()){//注册该实例 RegisterInstance(this);//注册回调函数到对应监听器 mKeyboardListener->SetPressedCallback (dtCore::GenericKeyboardListener::CallbackType (this, &Application::KeyPressed));//…… 剩下七七八八监听注册省略//配置窗口 mWindow = win;//创建默认View实例CreateInstances(); mStats = new dtCore::StatsHandler(*mCompositeViewer);if (!configFilename.empty()){ std::string foundPath = dtCore::FindFileInPathList(configFilename);//读取配置文件ParseConfigFile(foundPath)}} 其中的CreateInstances()中有view plaincopy to clipboardprint?mCompositeViewer = new osgViewer::CompositeViewer; mCompositeViewer->setUpThreading(); mCompositeViewer->addView(mViewList.front()->GetOsgViewerView()); //连接相关输入和对应监听器 GetKeyboard()->AddKeyboardListener(mKeyboardListener.get()); GetMouse()->AddMouseListener(mMouseListener.get()); mCompositeViewer = new osgViewer::CompositeViewer;mCompositeViewer->setUpThreading();mCompositeViewer->addView(mViewList.front()->GetOsgViewerView()); //连接相关输入和对应监听器 GetKeyboard()->AddKeyboardListener(mKeyboardListener.get()); GetMouse()->AddMouseListener(mMouseListener.get());

具体键盘和鼠标是怎么实现监听的没看呢还 关于OSG中的类现在还不了解 就先放在这不管他了 吼吼

因为它抚平了心底的不安;当你尝到了极品的美食,

杨德龙的专栏

相关文章:

你感兴趣的文章:

标签云: