From 881757a79269af4391cda33eceacd81a2ee322ea Mon Sep 17 00:00:00 2001 From: Siim Kallas Date: Sat, 1 Feb 2014 22:10:00 +0200 Subject: [PATCH 01/21] Fixed crashing when calling CCDirector's end(). --- cocos/2d/platform/desktop/CCGLView.cpp | 4 ++++ cocos/2d/platform/win32/CCApplication.cpp | 14 +++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cocos/2d/platform/desktop/CCGLView.cpp b/cocos/2d/platform/desktop/CCGLView.cpp index 5c3370a828..a969e32d29 100644 --- a/cocos/2d/platform/desktop/CCGLView.cpp +++ b/cocos/2d/platform/desktop/CCGLView.cpp @@ -472,7 +472,11 @@ bool GLView::isOpenGLReady() void GLView::end() { if(_mainWindow) + { glfwSetWindowShouldClose(_mainWindow,1); + _mainWindow = nullptr; + } + } void GLView::swapBuffers() diff --git a/cocos/2d/platform/win32/CCApplication.cpp b/cocos/2d/platform/win32/CCApplication.cpp index 767917c0de..a0b0b4a25b 100644 --- a/cocos/2d/platform/win32/CCApplication.cpp +++ b/cocos/2d/platform/win32/CCApplication.cpp @@ -94,13 +94,13 @@ int Application::run() } } - /* Only work on Desktop - * Director::mainLoop is really one frame logic - * when we want to close the window, we should call Director::end(); - * then call Director::mainLoop to do release of internal resources - */ - director->end(); - director->mainLoop(); + // Director should still do a cleanup if the window was closed manually. + if (glview->isOpenGLReady()) + { + director->end(); + director->mainLoop(); + director = nullptr; + } return true; } From 35326655206238819d447b6f8aeabb4f1ac7ba86 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Fri, 21 Feb 2014 09:45:33 +0800 Subject: [PATCH 02/21] issue #3956:Change tolua_fix.c to tolua_fix.cpp and modify the toluafix_pushusertype_ccobject function to get real type of object --- .../project.pbxproj.REMOVED.git-id | 2 +- cocos/scripting/lua/bindings/CCLuaStack.cpp | 3 +- .../lua/bindings/LuaBasicConversions.cpp | 20 +- .../lua/bindings/LuaBasicConversions.h | 47 ++- .../lua/bindings/LuaOpengl.cpp.REMOVED.git-id | 2 +- .../lua/bindings/LuaScriptHandlerMgr.cpp | 11 +- .../scripting/lua/bindings/Lua_web_socket.cpp | 12 +- .../lua_cocos2dx_coco_studio_manual.cpp | 10 +- .../lua/bindings/lua_cocos2dx_deprecated.cpp | 30 +- .../lua_cocos2dx_extension_manual.cpp | 10 +- .../lua/bindings/lua_cocos2dx_gui_manual.cpp | 10 +- .../lua_cocos2dx_manual.cpp.REMOVED.git-id | 2 +- .../bindings/lua_cocos2dx_physics_manual.cpp | 329 +++++------------- .../bindings/lua_cocos2dx_spine_manual.cpp | 10 +- .../lua/bindings/lua_xml_http_request.cpp | 7 +- .../bindings/{tolua_fix.c => tolua_fix.cpp} | 13 +- cocos/scripting/lua/bindings/tolua_fix.h | 9 - .../Classes/lua_assetsmanager_test_sample.cpp | 10 +- .../CocoStudioSceneTest.lua | 6 +- 19 files changed, 161 insertions(+), 382 deletions(-) rename cocos/scripting/lua/bindings/{tolua_fix.c => tolua_fix.cpp} (95%) diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id index 90a113389a..3f6e0e1d57 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj.REMOVED.git-id @@ -1 +1 @@ -8f6bd203bc07c8cff824450938e8931abc027341 \ No newline at end of file +07c75b564f4bc8d9eb83e574a4669ce058e422d4 \ No newline at end of file diff --git a/cocos/scripting/lua/bindings/CCLuaStack.cpp b/cocos/scripting/lua/bindings/CCLuaStack.cpp index b836f49853..23afcf4dd3 100644 --- a/cocos/scripting/lua/bindings/CCLuaStack.cpp +++ b/cocos/scripting/lua/bindings/CCLuaStack.cpp @@ -24,13 +24,12 @@ ****************************************************************************/ #include "CCLuaStack.h" - +#include "tolua_fix.h" extern "C" { #include "lua.h" #include "tolua++.h" #include "lualib.h" #include "lauxlib.h" -#include "tolua_fix.h" #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) #include "lua_extensions.h" #endif diff --git a/cocos/scripting/lua/bindings/LuaBasicConversions.cpp b/cocos/scripting/lua/bindings/LuaBasicConversions.cpp index a2d97434c8..955ea40109 100644 --- a/cocos/scripting/lua/bindings/LuaBasicConversions.cpp +++ b/cocos/scripting/lua/bindings/LuaBasicConversions.cpp @@ -23,14 +23,7 @@ ****************************************************************************/ #include "LuaBasicConversions.h" - -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua_fix.h" -#ifdef __cplusplus -} -#endif +#include "tolua_fix.h" std::unordered_map g_luaType; std::unordered_map g_typeCast; @@ -1596,18 +1589,9 @@ void physics_raycastinfo_to_luaval(lua_State* L, const PhysicsRayCastInfo& info) lua_pushnil(L); }else { - std::string hashName = typeid(*shape).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "PhysicsShape"; - } - int ID = (int)(shape->_ID); int* luaID = &(shape->_luaID); - toluafix_pushusertype_ccobject(L, ID, luaID, (void*)shape,className.c_str()); + toluafix_pushusertype_ccobject(L, ID, luaID, (void*)shape,"cc.PhysicsShape"); } lua_rawset(L, -3); /* table[key] = value, L: table */ diff --git a/cocos/scripting/lua/bindings/LuaBasicConversions.h b/cocos/scripting/lua/bindings/LuaBasicConversions.h index ac57af4556..92b99b7816 100644 --- a/cocos/scripting/lua/bindings/LuaBasicConversions.h +++ b/cocos/scripting/lua/bindings/LuaBasicConversions.h @@ -27,11 +27,11 @@ extern "C" { #include "lua.h" #include "tolua++.h" -#include "tolua_fix.h" } - +#include "tolua_fix.h" #include "cocos2d.h" + using namespace cocos2d; extern std::unordered_map g_luaType; @@ -294,36 +294,44 @@ void ccvaluemap_to_luaval(lua_State* L,const cocos2d::ValueMap& inValue); void ccvaluemapintkey_to_luaval(lua_State* L, const cocos2d::ValueMapIntKey& inValue); void ccvaluevector_to_luaval(lua_State* L, const cocos2d::ValueVector& inValue); +/** + Because all override functions wouldn't be bound,so we must use `typeid` to get the real class name + */ +template +const char* getLuaTypeName(T* ret,const char* type) +{ + if (nullptr != ret) + { + std::string hashName = typeid(*ret).name(); + auto iter = g_luaType.find(hashName); + if(g_luaType.end() != iter) + { + return iter->second.c_str(); + } + else + { + return type; + } + } + + return nullptr; +} + template void object_to_luaval(lua_State* L,const char* type, T* ret) { if(nullptr != ret) { - /** - Because all override functions wouldn't be bound,so we must use `typeid` to get the real class name - */ - std::string hashName = typeid(*ret).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(g_luaType.end() != iter) - { - className = iter->second.c_str(); - } - else - { - className = type; - } - cocos2d::Object* dynObject = dynamic_cast(ret); if (nullptr != dynObject) { int ID = (int)(dynObject->_ID) ; int* luaID = &(dynObject->_luaID); - toluafix_pushusertype_ccobject(L,ID, luaID, (void*)ret,className.c_str()); + toluafix_pushusertype_ccobject(L,ID, luaID, (void*)ret,type); } else { - tolua_pushusertype(L,(void*)ret,className.c_str()); + tolua_pushusertype(L,(void*)ret,getLuaTypeName(ret, type)); } } else @@ -332,4 +340,5 @@ void object_to_luaval(lua_State* L,const char* type, T* ret) } } + #endif //__COCOS2DX_SCRIPTING_LUA_COCOS2DXSUPPORT_LUABAISCCONVERSIONS_H__ diff --git a/cocos/scripting/lua/bindings/LuaOpengl.cpp.REMOVED.git-id b/cocos/scripting/lua/bindings/LuaOpengl.cpp.REMOVED.git-id index 935d4d7a44..89f3b3fca3 100644 --- a/cocos/scripting/lua/bindings/LuaOpengl.cpp.REMOVED.git-id +++ b/cocos/scripting/lua/bindings/LuaOpengl.cpp.REMOVED.git-id @@ -1 +1 @@ -79a0d9662a9a7c45ff5d17c60a855b7144b91d1f \ No newline at end of file +ac3ec208ccad60f34c9f194d1815f0129fe711dc \ No newline at end of file diff --git a/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp b/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp index c781d5b1ec..0c586b0afd 100644 --- a/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp +++ b/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp @@ -21,17 +21,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua_fix.h" -#ifdef __cplusplus -} -#endif - +#include "LuaScriptHandlerMgr.h" #include #include -#include "LuaScriptHandlerMgr.h" +#include "tolua_fix.h" #include "cocos2d.h" #include "extensions/cocos-ext.h" #include "CCLuaStack.h" diff --git a/cocos/scripting/lua/bindings/Lua_web_socket.cpp b/cocos/scripting/lua/bindings/Lua_web_socket.cpp index f508e720f6..dba46d8a65 100644 --- a/cocos/scripting/lua/bindings/Lua_web_socket.cpp +++ b/cocos/scripting/lua/bindings/Lua_web_socket.cpp @@ -23,18 +23,10 @@ ****************************************************************************/ #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) - -#ifdef __cplusplus -extern "C" { -#endif - #include "tolua_fix.h" -#ifdef __cplusplus -} -#endif - +#include "Lua_web_socket.h" #include #include -#include "Lua_web_socket.h" +#include "tolua_fix.h" #include "cocos2d.h" #include "CCLuaStack.h" #include "CCLuaValue.h" diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_coco_studio_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_coco_studio_manual.cpp index 581279907d..2c82ec9b33 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_coco_studio_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_coco_studio_manual.cpp @@ -22,16 +22,8 @@ THE SOFTWARE. ****************************************************************************/ #include "lua_cocos2dx_coco_studio_manual.hpp" - -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua_fix.h" -#ifdef __cplusplus -} -#endif - #include "cocos2d.h" +#include "tolua_fix.h" #include "LuaBasicConversions.h" #include "LuaScriptHandlerMgr.h" #include "CCLuaValue.h" diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp index e907189be2..2216959add 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp @@ -22,16 +22,8 @@ THE SOFTWARE. ****************************************************************************/ #include "lua_cocos2dx_deprecated.h" - -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua_fix.h" -#ifdef __cplusplus -} -#endif - #include "cocos2d.h" +#include "tolua_fix.h" #include "LuaBasicConversions.h" #include "LuaScriptHandlerMgr.h" #include "CCLuaValue.h" @@ -759,7 +751,7 @@ static int tolua_Cocos2d_CCArray_objectAtIndex00(lua_State* tolua_S) Object* tolua_ret = (Object*) self->getObjectAtIndex(index); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Object"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Object"); } } return 1; @@ -793,7 +785,7 @@ static int tolua_Cocos2d_CCArray_lastObject00(lua_State* tolua_S) Object* tolua_ret = (Object*) self->getLastObject(); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Object"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Object"); } } return 1; @@ -827,7 +819,7 @@ static int tolua_Cocos2d_CCArray_randomObject00(lua_State* tolua_S) Object* tolua_ret = (Object*) self->getRandomObject(); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Object"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Object"); } } return 1; @@ -1968,7 +1960,7 @@ static int tolua_cocos2d_Animation_createWithSpriteFrames_deprecated00(lua_State cocos2d::Animation* tolua_ret = (cocos2d::Animation*) cocos2d::Animation::createWithSpriteFrames(vec,delay); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Animation"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Animation"); } return 1; @@ -1993,7 +1985,7 @@ static int tolua_cocos2d_Animation_createWithSpriteFrames_deprecated01(lua_State cocos2d::Animation* tolua_ret = (cocos2d::Animation*) cocos2d::Animation::createWithSpriteFrames(vec); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Animation"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Animation"); } return 1; @@ -2037,7 +2029,7 @@ static int tolua_cocos2d_Sequence_createWithTwoActions(lua_State* tolua_S) Sequence* tolua_ret = (Sequence*) Sequence::createWithTwoActions(pActionOne,pActionTwo); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Sequence"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Sequence"); } } return 1; @@ -2066,7 +2058,7 @@ static int tolua_Cocos2d_Sequence_create_deprecated00(lua_State* tolua_S) Sequence* tolua_ret = (Sequence*) Sequence::create(vec); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Sequence"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Sequence"); } return 1; tolua_lerror: @@ -2174,7 +2166,7 @@ static int tolua_cocos2d_Spawn_createWithTwoActions_deprcated00(lua_State* tolua Spawn* tolua_ret = (Spawn*) Spawn::createWithTwoActions(pAction1,pAction2); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Spawn"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Spawn"); } } return 1; @@ -2217,7 +2209,7 @@ static int tolua_cocos2d_Menu_createWithArray00(lua_State* tolua_S) Menu* tolua_ret = (Menu*) Menu::createWithArray(vec); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Menu"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Menu"); } return 1; #ifndef TOLUA_RELEASE @@ -2321,7 +2313,7 @@ static int tolua_cocos2d_LayerMultiplex_createWithArray00(lua_State* tolua_S) LayerMultiplex* tolua_ret = (LayerMultiplex*) LayerMultiplex::createWithArray(vec); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"LayerMultiplex"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.LayerMultiplex"); } return 1; diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp index 739abb548c..5382606987 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp @@ -22,16 +22,8 @@ THE SOFTWARE. ****************************************************************************/ #include "lua_cocos2dx_extension_manual.h" - -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua_fix.h" -#ifdef __cplusplus -} -#endif - #include "cocos2d.h" +#include "tolua_fix.h" #include "LuaBasicConversions.h" #include "CCLuaValue.h" #include "cocos-ext.h" diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_gui_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_gui_manual.cpp index b51979ff53..51a0b85083 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_gui_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_gui_manual.cpp @@ -22,16 +22,8 @@ THE SOFTWARE. ****************************************************************************/ #include "lua_cocos2dx_gui_manual.hpp" - -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua_fix.h" -#ifdef __cplusplus -} -#endif - #include "cocos2d.h" +#include "tolua_fix.h" #include "LuaBasicConversions.h" #include "LuaScriptHandlerMgr.h" #include "CCLuaValue.h" diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id index 01f7b718a1..5f4f695e04 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_manual.cpp.REMOVED.git-id @@ -1 +1 @@ -29bde887dbd41a72f33704fb57cbab230d1a1688 \ No newline at end of file +6b4a49b88aacb735030875a6da6af87086f85628 \ No newline at end of file diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_physics_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_physics_manual.cpp index 8e0d8e323f..0a78923a05 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_physics_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_physics_manual.cpp @@ -1,15 +1,7 @@ #include "lua_cocos2dx_manual.hpp" #if CC_USE_PHYSICS - -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua_fix.h" -#ifdef __cplusplus -} -#endif - +#include "tolua_fix.h" #include "LuaBasicConversions.h" #include "CCLuaValue.h" #include "CCLuaEngine.h" @@ -63,17 +55,8 @@ int lua_cocos2dx_physics_PhysicsBody_getJoints(lua_State* tolua_S) if (nullptr == *iter) continue; - std::string hashName = typeid(*iter).name(); - auto name = g_luaType.find(hashName); - std::string className = ""; - if(name != g_luaType.end()){ - className = name->second.c_str(); - } else { - className = "cc.PhysicsJoint"; - } - lua_pushnumber(tolua_S, (lua_Number)indexTable); - tolua_pushusertype(tolua_S,(void*)(*iter), className.c_str()); + tolua_pushusertype(tolua_S,(void*)(*iter), getLuaTypeName(*iter, "cc.PhysicsJoint")); lua_rawset(tolua_S, -3); ++indexTable; } @@ -184,17 +167,8 @@ int lua_cocos2dx_physics_PhysicsWorld_rayCast(lua_State* tolua_S) LUA_FUNCTION handler = toluafix_ref_function(tolua_S, 2, 0); do { arg0 = [handler, tolua_S](cocos2d::PhysicsWorld &world, const cocos2d::PhysicsRayCastInfo &info, void * data) -> bool - { - std::string hashName = typeid(&world).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsWorld"; - } - - tolua_pushusertype(tolua_S, (void*)(&world), className.c_str()); + { + tolua_pushusertype(tolua_S, (void*)(&world), getLuaTypeName(&world, "cc.PhysicsWorld")); physics_raycastinfo_to_luaval(tolua_S, info); return LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); }; @@ -251,26 +225,8 @@ int lua_cocos2dx_physics_PhysicsWorld_queryRect(lua_State* tolua_S) do { arg0 = [handler, tolua_S](cocos2d::PhysicsWorld &world, cocos2d::PhysicsShape &shape, void * data) -> bool { - std::string hashName = typeid(&world).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsWorld"; - } - - tolua_pushusertype(tolua_S, (void*)(&world), className.c_str()); - - hashName = typeid(&shape).name(); - iter = g_luaType.find(hashName); - className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsShape"; - } - toluafix_pushusertype_ccobject(tolua_S, shape._ID, &shape._luaID, (void*)(&shape), className.c_str()); + tolua_pushusertype(tolua_S, (void*)(&world), getLuaTypeName(&world, "cc.PhysicsWorld")); + toluafix_pushusertype_ccobject(tolua_S, shape._ID, &shape._luaID, (void*)(&shape), "cc.PhysicsShape"); return LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); }; } while(0); @@ -326,27 +282,9 @@ int lua_cocos2dx_physics_PhysicsWorld_queryPoint(lua_State* tolua_S) LUA_FUNCTION handler = toluafix_ref_function(tolua_S, 2, 0); do { arg0 = [handler, tolua_S](cocos2d::PhysicsWorld &world, cocos2d::PhysicsShape &shape, void * data) -> bool - { - std::string hashName = typeid(&world).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsWorld"; - } - - tolua_pushusertype(tolua_S, (void*)(&world), className.c_str()); - - hashName = typeid(&shape).name(); - iter = g_luaType.find(hashName); - className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsShape"; - } - toluafix_pushusertype_ccobject(tolua_S, shape._ID, &shape._luaID, (void*)(&shape), className.c_str()); + { + tolua_pushusertype(tolua_S, (void*)(&world), getLuaTypeName(&world, "cc.PhysicsWorld")); + toluafix_pushusertype_ccobject(tolua_S, shape._ID, &shape._luaID, (void*)(&shape), "cc.PhysicsShape"); return LuaEngine::getInstance()->getLuaStack()->executeFunctionByHandler(handler, 2); }; assert(false); @@ -402,25 +340,16 @@ int lua_cocos2dx_physics_PhysicsBody_createPolygon(lua_State* tolua_S) cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createPolygon(arg0, arg1); CC_SAFE_FREE(arg0); do { - if (NULL != ret){ - std::string hashName = typeid(*ret).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsBody"; - } - cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); - if (NULL != dynObject) { - int ID = ret ? (int)(dynObject->_ID) : -1; - int* luaID = ret ? &(dynObject->_luaID) : NULL; - toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret,className.c_str()); - } else { - tolua_pushusertype(tolua_S,(void*)ret,className.c_str()); - }} else { - lua_pushnil(tolua_S); - } + if (nullptr != ret) + { + int ID = ret->_ID; + int* luaID = &ret->_luaID; + toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret, "cc.PhysicsBody"); + } + else + { + lua_pushnil(tolua_S); + } } while (0); return 1; } @@ -443,25 +372,16 @@ int lua_cocos2dx_physics_PhysicsBody_createPolygon(lua_State* tolua_S) cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createPolygon(arg0, arg1, arg2); CC_SAFE_FREE(arg0); do { - if (NULL != ret){ - std::string hashName = typeid(*ret).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsBody"; - } - cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); - if (NULL != dynObject) { - int ID = ret ? (int)(dynObject->_ID) : -1; - int* luaID = ret ? &(dynObject->_luaID) : NULL; - toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret,className.c_str()); - } else { - tolua_pushusertype(tolua_S,(void*)ret,className.c_str()); - }} else { - lua_pushnil(tolua_S); - } + if (nullptr != ret) + { + int ID = ret->_ID; + int* luaID = &ret->_luaID; + toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret, "cc.PhysicsBody"); + } + else + { + lua_pushnil(tolua_S); + } } while (0); return 1; } @@ -486,25 +406,16 @@ int lua_cocos2dx_physics_PhysicsBody_createPolygon(lua_State* tolua_S) cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createPolygon(arg0, arg1, arg2, arg3); CC_SAFE_FREE(arg0); do { - if (NULL != ret){ - std::string hashName = typeid(*ret).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsBody"; - } - cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); - if (NULL != dynObject) { - int ID = ret ? (int)(dynObject->_ID) : -1; - int* luaID = ret ? &(dynObject->_luaID) : NULL; - toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret,className.c_str()); - } else { - tolua_pushusertype(tolua_S,(void*)ret,className.c_str()); - }} else { - lua_pushnil(tolua_S); - } + if (nullptr != ret) + { + int ID = ret->_ID; + int* luaID = &ret->_luaID; + toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret, "cc.PhysicsBody"); + } + else + { + lua_pushnil(tolua_S); + } } while (0); return 1; } @@ -549,23 +460,14 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgePolygon(lua_State* tolua_S) cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgePolygon(arg0, arg1); CC_SAFE_FREE(arg0); do { - if (NULL != ret){ - std::string hashName = typeid(*ret).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsBody"; - } - cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); - if (NULL != dynObject) { - int ID = ret ? (int)(dynObject->_ID) : -1; - int* luaID = ret ? &(dynObject->_luaID) : NULL; - toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret,className.c_str()); - } else { - tolua_pushusertype(tolua_S,(void*)ret,className.c_str()); - }} else { + if (nullptr != ret) + { + int ID = ret->_ID; + int* luaID = &ret->_luaID; + toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret, "cc.PhysicsBody"); + } + else + { lua_pushnil(tolua_S); } } while (0); @@ -590,23 +492,14 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgePolygon(lua_State* tolua_S) cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgePolygon(arg0, arg1, arg2); CC_SAFE_FREE(arg0); do { - if (NULL != ret){ - std::string hashName = typeid(*ret).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsBody"; - } - cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); - if (NULL != dynObject) { - int ID = ret ? (int)(dynObject->_ID) : -1; - int* luaID = ret ? &(dynObject->_luaID) : NULL; - toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret,className.c_str()); - } else { - tolua_pushusertype(tolua_S,(void*)ret,className.c_str()); - }} else { + if (nullptr != ret) + { + int ID = ret->_ID; + int* luaID = &ret->_luaID; + toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret, "cc.PhysicsBody"); + } + else + { lua_pushnil(tolua_S); } } while (0); @@ -633,23 +526,14 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgePolygon(lua_State* tolua_S) cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgePolygon(arg0, arg1, arg2, arg3); CC_SAFE_FREE(arg0); do { - if (NULL != ret){ - std::string hashName = typeid(*ret).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsBody"; - } - cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); - if (NULL != dynObject) { - int ID = ret ? (int)(dynObject->_ID) : -1; - int* luaID = ret ? &(dynObject->_luaID) : NULL; - toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret,className.c_str()); - } else { - tolua_pushusertype(tolua_S,(void*)ret,className.c_str()); - }} else { + if (nullptr != ret) + { + int ID = ret->_ID; + int* luaID = &ret->_luaID; + toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret, "cc.PhysicsBody"); + } + else + { lua_pushnil(tolua_S); } } while (0); @@ -696,25 +580,16 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgeChain(lua_State* tolua_S) cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgeChain(arg0, arg1); CC_SAFE_FREE(arg0); do { - if (NULL != ret){ - std::string hashName = typeid(*ret).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsBody"; - } - cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); - if (NULL != dynObject) { - int ID = ret ? (int)(dynObject->_ID) : -1; - int* luaID = ret ? &(dynObject->_luaID) : NULL; - toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret,className.c_str()); - } else { - tolua_pushusertype(tolua_S,(void*)ret,className.c_str()); - }} else { - lua_pushnil(tolua_S); - } + if (nullptr != ret) + { + int ID = ret->_ID; + int* luaID = &ret->_luaID; + toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret, "cc.PhysicsBody"); + } + else + { + lua_pushnil(tolua_S); + } } while (0); return 1; } @@ -737,25 +612,16 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgeChain(lua_State* tolua_S) cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgeChain(arg0, arg1, arg2); CC_SAFE_FREE(arg0); do { - if (NULL != ret){ - std::string hashName = typeid(*ret).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsBody"; - } - cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); - if (NULL != dynObject) { - int ID = ret ? (int)(dynObject->_ID) : -1; - int* luaID = ret ? &(dynObject->_luaID) : NULL; - toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret,className.c_str()); - } else { - tolua_pushusertype(tolua_S,(void*)ret,className.c_str()); - }} else { - lua_pushnil(tolua_S); - } + if (nullptr != ret) + { + int ID = ret->_ID; + int* luaID = &ret->_luaID; + toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret, "cc.PhysicsBody"); + } + else + { + lua_pushnil(tolua_S); + } } while (0); return 1; } @@ -780,25 +646,16 @@ int lua_cocos2dx_physics_PhysicsBody_createEdgeChain(lua_State* tolua_S) cocos2d::PhysicsBody* ret = cocos2d::PhysicsBody::createEdgeChain(arg0, arg1, arg2, arg3); CC_SAFE_FREE(arg0); do { - if (NULL != ret){ - std::string hashName = typeid(*ret).name(); - auto iter = g_luaType.find(hashName); - std::string className = ""; - if(iter != g_luaType.end()){ - className = iter->second.c_str(); - } else { - className = "cc.PhysicsBody"; - } - cocos2d::Object *dynObject = dynamic_cast((cocos2d::PhysicsBody*)ret); - if (NULL != dynObject) { - int ID = ret ? (int)(dynObject->_ID) : -1; - int* luaID = ret ? &(dynObject->_luaID) : NULL; - toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret,className.c_str()); - } else { - tolua_pushusertype(tolua_S,(void*)ret,className.c_str()); - }} else { - lua_pushnil(tolua_S); - } + if (nullptr != ret) + { + int ID = ret->_ID; + int* luaID = &ret->_luaID; + toluafix_pushusertype_ccobject(tolua_S,ID, luaID, (void*)ret, "cc.PhysicsBody"); + } + else + { + lua_pushnil(tolua_S); + } } while (0); return 1; } diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_spine_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_spine_manual.cpp index 78c6e2b340..15ffe45d00 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_spine_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_spine_manual.cpp @@ -22,16 +22,8 @@ THE SOFTWARE. ****************************************************************************/ #include "lua_cocos2dx_spine_manual.hpp" - -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua_fix.h" -#ifdef __cplusplus -} -#endif - #include "cocos2d.h" +#include "tolua_fix.h" #include "LuaBasicConversions.h" #include "LuaScriptHandlerMgr.h" #include "CCLuaValue.h" diff --git a/cocos/scripting/lua/bindings/lua_xml_http_request.cpp b/cocos/scripting/lua/bindings/lua_xml_http_request.cpp index 9470afffb1..40456c3200 100644 --- a/cocos/scripting/lua/bindings/lua_xml_http_request.cpp +++ b/cocos/scripting/lua/bindings/lua_xml_http_request.cpp @@ -22,13 +22,8 @@ THE SOFTWARE. ****************************************************************************/ #include "lua_xml_http_request.h" - -extern "C" -{ -#include "tolua_fix.h" -} - #include +#include "tolua_fix.h" #include "CCLuaStack.h" #include "CCLuaValue.h" #include "CCLuaEngine.h" diff --git a/cocos/scripting/lua/bindings/tolua_fix.c b/cocos/scripting/lua/bindings/tolua_fix.cpp similarity index 95% rename from cocos/scripting/lua/bindings/tolua_fix.c rename to cocos/scripting/lua/bindings/tolua_fix.cpp index 2aabde0980..ced5595efd 100644 --- a/cocos/scripting/lua/bindings/tolua_fix.c +++ b/cocos/scripting/lua/bindings/tolua_fix.cpp @@ -1,7 +1,11 @@ #include "tolua_fix.h" +#include "CCObject.h" +#include "LuaBasicConversions.h" #include +using namespace cocos2d; + static int s_function_ref_id = 0; TOLUA_API void toluafix_open(lua_State* L) @@ -30,6 +34,9 @@ TOLUA_API int toluafix_pushusertype_ccobject(lua_State* L, lua_pushnil(L); return -1; } + + Object* vPtr = static_cast(ptr); + const char* vType = getLuaTypeName(vPtr, type); if (*p_refid == 0) { @@ -38,7 +45,7 @@ TOLUA_API int toluafix_pushusertype_ccobject(lua_State* L, lua_pushstring(L, TOLUA_REFID_PTR_MAPPING); lua_rawget(L, LUA_REGISTRYINDEX); /* stack: refid_ptr */ lua_pushinteger(L, refid); /* stack: refid_ptr refid */ - lua_pushlightuserdata(L, ptr); /* stack: refid_ptr refid ptr */ + lua_pushlightuserdata(L, vPtr); /* stack: refid_ptr refid ptr */ lua_rawset(L, -3); /* refid_ptr[refid] = ptr, stack: refid_ptr */ lua_pop(L, 1); /* stack: - */ @@ -46,14 +53,14 @@ TOLUA_API int toluafix_pushusertype_ccobject(lua_State* L, lua_pushstring(L, TOLUA_REFID_TYPE_MAPPING); lua_rawget(L, LUA_REGISTRYINDEX); /* stack: refid_type */ lua_pushinteger(L, refid); /* stack: refid_type refid */ - lua_pushstring(L, type); /* stack: refid_type refid type */ + lua_pushstring(L, vType); /* stack: refid_type refid type */ lua_rawset(L, -3); /* refid_type[refid] = type, stack: refid_type */ lua_pop(L, 1); /* stack: - */ //printf("[LUA] push CCObject OK - refid: %d, ptr: %x, type: %s\n", *p_refid, (int)ptr, type); } - tolua_pushusertype_and_addtoroot(L, ptr, type); + tolua_pushusertype_and_addtoroot(L, vPtr, vType); return 0; } diff --git a/cocos/scripting/lua/bindings/tolua_fix.h b/cocos/scripting/lua/bindings/tolua_fix.h index fde275ca48..a8a989f08e 100644 --- a/cocos/scripting/lua/bindings/tolua_fix.h +++ b/cocos/scripting/lua/bindings/tolua_fix.h @@ -3,11 +3,6 @@ #define __TOLUA_FIX_H_ #include "tolua++.h" - -#ifdef __cplusplus -extern "C" -{ -#endif #define TOLUA_REFID_PTR_MAPPING "toluafix_refid_ptr_mapping" #define TOLUA_REFID_TYPE_MAPPING "toluafix_refid_type_mapping" @@ -27,9 +22,5 @@ TOLUA_API int toluafix_isfunction(lua_State* L, int lo, const char* type, int de TOLUA_API int toluafix_totable(lua_State* L, int lo, int def); TOLUA_API int toluafix_istable(lua_State* L, int lo, const char* type, int def, tolua_Error* err); TOLUA_API void toluafix_stack_dump(lua_State* L, const char* label); - -#ifdef __cplusplus -} // extern "C" -#endif #endif // __TOLUA_FIX_H_ diff --git a/tests/test-lua/Classes/lua_assetsmanager_test_sample.cpp b/tests/test-lua/Classes/lua_assetsmanager_test_sample.cpp index a254c2cbbd..7ec451e94a 100644 --- a/tests/test-lua/Classes/lua_assetsmanager_test_sample.cpp +++ b/tests/test-lua/Classes/lua_assetsmanager_test_sample.cpp @@ -1,13 +1,5 @@ #include "lua_assetsmanager_test_sample.h" - -#ifdef __cplusplus -extern "C" { -#endif -#include "tolua_fix.h" -#ifdef __cplusplus -} -#endif - +#include "tolua_fix.h" #include "cocos2d.h" #include "cocos-ext.h" diff --git a/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua b/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua index 45635696b6..4be70e45fd 100644 --- a/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua +++ b/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua @@ -298,9 +298,9 @@ end function UIComponentTest:createGameScene() local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/UIComponentTest/UIComponentTest.json") if nil ~= node then - local render = tolua.cast(node:getChildByTag(10025):getComponent("GUIComponent"),"ccs.ComRender") - local widget = tolua.cast(render:getNode(), "ccui.Widget") - local button = tolua.cast(widget:getChildByName("Button_156"),"ccui.Button") + local render = node:getChildByTag(10025):getComponent("GUIComponent") + local widget = render:getNode() + local button = widget:getChildByName("Button_156") local function onTouch(sender, eventType) if eventType == ccui.TouchEventType.began then local blowFish = tolua.cast(node:getChildByTag(10010):getComponent("CCArmature"), "ccs.ComRender") From e436aa4022895457dddffc0c7a2c2acbc8c9d025 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Fri, 21 Feb 2014 10:22:03 +0800 Subject: [PATCH 03/21] issue #3956:Replace Object with Ref --- cocos/scripting/lua/bindings/tolua_fix.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/scripting/lua/bindings/tolua_fix.cpp b/cocos/scripting/lua/bindings/tolua_fix.cpp index ced5595efd..bd72d5dad5 100644 --- a/cocos/scripting/lua/bindings/tolua_fix.cpp +++ b/cocos/scripting/lua/bindings/tolua_fix.cpp @@ -1,6 +1,6 @@ #include "tolua_fix.h" -#include "CCObject.h" +#include "CCRef.h" #include "LuaBasicConversions.h" #include @@ -35,7 +35,7 @@ TOLUA_API int toluafix_pushusertype_ccobject(lua_State* L, return -1; } - Object* vPtr = static_cast(ptr); + Ref* vPtr = static_cast(ptr); const char* vType = getLuaTypeName(vPtr, type); if (*p_refid == 0) From 293ea664016901b7d691b3db61368945c43ceb69 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Fri, 21 Feb 2014 16:22:35 +0800 Subject: [PATCH 04/21] =?UTF-8?q?issue=20#3956:Remove=20the=20usage=20of?= =?UTF-8?q?=20=E2=80=9Ctolua.cast=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lua/bindings/LuaBasicConversions.h | 2 +- .../ActionsEaseTest/ActionsEaseTest.lua | 4 +- .../luaScript/ActionsTest/ActionsTest.lua | 10 +- .../CocoStudioArmatureTest.lua | 2 +- .../CocoStudioGUITest.lua.REMOVED.git-id | 2 +- .../CocoStudioSceneTest.lua | 26 ++-- .../EffectsAdvancedTest.lua | 2 +- .../ExtensionTest/CocosBuilderTest.lua | 50 +++---- .../luaScript/ExtensionTest/ExtensionTest.lua | 18 +-- .../luaScript/LabelTest/LabelTest.lua | 30 ++--- .../luaScript/LabelTestNew/LabelTestNew.lua | 16 +-- .../luaScript/LayerTest/LayerTest.lua | 12 +- .../Resources/luaScript/MenuTest/MenuTest.lua | 40 +++--- .../NewEventDispatcherTest.lua | 6 +- .../Resources/luaScript/NodeTest/NodeTest.lua | 13 +- .../luaScript/OpenGLTest/OpenGLTest.lua | 4 +- .../PerformanceTest/PerformanceTest.lua | 26 ++-- .../luaScript/SpriteTest/SpriteTest.lua | 4 +- .../luaScript/Texture2dTest/Texture2dTest.lua | 30 ++--- .../luaScript/TileMapTest/TileMapTest.lua | 126 +++--------------- 20 files changed, 169 insertions(+), 254 deletions(-) diff --git a/cocos/scripting/lua/bindings/LuaBasicConversions.h b/cocos/scripting/lua/bindings/LuaBasicConversions.h index b5de6057b8..19ab9a8f7f 100644 --- a/cocos/scripting/lua/bindings/LuaBasicConversions.h +++ b/cocos/scripting/lua/bindings/LuaBasicConversions.h @@ -87,7 +87,7 @@ bool luavals_variadic_to_ccvector( lua_State* L, int argc, cocos2d::Vector* r { tolua_Error err; //Undo check - if (!tolua_isusertype(L, i + 2, "cc.Object", 0, &err)) + if (!tolua_isusertype(L, i + 2, "cc.Ref", 0, &err)) { ok = false; break; diff --git a/tests/test-lua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua b/tests/test-lua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua index 7ceb78c0e7..5aa7d25fdb 100644 --- a/tests/test-lua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua +++ b/tests/test-lua/Resources/luaScript/ActionsEaseTest/ActionsEaseTest.lua @@ -425,10 +425,10 @@ local function SpeedTest() local spawn = cc.Spawn:create(seq3_1, seq3_2) SpeedTest_action1 = cc.Speed:create(cc.RepeatForever:create(spawn), 1.0) - local spawn2 = tolua.cast(spawn:clone(), "cc.Spawn") + local spawn2 = spawn:clone() SpeedTest_action2 = cc.Speed:create(cc.RepeatForever:create(spawn2), 1.0) - local spawn3 = tolua.cast(spawn:clone(), "cc.Spawn") + local spawn3 = spawn:clone() SpeedTest_action3 = cc.Speed:create(cc.RepeatForever:create(spawn3), 1.0) grossini:runAction(SpeedTest_action2) diff --git a/tests/test-lua/Resources/luaScript/ActionsTest/ActionsTest.lua b/tests/test-lua/Resources/luaScript/ActionsTest/ActionsTest.lua index 9b70078388..0c7a235768 100644 --- a/tests/test-lua/Resources/luaScript/ActionsTest/ActionsTest.lua +++ b/tests/test-lua/Resources/luaScript/ActionsTest/ActionsTest.lua @@ -550,8 +550,8 @@ local function ActionAnimate() tamara:runAction(cc.Sequence:create(action2, action2:reverse())) local animation3 = animation2:clone() - -- problem - tolua.cast(animation3,"cc.Animation"):setLoops(4) + + animation3:setLoops(4) local action3 = cc.Animate:create(animation3) kathia:runAction(action3) @@ -740,7 +740,7 @@ local function ActionRotateToRepeat() local act2 = cc.RotateTo:create(1, 0) local seq = cc.Sequence:create(act1, act2) local rep1 = cc.RepeatForever:create(seq) - local rep2 = cc.Repeat:create(tolua.cast(seq:clone(), "cc.Sequence"), 10) + local rep2 = cc.Repeat:create(seq:clone(), 10) tamara:runAction(rep1) kathia:runAction(rep2) @@ -931,8 +931,8 @@ local function ActionOrbit() local seq = cc.Sequence:create(move, move_back) local rfe = cc.RepeatForever:create(seq) kathia:runAction(rfe) - tamara:runAction(tolua.cast(rfe:clone(), "cc.ActionInterval")) - grossini:runAction(tolua.cast(rfe:clone(), "cc.ActionInterval")) + tamara:runAction(rfe:clone()) + grossini:runAction(rfe:clone()) Helper.subtitleLabel:setString("OrbitCamera action") diff --git a/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioArmatureTest/CocoStudioArmatureTest.lua b/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioArmatureTest/CocoStudioArmatureTest.lua index adca6996a5..895e157be8 100644 --- a/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioArmatureTest/CocoStudioArmatureTest.lua +++ b/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioArmatureTest/CocoStudioArmatureTest.lua @@ -428,7 +428,7 @@ end function TestPerformance:refreshTitle() local subTitleInfo = ArmatureTestLayer.subTitle(5) .. self._armatureCount - local label = tolua.cast(self:getChildByTag(10001),"cc.LabelTTF") + local label = self:getChildByTag(10001) label:setString(subTitleInfo) end diff --git a/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua.REMOVED.git-id b/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua.REMOVED.git-id index 0279040f69..a78499eac5 100644 --- a/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua.REMOVED.git-id +++ b/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioGUITest/CocoStudioGUITest.lua.REMOVED.git-id @@ -1 +1 @@ -09ed3c488f6d182685c416c291f8f325fb5cc2d2 \ No newline at end of file +55c597addccd9586d927093004a96fc08902b860 \ No newline at end of file diff --git a/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua b/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua index 4be70e45fd..ee3507c6dd 100644 --- a/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua +++ b/tests/test-lua/Resources/luaScript/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua @@ -193,9 +193,9 @@ function SpriteComponentTest:createGameScene() local action1 = cc.Blink:create(2, 10) local action2 = cc.Blink:create(2, 5) - local sister1 = tolua.cast(node:getChildByTag(10003):getComponent("CCSprite"),"ccs.ComRender") + local sister1 = node:getChildByTag(10003):getComponent("CCSprite") sister1:getNode():runAction(action1) - local sister2 = tolua.cast(node:getChildByTag(10004):getComponent("CCSprite"),"ccs.ComRender") + local sister2 = node:getChildByTag(10004):getComponent("CCSprite") sister2:getNode():runAction(action2) end @@ -245,10 +245,10 @@ end function ArmatureComponentTest:createGameScene() local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/ArmatureComponentTest/ArmatureComponentTest.json") if nil ~= node then - local blowFish = tolua.cast(node:getChildByTag(10007):getComponent("CCArmature"),"ccs.ComRender") + local blowFish = node:getChildByTag(10007):getComponent("CCArmature") blowFish:getNode():runAction(cc.MoveBy:create(10.0, cc.p(-1000.0, 0))) - local butterflyfish = tolua.cast(node:getChildByTag(10008):getComponent("CCArmature"),"ccs.ComRender") + local butterflyfish = node:getChildByTag(10008):getComponent("CCArmature") butterflyfish:getNode():runAction(CCMoveBy:create(10.0, cc.p(-1000.0, 0))) end @@ -303,10 +303,10 @@ function UIComponentTest:createGameScene() local button = widget:getChildByName("Button_156") local function onTouch(sender, eventType) if eventType == ccui.TouchEventType.began then - local blowFish = tolua.cast(node:getChildByTag(10010):getComponent("CCArmature"), "ccs.ComRender") + local blowFish = node:getChildByTag(10010):getComponent("CCArmature") blowFish:getNode():runAction(cc.MoveBy:create(10.0, cc.p(-1000.0, 0))) - local butterflyfish = tolua.cast(node:getChildByTag(10011):getComponent("CCArmature"), "ccs.ComRender") + local butterflyfish = node:getChildByTag(10011):getComponent("CCArmature") butterflyfish:getNode():runAction(cc.MoveBy:create(10.0, cc.p(-1000.0, 0))) end end @@ -360,7 +360,7 @@ end function TmxMapComponentTest:createGameScene() local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/TmxMapComponentTest/TmxMapComponentTest.json") if nil ~= node then - local tmxMap = tolua.cast(node:getChildByTag(10015):getComponent("CCTMXTiledMap"),"ccs.ComRender") + local tmxMap = node:getChildByTag(10015):getComponent("CCTMXTiledMap") local actionTo = cc.SkewTo:create(2, 0.0, 2.0) local rotateTo = cc.RotateTo:create(2, 61.0) local actionScaleTo = cc.ScaleTo:create(2, -0.44, 0.47) @@ -420,7 +420,7 @@ end function ParticleComponentTest:createGameScene() local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/ParticleComponentTest/ParticleComponentTest.json") if nil ~= node then - local particle = tolua.cast(node:getChildByTag(10020):getComponent("CCParticleSystemQuad"),"ccs.ComRender") + local particle = node:getChildByTag(10020):getComponent("CCParticleSystemQuad") local jump = cc.JumpBy:create(5, cc.p(-500,0), 50, 4) local action = cc.Sequence:create( jump, jump:reverse()) particle:getNode():runAction(action) @@ -472,13 +472,13 @@ end function EffectComponentTest:createGameScene() local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/EffectComponentTest/EffectComponentTest.json") if nil ~= node then - local render = tolua.cast(node:getChildByTag(10015):getComponent("CCArmature"),"ccs.ComRender") - local armature = tolua.cast(render:getNode(),"ccs.Armature") + local render = node:getChildByTag(10015):getComponent("CCArmature") + local armature = render:getNode() local function animationEvent(armatureBack,movementType,movementID) local id = movementID if movementType == ccs.MovementEventType.loopComplete then if id == "Fire" then - local audio = tolua.cast(node:getChildByTag(10015):getComponent("CCComAudio"), "ccs.ComAudio") + local audio = node:getChildByTag(10015):getComponent("CCComAudio") audio:playEffect() end end @@ -533,7 +533,7 @@ end function BackgroundComponentTest:createGameScene() local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/BackgroundComponentTest/BackgroundComponentTest.json") if nil ~= node then - local audio = tolua.cast(node:getComponent("CCBackgroundAudio"),"ccs.ComAudio") + local audio = node:getComponent("CCBackgroundAudio") audio:playBackgroundMusic() end @@ -582,7 +582,7 @@ end function AttributeComponentTest:createGameScene() local node = ccs.SceneReader:getInstance():createNodeWithSceneFile("scenetest/AttributeComponentTest/AttributeComponentTest.json") - local attribute = tolua.cast(node:getChildByTag(10015):getComponent("CCComAttribute"), "ccs.ComAttribute") + local attribute = node:getChildByTag(10015):getComponent("CCComAttribute") print(string.format("Name: %s, HP: %f, MP: %f", attribute:getString("name"), attribute:getFloat("maxHP"), attribute:getFloat("maxMP"))) return node end diff --git a/tests/test-lua/Resources/luaScript/EffectsAdvancedTest/EffectsAdvancedTest.lua b/tests/test-lua/Resources/luaScript/EffectsAdvancedTest/EffectsAdvancedTest.lua index 863044cd94..fe69156e73 100644 --- a/tests/test-lua/Resources/luaScript/EffectsAdvancedTest/EffectsAdvancedTest.lua +++ b/tests/test-lua/Resources/luaScript/EffectsAdvancedTest/EffectsAdvancedTest.lua @@ -95,7 +95,7 @@ local function Effect2() local delay = cc.DelayTime:create(1) - target:runAction(cc.Sequence:create(shaky, delay ,reuse, shuffle, tolua.cast(delay:clone(), "cc.Action"), turnoff, turnon)) + target:runAction(cc.Sequence:create(shaky, delay ,reuse, shuffle, delay:clone(), turnoff, turnon)) return ret end diff --git a/tests/test-lua/Resources/luaScript/ExtensionTest/CocosBuilderTest.lua b/tests/test-lua/Resources/luaScript/ExtensionTest/CocosBuilderTest.lua index 590ae907b6..d9465b215f 100644 --- a/tests/test-lua/Resources/luaScript/ExtensionTest/CocosBuilderTest.lua +++ b/tests/test-lua/Resources/luaScript/ExtensionTest/CocosBuilderTest.lua @@ -30,7 +30,7 @@ ccb["TestScrollViewsLayer"] = TestScrollViewsLayer local function onMenuItemAClicked() if nil ~= TestMenusLayer["mMenuItemStatusLabelBMFont"] then - local labelBmFt = tolua.cast(TestMenusLayer["mMenuItemStatusLabelBMFont"],"cc.LabelBMFont") + local labelBmFt = TestMenusLayer["mMenuItemStatusLabelBMFont"] if nil ~= labelBmFt then labelBmFt:setString("Menu Item A clicked."); end @@ -39,7 +39,7 @@ end local function onMenuItemBClicked() if nil ~= TestMenusLayer["mMenuItemStatusLabelBMFont"] then - local labelBmFt = tolua.cast(TestMenusLayer["mMenuItemStatusLabelBMFont"],"cc.LabelBMFont") + local labelBmFt = TestMenusLayer["mMenuItemStatusLabelBMFont"] if nil ~= labelBmFt then labelBmFt:setString("Menu Item B clicked."); end @@ -48,7 +48,7 @@ end local function pressedC( ... ) if nil ~= TestMenusLayer["mMenuItemStatusLabelBMFont"] then - local labelBmFt = tolua.cast(TestMenusLayer["mMenuItemStatusLabelBMFont"],"cc.LabelBMFont") + local labelBmFt = TestMenusLayer["mMenuItemStatusLabelBMFont"] if nil ~= labelBmFt then labelBmFt:setString("Menu Item C clicked."); end @@ -59,9 +59,9 @@ local function onMenuTestClicked() local scene = cc.Scene:create() local proxy = cc.CCBProxy:create() local node = CCBReaderLoad("cocosbuilderRes/ccb/ccb/TestMenus.ccbi",proxy,HelloCocosBuilderLayer) - local layer = tolua.cast(node,"cc.Layer") + local layer = node if nil ~= HelloCocosBuilderLayer["mTestTitleLabelTTF"] then - local ccLabelTTF = tolua.cast(HelloCocosBuilderLayer["mTestTitleLabelTTF"],"cc.LabelTTF") + local ccLabelTTF = HelloCocosBuilderLayer["mTestTitleLabelTTF"] if nil ~= ccLabelTTF then ccLabelTTF:setString("ccb/ccb/TestMenus.ccbi") end @@ -88,9 +88,9 @@ local function onSpriteTestClicked() local scene = cc.Scene:create() local proxy = cc.CCBProxy:create() local node = CCBReaderLoad("cocosbuilderRes/ccb/ccb/TestSprites.ccbi",proxy,HelloCocosBuilderLayer) - local layer = tolua.cast(node,"cc.Layer") + local layer = node if nil ~= HelloCocosBuilderLayer["mTestTitleLabelTTF"] then - local ccLabelTTF = tolua.cast(HelloCocosBuilderLayer["mTestTitleLabelTTF"],"cc.LabelTTF") + local ccLabelTTF = HelloCocosBuilderLayer["mTestTitleLabelTTF"] if nil ~= ccLabelTTF then ccLabelTTF:setString("ccb/ccb/TestSprites.ccbi") end @@ -107,9 +107,9 @@ local function onButtonTestClicked() local scene = cc.Scene:create() local proxy = cc.CCBProxy:create() local node = CCBReaderLoad("cocosbuilderRes/ccb/ccb/TestButtons.ccbi",proxy,HelloCocosBuilderLayer) - local layer = tolua.cast(node,"cc.Layer") + local layer = node if nil ~= HelloCocosBuilderLayer["mTestTitleLabelTTF"] then - local ccLabelTTF = tolua.cast(HelloCocosBuilderLayer["mTestTitleLabelTTF"],"cc.LabelTTF") + local ccLabelTTF = HelloCocosBuilderLayer["mTestTitleLabelTTF"] if nil ~= ccLabelTTF then ccLabelTTF:setString("ccb/ccb/TestButtons.ccbi") end @@ -122,7 +122,7 @@ local function onButtonTestClicked() end local function onCCControlButtonClicked(sender,controlEvent) - local labelTTF = tolua.cast(TestButtonsLayer["mCCControlEventLabel"],"cc.LabelBMFont") + local labelTTF = TestButtonsLayer["mCCControlEventLabel"] if nil == labelTTF then return @@ -158,9 +158,9 @@ local function onAnimationsTestClicked() local scene = cc.Scene:create() local proxy = cc.CCBProxy:create() local node = CCBReaderLoad("cocosbuilderRes/ccb/ccb/TestAnimations.ccbi",proxy,HelloCocosBuilderLayer) - local layer = tolua.cast(node,"cc.Layer") + local layer = node if nil ~= HelloCocosBuilderLayer["mTestTitleLabelTTF"] then - local ccLabelTTF = tolua.cast(HelloCocosBuilderLayer["mTestTitleLabelTTF"],"cc.LabelTTF") + local ccLabelTTF = HelloCocosBuilderLayer["mTestTitleLabelTTF"] if nil ~= ccLabelTTF then ccLabelTTF:setString("ccb/ccb/TestAnimations.ccbi") end @@ -177,9 +177,9 @@ local function onParticleSystemTestClicked() local scene = cc.Scene:create() local proxy = cc.CCBProxy:create() local node = CCBReaderLoad("cocosbuilderRes/ccb/ccb/TestParticleSystems.ccbi",proxy,HelloCocosBuilderLayer) - local layer = tolua.cast(node,"cc.Layer") + local layer = node if nil ~= HelloCocosBuilderLayer["mTestTitleLabelTTF"] then - local ccLabelTTF = tolua.cast(HelloCocosBuilderLayer["mTestTitleLabelTTF"],"cc.LabelTTF") + local ccLabelTTF = HelloCocosBuilderLayer["mTestTitleLabelTTF"] if nil ~= ccLabelTTF then ccLabelTTF:setString("ccb/ccb/TestParticleSystems.ccbi") end @@ -193,7 +193,7 @@ end local function onCCControlButtonIdleClicked() if nil ~= TestAnimationsLayer["mAnimationManager"] then - local animationMgr = tolua.cast(TestAnimationsLayer["mAnimationManager"],"cc.CCBAnimationManager") + local animationMgr = TestAnimationsLayer["mAnimationManager"] if nil ~= animationMgr then animationMgr:runAnimationsForSequenceNamedTweenDuration("Idle", 0.3) end @@ -202,7 +202,7 @@ end local function onCCControlButtonWaveClicked() if nil ~= TestAnimationsLayer["mAnimationManager"] then - local animationMgr = tolua.cast(TestAnimationsLayer["mAnimationManager"],"cc.CCBAnimationManager") + local animationMgr = TestAnimationsLayer["mAnimationManager"] if nil ~= animationMgr then animationMgr:runAnimationsForSequenceNamedTweenDuration("Wave", 0.3) end @@ -211,7 +211,7 @@ end local function onCCControlButtonJumpClicked() if nil ~= TestAnimationsLayer["mAnimationManager"] then - local animationMgr = tolua.cast(TestAnimationsLayer["mAnimationManager"],"cc.CCBAnimationManager") + local animationMgr = TestAnimationsLayer["mAnimationManager"] if nil ~= animationMgr then animationMgr:runAnimationsForSequenceNamedTweenDuration("Jump", 0.3) end @@ -220,7 +220,7 @@ end local function onCCControlButtonFunkyClicked() if nil ~= TestAnimationsLayer["mAnimationManager"] then - local animationMgr = tolua.cast(TestAnimationsLayer["mAnimationManager"],"cc.CCBAnimationManager") + local animationMgr = TestAnimationsLayer["mAnimationManager"] if nil ~= animationMgr then animationMgr:runAnimationsForSequenceNamedTweenDuration("Funky", 0.3) end @@ -237,9 +237,9 @@ local function onScrollViewTestClicked() local scene = cc.Scene:create() local proxy = cc.CCBProxy:create() local node = CCBReaderLoad("cocosbuilderRes/ccb/ccb/TestScrollViews.ccbi",proxy,HelloCocosBuilderLayer) - local layer = tolua.cast(node,"cc.Layer") + local layer = node if nil ~= HelloCocosBuilderLayer["mTestTitleLabelTTF"] then - local ccLabelTTF = tolua.cast(HelloCocosBuilderLayer["mTestTitleLabelTTF"],"cc.LabelTTF") + local ccLabelTTF = HelloCocosBuilderLayer["mTestTitleLabelTTF"] if nil ~= ccLabelTTF then ccLabelTTF:setString("ccb/ccb/TestScrollViews.ccbi") end @@ -256,9 +256,9 @@ local function onTimelineCallbackSoundClicked() local scene = cc.Scene:create() local proxy = cc.CCBProxy:create() local node = CCBReaderLoad("cocosbuilderRes/ccb/ccb/TestTimelineCallback.ccbi",proxy,HelloCocosBuilderLayer) - local layer = tolua.cast(node,"cc.Layer") + local layer = node if nil ~= HelloCocosBuilderLayer["mTestTitleLabelTTF"] then - local ccLabelTTF = tolua.cast(HelloCocosBuilderLayer["mTestTitleLabelTTF"],"cc.LabelTTF") + local ccLabelTTF = HelloCocosBuilderLayer["mTestTitleLabelTTF"] if nil ~= ccLabelTTF then ccLabelTTF:setString("ccb/ccb/TestTimelineCallback.ccbi") end @@ -272,7 +272,7 @@ end function onCallback1() if nil ~= TestTimelineLayer["helloLabel"] then - local ccLabelTTF = tolua.cast(TestTimelineLayer["helloLabel"],"cc.LabelTTF") + local ccLabelTTF = TestTimelineLayer["helloLabel"] if nil ~= ccLabelTTF then ccLabelTTF:runAction(cc.RotateBy:create(1, 360)) ccLabelTTF:setString("Callback 1"); @@ -282,7 +282,7 @@ end function onCallback2() if nil ~= TestTimelineLayer["helloLabel"] then - local ccLabelTTF = tolua.cast(TestTimelineLayer["helloLabel"],"cc.LabelTTF") + local ccLabelTTF = TestTimelineLayer["helloLabel"] if nil ~= ccLabelTTF then ccLabelTTF:runAction(cc.RotateBy:create(2, 360)) ccLabelTTF:setString("Callback 2"); @@ -306,7 +306,7 @@ local function HelloCCBTestMainLayer() print(type(cc.Scene)) local proxy = cc.CCBProxy:create() local node = CCBReaderLoad("cocosbuilderRes/ccb/HelloCocosBuilder.ccbi",proxy,HelloCocosBuilderLayer) - local layer = tolua.cast(node,"cc.Layer") + local layer = node return layer end diff --git a/tests/test-lua/Resources/luaScript/ExtensionTest/ExtensionTest.lua b/tests/test-lua/Resources/luaScript/ExtensionTest/ExtensionTest.lua index 8283c71e99..18c904bb61 100644 --- a/tests/test-lua/Resources/luaScript/ExtensionTest/ExtensionTest.lua +++ b/tests/test-lua/Resources/luaScript/ExtensionTest/ExtensionTest.lua @@ -69,7 +69,7 @@ local function runNotificationCenterTest() local s = cc.Director:getInstance():getWinSize() local function toggleSwitch(tag,menuItem) - local toggleItem = tolua.cast(menuItem,"cc.MenuItemToggle") + local toggleItem = menuItem local nIndex = toggleItem:getSelectedIndex() local selectedItem = toggleItem:getSelectedItem() if 0 == nIndex then @@ -155,7 +155,7 @@ local function runNotificationCenterTest() connectitem:setTag(NotificationCenterParam.kTagConnect+i) local function connectToSwitch(tag,menuItem) - local connectMenuitem = tolua.cast(menuItem,"cc.MenuItemToggle") + local connectMenuitem = menuItem local bConnected = true if connectMenuitem:getSelectedIndex() == 0 then bConnected = false @@ -376,7 +376,7 @@ local function runCCControlTest() if nil == pSender or nil == pDisplayValueLabel then return end - local pControl = tolua.cast(pSender,"cc.ControlSlider") + local pControl = pSender local strFmt = nil if pControl:getTag() == 1 then strFmt = string.format("Upper slider value = %.02f",pControl:getValue()) @@ -434,7 +434,7 @@ local function runCCControlTest() return end - local pPicker = tolua.cast(pSender,"cc.ControlColourPicker") + local pPicker = pSender local strFmt = string.format("#%02X%02X%02X",pPicker:getColor().r, pPicker:getColor().g, pPicker:getColor().b) pColorLabel:setString(strFmt) end @@ -499,7 +499,7 @@ local function runCCControlTest() return end - local pControl = tolua.cast(pSender,"cc.ControlSwitch") + local pControl = pSender if pControl:isOn() then pDisplayValueLabel:setString("On") else @@ -774,7 +774,7 @@ local function runCCControlTest() return end - local pControl = tolua.cast(pSender,"cc.ControlPotentiometer") + local pControl = pSender local strFmt = string.format("%0.2f",pControl:getValue()) pDisplayValueLabel:setString(strFmt ) end @@ -831,7 +831,7 @@ local function runCCControlTest() return end - local pControl = tolua.cast(pSender,"cc.ControlStepper") + local pControl = pSender local strFmt = string.format("%0.02f",pControl:getValue() ) pDisplayValueLabel:setString(strFmt ) end @@ -917,7 +917,7 @@ local function runEditBoxTest() local EditEmail = nil local function editBoxTextEventHandle(strEventName,pSender) - local edit = tolua.cast(pSender,"cc.EditBox") + local edit = pSender local strFmt if strEventName == "began" then strFmt = string.format("editBox %p DidBegin !", edit) @@ -1038,7 +1038,7 @@ function TableViewTestLayer.tableCellAtIndex(table, idx) label:setTag(123) cell:addChild(label) else - label = tolua.cast(cell:getChildByTag(123),"cc.LabelTTF") + label = cell:getChildByTag(123) if nil ~= label then label:setString(strValue) end diff --git a/tests/test-lua/Resources/luaScript/LabelTest/LabelTest.lua b/tests/test-lua/Resources/luaScript/LabelTest/LabelTest.lua index c92d347fcb..adfeb0a3eb 100644 --- a/tests/test-lua/Resources/luaScript/LabelTest/LabelTest.lua +++ b/tests/test-lua/Resources/luaScript/LabelTest/LabelTest.lua @@ -32,11 +32,11 @@ function LabelAtlasTest.step(dt) local string = string.format("%2.2f Test", m_time) local label1_origin = LabelAtlasTest.layer:getChildByTag(kTagSprite1) - local label1 = tolua.cast(label1_origin, "cc.LabelAtlas") + local label1 = label1_origin label1:setString(string) -- local label2_origin = LabelAtlasTest.layer:getChildByTag(kTagSprite2) - local label2 = tolua.cast(label2_origin, "cc.LabelAtlas") + local label2 = label2_origin string = string.format("%d", m_time) label2:setString(string) @@ -88,11 +88,11 @@ function LabelAtlasColorTest.step(dt) m_time = m_time + dt local string = string.format("%2.2f Test", m_time) local label1_origin = LabelAtlasColorTest.layer:getChildByTag(kTagSprite1) - local label1 = tolua.cast(label1_origin, "cc.LabelAtlas") + local label1 = label1_origin label1:setString(string) local label2_origin = LabelAtlasColorTest.layer:getChildByTag(kTagSprite2) - local label2 = tolua.cast(label2_origin, "cc.LabelAtlas") + local label2 = label2_origin string = string.format("%d", m_time) label2:setString(string) @@ -199,7 +199,7 @@ function Atlas3.create() label2:setColor(cc.c3b(255, 0, 0 )) layer:addChild(label2, 0, kTagBitmapAtlas2) - label2:runAction( tolua.cast(repeatAction:clone(), "cc.Action") ) + label2:runAction( repeatAction:clone()) local label3 = cc.LabelBMFont:create("Test", "fonts/bitmapFontTest2.fnt") -- testing anchors @@ -223,13 +223,13 @@ function Atlas3.step(dt) m_time = m_time + dt local string = string.format("%2.2f Test j", m_time) - local label1 = tolua.cast(Atlas3.layer:getChildByTag(kTagBitmapAtlas1), "cc.LabelBMFont") + local label1 = Atlas3.layer:getChildByTag(kTagBitmapAtlas1) label1:setString(string) - local label2 = tolua.cast(Atlas3.layer:getChildByTag(kTagBitmapAtlas2), "cc.LabelBMFont") + local label2 = Atlas3.layer:getChildByTag(kTagBitmapAtlas2) label2:setString(string) - local label3 = tolua.cast(Atlas3.layer:getChildByTag(kTagBitmapAtlas3), "cc.LabelBMFont") + local label3 = Atlas3.layer:getChildByTag(kTagBitmapAtlas3) label3:setString(string) end @@ -309,7 +309,7 @@ function Atlas4.create() label2:setPosition( cc.p(s.width/2.0, 80) ) local lastChar = label2:getChildByTag(3) - lastChar:runAction(tolua.cast( rot_4ever:clone(), "cc.Action" )) + lastChar:runAction(rot_4ever:clone()) layer:registerScriptHandler(Atlas4.onNodeEvent) @@ -329,7 +329,7 @@ function Atlas4.step(dt) local string = string.format("%04.1f", m_time) - local label1 = tolua.cast(Atlas4.layer:getChildByTag(kTagBitmapAtlas2), "cc.LabelBMFont") + local label1 = Atlas4.layer:getChildByTag(kTagBitmapAtlas2) label1:setString(string) end @@ -592,9 +592,9 @@ function LabelsEmpty.create() end function LabelsEmpty.updateStrings(dt) - local label1 = tolua.cast(LabelsEmpty.layer:getChildByTag(kTagBitmapAtlas1), "cc.LabelBMFont") - local label2 = tolua.cast(LabelsEmpty.layer:getChildByTag(kTagBitmapAtlas2), "cc.LabelTTF") - local label3 = tolua.cast(LabelsEmpty.layer:getChildByTag(kTagBitmapAtlas3), "cc.LabelAtlas") + local label1 = LabelsEmpty.layer:getChildByTag(kTagBitmapAtlas1) + local label2 = LabelsEmpty.layer:getChildByTag(kTagBitmapAtlas2) + local label3 = LabelsEmpty.layer:getChildByTag(kTagBitmapAtlas3) if( LabelsEmpty.setEmpty == false) then label1:setString("not empty") @@ -1118,7 +1118,7 @@ end function BitmapFontMultiLineAlignment.stringChanged(tag, sender) - local item = tolua.cast(sender, "cc.MenuItemFont") + local item = sender item:setColor(cc.c3b(255, 0, 0)) BitmapFontMultiLineAlignment._pLastAlignmentItem:setColor(cc.c3b(255, 255, 255)) BitmapFontMultiLineAlignment._pLastAlignmentItem = item @@ -1136,7 +1136,7 @@ end function BitmapFontMultiLineAlignment.alignmentChanged(tag, sender) -- cclog("BitmapFontMultiLineAlignment.alignmentChanged, tag:"..tag) - local item = tolua.cast(sender, "cc.MenuItemFont") + local item = sender item:setColor(cc.c3b(255, 0, 0)) BitmapFontMultiLineAlignment._pLastAlignmentItem:setColor(cc.c3b(255, 255, 255)) BitmapFontMultiLineAlignment._pLastAlignmentItem = item diff --git a/tests/test-lua/Resources/luaScript/LabelTestNew/LabelTestNew.lua b/tests/test-lua/Resources/luaScript/LabelTestNew/LabelTestNew.lua index 72011b9237..293480d08d 100644 --- a/tests/test-lua/Resources/luaScript/LabelTestNew/LabelTestNew.lua +++ b/tests/test-lua/Resources/luaScript/LabelTestNew/LabelTestNew.lua @@ -61,7 +61,7 @@ function LabelFNTColorAndOpacity.create() label2:setColor(cc.c3b(255, 0, 0 )) layer:addChild(label2, 0, kTagBitmapAtlas2) - label2:runAction( tolua.cast(repeatAction:clone(), "cc.Action") ) + label2:runAction(repeatAction:clone()) local label3 = cc.Label:createWithBMFont("fonts/bitmapFontTest2.fnt", "Test") -- testing anchors @@ -85,13 +85,13 @@ function LabelFNTColorAndOpacity.step(dt) m_time = m_time + dt local string = string.format("%2.2f Test j", m_time) - local label1 = tolua.cast(LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas1), "cc.Label") + local label1 = LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas1) label1:setString(string) - local label2 = tolua.cast(LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas2), "cc.Label") + local label2 = LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas2) label2:setString(string) - local label3 = tolua.cast(LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas3), "cc.Label") + local label3 = LabelFNTColorAndOpacity.layer:getChildByTag(kTagBitmapAtlas3) label3:setString(string) end @@ -165,7 +165,7 @@ function LabelFNTSpriteActions.create() label2:setPosition( cc.p(s.width/2.0, 80) ) local lastChar = label2:getLetter(3) - lastChar:runAction(tolua.cast( rot_4ever:clone(), "cc.Action" )) + lastChar:runAction(rot_4ever:clone()) layer:registerScriptHandler(LabelFNTSpriteActions.onNodeEvent) @@ -694,7 +694,7 @@ function LabelFNTMultiLineAlignment.create() local labelWidth = math.abs(LabelFNTMultiLineAlignment._pArrowsShouldRetain:getPositionX() - LabelFNTMultiLineAlignment._pLabelShouldRetain:getPositionX()) * 2 - LabelFNTMultiLineAlignment._pLabelShouldRetain:setWidth(labelWidth) + LabelFNTMultiLineAlignment._pLabelShouldRetain:setMaxLineWidth(labelWidth) end local function onTouchesEnded(touch, event) @@ -725,7 +725,7 @@ end function LabelFNTMultiLineAlignment.stringChanged(tag, sender) - local item = tolua.cast(sender, "cc.MenuItemFont") + local item = sender item:setColor(cc.c3b(255, 0, 0)) LabelFNTMultiLineAlignment._pLastAlignmentItem:setColor(cc.c3b(255, 255, 255)) LabelFNTMultiLineAlignment._pLastAlignmentItem = item @@ -743,7 +743,7 @@ end function LabelFNTMultiLineAlignment.alignmentChanged(tag, sender) -- cclog("LabelFNTMultiLineAlignment.alignmentChanged, tag:"..tag) - local item = tolua.cast(sender, "cc.MenuItemFont") + local item = sender item:setColor(cc.c3b(255, 0, 0)) LabelFNTMultiLineAlignment._pLastAlignmentItem:setColor(cc.c3b(255, 255, 255)) LabelFNTMultiLineAlignment._pLastAlignmentItem = item diff --git a/tests/test-lua/Resources/luaScript/LayerTest/LayerTest.lua b/tests/test-lua/Resources/luaScript/LayerTest/LayerTest.lua index 7fce8fdc99..053bd2af63 100644 --- a/tests/test-lua/Resources/luaScript/LayerTest/LayerTest.lua +++ b/tests/test-lua/Resources/luaScript/LayerTest/LayerTest.lua @@ -314,7 +314,7 @@ local function LayerTest1() local newSize = cc.size( math.abs(x - s.width/2)*2, math.abs(y - s.height/2)*2) - local l = tolua.cast(ret:getChildByTag(kTagLayer), "cc.LayerColor") + local l = ret:getChildByTag(kTagLayer) l:setContentSize( newSize ) end @@ -395,7 +395,7 @@ local function LayerTestBlend() local blend = true local function newBlend(dt) - local layer = tolua.cast(ret:getChildByTag(kTagLayer), "cc.LayerColor") + local layer = ret:getChildByTag(kTagLayer) local src = 0 local dst = 0 @@ -445,7 +445,7 @@ local function LayerGradient() local function toggleItem(sender) -- cclog("toggleItem") - local gradient = tolua.cast(ret:getChildByTag(kTagLayer), "cc.LayerGradient") + local gradient = ret:getChildByTag(kTagLayer) gradient:setCompressedInterpolation(not gradient:isCompressedInterpolation()) end @@ -463,7 +463,7 @@ local function LayerGradient() local diff = cc.p(movingPos.x - start.x, movingPos.y - start.y) diff = cc.pNormalize(diff) - local gradient = tolua.cast(ret:getChildByTag(1), "cc.LayerGradient") + local gradient = ret:getChildByTag(1) gradient:setVector(diff) end @@ -492,7 +492,7 @@ local function LayerIgnoreAnchorPointPos() l:setPosition(cc.p( s.width/2, s.height/2)) local move = cc.MoveBy:create(2, cc.p(100,2)) - local back = tolua.cast(move:reverse(), "cc.MoveBy") + local back = move:reverse() local seq = cc.Sequence:create(move, back) l:runAction(cc.RepeatForever:create(seq)) ret:addChild(l, 0, kLayerIgnoreAnchorPoint) @@ -569,7 +569,7 @@ local function LayerIgnoreAnchorPointScale() local scale = cc.ScaleBy:create(2, 2) - local back = tolua.cast(scale:reverse(), "cc.ScaleBy") + local back = scale:reverse() local seq = cc.Sequence:create(scale, back) l:runAction(cc.RepeatForever:create(seq)) diff --git a/tests/test-lua/Resources/luaScript/MenuTest/MenuTest.lua b/tests/test-lua/Resources/luaScript/MenuTest/MenuTest.lua index 5c1c78c42a..73d3574653 100644 --- a/tests/test-lua/Resources/luaScript/MenuTest/MenuTest.lua +++ b/tests/test-lua/Resources/luaScript/MenuTest/MenuTest.lua @@ -32,13 +32,13 @@ local function MenuLayerMainMenu() local function menuCallback(sender) cclog("menuCallback...") - tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(1) + ret:getParent():switchTo(1) end item1:registerScriptTapHandler(menuCallback) -- Image Item local function menuCallback2(sender) - tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(2) + ret:getParent():switchTo(2) end local item2 = cc.MenuItemImage:create(s_SendScore, s_PressSendScore) @@ -46,7 +46,7 @@ local function MenuLayerMainMenu() local schedulerEntry = nil - local scheduler = cc.Director:getInstance():getScheduler() + local scheduler = cc.Director:getInstance():getScheduler() local function allowTouches(dt) local pDirector = cc.Director:getInstance() --pDirector:getTouchDispatcher():setPriority(cc.MENU_HANDLER_PRIORITY +1, ret) @@ -85,7 +85,7 @@ local function MenuLayerMainMenu() cc.MenuItemFont:setFontName("Marker Felt") local function menuCallbackConfig(sender) - tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(3) + ret:getParent():switchTo(3) end -- Label Item (cc.LabelBMFont) @@ -99,7 +99,7 @@ local function MenuLayerMainMenu() -- Events cc.MenuItemFont:setFontName("Marker Felt") local function menuCallbackBugsTest(pSender) - tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(4) + ret:getParent():switchTo(4) end -- Bugs Item @@ -115,7 +115,7 @@ local function MenuLayerMainMenu() item7:registerScriptTapHandler(onQuit) local function menuMovingCallback(pSender) - tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(5) + ret:getParent():switchTo(5) end local item8 = cc.MenuItemFont:create("Remove menu item when moving") @@ -152,7 +152,7 @@ local function MenuLayerMainMenu() if pObject == nil then break end - child = tolua.cast(pObject, "cc.Node") + child = pObject local dstPointX, dstPointY = child:getPosition() local offset = s.width/2 + 50 if i % 2 == 0 then @@ -200,7 +200,7 @@ local function MenuLayer2() local function alignMenusH() local i = 0 for i=0, 1 do - local menu = tolua.cast(ret:getChildByTag(100+i), "cc.Menu") + local menu = ret:getChildByTag(100+i) menu:setPosition( m_centeredMenu ) if i==0 then -- TIP: if no padding, padding = 5 @@ -219,7 +219,7 @@ local function MenuLayer2() local function alignMenusV() local i = 0 for i=0, 1 do - local menu = tolua.cast(ret:getChildByTag(100+i), "cc.Menu") + local menu = ret:getChildByTag(100+i) menu:setPosition( m_centeredMenu ) if i==0 then -- TIP: if no padding, padding = 5 @@ -236,11 +236,11 @@ local function MenuLayer2() end local function menuCallback(sender) - tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(0) + ret:getParent():switchTo(0) end local function menuCallbackOpacity(tag, sender) - local menu = tolua.cast(sender:getParent(), "cc.Menu") + local menu = sender:getParent() local opacity = menu:getOpacity() if opacity == 128 then menu:setOpacity(255) @@ -305,7 +305,7 @@ local function MenuLayer3() local m_disabledItem = nil local ret = cc.Layer:create() local function menuCallback(sender) - tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(0) + ret:getParent():switchTo(0) end local function menuCallback2(sender) @@ -357,8 +357,8 @@ local function MenuLayer3() item2:runAction( cc.RepeatForever:create(cc.Sequence:create( jump, jump:reverse()))) local spin1 = cc.RotateBy:create(3, 360) - local spin2 = tolua.cast(spin1:clone(), "cc.ActionInterval") - local spin3 = tolua.cast(spin1:clone(), "cc.ActionInterval") + local spin2 = spin1:clone() + local spin3 = spin1:clone() item1:runAction( cc.RepeatForever:create(spin1) ) item2:runAction( cc.RepeatForever:create(spin2) ) @@ -398,11 +398,11 @@ local function MenuLayer4() local item1 = cc.MenuItemToggle:create(cc.MenuItemFont:create( "On" )) local function menuCallback(tag, sender) - cclog("selected item: tag: %d, index:%d", tag, tolua.cast(sender, "cc.MenuItemToggle"):getSelectedIndex() ) + cclog("selected item: tag: %d, index:%d", tag, sender:getSelectedIndex() ) end local function backCallback(tag, sender) - tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(0) + ret:getParent():switchTo(0) end item1:registerScriptTapHandler(menuCallback) @@ -475,21 +475,21 @@ end local function BugsTest() local ret = cc.Layer:create() local function issue1410MenuCallback(tag, pSender) - local menu = tolua.cast(pSender:getParent(), "cc.Menu") + local menu = pSender:getParent() menu:setEnabled(false) menu:setEnabled(true) cclog("NO CRASHES") end local function issue1410v2MenuCallback(tag, pSender) - local menu = tolua.cast(pSender:getParent(), "cc.Menu") + local menu = pSender:getParent() menu:setEnabled(true) menu:setEnabled(false) cclog("NO CRASHES. AND MENU SHOULD STOP WORKING") end local function backMenuCallback(tag, pSender) - tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(0) + ret:getParent():switchTo(0) end @@ -526,7 +526,7 @@ local function RemoveMenuItemWhenMove() local back = cc.MenuItemFont:create("go back") local function goBack(tag, pSender) - tolua.cast(ret:getParent(), "cc.LayerMultiplex"):switchTo(0) + ret:getParent():switchTo(0) end back:registerScriptTapHandler(goBack) diff --git a/tests/test-lua/Resources/luaScript/NewEventDispatcherTest/NewEventDispatcherTest.lua b/tests/test-lua/Resources/luaScript/NewEventDispatcherTest/NewEventDispatcherTest.lua index 959950d73e..69f96c0978 100644 --- a/tests/test-lua/Resources/luaScript/NewEventDispatcherTest/NewEventDispatcherTest.lua +++ b/tests/test-lua/Resources/luaScript/NewEventDispatcherTest/NewEventDispatcherTest.lua @@ -184,7 +184,7 @@ function TouchableSpriteTest:onEnter() sprite2:addChild(sprite3, 1) local function onTouchBegan(touch, event) - local target = tolua.cast(event:getCurrentTarget(),"cc.Sprite") + local target = event:getCurrentTarget() local locationInNode = target:convertToNodeSpace(touch:getLocation()) local s = target:getContentSize() @@ -199,14 +199,14 @@ function TouchableSpriteTest:onEnter() end local function onTouchMoved(touch, event) - local target = tolua.cast(event:getCurrentTarget(), "cc.Sprite") + local target = event:getCurrentTarget() local posX,posY = target:getPosition() local delta = touch:getDelta() target:setPosition(cc.p(posX + delta.x, posY + delta.y)) end local function onTouchEnded(touch, event) - local target = tolua.cast(event:getCurrentTarget(), "cc.Sprite") + local target = event:getCurrentTarget() print("sprite onTouchesEnded..") target:setOpacity(255) if target == sprite2 then diff --git a/tests/test-lua/Resources/luaScript/NodeTest/NodeTest.lua b/tests/test-lua/Resources/luaScript/NodeTest/NodeTest.lua index 6cf01b65e6..ecbc50f03c 100644 --- a/tests/test-lua/Resources/luaScript/NodeTest/NodeTest.lua +++ b/tests/test-lua/Resources/luaScript/NodeTest/NodeTest.lua @@ -261,10 +261,10 @@ local function Test6() local rot = cc.RotateBy:create(2, 360) local rot_back = rot:reverse() local forever1 = cc.RepeatForever:create(cc.Sequence:create(rot, rot_back)) - local forever11 = tolua.cast(forever1:clone(), "cc.RepeatForever") + local forever11 = forever1:clone() - local forever2 = tolua.cast(forever1:clone(), "cc.RepeatForever") - local forever21 = tolua.cast(forever1:clone(), "cc.RepeatForever") + local forever2 = forever1:clone() + local forever21 = forever1:clone() Test6_layer:addChild(sp1, 0, kTagSprite1) sp1:addChild(sp11) @@ -342,7 +342,7 @@ local function shouldNotLeak(dt) scheduler:unscheduleScriptEntry(StressTest2_entry) local sublayer = StressTest2_layer:getChildByTag(kTagSprite1) - sublayer:removeAllChildrenWithCleanup(true) + sublayer:removeAllChildren(true) end local function StressTest2_onEnterOrExit(tag) @@ -370,10 +370,9 @@ local function StressTest2() local fire = cc.ParticleFire:create() fire:setTexture(cc.Director:getInstance():getTextureCache():addImage("Images/fire.png")) - fire = tolua.cast(fire, "cc.Node") fire:setPosition(80, s.height / 2 - 50) - local copy_seq3 = tolua.cast(seq3:clone(), "cc.Sequence") + local copy_seq3 = seq3:clone() fire:runAction(cc.RepeatForever:create(copy_seq3)) sublayer:addChild(fire, 2) @@ -564,7 +563,7 @@ local function ConvertToNode() point:setPosition(sprite:getPosition()) - local copy = tolua.cast(action:clone(), "cc.RepeatForever") + local copy = action:clone() sprite:runAction(copy) ConvertToNode_layer:addChild(sprite, i) end diff --git a/tests/test-lua/Resources/luaScript/OpenGLTest/OpenGLTest.lua b/tests/test-lua/Resources/luaScript/OpenGLTest/OpenGLTest.lua index e34f399e07..239a67ea0e 100644 --- a/tests/test-lua/Resources/luaScript/OpenGLTest/OpenGLTest.lua +++ b/tests/test-lua/Resources/luaScript/OpenGLTest/OpenGLTest.lua @@ -147,7 +147,7 @@ local function OpenGLTestMainLayer() local i = 0 local len = table.getn(children) for i= 0 ,len - 1 do - local child = tolua.cast(children[i + 1], "cc.Sprite") + local child = children[i + 1] local oldPosX,oldPosY = child:getPosition() child:setPosition(oldPosX,math.sin(accum * 2 + i / 2.0) * 20) local scaleY = math.sin(accum * 2 + i / 2.0 + 0.707) @@ -558,7 +558,7 @@ local function OpenGLTestMainLayer() local function getCurrentResult() local var = {} - local glProgam = tolua.cast(sprite:getShaderProgram(),"cc.GLProgram") + local glProgam = sprite:getShaderProgram() if nil ~= glProgam then local p = glProgam:getProgram() local aaSize,aaType,aaName = gl.getActiveAttrib(p,0) diff --git a/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua b/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua index 25fc53ad33..50a5f57099 100644 --- a/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua +++ b/tests/test-lua/Resources/luaScript/PerformanceTest/PerformanceTest.lua @@ -148,7 +148,7 @@ local function runNodeChildrenTest() local function updateQuantityLabel() if nQuantityOfNodes ~= nLastRenderedCount then -- local pInfoLabel = pNewscene:getChildByTag(NodeChildrenTestParam.kTagInfoLayer) - local pInfoLabel = tolua.cast(pNewscene:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") + local pInfoLabel = pNewscene:getChildByTag(NodeChildrenTestParam.kTagInfoLayer) local strNode = nQuantityOfNodes.." nodes" pInfoLabel:setString(strNode) nLastRenderedCount = nQuantityOfNodes @@ -167,7 +167,7 @@ local function runNodeChildrenTest() local i = 0 local len = table.getn(pChildren) for i = 0, len - 1, 1 do - local child = tolua.cast(pChildren[i + 1], "cc.Sprite") + local child = pChildren[i + 1] child:setVisible(false) end end @@ -190,7 +190,7 @@ local function runNodeChildrenTest() end for i = 0 , nTotalToAdd - 1 do - local pChild = tolua.cast(pSprites[i + 1],"cc.Node") + local pChild = pSprites[i + 1] pBatchNode:addChild(pChild, zs[i], NodeChildrenTestParam.kTagBase + i) end @@ -217,7 +217,7 @@ local function runNodeChildrenTest() end -- add them with random Z (very important!) for i=0, nTotalToAdd - 1 do - local pChild = tolua.cast(pSprites[i + 1],"cc.Node") + local pChild = pSprites[i + 1] pBatchNode:addChild(pChild, math.random(-1,1) * 50, NodeChildrenTestParam.kTagBase + i) end @@ -245,7 +245,7 @@ local function runNodeChildrenTest() --dd them with random Z (very important!) for i = 0, nTotalToAdd - 1 do - local pChild = tolua.cast(pSprites[i + 1] ,"cc.Node") + local pChild = pSprites[i + 1] pBatchNode:addChild(pChild, math.random(-1,1) * 50, NodeChildrenTestParam.kTagBase + i) end @@ -253,7 +253,7 @@ local function runNodeChildrenTest() -- reorder them for i = 0, nTotalToAdd - 1 do - local pNode = tolua.cast(pSprites[i + 1],"cc.Node") + local pNode = pSprites[i + 1] pBatchNode:reorderChild(pNode, math.random(-1,1) * 50) end pBatchNode:sortAllChildren() @@ -509,7 +509,7 @@ local function runParticleTest() local function UpdateQuantityLabel() if nQuantityParticles ~= nLastRenderedCount then - local pInfoLabel = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagInfoLayer), "cc.LabelTTF") + local pInfoLabel = pNewScene:getChildByTag(ParticleTestParam.kTagInfoLayer) local strInfo = string.format("%u particles", nQuantityParticles) pInfoLabel:setString(strInfo) @@ -519,7 +519,7 @@ local function runParticleTest() local function doTest() local s = cc.Director:getInstance():getWinSize() - local pParticleSystem = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem),"cc.ParticleSystem") + local pParticleSystem = pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem) if nil == pParticleSystem then return end @@ -764,8 +764,8 @@ local function runParticleTest() end local function step(t) - local pAtlas = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagLabelAtlas),"cc.LabelAtlas") - local pEmitter = tolua.cast(pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem),"cc.ParticleSystem") + local pAtlas = pNewScene:getChildByTag(ParticleTestParam.kTagLabelAtlas) + local pEmitter = pNewScene:getChildByTag(ParticleTestParam.kTagParticleSystem) local strInfo = string.format("%4d",pEmitter:getParticleCount()) pAtlas:setString(strInfo) end @@ -990,7 +990,7 @@ local function runSpriteTest() local function UpdateNodes() if nQuantityNodes ~= nLastRenderedCount then - local pInfoLabel = tolua.cast(pNewScene:getChildByTag(SpriteTestParam.kTagInfoLayer), "cc.LabelTTF") + local pInfoLabel = pNewScene:getChildByTag(SpriteTestParam.kTagInfoLayer) local strInfo = string.format("%u nodes", nQuantityNodes) pInfoLabel:setString(strInfo) nLastRenderedCount = nQuantityNodes @@ -1701,14 +1701,14 @@ local function runFuncRelateWithTable() if quantityOfNodes == 0 then quantityOfNodes = 100 end - local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") + local numLabel = layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer) local strNum = string.format("%d", quantityOfNodes) numLabel:setString(strNum) end local function onIncrease() quantityOfNodes = quantityOfNodes + 100 - local numLabel = tolua.cast(layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer), "cc.LabelTTF") + local numLabel = layer:getChildByTag(NodeChildrenTestParam.kTagInfoLayer) local strNum = string.format("%d", quantityOfNodes) numLabel:setString(strNum) end diff --git a/tests/test-lua/Resources/luaScript/SpriteTest/SpriteTest.lua b/tests/test-lua/Resources/luaScript/SpriteTest/SpriteTest.lua index 29c4dae6aa..7f198756aa 100644 --- a/tests/test-lua/Resources/luaScript/SpriteTest/SpriteTest.lua +++ b/tests/test-lua/Resources/luaScript/SpriteTest/SpriteTest.lua @@ -446,7 +446,7 @@ function SpriteAnchorPoint.initLayer(layer) end point:setPosition( sprite:getPosition() ) - local copy = tolua.cast(action:clone(), "cc.Action") + local copy = action:clone() sprite:runAction(copy) layer:addChild(sprite, i) end @@ -499,7 +499,7 @@ function SpriteBatchNodeAnchorPoint.initLayer(layer) point:setPosition( cc.p(sprite:getPosition()) ) - local copy = tolua.cast(action:clone(), "cc.Action") + local copy = action:clone() sprite:runAction(copy) batch:addChild(sprite, i) end diff --git a/tests/test-lua/Resources/luaScript/Texture2dTest/Texture2dTest.lua b/tests/test-lua/Resources/luaScript/Texture2dTest/Texture2dTest.lua index 66a31b7988..3f58c1f0bd 100644 --- a/tests/test-lua/Resources/luaScript/Texture2dTest/Texture2dTest.lua +++ b/tests/test-lua/Resources/luaScript/Texture2dTest/Texture2dTest.lua @@ -110,7 +110,7 @@ local function TextureMipMap() local scale1 = cc.EaseOut:create(cc.ScaleBy:create(4, 0.01), 3) local sc_back = scale1:reverse() - local scale2 = tolua.cast(scale1:clone(), "cc.EaseOut") + local scale2 = scale1:clone() local sc_back2 = scale2:reverse() img0:runAction(cc.RepeatForever:create(cc.Sequence:create(scale1, sc_back))) @@ -148,7 +148,7 @@ local function TexturePVRMipMap() local scale1 = cc.EaseOut:create(cc.ScaleBy:create(4, 0.01), 3) local sc_back = scale1:reverse() - local scale2 = tolua.cast(scale1:clone(), "cc.EaseOut") + local scale2 = scale1:clone() local sc_back2 = scale2:reverse() imgMipMap:runAction(cc.RepeatForever:create(cc.Sequence:create(scale1, sc_back))) @@ -182,7 +182,7 @@ local function TexturePVRMipMap2() local scale1 = cc.EaseOut:create(cc.ScaleBy:create(4, 0.01), 3) local sc_back = scale1:reverse() - local scale2 = tolua.cast(scale1:clone(), "cc.EaseOut") + local scale2 = scale1:clone() local sc_back2 = scale2:reverse() imgMipMap:runAction(cc.RepeatForever:create(cc.Sequence:create(scale1, sc_back))) @@ -803,9 +803,9 @@ local function TextureAlias() -- scale them to show local sc = cc.ScaleBy:create(3, 8.0) - local sc_back = tolua.cast(sc:reverse(), "cc.ScaleBy") + local sc_back = sc:reverse() local scaleforever = cc.RepeatForever:create(cc.Sequence:create(sc, sc_back)) - local scaleToo = tolua.cast(scaleforever:clone(), "cc.RepeatForever") + local scaleToo = scaleforever:clone() sprite2:runAction(scaleforever) sprite:runAction(scaleToo) @@ -829,7 +829,7 @@ local function TexturePixelFormat() -- 3- 16-bit RGB5A1 -- 4- 16-bit RGB565 - local label = tolua.cast(ret:getChildByTag(kTagLabel), "cc.LabelTTF") + local label = ret:getChildByTag(kTagLabel) label:setColor(cc.c3b(16,16,255)) local s = cc.Director:getInstance():getWinSize() @@ -895,10 +895,10 @@ local function TexturePixelFormat() local fadein = cc.FadeIn:create(2) local seq = cc.Sequence:create(cc.DelayTime:create(2), fadeout, fadein) local seq_4ever = cc.RepeatForever:create(seq) - local seq_4ever2 = tolua.cast(seq_4ever:clone(), "cc.RepeatForever") - local seq_4ever3 = tolua.cast(seq_4ever:clone(), "cc.RepeatForever") - local seq_4ever4 = tolua.cast(seq_4ever:clone(), "cc.RepeatForever") - local seq_4ever5 = tolua.cast(seq_4ever:clone(), "cc.RepeatForever") + local seq_4ever2 = seq_4ever:clone() + local seq_4ever3 = seq_4ever:clone() + local seq_4ever4 = seq_4ever:clone() + local seq_4ever5 = seq_4ever:clone() sprite1:runAction(seq_4ever) sprite2:runAction(seq_4ever2) @@ -964,12 +964,12 @@ local function TextureAsync() ret:addChild(label, 10) local scale = cc.ScaleBy:create(0.3, 2) - local scale_back = tolua.cast(scale:reverse(), "cc.ScaleBy") + local scale_back = scale:reverse() local seq = cc.Sequence:create(scale, scale_back) label:runAction(cc.RepeatForever:create(seq)) local function imageLoaded(pObj) - local tex = tolua.cast(pObj, "cc.Texture2D") + local tex = pObj local director = cc.Director:getInstance() --cc.ASSERT( [NSThread currentThread] == [director runningThread], @"FAIL. Callback should be on cocos2d thread") @@ -1043,7 +1043,7 @@ local function TextureGlClamp() local rotate = cc.RotateBy:create(4, 360) sprite:runAction(rotate) local scale = cc.ScaleBy:create(2, 0.04) - local scaleBack = tolua.cast(scale:reverse(), "cc.ScaleBy") + local scaleBack = scale:reverse() local seq = cc.Sequence:create(scale, scaleBack) sprite:runAction(seq) local function onNodeEvent(event) @@ -1077,7 +1077,7 @@ local function TextureGlRepeat() local rotate = cc.RotateBy:create(4, 360) sprite:runAction(rotate) local scale = cc.ScaleBy:create(2, 0.04) - local scaleBack = tolua.cast(scale:reverse(), "cc.ScaleBy") + local scaleBack = scale:reverse() local seq = cc.Sequence:create(scale, scaleBack) sprite:runAction(seq) local function onNodeEvent(event) @@ -1338,7 +1338,7 @@ local function TexturePVRv3Premult() local function transformSprite(sprite) local fade = cc.FadeOut:create(2) local dl = cc.DelayTime:create(2) - local fadein = tolua.cast(fade:reverse(), "cc.FadeOut") + local fadein = fade:reverse() local seq = cc.Sequence:create(fade, fadein, dl) local repeatAction = cc.RepeatForever:create(seq) sprite:runAction(repeatAction) diff --git a/tests/test-lua/Resources/luaScript/TileMapTest/TileMapTest.lua b/tests/test-lua/Resources/luaScript/TileMapTest/TileMapTest.lua index 69d394373a..5788678632 100644 --- a/tests/test-lua/Resources/luaScript/TileMapTest/TileMapTest.lua +++ b/tests/test-lua/Resources/luaScript/TileMapTest/TileMapTest.lua @@ -82,7 +82,7 @@ local function TileMapEditTest() -- The only limitation is that you cannot change an empty, or assign an empty tile to a tile -- The value 0 not rendered so don't assign or change a tile with value 0 - local tilemap = tolua.cast(layer:getChildByTag(kTagTileMap), "cc.TileMapAtlas") + local tilemap = layer:getChildByTag(kTagTileMap) -- -- For example you can iterate over all the tiles @@ -157,7 +157,7 @@ local function TMXOrthoTest() local len = table.getn(pChildrenArray) for i = 0, len-1, 1 do pObject = pChildrenArray[i + 1] - child = tolua.cast(pObject, "cc.SpriteBatchNode") + child = pObject if child == nil then break @@ -211,7 +211,7 @@ local function TMXOrthoTest2() local len = table.getn(pChildrenArray) for i = 0, len-1, 1 do - child = tolua.cast(pChildrenArray[i + 1], "cc.SpriteBatchNode") + child = pChildrenArray[i + 1] if child == nil then break @@ -243,7 +243,7 @@ local function TMXOrthoTest3() local len = table.getn(pChildrenArray) for i = 0, len-1, 1 do - child = tolua.cast(pChildrenArray[i + 1], "cc.SpriteBatchNode") + child = pChildrenArray[i + 1] if child == nil then break @@ -277,7 +277,7 @@ local function TMXOrthoTest4() local len = table.getn(pChildrenArray) for i = 0, len-1, 1 do - child = tolua.cast(pChildrenArray[i + 1], "cc.SpriteBatchNode") + child = pChildrenArray[i + 1] if child == nil then break @@ -304,7 +304,7 @@ local function TMXOrthoTest4() local function removeSprite(dt) scheduler:unscheduleScriptEntry(schedulerEntry) schedulerEntry = nil - local map = tolua.cast(ret:getChildByTag(kTagTileMap), "cc.TMXTiledMap") + local map = ret:getChildByTag(kTagTileMap) local layer0 = map:getLayer("Layer 0") local s = layer0:getLayerSize() @@ -368,7 +368,7 @@ local function TMXReadWriteTest() local function removeSprite(sender) --------cclog("removing tile: %x", sender) - local node = tolua.cast(sender, "cc.Node") + local node = sender if nil == node then print("Errro node is nil") end @@ -382,9 +382,9 @@ local function TMXReadWriteTest() local finish = cc.CallFunc:create(removeSprite) local seq0 = cc.Sequence:create(move, rotate, scale, opacity, fadein, scaleback, finish) - local seq1 = tolua.cast(seq0:clone(), "cc.Action") - local seq2 = tolua.cast(seq0:clone(), "cc.Action") - local seq3 = tolua.cast(seq0:clone(), "cc.Action") + local seq1 = seq0:clone() + local seq2 = seq0:clone() + local seq3 = seq0:clone() tile0:runAction(seq0) tile1:runAction(seq1) @@ -400,8 +400,8 @@ local function TMXReadWriteTest() local function updateCol(dt) - local map = tolua.cast(ret:getChildByTag(kTagTileMap), "cc.TMXTiledMap") - local layer = tolua.cast(map:getChildByTag(0), "cc.TMXLayer") + local map = ret:getChildByTag(kTagTileMap) + local layer = map:getChildByTag(0) --------cclog("++++atlas quantity: %d", layer:textureAtlas():getTotalQuads()) --------cclog("++++children: %d", layer:getChildren():count() ) @@ -418,8 +418,8 @@ local function TMXReadWriteTest() local function repaintWithGID(dt) -- unschedule:_cmd) - local map = tolua.cast(ret:getChildByTag(kTagTileMap), "cc.TMXTiledMap") - local layer = tolua.cast(map:getChildByTag(0), "cc.TMXLayer") + local map = ret:getChildByTag(kTagTileMap) + local layer = map:getChildByTag(0) local s = layer:getLayerSize() local x = 0 @@ -433,8 +433,8 @@ local function TMXReadWriteTest() local function removeTiles(dt) scheduler:unscheduleScriptEntry(removeTilesScheduler) removeTilesScheduler = nil - local map = tolua.cast(ret:getChildByTag(kTagTileMap), "cc.TMXTiledMap") - local layer = tolua.cast(map:getChildByTag(0), "cc.TMXLayer") + local map = ret:getChildByTag(kTagTileMap) + local layer = map:getChildByTag(0) local s = layer:getLayerSize() local y = 0 for y=0, s.height-1, 1 do @@ -580,7 +580,7 @@ local function TMXUncompressedTest() local i = 0 local len = table.getn(pChildrenArray) for i = 0, len-1, 1 do - layer = tolua.cast(pChildrenArray[i + 1], "cc.TMXLayer") + layer = pChildrenArray[i + 1] if layer == nil then break end @@ -648,43 +648,6 @@ local function TMXOrthoObjectsTest() --------cclog("platform: %x", platform) return ret end - -local function draw() - - local map = tolua.cast(getChildByTag(kTagTileMap), "cc.TMXTiledMap") - local group = map:getObjectGroup("Object Group 1") - - local objects = group:getObjects() - local dict = nil - local i = 0 - local len = table.getn(objects) - for i = 0, len-1, 1 do - dict = objects[i + 1] - - if dict == nil then - break - end - - local key = "x" - local x = dict["x"] - key = "y" - local y = dict["y"]--dynamic_cast(dict:objectForKey("y")):getNumber() - key = "width" - local width = dict["width"]--dynamic_cast(dict:objectForKey("width")):getNumber() - key = "height" - local height = dict["height"]--dynamic_cast(dict:objectForKey("height")):getNumber() - - glLineWidth(3) - - cc.DrawPrimitives.drawLine( cc.p(x, y), cc.p((x+width), y) ) - cc.DrawPrimitives.drawLine( cc.p((x+width), y), cc.p((x+width), (y+height)) ) - cc.DrawPrimitives.drawLine( cc.p((x+width), (y+height)), cc.p(x, (y+height)) ) - cc.DrawPrimitives.drawLine( cc.p(x, (y+height)), cc.p(x, y) ) - - glLineWidth(1) - end -end - -------------------------------------------------------------------- -- -- TMXIsoObjectsTest @@ -704,56 +667,9 @@ local function TMXIsoObjectsTest() --UxMutableArray* objects = group:objects() local objects = group:getObjects() --UxMutableDictionary* dict - local dict = nil - local i = 0 - local len = table.getn(objects) - for i = 0, len-1, 1 do - dict = tolua.cast(objects[i + 1], "cc.Dictionary") - - if dict == nil then - break - end - --------cclog("object: %x", dict) - end return ret end -local function draw() - - local map = tolua.cast(getChildByTag(kTagTileMap), "cc.TMXTiledMap") - local group = map:getObjectGroup("Object Group 1") - - local objects = group:getObjects() - local dict = nil - local i = 0 - local len = table.getn(objects) - for i = 0, len-1, 1 do - dict = tolua.cast(objects[i + 1], "cc.Dictionary") - - if dict == nil then - break - end - - local key = "x" - local x = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast(dict:objectForKey("x")):getNumber() - key = "y" - local y = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast(dict:objectForKey("y")):getNumber() - key = "width" - local width = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast(dict:objectForKey("width")):getNumber() - key = "height" - local height = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast(dict:objectForKey("height")):getNumber() - - glLineWidth(3) - - cc.DrawPrimitives.drawLine( cc.p(x,y), cc.p(x+width,y) ) - cc.DrawPrimitives.drawLine( cc.p(x+width,y), cc.p(x+width,y+height) ) - cc.DrawPrimitives.drawLine( cc.p(x+width,y+height), cc.p(x,y+height) ) - cc.DrawPrimitives.drawLine( cc.p(x,y+height), cc.p(x,y) ) - - glLineWidth(1) - end -end - -------------------------------------------------------------------- -- -- TMXResizeTest @@ -1073,7 +989,7 @@ local function TMXOrthoFlipTest() local i = 0 for i = 0, table.getn(map:getChildren())-1, 1 do - local child = tolua.cast(map:getChildren()[i + 1], "cc.SpriteBatchNode") + local child = map:getChildren()[i + 1] child:getTexture():setAntiAliasTexParameters() end @@ -1098,7 +1014,7 @@ local function TMXOrthoFlipRunTimeTest() local i = 0 for i = 0, table.getn(map:getChildren())-1, 1 do - local child = tolua.cast(map:getChildren()[i + 1], "cc.SpriteBatchNode") + local child = map:getChildren()[i + 1] child:getTexture():setAntiAliasTexParameters() end @@ -1178,7 +1094,7 @@ local function TMXOrthoFromXMLTest() local i = 0 local len = table.getn(map:getChildren()) for i = 0, len-1, 1 do - local child = tolua.cast(map:getChildren()[i + 1], "cc.SpriteBatchNode") + local child = map:getChildren()[i + 1] child:getTexture():setAntiAliasTexParameters() end @@ -1206,7 +1122,7 @@ local function TMXBug987() local len = table.getn(childs) local pNode = nil for i = 0, len-1, 1 do - pNode = tolua.cast(childs[i + 1], "cc.TMXLayer") + pNode = childs[i + 1] if pNode == nil then break end From 8ca746af176229b317848e2935873b618426aa68 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Sat, 22 Feb 2014 17:47:56 -0800 Subject: [PATCH 05/21] Implements AABB culling for sprites --- cocos/2d/CCDirector.cpp | 14 -------- cocos/2d/CCDirector.h | 9 ----- cocos/2d/CCSprite.cpp | 34 ++++++------------- cocos/math/kazmath/include/kazmath/kazmath.h | 1 + .../SpriteTest/SpriteTest.cpp.REMOVED.git-id | 2 +- .../test-cpp/Classes/SpriteTest/SpriteTest.h | 18 ++++++++++ 6 files changed, 31 insertions(+), 47 deletions(-) diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index 64a6696dd6..f297097529 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -59,7 +59,6 @@ THE SOFTWARE. #include "CCEventCustom.h" #include "CCFontFreeType.h" #include "renderer/CCRenderer.h" -#include "renderer/CCFrustum.h" #include "CCConsole.h" #include "kazmath/kazmath.h" @@ -134,8 +133,6 @@ bool Director::init(void) _openGLView = nullptr; - _cullingFrustum = new Frustum(); - _contentScaleFactor = 1.0f; // scheduler @@ -277,16 +274,6 @@ void Director::drawScene() kmGLPushMatrix(); - //construct the frustum - { - kmMat4 view; - kmMat4 projection; - kmGLGetMatrix(KM_GL_PROJECTION, &projection); - kmGLGetMatrix(KM_GL_MODELVIEW, &view); - - _cullingFrustum->setupFromMatrix(view, projection); - } - // draw the scene if (_runningScene) { @@ -743,7 +730,6 @@ void Director::purgeDirector() CC_SAFE_RELEASE_NULL(_FPSLabel); CC_SAFE_RELEASE_NULL(_drawnBatchesLabel); CC_SAFE_RELEASE_NULL(_drawnVerticesLabel); - CC_SAFE_DELETE(_cullingFrustum); // purge bitmap cache FontFNT::purgeCachedData(); diff --git a/cocos/2d/CCDirector.h b/cocos/2d/CCDirector.h index d2f602959e..f6c8e1f6e1 100644 --- a/cocos/2d/CCDirector.h +++ b/cocos/2d/CCDirector.h @@ -58,7 +58,6 @@ class EventDispatcher; class EventCustom; class EventListenerCustom; class TextureCache; -class Frustum; class Renderer; class Console; @@ -330,12 +329,6 @@ public: */ void setContentScaleFactor(float scaleFactor); float getContentScaleFactor() const { return _contentScaleFactor; } - - /** - Get the Culling Frustum - */ - - Frustum* getFrustum() const { return _cullingFrustum; } /** Gets the Scheduler associated with this director @since v2.0 @@ -450,8 +443,6 @@ protected: unsigned int _frames; float _secondsPerFrame; - Frustum *_cullingFrustum; - /* The running scene */ Scene *_runningScene; diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index d19452b5bb..754d2bcb25 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -45,12 +45,14 @@ THE SOFTWARE. #include "CCAffineTransform.h" #include "TransformUtils.h" #include "CCProfiling.h" +#include "CCDirector.h" #include "renderer/CCRenderer.h" #include "renderer/CCQuadCommand.h" #include "renderer/CCFrustum.h" // external #include "kazmath/GL/matrix.h" +#include "kazmath/kazmath.h" using namespace std; @@ -605,38 +607,24 @@ void Sprite::updateTransform(void) void Sprite::draw(void) { - //TODO implement z order - _quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); - -// if(culling()) + if(culling()) { + _quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); Director::getInstance()->getRenderer()->addCommand(&_quadCommand); } } +// Culling function from cocos2d-iphone CCSprite.m file bool Sprite::culling() const { - Frustum* frustum = Director::getInstance()->getFrustum(); - //TODO optimize this transformation, should use parent's transformation instead - kmMat4 worldTM = getNodeToWorldTransform(); - //generate aabb + Size s = Director::getInstance()->getWinSize(); + kmVec3 v3 = {_contentSize.width*0.5f, _contentSize.height*0.5f, 0}; + kmVec3Transform(&v3, &v3, &_modelViewTransform); - // - // calculate the Quad based on the Affine Matrix - // - Rect newRect = RectApplyTransform(_rect, worldTM); + float cshw = _contentSize.width * fmaxf(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4])); + float cshh = _contentSize.height * fmaxf(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5])); - kmVec3 point = {newRect.getMinX(), newRect.getMinY(), _vertexZ}; - - AABB aabb(point,point); - kmVec3Fill(&point,newRect.getMaxX(), newRect.getMinY(), _vertexZ); - aabb.expand(point); - kmVec3Fill(&point,newRect.getMinX(), newRect.getMaxY(), _vertexZ); - aabb.expand(point); - kmVec3Fill(&point,newRect.getMaxX(), newRect.getMaxY(), _vertexZ); - aabb.expand(point); - - return Frustum::IntersectResult::OUTSIDE !=frustum->intersectAABB(aabb); + return ( (fabsf(v3.x)-cshw) < s.width/2 && (fabsf(v3.y)-cshh) < s.height/2); } void Sprite::updateQuadVertices() diff --git a/cocos/math/kazmath/include/kazmath/kazmath.h b/cocos/math/kazmath/include/kazmath/kazmath.h index ef09870bdd..fcd63b4e2e 100644 --- a/cocos/math/kazmath/include/kazmath/kazmath.h +++ b/cocos/math/kazmath/include/kazmath/kazmath.h @@ -28,6 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "vec2.h" #include "vec3.h" +#include "vec4.h" #include "mat3.h" #include "mat4.h" #include "utility.h" diff --git a/tests/test-cpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id b/tests/test-cpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id index a0be51dd8c..e3d8aeba62 100644 --- a/tests/test-cpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id +++ b/tests/test-cpp/Classes/SpriteTest/SpriteTest.cpp.REMOVED.git-id @@ -1 +1 @@ -dc22a9c6f7fee22f731cfe145212770b9a43b393 \ No newline at end of file +d381f5336bd2e06ba65eb51a5204c12eebe49c4e \ No newline at end of file diff --git a/tests/test-cpp/Classes/SpriteTest/SpriteTest.h b/tests/test-cpp/Classes/SpriteTest/SpriteTest.h index ac232f7a86..11b25539a6 100644 --- a/tests/test-cpp/Classes/SpriteTest/SpriteTest.h +++ b/tests/test-cpp/Classes/SpriteTest/SpriteTest.h @@ -731,6 +731,24 @@ public: virtual std::string subtitle() const override; }; +class SpriteCullTest1 : public SpriteTestDemo +{ +public: + CREATE_FUNC(SpriteCullTest1); + SpriteCullTest1(); + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + +class SpriteCullTest2 : public SpriteTestDemo +{ +public: + CREATE_FUNC(SpriteCullTest2); + SpriteCullTest2(); + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + class SpriteTestScene : public TestScene { public: From f37c606c4e6cbee038df92b9150c3bdd951c6a25 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Sat, 22 Feb 2014 17:55:03 -0800 Subject: [PATCH 06/21] removes unsued function keeps the code cleaner --- cocos/2d/CCSprite.cpp | 39 --------------------------------------- cocos/2d/CCSprite.h | 1 - 2 files changed, 40 deletions(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 754d2bcb25..423670ccb0 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -627,46 +627,7 @@ bool Sprite::culling() const return ( (fabsf(v3.x)-cshw) < s.width/2 && (fabsf(v3.y)-cshh) < s.height/2); } -void Sprite::updateQuadVertices() -{ -#if CC_USE_PHYSICS - updatePhysicsTransform(); - setDirty(true); -#endif - //TODO optimize the performance cache affineTransformation - - // recalculate matrix only if it is dirty - if(isDirty()) - { - -// if( ! _parent || _parent == (Node*)_batchNode ) -// { -// _transformToBatch = getNodeToParentTransform(); -// } -// else -// { -// CCASSERT( dynamic_cast(_parent), "Logic error in Sprite. Parent must be a Sprite"); -// _transformToBatch = AffineTransformConcat( getNodeToParentTransform() , static_cast(_parent)->_transformToBatch ); -// } - - //TODO optimize this transformation, should use parent's transformation instead - _transformToBatch = getNodeToWorldTransform(); - - // - // calculate the Quad based on the Affine Matrix - // - Rect newRect = RectApplyTransform(_rect, _transformToBatch); - - _quad.bl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMinX()), RENDER_IN_SUBPIXEL(newRect.getMinY()), _vertexZ ); - _quad.br.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMaxX()), RENDER_IN_SUBPIXEL(newRect.getMinY()), _vertexZ ); - _quad.tl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMinX()), RENDER_IN_SUBPIXEL(newRect.getMaxY()), _vertexZ ); - _quad.tr.vertices = Vertex3F( RENDER_IN_SUBPIXEL(newRect.getMaxX()), RENDER_IN_SUBPIXEL(newRect.getMaxY()), _vertexZ ); - - _recursiveDirty = false; - setDirty(false); - } -} // Node overrides diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index 2081ef8336..5510a00d46 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -423,7 +423,6 @@ public: virtual void setAnchorPoint(const Point& anchor) override; virtual void ignoreAnchorPointForPosition(bool value) override; virtual void setVisible(bool bVisible) override; - virtual void updateQuadVertices(); virtual void draw(void) override; virtual void setOpacityModifyRGB(bool modify) override; virtual bool isOpacityModifyRGB(void) const override; From fe1160cd8c246bf1ca7fe3d68ba2adc70a540eeb Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Sat, 22 Feb 2014 19:16:42 -0800 Subject: [PATCH 07/21] changes in API to support 3D --- cocos/2d/CCActionInterval.cpp | 102 ++++++++--- cocos/2d/CCActionInterval.h | 20 +- cocos/2d/CCDirector.cpp | 3 +- cocos/2d/CCLayer.cpp | 2 +- cocos/2d/CCNode.cpp | 173 +++++++++++++----- cocos/2d/CCNode.h | 121 +++++++----- cocos/2d/CCSprite.cpp | 8 +- cocos/editor-support/cocostudio/CCSkin.cpp | 8 +- .../Classes/ActionsTest/ActionsTest.cpp | 28 +++ .../Classes/ActionsTest/ActionsTest.h | 103 ++++++----- 10 files changed, 396 insertions(+), 172 deletions(-) diff --git a/cocos/2d/CCActionInterval.cpp b/cocos/2d/CCActionInterval.cpp index a8a48f4081..293dcdb471 100644 --- a/cocos/2d/CCActionInterval.cpp +++ b/cocos/2d/CCActionInterval.cpp @@ -747,7 +747,7 @@ void RotateTo::startWithTarget(Node *target) ActionInterval::startWithTarget(target); // Calculate X - _startAngleX = target->getRotationX(); + _startAngleX = target->getRotationSkewX(); if (_startAngleX > 0) { _startAngleX = fmodf(_startAngleX, 360.0f); @@ -768,7 +768,7 @@ void RotateTo::startWithTarget(Node *target) } //Calculate Y: It's duplicated from calculating X since the rotation wrap should be the same - _startAngleY = _target->getRotationY(); + _startAngleY = _target->getRotationSkewY(); if (_startAngleY > 0) { @@ -795,8 +795,8 @@ void RotateTo::update(float time) { if (_target) { - _target->setRotationX(_startAngleX + _diffAngleX * time); - _target->setRotationY(_startAngleY + _diffAngleY * time); + _target->setRotationSkewX(_startAngleX + _diffAngleX * time); + _target->setRotationSkewY(_startAngleY + _diffAngleY * time); } } @@ -819,17 +819,6 @@ RotateBy* RotateBy::create(float duration, float deltaAngle) return rotateBy; } -bool RotateBy::initWithDuration(float duration, float deltaAngle) -{ - if (ActionInterval::initWithDuration(duration)) - { - _angleX = _angleY = deltaAngle; - return true; - } - - return false; -} - RotateBy* RotateBy::create(float duration, float deltaAngleX, float deltaAngleY) { RotateBy *rotateBy = new RotateBy(); @@ -839,23 +828,64 @@ RotateBy* RotateBy::create(float duration, float deltaAngleX, float deltaAngleY) return rotateBy; } +RotateBy* RotateBy::create(float duration, const Vertex3F& deltaAngle3D) +{ + RotateBy *rotateBy = new RotateBy(); + rotateBy->initWithDuration(duration, deltaAngle3D); + rotateBy->autorelease(); + + return rotateBy; +} + +RotateBy::RotateBy() +: _is3D(false) +{ +} + +bool RotateBy::initWithDuration(float duration, float deltaAngle) +{ + if (ActionInterval::initWithDuration(duration)) + { + _angleZ_X = _angleZ_Y = deltaAngle; + return true; + } + + return false; +} + bool RotateBy::initWithDuration(float duration, float deltaAngleX, float deltaAngleY) { if (ActionInterval::initWithDuration(duration)) { - _angleX = deltaAngleX; - _angleY = deltaAngleY; + _angleZ_X = deltaAngleX; + _angleZ_Y = deltaAngleY; return true; } return false; } +bool RotateBy::initWithDuration(float duration, const Vertex3F& deltaAngle3D) +{ + if (ActionInterval::initWithDuration(duration)) + { + _angle3D = deltaAngle3D; + _is3D = true; + return true; + } + + return false; +} + + RotateBy* RotateBy::clone(void) const { // no copy constructor auto a = new RotateBy(); - a->initWithDuration(_duration, _angleX, _angleY); + if(_is3D) + a->initWithDuration(_duration, _angle3D); + else + a->initWithDuration(_duration, _angleZ_X, _angleZ_Y); a->autorelease(); return a; } @@ -863,8 +893,15 @@ RotateBy* RotateBy::clone(void) const void RotateBy::startWithTarget(Node *target) { ActionInterval::startWithTarget(target); - _startAngleX = target->getRotationX(); - _startAngleY = target->getRotationY(); + if(_is3D) + { + _startAngle3D = target->getRotation3D(); + } + else + { + _startAngleZ_X = target->getRotationSkewX(); + _startAngleZ_Y = target->getRotationSkewY(); + } } void RotateBy::update(float time) @@ -872,14 +909,33 @@ void RotateBy::update(float time) // XXX: shall I add % 360 if (_target) { - _target->setRotationX(_startAngleX + _angleX * time); - _target->setRotationY(_startAngleY + _angleY * time); + if(_is3D) + { + Vertex3F v; + v.x = _startAngle3D.x + _angle3D.x * time; + v.y = _startAngle3D.y + _angle3D.y * time; + v.z = _startAngle3D.z + _angle3D.z * time; + _target->setRotation3D(v); + } + else + { + _target->setRotationSkewX(_startAngleZ_X + _angleZ_X * time); + _target->setRotationSkewY(_startAngleZ_Y + _angleZ_Y * time); + } } } RotateBy* RotateBy::reverse() const { - return RotateBy::create(_duration, -_angleX, -_angleY); + if(_is3D) + { + Vertex3F v; + v.x = - _angle3D.x; + v.y = - _angle3D.y; + v.z = - _angle3D.z; + return RotateBy::create(_duration, v); + } + return RotateBy::create(_duration, -_angleZ_X, -_angleZ_Y); } // diff --git a/cocos/2d/CCActionInterval.h b/cocos/2d/CCActionInterval.h index e88331d309..8867315496 100644 --- a/cocos/2d/CCActionInterval.h +++ b/cocos/2d/CCActionInterval.h @@ -322,7 +322,8 @@ class CC_DLL RotateBy : public ActionInterval public: /** creates the action */ static RotateBy* create(float duration, float deltaAngle); - static RotateBy* create(float duration, float deltaAngleX, float deltaAngleY); + static RotateBy* create(float duration, float deltaAngleZ_X, float deltaAngleZ_Y); + static RotateBy* create(float duration, const Vertex3F& deltaAngle3D); // // Override @@ -333,16 +334,21 @@ public: virtual void update(float time) override; protected: - RotateBy() {} + RotateBy(); virtual ~RotateBy() {} /** initializes the action */ bool initWithDuration(float duration, float deltaAngle); - bool initWithDuration(float duration, float deltaAngleX, float deltaAngleY); + bool initWithDuration(float duration, float deltaAngleZ_X, float deltaAngleZ_Y); + bool initWithDuration(float duration, const Vertex3F& deltaAngle3D); - float _angleX; - float _startAngleX; - float _angleY; - float _startAngleY; + float _angleZ_X; + float _startAngleZ_X; + float _angleZ_Y; + float _startAngleZ_Y; + + bool _is3D; + Vertex3F _angle3D; + Vertex3F _startAngle3D; private: CC_DISALLOW_COPY_AND_ASSIGN(RotateBy); diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index f297097529..1261663340 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -59,6 +59,7 @@ THE SOFTWARE. #include "CCEventCustom.h" #include "CCFontFreeType.h" #include "renderer/CCRenderer.h" +#include "renderer/CCFrustum.h" #include "CCConsole.h" #include "kazmath/kazmath.h" @@ -446,7 +447,7 @@ void Director::setProjection(Projection projection) kmGLLoadIdentity(); // issue #1334 - kmMat4PerspectiveProjection(&matrixPerspective, 60, (GLfloat)size.width/size.height, 0.1f, zeye*2); + kmMat4PerspectiveProjection(&matrixPerspective, 60, (GLfloat)size.width/size.height, 10, zeye+size.height/2); // kmMat4PerspectiveProjection( &matrixPerspective, 60, (GLfloat)size.width/size.height, 0.1f, 1500); kmGLMultMatrix(&matrixPerspective); diff --git a/cocos/2d/CCLayer.cpp b/cocos/2d/CCLayer.cpp index 8f26de126f..d71fb67d84 100644 --- a/cocos/2d/CCLayer.cpp +++ b/cocos/2d/CCLayer.cpp @@ -590,7 +590,7 @@ void LayerColor::draw() for(int i = 0; i < 4; ++i) { kmVec3 pos; - pos.x = _squareVertices[i].x; pos.y = _squareVertices[i].y; pos.z = _vertexZ; + pos.x = _squareVertices[i].x; pos.y = _squareVertices[i].y; pos.z = _positionZ; kmVec3TransformCoord(&pos, &pos, &_modelViewTransform); _noMVPVertices[i] = Vertex3F(pos.x,pos.y,pos.z); } diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 35cd8ce00c..b2e0b56ca3 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -77,9 +77,12 @@ static int s_globalOrderOfArrival = 1; Node::Node(void) : _rotationX(0.0f) , _rotationY(0.0f) +, _rotationZ_X(0.0f) +, _rotationZ_Y(0.0f) , _scaleX(1.0f) , _scaleY(1.0f) -, _vertexZ(0.0f) +, _scaleZ(1.0f) +, _positionZ(0.0f) , _position(Point::ZERO) , _skewX(0.0f) , _skewY(0.0f) @@ -230,32 +233,17 @@ void Node::setGlobalZOrder(float globalZOrder) } } -/// vertexZ getter -float Node::getVertexZ() const -{ - return _vertexZ; -} - - -/// vertexZ setter -void Node::setVertexZ(float zOrder) -{ - _vertexZ = zOrder; - setGlobalZOrder(zOrder); -} - - /// rotation getter float Node::getRotation() const { - CCASSERT(_rotationX == _rotationY, "CCNode#rotation. RotationX != RotationY. Don't know which one to return"); - return _rotationX; + CCASSERT(_rotationZ_X == _rotationZ_Y, "CCNode#rotation. RotationX != RotationY. Don't know which one to return"); + return _rotationZ_X; } /// rotation setter void Node::setRotation(float newRotation) { - _rotationX = _rotationY = newRotation; + _rotationZ_X = _rotationZ_Y = newRotation; _transformDirty = _inverseDirty = true; #if CC_USE_PHYSICS @@ -266,25 +254,51 @@ void Node::setRotation(float newRotation) #endif } -float Node::getRotationX() const +float Node::getRotationSkewX() const { - return _rotationX; + return _rotationZ_X; } -void Node::setRotationX(float fRotationX) +void Node::setRotation3D(const Vertex3F& rotation) { - _rotationX = fRotationX; + _transformDirty = _inverseDirty = true; + + _rotationX = rotation.x; + _rotationY = rotation.y; + + // rotation Z is decomposed in 2 to simulate Skew for Flash animations + _rotationZ_Y = _rotationZ_X = rotation.z; + +#if CC_USE_PHYSICS + if (_physicsBody) + { + _physicsBody->setRotation(_rotationZ_X); + } +#endif +} + +Vertex3F Node::getRotation3D() const +{ + // rotation Z is decomposed in 2 to simulate Skew for Flash animations + CCASSERT(_rotationZ_X == _rotationZ_Y, "_rotationZ_X != _rotationZ_Y"); + + return Vertex3F(_rotationX,_rotationY,_rotationZ_X); +} + +void Node::setRotationSkewX(float fRotationX) +{ + _rotationZ_X = fRotationX; _transformDirty = _inverseDirty = true; } -float Node::getRotationY() const +float Node::getRotationSkewY() const { - return _rotationY; + return _rotationZ_Y; } -void Node::setRotationY(float rotationY) +void Node::setRotationSkewY(float rotationY) { - _rotationY = rotationY; + _rotationZ_Y = rotationY; _transformDirty = _inverseDirty = true; } @@ -329,6 +343,19 @@ float Node::getScaleY() const return _scaleY; } +/// scaleY setter +void Node::setScaleZ(float newScaleZ) +{ + _scaleZ = newScaleZ; + _transformDirty = _inverseDirty = true; +} + +/// scaleY getter +float Node::getScaleZ() const +{ + return _scaleZ; +} + /// scaleY setter void Node::setScaleY(float newScaleY) { @@ -336,6 +363,7 @@ void Node::setScaleY(float newScaleY) _transformDirty = _inverseDirty = true; } + /// position getter const Point& Node::getPosition() const { @@ -367,26 +395,72 @@ void Node::setPosition(float x, float y) setPosition(Point(x, y)); } +void Node::setPosition3D(const Vertex3F& position) +{ + _positionZ = position.z; + setPosition(Point(position.x, position.y)); +} + +Vertex3F Node::getPosition3D() const +{ + Vertex3F ret; + ret.x = _position.x; + ret.y = _position.y; + ret.z = _positionZ; + return ret; +} + float Node::getPositionX() const { return _position.x; } -float Node::getPositionY() const -{ - return _position.y; -} - void Node::setPositionX(float x) { setPosition(Point(x, _position.y)); } +float Node::getPositionY() const +{ + return _position.y; +} + void Node::setPositionY(float y) { setPosition(Point(_position.x, y)); } +float Node::getPositionZ() const +{ + return _positionZ; +} + +void Node::setPositionZ(float positionZ) +{ + _transformDirty = _inverseDirty = true; + + _positionZ = positionZ; + + // XXX BUG + // Global Z Order should based on the modelViewTransform + setGlobalZOrder(positionZ); +} + +void Node::setNormalizedPosition(const cocos2d::Point &position) +{ + _normalizedPosition = position; + Size s = Director::getInstance()->getVisibleSize(); + Point p; + p.x = s.width * position.x; + p.y = s.height * position.y; + setPosition(p); +} + +const Point& Node::getNormalizedPosition() const +{ + return _normalizedPosition; +} + ssize_t Node::getChildrenCount() const { return _children.size(); @@ -1139,6 +1213,7 @@ const kmMat4& Node::getNodeToParentTransform() const // Translate values float x = _position.x; float y = _position.y; + float z = _positionZ; if (_ignoreAnchorPointForPosition) { @@ -1150,10 +1225,10 @@ const kmMat4& Node::getNodeToParentTransform() const // Change rotation code to handle X and Y // If we skew with the exact same value for both x and y then we're simply just rotating float cx = 1, sx = 0, cy = 1, sy = 0; - if (_rotationX || _rotationY) + if (_rotationZ_X || _rotationZ_Y) { - float radiansX = -CC_DEGREES_TO_RADIANS(_rotationX); - float radiansY = -CC_DEGREES_TO_RADIANS(_rotationY); + float radiansX = -CC_DEGREES_TO_RADIANS(_rotationZ_X); + float radiansY = -CC_DEGREES_TO_RADIANS(_rotationZ_Y); cx = cosf(radiansX); sx = sinf(radiansX); cy = cosf(radiansY); @@ -1175,13 +1250,28 @@ const kmMat4& Node::getNodeToParentTransform() const // Build Transform Matrix // Adjusted transform calculation for rotational skew - kmScalar mat[] = { cy * _scaleX, sy * _scaleX, 0, 0, - -sx * _scaleY, cx * _scaleY, 0, 0, - 0, 0, 1, 0, - x, y, 0, 1 }; + kmScalar mat[] = { + cy * _scaleX, sy * _scaleX, 0, 0, + -sx * _scaleY, cx * _scaleY, 0, 0, + 0, 0, _scaleZ, 0, + x, y, z, 1 }; kmMat4Fill(&_transform, mat); + // XXX + // FIX ME: Expensive operation. + // FIX ME: It should be done together with the rotationZ + if(_rotationY) { + kmMat4 rotY; + kmMat4RotationY(&rotY,CC_DEGREES_TO_RADIANS(_rotationY)); + kmMat4Multiply(&_transform, &_transform, &rotY); + } + if(_rotationX) { + kmMat4 rotX; + kmMat4RotationX(&rotX,CC_DEGREES_TO_RADIANS(_rotationX)); + kmMat4Multiply(&_transform, &_transform, &rotX); + } + // XXX: Try to inline skew // If skew is needed, apply skew and then anchor point if (needsSkewMatrix) @@ -1203,9 +1293,6 @@ const kmMat4& Node::getNodeToParentTransform() const } } - // vertex Z - _transform.mat[14] = _vertexZ; - if (_useAdditionalTransform) { kmMat4Multiply(&_transform, &_transform, &_additionalTransform); @@ -1348,7 +1435,7 @@ bool Node::updatePhysicsTransform() if (_physicsBody != nullptr && _physicsBody->getWorld() != nullptr && !_physicsBody->isResting()) { _position = _physicsBody->getPosition(); - _rotationX = _rotationY = _physicsBody->getRotation(); + _rotationZ_X = _rotationZ_Y = _physicsBody->getRotation(); _transformDirty = _inverseDirty = true; return true; } diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 84b2b10e35..55df576f1c 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -35,7 +35,6 @@ #include "CCGL.h" #include "ccGLStateCache.h" #include "CCGLProgram.h" -#include "kazmath/kazmath.h" #include "CCScriptSupport.h" #include "CCProtocols.h" #include "CCEventDispatcher.h" @@ -214,29 +213,6 @@ public: */ virtual float getGlobalZOrder() const { return _globalZOrder; } - /** - * Sets the 'z' value in the OpenGL Depth Buffer. - * - * The OpenGL depth buffer and depth testing are disabled by default. You need to turn them on - * in order to use this property correctly. - * - * `setVertexZ()` also sets the `setGlobalZValue()` with the vertexZ value. - * - * @see `setGlobalZValue()` - * - * @param vertexZ OpenGL Z vertex of this node. - */ - virtual void setVertexZ(float vertexZ); - /** - * Gets OpenGL Z vertex of this node. - * - * @see setVertexZ(float) - * - * @return OpenGL Z vertex of this node - */ - virtual float getVertexZ() const; - - /** * Changes the scale factor on X axis of this node * @@ -272,6 +248,23 @@ public: */ virtual float getScaleY() const; + /** + * Changes the scale factor on Z axis of this node + * + * The Default value is 1.0 if you haven't changed it before. + * + * @param scaleY The scale factor on Y axis. + */ + virtual void setScaleZ(float scaleZ); + /** + * Returns the scale factor on Z axis of this node + * + * @see `setScaleZ(float)` + * + * @return The scale factor on Z axis. + */ + virtual float getScaleZ() const; + /** * Changes both X and Y scale factor of the node. @@ -359,6 +352,41 @@ public: virtual void setPositionY(float y); virtual float getPositionY(void) const; + virtual void setPosition3D(const Vertex3F& position); + virtual Vertex3F getPosition3D() const; + /** + * Sets the 'z' axis in the position. It is the OpenGL Z vertex value. + * + * The OpenGL depth buffer and depth testing are disabled by default. You need to turn them on + * in order to use this property correctly. + * + * `setPositionZ()` also sets the `setGlobalZValue()` with the positionZ as value. + * + * @see `setGlobalZValue()` + * + * @param vertexZ OpenGL Z vertex of this node. + */ + virtual void setPositionZ(float positionZ); + CC_DEPRECATED_ATTRIBUTE virtual void setVertexZ(float vertexZ) { setPositionZ(vertexZ); } + + /** + * Gets position Z axis of this node. + * + * @see setPositionZ(float) + * + * @return the position Z axis of this node. + */ + virtual float getPositionZ() const; + CC_DEPRECATED_ATTRIBUTE virtual float getVertexZ() const { return getPositionZ(); } + + /** Sets the position using normalized coordinates. + - (0,0) means bottom,left corner + - (1,1) means top,right corner + - (0.5,0.5) means center + */ + virtual void setNormalizedPosition(const Point& position); + /** returns the normalized position */ + const Point& getNormalizedPosition() const; /** * Changes the X skew angle of the node in degrees. @@ -486,6 +514,8 @@ public: */ virtual float getRotation() const; + virtual void setRotation3D(const Vertex3F& rotation); + virtual Vertex3F getRotation3D() const; /** * Sets the X rotation (angle) of the node in degrees which performs a horizontal rotational skew. @@ -495,16 +525,18 @@ public: * * @param rotationX The X rotation in degrees which performs a horizontal rotational skew. */ - virtual void setRotationX(float rotationX); + virtual void setRotationSkewX(float rotationX); + CC_DEPRECATED_ATTRIBUTE virtual void setRotationX(float rotationX) { return setRotationSkewX(rotationX); } + /** * Gets the X rotation (angle) of the node in degrees which performs a horizontal rotation skew. * - * @see `setRotationX(float)` + * @see `setRotationSkewX(float)` * * @return The X rotation in degrees. */ - virtual float getRotationX() const; - + virtual float getRotationSkewX() const; + CC_DEPRECATED_ATTRIBUTE virtual float getRotationX() const { return getRotationSkewX(); } /** * Sets the Y rotation (angle) of the node in degrees which performs a vertical rotational skew. @@ -514,16 +546,18 @@ public: * * @param rotationY The Y rotation in degrees. */ - virtual void setRotationY(float rotationY); + virtual void setRotationSkewY(float rotationY); + CC_DEPRECATED_ATTRIBUTE virtual void setRotationY(float rotationY) { return setRotationSkewY(rotationY); } + /** * Gets the Y rotation (angle) of the node in degrees which performs a vertical rotational skew. * - * @see `setRotationY(float)` + * @see `setRotationSkewY(float)` * * @return The Y rotation in degrees. */ - virtual float getRotationY() const; - + virtual float getRotationSkewY() const; + CC_DEPRECATED_ATTRIBUTE virtual float getRotationY() const { return getRotationSkewY(); } /** * Sets the arrival order when this node has a same ZOrder with other children. @@ -1429,18 +1463,23 @@ protected: virtual void disableCascadeColor(); virtual void updateColor() {} + float _rotationX; ///< rotation on the X-axis + float _rotationY; ///< rotation on the Y-axis - float _rotationX; ///< rotation angle on x-axis - float _rotationY; ///< rotation angle on y-axis + // rotation Z is decomposed in 2 to simulate Skew for Flash animations + float _rotationZ_X; ///< rotation angle on Z-axis, component X + float _rotationZ_Y; ///< rotation angle on Z-axis, component Y - float _scaleX; ///< scaling factor on x-axis - float _scaleY; ///< scaling factor on y-axis + float _scaleX; ///< scaling factor on x-axis + float _scaleY; ///< scaling factor on y-axis + float _scaleZ; ///< scaling factor on z-axis + Point _position; ///< position of the node + float _positionZ; ///< OpenGL real Z position + Point _normalizedPosition; ///< position in normalized coordinates - Point _position; ///< position of the node - - float _skewX; ///< skew angle on x-axis - float _skewY; ///< skew angle on y-axis + float _skewX; ///< skew angle on x-axis + float _skewY; ///< skew angle on y-axis Point _anchorPointInPoints; ///< anchor point in points Point _anchorPoint; ///< anchor point normalized (NOT in points) @@ -1460,8 +1499,6 @@ protected: int _localZOrder; ///< Local order (relative to its siblings) used to sort the node float _globalZOrder; ///< Global order used to sort the node - float _vertexZ; ///< OpenGL real Z vertex - Vector _children; ///< array of children nodes Node *_parent; ///< weak reference to parent node diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 423670ccb0..7cc7c47d11 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -565,10 +565,10 @@ void Sprite::updateTransform(void) float dx = x1 * cr - y2 * sr2 + x; float dy = x1 * sr + y2 * cr2 + y; - _quad.bl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), _vertexZ ); - _quad.br.vertices = Vertex3F( RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), _vertexZ ); - _quad.tl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), _vertexZ ); - _quad.tr.vertices = Vertex3F( RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), _vertexZ ); + _quad.bl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), _positionZ ); + _quad.br.vertices = Vertex3F( RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), _positionZ ); + _quad.tl.vertices = Vertex3F( RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), _positionZ ); + _quad.tr.vertices = Vertex3F( RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), _positionZ ); } // MARMALADE CHANGE: ADDED CHECK FOR nullptr, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS diff --git a/cocos/editor-support/cocostudio/CCSkin.cpp b/cocos/editor-support/cocostudio/CCSkin.cpp index e68239b803..fa46e5197e 100644 --- a/cocos/editor-support/cocostudio/CCSkin.cpp +++ b/cocos/editor-support/cocostudio/CCSkin.cpp @@ -188,10 +188,10 @@ void Skin::updateTransform() float dx = x1 * cr - y2 * sr2 + x; float dy = x1 * sr + y2 * cr2 + y; - SET_VERTEX3F( _quad.bl.vertices, RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), _vertexZ ); - SET_VERTEX3F( _quad.br.vertices, RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), _vertexZ ); - SET_VERTEX3F( _quad.tl.vertices, RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), _vertexZ ); - SET_VERTEX3F( _quad.tr.vertices, RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), _vertexZ ); + SET_VERTEX3F( _quad.bl.vertices, RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), _positionZ ); + SET_VERTEX3F( _quad.br.vertices, RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), _positionZ ); + SET_VERTEX3F( _quad.tl.vertices, RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), _positionZ ); + SET_VERTEX3F( _quad.tr.vertices, RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), _positionZ ); } // MARMALADE CHANGE: ADDED CHECK FOR nullptr, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS diff --git a/tests/test-cpp/Classes/ActionsTest/ActionsTest.cpp b/tests/test-cpp/Classes/ActionsTest/ActionsTest.cpp index 4ec278b9bc..fd13d0d53f 100644 --- a/tests/test-cpp/Classes/ActionsTest/ActionsTest.cpp +++ b/tests/test-cpp/Classes/ActionsTest/ActionsTest.cpp @@ -33,9 +33,12 @@ static std::function createFunctions[] = { + CL(ActionRotateBy3D), + CL(ActionManual), CL(ActionMove), CL(ActionRotate), + CL(ActionRotateBy3D), CL(ActionScale), CL(ActionSkew), CL(ActionRotationalSkew), @@ -501,6 +504,31 @@ std::string ActionRotate::subtitle() const return "RotateTo / RotateBy"; } +//------------------------------------------------------------------ +// +// ActionRotateBy3D +// +//------------------------------------------------------------------ +void ActionRotateBy3D::onEnter() +{ + ActionsDemo::onEnter(); + + centerSprites(3); + + auto actionBy1 = RotateBy::create(4, Vertex3F(360, 0, 0)); + auto actionBy2 = RotateBy::create(4, Vertex3F(0, 360, 0)); + auto actionBy3 = RotateBy::create(4 ,Vertex3F(0, 0, 360)); + + _tamara->runAction( Sequence::create(actionBy1, actionBy1->reverse(), nullptr)); + _grossini->runAction( Sequence::create(actionBy2, actionBy2->reverse(), nullptr)); + _kathia->runAction( Sequence::create(actionBy3, actionBy3->reverse(), nullptr)); +} + +std::string ActionRotateBy3D::subtitle() const +{ + return "RotateBy in 3D"; +} + //------------------------------------------------------------------ // // ActionJump diff --git a/tests/test-cpp/Classes/ActionsTest/ActionsTest.h b/tests/test-cpp/Classes/ActionsTest/ActionsTest.h index ea238068b7..9d48e1b1fe 100644 --- a/tests/test-cpp/Classes/ActionsTest/ActionsTest.h +++ b/tests/test-cpp/Classes/ActionsTest/ActionsTest.h @@ -49,7 +49,7 @@ protected: Sprite* _tamara; Sprite* _kathia; public: - virtual void onEnter(); + virtual void onEnter() override; virtual void onExit(); void centerSprites(unsigned int numberOfSprites); @@ -67,7 +67,7 @@ class ActionManual : public ActionsDemo public: CREATE_FUNC(ActionManual); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -76,7 +76,7 @@ class ActionMove : public ActionsDemo public: CREATE_FUNC(ActionMove); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -85,7 +85,7 @@ class ActionScale : public ActionsDemo public: CREATE_FUNC(ActionScale); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -94,7 +94,7 @@ class ActionSkew : public ActionsDemo public: CREATE_FUNC(ActionSkew); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -103,7 +103,7 @@ class ActionRotationalSkew : public ActionsDemo public: CREATE_FUNC(ActionRotationalSkew); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -112,7 +112,7 @@ class ActionRotationalSkewVSStandardSkew : public ActionsDemo public: CREATE_FUNC(ActionRotationalSkewVSStandardSkew); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -121,7 +121,7 @@ class ActionSkewRotateScale : public ActionsDemo public: CREATE_FUNC(ActionSkewRotateScale); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -130,7 +130,16 @@ class ActionRotate : public ActionsDemo public: CREATE_FUNC(ActionRotate); - virtual void onEnter(); + virtual void onEnter() override; + virtual std::string subtitle() const override; +}; + +class ActionRotateBy3D : public ActionsDemo +{ +public: + CREATE_FUNC(ActionRotateBy3D); + + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -139,7 +148,7 @@ class ActionJump : public ActionsDemo public: CREATE_FUNC(ActionJump); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -148,7 +157,7 @@ class ActionBezier : public ActionsDemo public: CREATE_FUNC(ActionBezier); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -157,7 +166,7 @@ class ActionBlink : public ActionsDemo public: CREATE_FUNC(ActionBlink); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -166,7 +175,7 @@ class ActionFade : public ActionsDemo public: CREATE_FUNC(ActionFade); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -175,7 +184,7 @@ class ActionTint : public ActionsDemo public: CREATE_FUNC(ActionTint); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -184,7 +193,7 @@ class ActionAnimate : public ActionsDemo public: CREATE_FUNC(ActionAnimate); - virtual void onEnter(); + virtual void onEnter() override; virtual void onExit(); virtual std::string title() const override; virtual std::string subtitle() const override; @@ -195,7 +204,7 @@ class ActionSequence : public ActionsDemo public: CREATE_FUNC(ActionSequence); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -204,7 +213,7 @@ class ActionSequence2 : public ActionsDemo public: CREATE_FUNC(ActionSequence2); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; void callback1(); @@ -217,7 +226,7 @@ class ActionSpawn : public ActionsDemo public: CREATE_FUNC(ActionSpawn); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -226,7 +235,7 @@ class ActionReverse : public ActionsDemo public: CREATE_FUNC(ActionReverse); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -235,7 +244,7 @@ class ActionRepeat : public ActionsDemo public: CREATE_FUNC(ActionRepeat); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -244,7 +253,7 @@ class ActionDelayTime : public ActionsDemo public: CREATE_FUNC(ActionDelayTime); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -253,7 +262,7 @@ class ActionReverseSequence : public ActionsDemo public: CREATE_FUNC(ActionReverseSequence); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -262,7 +271,7 @@ class ActionReverseSequence2 : public ActionsDemo public: CREATE_FUNC(ActionReverseSequence2); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -271,7 +280,7 @@ class ActionOrbit : public ActionsDemo public: CREATE_FUNC(ActionOrbit); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -280,7 +289,7 @@ class ActionRemoveSelf : public ActionsDemo public: CREATE_FUNC(ActionRemoveSelf); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -289,7 +298,7 @@ class ActionRepeatForever : public ActionsDemo public: CREATE_FUNC(ActionRepeatForever); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; void repeatForever(Node* pTarget); @@ -300,7 +309,7 @@ class ActionRotateToRepeat : public ActionsDemo public: CREATE_FUNC(ActionRotateToRepeat); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -309,7 +318,7 @@ class ActionRotateJerk : public ActionsDemo public: CREATE_FUNC(ActionRotateJerk); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; }; @@ -318,7 +327,7 @@ class ActionCallFuncN : public ActionsDemo public: CREATE_FUNC(ActionCallFuncN); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; void callback(Node* sender); @@ -329,7 +338,7 @@ class ActionCallFuncND : public ActionsDemo public: CREATE_FUNC(ActionCallFuncND); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; void doRemoveFromParentAndCleanup(Node* sender, bool cleanup); @@ -340,7 +349,7 @@ class ActionCallFuncO : public ActionsDemo public: CREATE_FUNC(ActionCallFuncO); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; void callback(Node* object, bool cleanup); @@ -351,7 +360,7 @@ class ActionCallFunction : public ActionsDemo public: CREATE_FUNC(ActionCallFunction); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; void callback1(); @@ -365,7 +374,7 @@ class ActionFollow : public ActionsDemo public: CREATE_FUNC(ActionFollow); - virtual void onEnter(); + virtual void onEnter() override; virtual void draw(); virtual std::string subtitle() const override; @@ -381,7 +390,7 @@ class ActionTargeted : public ActionsDemo public: CREATE_FUNC(ActionTargeted); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -391,7 +400,7 @@ class ActionTargetedReverse : public ActionsDemo public: CREATE_FUNC(ActionTargetedReverse); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -401,7 +410,7 @@ class ActionStacked : public ActionsDemo public: CREATE_FUNC(ActionStacked); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; virtual void addNewSpriteWithCoords(Point p); @@ -443,7 +452,7 @@ public: virtual ~ActionCatmullRomStacked(); virtual void draw(); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; protected: @@ -464,7 +473,7 @@ public: virtual ~ActionCardinalSplineStacked(); virtual void draw(); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; private: @@ -481,7 +490,7 @@ class Issue1305 : public ActionsDemo public: CREATE_FUNC(Issue1305); - virtual void onEnter(); + virtual void onEnter() override; virtual void onExit(); void log(Node* sender); void addSprite(float dt); @@ -496,7 +505,7 @@ class Issue1305_2 : public ActionsDemo public: CREATE_FUNC(Issue1305_2); - virtual void onEnter(); + virtual void onEnter() override; void printLog1(); void printLog2(); void printLog3(); @@ -510,7 +519,7 @@ class Issue1288 : public ActionsDemo public: CREATE_FUNC(Issue1288); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -520,7 +529,7 @@ class Issue1288_2 : public ActionsDemo public: CREATE_FUNC(Issue1288_2); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string title() const override; virtual std::string subtitle() const override; }; @@ -530,7 +539,7 @@ class Issue1327 : public ActionsDemo public: CREATE_FUNC(Issue1327); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; virtual std::string title() const override; void logSprRotation(Sprite* sender); @@ -543,7 +552,7 @@ public: void incrementInteger(); void incrementIntegerCallback(void* data); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; virtual std::string title() const override; private: @@ -557,7 +566,7 @@ public: ~ActionCatmullRom(); - virtual void onEnter(); + virtual void onEnter() override; virtual void draw(); virtual std::string subtitle() const override; virtual std::string title() const override; @@ -578,7 +587,7 @@ public: ~ActionCardinalSpline(); - virtual void onEnter(); + virtual void onEnter() override; virtual void draw(); virtual std::string subtitle() const override; virtual std::string title() const override; @@ -598,7 +607,7 @@ public: PauseResumeActions(); virtual ~PauseResumeActions(); - virtual void onEnter(); + virtual void onEnter() override; virtual std::string subtitle() const override; virtual std::string title() const override; From 04460750b894354c047eabdc8038cc95999cc626 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Sun, 23 Feb 2014 01:09:52 -0800 Subject: [PATCH 08/21] culling working for both 2d and 3d projections --- CHANGELOG | 17 ++++++++++++----- cocos/2d/CCDirector.cpp | 7 ++++--- cocos/2d/CCNode.h | 34 ++++++++++++++++++++++++++++++---- cocos/2d/CCSprite.cpp | 38 +++++++++++++++++++++++--------------- cocos/2d/CCSprite.h | 6 +++--- 5 files changed, 72 insertions(+), 30 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9b8ad49206..85319da06c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,12 +1,19 @@ cocos2d-x-3.0rc0 Feb.?? 2014 [All] - [NEW] Adds more console commands: director resume|pause|stopanimation|startanimation. - [NEW] Adds Dutch Language support. + [NEW] Action: RotateBy supports 3D rotations + [NEW] Bindings: Using python to automatically generate script bindings + [NEW] Bindings: Added JS bindings support for Linux [NEW] Console: Added 'resolution', 'projection' commands. Improved API + [NEW] Console: Added more commands: director resume|pause|stopanimation|startanimation. [NEW] Director: Displays 'Vertices drawn' in the stats. Useful to measure performance. - [NEW] Using python to automatically generate script bindings codes. - [NEW] Linux javascript bindings support. - + [NEW] Node: Added set/get Position3D() and set/get Rotation3D() + Node: Calculates rotation X and Y correctly. + Node: set/get VertexZ() -> set/get PositionZ() + Node: setRotationX() -> setRotationSkewX() + Node: setRotationY() -> setRotationSkewY() + [NEW] Language: Added Dutch support. + [NEW] Sprite: Added auto-culling support + [FIX] Character would not be aligned on the baseline when label using distance field. [FIX] Adds a macro to disable inserting script binding relevant codes. [FIX] Removing child from TMXLayer may cause crash. diff --git a/cocos/2d/CCDirector.cpp b/cocos/2d/CCDirector.cpp index 1261663340..d5af6ac15b 100644 --- a/cocos/2d/CCDirector.cpp +++ b/cocos/2d/CCDirector.cpp @@ -448,18 +448,19 @@ void Director::setProjection(Projection projection) // issue #1334 kmMat4PerspectiveProjection(&matrixPerspective, 60, (GLfloat)size.width/size.height, 10, zeye+size.height/2); - // kmMat4PerspectiveProjection( &matrixPerspective, 60, (GLfloat)size.width/size.height, 0.1f, 1500); +// kmMat4PerspectiveProjection( &matrixPerspective, 60, (GLfloat)size.width/size.height, 0.1f, 1500); kmGLMultMatrix(&matrixPerspective); - kmGLMatrixMode(KM_GL_MODELVIEW); - kmGLLoadIdentity(); kmVec3 eye, center, up; kmVec3Fill(&eye, size.width/2, size.height/2, zeye); kmVec3Fill(¢er, size.width/2, size.height/2, 0.0f); kmVec3Fill(&up, 0.0f, 1.0f, 0.0f); kmMat4LookAt(&matrixLookup, &eye, ¢er, &up); kmGLMultMatrix(&matrixLookup); + + kmGLMatrixMode(KM_GL_MODELVIEW); + kmGLLoadIdentity(); break; } diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 55df576f1c..baa9591fdc 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -352,8 +352,15 @@ public: virtual void setPositionY(float y); virtual float getPositionY(void) const; + /** + * Sets the X, Y, and Z axis position + */ virtual void setPosition3D(const Vertex3F& position); + /** + * returns the X, Y and Z axis position + */ virtual Vertex3F getPosition3D() const; + /** * Sets the 'z' axis in the position. It is the OpenGL Z vertex value. * @@ -391,13 +398,16 @@ public: /** * Changes the X skew angle of the node in degrees. * + * The difference between `setRotationalSkew()` and `setSkew()` is that the first one simulate Flash's skew functionality + * while the second one uses the real skew funciton. + * * This angle describes the shear distortion in the X direction. * Thus, it is the angle between the Y axis and the left edge of the shape * The default skewX angle is 0. Positive values distort the node in a CW direction. * - * @param fSkewX The X skew angle of the node in degrees. + * @param skewX The X skew angle of the node in degrees. */ - virtual void setSkewX(float fSkewX); + virtual void setSkewX(float skewX); /** * Returns the X skew angle of the node in degrees. * @@ -411,13 +421,16 @@ public: /** * Changes the Y skew angle of the node in degrees. * + * The difference between `setRotationalSkew()` and `setSkew()` is that the first one simulate Flash's skew functionality + * while the second one uses the real skew funciton. + * * This angle describes the shear distortion in the Y direction. * Thus, it is the angle between the X axis and the bottom edge of the shape * The default skewY angle is 0. Positive values distort the node in a CCW direction. * - * @param fSkewY The Y skew angle of the node in degrees. + * @param skewY The Y skew angle of the node in degrees. */ - virtual void setSkewY(float fSkewY); + virtual void setSkewY(float skewY); /** * Returns the Y skew angle of the node in degrees. * @@ -514,12 +527,22 @@ public: */ virtual float getRotation() const; + /** + * Sets the X, Y and Z axis rotation + * Useful for 3d rotations + */ virtual void setRotation3D(const Vertex3F& rotation); + /** + * returns the X, Y and Z axis rotation + */ virtual Vertex3F getRotation3D() const; /** * Sets the X rotation (angle) of the node in degrees which performs a horizontal rotational skew. * + * The difference between setRotationalSkew() and setSkew() is that the first one simulate Flash's skew functionality + * while the second one uses the real skew funciton. + * * 0 is the default rotation angle. * Positive values rotate node clockwise, and negative values for anti-clockwise. * @@ -541,6 +564,9 @@ public: /** * Sets the Y rotation (angle) of the node in degrees which performs a vertical rotational skew. * + * The difference between setRotationalSkew() and setSkew() is that the first one simulate Flash's skew functionality + * while the second one uses the real skew funciton. + * * 0 is the default rotation angle. * Positive values rotate node clockwise, and negative values for anti-clockwise. * diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 7cc7c47d11..181a60b0ca 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -599,7 +599,7 @@ void Sprite::updateTransform(void) Point( _quad.tr.vertices.x, _quad.tr.vertices.y ), Point( _quad.tl.vertices.x, _quad.tl.vertices.y ), }; - ccDrawPoly(vertices, 4, true); + DrawPrimitives::drawPoly(vertices, 4, true); #endif // CC_SPRITE_DEBUG_DRAW } @@ -618,19 +618,27 @@ void Sprite::draw(void) bool Sprite::culling() const { Size s = Director::getInstance()->getWinSize(); - kmVec3 v3 = {_contentSize.width*0.5f, _contentSize.height*0.5f, 0}; - kmVec3Transform(&v3, &v3, &_modelViewTransform); + float hcsx = _contentSize.width * 0.5f; + float hcsy = _contentSize.height * 0.5f; - float cshw = _contentSize.width * fmaxf(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4])); - float cshh = _contentSize.height * fmaxf(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5])); + // convert to world coordinates + float x = hcsx * _modelViewTransform.mat[0] + hcsy * _modelViewTransform.mat[4] + _modelViewTransform.mat[12]; + float y = hcsx * _modelViewTransform.mat[1] + hcsy * _modelViewTransform.mat[5] + _modelViewTransform.mat[13]; - return ( (fabsf(v3.x)-cshw) < s.width/2 && (fabsf(v3.y)-cshh) < s.height/2); + // center of screen is (0,0) + x -= s.width/2; + y -= s.height/2; + + // convert content size to world coordinates + float wchw = hcsx * fmaxf(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4])); + float wchh = hcsy * fmaxf(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5])); + + float tmpx = (fabsf(x)-wchw); + float tmpy = (fabsf(y)-wchh); + return (tmpx < s.width/2 && tmpy < s.height/2); } - - // Node overrides - void Sprite::addChild(Node *child, int zOrder, int tag) { CCASSERT(child != nullptr, "Argument must be non-nullptr"); @@ -796,15 +804,15 @@ void Sprite::setRotation(float rotation) SET_DIRTY_RECURSIVELY(); } -void Sprite::setRotationX(float fRotationX) +void Sprite::setRotationSkewX(float fRotationX) { - Node::setRotationX(fRotationX); + Node::setRotationSkewX(fRotationX); SET_DIRTY_RECURSIVELY(); } -void Sprite::setRotationY(float fRotationY) +void Sprite::setRotationSkewY(float fRotationY) { - Node::setRotationY(fRotationY); + Node::setRotationSkewY(fRotationY); SET_DIRTY_RECURSIVELY(); } @@ -844,9 +852,9 @@ void Sprite::setScale(float scaleX, float scaleY) SET_DIRTY_RECURSIVELY(); } -void Sprite::setVertexZ(float fVertexZ) +void Sprite::setPositionZ(float fVertexZ) { - Node::setVertexZ(fVertexZ); + Node::setPositionZ(fVertexZ); SET_DIRTY_RECURSIVELY(); } diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index 5510a00d46..bb77d131dc 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -408,8 +408,8 @@ public: virtual void setPosition(const Point& pos) override; virtual void setPosition(float x, float y) override; virtual void setRotation(float rotation) override; - virtual void setRotationX(float rotationX) override; - virtual void setRotationY(float rotationY) override; + virtual void setRotationSkewX(float rotationX) override; + virtual void setRotationSkewY(float rotationY) override; virtual void setSkewX(float sx) override; virtual void setSkewY(float sy) override; virtual void removeChild(Node* child, bool cleanup) override; @@ -419,7 +419,7 @@ public: virtual void addChild(Node *child, int zOrder, int tag) override; virtual void sortAllChildren() override; virtual void setScale(float scale) override; - virtual void setVertexZ(float vertexZ) override; + virtual void setPositionZ(float positionZ) override; virtual void setAnchorPoint(const Point& anchor) override; virtual void ignoreAnchorPointForPosition(bool value) override; virtual void setVisible(bool bVisible) override; From e306c53d21fc606503919b646c9f69a95a6cc978 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Sun, 23 Feb 2014 09:21:10 +0000 Subject: [PATCH 09/21] [AUTO] : updating submodule reference to latest autogenerated bindings --- cocos/scripting/auto-generated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/scripting/auto-generated b/cocos/scripting/auto-generated index 55b366484c..42d96e2c6b 160000 --- a/cocos/scripting/auto-generated +++ b/cocos/scripting/auto-generated @@ -1 +1 @@ -Subproject commit 55b366484cd48e5ddd3467dae0376a28fef36ab6 +Subproject commit 42d96e2c6b04d0d75c12e3fdf1cc24a160160e89 From f77b92f1d7866aa105a758e6794ab62df08189ee Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Sun, 23 Feb 2014 02:02:28 -0800 Subject: [PATCH 10/21] performance improvements in culling --- cocos/2d/CCSprite.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 181a60b0ca..7357db7f7f 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -617,25 +617,30 @@ void Sprite::draw(void) // Culling function from cocos2d-iphone CCSprite.m file bool Sprite::culling() const { - Size s = Director::getInstance()->getWinSize(); - float hcsx = _contentSize.width * 0.5f; - float hcsy = _contentSize.height * 0.5f; + // half size of the screen + Size screen_half = Director::getInstance()->getWinSize(); + screen_half.width /= 2; + screen_half.height /= 2; + + float hcsx = _contentSize.width / 2; + float hcsy = _contentSize.height / 2; // convert to world coordinates float x = hcsx * _modelViewTransform.mat[0] + hcsy * _modelViewTransform.mat[4] + _modelViewTransform.mat[12]; float y = hcsx * _modelViewTransform.mat[1] + hcsy * _modelViewTransform.mat[5] + _modelViewTransform.mat[13]; // center of screen is (0,0) - x -= s.width/2; - y -= s.height/2; + x -= screen_half.width; + y -= screen_half.height; // convert content size to world coordinates float wchw = hcsx * fmaxf(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4])); float wchh = hcsy * fmaxf(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5])); + // compare if it in the positive quarter of the screen float tmpx = (fabsf(x)-wchw); float tmpy = (fabsf(y)-wchh); - return (tmpx < s.width/2 && tmpy < s.height/2); + return (tmpx < screen_half.width && tmpy < screen_half.height); } // Node overrides From 5f28e6bd72f42dd80336f65c084c18b577d5438e Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Sun, 23 Feb 2014 20:56:49 +0800 Subject: [PATCH 11/21] =?UTF-8?q?Replace=20=E2=80=9Ccc.object=E2=80=9D=20w?= =?UTF-8?q?ith=20=E2=80=9Ccc.ref=E2=80=9D=20for=20lua=20binding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocos/scripting/lua/bindings/CCLuaEngine.cpp | 8 ++++---- cocos/scripting/lua/bindings/LuaBasicConversions.cpp | 2 +- cocos/scripting/lua/bindings/LuaBasicConversions.h | 4 ++-- cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp | 6 +++--- .../lua/bindings/lua_cocos2dx_extension_manual.cpp | 2 +- cocos/scripting/lua/bindings/lua_xml_http_request.cpp | 2 +- cocos/scripting/lua/script/DeprecatedClass.lua | 8 -------- 7 files changed, 12 insertions(+), 20 deletions(-) diff --git a/cocos/scripting/lua/bindings/CCLuaEngine.cpp b/cocos/scripting/lua/bindings/CCLuaEngine.cpp index 4b2f103f8e..08e7174cf2 100644 --- a/cocos/scripting/lua/bindings/CCLuaEngine.cpp +++ b/cocos/scripting/lua/bindings/CCLuaEngine.cpp @@ -167,7 +167,7 @@ int LuaEngine::executeEvent(int nHandler, const char* pEventName, Ref* pEventSou _stack->pushString(pEventName); if (pEventSource) { - _stack->pushObject(pEventSource, pEventSourceClassName ? pEventSourceClassName : "cc.Object"); + _stack->pushObject(pEventSource, pEventSourceClassName ? pEventSourceClassName : "cc.Ref"); } int ret = _stack->executeFunctionByHandler(nHandler, pEventSource ? 2 : 1); _stack->clean(); @@ -447,7 +447,7 @@ int LuaEngine::handleCommonEvent(void* data) } else { - _stack->pushObject(commonInfo->eventSource, "cc.Object"); + _stack->pushObject(commonInfo->eventSource, "cc.Ref"); } } int ret = _stack->executeFunctionByHandler(commonInfo->handler, commonInfo->eventSource ? 2 : 1); @@ -585,7 +585,7 @@ int LuaEngine::handlerControlEvent(void* data) if (0 != handler) { - _stack->pushObject((Ref*)basicScriptData->nativeObject, "cc.Object"); + _stack->pushObject((Ref*)basicScriptData->nativeObject, "cc.Ref"); _stack->pushInt(controlEvents); ret = _stack->executeFunctionByHandler(handler, 2); _stack->clean(); @@ -1013,7 +1013,7 @@ int LuaEngine::handleStudioEventListener(ScriptHandlerMgr::HandlerType type,void if (0 == handler) return 0; - _stack->pushObject(listenerData->objTarget, "cc.Object"); + _stack->pushObject(listenerData->objTarget, "cc.Ref"); _stack->pushInt(listenerData->eventType); _stack->executeFunctionByHandler(handler, 2); diff --git a/cocos/scripting/lua/bindings/LuaBasicConversions.cpp b/cocos/scripting/lua/bindings/LuaBasicConversions.cpp index ddd12b5259..6d79b330d5 100644 --- a/cocos/scripting/lua/bindings/LuaBasicConversions.cpp +++ b/cocos/scripting/lua/bindings/LuaBasicConversions.cpp @@ -1071,7 +1071,7 @@ bool luavals_variadic_to_array(lua_State* L,int argc, Array** ret) else if (lua_isuserdata(L, i + 2)) { tolua_Error err; - if (!tolua_isusertype(L, i + 2, "cc.Object", 0, &err)) + if (!tolua_isusertype(L, i + 2, "cc.Ref", 0, &err)) { #if COCOS2D_DEBUG >=1 luaval_to_native_err(L,"#ferror:",&err); diff --git a/cocos/scripting/lua/bindings/LuaBasicConversions.h b/cocos/scripting/lua/bindings/LuaBasicConversions.h index 9044d41dad..2deae086fd 100644 --- a/cocos/scripting/lua/bindings/LuaBasicConversions.h +++ b/cocos/scripting/lua/bindings/LuaBasicConversions.h @@ -87,8 +87,8 @@ bool luavals_variadic_to_ccvector( lua_State* L, int argc, cocos2d::Vector* r if (lua_isuserdata(L, i + 2)) { tolua_Error err; - //Undo check - if (!tolua_isusertype(L, i + 2, "cc.Object", 0, &err)) + + if (!tolua_isusertype(L, i + 2, "cc.Ref", 0, &err)) { ok = false; break; diff --git a/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp b/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp index c781d5b1ec..9c9fc2f6bc 100644 --- a/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp +++ b/cocos/scripting/lua/bindings/LuaScriptHandlerMgr.cpp @@ -282,7 +282,7 @@ static int tolua_Cocos2d_ScriptHandlerMgr_registerScriptHandler00(lua_State* tol #ifndef TOLUA_RELEASE tolua_Error tolua_err; if (!tolua_isusertype(tolua_S,1,"ScriptHandlerMgr",0,&tolua_err) || - !tolua_isusertype(tolua_S, 2, "cc.Object", 0, &tolua_err) || + !tolua_isusertype(tolua_S, 2, "cc.Ref", 0, &tolua_err) || !toluafix_isfunction(tolua_S, 3, "LUA_FUNCTION", 0, &tolua_err) || !tolua_isnumber(tolua_S, 4, 0, &tolua_err) || !tolua_isnoobj(tolua_S,5,&tolua_err) ) @@ -316,7 +316,7 @@ static int tolua_Cocos2d_ScriptHandlerMgr_unregisterScriptHandler00(lua_State* t #ifndef TOLUA_RELEASE tolua_Error tolua_err; if (!tolua_isusertype(tolua_S,1,"ScriptHandlerMgr",0,&tolua_err) || - !tolua_isusertype(tolua_S, 2, "cc.Object", 0, &tolua_err) || + !tolua_isusertype(tolua_S, 2, "cc.Ref", 0, &tolua_err) || !tolua_isnumber(tolua_S, 3, 0, &tolua_err) || !tolua_isnoobj(tolua_S,4,&tolua_err) ) goto tolua_lerror; @@ -348,7 +348,7 @@ static int tolua_Cocos2d_ScriptHandlerMgr_removeObjectAllHandlers00(lua_State* t #ifndef TOLUA_RELEASE tolua_Error tolua_err; if (!tolua_isusertype(tolua_S,1,"ScriptHandlerMgr",0,&tolua_err) || - !tolua_isusertype(tolua_S, 2, "cc.Object", 0, &tolua_err) || + !tolua_isusertype(tolua_S, 2, "cc.Ref", 0, &tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; else diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp index 7dec168f29..473fd8184e 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_extension_manual.cpp @@ -766,7 +766,7 @@ static int tolua_cocos2d_CCBReader_load(lua_State* tolua_S) } #if COCOS2D_DEBUG >= 1 - if (!tolua_isusertype(tolua_S, 3, "cc.Object", 0, &tolua_err)) + if (!tolua_isusertype(tolua_S, 3, "cc.Ref", 0, &tolua_err)) goto tolua_lerror; #endif Ref* owner = static_cast(tolua_tousertype(tolua_S, 3, 0)); diff --git a/cocos/scripting/lua/bindings/lua_xml_http_request.cpp b/cocos/scripting/lua/bindings/lua_xml_http_request.cpp index 9470afffb1..e0fe011736 100644 --- a/cocos/scripting/lua/bindings/lua_xml_http_request.cpp +++ b/cocos/scripting/lua/bindings/lua_xml_http_request.cpp @@ -1084,7 +1084,7 @@ TOLUA_API int register_xml_http_request(lua_State* L) lua_reg_xml_http_request(L); tolua_module(L,"cc",0); tolua_beginmodule(L,"cc"); - tolua_cclass(L,"XMLHttpRequest","cc.XMLHttpRequest","cc.Object",lua_collect_xml_http_request); + tolua_cclass(L,"XMLHttpRequest","cc.XMLHttpRequest","cc.Ref",lua_collect_xml_http_request); tolua_beginmodule(L,"XMLHttpRequest"); tolua_variable(L, "responseType", lua_get_XMLHttpRequest_responseType, lua_set_XMLHttpRequest_responseType); tolua_variable(L, "withCredentials", lua_get_XMLHttpRequest_withCredentials, lua_set_XMLHttpRequest_withCredentials); diff --git a/cocos/scripting/lua/script/DeprecatedClass.lua b/cocos/scripting/lua/script/DeprecatedClass.lua index 462c9ac137..2dd357d759 100644 --- a/cocos/scripting/lua/script/DeprecatedClass.lua +++ b/cocos/scripting/lua/script/DeprecatedClass.lua @@ -127,14 +127,6 @@ end _G["CCJumpBy"] = DeprecatedClass.CCJumpBy() --CCJumpBy class will be Deprecated,end ---CCObject class will be Deprecated,begin -function DeprecatedClass.CCObject() - deprecatedTip("CCObject","cc.Object") - return cc.Object -end -_G["CCObject"] = DeprecatedClass.CCObject() ---CCObject class will be Deprecated,end - --CCTransitionRotoZoom class will be Deprecated,begin function DeprecatedClass.CCTransitionRotoZoom() deprecatedTip("CCTransitionRotoZoom","cc.TransitionRotoZoom") From 4e09856624585e9d700365138a96f032387b3d3b Mon Sep 17 00:00:00 2001 From: Linghui Date: Mon, 24 Feb 2014 04:32:47 +0800 Subject: [PATCH 12/21] change the platform java path. --- template/multi-platform-cpp/proj.android/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/multi-platform-cpp/proj.android/README.md b/template/multi-platform-cpp/proj.android/README.md index 312835611a..53cb259634 100644 --- a/template/multi-platform-cpp/proj.android/README.md +++ b/template/multi-platform-cpp/proj.android/README.md @@ -84,4 +84,4 @@ If the last command results in sdk.dir missing error then do: $ android list target $ android update project -p . -t (id from step 6) - $ android update project -p cocos2d-x/cocos2dx/platform/android/java/ -t (id from step 6) + $ android update project -p cocos2d/cocos/2d/platform/android/java/ -t (id from step 6) From ac88d70d58f8187193c7849083ba2a9bec5b1ad8 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Mon, 24 Feb 2014 10:01:00 +0800 Subject: [PATCH 13/21] issue #3956:Update the related compile file --- cocos/scripting/lua/CMakeLists.txt | 2 +- cocos/scripting/lua/bindings/Android.mk | 2 +- cocos/scripting/lua/bindings/LuaBasicConversions.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos/scripting/lua/CMakeLists.txt b/cocos/scripting/lua/CMakeLists.txt index 7e73d8c514..571b106271 100644 --- a/cocos/scripting/lua/CMakeLists.txt +++ b/cocos/scripting/lua/CMakeLists.txt @@ -5,7 +5,7 @@ set(LUABINDING_SRC ../auto-generated/lua-bindings/lua_cocos2dx_gui_auto.cpp ../auto-generated/lua-bindings/lua_cocos2dx_spine_auto.cpp ../auto-generated/lua-bindings/lua_cocos2dx_physics_auto.cpp - bindings/tolua_fix.c + bindings/tolua_fix.cpp bindings/CCLuaBridge.cpp bindings/CCLuaEngine.cpp bindings/CCLuaStack.cpp diff --git a/cocos/scripting/lua/bindings/Android.mk b/cocos/scripting/lua/bindings/Android.mk index 5261274e43..ab84f97160 100644 --- a/cocos/scripting/lua/bindings/Android.mk +++ b/cocos/scripting/lua/bindings/Android.mk @@ -37,7 +37,7 @@ LOCAL_SRC_FILES := CCLuaBridge.cpp \ ../../../../external/lua/tolua/tolua_map.c \ ../../../../external/lua/tolua/tolua_push.c \ ../../../../external/lua/tolua/tolua_to.c \ - tolua_fix.c \ + tolua_fix.cpp \ socket/auxiliar.c \ socket/luasocket_buffer.c \ socket/except.c \ diff --git a/cocos/scripting/lua/bindings/LuaBasicConversions.h b/cocos/scripting/lua/bindings/LuaBasicConversions.h index 19ab9a8f7f..b5de6057b8 100644 --- a/cocos/scripting/lua/bindings/LuaBasicConversions.h +++ b/cocos/scripting/lua/bindings/LuaBasicConversions.h @@ -87,7 +87,7 @@ bool luavals_variadic_to_ccvector( lua_State* L, int argc, cocos2d::Vector* r { tolua_Error err; //Undo check - if (!tolua_isusertype(L, i + 2, "cc.Ref", 0, &err)) + if (!tolua_isusertype(L, i + 2, "cc.Object", 0, &err)) { ok = false; break; From 8fa8eaf64dbb50141dd6b2cb36c5bd90b5a91ca0 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Mon, 24 Feb 2014 10:08:00 +0800 Subject: [PATCH 14/21] issue #3956:Remove some unrelated modification --- cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp index b43605a778..4bd6fcfb2e 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp @@ -751,7 +751,7 @@ static int tolua_Cocos2d_CCArray_objectAtIndex00(lua_State* tolua_S) Ref* tolua_ret = (Ref*) self->getObjectAtIndex(index); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Object"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Object"); } } return 1; @@ -785,7 +785,7 @@ static int tolua_Cocos2d_CCArray_lastObject00(lua_State* tolua_S) Ref* tolua_ret = (Ref*) self->getLastObject(); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Object"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Object"); } } return 1; @@ -819,7 +819,7 @@ static int tolua_Cocos2d_CCArray_randomObject00(lua_State* tolua_S) Ref* tolua_ret = (Ref*) self->getRandomObject(); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Object"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Object"); } } return 1; From 82ee8a4abdaed88430b3c7bcb8e19e000334a9f1 Mon Sep 17 00:00:00 2001 From: samuele3hu Date: Mon, 24 Feb 2014 10:28:55 +0800 Subject: [PATCH 15/21] =?UTF-8?q?Add=20some=20omitted=20modifications=20ab?= =?UTF-8?q?out=20=E2=80=9Ccc.ref=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lua/bindings/lua_cocos2dx_deprecated.cpp | 28 +++++++++---------- .../scripting/lua/script/DeprecatedClass.lua | 16 +++++++++++ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp index 015950a437..23f0060c7e 100644 --- a/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp +++ b/cocos/scripting/lua/bindings/lua_cocos2dx_deprecated.cpp @@ -518,7 +518,7 @@ static int tolua_Cocos2d_CCArray_createWithObject00(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertable(tolua_S,1,"CCArray",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"Object",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cc.Ref",0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; @@ -709,7 +709,7 @@ static int tolua_Cocos2d_CCArray_indexOfObject00(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"CCArray",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"Object",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cc.Ref",0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; @@ -759,7 +759,7 @@ static int tolua_Cocos2d_CCArray_objectAtIndex00(lua_State* tolua_S) Ref* tolua_ret = (Ref*) self->getObjectAtIndex(index); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Object"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Ref"); } } return 1; @@ -793,7 +793,7 @@ static int tolua_Cocos2d_CCArray_lastObject00(lua_State* tolua_S) Ref* tolua_ret = (Ref*) self->getLastObject(); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Object"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Ref"); } } return 1; @@ -827,7 +827,7 @@ static int tolua_Cocos2d_CCArray_randomObject00(lua_State* tolua_S) Ref* tolua_ret = (Ref*) self->getRandomObject(); int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1; int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL; - toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"Object"); + toluafix_pushusertype_ccobject(tolua_S, nID, pLuaID, (void*)tolua_ret,"cc.Ref"); } } return 1; @@ -881,7 +881,7 @@ static int tolua_Cocos2d_CCArray_containsObject00(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"CCArray",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"Object",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cc.Ref",0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; @@ -915,7 +915,7 @@ static int tolua_Cocos2d_CCArray_addObject00(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"CCArray",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"Object",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cc.Ref",0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; @@ -980,7 +980,7 @@ static int tolua_Cocos2d_CCArray_insertObject00(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"CCArray",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"Object",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cc.Ref",0,&tolua_err) || !tolua_isnumber(tolua_S,3,0,&tolua_err) || !tolua_isnoobj(tolua_S,4,&tolua_err) ) @@ -1047,7 +1047,7 @@ static int tolua_Cocos2d_CCArray_removeObject00(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"CCArray",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"Object",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cc.Ref",0,&tolua_err) || !tolua_isboolean(tolua_S,3,1,&tolua_err) || !tolua_isnoobj(tolua_S,4,&tolua_err) ) @@ -1178,7 +1178,7 @@ static int tolua_Cocos2d_CCArray_fastRemoveObject00(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"CCArray",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"Object",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cc.Ref",0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; @@ -1243,8 +1243,8 @@ static int tolua_Cocos2d_CCArray_exchangeObject00(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"CCArray",0,&tolua_err) || - !tolua_isusertype(tolua_S,2,"Object",0,&tolua_err) || - !tolua_isusertype(tolua_S,3,"Object",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cc.Ref",0,&tolua_err) || + !tolua_isusertype(tolua_S,3,"cc.Ref",0,&tolua_err) || !tolua_isnoobj(tolua_S,4,&tolua_err) ) goto tolua_lerror; @@ -1375,7 +1375,7 @@ static int tolua_Cocos2d_CCArray_replaceObjectAtIndex00(lua_State* tolua_S) if ( !tolua_isusertype(tolua_S,1,"CCArray",0,&tolua_err) || !tolua_isnumber(tolua_S,2,0,&tolua_err) || - !tolua_isusertype(tolua_S,3,"Object",0,&tolua_err) || + !tolua_isusertype(tolua_S,3,"cc.Ref",0,&tolua_err) || !tolua_isboolean(tolua_S,4,1,&tolua_err) || !tolua_isnoobj(tolua_S,5,&tolua_err) ) @@ -1909,7 +1909,7 @@ tolua_lerror: static int register_cocos2dx_deprecated_String(lua_State* tolua_S) { tolua_usertype(tolua_S, "CCString"); - tolua_cclass(tolua_S,"CCString","CCString","Object",NULL); + tolua_cclass(tolua_S,"CCString","CCString","cc.Ref",NULL); tolua_beginmodule(tolua_S,"CCString"); tolua_function(tolua_S,"intValue",tolua_Cocos2d_CCString_intValue00); tolua_function(tolua_S,"uintValue",tolua_Cocos2d_CCString_uintValue00); diff --git a/cocos/scripting/lua/script/DeprecatedClass.lua b/cocos/scripting/lua/script/DeprecatedClass.lua index 2dd357d759..f04f8cc96a 100644 --- a/cocos/scripting/lua/script/DeprecatedClass.lua +++ b/cocos/scripting/lua/script/DeprecatedClass.lua @@ -127,6 +127,14 @@ end _G["CCJumpBy"] = DeprecatedClass.CCJumpBy() --CCJumpBy class will be Deprecated,end +--CCObject class will be Deprecated,begin +function DeprecatedClass.CCObject() + deprecatedTip("CCObject","cc.Ref") + return cc.Ref +end +_G["CCObject"] = DeprecatedClass.CCObject() +--CCObject class will be Deprecated,end + --CCTransitionRotoZoom class will be Deprecated,begin function DeprecatedClass.CCTransitionRotoZoom() deprecatedTip("CCTransitionRotoZoom","cc.TransitionRotoZoom") @@ -2179,4 +2187,12 @@ end _G["cc.EGLView"] = DeprecatedClass.EGLView() --EGLView class will be Deprecated,end +--cc.Object class will be Deprecated,begin +function DeprecatedClass.Object() + deprecatedTip("cc.Object","cc.Ref") + return cc.Ref +end +_G["cc.Object"] = DeprecatedClass.Object() +--cc.Object class will be Deprecated,end + From e1c961aeace12afeea019d37e6694a9d1b132018 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 24 Feb 2014 10:49:36 +0800 Subject: [PATCH 16/21] Update AUTHORS [ci skip] --- AUTHORS | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 56429a10aa..263bb45e89 100644 --- a/AUTHORS +++ b/AUTHORS @@ -763,7 +763,10 @@ Developers: s3tc compressed textures with no mipmaps fail to be loaded. floatinghotpot - Fix a bug that no callback is invoked when websocket connection fails + Fixed a bug that no callback is invoked when websocket connection fails + + Linghui + Updated README of template: fix wrong platform java path. Retired Core Developers: WenSheng Yang From d6cd2eb05f444b493f27f80448b6d61cdd80b33c Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 24 Feb 2014 11:38:03 +0800 Subject: [PATCH 17/21] fix compiling error cause by using 'fmaxf'. --- cocos/2d/CCSprite.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 7357db7f7f..f5b8337d9c 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -634,8 +634,8 @@ bool Sprite::culling() const y -= screen_half.height; // convert content size to world coordinates - float wchw = hcsx * fmaxf(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4])); - float wchh = hcsy * fmaxf(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5])); + float wchw = hcsx * std::max(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4])); + float wchh = hcsy * std::max(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5])); // compare if it in the positive quarter of the screen float tmpx = (fabsf(x)-wchw); From b54607bfc9b1c05a840a2220850d77deda221f81 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Mon, 24 Feb 2014 11:54:58 +0800 Subject: [PATCH 18/21] only using std::max for window. --- cocos/2d/CCSprite.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index f5b8337d9c..4b5ae03fe2 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -634,8 +634,13 @@ bool Sprite::culling() const y -= screen_half.height; // convert content size to world coordinates +#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 float wchw = hcsx * std::max(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4])); float wchh = hcsy * std::max(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5])); +#else + float wchw = hcsx * fmaxf(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4])); + float wchh = hcsy * fmaxf(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5])); +#endif // compare if it in the positive quarter of the screen float tmpx = (fabsf(x)-wchw); From 5c0f0ebef6afdca6962f4475f470ce070aeae0f5 Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Mon, 24 Feb 2014 07:30:47 +0000 Subject: [PATCH 19/21] [AUTO][ci skip] : updating tools/project-creator/module/cocos_files.json --- tools/project-creator/module/cocos_files.json.REMOVED.git-id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/project-creator/module/cocos_files.json.REMOVED.git-id b/tools/project-creator/module/cocos_files.json.REMOVED.git-id index acdadad644..c1f1953390 100644 --- a/tools/project-creator/module/cocos_files.json.REMOVED.git-id +++ b/tools/project-creator/module/cocos_files.json.REMOVED.git-id @@ -1 +1 @@ -4424247ae9eeee1aa36e04fe3b2ece70024a8987 \ No newline at end of file +11ebf82464dc9b20c1ca271619f8b29cefafa691 \ No newline at end of file From e7ab60c4f55dea6151724db585928c3b363b221d Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 24 Feb 2014 17:01:36 +0800 Subject: [PATCH 20/21] Update AUTHORS [ci skip] --- AUTHORS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index 263bb45e89..9f9fafb000 100644 --- a/AUTHORS +++ b/AUTHORS @@ -767,6 +767,9 @@ Developers: Linghui Updated README of template: fix wrong platform java path. + + seemk + Fixed crash if invoking Director::end() on WINDOWS. Retired Core Developers: WenSheng Yang From 8437e5f08b36643a14bde53e571adf1cbb7ecdee Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 24 Feb 2014 17:02:38 +0800 Subject: [PATCH 21/21] Update CHANGELOG [ci skip] --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 85319da06c..b053d658dd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ cocos2d-x-3.0rc0 Feb.?? 2014 [NEW] Language: Added Dutch support. [NEW] Sprite: Added auto-culling support + [FIX] Crash if invoking Director::end() on WINDOWS. [FIX] Character would not be aligned on the baseline when label using distance field. [FIX] Adds a macro to disable inserting script binding relevant codes. [FIX] Removing child from TMXLayer may cause crash.