[cocos2d-x] Fixed up binary loader support

This commit is contained in:
badlogic 2016-10-03 14:18:57 +02:00
parent 89d9ee00dc
commit 25be5370b2
4 changed files with 52 additions and 10 deletions

View File

@ -46,6 +46,8 @@
521A8E6519F0C34300D177D7 /* Default-736h@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 521A8E6319F0C34300D177D7 /* Default-736h@3x.png */; };
52B47A471A53D09C004E4C60 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52B47A461A53D09B004E4C60 /* Security.framework */; };
7602C5551D7DAA1300C7C674 /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7602C5541D7DAA1300C7C674 /* CoreText.framework */; };
765B3E181DA283F90071C974 /* SkeletonBinary.c in Sources */ = {isa = PBXBuildFile; fileRef = 765B3E171DA283F90071C974 /* SkeletonBinary.c */; };
765B3E191DA284060071C974 /* SkeletonBinary.c in Sources */ = {isa = PBXBuildFile; fileRef = 765B3E171DA283F90071C974 /* SkeletonBinary.c */; };
76AAA3C01D180F7C00C54FCB /* AppDelegate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3B31D180F7C00C54FCB /* AppDelegate.cpp */; };
76AAA3C11D180F7C00C54FCB /* BatchingExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3B61D180F7C00C54FCB /* BatchingExample.cpp */; };
76AAA3C21D180F7C00C54FCB /* GoblinsExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3B81D180F7C00C54FCB /* GoblinsExample.cpp */; };
@ -244,6 +246,8 @@
521A8E6319F0C34300D177D7 /* Default-736h@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-736h@3x.png"; sourceTree = "<group>"; };
52B47A461A53D09B004E4C60 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/System/Library/Frameworks/Security.framework; sourceTree = DEVELOPER_DIR; };
7602C5541D7DAA1300C7C674 /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks/CoreText.framework; sourceTree = DEVELOPER_DIR; };
765B3E161DA283F90071C974 /* kvec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = kvec.h; path = "../../../spine-c/src/spine/kvec.h"; sourceTree = "<group>"; };
765B3E171DA283F90071C974 /* SkeletonBinary.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SkeletonBinary.c; path = "../../../spine-c/src/spine/SkeletonBinary.c"; sourceTree = "<group>"; };
76AAA3B31D180F7C00C54FCB /* AppDelegate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppDelegate.cpp; sourceTree = "<group>"; };
76AAA3B41D180F7C00C54FCB /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
76AAA3B51D180F7C00C54FCB /* AppMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppMacros.h; sourceTree = "<group>"; };
@ -519,6 +523,8 @@
76AAA3B21D180F7300C54FCB /* spine */ = {
isa = PBXGroup;
children = (
765B3E161DA283F90071C974 /* kvec.h */,
765B3E171DA283F90071C974 /* SkeletonBinary.c */,
76F5BCF41D2BB57F005917E5 /* Animation.c */,
76F5BCF51D2BB57F005917E5 /* AnimationState.c */,
76F5BCF61D2BB57F005917E5 /* AnimationStateData.c */,
@ -741,6 +747,7 @@
76F5BD201D2BB57F005917E5 /* extension.c in Sources */,
76AAA3C01D180F7C00C54FCB /* AppDelegate.cpp in Sources */,
76AAA3C41D180F7C00C54FCB /* SimpleCommand.cpp in Sources */,
765B3E181DA283F90071C974 /* SkeletonBinary.c in Sources */,
76F5BD261D2BB57F005917E5 /* PathConstraint.c in Sources */,
503AE10017EB989F00D1A890 /* AppController.mm in Sources */,
76AAA40E1D18106000C54FCB /* SkeletonAnimation.cpp in Sources */,
@ -768,6 +775,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
765B3E191DA284060071C974 /* SkeletonBinary.c in Sources */,
76F5BD561D2BD7EF005917E5 /* TankExample.cpp in Sources */,
76F5BD571D2BD7EF005917E5 /* TankExample.h in Sources */,
76F5BD331D2BD4A9005917E5 /* Animation.c in Sources */,

View File

@ -80,7 +80,7 @@ SkeletonAnimation* SkeletonAnimation::createWithData (spSkeletonData* skeletonDa
SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& skeletonJsonFile, spAtlas* atlas, float scale) {
SkeletonAnimation* node = new SkeletonAnimation();
node->initWithFile(skeletonJsonFile, atlas, scale);
node->initWithJsonFile(skeletonJsonFile, atlas, scale);
node->autorelease();
return node;
}
@ -88,14 +88,14 @@ SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& ske
SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale) {
SkeletonAnimation* node = new SkeletonAnimation();
spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0);
node->initWithFile(skeletonJsonFile, atlas, scale);
node->initWithJsonFile(skeletonJsonFile, atlas, scale);
node->autorelease();
return node;
}
SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, spAtlas* atlas, float scale) {
SkeletonAnimation* node = new SkeletonAnimation();
node->initWithFile(skeletonBinaryFile, atlas, scale);
node->initWithBinaryFile(skeletonBinaryFile, atlas, scale);
node->autorelease();
return node;
}
@ -103,7 +103,7 @@ SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& s
SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, const std::string& atlasFile, float scale) {
SkeletonAnimation* node = new SkeletonAnimation();
spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0);
node->initWithFile(skeletonBinaryFile, atlas, scale);
node->initWithBinaryFile(skeletonBinaryFile, atlas, scale);
node->autorelease();
return node;
}

