Browse Source

Documented memory ownership.
Clean up and minor improvements.

NathanSweet 12 years ago
parent
commit
a1ad55f8a1

+ 1 - 1
spine-cpp/.cproject

@@ -31,7 +31,7 @@
 									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/includes}&quot;"/>
 									<listOptionValue builtIn="false" value="&quot;C:\Users\Nate\Desktop\SFML-2.0-rc\include&quot;"/>
 								</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"/>
 								<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1445618618" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
 							</tool>

+ 0 - 22
spine-cpp/data/spineboy-walk.json

@@ -274,27 +274,5 @@
 			{ "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" }
-		]
-	}
 }
 }

+ 2 - 4
spine-cpp/includes/spine-sfml/Atlas.h

@@ -8,9 +8,7 @@ namespace spine {
 
 class AtlasPage: public BaseAtlasPage {
 public:
-	~AtlasPage(){
-		delete texture;
-	}
+	~AtlasPage ();
 
 	sf::Texture *texture;
 };
@@ -34,7 +32,7 @@ public:
 	AtlasRegion* findRegion (const std::string &name);
 
 private:
-	virtual BaseAtlasPage* newAtlasPage (std::string name);
+	virtual BaseAtlasPage* newAtlasPage (const std::string &name);
 	virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage* page);
 };
 

+ 1 - 1
spine-cpp/includes/spine-sfml/Skeleton.h

@@ -9,7 +9,7 @@ namespace spine {
 class Skeleton: public BaseSkeleton, public sf::Drawable {
 public:
 	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);
 

+ 1 - 0
spine-cpp/includes/spine-sfml/SkeletonJson.h

@@ -10,6 +10,7 @@ class Atlas;
 class SkeletonJson: public BaseSkeletonJson {
 public:
 	SkeletonJson (Atlas *atlas);
+	/** The SkeletonJson owns the attachmentLoader */
 	SkeletonJson (BaseAttachmentLoader *attachmentLoader);
 };
 

+ 23 - 22
spine-cpp/includes/spine/Animation.h

@@ -15,10 +15,10 @@ public:
 	float duration;
 
 	Animation (const std::vector<Timeline*> &timelines, float duration);
-  ~Animation();
+	~Animation ();
 
-	void apply (BaseSkeleton *skeleton, float time, bool loop);
-	void mix (BaseSkeleton *skeleton, float time, bool loop, float alpha);
+	void apply (BaseSkeleton *skeleton, float time, bool loop) const;
+	void mix (BaseSkeleton *skeleton, float time, bool loop, float alpha) const;
 };
 
 //
@@ -28,11 +28,11 @@ public:
 	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. */
 	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);
 	virtual ~RotateTimeline ();
 
-	virtual float getDuration ();
-	virtual int getKeyframeCount ();
-	virtual void apply (BaseSkeleton *skeleton, float time, float alpha);
+	virtual float getDuration () const;
+	virtual int getKeyframeCount () const;
+	virtual void apply (BaseSkeleton *skeleton, float time, float alpha) const;
 
 	void setKeyframe (int keyframeIndex, float time, float value);
 };
@@ -85,9 +85,9 @@ public:
 	TranslateTimeline (int keyframeCount);
 	virtual ~TranslateTimeline ();
 
-	virtual float getDuration ();
-	virtual int getKeyframeCount ();
-	virtual void apply (BaseSkeleton *skeleton, float time, float alpha);
+	virtual float getDuration () const;
+	virtual int getKeyframeCount () const;
+	virtual void apply (BaseSkeleton *skeleton, float time, float alpha) const;
 
 	void setKeyframe (int keyframeIndex, float time, float x, float y);
 };
@@ -98,7 +98,7 @@ class ScaleTimeline: public TranslateTimeline {
 public:
 	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);
 	virtual ~ColorTimeline ();
 
-	virtual float getDuration ();
-	virtual int getKeyframeCount ();
-	virtual void apply (BaseSkeleton *skeleton, float time, float alpha);
+	virtual float getDuration () const;
+	virtual int getKeyframeCount () const;
+	virtual void apply (BaseSkeleton *skeleton, float time, float alpha) const;
 
 	void setKeyframe (int keyframeIndex, float time, float r, float g, float b, float a);
 };
@@ -131,12 +131,13 @@ public:
 	AttachmentTimeline (int keyframeCount);
 	virtual ~AttachmentTimeline ();
 
