Merge branch 'v3' of github.com:cocos2d/cocos2d-x into add_package_manager_support

This commit is contained in:
dualface 2015-01-07 17:39:30 +08:00
commit 8066343c69
58 changed files with 1013 additions and 1826 deletions

View File

@ -1061,6 +1061,9 @@ Developers:
shrimpz
Fix two typos in luaval_to_quaternion
Fix label crashed on android
ton1517
Fix the issue that JumpTo can not be applied more than once
Retired Core Developers:
WenSheng Yang

View File

@ -1,6 +1,12 @@
cocos2d-x-3.4rc0 Jan.9 2015
[NEW] 3rd: update libcurl to v7.39
[FIX] FileUtils: getData() can't get data from file when file was using by other application on windows
[FIX] FileUtils: getData() will cause memory leak if file size is 0 on windows
[FIX] GLProgram: when there is a shader compile error in shader, it will crash on windows
[FIX] JumpTo: can not be applied more than once
[FIX] Physics integration: physics body is not still after disabling gravitational force by PhysicsBody::setGravityEnable()
[FIX] Sprite3DTest: Sprite3DUVAnimationTest, Sprite3DFakeShadowTest, Sprite3DLightMapTest, Sprite3DBasicToonShaderTest will crash on android when switch to foreground from background
[FIX] HttpClient: http requests will be lost in immediately mode on iOS
[FIX] WP8: compiling error on ARM architecture
@ -11,6 +17,7 @@ cocos2d-x-3.4beta0 Dec.31 2014
[NEW] Application: added Turkish and Ukrainian language support
[NEW] UI:LoadingBar: add TextureResType to LoadingBar's create method
[NEW] Director: add setClearColor() to set clear values for the color buffers
[NEW] Node: rotation representation using quaternion
[NEW] UI: Added new layout functionality for Cocos Studio, keeps widget margins a fixed set and adjusts the widget size according to the margins.
[NEW] UI: Add gray shader to ui::Button, ui::CheckBox and ui::Slider when the disable state resources are not provided
[NEW] UI: Modify the default behavior when ui::Button, ui::CheckBox and ui::Slider's selected state resources are not provided, the new behavior is scale the normal state texture when the selected state texture are missing.

View File

@ -1928,28 +1928,6 @@
B29A7E3F19EE1B7700872B35 /* AnimationState.h in Headers */ = {isa = PBXBuildFile; fileRef = B29A7DC619EE1B7700872B35 /* AnimationState.h */; };
B29A7E4019EE1B7700872B35 /* AnimationState.h in Headers */ = {isa = PBXBuildFile; fileRef = B29A7DC619EE1B7700872B35 /* AnimationState.h */; };
B2CC507C19776DD10041958E /* CCPhysicsJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46A170721807CE7A005B8026 /* CCPhysicsJoint.cpp */; };
B37510711823AC9F00B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B37510451823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp */; };
B37510721823AC9F00B3BA6A /* CCPhysicsBodyInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B37510461823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.h */; };
B37510731823AC9F00B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B37510471823AC7B00B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp */; };
B37510741823AC9F00B3BA6A /* CCPhysicsContactInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B37510481823AC7B00B3BA6A /* CCPhysicsContactInfo_chipmunk.h */; };
B37510751823AC9F00B3BA6A /* CCPhysicsHelper_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B37510491823AC7B00B3BA6A /* CCPhysicsHelper_chipmunk.h */; };
B37510761823AC9F00B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B375104A1823AC7B00B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp */; };
B37510771823AC9F00B3BA6A /* CCPhysicsJointInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104B1823AC7B00B3BA6A /* CCPhysicsJointInfo_chipmunk.h */; };
B37510781823AC9F00B3BA6A /* CCPhysicsShapeInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B375104C1823AC7B00B3BA6A /* CCPhysicsShapeInfo_chipmunk.cpp */; };
B37510791823AC9F00B3BA6A /* CCPhysicsShapeInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104D1823AC7B00B3BA6A /* CCPhysicsShapeInfo_chipmunk.h */; };
B375107A1823AC9F00B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B375104E1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp */; };
B375107B1823AC9F00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104F1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h */; };
B375107C1823ACA100B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B37510451823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp */; };
B375107D1823ACA100B3BA6A /* CCPhysicsBodyInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B37510461823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.h */; };
B375107E1823ACA100B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B37510471823AC7B00B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp */; };
B375107F1823ACA100B3BA6A /* CCPhysicsContactInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B37510481823AC7B00B3BA6A /* CCPhysicsContactInfo_chipmunk.h */; };
B37510801823ACA100B3BA6A /* CCPhysicsHelper_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B37510491823AC7B00B3BA6A /* CCPhysicsHelper_chipmunk.h */; };
B37510811823ACA100B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B375104A1823AC7B00B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp */; };
B37510821823ACA100B3BA6A /* CCPhysicsJointInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104B1823AC7B00B3BA6A /* CCPhysicsJointInfo_chipmunk.h */; };
B37510831823ACA100B3BA6A /* CCPhysicsShapeInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B375104C1823AC7B00B3BA6A /* CCPhysicsShapeInfo_chipmunk.cpp */; };
B37510841823ACA100B3BA6A /* CCPhysicsShapeInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104D1823AC7B00B3BA6A /* CCPhysicsShapeInfo_chipmunk.h */; };
B37510851823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B375104E1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp */; };
B37510861823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B375104F1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h */; };
B60C5BD419AC68B10056FBDE /* CCBillBoard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B60C5BD219AC68B10056FBDE /* CCBillBoard.cpp */; };
B60C5BD519AC68B10056FBDE /* CCBillBoard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B60C5BD219AC68B10056FBDE /* CCBillBoard.cpp */; };
B60C5BD619AC68B10056FBDE /* CCBillBoard.h in Headers */ = {isa = PBXBuildFile; fileRef = B60C5BD319AC68B10056FBDE /* CCBillBoard.h */; };
@ -1990,6 +1968,8 @@
DABC9FAA19E7DFA900FA252C /* CCClippingRectangleNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DABC9FA719E7DFA900FA252C /* CCClippingRectangleNode.cpp */; };
DABC9FAB19E7DFA900FA252C /* CCClippingRectangleNode.h in Headers */ = {isa = PBXBuildFile; fileRef = DABC9FA819E7DFA900FA252C /* CCClippingRectangleNode.h */; };
DABC9FAC19E7DFA900FA252C /* CCClippingRectangleNode.h in Headers */ = {isa = PBXBuildFile; fileRef = DABC9FA819E7DFA900FA252C /* CCClippingRectangleNode.h */; };
ED74D7691A5B8A2600157FD4 /* CCPhysicsHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = ED74D7681A5B8A2600157FD4 /* CCPhysicsHelper.h */; };
ED74D76A1A5B8A2600157FD4 /* CCPhysicsHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = ED74D7681A5B8A2600157FD4 /* CCPhysicsHelper.h */; };
ED9C6A9418599AD8000A5232 /* CCNodeGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */; };
ED9C6A9518599AD8000A5232 /* CCNodeGrid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */; };
ED9C6A9618599AD8000A5232 /* CCNodeGrid.h in Headers */ = {isa = PBXBuildFile; fileRef = ED9C6A9318599AD8000A5232 /* CCNodeGrid.h */; };
@ -3043,17 +3023,6 @@
B29A7DC419EE1B7700872B35 /* Animation.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = Animation.c; sourceTree = "<group>"; };
B29A7DC519EE1B7700872B35 /* AnimationState.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = AnimationState.c; sourceTree = "<group>"; };
B29A7DC619EE1B7700872B35 /* AnimationState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnimationState.h; sourceTree = "<group>"; };
B37510451823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsBodyInfo_chipmunk.cpp; sourceTree = "<group>"; };
B37510461823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsBodyInfo_chipmunk.h; sourceTree = "<group>"; };
B37510471823AC7B00B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsContactInfo_chipmunk.cpp; sourceTree = "<group>"; };
B37510481823AC7B00B3BA6A /* CCPhysicsContactInfo_chipmunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsContactInfo_chipmunk.h; sourceTree = "<group>"; };
B37510491823AC7B00B3BA6A /* CCPhysicsHelper_chipmunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsHelper_chipmunk.h; sourceTree = "<group>"; };
B375104A1823AC7B00B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsJointInfo_chipmunk.cpp; sourceTree = "<group>"; };
B375104B1823AC7B00B3BA6A /* CCPhysicsJointInfo_chipmunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsJointInfo_chipmunk.h; sourceTree = "<group>"; };
B375104C1823AC7B00B3BA6A /* CCPhysicsShapeInfo_chipmunk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsShapeInfo_chipmunk.cpp; sourceTree = "<group>"; };
B375104D1823AC7B00B3BA6A /* CCPhysicsShapeInfo_chipmunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsShapeInfo_chipmunk.h; sourceTree = "<group>"; };
B375104E1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsWorldInfo_chipmunk.cpp; sourceTree = "<group>"; };
B375104F1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsWorldInfo_chipmunk.h; sourceTree = "<group>"; };
B3AF019E1842FBA400A98B85 /* b2MotorJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2MotorJoint.cpp; sourceTree = "<group>"; };
B3AF019F1842FBA400A98B85 /* b2MotorJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MotorJoint.h; sourceTree = "<group>"; };
B60C5BD219AC68B10056FBDE /* CCBillBoard.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCBillBoard.cpp; sourceTree = "<group>"; };
@ -3079,6 +3048,7 @@
DA8C62A119E52C6400000516 /* ioapi_mem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ioapi_mem.h; sourceTree = "<group>"; };
DABC9FA719E7DFA900FA252C /* CCClippingRectangleNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCClippingRectangleNode.cpp; sourceTree = "<group>"; };
DABC9FA819E7DFA900FA252C /* CCClippingRectangleNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCClippingRectangleNode.h; sourceTree = "<group>"; };
ED74D7681A5B8A2600157FD4 /* CCPhysicsHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsHelper.h; sourceTree = "<group>"; };
ED9C6A9218599AD8000A5232 /* CCNodeGrid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = CCNodeGrid.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
ED9C6A9318599AD8000A5232 /* CCNodeGrid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCNodeGrid.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -4787,7 +4757,7 @@
46A170611807CE7A005B8026 /* physics */ = {
isa = PBXGroup;
children = (
46A170791807CE7A005B8026 /* chipmunk */,
ED74D7681A5B8A2600157FD4 /* CCPhysicsHelper.h */,
46A1706E1807CE7A005B8026 /* CCPhysicsBody.cpp */,
46A1706F1807CE7A005B8026 /* CCPhysicsBody.h */,
46A170701807CE7A005B8026 /* CCPhysicsContact.cpp */,
@ -4803,24 +4773,6 @@
path = ../cocos/physics;
sourceTree = "<group>";
};
46A170791807CE7A005B8026 /* chipmunk */ = {
isa = PBXGroup;
children = (
B37510451823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp */,
B37510461823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.h */,
B37510471823AC7B00B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp */,
B37510481823AC7B00B3BA6A /* CCPhysicsContactInfo_chipmunk.h */,
B37510491823AC7B00B3BA6A /* CCPhysicsHelper_chipmunk.h */,
B375104A1823AC7B00B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp */,
B375104B1823AC7B00B3BA6A /* CCPhysicsJointInfo_chipmunk.h */,
B375104C1823AC7B00B3BA6A /* CCPhysicsShapeInfo_chipmunk.cpp */,
B375104D1823AC7B00B3BA6A /* CCPhysicsShapeInfo_chipmunk.h */,
B375104E1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp */,
B375104F1823AC7B00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h */,
);
path = chipmunk;
sourceTree = "<group>";
};
46A170851807CE87005B8026 /* math */ = {
isa = PBXGroup;
children = (
@ -5329,7 +5281,6 @@
15AE18F719AAD35000C27E9E /* CCBatchNode.h in Headers */,
15AE181419AAD2F700C27E9E /* CCAnimationCurve.h in Headers */,
50ABBE631925AB6F00A911A9 /* CCEventListenerAcceleration.h in Headers */,
B37510771823AC9F00B3BA6A /* CCPhysicsJointInfo_chipmunk.h in Headers */,
15AE1C1419AAE2C600C27E9E /* CCPhysicsSprite.h in Headers */,
46A170EE1807CECA005B8026 /* CCPhysicsShape.h in Headers */,
15AE1A5C19AAD40300C27E9E /* b2Timer.h in Headers */,
@ -5342,7 +5293,6 @@
15AE1A6D19AAD40300C27E9E /* b2ChainAndPolygonContact.h in Headers */,
3E2F27A719CFBFE400E7C490 /* AudioEngine.h in Headers */,
15AE183A19AAD2F700C27E9E /* CCRay.h in Headers */,
B375107B1823AC9F00B3BA6A /* CCPhysicsWorldInfo_chipmunk.h in Headers */,
15AE18A319AAD33D00C27E9E /* CCParticleSystemQuadLoader.h in Headers */,
46A170F01807CECA005B8026 /* CCPhysicsWorld.h in Headers */,
15AE199D19AAD39600C27E9E /* ScrollViewReader.h in Headers */,
@ -5416,7 +5366,6 @@
15AE1A6B19AAD40300C27E9E /* b2ChainAndCircleContact.h in Headers */,
1A570110180BC8EE0088DEC7 /* CCDrawingPrimitives.h in Headers */,
50CB247D19D9C5A100687767 /* AudioPlayer.h in Headers */,
B37510791823AC9F00B3BA6A /* CCPhysicsShapeInfo_chipmunk.h in Headers */,
1A570114180BC8EE0088DEC7 /* CCDrawNode.h in Headers */,
15AE1A6019AAD40300C27E9E /* b2ContactManager.h in Headers */,
15B3707A19EE414C00ABE682 /* AssetsManagerEx.h in Headers */,
@ -5501,6 +5450,7 @@
50ABBD401925AB0000A911A9 /* CCMath.h in Headers */,
B29A7E1F19EE1B7700872B35 /* BoneData.h in Headers */,
15AE1A9319AAD40300C27E9E /* b2WheelJoint.h in Headers */,
ED74D7691A5B8A2600157FD4 /* CCPhysicsHelper.h in Headers */,
15AE1A3119AAD3D500C27E9E /* b2ChainShape.h in Headers */,
1A5701FD180BCBAD0088DEC7 /* CCMenuItem.h in Headers */,
1A570204180BCBD40088DEC7 /* CCClippingNode.h in Headers */,
@ -5641,7 +5591,6 @@
50ABC0651926664800A911A9 /* CCGL-mac.h in Headers */,
50643BD419BFAECF00EF68ED /* CCGL.h in Headers */,
15AE190C19AAD35000C27E9E /* CCDisplayFactory.h in Headers */,
B37510751823AC9F00B3BA6A /* CCPhysicsHelper_chipmunk.h in Headers */,
15AE1A8B19AAD40300C27E9E /* b2PulleyJoint.h in Headers */,
15AE1A5119AAD40300C27E9E /* b2BlockAllocator.h in Headers */,
15AE199119AAD37200C27E9E /* ImageViewReader.h in Headers */,
@ -5672,7 +5621,6 @@
15AE186719AAD31D00C27E9E /* CDXMacOSXSupport.h in Headers */,
B29A7DCD19EE1B7700872B35 /* Slot.h in Headers */,
382384311A259112002C4610 /* ParticleReader.h in Headers */,
B37510741823AC9F00B3BA6A /* CCPhysicsContactInfo_chipmunk.h in Headers */,
5034CA35191D591100CE6051 /* ccShader_PositionTexture.frag in Headers */,
15AE1BB219AADFEF00C27E9E /* HttpClient.h in Headers */,
15AE197619AAD35700C27E9E /* CCTimelineMacro.h in Headers */,
@ -5761,7 +5709,6 @@
1A01C69018F57BE800EFE3A6 /* CCDictionary.h in Headers */,
1A9DCA29180E6955007A3AD4 /* CCGLBufferedNode.h in Headers */,
50ABC0031926664800A911A9 /* CCLock-apple.h in Headers */,
B37510721823AC9F00B3BA6A /* CCPhysicsBodyInfo_chipmunk.h in Headers */,
50ABBE2D1925AB6F00A911A9 /* ccCArray.h in Headers */,
50ABBD5E1925AB0000A911A9 /* Vec3.h in Headers */,
15AE188919AAD33D00C27E9E /* CCControlButtonLoader.h in Headers */,
@ -5860,6 +5807,7 @@
B29A7DFE19EE1B7700872B35 /* IkConstraintData.h in Headers */,
382384401A259140002C4610 /* SingleNodeReader.h in Headers */,
15AE1A4019AAD3D500C27E9E /* b2Collision.h in Headers */,
ED74D76A1A5B8A2600157FD4 /* CCPhysicsHelper.h in Headers */,
5034CA40191D591100CE6051 /* ccShader_Position_uColor.vert in Headers */,
15AE184719AAD2F700C27E9E /* CCSprite3DMaterial.h in Headers */,
15AE1BFC19AAE01E00C27E9E /* CCControlUtils.h in Headers */,
@ -5901,7 +5849,6 @@
1A570074180BC5A10088DEC7 /* CCActionGrid.h in Headers */,
15AE194A19AAD35100C27E9E /* CCComController.h in Headers */,
382384161A259092002C4610 /* NodeReaderProtocol.h in Headers */,
B37510841823ACA100B3BA6A /* CCPhysicsShapeInfo_chipmunk.h in Headers */,
5034CA46191D591100CE6051 /* ccShader_Label_outline.frag in Headers */,
1A570078180BC5A10088DEC7 /* CCActionGrid3D.h in Headers */,
50ABBD631925AB0000A911A9 /* Vec4.h in Headers */,
@ -5916,7 +5863,6 @@
15AE18CD19AAD33D00C27E9E /* CCNode+CCBRelativePositioning.h in Headers */,
382384121A259092002C4610 /* NodeReaderDefine.h in Headers */,
50ABBE781925AB6F00A911A9 /* CCEventListenerTouch.h in Headers */,
B37510861823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.h in Headers */,
15AE1BC019AADFF000C27E9E /* WebSocket.h in Headers */,
3823840A1A25900F002C4610 /* FlatBuffersSerialize.h in Headers */,
1A570080180BC5A10088DEC7 /* CCActionInterval.h in Headers */,
@ -6077,7 +6023,6 @@
15B3708B19EE414C00ABE682 /* Manifest.h in Headers */,
1A570213180BCBF40088DEC7 /* CCProgressTimer.h in Headers */,
38F526431A48363B000DB7F7 /* CSArmatureNode_generated.h in Headers */,
B37510821823ACA100B3BA6A /* CCPhysicsJointInfo_chipmunk.h in Headers */,
1A570217180BCBF40088DEC7 /* CCRenderTexture.h in Headers */,
15AE1ABB19AAD40300C27E9E /* b2EdgeAndPolygonContact.h in Headers */,
15AE198719AAD36400C27E9E /* WidgetReaderProtocol.h in Headers */,
@ -6166,7 +6111,6 @@
15AE18C419AAD33D00C27E9E /* CCLayerGradientLoader.h in Headers */,
1A570313180BCF190088DEC7 /* CCComponentContainer.h in Headers */,
1A087AEB1860400400196EF5 /* edtaa3func.h in Headers */,
B375107F1823ACA100B3BA6A /* CCPhysicsContactInfo_chipmunk.h in Headers */,
15AE185D19AAD31200C27E9E /* CocosDenshion.h in Headers */,
15AE194319AAD35100C27E9E /* CCColliderDetector.h in Headers */,
D0FD035C1A3B51AA00825BB5 /* CCAllocatorStrategyFixedBlock.h in Headers */,
@ -6322,12 +6266,10 @@
50ABC00A1926664800A911A9 /* CCCommon.h in Headers */,
15AE19AD19AAD39700C27E9E /* LoadingBarReader.h in Headers */,
50ABBE5C1925AB6F00A911A9 /* CCEventKeyboard.h in Headers */,
B375107D1823ACA100B3BA6A /* CCPhysicsBodyInfo_chipmunk.h in Headers */,
5E9F612D1A3FFE3D0038DE01 /* CCPlane.h in Headers */,
50ABC01C1926664800A911A9 /* CCSAXParser.h in Headers */,
503DD8F11926736A00CD74DD /* OpenGL_Internal-ios.h in Headers */,
38ACD1FF1A27111900C3093D /* WidgetCallBackHandlerProtocol.h in Headers */,
B37510801823ACA100B3BA6A /* CCPhysicsHelper_chipmunk.h in Headers */,
B29A7DF619EE1B7700872B35 /* Skeleton.h in Headers */,
50ABBDAA1925AB4100A911A9 /* CCRenderCommand.h in Headers */,
B29A7DF019EE1B7700872B35 /* SkeletonBounds.h in Headers */,
@ -6492,12 +6434,10 @@
15AE1A8219AAD40300C27E9E /* b2GearJoint.cpp in Sources */,
1A570071180BC5A10088DEC7 /* CCActionGrid.cpp in Sources */,
50CB247F19D9C5A100687767 /* AudioPlayer.mm in Sources */,
B37510761823AC9F00B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp in Sources */,
50ABBFFF1926664800A911A9 /* CCFileUtils-apple.mm in Sources */,
1A570075180BC5A10088DEC7 /* CCActionGrid3D.cpp in Sources */,
382383F81A258FA7002C4610 /* idl_gen_general.cpp in Sources */,
15AE1C1319AAE2C600C27E9E /* CCPhysicsSprite.cpp in Sources */,
B375107A1823AC9F00B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp in Sources */,
382384131A259092002C4610 /* NodeReaderProtocol.cpp in Sources */,
15AE1A5F19AAD40300C27E9E /* b2ContactManager.cpp in Sources */,
15AE1B9D19AADFDF00C27E9E /* UIVBox.cpp in Sources */,
@ -6531,7 +6471,6 @@
D0FD034B1A3B51AA00825BB5 /* CCAllocatorDiagnostics.cpp in Sources */,
15AE189B19AAD33D00C27E9E /* CCNode+CCBRelativePositioning.cpp in Sources */,
15AE183819AAD2F700C27E9E /* CCRay.cpp in Sources */,
B37510781823AC9F00B3BA6A /* CCPhysicsShapeInfo_chipmunk.cpp in Sources */,
50ABBE391925AB6F00A911A9 /* CCData.cpp in Sources */,
1A57010E180BC8EE0088DEC7 /* CCDrawingPrimitives.cpp in Sources */,
50ABBED71925AB6F00A911A9 /* ZipUtils.cpp in Sources */,
@ -6583,7 +6522,6 @@
50ABBD4C1925AB0000A911A9 /* MathUtil.cpp in Sources */,
15AE191719AAD35000C27E9E /* CCSpriteFrameCacheHelper.cpp in Sources */,
1A087AE81860400400196EF5 /* edtaa3func.cpp in Sources */,
B37510731823AC9F00B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp in Sources */,
50ABBD831925AB4100A911A9 /* CCBatchCommand.cpp in Sources */,
15AE18FF19AAD35000C27E9E /* CCComAudio.cpp in Sources */,
1A5701C7180BCB5A0088DEC7 /* CCLabelTextFormatter.cpp in Sources */,
@ -6716,7 +6654,6 @@
B29A7E0719EE1B7700872B35 /* SkinnedMeshAttachment.c in Sources */,
1A570310180BCF190088DEC7 /* CCComponentContainer.cpp in Sources */,
15AE190719AAD35000C27E9E /* CCDatas.cpp in Sources */,
B37510711823AC9F00B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp in Sources */,
1A01C69C18F57BE800EFE3A6 /* CCString.cpp in Sources */,
50ABBD3C1925AB0000A911A9 /* CCGeometry.cpp in Sources */,
B29A7DDD19EE1B7700872B35 /* BoneData.c in Sources */,
@ -6909,7 +6846,6 @@
15AE186119AAD31200C27E9E /* SimpleAudioEngine_objc.m in Sources */,
15AE182519AAD2F700C27E9E /* CCMesh.cpp in Sources */,
503DD8EE1926736A00CD74DD /* CCImage-ios.mm in Sources */,
B37510811823ACA100B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp in Sources */,
46A170FC1807CECB005B8026 /* CCPhysicsBody.cpp in Sources */,
15AE1BEA19AAE01E00C27E9E /* CCControlButton.cpp in Sources */,
50ABBD941925AB4100A911A9 /* CCGLProgramState.cpp in Sources */,
@ -6993,7 +6929,6 @@
15AE1AB219AAD40300C27E9E /* b2CircleContact.cpp in Sources */,
B29A7E2619EE1B7700872B35 /* Attachment.c in Sources */,
15AE18C119AAD33D00C27E9E /* CCLayerColorLoader.cpp in Sources */,
B37510851823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.cpp in Sources */,
50ABBD551925AB0000A911A9 /* TransformUtils.cpp in Sources */,
292DB14419B4574100A80320 /* UIEditBoxImpl-android.cpp in Sources */,
15AE193619AAD35100C27E9E /* CCArmature.cpp in Sources */,
@ -7028,7 +6963,6 @@
50ABBD4D1925AB0000A911A9 /* MathUtil.cpp in Sources */,
50ABBE3E1925AB6F00A911A9 /* CCDataVisitor.cpp in Sources */,
1A57009F180BC5D20088DEC7 /* CCNode.cpp in Sources */,
B37510831823ACA100B3BA6A /* CCPhysicsShapeInfo_chipmunk.cpp in Sources */,
1A57010F180BC8EE0088DEC7 /* CCDrawingPrimitives.cpp in Sources */,
1A570113180BC8EE0088DEC7 /* CCDrawNode.cpp in Sources */,
1A57011C180BC90D0088DEC7 /* CCGrabber.cpp in Sources */,
@ -7084,7 +7018,6 @@
15AE1BAD19AADFDF00C27E9E /* UILayoutParameter.cpp in Sources */,
3823843E1A259140002C4610 /* SingleNodeReader.cpp in Sources */,
B29A7DDE19EE1B7700872B35 /* BoneData.c in Sources */,
B375107E1823ACA100B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp in Sources */,
15AE19AA19AAD39700C27E9E /* ListViewReader.cpp in Sources */,
1A5701C8180BCB5A0088DEC7 /* CCLabelTextFormatter.cpp in Sources */,
1A5701CC180BCB5A0088DEC7 /* CCLabelTTF.cpp in Sources */,
@ -7214,7 +7147,6 @@
15AE193219AAD35100C27E9E /* CCActionNode.cpp in Sources */,
15AE195319AAD35100C27E9E /* CCDisplayFactory.cpp in Sources */,
50ABC0061926664800A911A9 /* CCThread-apple.mm in Sources */,
B375107C1823ACA100B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp in Sources */,
50ABBEB61925AB6F00A911A9 /* CCUserDefault-android.cpp in Sources */,
296BF6191A4405CB0038EC44 /* UIShaders.cpp in Sources */,
1A57034C180BD09B0088DEC7 /* tinyxml2.cpp in Sources */,

View File

@ -1450,6 +1450,22 @@ JumpTo* JumpTo::create(float duration, const Vec2& position, float height, int j
return jumpTo;
}
bool JumpTo::initWithDuration(float duration, const Vec2& position, float height, int jumps)
{
CCASSERT(jumps>=0, "Number of jumps must be >= 0");
if (ActionInterval::initWithDuration(duration) && jumps>=0)
{
_endPosition = position;
_height = height;
_jumps = jumps;
return true;
}
return false;
}
JumpTo* JumpTo::clone() const
{
// no copy constructor
@ -1468,7 +1484,7 @@ JumpTo* JumpTo::reverse() const
void JumpTo::startWithTarget(Node *target)
{
JumpBy::startWithTarget(target);
_delta = Vec2(_delta.x - _startPosition.x, _delta.y - _startPosition.y);
_delta = Vec2(_endPosition.x - _startPosition.x, _endPosition.y - _startPosition.y);
}
// Bezier cubic formula:

View File

@ -604,6 +604,12 @@ CC_CONSTRUCTOR_ACCESS:
JumpTo() {}
virtual ~JumpTo() {}
/** initializes the action */
bool initWithDuration(float duration, const Vec2& position, float height, int jumps);
protected:
Vec2 _endPosition;
private:
CC_DISALLOW_COPY_AND_ASSIGN(JumpTo);
};

View File

@ -391,13 +391,10 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags)
void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags)
{
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR);
glProgram->use();
glProgram->setUniformsForBuiltins(transform);
glProgram->setUniformLocationWith4fv(glProgram->getUniformLocation("u_color"), (GLfloat*) &_pointColor.r, 1);
glProgram->setUniformLocationWith1f(glProgram->getUniformLocation("u_pointSize"), _pointSize);
if (_dirtyGLPoint)
{
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
@ -459,6 +456,12 @@ void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, con
_dirtyGLPoint = true;
}
void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, const float pointSize, const Color4F &color)
{
_pointSize = pointSize;
drawPoints(position, numberOfPoints, color);
}
void DrawNode::drawLine(const Vec2 &origin, const Vec2 &destination, const Color4F &color)
{
ensureCapacityGLLine(2);
@ -660,25 +663,12 @@ void DrawNode::drawDot(const Vec2 &pos, float radius, const Color4F &color)
_dirty = true;
}
void DrawNode::drawRect(const Vec2 &lb, const Vec2 &lt, const Vec2 &rt, const Vec2& rb, const Color4F &color)
void DrawNode::drawRect(const Vec2 &p1, const Vec2 &p2, const Vec2 &p3, const Vec2& p4, const Color4F &color)
{
unsigned int vertex_count = 2*3;
ensureCapacity(vertex_count);
V2F_C4B_T2F a = {lb, Color4B(color), Tex2F(-1.0, -1.0) };
V2F_C4B_T2F b = {lt, Color4B(color), Tex2F(-1.0, 1.0) };
V2F_C4B_T2F c = {rt, Color4B(color), Tex2F( 1.0, 1.0) };
V2F_C4B_T2F d = {rb, Color4B(color), Tex2F( 1.0, -1.0) };
V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount);
V2F_C4B_T2F_Triangle triangle0 = {a, b, c};
V2F_C4B_T2F_Triangle triangle1 = {a, c, d};
triangles[0] = triangle0;
triangles[1] = triangle1;
_bufferCount += vertex_count;
_dirty = true;
drawLine(Vec2(p1.x, p1.y), Vec2(p2.x, p2.y), color);
drawLine(Vec2(p2.x, p2.y), Vec2(p3.x, p3.y), color);
drawLine(Vec2(p3.x, p3.y), Vec2(p4.x, p4.y), color);
drawLine(Vec2(p4.x, p4.y), Vec2(p1.x, p1.y), color);
}
void DrawNode::drawSegment(const Vec2 &from, const Vec2 &to, float radius, const Color4F &color)

