From 6038d6918376e87e3d533151f608db23ca2fdd52 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 12 Jul 2013 14:12:58 +0800 Subject: [PATCH] issue #2397: sharedSpriteFrameCache --> getInstance, purgeSharedSpriteFrameCache --> destroyInstance. --- .../GUI/CCControlExtension/CCScale9Sprite.cpp | 2 +- .../SpriteTest/SpriteTest.cpp.REMOVED.git-id | 2 +- .../ActionsProgressTest.lua | 2 +- .../RenderTextureTest/RenderTextureTest.lua | 2 +- .../luaScript/SpriteTest/SpriteTest.lua | 60 +++++++++---------- .../luaScript/ZwoptexTest/ZwoptexTest.lua | 14 ++--- tools/tojs/cocos2dx.ini | 3 +- tools/tolua++/CCSpriteFrameCache.pkg | 8 ++- 8 files changed, 49 insertions(+), 44 deletions(-) diff --git a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp index e4086ac8d3..864868018f 100644 --- a/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp +++ b/extensions/GUI/CCControlExtension/CCScale9Sprite.cpp @@ -581,7 +581,7 @@ Scale9Sprite* Scale9Sprite::createWithSpriteFrame(SpriteFrame* spriteFrame) bool Scale9Sprite::initWithSpriteFrameName(const char* spriteFrameName, Rect capInsets) { - CCAssert((SpriteFrameCache::getInstance()) != NULL, "sharedSpriteFrameCache must be non-NULL"); + CCAssert((SpriteFrameCache::getInstance()) != NULL, "SpriteFrameCache::getInstance() must be non-NULL"); SpriteFrame *frame = SpriteFrameCache::getInstance()->spriteFrameByName(spriteFrameName); CCAssert(frame != NULL, "CCSpriteFrame must be non-NULL"); diff --git a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id index 93ec7c443c..d9d2f2fcd8 100644 --- a/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id +++ b/samples/Cpp/TestCpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id @@ -1 +1 @@ -9aaefef976e0db10d9c5b473fed588a0f1f9feb2 \ No newline at end of file +6ece549f30445e73362dd4a81e44557bb087a528 \ No newline at end of file diff --git a/samples/Lua/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua b/samples/Lua/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua index 6963e622e0..59fc30012d 100644 --- a/samples/Lua/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/ActionsProgressTest/ActionsProgressTest.lua @@ -253,7 +253,7 @@ local function SpriteProgressWithSpriteFrame() local to = CCProgressTo:create(6, 100) - CCSpriteFrameCache:sharedSpriteFrameCache():addSpriteFramesWithFile("zwoptex/grossini.plist") + CCSpriteFrameCache:getInstance():addSpriteFramesWithFile("zwoptex/grossini.plist") local left = CCProgressTimer:create(CCSprite:createWithSpriteFrameName("grossini_dance_01.png")) left:setType(kCCProgressTimerTypeBar) diff --git a/samples/Lua/TestLua/Resources/luaScript/RenderTextureTest/RenderTextureTest.lua b/samples/Lua/TestLua/Resources/luaScript/RenderTextureTest/RenderTextureTest.lua index 97167dd9f3..985292d329 100644 --- a/samples/Lua/TestLua/Resources/luaScript/RenderTextureTest/RenderTextureTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/RenderTextureTest/RenderTextureTest.lua @@ -234,7 +234,7 @@ end -- label2:setVertexZ(0) -- label3:setVertexZ(-50) --- CCSpriteFrameCache:sharedSpriteFrameCache():addSpriteFramesWithFile("Images/bugs/circle.plist") +-- CCSpriteFrameCache:getInstance():addSpriteFramesWithFile("Images/bugs/circle.plist") -- mgr = CCSpriteBatchNode:create("Images/bugs/circle.png", 9) -- this:addChild(mgr) -- sp1 = CCSprite:createWithSpriteFrameName("circle.png") diff --git a/samples/Lua/TestLua/Resources/luaScript/SpriteTest/SpriteTest.lua b/samples/Lua/TestLua/Resources/luaScript/SpriteTest/SpriteTest.lua index 2faf04a475..38d01ae436 100644 --- a/samples/Lua/TestLua/Resources/luaScript/SpriteTest/SpriteTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/SpriteTest/SpriteTest.lua @@ -241,7 +241,7 @@ SpriteFrameTest.m_nCounter = 0 function SpriteFrameTest.onEnter() local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -295,7 +295,7 @@ function SpriteFrameTest.onEnter() end function SpriteFrameTest.onExit() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") cache:removeSpriteFramesFromFile("animations/grossini_blue.plist") @@ -362,7 +362,7 @@ SpriteFrameAliasNameTest.__index = SpriteFrameAliasNameTest function SpriteFrameAliasNameTest.onEnter() local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini-aliases.plist", "animations/grossini-aliases.png") local sprite = CCSprite:createWithSpriteFrameName("grossini_dance_01.png") @@ -386,7 +386,7 @@ function SpriteFrameAliasNameTest.onEnter() end function SpriteFrameAliasNameTest.onExit() - CCSpriteFrameCache:sharedSpriteFrameCache():removeSpriteFramesFromFile("animations/grossini-aliases.plist") + CCSpriteFrameCache:getInstance():removeSpriteFramesFromFile("animations/grossini-aliases.plist") end function SpriteFrameAliasNameTest.onEnterOrExit(tag) @@ -522,7 +522,7 @@ SpriteOffsetAnchorRotation.__index = SpriteOffsetAnchorRotation function SpriteOffsetAnchorRotation.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -567,7 +567,7 @@ end function SpriteOffsetAnchorRotation.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -597,7 +597,7 @@ function SpriteBatchNodeOffsetAnchorRotation.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -645,7 +645,7 @@ end function SpriteBatchNodeOffsetAnchorRotation.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -674,7 +674,7 @@ SpriteOffsetAnchorScale.__index = SpriteOffsetAnchorScale function SpriteOffsetAnchorScale.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -723,7 +723,7 @@ end function SpriteOffsetAnchorScale.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -751,7 +751,7 @@ local SpriteBatchNodeOffsetAnchorScale = {} function SpriteBatchNodeOffsetAnchorScale.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -801,7 +801,7 @@ function SpriteBatchNodeOffsetAnchorScale.initLayer(layer) end function SpriteBatchNodeOffsetAnchorScale.onExit() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -836,7 +836,7 @@ function SpriteOffsetAnchorSkew.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -892,7 +892,7 @@ end function SpriteOffsetAnchorSkew.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -919,7 +919,7 @@ function SpriteOffsetAnchorRotationalSkew.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -974,7 +974,7 @@ end function SpriteOffsetAnchorRotationalSkew.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -1003,7 +1003,7 @@ function SpriteBatchNodeOffsetAnchorSkew.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -1062,7 +1062,7 @@ end function SpriteBatchNodeOffsetAnchorSkew.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -1090,7 +1090,7 @@ function SpriteBatchNodeOffsetAnchorRotationalSkew.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -1151,7 +1151,7 @@ end -- remove resources function SpriteBatchNodeOffsetAnchorRotationalSkew.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -1177,7 +1177,7 @@ local SpriteOffsetAnchorSkewScale = {} function SpriteOffsetAnchorSkewScale.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -1238,7 +1238,7 @@ end function SpriteOffsetAnchorSkewScale.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -1263,7 +1263,7 @@ local SpriteOffsetAnchorRotationalSkewScale = {} function SpriteOffsetAnchorRotationalSkewScale.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -1324,7 +1324,7 @@ end function SpriteOffsetAnchorRotationalSkewScale.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -1349,7 +1349,7 @@ local SpriteBatchNodeOffsetAnchorSkewScale = {} function SpriteBatchNodeOffsetAnchorSkewScale.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -1413,7 +1413,7 @@ end function SpriteBatchNodeOffsetAnchorSkewScale.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -1437,7 +1437,7 @@ local SpriteBatchNodeOffsetAnchorRotationalSkewScale = {} function SpriteBatchNodeOffsetAnchorRotationalSkewScale.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -1500,7 +1500,7 @@ end function SpriteBatchNodeOffsetAnchorRotationalSkewScale.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end @@ -1524,7 +1524,7 @@ local SpriteOffsetAnchorFlip = {} function SpriteOffsetAnchorFlip.initLayer(layer) local s = CCDirector:getInstance():getWinSize() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:addSpriteFramesWithFile("animations/grossini.plist") cache:addSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray.png") @@ -1576,7 +1576,7 @@ end function SpriteOffsetAnchorFlip.eventHandler(tag) if tag == "exit" then - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("animations/grossini.plist") cache:removeSpriteFramesFromFile("animations/grossini_gray.plist") end diff --git a/samples/Lua/TestLua/Resources/luaScript/ZwoptexTest/ZwoptexTest.lua b/samples/Lua/TestLua/Resources/luaScript/ZwoptexTest/ZwoptexTest.lua index 9af50002c3..0ee4602f80 100644 --- a/samples/Lua/TestLua/Resources/luaScript/ZwoptexTest/ZwoptexTest.lua +++ b/samples/Lua/TestLua/Resources/luaScript/ZwoptexTest/ZwoptexTest.lua @@ -16,14 +16,14 @@ local function ZwoptexGenericTest() local sprite2 = nil local function onEnter() - CCSpriteFrameCache:sharedSpriteFrameCache():addSpriteFramesWithFile("zwoptex/grossini.plist") - CCSpriteFrameCache:sharedSpriteFrameCache():addSpriteFramesWithFile("zwoptex/grossini-generic.plist") + CCSpriteFrameCache:getInstance():addSpriteFramesWithFile("zwoptex/grossini.plist") + CCSpriteFrameCache:getInstance():addSpriteFramesWithFile("zwoptex/grossini-generic.plist") local layer1 = CCLayerColor:create(Color4B(255, 0, 0, 255), 85, 121) layer1:setPosition(ccp(s.width/2-80 - (85.0 * 0.5), s.height/2 - (121.0 * 0.5))) ret:addChild(layer1) - sprite1 = CCSprite:createWithSpriteFrame(CCSpriteFrameCache:sharedSpriteFrameCache():spriteFrameByName("grossini_dance_01.png")) + sprite1 = CCSprite:createWithSpriteFrame(CCSpriteFrameCache:getInstance():spriteFrameByName("grossini_dance_01.png")) sprite1:setPosition(ccp( s.width/2-80, s.height/2)) ret:addChild(sprite1) @@ -34,7 +34,7 @@ local function ZwoptexGenericTest() layer2:setPosition(ccp(s.width/2+80 - (85.0 * 0.5), s.height/2 - (121.0 * 0.5))) ret:addChild(layer2) - sprite2 = CCSprite:createWithSpriteFrame(CCSpriteFrameCache:sharedSpriteFrameCache():spriteFrameByName("grossini_dance_generic_01.png")) + sprite2 = CCSprite:createWithSpriteFrame(CCSpriteFrameCache:getInstance():spriteFrameByName("grossini_dance_generic_01.png")) sprite2:setPosition(ccp( s.width/2 + 80, s.height/2)) ret:addChild(sprite2) @@ -74,8 +74,8 @@ local function ZwoptexGenericTest() local str1 = string.format("grossini_dance_%02d.png", spriteFrameIndex) local str2 = string.format("grossini_dance_generic_%02d.png", spriteFrameIndex) - sprite1:setDisplayFrame(CCSpriteFrameCache:sharedSpriteFrameCache():spriteFrameByName(str1)) - sprite2:setDisplayFrame(CCSpriteFrameCache:sharedSpriteFrameCache():spriteFrameByName(str2)) + sprite1:setDisplayFrame(CCSpriteFrameCache:getInstance():spriteFrameByName(str1)) + sprite2:setDisplayFrame(CCSpriteFrameCache:getInstance():spriteFrameByName(str2)) end sprite1:retain() @@ -97,7 +97,7 @@ local function ZwoptexGenericTest() end sprite1:release() sprite2:release() - local cache = CCSpriteFrameCache:sharedSpriteFrameCache() + local cache = CCSpriteFrameCache:getInstance() cache:removeSpriteFramesFromFile("zwoptex/grossini.plist") cache:removeSpriteFramesFromFile("zwoptex/grossini-generic.plist") end diff --git a/tools/tojs/cocos2dx.ini b/tools/tojs/cocos2dx.ini index 2d0259250b..00b64e2a33 100644 --- a/tools/tojs/cocos2dx.ini +++ b/tools/tojs/cocos2dx.ini @@ -105,9 +105,10 @@ skip = Node::[^setPosition$ getGrid setGLServerState description getUserObject . Camera::[getEyeXYZ getCenterXYZ getUpXYZ], ShaderCache::[sharedShaderCache purgeSharedShaderCache], AnimationCache::[sharedAnimationCache purgeSharedAnimationCache], + SpriteFrameCache::[sharedSpriteFrameCache purgeSharedSpriteFrameCache], ccFontDefinition::[*] -rename_functions = SpriteFrameCache::[sharedSpriteFrameCache=getInstance addSpriteFramesWithFile=addSpriteFrames spriteFrameByName=getSpriteFrame isFlipX=isFlippedX isFlipY=isFlippedY], +rename_functions = SpriteFrameCache::[addSpriteFramesWithFile=addSpriteFrames spriteFrameByName=getSpriteFrame isFlipX=isFlippedX isFlipY=isFlippedY], MenuItemFont::[setFontNameObj=setFontName setFontSizeObj=setFontSize fontSizeObj=fontSize fontNameObj=fontName], ProgressTimer::[setReverseProgress=setReverseDirection], TextureCache::[sharedTextureCache=getInstance], diff --git a/tools/tolua++/CCSpriteFrameCache.pkg b/tools/tolua++/CCSpriteFrameCache.pkg index 326b3262ef..8e3bc374fa 100644 --- a/tools/tolua++/CCSpriteFrameCache.pkg +++ b/tools/tolua++/CCSpriteFrameCache.pkg @@ -16,6 +16,10 @@ class CCSpriteFrameCache : public CCObject CCSpriteFrame* spriteFrameByName(const char *pszName); - static CCSpriteFrameCache* sharedSpriteFrameCache(void); - static void purgeSharedSpriteFrameCache(void); + // XXX deprecated + static CCSpriteFrameCache* sharedSpriteFrameCache(); + static void purgeSharedSpriteFrameCache(); + + static CCSpriteFrameCache* getInstance(); + static void destroyInstance(); };