View File

@ -85,12 +85,12 @@ SkeletonRenderer::SkeletonRenderer (spSkeletonData *skeletonData, bool ownsSkele
SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, spAtlas* atlas, float scale)
: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _timeScale(1) {
initWithFile(skeletonDataFile, atlas, scale);
initWithJsonFile(skeletonDataFile, atlas, scale);
}
SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale)
: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _timeScale(1) {
initWithFile(skeletonDataFile, atlasFile, scale);
initWithJsonFile(skeletonDataFile, atlasFile, scale);
}
SkeletonRenderer::~SkeletonRenderer () {
@ -107,7 +107,7 @@ void SkeletonRenderer::initWithData (spSkeletonData* skeletonData, bool ownsSkel
initialize();
}
void SkeletonRenderer::initWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale) {
void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale) {
_atlas = atlas;
_attachmentLoader = SUPER(Cocos2dAttachmentLoader_create(_atlas));
@ -122,7 +122,7 @@ void SkeletonRenderer::initWithFile (const std::string& skeletonDataFile, spAtla
initialize();
}
void SkeletonRenderer::initWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
_atlas = spAtlas_createFromFile(atlasFile.c_str(), 0);
CCASSERT(_atlas, "Error reading atlas file.");
@ -138,6 +138,38 @@ void SkeletonRenderer::initWithFile (const std::string& skeletonDataFile, const
initialize();
}
void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale) {
_atlas = atlas;
_attachmentLoader = SUPER(Cocos2dAttachmentLoader_create(_atlas));
spSkeletonBinary* binary = spSkeletonBinary_createWithLoader(_attachmentLoader);
binary->scale = scale;
spSkeletonData* skeletonData = spSkeletonBinary_readSkeletonDataFile(binary, skeletonDataFile.c_str());
CCASSERT(skeletonData, binary->error ? binary->error : "Error reading skeleton data file.");
spSkeletonBinary_dispose(binary);
setSkeletonData(skeletonData, true);
initialize();
}
void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
_atlas = spAtlas_createFromFile(atlasFile.c_str(), 0);
CCASSERT(_atlas, "Error reading atlas file.");
_attachmentLoader = SUPER(Cocos2dAttachmentLoader_create(_atlas));
spSkeletonBinary* binary = spSkeletonBinary_createWithLoader(_attachmentLoader);
binary->scale = scale;
spSkeletonData* skeletonData = spSkeletonBinary_readSkeletonDataFile(binary, skeletonDataFile.c_str());
CCASSERT(skeletonData, binary->error ? binary->error : "Error reading skeleton data file.");
spSkeletonBinary_dispose(binary);
setSkeletonData(skeletonData, true);
initialize();
}
void SkeletonRenderer::update (float deltaTime) {

View File

@ -108,8 +108,10 @@ CC_CONSTRUCTOR_ACCESS:
virtual ~SkeletonRenderer ();
void initWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
void initWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1);
void initWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
void initWithJsonFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1);
void initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
void initWithBinaryFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1);
void initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
virtual void initialize ();