View File

@ -56,6 +56,7 @@ public:
void drawPoint(const Vec2& point, const float pointSize, const Color4F &color);
void drawPoints(const Vec2 *position, unsigned int numberOfPoints, const Color4F &color);
void drawPoints(const Vec2 *position, unsigned int numberOfPoints, const float pointSize, const Color4F &color);
void drawLine(const Vec2 &origin, const Vec2 &destination, const Color4F &color);
@ -79,7 +80,7 @@ public:
/** draw a dot at a position, with a given radius and color */
void drawDot(const Vec2 &pos, float radius, const Color4F &color);
void drawRect(const Vec2 &lb, const Vec2 &lt, const Vec2 &rt, const Vec2& rb, const Color4F &color);
void drawRect(const Vec2 &p1, const Vec2 &p2, const Vec2 &p3, const Vec2& p4, const Color4F &color);
void drawSolidRect(const Vec2 &origin, const Vec2 &destination, const Color4F &color);

View File

@ -513,8 +513,12 @@ void ParticleSystemQuad::setupVBO()
void ParticleSystemQuad::listenRendererRecreated(EventCustom* event)
{
//when comes to foreground in android, _buffersVBO and _VAOname is a wild handle
//before recreating, we need to reset them to 0
memset(_buffersVBO, 0, sizeof(_buffersVBO));
if (Configuration::getInstance()->supportsShareableVAO())
{
_VAOname = 0;
setupVBOandVAO();
}
else

View File

@ -408,11 +408,6 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClCompile Include="..\physics\CCPhysicsJoint.cpp" />
<ClCompile Include="..\physics\CCPhysicsShape.cpp" />
<ClCompile Include="..\physics\CCPhysicsWorld.cpp" />
<ClCompile Include="..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.cpp" />
<ClCompile Include="..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.cpp" />
<ClCompile Include="..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.cpp" />
<ClCompile Include="..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.cpp" />
<ClCompile Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.cpp" />
<ClCompile Include="..\platform\CCFileUtils.cpp" />
<ClCompile Include="..\platform\CCGLView.cpp" />
<ClCompile Include="..\platform\CCImage.cpp" />
@ -820,15 +815,10 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClInclude Include="..\network\WebSocket.h" />
<ClInclude Include="..\physics\CCPhysicsBody.h" />
<ClInclude Include="..\physics\CCPhysicsContact.h" />
<ClInclude Include="..\physics\CCPhysicsHelper.h" />
<ClInclude Include="..\physics\CCPhysicsJoint.h" />
<ClInclude Include="..\physics\CCPhysicsShape.h" />
<ClInclude Include="..\physics\CCPhysicsWorld.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsHelper_chipmunk.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.h" />
<ClInclude Include="..\platform\CCApplicationProtocol.h" />
<ClInclude Include="..\platform\CCCommon.h" />
<ClInclude Include="..\platform\CCDevice.h" />

View File

@ -4,9 +4,6 @@
<Filter Include="physics">
<UniqueIdentifier>{08593631-5bf5-46aa-9436-62595c4f7bf6}</UniqueIdentifier>
</Filter>
<Filter Include="physics\chipmunk">
<UniqueIdentifier>{aeadfa95-9c89-4212-98ae-89ad57db596a}</UniqueIdentifier>
</Filter>
<Filter Include="deprecated">
<UniqueIdentifier>{0b1152b1-c732-4560-8629-87843b0fbd7c}</UniqueIdentifier>
</Filter>
@ -264,21 +261,6 @@
<ClCompile Include="..\physics\CCPhysicsWorld.cpp">
<Filter>physics</Filter>
</ClCompile>
<ClCompile Include="..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="..\..\external\xxhash\xxhash.c">
<Filter>external\xxhash</Filter>
</ClCompile>
@ -766,9 +748,6 @@
<ClCompile Include="..\base\ccRandom.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\3d\CCAABB.cpp">
<Filter>3d</Filter>
</ClCompile>
<ClCompile Include="..\3d\CCAnimate3D.cpp">
<Filter>3d</Filter>
</ClCompile>
@ -1319,6 +1298,11 @@
<ClCompile Include="..\ui\shaders\UIShaders.cpp">
<Filter>ui\shaders</Filter>
</ClCompile>
<ClCompile Include="..\3d\CCFrustum.cpp" />
<ClCompile Include="..\3d\CCPlane.cpp" />
<ClCompile Include="..\3d\CCAABB.cpp">
<Filter>3d</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\physics\CCPhysicsBody.h">
@ -1336,24 +1320,6 @@
<ClInclude Include="..\physics\CCPhysicsWorld.h">
<Filter>physics</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsHelper_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\..\external\xxhash\xxhash.h">
<Filter>external\xxhash</Filter>
</ClInclude>
@ -2577,6 +2543,11 @@
<ClInclude Include="..\ui\shaders\UIShaders.h">
<Filter>ui\shaders</Filter>
</ClInclude>
<ClInclude Include="..\3d\CCFrustum.h" />
<ClInclude Include="..\3d\CCPlane.h" />
<ClInclude Include="..\physics\CCPhysicsHelper.h">
<Filter>physics</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\math\Mat4.inl">

View File

@ -287,15 +287,10 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\network\WebSocket.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsBody.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsContact.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsHelper.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsJoint.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsShape.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsWorld.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsHelper_chipmunk.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\CCApplication.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\CCApplicationProtocol.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\CCCommon.h" />
@ -697,11 +692,6 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsJoint.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsShape.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsWorld.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\CCFileUtils.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\CCGLView.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\platform\CCImage.cpp" />

View File

@ -195,24 +195,6 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\..\external\tinyxml2\tinyxml2.h">
<Filter>external\tinyxml2</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsHelper_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsBody.h">
<Filter>physics</Filter>
</ClInclude>
@ -1306,6 +1288,9 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\base\allocator\CCAllocatorStrategyPool.h">
<Filter>base\allocator</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsHelper.h">
<Filter>physics</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\cocos2d.cpp" />
@ -1474,21 +1459,6 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\..\external\tinyxml2\tinyxml2.cpp">
<Filter>external\tinyxml2</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\physics\CCPhysicsBody.cpp">
<Filter>physics</Filter>
</ClCompile>
@ -2479,9 +2449,6 @@
<Filter Include="external\xxhash">
<UniqueIdentifier>{9a5d5bc4-80f9-42aa-8865-c79711dfa7d6}</UniqueIdentifier>
</Filter>
<Filter Include="physics\chipmunk">
<UniqueIdentifier>{97dd34cb-0d69-4ecd-bbf6-976cdf236d60}</UniqueIdentifier>
</Filter>
<Filter Include="cocostudio\action">
<UniqueIdentifier>{7345e280-b8a5-4d89-a27c-60cf351952d2}</UniqueIdentifier>
</Filter>

View File

@ -435,15 +435,10 @@
<ClInclude Include="..\network\WebSocket.h" />
<ClInclude Include="..\physics\CCPhysicsBody.h" />
<ClInclude Include="..\physics\CCPhysicsContact.h" />
<ClInclude Include="..\physics\CCPhysicsHelper.h" />
<ClInclude Include="..\physics\CCPhysicsJoint.h" />
<ClInclude Include="..\physics\CCPhysicsShape.h" />
<ClInclude Include="..\physics\CCPhysicsWorld.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsHelper_chipmunk.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.h" />
<ClInclude Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.h" />
<ClInclude Include="..\platform\CCApplication.h" />
<ClInclude Include="..\platform\CCApplicationProtocol.h" />
<ClInclude Include="..\platform\CCCommon.h" />
@ -918,11 +913,6 @@
<ClCompile Include="..\physics\CCPhysicsJoint.cpp" />
<ClCompile Include="..\physics\CCPhysicsShape.cpp" />
<ClCompile Include="..\physics\CCPhysicsWorld.cpp" />
<ClCompile Include="..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.cpp" />
<ClCompile Include="..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.cpp" />
<ClCompile Include="..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.cpp" />
<ClCompile Include="..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.cpp" />
<ClCompile Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.cpp" />
<ClCompile Include="..\platform\CCFileUtils.cpp" />
<ClCompile Include="..\platform\CCGLView.cpp" />
<ClCompile Include="..\platform\CCImage.cpp" />

View File

@ -41,9 +41,6 @@
<Filter Include="physics">
<UniqueIdentifier>{a7501f5e-4fef-4f37-a646-ffe633008d9b}</UniqueIdentifier>
</Filter>
<Filter Include="physics\chipmunk">
<UniqueIdentifier>{12ce37e2-709d-416e-a592-1c60b33fd6ce}</UniqueIdentifier>
</Filter>
<Filter Include="platform">
<UniqueIdentifier>{1850cae0-9e70-47af-87d5-c90f8343c06a}</UniqueIdentifier>
</Filter>
@ -721,21 +718,6 @@
<ClCompile Include="..\physics\CCPhysicsWorld.cpp">
<Filter>physics</Filter>
</ClCompile>
<ClCompile Include="..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.cpp">
<Filter>physics\chipmunk</Filter>
</ClCompile>
<ClCompile Include="..\platform\CCFileUtils.cpp">
<Filter>platform</Filter>
</ClCompile>
@ -1871,24 +1853,6 @@
<ClInclude Include="..\physics\CCPhysicsWorld.h">
<Filter>physics</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsBodyInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsContactInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsHelper_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsJointInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsShapeInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\physics\chipmunk\CCPhysicsWorldInfo_chipmunk.h">
<Filter>physics\chipmunk</Filter>
</ClInclude>
<ClInclude Include="..\platform\CCApplication.h">
<Filter>platform</Filter>
</ClInclude>
@ -2631,6 +2595,9 @@
<ClInclude Include="..\base\allocator\CCAllocatorStrategyPool.h">
<Filter>base\allocator</Filter>
</ClInclude>
<ClInclude Include="..\physics\CCPhysicsHelper.h">
<Filter>physics</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\math\Mat4.inl">

View File

@ -1227,6 +1227,10 @@ bool Bundle3D::loadSkinDataBinary(SkinData* skindata)
return false;
}
// Fix bug: check if the bone number is 0.
if (boneNum == 0)
return false;
// bone names and bind pos
float bindpos[16];
for (unsigned int i = 0; i < boneNum; i++)

View File

@ -179,11 +179,6 @@ physics/CCPhysicsContact.cpp \
physics/CCPhysicsJoint.cpp \
physics/CCPhysicsShape.cpp \
physics/CCPhysicsWorld.cpp \
physics/chipmunk/CCPhysicsBodyInfo_chipmunk.cpp \
physics/chipmunk/CCPhysicsContactInfo_chipmunk.cpp \
physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp \
physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp \
physics/chipmunk/CCPhysicsWorldInfo_chipmunk.cpp \
../external/ConvertUTF/ConvertUTFWrapper.cpp \
../external/ConvertUTF/ConvertUTF.c \
../external/tinyxml2/tinyxml2.cpp \

View File

