issue #2377:Replace the CallFunc script Handler and repair Testlua Bug

This commit is contained in:
samuele3hu 2013-07-11 13:38:25 +08:00
parent 31d0e492c2
commit 9007b9feee
15 changed files with 105 additions and 67 deletions

View File

@ -30,6 +30,7 @@ THE SOFTWARE.
NS_CC_BEGIN
class ScriptHandlerMgr;
class CC_DLL NotificationCenter : public Object
{
friend class ScriptHandlerMgr;

View File

@ -1,4 +1,5 @@
local size = CCDirector:sharedDirector():getWinSize()
local scriptHandlerMgr = ScriptHandlerMgr:getInstance()
local function initWithLayer(layer)
grossini = CCSprite:create(s_pPathGrossini)
@ -592,9 +593,10 @@ local function ActionSequence2()
array:addObject(CCPlace:create(ccp(200,200)))
array:addObject(CCShow:create())
array:addObject(CCMoveBy:create(1, ccp(100,0)))
array:addObject(CCCallFunc:create(ActionSequenceCallback1))
array:addObject(CCCallFuncN:create(ActionSequenceCallback2))
array:addObject(CCCallFuncN:create(ActionSequenceCallback3))
array:addObject(scriptHandlerMgr:registerCallFuncHandler(ActionSequenceCallback1))
array:addObject(scriptHandlerMgr:registerCallFuncHandler(ActionSequenceCallback2))
array:addObject(scriptHandlerMgr:registerCallFuncHandler(ActionSequenceCallback3))
local action = CCSequence:create(array)
grossini:runAction(action)
@ -703,7 +705,7 @@ local function ActionRepeatForever()
local action = CCSequence:createWithTwoActions(
CCDelayTime:create(1),
CCCallFuncN:create(repeatForever))
scriptHandlerMgr:registerCallFuncHandler(repeatForever) )
grossini:runAction(action)
@ -796,18 +798,18 @@ local function ActionCallFunc()
local action = CCSequence:createWithTwoActions(
CCMoveBy:create(2, ccp(200,0)),
CCCallFunc:create(CallFucnCallback1))
scriptHandlerMgr:registerCallFuncHandler(CallFucnCallback1) )
local array = CCArray:create()
array:addObject(CCScaleBy:create(2, 2))
array:addObject(CCFadeOut:create(2))
array:addObject(CCCallFuncN:create(CallFucnCallback2))
array:addObject(scriptHandlerMgr:registerCallFuncHandler(CallFucnCallback2))
local action2 = CCSequence:create(array)
local array2 = CCArray:create()
array2:addObject(CCRotateBy:create(3 , 360))
array2:addObject(CCFadeOut:create(2))
array2:addObject(CCCallFuncN:create(CallFucnCallback3))
array2:addObject(scriptHandlerMgr:registerCallFuncHandler(CallFucnCallback3))
local action3 = CCSequence:create(array2)
grossini:runAction(action)
@ -1087,7 +1089,7 @@ local function ActionIssue1305()
centerSprites(0)
spriteTmp = CCSprite:create("Images/grossini.png")
spriteTmp:runAction(CCCallFuncN:create(Issue1305_log))
spriteTmp:runAction(scriptHandlerMgr:registerCallFuncHandler(Issue1305_log))
Issue1305_layer:registerScriptHandler(Issue1305_onEnterOrExit)
@ -1126,13 +1128,13 @@ local function ActionIssue1305_2()
layer:addChild(spr)
local act1 = CCMoveBy:create(2 ,ccp(0, 100))
local act2 = CCCallFunc:create(Issue1305_2_log1)
local act2 = scriptHandlerMgr:registerCallFuncHandler(Issue1305_2_log1)
local act3 = CCMoveBy:create(2, ccp(0, -100))
local act4 = CCCallFunc:create(Issue1305_2_log2)
local act4 = scriptHandlerMgr:registerCallFuncHandler(Issue1305_2_log2)
local act5 = CCMoveBy:create(2, ccp(100, -100))
local act6 = CCCallFunc:create(Issue1305_2_log3)
local act6 = scriptHandlerMgr:registerCallFuncHandler(Issue1305_2_log3)
local act7 = CCMoveBy:create(2, ccp(-100, 0))
local act8 = CCCallFunc:create(Issue1305_2_log4)
local act8 = scriptHandlerMgr:registerCallFuncHandler(Issue1305_2_log4)
local array = CCArray:create()
array:addObject(act1)
@ -1215,15 +1217,15 @@ local function ActionIssue1327()
spr:setPosition(ccp(100, 100))
layer:addChild(spr)
local act1 = CCCallFuncN:create(logSprRotation)
local act1 = scriptHandlerMgr:registerCallFuncHandler(logSprRotation)
local act2 = CCRotateBy:create(0.25, 45)
local act3 = CCCallFuncN:create(logSprRotation)
local act3 = scriptHandlerMgr:registerCallFuncHandler(logSprRotation)
local act4 = CCRotateBy:create(0.25, 45)
local act5 = CCCallFuncN:create(logSprRotation)
local act5 = scriptHandlerMgr:registerCallFuncHandler(logSprRotation)
local act6 = CCRotateBy:create(0.25, 45)
local act7 = CCCallFuncN:create(logSprRotation)
local act7 = scriptHandlerMgr:registerCallFuncHandler(logSprRotation)
local act8 = CCRotateBy:create(0.25, 45)
local act9 = CCCallFuncN:create(logSprRotation)
local act9 = scriptHandlerMgr:registerCallFuncHandler(logSprRotation)
local array = CCArray:create()
array:addObject(act1)

