fixed #1837: Refactoring schedule binding codes.

* 1) We need bind cc.Node.scheduleUpdate and cc.Scheduler.scheduleUpdate manually since `schedules` need to be associated with _schedFunc_target_ht and _schedObj_target_ht
* 2) Bind cc.Scheduler.unscheduleCallbackForTarget.
This commit is contained in:
James Chen 2013-03-18 15:29:53 +08:00
parent 62d7dd5002
commit f57a751a48
7 changed files with 25 additions and 2814 deletions

View File

@ -472,8 +472,8 @@ void CCScheduler::scheduleUpdateForTarget(CCObject *pTarget, int nPriority, bool
if (nPriority == 0)
{
appendIn(&m_pUpdates0List, pTarget, bPaused);
} else
if (nPriority < 0)
}
else if (nPriority < 0)
{
priorityIn(&m_pUpdatesNegList, pTarget, nPriority, bPaused);
}
@ -785,18 +785,11 @@ void CCScheduler::update(float dt)
// Iterate over all the Updates' selectors
tListEntry *pEntry, *pTmp;
CCScriptEngineProtocol* pEngine = CCScriptEngineManager::sharedManager()->getScriptEngine();
// updates with priority < 0
DL_FOREACH_SAFE(m_pUpdatesNegList, pEntry, pTmp)
{
if ((! pEntry->paused) && (! pEntry->markedForDeletion))
{
if (pEngine != NULL && kScriptTypeJavascript == pEngine->getScriptType())
{
pEngine->executeSchedule(0, dt, (CCNode *)pEntry->target);
}
pEntry->target->update(dt);
}
}
@ -806,11 +799,6 @@ void CCScheduler::update(float dt)
{
if ((! pEntry->paused) && (! pEntry->markedForDeletion))
{
if (pEngine != NULL && kScriptTypeJavascript == pEngine->getScriptType())
{
pEngine->executeSchedule(0, dt, (CCNode *)pEntry->target);
}
pEntry->target->update(dt);
}
}
@ -820,11 +808,6 @@ void CCScheduler::update(float dt)
{
if ((! pEntry->paused) && (! pEntry->markedForDeletion))
{
if (pEngine != NULL && kScriptTypeJavascript == pEngine->getScriptType())
{
pEngine->executeSchedule(0, dt, (CCNode *)pEntry->target);
}
pEntry->target->update(dt);
}
}

View File

