Merge branch 'v3' into renderFix

Conflicts:
	tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp
	tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.h
This commit is contained in:
Nite Luo 2015-01-12 20:43:55 -08:00
commit 1c10ae43bc
177 changed files with 6292 additions and 4946 deletions

10
AUTHORS
View File

@ -815,6 +815,7 @@ Developers:
Precompiled headers improvements
Added Application::openUrl for all supported platforms ecept WP8 and WinRT
Scale9Sprite capInsets set fix
Clang static analyzer crash fix
youknowone
Adds iOS-like elastic bounceback support for cocos2d::extension::ScrollView
@ -1062,6 +1063,15 @@ Developers:
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
takaokato
Fix wrong result in Node:getParenttoNodeTransform() if node is transformed
AknEp
Fix FileUtils::fullPathForFilename return empty string if file not found
Retired Core Developers:
WenSheng Yang
Author of windows port, CCTextField,

View File

@ -1,12 +1,26 @@
cocos2d-x-3.4 Jan.15 2015
[NEW] VertexBuffer&IndexBuffer: allow setting usage(GL_STATIC_DRAW or GL_DYNAMIC_DRAW) in create method
[FIX] GLProgramState: may cause GL_INVALID_VALUE error at start up on Android
cocos2d-x-3.4rc0 Jan.9 2015
[NEW] 3rd: update libcurl to v7.39
[NEW] 3rd: update luajit to v2.0.3
[FIX] C++: crash when run clang static analyzer in Xcode
[FIX] DrawNode: can not set color when DrawPoints, wrong behavior of drawRect
[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] GLProgramState: Assert error because uniforms and attribute is not refreshed when come to foreground on android
[FIX] HttpClient: http requests will be lost in immediately mode on iOS
[FIX] JumpTo: can not be applied more than once
[FIX] Label: may cause infinite loop if using system font on Android
[FIX] Particle: GL_INVALID_OPERATION error because VAO and VBOs is not reset when come to foreground on android
[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] Template: multiple dex files define error on Android if using Eclipse to build new generated application
[FIX] VideoPlayer: can not play video if passing path returned from FileUtils::fullPathForFilename() on Android
[FIX] WP8: compiling error on ARM architecture
cocos2d-x-3.4beta0 Dec.31 2014

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

@ -148,7 +148,6 @@ bool Speed::isDone() const
Speed *Speed::reverse() const
{
return Speed::create(_innerAction->reverse(), _speed);
}

View File

@ -138,7 +138,6 @@ Vec2 PointArray::getControlPointAtIndex(ssize_t index)
void PointArray::replaceControlPoint(cocos2d::Vec2 &controlPoint, ssize_t index)
{
Vec2 *temp = _controlPoints->at(index);
temp->x = controlPoint.x;
temp->y = controlPoint.y;
@ -390,7 +389,6 @@ CardinalSplineBy* CardinalSplineBy::reverse() const
p = current;
}
// convert to "diffs" to "reverse absolute"
PointArray *pReverse = copyConfig->reverse();
@ -535,7 +533,6 @@ CatmullRomBy* CatmullRomBy::reverse() const
p = current;
}
// convert to "diffs" to "reverse absolute"
PointArray *reverse = copyConfig->reverse();
@ -562,4 +559,3 @@ CatmullRomBy* CatmullRomBy::reverse() const
}
NS_CC_END;

View File

@ -744,4 +744,3 @@ void Twirl::update(float time)
}
NS_CC_END

View File

@ -859,12 +859,6 @@ void RotateTo::update(float time)
}
else
{
// _startAngle.x != _startAngle.y || _diffAngle.x != _diffAngle.y
if (_target->getPhysicsBody() != nullptr)
{
CCLOG("RotateTo WARNING: PhysicsBody doesn't support skew rotation");
}
_target->setRotationSkewX(_startAngle.x + _diffAngle.x * time);
_target->setRotationSkewY(_startAngle.y + _diffAngle.y * time);
}
@ -1002,12 +996,6 @@ void RotateBy::update(float time)
}
else
{
// _startAngle.x != _startAngle.y || _deltaAngle.x != _deltaAngle.y
if (_target->getPhysicsBody() != nullptr)
{
CCLOG("RotateBy WARNING: PhysicsBody doesn't support skew rotation");
}
_target->setRotationSkewX(_startAngle.x + _deltaAngle.x * time);
_target->setRotationSkewY(_startAngle.y + _deltaAngle.y * time);
}
@ -1450,6 +1438,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 +1472,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

@ -129,4 +129,3 @@ void ProgressFromTo::update(float time)
}
NS_CC_END

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

@ -102,5 +102,3 @@ const char * Font::getCurrentGlyphCollection() const
NS_CC_END

View File

@ -497,7 +497,6 @@ std::set<unsigned int>* BMFontConfiguration::parseBinaryConfigFile(unsigned char
for (unsigned long i = 0; i < count; i++)
{
uint32_t first = 0; memcpy(&first, pData + (i * 10), 4);
uint32_t second = 0; memcpy(&second, pData + (i * 10) + 4, 4);
int16_t amount = 0; memcpy(&amount, pData + (i * 10) + 8, 2);

View File

@ -412,4 +412,3 @@ void MotionStreak::draw(Renderer *renderer, const Mat4 &transform, uint32_t flag
}
NS_CC_END

View File

@ -60,7 +60,6 @@ THE SOFTWARE.
#define RENDER_IN_SUBPIXEL(__ARGS__) (ceil(__ARGS__))
#endif
extern int g_physicsSceneCount;
NS_CC_BEGIN
@ -125,6 +124,8 @@ Node::Node(void)
, _physicsBody(nullptr)
, _physicsScaleStartX(1.0f)
, _physicsScaleStartY(1.0f)
, _physicsRotation(0.0f)
, _physicsTransformDirty(true)
#endif
, _displayedOpacity(255)
, _realOpacity(255)
@ -330,13 +331,6 @@ void Node::setRotation(float rotation)
_rotationZ_X = _rotationZ_Y = rotation;
_transformUpdated = _transformDirty = _inverseDirty = true;
#if CC_USE_PHYSICS
if (!_physicsBody || !_physicsBody->_rotationResetTag)
{
updatePhysicsBodyRotation(getScene());
}
#endif
updateRotationQuat();
}
@ -472,16 +466,6 @@ void Node::setScale(float scale)
_scaleX = _scaleY = _scaleZ = scale;
_transformUpdated = _transformDirty = _inverseDirty = true;
#if CC_USE_PHYSICS
if(g_physicsSceneCount == 0)
return;
auto scene = getScene();
if (!scene || scene->getPhysicsWorld())
{
updatePhysicsBodyTransform(scene);
}
#endif
}
/// scaleX getter
@ -499,17 +483,6 @@ void Node::setScale(float scaleX,float scaleY)
_scaleX = scaleX;
_scaleY = scaleY;
_transformUpdated = _transformDirty = _inverseDirty = true;
#if CC_USE_PHYSICS
if(g_physicsSceneCount == 0)
return;
auto scene = getScene();
if (!scene || scene->getPhysicsWorld())
{
updatePhysicsBodyTransform(scene);
}
#endif
}
/// scaleX setter
@ -520,17 +493,6 @@ void Node::setScaleX(float scaleX)
_scaleX = scaleX;
_transformUpdated = _transformDirty = _inverseDirty = true;
#if CC_USE_PHYSICS
if(g_physicsSceneCount == 0)
return;
auto scene = getScene();
if (!scene || scene->getPhysicsWorld())
{
updatePhysicsBodyTransform(scene);
}
#endif
}
/// scaleY getter
@ -570,17 +532,6 @@ void Node::setScaleY(float scaleY)
_scaleY = scaleY;
_transformUpdated = _transformDirty = _inverseDirty = true;
#if CC_USE_PHYSICS
if (g_physicsSceneCount == 0)
return;
auto scene = getScene();
if (!scene || scene->getPhysicsWorld())
{
updatePhysicsBodyTransform(scene);
}
#endif
}
@ -612,13 +563,6 @@ void Node::setPosition(float x, float y)
_transformUpdated = _transformDirty = _inverseDirty = true;
_usingNormalizedPosition = false;
#if CC_USE_PHYSICS
if (!_physicsBody || !_physicsBody->_positionResetTag)
{
updatePhysicsBodyPosition(getScene());
}
#endif
}
void Node::setPosition3D(const Vec3& position)
@ -1076,7 +1020,6 @@ void Node::addChildHelper(Node* child, int localZOrder, int tag, const std::stri
auto scene = this->getScene();
if (scene && scene->getPhysicsWorld())
{
child->updatePhysicsBodyTransform(scene);
scene->addChildToPhysicsWorld(child);
}
#endif
@ -1301,6 +1244,12 @@ void Node::visit()
uint32_t Node::processParentFlags(const Mat4& parentTransform, uint32_t parentFlags)
{
#if CC_USE_PHYSICS
if (_physicsBody && _updateTransformFromPhysics)
{
updateTransformFromPhysics(parentTransform, parentFlags);
}
#endif
if(_usingNormalizedPosition)
{
CCASSERT(_parent, "setNormalizedPosition() doesn't work with orphan nodes");
@ -1880,7 +1829,7 @@ const Mat4& Node::getParentToNodeTransform() const
{
if ( _inverseDirty )
{
_inverse = _transform.getInversed();
_inverse = getNodeToParentTransform().getInversed();
_inverseDirty = false;
}
@ -2023,87 +1972,6 @@ void Node::removeAllComponents()
// MARK: Physics
void Node::updatePhysicsBodyTransform(Scene* scene)
{
updatePhysicsBodyScale(scene);
updatePhysicsBodyPosition(scene);
updatePhysicsBodyRotation(scene);
}
void Node::updatePhysicsBodyPosition(Scene* scene)
{
if (_physicsBody != nullptr)
{
if (scene && scene->getPhysicsWorld())
{
Vec2 pos = _parent == scene ? _position : scene->convertToNodeSpace(_parent->convertToWorldSpace(_position));
_physicsBody->setPosition(pos);
}
else
{
_physicsBody->setPosition(_position);
}
}
for (Node* child : _children)
{
child->updatePhysicsBodyPosition(scene);
}
}
void Node::updatePhysicsBodyRotation(Scene* scene)
{
if (_physicsBody != nullptr)
{
if (scene != nullptr && scene->getPhysicsWorld() != nullptr)
{
float rotation = _rotationZ_X;
for (Node* parent = _parent; parent != scene; parent = parent->_parent)
{
rotation += parent->getRotation();
}
_physicsBody->setRotation(rotation);
}
else
{
_physicsBody->setRotation(_rotationZ_X);
}
}
for (auto child : _children)
{
child->updatePhysicsBodyRotation(scene);
child->updatePhysicsBodyPosition(scene);
}
}
void Node::updatePhysicsBodyScale(Scene* scene)
{
if (_physicsBody != nullptr)
{
if (scene != nullptr && scene->getPhysicsWorld() != nullptr)
{
float scaleX = _scaleX / _physicsScaleStartX;
float scaleY = _scaleY / _physicsScaleStartY;
for (Node* parent = _parent; parent != scene; parent = parent->_parent)
{
scaleX *= parent->_scaleX;
scaleY *= parent->_scaleY;
}
_physicsBody->setScale(scaleX, scaleY);
}
else
{
_physicsBody->setScale(_scaleX / _physicsScaleStartX, _scaleY / _physicsScaleStartY);
}
}
for (const auto& child : _children)
{
child->updatePhysicsBodyScale(scene);
}
}
void Node::setPhysicsBody(PhysicsBody* body)
{
if (_physicsBody == body)
@ -2111,9 +1979,17 @@ void Node::setPhysicsBody(PhysicsBody* body)
return;
}
if (body != nullptr)
if (_physicsBody)
{
if (body->getNode() != nullptr)
_physicsBody->removeFromWorld();
_physicsBody->_node = nullptr;
_physicsBody->release();
_physicsBody = nullptr;
}
if (body)
{
if (body->getNode())
{
body->getNode()->setPhysicsBody(nullptr);
}
@ -2128,52 +2004,65 @@ void Node::setPhysicsBody(PhysicsBody* body)
CCLOG("Node warning: setPhysicsBody sets anchor point to Vec2::ANCHOR_MIDDLE.");
setAnchorPoint(Vec2::ANCHOR_MIDDLE);
}
}
if (_physicsBody != nullptr)
{
PhysicsWorld* world = _physicsBody->getWorld();
_physicsBody->removeFromWorld();
_physicsBody->_node = nullptr;
_physicsBody->release();
if (world != nullptr && body != nullptr)
{
world->addBody(body);
}
}
_physicsBody = body;
_physicsScaleStartX = _scaleX;
_physicsScaleStartY = _scaleY;
if (body != nullptr)
{
Node* node;
Scene* scene = nullptr;
for (node = this->getParent(); node != nullptr; node = node->getParent())
{
Scene* tmpScene = dynamic_cast<Scene*>(node);
if (tmpScene != nullptr && tmpScene->getPhysicsWorld() != nullptr)
{
scene = tmpScene;
break;
}
}
if (scene != nullptr)
auto scene = getScene();
if (scene && scene->getPhysicsWorld())
{
_physicsTransformDirty = true;
scene->getPhysicsWorld()->addBody(body);
}
updatePhysicsBodyTransform(scene);
}
}
PhysicsBody* Node::getPhysicsBody() const
void Node::updatePhysicsBodyTransform(Scene* scene, const Mat4& parentTransform, uint32_t parentFlags, float parentScaleX, float parentScaleY)
{
return _physicsBody;
_updateTransformFromPhysics = false;
auto flags = processParentFlags(parentTransform, parentFlags);
_updateTransformFromPhysics = true;
auto scaleX = parentScaleX * _scaleX;
auto scaleY = parentScaleY * _scaleY;
if (_parent)
{
_physicsRotation = _parent->_physicsRotation + _rotationZ_X;
}
if (_physicsBody && ((flags & FLAGS_DIRTY_MASK) || _physicsTransformDirty))
{
_physicsTransformDirty = false;
Vec3 vec3(_position.x, _position.y, 0);
Vec3 ret;
parentTransform.transformPoint(vec3, &ret);
_physicsBody->setPosition(Vec2(ret.x, ret.y));
_physicsBody->setScale(scaleX / _physicsScaleStartX, scaleY / _physicsScaleStartY);
_physicsBody->setRotation(_physicsRotation);
}
for (auto node : _children)
{
node->updatePhysicsBodyTransform(scene, _modelViewTransform, flags, scaleX, scaleY);
}
}
void Node::updateTransformFromPhysics(const Mat4& parentTransform, uint32_t parentFlags)
{
auto& newPosition = _physicsBody->getPosition();
auto& recordedPosition = _physicsBody->_recordedPosition;
if (parentFlags || recordedPosition.x != newPosition.x || recordedPosition.y != newPosition.y)
{
recordedPosition = newPosition;
Vec3 vec3(newPosition.x, newPosition.y, 0);
Vec3 ret;
parentTransform.getInversed().transformPoint(vec3, &ret);
setPosition(ret.x, ret.y);
}
_physicsRotation = _physicsBody->getRotation();
setRotation(_physicsRotation - _parent->_physicsRotation);
}
#endif //CC_USE_PHYSICS
// MARK: Opacity and Color

View File

@ -1533,13 +1533,16 @@ public:
/**
* get the PhysicsBody the sprite have
*/
PhysicsBody* getPhysicsBody() const;
PhysicsBody* getPhysicsBody() const { return _physicsBody; }
/**
* remove this node from physics world. it will remove all the physics bodies in it's children too.
*/
void removeFromPhysicsWorld();
void updateTransformFromPhysics(const Mat4& parentTransform, uint32_t parentFlags);
virtual void updatePhysicsBodyTransform(Scene* scene, const Mat4& parentTransform, uint32_t parentFlags, float parentScaleX, float parentScaleY);
#endif
// overrides
@ -1613,13 +1616,6 @@ protected:
// update Rotation3D from quaternion
void updateRotation3D();
#if CC_USE_PHYSICS
void updatePhysicsBodyTransform(Scene* layer);
virtual void updatePhysicsBodyPosition(Scene* layer);
virtual void updatePhysicsBodyRotation(Scene* layer);
virtual void updatePhysicsBodyScale(Scene* scene);
#endif // CC_USE_PHYSICS
private:
void addChildHelper(Node* child, int localZOrder, int tag, const std::string &name, bool setTag);
@ -1710,6 +1706,9 @@ protected:
PhysicsBody* _physicsBody; ///< the physicsBody the node have
float _physicsScaleStartX; ///< the scale x value when setPhysicsBody
float _physicsScaleStartY; ///< the scale y value when setPhysicsBody
float _physicsRotation;
bool _physicsTransformDirty;
bool _updateTransformFromPhysics;
#endif
// opacity controls

View File

@ -1180,4 +1180,3 @@ void ParticleSystem::setScaleY(float newScaleY)
NS_CC_END

View File

@ -523,8 +523,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

@ -37,8 +37,6 @@ THE SOFTWARE.
#include "physics/CCPhysicsWorld.h"
#endif
int g_physicsSceneCount = 0;
NS_CC_BEGIN
Scene::Scene()
@ -60,10 +58,6 @@ Scene::Scene()
Scene::~Scene()
{
#if CC_USE_PHYSICS
if (_physicsWorld)
{
g_physicsSceneCount--;
}
CC_SAFE_DELETE(_physicsWorld);
#endif
Director::getInstance()->getEventDispatcher()->removeEventListener(_event);
@ -132,6 +126,9 @@ void Scene::render(Renderer* renderer)
const auto& transform = getNodeToParentTransform();
for (const auto& camera : _cameras)
{
if (!camera->isVisible())
continue;
Camera::_visitingCamera = camera;
if (Camera::_visitingCamera->getCameraFlag() == CameraFlag::DEFAULT)
{
@ -177,15 +174,6 @@ void Scene::addChild(Node* child, int zOrder, const std::string &name)
addChildToPhysicsWorld(child);
}
void Scene::update(float delta)
{
Node::update(delta);
if (nullptr != _physicsWorld && _physicsWorld->isAutoStep())
{
_physicsWorld->update(delta);
}
}
Scene* Scene::createWithPhysics()
{
Scene *ret = new (std::nothrow) Scene();
@ -212,9 +200,7 @@ bool Scene::initWithPhysics()
this->setContentSize(director->getWinSize());
CC_BREAK_IF(! (_physicsWorld = PhysicsWorld::construct(*this)));
this->scheduleUpdate();
// success
g_physicsSceneCount += 1;
ret = true;
} while (0);
return ret;

View File

@ -110,7 +110,6 @@ private:
public:
virtual void addChild(Node* child, int zOrder, int tag) override;
virtual void addChild(Node* child, int zOrder, const std::string &name) override;
virtual void update(float delta) override;
inline PhysicsWorld* getPhysicsWorld() { return _physicsWorld; }
static Scene *createWithPhysics();

View File

@ -367,8 +367,17 @@ void SpriteBatchNode::draw(Renderer *renderer, const Mat4 &transform, uint32_t f
return;
}
for(const auto &child: _children)
for (const auto &child : _children)
{
#if CC_USE_PHYSICS
auto physicsBody = child->getPhysicsBody();
if (physicsBody)
{
child->updateTransformFromPhysics(transform, flags);
}
#endif
child->updateTransform();
}
//Render as 3D object
if (flags & FLAGS_RENDER_AS_3D)

View File

@ -196,4 +196,3 @@ Texture2D* SpriteFrame::getTexture()
}
NS_CC_END

View File

@ -428,4 +428,3 @@ SpriteFrame* SpriteFrameCache::getSpriteFrameByName(const std::string& name)
}
NS_CC_END

View File

@ -732,4 +732,3 @@ std::string TMXLayer::getDescription() const
NS_CC_END

View File

@ -263,4 +263,3 @@ std::string TMXTiledMap::getDescription() const
NS_CC_END

View File

@ -712,4 +712,3 @@ void TMXMapInfo::textHandler(void *ctx, const char *ch, int len)
}
NS_CC_END

View File

@ -341,4 +341,3 @@ ProgressTimer* TransitionProgressOutIn::progressTimerNodeWithRenderTexture(Rende
}
NS_CC_END

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>
@ -1338,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>
@ -2581,6 +2545,9 @@
</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

@ -65,6 +65,10 @@ THE SOFTWARE.
#include "CCScriptSupport.h"
#endif
#if CC_USE_PHYSICS
#include "physics/CCPhysicsWorld.h"
#endif
/**
Position of the FPS
@ -259,12 +263,6 @@ void Director::drawScene()
// calculate "global" dt
calculateDeltaTime();
// skip one flame when _deltaTime equal to zero.
if(_deltaTime < FLT_EPSILON)
{
return;
}
if (_openGLView)
{
_openGLView->pollEvents();
@ -291,6 +289,13 @@ void Director::drawScene()
if (_runningScene)
{
#if CC_USE_PHYSICS
auto physicsWorld = _runningScene->getPhysicsWorld();
if (physicsWorld && physicsWorld->isAutoStep())
{
physicsWorld->update(_deltaTime, false);
}
#endif
//clear draw stats
_renderer->clearDrawStats();
@ -990,7 +995,10 @@ void Director::reset()
#pragma warning (push)
#pragma warning (disable: 4996)
#endif
//it will crash clang static analyzer so hide it if __clang_analyzer__ defined
#ifndef __clang_analyzer__
DrawPrimitives::free();
#endif
#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
#pragma GCC diagnostic warning "-Wdeprecated-declarations"
#elif _MSC_VER >= 1400 //vs 2005 or higher

View File

@ -31,7 +31,7 @@ NS_CC_BEGIN
CC_DLL const char* cocos2dVersion()
{
return "cocos2d-x 3.4beta0";
return "cocos2d-x 3.4";
}
NS_CC_END

View File

@ -87,7 +87,10 @@ void ccDrawInit()
void ccDrawFree()
{
//it will crash clang static analyzer so hide it if __clang_analyzer__ defined
#ifndef __clang_analyzer__
DrawPrimitives::free();
#endif
}
void ccDrawPoint( const Vec2& point )

View File

@ -93,14 +93,14 @@ bool ActionTimeline::init()
void ActionTimeline::play(std::string name, bool loop)
{
if(_indexes.find(name) == _indexes.end())
if (_animationInfos.find(name) == _animationInfos.end())
{
CCLOG("Cann't find action indexes for %s.", name.c_str());
CCLOG("Can't find animation info for %s", name.c_str());
return;
}
ActionIndexes& indexes = _indexes[name];
gotoFrameAndPlay(indexes.startIndex, indexes.endIndex, loop);
AnimationInfo& index = _animationInfos[name];
gotoFrameAndPlay(index.startIndex, index.endIndex, loop);
}
void ActionTimeline::gotoFrameAndPlay(int startIndex)
@ -278,26 +278,37 @@ void ActionTimeline::removeTimeline(Timeline* timeline)
}
}
void ActionTimeline::addIndexes(const ActionIndexes& indexes)
void ActionTimeline::addAnimationInfo(const AnimationInfo& animationInfo)
{
if(_indexes.find(indexes.name) != _indexes.end())
if (_animationInfos.find(animationInfo.name) != _animationInfos.end())
{
CCLOG("ActionIndexes (%s) already exsists.", indexes.name.c_str());
CCLOG("Animation (%s) already exists.", animationInfo.name.c_str());
return;
}
_indexes[indexes.name] = indexes;
_animationInfos[animationInfo.name] = animationInfo;
}
void ActionTimeline::removeIndexes(std::string name)
void ActionTimeline::removeAnimationInfo(std::string animationName)
{
if(_indexes.find(name) == _indexes.end())
if (_animationInfos.find(animationName) == _animationInfos.end())
{
CCLOG("ActionIndexes %s don't exsists.", name.c_str());
CCLOG("AnimationInfo (%s) not exists.", animationName.c_str());
return;
}
_indexes.erase(name);
_animationInfos.erase(animationName);
}
bool ActionTimeline::IsAnimationInfoExists(const std::string& animationName)
{
return _animationInfos.find(animationName) != _animationInfos.end();
}
AnimationInfo ActionTimeline::getAnimationInfo(const std::string &animationName)
{
return _animationInfos.find(animationName)->second;
}
void ActionTimeline::setFrameEventCallFunc(std::function<void(Frame *)> listener)
@ -348,5 +359,4 @@ void ActionTimeline::stepToFrame(int frameIndex)
_timelineList.at(i)->stepToFrame(frameIndex);
}
}
NS_TIMELINE_END

View File

@ -31,7 +31,7 @@ THE SOFTWARE.
NS_TIMELINE_BEGIN
struct ActionIndexes
struct AnimationInfo
{
std::string name;
int startIndex;
@ -45,10 +45,10 @@ public:
virtual void setActionTag(int actionTag) { _actionTag = actionTag; }
virtual int getActionTag() const { return _actionTag; }
protected:
CC_CONSTRUCTOR_ACCESS:
ActionTimelineData();
virtual bool init(int actionTag);
protected:
int _actionTag;
};
@ -63,9 +63,9 @@ public:
ActionTimeline();
virtual ~ActionTimeline();
virtual bool init();
virtual void play(std::string animationName, bool loop);
virtual void play(std::string name, bool loop);
virtual bool init();
/** Goto the specified frame index, and start playing from this index.
* @param startIndex The animation will play from this index.
@ -98,7 +98,6 @@ public:
*/
virtual void gotoFrameAndPause(int startIndex);
/** Pause the animation. */
virtual void pause();
/** Resume the animation. */
@ -133,12 +132,14 @@ public:
virtual void addTimeline(Timeline* timeline);
virtual void removeTimeline(Timeline* timeline);
/** add ActionIndexes */
virtual void addIndexes(const ActionIndexes& indexes);
virtual void removeIndexes(std::string name);
virtual const cocos2d::Vector<Timeline*>& getTimelines() const { return _timelineList; }
/** AnimationInfo*/
virtual void addAnimationInfo(const AnimationInfo& animationInfo);
virtual void removeAnimationInfo(std::string animationName);
virtual bool IsAnimationInfoExists(const std::string& animationName);
virtual AnimationInfo getAnimationInfo(const std::string& animationName);
/** Set ActionTimeline's frame event callback function */
void setFrameEventCallFunc(std::function<void(Frame *)> listener);
void clearFrameEventCallFunc();
@ -182,7 +183,7 @@ protected:
std::function<void(Frame*)> _frameEventListener;
std::function<void()> _lastFrameListener;
std::map<std::string, ActionIndexes> _indexes;
std::map<std::string, AnimationInfo> _animationInfos;
};
NS_TIMELINE_END