-	virtual float getDuration ();
-	virtual int getKeyframeCount ();
-	virtual void apply (BaseSkeleton *skeleton, float time, float alpha);
+	virtual float getDuration () const;
+	virtual int getKeyframeCount () const;
+	virtual void apply (BaseSkeleton *skeleton, float time, float alpha) const;
 
-	/** @param attachmentName Pass an empty string to clear the image for a slot. */
-	void setKeyframe (int keyframeIndex, float time, const std::string &attachmentName);
+	/** The AttachmentTimeline owns the attachmentName.
+	 * @param attachmentName May be null to clear the image for a slot. */
+	void setKeyframe (int keyframeIndex, float time, std::string *attachmentName);
 };
 
 } /* namespace spine */

+ 2 - 3
spine-cpp/includes/spine/BaseAtlas.h

@@ -4,7 +4,6 @@
 #include <istream>
 #include <string>
 #include <vector>
-#include <map>
 
 namespace spine {
 
@@ -26,7 +25,7 @@ public:
 	virtual BaseAtlasRegion* findRegion (const std::string &name);
 
 private:
-	virtual BaseAtlasPage* newAtlasPage (std::string name) = 0;
+	virtual BaseAtlasPage* newAtlasPage (const std::string &name) = 0;
 	virtual BaseAtlasRegion* newAtlasRegion (BaseAtlasPage *page) = 0;
 };
 
@@ -71,7 +70,7 @@ public:
 	int *splits;
 	int *pads;
 
-  BaseAtlasRegion() : splits(0), pads(0) {}
+	BaseAtlasRegion ();
 	virtual ~BaseAtlasRegion ();
 };
 

+ 2 - 2
spine-cpp/includes/spine/BaseAttachmentLoader.h

@@ -1,10 +1,10 @@
 #ifndef SPINE_BASEATTACHMENTLOADER_H_
 #define SPINE_BASEATTACHMENTLOADER_H_
 
-#include <spine/Attachment.h>
-
 namespace spine {
 
+class Attachment;
+
 enum AttachmentType {
 	region, regionSequence
 };

+ 5 - 3
spine-cpp/includes/spine/BaseSkeleton.h

@@ -23,6 +23,7 @@ public:
 	float time;
 	bool flipX, flipY;
 
+	/** The BaseSkeleton owns the SkeletonData. */
 	BaseSkeleton (SkeletonData *data);
 	virtual ~BaseSkeleton ();
 
@@ -40,10 +41,11 @@ public:
 	int findSlotIndex (const std::string &slotName) const;
 
 	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 (int slotIndex, const std::string &attachmentName);
+	Attachment* getAttachment (const std::string &slotName, const std::string &attachmentName) const;
+	Attachment* getAttachment (int slotIndex, const std::string &attachmentName) const;
 	void setAttachment (const std::string &slotName, const std::string &attachmentName);
 };
 

+ 2 - 1
spine-cpp/includes/spine/BaseSkeletonJson.h

