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 GM
      component.OnAddedToGM();
   }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值