mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-25 22:23:42 +08:00
Documented memory ownership.
Clean up and minor improvements.
This commit is contained in:
parent
a347994c52
commit
a1ad55f8a1
@ -31,7 +31,7 @@
|
|||||||
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/includes}""/>
|
<listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/includes}""/>
|
||||||
<listOptionValue builtIn="false" value=""C:\Users\Nate\Desktop\SFML-2.0-rc\include""/>
|
<listOptionValue builtIn="false" value=""C:\Users\Nate\Desktop\SFML-2.0-rc\include""/>
|
||||||
</option>
|
</option>
|
||||||
<option id="gnu.cpp.compiler.option.warnings.allwarn.2053349441" name="All warnings (-Wall)" superClass="gnu.cpp.compiler.option.warnings.allwarn" value="false" valueType="boolean"/>
|
<option id="gnu.cpp.compiler.option.warnings.allwarn.2053349441" name="All warnings (-Wall)" superClass="gnu.cpp.compiler.option.warnings.allwarn" value="true" valueType="boolean"/>
|
||||||
<option id="gnu.cpp.compiler.option.preprocessor.def.1463772359" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def"/>
|
<option id="gnu.cpp.compiler.option.preprocessor.def.1463772359" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def"/>
|
||||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1445618618" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1445618618" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
|
||||||
</tool>
|
</tool>
|
||||||
|
|||||||
@ -274,27 +274,5 @@
|
|||||||
{ "time": 1.0666, "angle": 3.6 }
|
{ "time": 1.0666, "angle": 3.6 }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"slots": {
|
|
||||||
"torso": {
|
|
||||||
"attachment": [
|
|
||||||
{ "time": 0.4333, "name": null },
|
|
||||||
{ "time": 0.8, "name": "torso" }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"head": {
|
|
||||||
"color": [
|
|
||||||
{ "time": 0.1666, "color": "ffffffff" },
|
|
||||||
{ "time": 0.9333, "color": "ff0f00c1" }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"eyes": {
|
|
||||||
"attachment": [
|
|
||||||
{ "time": 0.2, "name": "eyes-closed" },
|
|
||||||
{ "time": 0.3, "name": "eyes" },
|
|
||||||
{ "time": 0.7, "name": "eyes-closed" },
|
|
||||||
{ "time": 0.8333, "name": "eyes" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8,9 +8,7 @@ namespace spine {
|
|||||||
|
|
||||||
class AtlasPage: public BaseAtlasPage {
|
class AtlasPage: public BaseAtlasPage {
|
||||||
public:
|
public:
|
||||||
~AtlasPage(){
|
~AtlasPage ();
|
||||||
delete texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
sf::Texture *texture;
|
sf::Texture *texture;
|
||||||
};
|
};
|
||||||
@ -34,7 +32,7 @@ public:
|
|||||||
AtlasRegion* findRegion (const std::string &name);
|
AtlasRegion* findRegion (const std::string &name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual BaseAtlasPage* newAtlasPage (std::string name);
|
virtual BaseAtlasPage* newAtlasPage (const std::string &name);
|
||||||
virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage* page);
|
virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage* page);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ namespace spine {
|
|||||||
class Skeleton: public BaseSkeleton, public sf::Drawable {
|
class Skeleton: public BaseSkeleton, public sf::Drawable {
|
||||||
public:
|
public:
|
||||||
sf::VertexArray vertexArray;
|
sf::VertexArray vertexArray;
|
||||||
sf::Texture *texture; // BOZO - This is ugly. Support multiple textures?
|
sf::Texture *texture; // This is a bit ugly and means all region attachments must use the same textures.
|
||||||
|
|
||||||
Skeleton (SkeletonData *skeletonData);
|
Skeleton (SkeletonData *skeletonData);
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ class Atlas;
|
|||||||
class SkeletonJson: public BaseSkeletonJson {
|
class SkeletonJson: public BaseSkeletonJson {
|
||||||
public:
|
public:
|
||||||
SkeletonJson (Atlas *atlas);
|
SkeletonJson (Atlas *atlas);
|
||||||
|
/** The SkeletonJson owns the attachmentLoader */
|
||||||
SkeletonJson (BaseAttachmentLoader *attachmentLoader);
|
SkeletonJson (BaseAttachmentLoader *attachmentLoader);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -15,10 +15,10 @@ public:
|
|||||||
float duration;
|
float duration;
|
||||||
|
|
||||||
Animation (const std::vector<Timeline*> &timelines, float duration);
|
Animation (const std::vector<Timeline*> &timelines, float duration);
|
||||||
~Animation();
|
~Animation ();
|
||||||
|
|
||||||
void apply (BaseSkeleton *skeleton, float time, bool loop);
|
void apply (BaseSkeleton *skeleton, float time, bool loop) const;
|
||||||
void mix (BaseSkeleton *skeleton, float time, bool loop, float alpha);
|
void mix (BaseSkeleton *skeleton, float time, bool loop, float alpha) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -28,11 +28,11 @@ public:
|
|||||||
virtual ~Timeline () {
|
virtual ~Timeline () {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual float getDuration () = 0;
|
virtual float getDuration () const = 0;
|
||||||
|
|
||||||
virtual int getKeyframeCount () = 0;
|
virtual int getKeyframeCount () const = 0;
|
||||||
|
|
||||||
virtual void apply (BaseSkeleton *skeleton, float time, float alpha) = 0;
|
virtual void apply (BaseSkeleton *skeleton, float time, float alpha) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -53,7 +53,7 @@ public:
|
|||||||
* the difference between the keyframe's values. */
|
* the difference between the keyframe's values. */
|
||||||
void setCurve (int keyframeIndex, float cx1, float cy1, float cx2, float cy2);
|
void setCurve (int keyframeIndex, float cx1, float cy1, float cx2, float cy2);
|
||||||
|
|
||||||
float getCurvePercent (int keyframeIndex, float percent);
|
float getCurvePercent (int keyframeIndex, float percent) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -67,9 +67,9 @@ public:
|
|||||||
RotateTimeline (int keyframeCount);
|
RotateTimeline (int keyframeCount);
|
||||||
virtual ~RotateTimeline ();
|
virtual ~RotateTimeline ();
|
||||||
|
|
||||||
virtual float getDuration ();
|
virtual float getDuration () const;
|
||||||
virtual int getKeyframeCount ();
|
virtual int getKeyframeCount () const;
|
||||||
virtual void apply (BaseSkeleton *skeleton, float time, float alpha);
|
virtual void apply (BaseSkeleton *skeleton, float time, float alpha) const;
|
||||||
|
|
||||||
void setKeyframe (int keyframeIndex, float time, float value);
|
void setKeyframe (int keyframeIndex, float time, float value);
|
||||||
};
|
};
|
||||||
@ -85,9 +85,9 @@ public:
|
|||||||
TranslateTimeline (int keyframeCount);
|
TranslateTimeline (int keyframeCount);
|
||||||
virtual ~TranslateTimeline ();
|
virtual ~TranslateTimeline ();
|
||||||
|
|
||||||
virtual float getDuration ();
|
virtual float getDuration () const;
|
||||||
virtual int getKeyframeCount ();
|
virtual int getKeyframeCount () const;
|
||||||
virtual void apply (BaseSkeleton *skeleton, float time, float alpha);
|
virtual void apply (BaseSkeleton *skeleton, float time, float alpha) const;
|
||||||
|
|
||||||
void setKeyframe (int keyframeIndex, float time, float x, float y);
|
void setKeyframe (int keyframeIndex, float time, float x, float y);
|
||||||
};
|
};
|
||||||
@ -98,7 +98,7 @@ class ScaleTimeline: public TranslateTimeline {
|
|||||||
public:
|
public:
|
||||||
ScaleTimeline (int keyframeCount);
|
ScaleTimeline (int keyframeCount);
|
||||||
|
|
||||||
virtual void apply (BaseSkeleton *skeleton, float time, float alpha);
|
virtual void apply (BaseSkeleton *skeleton, float time, float alpha) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -112,9 +112,9 @@ public:
|
|||||||
ColorTimeline (int keyframeCount);
|
ColorTimeline (int keyframeCount);
|
||||||
virtual ~ColorTimeline ();
|
virtual ~ColorTimeline ();
|
||||||
|
|
||||||
virtual float getDuration ();
|
virtual float getDuration () const;
|
||||||
virtual int getKeyframeCount ();
|
virtual int getKeyframeCount () const;
|
||||||
virtual void apply (BaseSkeleton *skeleton, float time, float alpha);
|
virtual void apply (BaseSkeleton *skeleton, float time, float alpha) const;
|
||||||
|
|
||||||
void setKeyframe (int keyframeIndex, float time, float r, float g, float b, float a);
|
void setKeyframe (int keyframeIndex, float time, float r, float g, float b, float a);
|
||||||
};
|
};
|
||||||
@ -131,12 +131,13 @@ public:
|
|||||||
AttachmentTimeline (int keyframeCount);
|
AttachmentTimeline (int keyframeCount);
|
||||||
virtual ~AttachmentTimeline ();
|
virtual ~AttachmentTimeline ();
|
||||||
|
|
||||||
virtual float getDuration ();
|
virtual float getDuration () const;
|
||||||
virtual int getKeyframeCount ();
|
virtual int getKeyframeCount () const;
|
||||||
virtual void apply (BaseSkeleton *skeleton, float time, float alpha);
|
virtual void apply (BaseSkeleton *skeleton, float time, float alpha) const;
|
||||||
|
|
||||||
/** @param attachmentName Pass an empty string to clear the image for a slot. */
|
/** The AttachmentTimeline owns the attachmentName.
|
||||||
void setKeyframe (int keyframeIndex, float time, const std::string &attachmentName);
|
* @param attachmentName May be null to clear the image for a slot. */
|
||||||
|
void setKeyframe (int keyframeIndex, float time, std::string *attachmentName);
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace spine */
|
} /* namespace spine */
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
#include <istream>
|
#include <istream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ public:
|
|||||||
virtual BaseAtlasRegion* findRegion (const std::string &name);
|
virtual BaseAtlasRegion* findRegion (const std::string &name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual BaseAtlasPage* newAtlasPage (std::string name) = 0;
|
virtual BaseAtlasPage* newAtlasPage (const std::string &name) = 0;
|
||||||
virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage *page) = 0;
|
virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage *page) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -71,7 +70,7 @@ public:
|
|||||||
int *splits;
|
int *splits;
|
||||||
int *pads;
|
int *pads;
|
||||||
|
|
||||||
BaseAtlasRegion() : splits(0), pads(0) {}
|
BaseAtlasRegion ();
|
||||||
virtual ~BaseAtlasRegion ();
|
virtual ~BaseAtlasRegion ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
#ifndef SPINE_BASEATTACHMENTLOADER_H_
|
#ifndef SPINE_BASEATTACHMENTLOADER_H_
|
||||||
#define SPINE_BASEATTACHMENTLOADER_H_
|
#define SPINE_BASEATTACHMENTLOADER_H_
|
||||||
|
|
||||||
#include <spine/Attachment.h>
|
|
||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
|
class Attachment;
|
||||||
|
|
||||||
enum AttachmentType {
|
enum AttachmentType {
|
||||||
region, regionSequence
|
region, regionSequence
|
||||||
};
|
};
|
||||||
|
|||||||
@ -23,6 +23,7 @@ public:
|
|||||||
float time;
|
float time;
|
||||||
bool flipX, flipY;
|
bool flipX, flipY;
|
||||||
|
|
||||||
|
/** The BaseSkeleton owns the SkeletonData. */
|
||||||
BaseSkeleton (SkeletonData *data);
|
BaseSkeleton (SkeletonData *data);
|
||||||
virtual ~BaseSkeleton ();
|
virtual ~BaseSkeleton ();
|
||||||
|
|
||||||
@ -40,10 +41,11 @@ public:
|
|||||||
int findSlotIndex (const std::string &slotName) const;
|
int findSlotIndex (const std::string &slotName) const;
|
||||||
|
|
||||||
void setSkin (const std::string &skinName);
|
void setSkin (const std::string &skinName);
|
||||||
void setSkin (Skin *newSkin);
|
/** @param skin May be null. */
|
||||||
|
void setSkin (Skin *skin);
|
||||||
|
|
||||||
Attachment* getAttachment (const std::string &slotName, const std::string &attachmentName);
|
Attachment* getAttachment (const std::string &slotName, const std::string &attachmentName) const;
|
||||||
Attachment* getAttachment (int slotIndex, const std::string &attachmentName);
|
Attachment* getAttachment (int slotIndex, const std::string &attachmentName) const;
|
||||||
void setAttachment (const std::string &slotName, const std::string &attachmentName);
|
void setAttachment (const std::string &slotName, const std::string &attachmentName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -13,8 +13,9 @@ class BaseSkeletonJson {
|
|||||||
public:
|
public:
|
||||||
BaseAttachmentLoader *attachmentLoader;
|
BaseAttachmentLoader *attachmentLoader;
|
||||||
float scale;
|
float scale;
|
||||||
bool flipY;
|
bool yDown;
|
||||||
|
|
||||||
|
/** The BaseSkeletonJson owns the attachmentLoader. */
|
||||||
BaseSkeletonJson (BaseAttachmentLoader *attachmentLoader);
|
BaseSkeletonJson (BaseAttachmentLoader *attachmentLoader);
|
||||||
virtual ~BaseSkeletonJson ();
|
virtual ~BaseSkeletonJson ();
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ class BoneData;
|
|||||||
class Bone {
|
class Bone {
|
||||||
public:
|
public:
|
||||||
BoneData *data;
|
BoneData *data;
|
||||||
|
/** May be null. */
|
||||||
Bone *parent;
|
Bone *parent;
|
||||||
float x, y;
|
float x, y;
|
||||||
float rotation;
|
float rotation;
|
||||||
|
|||||||
@ -13,7 +13,7 @@ public:
|
|||||||
float x, y;
|
float x, y;
|
||||||
float rotation;
|
float rotation;
|
||||||
float scaleX, scaleY;
|
float scaleX, scaleY;
|
||||||
float flipY;
|
float yDown;
|
||||||
|
|
||||||
BoneData (const std::string &name) :
|
BoneData (const std::string &name) :
|
||||||
name(name),
|
name(name),
|
||||||
@ -24,7 +24,7 @@ public:
|
|||||||
rotation(0),
|
rotation(0),
|
||||||
scaleX(1),
|
scaleX(1),
|
||||||
scaleY(1),
|
scaleY(1),
|
||||||
flipY(false) {
|
yDown(false) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -12,9 +12,13 @@ class Skin;
|
|||||||
|
|
||||||
class SkeletonData {
|
class SkeletonData {
|
||||||
public:
|
public:
|
||||||
|
/** The SkeletonData owns the bones. */
|
||||||
std::vector<BoneData*> bones;
|
std::vector<BoneData*> bones;
|
||||||
|
/** The SkeletonData owns the slots. */
|
||||||
std::vector<SlotData*> slots;
|
std::vector<SlotData*> slots;
|
||||||
|
/** The SkeletonData owns the skins. */
|
||||||
std::vector<Skin*> skins;
|
std::vector<Skin*> skins;
|
||||||
|
/** May be null. */
|
||||||
Skin *defaultSkin;
|
Skin *defaultSkin;
|
||||||
|
|
||||||
SkeletonData ();
|
SkeletonData ();
|
||||||
@ -26,7 +30,7 @@ public:
|
|||||||
SlotData* findSlot (const std::string &slotName) const;
|
SlotData* findSlot (const std::string &slotName) const;
|
||||||
int findSlotIndex (const std::string &slotName) const;
|
int findSlotIndex (const std::string &slotName) const;
|
||||||
|
|
||||||
Skin* findSkin (const std::string &skinName);
|
Skin* findSkin (const std::string &skinName) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace spine */
|
} /* namespace spine */
|
||||||
|
|||||||
@ -3,11 +3,11 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <spine/Attachment.h>
|
|
||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
class BaseSkeleton;
|
class BaseSkeleton;
|
||||||
|
class Attachment;
|
||||||
|
|
||||||
class Skin {
|
class Skin {
|
||||||
friend class BaseSkeleton;
|
friend class BaseSkeleton;
|
||||||
@ -31,8 +31,9 @@ public:
|
|||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
Skin (const std::string &name);
|
Skin (const std::string &name);
|
||||||
~Skin();
|
~Skin ();
|
||||||
|
|
||||||
|
/** The Skin owns the attachment. */
|
||||||
void addAttachment (int slotIndex, const std::string &name, Attachment *attachment);
|
void addAttachment (int slotIndex, const std::string &name, Attachment *attachment);
|
||||||
|
|
||||||
Attachment* getAttachment (int slotIndex, const std::string &name);
|
Attachment* getAttachment (int slotIndex, const std::string &name);
|
||||||
|
|||||||
@ -25,6 +25,7 @@ public:
|
|||||||
|
|
||||||
Slot (SlotData *data, BaseSkeleton *skeleton, Bone *bone);
|
Slot (SlotData *data, BaseSkeleton *skeleton, Bone *bone);
|
||||||
|
|
||||||
|
/** @param attachment May be null. */
|
||||||
void setAttachment (Attachment *attachment);
|
void setAttachment (Attachment *attachment);
|
||||||
|
|
||||||
void setAttachmentTime (float time);
|
void setAttachmentTime (float time);
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
#define SPINE_SLOTDATA_H_
|
#define SPINE_SLOTDATA_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
@ -15,23 +14,8 @@ public:
|
|||||||
float r, g, b, a;
|
float r, g, b, a;
|
||||||
std::string *attachmentName;
|
std::string *attachmentName;
|
||||||
|
|
||||||
SlotData (const std::string &name, BoneData *boneData) :
|
SlotData (const std::string &name, BoneData *boneData);
|
||||||
name(name),
|
~SlotData ();
|
||||||
boneData(boneData),
|
|
||||||
r(1),
|
|
||||||
g(1),
|
|
||||||
b(1),
|
|
||||||
a(1),
|
|
||||||
attachmentName(0) {
|
|
||||||
if (!boneData) throw std::invalid_argument("boneData cannot be null.");
|
|
||||||
}
|
|
||||||
|
|
||||||
~SlotData () {
|
|
||||||
if (attachmentName) {
|
|
||||||
delete attachmentName;
|
|
||||||
attachmentName = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace spine */
|
} /* namespace spine */
|
||||||
|
|||||||
@ -3,6 +3,12 @@
|
|||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
|
AtlasPage::~AtlasPage () {
|
||||||
|
delete texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
Atlas::Atlas (std::ifstream &file) {
|
Atlas::Atlas (std::ifstream &file) {
|
||||||
load(file);
|
load(file);
|
||||||
}
|
}
|
||||||
@ -19,7 +25,7 @@ Atlas::Atlas (const char *begin, const char *end) {
|
|||||||
load(begin, end);
|
load(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseAtlasPage* Atlas::newAtlasPage (std::string name) {
|
BaseAtlasPage* Atlas::newAtlasPage (const std::string &name) {
|
||||||
AtlasPage *page = new AtlasPage();
|
AtlasPage *page = new AtlasPage();
|
||||||
page->texture = new sf::Texture();
|
page->texture = new sf::Texture();
|
||||||
page->texture->loadFromFile(name);
|
page->texture->loadFromFile(name);
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
RegionAttachment::RegionAttachment (AtlasRegion *region) {
|
RegionAttachment::RegionAttachment (AtlasRegion *region) {
|
||||||
texture = region->page->texture; // BOZO - Resolve attachment as late as possible?
|
texture = region->page->texture;
|
||||||
int u = region->x;
|
int u = region->x;
|
||||||
int u2 = u + region->width;
|
int u2 = u + region->width;
|
||||||
int v = region->y;
|
int v = region->y;
|
||||||
@ -59,9 +59,9 @@ void RegionAttachment::draw (Slot *slot) {
|
|||||||
vertices[3].color.b = b;
|
vertices[3].color.b = b;
|
||||||
vertices[3].color.a = a;
|
vertices[3].color.a = a;
|
||||||
|
|
||||||
updateOffset(); // BOZO - Move to resolve()?
|
|
||||||
updateWorldVertices(slot->bone);
|
updateWorldVertices(slot->bone);
|
||||||
|
|
||||||
|
// SMFL doesn't handle batching for us, so we'll just force a single texture per skeleton.
|
||||||
skeleton->texture = texture;
|
skeleton->texture = texture;
|
||||||
skeleton->vertexArray.append(vertices[0]);
|
skeleton->vertexArray.append(vertices[0]);
|
||||||
skeleton->vertexArray.append(vertices[1]);
|
skeleton->vertexArray.append(vertices[1]);
|
||||||
|
|||||||
@ -5,12 +5,12 @@ namespace spine {
|
|||||||
|
|
||||||
SkeletonJson::SkeletonJson (BaseAttachmentLoader *attachmentLoader) :
|
SkeletonJson::SkeletonJson (BaseAttachmentLoader *attachmentLoader) :
|
||||||
BaseSkeletonJson(attachmentLoader) {
|
BaseSkeletonJson(attachmentLoader) {
|
||||||
flipY = true;
|
yDown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonJson::SkeletonJson (Atlas *atlas) :
|
SkeletonJson::SkeletonJson (Atlas *atlas) :
|
||||||
BaseSkeletonJson(new AtlasAttachmentLoader(atlas)) {
|
BaseSkeletonJson(new AtlasAttachmentLoader(atlas)) {
|
||||||
flipY = true;
|
yDown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace spine */
|
} /* namespace spine */
|
||||||
|
|||||||
@ -18,26 +18,19 @@ Animation::Animation (const vector<Timeline*> &timelines, float duration) :
|
|||||||
duration(duration) {
|
duration(duration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation::~Animation()
|
Animation::~Animation () {
|
||||||
{
|
for (int i = 0, n = timelines.size(); i < n; i++)
|
||||||
for (std::vector<Timeline*>::iterator iter = timelines.begin(); iter != timelines.end(); ++iter)
|
delete timelines[i];
|
||||||
{
|
|
||||||
delete *iter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::apply (BaseSkeleton *skeleton, float time, bool loop) {
|
void Animation::apply (BaseSkeleton *skeleton, float time, bool loop) const {
|
||||||
if (!skeleton) throw std::invalid_argument("skeleton cannot be null.");
|
|
||||||
|
|
||||||
if (loop && duration) time = fmodf(time, duration);
|
if (loop && duration) time = fmodf(time, duration);
|
||||||
|
|
||||||
for (int i = 0, n = timelines.size(); i < n; i++)
|
for (int i = 0, n = timelines.size(); i < n; i++)
|
||||||
timelines[i]->apply(skeleton, time, 1);
|
timelines[i]->apply(skeleton, time, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::mix (BaseSkeleton *skeleton, float time, bool loop, float alpha) {
|
void Animation::mix (BaseSkeleton *skeleton, float time, bool loop, float alpha) const {
|
||||||
if (!skeleton) throw std::invalid_argument("skeleton cannot be null.");
|
|
||||||
|
|
||||||
if (loop && duration) time = fmodf(time, duration);
|
if (loop && duration) time = fmodf(time, duration);
|
||||||
|
|
||||||
for (int i = 0, n = timelines.size(); i < n; i++)
|
for (int i = 0, n = timelines.size(); i < n; i++)
|
||||||
@ -88,7 +81,7 @@ void CurveTimeline::setCurve (int keyframeIndex, float cx1, float cy1, float cx2
|
|||||||
curves[i + 5] = tmp2y * pre5;
|
curves[i + 5] = tmp2y * pre5;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CurveTimeline::getCurvePercent (int keyframeIndex, float percent) {
|
float CurveTimeline::getCurvePercent (int keyframeIndex, float percent) const {
|
||||||
int curveIndex = keyframeIndex * 6;
|
int curveIndex = keyframeIndex * 6;
|
||||||
float dfx = curves[curveIndex];
|
float dfx = curves[curveIndex];
|
||||||
if (dfx == LINEAR) return percent;
|
if (dfx == LINEAR) return percent;
|
||||||
@ -162,11 +155,11 @@ RotateTimeline::~RotateTimeline () {
|
|||||||
delete[] frames;
|
delete[] frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
float RotateTimeline::getDuration () {
|
float RotateTimeline::getDuration () const {
|
||||||
return frames[framesLength - 2];
|
return frames[framesLength - 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
int RotateTimeline::getKeyframeCount () {
|
int RotateTimeline::getKeyframeCount () const {
|
||||||
return framesLength / 2;
|
return framesLength / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +169,7 @@ void RotateTimeline::setKeyframe (int keyframeIndex, float time, float value) {
|
|||||||
frames[keyframeIndex + 1] = value;
|
frames[keyframeIndex + 1] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotateTimeline::apply (BaseSkeleton *skeleton, float time, float alpha) {
|
void RotateTimeline::apply (BaseSkeleton *skeleton, float time, float alpha) const {
|
||||||
if (time < frames[0]) return; // Time is before first frame.
|
if (time < frames[0]) return; // Time is before first frame.
|
||||||
|
|
||||||
Bone *bone = skeleton->bones[boneIndex];
|
Bone *bone = skeleton->bones[boneIndex];
|
||||||
@ -233,11 +226,11 @@ TranslateTimeline::~TranslateTimeline () {
|
|||||||
delete[] frames;
|
delete[] frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
float TranslateTimeline::getDuration () {
|
float TranslateTimeline::getDuration () const {
|
||||||
return frames[framesLength - 3];
|
return frames[framesLength - 3];
|
||||||
}
|
}
|
||||||
|
|
||||||
int TranslateTimeline::getKeyframeCount () {
|
int TranslateTimeline::getKeyframeCount () const {
|
||||||
return framesLength / 3;
|
return framesLength / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +241,7 @@ void TranslateTimeline::setKeyframe (int keyframeIndex, float time, float x, flo
|
|||||||
frames[keyframeIndex + 2] = y;
|
frames[keyframeIndex + 2] = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TranslateTimeline::apply (BaseSkeleton *skeleton, float time, float alpha) {
|
void TranslateTimeline::apply (BaseSkeleton *skeleton, float time, float alpha) const {
|
||||||
if (time < frames[0]) return; // Time is before first frame.
|
if (time < frames[0]) return; // Time is before first frame.
|
||||||
|
|
||||||
Bone *bone = skeleton->bones[boneIndex];
|
Bone *bone = skeleton->bones[boneIndex];
|
||||||
@ -281,7 +274,7 @@ ScaleTimeline::ScaleTimeline (int keyframeCount) :
|
|||||||
TranslateTimeline(keyframeCount) {
|
TranslateTimeline(keyframeCount) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScaleTimeline::apply (BaseSkeleton *skeleton, float time, float alpha) {
|
void ScaleTimeline::apply (BaseSkeleton *skeleton, float time, float alpha) const {
|
||||||
if (time < frames[0]) return; // Time is before first frame.
|
if (time < frames[0]) return; // Time is before first frame.
|
||||||
|
|
||||||
Bone *bone = skeleton->bones[boneIndex];
|
Bone *bone = skeleton->bones[boneIndex];
|
||||||
@ -329,11 +322,11 @@ ColorTimeline::~ColorTimeline () {
|
|||||||
delete[] frames;
|
delete[] frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ColorTimeline::getDuration () {
|
float ColorTimeline::getDuration () const {
|
||||||
return frames[framesLength - 5];
|
return frames[framesLength - 5];
|
||||||
}
|
}
|
||||||
|
|
||||||
int ColorTimeline::getKeyframeCount () {
|
int ColorTimeline::getKeyframeCount () const {
|
||||||
return framesLength / 5;
|
return framesLength / 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +339,7 @@ void ColorTimeline::setKeyframe (int keyframeIndex, float time, float r, float g
|
|||||||
frames[keyframeIndex + 4] = a;
|
frames[keyframeIndex + 4] = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorTimeline::apply (BaseSkeleton *skeleton, float time, float alpha) {
|
void ColorTimeline::apply (BaseSkeleton *skeleton, float time, float alpha) const {
|
||||||
if (time < frames[0]) return; // Time is before first frame.
|
if (time < frames[0]) return; // Time is before first frame.
|
||||||
|
|
||||||
Slot *slot = skeleton->slots[slotIndex];
|
Slot *slot = skeleton->slots[slotIndex];
|
||||||
@ -410,21 +403,21 @@ AttachmentTimeline::~AttachmentTimeline () {
|
|||||||
delete[] attachmentNames;
|
delete[] attachmentNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
float AttachmentTimeline::getDuration () {
|
float AttachmentTimeline::getDuration () const {
|
||||||
return frames[framesLength - 1];
|
return frames[framesLength - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
int AttachmentTimeline::getKeyframeCount () {
|
int AttachmentTimeline::getKeyframeCount () const {
|
||||||
return framesLength;
|
return framesLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttachmentTimeline::setKeyframe (int keyframeIndex, float time, const string &attachmentName) {
|
void AttachmentTimeline::setKeyframe (int keyframeIndex, float time, string *attachmentName) {
|
||||||
frames[keyframeIndex] = time;
|
frames[keyframeIndex] = time;
|
||||||
if (attachmentNames[keyframeIndex]) delete attachmentNames[keyframeIndex];
|
if (attachmentNames[keyframeIndex]) delete attachmentNames[keyframeIndex];
|
||||||
attachmentNames[keyframeIndex] = attachmentName.length() == 0 ? 0 : new string(attachmentName);
|
attachmentNames[keyframeIndex] = attachmentName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttachmentTimeline::apply (BaseSkeleton *skeleton, float time, float alpha) {
|
void AttachmentTimeline::apply (BaseSkeleton *skeleton, float time, float alpha) const {
|
||||||
if (time < frames[0]) return; // Time is before first frame.
|
if (time < frames[0]) return; // Time is before first frame.
|
||||||
|
|
||||||
int frameIndex;
|
int frameIndex;
|
||||||
|
|||||||
@ -105,7 +105,7 @@ void BaseAtlas::load (const char *current, const char *end) {
|
|||||||
|
|
||||||
string value;
|
string value;
|
||||||
string tuple[4];
|
string tuple[4];
|
||||||
BaseAtlasPage *page = NULL;
|
BaseAtlasPage *page = 0;
|
||||||
while (current != end) {
|
while (current != end) {
|
||||||
readLine(current, end, value);
|
readLine(current, end, value);
|
||||||
trim(value);
|
trim(value);
|
||||||
@ -185,6 +185,11 @@ BaseAtlasRegion* BaseAtlas::findRegion (const std::string &name) {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
BaseAtlasRegion::BaseAtlasRegion () :
|
||||||
|
splits(0),
|
||||||
|
pads(0) {
|
||||||
|
}
|
||||||
|
|
||||||
BaseAtlasRegion::~BaseAtlasRegion () {
|
BaseAtlasRegion::~BaseAtlasRegion () {
|
||||||
if (splits) delete splits;
|
if (splits) delete splits;
|
||||||
if (pads) delete pads;
|
if (pads) delete pads;
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <spine/BaseRegionAttachment.h>
|
#include <spine/BaseRegionAttachment.h>
|
||||||
|
|
||||||
#ifndef M_PI // fix for windows removing precious information
|
#ifndef M_PI
|
||||||
#define M_PI 3.14159265358979323846
|
#define M_PI 3.1415926535897932385
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace spine {
|
namespace spine {
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <spine/BaseSkeleton.h>
|
#include <spine/BaseSkeleton.h>
|
||||||
#include <spine/SkeletonData.h>
|
#include <spine/SkeletonData.h>
|
||||||
@ -92,25 +93,25 @@ Bone* BaseSkeleton::getRootBone () const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bone* BaseSkeleton::findBone (const string &boneName) const {
|
Bone* BaseSkeleton::findBone (const string &boneName) const {
|
||||||
for (unsigned int i = 0; i < bones.size(); i++)
|
for (int i = 0, n = bones.size(); i < n; i++)
|
||||||
if (data->bones[i]->name == boneName) return bones[i];
|
if (data->bones[i]->name == boneName) return bones[i];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BaseSkeleton::findBoneIndex (const string &boneName) const {
|
int BaseSkeleton::findBoneIndex (const string &boneName) const {
|
||||||
for (unsigned int i = 0; i < bones.size(); i++)
|
for (int i = 0, n = bones.size(); i < n; i++)
|
||||||
if (data->bones[i]->name == boneName) return i;
|
if (data->bones[i]->name == boneName) return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Slot* BaseSkeleton::findSlot (const string &slotName) const {
|
Slot* BaseSkeleton::findSlot (const string &slotName) const {
|
||||||
for (unsigned int i = 0; i < slots.size(); i++)
|
for (int i = 0, n = slots.size(); i < n; i++)
|
||||||
if (data->slots[i]->name == slotName) return slots[i];
|
if (data->slots[i]->name == slotName) return slots[i];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BaseSkeleton::findSlotIndex (const string &slotName) const {
|
int BaseSkeleton::findSlotIndex (const string &slotName) const {
|
||||||
for (unsigned int i = 0; i < slots.size(); i++)
|
for (int i = 0, n = slots.size(); i < n; i++)
|
||||||
if (data->slots[i]->name == slotName) return i;
|
if (data->slots[i]->name == slotName) return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -126,11 +127,11 @@ void BaseSkeleton::setSkin (Skin *newSkin) {
|
|||||||
skin = newSkin;
|
skin = newSkin;
|
||||||
}
|
}
|
||||||
|
|
||||||
Attachment* BaseSkeleton::getAttachment (const string &slotName, const string &attachmentName) {
|
Attachment* BaseSkeleton::getAttachment (const string &slotName, const string &attachmentName) const {
|
||||||
return getAttachment(data->findSlotIndex(slotName), attachmentName);
|
return getAttachment(data->findSlotIndex(slotName), attachmentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Attachment* BaseSkeleton::getAttachment (int slotIndex, const string &attachmentName) {
|
Attachment* BaseSkeleton::getAttachment (int slotIndex, const string &attachmentName) const {
|
||||||
if (data->defaultSkin) {
|
if (data->defaultSkin) {
|
||||||
Attachment *attachment = data->defaultSkin->getAttachment(slotIndex, attachmentName);
|
Attachment *attachment = data->defaultSkin->getAttachment(slotIndex, attachmentName);
|
||||||
if (attachment) return attachment;
|
if (attachment) return attachment;
|
||||||
|
|||||||
@ -32,12 +32,12 @@ static float toColor (const string &value, int index) {
|
|||||||
BaseSkeletonJson::BaseSkeletonJson (BaseAttachmentLoader *attachmentLoader) :
|
BaseSkeletonJson::BaseSkeletonJson (BaseAttachmentLoader *attachmentLoader) :
|
||||||
attachmentLoader(attachmentLoader),
|
attachmentLoader(attachmentLoader),
|
||||||
scale(1),
|
scale(1),
|
||||||
flipY(false) {
|
yDown(false) {
|
||||||
|
if (!attachmentLoader) throw invalid_argument("attachmentLoader cannot be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseSkeletonJson::~BaseSkeletonJson () {
|
BaseSkeletonJson::~BaseSkeletonJson () {
|
||||||
if (attachmentLoader)
|
delete attachmentLoader;
|
||||||
delete attachmentLoader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonData* BaseSkeletonJson::readSkeletonData (std::ifstream &file) const {
|
SkeletonData* BaseSkeletonJson::readSkeletonData (std::ifstream &file) const {
|
||||||
@ -76,7 +76,7 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
|||||||
|
|
||||||
Json::Value bones = root["bones"];
|
Json::Value bones = root["bones"];
|
||||||
skeletonData->bones.reserve(bones.size());
|
skeletonData->bones.reserve(bones.size());
|
||||||
for (unsigned int i = 0; i < bones.size(); ++i) {
|
for (int i = 0, n = bones.size(); i < n; ++i) {
|
||||||
Json::Value boneMap = bones[i];
|
Json::Value boneMap = bones[i];
|
||||||
string boneName = boneMap["name"].asString();
|
string boneName = boneMap["name"].asString();
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
|||||||
boneData->rotation = (float)(boneMap.get("rotation", 0).asDouble());
|
boneData->rotation = (float)(boneMap.get("rotation", 0).asDouble());
|
||||||
boneData->scaleX = (float)(boneMap.get("scaleX", 1).asDouble());
|
boneData->scaleX = (float)(boneMap.get("scaleX", 1).asDouble());
|
||||||
boneData->scaleY = (float)(boneMap.get("scaleY", 1).asDouble());
|
boneData->scaleY = (float)(boneMap.get("scaleY", 1).asDouble());
|
||||||
boneData->flipY = flipY;
|
boneData->yDown = yDown;
|
||||||
|
|
||||||
skeletonData->bones.push_back(boneData);
|
skeletonData->bones.push_back(boneData);
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
|||||||
Json::Value slots = root["slots"];
|
Json::Value slots = root["slots"];
|
||||||
if (!slots.isNull()) {
|
if (!slots.isNull()) {
|
||||||
skeletonData->slots.reserve(slots.size());
|
skeletonData->slots.reserve(slots.size());
|
||||||
for (unsigned int i = 0; i < slots.size(); ++i) {
|
for (int i = 0, n = slots.size(); i < n; ++i) {
|
||||||
Json::Value slotMap = slots[i];
|
Json::Value slotMap = slots[i];
|
||||||
string slotName = slotMap["name"].asString();
|
string slotName = slotMap["name"].asString();
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
|||||||
Json::Value skinsMap = root["skins"];
|
Json::Value skinsMap = root["skins"];
|
||||||
vector<string> skinNames = skinsMap.getMemberNames();
|
vector<string> skinNames = skinsMap.getMemberNames();
|
||||||
skeletonData->skins.reserve(skinNames.size());
|
skeletonData->skins.reserve(skinNames.size());
|
||||||
for (unsigned int i = 0; i < skinNames.size(); i++) {
|
for (int i = 0, n = skinNames.size(); i < n; i++) {
|
||||||
string skinName = skinNames[i];
|
string skinName = skinNames[i];
|
||||||
Skin *skin = new Skin(skinName);
|
Skin *skin = new Skin(skinName);
|
||||||
skeletonData->skins.push_back(skin);
|
skeletonData->skins.push_back(skin);
|
||||||
@ -136,13 +136,13 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
|||||||
|
|
||||||
Json::Value slotMap = skinsMap[skinName];
|
Json::Value slotMap = skinsMap[skinName];
|
||||||
vector<string> slotNames = slotMap.getMemberNames();
|
vector<string> slotNames = slotMap.getMemberNames();
|
||||||
for (unsigned int i = 0; i < slotNames.size(); i++) {
|
for (int i = 0, n = slotNames.size(); i < n; i++) {
|
||||||
string slotName = slotNames[i];
|
string slotName = slotNames[i];
|
||||||
int slotIndex = skeletonData->findSlotIndex(slotName);
|
int slotIndex = skeletonData->findSlotIndex(slotName);
|
||||||
|
|
||||||
Json::Value attachmentsMap = slotMap[slotName];
|
Json::Value attachmentsMap = slotMap[slotName];
|
||||||
vector<string> attachmentNames = attachmentsMap.getMemberNames();
|
vector<string> attachmentNames = attachmentsMap.getMemberNames();
|
||||||
for (unsigned int i = 0; i < attachmentNames.size(); i++) {
|
for (int i = 0, n = attachmentNames.size(); i < n; i++) {
|
||||||
string attachmentName = attachmentNames[i];
|
string attachmentName = attachmentNames[i];
|
||||||
Json::Value attachmentMap = attachmentsMap[attachmentName];
|
Json::Value attachmentMap = attachmentsMap[attachmentName];
|
||||||
|
|
||||||
@ -167,6 +167,7 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
|||||||
regionAttachment->rotation = (float)(attachmentMap.get("rotation", 0).asDouble());
|
regionAttachment->rotation = (float)(attachmentMap.get("rotation", 0).asDouble());
|
||||||
regionAttachment->width = (float)(attachmentMap.get("width", 32).asDouble() * scale);
|
regionAttachment->width = (float)(attachmentMap.get("width", 32).asDouble() * scale);
|
||||||
regionAttachment->height = (float)(attachmentMap.get("height", 32).asDouble() * scale);
|
regionAttachment->height = (float)(attachmentMap.get("height", 32).asDouble() * scale);
|
||||||
|
regionAttachment->updateOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
skin->addAttachment(slotIndex, attachmentName, attachment);
|
skin->addAttachment(slotIndex, attachmentName, attachment);
|
||||||
@ -205,7 +206,8 @@ static void readCurve (CurveTimeline *timeline, int keyframeIndex, const Json::V
|
|||||||
if (curve.isString() && curve.asString() == "stepped")
|
if (curve.isString() && curve.asString() == "stepped")
|
||||||
timeline->setStepped(keyframeIndex);
|
timeline->setStepped(keyframeIndex);
|
||||||
else if (curve.isArray())
|
else if (curve.isArray())
|
||||||
timeline->setCurve(keyframeIndex, (float)curve[0u].asDouble(), (float)curve[1u].asDouble(), (float)curve[2u].asDouble(), (float)curve[3u].asDouble());
|
timeline->setCurve(keyframeIndex, (float)curve[0u].asDouble(), (float)curve[1u].asDouble(), (float)curve[2u].asDouble(),
|
||||||
|
(float)curve[3u].asDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end, const SkeletonData *skeletonData) const {
|
Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end, const SkeletonData *skeletonData) const {
|
||||||
@ -229,14 +231,14 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
|||||||
|
|
||||||
Json::Value bones = root["bones"];
|
Json::Value bones = root["bones"];
|
||||||
vector<string> boneNames = bones.getMemberNames();
|
vector<string> boneNames = bones.getMemberNames();
|
||||||
for (unsigned int i = 0; i < boneNames.size(); i++) {
|
for (int i = 0, n = boneNames.size(); i < n; i++) {
|
||||||
string boneName = boneNames[i];
|
string boneName = boneNames[i];
|
||||||
int boneIndex = skeletonData->findBoneIndex(boneName);
|
int boneIndex = skeletonData->findBoneIndex(boneName);
|
||||||
if (boneIndex == -1) throw runtime_error("Bone not found: " + boneName);
|
if (boneIndex == -1) throw runtime_error("Bone not found: " + boneName);
|
||||||
|
|
||||||
Json::Value timelineMap = bones[boneName];
|
Json::Value timelineMap = bones[boneName];
|
||||||
vector<string> timelineNames = timelineMap.getMemberNames();
|
vector<string> timelineNames = timelineMap.getMemberNames();
|
||||||
for (unsigned int i = 0; i < timelineNames.size(); i++) {
|
for (int i = 0, n = timelineNames.size(); i < n; i++) {
|
||||||
string timelineName = timelineNames[i];
|
string timelineName = timelineNames[i];
|
||||||
Json::Value values = timelineMap[timelineName];
|
Json::Value values = timelineMap[timelineName];
|
||||||
|
|
||||||
@ -245,7 +247,7 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
|||||||
timeline->boneIndex = boneIndex;
|
timeline->boneIndex = boneIndex;
|
||||||
|
|
||||||
int keyframeIndex = 0;
|
int keyframeIndex = 0;
|
||||||
for (unsigned int i = 0; i < values.size(); i++) {
|
for (int i = 0, n = values.size(); i < n; i++) {
|
||||||
Json::Value valueMap = values[i];
|
Json::Value valueMap = values[i];
|
||||||
|
|
||||||
float time = (float)valueMap["time"].asDouble();
|
float time = (float)valueMap["time"].asDouble();
|
||||||
@ -268,10 +270,9 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
|||||||
timeline->boneIndex = boneIndex;
|
timeline->boneIndex = boneIndex;
|
||||||
|
|
||||||
int keyframeIndex = 0;
|
int keyframeIndex = 0;
|
||||||
for (unsigned int i = 0; i < values.size(); i++) {
|
for (int i = 0, n = values.size(); i < n; i++) {
|
||||||
Json::Value valueMap = values[i];
|
Json::Value valueMap = values[i];
|
||||||
|
|
||||||
float time = (float)valueMap["time"].asDouble();
|
|
||||||
timeline->setKeyframe(keyframeIndex, //
|
timeline->setKeyframe(keyframeIndex, //
|
||||||
(float)valueMap["time"].asDouble(), //
|
(float)valueMap["time"].asDouble(), //
|
||||||
(float)valueMap.get("x", 0).asDouble() * timelineScale, //
|
(float)valueMap.get("x", 0).asDouble() * timelineScale, //
|
||||||
@ -291,14 +292,14 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
|||||||
Json::Value slots = root["slots"];
|
Json::Value slots = root["slots"];
|
||||||
if (!slots.isNull()) {
|
if (!slots.isNull()) {
|
||||||
vector<string> slotNames = slots.getMemberNames();
|
vector<string> slotNames = slots.getMemberNames();
|
||||||
for (unsigned int i = 0; i < slotNames.size(); i++) {
|
for (int i = 0, n = slotNames.size(); i < n; i++) {
|
||||||
string slotName = slotNames[i];
|
string slotName = slotNames[i];
|
||||||
int slotIndex = skeletonData->findSlotIndex(slotName);
|
int slotIndex = skeletonData->findSlotIndex(slotName);
|
||||||
if (slotIndex == -1) throw runtime_error("Slot not found: " + slotName);
|
if (slotIndex == -1) throw runtime_error("Slot not found: " + slotName);
|
||||||
|
|
||||||
Json::Value timelineMap = slots[slotName];
|
Json::Value timelineMap = slots[slotName];
|
||||||
vector<string> timelineNames = timelineMap.getMemberNames();
|
vector<string> timelineNames = timelineMap.getMemberNames();
|
||||||
for (unsigned int i = 0; i < timelineNames.size(); i++) {
|
for (int i = 0, n = timelineNames.size(); i < n; i++) {
|
||||||
string timelineName = timelineNames[i];
|
string timelineName = timelineNames[i];
|
||||||
Json::Value values = timelineMap[timelineName];
|
Json::Value values = timelineMap[timelineName];
|
||||||
|
|
||||||
@ -307,7 +308,7 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
|||||||
timeline->slotIndex = slotIndex;
|
timeline->slotIndex = slotIndex;
|
||||||
|
|
||||||
int keyframeIndex = 0;
|
int keyframeIndex = 0;
|
||||||
for (unsigned int i = 0; i < values.size(); i++) {
|
for (int i = 0, n = values.size(); i < n; i++) {
|
||||||
Json::Value valueMap = values[i];
|
Json::Value valueMap = values[i];
|
||||||
|
|
||||||
string s = valueMap["color"].asString();
|
string s = valueMap["color"].asString();
|
||||||
@ -324,11 +325,12 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
|||||||
timeline->slotIndex = slotIndex;
|
timeline->slotIndex = slotIndex;
|
||||||
|
|
||||||
int keyframeIndex = 0;
|
int keyframeIndex = 0;
|
||||||
for (unsigned int i = 0; i < values.size(); i++) {
|
for (int i = 0, n = values.size(); i < n; i++) {
|
||||||
Json::Value valueMap = values[i];
|
Json::Value valueMap = values[i];
|
||||||
|
|
||||||
Json::Value name = valueMap["name"];
|
Json::Value nameValue = valueMap["name"];
|
||||||
timeline->setKeyframe(keyframeIndex++, (float)valueMap["time"].asDouble(), name.isNull() ? "" : name.asString());
|
timeline->setKeyframe(keyframeIndex++, (float)valueMap["time"].asDouble(),
|
||||||
|
nameValue.isNull() ? 0 : new string(nameValue.asString()));
|
||||||
}
|
}
|
||||||
timelines.push_back(timeline);
|
timelines.push_back(timeline);
|
||||||
if (timeline->getDuration() > duration) duration = timeline->getDuration();
|
if (timeline->getDuration() > duration) duration = timeline->getDuration();
|
||||||
|
|||||||
@ -58,7 +58,7 @@ void Bone::updateWorldTransform (bool flipX, bool flipY) {
|
|||||||
m10 = -m10;
|
m10 = -m10;
|
||||||
m11 = -m11;
|
m11 = -m11;
|
||||||
}
|
}
|
||||||
if (data->flipY) {
|
if (data->yDown) {
|
||||||
m10 = -m10;
|
m10 = -m10;
|
||||||
m11 = -m11;
|
m11 = -m11;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,31 +21,31 @@ SkeletonData::~SkeletonData () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BoneData* SkeletonData::findBone (const string &boneName) const {
|
BoneData* SkeletonData::findBone (const string &boneName) const {
|
||||||
for (unsigned int i = 0; i < bones.size(); i++)
|
for (int i = 0, n = bones.size(); i < n; i++)
|
||||||
if (bones[i]->name == boneName) return bones[i];
|
if (bones[i]->name == boneName) return bones[i];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SkeletonData::findBoneIndex (const string &boneName) const {
|
int SkeletonData::findBoneIndex (const string &boneName) const {
|
||||||
for (unsigned int i = 0; i < bones.size(); i++)
|
for (int i = 0, n = bones.size(); i < n; i++)
|
||||||
if (bones[i]->name == boneName) return i;
|
if (bones[i]->name == boneName) return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SlotData* SkeletonData::findSlot (const string &slotName) const {
|
SlotData* SkeletonData::findSlot (const string &slotName) const {
|
||||||
for (unsigned int i = 0; i < slots.size(); i++)
|
for (int i = 0, n = slots.size(); i < n; i++)
|
||||||
if (slots[i]->name == slotName) return slots[i];
|
if (slots[i]->name == slotName) return slots[i];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SkeletonData::findSlotIndex (const string &slotName) const {
|
int SkeletonData::findSlotIndex (const string &slotName) const {
|
||||||
for (unsigned int i = 0; i < slots.size(); i++)
|
for (int i = 0, n = slots.size(); i < n; i++)
|
||||||
if (slots[i]->name == slotName) return i;
|
if (slots[i]->name == slotName) return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Skin* SkeletonData::findSkin (const string &skinName) {
|
Skin* SkeletonData::findSkin (const string &skinName) const {
|
||||||
for (unsigned int i = 0; i < skins.size(); i++)
|
for (int i = 0, n = skins.size(); i < n; i++)
|
||||||
if (skins[i]->name == skinName) return skins[i];
|
if (skins[i]->name == skinName) return skins[i];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#include <stdexcept>
|
||||||
|
#include <spine/Attachment.h>
|
||||||
#include <spine/Skin.h>
|
#include <spine/Skin.h>
|
||||||
#include <spine/BaseSkeleton.h>
|
#include <spine/BaseSkeleton.h>
|
||||||
#include <spine/Slot.h>
|
#include <spine/Slot.h>
|
||||||
@ -8,14 +10,13 @@ Skin::Skin (const std::string &name) :
|
|||||||
name(name) {
|
name(name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Skin::~Skin()
|
Skin::~Skin () {
|
||||||
{
|
for (std::map<Key, Attachment*>::iterator iter = attachments.begin(); iter != attachments.end(); iter++)
|
||||||
for (std::map<Key, Attachment*>::iterator iter = attachments.begin(); iter != attachments.end(); ++iter) {
|
delete iter->second;
|
||||||
delete iter->second;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skin::addAttachment (int slotIndex, const std::string &name, Attachment *attachment) {
|
void Skin::addAttachment (int slotIndex, const std::string &name, Attachment *attachment) {
|
||||||
|
if (!attachment) throw std::invalid_argument("attachment cannot be null.");
|
||||||
Key key = {slotIndex, name};
|
Key key = {slotIndex, name};
|
||||||
attachments[key] = attachment;
|
attachments[key] = attachment;
|
||||||
}
|
}
|
||||||
@ -26,7 +27,6 @@ Attachment* Skin::getAttachment (int slotIndex, const std::string &name) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Attach all attachments from this skin if the corresponding attachment from the old skin is currently attached. */
|
|
||||||
void Skin::attachAll (BaseSkeleton *skeleton, Skin *oldSkin) {
|
void Skin::attachAll (BaseSkeleton *skeleton, Skin *oldSkin) {
|
||||||
for (std::map<Key, Attachment*>::iterator iter = attachments.begin(); iter != attachments.end(); iter++) {
|
for (std::map<Key, Attachment*>::iterator iter = attachments.begin(); iter != attachments.end(); iter++) {
|
||||||
const Key key = iter->first;
|
const Key key = iter->first;
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#include <stdexcept>
|
||||||
#include <spine/Slot.h>
|
#include <spine/Slot.h>
|
||||||
#include <spine/SlotData.h>
|
#include <spine/SlotData.h>
|
||||||
#include <spine/BaseSkeleton.h>
|
#include <spine/BaseSkeleton.h>
|
||||||
@ -6,6 +7,7 @@
|
|||||||
namespace spine {
|
namespace spine {
|
||||||
|
|
||||||
Slot::Slot (SlotData *data, BaseSkeleton *skeleton, Bone *bone) :
|
Slot::Slot (SlotData *data, BaseSkeleton *skeleton, Bone *bone) :
|
||||||
|
attachmentTime(0),
|
||||||
data(data),
|
data(data),
|
||||||
skeleton(skeleton),
|
skeleton(skeleton),
|
||||||
bone(bone),
|
bone(bone),
|
||||||
@ -13,8 +15,7 @@ Slot::Slot (SlotData *data, BaseSkeleton *skeleton, Bone *bone) :
|
|||||||
g(1),
|
g(1),
|
||||||
b(1),
|
b(1),
|
||||||
a(1),
|
a(1),
|
||||||
attachment(0),
|
attachment(0) {
|
||||||
attachmentTime(0) {
|
|
||||||
if (!data) throw std::invalid_argument("data cannot be null.");
|
if (!data) throw std::invalid_argument("data cannot be null.");
|
||||||
if (!skeleton) throw std::invalid_argument("skeleton cannot be null.");
|
if (!skeleton) throw std::invalid_argument("skeleton cannot be null.");
|
||||||
if (!bone) throw std::invalid_argument("bone cannot be null.");
|
if (!bone) throw std::invalid_argument("bone cannot be null.");
|
||||||
|
|||||||
25
spine-cpp/src/spine/SlotData.cpp
Normal file
25
spine-cpp/src/spine/SlotData.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include <stdexcept>
|
||||||
|
#include <spine/SlotData.h>
|
||||||
|
|
||||||
|
namespace spine {
|
||||||
|
|
||||||
|
SlotData::SlotData (const std::string &name, BoneData *boneData) :
|
||||||
|
name(name),
|
||||||
|
boneData(boneData),
|
||||||
|
r(1),
|
||||||
|
g(1),
|
||||||
|
b(1),
|
||||||
|
a(1),
|
||||||
|
attachmentName(0) {
|
||||||
|
if (!boneData) throw std::invalid_argument("boneData cannot be null.");
|
||||||
|
}
|
||||||
|
|
||||||
|
SlotData::~SlotData () {
|
||||||
|
if (attachmentName) {
|
||||||
|
delete attachmentName;
|
||||||
|
attachmentName = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/* namespace spine */
|
||||||
Loading…
x
Reference in New Issue
Block a user