Delta3d组件机制
生活随笔
收集整理的這篇文章主要介紹了
Delta3d组件机制
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
dtGame::GMComponent主要用于處理系統中的消息,給系統動態的添加功能,增加系統的可維護性,
簡單來說,一個游戲管理器組件就是一個由游戲管理器管理的可以處理和發送消息的對象。它不像游戲角色,游戲管理器組件接受系統中所有的消息。通常情況下組件提供高層的系統行為,但它們可以處理你想要的任何事情。游戲管理器組件 是我們向游戲管理器添加自定義行為的最主要的方式。
由于組件接受系統中所有的消息,它就有機會知道所有的角色以及系統中發生的任何事情。我們可以創建簡單的組件來等待或監聽鼠標鍵盤的特定消息。我們也可以創建復雜的組件通過輔助對象來維護我們的所有角色。組件這種可擴展的結構,可以大大方便我們向游戲中添加任何重要的行為。
關于組件的優先級,在游戲管理器GameManager中,會根據組件的優先級對其中保存的組件進行排序:
void GameManager::AddComponent(GMComponent& component, const GameManager::ComponentPriority& priority){if (GetComponentByName(component.GetName()) != NULL){std::string errorText = "A component was already registered with the Game Manager with the name: " + component.GetName();LOG_ERROR(errorText);throw dtGame::InvalidParameterException(errorText, __FILE__, __LINE__);}component.SetGameManager(this);component.SetComponentPriority(priority);mGMImpl->mComponentList.push_back(dtCore::RefPtr<GMComponent>(&component)); //vector, list// we sort the items by priority so that components of higher priority get messages first.mGMImpl->mComponentList.sort(CompareComponentPriority);// notify the component that it was added to the GMcomponent.OnAddedToGM();}
總結
以上是生活随笔為你收集整理的Delta3d组件机制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows驱动程序运行时函数的调用
- 下一篇: 虚拟继承和虚表