View File

@ -128,7 +128,8 @@ function LabelAtlasColorTest.create()
local fade = CCFadeOut:create(1.0)
local fade_in = fade:reverse()
local cb = CCCallFunc:create(LabelAtlasColorTest.actionFinishCallback)
local scriptHandlerMgr = ScriptHandlerMgr:getInstance()
local cb = scriptHandlerMgr:registerCallFuncHandler(LabelAtlasColorTest.actionFinishCallback)
local actionArr = CCArray:create()
actionArr:addObject(fade)
actionArr:addObject(fade_in)

View File

@ -515,7 +515,8 @@ local function MenuLayerPriorityTest()
local function disableMenuCallback(tag, pSender)
m_pMenu1:setEnabled(false)
local wait = CCDelayTime:create(5)
local enable = CCCallFunc:create(enableMenuCallback)
local scriptHandlerMgr = ScriptHandlerMgr:getInstance()
local enable = scriptHandlerMgr:registerCallFuncHandler(enableMenuCallback)
local arr = CCArray:create()
arr:addObject(wait)
arr:addObject(enable)

View File

@ -313,7 +313,9 @@ local function shouldNotCrash(dt)
explosion:setPosition(s.width / 2, s.height / 2)
StressTest1_layer:setAnchorPoint(ccp(0, 0))
StressTest1_layer:runAction(CCSequence:createWithTwoActions(CCRotateBy:create(2, 360), CCCallFuncN:create(removeMe)))
local scriptHandlerMgr = ScriptHandlerMgr:getInstance()
local callFunc = scriptHandlerMgr:registerCallFuncHandler(removeMe)
StressTest1_layer:runAction(CCSequence:createWithTwoActions(CCRotateBy:create(2, 360), callFunc))
StressTest1_layer:addChild(explosion)
end

View File

@ -377,9 +377,12 @@ local function TMXReadWriteTest()
local fadein = CCFadeIn:create(2)
local scaleback = CCScaleTo:create(1, 1)
local function removeSprite(tag, sender)
local function removeSprite(sender)
--------cclog("removing tile: %x", sender)
local node = tolua.cast(sender, "CCNode");
local node = tolua.cast(sender, "CCNode")
if nil == node then
print("Errro node is nil")
end
local p = node:getParent()
if p ~= nil then
@ -388,8 +391,8 @@ local function TMXReadWriteTest()
----------cclog("atlas quantity: %d", p:textureAtlas():totalQuads())
end
local finish = CCCallFuncN:create(removeSprite)
local scriptHandlerMgr = ScriptHandlerMgr:getInstance()
local finish = scriptHandlerMgr:registerCallFuncHandler(removeSprite)
local arr = CCArray:create()
arr:addObject(move)
arr:addObject(rotate)

View File

