diff --git a/build/cocos2d_libs.xcodeproj/project.pbxproj b/build/cocos2d_libs.xcodeproj/project.pbxproj index 657bc74d48..8e7cb8bf6f 100644 --- a/build/cocos2d_libs.xcodeproj/project.pbxproj +++ b/build/cocos2d_libs.xcodeproj/project.pbxproj @@ -818,6 +818,42 @@ 15EFA212198A2BB5000C57D3 /* CCProtectedNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15EFA20F198A2BB5000C57D3 /* CCProtectedNode.cpp */; }; 15EFA213198A2BB5000C57D3 /* CCProtectedNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 15EFA210198A2BB5000C57D3 /* CCProtectedNode.h */; }; 15EFA214198A2BB5000C57D3 /* CCProtectedNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 15EFA210198A2BB5000C57D3 /* CCProtectedNode.h */; }; + 15FB206A1AE7BE7400C31518 /* PolySprite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20661AE7BE7400C31518 /* PolySprite.cpp */; }; + 15FB206B1AE7BE7400C31518 /* PolySprite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20661AE7BE7400C31518 /* PolySprite.cpp */; }; + 15FB206C1AE7BE7400C31518 /* PolySprite.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20671AE7BE7400C31518 /* PolySprite.h */; }; + 15FB206D1AE7BE7400C31518 /* PolySprite.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20671AE7BE7400C31518 /* PolySprite.h */; }; + 15FB206E1AE7BE7400C31518 /* PolySpriteCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20681AE7BE7400C31518 /* PolySpriteCache.cpp */; }; + 15FB206F1AE7BE7400C31518 /* PolySpriteCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20681AE7BE7400C31518 /* PolySpriteCache.cpp */; }; + 15FB20701AE7BE7400C31518 /* PolySpriteCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20691AE7BE7400C31518 /* PolySpriteCache.h */; }; + 15FB20711AE7BE7400C31518 /* PolySpriteCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20691AE7BE7400C31518 /* PolySpriteCache.h */; }; + 15FB20741AE7BF8600C31518 /* MarchingSquare.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20721AE7BF8600C31518 /* MarchingSquare.cpp */; }; + 15FB20751AE7BF8600C31518 /* MarchingSquare.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20721AE7BF8600C31518 /* MarchingSquare.cpp */; }; + 15FB20761AE7BF8600C31518 /* MarchingSquare.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20731AE7BF8600C31518 /* MarchingSquare.h */; }; + 15FB20771AE7BF8600C31518 /* MarchingSquare.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20731AE7BF8600C31518 /* MarchingSquare.h */; }; + 15FB20871AE7C57D00C31518 /* shapes.cc in Sources */ = {isa = PBXBuildFile; fileRef = 15FB207A1AE7C57D00C31518 /* shapes.cc */; }; + 15FB20881AE7C57D00C31518 /* shapes.cc in Sources */ = {isa = PBXBuildFile; fileRef = 15FB207A1AE7C57D00C31518 /* shapes.cc */; }; + 15FB20891AE7C57D00C31518 /* shapes.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB207B1AE7C57D00C31518 /* shapes.h */; }; + 15FB208A1AE7C57D00C31518 /* shapes.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB207B1AE7C57D00C31518 /* shapes.h */; }; + 15FB208B1AE7C57D00C31518 /* utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB207C1AE7C57D00C31518 /* utils.h */; }; + 15FB208C1AE7C57D00C31518 /* utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB207C1AE7C57D00C31518 /* utils.h */; }; + 15FB208D1AE7C57D00C31518 /* poly2tri.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB207D1AE7C57D00C31518 /* poly2tri.h */; }; + 15FB208E1AE7C57D00C31518 /* poly2tri.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB207D1AE7C57D00C31518 /* poly2tri.h */; }; + 15FB208F1AE7C57D00C31518 /* advancing_front.cc in Sources */ = {isa = PBXBuildFile; fileRef = 15FB207F1AE7C57D00C31518 /* advancing_front.cc */; }; + 15FB20901AE7C57D00C31518 /* advancing_front.cc in Sources */ = {isa = PBXBuildFile; fileRef = 15FB207F1AE7C57D00C31518 /* advancing_front.cc */; }; + 15FB20911AE7C57D00C31518 /* advancing_front.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20801AE7C57D00C31518 /* advancing_front.h */; }; + 15FB20921AE7C57D00C31518 /* advancing_front.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20801AE7C57D00C31518 /* advancing_front.h */; }; + 15FB20931AE7C57D00C31518 /* cdt.cc in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20811AE7C57D00C31518 /* cdt.cc */; }; + 15FB20941AE7C57D00C31518 /* cdt.cc in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20811AE7C57D00C31518 /* cdt.cc */; }; + 15FB20951AE7C57D00C31518 /* cdt.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20821AE7C57D00C31518 /* cdt.h */; }; + 15FB20961AE7C57D00C31518 /* cdt.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20821AE7C57D00C31518 /* cdt.h */; }; + 15FB20971AE7C57D00C31518 /* sweep.cc in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20831AE7C57D00C31518 /* sweep.cc */; }; + 15FB20981AE7C57D00C31518 /* sweep.cc in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20831AE7C57D00C31518 /* sweep.cc */; }; + 15FB20991AE7C57D00C31518 /* sweep.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20841AE7C57D00C31518 /* sweep.h */; }; + 15FB209A1AE7C57D00C31518 /* sweep.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20841AE7C57D00C31518 /* sweep.h */; }; + 15FB209B1AE7C57D00C31518 /* sweep_context.cc in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20851AE7C57D00C31518 /* sweep_context.cc */; }; + 15FB209C1AE7C57D00C31518 /* sweep_context.cc in Sources */ = {isa = PBXBuildFile; fileRef = 15FB20851AE7C57D00C31518 /* sweep_context.cc */; }; + 15FB209D1AE7C57D00C31518 /* sweep_context.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20861AE7C57D00C31518 /* sweep_context.h */; }; + 15FB209E1AE7C57D00C31518 /* sweep_context.h in Headers */ = {isa = PBXBuildFile; fileRef = 15FB20861AE7C57D00C31518 /* sweep_context.h */; }; 182C5CAE1A95961600C30D34 /* CSParse3DBinary_generated.h in Headers */ = {isa = PBXBuildFile; fileRef = 182C5CAD1A95961600C30D34 /* CSParse3DBinary_generated.h */; }; 182C5CB21A95964700C30D34 /* Node3DReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 182C5CB01A95964700C30D34 /* Node3DReader.cpp */; }; 182C5CB31A95964700C30D34 /* Node3DReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 182C5CB11A95964700C30D34 /* Node3DReader.h */; }; @@ -2673,6 +2709,24 @@ 15B3707719EE414C00ABE682 /* Manifest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Manifest.h; sourceTree = ""; }; 15EFA20F198A2BB5000C57D3 /* CCProtectedNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCProtectedNode.cpp; sourceTree = ""; }; 15EFA210198A2BB5000C57D3 /* CCProtectedNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCProtectedNode.h; sourceTree = ""; }; + 15FB20661AE7BE7400C31518 /* PolySprite.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolySprite.cpp; sourceTree = ""; }; + 15FB20671AE7BE7400C31518 /* PolySprite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolySprite.h; sourceTree = ""; }; + 15FB20681AE7BE7400C31518 /* PolySpriteCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolySpriteCache.cpp; sourceTree = ""; }; + 15FB20691AE7BE7400C31518 /* PolySpriteCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolySpriteCache.h; sourceTree = ""; }; + 15FB20721AE7BF8600C31518 /* MarchingSquare.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MarchingSquare.cpp; sourceTree = ""; }; + 15FB20731AE7BF8600C31518 /* MarchingSquare.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarchingSquare.h; sourceTree = ""; }; + 15FB207A1AE7C57D00C31518 /* shapes.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = shapes.cc; sourceTree = ""; }; + 15FB207B1AE7C57D00C31518 /* shapes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shapes.h; sourceTree = ""; }; + 15FB207C1AE7C57D00C31518 /* utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = utils.h; sourceTree = ""; }; + 15FB207D1AE7C57D00C31518 /* poly2tri.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = poly2tri.h; sourceTree = ""; }; + 15FB207F1AE7C57D00C31518 /* advancing_front.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = advancing_front.cc; sourceTree = ""; }; + 15FB20801AE7C57D00C31518 /* advancing_front.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = advancing_front.h; sourceTree = ""; }; + 15FB20811AE7C57D00C31518 /* cdt.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cdt.cc; sourceTree = ""; }; + 15FB20821AE7C57D00C31518 /* cdt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cdt.h; sourceTree = ""; }; + 15FB20831AE7C57D00C31518 /* sweep.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sweep.cc; sourceTree = ""; }; + 15FB20841AE7C57D00C31518 /* sweep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sweep.h; sourceTree = ""; }; + 15FB20851AE7C57D00C31518 /* sweep_context.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sweep_context.cc; sourceTree = ""; }; + 15FB20861AE7C57D00C31518 /* sweep_context.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sweep_context.h; sourceTree = ""; }; 182C5CAD1A95961600C30D34 /* CSParse3DBinary_generated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSParse3DBinary_generated.h; sourceTree = ""; }; 182C5CB01A95964700C30D34 /* Node3DReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Node3DReader.cpp; path = Node3DReader/Node3DReader.cpp; sourceTree = ""; }; 182C5CB11A95964700C30D34 /* Node3DReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Node3DReader.h; path = Node3DReader/Node3DReader.h; sourceTree = ""; }; @@ -4131,6 +4185,42 @@ name = Frameworks; sourceTree = ""; }; + 15FB20781AE7C57D00C31518 /* poly2tri */ = { + isa = PBXGroup; + children = ( + 15FB20791AE7C57D00C31518 /* common */, + 15FB207D1AE7C57D00C31518 /* poly2tri.h */, + 15FB207E1AE7C57D00C31518 /* sweep */, + ); + name = poly2tri; + path = ../external/poly2tri; + sourceTree = ""; + }; + 15FB20791AE7C57D00C31518 /* common */ = { + isa = PBXGroup; + children = ( + 15FB207A1AE7C57D00C31518 /* shapes.cc */, + 15FB207B1AE7C57D00C31518 /* shapes.h */, + 15FB207C1AE7C57D00C31518 /* utils.h */, + ); + path = common; + sourceTree = ""; + }; + 15FB207E1AE7C57D00C31518 /* sweep */ = { + isa = PBXGroup; + children = ( + 15FB207F1AE7C57D00C31518 /* advancing_front.cc */, + 15FB20801AE7C57D00C31518 /* advancing_front.h */, + 15FB20811AE7C57D00C31518 /* cdt.cc */, + 15FB20821AE7C57D00C31518 /* cdt.h */, + 15FB20831AE7C57D00C31518 /* sweep.cc */, + 15FB20841AE7C57D00C31518 /* sweep.h */, + 15FB20851AE7C57D00C31518 /* sweep_context.cc */, + 15FB20861AE7C57D00C31518 /* sweep_context.h */, + ); + path = sweep; + sourceTree = ""; + }; 182C5CAF1A95961E00C30D34 /* Node3DReader */ = { isa = PBXGroup; children = ( @@ -4485,6 +4575,12 @@ 1A570275180BCC840088DEC7 /* sprite-nodes */ = { isa = PBXGroup; children = ( + 15FB20721AE7BF8600C31518 /* MarchingSquare.cpp */, + 15FB20731AE7BF8600C31518 /* MarchingSquare.h */, + 15FB20661AE7BE7400C31518 /* PolySprite.cpp */, + 15FB20671AE7BE7400C31518 /* PolySprite.h */, + 15FB20681AE7BE7400C31518 /* PolySpriteCache.cpp */, + 15FB20691AE7BE7400C31518 /* PolySpriteCache.h */, 1A57028E180BCCAB0088DEC7 /* CCAnimation.cpp */, 1A57028F180BCCAB0088DEC7 /* CCAnimation.h */, 1A570290180BCCAB0088DEC7 /* CCAnimationCache.cpp */, @@ -4547,6 +4643,7 @@ 1A57033E180BD0490088DEC7 /* external */ = { isa = PBXGroup; children = ( + 15FB20781AE7C57D00C31518 /* poly2tri */, 382383E11A258FA7002C4610 /* flatbuffers */, 1AC026971914068200FA920D /* ConvertUTF */, 46C02E0418E91123004B7456 /* xxhash */, @@ -6629,6 +6726,7 @@ 3E2F27A719CFBFE400E7C490 /* AudioEngine.h in Headers */, 15AE183A19AAD2F700C27E9E /* CCRay.h in Headers */, 15AE18A319AAD33D00C27E9E /* CCParticleSystemQuadLoader.h in Headers */, + 15FB20761AE7BF8600C31518 /* MarchingSquare.h in Headers */, B665E2C41AA80A6500DDB1C5 /* CCPUGeometryRotatorTranslator.h in Headers */, 46A170F01807CECA005B8026 /* CCPhysicsWorld.h in Headers */, 15AE199D19AAD39600C27E9E /* ScrollViewReader.h in Headers */, @@ -6689,6 +6787,7 @@ 15AE18ED19AAD35000C27E9E /* CCActionObject.h in Headers */, ED9C6A9618599AD8000A5232 /* CCNodeGrid.h in Headers */, 15AE18A719AAD33D00C27E9E /* CCScrollViewLoader.h in Headers */, + 15FB20891AE7C57D00C31518 /* shapes.h in Headers */, 15AE184819AAD2F700C27E9E /* cocos3d.h in Headers */, 50ABBEC31925AB6F00A911A9 /* CCVector.h in Headers */, 1A57008B180BC5A10088DEC7 /* CCActionProgressTimer.h in Headers */, @@ -6762,6 +6861,7 @@ B68779021A8CA82E00643ABF /* CCParticle3DRender.h in Headers */, 15AE1B6C19AADA9900C27E9E /* UIWidget.h in Headers */, B665E2681AA80A6500DDB1C5 /* CCPUDoExpireEventHandlerTranslator.h in Headers */, + 15FB208B1AE7C57D00C31518 /* utils.h in Headers */, 15AE180E19AAD2F700C27E9E /* CCAnimate3D.h in Headers */, 1A5701B3180BCB590088DEC7 /* CCFontFNT.h in Headers */, 38F526421A48363B000DB7F7 /* CSArmatureNode_generated.h in Headers */, @@ -6802,6 +6902,7 @@ 15AE1A3319AAD3D500C27E9E /* b2CircleShape.h in Headers */, 1A5701E0180BCB8C0088DEC7 /* CCLayer.h in Headers */, 1A5701E4180BCB8C0088DEC7 /* CCScene.h in Headers */, + 15FB20701AE7BE7400C31518 /* PolySpriteCache.h in Headers */, B665E3D81AA80A6600DDB1C5 /* CCPUScriptParser.h in Headers */, 382384091A25900F002C4610 /* FlatBuffersSerialize.h in Headers */, 15AE1BDD19AAE01E00C27E9E /* CCControlUtils.h in Headers */, @@ -6894,6 +6995,7 @@ 1A57022F180BCC1A0088DEC7 /* CCParticleSystemQuad.h in Headers */, B665E37C1AA80A6500DDB1C5 /* CCPUParticleSystem3D.h in Headers */, 15AE188519AAD33D00C27E9E /* CCBSequence.h in Headers */, + 15FB20951AE7C57D00C31518 /* cdt.h in Headers */, B665E3541AA80A6500DDB1C5 /* CCPUOnQuotaObserver.h in Headers */, 50643BE219BFCF1800EF68ED /* CCPlatformConfig.h in Headers */, B29A7DF519EE1B7700872B35 /* Skeleton.h in Headers */, @@ -6986,6 +7088,7 @@ B29A7E3919EE1B7700872B35 /* Animation.h in Headers */, B665E2B01AA80A6500DDB1C5 /* CCPUFlockCenteringAffectorTranslator.h in Headers */, 382384381A259126002C4610 /* ProjectNodeReader.h in Headers */, + 15FB20991AE7C57D00C31518 /* sweep.h in Headers */, B665E3C41AA80A6600DDB1C5 /* CCPUScaleAffectorTranslator.h in Headers */, 15AE191019AAD35000C27E9E /* CCInputDelegate.h in Headers */, B665E4301AA80A6600DDB1C5 /* CCPUVelocityMatchingAffectorTranslator.h in Headers */, @@ -7002,6 +7105,7 @@ 382383EE1A258FA7002C4610 /* flatbuffers.h in Headers */, 15AE1B5619AADA9900C27E9E /* UIScrollView.h in Headers */, 50ABBDBB1925AB4100A911A9 /* CCTextureAtlas.h in Headers */, + 15FB20911AE7C57D00C31518 /* advancing_front.h in Headers */, 1A570302180BCE890088DEC7 /* CCParallaxNode.h in Headers */, 50ABBE4B1925AB6F00A911A9 /* CCEventAcceleration.h in Headers */, 1A57030E180BCF190088DEC7 /* CCComponent.h in Headers */, @@ -7042,6 +7146,7 @@ 15AE183219AAD2F700C27E9E /* CCOBB.h in Headers */, 15AE1BE319AAE01E00C27E9E /* CCScrollView.h in Headers */, B665E2941AA80A6500DDB1C5 /* CCPUEmitter.h in Headers */, + 15FB209D1AE7C57D00C31518 /* sweep_context.h in Headers */, 50CB247519D9C5A100687767 /* AudioCache.h in Headers */, 3823841C1A2590D2002C4610 /* ComAudioReader.h in Headers */, 50ABC01F1926664800A911A9 /* CCThread.h in Headers */, @@ -7049,6 +7154,7 @@ 1A57035A180BD0B00088DEC7 /* unzip.h in Headers */, 15AE188B19AAD33D00C27E9E /* CCControlLoader.h in Headers */, B29A7DF719EE1B7700872B35 /* Attachment.h in Headers */, + 15FB208D1AE7C57D00C31518 /* poly2tri.h in Headers */, 15AE1BCA19AAE01E00C27E9E /* CCControl.h in Headers */, 50ABBDBF1925AB4100A911A9 /* CCTextureCache.h in Headers */, B29A7E0D19EE1B7700872B35 /* Bone.h in Headers */, @@ -7147,6 +7253,7 @@ 50ABBE5B1925AB6F00A911A9 /* CCEventKeyboard.h in Headers */, B665E1F41AA80A6500DDB1C5 /* CCPUAffector.h in Headers */, 1A01C69E18F57BE800EFE3A6 /* CCString.h in Headers */, + 15FB206C1AE7BE7400C31518 /* PolySprite.h in Headers */, 50ABC00F1926664800A911A9 /* CCFileUtils.h in Headers */, B665E2981AA80A6500DDB1C5 /* CCPUEmitterManager.h in Headers */, 15AE1A3719AAD3D500C27E9E /* b2PolygonShape.h in Headers */, @@ -7260,6 +7367,7 @@ 5034CA38191D591100CE6051 /* ccShader_PositionColorLengthTexture.vert in Headers */, 15AE1B8119AADA9A00C27E9E /* UITextAtlas.h in Headers */, B29A7E3A19EE1B7700872B35 /* Animation.h in Headers */, + 15FB208C1AE7C57D00C31518 /* utils.h in Headers */, B665E2B51AA80A6500DDB1C5 /* CCPUForceField.h in Headers */, B665E2D91AA80A6500DDB1C5 /* CCPUJetAffector.h in Headers */, 15B3708319EE414C00ABE682 /* CCEventListenerAssetsManagerEx.h in Headers */, @@ -7271,6 +7379,7 @@ 46A171011807CECB005B8026 /* CCPhysicsJoint.h in Headers */, B665E3D91AA80A6600DDB1C5 /* CCPUScriptParser.h in Headers */, B665E43D1AA80A6600DDB1C5 /* CCPUVortexAffectorTranslator.h in Headers */, + 15FB208E1AE7C57D00C31518 /* poly2tri.h in Headers */, B29A7E3219EE1B7700872B35 /* SkinnedMeshAttachment.h in Headers */, 46A170FD1807CECB005B8026 /* CCPhysicsBody.h in Headers */, 50ABBE9C1925AB6F00A911A9 /* CCRef.h in Headers */, @@ -7343,6 +7452,7 @@ B665E4351AA80A6600DDB1C5 /* CCPUVertexEmitter.h in Headers */, B665E2451AA80A6500DDB1C5 /* CCPUCollisionAvoidanceAffector.h in Headers */, 50ABBEC41925AB6F00A911A9 /* CCVector.h in Headers */, + 15FB20711AE7BE7400C31518 /* PolySpriteCache.h in Headers */, 50ABBE501925AB6F00A911A9 /* CCEventCustom.h in Headers */, 15AE1AD719AAD40300C27E9E /* b2WheelJoint.h in Headers */, B665E3311AA80A6500DDB1C5 /* CCPUOnCountObserverTranslator.h in Headers */, @@ -7409,6 +7519,7 @@ 15AE1B7719AADA9A00C27E9E /* UIPageView.h in Headers */, 50ABBD8A1925AB4100A911A9 /* CCCustomCommand.h in Headers */, 299754F7193EC95400A54AC3 /* ObjectFactory.h in Headers */, + 15FB20921AE7C57D00C31518 /* advancing_front.h in Headers */, 50ABBE881925AB6F00A911A9 /* ccMacros.h in Headers */, B665E3991AA80A6500DDB1C5 /* CCPUPointEmitter.h in Headers */, B29A7E4019EE1B7700872B35 /* AnimationState.h in Headers */, @@ -7568,6 +7679,7 @@ B665E3A51AA80A6500DDB1C5 /* CCPUPositionEmitterTranslator.h in Headers */, B68779071A8CA82E00643ABF /* CCParticleSystem3D.h in Headers */, B665E2651AA80A6500DDB1C5 /* CCPUDoExpireEventHandler.h in Headers */, + 15FB208A1AE7C57D00C31518 /* shapes.h in Headers */, 50ABBEA21925AB6F00A911A9 /* CCScheduler.h in Headers */, 1A57020B180BCBDF0088DEC7 /* CCMotionStreak.h in Headers */, B665E2211AA80A6500DDB1C5 /* CCPUBehaviourManager.h in Headers */, @@ -7579,6 +7691,7 @@ 15AE1AA819AAD40300C27E9E /* b2Island.h in Headers */, B665E2391AA80A6500DDB1C5 /* CCPUBoxEmitterTranslator.h in Headers */, 15B3708B19EE414C00ABE682 /* Manifest.h in Headers */, + 15FB209A1AE7C57D00C31518 /* sweep.h in Headers */, 1A570213180BCBF40088DEC7 /* CCProgressTimer.h in Headers */, 38F526431A48363B000DB7F7 /* CSArmatureNode_generated.h in Headers */, 1A570217180BCBF40088DEC7 /* CCRenderTexture.h in Headers */, @@ -7588,6 +7701,7 @@ B665E3ED1AA80A6600DDB1C5 /* CCPUSlaveBehaviour.h in Headers */, 15AE198619AAD36400C27E9E /* WidgetReader.h in Headers */, 1A570224180BCC1A0088DEC7 /* CCParticleBatchNode.h in Headers */, + 15FB20961AE7C57D00C31518 /* cdt.h in Headers */, 15AE1AC919AAD40300C27E9E /* b2Joint.h in Headers */, 382383EF1A258FA7002C4610 /* flatbuffers.h in Headers */, B6D38B911AC3AFAC00043997 /* CCTextureCube.h in Headers */, @@ -7662,8 +7776,10 @@ 1A5702ED180BCE750088DEC7 /* CCTileMapAtlas.h in Headers */, 15AE195E19AAD35100C27E9E /* CCSkin.h in Headers */, 1A5702F1180BCE750088DEC7 /* CCTMXLayer.h in Headers */, + 15FB20771AE7BF8600C31518 /* MarchingSquare.h in Headers */, 15AE18AE19AAD33D00C27E9E /* CCBFileLoader.h in Headers */, 15AE197819AAD35700C27E9E /* CCActionTimeline.h in Headers */, + 15FB206D1AE7BE7400C31518 /* PolySprite.h in Headers */, 15AE1AA019AAD40300C27E9E /* b2Timer.h in Headers */, 5034CA44191D591100CE6051 /* ccShader_Label.vert in Headers */, 1A5702F5180BCE750088DEC7 /* CCTMXObjectGroup.h in Headers */, @@ -7893,6 +8009,7 @@ 15AE18BE19AAD33D00C27E9E /* CCLabelBMFontLoader.h in Headers */, 50ABC00A1926664800A911A9 /* CCCommon.h in Headers */, 15AE19AD19AAD39700C27E9E /* LoadingBarReader.h in Headers */, + 15FB209E1AE7C57D00C31518 /* sweep_context.h in Headers */, 50ABBE5C1925AB6F00A911A9 /* CCEventKeyboard.h in Headers */, B665E2191AA80A6500DDB1C5 /* CCPUBeamRender.h in Headers */, 5E9F612D1A3FFE3D0038DE01 /* CCPlane.h in Headers */, @@ -8052,6 +8169,7 @@ B665E4261AA80A6600DDB1C5 /* CCPUUtil.cpp in Sources */, 15AE1B6319AADA9900C27E9E /* UICheckBox.cpp in Sources */, 15EFA211198A2BB5000C57D3 /* CCProtectedNode.cpp in Sources */, + 15FB208F1AE7C57D00C31518 /* advancing_front.cc in Sources */, 50ABBEB71925AB6F00A911A9 /* ccUTF8.cpp in Sources */, B665E2621AA80A6500DDB1C5 /* CCPUDoExpireEventHandler.cpp in Sources */, B665E4161AA80A6600DDB1C5 /* CCPUTextureAnimatorTranslator.cpp in Sources */, @@ -8254,6 +8372,7 @@ B665E2A21AA80A6500DDB1C5 /* CCPUEventHandlerManager.cpp in Sources */, B665E3EE1AA80A6600DDB1C5 /* CCPUSlaveBehaviourTranslator.cpp in Sources */, 1A5701EE180BCB8C0088DEC7 /* CCTransitionProgress.cpp in Sources */, + 15FB20931AE7C57D00C31518 /* cdt.cc in Sources */, B29A7DE119EE1B7700872B35 /* MeshAttachment.c in Sources */, 15AE18F419AAD35000C27E9E /* CCArmatureDefine.cpp in Sources */, 15AE186619AAD31D00C27E9E /* CDOpenALSupport.m in Sources */, @@ -8267,6 +8386,7 @@ 1A5701FB180BCBAD0088DEC7 /* CCMenuItem.cpp in Sources */, 1A570202180BCBD40088DEC7 /* CCClippingNode.cpp in Sources */, 1A570208180BCBDF0088DEC7 /* CCMotionStreak.cpp in Sources */, + 15FB20971AE7C57D00C31518 /* sweep.cc in Sources */, 1A570210180BCBF40088DEC7 /* CCProgressTimer.cpp in Sources */, 292DB15F19B461CA00A80320 /* ExtensionDeprecated.cpp in Sources */, 292DB14D19B4574100A80320 /* UIEditBoxImpl-mac.mm in Sources */, @@ -8301,6 +8421,7 @@ 15AE199619AAD39600C27E9E /* ListViewReader.cpp in Sources */, 50ABC0191926664800A911A9 /* CCSAXParser.cpp in Sources */, 15AE189219AAD33D00C27E9E /* CCLayerGradientLoader.cpp in Sources */, + 15FB206E1AE7BE7400C31518 /* PolySpriteCache.cpp in Sources */, 15AE1B6A19AADA9900C27E9E /* UIDeprecated.cpp in Sources */, 15AE183C19AAD2F700C27E9E /* CCSkeleton3D.cpp in Sources */, 15AE1A2319AAD3D500C27E9E /* b2BroadPhase.cpp in Sources */, @@ -8385,6 +8506,7 @@ 15AE199A19AAD39600C27E9E /* PageViewReader.cpp in Sources */, 1A57030C180BCF190088DEC7 /* CCComponent.cpp in Sources */, 382383F61A258FA7002C4610 /* idl_gen_fbs.cpp in Sources */, + 15FB20741AE7BF8600C31518 /* MarchingSquare.cpp in Sources */, B665E2A61AA80A6500DDB1C5 /* CCPUEventHandlerTranslator.cpp in Sources */, 15AE1A5919AAD40300C27E9E /* b2StackAllocator.cpp in Sources */, B29A7E3D19EE1B7700872B35 /* AnimationState.c in Sources */, @@ -8397,6 +8519,7 @@ 1A01C69C18F57BE800EFE3A6 /* CCString.cpp in Sources */, B665E2721AA80A6500DDB1C5 /* CCPUDoPlacementParticleEventHandler.cpp in Sources */, 50ABBD3C1925AB0000A911A9 /* CCGeometry.cpp in Sources */, + 15FB206A1AE7BE7400C31518 /* PolySprite.cpp in Sources */, B29A7DDD19EE1B7700872B35 /* BoneData.c in Sources */, 15AE188A19AAD33D00C27E9E /* CCControlLoader.cpp in Sources */, B665E35A1AA80A6500DDB1C5 /* CCPUOnRandomObserver.cpp in Sources */, @@ -8440,6 +8563,7 @@ 15AE18F819AAD35000C27E9E /* CCBone.cpp in Sources */, B665E2121AA80A6500DDB1C5 /* CCPUBaseForceAffectorTranslator.cpp in Sources */, 38ACD1FC1A27111900C3093D /* WidgetCallBackHandlerProtocol.cpp in Sources */, + 15FB209B1AE7C57D00C31518 /* sweep_context.cc in Sources */, 15AE1A7619AAD40300C27E9E /* b2EdgeAndPolygonContact.cpp in Sources */, 50ABBD8B1925AB4100A911A9 /* CCGLProgram.cpp in Sources */, 464AD6E5197EBB1400E502D8 /* pvr.cpp in Sources */, @@ -8487,6 +8611,7 @@ 15AE19A019AAD39600C27E9E /* TextAtlasReader.cpp in Sources */, 15AE1A2A19AAD3D500C27E9E /* b2Distance.cpp in Sources */, 50ABBE6D1925AB6F00A911A9 /* CCEventListenerKeyboard.cpp in Sources */, + 15FB20871AE7C57D00C31518 /* shapes.cc in Sources */, B665E27A1AA80A6500DDB1C5 /* CCPUDoScaleEventHandler.cpp in Sources */, 15AE190B19AAD35000C27E9E /* CCDisplayFactory.cpp in Sources */, B29A7DE319EE1B7700872B35 /* SkeletonBounds.c in Sources */, @@ -8613,6 +8738,7 @@ 15AE192C19AAD35100C27E9E /* CCActionFrame.cpp in Sources */, 1A01C69918F57BE800EFE3A6 /* CCSet.cpp in Sources */, 1A01C69D18F57BE800EFE3A6 /* CCString.cpp in Sources */, + 15FB20981AE7C57D00C31518 /* sweep.cc in Sources */, 15AE199219AAD37300C27E9E /* ImageViewReader.cpp in Sources */, B665E1F71AA80A6500DDB1C5 /* CCPUAffectorManager.cpp in Sources */, 2986667F18B1B246000E39CA /* CCTweenFunction.cpp in Sources */, @@ -8727,6 +8853,7 @@ 50CB247C19D9C5A100687767 /* AudioEngine-inl.mm in Sources */, 15AE1AC819AAD40300C27E9E /* b2Joint.cpp in Sources */, 50ABBE461925AB6F00A911A9 /* CCEvent.cpp in Sources */, + 15FB20881AE7C57D00C31518 /* shapes.cc in Sources */, 50ABBEA01925AB6F00A911A9 /* CCScheduler.cpp in Sources */, 15AE1A4119AAD3D500C27E9E /* b2Distance.cpp in Sources */, 50ABBE4E1925AB6F00A911A9 /* CCEventCustom.cpp in Sources */, @@ -8854,6 +8981,7 @@ 15AE18AB19AAD33D00C27E9E /* CCBAnimationManager.cpp in Sources */, 15AE1B7219AADA9A00C27E9E /* UIListView.cpp in Sources */, 1A5701BE180BCB5A0088DEC7 /* CCLabelAtlas.cpp in Sources */, + 15FB20751AE7BF8600C31518 /* MarchingSquare.cpp in Sources */, 15AE1A3D19AAD3D500C27E9E /* b2CollideEdge.cpp in Sources */, 1A5701C2180BCB5A0088DEC7 /* CCLabelBMFont.cpp in Sources */, 1A087AE91860400400196EF5 /* edtaa3func.cpp in Sources */, @@ -8877,6 +9005,7 @@ 382384291A2590F9002C4610 /* NodeReader.cpp in Sources */, 15AE193419AAD35100C27E9E /* CCActionObject.cpp in Sources */, B665E4171AA80A6600DDB1C5 /* CCPUTextureAnimatorTranslator.cpp in Sources */, + 15FB20941AE7C57D00C31518 /* cdt.cc in Sources */, B665E34B1AA80A6500DDB1C5 /* CCPUOnPositionObserver.cpp in Sources */, 15AE1AD619AAD40300C27E9E /* b2WheelJoint.cpp in Sources */, 299754F5193EC95400A54AC3 /* ObjectFactory.cpp in Sources */, @@ -8984,10 +9113,12 @@ 15AE193E19AAD35100C27E9E /* CCBatchNode.cpp in Sources */, 15AE185919AAD31200C27E9E /* CDAudioManager.m in Sources */, 1A57028B180BCC900088DEC7 /* CCSpriteFrameCache.cpp in Sources */, + 15FB209C1AE7C57D00C31518 /* sweep_context.cc in Sources */, B665E3E31AA80A6600DDB1C5 /* CCPUSineForceAffector.cpp in Sources */, 1A570293180BCCAB0088DEC7 /* CCAnimation.cpp in Sources */, 15AE1AAE19AAD40300C27E9E /* b2ChainAndCircleContact.cpp in Sources */, 15AE194D19AAD35100C27E9E /* CCDataReaderHelper.cpp in Sources */, + 15FB20901AE7C57D00C31518 /* advancing_front.cc in Sources */, 15AE1B8C19AADA9A00C27E9E /* UIScale9Sprite.cpp in Sources */, 15AE19AE19AAD39700C27E9E /* PageViewReader.cpp in Sources */, B68778FD1A8CA82E00643ABF /* CCParticle3DEmitter.cpp in Sources */, @@ -9081,6 +9212,7 @@ 5027253D190BF1B900AAF4ED /* cocos2d.cpp in Sources */, B29A7E0819EE1B7700872B35 /* SkinnedMeshAttachment.c in Sources */, 15AE183919AAD2F700C27E9E /* CCRay.cpp in Sources */, + 15FB206B1AE7BE7400C31518 /* PolySprite.cpp in Sources */, 15AE1B8219AADA9A00C27E9E /* UITextBMFont.cpp in Sources */, 50ABBE6A1925AB6F00A911A9 /* CCEventListenerFocus.cpp in Sources */, 50ABBE661925AB6F00A911A9 /* CCEventListenerCustom.cpp in Sources */, @@ -9133,6 +9265,7 @@ B665E29F1AA80A6500DDB1C5 /* CCPUEventHandler.cpp in Sources */, 15AE195519AAD35100C27E9E /* CCDisplayManager.cpp in Sources */, B665E43B1AA80A6600DDB1C5 /* CCPUVortexAffectorTranslator.cpp in Sources */, + 15FB206F1AE7BE7400C31518 /* PolySpriteCache.cpp in Sources */, 15AE1BA719AADFDF00C27E9E /* UIRelativeBox.cpp in Sources */, 15AE1ACE19AAD40300C27E9E /* b2PulleyJoint.cpp in Sources */, B665E2DF1AA80A6500DDB1C5 /* CCPULineAffector.cpp in Sources */, @@ -9253,7 +9386,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/.. $(SRCROOT)/../cocos $(SRCROOT)/../cocos/editor-support $(SRCROOT)/../external/chipmunk/include/chipmunk $(SRCROOT)/../external $(SRCROOT)/../extensions"; + USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/.. $(SRCROOT)/../cocos $(SRCROOT)/../cocos/editor-support $(SRCROOT)/../external/chipmunk/include/chipmunk $(SRCROOT)/../external $(SRCROOT)/../extensions $(SRCROOT)/../external/poly2tri $(SRCROOT)/../external/poly2tri/common $(SRCROOT)/../external/poly2tri/sweep"; }; name = Debug; }; @@ -9286,7 +9419,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/.. $(SRCROOT)/../cocos $(SRCROOT)/../cocos/editor-support $(SRCROOT)/../external/chipmunk/include/chipmunk $(SRCROOT)/../external $(SRCROOT)/../extensions"; + USER_HEADER_SEARCH_PATHS = "$(SRCROOT)/.. $(SRCROOT)/../cocos $(SRCROOT)/../cocos/editor-support $(SRCROOT)/../external/chipmunk/include/chipmunk $(SRCROOT)/../external $(SRCROOT)/../extensions $(SRCROOT)/../external/poly2tri $(SRCROOT)/../external/poly2tri/common $(SRCROOT)/../external/poly2tri/sweep"; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/cocos/2d/CMakeLists.txt b/cocos/2d/CMakeLists.txt index 82e9c60dc4..a6ec0d870a 100644 --- a/cocos/2d/CMakeLists.txt +++ b/cocos/2d/CMakeLists.txt @@ -1,5 +1,8 @@ include_directories( - ../external/ConvertUTF, . + ../external/ConvertUTF + ../external/poly2tri + ../external/poly2tri/common + ../external/poly2tri/sweep ) set(COCOS_2D_SRC @@ -63,6 +66,9 @@ set(COCOS_2D_SRC 2d/CCSprite.cpp 2d/CCSpriteFrameCache.cpp 2d/CCSpriteFrame.cpp + 2d/MarchingSquare.cpp + 2d/PolySprite.cpp + 2d/PolySpriteCache.cpp 2d/CCTextFieldTTF.cpp 2d/CCTileMapAtlas.cpp 2d/CCTMXLayer.cpp diff --git a/cocos/2d/MarchingSquare.cpp b/cocos/2d/MarchingSquare.cpp new file mode 100644 index 0000000000..6735d16981 --- /dev/null +++ b/cocos/2d/MarchingSquare.cpp @@ -0,0 +1,347 @@ +/**************************************************************************** +Copyright (c) 2008-2010 Ricardo Quesada +Copyright (c) 2010-2012 cocos2d-x.org +Copyright (c) 2011 Zynga Inc. +Copyright (c) 2013-2014 Chukong Technologies Inc. + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#include "MarchingSquare.h" +#include "cocos2d.h" +#include + +USING_NS_CC; + +MarchingSquare::MarchingSquare(const std::string &filename, const unsigned int threshold) +{ + _filename = filename; + _threshold = threshold; + Image *image = new Image(); + image->initWithImageFile(filename); + CCASSERT(image->getRenderFormat()==Texture2D::PixelFormat::RGBA8888, "unsupported format, currently only supports rgba8888"); + data = image->getData(); + width = image->getWidth(); + height = image->getHeight(); +} + +void MarchingSquare::trace() +{ + unsigned int first = findFirstNoneTransparentPixel(); + start = Vec2(first%width, first/width); + marchSquare(start.x, start.y); +} + +unsigned int MarchingSquare::findFirstNoneTransparentPixel() +{ + for(unsigned int i = 0; i < width*height; i++) + { + if(getAlphaAt(i) > _threshold) + { +// CCLOG("first non transparent is at x:%d, y%d", i%width, i/width); + return i; + } + } + throw "image is all transparent!"; +} + +unsigned char MarchingSquare::getAlphaAt(const unsigned int i) +{ + return *(data+i*4+3); +} +unsigned char MarchingSquare::getAlphaAt(const int x, const int y) +{ + if(x < 0 || y < 0 || x > width-1 || y > height-1) + return 0; + return *(data+(y*width+x)*4+3); +} + +unsigned int MarchingSquare::getSquareValue(int x, int y) +{ + /* + checking the 2x2 pixel grid, assigning these values to each pixel, if not transparent + +---+---+ + | 1 | 2 | + +---+---+ + | 4 | 8 | <- current pixel (curx,cury) + +---+---+ + */ + unsigned int sv = 0; + if(getAlphaAt(x-1, y-1) > _threshold) + sv += 1; + if(getAlphaAt(x,y-1) > _threshold) + sv += 2; + if(getAlphaAt(x-1, y) > _threshold) + sv += 4; + if(getAlphaAt(x, y) > _threshold) + sv += 8; + return sv; +} + +void MarchingSquare::marchSquare(int startx, int starty) +{ + int stepx = 0; + int stepy = 0; + int prevx = 0; + int prevy = 0; + int curx = startx; + int cury = starty; + float halfWidth = width/2.0; + float halfHeight = height/2.0; + unsigned int count = 0; + unsigned int totalPixel = width*height; + bool problem = false; + std::vector case9s; + std::vector case6s; + int i; + std::vector::iterator it; + do{ + int sv = getSquareValue(curx, cury); + switch(sv){ + + case 1: + case 5: + case 13: + /* going UP with these cases: + 1 5 13 + +---+---+ +---+---+ +---+---+ + | 1 | | | 1 | | | 1 | | + +---+---+ +---+---+ +---+---+ + | | | | 4 | | | 4 | 8 | + +---+---+ +---+---+ +---+---+ + */ + stepx = 0; + stepy = -1; + break; + + + case 8: + case 10: + case 11: + /* going DOWN with these cases: + 8 10 11 + +---+---+ +---+---+ +---+---+ + | | | | | 2 | | 1 | 2 | + +---+---+ +---+---+ +---+---+ + | | 8 | | | 8 | | | 8 | + +---+---+ +---+---+ +---+---+ + */ + stepx = 0; + stepy = 1; + break; + + + case 4: + case 12: + case 14: + /* going LEFT with these cases: + 4 12 14 + +---+---+ +---+---+ +---+---+ + | | | | | | | | 2 | + +---+---+ +---+---+ +---+---+ + | 4 | | | 4 | 8 | | 4 | 8 | + +---+---+ +---+---+ +---+---+ + */ + stepx = -1; + stepy = 0; + break; + + + case 2 : + case 3 : + case 7 : + /* going RIGHT with these cases: + 2 3 7 + +---+---+ +---+---+ +---+---+ + | | 2 | | 1 | 2 | | 1 | 2 | + +---+---+ +---+---+ +---+---+ + | | | | | | | 4 | | + +---+---+ +---+---+ +---+---+ + */ + stepx=1; + stepy=0; + break; + case 9 : + /* + +---+---+ + | 1 | | + +---+---+ + | | 8 | + +---+---+ + this should normaly go UP, but if we already been here, we go down + */ + //find index from xy; + i = getIndexFromPos(curx, cury); + it = find (case9s.begin(), case9s.end(), i); + if (it != case9s.end()) + { + //found, so we go down, and delete from case9s; + stepx = 0; + stepy = 1; + case9s.erase(it); + problem = true; + } + else + { + //not found, we go up, and add to case9s; + stepx = 0; + stepy = -1; + case9s.push_back(i); + } + break; + case 6 : + /* + 6 + +---+---+ + | | 2 | + +---+---+ + | 4 | | + +---+---+ + this normally go RIGHT, but if its coming from UP, it should go LEFT + */ + i = getIndexFromPos(curx, cury); + it = find (case6s.begin(), case6s.end(), i); + if (it != case6s.end()) + { + //found, so we go down, and delete from case9s; + stepx = -1; + stepy = 0; + case6s.erase(it); + problem = true; + } + else{ + //not found, we go up, and add to case9s; + stepx = 1; + stepy = 0; + case6s.push_back(i); + } + break; + case 0: + CCLOG("case 0 at x:%d, y:%d, coming from %d, %d", curx, cury, prevx, prevy); + throw "this shoudln't happen"; + case 15: + CCLOG("case 15 at x:%d, y:%d, coming from %d, %d", curx, cury, prevx, prevy); + throw "this shoudln't happen"; + } + //little optimization + // if previous direction is same as current direction, + // then we should modify the last vec to current + curx += stepx; + cury += stepy; + if(stepx == prevx && stepy == prevy) + { + points.back().x = (float)curx-halfWidth; + points.back().y =(float)height-cury-halfHeight; + } + else if(problem) + { + //TODO: we triangulation cannot work collineer points, so we need to modify same point a little + //TODO: maybe we can detect if we go into a hole and coming back the hole, we should extract those points and remove them + points.back().x -= 0.00001; + points.back().y -= 0.00001; + points.push_back(Vec2((float)curx-halfWidth, (float)height-cury-halfHeight)); + } + else{ + points.push_back(Vec2((float)curx-halfWidth, (float)height-cury-halfHeight)); + } + + count++; + prevx = stepx; + prevy = stepy; + problem = false; + if(count > totalPixel) + throw "oh no, marching square cannot find starting position"; + } while(curx != startx || cury != starty); +} + +void MarchingSquare::printPoints() +{ + for(auto p : points) + { + CCLOG("%.1f %.1f", p.x, height-p.y); + } +} + +float MarchingSquare::perpendicularDistance(cocos2d::Vec2 ii, cocos2d::Vec2 ss, cocos2d::Vec2 ee) +{ + float res; + float slope; + float intercept; + + if(ss.x == ee.x) + { + res = fabsf(ii.x- ee.x); + } + else if (ss.y == ee.y) + { + res = fabsf(ii.y - ee.y); + } + else{ + slope = (ee.y - ss.y) / (ee.x - ss.x); + intercept = ss.y - (slope*ss.x); + res = fabsf(slope * ii.x - ii.y + intercept) / sqrtf(powf(slope, 2)+1); + } + return res; +} +std::vector MarchingSquare::rdp(std::vector v) +{ + if(v.size() < 3) + return v; + + int index = -1; + float dist = 0; + //not looping first and last point + for(int i = 1; i < v.size()-1; i++) + { + float cdist = perpendicularDistance(v[i], v.front(), v.back()); + if(cdist > dist) + { + dist = cdist; + index = i; + } + } + if (dist>epsilon) + { + std::vector::const_iterator begin = v.begin(); + std::vector::const_iterator end = v.end(); + std::vector l1(begin, begin+index+1); + std::vector l2(begin+index, end); + + std::vector r1 = rdp(l1); + std::vector r2 = rdp(l2); + + r1.insert(r1.end(), r2.begin()+1, r2.end()); + return r1; + } + else { + std::vector ret; + ret.push_back(v.front()); + ret.push_back(v.back()); + return ret; + } +} +void MarchingSquare::optimize(float level) +{ + if(level <= 0 || points.size()<4) + return; + epsilon = level; + points = rdp(points); +} \ No newline at end of file diff --git a/cocos/2d/MarchingSquare.h b/cocos/2d/MarchingSquare.h new file mode 100644 index 0000000000..cd223522f7 --- /dev/null +++ b/cocos/2d/MarchingSquare.h @@ -0,0 +1,77 @@ +/**************************************************************************** +Copyright (c) 2008-2010 Ricardo Quesada +Copyright (c) 2010-2012 cocos2d-x.org +Copyright (c) 2011 Zynga Inc. +Copyright (c) 2013-2014 Chukong Technologies Inc. + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#ifndef COCOS_2D_MARCHINGSQUARE_H__ +#define COCOS_2D_MARCHINGSQUARE_H__ + +#include +#include +#include "platform/CCPlatformMacros.h" +#include "math/Vec2.h" + +NS_CC_BEGIN + +class CC_DLL MarchingSquare +{ +public: + MarchingSquare(const std::string &filename, const unsigned int threshold = 0); + //TODO: should return list of vec2s + void trace(); +// unsigned int getAlphaAt(const unsigned int i); +// unsigned int getAlphaAt(int x, int y); + void setThreshold(unsigned int threshold){_threshold = threshold;}; + unsigned int getThreshold(){return _threshold;}; + unsigned int getVecCount(){return points.size();}; + std::vector getPoints(){return points;}; + void printPoints(); + //using Ramer–Douglas–Peucker algorithm + void optimize(float level = 0); + +protected: + unsigned int findFirstNoneTransparentPixel(); + void marchSquare(int startx, int starty); + unsigned int getSquareValue(int x, int y); + unsigned char * data; + std::string _filename; + unsigned int width; + unsigned int height; + unsigned int _threshold; + unsigned char getAlphaAt(const unsigned int i); + unsigned char getAlphaAt(const int x, const int y); + cocos2d::Vec2 start; + std::vector points; + int getIndexFromPos(int x, int y){return y*width+x;}; + cocos2d::Vec2 getPosFromIndex(int i){return cocos2d::Vec2(i%width, i/width);}; + + float epsilon; + std::vector rdp(std::vector v); + float perpendicularDistance(cocos2d::Vec2 i, cocos2d::Vec2 start, cocos2d::Vec2 end); +}; + +NS_CC_END + +#endif // #ifndef COCOS_2D_MARCHINGSQUARE_H__ \ No newline at end of file diff --git a/cocos/2d/PolySprite.cpp b/cocos/2d/PolySprite.cpp new file mode 100644 index 0000000000..8397af1840 --- /dev/null +++ b/cocos/2d/PolySprite.cpp @@ -0,0 +1,435 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2011 Zynga Inc. + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "PolySprite.h" +#include "3d/CCMesh.h" +#include "3d/CCMeshVertexIndexData.h" + +#include "MarchingSquare.h" + +#include "base/CCDirector.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCTextureCache.h" +#include "renderer/CCGLProgramState.h" +#include "renderer/CCGLProgramCache.h" +#include + +#include "poly2tri/poly2tri.h" +#include "PolySpriteCache.h" +#include "platform/CCFileUtils.h" +using namespace std; + + +USING_NS_CC; +using namespace cocos2d::experimental; + +PolySprite *PolySprite::create(const std::string& file, std::vector& verts, std::vector& indices) +{ + PolySprite *ret = new (std::nothrow) PolySprite(); + if (ret && ret->initWithVerts(file, verts, indices)) + { + ret->autorelease(); + return ret; + } + else + { + CC_SAFE_DELETE(ret); + return nullptr; + } +} +PolySprite *PolySprite::create(const std::string& file, std::vector& verts,std::vector& indices, const cocos2d::Rect& rect, bool rotated) +{ + PolySprite *ret = new (std::nothrow) PolySprite(); + if (ret && ret->initWithRect(file, verts, indices, rect, rotated)) + { + ret->autorelease(); + return ret; + } + else + { + CC_SAFE_DELETE(ret); + return nullptr; + } +} +PolySprite *PolySprite::create(const std::string& file, std::vector& verts, const cocos2d::Rect& rect, bool rotated) +{ + PolySprite *ret = new (std::nothrow) PolySprite(); + if (ret && ret->initWithPoly2tri(file, verts, rect, rotated)) + { + ret->autorelease(); + return ret; + } + else + { + CC_SAFE_DELETE(ret); + return nullptr; + } +} +PolySprite *PolySprite::create(const std::string &file, const cocos2d::Rect &rect, unsigned short optimization) +{ + PolySprite *ret = new (std::nothrow) PolySprite(); + if (ret && ret->initWithMarching(file, rect, optimization)) + { + ret->autorelease(); + return ret; + } + else + { + CC_SAFE_DELETE(ret); + return nullptr; + } +} + + + + +static Texture2D * getDummyTexture() +{ + auto texture = Director::getInstance()->getTextureCache()->getTextureForKey("/dummyTexture"); + if(!texture) + { + unsigned char data[] ={255,0,0,255};//1*1 pure red picture + Image * image =new (std::nothrow) Image(); + image->initWithRawData(data,sizeof(data),1,1,sizeof(unsigned char)); + texture=Director::getInstance()->getTextureCache()->addImage(image,"/dummyTexture"); + image->release(); + } + return texture; +} +void PolySprite::triangulate(std::vector & verts) +{ + std::vector points; + for(std::vector::const_iterator it = verts.begin(); itx, it->y); + points.push_back(p); + } + auto cdt = new p2t::CDT(points); + cdt->Triangulate(); + std::vector tris = cdt->GetTriangles(); + + _verts.clear(); + _indices.clear(); + auto bb = setContentSizeFromVecs(verts); +// auto bb = Rect(_textureRect); +// bb.origin.x = -bb.size.width/2; +// bb.origin.y = -bb.size.height/2; + unsigned short idx = 0; + auto texture = _texture; + auto textureWidth = (float)texture->getPixelsWide(); + auto textureHeight = (float)texture->getPixelsHigh(); + auto scaledRect = CC_RECT_POINTS_TO_PIXELS(_textureRect); + for(std::vector::const_iterator ite = tris.begin(); ite < tris.end(); ite++) + { + for(int i = 0; i < 3; i++) + { + auto p = (*ite)->GetPoint(i); + auto v3 = Vec3(p->x, p->y, 0); + auto c4b = Color4B::WHITE; + auto u = (scaledRect.origin.x + scaledRect.size.width* (p->x - bb.origin.x)/_contentSize.width)/textureWidth; + auto v = (scaledRect.origin.y + scaledRect.size.height* (p->y - bb.origin.y)/_contentSize.height)/textureHeight; + auto t2f = Tex2F(u,1-v); + _verts.push_back(V3F_C4B_T2F{v3,c4b,t2f}); + _indices.push_back(idx); + idx++; + } + } + for(auto j : points) + { + delete j; + } + delete cdt; + _triangles = TrianglesCommand::Triangles{&_verts[0], &_indices[0], (ssize_t)_verts.size(), (ssize_t)_indices.size()}; +} +bool PolySprite::initWithMarching(const std::string &file, const cocos2d::Rect &rect, unsigned short optimization) +{ + CCASSERT(file.size()>0, "Invalid filename for sprite"); + Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(file); + if (texture) + { + init(texture, rect); + } + else{ + throw "some error"; + } + + std::string fullpath = FileUtils::getInstance()->fullPathForFilename(file); + PolySpriteInfo* info = PolySpriteCache::getInstance()->getPolySpriteCache(fullpath, rect); + if (nullptr != info) + { + _textureRect = info->_textureRect; + _triangles = TrianglesCommand::Triangles{info->_triangles.verts, info->_triangles.indices, info->_triangles.vertCount, info->_triangles.indexCount}; +#if CC_SPRITE_DEBUG_DRAW + debugDraw(); +#endif + } + + + //Marching Square + auto marcher = new MarchingSquare(file); + marcher->trace(); +// marcher->printPoints(); + marcher->optimize(3); + auto p = marcher->getPoints(); + auto calculatedRect = setContentSizeFromVecs(p); + _textureRect = Rect(rect.origin.x,rect.origin.y,calculatedRect.size.width, calculatedRect.size.height); + triangulate(p); + delete marcher; +#if CC_SPRITE_DEBUG_DRAW + debugDraw(); +#endif + PolySpriteInfo storeInfo = {rect, _triangles, _textureRect }; + PolySpriteCache::getInstance()->addPolySpriteCache(fullpath, storeInfo); + return true; +} +bool PolySprite::initWithPoly2tri(const std::string &filename, std::vector & verts, const cocos2d::Rect &Rect, bool rotated) +{ + CCASSERT(filename.size()>0, "Invalid filename for sprite"); + Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); + if (texture) + { + init(texture, Rect); + } + else{ + throw "some error"; + } + triangulate(verts); + #if CC_SPRITE_DEBUG_DRAW + debugDraw(); + #endif + return true; +} +bool PolySprite::initWithVerts(const std::string& filename,std::vector& verts, std::vector& indices) +{ + + CCASSERT(filename.size()>0, "Invalid filename for sprite"); + + Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); + if (texture) + { +// rect.size = texture->getContentSize(); + init(texture); +// return initWithTexture(texture, rect); + } + else{ + throw "some error"; + } + _verts = verts; + _indices = indices; + _triangles = TrianglesCommand::Triangles{&_verts[0], &_indices[0], (ssize_t)_verts.size(), (ssize_t)_indices.size()}; +#if CC_SPRITE_DEBUG_DRAW + debugDraw(); +#endif + return true; +} +Rect PolySprite::setContentSizeFromVecs(std::vector& verts) +{ + //find min max x,y coords + auto firstV = &verts.front(); + auto left = firstV->x; + auto right = firstV->x; + auto top = firstV->y; + auto bot = firstV->y; + for(std::vector::const_iterator i = verts.begin()+1; ix < left) + { + left = i->x; + } + else if (i->x > right) + { + right = i->x; + } + if(i->y < bot) + { + bot = i->y; + } + else if (i->y > top) + { + top = i->y; + } + } + auto width = right - left; + auto height = top - bot; + setContentSize(Size(width, height)); + return Rect(left,bot,width,height); +} +bool PolySprite::initWithRect(const std::string& filename, std::vector& verts, std::vector& indices, const cocos2d::Rect& rect, bool rotated) +{ + CCASSERT(filename.size()>0, "Invalid filename for sprite"); + _rectRotated = rotated; + Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); + if (texture) + { + init(texture, rect); + } + else{ + throw "some error"; + } + auto bb = setContentSizeFromVecs(verts); + //build v3f_c4b_t2f verts from vec2 vector + _verts.clear(); + _indices.clear(); + unsigned short idx = 0; + auto textureWidth = (float)texture->getPixelsWide(); + auto textureHeight = (float)texture->getPixelsHigh(); + auto scaledRect = CC_RECT_POINTS_TO_PIXELS(rect); + for(std::vector::const_iterator it = verts.begin(); itx, it->y, 0); + auto c4b = Color4B::WHITE; + + auto u = (scaledRect.origin.x + scaledRect.size.width* (it->x - bb.origin.x)/_contentSize.width)/textureWidth; + auto v = (scaledRect.origin.y + scaledRect.size.height* (it->y - bb.origin.y)/_contentSize.height)/textureHeight; + auto t2f = Tex2F(u,1-v); + _verts.push_back(V3F_C4B_T2F{v3,c4b,t2f}); +// _indices.push_back(idx); + } + _indices = indices; + _triangles = TrianglesCommand::Triangles{&_verts[0], &_indices[0], (ssize_t)_verts.size(), (ssize_t)_indices.size()}; +#if CC_SPRITE_DEBUG_DRAW + debugDraw(); +#endif + return true; +} + +bool PolySprite::init(Texture2D *texture, const Rect &rect) +{ + Node::init(); + //init the triangles command + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP)); + + _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; + + setTexture(texture); + _textureRect = (rect.equals(Rect::ZERO))? Rect(0,0,texture->getPixelsWide(), texture->getPixelsHigh()) : rect; + + #if CC_SPRITE_DEBUG_DRAW + _debugDrawNode = DrawNode::create(); + addChild(_debugDrawNode); + #endif //CC_SPRITE_DEBUG_DRAW + return true; +} +void PolySprite::setTexture(const std::string &filename) +{ + Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); + setTexture(texture); + +// Rect rect = Rect::ZERO; +// if (texture) +// rect.size = texture->getContentSize(); +// setTextureRect(rect); +} +static unsigned char cc_2x2_white_image[] = { + // RGBA8888 + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF +}; +#define CC_2x2_WHITE_IMAGE_KEY "/cc_2x2_white_image" +void PolySprite::setTexture(Texture2D *texture) +{ + // accept texture==nil as argument + CCASSERT( !texture || dynamic_cast(texture), "setTexture expects a Texture2D. Invalid argument"); + + if (texture == nullptr) + { + // Gets the texture by key firstly. + texture = Director::getInstance()->getTextureCache()->getTextureForKey(CC_2x2_WHITE_IMAGE_KEY); + + // If texture wasn't in cache, create it from RAW data. + if (texture == nullptr) + { + Image* image = new (std::nothrow) Image(); + bool isOK = image->initWithRawData(cc_2x2_white_image, sizeof(cc_2x2_white_image), 2, 2, 8); + CC_UNUSED_PARAM(isOK); + CCASSERT(isOK, "The 2x2 empty texture was created unsuccessfully."); + + texture = Director::getInstance()->getTextureCache()->addImage(image, CC_2x2_WHITE_IMAGE_KEY); + CC_SAFE_RELEASE(image); + } + } + + if (_texture != texture) + { + CC_SAFE_RETAIN(texture); + CC_SAFE_RELEASE(_texture); + _texture = texture; +// updateBlendFunc(); + } +} +const float PolySprite::getArea(){ + float area = 0; + for(int i = 0; i < _indices.size(); i=i+3) + { + auto A = _verts[_indices[i]].vertices; + auto B = _verts[_indices[i+1]].vertices; + auto C = _verts[_indices[i+2]].vertices; + area += (A.x*(B.y-C.y) + B.x*(C.y-A.y) + C.x*(A.y - B.y))/2; + } + return area; +} + +void PolySprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) +{ + _tcmd.init(0, _texture->getName(), getGLProgramState(), _blendFunc, _triangles, transform, flags); + + renderer->addCommand(&_tcmd); + +} +#if CC_SPRITE_DEBUG_DRAW +void PolySprite::debugDraw() +{ + //draw all points + auto positions = new (std::nothrow) Vec2[_verts.size()]; + for(unsigned int i = 0; i < _verts.size(); i++) + { + positions[i].x = _verts[i].vertices.x; + positions[i].y = _verts[i].vertices.y; + } + _debugDrawNode->drawPoints(positions, _verts.size(), 8, Color4F{0.0,1.0,1.0,1.0}); + //draw lines + for(unsigned int i = 0; i < _indices.size()/3; i++) + { + //draw 3 lines + Vec3 from =_verts[_indices[i*3]].vertices; + Vec3 to = _verts[_indices[i*3+1]].vertices; + _debugDrawNode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN); + + from =_verts[_indices[i*3+1]].vertices; + to = _verts[_indices[i*3+2]].vertices; + _debugDrawNode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN); + + from =_verts[_indices[i*3+2]].vertices; + to = _verts[_indices[i*3]].vertices; + _debugDrawNode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::GREEN); + + } + CC_SAFE_DELETE_ARRAY(positions); +} +#endif //CC_SPRITE_DEBUG_DRAW diff --git a/cocos/2d/PolySprite.h b/cocos/2d/PolySprite.h new file mode 100644 index 0000000000..4ae661bd9b --- /dev/null +++ b/cocos/2d/PolySprite.h @@ -0,0 +1,99 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2011 Zynga Inc. + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef COCOS_2D_POLYSPRITE_H__ +#define COCOS_2D_POLYSPRITE_H__ + +#include +#include "platform/CCPlatformMacros.h" +#include "2d/CCNode.h" +#include "renderer/CCTrianglesCommand.h" +#include "CCDrawNode.h" + +NS_CC_BEGIN + +namespace experimental{ + +class CC_DLL PolySprite : public cocos2d::Node +{ +public: + //create with manually created vertices, color and uv and + static PolySprite *create(const std::string&, std::vector&, std::vector&); + bool initWithVerts(const std::string&, std::vector&, std::vector&); + + //create from list of vertices, with texture rect, and triangle indices, UV is calculated from the texture rect + static PolySprite *create(const std::string&, std::vector&, std::vector&, const cocos2d::Rect& rect = cocos2d::Rect::ZERO, bool rotated = false); + bool initWithRect(const std::string&, std::vector&, std::vector&, const cocos2d::Rect&, bool); + +// //create from ordered list of vertices, with texture rect, and rotated property, Triangles and UV is calculated on the fly + static PolySprite *create(const std::string&, std::vector&, const cocos2d::Rect& rect = cocos2d::Rect::ZERO, bool rotated = false); + bool initWithPoly2tri(const std::string&, std::vector&, const cocos2d::Rect&, bool); + + //create from a texture (rect), and automatically trace and optimize the points. + //not recommended for production, its better to use the vec2 list for better performance + static PolySprite *create(const std::string&, const cocos2d::Rect& rect = cocos2d::Rect::ZERO, unsigned short optimization = 1); + bool initWithMarching(const std::string &file, const cocos2d::Rect &rect, unsigned short optimization); + + bool init(cocos2d::Texture2D *texture, const cocos2d::Rect &rect = cocos2d::Rect::ZERO); + + virtual void setTexture(const std::string &filename ); + virtual void setTexture(cocos2d::Texture2D *texture); + + /** returns the Texture2D object used by the sprite */ + virtual cocos2d::Texture2D* getTexture(){return _texture;}; + const float getArea(); + const size_t getTrianglesCount(){return _indices.size()/3;}; +protected: + #if CC_SPRITE_DEBUG_DRAW + cocos2d::DrawNode *_debugDrawNode; + void debugDraw(); + #endif //CC_SPRITE_DEBUG_DRAW + + bool _triangleDirty; //if triangle is dirty, then it needs to be recalculated from verts and indices + bool _rectRotated; + std::vector _verts; + std::vector _indices; + cocos2d::TrianglesCommand _tcmd; + cocos2d::BlendFunc _blendFunc; + cocos2d::TrianglesCommand::Triangles _triangles; + cocos2d::Texture2D *_texture; + cocos2d::Rect _textureRect; + virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags); + + //======Triangulation + void triangulate(std::vector & verts); + cocos2d::Rect setContentSizeFromVecs(std::vector& verts); + + + //TODO: move those to ccUtils + +}; +} + +NS_CC_END + +#endif // #ifndef COCOS_2D_POLYSPRITE_H__ diff --git a/cocos/2d/PolySpriteCache.cpp b/cocos/2d/PolySpriteCache.cpp new file mode 100644 index 0000000000..cdf00637ee --- /dev/null +++ b/cocos/2d/PolySpriteCache.cpp @@ -0,0 +1,182 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2011 Zynga Inc. + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#include "PolySpriteCache.h" +#include "3d/CCMesh.h" +#include "3d/CCMeshVertexIndexData.h" + +#include "base/CCDirector.h" +#include "renderer/CCRenderer.h" +#include "renderer/CCTextureCache.h" +#include "renderer/CCGLProgramState.h" +#include "renderer/CCGLProgramCache.h" +#include + +#include "poly2tri/poly2tri.h" +#include "platform/CCFileUtils.h" +using namespace std; + +USING_NS_CC; + +PolySpriteCache* PolySpriteCache::_polySpriteCache = nullptr; + +PolySpriteCache::PolySpriteCache() +{ + +} + +PolySpriteCache::~PolySpriteCache() +{ +} + +PolySpriteCache* PolySpriteCache::getInstance() +{ + if (NULL == _polySpriteCache) + { + _polySpriteCache = new (std::nothrow) PolySpriteCache(); + _polySpriteCache->init(); + } + return _polySpriteCache; +} + +void PolySpriteCache::destroyInstance() +{ + CC_SAFE_DELETE(_polySpriteCache); +} + +void PolySpriteCache::init() +{ + +} + +void PolySpriteCache::addPolySpriteCache(const std::string& filePath, const PolySpriteInfo& polySpriteInfo) +{ + std::string fullpath = FileUtils::getInstance()->fullPathForFilename(filePath); + if (fullpath.size() == 0) + return; + + auto it = _polySpriteCacheMap.find(fullpath); + if (_polySpriteCacheMap.end() != it) + { + VecPolySpriteInfo vecInfo = it->second; + + auto infoIt = vecInfo.begin(); + for (; infoIt != vecInfo.end(); infoIt++) + { + if ((*infoIt)->_rect.equals(polySpriteInfo._rect)) + { + (*infoIt)->_triangles = polySpriteInfo._triangles; + (*infoIt)->_textureRect = polySpriteInfo._textureRect; + return; + } + } + } + + VecPolySpriteInfo vecInfo; + vecInfo.clear(); + PolySpriteInfo* info = new (std::nothrow)PolySpriteInfo; + if (nullptr != info) + { + info->_rect = polySpriteInfo._rect; + info->_triangles = polySpriteInfo._triangles; + info->_textureRect = polySpriteInfo._textureRect; + + vecInfo.push_back(info); + _polySpriteCacheMap[filePath] = vecInfo; + } +} + +PolySpriteInfo* PolySpriteCache::getPolySpriteCache(const std::string& filePath, const cocos2d::Rect& rect) +{ + std::string fullpath = FileUtils::getInstance()->fullPathForFilename(filePath); + if (fullpath.size() == 0) + return nullptr; + + auto it = _polySpriteCacheMap.find(fullpath); + if (_polySpriteCacheMap.end() == it) + return nullptr; + + auto infoIter = it->second.begin(); + for (; infoIter != it->second.end(); infoIter++) + { + if ((*infoIter)->_rect.equals(rect)) + return *infoIter; + } + + return nullptr; +} + +void PolySpriteCache::removePolySpriteCache(const std::string& filePath, const cocos2d::Rect* rect) +{ + std::string fullpath = FileUtils::getInstance()->fullPathForFilename(filePath); + if (fullpath.size() == 0) + return; + + auto it = _polySpriteCacheMap.find(fullpath); + if (_polySpriteCacheMap.end() == it) + return; + + if (nullptr == rect) + { + + } + + auto infoIter = it->second.begin(); + for (; infoIter != it->second.end(); infoIter++) + { + + } + + return; +} + +void PolySpriteCache::removeAllPolySpriteCache() +{ + +} + +bool PolySpriteCache::isPolySpriteCachExist(const std::string& filePath, const cocos2d::Rect& rect) +{ + std::string fullpath = FileUtils::getInstance()->fullPathForFilename(filePath); + if (fullpath.size() == 0) + return false; + + auto it = _polySpriteCacheMap.find(fullpath); + if (_polySpriteCacheMap.end() == it) + return false; + + auto infoIter = it->second.begin(); + for (; infoIter != it->second.end(); infoIter++) + { + if ((*infoIter)->_rect.equals(rect)) + return true; + } + + return false; +} + +USING_NS_CC; diff --git a/cocos/2d/PolySpriteCache.h b/cocos/2d/PolySpriteCache.h new file mode 100644 index 0000000000..68da14c88f --- /dev/null +++ b/cocos/2d/PolySpriteCache.h @@ -0,0 +1,73 @@ +/**************************************************************************** + Copyright (c) 2008-2010 Ricardo Quesada + Copyright (c) 2010-2012 cocos2d-x.org + Copyright (c) 2011 Zynga Inc. + Copyright (c) 2013-2014 Chukong Technologies Inc. + + http://www.cocos2d-x.org + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#ifndef COCOS_2D_POLYSPRITECACHE_H__ +#define COCOS_2D_POLYSPRITECACHE_H__ + +#include +#include "platform/CCPlatformMacros.h" +#include "2d/CCNode.h" +#include "renderer/CCTrianglesCommand.h" +#include "CCDrawNode.h" +#include "PolySprite.h" + +NS_CC_BEGIN + +struct CC_DLL PolySpriteInfo +{ + cocos2d::Rect _rect; + cocos2d::TrianglesCommand::Triangles _triangles; + cocos2d::Rect _textureRect; +}; + +typedef std::vector VecPolySpriteInfo; +typedef std::unordered_map MapPolySpriteInfo; + +class CC_DLL PolySpriteCache: public cocos2d::Ref +{ +public: + virtual ~PolySpriteCache(); + static PolySpriteCache* getInstance(); + static void destroyInstance(); + void addPolySpriteCache(const std::string& filePath, const PolySpriteInfo& polySpriteInfo); + PolySpriteInfo* getPolySpriteCache(const std::string& filePath, const cocos2d::Rect& rect); + void removePolySpriteCache(const std::string& filePath, const cocos2d::Rect* rect = nullptr); + void removeAllPolySpriteCache(); + bool isPolySpriteCachExist(const std::string& filePath, const cocos2d::Rect& rect); +protected: + PolySpriteCache(); +private: + void init(); +private: + static PolySpriteCache* _polySpriteCache; + MapPolySpriteInfo _polySpriteCacheMap; + +}; + +NS_CC_END + +#endif // #ifndef COCOS_2D_POLYSPRITECACHE_H__ diff --git a/cocos/2d/libcocos2d.vcxproj b/cocos/2d/libcocos2d.vcxproj old mode 100755 new mode 100644 index 0ed3692090..7c0a4ef920 --- a/cocos/2d/libcocos2d.vcxproj +++ b/cocos/2d/libcocos2d.vcxproj @@ -77,7 +77,7 @@ Disabled - $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\box2d;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\OpenalSoft\include;$(EngineRoot)external\win32-specific\MP3Decoder\include;$(EngineRoot)external\win32-specific\OggDecoder\include;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\xxhash;$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\curl\include\win32;$(EngineRoot)external\websockets\include\win32;$(EngineRoot)external;$(EngineRoot)cocos;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories) + $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\box2d;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\OpenalSoft\include;$(EngineRoot)external\win32-specific\MP3Decoder\include;$(EngineRoot)external\win32-specific\OggDecoder\include;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\xxhash;$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\curl\include\win32;$(EngineRoot)external\websockets\include\win32;$(EngineRoot)external\poly2tri\common;$(EngineRoot)external\poly2tri\sweep;$(EngineRoot)external\poly2tri;$(EngineRoot)external;$(EngineRoot)cocos;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories) WIN32;_USRDLL;_DEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;COCOS2D_DEBUG=1;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE3DDLL;_EXPORT_DLL_;_USRSTUDIODLL;_USREXDLL;_USEGUIDLL;CC_ENABLE_CHIPMUNK_INTEGRATION=1;PROTOBUF_USE_DLLS;LIBPROTOBUF_EXPORTS;%(PreprocessorDefinitions) false EnableFastChecks @@ -132,7 +132,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\debug-lib\*.*" - $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\MP3Decoder\include;$(EngineRoot)external\win32-specific\OggDecoder\include;$(EngineRoot)external\win32-specific\OpenalSoft\include;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\xxhash;$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\Box2d;$(EngineRoot)external\curl\include\win32;$(EngineRoot)external\websockets\include\win32\;$(EngineRoot)external;$(EngineRoot)cocos;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories) + $(MSBuildProgramFiles32)\Microsoft SDKs\Windows\v7.1A\include;$(EngineRoot)external\sqlite3\include;$(EngineRoot)external\unzip;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\tinyxml2;$(EngineRoot)external\png\include\win32;$(EngineRoot)external\jpeg\include\win32;$(EngineRoot)external\tiff\include\win32;$(EngineRoot)external\webp\include\win32;$(EngineRoot)external\freetype2\include\win32;$(EngineRoot)external\win32-specific\MP3Decoder\include;$(EngineRoot)external\win32-specific\OggDecoder\include;$(EngineRoot)external\win32-specific\OpenalSoft\include;$(EngineRoot)external\win32-specific\icon\include;$(EngineRoot)external\win32-specific\zlib\include;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\xxhash;$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\Box2d;$(EngineRoot)external\curl\include\win32;$(EngineRoot)external\websockets\include\win32\;$(EngineRoot)external\poly2tri\common;$(EngineRoot)external\poly2tri\sweep;$(EngineRoot)external\poly2tri;$(EngineRoot)external;$(EngineRoot)cocos;$(EngineRoot)cocos\editor-support;$(EngineRoot)cocos\audio\include;$(EngineRoot)extensions;$(EngineRoot);%(AdditionalIncludeDirectories) WIN32;_USRDLL;NDEBUG;_WINDOWS;_LIB;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE3DDLL;_EXPORT_DLL_;_USRSTUDIODLL;_USREXDLL;_USEGUIDLL;CC_ENABLE_CHIPMUNK_INTEGRATION=1;PROTOBUF_USE_DLLS;LIBPROTOBUF_EXPORTS;%(PreprocessorDefinitions) MultiThreadedDLL @@ -367,6 +367,11 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + + + + + @@ -697,6 +702,9 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + + + @@ -891,6 +899,13 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + + + + + + + @@ -1273,6 +1288,9 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.* + + + diff --git a/cocos/2d/libcocos2d.vcxproj.filters b/cocos/2d/libcocos2d.vcxproj.filters old mode 100755 new mode 100644 index f3ded72143..5b2ed389e0 --- a/cocos/2d/libcocos2d.vcxproj.filters +++ b/cocos/2d/libcocos2d.vcxproj.filters @@ -259,6 +259,15 @@ {e1848cce-b225-42c4-bb6e-6430b6da123b} + + {46294cdb-c29a-4480-9988-2e017f5f7846} + + + {b0703876-33ee-433c-bba3-45304ce83813} + + + {c37eceeb-5702-4ff7-88de-94680a22266f} + @@ -1794,6 +1803,30 @@ cocostudio\json + + 2d + + + 2d + + + 2d + + + external\poly2tri\common + + + external\poly2tri\sweep + + + external\poly2tri\sweep + + + external\poly2tri\sweep + + + external\poly2tri\sweep + @@ -3512,6 +3545,36 @@ cocostudio\json + + 2d + + + 2d + + + 2d + + + external\poly2tri + + + external\poly2tri\common + + + external\poly2tri\common + + + external\poly2tri\sweep + + + external\poly2tri\sweep + + + external\poly2tri\sweep + + + external\poly2tri\sweep + diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems index 00adbe78f3..19892bc32d 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems @@ -196,6 +196,13 @@ + + + + + + + @@ -594,6 +601,9 @@ + + + @@ -781,6 +791,11 @@ + + + + + @@ -1146,6 +1161,9 @@ + + + diff --git a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters index e3f9665cc0..ba87abae32 100644 --- a/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters +++ b/cocos/2d/libcocos2d_8_1/libcocos2d_8_1/libcocos2d_8_1.Shared/libcocos2d_8_1.Shared.vcxitems.filters @@ -1743,6 +1743,36 @@ platform\winrt + + 2d + + + 2d + + + 2d + + + external\poly2tri\common + + + external\poly2tri\common + + + external\poly2tri\sweep + + + external\poly2tri\sweep + + + external\poly2tri\sweep + + + external\poly2tri\sweep + + + external\poly2tri + @@ -3315,6 +3345,30 @@ platform\winrt + + 2d + + + 2d + + + 2d + + + external\poly2tri\common + + + external\poly2tri\sweep + + + external\poly2tri\sweep + + + external\poly2tri\sweep + + + external\poly2tri\sweep + @@ -3563,6 +3617,15 @@ {ed044d4b-058f-4cee-911e-49fad0a03953} + + {1567b8a7-947d-4cf9-883d-5e0cd06efffc} + + + {292e8d6b-015b-40ad-a77c-8d190940da04} + + + {932c5f6e-07b3-4b34-97ae-2f3d42024149} + diff --git a/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props b/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props index c77582b639..672498aa94 100644 --- a/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props +++ b/cocos/2d/winrt_8.1_props/cocos2d_winrt_8.1.props @@ -7,7 +7,7 @@ - $(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\angle\include;$(EngineRoot)external\freetype2\include\$(COCOS2D_PLATFORM)\freetype2;$(EngineRoot)external\curl\include\$(COCOS2D_PLATFORM);$(EngineRoot)external\websockets\include\$(COCOS2D_PLATFORM);$(EngineRoot)cocos\platform\winrt;$(EngineRoot)cocos\platform;$(EngineRoot)cocos\editor-support;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\sqlite3\include;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos;$(EngineRoot)extensions;$(EngineRoot)external;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot);$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\xxhash;%(AdditionalIncludeDirectories) + $(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\angle\include;$(EngineRoot)external\freetype2\include\$(COCOS2D_PLATFORM)\freetype2;$(EngineRoot)external\curl\include\$(COCOS2D_PLATFORM);$(EngineRoot)external\websockets\include\$(COCOS2D_PLATFORM);$(EngineRoot)cocos\platform\winrt;$(EngineRoot)cocos\platform;$(EngineRoot)cocos\editor-support;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\sqlite3\include;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos;$(EngineRoot)extensions;$(EngineRoot)external;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot);$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\xxhash;$(EngineRoot)external\poly2tri;$(EngineRoot)external\poly2tri\common;$(EngineRoot)external\poly2tri\sweep;%(AdditionalIncludeDirectories) WINRT;_VARIADIC_MAX=10;NOMINMAX;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions) @@ -19,7 +19,7 @@ libGLESv2.lib;libEGL.lib;ws2_32.lib;libwebsockets.lib;libcurl.lib;chipmunk.lib;zlib.lib;freetype.lib;sqlite3.lib;d2d1.lib;d3d11.lib;dxgi.lib;windowscodecs.lib;dwrite.lib;dxguid.lib;xaudio2.lib;mfcore.lib;mfplat.lib;mfreadwrite.lib;mfuuid.lib;%(AdditionalDependencies) - $(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\angle\prebuilt\$(Platform);$(EngineRoot)external\curl\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\websockets\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\chipmunk\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\zlib\prebuilt\$(Platform);$(EngineRoot)external\sqlite3\libraries\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\freetype2\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);%(AdditionalLibraryDirectories); + $(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\angle\prebuilt\$(Platform);$(EngineRoot)external\curl\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\websockets\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\chipmunk\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\zlib\prebuilt\$(Platform);$(EngineRoot)external\sqlite3\libraries\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\freetype2\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\poly2tri;$(EngineRoot)external\poly2tri\common;$(EngineRoot)external\poly2tri\sweep;%(AdditionalLibraryDirectories); /IGNORE:4264 %(AdditionalOptions) diff --git a/cocos/2d/winrt_props/cocos2d_winrt.props b/cocos/2d/winrt_props/cocos2d_winrt.props index eb5ffb6d54..a35aa77534 100644 --- a/cocos/2d/winrt_props/cocos2d_winrt.props +++ b/cocos/2d/winrt_props/cocos2d_winrt.props @@ -7,7 +7,7 @@ - $(EngineRoot)external\winrt-specific\angle\include;$(EngineRoot)external\freetype2\include\$(COCOS2D_PLATFORM);$(EngineRoot)external\curl\include\$(COCOS2D_PLATFORM);$(EngineRoot)external\websockets\include\$(COCOS2D_PLATFORM);$(EngineRoot)cocos\platform\winrt;$(EngineRoot)cocos\platform;$(EngineRoot)cocos\editor-support;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\sqlite3\include;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos;$(EngineRoot)extensions;$(EngineRoot)external;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot);$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\xxhash;%(AdditionalIncludeDirectories); + $(EngineRoot)external\winrt-specific\angle\include;$(EngineRoot)external\freetype2\include\$(COCOS2D_PLATFORM);$(EngineRoot)external\curl\include\$(COCOS2D_PLATFORM);$(EngineRoot)external\websockets\include\$(COCOS2D_PLATFORM);$(EngineRoot)cocos\platform\winrt;$(EngineRoot)cocos\platform;$(EngineRoot)cocos\editor-support;$(EngineRoot)external\chipmunk\include\chipmunk;$(EngineRoot)external\sqlite3\include;$(EngineRoot)cocos\audio\include;$(EngineRoot)cocos;$(EngineRoot)extensions;$(EngineRoot)external;$(EngineRoot)external\edtaa3func;$(EngineRoot)external\unzip;$(EngineRoot)external\tinyxml2;$(EngineRoot);$(EngineRoot)external\ConvertUTF;$(EngineRoot)external\xxhash;$(EngineRoot)external\poly2tri;$(EngineRoot)external\poly2tri\common;$(EngineRoot)external\poly2tri\sweep;%(AdditionalIncludeDirectories); WINRT;_VARIADIC_MAX=10;NOMINMAX;GL_GLEXT_PROTOTYPES;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions) @@ -19,7 +19,7 @@ libGLESv2.lib;libEGL.lib;ws2_32.lib;libwebsockets.lib;libcurl.lib;libchipmunk.lib;zlib.lib;libpng.lib;libjpeg.lib;libtiff.lib;freetype250.lib;sqlite3.lib;d2d1.lib;d3d11.lib;dxgi.lib;windowscodecs.lib;dwrite.lib;dxguid.lib;xaudio2.lib;mfcore.lib;mfplat.lib;mfreadwrite.lib;mfuuid.lib;%(AdditionalDependencies) - $(EngineRoot)external\winrt-specific\angle\prebuilt\$(Platform);$(EngineRoot)external\curl\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\websockets\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\chipmunk\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\zlib\prebuilt\$(Platform);$(EngineRoot)external\png\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\tiff\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\jpeg\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\sqlite3\libraries\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\freetype2\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);%(AdditionalLibraryDirectories); + $(EngineRoot)external\winrt-specific\angle\prebuilt\$(Platform);$(EngineRoot)external\curl\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\websockets\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\chipmunk\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\$(COCOS2D_PLATFORM)-specific\zlib\prebuilt\$(Platform);$(EngineRoot)external\png\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\tiff\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\jpeg\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\sqlite3\libraries\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\freetype2\prebuilt\$(COCOS2D_PLATFORM)\$(Platform);$(EngineRoot)external\poly2tri;$(EngineRoot)external\poly2tri\common;$(EngineRoot)external\poly2tri\sweep;%(AdditionalLibraryDirectories); /IGNORE:4264 %(AdditionalOptions) diff --git a/cocos/Android.mk b/cocos/Android.mk index 5bc5446d65..e49c199db5 100644 --- a/cocos/Android.mk +++ b/cocos/Android.mk @@ -71,6 +71,9 @@ cocos2d.cpp \ 2d/CCSpriteBatchNode.cpp \ 2d/CCSpriteFrame.cpp \ 2d/CCSpriteFrameCache.cpp \ +2d/MarchingSquare.cpp \ +2d/PolySprite.cpp \ +2d/PolySpriteCache.cpp \ 2d/CCTMXLayer.cpp \ 2d/CCFastTMXLayer.cpp \ 2d/CCTMXObjectGroup.cpp \ @@ -192,7 +195,12 @@ physics/CCPhysicsWorld.cpp \ ../external/unzip/ioapi.cpp \ ../external/unzip/unzip.cpp \ ../external/edtaa3func/edtaa3func.cpp \ -../external/xxhash/xxhash.c +../external/xxhash/xxhash.c \ +../external/poly2tri/common/shapes.cc \ +../external/poly2tri/sweep/advancing_front.cc \ +../external/poly2tri/sweep/cdt.cc \ +../external/poly2tri/sweep/sweep_context.cc \ +../external/poly2tri/sweep/sweep.cc LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \ @@ -205,7 +213,10 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/../external/unzip \ $(LOCAL_PATH)/../external/chipmunk/include/chipmunk \ $(LOCAL_PATH)/../external/xxhash \ - $(LOCAL_PATH)/../external/nslog + $(LOCAL_PATH)/../external/nslog \ + $(LOCAL_PATH)/../external/poly2tri \ + $(LOCAL_PATH)/../external/poly2tri/common \ + $(LOCAL_PATH)/../external/poly2tri/sweep LOCAL_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/. \ @@ -217,7 +228,10 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) \ $(LOCAL_PATH)/../external/edtaa3func \ $(LOCAL_PATH)/../external/xxhash \ $(LOCAL_PATH)/../external/ConvertUTF \ - $(LOCAL_PATH)/../external/nslog + $(LOCAL_PATH)/../external/nslog \ + $(LOCAL_PATH)/../external/poly2tri \ + $(LOCAL_PATH)/../external/poly2tri/common \ + $(LOCAL_PATH)/../external/poly2tri/sweep LOCAL_EXPORT_LDLIBS := -lGLESv2 \ -llog \ @@ -235,6 +249,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dxandroid_static # define the macro to compile through support/zip_support/ioapi.c LOCAL_CFLAGS := -DUSE_FILE32API +LOCAL_CFLAGS += -fexceptions LOCAL_CPPFLAGS := -Wno-deprecated-declarations -Wno-extern-c-compat LOCAL_EXPORT_CFLAGS := -DUSE_FILE32API LOCAL_EXPORT_CPPFLAGS := -Wno-deprecated-declarations -Wno-extern-c-compat diff --git a/cocos/platform/CMakeLists.txt b/cocos/platform/CMakeLists.txt index d5c6987a56..298a73296c 100644 --- a/cocos/platform/CMakeLists.txt +++ b/cocos/platform/CMakeLists.txt @@ -68,6 +68,9 @@ include_directories( platform ../external/ConvertUTF ../external/edtaa3func + ../external/poly2tri + ../external/poly2tri/common + ../external/poly2tri/sweep ) set(COCOS_PLATFORM_SRC @@ -80,6 +83,11 @@ set(COCOS_PLATFORM_SRC ../external/edtaa3func/edtaa3func.cpp ../external/ConvertUTF/ConvertUTFWrapper.cpp ../external/ConvertUTF/ConvertUTF.c + ../external/poly2tri/common/shapes.cc + ../external/poly2tri/sweep/advancing_front.cc + ../external/poly2tri/sweep/cdt.cc + ../external/poly2tri/sweep/sweep_context.cc + ../external/poly2tri/sweep/sweep.cc ${COCOS_PLATFORM_SPECIFIC_SRC} ) diff --git a/licenses/LICENSE_Poly2Tri.txt b/licenses/LICENSE_Poly2Tri.txt new file mode 100644 index 0000000000..326857c227 --- /dev/null +++ b/licenses/LICENSE_Poly2Tri.txt @@ -0,0 +1,28 @@ +Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors +http://code.google.com/p/poly2tri/ + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +* Neither the name of Poly2Tri nor the names of its contributors may be + used to endorse or promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.