@ -1332,6 +1332,8 @@ void DataReaderHelper::addDataFromJsonCache(const std::string& fileContent, Data
{
std::string plistPath = filePath + ".plist";
std::string pngPath = filePath + ".png";
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(dataInfo->baseFilePath + plistPath);
if (dict.find("particleLifespan") != dict.end()) continue;
ArmatureDataManager::getInstance()->addSpriteFrameFromFile((dataInfo->baseFilePath + plistPath).c_str(), (dataInfo->baseFilePath + pngPath).c_str(), dataInfo->filename.c_str());
}

View File

@ -31,16 +31,15 @@
#include "chipmunk.h"
#include "2d/CCScene.h"
#include "CCPhysicsShape.h"
#include "CCPhysicsJoint.h"
#include "CCPhysicsWorld.h"
#include "CCPhysicsHelper.h"
#include "physics/CCPhysicsShape.h"
#include "physics/CCPhysicsJoint.h"
#include "physics/CCPhysicsWorld.h"
#include "chipmunk/CCPhysicsBodyInfo_chipmunk.h"
#include "chipmunk/CCPhysicsJointInfo_chipmunk.h"
#include "chipmunk/CCPhysicsWorldInfo_chipmunk.h"
#include "chipmunk/CCPhysicsShapeInfo_chipmunk.h"
#include "chipmunk/CCPhysicsHelper_chipmunk.h"
static inline void cpBodyUpdateVelocityWithoutGravity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt)
{
cpBodyUpdateVelocity(body, cpvzero, damping, dt);
}
NS_CC_BEGIN
extern const float PHYSICS_INFINITY;
@ -54,7 +53,7 @@ namespace
PhysicsBody::PhysicsBody()
: _node(nullptr)
, _world(nullptr)
, _info(nullptr)
, _cpBody(nullptr)
, _dynamic(true)
, _enabled(true)
, _rotationEnabled(true)
@ -86,7 +85,10 @@ PhysicsBody::~PhysicsBody()
delete joint;
}
CC_SAFE_DELETE(_info);
if (_cpBody)
{
cpBodyFree(_cpBody);
}
}
PhysicsBody* PhysicsBody::create()
@ -189,7 +191,7 @@ PhysicsBody* PhysicsBody::createEdgeSegment(const Vec2& a, const Vec2& b, const
if (body && body->init())
{
body->addShape(PhysicsShapeEdgeSegment::create(a, b, material, border));
body->_dynamic = false;
body->setDynamic(false);
body->autorelease();
return body;
}
@ -204,7 +206,7 @@ PhysicsBody* PhysicsBody::createEdgeBox(const Size& size, const PhysicsMaterial&
if (body && body->init())
{
body->addShape(PhysicsShapeEdgeBox::create(size, material, border, offset));
body->_dynamic = false;
body->setDynamic(false);
body->autorelease();
return body;
}
@ -220,7 +222,7 @@ PhysicsBody* PhysicsBody::createEdgePolygon(const Vec2* points, int count, const
if (body && body->init())
{
body->addShape(PhysicsShapeEdgePolygon::create(points, count, material, border));
body->_dynamic = false;
body->setDynamic(false);
body->autorelease();
return body;
}
@ -236,7 +238,7 @@ PhysicsBody* PhysicsBody::createEdgeChain(const Vec2* points, int count, const P
if (body && body->init())
{
body->addShape(PhysicsShapeEdgeChain::create(points, count, material, border));
body->_dynamic = false;
body->setDynamic(false);
body->autorelease();
return body;
}
@ -250,12 +252,9 @@ bool PhysicsBody::init()
{
do
{
_info = new (std::nothrow) PhysicsBodyInfo();
CC_BREAK_IF(_info == nullptr);
_cpBody = cpBodyNew(PhysicsHelper::float2cpfloat(_mass), PhysicsHelper::float2cpfloat(_moment));
_info->setBody(cpBodyNew(PhysicsHelper::float2cpfloat(_mass), PhysicsHelper::float2cpfloat(_moment)));
CC_BREAK_IF(_info->getBody() == nullptr);
CC_BREAK_IF(_cpBody == nullptr);
return true;
} while (false);
@ -280,36 +279,32 @@ void PhysicsBody::setDynamic(bool dynamic)
_dynamic = dynamic;
if (dynamic)
{
cpBodySetMass(_info->getBody(), _mass);
cpBodySetMoment(_info->getBody(), _moment);
if (_world != nullptr)
if (_world && _cpBody->CP_PRIVATE(space))
{
// reset the gravity enable
if (isGravityEnabled())
{
_gravityEnabled = false;
setGravityEnable(true);
}
cpSpaceAddBody(_world->_info->getSpace(), _info->getBody());
cpSpaceConvertBodyToDynamic(_world->_cpSpace, _cpBody, _mass, _moment);
cpSpaceAddBody(_world->_cpSpace, _cpBody);
}
else
{
cpBodySetMass(_cpBody, _mass);
cpBodySetMoment(_cpBody, _moment);
_cpBody->CP_PRIVATE(node).idleTime = 0.0f;
}
}
else
{
if (_world != nullptr)
if (_world && _cpBody->CP_PRIVATE(space))
{
cpSpaceRemoveBody(_world->_info->getSpace(), _info->getBody());
cpSpaceRemoveBody(_world->_cpSpace, _cpBody);
cpSpaceConvertBodyToStatic(_world->_cpSpace, _cpBody);
}
else
{
cpBodySetMass(_cpBody, PHYSICS_INFINITY);
cpBodySetMoment(_cpBody, PHYSICS_INFINITY);
_cpBody->CP_PRIVATE(node).idleTime = (cpFloat)INFINITY;
}
// avoid incorrect collion simulation.
cpBodySetMass(_info->getBody(), PHYSICS_INFINITY);
cpBodySetMoment(_info->getBody(), PHYSICS_INFINITY);
cpBodySetVel(_info->getBody(), cpvzero);
cpBodySetAngVel(_info->getBody(), 0.0f);
resetForces();
}
}
}
@ -317,38 +312,33 @@ void PhysicsBody::setRotationEnable(bool enable)
{
if (_rotationEnabled != enable)
{
cpBodySetMoment(_info->getBody(), enable ? _moment : PHYSICS_INFINITY);
cpBodySetMoment(_cpBody, enable ? _moment : PHYSICS_INFINITY);
_rotationEnabled = enable;
}
}
void PhysicsBody::setGravityEnable(bool enable)
{
if (_gravityEnabled != enable)
_gravityEnabled = enable;
if (enable)
{
_gravityEnabled = enable;
if (_world != nullptr)
{
if (enable)
{
applyForce(_world->getGravity() * _mass);
}else
{
applyForce(-_world->getGravity() * _mass);
}
}
_cpBody->velocity_func = cpBodyUpdateVelocity;
}
else
{
_cpBody->velocity_func = cpBodyUpdateVelocityWithoutGravity;
}
}
void PhysicsBody::setPosition(const Vec2& position)
{
cpBodySetPos(_info->getBody(), PhysicsHelper::point2cpv(position + _positionOffset));
cpBodySetPos(_cpBody, PhysicsHelper::point2cpv(position + _positionOffset));
}
void PhysicsBody::setRotation(float rotation)
{
cpBodySetAngle(_info->getBody(), -PhysicsHelper::float2cpfloat((rotation + _rotationOffset) * (M_PI / 180.0f)));
cpBodySetAngle(_cpBody, -PhysicsHelper::float2cpfloat((rotation + _rotationOffset) * (M_PI / 180.0f)));
}
void PhysicsBody::setScale(float scale)
@ -385,13 +375,13 @@ void PhysicsBody::setScaleY(float scaleY)
Vec2 PhysicsBody::getPosition() const
{
cpVect vec = cpBodyGetPos(_info->getBody());
cpVect vec = cpBodyGetPos(_cpBody);
return PhysicsHelper::cpv2point(vec) - _positionOffset;
}
float PhysicsBody::getRotation() const
{
return -PhysicsHelper::cpfloat2float(cpBodyGetAngle(_info->getBody()) * (180.0f / M_PI)) - _rotationOffset;
return -PhysicsHelper::cpfloat2float(cpBodyGetAngle(_cpBody) * (180.0f / M_PI)) - _rotationOffset;
}
PhysicsShape* PhysicsBody::addShape(PhysicsShape* shape, bool addMassAndMoment/* = true*/)
@ -432,19 +422,13 @@ void PhysicsBody::applyForce(const Vect& force, const Vec2& offset)
{
if (_dynamic && _mass != PHYSICS_INFINITY)
{
cpBodyApplyForce(_info->getBody(), PhysicsHelper::point2cpv(force), PhysicsHelper::point2cpv(offset));
cpBodyApplyForce(_cpBody, PhysicsHelper::point2cpv(force), PhysicsHelper::point2cpv(offset));
}
}
void PhysicsBody::resetForces()
{
cpBodyResetForces(_info->getBody());
// if _gravityEnabled is false, add a reverse of gravity force to body
if (_world != nullptr && _dynamic && !_gravityEnabled && _mass != PHYSICS_INFINITY)
{
applyForce(-_world->getGravity() * _mass);
}
cpBodyResetForces(_cpBody);
}
void PhysicsBody::applyImpulse(const Vect& impulse)
@ -454,12 +438,12 @@ void PhysicsBody::applyImpulse(const Vect& impulse)
void PhysicsBody::applyImpulse(const Vect& impulse, const Vec2& offset)
{
cpBodyApplyImpulse(_info->getBody(), PhysicsHelper::point2cpv(impulse), PhysicsHelper::point2cpv(offset));
cpBodyApplyImpulse(_cpBody, PhysicsHelper::point2cpv(impulse), PhysicsHelper::point2cpv(offset));
}
void PhysicsBody::applyTorque(float torque)
{
cpBodySetTorque(_info->getBody(), PhysicsHelper::float2cpfloat(torque));
cpBodySetTorque(_cpBody, PhysicsHelper::float2cpfloat(torque));
}
void PhysicsBody::setMass(float mass)
@ -468,8 +452,6 @@ void PhysicsBody::setMass(float mass)
{
return;
}
int oldMass = _mass;
_mass = mass;
_massDefault = false;
@ -492,14 +474,12 @@ void PhysicsBody::setMass(float mass)
// the static body's mass and moment is always infinity
if (_dynamic)
{
updateMass(oldMass, _mass);
cpBodySetMass(_cpBody, _mass);
}
}
void PhysicsBody::addMass(float mass)
{
float oldMass = _mass;
if (mass == PHYSICS_INFINITY)
{
_mass = PHYSICS_INFINITY;
@ -540,7 +520,7 @@ void PhysicsBody::addMass(float mass)
// the static body's mass and moment is always infinity
if (_dynamic)
{
updateMass(oldMass, _mass);
cpBodySetMass(_cpBody, _mass);
}
}
@ -582,7 +562,7 @@ void PhysicsBody::addMoment(float moment)
// the static body's mass and moment is always infinity
if (_rotationEnabled && _dynamic)
{
cpBodySetMoment(_info->getBody(), PhysicsHelper::float2cpfloat(_moment));
cpBodySetMoment(_cpBody, PhysicsHelper::float2cpfloat(_moment));
}
}
@ -594,22 +574,22 @@ void PhysicsBody::setVelocity(const Vec2& velocity)
return;
}
cpBodySetVel(_info->getBody(), PhysicsHelper::point2cpv(velocity));
cpBodySetVel(_cpBody, PhysicsHelper::point2cpv(velocity));
}
Vec2 PhysicsBody::getVelocity()
{
return PhysicsHelper::cpv2point(cpBodyGetVel(_info->getBody()));
return PhysicsHelper::cpv2point(cpBodyGetVel(_cpBody));
}
Vec2 PhysicsBody::getVelocityAtLocalPoint(const Vec2& point)
{
return PhysicsHelper::cpv2point(cpBodyGetVelAtLocalPoint(_info->getBody(), PhysicsHelper::point2cpv(point)));
return PhysicsHelper::cpv2point(cpBodyGetVelAtLocalPoint(_cpBody, PhysicsHelper::point2cpv(point)));
}
Vec2 PhysicsBody::getVelocityAtWorldPoint(const Vec2& point)
{
return PhysicsHelper::cpv2point(cpBodyGetVelAtWorldPoint(_info->getBody(), PhysicsHelper::point2cpv(point)));
return PhysicsHelper::cpv2point(cpBodyGetVelAtWorldPoint(_cpBody, PhysicsHelper::point2cpv(point)));
}
void PhysicsBody::setAngularVelocity(float velocity)
@ -620,32 +600,32 @@ void PhysicsBody::setAngularVelocity(float velocity)
return;
}
cpBodySetAngVel(_info->getBody(), PhysicsHelper::float2cpfloat(velocity));
cpBodySetAngVel(_cpBody, PhysicsHelper::float2cpfloat(velocity));
}
float PhysicsBody::getAngularVelocity()
{
return PhysicsHelper::cpfloat2float(cpBodyGetAngVel(_info->getBody()));
return PhysicsHelper::cpfloat2float(cpBodyGetAngVel(_cpBody));
}
void PhysicsBody::setVelocityLimit(float limit)
{
cpBodySetVelLimit(_info->getBody(), PhysicsHelper::float2cpfloat(limit));
cpBodySetVelLimit(_cpBody, PhysicsHelper::float2cpfloat(limit));
}
float PhysicsBody::getVelocityLimit()
{
return PhysicsHelper::cpfloat2float(cpBodyGetVelLimit(_info->getBody()));
return PhysicsHelper::cpfloat2float(cpBodyGetVelLimit(_cpBody));
}
void PhysicsBody::setAngularVelocityLimit(float limit)
{
cpBodySetAngVelLimit(_info->getBody(), PhysicsHelper::float2cpfloat(limit));
cpBodySetAngVelLimit(_cpBody, PhysicsHelper::float2cpfloat(limit));
}
float PhysicsBody::getAngularVelocityLimit()
{
return PhysicsHelper::cpfloat2float(cpBodyGetAngVelLimit(_info->getBody()));
return PhysicsHelper::cpfloat2float(cpBodyGetAngVelLimit(_cpBody));
}
void PhysicsBody::setMoment(float moment)
@ -656,7 +636,7 @@ void PhysicsBody::setMoment(float moment)
// the static body's mass and moment is always infinity
if (_rotationEnabled && _dynamic)
{
cpBodySetMoment(_info->getBody(), PhysicsHelper::float2cpfloat(_moment));
cpBodySetMoment(_cpBody, PhysicsHelper::float2cpfloat(_moment));
}
}
@ -768,17 +748,17 @@ void PhysicsBody::setEnable(bool enable)
bool PhysicsBody::isResting() const
{
return CP_PRIVATE(_info->getBody()->node).root != ((cpBody*)0);
return CP_PRIVATE(_cpBody->node).root != ((cpBody*)0);
}
void PhysicsBody::setResting(bool rest) const
{
if (rest && !isResting())
{
cpBodySleep(_info->getBody());
cpBodySleep(_cpBody);
}else if(!rest && isResting())
{
cpBodyActivate(_info->getBody());
cpBodyActivate(_cpBody);
}
}
@ -811,9 +791,9 @@ void PhysicsBody::update(float delta)
// damping compute
if (_isDamping && _dynamic && !isResting())
{
_info->getBody()->v.x *= cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f);
_info->getBody()->v.y *= cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f);
_info->getBody()->w *= cpfclamp(1.0f - delta * _angularDamping, 0.0f, 1.0f);
_cpBody->v.x *= cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f);
_cpBody->v.y *= cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f);
_cpBody->w *= cpfclamp(1.0f - delta * _angularDamping, 0.0f, 1.0f);
}
}
}
@ -930,27 +910,12 @@ float PhysicsBody::getRotationOffset() const
Vec2 PhysicsBody::world2Local(const Vec2& point)
{
return PhysicsHelper::cpv2point(cpBodyWorld2Local(_info->getBody(), PhysicsHelper::point2cpv(point)));
return PhysicsHelper::cpv2point(cpBodyWorld2Local(_cpBody, PhysicsHelper::point2cpv(point)));
}
Vec2 PhysicsBody::local2World(const Vec2& point)
{
return PhysicsHelper::cpv2point(cpBodyLocal2World(_info->getBody(), PhysicsHelper::point2cpv(point)));
}
void PhysicsBody::updateMass(float oldMass, float newMass)
{
if (_dynamic && !_gravityEnabled && _world != nullptr && oldMass != PHYSICS_INFINITY)
{
applyForce(_world->getGravity() * oldMass);
}
cpBodySetMass(_info->getBody(), newMass);
if (_dynamic && !_gravityEnabled && _world != nullptr && newMass != PHYSICS_INFINITY)
{
applyForce(-_world->getGravity() * newMass);
}
return PhysicsHelper::cpv2point(cpBodyLocal2World(_cpBody, PhysicsHelper::point2cpv(point)));
}
NS_CC_END

View File

@ -33,13 +33,14 @@
#include "physics/CCPhysicsShape.h"
#include "base/CCVector.h"
struct cpBody;
NS_CC_BEGIN
class Node;
class Sprite;
class PhysicsWorld;
class PhysicsJoint;
class PhysicsBodyInfo;
typedef Vec2 Vect;
@ -296,6 +297,8 @@ public:
Vec2 world2Local(const Vec2& point);
/** convert the local point to world */
Vec2 local2World(const Vec2& point);
cpBody* getCPBody() { return _cpBody; }
protected:
@ -312,7 +315,6 @@ protected:
void removeJoint(PhysicsJoint* joint);
inline void updateDamping() { _isDamping = _linearDamping != 0.0f || _angularDamping != 0.0f; }
void updateMass(float oldMass, float newMass);
protected:
PhysicsBody();
@ -323,7 +325,7 @@ protected:
std::vector<PhysicsJoint*> _joints;
Vector<PhysicsShape*> _shapes;
PhysicsWorld* _world;
PhysicsBodyInfo* _info;
cpBody* _cpBody;
bool _dynamic;
bool _enabled;
bool _rotationEnabled;

View File

