123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- //
- // LoopWaiter.cpp
- // redream_runtime_mac
- //
- // Created by zhu on 2023/5/23.
- //
- #include "LoopWaiter.hpp"
- #include "ReboltRedManager.h"
- namespace redream {
- LoopWaiter::LoopWaiter(ReboltRedManager* reboltManager, red::RedBehaviacTree* tree, std::map<std::string, bool> &boolMap, std::map<std::string, std::string> &stringMap, std::string treeName)
- : _boolMap(boolMap)
- , _stringMap(stringMap)
- , _treeName(treeName)
- , _isLoopEnd(false)
- , _loopTimes(0)
- {
- _reboltManager = reboltManager;
- _fatherTree = tree;
- }
- LoopWaiter::~LoopWaiter(){
-
- }
- LoopWaiter* LoopWaiter::create(ReboltRedManager* reboltManager, red::RedBehaviacTree* tree, std::map<std::string, bool> &boolMap, std::map<std::string, std::string> &stringMap, std::string treeName){
- LoopWaiter * ret = new (std::nothrow) LoopWaiter(reboltManager, tree, boolMap, stringMap, treeName);
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool LoopWaiter::init(){
- return true;
- }
- void LoopWaiter::run(){
- _runningState.btState = RUNNING;
- createTreeAndRun();
- }
- void LoopWaiter::createTreeAndRun(){
- _loopTimes++;
- auto redBehaviacTree = _reboltManager->createBehaviacTree(_treeName, _boolMap, _stringMap);
- if(redBehaviacTree){
- _tree = redBehaviacTree;
- _tree->addRedBehaviacTreeDelegate(this);
- _tree->setReboltLoopManager(this);
- redBehaviacTree->runBehaviacTree();
- } else {
- _runningState.btState = FAILURE;
- }
- }
- int LoopWaiter::getLoopTimes(){
- return _loopTimes;
- }
- void LoopWaiter::onLoopEnd(){
- // 结束后立即调用父树的刷新,父树的对象直接调用
- _isLoopEnd = true;
- _tree->removeRedBehaviacTreeDelegate(this);
- onSuccessEnd();
- }
- void LoopWaiter::onTreeRunningEnd(red::RedBehaviacTree* tree, int endType, std::string treeName){
- // 数播放完毕之后,就需要播放一个新的树
- if(!_isLoopEnd){
- createTreeAndRun();
- }
- }
- };
|