Delta3d框架学习--程序启动过程详解
生活随笔
收集整理的這篇文章主要介紹了
Delta3d框架学习--程序启动过程详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一個Delta3d程序啟動過程詳解
一、初始化一個dtGame::GameApplication的實例,dtGame::GameApplication* app = new?dtGame::GameApplication();
設置游戲庫的名稱,SetGameLibraryName("libname");
調用app->Config("config.xml");Config內容如下:
//解析GameEntryPoint的dll,獲取相關函數指針 dtUtil::LibrarySharingManager& lsm = dtUtil::LibrarySharingManager::GetInstance(); std::string libName = GetGameLibraryName(); mEntryPointLib = lsm.LoadSharedLibrary(libName); dtUtil::LibrarySharingManager::LibraryHandle::SYMBOL_ADDRESS createAddr; dtUtil::LibrarySharingManager::LibraryHandle::SYMBOL_ADDRESS destroyAddr; createAddr = mEntryPointLib->FindSymbol("CreateGameEntryPoint"); destroyAddr = mEntryPointLib->FindSymbol("DestroyGameEntryPoint"); mCreateFunction = reinterpret_cast<CreateEntryPointFn>(createAddr); mDestroyFunction = reinterpret_cast<DestroyEntryPointFn>(destroyAddr); //創建Aplication和GameManager mApplication = mEntryPoint->CreateApplication(configFileName); mGameManager = new dtGame::GameManager(*mApplication->GetScene()); //執行相關初始化 mEntryPoint->Initialize(*mApplication, mArgc, mArgv); mApplication->Config(); mEntryPoint->OnStartup(*mApplication, *mGameManager); //開始系統循環 dtCore::System::GetInstance().Start();?
在GameEntryPoint中的OnStartUp函數中將相應的組件添加至游戲管理器GameManager中;
在dtCore::System中有一個定時的循環,在循環中發送相關的消息(System::MESSAGE_FRAME等),然后在dtABC::BaseABC中的OnMessage()中進行消息響應。
void BaseABC::OnMessage(MessageData* data) {if (data->message == dtCore::System::MESSAGE_EVENT_TRAVERSAL){EventTraversal(*static_cast<const double*>(data->userData));}else if (data->message == dtCore::System::MESSAGE_PRE_FRAME){PreFrame(*static_cast<const double*>(data->userData));}else if (data->message == dtCore::System::MESSAGE_FRAME){Frame(*static_cast<const double*>(data->userData));}else if (data->message == dtCore::System::MESSAGE_POST_FRAME){PostFrame(*static_cast<const double*>(data->userData));}else if (data->message == dtCore::System::MESSAGE_PAUSE){Pause(*static_cast<const double*>(data->userData));} }在Frame函數中進行模型的渲染 void Application::Frame(const double deltaSimTime) {if(!mCompositeViewer->done()){bool singleThreaded = mCompositeViewer->getThreadingModel() == osgViewer::ViewerBase::SingleThreaded;//NOTE: The OSG frame() advances the clock and does three traversals, event, update, and render.//We are moving the event traversal to be its own message so we can reliably accept input during the//typical Delta3D update of PreFrame(). The only exception to this is that we needif(mFirstFrame){#ifndef MULTITHREAD_FIX_HACK_BREAKS_CEGUIdtCore::ObserverPtr<osgViewer::GraphicsWindow> gw;if (GetWindow() != NULL){gw = GetWindow()->GetOsgViewerGraphicsWindow();}if (!singleThreaded && gw.valid() && gw->isRealized()){gw->releaseContext();} #endifif (singleThreaded) { GetCompositeViewer()->setReleaseContextAtEndOfFrameHint(false); }mCompositeViewer->setUpThreading();mCompositeViewer->frame(dtCore::System::GetInstance().GetSimTimeSinceStartup());mFirstFrame = false;}// NOTE: The new version OSG (2.2) relies on absolute frame time// to update drawables; especially particle systems.// The time delta will be ignored here and the absolute simulation// time passed to the OSG scene updater.mCompositeViewer->advance(dtCore::System::GetInstance().GetSimTimeSinceStartup());mCompositeViewer->updateTraversal();mCompositeViewer->renderingTraversals();} }
總結
以上是生活随笔為你收集整理的Delta3d框架学习--程序启动过程详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MonoBehaviour常用方法
- 下一篇: linux后台开发具备能力集锦