View File

@ -47,18 +47,16 @@ using namespace flatbuffers;
namespace cocostudio {
namespace timeline{
static const char* FrameType_VisibleFrame = "VisibleFrame";
static const char* FrameType_PositionFrame = "PositionFrame";
static const char* FrameType_ScaleFrame = "ScaleFrame";
static const char* FrameType_RotationFrame = "RotationFrame";
static const char* FrameType_SkewFrame = "SkewFrame";
static const char* FrameType_RotationSkewFrame = "RotationSkewFrame";
static const char* FrameType_AnchorFrame = "AnchorPointFrame";
static const char* FrameType_InnerActionFrame = "InnerActionFrame";
static const char* FrameType_ColorFrame = "ColorFrame";
static const char* FrameType_TextureFrame = "TextureFrame";
static const char* FrameType_EventFrame = "EventFrame";
static const char* FrameType_ZOrderFrame = "ZOrderFrame";
static const char* Property_VisibleForFrame = "VisibleForFrame";
static const char* Property_Position = "Position";
static const char* Property_Scale = "Scale";
static const char* Property_RotationSkew = "RotationSkew";
static const char* Property_CColor = "CColor";
static const char* Property_FileData = "FileData";
static const char* Property_FrameEvent = "FrameEvent";
static const char* Property_Alpha = "Alpha";
static const char* Property_ZOrder = "ZOrder";
static const char* Property_ActionValue = "ActionValue";
static const char* ACTION = "action";
static const char* DURATION = "duration";
@ -108,6 +106,7 @@ void ActionTimelineCache::purge()
void ActionTimelineCache::init()
{
using namespace std::placeholders;
/*
_funcs.insert(Pair(FrameType_VisibleFrame, std::bind(&ActionTimelineCache::loadVisibleFrame, this, _1)));
_funcs.insert(Pair(FrameType_PositionFrame, std::bind(&ActionTimelineCache::loadPositionFrame, this, _1)));
_funcs.insert(Pair(FrameType_ScaleFrame, std::bind(&ActionTimelineCache::loadScaleFrame, this, _1)));
@ -120,6 +119,7 @@ void ActionTimelineCache::init()
_funcs.insert(Pair(FrameType_TextureFrame, std::bind(&ActionTimelineCache::loadTextureFrame, this, _1)));
_funcs.insert(Pair(FrameType_EventFrame, std::bind(&ActionTimelineCache::loadEventFrame, this, _1)));
_funcs.insert(Pair(FrameType_ZOrderFrame, std::bind(&ActionTimelineCache::loadZOrderFrame, this, _1)));
*/
}
@ -439,6 +439,17 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(cons
float speed = nodeAction->speed();
action->setTimeSpeed(speed);
auto animationlist = csparsebinary->animationList();
int animationcount = animationlist->size();
for (int i = 0; i < animationcount; i++)
{
auto animationdata = animationlist->Get(i);
AnimationInfo info;
info.name = animationdata->name()->c_str();
info.startIndex = animationdata->startIndex();
info.endIndex = animationdata->endIndex();
action->addAnimationInfo(info);
}
auto timelines = nodeAction->timeLines();
int timelineLength = timelines->size();
@ -460,14 +471,14 @@ Timeline* ActionTimelineCache::loadTimelineWithFlatBuffers(const flatbuffers::Ti
{
Timeline* timeline = nullptr;
// get frame type
std::string frameType = flatbuffers->frameType()->c_str();
if(frameType == "")
// property
std::string property = flatbuffers->property()->c_str();
if(property == "")
return nullptr;
CCLOG("frameType = %s", frameType.c_str());
CCLOG("property = %s", property.c_str());
if(frameType != "")
if(property != "")
{
timeline = Timeline::create();
@ -482,52 +493,62 @@ Timeline* ActionTimelineCache::loadTimelineWithFlatBuffers(const flatbuffers::Ti
auto frameFlatbuf = framesFlatbuf->Get(i);
Frame* frame = nullptr;
if (frameType == FrameType_VisibleFrame)
if (property == Property_VisibleForFrame)
{
auto visibleFrame = frameFlatbuf->visibleFrame();
frame = loadVisibleFrameWithFlatBuffers(visibleFrame);
auto boolFrame = frameFlatbuf->boolFrame();
frame = loadVisibleFrameWithFlatBuffers(boolFrame);
}
else if (frameType == FrameType_ZOrderFrame)
else if (property == Property_Position)
{
auto zOrderFrame = frameFlatbuf->zOrderFrame();
frame = loadZOrderFrameWithFlatBuffers(zOrderFrame);
}
else if (frameType == FrameType_RotationSkewFrame)
{
auto rotationSkewFrame = frameFlatbuf->rotationSkewFrame();
frame = loadRotationSkewFrameWithFlatBuffers(rotationSkewFrame);
}
else if (frameType == FrameType_EventFrame)
{
auto eventFrame = frameFlatbuf->eventFrame();
frame = loadEventFrameWithFlatBuffers(eventFrame);
}
else if (frameType == FrameType_AnchorFrame)
{
auto anchorPointFrame = frameFlatbuf->anchorPointFrame();
frame = loadAnchorPointFrameWithFlatBuffers(anchorPointFrame);
}
else if (frameType == FrameType_PositionFrame)
{
auto potisionFrame = frameFlatbuf->positionFrame();
auto potisionFrame = frameFlatbuf->pointFrame();
frame = loadPositionFrameWithFlatBuffers(potisionFrame);
}
else if (frameType == FrameType_ScaleFrame)
else if (property == Property_Scale)
{
auto scaleFrame = frameFlatbuf->scaleFrame();
frame = loadScaleFrameWithFlatBuffers(scaleFrame);
}
else if (frameType == FrameType_ColorFrame)
else if (property == Property_RotationSkew)
{
auto scaleFrame = frameFlatbuf->scaleFrame();
frame = loadRotationSkewFrameWithFlatBuffers(scaleFrame);
}
else if (property == Property_CColor)
{
auto colorFrame = frameFlatbuf->colorFrame();
frame = loadColorFrameWithFlatBuffers(colorFrame);
}
else if (frameType == FrameType_TextureFrame)
else if (property == Property_FrameEvent)
{
auto eventFrame = frameFlatbuf->eventFrame();
frame = loadEventFrameWithFlatBuffers(eventFrame);
}
else if (property == Property_FileData)
{
auto textureFrame = frameFlatbuf->textureFrame();
frame = loadTextureFrameWithFlatBuffers(textureFrame);
}
else if (property == Property_Alpha)
{
auto intFrame = frameFlatbuf->intFrame();
frame = loadAlphaFrameWithFlatBuffers(intFrame);
}
else if (property == Property_ZOrder)
{
auto intFrame = frameFlatbuf->intFrame();
frame = loadZOrderFrameWithFlatBuffers(intFrame);
}
else if (property == Property_ActionValue)
{
auto innerActionFrame = frameFlatbuf->innerActionFrame();
frame = loadInnerActionFrameWithFlatBuffers(innerActionFrame);
}
if (!frame)
{
CCLOG("frame is invalid.");
continue;
}
timeline->addFrame(frame);
}
}
@ -535,15 +556,14 @@ Timeline* ActionTimelineCache::loadTimelineWithFlatBuffers(const flatbuffers::Ti
return timeline;
}
Frame* ActionTimelineCache::loadVisibleFrameWithFlatBuffers(const flatbuffers::TimeLineBoolFrame *flatbuffers)
Frame* ActionTimelineCache::loadVisibleFrameWithFlatBuffers(const flatbuffers::BoolFrame *flatbuffers)
{
VisibleFrame* frame = VisibleFrame::create();
bool visible = flatbuffers->value();
frame->setVisible(visible);
CCLOG("visible = %d", visible);
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
@ -553,80 +573,7 @@ Frame* ActionTimelineCache::loadVisibleFrameWithFlatBuffers(const flatbuffers::T
return frame;
}
Frame* ActionTimelineCache::loadZOrderFrameWithFlatBuffers(const flatbuffers::TimeLineIntFrame *flatbuffers)
{
ZOrderFrame* frame = ZOrderFrame::create();
int zorder = flatbuffers->value();
frame->setZOrder(zorder);
CCLOG("zorder = %d", zorder);
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
frame->setTween(tween);
return frame;
}
Frame* ActionTimelineCache::loadRotationSkewFrameWithFlatBuffers(const flatbuffers::TimeLinePointFrame *flatbuffers)
{
RotationSkewFrame* frame = RotationSkewFrame::create();
auto f_rotationSkew = flatbuffers->postion();
Vec2 rotationSkew(f_rotationSkew->x(), f_rotationSkew->y());
frame->setSkewX(rotationSkew.x);
frame->setSkewY(rotationSkew.y);
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
frame->setTween(tween);
return frame;
}
Frame* ActionTimelineCache::loadEventFrameWithFlatBuffers(const flatbuffers::TimeLineStringFrame *flatbuffers)
{
EventFrame* frame = EventFrame::create();
std::string event = flatbuffers->value()->c_str();
if (event != "")
frame->setEvent(event);
CCLOG("event = %s", event.c_str());
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
frame->setTween(tween);
return frame;
}
Frame* ActionTimelineCache::loadAnchorPointFrameWithFlatBuffers(const flatbuffers::TimeLinePointFrame *flatbuffers)
{
AnchorPointFrame* frame = AnchorPointFrame::create();
auto f_anchorPoint = flatbuffers->postion();
Vec2 anchorPoint(f_anchorPoint->x(), f_anchorPoint->y());
frame->setAnchorPoint(anchorPoint);
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
frame->setTween(tween);
return frame;
}
Frame* ActionTimelineCache::loadPositionFrameWithFlatBuffers(const flatbuffers::TimeLinePointFrame *flatbuffers)
Frame* ActionTimelineCache::loadPositionFrameWithFlatBuffers(const flatbuffers::PointFrame *flatbuffers)
{
PositionFrame* frame = PositionFrame::create();
@ -643,12 +590,12 @@ Frame* ActionTimelineCache::loadPositionFrameWithFlatBuffers(const flatbuffers::
return frame;
}
Frame* ActionTimelineCache::loadScaleFrameWithFlatBuffers(const flatbuffers::TimeLinePointFrame *flatbuffers)
Frame* ActionTimelineCache::loadScaleFrameWithFlatBuffers(const flatbuffers::ScaleFrame *flatbuffers)
{
ScaleFrame* frame = ScaleFrame::create();
auto f_scale = flatbuffers->postion();
Vec2 scale(f_scale->x(), f_scale->y());
auto f_scale = flatbuffers->scale();
Vec2 scale(f_scale->scaleX(), f_scale->scaleY());
frame->setScaleX(scale.x);
frame->setScaleY(scale.y);
@ -661,16 +608,14 @@ Frame* ActionTimelineCache::loadScaleFrameWithFlatBuffers(const flatbuffers::Tim
return frame;
}
Frame* ActionTimelineCache::loadColorFrameWithFlatBuffers(const flatbuffers::TimeLineColorFrame *flatbuffers)
Frame* ActionTimelineCache::loadRotationSkewFrameWithFlatBuffers(const flatbuffers::ScaleFrame *flatbuffers)
{
ColorFrame* frame = ColorFrame::create();
RotationSkewFrame* frame = RotationSkewFrame::create();
auto f_color = flatbuffers->color();
Color3B color(f_color->r(), f_color->g(), f_color->b());
frame->setColor(color);
int alpha = f_color->a();
frame->setAlpha(alpha);
auto f_scale = flatbuffers->scale();
Vec2 rotationSkew(f_scale->scaleX(), f_scale->scaleY());
frame->setSkewX(rotationSkew.x);
frame->setSkewY(rotationSkew.y);
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
@ -681,7 +626,24 @@ Frame* ActionTimelineCache::loadColorFrameWithFlatBuffers(const flatbuffers::Tim
return frame;
}
Frame* ActionTimelineCache::loadTextureFrameWithFlatBuffers(const flatbuffers::TimeLineTextureFrame *flatbuffers)
Frame* ActionTimelineCache::loadColorFrameWithFlatBuffers(const flatbuffers::ColorFrame *flatbuffers)
{
ColorFrame* frame = ColorFrame::create();
auto f_color = flatbuffers->color();
Color3B color(f_color->r(), f_color->g(), f_color->b());
frame->setColor(color);
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
frame->setTween(tween);
return frame;
}
Frame* ActionTimelineCache::loadTextureFrameWithFlatBuffers(const flatbuffers::TextureFrame *flatbuffers)
{
std::string path = "";
int resourceType = 0;
@ -689,7 +651,7 @@ Frame* ActionTimelineCache::loadTextureFrameWithFlatBuffers(const flatbuffers::T
TextureFrame* frame = TextureFrame::create();
auto fileNameData = flatbuffers->fileNameData();
auto fileNameData = flatbuffers->textureFile();
resourceType = fileNameData->resourceType();
switch (resourceType)
@ -727,7 +689,6 @@ Frame* ActionTimelineCache::loadTextureFrameWithFlatBuffers(const flatbuffers::T
break;
}
frame->setTextureName(path);
int frameIndex = flatbuffers->frameIndex();
@ -739,6 +700,85 @@ Frame* ActionTimelineCache::loadTextureFrameWithFlatBuffers(const flatbuffers::T
return frame;
}
Frame* ActionTimelineCache::loadEventFrameWithFlatBuffers(const flatbuffers::EventFrame *flatbuffers)
{
EventFrame* frame = EventFrame::create();
std::string event = flatbuffers->value()->c_str();
if (event != "")
frame->setEvent(event);
CCLOG("event = %s", event.c_str());
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
frame->setTween(tween);
return frame;
}
Frame* ActionTimelineCache::loadAlphaFrameWithFlatBuffers(const flatbuffers::IntFrame *flatbuffers)
{
AlphaFrame* frame = AlphaFrame::create();
int alpha = flatbuffers->value();
frame->setAlpha(alpha);
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
frame->setTween(tween);
return frame;
}
Frame* ActionTimelineCache::loadZOrderFrameWithFlatBuffers(const flatbuffers::IntFrame *flatbuffers)
{
ZOrderFrame* frame = ZOrderFrame::create();
int zorder = flatbuffers->value();
frame->setZOrder(zorder);
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
frame->setTween(tween);
return frame;
}
Frame* ActionTimelineCache::loadInnerActionFrameWithFlatBuffers(const flatbuffers::InnerActionFrame *flatbuffers)
{
InnerActionFrame* frame = InnerActionFrame::create();
InnerActionType innerActionType = (InnerActionType)flatbuffers->innerActionType();
std::string currentAnimationFrame = flatbuffers->currentAniamtionName()->c_str();
int singleFrameIndex = flatbuffers->singleFrameIndex();
int frameIndex = flatbuffers->frameIndex();
frame->setFrameIndex(frameIndex);
bool tween = flatbuffers->tween();
frame->setTween(tween);
frame->setInnerActionType(innerActionType);
frame->setSingleFrameIndex(singleFrameIndex);
frame->setEnterWithName(true);
frame->setAnimationName(currentAnimationFrame);
return frame;
}
ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersForSimulator(const std::string& fileName)
{
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
@ -758,6 +798,18 @@ ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersForSimulator(con
float speed = nodeAction->speed();
action->setTimeSpeed(speed);
auto animationlist = csparsebinary->animationList();
int animationcount = animationlist->size();
for (int i = 0; i < animationcount; i++)
{
auto animationdata = animationlist->Get(i);
AnimationInfo info;
info.name = animationdata->name()->c_str();
info.startIndex = animationdata->startIndex();
info.endIndex = animationdata->endIndex();
action->addAnimationInfo(info);
}
auto timeLines = nodeAction->timeLines();
int timelineLength = timeLines->size();
for (int i = 0; i < timelineLength; i++)

View File

@ -38,12 +38,14 @@ namespace flatbuffers
struct NodeAction;
struct TimeLine;
struct TimeLineBoolFrame;
struct TimeLineIntFrame;
struct TimeLineStringFrame;
struct TimeLinePointFrame;
struct TimeLineColorFrame;
struct TimeLineTextureFrame;
struct PointFrame;
struct ScaleFrame;
struct ColorFrame;
struct TextureFrame;
struct EventFrame;
struct IntFrame;
struct BoolFrame;
struct InnerActionFrame;
}
NS_TIMELINE_BEGIN
@ -55,6 +57,7 @@ class Frame;
class CC_STUDIO_DLL ActionTimelineCache
{
public:
/** Gets the singleton */
static ActionTimelineCache* getInstance();
@ -101,15 +104,16 @@ protected:
Timeline* loadTimelineWithFlatBuffers(const flatbuffers::TimeLine* flatbuffers);
Frame* loadVisibleFrameWithFlatBuffers (const flatbuffers::TimeLineBoolFrame* flatbuffers);
Frame* loadZOrderFrameWithFlatBuffers (const flatbuffers::TimeLineIntFrame* flatbuffers);
Frame* loadRotationSkewFrameWithFlatBuffers (const flatbuffers::TimeLinePointFrame* flatbuffers);
Frame* loadEventFrameWithFlatBuffers (const flatbuffers::TimeLineStringFrame* flatbuffers);
Frame* loadAnchorPointFrameWithFlatBuffers (const flatbuffers::TimeLinePointFrame* flatbuffers);
Frame* loadPositionFrameWithFlatBuffers (const flatbuffers::TimeLinePointFrame* flatbuffers);
Frame* loadScaleFrameWithFlatBuffers (const flatbuffers::TimeLinePointFrame* flatbuffers);
Frame* loadColorFrameWithFlatBuffers (const flatbuffers::TimeLineColorFrame* flatbuffers);
Frame* loadTextureFrameWithFlatBuffers (const flatbuffers::TimeLineTextureFrame* flatbuffers);
Frame* loadVisibleFrameWithFlatBuffers (const flatbuffers::BoolFrame* flatbuffers);
Frame* loadPositionFrameWithFlatBuffers (const flatbuffers::PointFrame* flatbuffers);
Frame* loadScaleFrameWithFlatBuffers (const flatbuffers::ScaleFrame* flatbuffers);
Frame* loadRotationSkewFrameWithFlatBuffers (const flatbuffers::ScaleFrame* flatbuffers);
Frame* loadColorFrameWithFlatBuffers (const flatbuffers::ColorFrame* flatbuffers);
Frame* loadTextureFrameWithFlatBuffers (const flatbuffers::TextureFrame* flatbuffers);
Frame* loadEventFrameWithFlatBuffers (const flatbuffers::EventFrame* flatbuffers);
Frame* loadAlphaFrameWithFlatBuffers (const flatbuffers::IntFrame* flatbuffers);
Frame* loadZOrderFrameWithFlatBuffers (const flatbuffers::IntFrame* flatbuffers);
Frame* loadInnerActionFrameWithFlatBuffers (const flatbuffers::InnerActionFrame* flatbuffers);
protected:

View File

@ -27,6 +27,8 @@ THE SOFTWARE.
#include "CCActionTimeline.h"
#include "2d/CCSpriteFrameCache.h"
#include "2d/CCSpriteFrame.h"
#include <exception>
#include <iostream>
USING_NS_CC;
@ -451,6 +453,8 @@ Frame* AnchorPointFrame::clone()
// InnerActionFrame
const std::string InnerActionFrame::AnimationAllName = "-- ALL --";
InnerActionFrame* InnerActionFrame::create()
{
InnerActionFrame* frame = new (std::nothrow) InnerActionFrame();
@ -464,22 +468,103 @@ InnerActionFrame* InnerActionFrame::create()
}
InnerActionFrame::InnerActionFrame()
: _innerActionType(LoopAction)
, _startFrameIndex(0)
: _innerActionType(InnerActionType::SingleFrame)
, _startFrameIndex(0)
, _endFrameIndex(0)
, _singleFrameIndex(0)
, _enterWithName(false)
, _animationName("")
{
}
void InnerActionFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
int start = _startFrameIndex;
int end = _endFrameIndex;
auto actiontimeline = static_cast<ActionTimeline*>(_node->getActionByTag(_node->getTag()));
if (InnerActionType::SingleFrame == _innerActionType)
{
actiontimeline->gotoFrameAndPause(_singleFrameIndex);
return;
}
if (_enterWithName)
{
if (_animationName == AnimationAllName)
{
start = 0;
end = actiontimeline->getDuration();
}
else if(actiontimeline->IsAnimationInfoExists(_animationName))
{
AnimationInfo info = actiontimeline->getAnimationInfo(_animationName);
start = info.startIndex;
end = info.endIndex;
}
else
{
CCLOG("Animation %s not exists!", _animationName.c_str());
}
}
if (InnerActionType::NoLoopAction == _innerActionType)
{
actiontimeline->gotoFrameAndPlay(start, end, false);
}
else if (InnerActionType::LoopAction == _innerActionType)
{
actiontimeline->gotoFrameAndPlay(start, end, true);
}
}
void InnerActionFrame::setStartFrameIndex(int frameIndex) throw()
{
if(_enterWithName)
{
CCLOG(" cannot set start when enter frame with name. setEnterWithName false firstly!");
throw std::exception();
}
_startFrameIndex = frameIndex;
}
void InnerActionFrame::setEndFrameIndex(int frameIndex) throw()
{
if(_enterWithName)
{
CCLOG(" cannot set end when enter frame with name. setEnterWithName false firstly!");
throw std::exception();
}
_endFrameIndex = frameIndex;
}
void InnerActionFrame::setAnimationName(const std::string& animationName) throw()
{
if(!_enterWithName)
{
CCLOG(" cannot set aniamtioname when enter frame with index. setEnterWithName true firstly!");
throw std::exception();
}
_animationName = animationName;
}
Frame* InnerActionFrame::clone()
{
InnerActionFrame* frame = InnerActionFrame::create();
frame->setInnerActionType(_innerActionType);
frame->setSingleFrameIndex(_singleFrameIndex);
if(_enterWithName)
{
frame->setEnterWithName(true);
frame->setAnimationName(_animationName);
}
else
{
frame->setStartFrameIndex(_startFrameIndex);
frame->setEndFrameIndex(_endFrameIndex);
}
frame->cloneProperty(this);
return frame;
@ -548,6 +633,51 @@ Frame* ColorFrame::clone()
return frame;
}
// AlphaFrame
AlphaFrame* AlphaFrame::create()
{
AlphaFrame* frame = new (std::nothrow) AlphaFrame();
if (frame)
{
frame->autorelease();
return frame;
}
CC_SAFE_DELETE(frame);
return nullptr;
}
AlphaFrame::AlphaFrame()
: _alpha(255)
{
}
void AlphaFrame::onEnter(Frame *nextFrame, int currentFrameIndex)
{
_node->setOpacity(_alpha);
if (_tween)
{
_betweenAlpha = static_cast<AlphaFrame*>(nextFrame)->_alpha - _alpha;
}
}
void AlphaFrame::apply(float percent)
{
if (_tween)
{
GLubyte alpha = _alpha + _betweenAlpha * percent;
_node->setOpacity(alpha);
}
}
Frame* AlphaFrame::clone()
{
AlphaFrame* frame = AlphaFrame::create();
frame->setAlpha(_alpha);
frame->cloneProperty(this);
return frame;
}
// EventFrame
EventFrame* EventFrame::create()

View File

@ -255,6 +255,8 @@ enum InnerActionType
class CC_STUDIO_DLL InnerActionFrame : public Frame
{
public:
static const std::string AnimationAllName;
static InnerActionFrame* create();
InnerActionFrame();
@ -264,12 +266,26 @@ public:
inline void setInnerActionType(InnerActionType type) { _innerActionType = type; }
inline InnerActionType getInnerActionType() const { return _innerActionType; }
inline void setStartFrameIndex(int frameIndex) { _startFrameIndex = frameIndex; }
inline void setEnterWithName(bool isEnterWithName) { _enterWithName = isEnterWithName;}
void setStartFrameIndex(int frameIndex) throw();
inline int getStartFrameIndex() const { return _startFrameIndex; }
void setEndFrameIndex(int frameIndex) throw();
inline int getEndFrameIndex() const { return _endFrameIndex; }
void setAnimationName(const std::string& animationNamed) throw();
inline void setSingleFrameIndex(int frameIndex) { _singleFrameIndex = frameIndex;}
inline int getSingleFrameIndex() const { return _singleFrameIndex;}
protected:
InnerActionType _innerActionType;
int _startFrameIndex;
int _endFrameIndex;
int _singleFrameIndex;
std::string _animationName;
bool _enterWithName;
};
@ -299,6 +315,23 @@ protected:
int _betweenBlue;
};
class CC_STUDIO_DLL AlphaFrame : public Frame
{
public:
static AlphaFrame* create();
AlphaFrame();
virtual void onEnter(Frame *nextFrame, int currentFrameIndex) override;
virtual void apply(float percent) override;
virtual Frame* clone() override;
inline void setAlpha(GLubyte alpha) { _alpha = alpha; }
inline GLubyte getAlpha() const { return _alpha; }
protected:
GLubyte _alpha;
int _betweenAlpha;
};
class CC_STUDIO_DLL EventFrame : public Frame
{

View File

@ -145,10 +145,6 @@ void Timeline::binarySearchKeyFrame(int frameIndex)
needEnterFrame = true;
_fromIndex = 0;
if(length > 1)
_toIndex = 1;
else
_toIndex = 0;
from = to = _frames.at(0);

View File

@ -181,7 +181,7 @@ CSLoader::CSLoader()
, _jsonPath("")
, _monoCocos2dxVersion("")
, _rootNode(nullptr)
, _csBuildID("2.0.8.0")
, _csBuildID("2.1.0.0")
{
CREATE_CLASS_NODE_READER_INFO(NodeReader);
CREATE_CLASS_NODE_READER_INFO(SingleNodeReader);
@ -285,6 +285,7 @@ ActionTimeline* CSLoader::createTimeline(const std::string &filename)
return nullptr;
}
/*
ActionTimelineNode* CSLoader::createActionTimelineNode(const std::string& filename)
{
Node* root = createNode(filename);
@ -308,6 +309,7 @@ ActionTimelineNode* CSLoader::createActionTimelineNode(const std::string& filena
return node;
}
*/
@ -834,28 +836,15 @@ Node* CSLoader::nodeWithFlatBuffers(const flatbuffers::NodeTree *nodetree)
if (filePath != "" && FileUtils::getInstance()->isFileExist(filePath))
{
Node* root = createNodeWithFlatBuffersFile(filePath);
reader->setPropsWithFlatBuffers(root, options->data());
bool isloop = projectNodeOptions->isLoop();
bool isautoplay = projectNodeOptions->isAutoPlay();
node = createNodeWithFlatBuffersFile(filePath);
reader->setPropsWithFlatBuffers(node, options->data());
cocostudio::timeline::ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersFile(filePath);
if (action)
{
root->runAction(action);
if (isautoplay)
{
action->gotoFrameAndPlay(0, isloop);
}
else
{
action->gotoFrameAndPause(0);
}
node->runAction(action);
}
node = ActionTimelineNode::create(root, action);
node->setName(root->getName());
}
}
else if (classname == "SimpleAudio")
@ -1183,21 +1172,10 @@ Node* CSLoader::nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree *nod
node = createNodeWithFlatBuffersForSimulator(filePath);
reader->setPropsWithFlatBuffers(node, options->data());
bool isloop = projectNodeOptions->isLoop();
bool isautoplay = projectNodeOptions->isAutoPlay();
cocostudio::timeline::ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersFile(filePath);
cocostudio::timeline::ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersForSimulator(filePath);
if (action)
{
node->runAction(action);
action->gotoFrameAndPlay(0);
if (isautoplay)
{
action->gotoFrameAndPlay(0, isloop);
}
else
{
action->gotoFrameAndPause(0);
}
}
}
}

View File

@ -77,8 +77,10 @@ public:
static cocos2d::Node* createNode(const std::string& filename);
static cocostudio::timeline::ActionTimeline* createTimeline(const std::string& filename);
/*
static cocostudio::timeline::ActionTimelineNode* createActionTimelineNode(const std::string& filename);
static cocostudio::timeline::ActionTimelineNode* createActionTimelineNode(const std::string& filename, int startIndex, int endIndex, bool loop);
*/
cocos2d::Node* createNodeFromJson(const std::string& filename);
cocos2d::Node* loadNodeWithFile(const std::string& fileName);

View File

@ -34,7 +34,7 @@ namespace cocostudio {
class CC_STUDIO_DLL ComRender : public cocos2d::Component
{
DECLARE_CLASS_COMPONENT_INFO
protected:
CC_CONSTRUCTOR_ACCESS:
/**
* @js ctor
*/

View File

@ -3,6 +3,8 @@ if(WINDOWS AND BUILD_SHARED_LIBS)
ADD_DEFINITIONS (-D_USRSTUDIODLL)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
set(COCOS_CS_SRC
editor-support/cocostudio/CCActionFrame.cpp

View File

@ -33,15 +33,18 @@ struct ListViewOptions;
struct ProjectNodeOptions;
struct ComponentOptions;
struct ComAudioOptions;
struct AnimationInfo;
struct NodeAction;
struct TimeLine;
struct Frame;
struct TimeLineBoolFrame;
struct TimeLineIntFrame;
struct TimeLineStringFrame;
struct TimeLinePointFrame;
struct TimeLineColorFrame;
struct TimeLineTextureFrame;
struct PointFrame;
struct ScaleFrame;
struct ColorFrame;
struct TextureFrame;
struct EventFrame;
struct IntFrame;
struct BoolFrame;
struct InnerActionFrame;
struct RotationSkew;
struct Position;
struct Scale;
@ -177,7 +180,8 @@ struct CSParseBinary : private flatbuffers::Table {
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *texturePngs() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(6); }
const NodeTree *nodeTree() const { return GetPointer<const NodeTree *>(8); }
const NodeAction *action() const { return GetPointer<const NodeAction *>(10); }
const flatbuffers::String *version() const { return GetPointer<const flatbuffers::String *>(12); }
const flatbuffers::Vector<flatbuffers::Offset<AnimationInfo>> *animationList() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<AnimationInfo>> *>(12); }
const flatbuffers::String *version() const { return GetPointer<const flatbuffers::String *>(14); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* textures */) &&
@ -190,7 +194,10 @@ struct CSParseBinary : private flatbuffers::Table {
verifier.VerifyTable(nodeTree()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 10 /* action */) &&
verifier.VerifyTable(action()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 12 /* version */) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 12 /* animationList */) &&
verifier.Verify(animationList()) &&
verifier.VerifyVectorOfTables(animationList()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 14 /* version */) &&
verifier.Verify(version()) &&
verifier.EndTable();
}
@ -203,11 +210,12 @@ struct CSParseBinaryBuilder {
void add_texturePngs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> texturePngs) { fbb_.AddOffset(6, texturePngs); }
void add_nodeTree(flatbuffers::Offset<NodeTree> nodeTree) { fbb_.AddOffset(8, nodeTree); }
void add_action(flatbuffers::Offset<NodeAction> action) { fbb_.AddOffset(10, action); }
void add_version(flatbuffers::Offset<flatbuffers::String> version) { fbb_.AddOffset(12, version); }
void add_animationList(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<AnimationInfo>>> animationList) { fbb_.AddOffset(12, animationList); }
void add_version(flatbuffers::Offset<flatbuffers::String> version) { fbb_.AddOffset(14, version); }
CSParseBinaryBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
CSParseBinaryBuilder &operator=(const CSParseBinaryBuilder &);
flatbuffers::Offset<CSParseBinary> Finish() {
auto o = flatbuffers::Offset<CSParseBinary>(fbb_.EndTable(start_, 5));
auto o = flatbuffers::Offset<CSParseBinary>(fbb_.EndTable(start_, 6));
return o;
}
};
@ -217,9 +225,11 @@ inline flatbuffers::Offset<CSParseBinary> CreateCSParseBinary(flatbuffers::FlatB
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> texturePngs = 0,
flatbuffers::Offset<NodeTree> nodeTree = 0,
flatbuffers::Offset<NodeAction> action = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<AnimationInfo>>> animationList = 0,
flatbuffers::Offset<flatbuffers::String> version = 0) {
CSParseBinaryBuilder builder_(_fbb);
builder_.add_version(version);
builder_.add_animationList(animationList);
builder_.add_action(action);
builder_.add_nodeTree(nodeTree);
builder_.add_texturePngs(texturePngs);
@ -1675,16 +1685,12 @@ inline flatbuffers::Offset<ListViewOptions> CreateListViewOptions(flatbuffers::F
struct ProjectNodeOptions : private flatbuffers::Table {
const WidgetOptions *nodeOptions() const { return GetPointer<const WidgetOptions *>(4); }
const flatbuffers::String *fileName() const { return GetPointer<const flatbuffers::String *>(6); }
uint8_t isLoop() const { return GetField<uint8_t>(8, 1); }
uint8_t isAutoPlay() const { return GetField<uint8_t>(10, 1); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* nodeOptions */) &&
verifier.VerifyTable(nodeOptions()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 6 /* fileName */) &&
verifier.Verify(fileName()) &&
VerifyField<uint8_t>(verifier, 8 /* isLoop */) &&
VerifyField<uint8_t>(verifier, 10 /* isAutoPlay */) &&
verifier.EndTable();
}
};
@ -1694,26 +1700,20 @@ struct ProjectNodeOptionsBuilder {
flatbuffers::uoffset_t start_;
void add_nodeOptions(flatbuffers::Offset<WidgetOptions> nodeOptions) { fbb_.AddOffset(4, nodeOptions); }
void add_fileName(flatbuffers::Offset<flatbuffers::String> fileName) { fbb_.AddOffset(6, fileName); }
void add_isLoop(uint8_t isLoop) { fbb_.AddElement<uint8_t>(8, isLoop, 1); }
void add_isAutoPlay(uint8_t isAutoPlay) { fbb_.AddElement<uint8_t>(10, isAutoPlay, 1); }
ProjectNodeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
ProjectNodeOptionsBuilder &operator=(const ProjectNodeOptionsBuilder &);
flatbuffers::Offset<ProjectNodeOptions> Finish() {
auto o = flatbuffers::Offset<ProjectNodeOptions>(fbb_.EndTable(start_, 4));
auto o = flatbuffers::Offset<ProjectNodeOptions>(fbb_.EndTable(start_, 2));
return o;
}
};
inline flatbuffers::Offset<ProjectNodeOptions> CreateProjectNodeOptions(flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<WidgetOptions> nodeOptions = 0,
flatbuffers::Offset<flatbuffers::String> fileName = 0,
uint8_t isLoop = 1,
uint8_t isAutoPlay = 1) {
flatbuffers::Offset<flatbuffers::String> fileName = 0) {
ProjectNodeOptionsBuilder builder_(_fbb);
builder_.add_fileName(fileName);
builder_.add_nodeOptions(nodeOptions);
builder_.add_isAutoPlay(isAutoPlay);
builder_.add_isLoop(isLoop);
return builder_.Finish();
}
@ -1814,10 +1814,50 @@ inline flatbuffers::Offset<ComAudioOptions> CreateComAudioOptions(flatbuffers::F
return builder_.Finish();
}
struct AnimationInfo : private flatbuffers::Table {
const flatbuffers::String *name() const { return GetPointer<const flatbuffers::String *>(4); }
int32_t startIndex() const { return GetField<int32_t>(6, 0); }
int32_t endIndex() const { return GetField<int32_t>(8, 0); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* name */) &&
verifier.Verify(name()) &&
VerifyField<int32_t>(verifier, 6 /* startIndex */) &&
VerifyField<int32_t>(verifier, 8 /* endIndex */) &&
verifier.EndTable();
}
};
struct AnimationInfoBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_name(flatbuffers::Offset<flatbuffers::String> name) { fbb_.AddOffset(4, name); }
void add_startIndex(int32_t startIndex) { fbb_.AddElement<int32_t>(6, startIndex, 0); }
void add_endIndex(int32_t endIndex) { fbb_.AddElement<int32_t>(8, endIndex, 0); }
AnimationInfoBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
AnimationInfoBuilder &operator=(const AnimationInfoBuilder &);
flatbuffers::Offset<AnimationInfo> Finish() {
auto o = flatbuffers::Offset<AnimationInfo>(fbb_.EndTable(start_, 3));
return o;
}
};
inline flatbuffers::Offset<AnimationInfo> CreateAnimationInfo(flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::String> name = 0,
int32_t startIndex = 0,
int32_t endIndex = 0) {
AnimationInfoBuilder builder_(_fbb);
builder_.add_endIndex(endIndex);
builder_.add_startIndex(startIndex);
builder_.add_name(name);
return builder_.Finish();
}
struct NodeAction : private flatbuffers::Table {
int32_t duration() const { return GetField<int32_t>(4, 0); }
float speed() const { return GetField<float>(6, 0); }
const flatbuffers::Vector<flatbuffers::Offset<TimeLine>> *timeLines() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<TimeLine>> *>(8); }
const flatbuffers::String *currentAnimationName() const { return GetPointer<const flatbuffers::String *>(10); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int32_t>(verifier, 4 /* duration */) &&
@ -1825,6 +1865,8 @@ struct NodeAction : private flatbuffers::Table {
VerifyField<flatbuffers::uoffset_t>(verifier, 8 /* timeLines */) &&
verifier.Verify(timeLines()) &&
verifier.VerifyVectorOfTables(timeLines()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 10 /* currentAnimationName */) &&
verifier.Verify(currentAnimationName()) &&
verifier.EndTable();
}
};
@ -1835,10 +1877,11 @@ struct NodeActionBuilder {
void add_duration(int32_t duration) { fbb_.AddElement<int32_t>(4, duration, 0); }
void add_speed(float speed) { fbb_.AddElement<float>(6, speed, 0); }
void add_timeLines(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<TimeLine>>> timeLines) { fbb_.AddOffset(8, timeLines); }
void add_currentAnimationName(flatbuffers::Offset<flatbuffers::String> currentAnimationName) { fbb_.AddOffset(10, currentAnimationName); }
NodeActionBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
NodeActionBuilder &operator=(const NodeActionBuilder &);
flatbuffers::Offset<NodeAction> Finish() {
auto o = flatbuffers::Offset<NodeAction>(fbb_.EndTable(start_, 3));
auto o = flatbuffers::Offset<NodeAction>(fbb_.EndTable(start_, 4));
return o;
}
};
@ -1846,8 +1889,10 @@ struct NodeActionBuilder {
inline flatbuffers::Offset<NodeAction> CreateNodeAction(flatbuffers::FlatBufferBuilder &_fbb,
int32_t duration = 0,
float speed = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<TimeLine>>> timeLines = 0) {
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<TimeLine>>> timeLines = 0,
flatbuffers::Offset<flatbuffers::String> currentAnimationName = 0) {
NodeActionBuilder builder_(_fbb);
builder_.add_currentAnimationName(currentAnimationName);
builder_.add_timeLines(timeLines);
builder_.add_speed(speed);
builder_.add_duration(duration);
@ -1855,13 +1900,13 @@ inline flatbuffers::Offset<NodeAction> CreateNodeAction(flatbuffers::FlatBufferB
}
struct TimeLine : private flatbuffers::Table {
const flatbuffers::String *frameType() const { return GetPointer<const flatbuffers::String *>(4); }
const flatbuffers::String *property() const { return GetPointer<const flatbuffers::String *>(4); }
int32_t actionTag() const { return GetField<int32_t>(6, 0); }
const flatbuffers::Vector<flatbuffers::Offset<Frame>> *frames() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<Frame>> *>(8); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* frameType */) &&
verifier.Verify(frameType()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* property */) &&
verifier.Verify(property()) &&
VerifyField<int32_t>(verifier, 6 /* actionTag */) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 8 /* frames */) &&
verifier.Verify(frames()) &&
@ -1873,7 +1918,7 @@ struct TimeLine : private flatbuffers::Table {
struct TimeLineBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_frameType(flatbuffers::Offset<flatbuffers::String> frameType) { fbb_.AddOffset(4, frameType); }
void add_property(flatbuffers::Offset<flatbuffers::String> property) { fbb_.AddOffset(4, property); }
void add_actionTag(int32_t actionTag) { fbb_.AddElement<int32_t>(6, actionTag, 0); }
void add_frames(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Frame>>> frames) { fbb_.AddOffset(8, frames); }
TimeLineBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
@ -1885,46 +1930,43 @@ struct TimeLineBuilder {
};
inline flatbuffers::Offset<TimeLine> CreateTimeLine(flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::String> frameType = 0,
flatbuffers::Offset<flatbuffers::String> property = 0,
int32_t actionTag = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Frame>>> frames = 0) {
TimeLineBuilder builder_(_fbb);
builder_.add_frames(frames);
builder_.add_actionTag(actionTag);
builder_.add_frameType(frameType);
builder_.add_property(property);
return builder_.Finish();
}
struct Frame : private flatbuffers::Table {
const TimeLineBoolFrame *visibleFrame() const { return GetPointer<const TimeLineBoolFrame *>(4); }
const TimeLineIntFrame *zOrderFrame() const { return GetPointer<const TimeLineIntFrame *>(6); }
const TimeLinePointFrame *rotationSkewFrame() const { return GetPointer<const TimeLinePointFrame *>(8); }
const TimeLineStringFrame *eventFrame() const { return GetPointer<const TimeLineStringFrame *>(10); }
const TimeLinePointFrame *anchorPointFrame() const { return GetPointer<const TimeLinePointFrame *>(12); }
const TimeLinePointFrame *positionFrame() const { return GetPointer<const TimeLinePointFrame *>(14); }
const TimeLinePointFrame *scaleFrame() const { return GetPointer<const TimeLinePointFrame *>(16); }
const TimeLineColorFrame *colorFrame() const { return GetPointer<const TimeLineColorFrame *>(18); }
const TimeLineTextureFrame *textureFrame() const { return GetPointer<const TimeLineTextureFrame *>(20); }
const PointFrame *pointFrame() const { return GetPointer<const PointFrame *>(4); }
const ScaleFrame *scaleFrame() const { return GetPointer<const ScaleFrame *>(6); }
const ColorFrame *colorFrame() const { return GetPointer<const ColorFrame *>(8); }
const TextureFrame *textureFrame() const { return GetPointer<const TextureFrame *>(10); }
const EventFrame *eventFrame() const { return GetPointer<const EventFrame *>(12); }
const IntFrame *intFrame() const { return GetPointer<const IntFrame *>(14); }
const BoolFrame *boolFrame() const { return GetPointer<const BoolFrame *>(16); }
const InnerActionFrame *innerActionFrame() const { return GetPointer<const InnerActionFrame *>(18); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* visibleFrame */) &&
verifier.VerifyTable(visibleFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 6 /* zOrderFrame */) &&
verifier.VerifyTable(zOrderFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 8 /* rotationSkewFrame */) &&
verifier.VerifyTable(rotationSkewFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 10 /* eventFrame */) &&
verifier.VerifyTable(eventFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 12 /* anchorPointFrame */) &&
verifier.VerifyTable(anchorPointFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 14 /* positionFrame */) &&
verifier.VerifyTable(positionFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 16 /* scaleFrame */) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 4 /* pointFrame */) &&
verifier.VerifyTable(pointFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 6 /* scaleFrame */) &&
verifier.VerifyTable(scaleFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 18 /* colorFrame */) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 8 /* colorFrame */) &&
verifier.VerifyTable(colorFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 20 /* textureFrame */) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 10 /* textureFrame */) &&
verifier.VerifyTable(textureFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 12 /* eventFrame */) &&
verifier.VerifyTable(eventFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 14 /* intFrame */) &&
verifier.VerifyTable(intFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 16 /* boolFrame */) &&
verifier.VerifyTable(boolFrame()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 18 /* innerActionFrame */) &&
verifier.VerifyTable(innerActionFrame()) &&
verifier.EndTable();
}
};
@ -1932,123 +1974,197 @@ struct Frame : private flatbuffers::Table {
struct FrameBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_visibleFrame(flatbuffers::Offset<TimeLineBoolFrame> visibleFrame) { fbb_.AddOffset(4, visibleFrame); }
void add_zOrderFrame(flatbuffers::Offset<TimeLineIntFrame> zOrderFrame) { fbb_.AddOffset(6, zOrderFrame); }
void add_rotationSkewFrame(flatbuffers::Offset<TimeLinePointFrame> rotationSkewFrame) { fbb_.AddOffset(8, rotationSkewFrame); }
void add_eventFrame(flatbuffers::Offset<TimeLineStringFrame> eventFrame) { fbb_.AddOffset(10, eventFrame); }
void add_anchorPointFrame(flatbuffers::Offset<TimeLinePointFrame> anchorPointFrame) { fbb_.AddOffset(12, anchorPointFrame); }
void add_positionFrame(flatbuffers::Offset<TimeLinePointFrame> positionFrame) { fbb_.AddOffset(14, positionFrame); }
void add_scaleFrame(flatbuffers::Offset<TimeLinePointFrame> scaleFrame) { fbb_.AddOffset(16, scaleFrame); }
void add_colorFrame(flatbuffers::Offset<TimeLineColorFrame> colorFrame) { fbb_.AddOffset(18, colorFrame); }
void add_textureFrame(flatbuffers::Offset<TimeLineTextureFrame> textureFrame) { fbb_.AddOffset(20, textureFrame); }
void add_pointFrame(flatbuffers::Offset<PointFrame> pointFrame) { fbb_.AddOffset(4, pointFrame); }
void add_scaleFrame(flatbuffers::Offset<ScaleFrame> scaleFrame) { fbb_.AddOffset(6, scaleFrame); }
void add_colorFrame(flatbuffers::Offset<ColorFrame> colorFrame) { fbb_.AddOffset(8, colorFrame); }
void add_textureFrame(flatbuffers::Offset<TextureFrame> textureFrame) { fbb_.AddOffset(10, textureFrame); }
void add_eventFrame(flatbuffers::Offset<EventFrame> eventFrame) { fbb_.AddOffset(12, eventFrame); }
void add_intFrame(flatbuffers::Offset<IntFrame> intFrame) { fbb_.AddOffset(14, intFrame); }
void add_boolFrame(flatbuffers::Offset<BoolFrame> boolFrame) { fbb_.AddOffset(16, boolFrame); }
void add_innerActionFrame(flatbuffers::Offset<InnerActionFrame> innerActionFrame) { fbb_.AddOffset(18, innerActionFrame); }
FrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
FrameBuilder &operator=(const FrameBuilder &);
flatbuffers::Offset<Frame> Finish() {
auto o = flatbuffers::Offset<Frame>(fbb_.EndTable(start_, 9));
auto o = flatbuffers::Offset<Frame>(fbb_.EndTable(start_, 8));
return o;
}
};
inline flatbuffers::Offset<Frame> CreateFrame(flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<TimeLineBoolFrame> visibleFrame = 0,
flatbuffers::Offset<TimeLineIntFrame> zOrderFrame = 0,
flatbuffers::Offset<TimeLinePointFrame> rotationSkewFrame = 0,
flatbuffers::Offset<TimeLineStringFrame> eventFrame = 0,
flatbuffers::Offset<TimeLinePointFrame> anchorPointFrame = 0,
flatbuffers::Offset<TimeLinePointFrame> positionFrame = 0,
flatbuffers::Offset<TimeLinePointFrame> scaleFrame = 0,
flatbuffers::Offset<TimeLineColorFrame> colorFrame = 0,
flatbuffers::Offset<TimeLineTextureFrame> textureFrame = 0) {
flatbuffers::Offset<PointFrame> pointFrame = 0,
flatbuffers::Offset<ScaleFrame> scaleFrame = 0,
flatbuffers::Offset<ColorFrame> colorFrame = 0,
flatbuffers::Offset<TextureFrame> textureFrame = 0,
flatbuffers::Offset<EventFrame> eventFrame = 0,
flatbuffers::Offset<IntFrame> intFrame = 0,
flatbuffers::Offset<BoolFrame> boolFrame = 0,
flatbuffers::Offset<InnerActionFrame> innerActionFrame = 0) {
FrameBuilder builder_(_fbb);
builder_.add_innerActionFrame(innerActionFrame);
builder_.add_boolFrame(boolFrame);
builder_.add_intFrame(intFrame);
builder_.add_eventFrame(eventFrame);
builder_.add_textureFrame(textureFrame);
builder_.add_colorFrame(colorFrame);
builder_.add_scaleFrame(scaleFrame);
builder_.add_positionFrame(positionFrame);
builder_.add_anchorPointFrame(anchorPointFrame);
builder_.add_eventFrame(eventFrame);
builder_.add_rotationSkewFrame(rotationSkewFrame);
builder_.add_zOrderFrame(zOrderFrame);
builder_.add_visibleFrame(visibleFrame);
builder_.add_pointFrame(pointFrame);
return builder_.Finish();
}
struct TimeLineBoolFrame : private flatbuffers::Table {
struct PointFrame : private flatbuffers::Table {
int32_t frameIndex() const { return GetField<int32_t>(4, 0); }
uint8_t tween() const { return GetField<uint8_t>(6, 1); }
uint8_t value() const { return GetField<uint8_t>(8, 0); }
const Position *postion() const { return GetStruct<const Position *>(8); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int32_t>(verifier, 4 /* frameIndex */) &&
VerifyField<uint8_t>(verifier, 6 /* tween */) &&
VerifyField<uint8_t>(verifier, 8 /* value */) &&
VerifyField<Position>(verifier, 8 /* postion */) &&
verifier.EndTable();
}
};
struct TimeLineBoolFrameBuilder {
struct PointFrameBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_frameIndex(int32_t frameIndex) { fbb_.AddElement<int32_t>(4, frameIndex, 0); }
void add_tween(uint8_t tween) { fbb_.AddElement<uint8_t>(6, tween, 1); }
void add_value(uint8_t value) { fbb_.AddElement<uint8_t>(8, value, 0); }
TimeLineBoolFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
TimeLineBoolFrameBuilder &operator=(const TimeLineBoolFrameBuilder &);
flatbuffers::Offset<TimeLineBoolFrame> Finish() {
auto o = flatbuffers::Offset<TimeLineBoolFrame>(fbb_.EndTable(start_, 3));
void add_postion(const Position *postion) { fbb_.AddStruct(8, postion); }
PointFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
PointFrameBuilder &operator=(const PointFrameBuilder &);
flatbuffers::Offset<PointFrame> Finish() {
auto o = flatbuffers::Offset<PointFrame>(fbb_.EndTable(start_, 3));
return o;
}
};
inline flatbuffers::Offset<TimeLineBoolFrame> CreateTimeLineBoolFrame(flatbuffers::FlatBufferBuilder &_fbb,
inline flatbuffers::Offset<PointFrame> CreatePointFrame(flatbuffers::FlatBufferBuilder &_fbb,
int32_t frameIndex = 0,
uint8_t tween = 1,
uint8_t value = 0) {
TimeLineBoolFrameBuilder builder_(_fbb);
builder_.add_frameIndex(frameIndex);
builder_.add_value(value);
builder_.add_tween(tween);
return builder_.Finish();
}
struct TimeLineIntFrame : private flatbuffers::Table {
int32_t frameIndex() const { return GetField<int32_t>(4, 0); }
uint8_t tween() const { return GetField<uint8_t>(6, 1); }
int32_t value() const { return GetField<int32_t>(8, 0); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int32_t>(verifier, 4 /* frameIndex */) &&
VerifyField<uint8_t>(verifier, 6 /* tween */) &&
VerifyField<int32_t>(verifier, 8 /* value */) &&
verifier.EndTable();
}
};
struct TimeLineIntFrameBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_frameIndex(int32_t frameIndex) { fbb_.AddElement<int32_t>(4, frameIndex, 0); }
void add_tween(uint8_t tween) { fbb_.AddElement<uint8_t>(6, tween, 1); }
void add_value(int32_t value) { fbb_.AddElement<int32_t>(8, value, 0); }
TimeLineIntFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
TimeLineIntFrameBuilder &operator=(const TimeLineIntFrameBuilder &);
flatbuffers::Offset<TimeLineIntFrame> Finish() {
auto o = flatbuffers::Offset<TimeLineIntFrame>(fbb_.EndTable(start_, 3));
return o;
}
};
inline flatbuffers::Offset<TimeLineIntFrame> CreateTimeLineIntFrame(flatbuffers::FlatBufferBuilder &_fbb,
int32_t frameIndex = 0,
uint8_t tween = 1,
int32_t value = 0) {
TimeLineIntFrameBuilder builder_(_fbb);
builder_.add_value(value);
const Position *postion = 0) {
PointFrameBuilder builder_(_fbb);
builder_.add_postion(postion);
builder_.add_frameIndex(frameIndex);
builder_.add_tween(tween);
return builder_.Finish();
}
struct TimeLineStringFrame : private flatbuffers::Table {
struct ScaleFrame : private flatbuffers::Table {
int32_t frameIndex() const { return GetField<int32_t>(4, 0); }
uint8_t tween() const { return GetField<uint8_t>(6, 1); }
const Scale *scale() const { return GetStruct<const Scale *>(8); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int32_t>(verifier, 4 /* frameIndex */) &&
VerifyField<uint8_t>(verifier, 6 /* tween */) &&
VerifyField<Scale>(verifier, 8 /* scale */) &&
verifier.EndTable();
}
};
struct ScaleFrameBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_frameIndex(int32_t frameIndex) { fbb_.AddElement<int32_t>(4, frameIndex, 0); }
void add_tween(uint8_t tween) { fbb_.AddElement<uint8_t>(6, tween, 1); }
void add_scale(const Scale *scale) { fbb_.AddStruct(8, scale); }
ScaleFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
ScaleFrameBuilder &operator=(const ScaleFrameBuilder &);
flatbuffers::Offset<ScaleFrame> Finish() {
auto o = flatbuffers::Offset<ScaleFrame>(fbb_.EndTable(start_, 3));
return o;
}
};
inline flatbuffers::Offset<ScaleFrame> CreateScaleFrame(flatbuffers::FlatBufferBuilder &_fbb,
int32_t frameIndex = 0,
uint8_t tween = 1,
const Scale *scale = 0) {
ScaleFrameBuilder builder_(_fbb);
builder_.add_scale(scale);
builder_.add_frameIndex(frameIndex);
builder_.add_tween(tween);
return builder_.Finish();
}
struct ColorFrame : private flatbuffers::Table {
int32_t frameIndex() const { return GetField<int32_t>(4, 0); }
uint8_t tween() const { return GetField<uint8_t>(6, 1); }
const Color *color() const { return GetStruct<const Color *>(8); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int32_t>(verifier, 4 /* frameIndex */) &&
VerifyField<uint8_t>(verifier, 6 /* tween */) &&
VerifyField<Color>(verifier, 8 /* color */) &&
verifier.EndTable();
}
};
struct ColorFrameBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_frameIndex(int32_t frameIndex) { fbb_.AddElement<int32_t>(4, frameIndex, 0); }
void add_tween(uint8_t tween) { fbb_.AddElement<uint8_t>(6, tween, 1); }
void add_color(const Color *color) { fbb_.AddStruct(8, color); }
ColorFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
ColorFrameBuilder &operator=(const ColorFrameBuilder &);
flatbuffers::Offset<ColorFrame> Finish() {
auto o = flatbuffers::Offset<ColorFrame>(fbb_.EndTable(start_, 3));
return o;
}
};
inline flatbuffers::Offset<ColorFrame> CreateColorFrame(flatbuffers::FlatBufferBuilder &_fbb,
int32_t frameIndex = 0,
uint8_t tween = 1,
const Color *color = 0) {
ColorFrameBuilder builder_(_fbb);
builder_.add_color(color);
builder_.add_frameIndex(frameIndex);
builder_.add_tween(tween);
return builder_.Finish();
}
struct TextureFrame : private flatbuffers::Table {
int32_t frameIndex() const { return GetField<int32_t>(4, 0); }
uint8_t tween() const { return GetField<uint8_t>(6, 1); }
const ResourceData *textureFile() const { return GetPointer<const ResourceData *>(8); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int32_t>(verifier, 4 /* frameIndex */) &&
VerifyField<uint8_t>(verifier, 6 /* tween */) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 8 /* textureFile */) &&
verifier.VerifyTable(textureFile()) &&
verifier.EndTable();
}
};
struct TextureFrameBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_frameIndex(int32_t frameIndex) { fbb_.AddElement<int32_t>(4, frameIndex, 0); }
void add_tween(uint8_t tween) { fbb_.AddElement<uint8_t>(6, tween, 1); }
void add_textureFile(flatbuffers::Offset<ResourceData> textureFile) { fbb_.AddOffset(8, textureFile); }
TextureFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
TextureFrameBuilder &operator=(const TextureFrameBuilder &);
flatbuffers::Offset<TextureFrame> Finish() {
auto o = flatbuffers::Offset<TextureFrame>(fbb_.EndTable(start_, 3));
return o;
}
};
inline flatbuffers::Offset<TextureFrame> CreateTextureFrame(flatbuffers::FlatBufferBuilder &_fbb,
int32_t frameIndex = 0,
uint8_t tween = 1,
flatbuffers::Offset<ResourceData> textureFile = 0) {
TextureFrameBuilder builder_(_fbb);
builder_.add_textureFile(textureFile);
builder_.add_frameIndex(frameIndex);
builder_.add_tween(tween);
return builder_.Finish();
}
struct EventFrame : private flatbuffers::Table {
int32_t frameIndex() const { return GetField<int32_t>(4, 0); }
uint8_t tween() const { return GetField<uint8_t>(6, 1); }
const flatbuffers::String *value() const { return GetPointer<const flatbuffers::String *>(8); }
@ -2062,141 +2178,151 @@ struct TimeLineStringFrame : private flatbuffers::Table {
}
};
struct TimeLineStringFrameBuilder {
struct EventFrameBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_frameIndex(int32_t frameIndex) { fbb_.AddElement<int32_t>(4, frameIndex, 0); }
void add_tween(uint8_t tween) { fbb_.AddElement<uint8_t>(6, tween, 1); }
void add_value(flatbuffers::Offset<flatbuffers::String> value) { fbb_.AddOffset(8, value); }
TimeLineStringFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
TimeLineStringFrameBuilder &operator=(const TimeLineStringFrameBuilder &);
flatbuffers::Offset<TimeLineStringFrame> Finish() {
auto o = flatbuffers::Offset<TimeLineStringFrame>(fbb_.EndTable(start_, 3));
EventFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
EventFrameBuilder &operator=(const EventFrameBuilder &);
flatbuffers::Offset<EventFrame> Finish() {
auto o = flatbuffers::Offset<EventFrame>(fbb_.EndTable(start_, 3));
return o;
}
};
inline flatbuffers::Offset<TimeLineStringFrame> CreateTimeLineStringFrame(flatbuffers::FlatBufferBuilder &_fbb,
inline flatbuffers::Offset<EventFrame> CreateEventFrame(flatbuffers::FlatBufferBuilder &_fbb,
int32_t frameIndex = 0,
uint8_t tween = 1,
flatbuffers::Offset<flatbuffers::String> value = 0) {
TimeLineStringFrameBuilder builder_(_fbb);
EventFrameBuilder builder_(_fbb);
builder_.add_value(value);
builder_.add_frameIndex(frameIndex);
builder_.add_tween(tween);
return builder_.Finish();
}
struct TimeLinePointFrame : private flatbuffers::Table {
struct IntFrame : private flatbuffers::Table {
int32_t frameIndex() const { return GetField<int32_t>(4, 0); }
uint8_t tween() const { return GetField<uint8_t>(6, 1); }
const Position *postion() const { return GetStruct<const Position *>(8); }
int32_t value() const { return GetField<int32_t>(8, 0); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int32_t>(verifier, 4 /* frameIndex */) &&
VerifyField<uint8_t>(verifier, 6 /* tween */) &&
VerifyField<Position>(verifier, 8 /* postion */) &&
VerifyField<int32_t>(verifier, 8 /* value */) &&
verifier.EndTable();
}
};
struct TimeLinePointFrameBuilder {
struct IntFrameBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_frameIndex(int32_t frameIndex) { fbb_.AddElement<int32_t>(4, frameIndex, 0); }
void add_tween(uint8_t tween) { fbb_.AddElement<uint8_t>(6, tween, 1); }
void add_postion(const Position *postion) { fbb_.AddStruct(8, postion); }
TimeLinePointFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
TimeLinePointFrameBuilder &operator=(const TimeLinePointFrameBuilder &);
flatbuffers::Offset<TimeLinePointFrame> Finish() {
auto o = flatbuffers::Offset<TimeLinePointFrame>(fbb_.EndTable(start_, 3));
void add_value(int32_t value) { fbb_.AddElement<int32_t>(8, value, 0); }
IntFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
IntFrameBuilder &operator=(const IntFrameBuilder &);
flatbuffers::Offset<IntFrame> Finish() {
auto o = flatbuffers::Offset<IntFrame>(fbb_.EndTable(start_, 3));
return o;
}
};
inline flatbuffers::Offset<TimeLinePointFrame> CreateTimeLinePointFrame(flatbuffers::FlatBufferBuilder &_fbb,
inline flatbuffers::Offset<IntFrame> CreateIntFrame(flatbuffers::FlatBufferBuilder &_fbb,
int32_t frameIndex = 0,
uint8_t tween = 1,
const Position *postion = 0) {
TimeLinePointFrameBuilder builder_(_fbb);
builder_.add_postion(postion);
int32_t value = 0) {
IntFrameBuilder builder_(_fbb);
builder_.add_value(value);
builder_.add_frameIndex(frameIndex);
builder_.add_tween(tween);
return builder_.Finish();
}
struct TimeLineColorFrame : private flatbuffers::Table {
struct BoolFrame : private flatbuffers::Table {
int32_t frameIndex() const { return GetField<int32_t>(4, 0); }
uint8_t tween() const { return GetField<uint8_t>(6, 1); }
const Color *color() const { return GetStruct<const Color *>(8); }
uint8_t value() const { return GetField<uint8_t>(8, 1); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int32_t>(verifier, 4 /* frameIndex */) &&
VerifyField<uint8_t>(verifier, 6 /* tween */) &&
VerifyField<Color>(verifier, 8 /* color */) &&
VerifyField<uint8_t>(verifier, 8 /* value */) &&
verifier.EndTable();
}
};
struct TimeLineColorFrameBuilder {
struct BoolFrameBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_frameIndex(int32_t frameIndex) { fbb_.AddElement<int32_t>(4, frameIndex, 0); }
void add_tween(uint8_t tween) { fbb_.AddElement<uint8_t>(6, tween, 1); }
void add_color(const Color *color) { fbb_.AddStruct(8, color); }
TimeLineColorFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
TimeLineColorFrameBuilder &operator=(const TimeLineColorFrameBuilder &);
flatbuffers::Offset<TimeLineColorFrame> Finish() {
auto o = flatbuffers::Offset<TimeLineColorFrame>(fbb_.EndTable(start_, 3));
void add_value(uint8_t value) { fbb_.AddElement<uint8_t>(8, value, 1); }
BoolFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
BoolFrameBuilder &operator=(const BoolFrameBuilder &);
flatbuffers::Offset<BoolFrame> Finish() {
auto o = flatbuffers::Offset<BoolFrame>(fbb_.EndTable(start_, 3));
return o;
}
};
inline flatbuffers::Offset<TimeLineColorFrame> CreateTimeLineColorFrame(flatbuffers::FlatBufferBuilder &_fbb,
inline flatbuffers::Offset<BoolFrame> CreateBoolFrame(flatbuffers::FlatBufferBuilder &_fbb,
int32_t frameIndex = 0,
uint8_t tween = 1,
const Color *color = 0) {
TimeLineColorFrameBuilder builder_(_fbb);
builder_.add_color(color);
uint8_t value = 1) {
BoolFrameBuilder builder_(_fbb);
builder_.add_frameIndex(frameIndex);
builder_.add_value(value);
builder_.add_tween(tween);
return builder_.Finish();
}
struct TimeLineTextureFrame : private flatbuffers::Table {
struct InnerActionFrame : private flatbuffers::Table {
int32_t frameIndex() const { return GetField<int32_t>(4, 0); }
uint8_t tween() const { return GetField<uint8_t>(6, 1); }
const ResourceData *fileNameData() const { return GetPointer<const ResourceData *>(8); }
int32_t innerActionType() const { return GetField<int32_t>(8, 0); }
const flatbuffers::String *currentAniamtionName() const { return GetPointer<const flatbuffers::String *>(10); }
int32_t singleFrameIndex() const { return GetField<int32_t>(12, 0); }
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<int32_t>(verifier, 4 /* frameIndex */) &&
VerifyField<uint8_t>(verifier, 6 /* tween */) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 8 /* fileNameData */) &&
verifier.VerifyTable(fileNameData()) &&
VerifyField<int32_t>(verifier, 8 /* innerActionType */) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 10 /* currentAniamtionName */) &&
verifier.Verify(currentAniamtionName()) &&
VerifyField<int32_t>(verifier, 12 /* singleFrameIndex */) &&
verifier.EndTable();
}
};
struct TimeLineTextureFrameBuilder {
struct InnerActionFrameBuilder {
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_frameIndex(int32_t frameIndex) { fbb_.AddElement<int32_t>(4, frameIndex, 0); }
void add_tween(uint8_t tween) { fbb_.AddElement<uint8_t>(6, tween, 1); }
void add_fileNameData(flatbuffers::Offset<ResourceData> fileNameData) { fbb_.AddOffset(8, fileNameData); }
TimeLineTextureFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
TimeLineTextureFrameBuilder &operator=(const TimeLineTextureFrameBuilder &);
flatbuffers::Offset<TimeLineTextureFrame> Finish() {
auto o = flatbuffers::Offset<TimeLineTextureFrame>(fbb_.EndTable(start_, 3));
void add_innerActionType(int32_t innerActionType) { fbb_.AddElement<int32_t>(8, innerActionType, 0); }
void add_currentAniamtionName(flatbuffers::Offset<flatbuffers::String> currentAniamtionName) { fbb_.AddOffset(10, currentAniamtionName); }
void add_singleFrameIndex(int32_t singleFrameIndex) { fbb_.AddElement<int32_t>(12, singleFrameIndex, 0); }
InnerActionFrameBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
InnerActionFrameBuilder &operator=(const InnerActionFrameBuilder &);
flatbuffers::Offset<InnerActionFrame> Finish() {
auto o = flatbuffers::Offset<InnerActionFrame>(fbb_.EndTable(start_, 5));
return o;
}
};
inline flatbuffers::Offset<TimeLineTextureFrame> CreateTimeLineTextureFrame(flatbuffers::FlatBufferBuilder &_fbb,
inline flatbuffers::Offset<InnerActionFrame> CreateInnerActionFrame(flatbuffers::FlatBufferBuilder &_fbb,
int32_t frameIndex = 0,
uint8_t tween = 1,
flatbuffers::Offset<ResourceData> fileNameData = 0) {
TimeLineTextureFrameBuilder builder_(_fbb);
builder_.add_fileNameData(fileNameData);
int32_t innerActionType = 0,
flatbuffers::Offset<flatbuffers::String> currentAniamtionName = 0,
int32_t singleFrameIndex = 0) {
InnerActionFrameBuilder builder_(_fbb);
builder_.add_singleFrameIndex(singleFrameIndex);
builder_.add_currentAniamtionName(currentAniamtionName);
builder_.add_innerActionType(innerActionType);
builder_.add_frameIndex(frameIndex);
builder_.add_tween(tween);
return builder_.Finish();

View File

@ -68,15 +68,16 @@ using namespace flatbuffers;
namespace cocostudio {
static const char* FrameType_VisibleFrame = "VisibleFrame";
static const char* FrameType_PositionFrame = "PositionFrame";
static const char* FrameType_ScaleFrame = "ScaleFrame";
static const char* FrameType_RotationSkewFrame = "RotationSkewFrame";
static const char* FrameType_AnchorFrame = "AnchorPointFrame";
static const char* FrameType_ColorFrame = "ColorFrame";
static const char* FrameType_TextureFrame = "TextureFrame";
static const char* FrameType_EventFrame = "EventFrame";
static const char* FrameType_ZOrderFrame = "ZOrderFrame";
static const char* Property_VisibleForFrame = "VisibleForFrame";
static const char* Property_Position = "Position";
static const char* Property_Scale = "Scale";
static const char* Property_RotationSkew = "RotationSkew";
static const char* Property_CColor = "CColor";
static const char* Property_FileData = "FileData";
static const char* Property_FrameEvent = "FrameEvent";
static const char* Property_Alpha = "Alpha";
static const char* Property_ZOrder = "ZOrder";
static const char* Property_ActionValue = "ActionValue";
static FlatBuffersSerialize* _instanceFlatBuffersSerialize = nullptr;
@ -232,7 +233,7 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const std::str
Offset<NodeTree> nodeTree;
Offset<NodeAction> aciton;
std::vector<Offset<flatbuffers::AnimationInfo>> animationInfos;
const tinyxml2::XMLElement* child = element->FirstChildElement();
@ -250,15 +251,26 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const std::str
const tinyxml2::XMLElement* objectData = child;
nodeTree = createNodeTree(objectData, rootType);
}
else if (name == "AnimationList") // animation list
{
const tinyxml2::XMLElement* animationinfoElement = child->FirstChildElement();
while (animationinfoElement)
{
auto animationinfo = createAnimationInfo(animationinfoElement);
animationInfos.push_back(animationinfo);
animationinfoElement = animationinfoElement->NextSiblingElement();
}
}
child = child->NextSiblingElement();
}
auto csparsebinary = CreateCSParseBinary(*_builder,
_builder->CreateVector(_textures),
_builder->CreateVector(_texturePngs),
nodeTree,
aciton,
_builder->CreateVector(animationInfos),
_builder->CreateString(_csdVersion));
_builder->Finish(csparsebinary);
@ -514,6 +526,7 @@ Offset<NodeAction> FlatBuffersSerialize::createNodeAction(const tinyxml2::XMLEle
{
int duration = 0;
float speed = 0.0f;
std::string currentAnimationName = "";
// CCLOG("animation name = %s", objectData->Name());
@ -534,6 +547,10 @@ Offset<NodeAction> FlatBuffersSerialize::createNodeAction(const tinyxml2::XMLEle
{
speed = atof(value.c_str());
}
else if (name == "ActivedAnimationName")
{
currentAnimationName = value.c_str();
}
attribute = attribute->Next();
}
@ -552,13 +569,43 @@ Offset<NodeAction> FlatBuffersSerialize::createNodeAction(const tinyxml2::XMLEle
return CreateNodeAction(*_builder,
duration,
speed,
_builder->CreateVector(timelines));
_builder->CreateVector(timelines),
_builder->CreateString(currentAnimationName));
}
Offset<flatbuffers::AnimationInfo> FlatBuffersSerialize::createAnimationInfo(const tinyxml2::XMLElement *objectData)
{
std::string infoName = "";
int startIndex = 0;
int endIndex = 0;
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string attriname = attribute->Name();
std::string attrivalue = attribute->Value();
if (attriname == "Name")
{
infoName = attrivalue;
}
else if (attriname == "StartIndex")
{
startIndex = atoi(attrivalue.c_str());
}
else if (attriname == "EndIndex")
{
endIndex = atoi(attrivalue.c_str());
}
attribute = attribute->Next();
}
return CreateAnimationInfo(*_builder, _builder->CreateString(infoName), startIndex, endIndex);
}
Offset<TimeLine> FlatBuffersSerialize::createTimeLine(const tinyxml2::XMLElement *objectData)
{
int actionTag = 0;
std::string frameType = "";
std::string property = "";
// TimelineData attrsibutes
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
@ -571,9 +618,9 @@ Offset<TimeLine> FlatBuffersSerialize::createTimeLine(const tinyxml2::XMLElement
{
actionTag = atoi(value.c_str());
}
else if (name == "FrameType")
else if (name == "Property")
{
frameType = value;
property = value;
}
attribute = attribute->Next();
@ -587,210 +634,113 @@ Offset<TimeLine> FlatBuffersSerialize::createTimeLine(const tinyxml2::XMLElement
{
Offset<flatbuffers::Frame> frame;
if (frameType == FrameType_VisibleFrame)
if (property == Property_VisibleForFrame)
{
auto visibleFrame = createTimeLineBoolFrame(frameElement);
auto boolFrame = createBoolFrame(frameElement);
frame = CreateFrame(*_builder,
visibleFrame);
}
else if (frameType == FrameType_ZOrderFrame)
{
auto zOrderFrame = createTimeLineIntFrame(frameElement);
frame = CreateFrame(*_builder,
0, // VisibleFrame
zOrderFrame);
}
else if (frameType == FrameType_RotationSkewFrame)
{
auto rotationSkewFrame = createTimeLinePointFrame(frameElement);
frame = CreateFrame(*_builder,
0, // VisibleFrame
0, // ZOrderFrame
rotationSkewFrame);
}
else if (frameType == FrameType_EventFrame)
{
auto eventFrame = createTimeLineStringFrame(frameElement);
frame = CreateFrame(*_builder,
0, // VisibleFrame
0, // ZOrderFrame
0, // RotationSkewFrame
eventFrame);
}
else if (frameType == FrameType_AnchorFrame)
{
auto anchorPointFrame = createTimeLinePointFrame(frameElement);
frame = CreateFrame(*_builder,
0, // VisibleFrame
0, // ZOrderFrame
0, // RotationSkewFrame
0, // PointFrame
0, // ScaleFrame
0, // ColorFrame
0, // TextureFrame
0, // EventFrame
anchorPointFrame);
0, // IntFrame
boolFrame);
}
else if (frameType == FrameType_PositionFrame)
else if (property == Property_Position)
{
auto positionFrame = createTimeLinePointFrame(frameElement);
auto pointFrame = createPointFrame(frameElement);
frame = CreateFrame(*_builder,
0, // VisibleFrame
0, // ZOrderFrame
0, // RotationSkewFrame
0, // EventFrame
0, // AnchorPointFrame
positionFrame);
pointFrame);
}
else if (frameType == FrameType_ScaleFrame)
else if (property == Property_Scale)
{
auto scaleFrame = createTimeLinePointFrame(frameElement);
auto scaleFrame = createScaleFrame(frameElement);
frame = CreateFrame(*_builder,
0, // VisibleFrame
0, // ZOrderFrame
0, // RotationSkewFrame
0, // EventFrame
0, // AnchorPointFrame
0, // PositionFrame
0, // PointFrame
scaleFrame);
}
else if (frameType == FrameType_ColorFrame)
else if (property == Property_RotationSkew)
{
auto colorFrame = createTimeLineColorFrame(frameElement);
auto scaleFrame = createScaleFrame(frameElement);
frame = CreateFrame(*_builder,
0, // VisibleFrame
0, // ZOrderFrame
0, // RotationSkewFrame
0, // EventFrame
0, // AnchorPointFrame
0, // PositionFrame
0, // PointFrame
scaleFrame);
}
else if (property == Property_CColor)
{
auto colorFrame = createColorFrame(frameElement);
frame = CreateFrame(*_builder,
0, // PointFrame
0, // ScaleFrame
colorFrame);
}
else if (frameType == FrameType_TextureFrame)
else if (property == Property_FileData)
{
auto textureFrame = createTimeLineTextureFrame(frameElement);
auto textureFrame = createTextureFrame(frameElement);
frame = CreateFrame(*_builder,
0, // VisibleFrame
0, // ZOrderFrame
0, // RotationSkewFrame
0, // EventFrame
0, // AnchorPointFrame
0, // PositionFrame
0, // PointFrame
0, // ScaleFrame
0, // ColorFrame
textureFrame);
}
else if (property == Property_FrameEvent)
{
auto eventFrame = createEventFrame(frameElement);
frame = CreateFrame(*_builder,
0, // PointFrame
0, // ScaleFrame
0, // ColorFrame
0, // TextureFrame
eventFrame);
}
else if (property == Property_Alpha)
{
auto intFrame = createIntFrame(frameElement);
frame = CreateFrame(*_builder,
0, // PointFrame
0, // ScaleFrame
0, // ColorFrame
0, // TextureFrame
0, // EventFrame
intFrame);
}
else if (property == Property_ZOrder)
{
auto intFrame = createIntFrame(frameElement);
frame = CreateFrame(*_builder,
0, // PointFrame
0, // ScaleFrame
0, // ColorFrame
0, // TextureFrame
0, // EventFrame
intFrame);
}
else if (property == Property_ActionValue)
{
auto innerActionFrame = createInnerActionFrame(frameElement);
frame = CreateFrame(*_builder,
0, // PointFrame
0, // ScaleFrame
0, // ColorFrame
0, // TextureFrame
0, // EventFrame
0, // IntFrame
0, // BoolFrame
innerActionFrame);
}
frames.push_back(frame);
frameElement = frameElement->NextSiblingElement();
}
return CreateTimeLine(*_builder,
_builder->CreateString(frameType),
_builder->CreateString(property),
actionTag,
_builder->CreateVector(frames));
}
Offset<TimeLineBoolFrame> FlatBuffersSerialize::createTimeLineBoolFrame(const tinyxml2::XMLElement *objectData)
{
int frameIndex = 0;
bool tween = true;
bool value = false;
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string name = attribute->Name();
std::string attrivalue = attribute->Value();
if (name == "Value")
{
value = (attrivalue == "True") ? true : false;
}
else if (name == "FrameIndex")
{
frameIndex = atoi(attrivalue.c_str());
}
else if (name == "Tween")
{
tween = atoi(attrivalue.c_str());
}
attribute = attribute->Next();
}
return CreateTimeLineBoolFrame(*_builder,
frameIndex,
tween,
value);
}
Offset<TimeLineIntFrame> FlatBuffersSerialize::createTimeLineIntFrame(const tinyxml2::XMLElement *objectData)
{
int frameIndex = 0;
bool tween = true;
int value = 0;
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string name = attribute->Name();
std::string attrivalue = attribute->Value();
if (name == "Value") // to be gonna modify
{
value = atoi(attrivalue.c_str());
}
else if (name == "FrameIndex")
{
frameIndex = atoi(attrivalue.c_str());
}
else if (name == "Tween")
{
tween = (attrivalue == "True") ? true : false;
}
attribute = attribute->Next();
}
return CreateTimeLineIntFrame(*_builder,
frameIndex,
tween,
value);
}
Offset<TimeLineStringFrame> FlatBuffersSerialize::createTimeLineStringFrame(const tinyxml2::XMLElement *objectData)
{
int frameIndex = 0;
bool tween = true;
std::string value = "";
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string name = attribute->Name();
std::string attrivalue = attribute->Value();
if (name == "Value") // to be gonna modify
{
value = attrivalue;
}
else if (name == "FrameIndex")
{
frameIndex = atoi(attrivalue.c_str());
}
else if (name == "Tween")
{
tween = (attrivalue == "True") ? true : false;
}
attribute = attribute->Next();
}
return CreateTimeLineStringFrame(*_builder,
frameIndex,
tween,
_builder->CreateString(value));
}
Offset<TimeLinePointFrame> FlatBuffersSerialize::createTimeLinePointFrame(const tinyxml2::XMLElement *objectData)
Offset<flatbuffers::PointFrame> FlatBuffersSerialize::createPointFrame(const tinyxml2::XMLElement *objectData)
{
int frameIndex = 0;
bool tween = true;
@ -824,17 +774,57 @@ Offset<TimeLinePointFrame> FlatBuffersSerialize::createTimeLinePointFrame(const
Position f_position(position.x, position.y);
return CreateTimeLinePointFrame(*_builder,
return CreatePointFrame(*_builder,
frameIndex,
tween,
&f_position);
}
Offset<TimeLineColorFrame> FlatBuffersSerialize::createTimeLineColorFrame(const tinyxml2::XMLElement *objectData)
Offset<flatbuffers::ScaleFrame> FlatBuffersSerialize::createScaleFrame(const tinyxml2::XMLElement *objectData)
{
int frameIndex = 0;
bool tween = true;
Color4B color;
Vec2 scale;
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string name = attribute->Name();
std::string value = attribute->Value();
if (name == "X")
{
scale.x = atof(value.c_str());
}
else if (name == "Y")
{
scale.y = atof(value.c_str());
}
else if (name == "FrameIndex")
{
frameIndex = atoi(value.c_str());
}
else if (name == "Tween")
{
tween = (value == "True") ? true : false;
}
attribute = attribute->Next();
}
Scale f_scale(scale.x, scale.y);
return CreateScaleFrame(*_builder,
frameIndex,
tween,
&f_scale);
}
Offset<flatbuffers::ColorFrame> FlatBuffersSerialize::createColorFrame(const tinyxml2::XMLElement *objectData)
{
int frameIndex = 0;
bool tween = true;
Color3B color;
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
@ -846,10 +836,6 @@ Offset<TimeLineColorFrame> FlatBuffersSerialize::createTimeLineColorFrame(const
{
frameIndex = atoi(value.c_str());
}
else if (name == "Alpha")
{
color.a = atoi(value.c_str());
}
else if (name == "Tween")
{
tween = (value == "True") ? true : false;
@ -887,16 +873,16 @@ Offset<TimeLineColorFrame> FlatBuffersSerialize::createTimeLineColorFrame(const
child = child->NextSiblingElement();
}
Color f_color(color.a, color.r, color.g, color.b);
Color f_color(255, color.r, color.g, color.b);
return CreateTimeLineColorFrame(*_builder,
return CreateColorFrame(*_builder,
frameIndex,
tween,
&f_color);
}
Offset<TimeLineTextureFrame> FlatBuffersSerialize::createTimeLineTextureFrame(const tinyxml2::XMLElement *objectData)
{
Offset<flatbuffers::TextureFrame> FlatBuffersSerialize::createTextureFrame(const tinyxml2::XMLElement *objectData)
{
int frameIndex = 0;
bool tween = true;
@ -959,13 +945,172 @@ Offset<TimeLineColorFrame> FlatBuffersSerialize::createTimeLineColorFrame(const
child = child->NextSiblingElement();
}
return CreateTimeLineTextureFrame(*_builder,
return CreateTextureFrame(*_builder,
frameIndex,
tween,
CreateResourceData(*_builder,
_builder->CreateString(path),
_builder->CreateString(plistFile),
resourceType));
}
Offset<flatbuffers::EventFrame> FlatBuffersSerialize::createEventFrame(const tinyxml2::XMLElement *objectData)
{
int frameIndex = 0;
bool tween = true;
std::string value = "";
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string name = attribute->Name();
std::string attrivalue = attribute->Value();
if (name == "Value") // to be gonna modify
{
value = attrivalue;
}
else if (name == "FrameIndex")
{
frameIndex = atoi(attrivalue.c_str());
}
else if (name == "Tween")
{
tween = (attrivalue == "True") ? true : false;
}
attribute = attribute->Next();
}
return CreateEventFrame(*_builder,
frameIndex,
tween,
_builder->CreateString(value));
}
Offset<flatbuffers::IntFrame> FlatBuffersSerialize::createIntFrame(const tinyxml2::XMLElement *objectData)
{
int frameIndex = 0;
bool tween = true;
int value = 0;
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string name = attribute->Name();
std::string attrivalue = attribute->Value();
if (name == "Value") // to be gonna modify
{
value = atoi(attrivalue.c_str());
}
else if (name == "FrameIndex")
{
frameIndex = atoi(attrivalue.c_str());
}
else if (name == "Tween")
{
tween = (attrivalue == "True") ? true : false;
}
attribute = attribute->Next();
}
return CreateIntFrame(*_builder,
frameIndex,
tween,
value);
}
Offset<flatbuffers::BoolFrame> FlatBuffersSerialize::createBoolFrame(const tinyxml2::XMLElement *objectData)
{
int frameIndex = 0;
bool tween = true;
bool value = true;
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string name = attribute->Name();
std::string attrivalue = attribute->Value();
if (name == "Value")
{
value = (attrivalue == "True") ? true : false;
}
else if (name == "FrameIndex")
{
frameIndex = atoi(attrivalue.c_str());
}
else if (name == "Tween")
{
tween = (attrivalue == "True") ? true : false;
}
attribute = attribute->Next();
}
return CreateBoolFrame(*_builder,
frameIndex,
tween,
value);
}
Offset<flatbuffers::InnerActionFrame> FlatBuffersSerialize::createInnerActionFrame(const tinyxml2::XMLElement *objectData)
{
int frameIndex = 0;
bool tween = true;
int innerActionType = 0;
std::string currentAniamtionName = "";
int singleFrameIndex = 0;
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string name = attribute->Name();
std::string attrivalue = attribute->Value();
if (name == "InnerActionType")
{
if (attrivalue == "LoopAction")
{
innerActionType = 0;
}
else if (attrivalue == "NoLoopAction")
{
innerActionType = 1;
}
else if (attrivalue == "SingleFrame")
{
innerActionType = 2;
}
}
else if (name == "CurrentAniamtionName")
{
currentAniamtionName = attrivalue;
}
else if (name == "SingleFrameIndex")
{
singleFrameIndex = atoi(attrivalue.c_str());
}
else if (name == "FrameIndex")
{
frameIndex = atoi(attrivalue.c_str());
}
else if (name == "Tween")
{
tween = (attrivalue == "True") ? true : false;
}
attribute = attribute->Next();
}
return CreateInnerActionFrame(*_builder,
frameIndex,
tween,
innerActionType,
_builder->CreateString(currentAniamtionName),
singleFrameIndex);
}
/* create flat buffers with XML */
@ -1040,7 +1185,7 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato
Offset<NodeTree> nodeTree;
Offset<NodeAction> aciton;
std::vector<Offset<flatbuffers::AnimationInfo> > animationInfos;
const tinyxml2::XMLElement* child = element->FirstChildElement();
@ -1058,6 +1203,16 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato
const tinyxml2::XMLElement* objectData = child;
nodeTree = createNodeTreeForSimulator(objectData, rootType);
}
else if (name == "AnimationList") // animation list
{
const tinyxml2::XMLElement* animationinfoElement = child->FirstChildElement();
while (animationinfoElement)
{
auto animationinfo = createAnimationInfo(animationinfoElement);
animationInfos.push_back(animationinfo);
animationinfoElement = animationinfoElement->NextSiblingElement();
}
}
child = child->NextSiblingElement();
}
@ -1067,6 +1222,7 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato
_builder->CreateVector(_texturePngs),
nodeTree,
aciton,
_builder->CreateVector(animationInfos),
_builder->CreateString(_csdVersion));
_builder->Finish(csparsebinary);
@ -1190,26 +1346,6 @@ Offset<ProjectNodeOptions> FlatBuffersSerialize::createProjectNodeOptionsForSimu
std::string filename = "";
bool isloop = true;
bool isAutoPlay = true;
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string attriname = attribute->Name();
std::string value = attribute->Value();
if (attriname == "IsLoop")
{
isloop = (value == "True") ? true : false;
}
else if (attriname == "IsAutoPlay")
{
isAutoPlay = (value == "True") ? true : false;
}
attribute = attribute->Next();
}
// FileData
const tinyxml2::XMLElement* child = objectData->FirstChildElement();
while (child)
@ -1218,19 +1354,19 @@ Offset<ProjectNodeOptions> FlatBuffersSerialize::createProjectNodeOptionsForSimu
if (name == "FileData")
{
const tinyxml2::XMLAttribute* attributeFileData = child->FirstAttribute();
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
while (attributeFileData)
while (attribute)
{
name = attributeFileData->Name();
std::string value = attributeFileData->Value();
name = attribute->Name();
std::string value = attribute->Value();
if (name == "Path")
{
filename = value;
}
attributeFileData = attributeFileData->Next();
attribute = attribute->Next();
}
}
@ -1239,9 +1375,7 @@ Offset<ProjectNodeOptions> FlatBuffersSerialize::createProjectNodeOptionsForSimu
return CreateProjectNodeOptions(*_builder,
nodeOptions,
_builder->CreateString(filename),
isloop,
isAutoPlay);
_builder->CreateString(filename));
}
}

View File

@ -65,16 +65,18 @@ namespace flatbuffers
struct TextAtlasOptions;
struct NodeAction;
struct AnimationInfo;
struct TimeLine;
struct Frame;
struct TimeLineBoolFrame;
struct TimeLineIntFrame;
struct TimeLineStringFrame;
struct TimeLinePointFrame;
struct TimeLineColorFrame;
struct TimeLineTextureFrame;
struct PointFrame;
struct ScaleFrame;
struct ColorFrame;
struct TextureFrame;
struct EventFrame;
struct IntFrame;
struct BoolFrame;
struct InnerActionFrame;
}
namespace tinyxml2
@ -110,12 +112,17 @@ public:
// NodeAction
flatbuffers::Offset<flatbuffers::NodeAction> createNodeAction(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::TimeLine> createTimeLine(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::TimeLineBoolFrame> createTimeLineBoolFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::TimeLineIntFrame> createTimeLineIntFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::TimeLineStringFrame> createTimeLineStringFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::TimeLinePointFrame> createTimeLinePointFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::TimeLineColorFrame> createTimeLineColorFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::TimeLineTextureFrame> createTimeLineTextureFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::PointFrame> createPointFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::ScaleFrame> createScaleFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::ColorFrame> createColorFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::TextureFrame> createTextureFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::EventFrame> createEventFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::IntFrame> createIntFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::BoolFrame> createBoolFrame(const tinyxml2::XMLElement* objectData);
flatbuffers::Offset<flatbuffers::InnerActionFrame> createInnerActionFrame(const tinyxml2::XMLElement* objectData);
//Animation Info
flatbuffers::Offset<flatbuffers::AnimationInfo> createAnimationInfo(const tinyxml2::XMLElement* objectData);
/**/
int getResourceType(std::string key);

View File

@ -69,26 +69,6 @@ namespace cocostudio
auto nodeOptions = *(Offset<WidgetOptions>*)(&temp);
std::string filename = "";
bool isloop = true;
bool isAutoPlay = true;
const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
while (attribute)
{
std::string attriname = attribute->Name();
std::string value = attribute->Value();
if (attriname == "IsLoop")
{
isloop = (value == "True") ? true : false;
}
else if (attriname == "IsAutoPlay")
{
isAutoPlay = (value == "True") ? true : false;
}
attribute = attribute->Next();
}
// FileData
const tinyxml2::XMLElement* child = objectData->FirstChildElement();
@ -98,12 +78,12 @@ namespace cocostudio
if (name == "FileData")
{
const tinyxml2::XMLAttribute* attributeFileData = child->FirstAttribute();
const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
while (attributeFileData)
while (attribute)
{
name = attributeFileData->Name();
std::string value = attributeFileData->Value();
name = attribute->Name();
std::string value = attribute->Value();
if (name == "Path")
{
@ -112,7 +92,7 @@ namespace cocostudio
filename = convert;
}
attributeFileData = attributeFileData->Next();
attribute = attribute->Next();
}
}
@ -121,9 +101,7 @@ namespace cocostudio
auto options = CreateProjectNodeOptions(*builder,
nodeOptions,
builder->CreateString(filename),
isloop,
isAutoPlay);
builder->CreateString(filename));
return *(Offset<Table>*)(&options);
}

View File

@ -43,6 +43,7 @@
@property (readonly) NSInteger getDataTime;
@property (readonly) NSInteger responseCode;
@property (readonly) NSString *statusString;
@property (strong) NSError *responseError;

View File

@ -32,6 +32,7 @@
@synthesize responseData;
@synthesize getDataTime;
@synthesize responseCode;
@synthesize statusString;
@synthesize responseError;
@synthesize conn;
@synthesize finish;
@ -73,7 +74,20 @@
responseHeader = [[httpResponse allHeaderFields] copy];
responseCode = httpResponse.statusCode;
if (responseCode != 200)
statusString = [[NSHTTPURLResponse localizedStringForStatusCode:responseCode] copy];
if(responseCode == 200)
statusString = @"OK";
/*The individual values of the numeric status codes defined for HTTP/1.1
| 200 ; OK
| 201 ; Created
| 202 ; Accepted
| 203 ; Non-Authoritative Information
| 204 ; No Content
| 205 ; Reset Content
| 206 ; Partial Content
*/
if (responseCode >= 200 && responseCode < 300)
{// something went wrong, abort the whole thing
[connection cancel];

View File

@ -187,10 +187,14 @@ static int processTask(HttpRequest *request, NSString* requestType, void *stream
}
}
NSString* requestData = [NSString stringWithUTF8String:request->getRequestData()];
char* requestDataBuffer = request->getRequestData();
if (nullptr != requestDataBuffer && 0 != strlen(requestDataBuffer))
{
NSString* requestData = [NSString stringWithUTF8String:requestDataBuffer];
NSData *postData = [requestData dataUsingEncoding:NSUTF8StringEncoding];
[nsrequest setHTTPBody:postData];
}
}
//read cookie propertities from file and set cookie
if(!s_cookieFilename.empty())
@ -275,6 +279,7 @@ static int processTask(HttpRequest *request, NSString* requestType, void *stream
//handle response header
NSMutableString *header = [NSMutableString new];
[header appendFormat:@"HTTP/1.1 %ld %@\n", httpAsynConn.responseCode, httpAsynConn.statusString];
for (id key in httpAsynConn.responseHeader)
{
[header appendFormat:@"%@: %@\n", key, [httpAsynConn.responseHeader objectForKey:key]];

View File

@ -31,16 +31,10 @@
#include "chipmunk.h"
#include "2d/CCScene.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"
#include "CCPhysicsShape.h"
#include "CCPhysicsJoint.h"
#include "CCPhysicsWorld.h"
#include "CCPhysicsHelper.h"
static inline void cpBodyUpdateVelocityWithoutGravity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt)
{
@ -59,7 +53,7 @@ namespace
PhysicsBody::PhysicsBody()
: _node(nullptr)
, _world(nullptr)
, _info(nullptr)
, _cpBody(nullptr)
, _dynamic(true)
, _enabled(true)
, _rotationEnabled(true)
@ -74,9 +68,10 @@ PhysicsBody::PhysicsBody()
, _linearDamping(0.0f)
, _angularDamping(0.0f)
, _tag(0)
, _positionResetTag(false)
, _rotationResetTag(false)
, _rotationOffset(0)
, _recordedPosition(Vec2::ZERO)
, _recordedRotation(0.0f)
, _recordedAngle(0.0)
{
}
@ -91,7 +86,10 @@ PhysicsBody::~PhysicsBody()
delete joint;
}
CC_SAFE_DELETE(_info);
if (_cpBody)
{
cpBodyFree(_cpBody);
}
}
PhysicsBody* PhysicsBody::create()
@ -255,12 +253,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);
@ -283,33 +278,32 @@ void PhysicsBody::setDynamic(bool dynamic)
if (dynamic != _dynamic)
{
_dynamic = dynamic;
auto body = _info->getBody();
if (dynamic)
{
if (_world && body->CP_PRIVATE(space))
if (_world && _cpBody->CP_PRIVATE(space))
{
cpSpaceConvertBodyToDynamic(_world->_info->getSpace(), body, _mass, _moment);
cpSpaceAddBody(_world->_info->getSpace(), body);
cpSpaceConvertBodyToDynamic(_world->_cpSpace, _cpBody, _mass, _moment);
cpSpaceAddBody(_world->_cpSpace, _cpBody);
}
else
{
cpBodySetMass(body, _mass);
cpBodySetMoment(body, _moment);
body->CP_PRIVATE(node).idleTime = 0.0f;
cpBodySetMass(_cpBody, _mass);
cpBodySetMoment(_cpBody, _moment);
}
}
else
{
if (_world && body->CP_PRIVATE(space))
if (_world && _cpBody->CP_PRIVATE(space))
{
cpSpaceRemoveBody(_world->_info->getSpace(), body);
cpSpaceConvertBodyToStatic(_world->_info->getSpace(), body);
cpSpaceRemoveBody(_world->_cpSpace, _cpBody);
cpSpaceConvertBodyToStatic(_world->_cpSpace, _cpBody);
}
else
{
cpBodySetMass(body, PHYSICS_INFINITY);
cpBodySetMoment(body, PHYSICS_INFINITY);
body->CP_PRIVATE(node).idleTime = (cpFloat)INFINITY;
cpBodySetMass(_cpBody, PHYSICS_INFINITY);
cpBodySetMoment(_cpBody, PHYSICS_INFINITY);
cpBodySetVel(_cpBody, cpvzero);
cpBodySetAngVel(_cpBody, 0.0);
}
}
}
@ -319,7 +313,7 @@ void PhysicsBody::setRotationEnable(bool enable)
{
if (_rotationEnabled != enable)
{
cpBodySetMoment(_info->getBody(), enable ? _moment : PHYSICS_INFINITY);
cpBodySetMoment(_cpBody, enable ? _moment : PHYSICS_INFINITY);
_rotationEnabled = enable;
}
}
@ -330,30 +324,25 @@ void PhysicsBody::setGravityEnable(bool enable)
if (enable)
{
_info->getBody()->velocity_func = cpBodyUpdateVelocity;
_cpBody->velocity_func = cpBodyUpdateVelocity;
}
else
{
_info->getBody()->velocity_func = cpBodyUpdateVelocityWithoutGravity;
_cpBody->velocity_func = cpBodyUpdateVelocityWithoutGravity;
}
}
void PhysicsBody::setPosition(const Vec2& position)
{
cpBodySetPos(_info->getBody(), PhysicsHelper::point2cpv(position + _positionOffset));
_recordedPosition = position;
cpBodySetPos(_cpBody, PhysicsHelper::point2cpv(position + _positionOffset));
}
void PhysicsBody::setRotation(float rotation)
{
cpBodySetAngle(_info->getBody(), -PhysicsHelper::float2cpfloat((rotation + _rotationOffset) * (M_PI / 180.0f)));
}
void PhysicsBody::setScale(float scale)
{
for (auto shape : _shapes)
{
shape->setScale(scale);
}
_recordedRotation = rotation;
_recordedAngle = - (rotation + _rotationOffset) * (M_PI / 180.0);
cpBodySetAngle(_cpBody, _recordedAngle);
}
void PhysicsBody::setScale(float scaleX, float scaleY)
@ -364,31 +353,21 @@ void PhysicsBody::setScale(float scaleX, float scaleY)
}
}
void PhysicsBody::setScaleX(float scaleX)
const Vec2& PhysicsBody::getPosition()
{
for (auto shape : _shapes)
{
shape->setScaleX(scaleX);
_latestPosition.x = _cpBody->p.x - _positionOffset.x;
_latestPosition.y = _cpBody->p.y - _positionOffset.y;
return _latestPosition;
}
float PhysicsBody::getRotation()
{
if (_recordedAngle != cpBodyGetAngle(_cpBody)) {
_recordedAngle = cpBodyGetAngle(_cpBody);
_recordedRotation = - _recordedAngle * 180.0 / M_PI - _rotationOffset;
}
}
void PhysicsBody::setScaleY(float scaleY)
{
for (auto shape : _shapes)
{
shape->setScaleY(scaleY);
}
}
Vec2 PhysicsBody::getPosition() const
{
cpVect vec = cpBodyGetPos(_info->getBody());
return PhysicsHelper::cpv2point(vec) - _positionOffset;
}
float PhysicsBody::getRotation() const
{
return -PhysicsHelper::cpfloat2float(cpBodyGetAngle(_info->getBody()) * (180.0f / M_PI)) - _rotationOffset;
return _recordedRotation;
}
PhysicsShape* PhysicsBody::addShape(PhysicsShape* shape, bool addMassAndMoment/* = true*/)
@ -409,7 +388,7 @@ PhysicsShape* PhysicsBody::addShape(PhysicsShape* shape, bool addMassAndMoment/*
addMoment(shape->getMoment());
}
if (_world != nullptr)
if (_world && _cpBody->CP_PRIVATE(space))
{
_world->addShape(shape);
}
@ -429,13 +408,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());
cpBodyResetForces(_cpBody);
}
void PhysicsBody::applyImpulse(const Vect& impulse)
@ -445,12 +424,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)
@ -481,7 +460,7 @@ void PhysicsBody::setMass(float mass)
// the static body's mass and moment is always infinity
if (_dynamic)
{
cpBodySetMass(_info->getBody(), _mass);
cpBodySetMass(_cpBody, _mass);
}
}
@ -527,7 +506,7 @@ void PhysicsBody::addMass(float mass)
// the static body's mass and moment is always infinity
if (_dynamic)
{
cpBodySetMass(_info->getBody(), _mass);
cpBodySetMass(_cpBody, _mass);
}
}
@ -569,7 +548,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));
}
}
@ -581,22 +560,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)
@ -607,32 +586,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)
@ -643,7 +622,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));
}
}
@ -755,52 +734,30 @@ 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);
}
}
void PhysicsBody::update(float delta)
{
if (_node != nullptr)
if (_node)
{
for (auto shape : _shapes)
{
shape->update(delta);
}
Node* parent = _node->getParent();
Node* scene = &_world->getScene();
Vec2 position = parent != scene ? parent->convertToNodeSpace(scene->convertToWorldSpace(getPosition())) : getPosition();
float rotation = getRotation();
for (; parent != scene; parent = parent->getParent())
{
rotation -= parent->getRotation();
}
_positionResetTag = true;
_rotationResetTag = true;
_node->setPosition(position);
_node->setRotation(rotation);
_positionResetTag = false;
_rotationResetTag = false;
// 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);
}
}
}
@ -895,11 +852,6 @@ void PhysicsBody::setPositionOffset(const Vec2& position)
}
}
Vec2 PhysicsBody::getPositionOffset() const
{
return _positionOffset;
}
void PhysicsBody::setRotationOffset(float rotation)
{
if (std::abs(_rotationOffset - rotation) > 0.5f)
@ -910,19 +862,14 @@ void PhysicsBody::setRotationOffset(float rotation)
}
}
float PhysicsBody::getRotationOffset() const
{
return _rotationOffset;
}
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)));
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;
@ -188,18 +189,18 @@ public:
int getGroup() const;
/** get the body position. */
Vec2 getPosition() const;
const Vec2& getPosition();
/** get the body rotation. */
float getRotation() const;
float getRotation();
/** set body position offset, it's the position witch relative to node */
void setPositionOffset(const Vec2& position);
/** get body position offset. */
Vec2 getPositionOffset() const;
const Vec2& getPositionOffset() const { return _positionOffset; }
/** set body rotation offset, it's the rotation witch relative to node */
void setRotationOffset(float rotation);
/** set the body rotation offset */
float getRotationOffset() const;
float getRotationOffset() const { return _rotationOffset; }
/**
* @brief test the body is dynamic or not.
@ -297,16 +298,15 @@ public:
/** convert the local point to world */
Vec2 local2World(const Vec2& point);
cpBody* getCPBody() { return _cpBody; }
protected:
bool init();
virtual void setPosition(const Vec2& position);
virtual void setRotation(float rotation);
virtual void setScale(float scale);
virtual void setScale(float scaleX, float scaleY);
virtual void setScaleX(float scaleX);
virtual void setScaleY(float scaleY);
void update(float delta);
@ -322,7 +322,7 @@ protected:
std::vector<PhysicsJoint*> _joints;
Vector<PhysicsShape*> _shapes;
PhysicsWorld* _world;
PhysicsBodyInfo* _info;
cpBody* _cpBody;
bool _dynamic;
bool _enabled;
bool _rotationEnabled;
@ -338,10 +338,12 @@ protected:
float _angularDamping;
int _tag;
bool _positionResetTag; /// To avoid reset the body position when body invoke Node::setPosition().
bool _rotationResetTag; /// To avoid reset the body rotation when body invoke Node::setRotation().
Vec2 _recordedPosition;
Vec2 _latestPosition;
Vec2 _positionOffset;
float _rotationOffset;
float _recordedRotation;
double _recordedAngle;
friend class PhysicsWorld;
friend class PhysicsShape;

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,11 +37,12 @@ PhysicsJoint::PhysicsJoint()
: _bodyA(nullptr)
, _bodyB(nullptr)
, _world(nullptr)
, _info(nullptr)
, _enable(false)
, _collisionEnable(true)
, _destoryMark(false)
, _initDirty(true)
, _tag(0)
, _maxForce(PHYSICS_INFINITY)
{
}
@ -55,7 +52,11 @@ PhysicsJoint::~PhysicsJoint()
// reset the shapes collision group
setCollisionEnable(true);
CC_SAFE_DELETE(_info);
for (cpConstraint* joint : _cpConstraints)
{
cpConstraintFree(joint);
}
_cpConstraints.clear();
}
bool PhysicsJoint::init(cocos2d::PhysicsBody *a, cocos2d::PhysicsBody *b)
@ -65,11 +66,9 @@ 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;
_bodyA->_joints.push_back(this);
_bodyB->_joints.push_back(this);
return true;
@ -78,35 +77,47 @@ bool PhysicsJoint::init(cocos2d::PhysicsBody *a, cocos2d::PhysicsBody *b)
return false;
}
bool PhysicsJoint::initJoint()
{
bool ret = !_initDirty;
while (_initDirty)
{
ret = createConstraints();
CC_BREAK_IF(!ret);
for (auto subjoint : _cpConstraints)
{
subjoint->maxForce = _maxForce;
subjoint->errorBias = cpfpow(1.0f - 0.15f, 60.0f);
cpSpaceAddConstraint(_world->_cpSpace, subjoint);
}
_initDirty = false;
ret = true;
}
return ret;
}
void PhysicsJoint::setEnable(bool enable)
{
if (_enable != enable)
{
_enable = enable;
if (_world != nullptr)
if (_world)
{
if (enable)
{
_world->addJointOrDelay(this);
}else
_world->addJoint(this);
}
else
{
_world->removeJointOrDelay(this);
_world->removeJoint(this, false);
}
}
}
}
PhysicsBodyInfo* PhysicsJoint::getBodyInfo(PhysicsBody* body) const
{
return body->_info;
}
Node* PhysicsJoint::getBodyNode(PhysicsBody* body) const
{
return body->_node;
}
void PhysicsJoint::setCollisionEnable(bool enable)
{
if (_collisionEnable != enable)
@ -123,51 +134,22 @@ void PhysicsJoint::removeFormWorld()
}
}
void PhysicsJoint::destroy(PhysicsJoint* joint)
{
if (joint!= nullptr)
{
// remove the joint and delete it.
if (joint->_world != nullptr)
{
joint->_world->removeJoint(joint, true);
}
else
{
if (joint->_bodyA != nullptr)
{
joint->_bodyA->removeJoint(joint);
}
if (joint->_bodyB != nullptr)
{
joint->_bodyB->removeJoint(joint);
}
delete joint;
}
}
}
void PhysicsJoint::setMaxForce(float force)
{
for (cpConstraint* joint : _info->getJoints())
_maxForce = force;
for (auto joint : _cpConstraints)
{
joint->maxForce = PhysicsHelper::float2cpfloat(force);
}
}
float PhysicsJoint::getMaxForce() const
{
return PhysicsHelper::cpfloat2float(_info->getJoints().front()->maxForce);
}
PhysicsJointFixed* PhysicsJointFixed::construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr)
{
PhysicsJointFixed* joint = new (std::nothrow) PhysicsJointFixed();
auto joint = new (std::nothrow) PhysicsJointFixed();
if (joint && joint->init(a, b, anchr))
if (joint && joint->init(a, b))
{
joint->_anchr = anchr;
return joint;
}
@ -175,27 +157,25 @@ PhysicsJointFixed* PhysicsJointFixed::construct(PhysicsBody* a, PhysicsBody* b,
return nullptr;
}
bool PhysicsJointFixed::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr)
bool PhysicsJointFixed::createConstraints()
{
do
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
getBodyNode(a)->setPosition(anchr);
getBodyNode(b)->setPosition(anchr);
_bodyA->getNode()->setPosition(_anchr);
_bodyB->getNode()->setPosition(_anchr);
// add a pivot joint to fixed two body together
cpConstraint* joint = cpPivotJointNew(getBodyInfo(a)->getBody(), getBodyInfo(b)->getBody(),
PhysicsHelper::point2cpv(anchr));
auto joint = cpPivotJointNew(_bodyA->getCPBody(), _bodyB->getCPBody(),
PhysicsHelper::point2cpv(_anchr));
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
_cpConstraints.push_back(joint);
// add a gear joint to make two body have the same rotation.
joint = cpGearJointNew(getBodyInfo(a)->getBody(), getBodyInfo(b)->getBody(), 0, 1);
joint = cpGearJointNew(_bodyA->getCPBody(), _bodyB->getCPBody(), 0, 1);
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
_cpConstraints.push_back(joint);
setCollisionEnable(false);
_collisionEnable = false;
return true;
} while (false);
@ -203,12 +183,14 @@ bool PhysicsJointFixed::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr)
return false;
}
PhysicsJointPin* PhysicsJointPin::construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr)
PhysicsJointPin* PhysicsJointPin::construct(PhysicsBody* a, PhysicsBody* b, const Vec2& pivot)
{
PhysicsJointPin* joint = new (std::nothrow) PhysicsJointPin();
auto joint = new (std::nothrow) PhysicsJointPin();
if (joint && joint->init(a, b, anchr))
if (joint && joint->init(a, b))
{
joint->_anchr1 = pivot;
joint->_useSpecificAnchr = false;
return joint;
}
@ -216,17 +198,41 @@ PhysicsJointPin* PhysicsJointPin::construct(PhysicsBody* a, PhysicsBody* b, cons
return nullptr;
}
bool PhysicsJointPin::init(PhysicsBody *a, PhysicsBody *b, const Vec2& anchr)
PhysicsJointPin* PhysicsJointPin::construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2)
{
auto joint = new (std::nothrow) PhysicsJointPin();
if (joint && joint->init(a, b))
{
joint->_anchr1 = anchr1;
joint->_anchr2 = anchr2;
joint->_useSpecificAnchr = true;
return joint;
}
CC_SAFE_DELETE(joint);
return nullptr;
}
bool PhysicsJointPin::createConstraints()
{
do
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpPivotJointNew(getBodyInfo(a)->getBody(), getBodyInfo(b)->getBody(),
PhysicsHelper::point2cpv(anchr));
cpConstraint* joint = nullptr;
if (_useSpecificAnchr)
{
joint = cpPivotJointNew2(_bodyA->getCPBody(), _bodyB->getCPBody(),
PhysicsHelper::point2cpv(_anchr1), PhysicsHelper::point2cpv(_anchr2));
}
else
{
joint = cpPivotJointNew(_bodyA->getCPBody(), _bodyB->getCPBody(),
PhysicsHelper::point2cpv(_anchr1));
}
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
_cpConstraints.push_back(joint);
return true;
} while (false);
@ -236,10 +242,15 @@ bool PhysicsJointPin::init(PhysicsBody *a, PhysicsBody *b, const Vec2& anchr)
PhysicsJointLimit* PhysicsJointLimit::construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2, float min, float max)
{
PhysicsJointLimit* joint = new (std::nothrow) PhysicsJointLimit();
auto joint = new (std::nothrow) PhysicsJointLimit();
if (joint && joint->init(a, b, anchr1, anchr2, min, max))
if (joint && joint->init(a, b))
{
joint->_anchr1 = anchr1;
joint->_anchr2 = anchr2;
joint->_min = min;
joint->_max = max;
return joint;
}
@ -252,21 +263,18 @@ PhysicsJointLimit* PhysicsJointLimit::construct(PhysicsBody* a, PhysicsBody* b,
return construct(a, b, anchr1, anchr2, 0, b->local2World(anchr1).getDistance(a->local2World(anchr2)));
}
bool PhysicsJointLimit::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2, float min, float max)
bool PhysicsJointLimit::createConstraints()
{
do
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpSlideJointNew(getBodyInfo(a)->getBody(), getBodyInfo(b)->getBody(),
PhysicsHelper::point2cpv(anchr1),
PhysicsHelper::point2cpv(anchr2),
PhysicsHelper::float2cpfloat(min),
PhysicsHelper::float2cpfloat(max));
auto joint = cpSlideJointNew(_bodyA->getCPBody(), _bodyB->getCPBody(),
PhysicsHelper::point2cpv(_anchr1),
PhysicsHelper::point2cpv(_anchr2),
PhysicsHelper::float2cpfloat(_min),
PhysicsHelper::float2cpfloat(_max));
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
_cpConstraints.push_back(joint);
return true;
} while (false);
@ -276,50 +284,53 @@ 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)
{
PhysicsJointDistance* joint = new (std::nothrow) PhysicsJointDistance();
auto joint = new (std::nothrow) PhysicsJointDistance();
if (joint && joint->init(a, b, anchr1, anchr2))
if (joint && joint->init(a, b))
{
joint->_anchr1 = anchr1;
joint->_anchr2 = anchr2;
return joint;
}
@ -327,20 +338,16 @@ PhysicsJointDistance* PhysicsJointDistance::construct(PhysicsBody* a, PhysicsBod
return nullptr;
}
bool PhysicsJointDistance::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2)
bool PhysicsJointDistance::createConstraints()
{
do
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpPinJointNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
PhysicsHelper::point2cpv(anchr1),
PhysicsHelper::point2cpv(anchr2));
auto joint = cpPinJointNew(_bodyA->getCPBody(),
_bodyB->getCPBody(),
PhysicsHelper::point2cpv(_anchr1),
PhysicsHelper::point2cpv(_anchr2));
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
_cpConstraints.push_back(joint);
return true;
} while (false);
@ -350,20 +357,25 @@ 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)
{
PhysicsJointSpring* joint = new (std::nothrow) PhysicsJointSpring();
auto joint = new (std::nothrow) PhysicsJointSpring();
if (joint && joint->init(a, b, anchr1, anchr2, stiffness, damping))
if (joint && joint->init(a, b))
{
joint->_anchr1 = anchr1;
joint->_anchr2 = anchr2;
joint->_stiffness = stiffness;
joint->_damping = damping;
return joint;
}
@ -371,22 +383,19 @@ PhysicsJointSpring* PhysicsJointSpring::construct(PhysicsBody* a, PhysicsBody* b
return nullptr;
}
bool PhysicsJointSpring::init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2, float stiffness, float damping)
bool PhysicsJointSpring::createConstraints()
{
do {
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpDampedSpringNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
PhysicsHelper::point2cpv(anchr1),
PhysicsHelper::point2cpv(anchr2),
PhysicsHelper::float2cpfloat(_bodyB->local2World(anchr1).getDistance(_bodyA->local2World(anchr2))),
PhysicsHelper::float2cpfloat(stiffness),
PhysicsHelper::float2cpfloat(damping));
auto joint = cpDampedSpringNew(_bodyA->getCPBody(),
_bodyB->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);
_info->add(joint);
_cpConstraints.push_back(joint);
return true;
} while (false);
@ -396,60 +405,64 @@ 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)
{
PhysicsJointGroove* joint = new (std::nothrow) PhysicsJointGroove();
auto joint = new (std::nothrow) PhysicsJointGroove();
if (joint && joint->init(a, b, grooveA, grooveB, anchr2))
if (joint && joint->init(a, b))
{
joint->_grooveA = grooveA;
joint->_grooveB = grooveB;
joint->_anchr2 = anchr2;
return joint;
}
@ -457,20 +470,17 @@ PhysicsJointGroove* PhysicsJointGroove::construct(PhysicsBody* a, PhysicsBody* b
return nullptr;
}
bool PhysicsJointGroove::init(PhysicsBody* a, PhysicsBody* b, const Vec2& grooveA, const Vec2& grooveB, const Vec2& anchr2)
bool PhysicsJointGroove::createConstraints()
{
do {
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpGrooveJointNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
PhysicsHelper::point2cpv(grooveA),
PhysicsHelper::point2cpv(grooveB),
PhysicsHelper::point2cpv(anchr2));
auto joint = cpGrooveJointNew(_bodyA->getCPBody(),
_bodyB->getCPBody(),
PhysicsHelper::point2cpv(_grooveA),
PhysicsHelper::point2cpv(_grooveB),
PhysicsHelper::point2cpv(_anchr2));
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
_cpConstraints.push_back(joint);
return true;
} while (false);
@ -480,40 +490,43 @@ 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)
{
PhysicsJointRotarySpring* joint = new (std::nothrow) PhysicsJointRotarySpring();
auto joint = new (std::nothrow) PhysicsJointRotarySpring();
if (joint && joint->init(a, b, stiffness, damping))
if (joint && joint->init(a, b))
{
joint->_stiffness = stiffness;
joint->_damping = damping;
return joint;
}
@ -521,20 +534,17 @@ PhysicsJointRotarySpring* PhysicsJointRotarySpring::construct(PhysicsBody* a, Ph
return nullptr;
}
bool PhysicsJointRotarySpring::init(PhysicsBody* a, PhysicsBody* b, float stiffness, float damping)
bool PhysicsJointRotarySpring::createConstraints()
{
do {
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpDampedRotarySpringNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
auto joint = cpDampedRotarySpringNew(_bodyA->getCPBody(),
_bodyB->getCPBody(),
PhysicsHelper::float2cpfloat(_bodyB->getRotation() - _bodyA->getRotation()),
PhysicsHelper::float2cpfloat(stiffness),
PhysicsHelper::float2cpfloat(damping));
PhysicsHelper::float2cpfloat(_stiffness),
PhysicsHelper::float2cpfloat(_damping));
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
_cpConstraints.push_back(joint);
return true;
} while (false);
@ -544,40 +554,43 @@ 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)
{
PhysicsJointRotaryLimit* joint = new (std::nothrow) PhysicsJointRotaryLimit();
auto joint = new (std::nothrow) PhysicsJointRotaryLimit();
if (joint && joint->init(a, b, min, max))
if (joint && joint->init(a, b))
{
joint->_min = min;
joint->_max = max;
return joint;
}
@ -590,20 +603,17 @@ PhysicsJointRotaryLimit* PhysicsJointRotaryLimit::construct(PhysicsBody* a, Phys
return construct(a, b, 0.0f, 0.0f);
}
bool PhysicsJointRotaryLimit::init(PhysicsBody* a, PhysicsBody* b, float min, float max)
bool PhysicsJointRotaryLimit::createConstraints()
{
do
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpRotaryLimitJointNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
PhysicsHelper::float2cpfloat(min),
PhysicsHelper::float2cpfloat(max));
auto joint = cpRotaryLimitJointNew(_bodyA->getCPBody(),
_bodyB->getCPBody(),
PhysicsHelper::float2cpfloat(_min),
PhysicsHelper::float2cpfloat(_max));
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
_cpConstraints.push_back(joint);
return true;
} while (false);
@ -613,30 +623,33 @@ 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)
{
PhysicsJointRatchet* joint = new (std::nothrow) PhysicsJointRatchet();
auto joint = new (std::nothrow) PhysicsJointRatchet();
if (joint && joint->init(a, b, phase, ratchet))
if (joint && joint->init(a, b))
{
joint->_phase = phase;
joint->_ratchet = ratchet;
return joint;
}
@ -644,20 +657,17 @@ PhysicsJointRatchet* PhysicsJointRatchet::construct(PhysicsBody* a, PhysicsBody*
return nullptr;
}
bool PhysicsJointRatchet::init(PhysicsBody* a, PhysicsBody* b, float phase, float ratchet)
bool PhysicsJointRatchet::createConstraints()
{
do
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpRatchetJointNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
PhysicsHelper::float2cpfloat(phase),
PhysicsHelper::cpfloat2float(ratchet));
auto joint = cpRatchetJointNew(_bodyA->getCPBody(),
_bodyB->getCPBody(),
PhysicsHelper::float2cpfloat(_phase),
PhysicsHelper::cpfloat2float(_ratchet));
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
_cpConstraints.push_back(joint);
return true;
} while (false);
@ -667,40 +677,43 @@ 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)
PhysicsJointGear* PhysicsJointGear::construct(PhysicsBody* a, PhysicsBody* b, float phase, float ratio)
{
PhysicsJointGear* joint = new (std::nothrow) PhysicsJointGear();
auto joint = new (std::nothrow) PhysicsJointGear();
if (joint && joint->init(a, b, phase, ratchet))
if (joint && joint->init(a, b))
{
joint->_phase = phase;
joint->_ratio = ratio;
return joint;
}
@ -708,20 +721,17 @@ PhysicsJointGear* PhysicsJointGear::construct(PhysicsBody* a, PhysicsBody* b, fl
return nullptr;
}
bool PhysicsJointGear::init(PhysicsBody* a, PhysicsBody* b, float phase, float ratio)
bool PhysicsJointGear::createConstraints()
{
do
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpGearJointNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
PhysicsHelper::float2cpfloat(phase),
PhysicsHelper::float2cpfloat(ratio));
auto joint = cpGearJointNew(_bodyA->getCPBody(),
_bodyB->getCPBody(),
PhysicsHelper::float2cpfloat(_phase),
PhysicsHelper::float2cpfloat(_ratio));
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
_cpConstraints.push_back(joint);
return true;
} while (false);
@ -731,30 +741,32 @@ 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)
{
PhysicsJointMotor* joint = new (std::nothrow) PhysicsJointMotor();
auto joint = new (std::nothrow) PhysicsJointMotor();
if (joint && joint->init(a, b, rate))
if (joint && joint->init(a, b))
{
joint->_rate = rate;
return joint;
}
@ -762,19 +774,16 @@ PhysicsJointMotor* PhysicsJointMotor::construct(PhysicsBody* a, PhysicsBody* b,
return nullptr;
}
bool PhysicsJointMotor::init(PhysicsBody* a, PhysicsBody* b, float rate)
bool PhysicsJointMotor::createConstraints()
{
do
{
CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpSimpleMotorNew(getBodyInfo(a)->getBody(),
getBodyInfo(b)->getBody(),
PhysicsHelper::float2cpfloat(rate));
auto joint = cpSimpleMotorNew(_bodyA->getCPBody(),
_bodyB->getCPBody(),
PhysicsHelper::float2cpfloat(_rate));
CC_BREAK_IF(joint == nullptr);
_info->add(joint);
_cpConstraints.push_back(joint);
return true;
} while (false);
@ -784,12 +793,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.
@ -62,32 +62,30 @@ public:
void setCollisionEnable(bool enable);
/** Remove the joint from the world */
void removeFormWorld();
/** Distory the joint*/
static void destroy(PhysicsJoint* joint);
/** Set the max force between two bodies */
void setMaxForce(float force);
/** Get the max force setting */
float getMaxForce() const;
float getMaxForce() const { return _maxForce; }
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;
bool initJoint();
virtual bool createConstraints() { return false; }
protected:
std::vector<cpConstraint*> _cpConstraints;
PhysicsBody* _bodyA;
PhysicsBody* _bodyB;
PhysicsWorld* _world;
PhysicsJointInfo* _info;
bool _enable;
bool _collisionEnable;
bool _destoryMark;
int _tag;
float _maxForce;
bool _initDirty;
friend class PhysicsBody;
friend class PhysicsWorld;
@ -95,24 +93,25 @@ protected:
};
/*
* @brief A fixed joint fuses the two bodies together at a reference point. Fixed joints are useful for creating complex shapes that can be broken apart later.
*/
* @brief A fixed joint fuses the two bodies together at a reference point. Fixed joints are useful for creating complex shapes that can be broken apart later.
*/
class CC_DLL PhysicsJointFixed : public PhysicsJoint
{
public:
static PhysicsJointFixed* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr);
protected:
bool init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr);
virtual bool createConstraints() override;
protected:
PhysicsJointFixed() {}
virtual ~PhysicsJointFixed() {}
Vec2 _anchr;
};
/*
* @brief A limit joint imposes a maximum distance between the two bodies, as if they were connected by a rope.
*/
* @brief A limit joint imposes a maximum distance between the two bodies, as if they were connected by a rope.
*/
class CC_DLL PhysicsJointLimit : public PhysicsJoint
{
public:
@ -128,28 +127,36 @@ public:
float getMax() const;
void setMax(float max);
protected:
bool init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2, float min, float max);
virtual bool createConstraints() override;
protected:
PhysicsJointLimit() {}
virtual ~PhysicsJointLimit() {}
Vec2 _anchr1;
Vec2 _anchr2;
float _min;
float _max;
};
/*
* @brief A pin joint allows the two bodies to independently rotate around the anchor point as if pinned together.
*/
* @brief A pin joint allows the two bodies to independently rotate around the anchor point as if pinned together.
*/
class CC_DLL PhysicsJointPin : public PhysicsJoint
{
public:
static PhysicsJointPin* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr);
static PhysicsJointPin* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& pivot);
static PhysicsJointPin* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2);
protected:
bool init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr);
virtual bool createConstraints() override;
protected:
PhysicsJointPin() {}
virtual ~PhysicsJointPin() {}
bool _useSpecificAnchr;
Vec2 _anchr1;
Vec2 _anchr2;
};
/** Set the fixed distance with two bodies */
@ -160,13 +167,14 @@ public:
float getDistance() const;
void setDistance(float distance);
protected:
bool init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2);
virtual bool createConstraints() override;
protected:
PhysicsJointDistance() {}
virtual ~PhysicsJointDistance() {}
Vec2 _anchr1;
Vec2 _anchr2;
};
/** Connecting two physics bodies together with a spring. */
@ -184,13 +192,16 @@ public:
void setStiffness(float stiffness);
float getDamping() const;
void setDamping(float damping);
protected:
bool init(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2, float stiffness, float damping);
virtual bool createConstraints() override;
protected:
PhysicsJointSpring() {}
virtual ~PhysicsJointSpring() {}
Vec2 _anchr1;
Vec2 _anchr2;
float _stiffness;
float _damping;
};
/** Attach body a to a line, and attach body b to a dot */
@ -205,13 +216,15 @@ public:
void setGrooveB(const Vec2& grooveB);
Vec2 getAnchr2() const;
void setAnchr2(const Vec2& anchr2);
protected:
bool init(PhysicsBody* a, PhysicsBody* b, const Vec2& grooveA, const Vec2& grooveB, const Vec2& anchr);
virtual bool createConstraints() override;
protected:
PhysicsJointGroove() {}
virtual ~PhysicsJointGroove() {}
Vec2 _grooveA;
Vec2 _grooveB;
Vec2 _anchr2;
};
/** Likes a spring joint, but works with rotary */
@ -226,13 +239,14 @@ public:
void setStiffness(float stiffness);
float getDamping() const;
void setDamping(float damping);
protected:
bool init(PhysicsBody* a, PhysicsBody* b, float stiffness, float damping);
virtual bool createConstraints() override;
protected:
PhysicsJointRotarySpring() {}
virtual ~PhysicsJointRotarySpring() {}
float _stiffness;
float _damping;
};
/** Likes a limit joint, but works with rotary */
@ -246,13 +260,14 @@ public:
void setMin(float min);
float getMax() const;
void setMax(float max);
protected:
bool init(PhysicsBody* a, PhysicsBody* b, float min, float max);
virtual bool createConstraints() override;
protected:
PhysicsJointRotaryLimit() {}
virtual ~PhysicsJointRotaryLimit() {}
float _min;
float _max;
};
/** Works like a socket wrench. */
@ -267,13 +282,14 @@ public:
void setPhase(float phase);
float getRatchet() const;
void setRatchet(float ratchet);
protected:
bool init(PhysicsBody* a, PhysicsBody* b, float phase, float ratchet);
virtual bool createConstraints() override;
protected:
PhysicsJointRatchet() {}
virtual ~PhysicsJointRatchet() {}
float _phase;
float _ratchet;
};
/** Keeps the angular velocity ratio of a pair of bodies constant. */
@ -287,12 +303,14 @@ public:
float getRatio() const;
void setRatio(float ratchet);
protected:
bool init(PhysicsBody* a, PhysicsBody* b, float phase, float ratio);
virtual bool createConstraints() override;
protected:
PhysicsJointGear() {}
virtual ~PhysicsJointGear() {}
float _phase;
float _ratio;
};
/** Keeps the relative angular velocity of a pair of bodies constant */
@ -303,13 +321,13 @@ public:
float getRate() const;
void setRate(float rate);
protected:
bool init(PhysicsBody* a, PhysicsBody* b, float rate);
virtual bool createConstraints() override;
protected:
PhysicsJointMotor() {}
virtual ~PhysicsJointMotor() {}
float _rate;
};
NS_CC_END

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)
@ -51,29 +50,26 @@ PhysicsShape::PhysicsShape()
, _scaleY(1.0f)
, _newScaleX(1.0f)
, _newScaleY(1.0f)
, _dirty(false)
, _tag(0)
, _categoryBitmask(UINT_MAX)
, _collisionBitmask(UINT_MAX)
, _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,60 +111,34 @@ 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);
setScaleY(scale);
}
void PhysicsShape::setScale(float scaleX, float scaleY)
{
setScaleX(scaleX);
setScaleY(scaleY);
}
void PhysicsShape::setScaleX(float scaleX)
{
if (_scaleX == scaleX)
if (_scaleX != scaleX || _scaleY != scaleY)
{
if (_type == Type::CIRCLE && scaleX != scaleY)
{
CCLOG("PhysicsShapeCircle WARNING: CANNOT support setScale with different x and y");
return;
}
_newScaleX = scaleX;
_dirty = true;
}
void PhysicsShape::setScaleY(float scaleY)
{
if (_scaleY == scaleY)
{
return;
}
_newScaleY = scaleY;
_dirty = true;
updateScale();
}
}
void PhysicsShape::update(float delta)
void PhysicsShape::updateScale()
{
CC_UNUSED_PARAM(delta);
if (_dirty)
{
_scaleX = _newScaleX;
_scaleY = _newScaleY;
_dirty = false;
}
void PhysicsShape::addShape(cpShape* shape)
{
if (shape)
{
cpShapeSetGroup(shape, _group);
_cpShapes.push_back(shape);
s_physicsShapeMap.insert(std::pair<cpShape*, PhysicsShape*>(shape, this));
}
}
@ -264,7 +234,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 +244,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 +279,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 +314,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 +349,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,72 +365,26 @@ 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)
void PhysicsShapeCircle::updateScale()
{
if (_scaleX == scale)
{
return;
}
cpFloat factor = std::abs(PhysicsHelper::float2cpfloat(_newScaleX / _scaleX));
_newScaleX = _newScaleY = scale;
_dirty = true;
}
void PhysicsShapeCircle::setScale(float scaleX, float scaleY)
{
if (scaleX != scaleY)
{
CCLOG("PhysicsShapeCircle WARNING: CANNOT support setScale with different x and y");
}
if (_scaleX == scaleX)
{
return;
}
_newScaleX = _newScaleY = scaleX;
_dirty = true;
}
void PhysicsShapeCircle::setScaleX(float scale)
{
CCLOG("PhysicsShapeCircle WARNING: CANNOT support setScaleX");
setScale(scale);
}
void PhysicsShapeCircle::setScaleY(float scale)
{
CCLOG("PhysicsShapeCircle WARNING: CANNOT support setScaleY");
setScale(scale);
}
void PhysicsShapeCircle::update(float delta)
{
if (_dirty)
{
cpFloat factor = std::abs(PhysicsHelper::float2cpfloat( _newScaleX / _scaleX ));
cpShape* shape = _info->getShapes().front();
cpShape* shape = _cpShapes.front();
cpVect v = cpCircleShapeGetOffset(shape);
v = cpvmult(v, PhysicsHelper::float2cpfloat(factor));
((cpCircleShape*)shape)->c = v;
cpCircleShapeSetRadius(shape, cpCircleShapeGetRadius(shape) * factor);
}
PhysicsShape::update(delta);
PhysicsShape::updateScale();
}
// PhysicsShapeEdgeSegment
@ -485,21 +405,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,29 +429,27 @@ 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;
}
void PhysicsShapeEdgeSegment::update(float delta)
void PhysicsShapeEdgeSegment::updateScale()
{
if (_dirty)
{
cpFloat factorX = PhysicsHelper::float2cpfloat(_newScaleX / _scaleX);
cpFloat factorY = PhysicsHelper::float2cpfloat(_newScaleY / _scaleY);
cpShape* shape = _info->getShapes().front();
cpShape* shape = _cpShapes.front();
cpVect a = cpSegmentShapeGetA(shape);
a.x *= factorX;
a.y *= factorY;
@ -540,9 +457,8 @@ void PhysicsShapeEdgeSegment::update(float delta)
b.x *= factorX;
b.y *= factorY;
cpSegmentShapeSetEndpoints(shape, a, b);
}
PhysicsShape::update(delta);
PhysicsShape::updateScale();
}
// PhysicsShapeBox
@ -563,19 +479,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 +507,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 +530,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,58 +576,56 @@ 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)
void PhysicsShapePolygon::updateScale()
{
if (_dirty)
{
cpFloat factorX = PhysicsHelper::float2cpfloat( _newScaleX / _scaleX );
cpFloat factorY = PhysicsHelper::float2cpfloat( _newScaleY / _scaleY );
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;
for (int i = 0; i < count ; ++i)
for (int i = 0; i < count; ++i)
{
vects[i].x *= factorX;
vects[i].y *= factorY;
}
// convert hole to clockwise
if ( factorX * factorY < 0 )
if (factorX * factorY < 0)
{
for (int i = 0; i < count / 2; ++i)
{
@ -728,9 +642,8 @@ void PhysicsShapePolygon::update(float delta)
planes[i].n = n;
planes[i].d = cpvdot(n, vects[i]);
}
}
PhysicsShape::update(delta);
PhysicsShape::updateScale();
}
// PhysicsShapeEdgeBox
@ -751,7 +664,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 +675,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 +712,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 +720,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);
addShape(shape);
}
CC_SAFE_DELETE_ARRAY(vec);
@ -833,10 +746,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 +763,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 +771,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
@ -875,14 +788,12 @@ PhysicsShapeEdgeChain* PhysicsShapeEdgeChain::create(const Vec2* points, int cou
return nullptr;
}
void PhysicsShapeEdgePolygon::update(float delta)
void PhysicsShapeEdgePolygon::updateScale()
{
if (_dirty)
{
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;
@ -892,9 +803,8 @@ void PhysicsShapeEdgePolygon::update(float delta)
b.y *= factorY;
cpSegmentShapeSetEndpoints(shape, a, b);
}
}
PhysicsShape::update(delta);
PhysicsShape::updateScale();
}
bool PhysicsShapeEdgeChain::init(const Vec2* points, int count, const PhysicsMaterial& material/* = MaterialDefault*/, float border/* = 1*/)
@ -902,7 +812,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 +820,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);
addShape(shape);
}
CC_SAFE_DELETE_ARRAY(vec);
CC_BREAK_IF(i < count - 1);
@ -935,15 +845,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,27 +864,25 @@ 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)
void PhysicsShapeEdgeChain::updateScale()
{
if (_dirty)
{
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;
@ -984,16 +892,15 @@ void PhysicsShapeEdgeChain::update(float delta)
b.y *= factorY;
cpSegmentShapeSetEndpoints(shape, a, b);
}
}
PhysicsShape::update(delta);
PhysicsShape::updateScale();
}
void PhysicsShape::setGroup(int group)
{
if (group < 0)
{
for (auto shape : _info->getShapes())
for (auto shape : _cpShapes)
{
cpShapeSetGroup(shape, (cpGroup)group);
}
@ -1004,7 +911,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
{
@ -57,7 +56,7 @@ typedef struct CC_DLL PhysicsMaterial
{}
}PhysicsMaterial;
const PhysicsMaterial PHYSICSSHAPE_MATERIAL_DEFAULT(0.0f, 0.5f, 0.5f);
const PhysicsMaterial PHYSICSSHAPE_MATERIAL_DEFAULT;
/**
* @brief A shape for body. You do not create PhysicsWorld objects directly, instead, you can view PhysicsBody to see how to create it.
@ -149,23 +148,14 @@ 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 */
virtual float calculateArea() { return 0.0f; }
virtual void setScale(float scale);
virtual void setScale(float scaleX, float scaleY);
virtual void setScaleX(float scaleX);
virtual void setScaleY(float scaleY);
virtual void update(float delta);
virtual void updateScale();
void addShape(cpShape* shape);
protected:
PhysicsShape();
@ -173,7 +163,8 @@ protected:
protected:
PhysicsBody* _body;
PhysicsShapeInfo* _info;
std::vector<cpShape*> _cpShapes;
Type _type;
float _area;
float _mass;
@ -182,7 +173,6 @@ protected:
float _scaleY;
float _newScaleX;
float _newScaleY;
bool _dirty;
PhysicsMaterial _material;
int _tag;
int _categoryBitmask;
@ -212,11 +202,7 @@ public:
protected:
bool init(float radius, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, const Vec2& offset = Vec2::ZERO);
virtual float calculateArea() override;
virtual void setScale(float scale) override;
virtual void setScale(float scaleX, float scaleY) override;
virtual void setScaleX(float scale) override;
virtual void setScaleY(float scale) override;
virtual void update(float delta) override;
virtual void updateScale() override;
protected:
PhysicsShapeCircle();
@ -240,7 +226,7 @@ public:
protected:
bool init(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, const Vec2& offset = Vec2::ZERO);
float calculateArea() override;
virtual void update(float delta) override;
virtual void updateScale() override;
protected:
PhysicsShapePolygon();
@ -276,7 +262,7 @@ public:
protected:
bool init(const Vec2& a, const Vec2& b, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
virtual void update(float delta) override;
virtual void updateScale() override;
protected:
PhysicsShapeEdgeSegment();
@ -296,7 +282,7 @@ public:
protected:
bool init(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
virtual void update(float delta) override;
virtual void updateScale() override;
protected:
PhysicsShapeEdgePolygon();
@ -333,7 +319,7 @@ public:
protected:
bool init(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
virtual void update(float delta) override;
virtual void updateScale() override;
protected:
PhysicsShapeEdgeChain();

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,
@ -476,9 +468,9 @@ void PhysicsWorld::doAddBody(PhysicsBody* body)
if (body->isEnabled())
{
// 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
@ -489,7 +481,6 @@ void PhysicsWorld::doAddBody(PhysicsBody* body)
}
}
void PhysicsWorld::addBodyOrDelay(PhysicsBody* body)
{
auto removeBodyIter = _delayRemoveBodies.find(body);
@ -499,23 +490,16 @@ void PhysicsWorld::addBodyOrDelay(PhysicsBody* body)
return;
}
if (_info->isLocked())
{
if (_delayAddBodies.find(body) == _delayAddBodies.end())
{
_delayAddBodies.pushBack(body);
_delayDirty = true;
}
}
else
{
doAddBody(body);
}
}
void PhysicsWorld::updateBodies()
{
if (_info->isLocked())
if (cpSpaceIsLocked(_cpSpace))
{
return;
}
@ -550,7 +534,6 @@ void PhysicsWorld::removeBody(int tag)
void PhysicsWorld::removeBody(PhysicsBody* body)
{
if (body->getWorld() != this)
{
CCLOG("Physics Warnning: this body doesn't belong to this world");
@ -558,25 +541,11 @@ void PhysicsWorld::removeBody(PhysicsBody* body)
}
// destory the body's joints
for (auto joint : body->_joints)
auto removeCopy = body->_joints;
for (auto joint : removeCopy)
{
// set destroy param to false to keep the iterator available
removeJoint(joint, false);
PhysicsBody* other = (joint->getBodyA() == body ? joint->getBodyB() : joint->getBodyA());
other->removeJoint(joint);
// test the distraction is delaied or not
if (std::find(_delayRemoveJoints.rbegin(), _delayRemoveJoints.rend(), joint) != _delayRemoveJoints.rend())
{
joint->_destoryMark = true;
removeJoint(joint, true);
}
else
{
delete joint;
}
}
body->_joints.clear();
removeBodyOrDelay(body);
@ -593,7 +562,7 @@ void PhysicsWorld::removeBodyOrDelay(PhysicsBody* body)
return;
}
if (_info->isLocked())
if (cpSpaceIsLocked(_cpSpace))
{
if (_delayRemoveBodies.getIndex(body) == CC_INVALID_INDEX)
{
@ -606,116 +575,19 @@ void PhysicsWorld::removeBodyOrDelay(PhysicsBody* body)
}
}
void PhysicsWorld::doAddJoint(PhysicsJoint *joint)
{
if (joint == nullptr || joint->_info == nullptr)
{
return;
}
_info->addJoint(*joint->_info);
}
void PhysicsWorld::removeJoint(PhysicsJoint* joint, bool destroy)
{
if (joint->getWorld() != this)
if (joint)
{
if (destroy)
if (joint->getWorld() != this && destroy)
{
CCLOG("physics warnning: the joint is not in this world, it won't be destoried utill the body it conntect is destoried");
}
return;
}
removeJointOrDelay(joint);
_joints.remove(joint);
joint->_world = nullptr;
// clean the connection to this joint
if (destroy)
joint->_destoryMark = destroy;
if (cpSpaceIsLocked(_cpSpace))
{
if (joint->getBodyA() != nullptr)
{
joint->getBodyA()->removeJoint(joint);
}
if (joint->getBodyB() != nullptr)
{
joint->getBodyB()->removeJoint(joint);
}
// test the distraction is delaied or not
if (std::find(_delayRemoveJoints.rbegin(), _delayRemoveJoints.rend(), joint) != _delayRemoveJoints.rend())
{
joint->_destoryMark = true;
}
else
{
delete joint;
}
}
}
void PhysicsWorld::updateJoints()
{
if (_info->isLocked())
{
return;
}
auto addCopy = _delayAddJoints;
_delayAddJoints.clear();
for (auto joint : addCopy)
{
doAddJoint(joint);
}
auto removeCopy = _delayRemoveJoints;
_delayRemoveJoints.clear();
for (auto joint : removeCopy)
{
doRemoveJoint(joint);
if (joint->_destoryMark)
{
delete joint;
}
}
}
void PhysicsWorld::removeShape(PhysicsShape* shape)
{
if (shape != nullptr)
{
_info->removeShape(*shape->_info);
}
}
void PhysicsWorld::addJointOrDelay(PhysicsJoint* joint)
{
auto it = std::find(_delayRemoveJoints.begin(), _delayRemoveJoints.end(), joint);
if (it != _delayRemoveJoints.end())
{
_delayRemoveJoints.erase(it);
return;
}
if (_info->isLocked())
{
if (std::find(_delayAddJoints.begin(), _delayAddJoints.end(), joint) == _delayAddJoints.end())
{
_delayAddJoints.push_back(joint);
_delayDirty = true;
}
}else
{
doAddJoint(joint);
}
}
void PhysicsWorld::removeJointOrDelay(PhysicsJoint* joint)
{
auto it = std::find(_delayAddJoints.begin(), _delayAddJoints.end(), joint);
if (it != _delayAddJoints.end())
{
@ -723,71 +595,102 @@ void PhysicsWorld::removeJointOrDelay(PhysicsJoint* joint)
return;
}
if (_info->isLocked())
{
if (std::find(_delayRemoveJoints.rbegin(), _delayRemoveJoints.rend(), joint) == _delayRemoveJoints.rend())
{
_delayRemoveJoints.push_back(joint);
_delayDirty = true;
}
}else
}
else
{
doRemoveJoint(joint);
}
}
}
void PhysicsWorld::addJoint(PhysicsJoint* joint)
void PhysicsWorld::updateJoints()
{
if (joint->getWorld() != nullptr && joint->getWorld() != this)
if (cpSpaceIsLocked(_cpSpace))
{
joint->removeFormWorld();
return;
}
addJointOrDelay(joint);
_joints.push_back(joint);
for (auto joint : _delayAddJoints)
{
joint->_world = this;
}
void PhysicsWorld::removeAllJoints(bool destroy)
{
for (auto joint : _joints)
if (joint->initJoint())
{
removeJointOrDelay(joint);
joint->_world = nullptr;
// clean the connection to this joint
if (destroy)
{
if (joint->getBodyA() != nullptr)
{
joint->getBodyA()->removeJoint(joint);
}
if (joint->getBodyB() != nullptr)
{
joint->getBodyB()->removeJoint(joint);
}
// test the distraction is delaied or not
if (std::find(_delayRemoveJoints.rbegin(), _delayRemoveJoints.rend(), joint) != _delayRemoveJoints.rend())
{
joint->_destoryMark = true;
_joints.push_back(joint);
}
else
{
delete joint;
}
}
}
_delayAddJoints.clear();
_joints.clear();
for (auto joint : _delayRemoveJoints)
{
doRemoveJoint(joint);
}
_delayRemoveJoints.clear();
}
void PhysicsWorld::addShape(PhysicsShape* shape)
void PhysicsWorld::removeShape(PhysicsShape* shape)
{
if (shape != nullptr)
if (shape)
{
_info->addShape(*shape->_info);
for (auto cps : shape->_cpShapes)
{
if (cpSpaceContainsShape(_cpSpace, cps))
{
cpSpaceRemoveShape(_cpSpace, cps);
}
}
}
}
void PhysicsWorld::addJoint(PhysicsJoint* joint)
{
if (joint)
{
if (joint->getWorld() && joint->getWorld() != this)
{
joint->removeFormWorld();
}
auto it = std::find(_delayRemoveJoints.begin(), _delayRemoveJoints.end(), joint);
if (it != _delayRemoveJoints.end())
{
_delayRemoveJoints.erase(it);
return;
}
if (std::find(_delayAddJoints.begin(), _delayAddJoints.end(), joint) == _delayAddJoints.end())
{
_delayAddJoints.push_back(joint);
_delayDirty = true;
}
}
}
void PhysicsWorld::removeAllJoints(bool destroy)
{
auto removeCopy = _joints;
for (auto joint : removeCopy)
{
removeJoint(joint, destroy);
}
}
void PhysicsWorld::addShape(PhysicsShape* physicsShape)
{
if (physicsShape)
{
for (auto shape : physicsShape->_cpShapes)
{
cpSpaceAddShape(_cpSpace, shape);
}
}
}
@ -802,12 +705,35 @@ 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);
}
_joints.remove(joint);
joint->_world = nullptr;
if (joint->getBodyA())
{
joint->getBodyA()->removeJoint(joint);
}
if (joint->getBodyB())
{
joint->getBodyB()->removeJoint(joint);
}
if (joint->_destoryMark)
{
delete joint;
}
}
void PhysicsWorld::removeAllBodies()
@ -852,7 +778,7 @@ PhysicsBody* PhysicsWorld::getBody(int tag) const
void PhysicsWorld::setGravity(const Vect& gravity)
{
_gravity = gravity;
_info->setGravity(gravity);
cpSpaceSetGravity(_cpSpace, PhysicsHelper::point2cpv(gravity));
}
void PhysicsWorld::setSubsteps(int steps)
@ -881,17 +807,24 @@ void PhysicsWorld::step(float delta)
void PhysicsWorld::update(float delta, bool userCall/* = false*/)
{
if (delta < FLT_EPSILON)
{
return;
}
_scene->updatePhysicsBodyTransform(_scene, _scene->getNodeToParentTransform(), 0, 1.0f, 1.0f);
while (_delayDirty)
{
// the updateJoints must run before the updateBodies.
updateJoints();
updateBodies();
updateJoints();
_delayDirty = !(_delayAddBodies.size() == 0 && _delayRemoveBodies.size() == 0 && _delayAddJoints.size() == 0 && _delayRemoveJoints.size() == 0);
}
if (userCall)
{
_info->step(delta);
cpSpaceStep(_cpSpace, delta);
for (auto& body : _bodies)
{
body->update(delta);
@ -905,7 +838,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);
@ -929,7 +862,7 @@ PhysicsWorld::PhysicsWorld()
, _updateRateCount(0)
, _updateTime(0.0f)
, _substeps(1)
, _info(nullptr)
, _cpSpace(nullptr)
, _scene(nullptr)
, _delayDirty(false)
, _autoStep(true)
@ -943,7 +876,10 @@ PhysicsWorld::~PhysicsWorld()
{
removeAllJoints(true);
removeAllBodies();
CC_SAFE_DELETE(_info);
if (_cpSpace)
{
cpSpaceFree(_cpSpace);
}
CC_SAFE_DELETE(_debugDraw);
}
@ -976,7 +912,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;
@ -1032,7 +968,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,16 +34,18 @@
#include "physics/CCPhysicsBody.h"
#include <list>
struct cpSpace;
NS_CC_BEGIN
class PhysicsBody;
class PhysicsJoint;
class PhysicsWorldInfo;
class PhysicsShape;
class PhysicsContact;
typedef Vec2 Vect;
class Director;
class Node;
class Sprite;
class Scene;
@ -187,12 +189,9 @@ protected:
virtual void doAddBody(PhysicsBody* body);
virtual void doRemoveBody(PhysicsBody* body);
virtual void doAddJoint(PhysicsJoint* joint);
virtual void doRemoveJoint(PhysicsJoint* joint);
virtual void addBodyOrDelay(PhysicsBody* body);
virtual void removeBodyOrDelay(PhysicsBody* body);
virtual void addJointOrDelay(PhysicsJoint* joint);
virtual void removeJointOrDelay(PhysicsJoint* joint);
virtual void updateBodies();
virtual void updateJoints();
@ -203,7 +202,7 @@ protected:
int _updateRateCount;
float _updateTime;
int _substeps;
PhysicsWorldInfo* _info;
cpSpace* _cpSpace;
Vector<PhysicsBody*> _bodies;
std::list<PhysicsJoint*> _joints;
@ -227,6 +226,7 @@ protected:
friend class Node;
friend class Sprite;
friend class Scene;
friend class Director;
friend class PhysicsBody;
friend class PhysicsShape;
friend class PhysicsJoint;

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

@ -779,9 +779,8 @@ std::string FileUtils::fullPathForFilename(const std::string &filename)
CCLOG("cocos2d: fullPathForFilename: No file found at %s. Possible missing file.", filename.c_str());
}
// FIXME: Should it return nullptr ? or an empty string ?
// The file wasn't found, return the file name passed in.
return filename;
// The file wasn't found, return empty string.
return "";
}
std::string FileUtils::fullPathFromRelativeFile(const std::string &filename, const std::string &relativeFile)