@ -25,11 +25,8 @@
#if CC_USE_PHYSICS
#include "chipmunk.h"
#include "physics/CCPhysicsBody.h"
#include "chipmunk/CCPhysicsContactInfo_chipmunk.h"
#include "chipmunk/CCPhysicsHelper_chipmunk.h"
#include "CCPhysicsBody.h"
#include "CCPhysicsHelper.h"
#include "base/CCEventCustom.h"
NS_CC_BEGIN
@ -42,7 +39,6 @@ PhysicsContact::PhysicsContact()
, _shapeA(nullptr)
, _shapeB(nullptr)
, _eventCode(EventCode::NONE)
, _info(nullptr)
, _notificationEnable(true)
, _result(true)
, _data(nullptr)
@ -55,7 +51,6 @@ PhysicsContact::PhysicsContact()
PhysicsContact::~PhysicsContact()
{
CC_SAFE_DELETE(_info);
CC_SAFE_DELETE(_contactData);
CC_SAFE_DELETE(_preContactData);
}
@ -78,8 +73,6 @@ bool PhysicsContact::init(PhysicsShape* a, PhysicsShape* b)
{
CC_BREAK_IF(a == nullptr || b == nullptr);
CC_BREAK_IF(!(_info = new (std::nothrow) PhysicsContactInfo(this)));
_shapeA = a;
_shapeB = b;

View File

@ -40,8 +40,6 @@ class PhysicsShape;
class PhysicsBody;
class PhysicsWorld;
class PhysicsContactInfo;
typedef Vec2 Vect;
typedef struct CC_DLL PhysicsContactData
@ -112,7 +110,6 @@ private:
PhysicsShape* _shapeA;
PhysicsShape* _shapeB;
EventCode _eventCode;
PhysicsContactInfo* _info;
bool _notificationEnable;
bool _result;

View File

@ -22,8 +22,8 @@
THE SOFTWARE.
****************************************************************************/
#ifndef __CCPHYSICS_HELPER_CHIPMUNK_H__
#define __CCPHYSICS_HELPER_CHIPMUNK_H__
#ifndef __CCPHYSICS_HELPER_H__
#define __CCPHYSICS_HELPER_H__
#include "base/ccConfig.h"
#if CC_USE_PHYSICS
@ -70,4 +70,4 @@ public:
NS_CC_END
#endif // CC_USE_PHYSICS
#endif // __CCPHYSICS_HELPER_CHIPMUNK_H__
#endif // __CCPHYSICS_HELPER_H__

View File

@ -26,13 +26,9 @@
#if CC_USE_PHYSICS
#include "chipmunk.h"
#include "physics/CCPhysicsBody.h"
#include "physics/CCPhysicsWorld.h"
#include "chipmunk/CCPhysicsJointInfo_chipmunk.h"
#include "chipmunk/CCPhysicsBodyInfo_chipmunk.h"
#include "chipmunk/CCPhysicsShapeInfo_chipmunk.h"
#include "chipmunk/CCPhysicsHelper_chipmunk.h"
#include "CCPhysicsBody.h"
#include "CCPhysicsWorld.h"
#include "CCPhysicsHelper.h"
#include "2d/CCNode.h"
NS_CC_BEGIN
@ -41,7 +37,6 @@ PhysicsJoint::PhysicsJoint()
: _bodyA(nullptr)
, _bodyB(nullptr)
, _world(nullptr)
, _info(nullptr)
, _enable(false)
, _collisionEnable(true)
, _destoryMark(false)
@ -55,7 +50,10 @@ PhysicsJoint::~PhysicsJoint()
// reset the shapes collision group
setCollisionEnable(true);
CC_SAFE_DELETE(_info);
for (auto constraint : _cpConstraints)
{
cpConstraintFree(constraint);
}
}
bool PhysicsJoint::init(cocos2d::PhysicsBody *a, cocos2d::PhysicsBody *b)
@ -65,8 +63,6 @@ bool PhysicsJoint::init(cocos2d::PhysicsBody *a, cocos2d::PhysicsBody *b)
CCASSERT(a != nullptr && b != nullptr, "the body passed in is nil");
CCASSERT(a != b, "the two bodies are equal");
CC_BREAK_IF(!(_info = new (std::nothrow) PhysicsJointInfo(this)));
_bodyA = a;
_bodyA->_joints.push_back(this);
_bodyB = b;
@ -97,11 +93,6 @@ void PhysicsJoint::setEnable(bool enable)
}
}
PhysicsBodyInfo* PhysicsJoint::getBodyInfo(PhysicsBody* body) const
{
return body->_info;
}
Node* PhysicsJoint::getBodyNode(PhysicsBody* body) const
{
return body->_node;
@ -151,7 +142,7 @@ void PhysicsJoint::destroy(PhysicsJoint* joint)
void PhysicsJoint::setMaxForce(float force)
{
for (cpConstraint* joint : _info->getJoints())
for (auto joint : _cpConstraints)
{
joint->maxForce = PhysicsHelper::float2cpfloat(force);
}
@ -159,7 +150,7 @@ void PhysicsJoint::setMaxForce(float force)
float PhysicsJoint::getMaxForce() const
{
return PhysicsHelper::cpfloat2float(_info->getJoints().front()->maxForce);
return PhysicsHelper::cpfloat2float(_cpConstraints.front()->maxForce);
}
PhysicsJointFixed* PhysicsJointFixed::construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr)
@ -185,15 +176,15 @@ bool PhysicsJointFixed::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr)
getBodyNode(b)->setPosition(anchr);
// add a pivot joint to fixed two body together
cpConstraint* joint = cpPivotJointNew(getBodyInfo(a)->getBody(), getBodyInfo(b)->getBody(),
auto constraint = cpPivotJointNew(a->getCPBody(), b->getCPBody(),
PhysicsHelper::point2cpv(anchr));
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
CC_BREAK_IF(constraint == nullptr);
_cpConstraints.push_back(constraint);
// add a gear joint to make two body have the same rotation.
joint = cpGearJointNew(getBodyInfo(a)->getBody(), getBodyInfo(b)->getBody(), 0, 1);
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
constraint = cpGearJointNew(a->getCPBody(), b->getCPBody(), 0, 1);
CC_BREAK_IF(constraint == nullptr);
_cpConstraints.push_back(constraint);
setCollisionEnable(false);
@ -221,12 +212,12 @@ bool PhysicsJointPin::init(PhysicsBody *a, PhysicsBody *b, const Vec2& anchr)
do
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpPivotJointNew(getBodyInfo(a)->getBody(), getBodyInfo(b)->getBody(),
auto constraint = cpPivotJointNew(a->getCPBody(), b->getCPBody(),
PhysicsHelper::point2cpv(anchr));
CC_BREAK_IF(joint == nullptr);
CC_BREAK_IF(constraint == nullptr);
_info->add(joint);
_cpConstraints.push_back(constraint);
return true;
} while (false);
@ -258,15 +249,15 @@ bool PhysicsJointLimit::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1,
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpSlideJointNew(getBodyInfo(a)->getBody(), getBodyInfo(b)->getBody(),
auto constraint = cpSlideJointNew(a->getCPBody(), b->getCPBody(),
PhysicsHelper::point2cpv(anchr1),
PhysicsHelper::point2cpv(anchr2),
PhysicsHelper::float2cpfloat(min),
PhysicsHelper::float2cpfloat(max));
CC_BREAK_IF(joint == nullptr);
CC_BREAK_IF(constraint == nullptr);
_info->add(joint);
_cpConstraints.push_back(constraint);
return true;
} while (false);
@ -276,42 +267,42 @@ bool PhysicsJointLimit::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1,
float PhysicsJointLimit::getMin() const
{
return PhysicsHelper::cpfloat2float(cpSlideJointGetMin(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpSlideJointGetMin(_cpConstraints.front()));
}
void PhysicsJointLimit::setMin(float min)
{
cpSlideJointSetMin(_info->getJoints().front(), PhysicsHelper::float2cpfloat(min));
cpSlideJointSetMin(_cpConstraints.front(), PhysicsHelper::float2cpfloat(min));
}
float PhysicsJointLimit::getMax() const
{
return PhysicsHelper::cpfloat2float(cpSlideJointGetMax(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpSlideJointGetMax(_cpConstraints.front()));
}
void PhysicsJointLimit::setMax(float max)
{
cpSlideJointSetMax(_info->getJoints().front(), PhysicsHelper::float2cpfloat(max));
cpSlideJointSetMax(_cpConstraints.front(), PhysicsHelper::float2cpfloat(max));
}
Vec2 PhysicsJointLimit::getAnchr1() const
{
return PhysicsHelper::cpv2point(cpSlideJointGetAnchr1(_info->getJoints().front()));
return PhysicsHelper::cpv2point(cpSlideJointGetAnchr1(_cpConstraints.front()));
}
void PhysicsJointLimit::setAnchr1(const Vec2& anchr)
{
cpSlideJointSetAnchr1(_info->getJoints().front(), PhysicsHelper::point2cpv(anchr));
cpSlideJointSetAnchr1(_cpConstraints.front(), PhysicsHelper::point2cpv(anchr));
}
Vec2 PhysicsJointLimit::getAnchr2() const
{
return PhysicsHelper::cpv2point(cpSlideJointGetAnchr2(_info->getJoints().front()));
return PhysicsHelper::cpv2point(cpSlideJointGetAnchr2(_cpConstraints.front()));
}
void PhysicsJointLimit::setAnchr2(const Vec2& anchr)
{
cpSlideJointSetAnchr1(_info->getJoints().front(), PhysicsHelper::point2cpv(anchr));
cpSlideJointSetAnchr1(_cpConstraints.front(), PhysicsHelper::point2cpv(anchr));
}
PhysicsJointDistance* PhysicsJointDistance::construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2)
@ -333,14 +324,14 @@ bool PhysicsJointDistance::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anch
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpPinJointNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
auto constraint = cpPinJointNew(a->getCPBody(),
b->getCPBody(),
PhysicsHelper::point2cpv(anchr1),
PhysicsHelper::point2cpv(anchr2));
CC_BREAK_IF(joint == nullptr);
CC_BREAK_IF(constraint == nullptr);
_info->add(joint);
_cpConstraints.push_back(constraint);
return true;
} while (false);
@ -350,12 +341,12 @@ bool PhysicsJointDistance::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anch
float PhysicsJointDistance::getDistance() const
{
return PhysicsHelper::cpfloat2float(cpPinJointGetDist(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpPinJointGetDist(_cpConstraints.front()));
}
void PhysicsJointDistance::setDistance(float distance)
{
cpPinJointSetDist(_info->getJoints().front(), PhysicsHelper::float2cpfloat(distance));
cpPinJointSetDist(_cpConstraints.front(), PhysicsHelper::float2cpfloat(distance));
}
PhysicsJointSpring* PhysicsJointSpring::construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2, float stiffness, float damping)
@ -376,17 +367,17 @@ bool PhysicsJointSpring::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1
do {
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpDampedSpringNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
auto constraint = cpDampedSpringNew(a->getCPBody(),
b->getCPBody(),
PhysicsHelper::point2cpv(anchr1),
PhysicsHelper::point2cpv(anchr2),
PhysicsHelper::float2cpfloat(_bodyB->local2World(anchr1).getDistance(_bodyA->local2World(anchr2))),
PhysicsHelper::float2cpfloat(stiffness),
PhysicsHelper::float2cpfloat(damping));
CC_BREAK_IF(joint == nullptr);
CC_BREAK_IF(constraint == nullptr);
_info->add(joint);
_cpConstraints.push_back(constraint);
return true;
} while (false);
@ -396,52 +387,52 @@ bool PhysicsJointSpring::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1
Vec2 PhysicsJointSpring::getAnchr1() const
{
return PhysicsHelper::cpv2point(cpDampedSpringGetAnchr1(_info->getJoints().front()));
return PhysicsHelper::cpv2point(cpDampedSpringGetAnchr1(_cpConstraints.front()));
}
void PhysicsJointSpring::setAnchr1(const Vec2& anchr)
{
cpDampedSpringSetAnchr1(_info->getJoints().front(), PhysicsHelper::point2cpv(anchr));
cpDampedSpringSetAnchr1(_cpConstraints.front(), PhysicsHelper::point2cpv(anchr));
}
Vec2 PhysicsJointSpring::getAnchr2() const
{
return PhysicsHelper::cpv2point(cpDampedSpringGetAnchr2(_info->getJoints().front()));
return PhysicsHelper::cpv2point(cpDampedSpringGetAnchr2(_cpConstraints.front()));
}
void PhysicsJointSpring::setAnchr2(const Vec2& anchr)
{
cpDampedSpringSetAnchr1(_info->getJoints().front(), PhysicsHelper::point2cpv(anchr));
cpDampedSpringSetAnchr1(_cpConstraints.front(), PhysicsHelper::point2cpv(anchr));
}
float PhysicsJointSpring::getRestLength() const
{
return PhysicsHelper::cpfloat2float(cpDampedSpringGetRestLength(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpDampedSpringGetRestLength(_cpConstraints.front()));
}
void PhysicsJointSpring::setRestLength(float restLength)
{
cpDampedSpringSetRestLength(_info->getJoints().front(), PhysicsHelper::float2cpfloat(restLength));
cpDampedSpringSetRestLength(_cpConstraints.front(), PhysicsHelper::float2cpfloat(restLength));
}
float PhysicsJointSpring::getStiffness() const
{
return PhysicsHelper::cpfloat2float(cpDampedSpringGetStiffness(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpDampedSpringGetStiffness(_cpConstraints.front()));
}
void PhysicsJointSpring::setStiffness(float stiffness)
{
cpDampedSpringSetStiffness(_info->getJoints().front(), PhysicsHelper::float2cpfloat(stiffness));
cpDampedSpringSetStiffness(_cpConstraints.front(), PhysicsHelper::float2cpfloat(stiffness));
}
float PhysicsJointSpring::getDamping() const
{
return PhysicsHelper::cpfloat2float(cpDampedSpringGetDamping(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpDampedSpringGetDamping(_cpConstraints.front()));
}
void PhysicsJointSpring::setDamping(float damping)
{
cpDampedSpringSetDamping(_info->getJoints().front(), PhysicsHelper::float2cpfloat(damping));
cpDampedSpringSetDamping(_cpConstraints.front(), PhysicsHelper::float2cpfloat(damping));
}
PhysicsJointGroove* PhysicsJointGroove::construct(PhysicsBody* a, PhysicsBody* b, const Vec2& grooveA, const Vec2& grooveB, const Vec2& anchr2)
@ -462,15 +453,15 @@ bool PhysicsJointGroove::init(PhysicsBody* a, PhysicsBody* b, const Vec2& groove
do {
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpGrooveJointNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
auto constraint = cpGrooveJointNew(a->getCPBody(),
b->getCPBody(),
PhysicsHelper::point2cpv(grooveA),
PhysicsHelper::point2cpv(grooveB),
PhysicsHelper::point2cpv(anchr2));
CC_BREAK_IF(joint == nullptr);
CC_BREAK_IF(constraint == nullptr);
_info->add(joint);
_cpConstraints.push_back(constraint);
return true;
} while (false);
@ -480,32 +471,32 @@ bool PhysicsJointGroove::init(PhysicsBody* a, PhysicsBody* b, const Vec2& groove
Vec2 PhysicsJointGroove::getGrooveA() const
{
return PhysicsHelper::cpv2point(cpGrooveJointGetGrooveA(_info->getJoints().front()));
return PhysicsHelper::cpv2point(cpGrooveJointGetGrooveA(_cpConstraints.front()));
}
void PhysicsJointGroove::setGrooveA(const Vec2& grooveA)
{
cpGrooveJointSetGrooveA(_info->getJoints().front(), PhysicsHelper::point2cpv(grooveA));
cpGrooveJointSetGrooveA(_cpConstraints.front(), PhysicsHelper::point2cpv(grooveA));
}
Vec2 PhysicsJointGroove::getGrooveB() const
{
return PhysicsHelper::cpv2point(cpGrooveJointGetGrooveB(_info->getJoints().front()));
return PhysicsHelper::cpv2point(cpGrooveJointGetGrooveB(_cpConstraints.front()));
}
void PhysicsJointGroove::setGrooveB(const Vec2& grooveB)
{
cpGrooveJointSetGrooveB(_info->getJoints().front(), PhysicsHelper::point2cpv(grooveB));
cpGrooveJointSetGrooveB(_cpConstraints.front(), PhysicsHelper::point2cpv(grooveB));
}
Vec2 PhysicsJointGroove::getAnchr2() const
{
return PhysicsHelper::cpv2point(cpGrooveJointGetAnchr2(_info->getJoints().front()));
return PhysicsHelper::cpv2point(cpGrooveJointGetAnchr2(_cpConstraints.front()));
}
void PhysicsJointGroove::setAnchr2(const Vec2& anchr2)
{
cpGrooveJointSetAnchr2(_info->getJoints().front(), PhysicsHelper::point2cpv(anchr2));
cpGrooveJointSetAnchr2(_cpConstraints.front(), PhysicsHelper::point2cpv(anchr2));
}
PhysicsJointRotarySpring* PhysicsJointRotarySpring::construct(PhysicsBody* a, PhysicsBody* b, float stiffness, float damping)
@ -526,15 +517,15 @@ bool PhysicsJointRotarySpring::init(PhysicsBody* a, PhysicsBody* b, float stiffn
do {
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpDampedRotarySpringNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
auto constraint = cpDampedRotarySpringNew(a->getCPBody(),
b->getCPBody(),
PhysicsHelper::float2cpfloat(_bodyB->getRotation() - _bodyA->getRotation()),
PhysicsHelper::float2cpfloat(stiffness),
PhysicsHelper::float2cpfloat(damping));
CC_BREAK_IF(joint == nullptr);
CC_BREAK_IF(constraint == nullptr);
_info->add(joint);
_cpConstraints.push_back(constraint);
return true;
} while (false);
@ -544,32 +535,32 @@ bool PhysicsJointRotarySpring::init(PhysicsBody* a, PhysicsBody* b, float stiffn
float PhysicsJointRotarySpring::getRestAngle() const
{
return PhysicsHelper::cpfloat2float(cpDampedRotarySpringGetRestAngle(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpDampedRotarySpringGetRestAngle(_cpConstraints.front()));
}
void PhysicsJointRotarySpring::setRestAngle(float restAngle)
{
cpDampedRotarySpringSetRestAngle(_info->getJoints().front(), PhysicsHelper::float2cpfloat(restAngle));
cpDampedRotarySpringSetRestAngle(_cpConstraints.front(), PhysicsHelper::float2cpfloat(restAngle));
}
float PhysicsJointRotarySpring::getStiffness() const
{
return PhysicsHelper::cpfloat2float(cpDampedRotarySpringGetStiffness(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpDampedRotarySpringGetStiffness(_cpConstraints.front()));
}
void PhysicsJointRotarySpring::setStiffness(float stiffness)
{
cpDampedRotarySpringSetStiffness(_info->getJoints().front(), PhysicsHelper::float2cpfloat(stiffness));
cpDampedRotarySpringSetStiffness(_cpConstraints.front(), PhysicsHelper::float2cpfloat(stiffness));
}
float PhysicsJointRotarySpring::getDamping() const
{
return PhysicsHelper::cpfloat2float(cpDampedRotarySpringGetDamping(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpDampedRotarySpringGetDamping(_cpConstraints.front()));
}
void PhysicsJointRotarySpring::setDamping(float damping)
{
cpDampedRotarySpringSetDamping(_info->getJoints().front(), PhysicsHelper::float2cpfloat(damping));
cpDampedRotarySpringSetDamping(_cpConstraints.front(), PhysicsHelper::float2cpfloat(damping));
}
PhysicsJointRotaryLimit* PhysicsJointRotaryLimit::construct(PhysicsBody* a, PhysicsBody* b, float min, float max)
@ -596,14 +587,14 @@ bool PhysicsJointRotaryLimit::init(PhysicsBody* a, PhysicsBody* b, float min, fl
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpRotaryLimitJointNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
auto constraint = cpRotaryLimitJointNew(a->getCPBody(),
b->getCPBody(),
PhysicsHelper::float2cpfloat(min),
PhysicsHelper::float2cpfloat(max));
CC_BREAK_IF(joint == nullptr);
CC_BREAK_IF(constraint == nullptr);
_info->add(joint);
_cpConstraints.push_back(constraint);
return true;
} while (false);
@ -613,22 +604,22 @@ bool PhysicsJointRotaryLimit::init(PhysicsBody* a, PhysicsBody* b, float min, fl
float PhysicsJointRotaryLimit::getMin() const
{
return PhysicsHelper::cpfloat2float(cpRotaryLimitJointGetMin(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpRotaryLimitJointGetMin(_cpConstraints.front()));
}
void PhysicsJointRotaryLimit::setMin(float min)
{
cpRotaryLimitJointSetMin(_info->getJoints().front(), PhysicsHelper::float2cpfloat(min));
cpRotaryLimitJointSetMin(_cpConstraints.front(), PhysicsHelper::float2cpfloat(min));
}
float PhysicsJointRotaryLimit::getMax() const
{
return PhysicsHelper::cpfloat2float(cpRotaryLimitJointGetMax(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpRotaryLimitJointGetMax(_cpConstraints.front()));
}
void PhysicsJointRotaryLimit::setMax(float max)
{
cpRotaryLimitJointSetMax(_info->getJoints().front(), PhysicsHelper::float2cpfloat(max));
cpRotaryLimitJointSetMax(_cpConstraints.front(), PhysicsHelper::float2cpfloat(max));
}
PhysicsJointRatchet* PhysicsJointRatchet::construct(PhysicsBody* a, PhysicsBody* b, float phase, float ratchet)
@ -650,14 +641,14 @@ bool PhysicsJointRatchet::init(PhysicsBody* a, PhysicsBody* b, float phase, floa
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpRatchetJointNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
auto constraint = cpRatchetJointNew(a->getCPBody(),
b->getCPBody(),
PhysicsHelper::float2cpfloat(phase),
PhysicsHelper::cpfloat2float(ratchet));
CC_BREAK_IF(joint == nullptr);
CC_BREAK_IF(constraint == nullptr);
_info->add(joint);
_cpConstraints.push_back(constraint);
return true;
} while (false);
@ -667,32 +658,32 @@ bool PhysicsJointRatchet::init(PhysicsBody* a, PhysicsBody* b, float phase, floa
float PhysicsJointRatchet::getAngle() const
{
return PhysicsHelper::cpfloat2float(cpRatchetJointGetAngle(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpRatchetJointGetAngle(_cpConstraints.front()));
}
void PhysicsJointRatchet::setAngle(float angle)
{
cpRatchetJointSetAngle(_info->getJoints().front(), PhysicsHelper::float2cpfloat(angle));
cpRatchetJointSetAngle(_cpConstraints.front(), PhysicsHelper::float2cpfloat(angle));
}
float PhysicsJointRatchet::getPhase() const
{
return PhysicsHelper::cpfloat2float(cpRatchetJointGetPhase(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpRatchetJointGetPhase(_cpConstraints.front()));
}
void PhysicsJointRatchet::setPhase(float phase)
{
cpRatchetJointSetPhase(_info->getJoints().front(), PhysicsHelper::float2cpfloat(phase));
cpRatchetJointSetPhase(_cpConstraints.front(), PhysicsHelper::float2cpfloat(phase));
}
float PhysicsJointRatchet::getRatchet() const
{
return PhysicsHelper::cpfloat2float(cpRatchetJointGetRatchet(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpRatchetJointGetRatchet(_cpConstraints.front()));
}
void PhysicsJointRatchet::setRatchet(float ratchet)
{
cpRatchetJointSetRatchet(_info->getJoints().front(), PhysicsHelper::float2cpfloat(ratchet));
cpRatchetJointSetRatchet(_cpConstraints.front(), PhysicsHelper::float2cpfloat(ratchet));
}
PhysicsJointGear* PhysicsJointGear::construct(PhysicsBody* a, PhysicsBody* b, float phase, float ratchet)
@ -714,14 +705,14 @@ bool PhysicsJointGear::init(PhysicsBody* a, PhysicsBody* b, float phase, float r
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpGearJointNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
auto constraint = cpGearJointNew(a->getCPBody(),
b->getCPBody(),
PhysicsHelper::float2cpfloat(phase),
PhysicsHelper::float2cpfloat(ratio));
CC_BREAK_IF(joint == nullptr);
CC_BREAK_IF(constraint == nullptr);
_info->add(joint);
_cpConstraints.push_back(constraint);
return true;
} while (false);
@ -731,22 +722,22 @@ bool PhysicsJointGear::init(PhysicsBody* a, PhysicsBody* b, float phase, float r
float PhysicsJointGear::getPhase() const
{
return PhysicsHelper::cpfloat2float(cpGearJointGetPhase(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpGearJointGetPhase(_cpConstraints.front()));
}
void PhysicsJointGear::setPhase(float phase)
{
cpGearJointSetPhase(_info->getJoints().front(), PhysicsHelper::float2cpfloat(phase));
cpGearJointSetPhase(_cpConstraints.front(), PhysicsHelper::float2cpfloat(phase));
}
float PhysicsJointGear::getRatio() const
{
return PhysicsHelper::cpfloat2float(cpGearJointGetRatio(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpGearJointGetRatio(_cpConstraints.front()));
}
void PhysicsJointGear::setRatio(float ratio)
{
cpGearJointSetRatio(_info->getJoints().front(), PhysicsHelper::float2cpfloat(ratio));
cpGearJointSetRatio(_cpConstraints.front(), PhysicsHelper::float2cpfloat(ratio));
}
PhysicsJointMotor* PhysicsJointMotor::construct(PhysicsBody* a, PhysicsBody* b, float rate)
@ -768,13 +759,13 @@ bool PhysicsJointMotor::init(PhysicsBody* a, PhysicsBody* b, float rate)
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpSimpleMotorNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
auto constraint = cpSimpleMotorNew(a->getCPBody(),
b->getCPBody(),
PhysicsHelper::float2cpfloat(rate));
CC_BREAK_IF(joint == nullptr);
CC_BREAK_IF(constraint == nullptr);
_info->add(joint);
_cpConstraints.push_back(constraint);
return true;
} while (false);
@ -784,12 +775,12 @@ bool PhysicsJointMotor::init(PhysicsBody* a, PhysicsBody* b, float rate)
float PhysicsJointMotor::getRate() const
{
return PhysicsHelper::cpfloat2float(cpSimpleMotorGetRate(_info->getJoints().front()));
return PhysicsHelper::cpfloat2float(cpSimpleMotorGetRate(_cpConstraints.front()));
}
void PhysicsJointMotor::setRate(float rate)
{
cpSimpleMotorSetRate(_info->getJoints().front(), PhysicsHelper::float2cpfloat(rate));
cpSimpleMotorSetRate(_cpConstraints.front(), PhysicsHelper::float2cpfloat(rate));
}
NS_CC_END

View File

@ -31,13 +31,13 @@
#include "base/CCRef.h"
#include "math/CCGeometry.h"
struct cpConstraint;
NS_CC_BEGIN
class Node;
class PhysicsBody;
class PhysicsWorld;
class PhysicsJointInfo;
class PhysicsBodyInfo;
/*
* @brief An PhysicsJoint object connects two physics bodies together.
@ -72,18 +72,13 @@ public:
protected:
bool init(PhysicsBody* a, PhysicsBody* b);
/**
* PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody.
*/
PhysicsBodyInfo* getBodyInfo(PhysicsBody* body) const;
Node* getBodyNode(PhysicsBody* body) const;
protected:
PhysicsBody* _bodyA;
PhysicsBody* _bodyB;
PhysicsWorld* _world;
PhysicsJointInfo* _info;
std::vector<cpConstraint*> _cpConstraints;
bool _enable;
bool _collisionEnable;
bool _destoryMark;

View File

@ -26,23 +26,22 @@
#if CC_USE_PHYSICS
#include <climits>
#include <unordered_map>
#include "chipmunk.h"
#include "chipmunk_unsafe.h"
#include "physics/CCPhysicsBody.h"
#include "physics/CCPhysicsWorld.h"
#include "chipmunk/CCPhysicsBodyInfo_chipmunk.h"
#include "chipmunk/CCPhysicsShapeInfo_chipmunk.h"
#include "chipmunk/CCPhysicsHelper_chipmunk.h"
#include "CCPhysicsBody.h"
#include "CCPhysicsWorld.h"
#include "CCPhysicsHelper.h"
NS_CC_BEGIN
extern const float PHYSICS_INFINITY;
std::unordered_map<cpShape*, PhysicsShape*> s_physicsShapeMap;
static cpBody* s_sharedBody = nullptr;
PhysicsShape::PhysicsShape()
: _body(nullptr)
, _info(nullptr)
, _type(Type::UNKNOWN)
, _area(0.0f)
, _mass(0.0f)
@ -58,22 +57,20 @@ PhysicsShape::PhysicsShape()
, _contactTestBitmask(0)
, _group(0)
{
if (s_sharedBody == nullptr)
{
s_sharedBody = cpBodyNewStatic();
}
}
PhysicsShape::~PhysicsShape()
{
CC_SAFE_DELETE(_info);
}
for (auto shape : _cpShapes)
{
s_physicsShapeMap.erase(shape);
bool PhysicsShape::init(Type type)
{
_info = new (std::nothrow) PhysicsShapeInfo(this);
if (_info == nullptr) return false;
_type = type;
return true;
cpShapeFree(shape);
}
}
void PhysicsShape::setMass(float mass)
@ -115,17 +112,6 @@ void PhysicsShape::setMaterial(const PhysicsMaterial& material)
setFriction(material.friction);
}
PhysicsBodyInfo* PhysicsShape::bodyInfo() const
{
if (_body != nullptr)
{
return _body->_info;
}else
{
return nullptr;
}
}
void PhysicsShape::setScale(float scale)
{
setScaleX(scale);
@ -172,6 +158,16 @@ void PhysicsShape::update(float delta)
}
}
void PhysicsShape::addShape(cpShape* shape)
{
if (shape)
{
cpShapeSetGroup(shape, _group);
_cpShapes.push_back(shape);
s_physicsShapeMap.insert(std::pair<cpShape*, PhysicsShape*>(shape, this));
}
}
PhysicsShapeCircle::PhysicsShapeCircle()
{
@ -264,7 +260,7 @@ void PhysicsShape::setRestitution(float restitution)
{
_material.restitution = restitution;
for (cpShape* shape : _info->getShapes())
for (cpShape* shape : _cpShapes)
{
cpShapeSetElasticity(shape, PhysicsHelper::float2cpfloat(restitution));
}
@ -274,7 +270,7 @@ void PhysicsShape::setFriction(float friction)
{
_material.friction = friction;
for (cpShape* shape : _info->getShapes())
for (cpShape* shape : _cpShapes)
{
cpShapeSetFriction(shape, PhysicsHelper::float2cpfloat(friction));
}
@ -309,25 +305,21 @@ Vec2 PhysicsShape::getPolyonCenter(const Vec2* points, int count)
void PhysicsShape::setBody(PhysicsBody *body)
{
// already added
if (body != nullptr && _body == body)
if (body && _body == body)
{
return;
}
if (_body != nullptr)
if (_body)
{
_body->removeShape(this);
}
if (body == nullptr)
for (auto shape : _cpShapes)
{
_info->setBody(nullptr);
_body = nullptr;
}else
{
_info->setBody(body->_info->getBody());
_body = body;
cpShapeSetBody(shape, body == nullptr ? s_sharedBody : body->_cpBody);
}
_body = body;
}
// PhysicsShapeCircle
@ -348,13 +340,13 @@ bool PhysicsShapeCircle::init(float radius, const PhysicsMaterial& material/* =
{
do
{
CC_BREAK_IF(!PhysicsShape::init(Type::CIRCLE));
_type = Type::CIRCLE;
cpShape* shape = cpCircleShapeNew(_info->getSharedBody(), radius, PhysicsHelper::point2cpv(offset));
auto shape = cpCircleShapeNew(s_sharedBody, radius, PhysicsHelper::point2cpv(offset));
CC_BREAK_IF(shape == nullptr);
_info->add(shape);
addShape(shape);
_area = calculateArea();
_mass = material.density == PHYSICS_INFINITY ? PHYSICS_INFINITY : material.density * _area;
@ -383,12 +375,12 @@ float PhysicsShapeCircle::calculateMoment(float mass, float radius, const Vec2&
float PhysicsShapeCircle::calculateArea()
{
return PhysicsHelper::cpfloat2float(cpAreaForCircle(0, cpCircleShapeGetRadius(_info->getShapes().front())));
return PhysicsHelper::cpfloat2float(cpAreaForCircle(0, cpCircleShapeGetRadius(_cpShapes.front())));
}
float PhysicsShapeCircle::calculateDefaultMoment()
{
cpShape* shape = _info->getShapes().front();
auto shape = _cpShapes.front();
return _mass == PHYSICS_INFINITY ? PHYSICS_INFINITY
: PhysicsHelper::cpfloat2float(cpMomentForCircle(PhysicsHelper::float2cpfloat(_mass),
@ -399,12 +391,12 @@ float PhysicsShapeCircle::calculateDefaultMoment()
float PhysicsShapeCircle::getRadius() const
{
return PhysicsHelper::cpfloat2float(cpCircleShapeGetRadius(_info->getShapes().front()));
return PhysicsHelper::cpfloat2float(cpCircleShapeGetRadius(_cpShapes.front()));
}
Vec2 PhysicsShapeCircle::getOffset()
{
return PhysicsHelper::cpv2point(cpCircleShapeGetOffset(_info->getShapes().front()));
return PhysicsHelper::cpv2point(cpCircleShapeGetOffset(_cpShapes.front()));
}
void PhysicsShapeCircle::setScale(float scale)
@ -450,13 +442,12 @@ void PhysicsShapeCircle::setScaleY(float scale)
void PhysicsShapeCircle::update(float delta)
{
if (_dirty)
{
cpFloat factor = std::abs(PhysicsHelper::float2cpfloat( _newScaleX / _scaleX ));
cpShape* shape = _info->getShapes().front();
cpVect v = cpCircleShapeGetOffset(shape);
auto shape = _cpShapes.front();
auto v = cpCircleShapeGetOffset(shape);
v = cpvmult(v, PhysicsHelper::float2cpfloat(factor));
((cpCircleShape*)shape)->c = v;
@ -485,21 +476,20 @@ bool PhysicsShapeEdgeSegment::init(const Vec2& a, const Vec2& b, const PhysicsMa
{
do
{
CC_BREAK_IF(!PhysicsShape::init(Type::EDGESEGMENT));
_type = Type::EDGESEGMENT;
cpShape* shape = cpSegmentShapeNew(_info->getSharedBody(),
auto shape = cpSegmentShapeNew(s_sharedBody,
PhysicsHelper::point2cpv(a),
PhysicsHelper::point2cpv(b),
PhysicsHelper::float2cpfloat(border));
CC_BREAK_IF(shape == nullptr);
_info->add(shape);
addShape(shape);
_mass = PHYSICS_INFINITY;
_moment = PHYSICS_INFINITY;
setMaterial(material);
return true;
@ -510,18 +500,18 @@ bool PhysicsShapeEdgeSegment::init(const Vec2& a, const Vec2& b, const PhysicsMa
Vec2 PhysicsShapeEdgeSegment::getPointA() const
{
return PhysicsHelper::cpv2point(((cpSegmentShape*)(_info->getShapes().front()))->ta);
return PhysicsHelper::cpv2point(((cpSegmentShape*)(_cpShapes.front()))->ta);
}
Vec2 PhysicsShapeEdgeSegment::getPointB() const
{
return PhysicsHelper::cpv2point(((cpSegmentShape*)(_info->getShapes().front()))->tb);
return PhysicsHelper::cpv2point(((cpSegmentShape*)(_cpShapes.front()))->tb);
}
Vec2 PhysicsShapeEdgeSegment::getCenter()
{
Vec2 a = PhysicsHelper::cpv2point(cpSegmentShapeGetA(_info->getShapes().front()));
Vec2 b = PhysicsHelper::cpv2point(cpSegmentShapeGetB(_info->getShapes().front()));
auto a = PhysicsHelper::cpv2point(cpSegmentShapeGetA(_cpShapes.front()));
auto b = PhysicsHelper::cpv2point(cpSegmentShapeGetB(_cpShapes.front()));
return ( a + b ) / 2;
}
@ -529,14 +519,14 @@ void PhysicsShapeEdgeSegment::update(float delta)
{
if (_dirty)
{
cpFloat factorX = PhysicsHelper::float2cpfloat(_newScaleX / _scaleX);
cpFloat factorY = PhysicsHelper::float2cpfloat(_newScaleY / _scaleY);
auto factorX = PhysicsHelper::float2cpfloat(_newScaleX / _scaleX);
auto factorY = PhysicsHelper::float2cpfloat(_newScaleY / _scaleY);
cpShape* shape = _info->getShapes().front();
cpVect a = cpSegmentShapeGetA(shape);
auto shape = _cpShapes.front();
auto a = cpSegmentShapeGetA(shape);
a.x *= factorX;
a.y *= factorY;
cpVect b = cpSegmentShapeGetB(shape);
auto b = cpSegmentShapeGetB(shape);
b.x *= factorX;
b.y *= factorY;
cpSegmentShapeSetEndpoints(shape, a, b);
@ -563,19 +553,19 @@ bool PhysicsShapeBox::init(const Size& size, const PhysicsMaterial& material/* =
{
do
{
CC_BREAK_IF(!PhysicsShape::init(Type::BOX));
_type = Type::BOX;
cpVect wh = PhysicsHelper::size2cpv(size);
auto wh = PhysicsHelper::size2cpv(size);
cpVect vec[4] =
{
{-wh.x/2.0f, -wh.y/2.0f}, {-wh.x/2.0f, wh.y/2.0f}, {wh.x/2.0f, wh.y/2.0f}, {wh.x/2.0f, -wh.y/2.0f}
};
cpShape* shape = cpPolyShapeNew(_info->getSharedBody(), 4, vec, PhysicsHelper::point2cpv(offset));
auto shape = cpPolyShapeNew(s_sharedBody, 4, vec, PhysicsHelper::point2cpv(offset));
CC_BREAK_IF(shape == nullptr);
_info->add(shape);
addShape(shape);
_area = calculateArea();
_mass = material.density == PHYSICS_INFINITY ? PHYSICS_INFINITY : material.density * _area;
@ -591,7 +581,7 @@ bool PhysicsShapeBox::init(const Size& size, const PhysicsMaterial& material/* =
Size PhysicsShapeBox::getSize() const
{
cpShape* shape = _info->getShapes().front();
cpShape* shape = _cpShapes.front();
return PhysicsHelper::cpv2size(cpv(cpvdist(cpPolyShapeGetVert(shape, 1), cpPolyShapeGetVert(shape, 2)),
cpvdist(cpPolyShapeGetVert(shape, 0), cpPolyShapeGetVert(shape, 1))));
}
@ -614,16 +604,16 @@ bool PhysicsShapePolygon::init(const Vec2* points, int count, const PhysicsMater
{
do
{
CC_BREAK_IF(!PhysicsShape::init(Type::POLYGEN));
_type = Type::POLYGEN;
cpVect* vecs = new cpVect[count];
auto vecs = new cpVect[count];
PhysicsHelper::points2cpvs(points, vecs, count);
cpShape* shape = cpPolyShapeNew(_info->getSharedBody(), count, vecs, PhysicsHelper::point2cpv(offset));
auto shape = cpPolyShapeNew(s_sharedBody, count, vecs, PhysicsHelper::point2cpv(offset));
CC_SAFE_DELETE_ARRAY(vecs);
CC_BREAK_IF(shape == nullptr);
_info->add(shape);
addShape(shape);
_area = calculateArea();
_mass = material.density == PHYSICS_INFINITY ? PHYSICS_INFINITY : material.density * _area;
@ -660,36 +650,36 @@ float PhysicsShapePolygon::calculateMoment(float mass, const Vec2* points, int c
float PhysicsShapePolygon::calculateArea()
{
cpShape* shape = _info->getShapes().front();
auto shape = _cpShapes.front();
return PhysicsHelper::cpfloat2float(cpAreaForPoly(((cpPolyShape*)shape)->numVerts, ((cpPolyShape*)shape)->verts));
}
float PhysicsShapePolygon::calculateDefaultMoment()
{
cpShape* shape = _info->getShapes().front();
auto shape = _cpShapes.front();
return _mass == PHYSICS_INFINITY ? PHYSICS_INFINITY
: PhysicsHelper::cpfloat2float(cpMomentForPoly(_mass, ((cpPolyShape*)shape)->numVerts, ((cpPolyShape*)shape)->verts, cpvzero));
}
Vec2 PhysicsShapePolygon::getPoint(int i) const
{
return PhysicsHelper::cpv2point(cpPolyShapeGetVert(_info->getShapes().front(), i));
return PhysicsHelper::cpv2point(cpPolyShapeGetVert(_cpShapes.front(), i));
}
void PhysicsShapePolygon::getPoints(Vec2* outPoints) const
{
cpShape* shape = _info->getShapes().front();
auto shape = _cpShapes.front();
PhysicsHelper::cpvs2points(((cpPolyShape*)shape)->verts, outPoints, ((cpPolyShape*)shape)->numVerts);
}
int PhysicsShapePolygon::getPointsCount() const
{
return ((cpPolyShape*)_info->getShapes().front())->numVerts;
return ((cpPolyShape*)_cpShapes.front())->numVerts;
}
Vec2 PhysicsShapePolygon::getCenter()
{
return PhysicsHelper::cpv2point(cpCentroidForPoly(((cpPolyShape*)_info->getShapes().front())->numVerts, ((cpPolyShape*)_info->getShapes().front())->verts));
return PhysicsHelper::cpv2point(cpCentroidForPoly(((cpPolyShape*)_cpShapes.front())->numVerts, ((cpPolyShape*)_cpShapes.front())->verts));
}
void PhysicsShapePolygon::update(float delta)
@ -699,7 +689,7 @@ void PhysicsShapePolygon::update(float delta)
cpFloat factorX = PhysicsHelper::float2cpfloat( _newScaleX / _scaleX );
cpFloat factorY = PhysicsHelper::float2cpfloat( _newScaleY / _scaleY );
cpShape* shape = _info->getShapes().front();
auto shape = _cpShapes.front();
int count = cpPolyShapeGetNumVerts(shape);
cpVect* vects = ((cpPolyShape*)shape)->verts;
cpSplittingPlane* planes = ((cpPolyShape*)shape)->planes;
@ -751,7 +741,7 @@ bool PhysicsShapeEdgeBox::init(const Size& size, const PhysicsMaterial& material
{
do
{
CC_BREAK_IF(!PhysicsShape::init(Type::EDGEBOX));
_type = Type::EDGEBOX;
cpVect vec[4] = {};
vec[0] = PhysicsHelper::point2cpv(Vec2(-size.width/2+offset.x, -size.height/2+offset.y));
@ -762,10 +752,10 @@ bool PhysicsShapeEdgeBox::init(const Size& size, const PhysicsMaterial& material
int i = 0;
for (; i < 4; ++i)
{
cpShape* shape = cpSegmentShapeNew(_info->getSharedBody(), vec[i], vec[(i+1)%4],
auto shape = cpSegmentShapeNew(s_sharedBody, vec[i], vec[(i + 1) % 4],
PhysicsHelper::float2cpfloat(border));
CC_BREAK_IF(shape == nullptr);
_info->add(shape);
addShape(shape);
}
CC_BREAK_IF(i < 4);
@ -799,7 +789,7 @@ bool PhysicsShapeEdgePolygon::init(const Vec2* points, int count, const PhysicsM
cpVect* vec = nullptr;
do
{
CC_BREAK_IF(!PhysicsShape::init(Type::EDGEPOLYGEN));
_type = Type::EDGEPOLYGEN;
vec = new cpVect[count];
PhysicsHelper::points2cpvs(points, vec, count);
@ -807,12 +797,12 @@ bool PhysicsShapeEdgePolygon::init(const Vec2* points, int count, const PhysicsM
int i = 0;
for (; i < count; ++i)
{
cpShape* shape = cpSegmentShapeNew(_info->getSharedBody(), vec[i], vec[(i+1)%count],
auto shape = cpSegmentShapeNew(s_sharedBody, vec[i], vec[(i + 1) % count],
PhysicsHelper::float2cpfloat(border));
CC_BREAK_IF(shape == nullptr);
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
_info->add(shape);
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
addShape(shape);
}
CC_SAFE_DELETE_ARRAY(vec);
@ -833,10 +823,10 @@ bool PhysicsShapeEdgePolygon::init(const Vec2* points, int count, const PhysicsM
Vec2 PhysicsShapeEdgePolygon::getCenter()
{
int count = (int)_info->getShapes().size();
int count = (int)_cpShapes.size();
cpVect* points = new cpVect[count];
int i = 0;
for(auto shape : _info->getShapes())
for(auto shape : _cpShapes)
{
points[i++] = ((cpSegmentShape*)shape)->a;
}
@ -850,7 +840,7 @@ Vec2 PhysicsShapeEdgePolygon::getCenter()
void PhysicsShapeEdgePolygon::getPoints(cocos2d::Vec2 *outPoints) const
{
int i = 0;
for(auto shape : _info->getShapes())
for(auto shape : _cpShapes)
{
outPoints[i++] = PhysicsHelper::cpv2point(((cpSegmentShape*)shape)->a);
}
@ -858,7 +848,7 @@ void PhysicsShapeEdgePolygon::getPoints(cocos2d::Vec2 *outPoints) const
int PhysicsShapeEdgePolygon::getPointsCount() const
{
return static_cast<int>(_info->getShapes().size());
return static_cast<int>(_cpShapes.size());
}
// PhysicsShapeEdgeChain
@ -882,7 +872,7 @@ void PhysicsShapeEdgePolygon::update(float delta)
cpFloat factorX = PhysicsHelper::float2cpfloat(_newScaleX / _scaleX);
cpFloat factorY = PhysicsHelper::float2cpfloat(_newScaleY / _scaleY);
for(auto shape : _info->getShapes())
for(auto shape : _cpShapes)
{
cpVect a = cpSegmentShapeGetA(shape);
a.x *= factorX;
@ -902,7 +892,7 @@ bool PhysicsShapeEdgeChain::init(const Vec2* points, int count, const PhysicsMat
cpVect* vec = nullptr;
do
{
CC_BREAK_IF(!PhysicsShape::init(Type::EDGECHAIN));
_type = Type::EDGECHAIN;
vec = new cpVect[count];
PhysicsHelper::points2cpvs(points, vec, count);
@ -910,12 +900,12 @@ bool PhysicsShapeEdgeChain::init(const Vec2* points, int count, const PhysicsMat
int i = 0;
for (; i < count - 1; ++i)
{
cpShape* shape = cpSegmentShapeNew(_info->getSharedBody(), vec[i], vec[i+1],
auto shape = cpSegmentShapeNew(s_sharedBody, vec[i], vec[i + 1],
PhysicsHelper::float2cpfloat(border));
CC_BREAK_IF(shape == nullptr);
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
_info->add(shape);
cpShapeSetElasticity(shape, 1.0f);
cpShapeSetFriction(shape, 1.0f);
addShape(shape);
}
CC_SAFE_DELETE_ARRAY(vec);
CC_BREAK_IF(i < count - 1);
@ -935,15 +925,15 @@ bool PhysicsShapeEdgeChain::init(const Vec2* points, int count, const PhysicsMat
Vec2 PhysicsShapeEdgeChain::getCenter()
{
int count = (int)_info->getShapes().size() + 1;
int count = (int)_cpShapes.size() + 1;
cpVect* points = new cpVect[count];
int i = 0;
for(auto shape : _info->getShapes())
for(auto shape : _cpShapes)
{
points[i++] = ((cpSegmentShape*)shape)->a;
}
points[i++] = ((cpSegmentShape*)_info->getShapes().back())->b;
points[i++] = ((cpSegmentShape*)_cpShapes.back())->b;
Vec2 center = PhysicsHelper::cpv2point(cpCentroidForPoly(count, points));
delete[] points;
@ -954,17 +944,17 @@ Vec2 PhysicsShapeEdgeChain::getCenter()
void PhysicsShapeEdgeChain::getPoints(Vec2* outPoints) const
{
int i = 0;
for(auto shape : _info->getShapes())
for(auto shape : _cpShapes)
{
outPoints[i++] = PhysicsHelper::cpv2point(((cpSegmentShape*)shape)->a);
}
outPoints[i++] = PhysicsHelper::cpv2point(((cpSegmentShape*)_info->getShapes().back())->b);
outPoints[i++] = PhysicsHelper::cpv2point(((cpSegmentShape*)_cpShapes.back())->b);
}
int PhysicsShapeEdgeChain::getPointsCount() const
{
return static_cast<int>(_info->getShapes().size() + 1);
return static_cast<int>(_cpShapes.size() + 1);
}
void PhysicsShapeEdgeChain::update(float delta)
@ -974,7 +964,7 @@ void PhysicsShapeEdgeChain::update(float delta)
cpFloat factorX = PhysicsHelper::float2cpfloat(_newScaleX / _scaleX);
cpFloat factorY = PhysicsHelper::float2cpfloat(_newScaleY / _scaleY);
for(auto shape : _info->getShapes())
for(auto shape : _cpShapes)
{
cpVect a = cpSegmentShapeGetA(shape);
a.x *= factorX;
@ -993,7 +983,7 @@ void PhysicsShape::setGroup(int group)
{
if (group < 0)
{
for (auto shape : _info->getShapes())
for (auto shape : _cpShapes)
{
cpShapeSetGroup(shape, (cpGroup)group);
}
@ -1004,7 +994,7 @@ void PhysicsShape::setGroup(int group)
bool PhysicsShape::containsPoint(const Vec2& point) const
{
for (auto shape : _info->getShapes())
for (auto shape : _cpShapes)
{
if (cpShapePointQuery(shape, PhysicsHelper::point2cpv(point)))
{

View File

@ -31,12 +31,11 @@
#include "base/CCRef.h"
#include "math/CCGeometry.h"
struct cpShape;
NS_CC_BEGIN
class PhysicsShapeInfo;
class PhysicsBody;
class PhysicsBodyInfo;
typedef struct CC_DLL PhysicsMaterial
{
@ -149,13 +148,6 @@ public:
inline int getGroup() { return _group; }
protected:
bool init(Type type);
/**
* @brief PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody.
*/
PhysicsBodyInfo* bodyInfo() const;
void setBody(PhysicsBody* body);
/** calculate the area of this shape */
@ -166,6 +158,7 @@ protected:
virtual void setScaleX(float scaleX);
virtual void setScaleY(float scaleY);
virtual void update(float delta);
void addShape(cpShape* shape);
protected:
PhysicsShape();
@ -173,7 +166,8 @@ protected:
protected:
PhysicsBody* _body;
PhysicsShapeInfo* _info;
std::vector<cpShape*> _cpShapes;
Type _type;
float _area;
float _mass;

View File

@ -24,23 +24,16 @@
#include "physics/CCPhysicsWorld.h"
#if CC_USE_PHYSICS
#include <algorithm>
#include <climits>
#include "chipmunk.h"
#include "physics/CCPhysicsBody.h"
#include "physics/CCPhysicsShape.h"
#include "CCPhysicsBody.h"
#include "CCPhysicsShape.h"
#include "CCPhysicsContact.h"
#include "physics/CCPhysicsJoint.h"
#include "CCPhysicsJoint.h"
#include "CCPhysicsContact.h"
#include "chipmunk/CCPhysicsWorldInfo_chipmunk.h"
#include "chipmunk/CCPhysicsBodyInfo_chipmunk.h"
#include "chipmunk/CCPhysicsShapeInfo_chipmunk.h"
#include "chipmunk/CCPhysicsContactInfo_chipmunk.h"
#include "chipmunk/CCPhysicsJointInfo_chipmunk.h"
#include "chipmunk/CCPhysicsHelper_chipmunk.h"
#include "CCPhysicsHelper.h"
#include "2d/CCDrawNode.h"
#include "2d/CCScene.h"
@ -48,11 +41,10 @@
#include "base/CCEventDispatcher.h"
#include "base/CCEventCustom.h"
#include <algorithm>
NS_CC_BEGIN
const float PHYSICS_INFINITY = INFINITY;
extern const char* PHYSICSCONTACT_EVENT_NAME;
extern std::unordered_map<cpShape*, PhysicsShape*> s_physicsShapeMap;
const int PhysicsWorld::DEBUGDRAW_NONE = 0x00;
const int PhysicsWorld::DEBUGDRAW_SHAPE = 0x01;
@ -108,11 +100,11 @@ int PhysicsWorldCallback::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSp
{
CP_ARBITER_GET_SHAPES(arb, a, b);
auto ita = PhysicsShapeInfo::getMap().find(a);
auto itb = PhysicsShapeInfo::getMap().find(b);
CC_ASSERT(ita != PhysicsShapeInfo::getMap().end() && itb != PhysicsShapeInfo::getMap().end());
auto ita = s_physicsShapeMap.find(a);
auto itb = s_physicsShapeMap.find(b);
CC_ASSERT(ita != s_physicsShapeMap.end() && itb != s_physicsShapeMap.end());
PhysicsContact* contact = PhysicsContact::construct(ita->second->getShape(), itb->second->getShape());
auto contact = PhysicsContact::construct(ita->second, itb->second);
arb->data = contact;
contact->_contactInfo = arb;
@ -145,12 +137,12 @@ void PhysicsWorldCallback::rayCastCallbackFunc(cpShape *shape, cpFloat t, cpVect
return;
}
auto it = PhysicsShapeInfo::getMap().find(shape);
CC_ASSERT(it != PhysicsShapeInfo::getMap().end());
auto it = s_physicsShapeMap.find(shape);
CC_ASSERT(it != s_physicsShapeMap.end());
PhysicsRayCastInfo callbackInfo =
{
it->second->getShape(),
it->second,
info->p1,
info->p2,
Vec2(info->p1.x+(info->p2.x-info->p1.x)*t, info->p1.y+(info->p2.y-info->p1.y)*t),
@ -163,34 +155,34 @@ void PhysicsWorldCallback::rayCastCallbackFunc(cpShape *shape, cpFloat t, cpVect
void PhysicsWorldCallback::queryRectCallbackFunc(cpShape *shape, RectQueryCallbackInfo *info)
{
auto it = PhysicsShapeInfo::getMap().find(shape);
auto it = s_physicsShapeMap.find(shape);
CC_ASSERT(it != PhysicsShapeInfo::getMap().end());
CC_ASSERT(it != s_physicsShapeMap.end());
if (!PhysicsWorldCallback::continues)
{
return;
}
PhysicsWorldCallback::continues = info->func(*info->world, *it->second->getShape(), info->data);
PhysicsWorldCallback::continues = info->func(*info->world, *it->second, info->data);
}
void PhysicsWorldCallback::getShapesAtPointFunc(cpShape *shape, cpFloat distance, cpVect point, Vector<PhysicsShape*>* arr)
{
auto it = PhysicsShapeInfo::getMap().find(shape);
auto it = s_physicsShapeMap.find(shape);
CC_ASSERT(it != PhysicsShapeInfo::getMap().end());
CC_ASSERT(it != s_physicsShapeMap.end());
arr->pushBack(it->second->getShape());
arr->pushBack(it->second);
}
void PhysicsWorldCallback::queryPointFunc(cpShape *shape, cpFloat distance, cpVect point, PointQueryCallbackInfo *info)
{
auto it = PhysicsShapeInfo::getMap().find(shape);
auto it = s_physicsShapeMap.find(shape);
CC_ASSERT(it != PhysicsShapeInfo::getMap().end());
CC_ASSERT(it != s_physicsShapeMap.end());
PhysicsWorldCallback::continues = info->func(*info->world, *it->second->getShape(), info->data);
PhysicsWorldCallback::continues = info->func(*info->world, *it->second, info->data);
}
void PhysicsWorld::debugDraw()
@ -343,7 +335,7 @@ void PhysicsWorld::rayCast(PhysicsRayCastCallbackFunc func, const Vec2& point1,
RayCastCallbackInfo info = { this, func, point1, point2, data };
PhysicsWorldCallback::continues = true;
cpSpaceSegmentQuery(this->_info->getSpace(),
cpSpaceSegmentQuery(_cpSpace,
PhysicsHelper::point2cpv(point1),
PhysicsHelper::point2cpv(point2),
CP_ALL_LAYERS,
@ -362,7 +354,7 @@ void PhysicsWorld::queryRect(PhysicsQueryRectCallbackFunc func, const Rect& rect
RectQueryCallbackInfo info = {this, func, data};
PhysicsWorldCallback::continues = true;
cpSpaceBBQuery(this->_info->getSpace(),
cpSpaceBBQuery(_cpSpace,
PhysicsHelper::rect2cpbb(rect),
CP_ALL_LAYERS,
CP_NO_GROUP,
@ -380,7 +372,7 @@ void PhysicsWorld::queryPoint(PhysicsQueryPointCallbackFunc func, const Vec2& po
PointQueryCallbackInfo info = {this, func, data};
PhysicsWorldCallback::continues = true;
cpSpaceNearestPointQuery(this->_info->getSpace(),
cpSpaceNearestPointQuery(_cpSpace,
PhysicsHelper::point2cpv(point),
0,
CP_ALL_LAYERS,
@ -393,7 +385,7 @@ void PhysicsWorld::queryPoint(PhysicsQueryPointCallbackFunc func, const Vec2& po
Vector<PhysicsShape*> PhysicsWorld::getShapes(const Vec2& point) const
{
Vector<PhysicsShape*> arr;
cpSpaceNearestPointQuery(this->_info->getSpace(),
cpSpaceNearestPointQuery(_cpSpace,
PhysicsHelper::point2cpv(point),
0,
CP_ALL_LAYERS,
@ -406,14 +398,14 @@ Vector<PhysicsShape*> PhysicsWorld::getShapes(const Vec2& point) const
PhysicsShape* PhysicsWorld::getShape(const Vec2& point) const
{
cpShape* shape = cpSpaceNearestPointQueryNearest(this->_info->getSpace(),
cpShape* shape = cpSpaceNearestPointQueryNearest(_cpSpace,
PhysicsHelper::point2cpv(point),
0,
CP_ALL_LAYERS,
CP_NO_GROUP,
nullptr);
return shape == nullptr ? nullptr : PhysicsShapeInfo::getMap().find(shape)->second->getShape();
return shape == nullptr ? nullptr : s_physicsShapeMap.find(shape)->second;
}
PhysicsWorld* PhysicsWorld::construct(Scene& scene)
@ -432,14 +424,14 @@ bool PhysicsWorld::init(Scene& scene)
{
do
{
_info = new (std::nothrow) PhysicsWorldInfo();
CC_BREAK_IF(_info == nullptr);
_cpSpace = cpSpaceNew();
CC_BREAK_IF(_cpSpace == nullptr);
_scene = &scene;
_info->setGravity(_gravity);
cpSpaceSetGravity(_cpSpace, PhysicsHelper::point2cpv(_gravity));
cpSpaceSetDefaultCollisionHandler(_info->getSpace(),
cpSpaceSetDefaultCollisionHandler(_cpSpace,
(cpCollisionBeginFunc)PhysicsWorldCallback::collisionBeginCallbackFunc,
(cpCollisionPreSolveFunc)PhysicsWorldCallback::collisionPreSolveCallbackFunc,
(cpCollisionPostSolveFunc)PhysicsWorldCallback::collisionPostSolveCallbackFunc,
@ -475,16 +467,10 @@ void PhysicsWorld::doAddBody(PhysicsBody* body)
{
if (body->isEnabled())
{
//is gravity enable
if (!body->isGravityEnabled())
{
body->applyForce(-_gravity * body->getMass());
}
// add body to space
if (body->isDynamic())
if (body->isDynamic() && !cpSpaceContainsBody(_cpSpace, body->_cpBody))
{
_info->addBody(*body->_info);
cpSpaceAddBody(_cpSpace, body->_cpBody);
}
// add shapes to space
@ -505,7 +491,7 @@ void PhysicsWorld::addBodyOrDelay(PhysicsBody* body)
return;
}
if (_info->isLocked())
if (cpSpaceIsLocked(_cpSpace))
{
if (_delayAddBodies.find(body) == _delayAddBodies.end())
{
@ -521,7 +507,7 @@ void PhysicsWorld::addBodyOrDelay(PhysicsBody* body)
void PhysicsWorld::updateBodies()
{
if (_info->isLocked())
if (cpSpaceIsLocked(_cpSpace))
{
return;
}
@ -599,7 +585,7 @@ void PhysicsWorld::removeBodyOrDelay(PhysicsBody* body)
return;
}
if (_info->isLocked())
if (cpSpaceIsLocked(_cpSpace))
{
if (_delayRemoveBodies.getIndex(body) == CC_INVALID_INDEX)
{
@ -614,12 +600,13 @@ void PhysicsWorld::removeBodyOrDelay(PhysicsBody* body)
void PhysicsWorld::doAddJoint(PhysicsJoint *joint)
{
if (joint == nullptr || joint->_info == nullptr)
if (joint)
{
return;
for (auto constraint : joint->_cpConstraints)
{
cpSpaceAddConstraint(_cpSpace, constraint);
}
}
_info->addJoint(*joint->_info);
}
void PhysicsWorld::removeJoint(PhysicsJoint* joint, bool destroy)
@ -665,7 +652,7 @@ void PhysicsWorld::removeJoint(PhysicsJoint* joint, bool destroy)
void PhysicsWorld::updateJoints()
{
if (_info->isLocked())
if (cpSpaceIsLocked(_cpSpace))
{
return;
}
@ -692,9 +679,15 @@ void PhysicsWorld::updateJoints()
void PhysicsWorld::removeShape(PhysicsShape* shape)
{
if (shape != nullptr)
if (shape)
{
_info->removeShape(*shape->_info);
for (auto cps : shape->_cpShapes)
{
if (cpSpaceContainsShape(_cpSpace, cps))
{
cpSpaceRemoveShape(_cpSpace, cps);
}
}
}
}
@ -707,7 +700,7 @@ void PhysicsWorld::addJointOrDelay(PhysicsJoint* joint)
return;
}
if (_info->isLocked())
if (cpSpaceIsLocked(_cpSpace))
{
if (std::find(_delayAddJoints.begin(), _delayAddJoints.end(), joint) == _delayAddJoints.end())
{
@ -729,7 +722,7 @@ void PhysicsWorld::removeJointOrDelay(PhysicsJoint* joint)
return;
}
if (_info->isLocked())
if (cpSpaceIsLocked(_cpSpace))
{
if (std::find(_delayRemoveJoints.rbegin(), _delayRemoveJoints.rend(), joint) == _delayRemoveJoints.rend())
{
@ -789,11 +782,14 @@ void PhysicsWorld::removeAllJoints(bool destroy)
_joints.clear();
}
void PhysicsWorld::addShape(PhysicsShape* shape)
void PhysicsWorld::addShape(PhysicsShape* physicsShape)
{
if (shape != nullptr)
if (physicsShape)
{
_info->addShape(*shape->_info);
for (auto shape : physicsShape->_cpShapes)
{
cpSpaceAddShape(_cpSpace, shape);
}
}
}
@ -801,12 +797,6 @@ void PhysicsWorld::doRemoveBody(PhysicsBody* body)
{
CCASSERT(body != nullptr, "the body can not be nullptr");
// reset the gravity
if (!body->isGravityEnabled())
{
body->applyForce(_gravity * body->getMass());
}
// remove shaps
for (auto& shape : body->getShapes())
{
@ -814,12 +804,18 @@ void PhysicsWorld::doRemoveBody(PhysicsBody* body)
}
// remove body
_info->removeBody(*body->_info);
if (cpSpaceContainsBody(_cpSpace, body->_cpBody))
{
cpSpaceRemoveBody(_cpSpace, body->_cpBody);
}
}
void PhysicsWorld::doRemoveJoint(PhysicsJoint* joint)
{
_info->removeJoint(*joint->_info);
for (auto constraint : joint->_cpConstraints)
{
cpSpaceRemoveConstraint(_cpSpace, constraint);
}
}
void PhysicsWorld::removeAllBodies()
@ -863,20 +859,8 @@ PhysicsBody* PhysicsWorld::getBody(int tag) const
void PhysicsWorld::setGravity(const Vect& gravity)
{
if (!_bodies.empty())
{
for (auto& body : _bodies)
{
// reset gravity for body
if (!body->isGravityEnabled())
{
body->applyForce((_gravity - gravity) * body->getMass());
}
}
}
_gravity = gravity;
_info->setGravity(gravity);
cpSpaceSetGravity(_cpSpace, PhysicsHelper::point2cpv(gravity));
}
void PhysicsWorld::setSubsteps(int steps)
@ -915,7 +899,7 @@ void PhysicsWorld::update(float delta, bool userCall/* = false*/)
if (userCall)
{
_info->step(delta);
cpSpaceStep(_cpSpace, delta);
for (auto& body : _bodies)
{
body->update(delta);
@ -929,7 +913,7 @@ void PhysicsWorld::update(float delta, bool userCall/* = false*/)
const float dt = _updateTime * _speed / _substeps;
for (int i = 0; i < _substeps; ++i)
{
_info->step(dt);
cpSpaceStep(_cpSpace, dt);
for (auto& body : _bodies)
{
body->update(dt);
@ -953,7 +937,7 @@ PhysicsWorld::PhysicsWorld()
, _updateRateCount(0)
, _updateTime(0.0f)
, _substeps(1)
, _info(nullptr)
, _cpSpace(nullptr)
, _scene(nullptr)
, _delayDirty(false)
, _autoStep(true)
@ -967,7 +951,10 @@ PhysicsWorld::~PhysicsWorld()
{
removeAllJoints(true);
removeAllBodies();
CC_SAFE_DELETE(_info);
if (_cpSpace)
{
cpSpaceFree(_cpSpace);
}
CC_SAFE_DELETE(_debugDraw);
}
@ -1000,7 +987,7 @@ void PhysicsDebugDraw::drawShape(PhysicsShape& shape)
const Color4F fillColor(1.0f, 0.0f, 0.0f, 0.3f);
const Color4F outlineColor(1.0f, 0.0f, 0.0f, 1.0f);
for (auto it = shape._info->getShapes().begin(); it != shape._info->getShapes().end(); ++it)
for (auto it = shape._cpShapes.begin(); it != shape._cpShapes.end(); ++it)
{
cpShape *subShape = *it;
@ -1056,7 +1043,7 @@ void PhysicsDebugDraw::drawJoint(PhysicsJoint& joint)
const Color4F lineColor(0.0f, 0.0f, 1.0f, 1.0f);
const Color4F jointPointColor(0.0f, 1.0f, 0.0f, 1.0f);
for (auto it = joint._info->getJoints().begin(); it != joint._info->getJoints().end(); ++it)
for (auto it = joint._cpConstraints.begin(); it != joint._cpConstraints.end(); ++it)
{
cpConstraint *constraint = *it;

View File

@ -34,11 +34,12 @@
#include "physics/CCPhysicsBody.h"
#include <list>
struct cpSpace;
NS_CC_BEGIN
class PhysicsBody;
class PhysicsJoint;
class PhysicsWorldInfo;
class PhysicsShape;
class PhysicsContact;
@ -203,7 +204,7 @@ protected:
int _updateRateCount;
float _updateTime;
int _substeps;
PhysicsWorldInfo* _info;
cpSpace* _cpSpace;
Vector<PhysicsBody*> _bodies;
std::list<PhysicsJoint*> _joints;

View File

@ -6,10 +6,5 @@ set(COCOS_PHYSICS_SRC
physics/CCPhysicsJoint.cpp
physics/CCPhysicsShape.cpp
physics/CCPhysicsWorld.cpp
physics/chipmunk/CCPhysicsBodyInfo_chipmunk.cpp
physics/chipmunk/CCPhysicsContactInfo_chipmunk.cpp
physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp
physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp
physics/chipmunk/CCPhysicsWorldInfo_chipmunk.cpp
)

View File

@ -1,41 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 "CCPhysicsBodyInfo_chipmunk.h"
#if CC_USE_PHYSICS
#include "chipmunk.h"
NS_CC_BEGIN
PhysicsBodyInfo::PhysicsBodyInfo()
: _body(nullptr)
{
}
PhysicsBodyInfo::~PhysicsBodyInfo()
{
if (_body) cpBodyFree(_body);
}
NS_CC_END
#endif // CC_USE_PHYSICS

View File

@ -1,57 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 __CCPHYSICS_BODY_INFO_CHIPMUNK_H__
#define __CCPHYSICS_BODY_INFO_CHIPMUNK_H__
#include "base/ccConfig.h"
#if CC_USE_PHYSICS
#include "platform/CCPlatformMacros.h"
#include "base/CCRef.h"
struct cpBody;
NS_CC_BEGIN
class PhysicsBodyInfo
{
public:
inline cpBody* getBody() const { return _body; }
inline void setBody(cpBody* body) { _body = body; }
private:
PhysicsBodyInfo();
~PhysicsBodyInfo();
private:
cpBody* _body;
friend class PhysicsBody;
};
NS_CC_END
#endif // CC_USE_PHYSICS
#endif // __CCPHYSICS_BODY_INFO_CHIPMUNK_H__

View File

@ -1,40 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 "CCPhysicsContactInfo_chipmunk.h"
#if CC_USE_PHYSICS
#include "chipmunk.h"
NS_CC_BEGIN
PhysicsContactInfo::PhysicsContactInfo(PhysicsContact* contact)
: _contact(contact)
{
}
PhysicsContactInfo::~PhysicsContactInfo()
{
}
NS_CC_END
#endif // CC_USE_PHYSICS

View File

@ -1,53 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 __CCPHYSICS_CONTACT_INFO_CHIPMUNK_H__
#define __CCPHYSICS_CONTACT_INFO_CHIPMUNK_H__
#include "base/ccConfig.h"
#if CC_USE_PHYSICS
#include "platform/CCPlatformMacros.h"
NS_CC_BEGIN
class PhysicsContact;
class PhysicsContactInfo
{
public:
inline PhysicsContact* getContact() const { return _contact; }
private:
PhysicsContactInfo(PhysicsContact* contact);
~PhysicsContactInfo();
private:
PhysicsContact* _contact;
friend class PhysicsContact;
};
NS_CC_END
#endif // CC_USE_PHYSICS
#endif // __CCPHYSICS_CONTACT_INFO_CHIPMUNK_H__

View File

@ -1,85 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 "CCPhysicsJointInfo_chipmunk.h"
#if CC_USE_PHYSICS
#include <algorithm>
#include <unordered_map>
#include "chipmunk.h"
NS_CC_BEGIN
std::unordered_map<cpConstraint*, PhysicsJointInfo*> PhysicsJointInfo::_map;
PhysicsJointInfo::PhysicsJointInfo(PhysicsJoint* joint)
: _joint(joint)
{
}
PhysicsJointInfo::~PhysicsJointInfo()
{
for (cpConstraint* joint : _joints)
{
cpConstraintFree(joint);
}
}
void PhysicsJointInfo::add(cpConstraint* joint)
{
if (joint == nullptr) return;
_joints.push_back(joint);
_map.insert(std::pair<cpConstraint*, PhysicsJointInfo*>(joint, this));
}
void PhysicsJointInfo::remove(cpConstraint* joint)
{
if (joint == nullptr) return;
auto it = std::find(_joints.begin(), _joints.end(), joint);
if (it != _joints.end())
{
_joints.erase(it);
auto mit = _map.find(joint);
if (mit != _map.end()) _map.erase(mit);
cpConstraintFree(joint);
}
}
void PhysicsJointInfo::removeAll()
{
for (cpConstraint* joint : _joints)
{
auto mit = _map.find(joint);
if (mit != _map.end()) _map.erase(mit);
cpConstraintFree(joint);
}
_joints.clear();
}
NS_CC_END
#endif // CC_USE_PHYSICS

View File

@ -1,65 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 __CCPHYSICS_JOINT_INFO_CHIPMUNK_H__
#define __CCPHYSICS_JOINT_INFO_CHIPMUNK_H__
#include "base/ccConfig.h"
#if CC_USE_PHYSICS
#include "platform/CCPlatformMacros.h"
#include <vector>
#include <unordered_map>
struct cpConstraint;
NS_CC_BEGIN
class PhysicsJoint;
class PhysicsJointInfo
{
public:
void add(cpConstraint* shape);
void remove(cpConstraint* shape);
void removeAll();
PhysicsJoint* getJoint() const { return _joint; }
std::vector<cpConstraint*>& getJoints() { return _joints; }
static std::unordered_map<cpConstraint*, PhysicsJointInfo*>& getMap() { return _map; }
protected:
PhysicsJointInfo(PhysicsJoint* joint);
~PhysicsJointInfo();
std::vector<cpConstraint*> _joints;
PhysicsJoint* _joint;
static std::unordered_map<cpConstraint*, PhysicsJointInfo*> _map;
friend class PhysicsJoint;
};
NS_CC_END
#endif // CC_USE_PHYSICS
#endif // __CCPHYSICS_JOINT_INFO_CHIPMUNK_H__

View File

@ -1,118 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 "CCPhysicsShapeInfo_chipmunk.h"
#if CC_USE_PHYSICS
#include <algorithm>
#include <unordered_map>
NS_CC_BEGIN
std::unordered_map<cpShape*, PhysicsShapeInfo*> PhysicsShapeInfo::_map;
cpBody* PhysicsShapeInfo::_sharedBody = nullptr;
PhysicsShapeInfo::PhysicsShapeInfo(PhysicsShape* shape)
: _shape(shape)
, _group(CP_NO_GROUP)
{
if (_sharedBody == nullptr)
{
_sharedBody = cpBodyNewStatic();
}
_body = _sharedBody;
}
PhysicsShapeInfo::~PhysicsShapeInfo()
{
for (auto shape : _shapes)
{
auto it = _map.find(shape);
if (it != _map.end()) _map.erase(shape);
cpShapeFree(shape);
}
}
void PhysicsShapeInfo::setGroup(cpGroup group)
{
this->_group = group;
for (cpShape* shape : _shapes)
{
cpShapeSetGroup(shape, group);
}
}
void PhysicsShapeInfo::setBody(cpBody* body)
{
if (this->_body != body)
{
this->_body = body;
for (cpShape* shape : _shapes)
{
cpShapeSetBody(shape, body == nullptr ? _sharedBody : body);
}
}
}
void PhysicsShapeInfo::add(cpShape* shape)
{
if (shape == nullptr) return;
cpShapeSetGroup(shape, _group);
_shapes.push_back(shape);
_map.insert(std::pair<cpShape*, PhysicsShapeInfo*>(shape, this));
}
void PhysicsShapeInfo::remove(cpShape* shape)
{
if (shape == nullptr) return;
auto it = std::find(_shapes.begin(), _shapes.end(), shape);
if (it != _shapes.end())
{
_shapes.erase(it);
auto mit = _map.find(shape);
if (mit != _map.end()) _map.erase(mit);
cpShapeFree(shape);
}
}
void PhysicsShapeInfo::removeAll()
{
for (cpShape* shape : _shapes)
{
auto mit = _map.find(shape);
if (mit != _map.end()) _map.erase(mit);
cpShapeFree(shape);
}
_shapes.clear();
}
NS_CC_END
#endif // CC_USE_PHYSICS

View File

@ -1,73 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 __CCPHYSICS_SHAPE_INFO_CHIPMUNK_H__
#define __CCPHYSICS_SHAPE_INFO_CHIPMUNK_H__
#include "base/ccConfig.h"
#if CC_USE_PHYSICS
#include <vector>
#include <unordered_map>
#include "platform/CCPlatformMacros.h"
#include "chipmunk.h"
NS_CC_BEGIN
class PhysicsShape;
class PhysicsShapeInfo
{
public:
void add(cpShape* shape);
void remove(cpShape* shape);
void removeAll();
void setGroup(cpGroup group);
void setBody(cpBody* body);
PhysicsShape* getShape() const { return _shape; }
std::vector<cpShape*>& getShapes() { return _shapes; }
cpBody* getBody() const { return _body; }
cpGroup getGourp() const { return _group; }
static std::unordered_map<cpShape*, PhysicsShapeInfo*>& getMap() { return _map; }
static cpBody* getSharedBody() { return _sharedBody; }
protected:
PhysicsShapeInfo(PhysicsShape* shape);
~PhysicsShapeInfo();
std::vector<cpShape*> _shapes;
PhysicsShape* _shape;
cpBody* _body;
cpGroup _group;
static std::unordered_map<cpShape*, PhysicsShapeInfo*> _map;
static cpBody* _sharedBody;
friend class PhysicsShape;
};
NS_CC_END
#endif // CC_USE_PHYSICS
#endif // __CCPHYSICS_SHAPE_INFO_CHIPMUNK_H__

View File

@ -1,112 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 "CCPhysicsWorldInfo_chipmunk.h"
#if CC_USE_PHYSICS
#include "CCPhysicsHelper_chipmunk.h"
#include "CCPhysicsBodyInfo_chipmunk.h"
#include "CCPhysicsShapeInfo_chipmunk.h"
#include "CCPhysicsJointInfo_chipmunk.h"
#include "chipmunk.h"
NS_CC_BEGIN
PhysicsWorldInfo::PhysicsWorldInfo()
{
_space = cpSpaceNew();
}
PhysicsWorldInfo::~PhysicsWorldInfo()
{
cpSpaceFree(_space);
}
void PhysicsWorldInfo::setGravity(const Vect& gravity)
{
cpSpaceSetGravity(_space, PhysicsHelper::point2cpv(gravity));
}
void PhysicsWorldInfo::addBody(PhysicsBodyInfo& body)
{
if (!cpSpaceContainsBody(_space, body.getBody()))
{
cpSpaceAddBody(_space, body.getBody());
}
}
void PhysicsWorldInfo::removeBody(PhysicsBodyInfo& body)
{
if (cpSpaceContainsBody(_space, body.getBody()))
{
cpSpaceRemoveBody(_space, body.getBody());
}
}
void PhysicsWorldInfo::addShape(PhysicsShapeInfo& shape)
{
for (auto cps : shape.getShapes())
{
cpSpaceAddShape(_space, cps);
}
}
void PhysicsWorldInfo::removeShape(PhysicsShapeInfo& shape)
{
for (auto cps : shape.getShapes())
{
if (cpSpaceContainsShape(_space, cps))
{
cpSpaceRemoveShape(_space, cps);
}
}
}
void PhysicsWorldInfo::addJoint(PhysicsJointInfo& joint)
{
for (auto subjoint : joint.getJoints())
{
cpSpaceAddConstraint(_space, subjoint);
}
}
void PhysicsWorldInfo::removeJoint(PhysicsJointInfo& joint)
{
for (auto subjoint : joint.getJoints())
{
cpSpaceRemoveConstraint(_space, subjoint);
}
}
bool PhysicsWorldInfo::isLocked()
{
return 0 == _space->locked_private ? false : true;
}
void PhysicsWorldInfo::step(float delta)
{
cpSpaceStep(_space, delta);
}
NS_CC_END
#endif // CC_USE_PHYSICS

View File

@ -1,71 +0,0 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 __CCPHYSICS_WORLD_INFO_CHIPMUNK_H__
#define __CCPHYSICS_WORLD_INFO_CHIPMUNK_H__
#include "base/ccConfig.h"
#if CC_USE_PHYSICS
#include <vector>
#include "platform/CCPlatformMacros.h"
#include "math/CCGeometry.h"
struct cpSpace;
NS_CC_BEGIN
typedef Vec2 Vect;
class PhysicsBodyInfo;
class PhysicsJointInfo;
class PhysicsShapeInfo;
class PhysicsWorldInfo
{
public:
cpSpace* getSpace() const { return _space; }
void addShape(PhysicsShapeInfo& shape);
void removeShape(PhysicsShapeInfo& shape);
void addBody(PhysicsBodyInfo& body);
void removeBody(PhysicsBodyInfo& body);
void addJoint(PhysicsJointInfo& joint);
void removeJoint(PhysicsJointInfo& joint);
void setGravity(const Vect& gravity);
bool isLocked();
void step(float delta);
private:
PhysicsWorldInfo();
~PhysicsWorldInfo();
private:
cpSpace* _space;
friend class PhysicsWorld;
};
NS_CC_END
#endif // CC_USE_PHYSICS
#endif // __CCPHYSICS_WORLD_INFO_CHIPMUNK_H__

View File

@ -62,6 +62,127 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
private static Cocos2dxActivity sContext = null;
private Cocos2dxVideoHelper mVideoHelper = null;
private Cocos2dxWebViewHelper mWebViewHelper = null;
public class Cocos2dxEGLConfigChooser implements GLSurfaceView.EGLConfigChooser
{
protected int[] configAttribs;
public Cocos2dxEGLConfigChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize)
{
configAttribs = new int[] {redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize};
}
public Cocos2dxEGLConfigChooser(int[] attribs)
{
configAttribs = attribs;
}
public EGLConfig selectConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs, int[] attribs)
{
for (EGLConfig config : configs) {
int d = findConfigAttrib(egl, display, config,
EGL10.EGL_DEPTH_SIZE, 0);
int s = findConfigAttrib(egl, display, config,
EGL10.EGL_STENCIL_SIZE, 0);
if ((d >= attribs[4]) && (s >= attribs[5])) {
int r = findConfigAttrib(egl, display, config,
EGL10.EGL_RED_SIZE, 0);
int g = findConfigAttrib(egl, display, config,
EGL10.EGL_GREEN_SIZE, 0);
int b = findConfigAttrib(egl, display, config,
EGL10.EGL_BLUE_SIZE, 0);
int a = findConfigAttrib(egl, display, config,
EGL10.EGL_ALPHA_SIZE, 0);
if ((r >= attribs[0]) && (g >= attribs[1])
&& (b >= attribs[2]) && (a >= attribs[3])) {
return config;
}
}
}
return null;
}
private int findConfigAttrib(EGL10 egl, EGLDisplay display,
EGLConfig config, int attribute, int defaultValue) {
int[] value = new int[1];
if (egl.eglGetConfigAttrib(display, config, attribute, value)) {
return value[0];
}
return defaultValue;
}
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
{
int[] numConfigs = new int[1];
if(egl.eglGetConfigs(display, null, 0, numConfigs))
{
EGLConfig[] configs = new EGLConfig[numConfigs[0]];
int[] EGLattribs = {
EGL10.EGL_RED_SIZE, configAttribs[0],
EGL10.EGL_GREEN_SIZE, configAttribs[1],
EGL10.EGL_BLUE_SIZE, configAttribs[2],
EGL10.EGL_ALPHA_SIZE, configAttribs[3],
EGL10.EGL_DEPTH_SIZE, configAttribs[4],
EGL10.EGL_STENCIL_SIZE,configAttribs[5],
EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
EGL10.EGL_NONE
};
int[] choosedConfigNum = new int[1];
egl.eglChooseConfig(display, EGLattribs, configs, numConfigs[0], choosedConfigNum);
if(choosedConfigNum[0]>0)
{
return selectConfig(egl, display, configs, configAttribs);
}
else
{
int[] defaultEGLattribs = {
EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_ALPHA_SIZE, 0,
EGL10.EGL_DEPTH_SIZE, 0,
EGL10.EGL_STENCIL_SIZE,0,
EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
EGL10.EGL_NONE
};
int[] defaultEGLattribsAlpha = {
EGL10.EGL_RED_SIZE, 4,
EGL10.EGL_GREEN_SIZE, 4,
EGL10.EGL_BLUE_SIZE, 4,
EGL10.EGL_ALPHA_SIZE, 4,
EGL10.EGL_DEPTH_SIZE, 0,
EGL10.EGL_STENCIL_SIZE,0,
EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
EGL10.EGL_NONE
};
int[] attribs = null;
//choose one can use
if(this.configAttribs[3] == 0)
{
egl.eglChooseConfig(display, defaultEGLattribs, configs, numConfigs[0], choosedConfigNum);
attribs = new int[]{5,6,5,0,0,0};
}
else
{
egl.eglChooseConfig(display, defaultEGLattribsAlpha, configs, numConfigs[0], choosedConfigNum);
attribs = new int[]{4,4,4,4,0,0};
}
if(choosedConfigNum[0] > 0)
{
return selectConfig(egl, display, configs, attribs);
}
else
{
Log.e(DEVICE_POLICY_SERVICE, "Can not select an EGLConfig for rendering.");
return null;
}
}
}
Log.e(DEVICE_POLICY_SERVICE, "Can not select an EGLConfig for rendering.");
return null;
}
}
public static Context getContext() {
return sContext;
@ -223,128 +344,8 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
//this line is need on some device if we specify an alpha bits
if(this.mGLContextAttrs[3] > 0) glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
class cocos2dEGLConfigChooser implements GLSurfaceView.EGLConfigChooser
{
protected int[] configAttribs;
public cocos2dEGLConfigChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize)
{
configAttribs = new int[] {redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize};
}
public cocos2dEGLConfigChooser(int[] attribs)
{
configAttribs = attribs;
}
public EGLConfig selectConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs, int[] attribs)
{
for (EGLConfig config : configs) {
int d = findConfigAttrib(egl, display, config,
EGL10.EGL_DEPTH_SIZE, 0);
int s = findConfigAttrib(egl, display, config,
EGL10.EGL_STENCIL_SIZE, 0);
if ((d >= attribs[4]) && (s >= attribs[5])) {
int r = findConfigAttrib(egl, display, config,
EGL10.EGL_RED_SIZE, 0);
int g = findConfigAttrib(egl, display, config,
EGL10.EGL_GREEN_SIZE, 0);
int b = findConfigAttrib(egl, display, config,
EGL10.EGL_BLUE_SIZE, 0);
int a = findConfigAttrib(egl, display, config,
EGL10.EGL_ALPHA_SIZE, 0);
if ((r >= attribs[0]) && (g >= attribs[1])
&& (b >= attribs[2]) && (a >= attribs[3])) {
return config;
}
}
}
return null;
}
private int findConfigAttrib(EGL10 egl, EGLDisplay display,
EGLConfig config, int attribute, int defaultValue) {
int[] value = new int[1];
if (egl.eglGetConfigAttrib(display, config, attribute, value)) {
return value[0];
}
return defaultValue;
}
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
{
int[] numConfigs = new int[1];
if(egl.eglGetConfigs(display, null, 0, numConfigs))
{
EGLConfig[] configs = new EGLConfig[numConfigs[0]];
int[] EGLattribs = {
EGL10.EGL_RED_SIZE, configAttribs[0],
EGL10.EGL_GREEN_SIZE, configAttribs[1],
EGL10.EGL_BLUE_SIZE, configAttribs[2],
EGL10.EGL_ALPHA_SIZE, configAttribs[3],
EGL10.EGL_DEPTH_SIZE, configAttribs[4],
EGL10.EGL_STENCIL_SIZE,configAttribs[5],
EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
EGL10.EGL_NONE
};
int[] choosedConfigNum = new int[1];
egl.eglChooseConfig(display, EGLattribs, configs, numConfigs[0], choosedConfigNum);
if(choosedConfigNum[0]>0)
{
return selectConfig(egl, display, configs, configAttribs);
}
else
{
int[] defaultEGLattribs = {
EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_ALPHA_SIZE, 0,
EGL10.EGL_DEPTH_SIZE, 0,
EGL10.EGL_STENCIL_SIZE,0,
EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
EGL10.EGL_NONE
};
int[] defaultEGLattribsAlpha = {
EGL10.EGL_RED_SIZE, 4,
EGL10.EGL_GREEN_SIZE, 4,
EGL10.EGL_BLUE_SIZE, 4,
EGL10.EGL_ALPHA_SIZE, 4,
EGL10.EGL_DEPTH_SIZE, 0,
EGL10.EGL_STENCIL_SIZE,0,
EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
EGL10.EGL_NONE
};
int[] attribs = null;
//choose one can use
if(this.configAttribs[3] == 0)
{
egl.eglChooseConfig(display, defaultEGLattribs, configs, numConfigs[0], choosedConfigNum);
attribs = new int[]{5,6,5,0,0,0};
}
else
{
egl.eglChooseConfig(display, defaultEGLattribsAlpha, configs, numConfigs[0], choosedConfigNum);
attribs = new int[]{4,4,4,4,0,0};
}
if(choosedConfigNum[0] > 0)
{
return selectConfig(egl, display, configs, attribs);
}
else
{
Log.e(DEVICE_POLICY_SERVICE, "Can not select an EGLConfig for rendering.");
return null;
}
}
}
Log.e(DEVICE_POLICY_SERVICE, "Can not select an EGLConfig for rendering.");
return null;
}
}
cocos2dEGLConfigChooser chooser = new cocos2dEGLConfigChooser(this.mGLContextAttrs);
Cocos2dxEGLConfigChooser chooser = new Cocos2dxEGLConfigChooser(this.mGLContextAttrs);
glSurfaceView.setEGLConfigChooser(chooser);
return glSurfaceView;

View File

@ -147,7 +147,7 @@ static Data getData(const std::string& filename, bool forString)
WCHAR wszBuf[CC_MAX_PATH] = {0};
MultiByteToWideChar(CP_UTF8, 0, fullPath.c_str(), -1, wszBuf, sizeof(wszBuf)/sizeof(wszBuf[0]));
HANDLE fileHandle = ::CreateFileW(wszBuf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, nullptr);
HANDLE fileHandle = ::CreateFileW(wszBuf, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, nullptr);
CC_BREAK_IF(fileHandle == INVALID_HANDLE_VALUE);
size = ::GetFileSize(fileHandle, nullptr);
@ -189,6 +189,9 @@ static Data getData(const std::string& filename, bool forString)
msg = msg + filename + ") failed, error code is " + errorCodeBuffer;
CCLOG("%s", msg.c_str());
if (buffer)
free(buffer);
}
else
{
@ -226,7 +229,7 @@ unsigned char* FileUtilsWin32::getFileData(const std::string& filename, const ch
WCHAR wszBuf[CC_MAX_PATH] = {0};
MultiByteToWideChar(CP_UTF8, 0, fullPath.c_str(), -1, wszBuf, sizeof(wszBuf)/sizeof(wszBuf[0]));
HANDLE fileHandle = ::CreateFileW(wszBuf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, nullptr);
HANDLE fileHandle = ::CreateFileW(wszBuf, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, nullptr);
CC_BREAK_IF(fileHandle == INVALID_HANDLE_VALUE);
*size = ::GetFileSize(fileHandle, nullptr);

View File

@ -23,13 +23,6 @@
-- @param #string name
-- @return bool#bool ret (return value: bool)
--------------------------------
-- set the PhysicsBody that let the sprite effect with physics<br>
-- note This method will set anchor point to Vec2::ANCHOR_MIDDLE if body not null, and you cann't change anchor point if node has a physics body.
-- @function [parent=#Node] setPhysicsBody
-- @param self
-- @param #cc.PhysicsBody body
--------------------------------
-- Gets the description string. It makes debugging easier.<br>
-- return A string<br>
@ -174,11 +167,6 @@
-- @param self
-- @param #function callback
--------------------------------
-- remove this node from physics world. it will remove all the physics bodies in it's children too.
-- @function [parent=#Node] removeFromPhysicsWorld
-- @param self
--------------------------------
-- removes all components
-- @function [parent=#Node] removeAllComponents
@ -373,12 +361,6 @@
-- @param #vec2_table worldPoint
-- @return vec2_table#vec2_table ret (return value: vec2_table)
--------------------------------
-- get the PhysicsBody the sprite have
-- @function [parent=#Node] getPhysicsBody
-- @param self
-- @return PhysicsBody#PhysicsBody ret (return value: cc.PhysicsBody)
--------------------------------
-- @overload self, float, float
-- @overload self, vec2_table

View File

@ -332,6 +332,12 @@
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
--
-- @function [parent=#PhysicsBody] getCPBody
-- @param self
-- @return cpBody#cpBody ret (return value: cpBody)
--------------------------------
-- get angular damping.
-- @function [parent=#PhysicsBody] getAngularDamping

View File

@ -4,12 +4,6 @@
-- @extend Node
-- @parent_module cc
--------------------------------
--
-- @function [parent=#Scene] getPhysicsWorld
-- @param self
-- @return PhysicsWorld#PhysicsWorld ret (return value: cc.PhysicsWorld)
--------------------------------
-- render the scene
-- @function [parent=#Scene] render
@ -29,12 +23,6 @@
-- @param self
-- @return Scene#Scene ret (return value: cc.Scene)
--------------------------------
--
-- @function [parent=#Scene] createWithPhysics
-- @param self
-- @return Scene#Scene ret (return value: cc.Scene)
--------------------------------
-- @overload self, cc.Node, int, string
-- @overload self, cc.Node, int, int

View File

@ -2964,55 +2964,6 @@ int lua_cocos2dx_Node_removeComponent(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_Node_setPhysicsBody(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Node* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Node_setPhysicsBody'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
cocos2d::PhysicsBody* arg0;
ok &= luaval_to_object<cocos2d::PhysicsBody>(tolua_S, 2, "cc.PhysicsBody",&arg0);
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Node_setPhysicsBody'", nullptr);
return 0;
}
cobj->setPhysicsBody(arg0);
return 0;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Node:setPhysicsBody",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Node_setPhysicsBody'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Node_getDescription(lua_State* tolua_S)
{
int argc = 0;
@ -3894,52 +3845,6 @@ int lua_cocos2dx_Node_setonEnterTransitionDidFinishCallback(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_Node_removeFromPhysicsWorld(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Node* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Node_removeFromPhysicsWorld'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Node_removeFromPhysicsWorld'", nullptr);
return 0;
}
cobj->removeFromPhysicsWorld();
return 0;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Node:removeFromPhysicsWorld",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Node_removeFromPhysicsWorld'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Node_removeAllComponents(lua_State* tolua_S)
{
int argc = 0;
@ -5277,53 +5182,6 @@ int lua_cocos2dx_Node_convertToNodeSpace(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_Node_getPhysicsBody(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Node* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Node_getPhysicsBody'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Node_getPhysicsBody'", nullptr);
return 0;
}
cocos2d::PhysicsBody* ret = cobj->getPhysicsBody();
object_to_luaval<cocos2d::PhysicsBody>(tolua_S, "cc.PhysicsBody",(cocos2d::PhysicsBody*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Node:getPhysicsBody",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Node_getPhysicsBody'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Node_setPosition(lua_State* tolua_S)
{
int argc = 0;
@ -9474,7 +9332,6 @@ int lua_register_cocos2dx_Node(lua_State* tolua_S)
tolua_beginmodule(tolua_S,"Node");
tolua_function(tolua_S,"addChild",lua_cocos2dx_Node_addChild);
tolua_function(tolua_S,"removeComponent",lua_cocos2dx_Node_removeComponent);
tolua_function(tolua_S,"setPhysicsBody",lua_cocos2dx_Node_setPhysicsBody);
tolua_function(tolua_S,"getDescription",lua_cocos2dx_Node_getDescription);
tolua_function(tolua_S,"setRotationSkewY",lua_cocos2dx_Node_setRotationSkewY);
tolua_function(tolua_S,"setOpacityModifyRGB",lua_cocos2dx_Node_setOpacityModifyRGB);
@ -9493,7 +9350,6 @@ int lua_register_cocos2dx_Node(lua_State* tolua_S)
tolua_function(tolua_S,"setScaleX",lua_cocos2dx_Node_setScaleX);
tolua_function(tolua_S,"setRotationSkewX",lua_cocos2dx_Node_setRotationSkewX);
tolua_function(tolua_S,"setonEnterTransitionDidFinishCallback",lua_cocos2dx_Node_setonEnterTransitionDidFinishCallback);
tolua_function(tolua_S,"removeFromPhysicsWorld",lua_cocos2dx_Node_removeFromPhysicsWorld);
tolua_function(tolua_S,"removeAllComponents",lua_cocos2dx_Node_removeAllComponents);
tolua_function(tolua_S,"getOpacity",lua_cocos2dx_Node_getOpacity);
tolua_function(tolua_S,"setCameraMask",lua_cocos2dx_Node_setCameraMask);
@ -9521,7 +9377,6 @@ int lua_register_cocos2dx_Node(lua_State* tolua_S)
tolua_function(tolua_S,"getNodeToParentTransform",lua_cocos2dx_Node_getNodeToParentTransform);
tolua_function(tolua_S,"convertTouchToNodeSpaceAR",lua_cocos2dx_Node_convertTouchToNodeSpaceAR);
tolua_function(tolua_S,"convertToNodeSpace",lua_cocos2dx_Node_convertToNodeSpace);
tolua_function(tolua_S,"getPhysicsBody",lua_cocos2dx_Node_getPhysicsBody);
tolua_function(tolua_S,"setPosition",lua_cocos2dx_Node_setPosition);
tolua_function(tolua_S,"stopActionByTag",lua_cocos2dx_Node_stopActionByTag);
tolua_function(tolua_S,"reorderChild",lua_cocos2dx_Node_reorderChild);
@ -9614,53 +9469,6 @@ int lua_register_cocos2dx_Node(lua_State* tolua_S)
return 1;
}
int lua_cocos2dx_Scene_getPhysicsWorld(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Scene* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Scene",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Scene*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Scene_getPhysicsWorld'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Scene_getPhysicsWorld'", nullptr);
return 0;
}
cocos2d::PhysicsWorld* ret = cobj->getPhysicsWorld();
object_to_luaval<cocos2d::PhysicsWorld>(tolua_S, "cc.PhysicsWorld",(cocos2d::PhysicsWorld*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Scene:getPhysicsWorld",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Scene_getPhysicsWorld'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Scene_render(lua_State* tolua_S)
{
int argc = 0;
@ -9780,40 +9588,6 @@ int lua_cocos2dx_Scene_create(lua_State* tolua_S)
#endif
return 0;
}
int lua_cocos2dx_Scene_createWithPhysics(lua_State* tolua_S)
{
int argc = 0;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertable(tolua_S,1,"cc.Scene",0,&tolua_err)) goto tolua_lerror;
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Scene_createWithPhysics'", nullptr);
return 0;
}
cocos2d::Scene* ret = cocos2d::Scene::createWithPhysics();
object_to_luaval<cocos2d::Scene>(tolua_S, "cc.Scene",(cocos2d::Scene*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "cc.Scene:createWithPhysics",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Scene_createWithPhysics'.",&tolua_err);
#endif
return 0;
}
static int lua_cocos2dx_Scene_finalize(lua_State* tolua_S)
{
printf("luabindings: finalizing LUA object (Scene)");
@ -9826,11 +9600,9 @@ int lua_register_cocos2dx_Scene(lua_State* tolua_S)
tolua_cclass(tolua_S,"Scene","cc.Scene","cc.Node",nullptr);
tolua_beginmodule(tolua_S,"Scene");
tolua_function(tolua_S,"getPhysicsWorld",lua_cocos2dx_Scene_getPhysicsWorld);
tolua_function(tolua_S,"render",lua_cocos2dx_Scene_render);
tolua_function(tolua_S,"createWithSize", lua_cocos2dx_Scene_createWithSize);
tolua_function(tolua_S,"create", lua_cocos2dx_Scene_create);
tolua_function(tolua_S,"createWithPhysics", lua_cocos2dx_Scene_createWithPhysics);
tolua_endmodule(tolua_S);
std::string typeName = typeid(cocos2d::Scene).name();
g_luaType[typeName] = "cc.Scene";

View File

@ -1618,11 +1618,6 @@ int register_all_cocos2dx(lua_State* tolua_S);

View File

@ -4839,6 +4839,53 @@ int lua_cocos2dx_physics_PhysicsBody_isRotationEnabled(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_physics_PhysicsBody_getCPBody(lua_State* tolua_S)
{
int argc = 0;
cocos2d::PhysicsBody* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsBody",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::PhysicsBody*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_PhysicsBody_getCPBody'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics_PhysicsBody_getCPBody'", nullptr);
return 0;
}
cpBody* ret = cobj->getCPBody();
#pragma warning NO CONVERSION FROM NATIVE FOR cpBody*;
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsBody:getCPBody",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsBody_getCPBody'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_physics_PhysicsBody_getAngularDamping(lua_State* tolua_S)
{
int argc = 0;
@ -5790,6 +5837,7 @@ int lua_register_cocos2dx_physics_PhysicsBody(lua_State* tolua_S)
tolua_function(tolua_S,"setPositionOffset",lua_cocos2dx_physics_PhysicsBody_setPositionOffset);
tolua_function(tolua_S,"setRotationEnable",lua_cocos2dx_physics_PhysicsBody_setRotationEnable);
tolua_function(tolua_S,"isRotationEnabled",lua_cocos2dx_physics_PhysicsBody_isRotationEnabled);
tolua_function(tolua_S,"getCPBody",lua_cocos2dx_physics_PhysicsBody_getCPBody);
tolua_function(tolua_S,"getAngularDamping",lua_cocos2dx_physics_PhysicsBody_getAngularDamping);
tolua_function(tolua_S,"getVelocityAtLocalPoint",lua_cocos2dx_physics_PhysicsBody_getVelocityAtLocalPoint);
tolua_function(tolua_S,"isResting",lua_cocos2dx_physics_PhysicsBody_isResting);

View File

@ -266,6 +266,7 @@ int register_all_cocos2dx_physics(lua_State* tolua_S);
#endif // __cocos2dx_physics_h__

View File

@ -414,6 +414,7 @@ bool luaval_to_blendfunc(lua_State* L, int lo, cocos2d::BlendFunc* outValue, con
return ok;
}
#if CC_USE_PHYSICS
bool luaval_to_physics_material(lua_State* L,int lo,PhysicsMaterial* outValue, const char* funcName)
{
if (NULL == L || NULL == outValue)
@ -450,6 +451,7 @@ bool luaval_to_physics_material(lua_State* L,int lo,PhysicsMaterial* outValue, c
}
return ok;
}
#endif //#if CC_USE_PHYSICS
bool luaval_to_ssize(lua_State* L,int lo, ssize_t* outValue, const char* funcName)
{
@ -2103,6 +2105,7 @@ void vec4_to_luaval(lua_State* L,const cocos2d::Vec4& vec4)
lua_rawset(L, -3);
}
#if CC_USE_PHYSICS
void physics_material_to_luaval(lua_State* L,const PhysicsMaterial& pm)
{
if (nullptr == L)
@ -2179,6 +2182,7 @@ void physics_contactdata_to_luaval(lua_State* L, const PhysicsContactData* data)
lua_pushnumber(L, data->POINT_MAX);
lua_rawset(L, -3);
}
#endif //#if CC_USE_PHYSICS
void size_to_luaval(lua_State* L,const Size& sz)
{

View File

@ -63,7 +63,9 @@ extern bool luaval_to_rect(lua_State* L,int lo,Rect* outValue, const char* funcN
extern bool luaval_to_color3b(lua_State* L,int lo,Color3B* outValue, const char* funcName = "");
extern bool luaval_to_color4b(lua_State* L,int lo,Color4B* outValue, const char* funcName = "");
extern bool luaval_to_color4f(lua_State* L,int lo,Color4F* outValue, const char* funcName = "");
#if CC_USE_PHYSICS
extern bool luaval_to_physics_material(lua_State* L,int lo, cocos2d::PhysicsMaterial* outValue, const char* funcName = "");
#endif //#if CC_USE_PHYSICS
extern bool luaval_to_affinetransform(lua_State* L,int lo, AffineTransform* outValue, const char* funcName = "");
extern bool luaval_to_fontdefinition(lua_State* L, int lo, FontDefinition* outValue , const char* funcName = "");
extern bool luaval_to_mat4(lua_State* L, int lo, cocos2d::Mat4* outValue , const char* funcName = "");
@ -247,9 +249,11 @@ extern void rect_to_luaval(lua_State* L,const Rect& rt);
extern void color3b_to_luaval(lua_State* L,const Color3B& cc);
extern void color4b_to_luaval(lua_State* L,const Color4B& cc);
extern void color4f_to_luaval(lua_State* L,const Color4F& cc);
#if CC_USE_PHYSICS
extern void physics_material_to_luaval(lua_State* L,const PhysicsMaterial& pm);
extern void physics_raycastinfo_to_luaval(lua_State* L, const PhysicsRayCastInfo& info);
extern void physics_contactdata_to_luaval(lua_State* L, const PhysicsContactData* data);
#endif //#if CC_USE_PHYSICS
extern void affinetransform_to_luaval(lua_State* L,const AffineTransform& inValue);
extern void fontdefinition_to_luaval(lua_State* L,const FontDefinition& inValue);
extern void array_to_luaval(lua_State* L, __Array* inValue);

View File

@ -2371,6 +2371,155 @@ tolua_lerror:
return 0;
}
#if CC_USE_PHYSICS
int lua_cocos2dx_Node_setPhysicsBody(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Node* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Node_setPhysicsBody'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 1)
{
cocos2d::PhysicsBody* arg0;
ok &= luaval_to_object<cocos2d::PhysicsBody>(tolua_S, 2, "cc.PhysicsBody",&arg0);
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Node_setPhysicsBody'", nullptr);
return 0;
}
cobj->setPhysicsBody(arg0);
return 0;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Node:setPhysicsBody",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Node_setPhysicsBody'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Node_removeFromPhysicsWorld(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Node* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Node_removeFromPhysicsWorld'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Node_removeFromPhysicsWorld'", nullptr);
return 0;
}
cobj->removeFromPhysicsWorld();
return 0;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Node:removeFromPhysicsWorld",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Node_removeFromPhysicsWorld'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Node_getPhysicsBody(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Node* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Node_getPhysicsBody'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Node_getPhysicsBody'", nullptr);
return 0;
}
cocos2d::PhysicsBody* ret = cobj->getPhysicsBody();
object_to_luaval<cocos2d::PhysicsBody>(tolua_S, "cc.PhysicsBody",(cocos2d::PhysicsBody*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Node:getPhysicsBody",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Node_getPhysicsBody'.",&tolua_err);
#endif
return 0;
}
#endif //CC_USE_PHYSICS
static int tolua_cocos2d_Spawn_create(lua_State* tolua_S)
{
if (NULL == tolua_S)
@ -4300,6 +4449,111 @@ tolua_lerror:
return 0;
}
#if CC_USE_PHYSICS
int lua_cocos2dx_Scene_getPhysicsWorld(lua_State* tolua_S)
{
int argc = 0;
cocos2d::Scene* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.Scene",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::Scene*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Scene_getPhysicsWorld'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Scene_getPhysicsWorld'", nullptr);
return 0;
}
cocos2d::PhysicsWorld* ret = cobj->getPhysicsWorld();
object_to_luaval<cocos2d::PhysicsWorld>(tolua_S, "cc.PhysicsWorld",(cocos2d::PhysicsWorld*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Scene:getPhysicsWorld",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Scene_getPhysicsWorld'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_Scene_createWithPhysics(lua_State* tolua_S)
{
int argc = 0;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertable(tolua_S,1,"cc.Scene",0,&tolua_err)) goto tolua_lerror;
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Scene_createWithPhysics'", nullptr);
return 0;
}
cocos2d::Scene* ret = cocos2d::Scene::createWithPhysics();
object_to_luaval<cocos2d::Scene>(tolua_S, "cc.Scene",(cocos2d::Scene*)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "cc.Scene:createWithPhysics",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Scene_createWithPhysics'.",&tolua_err);
#endif
return 0;
}
#endif //CC_USE_PHYSICS
static void extendScene(lua_State* tolua_S)
{
lua_pushstring(tolua_S, "cc.Scene");
lua_rawget(tolua_S, LUA_REGISTRYINDEX);
if (lua_istable(tolua_S,-1))
{
#if CC_USE_PHYSICS
lua_pushstring(tolua_S, "getPhysicsWorld");
lua_pushcfunction(tolua_S, lua_cocos2dx_Scene_getPhysicsWorld);
lua_rawset(tolua_S, -3);
lua_pushstring(tolua_S, "createWithPhysics");
lua_pushcfunction(tolua_S, lua_cocos2dx_Scene_createWithPhysics);
lua_rawset(tolua_S, -3);
#endif
}
lua_pop(tolua_S, 1);
}
static void extendTexture2D(lua_State* tolua_S)
{
lua_pushstring(tolua_S, "cc.Texture2D");
@ -4449,6 +4703,18 @@ static void extendNode(lua_State* tolua_S)
lua_pushstring(tolua_S, "setRotationQuat");
lua_pushcfunction(tolua_S, lua_cocos2dx_Node_setRotationQuat);
lua_rawset(tolua_S, -3);
#if CC_USE_PHYSICS
lua_pushstring(tolua_S, "setPhysicsBody");
lua_pushcfunction(tolua_S, lua_cocos2dx_Node_setPhysicsBody);
lua_rawset(tolua_S, -3);
lua_pushstring(tolua_S, "removeFromPhysicsWorld");
lua_pushcfunction(tolua_S, lua_cocos2dx_Node_removeFromPhysicsWorld);
lua_rawset(tolua_S, -3);
lua_pushstring(tolua_S, "getPhysicsBody");
lua_pushcfunction(tolua_S, lua_cocos2dx_Node_getPhysicsBody);
lua_rawset(tolua_S, -3);
#endif //CC_USE_PHYSICS
}
lua_pop(tolua_S, 1);
}
@ -6961,6 +7227,7 @@ int register_all_cocos2dx_manual(lua_State* tolua_S)
return 0;
extendNode(tolua_S);
extendScene(tolua_S);
extendLayer(tolua_S);
extendMenuItem(tolua_S);
extendMenuItemImage(tolua_S);

View File

@ -370,7 +370,7 @@ function display.newSprite(source, x, y, params)
sprite = spriteClass:create(source, params.rect, params.capInsets)
end
if display.TEXTURES_PIXEL_FORMAT[source] then
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2D_PIXEL_FORMAT_RGBA8888)
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_BGR_A8888)
end
break
elseif sourceType ~= "userdata" then
@ -495,7 +495,7 @@ function display.loadSpriteFrames(dataFilename, imageFilename, callback)
spriteFrameCache:addSpriteFramesAsync(dataFilename, imageFilename, callback)
end
if display.TEXTURES_PIXEL_FORMAT[imageFilename] then
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2D_PIXEL_FORMAT_RGBA8888)
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_BGR_A8888)
end
end

View File

@ -172,3 +172,61 @@ If the selected state texture is missing, when user press the widget, the normal
If the disable state texture is missing, when the widget is in disable state, we use gray shader to turn the normal state texture to gray.
The original ui::Button also support the gray shader enhancement.
### Custom Allocators
in ccConfig.h you can control the custom allocator system with the following defines.
```c++
#define CC_ENABLE_ALLOCATOR 1
#define CC_ENABLE_ALLOCATOR_DIAGNOSTICS CC_ENABLE_ALLOCATOR
#define CC_ENABLE_ALLOCATOR_GLOBAL_NEW_DELETE 0
#define CC_ALLOCATOR_GLOBAL cocos2d::allocator::AllocatorStrategyDefault
#define CC_ALLOCATOR_GLOBAL_NEW_DELETE cocos2d::allocator::AllocatorStrategyGlobalSmallBlock
```
__CC_ENABLE_ALLOCATOR__ turns everything on or off. When set to 0, everything should still build, but all custom allocator code is disabled or removed. This is handled mainly through macros, but if you implement new allocator strategies, you should be aware of, and respect this preprocessor directive.
__CC_ENABLE_ALLOCATOR_DIAGNOSTICS__ defaults to the same value as __CC_ENABLE_ALLOCATOR__, but setting this to 0 will disable allocator diagnostics via the control panel. Diagnostics have significant overhead, so you definitely want to disable them for production builds.
__CC_ENABLE_ALLOCATOR_GLOBAL_NEW_DELETE__ enables overriding of the global __new__ and __delete__ operators. The allocator strategy used can be selected by setting the __CC_ALLOCATOR_GLOBAL_NEW_DELETE__ define.
__CC_ALLOCATOR_GLOBAL__ defines the allocator strategy to use for global allocations. All memory needed by other allocators will use this global allocator, as well as the macros __CC_MALLOC__, __CC_FREE__ etc.
Third party libraries that use malloc/free will continue to use the original malloc/free so their memory usage will not be tracked.
Calls to new/delete from shared libraries should work ok provided the library is loaded after the allocator has initialized, which should be the case, unless you load a shared library from a static variable initialization.
#### Default Allocator
The default allocator wraps malloc and free and provides an allocator interface that anyone can use to allocate blocks of memory. Tracking is not currently enabled here, but can be added in the future.
#### General Allocator
The general allocator provides a series of fixed sized allocators from the smallest allocation size of 4 bytes up to some threshold which currently defaults to 8 Kbytes. Anything larger than this threshold will fallback to the default allocator. See fixed allocators for more details.
#### Fixed Block Allocator
Fixed block allocators provide a memory pool of blocks of fixed size. They are extremely fast since no searching for best fit is required, they can simply pop the first block off a list and return that. Similarly, freeing memory is also extremely fast since they just push the block on the front of the list. Memory is not actually freed, it is kept allocated and track on a free list. It will be possible to reduce the allocated memory by freeing up unused pages of memory from the list.
#### Pool Allocator
Implements a custom fixed block allocator for a specific type. You can override local new/delete for types that are classes or structs using __CC_USE_ALLOCATOR_POOL(pool)__. Additionally, these allocators are configurable in terms of the initial size.
### Implementing Custom Allocators for Objects
Simply add a static instance of the pool allocator to your class, and use the __CC_USE_ALLOCATOR_POOL__ macro to implement operators __new__ and __delete__ for your class.
```c++
class SomeClass
{
public:
cocos2d::allocator::AllocatorStrategyPool<SomeClass> _allocator;
CC_USE_ALLOCATOR_POOL(SomeClass, _allocator);
};
```
### Console (allocator command, tags, counts etc)
You can connect to the running app using the console. I.e. __telnet localhost 5678__ and issue the __allocator__ command to dump out all allocator diagnostic information. One of the useful pieces of information is the highest count for pool allocators. You can plug this value back into the initial size for the allocator to preallocate this number of objects when starting, improving startup speed significantly.

View File

@ -816,6 +816,7 @@
"cocos/physics/CCPhysicsBody.h",
"cocos/physics/CCPhysicsContact.cpp",
"cocos/physics/CCPhysicsContact.h",
"cocos/physics/CCPhysicsHelper.h",
"cocos/physics/CCPhysicsJoint.cpp",
"cocos/physics/CCPhysicsJoint.h",
"cocos/physics/CCPhysicsShape.cpp",
@ -823,17 +824,6 @@
"cocos/physics/CCPhysicsWorld.cpp",
"cocos/physics/CCPhysicsWorld.h",
"cocos/physics/CMakeLists.txt",
"cocos/physics/chipmunk/CCPhysicsBodyInfo_chipmunk.cpp",
"cocos/physics/chipmunk/CCPhysicsBodyInfo_chipmunk.h",
"cocos/physics/chipmunk/CCPhysicsContactInfo_chipmunk.cpp",
"cocos/physics/chipmunk/CCPhysicsContactInfo_chipmunk.h",
"cocos/physics/chipmunk/CCPhysicsHelper_chipmunk.h",
"cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp",
"cocos/physics/chipmunk/CCPhysicsJointInfo_chipmunk.h",
"cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp",
"cocos/physics/chipmunk/CCPhysicsShapeInfo_chipmunk.h",
"cocos/physics/chipmunk/CCPhysicsWorldInfo_chipmunk.cpp",
"cocos/physics/chipmunk/CCPhysicsWorldInfo_chipmunk.h",
"cocos/platform/CCApplication.h",
"cocos/platform/CCApplicationProtocol.h",
"cocos/platform/CCCommon.h",

View File

@ -21,6 +21,31 @@ CurlTest::CurlTest()
_label->retain();
}
struct MemoryStruct {
char *memory;
size_t size;
};
static size_t
WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)userp;
mem->memory = (char*)realloc(mem->memory, mem->size + realsize + 1);
if(mem->memory == NULL) {
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
return 0;
}
memcpy(&(mem->memory[mem->size]), contents, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
return realsize;
}
// the test code is
// http://curl.haxx.se/mail/lib-2009-12/0071.html
@ -30,16 +55,27 @@ void CurlTest::onTouchesEnded(const std::vector<Touch*>& touches, Event *event)
CURLcode res;
char buffer[10];
struct MemoryStruct chunk;
chunk.memory = (char*)malloc(1); /* will be grown as needed by the realloc above */
chunk.size = 0; /* no data at this point */
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://webtest.cocos2d-x.org/curltest");
//code from http://curl.haxx.se/libcurl/c/getinmemory.html
/* we pass our 'chunk' struct to the callback function */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
//If we don't provide a write function for curl, it will recieve error code 23 on windows.
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
if (res == 0)
{
_label->setString("Connect successfully!");
_label->setString(StringUtils::format("Connect successfully!\n%s", chunk.memory));
}
else
{

View File

@ -278,6 +278,8 @@ DrawNodeTest::DrawNodeTest()
// draw a rectangle
draw->drawRect(Vec2(23,23), Vec2(7,7), Color4F(1,1,0,1));
draw->drawRect(Vec2(15,30), Vec2(30,15), Vec2(15,0), Vec2(0,15), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
// draw a circle
draw->drawCircle(VisibleRect::center() + Vec2(140,0), 100, CC_DEGREES_TO_RADIANS(90), 50, true, 1.0f, 2.0f, Color4F(1.0, 0.0, 0.0, 0.5));

@ -1 +1 @@
Subproject commit 0da825a0256ff8f7edc33b4930ecdc703eaebe41
Subproject commit 77aca3d1b5d8baf8b0a24078707522d464e81e01

View File

@ -35,7 +35,7 @@ classes = New.* Sprite.* Scene Node.* Director Layer.* Menu.* Touch .*Action.* M
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
# functions from all classes.
skip = Node::[setGLServerState description getUserObject .*UserData getGLServerState .*schedule getPosition$ setContentSize setAnchorPoint enumerateChildren getonEnterTransitionDidFinishCallback getOnEnterCallback getOnExitCallback getonExitTransitionDidStartCallback setAdditionalTransform setRotationQuat getRotationQuat],
skip = Node::[setGLServerState description getUserObject .*UserData getGLServerState .*schedule getPosition$ setContentSize setAnchorPoint enumerateChildren getonEnterTransitionDidFinishCallback getOnEnterCallback getOnExitCallback getonExitTransitionDidStartCallback setAdditionalTransform setRotationQuat getRotationQuat .*(Physics).*],
Sprite::[getQuad getBlendFunc ^setPosition$ setBlendFunc],
SpriteBatchNode::[getBlendFunc setBlendFunc getDescendants],
MotionStreak::[getBlendFunc setBlendFunc draw update],
@ -126,7 +126,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS
TurnOffTiles::[shuffle],
LabelTTF::[*],
LabelBMFont::[*],
Scene::[getCameras getLights],
Scene::[getCameras getLights .*(Physics).*],
Animate3D::[*],
Sprite3D::[*],
AttachNode::[*],