diff --git a/spine-cpp/.settings/org.eclipse.cdt.codan.core.prefs b/spine-cpp/.settings/org.eclipse.cdt.codan.core.prefs index 4fa6ad5b7..b2d528b86 100644 --- a/spine-cpp/.settings/org.eclipse.cdt.codan.core.prefs +++ b/spine-cpp/.settings/org.eclipse.cdt.codan.core.prefs @@ -19,7 +19,7 @@ org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},unknown\=>false,exceptions\=>()} org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=-Warning +org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},skip\=>true} org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} @@ -65,4 +65,3 @@ org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},macro\=>true,exceptions\=>("@(\#)","$Id")} org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}} -useParentScope=false diff --git a/spine-cpp/.settings/org.eclipse.ltk.core.refactoring.prefs b/spine-cpp/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 000000000..b196c64a3 --- /dev/null +++ b/spine-cpp/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/spine-cpp/spineboy-skeleton.json b/spine-cpp/data/spineboy-skeleton.json similarity index 98% rename from spine-cpp/spineboy-skeleton.json rename to spine-cpp/data/spineboy-skeleton.json index a51a9feeb..e6df6f99a 100644 --- a/spine-cpp/spineboy-skeleton.json +++ b/spine-cpp/data/spineboy-skeleton.json @@ -41,9 +41,6 @@ ], "skins": { "default": { - "template": { - "spineboy": { "y": 167.82, "width": 145, "height": 341 } - }, "left shoulder": { "left-shoulder": { "x": 23.74, "y": 0.11, "rotation": 62.01, "width": 34, "height": 53 } }, diff --git a/spine-cpp/data/spineboy-walk.json b/spine-cpp/data/spineboy-walk.json new file mode 100644 index 000000000..b40e53a95 --- /dev/null +++ b/spine-cpp/data/spineboy-walk.json @@ -0,0 +1,278 @@ +{ +"bones": { + "left upper leg": { + "rotate": [ + { "time": 0, "angle": -26.55 }, + { "time": 0.1333, "angle": -8.78 }, + { "time": 0.2666, "angle": 9.51 }, + { "time": 0.4, "angle": 30.74 }, + { "time": 0.5333, "angle": 25.33 }, + { "time": 0.6666, "angle": 26.11 }, + { "time": 0.8, "angle": -7.7 }, + { "time": 0.9333, "angle": -21.19 }, + { "time": 1.0666, "angle": -26.55 } + ], + "translate": [ + { "time": 0, "x": -3, "y": -2.25 }, + { "time": 0.4, "x": -2.18, "y": -2.25 }, + { "time": 1.0666, "x": -3, "y": -2.25 } + ] + }, + "right upper leg": { + "rotate": [ + { "time": 0, "angle": 42.45 }, + { "time": 0.1333, "angle": 52.1 }, + { "time": 0.2666, "angle": 5.96 }, + { "time": 0.5333, "angle": -16.93 }, + { "time": 0.6666, "angle": 1.89 }, + { + "time": 0.8, + "angle": 28.06, + "curve": [ 0.462, 0.11, 1, 1 ] + }, + { + "time": 0.9333, + "angle": 58.68, + "curve": [ 0.5, 0.02, 1, 1 ] + }, + { "time": 1.0666, "angle": 42.45 } + ], + "translate": [ + { "time": 0, "x": 8.11, "y": -2.36 }, + { "time": 0.1333, "x": 10.03, "y": -2.56 }, + { "time": 0.4, "x": 2.76, "y": -2.97 }, + { "time": 0.5333, "x": 2.76, "y": -2.81 }, + { "time": 0.9333, "x": 8.67, "y": -2.54 }, + { "time": 1.0666, "x": 8.11, "y": -2.36 } + ] + }, + "left lower leg": { + "rotate": [ + { "time": 0, "angle": -10.21 }, + { "time": 0.1333, "angle": -55.64 }, + { "time": 0.2666, "angle": -68.12 }, + { "time": 0.5333, "angle": 5.11 }, + { "time": 0.6666, "angle": -28.29 }, + { "time": 0.8, "angle": 4.08 }, + { "time": 0.9333, "angle": 3.53 }, + { "time": 1.0666, "angle": -10.21 } + ] + }, + "left foot": { + "rotate": [ + { "time": 0, "angle": -3.69 }, + { "time": 0.1333, "angle": -10.42 }, + { "time": 0.2666, "angle": -17.14 }, + { "time": 0.4, "angle": -2.83 }, + { "time": 0.5333, "angle": -3.87 }, + { "time": 0.6666, "angle": 2.78 }, + { "time": 0.8, "angle": 1.68 }, + { "time": 0.9333, "angle": -8.54 }, + { "time": 1.0666, "angle": -3.69 } + ] + }, + "right shoulder": { + "rotate": [ + { + "time": 0, + "angle": 20.89, + "curve": [ 0.264, 0, 0.75, 1 ] + }, + { + "time": 0.1333, + "angle": 3.72, + "curve": [ 0.272, 0, 0.841, 1 ] + }, + { "time": 0.6666, "angle": -278.28 }, + { "time": 1.0666, "angle": 20.89 } + ], + "translate": [ + { "time": 0, "x": -7.84, "y": 7.19 }, + { "time": 0.1333, "x": -6.36, "y": 6.42 }, + { "time": 0.6666, "x": -11.07, "y": 5.25 }, + { "time": 1.0666, "x": -7.84, "y": 7.19 } + ] + }, + "right arm": { + "rotate": [ + { + "time": 0, + "angle": -4.02, + "curve": [ 0.267, 0, 0.804, 0.99 ] + }, + { + "time": 0.1333, + "angle": -13.99, + "curve": [ 0.341, 0, 1, 1 ] + }, + { + "time": 0.6666, + "angle": 36.54, + "curve": [ 0.307, 0, 0.787, 0.99 ] + }, + { "time": 1.0666, "angle": -4.02 } + ] + }, + "right hand": { + "rotate": [ + { "time": 0, "angle": 22.92 }, + { "time": 0.4, "angle": -8.97 }, + { "time": 0.6666, "angle": 0.51 }, + { "time": 1.0666, "angle": 22.92 } + ] + }, + "left shoulder": { + "rotate": [ + { "time": 0, "angle": -1.47 }, + { "time": 0.1333, "angle": 13.6 }, + { "time": 0.6666, "angle": 280.74 }, + { "time": 1.0666, "angle": -1.47 } + ], + "translate": [ + { "time": 0, "x": -1.76, "y": 0.56 }, + { "time": 0.6666, "x": -2.47, "y": 8.14 }, + { "time": 1.0666, "x": -1.76, "y": 0.56 } + ] + }, + "left hand": { + "rotate": [ + { + "time": 0, + "angle": 11.58, + "curve": [ 0.169, 0.37, 0.632, 1.55 ] + }, + { + "time": 0.1333, + "angle": 28.13, + "curve": [ 0.692, 0, 0.692, 0.99 ] + }, + { + "time": 0.6666, + "angle": -27.42, + "curve": [ 0.117, 0.41, 0.738, 1.76 ] + }, + { "time": 0.8, "angle": -36.32 }, + { "time": 1.0666, "angle": 11.58 } + ] + }, + "left arm": { + "rotate": [ + { "time": 0, "angle": -8.27 }, + { "time": 0.1333, "angle": 18.43 }, + { "time": 0.6666, "angle": 0.88 }, + { "time": 1.0666, "angle": -8.27 } + ] + }, + "torso": { + "rotate": [ + { "time": 0, "angle": -10.28 }, + { + "time": 0.1333, + "angle": -15.38, + "curve": [ 0.545, 0, 1, 1 ] + }, + { + "time": 0.4, + "angle": -9.78, + "curve": [ 0.58, 0.17, 1, 1 ] + }, + { "time": 0.6666, "angle": -15.75 }, + { "time": 0.9333, "angle": -7.06 }, + { "time": 1.0666, "angle": -10.28 } + ], + "translate": [ + { "time": 0, "x": -3.67, "y": 1.68 }, + { "time": 0.1333, "x": -3.67, "y": 0.68 }, + { "time": 0.4, "x": -3.67, "y": 1.97 }, + { "time": 0.6666, "x": -3.67, "y": -0.14 }, + { "time": 1.0666, "x": -3.67, "y": 1.68 } + ] + }, + "right foot": { + "rotate": [ + { "time": 0, "angle": -5.25 }, + { "time": 0.2666, "angle": -4.08 }, + { "time": 0.4, "angle": -6.45 }, + { "time": 0.5333, "angle": -5.39 }, + { "time": 0.8, "angle": -11.68 }, + { "time": 0.9333, "angle": 0.46 }, + { "time": 1.0666, "angle": -5.25 } + ] + }, + "right lower leg": { + "rotate": [ + { "time": 0, "angle": -3.39 }, + { "time": 0.1333, "angle": -45.53 }, + { "time": 0.2666, "angle": -2.59 }, + { "time": 0.5333, "angle": -19.53 }, + { "time": 0.6666, "angle": -64.8 }, + { + "time": 0.8, + "angle": -82.56, + "curve": [ 0.557, 0.18, 1, 1 ] + }, + { "time": 1.0666, "angle": -3.39 } + ] + }, + "hip": { + "rotate": [ + { "time": 0, "angle": 0, "curve": "stepped" }, + { "time": 1.0666, "angle": 0 } + ], + "translate": [ + { "time": 0, "x": 0, "y": 0 }, + { + "time": 0.1333, + "x": 0, + "y": -7.61, + "curve": [ 0.272, 0.86, 1, 1 ] + }, + { "time": 0.4, "x": 0, "y": 8.7 }, + { "time": 0.5333, "x": 0, "y": -0.41 }, + { + "time": 0.6666, + "x": 0, + "y": -7.05, + "curve": [ 0.235, 0.89, 1, 1 ] + }, + { "time": 0.8, "x": 0, "y": 2.92 }, + { "time": 0.9333, "x": 0, "y": 6.78 }, + { "time": 1.0666, "x": 0, "y": 0 } + ] + }, + "neck": { + "rotate": [ + { "time": 0, "angle": 3.6 }, + { "time": 0.1333, "angle": 17.49 }, + { "time": 0.2666, "angle": 6.1 }, + { "time": 0.4, "angle": 3.45 }, + { "time": 0.5333, "angle": 5.17 }, + { "time": 0.6666, "angle": 18.36 }, + { "time": 0.8, "angle": 6.09 }, + { "time": 0.9333, "angle": 2.28 }, + { "time": 1.0666, "angle": 3.6 } + ] + }, + "head": { + "rotate": [ + { + "time": 0, + "angle": 3.6, + "curve": [ 0, 0, 0.704, 1.61 ] + }, + { "time": 0.1666, "angle": -0.2 }, + { "time": 0.2666, "angle": 6.1 }, + { "time": 0.4, "angle": 3.45 }, + { + "time": 0.5333, + "angle": 5.17, + "curve": [ 0, 0, 0.704, 1.61 ] + }, + { "time": 0.7, "angle": 1.1 }, + { "time": 0.8, "angle": 6.09 }, + { "time": 0.9333, "angle": 2.28 }, + { "time": 1.0666, "angle": 3.6 } + ] + } +} +} \ No newline at end of file diff --git a/spine-cpp/data/spineboy.atlas b/spine-cpp/data/spineboy.atlas new file mode 100644 index 000000000..ac19de904 --- /dev/null +++ b/spine-cpp/data/spineboy.atlas @@ -0,0 +1,166 @@ + +../data/spineboy.png +format: RGBA8888 +filter: Nearest,Nearest +repeat: none +head + rotate: false + xy: 1, 122 + size: 121, 132 + orig: 121, 132 + offset: 0, 0 + index: -1 +torso + rotate: false + xy: 1, 28 + size: 68, 92 + orig: 68, 92 + offset: 0, 0 + index: -1 +left-pant-bottom + rotate: false + xy: 1, 4 + size: 44, 22 + orig: 44, 22 + offset: 0, 0 + index: -1 +right-pant-bottom + rotate: false + xy: 47, 8 + size: 46, 18 + orig: 46, 18 + offset: 0, 0 + index: -1 +right-upper-leg + rotate: false + xy: 71, 50 + size: 44, 70 + orig: 44, 70 + offset: 0, 0 + index: -1 +pelvis + rotate: false + xy: 95, 1 + size: 63, 47 + orig: 63, 47 + offset: 0, 0 + index: -1 +left-upper-leg + rotate: false + xy: 117, 53 + size: 33, 67 + orig: 33, 67 + offset: 0, 0 + index: -1 +right-foot + rotate: false + xy: 160, 224 + size: 67, 30 + orig: 67, 30 + offset: 0, 0 + index: -1 +left-shoulder + rotate: false + xy: 124, 201 + size: 34, 53 + orig: 34, 53 + offset: 0, 0 + index: -1 +left-ankle + rotate: false + xy: 229, 222 + size: 25, 32 + orig: 25, 32 + offset: 0, 0 + index: -1 +left-foot + rotate: false + xy: 160, 192 + size: 65, 30 + orig: 65, 30 + offset: 0, 0 + index: -1 +neck + rotate: false + xy: 124, 171 + size: 34, 28 + orig: 34, 28 + offset: 0, 0 + index: -1 +right-arm + rotate: false + xy: 124, 124 + size: 21, 45 + orig: 21, 45 + offset: 0, 0 + index: -1 +right-ankle + rotate: false + xy: 227, 190 + size: 25, 30 + orig: 25, 30 + offset: 0, 0 + index: -1 +left-hand + rotate: false + xy: 147, 131 + size: 35, 38 + orig: 35, 38 + offset: 0, 0 + index: -1 +left-arm + rotate: false + xy: 184, 161 + size: 35, 29 + orig: 35, 29 + offset: 0, 0 + index: -1 +eyes-closed + rotate: false + xy: 221, 161 + size: 34, 27 + orig: 34, 27 + offset: 0, 0 + index: -1 +right-lower-leg + rotate: false + xy: 152, 65 + size: 51, 64 + orig: 51, 64 + offset: 0, 0 + index: -1 +right-foot-idle + rotate: false + xy: 184, 131 + size: 53, 28 + orig: 53, 28 + offset: 0, 0 + index: -1 +left-lower-leg + rotate: false + xy: 205, 65 + size: 49, 64 + orig: 49, 64 + offset: 0, 0 + index: -1 +right-shoulder + rotate: false + xy: 160, 12 + size: 52, 51 + orig: 52, 51 + offset: 0, 0 + index: -1 +eyes + rotate: false + xy: 214, 36 + size: 34, 27 + orig: 34, 27 + offset: 0, 0 + index: -1 +right-hand + rotate: false + xy: 214, 2 + size: 32, 32 + orig: 32, 32 + offset: 0, 0 + index: -1 diff --git a/spine-cpp/data/spineboy.png b/spine-cpp/data/spineboy.png new file mode 100644 index 000000000..b8b493dfd Binary files /dev/null and b/spine-cpp/data/spineboy.png differ diff --git a/spine-cpp/includes/spine-sfml/Atlas.h b/spine-cpp/includes/spine-sfml/Atlas.h new file mode 100644 index 000000000..25fbc2d77 --- /dev/null +++ b/spine-cpp/includes/spine-sfml/Atlas.h @@ -0,0 +1,38 @@ +#ifndef SPINE_ATLAS_H_ +#define SPINE_ATLAS_H_ + +#include +#include + +namespace spine { + +class AtlasPage: public BaseAtlasPage { +public: + sf::Texture *texture; +}; + +// + +class AtlasRegion: public BaseAtlasRegion { +public: + AtlasPage *page; +}; + +// + +class Atlas: public BaseAtlas { +public: + Atlas (std::ifstream &file); + Atlas (std::istream &input); + Atlas (const std::string &text); + Atlas (const char *begin, const char *end); + + AtlasRegion* findRegion (const std::string &name); + +private: + virtual BaseAtlasPage* newAtlasPage (std::string name); + virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage* page); +}; + +} /* namespace spine */ +#endif /* SPINE_ATLAS_H_ */ diff --git a/spine-cpp/includes/spine-sfml/AtlasAttachmentLoader.h b/spine-cpp/includes/spine-sfml/AtlasAttachmentLoader.h new file mode 100644 index 000000000..57bceebcb --- /dev/null +++ b/spine-cpp/includes/spine-sfml/AtlasAttachmentLoader.h @@ -0,0 +1,21 @@ +#ifndef SPINE_ATLASATTACHMENTLOADER_H_ +#define SPINE_ATLASATTACHMENTLOADER_H_ + +#include + +namespace spine { + +class Atlas; + +class AtlasAttachmentLoader: public BaseAttachmentLoader { +public: + Atlas *atlas; + + AtlasAttachmentLoader (Atlas *atlas); + + virtual Attachment* newAttachment (AttachmentType type, const std::string &name); +} +; + +} /* namespace spine */ +#endif /* SPINE_ATLASATTACHMENTLOADER_H_ */ diff --git a/spine-cpp/includes/spine-sfml/RegionAttachment.h b/spine-cpp/includes/spine-sfml/RegionAttachment.h index 5ced52e1a..6c2afbdcf 100644 --- a/spine-cpp/includes/spine-sfml/RegionAttachment.h +++ b/spine-cpp/includes/spine-sfml/RegionAttachment.h @@ -3,20 +3,22 @@ #include #include +#include namespace spine { class Bone; +class AtlasRegion; class RegionAttachment: public BaseRegionAttachment { public: sf::Vertex vertices[4]; + sf::Texture *texture; - RegionAttachment (); + RegionAttachment (AtlasRegion *region); virtual void updateWorldVertices (Bone *bone); - - virtual void draw (const BaseSkeleton *skeleton); + virtual void draw (Slot *slot); }; } /* namespace spine */ diff --git a/spine-cpp/includes/spine-sfml/Skeleton.h b/spine-cpp/includes/spine-sfml/Skeleton.h index e5d8d90a1..d298f64c5 100644 --- a/spine-cpp/includes/spine-sfml/Skeleton.h +++ b/spine-cpp/includes/spine-sfml/Skeleton.h @@ -6,9 +6,10 @@ namespace spine { -class Skeleton: public BaseSkeleton, private sf::Drawable { +class Skeleton: public BaseSkeleton, public sf::Drawable { public: sf::VertexArray vertexArray; + sf::Texture *texture; Skeleton (SkeletonData *skeletonData); diff --git a/spine-cpp/includes/spine-sfml/SkeletonJson.h b/spine-cpp/includes/spine-sfml/SkeletonJson.h index 13f32a04e..fc01e0623 100644 --- a/spine-cpp/includes/spine-sfml/SkeletonJson.h +++ b/spine-cpp/includes/spine-sfml/SkeletonJson.h @@ -5,9 +5,12 @@ namespace spine { +class Atlas; + class SkeletonJson: public BaseSkeletonJson { public: - SkeletonJson (); + SkeletonJson (Atlas *atlas); + SkeletonJson (BaseAttachmentLoader *attachmentLoader); }; } /* namespace spine */ diff --git a/spine-cpp/includes/spine-sfml/spine.h b/spine-cpp/includes/spine-sfml/spine.h index d6000c1ba..c80b8ef12 100644 --- a/spine-cpp/includes/spine-sfml/spine.h +++ b/spine-cpp/includes/spine-sfml/spine.h @@ -10,7 +10,10 @@ #include #include -#include #include +#include +#include +#include +#include #endif /* SF_SPINE_H_ */ diff --git a/spine-cpp/includes/spine/AtlasData.h b/spine-cpp/includes/spine/AtlasData.h deleted file mode 100644 index c2a51fd08..000000000 --- a/spine-cpp/includes/spine/AtlasData.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef SPINE_ATLASDATA_H_ -#define SPINE_ATLASDATA_H_ - -#include -#include -#include - -namespace spine { - -class AtlasPage; -class AtlasRegion; - -class AtlasData { -public: - std::vector pages; - std::vector regions; - - AtlasData (const char *begin, const char *end); - AtlasData (const std::string &json); - AtlasData (std::istream &file); - ~AtlasData (); - -private: - void init (const char *begin, const char *end); -}; - -enum Format { - alpha, intensity, luminanceAlpha, rgb565, rgba4444, rgb888, rgba8888 -}; - -enum TextureFilter { - nearest, linear, mipMap, mipMapNearestNearest, mipMapLinearNearest, mipMapNearestLinear, mipMapLinearLinear -}; - -enum TextureWrap { - mirroredRepeat, clampToEdge, repeat -}; - -class AtlasPage { -public: - std::string name; - Format format; - TextureFilter minFilter, magFilter; - TextureWrap uWrap, vWrap; -}; - -class AtlasRegion { -public: - std::string name; - AtlasPage *page; - int x, y, width, height; - float offsetX, offsetY; - int originalWidth, originalHeight; - int index; - bool rotate; - bool flip; - int *splits; - int *pads; -}; - -} /* namespace spine */ -#endif /* SPINE_ATLASDATA_H_ */ diff --git a/spine-cpp/includes/spine/Attachment.h b/spine-cpp/includes/spine/Attachment.h index 8c4a53967..5ef4ce128 100644 --- a/spine-cpp/includes/spine/Attachment.h +++ b/spine-cpp/includes/spine/Attachment.h @@ -6,6 +6,7 @@ namespace spine { class BaseSkeleton; +class Slot; class Attachment { public: @@ -15,7 +16,7 @@ public: virtual ~Attachment () { } - virtual void draw (const BaseSkeleton *skeleton) = 0; + virtual void draw (Slot *slot) = 0; }; } /* namespace spine */ diff --git a/spine-cpp/includes/spine/BaseAtlas.h b/spine-cpp/includes/spine/BaseAtlas.h new file mode 100644 index 000000000..7aba26972 --- /dev/null +++ b/spine-cpp/includes/spine/BaseAtlas.h @@ -0,0 +1,78 @@ +#ifndef SPINE_BASEATLASDATA_H_ +#define SPINE_BASEATLASDATA_H_ + +#include +#include +#include +#include + +namespace spine { + +class BaseAtlasPage; +class BaseAtlasRegion; + +class BaseAtlas { +public: + std::vector pages; + std::vector regions; + + virtual ~BaseAtlas (); + + void load (std::ifstream &file); + void load (std::istream &input); + void load (const std::string &text); + void load (const char *begin, const char *end); + + virtual BaseAtlasRegion* findRegion (const std::string &name); + +private: + virtual BaseAtlasPage* newAtlasPage (std::string name) = 0; + virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage*) = 0; +}; + +// + +enum Format { + alpha, intensity, luminanceAlpha, rgb565, rgba4444, rgb888, rgba8888 +}; + +enum TextureFilter { + nearest, linear, mipMap, mipMapNearestNearest, mipMapLinearNearest, mipMapNearestLinear, mipMapLinearLinear +}; + +enum TextureWrap { + mirroredRepeat, clampToEdge, repeat +}; + +// + +class BaseAtlasPage { +public: + std::string name; + Format format; + TextureFilter minFilter, magFilter; + TextureWrap uWrap, vWrap; + + virtual ~BaseAtlasPage () { + } +}; + +// + +class BaseAtlasRegion { +public: + std::string name; + int x, y, width, height; + float offsetX, offsetY; + int originalWidth, originalHeight; + int index; + bool rotate; + bool flip; + int *splits; + int *pads; + + virtual ~BaseAtlasRegion (); +}; + +} /* namespace spine */ +#endif /* SPINE_BASEATLASDATA_H_ */ diff --git a/spine-cpp/includes/spine/BaseAttachmentLoader.h b/spine-cpp/includes/spine/BaseAttachmentLoader.h index 644fb0e65..190927b15 100644 --- a/spine-cpp/includes/spine/BaseAttachmentLoader.h +++ b/spine-cpp/includes/spine/BaseAttachmentLoader.h @@ -14,7 +14,7 @@ public: virtual ~BaseAttachmentLoader () { } - virtual Attachment* newAttachment (AttachmentType type) = 0; + virtual Attachment* newAttachment (AttachmentType type, const std::string &name) = 0; }; } /* namespace spine */ diff --git a/spine-cpp/includes/spine/BaseRegionAttachment.h b/spine-cpp/includes/spine/BaseRegionAttachment.h index d32ee2b1f..142b75e4d 100644 --- a/spine-cpp/includes/spine/BaseRegionAttachment.h +++ b/spine-cpp/includes/spine/BaseRegionAttachment.h @@ -6,6 +6,7 @@ namespace spine { class Bone; +class Slot; class BaseRegionAttachment: public Attachment { public: diff --git a/spine-cpp/includes/spine/BaseSkeletonJson.h b/spine-cpp/includes/spine/BaseSkeletonJson.h index 90f730978..161707e99 100644 --- a/spine-cpp/includes/spine/BaseSkeletonJson.h +++ b/spine-cpp/includes/spine/BaseSkeletonJson.h @@ -16,9 +16,10 @@ public: BaseSkeletonJson (BaseAttachmentLoader *attachmentLoader); virtual ~BaseSkeletonJson (); - SkeletonData* readSkeletonData (const char *begin, const char *end) const; - SkeletonData* readSkeletonData (const std::string &json) const; + SkeletonData* readSkeletonData (std::ifstream &file) const; SkeletonData* readSkeletonData (std::istream &file) const; + SkeletonData* readSkeletonData (const std::string &json) const; + SkeletonData* readSkeletonData (const char *begin, const char *end) const; }; } /* namespace spine */ diff --git a/spine-cpp/src/main.cpp b/spine-cpp/src/main.cpp index 78f497d89..d4c9e5f5e 100644 --- a/spine-cpp/src/main.cpp +++ b/spine-cpp/src/main.cpp @@ -1,7 +1,5 @@ #include #include -#include -#include #include #include @@ -9,40 +7,30 @@ using namespace std; using namespace spine; int main () { - ifstream file("../spineboy-skeleton.json"); + ifstream file("../data/spineboy-skeleton.json"); try { - SkeletonJson skeletonJson; + ifstream file2("../data/spineboy.atlas"); + Atlas *atlas = new Atlas(file2); + SkeletonJson skeletonJson(atlas); SkeletonData *skeletonData = skeletonJson.readSkeletonData(file); - cout << skeletonData->bones.size() << " bone datas.\n"; - cout << skeletonData->slots.size() << " slot datas.\n"; - cout << skeletonData->skins.size() << " skins.\n"; - cout << (skeletonData->defaultSkin ? "Has" : "Doesn't have") << " default skin.\n"; + Skeleton *skeleton = new Skeleton(skeletonData); + skeleton->setToBindPose(); + skeleton->getRootBone()->x = 200; + skeleton->getRootBone()->y = 420; + skeleton->updateWorldTransform(); - BaseSkeleton *skeleton = new BaseSkeleton(skeletonData); - cout << skeleton->bones.size() << " bones.\n"; + sf::RenderWindow window(sf::VideoMode(640, 480), "Spine SFML"); + window.setFramerateLimit(60); + sf::Event event; + while (window.isOpen()) { + while (window.pollEvent(event)) + if (event.type == sf::Event::Closed) window.close(); + window.clear(); + window.draw(*skeleton); + window.display(); + } } catch (exception &ex) { - cout << ex.what() << endl; + cout << ex.what() << endl << flush; } - cout << flush; - - ifstream file2("../uiskin.atlas"); - new AtlasData(file2); - - sf::RenderWindow window(sf::VideoMode(640, 480), "Spine SFML"); - window.setFramerateLimit(60); - - sf::CircleShape shape(100.f); - shape.setFillColor(sf::Color::Green); - - sf::Event event; - while (window.isOpen() && false) { - while (window.pollEvent(event)) - if (event.type == sf::Event::Closed) window.close(); - window.clear(); - window.draw(shape); - window.display(); - } - - return 0; } diff --git a/spine-cpp/src/spine-sfml/Atlas.cpp b/spine-cpp/src/spine-sfml/Atlas.cpp new file mode 100644 index 000000000..4bf376588 --- /dev/null +++ b/spine-cpp/src/spine-sfml/Atlas.cpp @@ -0,0 +1,39 @@ +#include +#include + +namespace spine { + +Atlas::Atlas (std::ifstream &file) { + load(file); +} + +Atlas::Atlas (std::istream &input) { + load(input); +} + +Atlas::Atlas (const std::string &text) { + load(text); +} + +Atlas::Atlas (const char *begin, const char *end) { + load(begin, end); +} + +BaseAtlasPage* Atlas::newAtlasPage (std::string name) { + AtlasPage *page = new AtlasPage(); + page->texture = new sf::Texture(); + page->texture->loadFromFile(name); + return page; +} + +BaseAtlasRegion* Atlas::newAtlasRegion (BaseAtlasPage* page) { + AtlasRegion *region = new AtlasRegion(); + region->page = reinterpret_cast(page); + return region; +} + +AtlasRegion* Atlas::findRegion (const std::string &name) { + return reinterpret_cast(BaseAtlas::findRegion(name)); +} + +} /* namespace spine */ diff --git a/spine-cpp/src/spine-sfml/AtlasAttachmentLoader.cpp b/spine-cpp/src/spine-sfml/AtlasAttachmentLoader.cpp new file mode 100644 index 000000000..4cfe3e63d --- /dev/null +++ b/spine-cpp/src/spine-sfml/AtlasAttachmentLoader.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include + +namespace spine { + +AtlasAttachmentLoader::AtlasAttachmentLoader (Atlas *atlas) : + atlas(atlas) { +} + +Attachment* AtlasAttachmentLoader::newAttachment (AttachmentType type, const std::string &name) { + switch (type) { + case region: { + AtlasRegion *region = atlas->findRegion(name); + if (!region) throw std::runtime_error("Atlas region not found: " + name); + return new RegionAttachment(region); + } + default: + throw std::runtime_error("Unknown attachment type: " + type); + } +} + +} /* namespace spine */ diff --git a/spine-cpp/src/spine-sfml/AttachmentLoader.h b/spine-cpp/src/spine-sfml/AttachmentLoader.h deleted file mode 100644 index 245978648..000000000 --- a/spine-cpp/src/spine-sfml/AttachmentLoader.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ATTACHMENTLOADER_H_ -#define ATTACHMENTLOADER_H_ - -#include -#include -#include - -namespace spine { - -class AttachmentLoader: public BaseAttachmentLoader { -public: - virtual Attachment* newAttachment (AttachmentType type) { - switch (type) { - case region: - return new RegionAttachment(); - default: - throw std::runtime_error("Unknown attachment type: " + type); - } - } -}; - -} /* namespace spine */ -#endif /* ATTACHMENTLOADER_H_ */ diff --git a/spine-cpp/src/spine-sfml/RegionAttachment.cpp b/spine-cpp/src/spine-sfml/RegionAttachment.cpp index 240916c20..d909f27e2 100644 --- a/spine-cpp/src/spine-sfml/RegionAttachment.cpp +++ b/spine-cpp/src/spine-sfml/RegionAttachment.cpp @@ -1,14 +1,73 @@ +#include +#include #include +#include #include #include +#include namespace spine { -RegionAttachment::RegionAttachment () { +RegionAttachment::RegionAttachment (AtlasRegion *region) { + texture = region->page->texture; + sf::Vector2u size = texture->getSize(); + int u = region->x; + int u2 = u + region->width; + int v = region->y; + int v2 = v + region->height; + if (region->rotate) { + vertices[1].texCoords.x = u; + vertices[1].texCoords.y = v2; + vertices[2].texCoords.x = u; + vertices[2].texCoords.y = v; + vertices[3].texCoords.x = u2; + vertices[3].texCoords.y = v; + vertices[0].texCoords.x = u2; + vertices[0].texCoords.y = v2; + } else { + vertices[0].texCoords.x = u; + vertices[0].texCoords.y = v2; + vertices[1].texCoords.x = u; + vertices[1].texCoords.y = v; + vertices[2].texCoords.x = u2; + vertices[2].texCoords.y = v; + vertices[3].texCoords.x = u2; + vertices[3].texCoords.y = v2; + } } -void RegionAttachment::draw (const BaseSkeleton *skeleton) { - ((Skeleton*)skeleton)->vertexArray.append(vertices[0]); +void RegionAttachment::draw (Slot *slot) { + Skeleton* skeleton = (Skeleton*)slot->skeleton; + + sf::Uint8 r = skeleton->r * slot->r * 255; + sf::Uint8 g = skeleton->g * slot->g * 255; + sf::Uint8 b = skeleton->b * slot->b * 255; + sf::Uint8 a = skeleton->a * slot->a * 255; + vertices[0].color.r = r; + vertices[0].color.g = g; + vertices[0].color.b = b; + vertices[0].color.a = a; + vertices[1].color.r = r; + vertices[1].color.g = g; + vertices[1].color.b = b; + vertices[1].color.a = a; + vertices[2].color.r = r; + vertices[2].color.g = g; + vertices[2].color.b = b; + vertices[2].color.a = a; + vertices[3].color.r = r; + vertices[3].color.g = g; + vertices[3].color.b = b; + vertices[3].color.a = a; + + updateOffset(); // BOZO - Move to resolve()? + updateWorldVertices(slot->bone); + + skeleton->texture = texture; + skeleton->vertexArray.append(vertices[0]); + skeleton->vertexArray.append(vertices[1]); + skeleton->vertexArray.append(vertices[2]); + skeleton->vertexArray.append(vertices[3]); } void RegionAttachment::updateWorldVertices (spine::Bone *bone) { diff --git a/spine-cpp/src/spine-sfml/Skeleton.cpp b/spine-cpp/src/spine-sfml/Skeleton.cpp index ef6e8ce77..bc5c3fbac 100644 --- a/spine-cpp/src/spine-sfml/Skeleton.cpp +++ b/spine-cpp/src/spine-sfml/Skeleton.cpp @@ -1,23 +1,30 @@ +#include #include #include #include #include #include #include +#include -using namespace sf; +using sf::Quads; +using sf::RenderTarget; +using sf::RenderStates; namespace spine { Skeleton::Skeleton (SkeletonData *skeletonData) : BaseSkeleton(skeletonData), - vertexArray(Quads, skeletonData->bones.size() * 4) { + vertexArray(Quads, skeletonData->bones.size() * 4), + texture(0) { + flipY = true; // BOZO - Flip in loader for animation? } void Skeleton::draw (RenderTarget& target, RenderStates states) const { + const_cast(this)->vertexArray.clear(); for (int i = 0, n = slots.size(); i < n; i++) - if (slots[i]->attachment) slots[i]->attachment->draw(this); - target.draw(vertexArray, states); + if (slots[i]->attachment) slots[i]->attachment->draw(slots[i]); + target.draw(vertexArray, texture); } } /* namespace spine */ diff --git a/spine-cpp/src/spine-sfml/SkeletonJson.cpp b/spine-cpp/src/spine-sfml/SkeletonJson.cpp index 8f5eb2d20..fe040c5b9 100644 --- a/spine-cpp/src/spine-sfml/SkeletonJson.cpp +++ b/spine-cpp/src/spine-sfml/SkeletonJson.cpp @@ -1,9 +1,14 @@ #include -#include "AttachmentLoader.h" +#include namespace spine { -SkeletonJson::SkeletonJson () : BaseSkeletonJson(new AttachmentLoader()) { +SkeletonJson::SkeletonJson (BaseAttachmentLoader *attachmentLoader) : + BaseSkeletonJson(attachmentLoader) { +} + +SkeletonJson::SkeletonJson (Atlas *atlas) : + BaseSkeletonJson(new AtlasAttachmentLoader(atlas)) { } } /* namespace spine */ diff --git a/spine-cpp/src/spine/AtlasData.cpp b/spine-cpp/src/spine/BaseAtlas.cpp similarity index 84% rename from spine-cpp/src/spine/AtlasData.cpp rename to spine-cpp/src/spine/BaseAtlas.cpp index 5b4e661e8..5d0a7b0a9 100644 --- a/spine-cpp/src/spine/AtlasData.cpp +++ b/spine-cpp/src/spine/BaseAtlas.cpp @@ -1,9 +1,9 @@ #include -#include +#include #include #include #include -#include +#include using std::string; using std::runtime_error; @@ -65,35 +65,45 @@ static string formatNames[] = {"Alpha", "Intensity", "LuminanceAlpha", "RGB565", static string textureFilterNames[] = {"Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest", "MipMapNearestLinear", "MipMapLinearLinear"}; -AtlasData::AtlasData (std::istream &file) { +// + +BaseAtlas::~BaseAtlas () { + for (int i = 0, n = pages.size(); i < n; i++) + delete pages[i]; + for (int i = 0, n = regions.size(); i < n; i++) + delete regions[i]; +} + +void BaseAtlas::load (std::ifstream &file) { + if (!file.is_open()) throw runtime_error("Atlas file is not open."); + load((std::istream&)file); +} + +void BaseAtlas::load (std::istream &input) { string text; - std::getline(file, text, (char)EOF); + std::getline(input, text, (char)EOF); const char *begin = text.c_str(); const char *end = begin + text.length(); - init(begin, end); + load(begin, end); } -AtlasData::AtlasData (const string &text) { +void BaseAtlas::load (const string &text) { const char *begin = text.c_str(); const char *end = begin + text.length(); - init(begin, end); + load(begin, end); } -AtlasData::AtlasData (const char *begin, const char *end) { - init(begin, end); -} - -void AtlasData::init (const char *current, const char *end) { +void BaseAtlas::load (const char *current, const char *end) { string value; string tuple[4]; - AtlasPage *page; + BaseAtlasPage *page; while (current != end) { readLine(current, end, value); trim(value); if (value.length() == 0) { page = 0; } else if (!page) { - page = new AtlasPage(); + page = newAtlasPage(value); pages.push_back(page); page->name = value; page->format = static_cast(indexOf(formatNames, 7, readValue(current, end, value))); @@ -114,10 +124,9 @@ void AtlasData::init (const char *current, const char *end) { page->vWrap = repeat; } } else { - AtlasRegion *region = new AtlasRegion(); + BaseAtlasRegion *region = newAtlasRegion(page); regions.push_back(region); region->name = value; - region->page = page; region->rotate = readValue(current, end, value) == "true"; @@ -159,11 +168,17 @@ void AtlasData::init (const char *current, const char *end) { } } -AtlasData::~AtlasData () { - for (int i = 0, n = pages.size(); i < n; i++) - delete pages[i]; +BaseAtlasRegion* BaseAtlas::findRegion (const std::string &name) { for (int i = 0, n = regions.size(); i < n; i++) - delete regions[i]; + if (regions[i]->name == name) return regions[i]; + return 0; +} + +// + +BaseAtlasRegion::~BaseAtlasRegion () { + if (splits) delete splits; + if (pads) delete pads; } } /* namespace spine */ diff --git a/spine-cpp/src/spine/BaseSkeleton.cpp b/spine-cpp/src/spine/BaseSkeleton.cpp index 917312cad..f87b3ac10 100644 --- a/spine-cpp/src/spine/BaseSkeleton.cpp +++ b/spine-cpp/src/spine/BaseSkeleton.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -17,7 +18,10 @@ BaseSkeleton::BaseSkeleton (SkeletonData *data) : r(1), g(1), b(1), - a(1) { + a(1), + time(0), + flipX(false), + flipY(false) { if (!data) throw invalid_argument("data cannot be null."); int boneCount = data->bones.size(); diff --git a/spine-cpp/src/spine/BaseSkeletonJson.cpp b/spine-cpp/src/spine/BaseSkeletonJson.cpp index 2ae9f2c1c..76e80cae0 100644 --- a/spine-cpp/src/spine/BaseSkeletonJson.cpp +++ b/spine-cpp/src/spine/BaseSkeletonJson.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -31,9 +31,14 @@ float toColor (const string &value, int index) { return color / (float)255; } -SkeletonData* BaseSkeletonJson::readSkeletonData (std::istream &file) const { +SkeletonData* BaseSkeletonJson::readSkeletonData (std::ifstream &file) const { + if (!file.is_open()) throw runtime_error("Skeleton file is not open."); + return readSkeletonData((std::istream&)file); +} + +SkeletonData* BaseSkeletonJson::readSkeletonData (std::istream &input) const { string json; - std::getline(file, json, (char)EOF); + std::getline(input, json, (char)EOF); return readSkeletonData(json); } @@ -133,8 +138,8 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char else throw runtime_error("Unknown attachment type: " + typeString + " (" + attachmentName + ")"); - Attachment* attachment = attachmentLoader->newAttachment(type); - attachment->name = attachmentMap.get("name", attachmentName).asString(); + Attachment* attachment = attachmentLoader->newAttachment(type, + attachmentMap.get("name", attachmentName).asString()); attachment->x = attachmentMap.get("x", 0).asDouble() * scale; attachment->y = attachmentMap.get("y", 0).asDouble() * scale; attachment->scaleX = attachmentMap.get("scaleX", 1).asDouble(); diff --git a/spine-cpp/uiskin.atlas b/spine-cpp/uiskin.atlas deleted file mode 100644 index c19358167..000000000 --- a/spine-cpp/uiskin.atlas +++ /dev/null @@ -1,198 +0,0 @@ - -uiskin.png -format: RGBA8888 -filter: Nearest,Nearest -repeat: none -default - rotate: false - xy: 1, 50 - size: 254, 77 - orig: 254, 77 - offset: 0, 0 - index: -1 -default-window - rotate: false - xy: 1, 20 - size: 27, 29 - split: 4, 3, 20, 3 - orig: 27, 29 - offset: 0, 0 - index: -1 -default-select - rotate: false - xy: 29, 29 - size: 27, 20 - split: 4, 14, 4, 4 - orig: 27, 20 - offset: 0, 0 - index: -1 -default-round-large - rotate: false - xy: 57, 29 - size: 20, 20 - split: 5, 5, 5, 4 - orig: 20, 20 - offset: 0, 0 - index: -1 -default-scroll - rotate: false - xy: 78, 29 - size: 20, 20 - split: 2, 2, 2, 2 - orig: 20, 20 - offset: 0, 0 - index: -1 -default-slider-knob - rotate: false - xy: 1, 1 - size: 9, 18 - orig: 9, 18 - offset: 0, 0 - index: -1 -default-round-down - rotate: false - xy: 99, 29 - size: 12, 20 - split: 5, 5, 5, 4 - orig: 12, 20 - offset: 0, 0 - index: -1 -default-round - rotate: false - xy: 112, 29 - size: 12, 20 - split: 5, 5, 5, 4 - pad: 4, 4, 1, 1 - orig: 12, 20 - offset: 0, 0 - index: -1 -check-off - rotate: false - xy: 11, 5 - size: 14, 14 - orig: 14, 14 - offset: 0, 0 - index: -1 -textfield - rotate: false - xy: 11, 5 - size: 14, 14 - split: 3, 3, 3, 3 - orig: 14, 14 - offset: 0, 0 - index: -1 -check-on - rotate: false - xy: 125, 35 - size: 14, 14 - orig: 14, 14 - offset: 0, 0 - index: -1 -tree-minus - rotate: false - xy: 140, 35 - size: 14, 14 - orig: 14, 14 - offset: 0, 0 - index: -1 -tree-plus - rotate: false - xy: 155, 35 - size: 14, 14 - orig: 14, 14 - offset: 0, 0 - index: -1 -default-slider - rotate: false - xy: 29, 20 - size: 8, 8 - split: 2, 2, 2, 2 - orig: 8, 8 - offset: 0, 0 - index: -1 -default-pane - rotate: false - xy: 11, 1 - size: 5, 3 - split: 1, 1, 1, 1 - orig: 5, 3 - offset: 0, 0 - index: -1 -default-rect-pad - rotate: false - xy: 11, 1 - size: 5, 3 - split: 1, 1, 1, 1 - orig: 5, 3 - offset: 0, 0 - index: -1 -default-splitpane - rotate: false - xy: 17, 1 - size: 5, 3 - split: 0, 5, 0, 0 - orig: 5, 3 - offset: 0, 0 - index: -1 -cursor - rotate: false - xy: 23, 1 - size: 3, 3 - split: 1, 1, 1, 1 - orig: 3, 3 - offset: 0, 0 - index: -1 -default-splitpane-vertical - rotate: false - xy: 125, 29 - size: 3, 5 - split: 0, 0, 0, 5 - orig: 3, 5 - offset: 0, 0 - index: -1 -default-rect-down - rotate: false - xy: 170, 46 - size: 3, 3 - split: 1, 1, 1, 1 - orig: 3, 3 - offset: 0, 0 - index: -1 -default-rect - rotate: false - xy: 38, 25 - size: 3, 3 - split: 1, 1, 1, 1 - orig: 3, 3 - offset: 0, 0 - index: -1 -default-select-selection - rotate: false - xy: 26, 16 - size: 3, 3 - split: 1, 1, 1, 1 - orig: 3, 3 - offset: 0, 0 - index: -1 -default-pane-noborder - rotate: false - xy: 129, 33 - size: 1, 1 - split: 0, 0, 0, 0 - orig: 1, 1 - offset: 0, 0 - index: -1 -selection - rotate: false - xy: 170, 44 - size: 1, 1 - orig: 1, 1 - offset: 0, 0 - index: -1 -white - rotate: false - xy: 174, 48 - size: 1, 1 - orig: 1, 1 - offset: 0, 0 - index: -1