From 4a10f2966625ffd12e4e2ede139d32717bbe3348 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Wed, 29 Mar 2017 16:57:25 +0800 Subject: [PATCH 1/7] fixed physics memory leak --- .../cocos2d_libs.xcodeproj/project.pbxproj | 155 ++++++---- .../creator/CCPhysicsContactWrapper.cpp | 9 + .../creator/CCPhysicsContactWrapper.h | 14 + .../creator/CCPhysicsWorldManifoldWrapper.cpp | 9 + .../creator/CCPhysicsWorldManifoldWrapper.h | 14 + .../physics/CCPhysicsAABBQueryCallback.cpp | 52 ++++ .../physics/CCPhysicsAABBQueryCallback.h | 50 ++++ .../physics/CCPhysicsContactListener.cpp | 107 +++++++ .../physics/CCPhysicsContactListener.h | 62 ++++ .../creator/physics/CCPhysicsDebugDraw.cpp | 109 +++++++ .../creator/physics/CCPhysicsDebugDraw.h | 62 ++++ .../creator/physics/CCPhysicsDefine.h | 14 + .../physics/CCPhysicsManifoldWrapper.cpp | 9 + .../physics/CCPhysicsManifoldWrapper.h | 14 + .../physics/CCPhysicsRayCastCallback.cpp | 69 +++++ .../physics/CCPhysicsRayCastCallback.h | 55 ++++ .../creator/physics/CCPhysicsUtils.cpp | 100 +++++++ .../creator/physics/CCPhysicsUtils.h | 60 ++++ .../physics/CCPhysicsWorldManifoldWrapper.cpp | 55 ++++ .../physics/CCPhysicsWorldManifoldWrapper.h | 51 ++++ .../auto/api/jsb_creator_auto_api.js | 94 ++++++ .../js-bindings/auto/jsb_creator_auto.cpp | 274 +++++++++++++++++- .../js-bindings/auto/jsb_creator_auto.hpp | 17 ++ .../creator/js_bindings_creator_manual.cpp | 88 +----- native/tools/tojs/creator.ini | 6 +- native/tools/tojs/genbindings.py | 25 +- 26 files changed, 1414 insertions(+), 160 deletions(-) create mode 100644 native/cocos/editor-support/creator/CCPhysicsContactWrapper.cpp create mode 100644 native/cocos/editor-support/creator/CCPhysicsContactWrapper.h create mode 100644 native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.cpp create mode 100644 native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.h create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.cpp create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.h create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.cpp create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.h create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsDefine.h create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.cpp create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.cpp create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.h create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsUtils.h create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.cpp create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h diff --git a/native/build/cocos2d_libs.xcodeproj/project.pbxproj b/native/build/cocos2d_libs.xcodeproj/project.pbxproj index ed3ae91c3f..1029062863 100644 --- a/native/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/native/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -638,18 +638,6 @@ 464AD6E6197EBB1400E502D8 /* pvr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 464AD6E3197EBB1400E502D8 /* pvr.cpp */; }; 464AD6E7197EBB1400E502D8 /* pvr.h in Headers */ = {isa = PBXBuildFile; fileRef = 464AD6E4197EBB1400E502D8 /* pvr.h */; }; 464AD6E8197EBB1400E502D8 /* pvr.h in Headers */ = {isa = PBXBuildFile; fileRef = 464AD6E4197EBB1400E502D8 /* pvr.h */; }; - 4D11DCC71E48450D00DB6838 /* CCPhysicsContactListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D11DCC41E48450D00DB6838 /* CCPhysicsContactListener.h */; }; - 4D11DCC81E48450D00DB6838 /* CCPhysicsContactListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D11DCC41E48450D00DB6838 /* CCPhysicsContactListener.h */; }; - 4D11DCD41E487FA700DB6838 /* CCPhysicsAABBQueryCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D11DCD11E487FA700DB6838 /* CCPhysicsAABBQueryCallback.h */; }; - 4D11DCD51E487FA700DB6838 /* CCPhysicsAABBQueryCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D11DCD11E487FA700DB6838 /* CCPhysicsAABBQueryCallback.h */; }; - 4D2837131E0B7AE800501B7F /* CCPhysicsUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2837111E0B7AE800501B7F /* CCPhysicsUtils.cpp */; }; - 4D2837141E0B7AE800501B7F /* CCPhysicsUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2837111E0B7AE800501B7F /* CCPhysicsUtils.cpp */; }; - 4D2837151E0B7AE800501B7F /* CCPhysicsUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D2837121E0B7AE800501B7F /* CCPhysicsUtils.h */; }; - 4D2837161E0B7AE800501B7F /* CCPhysicsUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D2837121E0B7AE800501B7F /* CCPhysicsUtils.h */; }; - 4D2837191E0B7B6300501B7F /* CCPhysicsDebugDraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2837171E0B7B6300501B7F /* CCPhysicsDebugDraw.cpp */; }; - 4D28371A1E0B7B6300501B7F /* CCPhysicsDebugDraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2837171E0B7B6300501B7F /* CCPhysicsDebugDraw.cpp */; }; - 4D28371B1E0B7B6300501B7F /* CCPhysicsDebugDraw.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D2837181E0B7B6300501B7F /* CCPhysicsDebugDraw.h */; }; - 4D28371C1E0B7B6300501B7F /* CCPhysicsDebugDraw.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D2837181E0B7B6300501B7F /* CCPhysicsDebugDraw.h */; }; 4D2E69071CC543B40032DD5C /* CCGraphicsNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2E69031CC543B40032DD5C /* CCGraphicsNode.cpp */; }; 4D2E69081CC543B40032DD5C /* CCGraphicsNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2E69031CC543B40032DD5C /* CCGraphicsNode.cpp */; }; 4D2E69091CC543B40032DD5C /* CCGraphicsNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D2E69041CC543B40032DD5C /* CCGraphicsNode.h */; }; @@ -658,8 +646,6 @@ 4D2E690C1CC543B40032DD5C /* Triangulate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2E69051CC543B40032DD5C /* Triangulate.cpp */; }; 4D2E690D1CC543B40032DD5C /* Triangulate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D2E69061CC543B40032DD5C /* Triangulate.h */; }; 4D2E690E1CC543B40032DD5C /* Triangulate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D2E69061CC543B40032DD5C /* Triangulate.h */; }; - 4D3818D11E6D4EDB00DA344B /* CCPhysicsRayCastCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D3818CE1E6D4EDB00DA344B /* CCPhysicsRayCastCallback.h */; }; - 4D3818D21E6D4EDB00DA344B /* CCPhysicsRayCastCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D3818CE1E6D4EDB00DA344B /* CCPhysicsRayCastCallback.h */; }; 4D6CF4371E83AAD5003327D4 /* CCCameraNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D6CF4351E83AAD5003327D4 /* CCCameraNode.cpp */; }; 4D6CF4381E83AAD5003327D4 /* CCCameraNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D6CF4351E83AAD5003327D4 /* CCCameraNode.cpp */; }; 4D6CF4391E83AAD5003327D4 /* CCCameraNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D6CF4361E83AAD5003327D4 /* CCCameraNode.h */; }; @@ -668,12 +654,34 @@ 4D76BE3B1A4AAF0A00102962 /* CCActionTimelineNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */; }; 4D76BE3C1A4AAF0A00102962 /* CCActionTimelineNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */; }; 4D76BE3D1A4AAF0A00102962 /* CCActionTimelineNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */; }; - 4D938F981E77E59400C35653 /* CCPhysicsAABBQueryCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D938F951E77E59400C35653 /* CCPhysicsAABBQueryCallback.cpp */; }; - 4D938F991E77E59400C35653 /* CCPhysicsContactListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D938F961E77E59400C35653 /* CCPhysicsContactListener.cpp */; }; - 4D938F9A1E77E59400C35653 /* CCPhysicsRayCastCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D938F971E77E59400C35653 /* CCPhysicsRayCastCallback.cpp */; }; - 4D938F9B1E77E5A100C35653 /* CCPhysicsAABBQueryCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D938F951E77E59400C35653 /* CCPhysicsAABBQueryCallback.cpp */; }; - 4D938F9C1E77E5A400C35653 /* CCPhysicsContactListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D938F961E77E59400C35653 /* CCPhysicsContactListener.cpp */; }; - 4D938F9D1E77E5A700C35653 /* CCPhysicsRayCastCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D938F971E77E59400C35653 /* CCPhysicsRayCastCallback.cpp */; }; + 4DC06BCF1E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BC11E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.cpp */; }; + 4DC06BD01E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BC11E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.cpp */; }; + 4DC06BD11E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BC21E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.h */; }; + 4DC06BD21E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BC21E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.h */; }; + 4DC06BD31E8A68D400CA08B1 /* CCPhysicsContactListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BC31E8A68D400CA08B1 /* CCPhysicsContactListener.cpp */; }; + 4DC06BD41E8A68D400CA08B1 /* CCPhysicsContactListener.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BC31E8A68D400CA08B1 /* CCPhysicsContactListener.cpp */; }; + 4DC06BD51E8A68D400CA08B1 /* CCPhysicsContactListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BC41E8A68D400CA08B1 /* CCPhysicsContactListener.h */; }; + 4DC06BD61E8A68D400CA08B1 /* CCPhysicsContactListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BC41E8A68D400CA08B1 /* CCPhysicsContactListener.h */; }; + 4DC06BDB1E8A68D400CA08B1 /* CCPhysicsDebugDraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BC71E8A68D400CA08B1 /* CCPhysicsDebugDraw.cpp */; }; + 4DC06BDC1E8A68D400CA08B1 /* CCPhysicsDebugDraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BC71E8A68D400CA08B1 /* CCPhysicsDebugDraw.cpp */; }; + 4DC06BDD1E8A68D400CA08B1 /* CCPhysicsDebugDraw.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BC81E8A68D400CA08B1 /* CCPhysicsDebugDraw.h */; }; + 4DC06BDE1E8A68D400CA08B1 /* CCPhysicsDebugDraw.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BC81E8A68D400CA08B1 /* CCPhysicsDebugDraw.h */; }; + 4DC06BDF1E8A68D400CA08B1 /* CCPhysicsRayCastCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BC91E8A68D400CA08B1 /* CCPhysicsRayCastCallback.cpp */; }; + 4DC06BE01E8A68D400CA08B1 /* CCPhysicsRayCastCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BC91E8A68D400CA08B1 /* CCPhysicsRayCastCallback.cpp */; }; + 4DC06BE11E8A68D400CA08B1 /* CCPhysicsRayCastCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BCA1E8A68D400CA08B1 /* CCPhysicsRayCastCallback.h */; }; + 4DC06BE21E8A68D400CA08B1 /* CCPhysicsRayCastCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BCA1E8A68D400CA08B1 /* CCPhysicsRayCastCallback.h */; }; + 4DC06BE31E8A68D400CA08B1 /* CCPhysicsUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BCB1E8A68D400CA08B1 /* CCPhysicsUtils.cpp */; }; + 4DC06BE41E8A68D400CA08B1 /* CCPhysicsUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BCB1E8A68D400CA08B1 /* CCPhysicsUtils.cpp */; }; + 4DC06BE51E8A68D400CA08B1 /* CCPhysicsUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BCC1E8A68D400CA08B1 /* CCPhysicsUtils.h */; }; + 4DC06BE61E8A68D400CA08B1 /* CCPhysicsUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BCC1E8A68D400CA08B1 /* CCPhysicsUtils.h */; }; + 4DC06BE71E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BCD1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.cpp */; }; + 4DC06BE81E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BCD1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.cpp */; }; + 4DC06BE91E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BCE1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.h */; }; + 4DC06BEA1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BCE1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.h */; }; + 4DC06BED1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BEB1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.cpp */; }; + 4DC06BEE1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DC06BEB1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.cpp */; }; + 4DC06BEF1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BEC1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.h */; }; + 4DC06BF01E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DC06BEC1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.h */; }; 4DED47D21DFFA4AF0070C5C4 /* Box2D.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DED476B1DFFA4AF0070C5C4 /* Box2D.h */; }; 4DED47D31DFFA4AF0070C5C4 /* Box2D.h in Headers */ = {isa = PBXBuildFile; fileRef = 4DED476B1DFFA4AF0070C5C4 /* Box2D.h */; }; 4DED47D41DFFA4AF0070C5C4 /* b2BroadPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DED476F1DFFA4AF0070C5C4 /* b2BroadPhase.cpp */; }; @@ -2263,24 +2271,29 @@ 46A168631807AF4E005B8026 /* CCTableView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCTableView.h; sourceTree = ""; }; 46A168641807AF4E005B8026 /* CCTableViewCell.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCTableViewCell.cpp; sourceTree = ""; }; 46A168651807AF4E005B8026 /* CCTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCTableViewCell.h; sourceTree = ""; }; - 4D11DCC41E48450D00DB6838 /* CCPhysicsContactListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCPhysicsContactListener.h; path = creator/CCPhysicsContactListener.h; sourceTree = ""; }; - 4D11DCD11E487FA700DB6838 /* CCPhysicsAABBQueryCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCPhysicsAABBQueryCallback.h; path = creator/CCPhysicsAABBQueryCallback.h; sourceTree = ""; }; - 4D2837111E0B7AE800501B7F /* CCPhysicsUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCPhysicsUtils.cpp; path = creator/CCPhysicsUtils.cpp; sourceTree = ""; }; - 4D2837121E0B7AE800501B7F /* CCPhysicsUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCPhysicsUtils.h; path = creator/CCPhysicsUtils.h; sourceTree = ""; }; - 4D2837171E0B7B6300501B7F /* CCPhysicsDebugDraw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCPhysicsDebugDraw.cpp; path = creator/CCPhysicsDebugDraw.cpp; sourceTree = ""; }; - 4D2837181E0B7B6300501B7F /* CCPhysicsDebugDraw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCPhysicsDebugDraw.h; path = creator/CCPhysicsDebugDraw.h; sourceTree = ""; }; 4D2E69031CC543B40032DD5C /* CCGraphicsNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCGraphicsNode.cpp; path = creator/CCGraphicsNode.cpp; sourceTree = ""; }; 4D2E69041CC543B40032DD5C /* CCGraphicsNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCGraphicsNode.h; path = creator/CCGraphicsNode.h; sourceTree = ""; }; 4D2E69051CC543B40032DD5C /* Triangulate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Triangulate.cpp; path = creator/Triangulate.cpp; sourceTree = ""; }; 4D2E69061CC543B40032DD5C /* Triangulate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Triangulate.h; path = creator/Triangulate.h; sourceTree = ""; }; - 4D3818CE1E6D4EDB00DA344B /* CCPhysicsRayCastCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCPhysicsRayCastCallback.h; path = creator/CCPhysicsRayCastCallback.h; sourceTree = ""; }; 4D6CF4351E83AAD5003327D4 /* CCCameraNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCCameraNode.cpp; path = creator/CCCameraNode.cpp; sourceTree = ""; }; 4D6CF4361E83AAD5003327D4 /* CCCameraNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCCameraNode.h; path = creator/CCCameraNode.h; sourceTree = ""; }; 4D76BE381A4AAF0A00102962 /* CCActionTimelineNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCActionTimelineNode.cpp; sourceTree = ""; }; 4D76BE391A4AAF0A00102962 /* CCActionTimelineNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCActionTimelineNode.h; sourceTree = ""; }; - 4D938F951E77E59400C35653 /* CCPhysicsAABBQueryCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCPhysicsAABBQueryCallback.cpp; path = creator/CCPhysicsAABBQueryCallback.cpp; sourceTree = ""; }; - 4D938F961E77E59400C35653 /* CCPhysicsContactListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCPhysicsContactListener.cpp; path = creator/CCPhysicsContactListener.cpp; sourceTree = ""; }; - 4D938F971E77E59400C35653 /* CCPhysicsRayCastCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCPhysicsRayCastCallback.cpp; path = creator/CCPhysicsRayCastCallback.cpp; sourceTree = ""; }; + 4DC06BC11E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsAABBQueryCallback.cpp; sourceTree = ""; }; + 4DC06BC21E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsAABBQueryCallback.h; sourceTree = ""; }; + 4DC06BC31E8A68D400CA08B1 /* CCPhysicsContactListener.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsContactListener.cpp; sourceTree = ""; }; + 4DC06BC41E8A68D400CA08B1 /* CCPhysicsContactListener.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsContactListener.h; sourceTree = ""; }; + 4DC06BC71E8A68D400CA08B1 /* CCPhysicsDebugDraw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsDebugDraw.cpp; sourceTree = ""; }; + 4DC06BC81E8A68D400CA08B1 /* CCPhysicsDebugDraw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsDebugDraw.h; sourceTree = ""; }; + 4DC06BC91E8A68D400CA08B1 /* CCPhysicsRayCastCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsRayCastCallback.cpp; sourceTree = ""; }; + 4DC06BCA1E8A68D400CA08B1 /* CCPhysicsRayCastCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsRayCastCallback.h; sourceTree = ""; }; + 4DC06BCB1E8A68D400CA08B1 /* CCPhysicsUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsUtils.cpp; sourceTree = ""; }; + 4DC06BCC1E8A68D400CA08B1 /* CCPhysicsUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsUtils.h; sourceTree = ""; }; + 4DC06BCD1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsWorldManifoldWrapper.cpp; sourceTree = ""; }; + 4DC06BCE1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsWorldManifoldWrapper.h; sourceTree = ""; }; + 4DC06BEB1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsManifoldWrapper.cpp; sourceTree = ""; }; + 4DC06BEC1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsManifoldWrapper.h; sourceTree = ""; }; + 4DC06BF11E8B8D1300CA08B1 /* CCPhysicsDefine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCPhysicsDefine.h; sourceTree = ""; }; 4DED476B1DFFA4AF0070C5C4 /* Box2D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Box2D.h; sourceTree = ""; }; 4DED476C1DFFA4AF0070C5C4 /* Box2DConfig.cmake.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Box2DConfig.cmake.in; sourceTree = ""; }; 4DED476D1DFFA4AF0070C5C4 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; @@ -4029,6 +4042,29 @@ path = ../cocos/math; sourceTree = ""; }; + 4DC06BC01E8A68D400CA08B1 /* physics */ = { + isa = PBXGroup; + children = ( + 4DC06BC11E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.cpp */, + 4DC06BC21E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.h */, + 4DC06BC31E8A68D400CA08B1 /* CCPhysicsContactListener.cpp */, + 4DC06BC41E8A68D400CA08B1 /* CCPhysicsContactListener.h */, + 4DC06BCD1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.cpp */, + 4DC06BCE1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.h */, + 4DC06BEB1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.cpp */, + 4DC06BEC1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.h */, + 4DC06BC71E8A68D400CA08B1 /* CCPhysicsDebugDraw.cpp */, + 4DC06BC81E8A68D400CA08B1 /* CCPhysicsDebugDraw.h */, + 4DC06BC91E8A68D400CA08B1 /* CCPhysicsRayCastCallback.cpp */, + 4DC06BCA1E8A68D400CA08B1 /* CCPhysicsRayCastCallback.h */, + 4DC06BCB1E8A68D400CA08B1 /* CCPhysicsUtils.cpp */, + 4DC06BCC1E8A68D400CA08B1 /* CCPhysicsUtils.h */, + 4DC06BF11E8B8D1300CA08B1 /* CCPhysicsDefine.h */, + ); + name = physics; + path = creator/physics; + sourceTree = ""; + }; 4DED476A1DFFA4AF0070C5C4 /* Box2D */ = { isa = PBXGroup; children = ( @@ -4192,22 +4228,13 @@ 4DFA4C141CBCE32800E3B736 /* creator */ = { isa = PBXGroup; children = ( - 4D2837171E0B7B6300501B7F /* CCPhysicsDebugDraw.cpp */, - 4D2837181E0B7B6300501B7F /* CCPhysicsDebugDraw.h */, + 4DC06BC01E8A68D400CA08B1 /* physics */, 4D2E69031CC543B40032DD5C /* CCGraphicsNode.cpp */, 4D2E69041CC543B40032DD5C /* CCGraphicsNode.h */, 4D2E69051CC543B40032DD5C /* Triangulate.cpp */, 4D2E69061CC543B40032DD5C /* Triangulate.h */, 4DFA4C151CBCE34100E3B736 /* CCScale9Sprite.cpp */, 4DFA4C161CBCE34100E3B736 /* CCScale9Sprite.h */, - 4D2837111E0B7AE800501B7F /* CCPhysicsUtils.cpp */, - 4D2837121E0B7AE800501B7F /* CCPhysicsUtils.h */, - 4D938F961E77E59400C35653 /* CCPhysicsContactListener.cpp */, - 4D11DCC41E48450D00DB6838 /* CCPhysicsContactListener.h */, - 4D938F951E77E59400C35653 /* CCPhysicsAABBQueryCallback.cpp */, - 4D11DCD11E487FA700DB6838 /* CCPhysicsAABBQueryCallback.h */, - 4D938F971E77E59400C35653 /* CCPhysicsRayCastCallback.cpp */, - 4D3818CE1E6D4EDB00DA344B /* CCPhysicsRayCastCallback.h */, 4D6CF4351E83AAD5003327D4 /* CCCameraNode.cpp */, 4D6CF4361E83AAD5003327D4 /* CCCameraNode.h */, ); @@ -4828,7 +4855,6 @@ 4DED48101DFFA4AF0070C5C4 /* b2Settings.h in Headers */, BAFF7C941D59E0DA0051B92F /* CCArmatureDefine.h in Headers */, 4DED486A1DFFA4AF0070C5C4 /* b2MotorJoint.h in Headers */, - 4D11DCD41E487FA700DB6838 /* CCPhysicsAABBQueryCallback.h in Headers */, 50ABBE8D1925AB6F00A911A9 /* CCNS.h in Headers */, 50ABBEA51925AB6F00A911A9 /* CCScriptSupport.h in Headers */, BAFF7CC61D59E0DB0051B92F /* CCDisplayFactory.h in Headers */, @@ -4882,6 +4908,7 @@ 15AE187B19AAD33D00C27E9E /* CCBAnimationManager.h in Headers */, C503066C1B60B583001E6D43 /* CCSkeletonNode.h in Headers */, 1A57006B180BC5A10088DEC7 /* CCActionCatmullRom.h in Headers */, + 4DC06BEF1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.h in Headers */, 4DED487A1DFFA4AF0070C5C4 /* b2RevoluteJoint.h in Headers */, 4D76BE3C1A4AAF0A00102962 /* CCActionTimelineNode.h in Headers */, 4DED487E1DFFA4AF0070C5C4 /* b2RopeJoint.h in Headers */, @@ -4906,6 +4933,7 @@ 15AE188719AAD33D00C27E9E /* CCBSequenceProperty.h in Headers */, 4D2E690D1CC543B40032DD5C /* Triangulate.h in Headers */, 1A570083180BC5A10088DEC7 /* CCActionManager.h in Headers */, + 4DC06BE51E8A68D400CA08B1 /* CCPhysicsUtils.h in Headers */, 4DED483E1DFFA4AF0070C5C4 /* b2CircleContact.h in Headers */, 4DFA4C191CBCE34100E3B736 /* CCScale9Sprite.h in Headers */, 4DED48181DFFA4AF0070C5C4 /* b2Timer.h in Headers */, @@ -5037,11 +5065,13 @@ 1A570223180BCC1A0088DEC7 /* CCParticleBatchNode.h in Headers */, 4D6CF4391E83AAD5003327D4 /* CCCameraNode.h in Headers */, FAC8F6681E1DF15D002B17E8 /* kvec.h in Headers */, + 4DC06BE11E8A68D400CA08B1 /* CCPhysicsRayCastCallback.h in Headers */, 15AE1BD519AAE01E00C27E9E /* CCControlSaturationBrightnessPicker.h in Headers */, 15AE186919AAD31D00C27E9E /* CocosDenshion.h in Headers */, 50ABBD891925AB4100A911A9 /* CCCustomCommand.h in Headers */, 5034CA43191D591100CE6051 /* ccShader_Label.vert in Headers */, 15AE189719AAD33D00C27E9E /* CCMenuItemImageLoader.h in Headers */, + 4DC06BDD1E8A68D400CA08B1 /* CCPhysicsDebugDraw.h in Headers */, 15AE189319AAD33D00C27E9E /* CCLayerGradientLoader.h in Headers */, 1A570227180BCC1A0088DEC7 /* CCParticleExamples.h in Headers */, FA6F1B851D80F858007DD223 /* BaseFactory.h in Headers */, @@ -5077,7 +5107,6 @@ BAFF7D4C1D5C1CF80051B92F /* AnimationState.h in Headers */, BAFF7D541D5C1CF80051B92F /* Atlas.h in Headers */, 1A570280180BCC900088DEC7 /* CCSprite.h in Headers */, - 4D28371B1E0B7B6300501B7F /* CCPhysicsDebugDraw.h in Headers */, 15AE1B4E19AADA9900C27E9E /* UIListView.h in Headers */, 1A570284180BCC900088DEC7 /* CCSpriteBatchNode.h in Headers */, 5034CA2B191D591100CE6051 /* ccShader_PositionTextureA8Color.vert in Headers */, @@ -5123,6 +5152,7 @@ BA68D7871D62F4A500B7A3F9 /* advancing_front.h in Headers */, 1A12775B18DFCC540005F345 /* CCTweenFunction.h in Headers */, 1A5702CA180BCE370088DEC7 /* CCTextFieldTTF.h in Headers */, + 4DC06BD51E8A68D400CA08B1 /* CCPhysicsContactListener.h in Headers */, BAFF7D741D5C1CF80051B92F /* Cocos2dAttachmentLoader.h in Headers */, 15EFA213198A2BB5000C57D3 /* CCProtectedNode.h in Headers */, 1A5702EC180BCE750088DEC7 /* CCTileMapAtlas.h in Headers */, @@ -5196,6 +5226,7 @@ 4DED483A1DFFA4AF0070C5C4 /* b2ChainAndPolygonContact.h in Headers */, 4DED48561DFFA4AF0070C5C4 /* b2PolygonContact.h in Headers */, 50ABBE6F1925AB6F00A911A9 /* CCEventListenerKeyboard.h in Headers */, + 4DC06BE91E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.h in Headers */, 50ABBE9D1925AB6F00A911A9 /* CCRefPtr.h in Headers */, 4DED484A1DFFA4AF0070C5C4 /* b2EdgeAndCircleContact.h in Headers */, FA6F1B631D80F858007DD223 /* TransformObject.h in Headers */, @@ -5242,6 +5273,7 @@ 50ABBEC91925AB6F00A911A9 /* firePngData.h in Headers */, FAC8F25D1D339EB70061CEDD /* CCTMXLayer.h in Headers */, BAFF7CF61D59E3840051B92F /* CocosStudioExtension.h in Headers */, + 4DC06BD11E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.h in Headers */, 503DD8F51926B0DB00CD74DD /* CCIMEDelegate.h in Headers */, 50ABBD5A1925AB0000A911A9 /* Vec2.h in Headers */, BAFF7CCE1D59E0DB0051B92F /* CCInputDelegate.h in Headers */, @@ -5252,7 +5284,6 @@ 15AE188F19AAD33D00C27E9E /* CCLabelTTFLoader.h in Headers */, 50ABBEBD1925AB6F00A911A9 /* ccUtils.h in Headers */, 4DED486E1DFFA4AF0070C5C4 /* b2MouseJoint.h in Headers */, - 4D11DCC71E48450D00DB6838 /* CCPhysicsContactListener.h in Headers */, A0534A651B872FFD006B03E5 /* CCDownloader-apple.h in Headers */, BA679B361CEC373000F875FA /* CCEventAssetsManagerEx.h in Headers */, 50ABC0231926664800A911A9 /* CCGLViewImpl-desktop.h in Headers */, @@ -5280,7 +5311,6 @@ 50ABBE671925AB6F00A911A9 /* CCEventListenerCustom.h in Headers */, 50ABBE2F1925AB6F00A911A9 /* ccConfig.h in Headers */, 15AE188019AAD33D00C27E9E /* CCBMemberVariableAssigner.h in Headers */, - 4D3818D11E6D4EDB00DA344B /* CCPhysicsRayCastCallback.h in Headers */, 1AAF5851180E40B9000584C8 /* LocalStorage.h in Headers */, A0E749F91BA8FD7F001A8332 /* UIEditBoxImpl-common.h in Headers */, FA6F1B9F1D80F858007DD223 /* FrameData.h in Headers */, @@ -5326,7 +5356,6 @@ 464AD6E7197EBB1400E502D8 /* pvr.h in Headers */, BAFF7D801D5C1CF80051B92F /* extension.h in Headers */, BAFF7C741D59E0DA0051B92F /* CCActionFrame.h in Headers */, - 4D2837151E0B7AE800501B7F /* CCPhysicsUtils.h in Headers */, 4DED48281DFFA4AF0070C5C4 /* b2Island.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -5351,6 +5380,7 @@ 5034CA38191D591100CE6051 /* ccShader_PositionColorLengthTexture.vert in Headers */, 15AE1B8119AADA9A00C27E9E /* UITextAtlas.h in Headers */, 50ABBE7C1925AB6F00A911A9 /* CCEventMouse.h in Headers */, + 4DC06BD21E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.h in Headers */, 50ABBE9C1925AB6F00A911A9 /* CCRef.h in Headers */, 50ABBD961925AB4100A911A9 /* CCGLProgramState.h in Headers */, 4649FF031BBA9FBE0001CC6F /* CCVertexAttribBinding.h in Headers */, @@ -5390,6 +5420,7 @@ BAFF7D591D5C1CF80051B92F /* AtlasAttachmentLoader.h in Headers */, 4DED486F1DFFA4AF0070C5C4 /* b2MouseJoint.h in Headers */, 503DD8EC1926736A00CD74DD /* CCGLViewImpl-ios.h in Headers */, + 4DC06BEA1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.h in Headers */, BAFF7D7D1D5C1CF80051B92F /* EventData.h in Headers */, FA6F1B9C1D80F858007DD223 /* DragonBonesData.h in Headers */, 15AE18D819AAD33D00C27E9E /* CCScrollViewLoader.h in Headers */, @@ -5527,7 +5558,6 @@ 50ABBDA61925AB4100A911A9 /* CCQuadCommand.h in Headers */, 15AE1BB019AADFDF00C27E9E /* UILayoutManager.h in Headers */, 50ABBE9E1925AB6F00A911A9 /* CCRefPtr.h in Headers */, - 4D2837161E0B7AE800501B7F /* CCPhysicsUtils.h in Headers */, 15AE18DA19AAD33D00C27E9E /* CCSpriteLoader.h in Headers */, 1A5701CA180BCB5A0088DEC7 /* CCLabelTextFormatter.h in Headers */, 50643BDC19BFAF4400EF68ED /* CCStdC.h in Headers */, @@ -5558,6 +5588,7 @@ 1A5701FA180BCBAD0088DEC7 /* CCMenu.h in Headers */, FA6F1BA01D80F858007DD223 /* FrameData.h in Headers */, BAFF7CE91D59E0DB0051B92F /* CocosStudioExport.h in Headers */, + 4DC06BD61E8A68D400CA08B1 /* CCPhysicsContactListener.h in Headers */, BAFF7C7D1D59E0DA0051B92F /* CCActionManagerEx.h in Headers */, 15AE18BA19AAD33D00C27E9E /* CCControlButtonLoader.h in Headers */, 1A5701FE180BCBAD0088DEC7 /* CCMenuItem.h in Headers */, @@ -5578,6 +5609,7 @@ BAFF7DB11D5C1CF80051B92F /* SkeletonBounds.h in Headers */, 15AE1C0419AAE01E00C27E9E /* CCTableView.h in Headers */, 50ABBEA21925AB6F00A911A9 /* CCScheduler.h in Headers */, + 4DC06BE21E8A68D400CA08B1 /* CCPhysicsRayCastCallback.h in Headers */, 4DED48431DFFA4AF0070C5C4 /* b2Contact.h in Headers */, 1A57020B180BCBDF0088DEC7 /* CCMotionStreak.h in Headers */, 1A75DC171DFE3C7700A271DF /* AudioDecoder.h in Headers */, @@ -5598,6 +5630,7 @@ 29394CF119B01DBA00D2DE1A /* UIWebView.h in Headers */, 2980F0261BA9A5550059E678 /* CCUISingleLineTextField.h in Headers */, 15AE18B419AAD33D00C27E9E /* CCBSelectorResolver.h in Headers */, + 4DC06BDE1E8A68D400CA08B1 /* CCPhysicsDebugDraw.h in Headers */, B24AA988195A675C007B4522 /* CCFastTMXLayer.h in Headers */, 15AE1B7319AADA9A00C27E9E /* UIListView.h in Headers */, 5034CA2C191D591100CE6051 /* ccShader_PositionTextureA8Color.vert in Headers */, @@ -5615,7 +5648,6 @@ 15EFA214198A2BB5000C57D3 /* CCProtectedNode.h in Headers */, 4DED485B1DFFA4AF0070C5C4 /* b2DistanceJoint.h in Headers */, 15AE1B8719AADA9A00C27E9E /* UIButton.h in Headers */, - 4D11DCD51E487FA700DB6838 /* CCPhysicsAABBQueryCallback.h in Headers */, 50ABBE441925AB6F00A911A9 /* CCDirector.h in Headers */, BAFF7DC91D5C1CF80051B92F /* SlotData.h in Headers */, BAFF7DB91D5C1CF80051B92F /* SkeletonJson.h in Headers */, @@ -5700,6 +5732,7 @@ 15AE1BC419AADFFB00C27E9E /* ExtensionMacros.h in Headers */, 15AE185A19AAD31200C27E9E /* CDConfig.h in Headers */, 15AE1BFE19AAE01E00C27E9E /* CCInvocation.h in Headers */, + 4DC06BF01E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.h in Headers */, 50ABBD4B1925AB0000A911A9 /* Mat4.h in Headers */, 15AE1BBE19AADFF000C27E9E /* SocketIO.h in Headers */, 50ABBED61925AB6F00A911A9 /* utlist.h in Headers */, @@ -5709,13 +5742,11 @@ FA6F1BA81D80F858007DD223 /* DataParser.h in Headers */, 50ABBD531925AB0000A911A9 /* Quaternion.h in Headers */, 503DD8E81926736A00CD74DD /* CCES2Renderer-ios.h in Headers */, - 4D3818D21E6D4EDB00DA344B /* CCPhysicsRayCastCallback.h in Headers */, BAFF7CF11D59E0DB0051B92F /* DictionaryHelper.h in Headers */, 50ABBE6C1925AB6F00A911A9 /* CCEventListenerFocus.h in Headers */, 5034CA3E191D591100CE6051 /* ccShader_PositionColor.frag in Headers */, 4DED484B1DFFA4AF0070C5C4 /* b2EdgeAndCircleContact.h in Headers */, 50ABBE301925AB6F00A911A9 /* ccConfig.h in Headers */, - 4D28371C1E0B7B6300501B7F /* CCPhysicsDebugDraw.h in Headers */, 50ABBDAC1925AB4100A911A9 /* CCRenderCommandPool.h in Headers */, 5034CA3C191D591100CE6051 /* ccShader_PositionColor.vert in Headers */, 50ABC0181926664800A911A9 /* CCImage.h in Headers */, @@ -5775,6 +5806,7 @@ 50ABBE821925AB6F00A911A9 /* CCEventType.h in Headers */, BAFF7D511D5C1CF80051B92F /* AnimationStateData.h in Headers */, 1AAF5852180E40B9000584C8 /* LocalStorage.h in Headers */, + 4DC06BE61E8A68D400CA08B1 /* CCPhysicsUtils.h in Headers */, 50CB247619D9C5A100687767 /* AudioCache.h in Headers */, 50ABBD471925AB0000A911A9 /* CCVertex.h in Headers */, 1A9DCA2A180E6955007A3AD4 /* CCGLBufferedNode.h in Headers */, @@ -5799,7 +5831,6 @@ 50ABC0201926664800A911A9 /* CCThread.h in Headers */, 15AE1B8519AADA9A00C27E9E /* UITextField.h in Headers */, BAFF7DA51D5C1CF80051B92F /* Skeleton.h in Headers */, - 4D11DCC81E48450D00DB6838 /* CCPhysicsContactListener.h in Headers */, 15AE184B19AAD30500C27E9E /* Export.h in Headers */, 50ABBED21925AB6F00A911A9 /* TGAlib.h in Headers */, 4DED47F11DFFA4AF0070C5C4 /* b2ChainShape.h in Headers */, @@ -5919,7 +5950,6 @@ 50ABBD581925AB0000A911A9 /* Vec2.cpp in Sources */, 50ABBE311925AB6F00A911A9 /* CCConfiguration.cpp in Sources */, 4D2E690B1CC543B40032DD5C /* Triangulate.cpp in Sources */, - 4D938F981E77E59400C35653 /* CCPhysicsAABBQueryCallback.cpp in Sources */, 15AE1BDA19AAE01E00C27E9E /* CCControlSwitch.cpp in Sources */, 4DED47F21DFFA4AF0070C5C4 /* b2CircleShape.cpp in Sources */, 15AE18DC19AAD35000C27E9E /* CocoLoader.cpp in Sources */, @@ -5930,6 +5960,7 @@ 50ABC0611926664800A911A9 /* CCCommon-mac.mm in Sources */, 50ABBDB11925AB4100A911A9 /* ccShaders.cpp in Sources */, 4DED483C1DFFA4AF0070C5C4 /* b2CircleContact.cpp in Sources */, + 4DC06BED1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.cpp in Sources */, A63CF00D1CD9CF3500A6971D /* CCUITextFieldFormatter.m in Sources */, 4DED47EA1DFFA4AF0070C5C4 /* b2TimeOfImpact.cpp in Sources */, FA6F1B511D80F858007DD223 /* WorldClock.cpp in Sources */, @@ -5960,6 +5991,7 @@ 50ABBE271925AB6F00A911A9 /* CCAutoreleasePool.cpp in Sources */, 15AE197419AAD35700C27E9E /* CCTimeLine.cpp in Sources */, BAFF7D6E1D5C1CF80051B92F /* BoundingBoxAttachment.c in Sources */, + 4DC06BDB1E8A68D400CA08B1 /* CCPhysicsDebugDraw.cpp in Sources */, 15AE188E19AAD33D00C27E9E /* CCLabelTTFLoader.cpp in Sources */, 50ABBE8B1925AB6F00A911A9 /* CCNS.cpp in Sources */, FA6F1B551D80F858007DD223 /* Armature.cpp in Sources */, @@ -6026,13 +6058,13 @@ 50ABBE651925AB6F00A911A9 /* CCEventListenerCustom.cpp in Sources */, 15AE189B19AAD33D00C27E9E /* CCNode+CCBRelativePositioning.cpp in Sources */, 50ABBE391925AB6F00A911A9 /* CCData.cpp in Sources */, + 4DC06BE71E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.cpp in Sources */, 1A57010E180BC8EE0088DEC7 /* CCDrawingPrimitives.cpp in Sources */, 50ABBED71925AB6F00A911A9 /* ZipUtils.cpp in Sources */, BAFF7DC21D5C1CF80051B92F /* Slot.c in Sources */, 1A570112180BC8EE0088DEC7 /* CCDrawNode.cpp in Sources */, 4DED482C1DFFA4AF0070C5C4 /* b2World.cpp in Sources */, 15AE186D19AAD31D00C27E9E /* SimpleAudioEngine_objc.m in Sources */, - 4D2837191E0B7B6300501B7F /* CCPhysicsDebugDraw.cpp in Sources */, 1A57011B180BC90D0088DEC7 /* CCGrabber.cpp in Sources */, 1A57011F180BC90D0088DEC7 /* CCGrid.cpp in Sources */, BAFF7D861D5C1CF80051B92F /* IkConstraintData.c in Sources */, @@ -6057,6 +6089,7 @@ BAFF7D6A1D5C1CF80051B92F /* BoneData.c in Sources */, 4DED48881DFFA4AF0070C5C4 /* b2Rope.cpp in Sources */, 1A5701B5180BCB590088DEC7 /* CCFontFreeType.cpp in Sources */, + 4DC06BDF1E8A68D400CA08B1 /* CCPhysicsRayCastCallback.cpp in Sources */, 1A5701B9180BCB5A0088DEC7 /* CCLabel.cpp in Sources */, 1A5701BD180BCB5A0088DEC7 /* CCLabelAtlas.cpp in Sources */, BA68D7B21D62F66300B7A3F9 /* CCPass.cpp in Sources */, @@ -6099,6 +6132,7 @@ 15AE186B19AAD31D00C27E9E /* SimpleAudioEngine.mm in Sources */, 50ABBDAD1925AB4100A911A9 /* CCRenderer.cpp in Sources */, BAFF7DB21D5C1CF80051B92F /* SkeletonData.c in Sources */, + 4DC06BD31E8A68D400CA08B1 /* CCPhysicsContactListener.cpp in Sources */, BA68D7BC1D62F71700B7A3F9 /* CCFrameBuffer.cpp in Sources */, 1A5701EE180BCB8C0088DEC7 /* CCTransitionProgress.cpp in Sources */, 15AE186619AAD31D00C27E9E /* CDOpenALSupport.m in Sources */, @@ -6125,6 +6159,7 @@ 15AE1B6119AADA9900C27E9E /* UIButton.cpp in Sources */, B276EF651988D1D500CD400F /* CCVertexIndexBuffer.cpp in Sources */, 50ABBE411925AB6F00A911A9 /* CCDirector.cpp in Sources */, + 4DC06BE31E8A68D400CA08B1 /* CCPhysicsUtils.cpp in Sources */, 1A570221180BCC1A0088DEC7 /* CCParticleBatchNode.cpp in Sources */, 1A570225180BCC1A0088DEC7 /* CCParticleExamples.cpp in Sources */, 1A570229180BCC1A0088DEC7 /* CCParticleSystem.cpp in Sources */, @@ -6199,7 +6234,6 @@ 15FB20741AE7BF8600C31518 /* CCAutoPolygon.cpp in Sources */, 15AE196C19AAD35700C27E9E /* CCActionTimeline.cpp in Sources */, BAFF7CAC1D59E0DA0051B92F /* CCComController.cpp in Sources */, - 4D938F9A1E77E59400C35653 /* CCPhysicsRayCastCallback.cpp in Sources */, 1A570310180BCF190088DEC7 /* CCComponentContainer.cpp in Sources */, 50ABBD3C1925AB0000A911A9 /* CCGeometry.cpp in Sources */, 15AE188A19AAD33D00C27E9E /* CCControlLoader.cpp in Sources */, @@ -6266,6 +6300,7 @@ 3E2F27A619CFBFE100E7C490 /* AudioEngine.cpp in Sources */, BA68D7A41D62F60100B7A3F9 /* UITabControl.cpp in Sources */, BAFF7DBE1D5C1CF80051B92F /* Skin.c in Sources */, + 4DC06BCF1E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.cpp in Sources */, 50ABBD9B1925AB4100A911A9 /* ccGLStateCache.cpp in Sources */, 15AE188119AAD33D00C27E9E /* CCBReader.cpp in Sources */, 50ABBDB91925AB4100A911A9 /* CCTextureAtlas.cpp in Sources */, @@ -6316,7 +6351,6 @@ A6F0D7A11C2796020029CC44 /* CCStencilStateManager.cpp in Sources */, 15AE1BB519AADFEF00C27E9E /* SocketIO.cpp in Sources */, 15AE1B6519AADA9900C27E9E /* UIImageView.cpp in Sources */, - 4D2837131E0B7AE800501B7F /* CCPhysicsUtils.cpp in Sources */, 4DED48341DFFA4AF0070C5C4 /* b2ChainAndCircleContact.cpp in Sources */, 50ABBE5D1925AB6F00A911A9 /* CCEventListener.cpp in Sources */, 4DED47E21DFFA4AF0070C5C4 /* b2Distance.cpp in Sources */, @@ -6330,7 +6364,6 @@ 50ABC05F1926664800A911A9 /* CCApplication-mac.mm in Sources */, 15AE189619AAD33D00C27E9E /* CCMenuItemImageLoader.cpp in Sources */, 15AE1BB719AADFEF00C27E9E /* WebSocket.cpp in Sources */, - 4D938F991E77E59400C35653 /* CCPhysicsContactListener.cpp in Sources */, 15AE1B5119AADA9900C27E9E /* UIPageView.cpp in Sources */, ED3057A11BEC77D50083C3ED /* xxhash.c in Sources */, 50ABBD381925AB0000A911A9 /* CCAffineTransform.cpp in Sources */, @@ -6395,7 +6428,6 @@ ED30578B1BEC774D0083C3ED /* ioapi_mem.cpp in Sources */, BAFF7CE11D59E0DB0051B92F /* CCTween.cpp in Sources */, FA6F1B421D80F858007DD223 /* Animation.cpp in Sources */, - 4D938F9D1E77E5A700C35653 /* CCPhysicsRayCastCallback.cpp in Sources */, BA68D7AF1D62F66300B7A3F9 /* CCMaterial.cpp in Sources */, B257B44F1989D5E800D9A687 /* CCPrimitive.cpp in Sources */, BAFF7CC91D59E0DB0051B92F /* CCDisplayManager.cpp in Sources */, @@ -6411,6 +6443,7 @@ 1A570062180BC5A10088DEC7 /* CCAction.cpp in Sources */, 1A570066180BC5A10088DEC7 /* CCActionCamera.cpp in Sources */, 4DED47E31DFFA4AF0070C5C4 /* b2Distance.cpp in Sources */, + 4DC06BE81E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.cpp in Sources */, B276EF661988D1D500CD400F /* CCVertexIndexBuffer.cpp in Sources */, 15AE1C0119AAE01E00C27E9E /* CCScrollView.cpp in Sources */, ED30579E1BEC77BD0083C3ED /* ConvertUTFWrapper.cpp in Sources */, @@ -6431,7 +6464,6 @@ ED30578C1BEC77510083C3ED /* ioapi.cpp in Sources */, 4DED48411DFFA4AF0070C5C4 /* b2Contact.cpp in Sources */, FA6F1B841D80F858007DD223 /* BaseFactory.cpp in Sources */, - 4D2837141E0B7AE800501B7F /* CCPhysicsUtils.cpp in Sources */, DABC9FAA19E7DFA900FA252C /* CCClippingRectangleNode.cpp in Sources */, 15AE1BF119AAE01E00C27E9E /* CCControlPotentiometer.cpp in Sources */, 4DED48791DFFA4AF0070C5C4 /* b2RevoluteJoint.cpp in Sources */, @@ -6458,6 +6490,7 @@ 50ABBEA01925AB6F00A911A9 /* CCScheduler.cpp in Sources */, 50ABBE4E1925AB6F00A911A9 /* CCEventCustom.cpp in Sources */, 15AE1BF519AAE01E00C27E9E /* CCControlSlider.cpp in Sources */, + 4DC06BEE1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.cpp in Sources */, 15AE18B719AAD33D00C27E9E /* CCBSequenceProperty.cpp in Sources */, 15AE18B919AAD33D00C27E9E /* CCControlButtonLoader.cpp in Sources */, 50ABBE761925AB6F00A911A9 /* CCEventListenerTouch.cpp in Sources */, @@ -6471,6 +6504,7 @@ 4DED480B1DFFA4AF0070C5C4 /* b2Math.cpp in Sources */, 1A57007A180BC5A10088DEC7 /* CCActionInstant.cpp in Sources */, 15AE1BEC19AAE01E00C27E9E /* CCControlColourPicker.cpp in Sources */, + 4DC06BD41E8A68D400CA08B1 /* CCPhysicsContactListener.cpp in Sources */, FA6F1B4E1D80F858007DD223 /* TimelineState.cpp in Sources */, 50ABBEC01925AB6F00A911A9 /* CCValue.cpp in Sources */, 50ABBD591925AB0000A911A9 /* Vec2.cpp in Sources */, @@ -6486,6 +6520,7 @@ BA679B311CEC373000F875FA /* AssetsManagerEx.cpp in Sources */, 1A57007E180BC5A10088DEC7 /* CCActionInterval.cpp in Sources */, 15AE1BF319AAE01E00C27E9E /* CCControlSaturationBrightnessPicker.cpp in Sources */, + 4DC06BD01E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.cpp in Sources */, 1A570082180BC5A10088DEC7 /* CCActionManager.cpp in Sources */, 4D6CF4381E83AAD5003327D4 /* CCCameraNode.cpp in Sources */, A0534A681B872FFD006B03E5 /* CCDownloader-apple.mm in Sources */, @@ -6519,7 +6554,6 @@ 292DB14A19B4574100A80320 /* UIEditBoxImpl-ios.mm in Sources */, 1A5701A2180BCB590088DEC7 /* CCFontAtlas.cpp in Sources */, 50ABC00E1926664800A911A9 /* CCFileUtils.cpp in Sources */, - 4D938F9C1E77E5A400C35653 /* CCPhysicsContactListener.cpp in Sources */, BAFF7CAD1D59E0DA0051B92F /* CCComController.cpp in Sources */, BAFF7C8B1D59E0DA0051B92F /* CCArmatureAnimation.cpp in Sources */, 299CF1FC19A434BC00C378C1 /* ccRandom.cpp in Sources */, @@ -6541,11 +6575,11 @@ BAFF7D971D5C1CF80051B92F /* PathConstraint.c in Sources */, 15AE18AD19AAD33D00C27E9E /* CCBFileLoader.cpp in Sources */, B5CE6DC91B3C05BA002B0419 /* UIRadioButton.cpp in Sources */, - 4D938F9B1E77E5A100C35653 /* CCPhysicsAABBQueryCallback.cpp in Sources */, BAFF7D771D5C1CF80051B92F /* Event.c in Sources */, 15AE18AB19AAD33D00C27E9E /* CCBAnimationManager.cpp in Sources */, 15AE1B7219AADA9A00C27E9E /* UIListView.cpp in Sources */, 4D2E69081CC543B40032DD5C /* CCGraphicsNode.cpp in Sources */, + 4DC06BE01E8A68D400CA08B1 /* CCPhysicsRayCastCallback.cpp in Sources */, 1A5701BE180BCB5A0088DEC7 /* CCLabelAtlas.cpp in Sources */, 4DED47F31DFFA4AF0070C5C4 /* b2CircleShape.cpp in Sources */, 15FB20751AE7BF8600C31518 /* CCAutoPolygon.cpp in Sources */, @@ -6622,9 +6656,11 @@ 1A57022E180BCC1A0088DEC7 /* CCParticleSystemQuad.cpp in Sources */, 50ABBD901925AB4100A911A9 /* CCGLProgramCache.cpp in Sources */, BAFF7C9F1D59E0DA0051B92F /* CCColliderDetector.cpp in Sources */, + 4DC06BE41E8A68D400CA08B1 /* CCPhysicsUtils.cpp in Sources */, 4DED481B1DFFA4AF0070C5C4 /* b2Body.cpp in Sources */, BAFF7D631D5C1CF80051B92F /* AttachmentVertices.cpp in Sources */, ED3057931BEC77790083C3ED /* edtaa3func.cpp in Sources */, + 4DC06BDC1E8A68D400CA08B1 /* CCPhysicsDebugDraw.cpp in Sources */, 15AE197F19AAD35700C27E9E /* CCTimeLine.cpp in Sources */, BAFF7D9F1D5C1CF80051B92F /* RegionAttachment.c in Sources */, 1A57027F180BCC900088DEC7 /* CCSprite.cpp in Sources */, @@ -6635,7 +6671,6 @@ BAFF7CF51D59E3840051B92F /* CocosStudioExtension.cpp in Sources */, FA6F1B741D80F858007DD223 /* CCTextureData.cpp in Sources */, BAFF7CC11D59E0DB0051B92F /* CCDecorativeDisplay.cpp in Sources */, - 4D28371A1E0B7B6300501B7F /* CCPhysicsDebugDraw.cpp in Sources */, 2980F02A1BA9A5550059E678 /* UITextField+CCUITextInput.mm in Sources */, 4DED48551DFFA4AF0070C5C4 /* b2PolygonContact.cpp in Sources */, 15AE185919AAD31200C27E9E /* CDAudioManager.m in Sources */, diff --git a/native/cocos/editor-support/creator/CCPhysicsContactWrapper.cpp b/native/cocos/editor-support/creator/CCPhysicsContactWrapper.cpp new file mode 100644 index 0000000000..f1801dc00b --- /dev/null +++ b/native/cocos/editor-support/creator/CCPhysicsContactWrapper.cpp @@ -0,0 +1,9 @@ +// +// CCPhysicsContactWrapper.cpp +// cocos2d_libs +// +// Created by youyou on 17/3/28. +// +// + +#include "CCPhysicsContactWrapper.hpp" diff --git a/native/cocos/editor-support/creator/CCPhysicsContactWrapper.h b/native/cocos/editor-support/creator/CCPhysicsContactWrapper.h new file mode 100644 index 0000000000..12a8f86c41 --- /dev/null +++ b/native/cocos/editor-support/creator/CCPhysicsContactWrapper.h @@ -0,0 +1,14 @@ +// +// CCPhysicsContactWrapper.hpp +// cocos2d_libs +// +// Created by youyou on 17/3/28. +// +// + +#ifndef CCPhysicsContactWrapper_hpp +#define CCPhysicsContactWrapper_hpp + +#include + +#endif /* CCPhysicsContactWrapper_hpp */ diff --git a/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.cpp b/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.cpp new file mode 100644 index 0000000000..f7a6afed69 --- /dev/null +++ b/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.cpp @@ -0,0 +1,9 @@ +// +// CCPhysicsWorldManifoldWrapper.cpp +// cocos2d_libs +// +// Created by youyou on 17/3/28. +// +// + +#include "CCPhysicsWorldManifoldWrapper.hpp" diff --git a/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.h b/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.h new file mode 100644 index 0000000000..36a9a488b4 --- /dev/null +++ b/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.h @@ -0,0 +1,14 @@ +// +// CCPhysicsWorldManifoldWrapper.hpp +// cocos2d_libs +// +// Created by youyou on 17/3/28. +// +// + +#ifndef CCPhysicsWorldManifoldWrapper_hpp +#define CCPhysicsWorldManifoldWrapper_hpp + +#include + +#endif /* CCPhysicsWorldManifoldWrapper_hpp */ diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.cpp new file mode 100644 index 0000000000..2ec30ba755 --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.cpp @@ -0,0 +1,52 @@ +#include "CCPhysicsAABBQueryCallback.h" + +using namespace cocos2d; + +namespace creator { + +PhysicsAABBQueryCallback::PhysicsAABBQueryCallback() +: _isPoint(false) +{ +} + +PhysicsAABBQueryCallback::PhysicsAABBQueryCallback(const b2Vec2& p) +: _isPoint(false) +{ + _point = p; +} + +PhysicsAABBQueryCallback::~PhysicsAABBQueryCallback() +{ +} + +bool PhysicsAABBQueryCallback::ReportFixture(b2Fixture* fixture) +{ + b2Body* body = fixture->GetBody(); + if (body->GetType() == b2_dynamicBody) { + if (_isPoint) { + if (fixture->TestPoint(_point)) { + _fixtures.push_back(fixture); + // We are done, terminate the query. + return false; + } + } + else { + _fixtures.push_back(fixture); + } + } + + // Continue the query. + return true; +} + +b2Fixture* PhysicsAABBQueryCallback::getFixture() +{ + return _fixtures.size() > 0 ? _fixtures[0] : nullptr; +} + +std::vector PhysicsAABBQueryCallback::getFixtures() +{ + return _fixtures; +} + +} diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.h b/native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.h new file mode 100644 index 0000000000..6b32035071 --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com + * + * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef CCPhysicsAABBQueryCallback_h +#define CCPhysicsAABBQueryCallback_h + +#include "Box2D/Box2D.h" +#include "cocos2d.h" + +namespace creator { + +class CC_DLL PhysicsAABBQueryCallback : public b2QueryCallback +{ +public: + PhysicsAABBQueryCallback(); + PhysicsAABBQueryCallback(const b2Vec2& p); + + ~PhysicsAABBQueryCallback(); + + virtual bool ReportFixture(b2Fixture* fixture); + + b2Fixture* getFixture(); + std::vector getFixtures(); + +protected: + b2Vec2 _point; + std::vector _fixtures; + bool _isPoint; +}; + +} + +#endif /* CCPhysicsAABBQueryCallback_h */ diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp new file mode 100644 index 0000000000..d6d6af924c --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp @@ -0,0 +1,107 @@ +#include "CCPhysicsContactListener.h" +#include "cocos2d.h" + +using namespace cocos2d; + +namespace creator { + +PhysicsContactListener::PhysicsContactListener() +{ +} + +PhysicsContactListener::~PhysicsContactListener() { +} + +void PhysicsContactListener::setBeginContact(std::function callback) +{ + _beginContact = callback; +} + +void PhysicsContactListener::setEndContact(std::function callback) +{ + _endContact = callback; +} + +void PhysicsContactListener::setPreSolve(std::function callback) +{ + _preSolve = callback; +} + +void PhysicsContactListener::setPostSolve(std::function callback) +{ + _postSolve = callback; +} + + +void PhysicsContactListener::BeginContact(b2Contact* contact) +{ + if (!_beginContact) return; + + b2Fixture* fixtureA = contact->GetFixtureA(); + b2Fixture* fixtureB = contact->GetFixtureB(); + + if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || + find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) + { + _beginContact(contact); + } + +} + +void PhysicsContactListener::EndContact(b2Contact* contact) +{ + if (!_endContact) return; + + b2Fixture* fixtureA = contact->GetFixtureA(); + b2Fixture* fixtureB = contact->GetFixtureB(); + + if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || + find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) + { + _endContact(contact); + } +} + +void PhysicsContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold) +{ + if (!_preSolve) return; + + b2Fixture* fixtureA = contact->GetFixtureA(); + b2Fixture* fixtureB = contact->GetFixtureB(); + + if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || + find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) + { + _preSolve(contact, oldManifold); + } +} + +void PhysicsContactListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) +{ + if (!_postSolve) return; + + b2Fixture* fixtureA = contact->GetFixtureA(); + b2Fixture* fixtureB = contact->GetFixtureB(); + + if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || + find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) + { + _postSolve(contact, impulse); + } +} + +void PhysicsContactListener::registerContactFixture(b2Fixture* fixture) +{ + _contactFixtures.push_back(fixture); +} + +void PhysicsContactListener::unregisterContactFixture(b2Fixture* fixture) +{ + auto result = find(_contactFixtures.begin(), _contactFixtures.end(), fixture); + if (result != _contactFixtures.end()) + { + _contactFixtures.erase(result); + } +} + +} diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h new file mode 100644 index 0000000000..a3e6515628 --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com + * + * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef PhysicsContactListener_H +#define PhysicsContactListener_H + +#include "Box2D/Box2D.h" +#include "cocos2d.h" +#include +#include + +namespace creator { + +class CC_DLL PhysicsContactListener : public b2ContactListener +{ +public: + PhysicsContactListener(); + virtual ~PhysicsContactListener(); + + void setBeginContact(std::function callback); + void setEndContact(std::function callback); + void setPreSolve(std::function callback); + void setPostSolve(std::function callback); + + + virtual void BeginContact(b2Contact* contact); + virtual void EndContact(b2Contact* contact); + virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold); + virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse); + + void registerContactFixture(b2Fixture* fixture); + void unregisterContactFixture(b2Fixture* fixture); + +protected: + std::function _beginContact; + std::function _endContact; + std::function _preSolve; + std::function _postSolve; + + std::vector _contactFixtures; +}; + +} + +#endif diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.cpp new file mode 100644 index 0000000000..ffebbec0e7 --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.cpp @@ -0,0 +1,109 @@ +#include "CCPhysicsDebugDraw.h" +#include "CCPhysicsDefine.h" + +#include "cocos2d.h" + +using namespace cocos2d; + +namespace creator { + +PhysicsDebugDraw::PhysicsDebugDraw() +{ + _drawer = GraphicsNode::create(); + _drawer->retain(); +} + +PhysicsDebugDraw::~PhysicsDebugDraw() +{ + _drawer->release(); +} + +creator::GraphicsNode* PhysicsDebugDraw::getDrawer() +{ + return _drawer; +} + +void PhysicsDebugDraw::ClearDraw() +{ + _drawer->clear(); +} + +void PhysicsDebugDraw::AddDrawerToNode(cocos2d::Node *node) +{ + _drawer->removeFromParent(); + node->addChild(_drawer); +} + +void PhysicsDebugDraw::DrawPolygon(const b2Vec2* old_vertices, int vertexCount, const b2Color& color) +{ + Color4F c(color.r, color.g, color.b, /*color.a*/0.5); + _drawer->setStrokeColor(c); + + for( int i=0;imoveTo(old_vertices[i].x * CC_PTM_RATIO, old_vertices[i].y * CC_PTM_RATIO); + else { + _drawer->lineTo(old_vertices[i].x * CC_PTM_RATIO, old_vertices[i].y * CC_PTM_RATIO); + } + } + _drawer->close(); + _drawer->stroke(); +} + +void PhysicsDebugDraw::DrawSolidPolygon(const b2Vec2* old_vertices, int vertexCount, const b2Color& color) +{ + Color4F c(color.r, color.g, color.b, /*color.a*/0.5); + _drawer->setFillColor(c); + + for( int i=0;imoveTo(old_vertices[i].x * CC_PTM_RATIO, old_vertices[i].y * CC_PTM_RATIO); + else { + _drawer->lineTo(old_vertices[i].x * CC_PTM_RATIO, old_vertices[i].y * CC_PTM_RATIO); + } + } + _drawer->close(); + _drawer->fill(); +} + +void PhysicsDebugDraw::DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) +{ + Color4F c(color.r, color.g, color.b, /*color.a*/0.5); + _drawer->setStrokeColor(c); + + _drawer->circle(center.x * CC_PTM_RATIO, center.y * CC_PTM_RATIO, radius * CC_PTM_RATIO); + _drawer->stroke(); +} + +void PhysicsDebugDraw::DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) +{ + Color4F c(color.r, color.g, color.b, /*color.a*/0.5); + _drawer->setFillColor(c); + + _drawer->circle(center.x * CC_PTM_RATIO, center.y * CC_PTM_RATIO, radius * CC_PTM_RATIO); + _drawer->fill(); +} + +void PhysicsDebugDraw::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) +{ + Color4F c(color.r, color.g, color.b, /*color.a*/0.5); + _drawer->setStrokeColor(c); + + _drawer->moveTo(p1.x * CC_PTM_RATIO, p1.y * CC_PTM_RATIO); + _drawer->lineTo(p2.x * CC_PTM_RATIO, p2.y * CC_PTM_RATIO); + _drawer->stroke(); +} + +void PhysicsDebugDraw::DrawTransform(const b2Transform& xf) +{ + // b2Vec2 p1 = xf.p, p2; + // const float32 k_axisScale = 0.4f; + // + // p2 = p1 + k_axisScale * xf.R.col1; + // DrawSegment(p1,p2,b2Color(1,0,0)); + // + // p2 = p1 + k_axisScale * xf.R.col2; + // DrawSegment(p1,p2,b2Color(0,1,0)); +} + +} diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.h b/native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.h new file mode 100644 index 0000000000..bf9c8d6709 --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com + * + * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef PhysicsDebugDraw_H +#define PhysicsDebugDraw_H + +#include "Box2D/Box2D.h" +#include "editor-support/creator/CCGraphicsNode.h" + +namespace creator { + +// This class implements debug drawing callbacks that are invoked +// inside b2World::Step. +class CC_DLL PhysicsDebugDraw : public b2Draw +{ +public: + PhysicsDebugDraw(); + ~PhysicsDebugDraw(); + + creator::GraphicsNode* getDrawer(); + + void ClearDraw(); + + void AddDrawerToNode(cocos2d::Node* node); + + void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color); + + void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color); + + void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color); + + void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color); + + void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color); + + void DrawTransform(const b2Transform& xf); + +protected: + creator::GraphicsNode* _drawer; + +}; + +} + +#endif diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsDefine.h b/native/cocos/editor-support/creator/physics/CCPhysicsDefine.h new file mode 100644 index 0000000000..db7d75a3b8 --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsDefine.h @@ -0,0 +1,14 @@ +// +// CCPhysicsDefine.h +// cocos2d_libs +// +// Created by youyou on 17/3/29. +// +// + +#ifndef CCPhysicsDefine_h +#define CCPhysicsDefine_h + +#define CC_PTM_RATIO 32 + +#endif /* CCPhysicsDefine_h */ diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.cpp new file mode 100644 index 0000000000..73191fb52c --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.cpp @@ -0,0 +1,9 @@ +// +// CCPhysicsManifoldWrapper.cpp +// cocos2d_libs +// +// Created by youyou on 17/3/29. +// +// + +#include "CCPhysicsManifoldWrapper.h" diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h b/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h new file mode 100644 index 0000000000..777d6ccdea --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h @@ -0,0 +1,14 @@ +// +// CCPhysicsManifoldWrapper.hpp +// cocos2d_libs +// +// Created by youyou on 17/3/29. +// +// + +#ifndef CCPhysicsManifoldWrapper_h +#define CCPhysicsManifoldWrapper_h + +#include + +#endif /* CCPhysicsManifoldWrapper_h */ diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.cpp new file mode 100644 index 0000000000..7a38698bec --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.cpp @@ -0,0 +1,69 @@ +#include "CCPhysicsRayCastCallback.h" + +using namespace cocos2d; + +namespace creator { + +PhysicsRayCastCallback::PhysicsRayCastCallback(int type) +{ + _rayCastType = type; +} + +PhysicsRayCastCallback::~PhysicsRayCastCallback() { +} + +float32 PhysicsRayCastCallback::ReportFixture(b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction) +{ + if (_rayCastType == 0) { + if (_fixtures.size() > 0) { + _fixtures[0] = fixture; + _normals[0] = normal; + _points[0] = point; + _fractions[0] = fraction; + } + else { + _fixtures.push_back(fixture); + _normals.push_back(normal); + _points.push_back(point); + _fractions.push_back(fraction); + } + + return fraction; + } + + _fixtures.push_back(fixture); + _normals.push_back(normal); + _points.push_back(point); + _fractions.push_back(fraction); + + if (_rayCastType == 1) { + return 0; + } + else { + return 1; + } + + return fraction; +} + +std::vector& PhysicsRayCastCallback::getFixtures() { + return _fixtures; +} + +std::vector& PhysicsRayCastCallback::getPoints() { + return _points; +} + +std::vector& PhysicsRayCastCallback::getNormals() { + return _normals; +} + +std::vector& PhysicsRayCastCallback::getFractions() { + return _fractions; +} + +int PhysicsRayCastCallback::getType() { + return _rayCastType; +} + +} diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.h b/native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.h new file mode 100644 index 0000000000..2461ac626e --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com + * + * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef CCPhysicsRayCastCallback_h +#define CCPhysicsRayCastCallback_h + +#include "Box2D/Box2D.h" +#include "cocos2d.h" + +namespace creator { + +class CC_DLL PhysicsRayCastCallback : public b2RayCastCallback +{ +public: + PhysicsRayCastCallback(int type); + ~PhysicsRayCastCallback(); + + virtual float32 ReportFixture(b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction); + + std::vector& getFixtures(); + std::vector& getPoints(); + std::vector& getNormals(); + std::vector& getFractions(); + + int getType(); + +protected: + int _rayCastType; + + std::vector _fixtures; + std::vector _points; + std::vector _normals; + std::vector _fractions; +}; + +} + +#endif /* CCPhysicsRayCastCallback_h */ diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp new file mode 100644 index 0000000000..52711d8d3e --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp @@ -0,0 +1,100 @@ +// +// CCPhysicsUtils.cpp +// cocos2d_libs +// +// Created by youyou on 16/12/22. +// +// + +#include "CCPhysicsUtils.h" +#include "CCPhysicsDefine.h" + +using namespace cocos2d; + +namespace creator { + +static PhysicsWorldManifoldWrapper _worldManifoldWrapper; + +PhysicsUtils::PhysicsUtils() +{ + +} + +PhysicsUtils::~PhysicsUtils() +{ + +} + +void PhysicsUtils::addB2Body(b2Body* body) +{ + _bodies.push_back(body); +} + +void PhysicsUtils::removeB2Body(b2Body *body) +{ + const auto iterator = std::find(_bodies.begin(), _bodies.end(), body); + if (iterator != _bodies.end()) + { + _bodies.erase(iterator); + } +} + +void PhysicsUtils::syncNode() +{ + for (auto begin = _bodies.begin(); begin != _bodies.end(); begin++) + { + b2Body* body = *begin; + Node* node = (Node*)body->GetUserData(); + + const b2Vec2& pos = body->GetPosition(); + + Vec2 position(pos.x*CC_PTM_RATIO, pos.y*CC_PTM_RATIO); + float angle = -CC_RADIANS_TO_DEGREES(body->GetAngle()); + + if (node->getParent() && node->getParent()->getParent()) { + node->setPosition( _convertToNodePosition(node->getParent(), position) ); + node->setRotation( _convertToNodeRotation(node->getParent(), angle) ); + } + else { + node->setPosition(position); + node->setRotation(angle); + } + } +} + +void PhysicsUtils::setFixtureNext(b2Fixture* fixture, b2Fixture* next) +{ + b2Fixture* f = fixture->GetNext(); + *&f = next; +} + +const PhysicsWorldManifoldWrapper* PhysicsUtils::getContactWorldManifoldWrapper(b2Contact* contact) +{ + _worldManifoldWrapper.init(contact); + contact->GetWorldManifold(_worldManifoldWrapper.getb2WorldManifold()); + return &_worldManifoldWrapper; +} + +cocos2d::Vec2 PhysicsUtils::_convertToNodePosition(cocos2d::Node* node, cocos2d::Vec2& position) +{ + if (node->isIgnoreAnchorPointForPosition()) { + // see https://github.com/cocos-creator/engine/pull/391 + return node->convertToNodeSpace(position); + } + else { + return node->convertToNodeSpaceAR(position); + } +} + +float PhysicsUtils::_convertToNodeRotation(cocos2d::Node* node, float rotation) +{ + rotation -= node->getRotation(); + Node* parent = node->getParent(); + while(parent->getParent()){ + rotation -= parent->getRotation(); + parent = parent->getParent(); + } + return rotation; +} + +} diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsUtils.h b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.h new file mode 100644 index 0000000000..a6874ad640 --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com + * + * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef PhysicsUtils_H +#define PhysicsUtils_H + +#include + +#include "Box2D/Box2D.h" +#include "cocos2d.h" + +#include "CCPhysicsWorldManifoldWrapper.h" + +namespace creator { + +// This class implements debug drawing callbacks that are invoked +// inside b2World::Step. +class CC_DLL PhysicsUtils +{ +public: + PhysicsUtils(); + ~PhysicsUtils(); + + void addB2Body(b2Body* body); + void removeB2Body(b2Body* body); + + void syncNode(); + + void setFixtureNext(b2Fixture* fixture, b2Fixture* next); + +public: + static const PhysicsWorldManifoldWrapper* getContactWorldManifoldWrapper(b2Contact* contact); + +protected: + cocos2d::Vec2 _convertToNodePosition(cocos2d::Node* node, cocos2d::Vec2& position); + float _convertToNodeRotation(cocos2d::Node* node, float rotation); + + std::vector _bodies; +}; + +} + +#endif diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.cpp new file mode 100644 index 0000000000..6823001b44 --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.cpp @@ -0,0 +1,55 @@ +// +// CCPhysicsWorldManifoldWrapper.cpp +// cocos2d_libs +// +// Created by youyou on 17/3/28. +// +// + +#include "CCPhysicsWorldManifoldWrapper.h" +#include "CCPhysicsDefine.h" + +namespace creator { + PhysicsWorldManifoldWrapper::PhysicsWorldManifoldWrapper() + { + } + PhysicsWorldManifoldWrapper::~PhysicsWorldManifoldWrapper() + { + } + + void PhysicsWorldManifoldWrapper::init(b2Contact* contact) + { + _contact = contact; + } + b2WorldManifold* PhysicsWorldManifoldWrapper::getb2WorldManifold() + { + return &_manifold; + } + + int PhysicsWorldManifoldWrapper::getCount() + { + b2Manifold* m = _contact->GetManifold(); + return m->pointCount; + } + + float32 PhysicsWorldManifoldWrapper::getX(int index) + { + return _manifold.points[index].x * CC_PTM_RATIO; + } + float32 PhysicsWorldManifoldWrapper::getY(int index) + { + return _manifold.points[index].y * CC_PTM_RATIO; + } + float32 PhysicsWorldManifoldWrapper::getSeparation(int index) + { + return _manifold.separations[index] * CC_PTM_RATIO; + } + float32 PhysicsWorldManifoldWrapper::getNormalX() + { + return _manifold.normal.x; + } + float32 PhysicsWorldManifoldWrapper::getNormalY() + { + return _manifold.normal.y; + } +} diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h b/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h new file mode 100644 index 0000000000..657b412834 --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com + * + * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#ifndef CCPhysicsWorldManifoldWrapper_h +#define CCPhysicsWorldManifoldWrapper_h + +#include "Box2D/Box2D.h" +#include "cocos2d.h" + +namespace creator { + class PhysicsWorldManifoldWrapper : public cocos2d::Ref + { + public: + PhysicsWorldManifoldWrapper(); + ~PhysicsWorldManifoldWrapper(); + + void init(b2Contact* contact); + b2WorldManifold* getb2WorldManifold(); + + int getCount(); + float32 getX(int index); + float32 getY(int index); + float32 getSeparation(int index); + float32 getNormalX(); + float32 getNormalY(); + + protected: + b2WorldManifold _manifold; + b2Contact* _contact; + }; +} + + +#endif /* CCPhysicsWorldManifoldWrapper_h */ diff --git a/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js b/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js index 5682dd8480..e686dcad37 100644 --- a/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js +++ b/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js @@ -785,6 +785,88 @@ PhysicsDebugDraw : function ( }; +/** + * @class PhysicsWorldManifoldWrapper + */ +cc.PhysicsWorldManifoldWrapper = { + +/** + * @method getSeparation + * @param {int} arg0 + * @return {float} + */ +getSeparation : function ( +int +) +{ + return 0; +}, + +/** + * @method getX + * @param {int} arg0 + * @return {float} + */ +getX : function ( +int +) +{ + return 0; +}, + +/** + * @method getY + * @param {int} arg0 + * @return {float} + */ +getY : function ( +int +) +{ + return 0; +}, + +/** + * @method getCount + * @return {int} + */ +getCount : function ( +) +{ + return 0; +}, + +/** + * @method getNormalY + * @return {float} + */ +getNormalY : function ( +) +{ + return 0; +}, + +/** + * @method getNormalX + * @return {float} + */ +getNormalX : function ( +) +{ + return 0; +}, + +/** + * @method PhysicsWorldManifoldWrapper + * @constructor + */ +PhysicsWorldManifoldWrapper : function ( +) +{ +}, + +}; + /** * @class PhysicsUtils */ @@ -830,6 +912,18 @@ b2body { }, +/** + * @method getContactWorldManifoldWrapper + * @param {b2Contact} arg0 + * @return {creator::PhysicsWorldManifoldWrapper} + */ +getContactWorldManifoldWrapper : function ( +b2contact +) +{ + return creator::PhysicsWorldManifoldWrapper; +}, + /** * @method PhysicsUtils * @constructor diff --git a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp index 30936f89ae..328adc3afc 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp @@ -2,11 +2,12 @@ #include "scripting/js-bindings/manual/cocos2d_specifics.hpp" #include "creator/CCScale9Sprite.h" #include "creator/CCGraphicsNode.h" -#include "editor-support/creator/CCPhysicsDebugDraw.h" -#include "editor-support/creator/CCPhysicsUtils.h" -#include "editor-support/creator/CCPhysicsContactListener.h" -#include "editor-support/creator/CCPhysicsAABBQueryCallback.h" -#include "editor-support/creator/CCPhysicsRayCastCallback.h" +#include "editor-support/creator/physics/CCPhysicsDebugDraw.h" +#include "editor-support/creator/physics/CCPhysicsUtils.h" +#include "editor-support/creator/physics/CCPhysicsContactListener.h" +#include "editor-support/creator/physics/CCPhysicsAABBQueryCallback.h" +#include "editor-support/creator/physics/CCPhysicsRayCastCallback.h" +#include "editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h" #include "editor-support/creator/CCCameraNode.h" #include "scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.h" @@ -1853,6 +1854,193 @@ void js_register_creator_PhysicsDebugDraw(JSContext *cx, JS::HandleObject global jsb_register_class(cx, jsb_creator_PhysicsDebugDraw_class, proto, parent_proto); } +JSClass *jsb_creator_PhysicsWorldManifoldWrapper_class; +JSObject *jsb_creator_PhysicsWorldManifoldWrapper_prototype; + +bool js_creator_PhysicsWorldManifoldWrapper_getSeparation(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + creator::PhysicsWorldManifoldWrapper* cobj = (creator::PhysicsWorldManifoldWrapper *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsWorldManifoldWrapper_getSeparation : Invalid Native Object"); + if (argc == 1) { + int arg0 = 0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_creator_PhysicsWorldManifoldWrapper_getSeparation : Error processing arguments"); + double ret = cobj->getSeparation(arg0); + JS::RootedValue jsret(cx); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_creator_PhysicsWorldManifoldWrapper_getSeparation : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_creator_PhysicsWorldManifoldWrapper_getX(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + creator::PhysicsWorldManifoldWrapper* cobj = (creator::PhysicsWorldManifoldWrapper *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsWorldManifoldWrapper_getX : Invalid Native Object"); + if (argc == 1) { + int arg0 = 0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_creator_PhysicsWorldManifoldWrapper_getX : Error processing arguments"); + double ret = cobj->getX(arg0); + JS::RootedValue jsret(cx); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_creator_PhysicsWorldManifoldWrapper_getX : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_creator_PhysicsWorldManifoldWrapper_getY(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + creator::PhysicsWorldManifoldWrapper* cobj = (creator::PhysicsWorldManifoldWrapper *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsWorldManifoldWrapper_getY : Invalid Native Object"); + if (argc == 1) { + int arg0 = 0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_creator_PhysicsWorldManifoldWrapper_getY : Error processing arguments"); + double ret = cobj->getY(arg0); + JS::RootedValue jsret(cx); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_creator_PhysicsWorldManifoldWrapper_getY : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_creator_PhysicsWorldManifoldWrapper_getCount(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + creator::PhysicsWorldManifoldWrapper* cobj = (creator::PhysicsWorldManifoldWrapper *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsWorldManifoldWrapper_getCount : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getCount(); + JS::RootedValue jsret(cx); + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_creator_PhysicsWorldManifoldWrapper_getCount : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_creator_PhysicsWorldManifoldWrapper_getNormalY(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + creator::PhysicsWorldManifoldWrapper* cobj = (creator::PhysicsWorldManifoldWrapper *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsWorldManifoldWrapper_getNormalY : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getNormalY(); + JS::RootedValue jsret(cx); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_creator_PhysicsWorldManifoldWrapper_getNormalY : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_creator_PhysicsWorldManifoldWrapper_getNormalX(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + creator::PhysicsWorldManifoldWrapper* cobj = (creator::PhysicsWorldManifoldWrapper *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsWorldManifoldWrapper_getNormalX : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->getNormalX(); + JS::RootedValue jsret(cx); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_creator_PhysicsWorldManifoldWrapper_getNormalX : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_creator_PhysicsWorldManifoldWrapper_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + creator::PhysicsWorldManifoldWrapper* cobj = new (std::nothrow) creator::PhysicsWorldManifoldWrapper(); + + js_type_class_t *typeClass = js_get_type_from_native(cobj); + + // link the native object with the javascript object + JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, cobj, typeClass, "creator::PhysicsWorldManifoldWrapper")); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); + if (JS_HasProperty(cx, jsobj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(jsobj), "_ctor", args); + return true; +} + + +void js_register_creator_PhysicsWorldManifoldWrapper(JSContext *cx, JS::HandleObject global) { + jsb_creator_PhysicsWorldManifoldWrapper_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_creator_PhysicsWorldManifoldWrapper_class->name = "PhysicsWorldManifoldWrapper"; + jsb_creator_PhysicsWorldManifoldWrapper_class->addProperty = JS_PropertyStub; + jsb_creator_PhysicsWorldManifoldWrapper_class->delProperty = JS_DeletePropertyStub; + jsb_creator_PhysicsWorldManifoldWrapper_class->getProperty = JS_PropertyStub; + jsb_creator_PhysicsWorldManifoldWrapper_class->setProperty = JS_StrictPropertyStub; + jsb_creator_PhysicsWorldManifoldWrapper_class->enumerate = JS_EnumerateStub; + jsb_creator_PhysicsWorldManifoldWrapper_class->resolve = JS_ResolveStub; + jsb_creator_PhysicsWorldManifoldWrapper_class->convert = JS_ConvertStub; + jsb_creator_PhysicsWorldManifoldWrapper_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getSeparation", js_creator_PhysicsWorldManifoldWrapper_getSeparation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getX", js_creator_PhysicsWorldManifoldWrapper_getX, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getY", js_creator_PhysicsWorldManifoldWrapper_getY, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getCount", js_creator_PhysicsWorldManifoldWrapper_getCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getNormalY", js_creator_PhysicsWorldManifoldWrapper_getNormalY, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getNormalX", js_creator_PhysicsWorldManifoldWrapper_getNormalX, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + JSFunctionSpec *st_funcs = NULL; + + jsb_creator_PhysicsWorldManifoldWrapper_prototype = JS_InitClass( + cx, global, + JS::NullPtr(), + jsb_creator_PhysicsWorldManifoldWrapper_class, + js_creator_PhysicsWorldManifoldWrapper_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + + JS::RootedObject proto(cx, jsb_creator_PhysicsWorldManifoldWrapper_prototype); + JS::RootedValue className(cx, std_string_to_jsval(cx, "PhysicsWorldManifoldWrapper")); + JS_SetProperty(cx, proto, "_className", className); + JS_SetProperty(cx, proto, "__nativeObj", JS::TrueHandleValue); + JS_SetProperty(cx, proto, "__is_ref", JS::TrueHandleValue); + // add the proto and JSClass to the type->js info hash table + jsb_register_class(cx, jsb_creator_PhysicsWorldManifoldWrapper_class, proto, JS::NullPtr()); +} + JSClass *jsb_creator_PhysicsUtils_class; JSObject *jsb_creator_PhysicsUtils_prototype; @@ -1900,6 +2088,44 @@ bool js_creator_PhysicsUtils_syncNode(JSContext *cx, uint32_t argc, jsval *vp) JS_ReportError(cx, "js_creator_PhysicsUtils_syncNode : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_creator_PhysicsUtils_setFixtureNext(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + creator::PhysicsUtils* cobj = (creator::PhysicsUtils *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsUtils_setFixtureNext : Invalid Native Object"); + if (argc == 2) { + b2Fixture* arg0 = nullptr; + b2Fixture* arg1 = nullptr; + do { + if (args.get(0).isNull()) { arg0 = nullptr; break; } + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (b2Fixture*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + do { + if (args.get(1).isNull()) { arg1 = nullptr; break; } + if (!args.get(1).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(1).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg1 = (b2Fixture*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_creator_PhysicsUtils_setFixtureNext : Error processing arguments"); + cobj->setFixtureNext(arg0, arg1); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_creator_PhysicsUtils_setFixtureNext : wrong number of arguments: %d, was expecting %d", argc, 2); + return false; +} bool js_creator_PhysicsUtils_removeB2Body(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -1928,6 +2154,37 @@ bool js_creator_PhysicsUtils_removeB2Body(JSContext *cx, uint32_t argc, jsval *v JS_ReportError(cx, "js_creator_PhysicsUtils_removeB2Body : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_creator_PhysicsUtils_getContactWorldManifoldWrapper(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + b2Contact* arg0 = nullptr; + do { + if (args.get(0).isNull()) { arg0 = nullptr; break; } + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (b2Contact*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_creator_PhysicsUtils_getContactWorldManifoldWrapper : Error processing arguments"); + + const creator::PhysicsWorldManifoldWrapper* ret = creator::PhysicsUtils::getContactWorldManifoldWrapper(arg0); + jsval jsret = JSVAL_NULL; + if (ret) { + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (creator::PhysicsWorldManifoldWrapper*)ret)); + } else { + jsret = JSVAL_NULL; + }; + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_creator_PhysicsUtils_getContactWorldManifoldWrapper : wrong number of arguments"); + return false; +} + bool js_creator_PhysicsUtils_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -1988,11 +2245,15 @@ void js_register_creator_PhysicsUtils(JSContext *cx, JS::HandleObject global) { static JSFunctionSpec funcs[] = { JS_FN("addB2Body", js_creator_PhysicsUtils_addB2Body, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("syncNode", js_creator_PhysicsUtils_syncNode, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("setFixtureNext", js_creator_PhysicsUtils_setFixtureNext, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeB2Body", js_creator_PhysicsUtils_removeB2Body, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; - JSFunctionSpec *st_funcs = NULL; + static JSFunctionSpec st_funcs[] = { + JS_FN("getContactWorldManifoldWrapper", js_creator_PhysicsUtils_getContactWorldManifoldWrapper, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; jsb_creator_PhysicsUtils_prototype = JS_InitClass( cx, global, @@ -2595,6 +2856,7 @@ void register_all_creator(JSContext* cx, JS::HandleObject obj) { js_register_creator_PhysicsContactListener(cx, ns); js_register_creator_PhysicsUtils(cx, ns); js_register_creator_Scale9SpriteV2(cx, ns); + js_register_creator_PhysicsWorldManifoldWrapper(cx, ns); js_register_creator_GraphicsNode(cx, ns); js_register_creator_PhysicsAABBQueryCallback(cx, ns); js_register_creator_CameraNode(cx, ns); diff --git a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp index 96c8cc6390..ef31fe04ae 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp @@ -98,6 +98,21 @@ bool js_creator_PhysicsDebugDraw_ClearDraw(JSContext *cx, uint32_t argc, jsval * bool js_creator_PhysicsDebugDraw_AddDrawerToNode(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsDebugDraw_PhysicsDebugDraw(JSContext *cx, uint32_t argc, jsval *vp); +extern JSClass *jsb_creator_PhysicsWorldManifoldWrapper_class; +extern JSObject *jsb_creator_PhysicsWorldManifoldWrapper_prototype; + +bool js_creator_PhysicsWorldManifoldWrapper_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_creator_PhysicsWorldManifoldWrapper_finalize(JSContext *cx, JSObject *obj); +void js_register_creator_PhysicsWorldManifoldWrapper(JSContext *cx, JS::HandleObject global); +void register_all_creator(JSContext* cx, JS::HandleObject obj); +bool js_creator_PhysicsWorldManifoldWrapper_getSeparation(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsWorldManifoldWrapper_getX(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsWorldManifoldWrapper_getY(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsWorldManifoldWrapper_getCount(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsWorldManifoldWrapper_getNormalY(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsWorldManifoldWrapper_getNormalX(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsWorldManifoldWrapper_PhysicsWorldManifoldWrapper(JSContext *cx, uint32_t argc, jsval *vp); + extern JSClass *jsb_creator_PhysicsUtils_class; extern JSObject *jsb_creator_PhysicsUtils_prototype; @@ -107,7 +122,9 @@ void js_register_creator_PhysicsUtils(JSContext *cx, JS::HandleObject global); void register_all_creator(JSContext* cx, JS::HandleObject obj); bool js_creator_PhysicsUtils_addB2Body(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_syncNode(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsUtils_setFixtureNext(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_removeB2Body(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsUtils_getContactWorldManifoldWrapper(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_PhysicsUtils(JSContext *cx, uint32_t argc, jsval *vp); extern JSClass *jsb_creator_PhysicsContactListener_class; diff --git a/native/cocos/scripting/js-bindings/manual/creator/js_bindings_creator_manual.cpp b/native/cocos/scripting/js-bindings/manual/creator/js_bindings_creator_manual.cpp index e90e5beec7..e9f34a455c 100644 --- a/native/cocos/scripting/js-bindings/manual/creator/js_bindings_creator_manual.cpp +++ b/native/cocos/scripting/js-bindings/manual/creator/js_bindings_creator_manual.cpp @@ -164,11 +164,11 @@ bool js_creator_PhysicsContactListener_setPreSolve(JSContext *cx, uint32_t argc, } else { largv[0] = JSVAL_NULL; }; - if (larg1) { - largv[1] = b2Manifold_to_jsval(cx, larg1); - } else { +// if (larg1) { +// largv[1] = b2Manifold_to_jsval(cx, larg1); +// } else { largv[1] = JSVAL_NULL; - }; +// }; JS::RootedValue rval(cx); bool succeed = func->invoke(JS::HandleValueArray::fromMarkedLocation(2, largv), &rval); if (!succeed && JS_IsExceptionPending(cx)) { @@ -216,11 +216,11 @@ bool js_creator_PhysicsContactListener_setPostSolve(JSContext *cx, uint32_t argc } else { largv[0] = JSVAL_NULL; }; - if (larg1) { - largv[1] = b2ContactImpulse_to_jsval(cx, (b2ContactImpulse*)larg1); - } else { +// if (larg1) { +// largv[1] = b2ContactImpulse_to_jsval(cx, (b2ContactImpulse*)larg1); +// } else { largv[1] = JSVAL_NULL; - }; +// }; JS::RootedValue rval(cx); bool succeed = func->invoke(JS::HandleValueArray::fromMarkedLocation(2, largv), &rval); if (!succeed && JS_IsExceptionPending(cx)) { @@ -245,73 +245,6 @@ bool js_creator_PhysicsContactListener_setPostSolve(JSContext *cx, uint32_t argc return false; } -bool js_creator_PhysicsUtils_getContactWorldManifold(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - bool ok = true; - if (argc == 1) { - b2Contact* arg0 = nullptr; - do { - if (args.get(0).isNull()) { arg0 = nullptr; break; } - if (!args.get(0).isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (b2Contact*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_creator_PhysicsUtils_getContactWorldManifold : Error processing arguments"); - - const b2WorldManifold* ret = creator::PhysicsUtils::getContactWorldManifold(arg0); - - // - jsval jsret = JSVAL_NULL; - - JS::RootedObject tmp(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); - - ok = JS_DefineProperty(cx, tmp, "normal", JS::RootedValue(cx, b2Vec2_to_jsval(cx, ret->normal)), JSPROP_ENUMERATE | JSPROP_PERMANENT); - - - b2Manifold* manifold = arg0->GetManifold(); - int count = manifold->pointCount; - - // points - JS::RootedObject jsretPoints(cx, JS_NewArrayObject(cx, 0)); - for (int i = 0; i < count; i++) - { - const b2Vec2& p = ret->points[i]; - - if (!JS_SetElement(cx, jsretPoints, i, JS::RootedValue(cx, b2Vec2_to_jsval(cx, p)))) { - ok = false; - break; - } - } - ok &= JS_DefineProperty(cx, tmp, "points", jsretPoints, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - // separations - JS::RootedObject jsretSeparations(cx, JS_NewArrayObject(cx, 0)); - for (int i = 0; i < count; i++) - { - float32 v = ret->separations[i]; - - if (!JS_SetElement(cx, jsretSeparations, i, v)) { - ok = false; - break; - } - } - ok &= JS_DefineProperty(cx, tmp, "separations", jsretSeparations, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - if (ok) { - jsret = OBJECT_TO_JSVAL(tmp); - } - - args.rval().set(jsret); - return true; - } - JS_ReportError(cx, "js_creator_PhysicsUtils_getContactWorldManifold : wrong number of arguments"); - return false; -} - bool js_creator_PhysicsAABBQueryCallback_getFixtures(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -400,10 +333,7 @@ void register_all_creatorclasses_manual(JSContext* cx, JS::HandleObject obj) { JS_DefineFunction(cx, tmpObj, "setPostSolve", js_creator_PhysicsContactListener_setPostSolve, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "setBeginContact", js_creator_PhysicsContactListener_setBeginContact, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); JS_DefineFunction(cx, tmpObj, "setEndContact", js_creator_PhysicsContactListener_setEndContact, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - - tmpObj.set(jsb_creator_PhysicsUtils_prototype); - JS_DefineFunction(cx, tmpObj, "getContactWorldManifold", js_creator_PhysicsUtils_getContactWorldManifold, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT); - + tmpObj.set(jsb_creator_PhysicsAABBQueryCallback_prototype); JS_DefineFunction(cx, tmpObj, "getFixtures", js_creator_PhysicsAABBQueryCallback_getFixtures, 0, JSPROP_ENUMERATE | JSPROP_PERMANENT); diff --git a/native/tools/tojs/creator.ini b/native/tools/tojs/creator.ini index b3a9827bf0..d3222ec972 100755 --- a/native/tools/tojs/creator.ini +++ b/native/tools/tojs/creator.ini @@ -26,7 +26,7 @@ cxxgenerator_headers = extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s # what headers to parse -headers = %(creatordir)s/CCScale9Sprite.h %(creatordir)s/CCGraphicsNode.h %(creatordir)s/CCPhysicsDebugDraw.h %(creatordir)s/CCPhysicsUtils.h %(creatordir)s/CCPhysicsContactListener.h %(creatordir)s/CCPhysicsAABBQueryCallback.h %(creatordir)s/CCPhysicsRayCastCallback.h %(creatordir)s/CCCameraNode.h +headers = %(creatordir)s/CCScale9Sprite.h %(creatordir)s/CCGraphicsNode.h %(creatordir)s/physics/CCPhysicsDebugDraw.h %(creatordir)s/physics/CCPhysicsUtils.h %(creatordir)s/physics/CCPhysicsContactListener.h %(creatordir)s/physics/CCPhysicsAABBQueryCallback.h %(creatordir)s/physics/CCPhysicsRayCastCallback.h %(creatordir)s/physics/CCPhysicsWorldManifoldWrapper.h %(creatordir)s/CCCameraNode.h cpp_headers = scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.h @@ -34,7 +34,7 @@ replace_headers = CCScale9Sprite.h::creator/CCScale9Sprite.h,CCGraphicsNode.h::c # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = Scale9SpriteV2 GraphicsNode PhysicsDebugDraw PhysicsUtils PhysicsContactListener PhysicsAABBQueryCallback PhysicsRayCastCallback CameraNode +classes = Scale9SpriteV2 GraphicsNode PhysicsDebugDraw PhysicsUtils PhysicsContactListener PhysicsAABBQueryCallback PhysicsRayCastCallback PhysicsWorldManifoldWrapper CameraNode classes_need_extend = Scale9SpriteV2 GraphicsNode @@ -47,9 +47,9 @@ classes_need_extend = Scale9SpriteV2 GraphicsNode skip = PhysicsDebugDraw::[DrawPolygon DrawSolidPolygon DrawCircle DrawSolidCircle DrawSegment DrawTransform], PhysicsContactListener::[BeginContact EndContact PreSolve PostSolve setBeginContact setEndContact setPreSolve setPostSolve], - PhysicsUtils::[getContactWorldManifold], PhysicsAABBQueryCallback::[ReportFixture getFixtures], PhysicsRayCastCallback::[ReportFixture getFixtures getNormals getPoints], + PhysicsWorldManifoldWrapper::[init getb2WorldManifold], CameraNode::[(.*)Visit] rename_functions = diff --git a/native/tools/tojs/genbindings.py b/native/tools/tojs/genbindings.py index c608fd0b8e..f910b47de3 100755 --- a/native/tools/tojs/genbindings.py +++ b/native/tools/tojs/genbindings.py @@ -150,19 +150,20 @@ def main(): tojs_root = '%s/tools/tojs' % project_root output_dir = '%s/cocos/scripting/js-bindings/auto' % project_root - cmd_args = {'cocos2dx.ini' : ('cocos2d-x', 'jsb_cocos2dx_auto'), \ - 'cocos2dx_audioengine.ini' : ('cocos2dx_audioengine', 'jsb_cocos2dx_audioengine_auto'), \ - 'cocos2dx_network.ini' : ('cocos2dx_network', 'jsb_cocos2dx_network_auto'), \ - 'cocos2dx_extension.ini' : ('cocos2dx_extension', 'jsb_cocos2dx_extension_auto'), \ - 'cocos2dx_builder.ini' : ('cocos2dx_builder', 'jsb_cocos2dx_builder_auto'), \ - 'cocos2dx_ui.ini' : ('cocos2dx_ui', 'jsb_cocos2dx_ui_auto'), \ - 'cocos2dx_studio.ini' : ('cocos2dx_studio', 'jsb_cocos2dx_studio_auto'), \ - 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'jsb_cocos2dx_spine_auto'), \ - 'cocos2dx_dragonbones.ini' : ('cocos2dx_dragonbones', 'jsb_cocos2dx_dragonbones_auto'), \ - 'cocos2dx_experimental_webView.ini' : ('cocos2dx_experimental_webView', 'jsb_cocos2dx_experimental_webView_auto'), \ - 'cocos2dx_experimental_video.ini' : ('cocos2dx_experimental_video', 'jsb_cocos2dx_experimental_video_auto'), \ + cmd_args = { + # 'cocos2dx.ini' : ('cocos2d-x', 'jsb_cocos2dx_auto'), \ + # 'cocos2dx_audioengine.ini' : ('cocos2dx_audioengine', 'jsb_cocos2dx_audioengine_auto'), \ + # 'cocos2dx_network.ini' : ('cocos2dx_network', 'jsb_cocos2dx_network_auto'), \ + # 'cocos2dx_extension.ini' : ('cocos2dx_extension', 'jsb_cocos2dx_extension_auto'), \ + # 'cocos2dx_builder.ini' : ('cocos2dx_builder', 'jsb_cocos2dx_builder_auto'), \ + # 'cocos2dx_ui.ini' : ('cocos2dx_ui', 'jsb_cocos2dx_ui_auto'), \ + # 'cocos2dx_studio.ini' : ('cocos2dx_studio', 'jsb_cocos2dx_studio_auto'), \ + # 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'jsb_cocos2dx_spine_auto'), \ + # 'cocos2dx_dragonbones.ini' : ('cocos2dx_dragonbones', 'jsb_cocos2dx_dragonbones_auto'), \ + # 'cocos2dx_experimental_webView.ini' : ('cocos2dx_experimental_webView', 'jsb_cocos2dx_experimental_webView_auto'), \ + # 'cocos2dx_experimental_video.ini' : ('cocos2dx_experimental_video', 'jsb_cocos2dx_experimental_video_auto'), \ 'creator.ini': ('creator', 'jsb_creator_auto'), - 'box2d.ini' : ('box2d', 'jsb_box2d_auto'), + # 'box2d.ini' : ('box2d', 'jsb_box2d_auto'), } target = 'spidermonkey' generator_py = '%s/generator.py' % cxx_generator_root From 2612e32ef1dcaa88f66aaaaac4553548ef86770d Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Thu, 30 Mar 2017 16:06:09 +0800 Subject: [PATCH 2/7] optimize physics with cache object --- .../cocos2d_libs.xcodeproj/project.pbxproj | 12 ++ .../cocos/editor-support/creator/Android.mk | 13 +- .../editor-support/creator/CCCameraNode.h | 42 ++--- .../creator/CCPhysicsAABBQueryCallback.cpp | 52 ------ .../creator/CCPhysicsAABBQueryCallback.h | 50 ------ .../creator/CCPhysicsContactListener.cpp | 107 ------------ .../creator/CCPhysicsContactListener.h | 62 ------- .../creator/CCPhysicsContactWrapper.cpp | 9 - .../creator/CCPhysicsContactWrapper.h | 14 -- .../creator/CCPhysicsDebugDraw.cpp | 115 ------------- .../creator/CCPhysicsDebugDraw.h | 63 ------- .../creator/CCPhysicsRayCastCallback.cpp | 69 -------- .../creator/CCPhysicsRayCastCallback.h | 55 ------ .../editor-support/creator/CCPhysicsUtils.cpp | 93 ---------- .../editor-support/creator/CCPhysicsUtils.h | 57 ------- .../creator/CCPhysicsWorldManifoldWrapper.cpp | 9 - .../creator/CCPhysicsWorldManifoldWrapper.h | 14 -- .../physics/CCPhysicsAABBQueryCallback.h | 42 ++--- .../physics/CCPhysicsContactImpulse.cpp | 55 ++++++ .../creator/physics/CCPhysicsContactImpulse.h | 50 ++++++ .../physics/CCPhysicsContactListener.cpp | 9 +- .../physics/CCPhysicsContactListener.h | 53 +++--- .../creator/physics/CCPhysicsDebugDraw.h | 42 ++--- .../creator/physics/CCPhysicsDefine.h | 30 +++- .../physics/CCPhysicsManifoldWrapper.cpp | 85 +++++++++- .../physics/CCPhysicsManifoldWrapper.h | 62 ++++++- .../physics/CCPhysicsRayCastCallback.h | 42 ++--- .../creator/physics/CCPhysicsUtils.cpp | 7 + .../creator/physics/CCPhysicsUtils.h | 45 ++--- .../physics/CCPhysicsWorldManifoldWrapper.cpp | 27 ++- .../physics/CCPhysicsWorldManifoldWrapper.h | 42 ++--- .../auto/api/jsb_creator_auto_api.js | 62 +++++++ .../js-bindings/auto/jsb_creator_auto.cpp | 160 ++++++++++++++++++ .../js-bindings/auto/jsb_creator_auto.hpp | 13 ++ .../creator/js_bindings_creator_manual.cpp | 34 ++-- native/tools/tojs/creator.ini | 5 +- 36 files changed, 734 insertions(+), 967 deletions(-) delete mode 100644 native/cocos/editor-support/creator/CCPhysicsAABBQueryCallback.cpp delete mode 100644 native/cocos/editor-support/creator/CCPhysicsAABBQueryCallback.h delete mode 100644 native/cocos/editor-support/creator/CCPhysicsContactListener.cpp delete mode 100644 native/cocos/editor-support/creator/CCPhysicsContactListener.h delete mode 100644 native/cocos/editor-support/creator/CCPhysicsContactWrapper.cpp delete mode 100644 native/cocos/editor-support/creator/CCPhysicsContactWrapper.h delete mode 100644 native/cocos/editor-support/creator/CCPhysicsDebugDraw.cpp delete mode 100644 native/cocos/editor-support/creator/CCPhysicsDebugDraw.h delete mode 100644 native/cocos/editor-support/creator/CCPhysicsRayCastCallback.cpp delete mode 100644 native/cocos/editor-support/creator/CCPhysicsRayCastCallback.h delete mode 100644 native/cocos/editor-support/creator/CCPhysicsUtils.cpp delete mode 100644 native/cocos/editor-support/creator/CCPhysicsUtils.h delete mode 100644 native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.cpp delete mode 100644 native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.h create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.cpp create mode 100644 native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.h diff --git a/native/build/cocos2d_libs.xcodeproj/project.pbxproj b/native/build/cocos2d_libs.xcodeproj/project.pbxproj index 1029062863..8b17c4e6b0 100644 --- a/native/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/native/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -638,6 +638,10 @@ 464AD6E6197EBB1400E502D8 /* pvr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 464AD6E3197EBB1400E502D8 /* pvr.cpp */; }; 464AD6E7197EBB1400E502D8 /* pvr.h in Headers */ = {isa = PBXBuildFile; fileRef = 464AD6E4197EBB1400E502D8 /* pvr.h */; }; 464AD6E8197EBB1400E502D8 /* pvr.h in Headers */ = {isa = PBXBuildFile; fileRef = 464AD6E4197EBB1400E502D8 /* pvr.h */; }; + 4D2816661E8CBB7200F26B06 /* CCPhysicsContactImpulse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2816641E8CBB7200F26B06 /* CCPhysicsContactImpulse.cpp */; }; + 4D2816671E8CBB7200F26B06 /* CCPhysicsContactImpulse.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2816641E8CBB7200F26B06 /* CCPhysicsContactImpulse.cpp */; }; + 4D2816681E8CBB7200F26B06 /* CCPhysicsContactImpulse.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D2816651E8CBB7200F26B06 /* CCPhysicsContactImpulse.h */; }; + 4D2816691E8CBB7200F26B06 /* CCPhysicsContactImpulse.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D2816651E8CBB7200F26B06 /* CCPhysicsContactImpulse.h */; }; 4D2E69071CC543B40032DD5C /* CCGraphicsNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2E69031CC543B40032DD5C /* CCGraphicsNode.cpp */; }; 4D2E69081CC543B40032DD5C /* CCGraphicsNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D2E69031CC543B40032DD5C /* CCGraphicsNode.cpp */; }; 4D2E69091CC543B40032DD5C /* CCGraphicsNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D2E69041CC543B40032DD5C /* CCGraphicsNode.h */; }; @@ -2271,6 +2275,8 @@ 46A168631807AF4E005B8026 /* CCTableView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCTableView.h; sourceTree = ""; }; 46A168641807AF4E005B8026 /* CCTableViewCell.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CCTableViewCell.cpp; sourceTree = ""; }; 46A168651807AF4E005B8026 /* CCTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CCTableViewCell.h; sourceTree = ""; }; + 4D2816641E8CBB7200F26B06 /* CCPhysicsContactImpulse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsContactImpulse.cpp; sourceTree = ""; }; + 4D2816651E8CBB7200F26B06 /* CCPhysicsContactImpulse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsContactImpulse.h; sourceTree = ""; }; 4D2E69031CC543B40032DD5C /* CCGraphicsNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCGraphicsNode.cpp; path = creator/CCGraphicsNode.cpp; sourceTree = ""; }; 4D2E69041CC543B40032DD5C /* CCGraphicsNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCGraphicsNode.h; path = creator/CCGraphicsNode.h; sourceTree = ""; }; 4D2E69051CC543B40032DD5C /* Triangulate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Triangulate.cpp; path = creator/Triangulate.cpp; sourceTree = ""; }; @@ -4049,6 +4055,8 @@ 4DC06BC21E8A68D400CA08B1 /* CCPhysicsAABBQueryCallback.h */, 4DC06BC31E8A68D400CA08B1 /* CCPhysicsContactListener.cpp */, 4DC06BC41E8A68D400CA08B1 /* CCPhysicsContactListener.h */, + 4D2816641E8CBB7200F26B06 /* CCPhysicsContactImpulse.cpp */, + 4D2816651E8CBB7200F26B06 /* CCPhysicsContactImpulse.h */, 4DC06BCD1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.cpp */, 4DC06BCE1E8A68D400CA08B1 /* CCPhysicsWorldManifoldWrapper.h */, 4DC06BEB1E8B604B00CA08B1 /* CCPhysicsManifoldWrapper.cpp */, @@ -5208,6 +5216,7 @@ FA6F1B611D80F858007DD223 /* Slot.h in Headers */, BAFF7CEC1D59E0DB0051B92F /* CocoStudio.h in Headers */, 50ABBE331925AB6F00A911A9 /* CCConfiguration.h in Headers */, + 4D2816681E8CBB7200F26B06 /* CCPhysicsContactImpulse.h in Headers */, 15AE1BE319AAE01E00C27E9E /* CCScrollView.h in Headers */, 50CB247519D9C5A100687767 /* AudioCache.h in Headers */, 50ABC01F1926664800A911A9 /* CCThread.h in Headers */, @@ -5609,6 +5618,7 @@ BAFF7DB11D5C1CF80051B92F /* SkeletonBounds.h in Headers */, 15AE1C0419AAE01E00C27E9E /* CCTableView.h in Headers */, 50ABBEA21925AB6F00A911A9 /* CCScheduler.h in Headers */, + 4D2816691E8CBB7200F26B06 /* CCPhysicsContactImpulse.h in Headers */, 4DC06BE21E8A68D400CA08B1 /* CCPhysicsRayCastCallback.h in Headers */, 4DED48431DFFA4AF0070C5C4 /* b2Contact.h in Headers */, 1A57020B180BCBDF0088DEC7 /* CCMotionStreak.h in Headers */, @@ -6212,6 +6222,7 @@ BAFF7CC01D59E0DB0051B92F /* CCDecorativeDisplay.cpp in Sources */, 15AE1BA319AADFDF00C27E9E /* UILayoutManager.cpp in Sources */, 4DED47DC1DFFA4AF0070C5C4 /* b2CollidePolygon.cpp in Sources */, + 4D2816661E8CBB7200F26B06 /* CCPhysicsContactImpulse.cpp in Sources */, BAFF7DCA1D5C1CF80051B92F /* spine-cocos2dx.cpp in Sources */, 4DED48041DFFA4AF0070C5C4 /* b2Draw.cpp in Sources */, B230ED7119B417AE00364AA8 /* CCTrianglesCommand.cpp in Sources */, @@ -6605,6 +6616,7 @@ 29394CF319B01DBA00D2DE1A /* UIWebView.mm in Sources */, 15AE18BD19AAD33D00C27E9E /* CCLabelBMFontLoader.cpp in Sources */, 50ABC01E1926664800A911A9 /* CCThread.cpp in Sources */, + 4D2816671E8CBB7200F26B06 /* CCPhysicsContactImpulse.cpp in Sources */, 2980F0271BA9A5550059E678 /* CCUISingleLineTextField.mm in Sources */, BAFF7CD91D59E0DB0051B92F /* CCSpriteFrameCacheHelper.cpp in Sources */, 1A5701EB180BCB8C0088DEC7 /* CCTransitionPageTurn.cpp in Sources */, diff --git a/native/cocos/editor-support/creator/Android.mk b/native/cocos/editor-support/creator/Android.mk index 5d9f388e1c..e5fc44c7e1 100644 --- a/native/cocos/editor-support/creator/Android.mk +++ b/native/cocos/editor-support/creator/Android.mk @@ -8,11 +8,14 @@ LOCAL_MODULE_FILENAME := libcreator LOCAL_SRC_FILES := CCScale9Sprite.cpp \ CCGraphicsNode.cpp \ Triangulate.cpp \ - CCPhysicsDebugDraw.cpp \ - CCPhysicsUtils.cpp \ - CCPhysicsAABBQueryCallback.cpp \ - CCPhysicsContactListener.cpp \ - CCPhysicsRayCastCallback.cpp \ + physics/CCPhysicsDebugDraw.cpp \ + physics/CCPhysicsUtils.cpp \ + physics/CCPhysicsAABBQueryCallback.cpp \ + physics/CCPhysicsContactListener.cpp \ + physics/CCPhysicsRayCastCallback.cpp \ + physics/CCPhysicsManifoldWrapper.cpp \ + physics/CCPhysicsWorldManifoldWrapper.cpp \ + physics/CCPhysicsContactImpulse.cpp \ CCCameraNode.cpp LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/.. diff --git a/native/cocos/editor-support/creator/CCCameraNode.h b/native/cocos/editor-support/creator/CCCameraNode.h index 30e81b5a8b..c273c58737 100644 --- a/native/cocos/editor-support/creator/CCCameraNode.h +++ b/native/cocos/editor-support/creator/CCCameraNode.h @@ -1,22 +1,26 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef __CREATOR_CCCAMERANODE_H__ #define __CREATOR_CCCAMERANODE_H__ diff --git a/native/cocos/editor-support/creator/CCPhysicsAABBQueryCallback.cpp b/native/cocos/editor-support/creator/CCPhysicsAABBQueryCallback.cpp deleted file mode 100644 index 2ec30ba755..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsAABBQueryCallback.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "CCPhysicsAABBQueryCallback.h" - -using namespace cocos2d; - -namespace creator { - -PhysicsAABBQueryCallback::PhysicsAABBQueryCallback() -: _isPoint(false) -{ -} - -PhysicsAABBQueryCallback::PhysicsAABBQueryCallback(const b2Vec2& p) -: _isPoint(false) -{ - _point = p; -} - -PhysicsAABBQueryCallback::~PhysicsAABBQueryCallback() -{ -} - -bool PhysicsAABBQueryCallback::ReportFixture(b2Fixture* fixture) -{ - b2Body* body = fixture->GetBody(); - if (body->GetType() == b2_dynamicBody) { - if (_isPoint) { - if (fixture->TestPoint(_point)) { - _fixtures.push_back(fixture); - // We are done, terminate the query. - return false; - } - } - else { - _fixtures.push_back(fixture); - } - } - - // Continue the query. - return true; -} - -b2Fixture* PhysicsAABBQueryCallback::getFixture() -{ - return _fixtures.size() > 0 ? _fixtures[0] : nullptr; -} - -std::vector PhysicsAABBQueryCallback::getFixtures() -{ - return _fixtures; -} - -} diff --git a/native/cocos/editor-support/creator/CCPhysicsAABBQueryCallback.h b/native/cocos/editor-support/creator/CCPhysicsAABBQueryCallback.h deleted file mode 100644 index 6b32035071..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsAABBQueryCallback.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#ifndef CCPhysicsAABBQueryCallback_h -#define CCPhysicsAABBQueryCallback_h - -#include "Box2D/Box2D.h" -#include "cocos2d.h" - -namespace creator { - -class CC_DLL PhysicsAABBQueryCallback : public b2QueryCallback -{ -public: - PhysicsAABBQueryCallback(); - PhysicsAABBQueryCallback(const b2Vec2& p); - - ~PhysicsAABBQueryCallback(); - - virtual bool ReportFixture(b2Fixture* fixture); - - b2Fixture* getFixture(); - std::vector getFixtures(); - -protected: - b2Vec2 _point; - std::vector _fixtures; - bool _isPoint; -}; - -} - -#endif /* CCPhysicsAABBQueryCallback_h */ diff --git a/native/cocos/editor-support/creator/CCPhysicsContactListener.cpp b/native/cocos/editor-support/creator/CCPhysicsContactListener.cpp deleted file mode 100644 index d6d6af924c..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsContactListener.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "CCPhysicsContactListener.h" -#include "cocos2d.h" - -using namespace cocos2d; - -namespace creator { - -PhysicsContactListener::PhysicsContactListener() -{ -} - -PhysicsContactListener::~PhysicsContactListener() { -} - -void PhysicsContactListener::setBeginContact(std::function callback) -{ - _beginContact = callback; -} - -void PhysicsContactListener::setEndContact(std::function callback) -{ - _endContact = callback; -} - -void PhysicsContactListener::setPreSolve(std::function callback) -{ - _preSolve = callback; -} - -void PhysicsContactListener::setPostSolve(std::function callback) -{ - _postSolve = callback; -} - - -void PhysicsContactListener::BeginContact(b2Contact* contact) -{ - if (!_beginContact) return; - - b2Fixture* fixtureA = contact->GetFixtureA(); - b2Fixture* fixtureB = contact->GetFixtureB(); - - if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || - find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) - { - _beginContact(contact); - } - -} - -void PhysicsContactListener::EndContact(b2Contact* contact) -{ - if (!_endContact) return; - - b2Fixture* fixtureA = contact->GetFixtureA(); - b2Fixture* fixtureB = contact->GetFixtureB(); - - if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || - find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) - { - _endContact(contact); - } -} - -void PhysicsContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold) -{ - if (!_preSolve) return; - - b2Fixture* fixtureA = contact->GetFixtureA(); - b2Fixture* fixtureB = contact->GetFixtureB(); - - if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || - find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) - { - _preSolve(contact, oldManifold); - } -} - -void PhysicsContactListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) -{ - if (!_postSolve) return; - - b2Fixture* fixtureA = contact->GetFixtureA(); - b2Fixture* fixtureB = contact->GetFixtureB(); - - if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || - find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) - { - _postSolve(contact, impulse); - } -} - -void PhysicsContactListener::registerContactFixture(b2Fixture* fixture) -{ - _contactFixtures.push_back(fixture); -} - -void PhysicsContactListener::unregisterContactFixture(b2Fixture* fixture) -{ - auto result = find(_contactFixtures.begin(), _contactFixtures.end(), fixture); - if (result != _contactFixtures.end()) - { - _contactFixtures.erase(result); - } -} - -} diff --git a/native/cocos/editor-support/creator/CCPhysicsContactListener.h b/native/cocos/editor-support/creator/CCPhysicsContactListener.h deleted file mode 100644 index a3e6515628..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsContactListener.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#ifndef PhysicsContactListener_H -#define PhysicsContactListener_H - -#include "Box2D/Box2D.h" -#include "cocos2d.h" -#include -#include - -namespace creator { - -class CC_DLL PhysicsContactListener : public b2ContactListener -{ -public: - PhysicsContactListener(); - virtual ~PhysicsContactListener(); - - void setBeginContact(std::function callback); - void setEndContact(std::function callback); - void setPreSolve(std::function callback); - void setPostSolve(std::function callback); - - - virtual void BeginContact(b2Contact* contact); - virtual void EndContact(b2Contact* contact); - virtual void PreSolve(b2Contact* contact, const b2Manifold* oldManifold); - virtual void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse); - - void registerContactFixture(b2Fixture* fixture); - void unregisterContactFixture(b2Fixture* fixture); - -protected: - std::function _beginContact; - std::function _endContact; - std::function _preSolve; - std::function _postSolve; - - std::vector _contactFixtures; -}; - -} - -#endif diff --git a/native/cocos/editor-support/creator/CCPhysicsContactWrapper.cpp b/native/cocos/editor-support/creator/CCPhysicsContactWrapper.cpp deleted file mode 100644 index f1801dc00b..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsContactWrapper.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// CCPhysicsContactWrapper.cpp -// cocos2d_libs -// -// Created by youyou on 17/3/28. -// -// - -#include "CCPhysicsContactWrapper.hpp" diff --git a/native/cocos/editor-support/creator/CCPhysicsContactWrapper.h b/native/cocos/editor-support/creator/CCPhysicsContactWrapper.h deleted file mode 100644 index 12a8f86c41..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsContactWrapper.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// CCPhysicsContactWrapper.hpp -// cocos2d_libs -// -// Created by youyou on 17/3/28. -// -// - -#ifndef CCPhysicsContactWrapper_hpp -#define CCPhysicsContactWrapper_hpp - -#include - -#endif /* CCPhysicsContactWrapper_hpp */ diff --git a/native/cocos/editor-support/creator/CCPhysicsDebugDraw.cpp b/native/cocos/editor-support/creator/CCPhysicsDebugDraw.cpp deleted file mode 100644 index 28ec1f47be..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsDebugDraw.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "CCPhysicsDebugDraw.h" -#include "CCGL.h" - -#include "cocos2d.h" - -#include -#include - -#include - -using namespace cocos2d; - -namespace creator { - -PhysicsDebugDraw::PhysicsDebugDraw( float32 ratio ) -: mRatio( ratio ) -{ - _drawer = GraphicsNode::create(); - _drawer->retain(); -} - -PhysicsDebugDraw::~PhysicsDebugDraw() -{ - _drawer->release(); -} - -creator::GraphicsNode* PhysicsDebugDraw::getDrawer() -{ - return _drawer; -} - -void PhysicsDebugDraw::ClearDraw() -{ - _drawer->clear(); -} - -void PhysicsDebugDraw::AddDrawerToNode(cocos2d::Node *node) -{ - _drawer->removeFromParent(); - node->addChild(_drawer); -} - -void PhysicsDebugDraw::DrawPolygon(const b2Vec2* old_vertices, int vertexCount, const b2Color& color) -{ - Color4F c(color.r, color.g, color.b, /*color.a*/0.5); - _drawer->setStrokeColor(c); - - for( int i=0;imoveTo(old_vertices[i].x * mRatio, old_vertices[i].y * mRatio); - else { - _drawer->lineTo(old_vertices[i].x * mRatio, old_vertices[i].y * mRatio); - } - } - _drawer->close(); - _drawer->stroke(); -} - -void PhysicsDebugDraw::DrawSolidPolygon(const b2Vec2* old_vertices, int vertexCount, const b2Color& color) -{ - Color4F c(color.r, color.g, color.b, /*color.a*/0.5); - _drawer->setFillColor(c); - - for( int i=0;imoveTo(old_vertices[i].x * mRatio, old_vertices[i].y * mRatio); - else { - _drawer->lineTo(old_vertices[i].x * mRatio, old_vertices[i].y * mRatio); - } - } - _drawer->close(); - _drawer->fill(); -} - -void PhysicsDebugDraw::DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) -{ - Color4F c(color.r, color.g, color.b, /*color.a*/0.5); - _drawer->setStrokeColor(c); - - _drawer->circle(center.x * mRatio, center.y * mRatio, radius * mRatio); - _drawer->stroke(); -} - -void PhysicsDebugDraw::DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) -{ - Color4F c(color.r, color.g, color.b, /*color.a*/0.5); - _drawer->setFillColor(c); - - _drawer->circle(center.x * mRatio, center.y * mRatio, radius * mRatio); - _drawer->fill(); -} - -void PhysicsDebugDraw::DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) -{ - Color4F c(color.r, color.g, color.b, /*color.a*/0.5); - _drawer->setStrokeColor(c); - - _drawer->moveTo(p1.x * mRatio, p1.y * mRatio); - _drawer->lineTo(p2.x * mRatio, p2.y * mRatio); - _drawer->stroke(); -} - -void PhysicsDebugDraw::DrawTransform(const b2Transform& xf) -{ - // b2Vec2 p1 = xf.p, p2; - // const float32 k_axisScale = 0.4f; - // - // p2 = p1 + k_axisScale * xf.R.col1; - // DrawSegment(p1,p2,b2Color(1,0,0)); - // - // p2 = p1 + k_axisScale * xf.R.col2; - // DrawSegment(p1,p2,b2Color(0,1,0)); -} - -} diff --git a/native/cocos/editor-support/creator/CCPhysicsDebugDraw.h b/native/cocos/editor-support/creator/CCPhysicsDebugDraw.h deleted file mode 100644 index fa24bc1ce2..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsDebugDraw.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#ifndef PhysicsDebugDraw_H -#define PhysicsDebugDraw_H - -#include "Box2D/Box2D.h" -#include "editor-support/creator/CCGraphicsNode.h" - -namespace creator { - -// This class implements debug drawing callbacks that are invoked -// inside b2World::Step. -class CC_DLL PhysicsDebugDraw : public b2Draw -{ -public: - PhysicsDebugDraw(float ratio = 32.0f); - ~PhysicsDebugDraw(); - - creator::GraphicsNode* getDrawer(); - - void ClearDraw(); - - void AddDrawerToNode(cocos2d::Node* node); - - void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color); - - void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color); - - void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color); - - void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color); - - void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color); - - void DrawTransform(const b2Transform& xf); - -protected: - float mRatio; - creator::GraphicsNode* _drawer; - -}; - -} - -#endif diff --git a/native/cocos/editor-support/creator/CCPhysicsRayCastCallback.cpp b/native/cocos/editor-support/creator/CCPhysicsRayCastCallback.cpp deleted file mode 100644 index 7a38698bec..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsRayCastCallback.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "CCPhysicsRayCastCallback.h" - -using namespace cocos2d; - -namespace creator { - -PhysicsRayCastCallback::PhysicsRayCastCallback(int type) -{ - _rayCastType = type; -} - -PhysicsRayCastCallback::~PhysicsRayCastCallback() { -} - -float32 PhysicsRayCastCallback::ReportFixture(b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction) -{ - if (_rayCastType == 0) { - if (_fixtures.size() > 0) { - _fixtures[0] = fixture; - _normals[0] = normal; - _points[0] = point; - _fractions[0] = fraction; - } - else { - _fixtures.push_back(fixture); - _normals.push_back(normal); - _points.push_back(point); - _fractions.push_back(fraction); - } - - return fraction; - } - - _fixtures.push_back(fixture); - _normals.push_back(normal); - _points.push_back(point); - _fractions.push_back(fraction); - - if (_rayCastType == 1) { - return 0; - } - else { - return 1; - } - - return fraction; -} - -std::vector& PhysicsRayCastCallback::getFixtures() { - return _fixtures; -} - -std::vector& PhysicsRayCastCallback::getPoints() { - return _points; -} - -std::vector& PhysicsRayCastCallback::getNormals() { - return _normals; -} - -std::vector& PhysicsRayCastCallback::getFractions() { - return _fractions; -} - -int PhysicsRayCastCallback::getType() { - return _rayCastType; -} - -} diff --git a/native/cocos/editor-support/creator/CCPhysicsRayCastCallback.h b/native/cocos/editor-support/creator/CCPhysicsRayCastCallback.h deleted file mode 100644 index 2461ac626e..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsRayCastCallback.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#ifndef CCPhysicsRayCastCallback_h -#define CCPhysicsRayCastCallback_h - -#include "Box2D/Box2D.h" -#include "cocos2d.h" - -namespace creator { - -class CC_DLL PhysicsRayCastCallback : public b2RayCastCallback -{ -public: - PhysicsRayCastCallback(int type); - ~PhysicsRayCastCallback(); - - virtual float32 ReportFixture(b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction); - - std::vector& getFixtures(); - std::vector& getPoints(); - std::vector& getNormals(); - std::vector& getFractions(); - - int getType(); - -protected: - int _rayCastType; - - std::vector _fixtures; - std::vector _points; - std::vector _normals; - std::vector _fractions; -}; - -} - -#endif /* CCPhysicsRayCastCallback_h */ diff --git a/native/cocos/editor-support/creator/CCPhysicsUtils.cpp b/native/cocos/editor-support/creator/CCPhysicsUtils.cpp deleted file mode 100644 index b9adf5bae4..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsUtils.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// -// CCPhysicsUtils.cpp -// cocos2d_libs -// -// Created by youyou on 16/12/22. -// -// - -#include "CCPhysicsUtils.h" - -using namespace cocos2d; - -namespace creator { - -static b2WorldManifold _worldManifold; - -PhysicsUtils::PhysicsUtils() - : PTM_RATIO(32) -{ - -} - -PhysicsUtils::~PhysicsUtils() -{ - -} - -void PhysicsUtils::addB2Body(b2Body* body) -{ - _bodies.push_back(body); -} - -void PhysicsUtils::removeB2Body(b2Body *body) -{ - const auto iterator = std::find(_bodies.begin(), _bodies.end(), body); - if (iterator != _bodies.end()) - { - _bodies.erase(iterator); - } -} - -void PhysicsUtils::syncNode() -{ - for (auto begin = _bodies.begin(); begin != _bodies.end(); begin++) - { - b2Body* body = *begin; - Node* node = (Node*)body->GetUserData(); - - const b2Vec2& pos = body->GetPosition(); - - Vec2 position(pos.x*PTM_RATIO, pos.y*PTM_RATIO); - float angle = -CC_RADIANS_TO_DEGREES(body->GetAngle()); - - if (node->getParent() && node->getParent()->getParent()) { - node->setPosition( _convertToNodePosition(node->getParent(), position) ); - node->setRotation( _convertToNodeRotation(node->getParent(), angle) ); - } - else { - node->setPosition(position); - node->setRotation(angle); - } - } -} - -const b2WorldManifold* PhysicsUtils::getContactWorldManifold(b2Contact* contact) -{ - contact->GetWorldManifold(&_worldManifold); - return &_worldManifold; -} - -cocos2d::Vec2 PhysicsUtils::_convertToNodePosition(cocos2d::Node* node, cocos2d::Vec2& position) -{ - if (node->isIgnoreAnchorPointForPosition()) { - // see https://github.com/cocos-creator/engine/pull/391 - return node->convertToNodeSpace(position); - } - else { - return node->convertToNodeSpaceAR(position); - } -} - -float PhysicsUtils::_convertToNodeRotation(cocos2d::Node* node, float rotation) -{ - rotation -= node->getRotation(); - Node* parent = node->getParent(); - while(parent->getParent()){ - rotation -= parent->getRotation(); - parent = parent->getParent(); - } - return rotation; -} - -} diff --git a/native/cocos/editor-support/creator/CCPhysicsUtils.h b/native/cocos/editor-support/creator/CCPhysicsUtils.h deleted file mode 100644 index 5621f5177f..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsUtils.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#ifndef PhysicsUtils_H -#define PhysicsUtils_H - -#include - -#include "Box2D/Box2D.h" -#include "cocos2d.h" - -namespace creator { - -// This class implements debug drawing callbacks that are invoked -// inside b2World::Step. -class CC_DLL PhysicsUtils -{ -public: - PhysicsUtils(); - ~PhysicsUtils(); - - void addB2Body(b2Body* body); - void removeB2Body(b2Body* body); - - void syncNode(); - -public: - static const b2WorldManifold* getContactWorldManifold(b2Contact* contact); - -protected: - cocos2d::Vec2 _convertToNodePosition(cocos2d::Node* node, cocos2d::Vec2& position); - float _convertToNodeRotation(cocos2d::Node* node, float rotation); - - std::vector _bodies; - float PTM_RATIO; -}; - -} - -#endif diff --git a/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.cpp b/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.cpp deleted file mode 100644 index f7a6afed69..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// CCPhysicsWorldManifoldWrapper.cpp -// cocos2d_libs -// -// Created by youyou on 17/3/28. -// -// - -#include "CCPhysicsWorldManifoldWrapper.hpp" diff --git a/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.h b/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.h deleted file mode 100644 index 36a9a488b4..0000000000 --- a/native/cocos/editor-support/creator/CCPhysicsWorldManifoldWrapper.h +++ /dev/null @@ -1,14 +0,0 @@ -// -// CCPhysicsWorldManifoldWrapper.hpp -// cocos2d_libs -// -// Created by youyou on 17/3/28. -// -// - -#ifndef CCPhysicsWorldManifoldWrapper_hpp -#define CCPhysicsWorldManifoldWrapper_hpp - -#include - -#endif /* CCPhysicsWorldManifoldWrapper_hpp */ diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.h b/native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.h index 6b32035071..b5beb56a15 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsAABBQueryCallback.h @@ -1,22 +1,26 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef CCPhysicsAABBQueryCallback_h #define CCPhysicsAABBQueryCallback_h diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.cpp new file mode 100644 index 0000000000..ebb5b80aab --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "CCPhysicsContactImpulse.h" +#include "CCPhysicsDefine.h" + +namespace creator { + PhysicsContactImpulse::PhysicsContactImpulse() + { + } + PhysicsContactImpulse::~PhysicsContactImpulse() + { + } + + void PhysicsContactImpulse::init(const b2ContactImpulse* impulse) + { + _impulse = *impulse; + } + + int PhysicsContactImpulse::getCount() + { + return _impulse.count; + } + + float32 PhysicsContactImpulse::getNormalImpulse(int index) + { + return _impulse.normalImpulses[index] * CC_PTM_RATIO; + } + float32 PhysicsContactImpulse::getTangentImpulse(int index) + { + return _impulse.tangentImpulses[index]; + } +} + diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.h b/native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.h new file mode 100644 index 0000000000..b9a1f435ca --- /dev/null +++ b/native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.h @@ -0,0 +1,50 @@ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef CCPhysicsContactImpulse_h +#define CCPhysicsContactImpulse_h + +#include "Box2D/Box2D.h" +#include "cocos2d.h" + +namespace creator { + class PhysicsContactImpulse : public cocos2d::Ref + { + public: + PhysicsContactImpulse(); + ~PhysicsContactImpulse(); + + void init(const b2ContactImpulse* impulse); + + int getCount(); + float32 getNormalImpulse(int index); + float32 getTangentImpulse(int index); + + protected: + b2ContactImpulse _impulse; + }; +} + + +#endif /* CCPhysicsContactImpulse_h */ diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp index d6d6af924c..1bd6e5f03a 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp +++ b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp @@ -22,12 +22,12 @@ void PhysicsContactListener::setEndContact(std::function callback) +void PhysicsContactListener::setPreSolve(std::function callback) { _preSolve = callback; } -void PhysicsContactListener::setPostSolve(std::function callback) +void PhysicsContactListener::setPostSolve(std::function callback) { _postSolve = callback; } @@ -72,7 +72,7 @@ void PhysicsContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldM if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) { - _preSolve(contact, oldManifold); + _preSolve(contact); } } @@ -86,7 +86,8 @@ void PhysicsContactListener::PostSolve(b2Contact* contact, const b2ContactImpuls if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) { - _postSolve(contact, impulse); + _impulse.init(impulse); + _postSolve(contact, &_impulse); } } diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h index a3e6515628..38dd11975d 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h @@ -1,28 +1,34 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef PhysicsContactListener_H #define PhysicsContactListener_H #include "Box2D/Box2D.h" #include "cocos2d.h" +#include "CCPhysicsContactImpulse.h" + #include #include @@ -36,8 +42,8 @@ public: void setBeginContact(std::function callback); void setEndContact(std::function callback); - void setPreSolve(std::function callback); - void setPostSolve(std::function callback); + void setPreSolve(std::function callback); + void setPostSolve(std::function callback); virtual void BeginContact(b2Contact* contact); @@ -51,10 +57,11 @@ public: protected: std::function _beginContact; std::function _endContact; - std::function _preSolve; - std::function _postSolve; + std::function _preSolve; + std::function _postSolve; std::vector _contactFixtures; + PhysicsContactImpulse _impulse; }; } diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.h b/native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.h index bf9c8d6709..4d33bfa5a0 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsDebugDraw.h @@ -1,22 +1,26 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef PhysicsDebugDraw_H #define PhysicsDebugDraw_H diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsDefine.h b/native/cocos/editor-support/creator/physics/CCPhysicsDefine.h index db7d75a3b8..205b5951b7 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsDefine.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsDefine.h @@ -1,10 +1,26 @@ -// -// CCPhysicsDefine.h -// cocos2d_libs -// -// Created by youyou on 17/3/29. -// -// +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef CCPhysicsDefine_h #define CCPhysicsDefine_h diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.cpp index 73191fb52c..5faba7df85 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.cpp +++ b/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.cpp @@ -1,9 +1,80 @@ -// -// CCPhysicsManifoldWrapper.cpp -// cocos2d_libs -// -// Created by youyou on 17/3/29. -// -// +/* + * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com + * + * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + #include "CCPhysicsManifoldWrapper.h" +#include "CCPhysicsDefine.h" + +namespace creator { + PhysicsManifoldWrapper::PhysicsManifoldWrapper() + { + } + PhysicsManifoldWrapper::~PhysicsManifoldWrapper() + { + } + + void PhysicsManifoldWrapper::init(b2Contact* contact) + { + _contact = contact; + _manifold = _contact->GetManifold(); + } + + int PhysicsManifoldWrapper::getCount() + { + return _manifold->pointCount; + } + int PhysicsManifoldWrapper::getType() + { + return _manifold->type; + } + + float32 PhysicsManifoldWrapper::getX(int index) + { + return _manifold->points[index].localPoint.x * CC_PTM_RATIO; + } + float32 PhysicsManifoldWrapper::getY(int index) + { + return _manifold->points[index].localPoint.y * CC_PTM_RATIO; + } + float32 PhysicsManifoldWrapper::getNormalImpulse(int index) + { + return _manifold->points[index].normalImpulse * CC_PTM_RATIO; + } + float32 PhysicsManifoldWrapper::getTangentImpulse(int index) + { + return _manifold->points[index].tangentImpulse; + } + float32 PhysicsManifoldWrapper::getLocalNormalX() + { + return _manifold->localNormal.x; + } + float32 PhysicsManifoldWrapper::getLocalNormalY() + { + return _manifold->localNormal.y; + } + float32 PhysicsManifoldWrapper::getLocalPointX() + { + return _manifold->localPoint.x * CC_PTM_RATIO; + } + float32 PhysicsManifoldWrapper::getLocalPointY() + { + return _manifold->localPoint.y * CC_PTM_RATIO; + } +} diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h b/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h index 777d6ccdea..ebacd1f40f 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h @@ -1,14 +1,58 @@ -// -// CCPhysicsManifoldWrapper.hpp -// cocos2d_libs -// -// Created by youyou on 17/3/29. -// -// +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef CCPhysicsManifoldWrapper_h #define CCPhysicsManifoldWrapper_h -#include +#include "Box2D/Box2D.h" +#include "cocos2d.h" -#endif /* CCPhysicsManifoldWrapper_h */ +namespace creator { + class PhysicsManifoldWrapper : public cocos2d::Ref + { + public: + PhysicsManifoldWrapper(); + ~PhysicsManifoldWrapper(); + + void init(b2Contact* contact); + + int getCount(); + int getType(); + float32 getX(int index); + float32 getY(int index); + float32 getNormalImpulse(int index); + float32 getTangentImpulse(int index); + float32 getLocalNormalX(); + float32 getLocalNormalY(); + float32 getLocalPointX(); + float32 getLocalPointY(); + + protected: + b2Contact* _contact; + b2Manifold* _manifold; + }; +} + + +#endif /* CCPhysicsWorldManifoldWrapper_h */ diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.h b/native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.h index 2461ac626e..9b5b0b27f9 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsRayCastCallback.h @@ -1,22 +1,26 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef CCPhysicsRayCastCallback_h #define CCPhysicsRayCastCallback_h diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp index 52711d8d3e..ad62b2b41c 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp +++ b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp @@ -14,6 +14,7 @@ using namespace cocos2d; namespace creator { static PhysicsWorldManifoldWrapper _worldManifoldWrapper; +static PhysicsManifoldWrapper _manifoldWrapper; PhysicsUtils::PhysicsUtils() { @@ -75,6 +76,12 @@ const PhysicsWorldManifoldWrapper* PhysicsUtils::getContactWorldManifoldWrapper( return &_worldManifoldWrapper; } +const PhysicsManifoldWrapper* PhysicsUtils::getContactManifoldWrapper(b2Contact* contact) +{ + _manifoldWrapper.init(contact); + return &_manifoldWrapper; +} + cocos2d::Vec2 PhysicsUtils::_convertToNodePosition(cocos2d::Node* node, cocos2d::Vec2& position) { if (node->isIgnoreAnchorPointForPosition()) { diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsUtils.h b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.h index a6874ad640..e8935ca568 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsUtils.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.h @@ -1,22 +1,26 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef PhysicsUtils_H #define PhysicsUtils_H @@ -27,6 +31,7 @@ #include "cocos2d.h" #include "CCPhysicsWorldManifoldWrapper.h" +#include "CCPhysicsManifoldWrapper.h" namespace creator { @@ -47,7 +52,7 @@ public: public: static const PhysicsWorldManifoldWrapper* getContactWorldManifoldWrapper(b2Contact* contact); - + static const PhysicsManifoldWrapper* getContactManifoldWrapper(b2Contact* contact); protected: cocos2d::Vec2 _convertToNodePosition(cocos2d::Node* node, cocos2d::Vec2& position); float _convertToNodeRotation(cocos2d::Node* node, float rotation); diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.cpp index 6823001b44..7d8b7fc6f1 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.cpp +++ b/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.cpp @@ -1,10 +1,23 @@ -// -// CCPhysicsWorldManifoldWrapper.cpp -// cocos2d_libs -// -// Created by youyou on 17/3/28. -// -// +/* + * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com + * + * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + #include "CCPhysicsWorldManifoldWrapper.h" #include "CCPhysicsDefine.h" diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h b/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h index 657b412834..b5ddbd9746 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h @@ -1,22 +1,26 @@ -/* - * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com - * - * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ #ifndef CCPhysicsWorldManifoldWrapper_h #define CCPhysicsWorldManifoldWrapper_h diff --git a/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js b/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js index e686dcad37..03ef27f27f 100644 --- a/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js +++ b/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js @@ -912,6 +912,18 @@ b2body { }, +/** + * @method getContactManifoldWrapper + * @param {b2Contact} arg0 + * @return {creator::PhysicsManifoldWrapper} + */ +getContactManifoldWrapper : function ( +b2contact +) +{ + return creator::PhysicsManifoldWrapper; +}, + /** * @method getContactWorldManifoldWrapper * @param {b2Contact} arg0 @@ -935,6 +947,56 @@ PhysicsUtils : function ( }; +/** + * @class PhysicsContactImpulse + */ +cc.PhysicsContactImpulse = { + +/** + * @method getCount + * @return {int} + */ +getCount : function ( +) +{ + return 0; +}, + +/** + * @method getNormalImpulse + * @param {int} arg0 + * @return {float} + */ +getNormalImpulse : function ( +int +) +{ + return 0; +}, + +/** + * @method getTangentImpulse + * @param {int} arg0 + * @return {float} + */ +getTangentImpulse : function ( +int +) +{ + return 0; +}, + +/** + * @method PhysicsContactImpulse + * @constructor + */ +PhysicsContactImpulse : function ( +) +{ +}, + +}; + /** * @class PhysicsContactListener */ diff --git a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp index 328adc3afc..27eddb0dc7 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp @@ -8,6 +8,7 @@ #include "editor-support/creator/physics/CCPhysicsAABBQueryCallback.h" #include "editor-support/creator/physics/CCPhysicsRayCastCallback.h" #include "editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h" +#include "editor-support/creator/physics/CCPhysicsContactImpulse.h" #include "editor-support/creator/CCCameraNode.h" #include "scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.h" @@ -2154,6 +2155,37 @@ bool js_creator_PhysicsUtils_removeB2Body(JSContext *cx, uint32_t argc, jsval *v JS_ReportError(cx, "js_creator_PhysicsUtils_removeB2Body : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_creator_PhysicsUtils_getContactManifoldWrapper(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + if (argc == 1) { + b2Contact* arg0 = nullptr; + do { + if (args.get(0).isNull()) { arg0 = nullptr; break; } + if (!args.get(0).isObject()) { ok = false; break; } + js_proxy_t *jsProxy; + JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); + jsProxy = jsb_get_js_proxy(tmpObj); + arg0 = (b2Contact*)(jsProxy ? jsProxy->ptr : NULL); + JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); + } while (0); + JSB_PRECONDITION2(ok, cx, false, "js_creator_PhysicsUtils_getContactManifoldWrapper : Error processing arguments"); + + const creator::PhysicsManifoldWrapper* ret = creator::PhysicsUtils::getContactManifoldWrapper(arg0); + jsval jsret = JSVAL_NULL; + if (ret) { + jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (creator::PhysicsManifoldWrapper*)ret)); + } else { + jsret = JSVAL_NULL; + }; + args.rval().set(jsret); + return true; + } + JS_ReportError(cx, "js_creator_PhysicsUtils_getContactManifoldWrapper : wrong number of arguments"); + return false; +} + bool js_creator_PhysicsUtils_getContactWorldManifoldWrapper(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -2251,6 +2283,7 @@ void js_register_creator_PhysicsUtils(JSContext *cx, JS::HandleObject global) { }; static JSFunctionSpec st_funcs[] = { + JS_FN("getContactManifoldWrapper", js_creator_PhysicsUtils_getContactManifoldWrapper, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getContactWorldManifoldWrapper", js_creator_PhysicsUtils_getContactWorldManifoldWrapper, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; @@ -2274,6 +2307,132 @@ void js_register_creator_PhysicsUtils(JSContext *cx, JS::HandleObject global) { jsb_register_class(cx, jsb_creator_PhysicsUtils_class, proto, JS::NullPtr()); } +JSClass *jsb_creator_PhysicsContactImpulse_class; +JSObject *jsb_creator_PhysicsContactImpulse_prototype; + +bool js_creator_PhysicsContactImpulse_getCount(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + creator::PhysicsContactImpulse* cobj = (creator::PhysicsContactImpulse *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsContactImpulse_getCount : Invalid Native Object"); + if (argc == 0) { + int ret = cobj->getCount(); + JS::RootedValue jsret(cx); + jsret = int32_to_jsval(cx, ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_creator_PhysicsContactImpulse_getCount : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} +bool js_creator_PhysicsContactImpulse_getNormalImpulse(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + creator::PhysicsContactImpulse* cobj = (creator::PhysicsContactImpulse *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsContactImpulse_getNormalImpulse : Invalid Native Object"); + if (argc == 1) { + int arg0 = 0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_creator_PhysicsContactImpulse_getNormalImpulse : Error processing arguments"); + double ret = cobj->getNormalImpulse(arg0); + JS::RootedValue jsret(cx); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_creator_PhysicsContactImpulse_getNormalImpulse : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_creator_PhysicsContactImpulse_getTangentImpulse(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + creator::PhysicsContactImpulse* cobj = (creator::PhysicsContactImpulse *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsContactImpulse_getTangentImpulse : Invalid Native Object"); + if (argc == 1) { + int arg0 = 0; + ok &= jsval_to_int32(cx, args.get(0), (int32_t *)&arg0); + JSB_PRECONDITION2(ok, cx, false, "js_creator_PhysicsContactImpulse_getTangentImpulse : Error processing arguments"); + double ret = cobj->getTangentImpulse(arg0); + JS::RootedValue jsret(cx); + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_creator_PhysicsContactImpulse_getTangentImpulse : wrong number of arguments: %d, was expecting %d", argc, 1); + return false; +} +bool js_creator_PhysicsContactImpulse_constructor(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + bool ok = true; + creator::PhysicsContactImpulse* cobj = new (std::nothrow) creator::PhysicsContactImpulse(); + + js_type_class_t *typeClass = js_get_type_from_native(cobj); + + // link the native object with the javascript object + JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, cobj, typeClass, "creator::PhysicsContactImpulse")); + args.rval().set(OBJECT_TO_JSVAL(jsobj)); + if (JS_HasProperty(cx, jsobj, "_ctor", &ok) && ok) + ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(jsobj), "_ctor", args); + return true; +} + + +void js_register_creator_PhysicsContactImpulse(JSContext *cx, JS::HandleObject global) { + jsb_creator_PhysicsContactImpulse_class = (JSClass *)calloc(1, sizeof(JSClass)); + jsb_creator_PhysicsContactImpulse_class->name = "PhysicsContactImpulse"; + jsb_creator_PhysicsContactImpulse_class->addProperty = JS_PropertyStub; + jsb_creator_PhysicsContactImpulse_class->delProperty = JS_DeletePropertyStub; + jsb_creator_PhysicsContactImpulse_class->getProperty = JS_PropertyStub; + jsb_creator_PhysicsContactImpulse_class->setProperty = JS_StrictPropertyStub; + jsb_creator_PhysicsContactImpulse_class->enumerate = JS_EnumerateStub; + jsb_creator_PhysicsContactImpulse_class->resolve = JS_ResolveStub; + jsb_creator_PhysicsContactImpulse_class->convert = JS_ConvertStub; + jsb_creator_PhysicsContactImpulse_class->flags = JSCLASS_HAS_RESERVED_SLOTS(2); + + static JSPropertySpec properties[] = { + JS_PS_END + }; + + static JSFunctionSpec funcs[] = { + JS_FN("getCount", js_creator_PhysicsContactImpulse_getCount, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getNormalImpulse", js_creator_PhysicsContactImpulse_getNormalImpulse, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("getTangentImpulse", js_creator_PhysicsContactImpulse_getTangentImpulse, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FS_END + }; + + JSFunctionSpec *st_funcs = NULL; + + jsb_creator_PhysicsContactImpulse_prototype = JS_InitClass( + cx, global, + JS::NullPtr(), + jsb_creator_PhysicsContactImpulse_class, + js_creator_PhysicsContactImpulse_constructor, 0, // constructor + properties, + funcs, + NULL, // no static properties + st_funcs); + + JS::RootedObject proto(cx, jsb_creator_PhysicsContactImpulse_prototype); + JS::RootedValue className(cx, std_string_to_jsval(cx, "PhysicsContactImpulse")); + JS_SetProperty(cx, proto, "_className", className); + JS_SetProperty(cx, proto, "__nativeObj", JS::TrueHandleValue); + JS_SetProperty(cx, proto, "__is_ref", JS::TrueHandleValue); + // add the proto and JSClass to the type->js info hash table + jsb_register_class(cx, jsb_creator_PhysicsContactImpulse_class, proto, JS::NullPtr()); +} + JSClass *jsb_creator_PhysicsContactListener_class; JSObject *jsb_creator_PhysicsContactListener_prototype; @@ -2854,6 +3013,7 @@ void register_all_creator(JSContext* cx, JS::HandleObject obj) { js_register_creator_PhysicsRayCastCallback(cx, ns); js_register_creator_PhysicsDebugDraw(cx, ns); js_register_creator_PhysicsContactListener(cx, ns); + js_register_creator_PhysicsContactImpulse(cx, ns); js_register_creator_PhysicsUtils(cx, ns); js_register_creator_Scale9SpriteV2(cx, ns); js_register_creator_PhysicsWorldManifoldWrapper(cx, ns); diff --git a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp index ef31fe04ae..a6d41cd869 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp @@ -124,9 +124,22 @@ bool js_creator_PhysicsUtils_addB2Body(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_syncNode(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_setFixtureNext(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_removeB2Body(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsUtils_getContactManifoldWrapper(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_getContactWorldManifoldWrapper(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_PhysicsUtils(JSContext *cx, uint32_t argc, jsval *vp); +extern JSClass *jsb_creator_PhysicsContactImpulse_class; +extern JSObject *jsb_creator_PhysicsContactImpulse_prototype; + +bool js_creator_PhysicsContactImpulse_constructor(JSContext *cx, uint32_t argc, jsval *vp); +void js_creator_PhysicsContactImpulse_finalize(JSContext *cx, JSObject *obj); +void js_register_creator_PhysicsContactImpulse(JSContext *cx, JS::HandleObject global); +void register_all_creator(JSContext* cx, JS::HandleObject obj); +bool js_creator_PhysicsContactImpulse_getCount(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsContactImpulse_getNormalImpulse(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsContactImpulse_getTangentImpulse(JSContext *cx, uint32_t argc, jsval *vp); +bool js_creator_PhysicsContactImpulse_PhysicsContactImpulse(JSContext *cx, uint32_t argc, jsval *vp); + extern JSClass *jsb_creator_PhysicsContactListener_class; extern JSObject *jsb_creator_PhysicsContactListener_prototype; diff --git a/native/cocos/scripting/js-bindings/manual/creator/js_bindings_creator_manual.cpp b/native/cocos/scripting/js-bindings/manual/creator/js_bindings_creator_manual.cpp index e9f34a455c..b66f86578b 100644 --- a/native/cocos/scripting/js-bindings/manual/creator/js_bindings_creator_manual.cpp +++ b/native/cocos/scripting/js-bindings/manual/creator/js_bindings_creator_manual.cpp @@ -34,10 +34,11 @@ #include "scripting/js-bindings/auto/jsb_creator_auto.hpp" -#include "editor-support/creator/CCPhysicsContactListener.h" -#include "editor-support/creator/CCPhysicsUtils.h" -#include "editor-support/creator/CCPhysicsAABBQueryCallback.h" -#include "editor-support/creator/CCPhysicsRayCastCallback.h" +#include "editor-support/creator/physics/CCPhysicsContactListener.h" +#include "editor-support/creator/physics/CCPhysicsUtils.h" +#include "editor-support/creator/physics/CCPhysicsAABBQueryCallback.h" +#include "editor-support/creator/physics/CCPhysicsRayCastCallback.h" +#include "editor-support/creator/physics/CCPhysicsContactImpulse.h" USING_NS_CC_EXT; @@ -150,27 +151,22 @@ bool js_creator_PhysicsContactListener_setPreSolve(JSContext *cx, uint32_t argc, creator::PhysicsContactListener* cobj = (creator::PhysicsContactListener *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsContactListener_setPreSolve : Invalid Native Object"); if (argc == 1) { - std::function arg0; + std::function arg0; do { if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { JS::RootedObject jstarget(cx, args.thisv().toObjectOrNull()); std::shared_ptr func(new JSFunctionWrapper(cx, jstarget, args.get(0), args.thisv())); - auto lambda = [=](b2Contact* larg0, const b2Manifold* larg1) -> void { + auto lambda = [=](b2Contact* larg0) -> void { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET - jsval largv[2]; + jsval largv[1]; if (larg0) { largv[0] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (b2Contact*)larg0)); } else { largv[0] = JSVAL_NULL; }; -// if (larg1) { -// largv[1] = b2Manifold_to_jsval(cx, larg1); -// } else { - largv[1] = JSVAL_NULL; -// }; JS::RootedValue rval(cx); - bool succeed = func->invoke(JS::HandleValueArray::fromMarkedLocation(2, largv), &rval); + bool succeed = func->invoke(JS::HandleValueArray::fromMarkedLocation(1, largv), &rval); if (!succeed && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } @@ -202,13 +198,13 @@ bool js_creator_PhysicsContactListener_setPostSolve(JSContext *cx, uint32_t argc creator::PhysicsContactListener* cobj = (creator::PhysicsContactListener *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsContactListener_setPostSolve : Invalid Native Object"); if (argc == 1) { - std::function arg0; + std::function arg0; do { if(JS_TypeOfValue(cx, args.get(0)) == JSTYPE_FUNCTION) { JS::RootedObject jstarget(cx, args.thisv().toObjectOrNull()); std::shared_ptr func(new JSFunctionWrapper(cx, jstarget, args.get(0), args.thisv())); - auto lambda = [=](b2Contact* larg0, const b2ContactImpulse* larg1) -> void { + auto lambda = [=](b2Contact* larg0, const creator::PhysicsContactImpulse* larg1) -> void { JSB_AUTOCOMPARTMENT_WITH_GLOBAL_OBJCET jsval largv[2]; if (larg0) { @@ -216,11 +212,11 @@ bool js_creator_PhysicsContactListener_setPostSolve(JSContext *cx, uint32_t argc } else { largv[0] = JSVAL_NULL; }; -// if (larg1) { -// largv[1] = b2ContactImpulse_to_jsval(cx, (b2ContactImpulse*)larg1); -// } else { + if (larg1) { + largv[1] = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, (creator::PhysicsContactImpulse*)larg1)); + } else { largv[1] = JSVAL_NULL; -// }; + }; JS::RootedValue rval(cx); bool succeed = func->invoke(JS::HandleValueArray::fromMarkedLocation(2, largv), &rval); if (!succeed && JS_IsExceptionPending(cx)) { diff --git a/native/tools/tojs/creator.ini b/native/tools/tojs/creator.ini index d3222ec972..2dc905c4bc 100755 --- a/native/tools/tojs/creator.ini +++ b/native/tools/tojs/creator.ini @@ -26,7 +26,7 @@ cxxgenerator_headers = extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s # what headers to parse -headers = %(creatordir)s/CCScale9Sprite.h %(creatordir)s/CCGraphicsNode.h %(creatordir)s/physics/CCPhysicsDebugDraw.h %(creatordir)s/physics/CCPhysicsUtils.h %(creatordir)s/physics/CCPhysicsContactListener.h %(creatordir)s/physics/CCPhysicsAABBQueryCallback.h %(creatordir)s/physics/CCPhysicsRayCastCallback.h %(creatordir)s/physics/CCPhysicsWorldManifoldWrapper.h %(creatordir)s/CCCameraNode.h +headers = %(creatordir)s/CCScale9Sprite.h %(creatordir)s/CCGraphicsNode.h %(creatordir)s/physics/CCPhysicsDebugDraw.h %(creatordir)s/physics/CCPhysicsUtils.h %(creatordir)s/physics/CCPhysicsContactListener.h %(creatordir)s/physics/CCPhysicsAABBQueryCallback.h %(creatordir)s/physics/CCPhysicsRayCastCallback.h %(creatordir)s/physics/CCPhysicsWorldManifoldWrapper.h %(creatordir)s/physics/CCPhysicsContactImpulse.h %(creatordir)s/CCCameraNode.h cpp_headers = scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.h @@ -34,7 +34,7 @@ replace_headers = CCScale9Sprite.h::creator/CCScale9Sprite.h,CCGraphicsNode.h::c # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = Scale9SpriteV2 GraphicsNode PhysicsDebugDraw PhysicsUtils PhysicsContactListener PhysicsAABBQueryCallback PhysicsRayCastCallback PhysicsWorldManifoldWrapper CameraNode +classes = Scale9SpriteV2 GraphicsNode PhysicsDebugDraw PhysicsUtils PhysicsContactListener PhysicsAABBQueryCallback PhysicsRayCastCallback PhysicsWorldManifoldWrapper PhysicsContactImpulse CameraNode classes_need_extend = Scale9SpriteV2 GraphicsNode @@ -50,6 +50,7 @@ skip = PhysicsDebugDraw::[DrawPolygon DrawSolidPolygon DrawCircle DrawSolidCircl PhysicsAABBQueryCallback::[ReportFixture getFixtures], PhysicsRayCastCallback::[ReportFixture getFixtures getNormals getPoints], PhysicsWorldManifoldWrapper::[init getb2WorldManifold], + PhysicsContactImpulse::[init], CameraNode::[(.*)Visit] rename_functions = From 8cb30741bf823ceecd105dfd580852063a68bc22 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Sat, 1 Apr 2017 15:27:34 +0800 Subject: [PATCH 3/7] optimize contact listener --- .../physics/CCPhysicsContactListener.cpp | 21 ++++++------------- .../physics/CCPhysicsContactListener.h | 3 +++ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp index 1bd6e5f03a..16d304be9c 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp +++ b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.cpp @@ -43,6 +43,7 @@ void PhysicsContactListener::BeginContact(b2Contact* contact) if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) { + _contactMap[contact] = true; _beginContact(contact); } @@ -52,13 +53,11 @@ void PhysicsContactListener::EndContact(b2Contact* contact) { if (!_endContact) return; - b2Fixture* fixtureA = contact->GetFixtureA(); - b2Fixture* fixtureB = contact->GetFixtureB(); - - if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || - find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) + auto i = _contactMap.find(contact); + if (i != _contactMap.end()) { _endContact(contact); + _contactMap.erase(i); } } @@ -66,11 +65,7 @@ void PhysicsContactListener::PreSolve(b2Contact* contact, const b2Manifold* oldM { if (!_preSolve) return; - b2Fixture* fixtureA = contact->GetFixtureA(); - b2Fixture* fixtureB = contact->GetFixtureB(); - - if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || - find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) + if (_contactMap.find(contact) != _contactMap.end()) { _preSolve(contact); } @@ -80,11 +75,7 @@ void PhysicsContactListener::PostSolve(b2Contact* contact, const b2ContactImpuls { if (!_postSolve) return; - b2Fixture* fixtureA = contact->GetFixtureA(); - b2Fixture* fixtureB = contact->GetFixtureB(); - - if (find(_contactFixtures.begin(), _contactFixtures.end(), fixtureA) != _contactFixtures.end() || - find(_contactFixtures.begin(), _contactFixtures.end(), fixtureB) != _contactFixtures.end()) + if (_contactMap.find(contact) != _contactMap.end()) { _impulse.init(impulse); _postSolve(contact, &_impulse); diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h index 38dd11975d..b3434cac50 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsContactListener.h @@ -32,6 +32,7 @@ #include #include + namespace creator { class CC_DLL PhysicsContactListener : public b2ContactListener @@ -62,6 +63,8 @@ protected: std::vector _contactFixtures; PhysicsContactImpulse _impulse; + + std::unordered_map _contactMap; }; } From c245c0862487c7c4590874bfbc012df7357f0482 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Sat, 1 Apr 2017 15:28:07 +0800 Subject: [PATCH 4/7] add b2AABB_to_jsval --- .../js-bindings/auto/jsb_box2d_auto.cpp | 2 +- .../manual/box2d/js_bindings_box2d_manual.cpp | 28 ++++++++++++++++++- .../manual/box2d/js_bindings_box2d_manual.h | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/native/cocos/scripting/js-bindings/auto/jsb_box2d_auto.cpp b/native/cocos/scripting/js-bindings/auto/jsb_box2d_auto.cpp index c686d48e6f..c39e99d3f7 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_box2d_auto.cpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_box2d_auto.cpp @@ -3310,7 +3310,7 @@ bool js_box2dclasses_b2Fixture_GetAABB(JSContext *cx, uint32_t argc, jsval *vp) JSB_PRECONDITION2(ok, cx, false, "js_box2dclasses_b2Fixture_GetAABB : Error processing arguments"); const b2AABB& ret = cobj->GetAABB(arg0); JS::RootedValue jsret(cx); - #pragma warning NO CONVERSION FROM NATIVE FOR b2AABB; + jsret = b2AABB_to_jsval(cx, ret); args.rval().set(jsret); return true; } diff --git a/native/cocos/scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.cpp b/native/cocos/scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.cpp index 12ca77aa78..3f814f4c48 100644 --- a/native/cocos/scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.cpp +++ b/native/cocos/scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.cpp @@ -814,6 +814,33 @@ jsval array_of_b2Vec2_to_jsval(JSContext* cx, const std::vector& vs) return OBJECT_TO_JSVAL(jsret); } +jsval b2AABB_to_jsval(JSContext* cx, const b2AABB& v) +{ + JS::RootedObject object(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); + if (!object) { + return JSVAL_VOID; + } + + JS::RootedObject lowerBound(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); + if (!JS_DefineProperty(cx, lowerBound, "x", v.lowerBound.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) || + !JS_DefineProperty(cx, lowerBound, "y", v.lowerBound.y, JSPROP_ENUMERATE | JSPROP_PERMANENT) ) { + return JSVAL_VOID; + } + + JS::RootedObject upperBound(cx, JS_NewObject(cx, NULL, JS::NullPtr(), JS::NullPtr())); + if (!JS_DefineProperty(cx, upperBound, "x", v.upperBound.x, JSPROP_ENUMERATE | JSPROP_PERMANENT) || + !JS_DefineProperty(cx, upperBound, "y", v.upperBound.y, JSPROP_ENUMERATE | JSPROP_PERMANENT) ) { + return JSVAL_VOID; + } + + if (!JS_DefineProperty(cx, object, "lowerBound", lowerBound, JSPROP_ENUMERATE | JSPROP_PERMANENT) || + !JS_DefineProperty(cx, object, "upperBound", upperBound, JSPROP_ENUMERATE | JSPROP_PERMANENT) ) { + return JSVAL_VOID; + } + + return OBJECT_TO_JSVAL(object); +} + extern JSClass *jsb_b2Shape_class; extern JSObject *jsb_b2Shape_prototype; @@ -1256,7 +1283,6 @@ bool js_box2dclasses_b2ChainShape_CreateLoop(JSContext *cx, uint32_t argc, jsval return false; } - void register_all_box2dclasses_manual(JSContext* cx, JS::HandleObject obj) { JS::RootedObject tmpObj(cx); diff --git a/native/cocos/scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.h b/native/cocos/scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.h index 7bb1c8eb62..5e406a23e0 100644 --- a/native/cocos/scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.h +++ b/native/cocos/scripting/js-bindings/manual/box2d/js_bindings_box2d_manual.h @@ -47,6 +47,7 @@ jsval b2Manifold_to_jsval(JSContext* cx, const b2Manifold* v); jsval b2ContactImpulse_to_jsval(JSContext* cx, const b2ContactImpulse* v); jsval array_of_b2Fixture_to_jsval(JSContext* cx, const std::vector& fixtures); jsval array_of_b2Vec2_to_jsval(JSContext* cx, const std::vector& vs); +jsval b2AABB_to_jsval(JSContext* cx, const b2AABB& v); void register_all_box2dclasses_manual(JSContext* cx, JS::HandleObject obj); From cff21d0aa1202e105d696d0f0b3c7d07a18aa1a5 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Sat, 1 Apr 2017 16:32:29 +0800 Subject: [PATCH 5/7] revert changes --- .../creator/physics/CCPhysicsUtils.cpp | 6 --- .../creator/physics/CCPhysicsUtils.h | 4 +- .../auto/api/jsb_creator_auto_api.js | 12 ------ .../js-bindings/auto/jsb_creator_auto.cpp | 39 ------------------- .../js-bindings/auto/jsb_creator_auto.hpp | 1 - native/tools/tojs/genbindings.py | 25 ++++++------ 6 files changed, 13 insertions(+), 74 deletions(-) diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp index ad62b2b41c..146a9e57a0 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp +++ b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.cpp @@ -63,12 +63,6 @@ void PhysicsUtils::syncNode() } } -void PhysicsUtils::setFixtureNext(b2Fixture* fixture, b2Fixture* next) -{ - b2Fixture* f = fixture->GetNext(); - *&f = next; -} - const PhysicsWorldManifoldWrapper* PhysicsUtils::getContactWorldManifoldWrapper(b2Contact* contact) { _worldManifoldWrapper.init(contact); diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsUtils.h b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.h index e8935ca568..aa9625acf7 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsUtils.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsUtils.h @@ -43,13 +43,11 @@ public: PhysicsUtils(); ~PhysicsUtils(); +public: void addB2Body(b2Body* body); void removeB2Body(b2Body* body); void syncNode(); - - void setFixtureNext(b2Fixture* fixture, b2Fixture* next); - public: static const PhysicsWorldManifoldWrapper* getContactWorldManifoldWrapper(b2Contact* contact); static const PhysicsManifoldWrapper* getContactManifoldWrapper(b2Contact* contact); diff --git a/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js b/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js index 03ef27f27f..50b66c98f3 100644 --- a/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js +++ b/native/cocos/scripting/js-bindings/auto/api/jsb_creator_auto_api.js @@ -890,18 +890,6 @@ syncNode : function ( { }, -/** - * @method setFixtureNext - * @param {b2Fixture} arg0 - * @param {b2Fixture} arg1 - */ -setFixtureNext : function ( -b2fixture, -b2fixture -) -{ -}, - /** * @method removeB2Body * @param {b2Body} arg0 diff --git a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp index 27eddb0dc7..406c643d06 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp @@ -2089,44 +2089,6 @@ bool js_creator_PhysicsUtils_syncNode(JSContext *cx, uint32_t argc, jsval *vp) JS_ReportError(cx, "js_creator_PhysicsUtils_syncNode : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } -bool js_creator_PhysicsUtils_setFixtureNext(JSContext *cx, uint32_t argc, jsval *vp) -{ - JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - bool ok = true; - JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); - js_proxy_t *proxy = jsb_get_js_proxy(obj); - creator::PhysicsUtils* cobj = (creator::PhysicsUtils *)(proxy ? proxy->ptr : NULL); - JSB_PRECONDITION2( cobj, cx, false, "js_creator_PhysicsUtils_setFixtureNext : Invalid Native Object"); - if (argc == 2) { - b2Fixture* arg0 = nullptr; - b2Fixture* arg1 = nullptr; - do { - if (args.get(0).isNull()) { arg0 = nullptr; break; } - if (!args.get(0).isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JS::RootedObject tmpObj(cx, args.get(0).toObjectOrNull()); - jsProxy = jsb_get_js_proxy(tmpObj); - arg0 = (b2Fixture*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object"); - } while (0); - do { - if (args.get(1).isNull()) { arg1 = nullptr; break; } - if (!args.get(1).isObject()) { ok = false; break; } - js_proxy_t *jsProxy; - JS::RootedObject tmpObj(cx, args.get(1).toObjectOrNull()); - jsProxy = jsb_get_js_proxy(tmpObj); - arg1 = (b2Fixture*)(jsProxy ? jsProxy->ptr : NULL); - JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object"); - } while (0); - JSB_PRECONDITION2(ok, cx, false, "js_creator_PhysicsUtils_setFixtureNext : Error processing arguments"); - cobj->setFixtureNext(arg0, arg1); - args.rval().setUndefined(); - return true; - } - - JS_ReportError(cx, "js_creator_PhysicsUtils_setFixtureNext : wrong number of arguments: %d, was expecting %d", argc, 2); - return false; -} bool js_creator_PhysicsUtils_removeB2Body(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -2277,7 +2239,6 @@ void js_register_creator_PhysicsUtils(JSContext *cx, JS::HandleObject global) { static JSFunctionSpec funcs[] = { JS_FN("addB2Body", js_creator_PhysicsUtils_addB2Body, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("syncNode", js_creator_PhysicsUtils_syncNode, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), - JS_FN("setFixtureNext", js_creator_PhysicsUtils_setFixtureNext, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("removeB2Body", js_creator_PhysicsUtils_removeB2Body, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END }; diff --git a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp index a6d41cd869..77b561da73 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.hpp @@ -122,7 +122,6 @@ void js_register_creator_PhysicsUtils(JSContext *cx, JS::HandleObject global); void register_all_creator(JSContext* cx, JS::HandleObject obj); bool js_creator_PhysicsUtils_addB2Body(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_syncNode(JSContext *cx, uint32_t argc, jsval *vp); -bool js_creator_PhysicsUtils_setFixtureNext(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_removeB2Body(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_getContactManifoldWrapper(JSContext *cx, uint32_t argc, jsval *vp); bool js_creator_PhysicsUtils_getContactWorldManifoldWrapper(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/native/tools/tojs/genbindings.py b/native/tools/tojs/genbindings.py index f910b47de3..c608fd0b8e 100755 --- a/native/tools/tojs/genbindings.py +++ b/native/tools/tojs/genbindings.py @@ -150,20 +150,19 @@ def main(): tojs_root = '%s/tools/tojs' % project_root output_dir = '%s/cocos/scripting/js-bindings/auto' % project_root - cmd_args = { - # 'cocos2dx.ini' : ('cocos2d-x', 'jsb_cocos2dx_auto'), \ - # 'cocos2dx_audioengine.ini' : ('cocos2dx_audioengine', 'jsb_cocos2dx_audioengine_auto'), \ - # 'cocos2dx_network.ini' : ('cocos2dx_network', 'jsb_cocos2dx_network_auto'), \ - # 'cocos2dx_extension.ini' : ('cocos2dx_extension', 'jsb_cocos2dx_extension_auto'), \ - # 'cocos2dx_builder.ini' : ('cocos2dx_builder', 'jsb_cocos2dx_builder_auto'), \ - # 'cocos2dx_ui.ini' : ('cocos2dx_ui', 'jsb_cocos2dx_ui_auto'), \ - # 'cocos2dx_studio.ini' : ('cocos2dx_studio', 'jsb_cocos2dx_studio_auto'), \ - # 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'jsb_cocos2dx_spine_auto'), \ - # 'cocos2dx_dragonbones.ini' : ('cocos2dx_dragonbones', 'jsb_cocos2dx_dragonbones_auto'), \ - # 'cocos2dx_experimental_webView.ini' : ('cocos2dx_experimental_webView', 'jsb_cocos2dx_experimental_webView_auto'), \ - # 'cocos2dx_experimental_video.ini' : ('cocos2dx_experimental_video', 'jsb_cocos2dx_experimental_video_auto'), \ + cmd_args = {'cocos2dx.ini' : ('cocos2d-x', 'jsb_cocos2dx_auto'), \ + 'cocos2dx_audioengine.ini' : ('cocos2dx_audioengine', 'jsb_cocos2dx_audioengine_auto'), \ + 'cocos2dx_network.ini' : ('cocos2dx_network', 'jsb_cocos2dx_network_auto'), \ + 'cocos2dx_extension.ini' : ('cocos2dx_extension', 'jsb_cocos2dx_extension_auto'), \ + 'cocos2dx_builder.ini' : ('cocos2dx_builder', 'jsb_cocos2dx_builder_auto'), \ + 'cocos2dx_ui.ini' : ('cocos2dx_ui', 'jsb_cocos2dx_ui_auto'), \ + 'cocos2dx_studio.ini' : ('cocos2dx_studio', 'jsb_cocos2dx_studio_auto'), \ + 'cocos2dx_spine.ini' : ('cocos2dx_spine', 'jsb_cocos2dx_spine_auto'), \ + 'cocos2dx_dragonbones.ini' : ('cocos2dx_dragonbones', 'jsb_cocos2dx_dragonbones_auto'), \ + 'cocos2dx_experimental_webView.ini' : ('cocos2dx_experimental_webView', 'jsb_cocos2dx_experimental_webView_auto'), \ + 'cocos2dx_experimental_video.ini' : ('cocos2dx_experimental_video', 'jsb_cocos2dx_experimental_video_auto'), \ 'creator.ini': ('creator', 'jsb_creator_auto'), - # 'box2d.ini' : ('box2d', 'jsb_box2d_auto'), + 'box2d.ini' : ('box2d', 'jsb_box2d_auto'), } target = 'spidermonkey' generator_py = '%s/generator.py' % cxx_generator_root From bc1e86300d0b8f44cd4e15043fbe9a5d0a7bbff5 Mon Sep 17 00:00:00 2001 From: 2youyou2 <501251991@qq.com> Date: Sat, 1 Apr 2017 17:26:06 +0800 Subject: [PATCH 6/7] update windows physics project --- native/cocos/2d/libcocos2d.vcxproj | 27 +++--- native/cocos/2d/libcocos2d.vcxproj.filters | 84 ++++++++++++------- .../creator/physics/CCPhysicsContactImpulse.h | 2 +- .../physics/CCPhysicsManifoldWrapper.h | 2 +- .../physics/CCPhysicsWorldManifoldWrapper.h | 2 +- 5 files changed, 74 insertions(+), 43 deletions(-) diff --git a/native/cocos/2d/libcocos2d.vcxproj b/native/cocos/2d/libcocos2d.vcxproj index bef19ae147..6b503a4e3b 100644 --- a/native/cocos/2d/libcocos2d.vcxproj +++ b/native/cocos/2d/libcocos2d.vcxproj @@ -303,12 +303,15 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32\libs\*.*" "$(OutDir)" - - - - - + + + + + + + + @@ -653,12 +656,16 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\win32\libs\*.*" "$(OutDir)" - - - - - + + + + + + + + + diff --git a/native/cocos/2d/libcocos2d.vcxproj.filters b/native/cocos/2d/libcocos2d.vcxproj.filters index 98a7da9423..3d3b73c408 100644 --- a/native/cocos/2d/libcocos2d.vcxproj.filters +++ b/native/cocos/2d/libcocos2d.vcxproj.filters @@ -172,6 +172,9 @@ {c1b7ac70-432f-4d5b-bd3b-5ff5fce3436b} + + {7ea5175c-acae-4b2f-ae6e-50daf6131b12} + @@ -1091,21 +1094,6 @@ creator - - creator - - - creator - - - creator - - - creator - - - creator - @@ -1113,6 +1101,30 @@ creator + + creator\physics + + + creator\physics + + + creator\physics + + + creator\physics + + + creator\physics + + + creator\physics + + + creator\physics + + + creator\physics + @@ -2107,21 +2119,6 @@ creator - - creator - - - creator - - - creator - - - creator - - - creator - @@ -2148,6 +2145,33 @@ creator + + creator\physics + + + creator\physics + + + creator\physics + + + creator\physics + + + creator\physics + + + creator\physics + + + creator\physics + + + creator\physics + + + creator\physics + diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.h b/native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.h index b9a1f435ca..a099b37c57 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsContactImpulse.h @@ -29,7 +29,7 @@ #include "cocos2d.h" namespace creator { - class PhysicsContactImpulse : public cocos2d::Ref + class CC_DLL PhysicsContactImpulse : public cocos2d::Ref { public: PhysicsContactImpulse(); diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h b/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h index ebacd1f40f..a34ea8c707 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsManifoldWrapper.h @@ -29,7 +29,7 @@ #include "cocos2d.h" namespace creator { - class PhysicsManifoldWrapper : public cocos2d::Ref + class CC_DLL PhysicsManifoldWrapper : public cocos2d::Ref { public: PhysicsManifoldWrapper(); diff --git a/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h b/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h index b5ddbd9746..d8d307e45c 100644 --- a/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h +++ b/native/cocos/editor-support/creator/physics/CCPhysicsWorldManifoldWrapper.h @@ -29,7 +29,7 @@ #include "cocos2d.h" namespace creator { - class PhysicsWorldManifoldWrapper : public cocos2d::Ref + class CC_DLL PhysicsWorldManifoldWrapper : public cocos2d::Ref { public: PhysicsWorldManifoldWrapper(); From 25a0b03c7961026bd2b11f6b58e44ac8eb3d6225 Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Sat, 1 Apr 2017 17:40:40 +0800 Subject: [PATCH 7/7] update bindings-generator --- native/tools/bindings-generator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/tools/bindings-generator b/native/tools/bindings-generator index 30c6b8237e..b32f0335fa 160000 --- a/native/tools/bindings-generator +++ b/native/tools/bindings-generator @@ -1 +1 @@ -Subproject commit 30c6b8237ef54675fb484ce0480115ab60930dec +Subproject commit b32f0335fae287aaa6b6dc1fcb9e57a550c91d6e