@ -61,7 +61,8 @@ end
function schedule(node, callback, delay)
local delay = CCDelayTime:create(delay)
local callfunc = CCCallFunc:create(callback)
local scriptHandlerMgr = ScriptHandlerMgr:getInstance()
local callfunc = scriptHandlerMgr:registerCallFuncHandler(callback)
local sequence = CCSequence:createWithTwoActions(delay, callfunc)
local action = CCRepeatForever:create(sequence)
node:runAction(action)
@ -70,7 +71,8 @@ end
function performWithDelay(node, callback, delay)
local delay = CCDelayTime:create(delay)
local callfunc = CCCallFunc:create(callback)
local scriptHandlerMgr = ScriptHandlerMgr:getInstance()
local callfunc = scriptHandlerMgr:registerCallFuncHandler(callback)
local sequence = CCSequence:createWithTwoActions(delay, callfunc)
node:runAction(sequence)
return sequence

View File

@ -45,51 +45,50 @@ local BeginPos = {x = 0, y = 0}
local _allTests = {
{ isSupported = true, name = "ActionsTest" , create_func = ActionsTest },
{ isSupported = true, name = "TransitionsTest" , create_func = TransitionsTest },
{ isSupported = true, name = "ActionsProgressTest" , create_func = ProgressActionsTest },
{ isSupported = true, name = "EffectsTest" , create_func = EffectsTest },
{ isSupported = true, name = "ClickAndMoveTest" , create_func = ClickAndMoveTest },
{ isSupported = true, name = "RotateWorldTest" , create_func = RotateWorldTest },
{ isSupported = true, name = "ParticleTest" , create_func = ParticleTest },
{ isSupported = true, name = "ActionsEaseTest" , create_func = EaseActionsTest },
{ isSupported = true, name = "MotionStreakTest" , create_func = MotionStreakTest },
{ isSupported = false, name = "DrawPrimitivesTest" , create_func= DrawPrimitivesTest },
{ isSupported = true, name = "NodeTest" , create_func = CocosNodeTest },
{ isSupported = true, name = "TouchesTest" , create_func = TouchesTest },
--Many tests in MenuTest will crash, so disable it. Should enable it after all crashes are resolved.
{ isSupported = true, name = "MenuTest" , create_func = MenuTestMain },
{ isSupported = true, name = "Accelerometer" , create_func= AccelerometerMain },
{ isSupported = true, name = "ActionManagerTest" , create_func = ActionManagerTestMain },
{ isSupported = true, name = "LayerTest" , create_func = LayerTestMain },
{ isSupported = true, name = "SceneTest" , create_func = SceneTestMain },
{ isSupported = true, name = "ParallaxTest" , create_func = ParallaxTestMain },
{ isSupported = true, name = "TileMapTest" , create_func = TileMapTestMain },
{ isSupported = true, name = "IntervalTest" , create_func = IntervalTestMain },
{ isSupported = false, name = "ChipmunkAccelTouchTest" , create_func= ChipmunkAccelTouchTestMain },
{ isSupported = true, name = "LabelTest" , create_func = LabelTest },
{ isSupported = false, name = "TextInputTest" , create_func= TextInputTestMain },
{ isSupported = true, name = "SpriteTest" , create_func = SpriteTest },
{ isSupported = false, name = "SchdulerTest" , create_func= SchdulerTestMain },
{ isSupported = true, name = "RenderTextureTest" , create_func = RenderTextureTestMain },
{ isSupported = true, name = "Texture2DTest" , create_func = Texture2dTestMain },
{ isSupported = true, name = "ActionsEaseTest" , create_func = EaseActionsTest },
{ isSupported = true, name = "ActionsProgressTest" , create_func = ProgressActionsTest },
{ isSupported = true, name = "ActionsTest" , create_func = ActionsTest },
{ isSupported = false, name = "Box2dTest" , create_func= Box2dTestMain },
{ isSupported = false, name = "Box2dTestBed" , create_func= Box2dTestBedMain },
{ isSupported = true, name = "EffectAdvancedTest" , create_func = EffectAdvancedTestMain },
{ isSupported = true, name = "Accelerometer" , create_func= AccelerometerMain },
{ isSupported = true, name = "KeypadTest" , create_func= KeypadTestMain },
{ isSupported = true, name = "CocosDenshionTest" , create_func = CocosDenshionTestMain },
{ isSupported = true, name = "PerformanceTest" , create_func= PerformanceTestMain },
{ isSupported = true, name = "ZwoptexTest" , create_func = ZwoptexTestMain },
{ isSupported = false, name = "CurlTest" , create_func= CurlTestMain },
{ isSupported = true, name = "UserDefaultTest" , create_func= UserDefaultTestMain },
{ isSupported = true, name = "BugsTest" , create_func= BugsTestMain },
{ isSupported = true, name = "FontTest" , create_func = FontTestMain },
{ isSupported = false, name = "ChipmunkAccelTouchTest" , create_func= ChipmunkAccelTouchTestMain },
{ isSupported = true, name = "ClickAndMoveTest" , create_func = ClickAndMoveTest },
{ isSupported = true, name = "CocosDenshionTest" , create_func = CocosDenshionTestMain },
{ isSupported = false, name = "CurlTest" , create_func= CurlTestMain },
{ isSupported = true, name = "CurrentLanguageTest" , create_func= CurrentLanguageTestMain },
{ isSupported = false, name = "TextureCacheTest" , create_func= TextureCacheTestMain },
{ isSupported = false, name = "DrawPrimitivesTest" , create_func= DrawPrimitivesTest },
{ isSupported = true, name = "EffectsTest" , create_func = EffectsTest },
{ isSupported = true, name = "EffectAdvancedTest" , create_func = EffectAdvancedTestMain },
{ isSupported = true, name = "ExtensionsTest" , create_func= ExtensionsTestMain },
{ isSupported = false, name = "ShaderTest" , create_func= ShaderTestMain },
{ isSupported = true, name = "FontTest" , create_func = FontTestMain },
{ isSupported = true, name = "IntervalTest" , create_func = IntervalTestMain },
{ isSupported = true, name = "KeypadTest" , create_func= KeypadTestMain },
{ isSupported = true, name = "LabelTest" , create_func = LabelTest },
{ isSupported = true, name = "LayerTest" , create_func = LayerTestMain },
{ isSupported = true, name = "MenuTest" , create_func = MenuTestMain },
{ isSupported = true, name = "MotionStreakTest" , create_func = MotionStreakTest },
{ isSupported = false, name = "MutiTouchTest" , create_func= MutiTouchTestMain },
{ isSupported = true, name = "OpenGLTest" , create_func= OpenGLTestMain }
{ isSupported = true, name = "NodeTest" , create_func = CocosNodeTest },
{ isSupported = true, name = "OpenGLTest" , create_func= OpenGLTestMain },
{ isSupported = true, name = "ParallaxTest" , create_func = ParallaxTestMain },
{ isSupported = true, name = "ParticleTest" , create_func = ParticleTest },
{ isSupported = true, name = "PerformanceTest" , create_func= PerformanceTestMain },
{ isSupported = true, name = "RenderTextureTest" , create_func = RenderTextureTestMain },
{ isSupported = true, name = "RotateWorldTest" , create_func = RotateWorldTest },
{ isSupported = true, name = "SceneTest" , create_func = SceneTestMain },
{ isSupported = false, name = "SchdulerTest" , create_func= SchdulerTestMain },
{ isSupported = false, name = "ShaderTest" , create_func= ShaderTestMain },
{ isSupported = true, name = "SpriteTest" , create_func = SpriteTest },
{ isSupported = false, name = "TextInputTest" , create_func= TextInputTestMain },
{ isSupported = true, name = "Texture2DTest" , create_func = Texture2dTestMain },
{ isSupported = false, name = "TextureCacheTest" , create_func= TextureCacheTestMain },
{ isSupported = true, name = "TileMapTest" , create_func = TileMapTestMain },
{ isSupported = true, name = "TouchesTest" , create_func = TouchesTest },
{ isSupported = true, name = "TransitionsTest" , create_func = TransitionsTest },
{ isSupported = true, name = "UserDefaultTest" , create_func= UserDefaultTestMain },
{ isSupported = true, name = "ZwoptexTest" , create_func = ZwoptexTestMain }
}
local TESTS_COUNT = table.getn(_allTests)

