当前位置:
首页 >
Delta3d组件以及消息机制
发布时间:2024/8/23
53
豆豆
生活随笔
收集整理的这篇文章主要介绍了
Delta3d组件以及消息机制
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
在游戏管理器(GameManager)中维护一个消息队列std::queue(mSendMessageQueue),在GameManager::SendMessage中将消息放入队列中,如下
void GameManager::SendMessage(const Message& message){mGMImpl->mSendMessageQueue.push(dtCore::RefPtr<const Message>(&message));}然后在每一帧的渲染过程中处理消息队列中的消息,调用所有组件的ProcessMessage函数,过程如下
void GameManager::DoSendMessages(){// PROCESS MESSAGES - Send all Process messages to components and interested actorswhile (!mGMImpl->mSendMessageQueue.empty()){mGMImpl->mGMStatistics.mStatsNumProcMessages += 1;// Forward to Components firstdtCore::RefPtr<const Message> messageRef = mGMImpl->mSendMessageQueue.front();mGMImpl->mSendMessageQueue.pop();if (!messageRef.valid()){mGMImpl->mLogger->LogMessage(dtUtil::Log::LOG_ERROR, __FUNCTION__, __LINE__,"Message in send queue is NULL. Something is majorly wrong with the GameManager.");continue;}const Message& message = *messageRef;DoSendMessage(message);}}void GameManager::DoSendMessage(const Message& message){DoSendMessageToComponents(message, false);} void GameManager::DoSendMessageToComponents(const Message& message, bool toNetwork){GMImpl::GMComponentContainer::iterator compItr = mGMImpl->mComponentList.begin();while (compItr != mGMImpl->mComponentList.end()){ //RefPtr in case it get deleted during a Message. We need to hang onto it for a bit.dtCore::RefPtr<GMComponent>& component = *compItr; component->ProcessMessage(message); ++compItr;}}
总结
以上是生活随笔为你收集整理的Delta3d组件以及消息机制的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: OpenGL渲染管线,着色器,光栅化等概
- 下一篇: Delta3d插件机制