mirror of https://github.com/axmolengine/axmol.git
Add AsyncLoadSprite3D test case and update the related lua binding
This commit is contained in:
parent
cd42806367
commit
80c2e0c153
|
@ -116,6 +116,89 @@ tolua_lerror:
|
|||
return 0;
|
||||
}
|
||||
|
||||
int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
bool ok = true;
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
#endif
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertable(tolua_S,1,"cc.Sprite3D",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(tolua_S)-1;
|
||||
|
||||
do
|
||||
{
|
||||
if (argc == 3)
|
||||
{
|
||||
std::string modelPath;
|
||||
ok &= luaval_to_std_string(tolua_S, 2,&modelPath, "cc.Sprite3D:createAsync");
|
||||
if (!ok)
|
||||
break;
|
||||
std::string texturePath;
|
||||
ok &= luaval_to_std_string(tolua_S, 3,&texturePath, "cc.Sprite3D:createAsync");
|
||||
if (!ok)
|
||||
break;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!toluafix_isfunction(tolua_S,4,"LUA_FUNCTION",0,&tolua_err)) {
|
||||
goto tolua_lerror;
|
||||
}
|
||||
#endif
|
||||
LUA_FUNCTION handler = toluafix_ref_function(tolua_S,4,0);
|
||||
|
||||
cocos2d::Sprite3D::createAsync(modelPath, texturePath, [=](cocos2d::Sprite3D* sprite, void* callbackparam){
|
||||
int id = (sprite) ? (int)sprite->_ID : -1;
|
||||
int* luaID = (sprite) ? &sprite->_luaID : nullptr;
|
||||
toluafix_pushusertype_ccobject(tolua_S, id, luaID, (void*)sprite,"cc.Sprite3D");
|
||||
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 1);
|
||||
}, nullptr);
|
||||
|
||||
lua_settop(tolua_S, 1);
|
||||
return 1;
|
||||
}
|
||||
} while (0);
|
||||
ok = true;
|
||||
do
|
||||
{
|
||||
if (argc == 2)
|
||||
{
|
||||
std::string modelPath;
|
||||
ok &= luaval_to_std_string(tolua_S, 2,&modelPath, "cc.Sprite3D:createAsync");
|
||||
if (!ok)
|
||||
break;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!toluafix_isfunction(tolua_S, 3, "LUA_FUNCTION", 0, &tolua_err)) {
|
||||
goto tolua_lerror;
|
||||
}
|
||||
#endif
|
||||
LUA_FUNCTION handler = toluafix_ref_function(tolua_S, 3, 0);
|
||||
|
||||
cocos2d::Sprite3D::createAsync(modelPath, [=](cocos2d::Sprite3D* sprite, void* callbackparam){
|
||||
int id = (sprite) ? (int)sprite->_ID : -1;
|
||||
int* luaID = (sprite) ? &sprite->_luaID : nullptr;
|
||||
toluafix_pushusertype_ccobject(tolua_S, id, luaID, (void*)sprite,"cc.Sprite3D");
|
||||
LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 1);
|
||||
}, nullptr);
|
||||
|
||||
lua_settop(tolua_S, 1);
|
||||
return 1;
|
||||
}
|
||||
} while (0);
|
||||
ok = true;
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d", "cc.Sprite3D:createAsync",argc, 3);
|
||||
return 0;
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_3d_Sprite3D_createAsync'.",&tolua_err);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void extendSprite3D(lua_State* L)
|
||||
{
|
||||
lua_pushstring(L, "cc.Sprite3D");
|
||||
|
@ -124,6 +207,7 @@ static void extendSprite3D(lua_State* L)
|
|||
{
|
||||
tolua_function(L, "setBlendFunc", lua_cocos2dx_3d_Sprite3D_setBlendFunc01);
|
||||
tolua_function(L, "getAABB", lua_cocos2dx_3d_Sprite3D_getAABB);
|
||||
tolua_function(L, "createAsync", lua_cocos2dx_3d_Sprite3D_createAsync);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
|
|
@ -610,3 +610,12 @@ cc.LightFlag =
|
|||
LIGHT14 = math.pow(2,14),
|
||||
LIGHT15 = math.pow(2,15),
|
||||
}
|
||||
|
||||
cc.AsyncTaskPool.TaskType =
|
||||
{
|
||||
TASK_IO = 0,
|
||||
TASK_NETWORK = 1,
|
||||
TASK_OTHER = 2,
|
||||
TASK_MAX_TYPE = 3,
|
||||
}
|
||||
|
||||
|
|
|
@ -919,6 +919,113 @@ function Sprite3DMirrorTest.create()
|
|||
return layer
|
||||
end
|
||||
|
||||
|
||||
----------------------------------------
|
||||
----AsyncLoadSprite3DTest
|
||||
----------------------------------------
|
||||
local AsyncLoadSprite3DTest = class("AsyncLoadSprite3DTest", function ()
|
||||
local layer = cc.Layer:create()
|
||||
Helper.initWithLayer(layer)
|
||||
return layer
|
||||
end)
|
||||
|
||||
function AsyncLoadSprite3DTest:ctor()
|
||||
-- body
|
||||
self:init()
|
||||
end
|
||||
|
||||
function AsyncLoadSprite3DTest:init()
|
||||
Helper.titleLabel:setString(self:title())
|
||||
Helper.subtitleLabel:setString(self:subtitle())
|
||||
|
||||
self:registerScriptHandler(function (event)
|
||||
if event == "enter" then
|
||||
self:onEnter()
|
||||
elseif event == "exit" then
|
||||
self:onExit()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function AsyncLoadSprite3DTest:title()
|
||||
return "Testing Sprite3D:createAsync"
|
||||
end
|
||||
|
||||
function AsyncLoadSprite3DTest:subtitle()
|
||||
return ""
|
||||
end
|
||||
|
||||
function AsyncLoadSprite3DTest:onEnter()
|
||||
|
||||
local ttfConfig = {}
|
||||
ttfConfig.fontFilePath = "fonts/arial.ttf"
|
||||
ttfConfig.fontSize = 15
|
||||
|
||||
local paths = {"Sprite3DTest/boss.obj", "Sprite3DTest/girl.c3b", "Sprite3DTest/orc.c3b", "Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/axe.c3b"}
|
||||
|
||||
local label1 = cc.Label:createWithTTF(ttfConfig,"AsyncLoad Sprite3D")
|
||||
local item1 = cc.MenuItemLabel:create(label1)
|
||||
|
||||
function menuCallback_asyncLoadSprite(tag, sender)
|
||||
--Note that you must stop the tasks before leaving the scene.
|
||||
cc.AsyncTaskPool:getInstance():stopTasks(cc.AsyncTaskPool.TaskType.TASK_IO)
|
||||
|
||||
local node = self:getChildByTag(101)
|
||||
--remove all loaded sprite
|
||||
node:removeAllChildren()
|
||||
|
||||
--remove cache data
|
||||
cc.Sprite3DCache:getInstance():removeAllSprite3DData()
|
||||
|
||||
local function callback(sprite, index)
|
||||
local node = self:getChildByTag(101)
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local width = s.width / (#paths)
|
||||
local point = cc.p(width * (0.5 + index), s.height / 2.0)
|
||||
sprite:setPosition(point)
|
||||
node:addChild(sprite)
|
||||
end
|
||||
|
||||
cc.Sprite3D:createAsync(paths[1], function(sprite)
|
||||
callback(sprite, 0)
|
||||
end)
|
||||
|
||||
cc.Sprite3D:createAsync(paths[2], function(sprite)
|
||||
callback(sprite, 1)
|
||||
end)
|
||||
|
||||
cc.Sprite3D:createAsync(paths[3], function(sprite)
|
||||
callback(sprite, 2)
|
||||
end)
|
||||
|
||||
cc.Sprite3D:createAsync(paths[4], function(sprite)
|
||||
callback(sprite, 3)
|
||||
end)
|
||||
|
||||
cc.Sprite3D:createAsync(paths[5], function(sprite)
|
||||
callback(sprite, 4)
|
||||
end)
|
||||
end
|
||||
item1:registerScriptTapHandler(menuCallback_asyncLoadSprite)
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
item1:setPosition( s.width * 0.5, s.height * 0.8)
|
||||
|
||||
local menu = cc.Menu:create(item1)
|
||||
menu:setPosition(cc.p(0,0))
|
||||
self:addChild(menu, 10)
|
||||
|
||||
local node = cc.Node:create()
|
||||
node:setTag(101)
|
||||
self:addChild(node)
|
||||
|
||||
menuCallback_asyncLoadSprite()
|
||||
end
|
||||
|
||||
function AsyncLoadSprite3DTest:onExit()
|
||||
|
||||
end
|
||||
|
||||
function Sprite3DTest()
|
||||
local scene = cc.Scene:create()
|
||||
|
||||
|
@ -932,6 +1039,7 @@ function Sprite3DTest()
|
|||
Sprite3DReskinTest.create,
|
||||
Sprite3DWithOBBPerfromanceTest.create,
|
||||
Sprite3DMirrorTest.create,
|
||||
AsyncLoadSprite3DTest.create
|
||||
}
|
||||
|
||||
scene:addChild(Sprite3DBasicTest.create())
|
||||
|
|
|
@ -22,11 +22,11 @@ cxxgenerator_headers =
|
|||
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
|
||||
|
||||
# what headers to parse
|
||||
headers = %(cocosdir)s/cocos/cocos2d.h %(cocosdir)s/cocos/2d/CCProtectedNode.h
|
||||
headers = %(cocosdir)s/cocos/cocos2d.h %(cocosdir)s/cocos/2d/CCProtectedNode.h %(cocosdir)s/cocos/base/CCAsyncTaskPool.h
|
||||
|
||||
# what classes to produce code for. You can use regular expressions here. When testing the regular
|
||||
# expression, it will be enclosed in "^$", like this: "^Menu*$".
|
||||
classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* .*TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Ref$ UserDefault GLViewImpl GLView Image Event(?!.*(Physics).*).* Component ProtectedNode Console GLProgramCache GLProgramState Device ClippingRectangleNode .*Light$
|
||||
classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* Move.* Rotate.* Blink.* Tint.* Sequence Repeat.* Fade.* Ease.* Scale.* Transition.* Spawn Animat.* Flip.* Delay.* Skew.* Jump.* Place.* Show.* Progress.* PointArray ToggleVisibility.* RemoveSelf Hide Particle.* Label.* Atlas.* TextureCache.* Texture2D Cardinal.* CatmullRom.* ParallaxNode TileMap.* .*TMX.* CallFunc RenderTexture GridAction Grid3DAction GridBase$ .+Grid Shaky3D Waves3D FlipX3D FlipY3D Speed ActionManager Set Scheduler Timer Orbit.* Follow.* Bezier.* CardinalSpline.* Camera.* DrawNode .*3D$ Liquid$ Waves$ ShuffleTiles$ TurnOffTiles$ Split.* Twirl$ FileUtils$ GLProgram ShaderCache Application ClippingNode MotionStreak ^Ref$ UserDefault GLViewImpl GLView Image Event(?!.*(Physics).*).* Component ProtectedNode Console GLProgramCache GLProgramState Device ClippingRectangleNode .*Light$ AsyncTaskPool
|
||||
|
||||
# what should we skip? in the format ClassName::[function function]
|
||||
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
|
||||
|
|
|
@ -26,7 +26,7 @@ headers = %(cocosdir)s/cocos/cocos2d.h
|
|||
|
||||
# what classes to produce code for. You can use regular expressions here. When testing the regular
|
||||
# expression, it will be enclosed in "^$", like this: "^Menu*$".
|
||||
classes = Animate3D Sprite3D Animation3D Skeleton3D ^Mesh$ AttachNode BillBoard
|
||||
classes = Animate3D Sprite3D Animation3D Skeleton3D ^Mesh$ AttachNode BillBoard Sprite3DCache
|
||||
|
||||
# what should we skip? in the format ClassName::[function function]
|
||||
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
|
||||
|
@ -36,10 +36,11 @@ classes = Animate3D Sprite3D Animation3D Skeleton3D ^Mesh$ AttachNode BillBoard
|
|||
# functions from all classes.
|
||||
|
||||
skip = Mesh::[create getAABB getVertexBuffer hasVertexAttrib getSkin getMeshIndexData getGLProgramState getPrimitiveType getIndexCount getIndexFormat getIndexBuffer],
|
||||
Sprite3D::[getSkin getAABB getMeshArrayByName],
|
||||
Sprite3D::[getSkin getAABB getMeshArrayByName createAsync],
|
||||
Skeleton3D::[create],
|
||||
Animation3D::[getBoneCurveByName],
|
||||
BillBoard::[draw]
|
||||
BillBoard::[draw],
|
||||
Sprite3DCache::[addSprite3DData getSpriteData]
|
||||
|
||||
|
||||
rename_functions =
|
||||
|
|
Loading…
Reference in New Issue