View File

@ -68,6 +68,7 @@ void LuaEngine::addLuaLoader(lua_CFunction func)
void LuaEngine::removeScriptObjectByObject(Object* pObj)
{
_stack->removeScriptObjectByObject(pObj);
ScriptHandlerMgr::getInstance()->unregisterObjectAllHandlers(pObj);
}
void LuaEngine::removeScriptHandler(int nHandler)

View File

@ -18,6 +18,7 @@ extern "C" {
using namespace cocos2d;
using namespace cocos2d::extension;
NS_CC_BEGIN
ScheduleHandlerDelegate* ScheduleHandlerDelegate::create()
{
@ -81,7 +82,7 @@ void CallFuncHandlerDelegate::callFunc(Node* node)
if (0 != handler)
{
BasicScriptData data((void*)this,(void*)_callFunc->getTarget());
BasicScriptData data((void*)this,(void*)node);
ScriptEvent event(kCallFuncEvent,(void*)&data);
ScriptEngineManager::sharedManager()->getScriptEngine()->sendEvent(&event);
}
@ -185,6 +186,20 @@ int ScriptHandlerMgr::getObjecHandlerByEvent(void* object,int eventType)
return 0;
}
void ScriptHandlerMgr::unregisterObjectAllHandlers(void* object)
{
if (NULL == object || _mapObjectHandlers.empty())
return;
auto iter = _mapObjectHandlers.find(object);
if (_mapObjectHandlers.end() != iter)
{
(iter->second).clear();
_mapObjectHandlers.erase(iter);
}
}
ScheduleHandlerDelegate* ScriptHandlerMgr::registerScheduleHandler(int handler,float interval, unsigned int repeat, float delay, bool paused)
{
if ( 0 == handler || NULL == Director::sharedDirector()->getScheduler() )
@ -535,6 +550,7 @@ void ScriptHandlerMgr::removeNodeSchedule(cocos2d::Node* node,ScheduleHandlerDel
}
}
NS_CC_END
static void tolua_reg_script_handler_mgr_type(lua_State* tolua_S)
{

View File

@ -13,6 +13,8 @@ extern "C" {
#include <vector>
#include <map>
NS_CC_BEGIN
class ScheduleHandlerDelegate;
typedef int EventType;
@ -71,6 +73,7 @@ public:
void registerObjectHandler(void* object,int handler,int eventType);
void unregisterObjectHandler(void* object,int eventType);
int getObjecHandlerByEvent(void* object,int eventType);
void unregisterObjectAllHandlers(void* object);
void registerNotificationHandler(cocos2d::Object* target,int handler,const char* name);
void unregisterNotificationHandler(cocos2d::Object* target,const char* name);
@ -114,6 +117,8 @@ private:
MapNodeSchedules _mapNodeScehdules;
};
NS_CC_END
TOLUA_API int tolua_script_handler_mgr_open(lua_State* tolua_S);
#endif //__LUA_SCRIPT_HANDLER_MGR_H__

View File

@ -16,6 +16,7 @@ LOCAL_SRC_FILES := ../cocos2dx_support/CCLuaBridge.cpp \
../cocos2dx_support/Lua_web_socket.cpp \
../cocos2dx_support/LuaOpengl.cpp \
../cocos2dx_support/LuaScrollView.cpp \
../cocos2dx_support/LuaScriptHandlerMgr.cpp \
../tolua/tolua_event.c \
../tolua/tolua_is.c \
../tolua/tolua_map.c \

View File

@ -48,7 +48,8 @@ SOURCES = ../lua/lapi.o \
../cocos2dx_support/CCBProxy.cpp \
../cocos2dx_support/Lua_extensions_CCB.cpp \
../cocos2dx_support/LuaOpengl.cpp \
../cocos2dx_support/LuaScrollView.cpp
../cocos2dx_support/LuaScrollView.cpp \
../cocos2dx_support/LuaScriptHandlerMgr.cpp
include ../../../cocos2dx/proj.emscripten/cocos2dx.mk

View File

@ -48,7 +48,8 @@ SOURCES = ../lua/lapi.o \
../cocos2dx_support/CCBProxy.cpp \
../cocos2dx_support/Lua_extensions_CCB.cpp \
../cocos2dx_support/LuaOpengl.cpp \
../cocos2dx_support/LuaScrollView.cpp
../cocos2dx_support/LuaScrollView.cpp \
../cocos2dx_support/LuaScriptHandlerMgr.cpp
include ../../../cocos2dx/proj.linux/cocos2dx.mk

View File

@ -42,4 +42,6 @@ files
"LuaOpengl.h"
"LuaScrollView.cpp"
"LuaScrollView.h"
"LuaScriptHandlerMgr.cpp"
"LuaScriptHandlerMgr.h"
}