Skip to content

Commit

Permalink
Documented memory ownership.
Browse files Browse the repository at this point in the history
Clean up and minor improvements.
  • Loading branch information
NathanSweet committed Mar 15, 2013
1 parent a347994 commit a1ad55f
Show file tree
Hide file tree
Showing 29 changed files with 164 additions and 160 deletions.
2 changes: 1 addition & 1 deletion spine-cpp/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
22 changes: 0 additions & 22 deletions spine-cpp/data/spineboy-walk.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
]
}
}
}
6 changes: 2 additions & 4 deletions spine-cpp/includes/spine-sfml/Atlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ namespace spine {

class AtlasPage: public BaseAtlasPage {
public:
~AtlasPage(){
delete texture;
}
~AtlasPage ();

sf::Texture *texture;
};
Expand All @@ -34,7 +32,7 @@ class Atlas: public BaseAtlas {
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);
};

Expand Down
2 changes: 1 addition & 1 deletion spine-cpp/includes/spine-sfml/Skeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions spine-cpp/includes/spine-sfml/SkeletonJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Atlas;
class SkeletonJson: public BaseSkeletonJson {
public:
SkeletonJson (Atlas *atlas);
/** The SkeletonJson owns the attachmentLoader */
SkeletonJson (BaseAttachmentLoader *attachmentLoader);
};

Expand Down
45 changes: 23 additions & 22 deletions spine-cpp/includes/spine/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class Animation {
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;
};

//
Expand All @@ -28,11 +28,11 @@ class 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;
};

//
Expand All @@ -53,7 +53,7 @@ class CurveTimeline: public Timeline {
* 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;
};

//
Expand All @@ -67,9 +67,9 @@ class RotateTimeline: public CurveTimeline {
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);
};
Expand All @@ -85,9 +85,9 @@ class TranslateTimeline: public CurveTimeline {
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);
};
Expand All @@ -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;
};

//
Expand All @@ -112,9 +112,9 @@ class ColorTimeline: public CurveTimeline {
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);
};
Expand All @@ -131,12 +131,13 @@ class AttachmentTimeline: public Timeline {
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 */
Expand Down
5 changes: 2 additions & 3 deletions spine-cpp/includes/spine/BaseAtlas.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <istream>
#include <string>
#include <vector>
#include <map>

namespace spine {

Expand All @@ -26,7 +25,7 @@ class BaseAtlas {
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;
};

Expand Down Expand Up @@ -71,7 +70,7 @@ class BaseAtlasRegion {
int *splits;
int *pads;

BaseAtlasRegion() : splits(0), pads(0) {}
BaseAtlasRegion ();
virtual ~BaseAtlasRegion ();
};

Expand Down
4 changes: 2 additions & 2 deletions spine-cpp/includes/spine/BaseAttachmentLoader.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#ifndef SPINE_BASEATTACHMENTLOADER_H_
#define SPINE_BASEATTACHMENTLOADER_H_

#include <spine/Attachment.h>

namespace spine {

class Attachment;

enum AttachmentType {
region, regionSequence
};
Expand Down
8 changes: 5 additions & 3 deletions spine-cpp/includes/spine/BaseSkeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class BaseSkeleton {
float time;
bool flipX, flipY;

/** The BaseSkeleton owns the SkeletonData. */
BaseSkeleton (SkeletonData *data);
virtual ~BaseSkeleton ();

Expand All @@ -40,10 +41,11 @@ class BaseSkeleton {
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);
};

Expand Down
3 changes: 2 additions & 1 deletion spine-cpp/includes/spine/BaseSkeletonJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();

Expand Down
1 change: 1 addition & 0 deletions spine-cpp/includes/spine/Bone.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class BoneData;
class Bone {
public:
BoneData *data;
/** May be null. */
Bone *parent;
float x, y;
float rotation;
Expand Down
4 changes: 2 additions & 2 deletions spine-cpp/includes/spine/BoneData.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BoneData {
float x, y;
float rotation;
float scaleX, scaleY;
float flipY;
float yDown;

BoneData (const std::string &name) :
name(name),
Expand All @@ -24,7 +24,7 @@ class BoneData {
rotation(0),
scaleX(1),
scaleY(1),
flipY(false) {
yDown(false) {
}
};

Expand Down
6 changes: 5 additions & 1 deletion spine-cpp/includes/spine/SkeletonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -26,7 +30,7 @@ class SkeletonData {
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 */
Expand Down
5 changes: 3 additions & 2 deletions spine-cpp/includes/spine/Skin.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

#include <string>
#include <map>
#include <spine/Attachment.h>

namespace spine {

class BaseSkeleton;
class Attachment;

class Skin {
friend class BaseSkeleton;
Expand All @@ -31,8 +31,9 @@ class Skin {
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);
Expand Down
1 change: 1 addition & 0 deletions spine-cpp/includes/spine/Slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Slot {

Slot (SlotData *data, BaseSkeleton *skeleton, Bone *bone);

/** @param attachment May be null. */
void setAttachment (Attachment *attachment);

void setAttachmentTime (float time);
Expand Down
20 changes: 2 additions & 18 deletions spine-cpp/includes/spine/SlotData.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define SPINE_SLOTDATA_H_

#include <string>
#include <stdexcept>

namespace spine {

Expand All @@ -15,23 +14,8 @@ class SlotData {
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 */
Expand Down
8 changes: 7 additions & 1 deletion spine-cpp/src/spine-sfml/Atlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

namespace spine {

AtlasPage::~AtlasPage () {
delete texture;
}

//

Atlas::Atlas (std::ifstream &file) {
load(file);
}
Expand All @@ -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);
Expand Down
Loading

0 comments on commit a1ad55f

Please sign in to comment.