View File

@ -63,6 +63,127 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
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;
}
@ -224,127 +345,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
//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

@ -384,7 +384,7 @@ public class Cocos2dxBitmap {
i = lastIndexOfSpace + 1; // skip space
} else {
// Should not exceed the width.
if (tempWidth > maxWidth) {
if (tempWidth > maxWidth && i != start + 1) {
strList.add(string.substring(start, i - 1));
// Compute from previous char.
--i;

View File

@ -184,14 +184,14 @@ public class Cocos2dxHttpURLConnection
return null;
}
String header = null;
String header = "";
for (Entry<String, List<String>> entry: headers.entrySet()) {
String key = entry.getKey();
if (null == key) {
header += listToString(entry.getValue(), ",");
header += listToString(entry.getValue(), ",") + "\n";
} else {
header += key + ":" + listToString(entry.getValue(), ",");
header += key + ":" + listToString(entry.getValue(), ",") + "\n";
}
}

View File

@ -210,13 +210,16 @@ public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl
private boolean isAssetRouse = false;
private String fileName = null;
private String assetResourceRoot = "assets/";
public void setVideoFileName(String path) {
if (path.startsWith("/")) {
isAssetRouse = false;
setVideoURI(Uri.parse(path),null);
}
else {
if (path.startsWith(assetResourceRoot)) {
path = path.substring(assetResourceRoot.length());
}
fileName = path;
isAssetRouse = true;
setVideoURI(Uri.parse(path),null);

View File

@ -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
{

View File

@ -375,6 +375,7 @@ void GLProgramState::applyAttributes(bool applyAttribFlags)
{
// Don't set attributes if they weren't set
// Use Case: Auto-batching
updateUniformsAndAttributes();
if(_vertexAttribsFlags) {
// enable/disable vertex attribs
if (applyAttribFlags)
@ -389,6 +390,7 @@ void GLProgramState::applyAttributes(bool applyAttribFlags)
void GLProgramState::applyUniforms()
{
// set uniforms
updateUniformsAndAttributes();
for(auto& uniform : _uniforms) {
uniform.second.apply();
}

View File

@ -42,10 +42,10 @@ bool IndexBuffer::_enableShadowCopy = true;
bool IndexBuffer::_enableShadowCopy = false;
#endif
VertexBuffer* VertexBuffer::create(int sizePerVertex, int vertexNumber)
VertexBuffer* VertexBuffer::create(int sizePerVertex, int vertexNumber, GLenum usage/* = GL_STATIC_DRAW*/)
{
auto result = new (std::nothrow) VertexBuffer();
if(result && result->init(sizePerVertex, vertexNumber))
if(result && result->init(sizePerVertex, vertexNumber, usage))
{
result->autorelease();
return result;
@ -85,12 +85,13 @@ VertexBuffer::~VertexBuffer()
#endif
}
bool VertexBuffer::init(int sizePerVertex, int vertexNumber)
bool VertexBuffer::init(int sizePerVertex, int vertexNumber, GLenum usage/* = GL_STATIC_DRAW*/)
{
if(0 == sizePerVertex || 0 == vertexNumber)
return false;
_sizePerVertex = sizePerVertex;
_vertexNumber = vertexNumber;
_usage = usage;
if(isShadowCopyEnabled())
{
@ -99,7 +100,7 @@ bool VertexBuffer::init(int sizePerVertex, int vertexNumber)
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, getSize(), nullptr, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, getSize(), nullptr, _usage);
glBindBuffer(GL_ARRAY_BUFFER, 0);
return true;
}
@ -158,7 +159,7 @@ void VertexBuffer::recreateVBO() const
buffer = &_shadowCopy[0];
}
CCLOG("recreate IndexBuffer with size %d %d", getSizePerVertex(), _vertexNumber);
glBufferData(GL_ARRAY_BUFFER, _sizePerVertex * _vertexNumber, buffer, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, _sizePerVertex * _vertexNumber, buffer, _usage);
glBindBuffer(GL_ARRAY_BUFFER, 0);
if(!glIsBuffer(_vbo))
{
@ -171,10 +172,10 @@ int VertexBuffer::getSize() const
return _sizePerVertex * _vertexNumber;
}
IndexBuffer* IndexBuffer::create(IndexType type, int number)
IndexBuffer* IndexBuffer::create(IndexType type, int number, GLenum usage/* = GL_STATIC_DRAW*/)
{
auto result = new (std::nothrow) IndexBuffer();
if(result && result->init(type, number))
if(result && result->init(type, number, usage))
{
result->autorelease();
return result;
@ -211,16 +212,17 @@ IndexBuffer::~IndexBuffer()
#endif
}
bool IndexBuffer::init(IndexBuffer::IndexType type, int number)
bool IndexBuffer::init(IndexBuffer::IndexType type, int number, GLenum usage/* = GL_STATIC_DRAW*/)
{
if(number <=0 ) return false;
_type = type;
_indexNumber = number;
_usage = usage;
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vbo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, getSize(), nullptr, GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, getSize(), nullptr, _usage);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
if(isShadowCopyEnabled())
@ -295,7 +297,7 @@ void IndexBuffer::recreateVBO() const
buffer = &_shadowCopy[0];
}
CCLOG("recreate IndexBuffer with size %d %d ", getSizePerIndex(), _indexNumber);
glBufferData(GL_ARRAY_BUFFER, getSize(), buffer, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, getSize(), buffer, _usage);
glBindBuffer(GL_ARRAY_BUFFER, 0);
if(!glIsBuffer(_vbo))
{

View File

@ -36,7 +36,7 @@ class EventListenerCustom;
class CC_DLL VertexBuffer : public Ref
{
public:
static VertexBuffer* create(int sizePerVertex, int vertexNumber);
static VertexBuffer* create(int sizePerVertex, int vertexNumber, GLenum usage = GL_STATIC_DRAW);
int getSizePerVertex() const;
int getVertexNumber() const;
@ -50,7 +50,7 @@ protected:
VertexBuffer();
virtual ~VertexBuffer();
bool init(int sizePerVertex, int vertexNumber);
bool init(int sizePerVertex, int vertexNumber, GLenum usage = GL_STATIC_DRAW);
protected:
//event listener for foreground
void recreateVBO() const;
@ -61,6 +61,7 @@ protected:
int _vertexNumber;
//buffer used for shadow copy
std::vector<unsigned char> _shadowCopy;
GLenum _usage;
protected:
static bool _enableShadowCopy;
public:
@ -78,7 +79,7 @@ public:
};
public:
static IndexBuffer* create(IndexType type, int number);
static IndexBuffer* create(IndexType type, int number, GLenum usage = GL_STATIC_DRAW);
IndexType getType() const;
int getSizePerIndex() const;
@ -93,7 +94,7 @@ protected:
IndexBuffer();
virtual ~IndexBuffer();
bool init(IndexType type, int number);
bool init(IndexType type, int number, GLenum usage = GL_STATIC_DRAW);
protected:
mutable GLuint _vbo;
@ -106,6 +107,7 @@ protected:
EventListenerCustom* _recreateVBOEventListener;
//buffer used for shadow copy
std::vector<unsigned char> _shadowCopy;
GLenum _usage;
protected:
static bool _enableShadowCopy;
public:

View File

@ -33,18 +33,6 @@
-- @function [parent=#ActionTimeline] pause
-- @param self
--------------------------------
-- @overload self, int, bool
-- @overload self, int
-- @overload self, int, int, bool
-- @overload self, int, int, int, bool
-- @function [parent=#ActionTimeline] gotoFrameAndPlay
-- @param self
-- @param #int startIndex
-- @param #int endIndex
-- @param #int currentFrameIndex
-- @param #bool loop
--------------------------------
--
-- @function [parent=#ActionTimeline] init
@ -57,6 +45,11 @@
-- @param self
-- @param #ccs.Timeline timeline
--------------------------------
--
-- @function [parent=#ActionTimeline] clearFrameEventCallFunc
-- @param self
--------------------------------
-- Last frame callback will call when arriving last frame
-- @function [parent=#ActionTimeline] setLastFrameCallFunc
@ -73,20 +66,39 @@
--
-- @function [parent=#ActionTimeline] play
-- @param self
-- @param #string name
-- @param #string animationName
-- @param #bool loop
--------------------------------
--
-- @function [parent=#ActionTimeline] getAnimationInfo
-- @param self
-- @param #string animationName
-- @return AnimationInfo#AnimationInfo ret (return value: ccs.AnimationInfo)
--------------------------------
-- Resume the animation.
-- @function [parent=#ActionTimeline] resume
-- @param self
--------------------------------
--
-- @function [parent=#ActionTimeline] removeAnimationInfo
-- @param self
-- @param #string animationName
--------------------------------
-- Get current animation speed.
-- @function [parent=#ActionTimeline] getTimeSpeed
-- @param self
-- @return float#float ret (return value: float)
--------------------------------
-- AnimationInfo
-- @function [parent=#ActionTimeline] addAnimationInfo
-- @param self
-- @param #ccs.AnimationInfo animationInfo
--------------------------------
--
-- @function [parent=#ActionTimeline] getDuration
@ -107,15 +119,23 @@
-- @return bool#bool ret (return value: bool)
--------------------------------
--
-- @function [parent=#ActionTimeline] removeIndexes
-- @overload self, int, bool
-- @overload self, int
-- @overload self, int, int, bool
-- @overload self, int, int, int, bool
-- @function [parent=#ActionTimeline] gotoFrameAndPlay
-- @param self
-- @param #string name
-- @param #int startIndex
-- @param #int endIndex
-- @param #int currentFrameIndex
-- @param #bool loop
--------------------------------
--
-- @function [parent=#ActionTimeline] clearFrameEventCallFunc
-- @function [parent=#ActionTimeline] IsAnimationInfoExists
-- @param self
-- @param #string animationName
-- @return bool#bool ret (return value: bool)
--------------------------------
-- End frame of this action.<br>
@ -125,12 +145,6 @@
-- @param self
-- @return int#int ret (return value: int)
--------------------------------
-- Set current frame index, this will cause action plays to this frame.
-- @function [parent=#ActionTimeline] setCurrentFrame
-- @param self
-- @param #int frameIndex
--------------------------------
-- Set the animation speed, this will speed up or slow down the speed.
-- @function [parent=#ActionTimeline] setTimeSpeed
@ -149,10 +163,10 @@
-- @param #int duration
--------------------------------
-- add ActionIndexes
-- @function [parent=#ActionTimeline] addIndexes
-- Set current frame index, this will cause action plays to this frame.
-- @function [parent=#ActionTimeline] setCurrentFrame
-- @param self
-- @param #ccs.ActionIndexes indexes
-- @param #int frameIndex
--------------------------------
--

View File

@ -0,0 +1,42 @@
--------------------------------
-- @module AlphaFrame
-- @extend Frame
-- @parent_module ccs
--------------------------------
--
-- @function [parent=#AlphaFrame] getAlpha
-- @param self
-- @return unsigned char#unsigned char ret (return value: unsigned char)
--------------------------------
--
-- @function [parent=#AlphaFrame] setAlpha
-- @param self
-- @param #unsigned char alpha
--------------------------------
--
-- @function [parent=#AlphaFrame] create
-- @param self
-- @return AlphaFrame#AlphaFrame ret (return value: ccs.AlphaFrame)
--------------------------------
--
-- @function [parent=#AlphaFrame] apply
-- @param self
-- @param #float percent
--------------------------------
--
-- @function [parent=#AlphaFrame] clone
-- @param self
-- @return Frame#Frame ret (return value: ccs.Frame)
--------------------------------
--
-- @function [parent=#AlphaFrame] AlphaFrame
-- @param self
return nil

View File

@ -17,10 +17,10 @@
-- @overload self, vec2_table, vec2_table, color4f_table
-- @function [parent=#DrawNode] drawRect
-- @param self
-- @param #vec2_table lb
-- @param #vec2_table lt
-- @param #vec2_table rt
-- @param #vec2_table rb
-- @param #vec2_table p1
-- @param #vec2_table p2
-- @param #vec2_table p3
-- @param #vec2_table p4
-- @param #color4f_table color
--------------------------------

View File

@ -4,18 +4,54 @@
-- @extend Frame
-- @parent_module ccs
--------------------------------
--
-- @function [parent=#InnerActionFrame] getEndFrameIndex
-- @param self
-- @return int#int ret (return value: int)
--------------------------------
--
-- @function [parent=#InnerActionFrame] getStartFrameIndex
-- @param self
-- @return int#int ret (return value: int)
--------------------------------
--
-- @function [parent=#InnerActionFrame] getInnerActionType
-- @param self
-- @return int#int ret (return value: int)
--------------------------------
--
-- @function [parent=#InnerActionFrame] setEndFrameIndex
-- @param self
-- @param #int frameIndex
--------------------------------
--
-- @function [parent=#InnerActionFrame] setEnterWithName
-- @param self
-- @param #bool isEnterWithName
--------------------------------
--
-- @function [parent=#InnerActionFrame] setSingleFrameIndex
-- @param self
-- @param #int frameIndex
--------------------------------
--
-- @function [parent=#InnerActionFrame] setStartFrameIndex
-- @param self
-- @param #int frameIndex
--------------------------------
--
-- @function [parent=#InnerActionFrame] getSingleFrameIndex
-- @param self
-- @return int#int ret (return value: int)
--------------------------------
--
-- @function [parent=#InnerActionFrame] setInnerActionType
@ -24,9 +60,9 @@
--------------------------------
--
-- @function [parent=#InnerActionFrame] getStartFrameIndex
-- @function [parent=#InnerActionFrame] setAnimationName
-- @param self
-- @return int#int ret (return value: int)
-- @param #string animationNamed
--------------------------------
--

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

@ -74,10 +74,4 @@
-- @param self
-- @return int#int ret (return value: int)
--------------------------------
-- Distory the joint
-- @function [parent=#PhysicsJoint] destroy
-- @param self
-- @param #cc.PhysicsJoint joint
return nil

View File

@ -4,6 +4,12 @@
-- @extend PhysicsJoint
-- @parent_module cc
--------------------------------
--
-- @function [parent=#PhysicsJointDistance] createConstraints
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
--
-- @function [parent=#PhysicsJointDistance] setDistance

View File

@ -4,6 +4,12 @@
-- @extend PhysicsJoint
-- @parent_module cc
--------------------------------
--
-- @function [parent=#PhysicsJointFixed] createConstraints
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
--
-- @function [parent=#PhysicsJointFixed] construct

View File

@ -22,6 +22,12 @@
-- @param self
-- @param #float phase
--------------------------------
--
-- @function [parent=#PhysicsJointGear] createConstraints
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
--
-- @function [parent=#PhysicsJointGear] getRatio

View File

@ -40,6 +40,12 @@
-- @param self
-- @return vec2_table#vec2_table ret (return value: vec2_table)
--------------------------------
--
-- @function [parent=#PhysicsJointGroove] createConstraints
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
--
-- @function [parent=#PhysicsJointGroove] construct

View File

@ -34,6 +34,12 @@
-- @param self
-- @return vec2_table#vec2_table ret (return value: vec2_table)
--------------------------------
--
-- @function [parent=#PhysicsJointLimit] createConstraints
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
--
-- @function [parent=#PhysicsJointLimit] getMin

View File

@ -16,6 +16,12 @@
-- @param self
-- @return float#float ret (return value: float)
--------------------------------
--
-- @function [parent=#PhysicsJointMotor] createConstraints
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
--
-- @function [parent=#PhysicsJointMotor] construct

Some files were not shown because too many files have changed in this diff Show More