@@ -13,8 +13,9 @@ class BaseSkeletonJson {
 public:
 	BaseAttachmentLoader *attachmentLoader;
 	float scale;
-	bool flipY;
+	bool yDown;
 
+	/** The BaseSkeletonJson owns the attachmentLoader. */
 	BaseSkeletonJson (BaseAttachmentLoader *attachmentLoader);
 	virtual ~BaseSkeletonJson ();
 

+ 1 - 0
spine-cpp/includes/spine/Bone.h

@@ -8,6 +8,7 @@ class BoneData;
 class Bone {
 public:
 	BoneData *data;
+	/** May be null. */
 	Bone *parent;
 	float x, y;
 	float rotation;

+ 2 - 2
spine-cpp/includes/spine/BoneData.h

@@ -13,7 +13,7 @@ public:
 	float x, y;
 	float rotation;
 	float scaleX, scaleY;
-	float flipY;
+	float yDown;
 
 	BoneData (const std::string &name) :
 					name(name),
@@ -24,7 +24,7 @@ public:
 					rotation(0),
 					scaleX(1),
 					scaleY(1),
-					flipY(false) {
+					yDown(false) {
 	}
 };
 

+ 5 - 1
spine-cpp/includes/spine/SkeletonData.h

@@ -12,9 +12,13 @@ class Skin;
 
 class SkeletonData {
 public:
+	/** The SkeletonData owns the bones. */
 	std::vector<BoneData*> bones;
+	/** The SkeletonData owns the slots. */
 	std::vector<SlotData*> slots;
+	/** The SkeletonData owns the skins. */
 	std::vector<Skin*> skins;
+	/** May be null. */
 	Skin *defaultSkin;
 
 	SkeletonData ();
@@ -26,7 +30,7 @@ public:
 	SlotData* findSlot (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 */

+ 3 - 2
spine-cpp/includes/spine/Skin.h

@@ -3,11 +3,11 @@
 
 #include <string>
 #include <map>
-#include <spine/Attachment.h>
 
 namespace spine {
 
 class BaseSkeleton;
+class Attachment;
 
 class Skin {
 	friend class BaseSkeleton;
@@ -31,8 +31,9 @@ public:
 	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);
 
 	Attachment* getAttachment (int slotIndex, const std::string &name);

+ 1 - 0
spine-cpp/includes/spine/Slot.h

@@ -25,6 +25,7 @@ public:
 
 	Slot (SlotData *data, BaseSkeleton *skeleton, Bone *bone);
 
+	/** @param attachment May be null. */
 	void setAttachment (Attachment *attachment);
 
 	void setAttachmentTime (float time);

+ 2 - 18
spine-cpp/includes/spine/SlotData.h

@@ -2,7 +2,6 @@
 #define SPINE_SLOTDATA_H_
 
 #include <string>
-#include <stdexcept>
 
 namespace spine {
 
@@ -15,23 +14,8 @@ public:
 	float r, g, b, a;
 	std::string *attachmentName;
 
-	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 () {
-		if (attachmentName) {
-			delete attachmentName;
-			attachmentName = 0;
-		}
-	}
+	SlotData (const std::string &name, BoneData *boneData);
+	~SlotData ();
 };
 
 } /* namespace spine */

+ 7 - 1
spine-cpp/src/spine-sfml/Atlas.cpp

@@ -3,6 +3,12 @@
 
 namespace spine {
 
+AtlasPage::~AtlasPage () {
+	delete texture;
+}
+
+//
+
 Atlas::Atlas (std::ifstream &file) {
 	load(file);
 }
@@ -19,7 +25,7 @@ Atlas::Atlas (const char *begin, const char *end) {
 	load(begin, end);
 }
 
-BaseAtlasPage* Atlas::newAtlasPage (std::string name) {
+BaseAtlasPage* Atlas::newAtlasPage (const std::string &name) {
 	AtlasPage *page = new AtlasPage();
 	page->texture = new sf::Texture();
 	page->texture->loadFromFile(name);

+ 2 - 2
spine-cpp/src/spine-sfml/RegionAttachment.cpp

@@ -9,7 +9,7 @@
 namespace spine {
 
 RegionAttachment::RegionAttachment (AtlasRegion *region) {
-	texture = region->page->texture; // BOZO - Resolve attachment as late as possible?
+	texture = region->page->texture;
 	int u = region->x;
 	int u2 = u + region->width;
 	int v = region->y;
@@ -59,9 +59,9 @@ void RegionAttachment::draw (Slot *slot) {
 	vertices[3].color.b = b;
 	vertices[3].color.a = a;
 
-	updateOffset(); // BOZO - Move to resolve()?
 	updateWorldVertices(slot->bone);
 
+	// SMFL doesn't handle batching for us, so we'll just force a single texture per skeleton.
 	skeleton->texture = texture;
 	skeleton->vertexArray.append(vertices[0]);
 	skeleton->vertexArray.append(vertices[1]);

+ 2 - 2
spine-cpp/src/spine-sfml/SkeletonJson.cpp

@@ -5,12 +5,12 @@ namespace spine {
 
 SkeletonJson::SkeletonJson (BaseAttachmentLoader *attachmentLoader) :
 				BaseSkeletonJson(attachmentLoader) {
-	flipY = true;
+	yDown = true;
 }
 
 SkeletonJson::SkeletonJson (Atlas *atlas) :
 				BaseSkeletonJson(new AtlasAttachmentLoader(atlas)) {
-	flipY = true;
+	yDown = true;
 }
 
 } /* namespace spine */

+ 21 - 28
spine-cpp/src/spine/Animation.cpp

@@ -18,26 +18,19 @@ Animation::Animation (const vector<Timeline*> &timelines, float duration) :
 				duration(duration) {
 }
 
-Animation::~Animation()
-{
-  for (std::vector<Timeline*>::iterator iter = timelines.begin(); iter != timelines.end(); ++iter)
-  {
-    delete *iter;
-  }
+Animation::~Animation () {
+	for (int i = 0, n = timelines.size(); i < n; i++)
+		delete timelines[i];
 }
 
-void Animation::apply (BaseSkeleton *skeleton, float time, bool loop) {
-	if (!skeleton) throw std::invalid_argument("skeleton cannot be null.");
-
+void Animation::apply (BaseSkeleton *skeleton, float time, bool loop) const {
 	if (loop && duration) time = fmodf(time, duration);
 
 	for (int i = 0, n = timelines.size(); i < n; i++)
 		timelines[i]->apply(skeleton, time, 1);
 }
 
-void Animation::mix (BaseSkeleton *skeleton, float time, bool loop, float alpha) {
-	if (!skeleton) throw std::invalid_argument("skeleton cannot be null.");
-
+void Animation::mix (BaseSkeleton *skeleton, float time, bool loop, float alpha) const {
 	if (loop && duration) time = fmodf(time, duration);
 
 	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;
 }
 
-float CurveTimeline::getCurvePercent (int keyframeIndex, float percent) {
+float CurveTimeline::getCurvePercent (int keyframeIndex, float percent) const {
 	int curveIndex = keyframeIndex * 6;
 	float dfx = curves[curveIndex];
 	if (dfx == LINEAR) return percent;
@@ -162,11 +155,11 @@ RotateTimeline::~RotateTimeline () {
 	delete[] frames;
 }
 
-float RotateTimeline::getDuration () {
+float RotateTimeline::getDuration () const {
 	return frames[framesLength - 2];
 }
 
-int RotateTimeline::getKeyframeCount () {
+int RotateTimeline::getKeyframeCount () const {
 	return framesLength / 2;
 }
 
@@ -176,7 +169,7 @@ void RotateTimeline::setKeyframe (int keyframeIndex, float time, float 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.
 
 	Bone *bone = skeleton->bones[boneIndex];
@@ -233,11 +226,11 @@ TranslateTimeline::~TranslateTimeline () {
 	delete[] frames;
 }
 
-float TranslateTimeline::getDuration () {
+float TranslateTimeline::getDuration () const {
 	return frames[framesLength - 3];
 }
 
-int TranslateTimeline::getKeyframeCount () {
+int TranslateTimeline::getKeyframeCount () const {
 	return framesLength / 3;
 }
 
@@ -248,7 +241,7 @@ void TranslateTimeline::setKeyframe (int keyframeIndex, float time, float x, flo
 	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.
 
 	Bone *bone = skeleton->bones[boneIndex];
@@ -281,7 +274,7 @@ ScaleTimeline::ScaleTimeline (int 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.
 
 	Bone *bone = skeleton->bones[boneIndex];
@@ -329,11 +322,11 @@ ColorTimeline::~ColorTimeline () {
 	delete[] frames;
 }
 
-float ColorTimeline::getDuration () {
+float ColorTimeline::getDuration () const {
 	return frames[framesLength - 5];
 }
 
-int ColorTimeline::getKeyframeCount () {
+int ColorTimeline::getKeyframeCount () const {
 	return framesLength / 5;
 }
 
@@ -346,7 +339,7 @@ void ColorTimeline::setKeyframe (int keyframeIndex, float time, float r, float g
 	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.
 
 	Slot *slot = skeleton->slots[slotIndex];
@@ -410,21 +403,21 @@ AttachmentTimeline::~AttachmentTimeline () {
 	delete[] attachmentNames;
 }
 
-float AttachmentTimeline::getDuration () {
+float AttachmentTimeline::getDuration () const {
 	return frames[framesLength - 1];
 }
 
-int AttachmentTimeline::getKeyframeCount () {
+int AttachmentTimeline::getKeyframeCount () const {
 	return framesLength;
 }
 
-void AttachmentTimeline::setKeyframe (int keyframeIndex, float time, const string &attachmentName) {
+void AttachmentTimeline::setKeyframe (int keyframeIndex, float time, string *attachmentName) {
 	frames[keyframeIndex] = time;
 	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.
 
 	int frameIndex;

+ 6 - 1
spine-cpp/src/spine/BaseAtlas.cpp

@@ -105,7 +105,7 @@ void BaseAtlas::load (const char *current, const char *end) {
 
 	string value;
 	string tuple[4];
-	BaseAtlasPage *page = NULL;
+	BaseAtlasPage *page = 0;
 	while (current != end) {
 		readLine(current, end, value);
 		trim(value);
@@ -185,6 +185,11 @@ BaseAtlasRegion* BaseAtlas::findRegion (const std::string &name) {
 
 //
 
+BaseAtlasRegion::BaseAtlasRegion () :
+				splits(0),
+				pads(0) {
+}
+
 BaseAtlasRegion::~BaseAtlasRegion () {
 	if (splits) delete splits;
 	if (pads) delete pads;

+ 2 - 2
spine-cpp/src/spine/BaseRegionAttachment.cpp

@@ -1,8 +1,8 @@
 #include <math.h>
 #include <spine/BaseRegionAttachment.h>
 
-#ifndef M_PI // fix for windows removing precious information
-#define M_PI 3.14159265358979323846
+#ifndef M_PI
+#define M_PI 3.1415926535897932385
 #endif
 
 namespace spine {

+ 7 - 6
spine-cpp/src/spine/BaseSkeleton.cpp

@@ -1,3 +1,4 @@
+#include <stdexcept>
 #include <iostream>
 #include <spine/BaseSkeleton.h>
 #include <spine/SkeletonData.h>
@@ -92,25 +93,25 @@ Bone* BaseSkeleton::getRootBone () 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];
 	return 0;
 }
 
 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;
 	return -1;
 }
 
 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];
 	return 0;
 }
 
 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;
 	return -1;
 }
@@ -126,11 +127,11 @@ void BaseSkeleton::setSkin (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);
 }
 
-Attachment* BaseSkeleton::getAttachment (int slotIndex, const string &attachmentName) {
+Attachment* BaseSkeleton::getAttachment (int slotIndex, const string &attachmentName) const {
 	if (data->defaultSkin) {
 		Attachment *attachment = data->defaultSkin->getAttachment(slotIndex, attachmentName);
 		if (attachment) return attachment;

+ 23 - 21
spine-cpp/src/spine/BaseSkeletonJson.cpp

@@ -32,12 +32,12 @@ static float toColor (const string &value, int index) {
 BaseSkeletonJson::BaseSkeletonJson (BaseAttachmentLoader *attachmentLoader) :
 				attachmentLoader(attachmentLoader),
 				scale(1),
-				flipY(false) {
+				yDown(false) {
+	if (!attachmentLoader) throw invalid_argument("attachmentLoader cannot be null.");
 }
 
 BaseSkeletonJson::~BaseSkeletonJson () {
-  if (attachmentLoader)
-    delete attachmentLoader;
+	delete attachmentLoader;
 }
 
 SkeletonData* BaseSkeletonJson::readSkeletonData (std::ifstream &file) const {
@@ -76,7 +76,7 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
 
 	Json::Value bones = root["bones"];
 	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];
 		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->scaleX = (float)(boneMap.get("scaleX", 1).asDouble());
 		boneData->scaleY = (float)(boneMap.get("scaleY", 1).asDouble());
-		boneData->flipY = flipY;
+		boneData->yDown = yDown;
 
 		skeletonData->bones.push_back(boneData);
 	}
@@ -100,7 +100,7 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
 	Json::Value slots = root["slots"];
 	if (!slots.isNull()) {
 		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];
 			string slotName = slotMap["name"].asString();
 
@@ -128,7 +128,7 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
 		Json::Value skinsMap = root["skins"];
 		vector<string> skinNames = skinsMap.getMemberNames();
 		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];
 			Skin *skin = new Skin(skinName);
 			skeletonData->skins.push_back(skin);
@@ -136,13 +136,13 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
 
 			Json::Value slotMap = skinsMap[skinName];
 			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];
 				int slotIndex = skeletonData->findSlotIndex(slotName);
 
 				Json::Value attachmentsMap = slotMap[slotName];
 				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];
 					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->width = (float)(attachmentMap.get("width", 32).asDouble() * scale);
 						regionAttachment->height = (float)(attachmentMap.get("height", 32).asDouble() * scale);
+						regionAttachment->updateOffset();
 					}
 
 					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")
 		timeline->setStepped(keyframeIndex);
 	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 {
@@ -229,14 +231,14 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
 
 	Json::Value bones = root["bones"];
 	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];
 		int boneIndex = skeletonData->findBoneIndex(boneName);
 		if (boneIndex == -1) throw runtime_error("Bone not found: " + boneName);
 
 		Json::Value timelineMap = bones[boneName];
 		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];
 			Json::Value values = timelineMap[timelineName];
 
@@ -245,7 +247,7 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
 				timeline->boneIndex = boneIndex;
 
 				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];
 
 					float time = (float)valueMap["time"].asDouble();
@@ -268,10 +270,9 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
 				timeline->boneIndex = boneIndex;
 
 				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];
 
-					float time = (float)valueMap["time"].asDouble();
 					timeline->setKeyframe(keyframeIndex, //
 							(float)valueMap["time"].asDouble(), //
 							(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"];
 	if (!slots.isNull()) {
 		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];
 			int slotIndex = skeletonData->findSlotIndex(slotName);
 			if (slotIndex == -1) throw runtime_error("Slot not found: " + slotName);
 
 			Json::Value timelineMap = slots[slotName];
 			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];
 				Json::Value values = timelineMap[timelineName];
 
@@ -307,7 +308,7 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
 					timeline->slotIndex = slotIndex;
 
 					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];
 
 						string s = valueMap["color"].asString();
@@ -324,11 +325,12 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
 					timeline->slotIndex = slotIndex;
 
 					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 name = valueMap["name"];
-						timeline->setKeyframe(keyframeIndex++, (float)valueMap["time"].asDouble(), name.isNull() ? "" : name.asString());
+						Json::Value nameValue = valueMap["name"];
+						timeline->setKeyframe(keyframeIndex++, (float)valueMap["time"].asDouble(),
+								nameValue.isNull() ? 0 : new string(nameValue.asString()));
 					}
 					timelines.push_back(timeline);
 					if (timeline->getDuration() > duration) duration = timeline->getDuration();

+ 1 - 1
spine-cpp/src/spine/Bone.cpp

@@ -58,7 +58,7 @@ void Bone::updateWorldTransform (bool flipX, bool flipY) {
 		m10 = -m10;
 		m11 = -m11;
 	}
-	if (data->flipY) {
+	if (data->yDown) {
 		m10 = -m10;
 		m11 = -m11;
 	}

+ 6 - 6
spine-cpp/src/spine/SkeletonData.cpp

@@ -21,31 +21,31 @@ SkeletonData::~SkeletonData () {
 }
 
 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];
 	return 0;
 }
 
 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;
 	return -1;
 }
 
 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];
 	return 0;
 }
 
 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;
 	return -1;
 }
 
-Skin* SkeletonData::findSkin (const string &skinName) {
-	for (unsigned int i = 0; i < skins.size(); i++)
+Skin* SkeletonData::findSkin (const string &skinName) const {
+	for (int i = 0, n = skins.size(); i < n; i++)
 		if (skins[i]->name == skinName) return skins[i];
 	return 0;
 }

+ 6 - 6
spine-cpp/src/spine/Skin.cpp

@@ -1,3 +1,5 @@
+#include <stdexcept>
+#include <spine/Attachment.h>
 #include <spine/Skin.h>
 #include <spine/BaseSkeleton.h>
 #include <spine/Slot.h>
@@ -8,14 +10,13 @@ Skin::Skin (const std::string &name) :
 				name(name) {
 }
 
-Skin::~Skin()
-{
-	for (std::map<Key, Attachment*>::iterator iter = attachments.begin(); iter != attachments.end(); ++iter) {
-    delete iter->second;
-  }
+Skin::~Skin () {
+	for (std::map<Key, Attachment*>::iterator iter = attachments.begin(); iter != attachments.end(); iter++)
+		delete iter->second;
 }
 
 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};
 	attachments[key] = attachment;
 }
@@ -26,7 +27,6 @@ Attachment* Skin::getAttachment (int slotIndex, const std::string &name) {
 	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) {
 	for (std::map<Key, Attachment*>::iterator iter = attachments.begin(); iter != attachments.end(); iter++) {
 		const Key key = iter->first;

+ 3 - 2
spine-cpp/src/spine/Slot.cpp

@@ -1,3 +1,4 @@
+#include <stdexcept>
 #include <spine/Slot.h>
 #include <spine/SlotData.h>
 #include <spine/BaseSkeleton.h>
@@ -6,6 +7,7 @@
 namespace spine {
 
 Slot::Slot (SlotData *data, BaseSkeleton *skeleton, Bone *bone) :
+				attachmentTime(0),
 				data(data),
 				skeleton(skeleton),
 				bone(bone),
@@ -13,8 +15,7 @@ Slot::Slot (SlotData *data, BaseSkeleton *skeleton, Bone *bone) :
 				g(1),
 				b(1),
 				a(1),
-				attachment(0),
-				attachmentTime(0) {
+				attachment(0) {
 	if (!data) throw std::invalid_argument("data cannot be null.");
 	if (!skeleton) throw std::invalid_argument("skeleton cannot be null.");
 	if (!bone) throw std::invalid_argument("bone cannot be null.");

+ 25 - 0
spine-cpp/src/spine/SlotData.cpp

@@ -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 */