@ -1105,7 +1105,7 @@ void CCNode::update(float fDelta)
{
if (m_nUpdateScriptHandler)
{
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nUpdateScriptHandler, fDelta);
CCScriptEngineManager::sharedManager()->getScriptEngine()->executeSchedule(m_nUpdateScriptHandler, fDelta, this);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
fa5b9ac318ba66fa30f0aa5955bfed23f79e4ee1

View File

@ -142,13 +142,18 @@ public:
class JSScheduleWrapper: public JSCallbackWrapper {
public:
JSScheduleWrapper() : _pTarget(NULL), _pPureJSTarget(NULL) {}
JSScheduleWrapper() : _pTarget(NULL), _pPureJSTarget(NULL), _priority(0), _isUpdateSchedule(false) {}
virtual ~JSScheduleWrapper();
static void setTargetForSchedule(jsval sched, JSScheduleWrapper *target);
static CCArray * getTargetForSchedule(jsval sched);
static void setTargetForJSObject(JSObject* jsTargetObj, JSScheduleWrapper *target);
static CCArray * getTargetForJSObject(JSObject* jsTargetObj);
// Remove all targets.
static void removeAllTargets();
// Remove all targets for priority.
static void removeAllTargetsForMinPriority(int minPriority);
// Remove all targets by js object from hash table(_schedFunc_target_ht and _schedObj_target_ht).
static void removeAllTargetsForJSObject(JSObject* jsTargetObj);
// Remove the target by js object and the wrapper for native schedule.
@ -158,14 +163,25 @@ public:
void pause();
void scheduleFunc(float dt) const;
virtual void update(float dt);
CCObject* getTarget();
void setTarget(CCObject* pTarget);
void setPureJSTarget(JSObject* jstarget);
JSObject* getPureJSTarget();
void setPriority(int priority);
int getPriority();
void setUpdateSchedule(bool isUpdateSchedule);
bool isUpdateSchedule();
protected:
CCObject* _pTarget;
JSObject* _pPureJSTarget;
int _priority;
bool _isUpdateSchedule;
};

View File

@ -151,6 +151,7 @@ int CCLuaEngine::executeCallFuncActionEvent(CCCallFunc* pAction, CCObject* pTarg
int CCLuaEngine::executeSchedule(int nHandler, float dt, CCNode* pNode/* = NULL*/)
{
if (!nHandler) return 0;
m_stack->pushFloat(dt);
return m_stack->executeFunctionByHandler(nHandler, 1);
}

View File

@ -35,7 +35,7 @@ classes = CCSprite.* CCScene CCNode.* CCDirector CCLayer.* CCMenu.* CCTouch CC.*
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = CCNode::[.*Transform convertToWindowSpace ^setPosition$ getGrid setGLServerState description getShaderProgram getUserObject .*UserData getGLServerState unscheduleAllSelectors],
skip = CCNode::[.*Transform convertToWindowSpace ^setPosition$ getGrid setGLServerState description getShaderProgram getUserObject .*UserData getGLServerState .*schedule],
CCSprite::[getQuad displayFrame getBlendFunc ^setPosition$ setBlendFunc setSpriteBatchNode getSpriteBatchNode],
CCSpriteBatchNode::[getBlendFunc setBlendFunc],
CCMotionStreak::[getBlendFunc setBlendFunc],
@ -91,7 +91,7 @@ skip = CCNode::[.*Transform convertToWindowSpace ^setPosition$ getGrid setGLServ
CCCatmullRom.*::[create actionWithDuration],
CCBezier.*::[create actionWithDuration],
CCCardinalSpline.*::[create actionWithDuration setPoints],
CCScheduler::[pause resume unscheduleAllSelectorsForTarget],
CCScheduler::[pause resume unschedule schedule update isTargetPaused],
CCTextureCache::[addPVRTCImage],
CCTimer::[getSelector],
*::[copyWith.* onEnter.* onExit.* ^description$ getObjectType],
@ -113,7 +113,6 @@ rename_functions = CCDirector::[sharedDirector=getInstance],
CCTileMapAtlas::[tileAt=getTileAt],
CCSprite::[isFlipX=isFlippedX isFlipY=isFlippedY],
CCTouch::[getID=getId],
CCScheduler::[unscheduleAllSelectorsForTarget=unscheduleAllCallbacksForTarget unscheduleAll=unscheduleAllCallbacks],
SimpleAudioEngine::[sharedEngine=getInstance preloadBackgroundMusic=preloadMusic setBackgroundMusicVolume=setMusicVolume getBackgroundMusicVolume=getMusicVolume playBackgroundMusic=playMusic stopBackgroundMusic=stopMusic pauseBackgroundMusic=pauseMusic resumeBackgroundMusic=resumeMusic rewindBackgroundMusic=rewindMusic isBackgroundMusicPlaying=isMusicPlaying willPlayBackgroundMusic=willPlayMusic],
CCCamera.*::[setUpXYZ=setUp getUpXYZ=getUp setEyeXYZ=setEye getEyeXYZ=getEye setCenterXYZ=setCenter getCenterXYZ=getCenter],
CCTMXTiledMap::[layerNamed=getLayer objectGroupNamed=getObjectGroup propertyNamed=getProperty],
@ -134,7 +133,7 @@ base_classes_to_skip = CCObject
# classes that create no constructor
# CCSet is special and we will use a hand-written constructor
abstract_classes = CCDirector CCSpriteFrameCache CCTransitionEaseScene CCSet SimpleAudioEngine CCFileUtils CCScheduler
abstract_classes = CCDirector CCSpriteFrameCache CCTransitionEaseScene CCSet SimpleAudioEngine CCFileUtils
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
script_control_cpp = no