Merge pull request #5862 from samuele3hu/develop_script_mgr

closed #4452: Adds `addCustomHandler` in the ScriptHandlerMgr for Console auto test.
This commit is contained in:
James Chen 2014-03-21 16:48:53 +08:00
commit 832ab120aa
2 changed files with 28 additions and 1 deletions

View File

@ -236,6 +236,29 @@ void ScriptHandlerMgr::removeObjectAllHandlers(void* object)
}
}
ScriptHandlerMgr::HandlerType ScriptHandlerMgr::addCustomHandler(void* object, int handler)
{
assert(nullptr != object);
auto iter = _mapObjectHandlers.find(object);
VecHandlerPairs vecHandlers;
vecHandlers.clear();
HandlerType handlerType = HandlerType::EVENT_CUSTOM_BEGAN;
if (_mapObjectHandlers.end() != iter)
{
vecHandlers = iter->second;
handlerType = static_cast<HandlerType>((int)vecHandlers.back().first + 1);
}
assert(handlerType <= HandlerType::EVENT_CUSTOM_ENDED);
HandlerPair eventHanler = std::make_pair(handlerType, handler);
vecHandlers.push_back(eventHanler);
_mapObjectHandlers[object] = vecHandlers;
return handlerType;
}
NS_CC_END

View File

@ -160,8 +160,11 @@ public:
EVENT_PHYSICS_CONTACT_PRESOLVE,
EVENT_PHYSICS_CONTACT_POSTSOLVE,
EVENT_PHYSICS_CONTACT_SEPERATE,
EVENT_CUSTOM_BEGAN = 10000,
EVENT_CUSTOM_ENDED = 11000,
};
typedef int Handler;
typedef std::pair<HandlerType, Handler> HandlerPair;
typedef std::vector<HandlerPair> VecHandlerPairs;
@ -175,6 +178,7 @@ public:
void removeObjectHandler(void* object,ScriptHandlerMgr::HandlerType handlerType);
int getObjectHandler(void* object,ScriptHandlerMgr::HandlerType handlerType);
void removeObjectAllHandlers(void* object);
ScriptHandlerMgr::HandlerType addCustomHandler(void* object, int handler);
private:
void init(void);