Moving Braces to Same Line

This commit is contained in:
Stephen Gowen 2017-12-12 10:51:11 -05:00
parent 0764543bf5
commit 64fd7c2886
132 changed files with 2071 additions and 4132 deletions

View File

@ -43,8 +43,7 @@ namespace Spine
class Skeleton;
class Event;
class Animation
{
class Animation {
friend class AnimationState;
friend class TrackEntry;
friend class AnimationStateData;

View File

@ -37,8 +37,7 @@
namespace Spine
{
enum EventType
{
enum EventType {
EventType_Start,
EventType_Interrupt,
EventType_End,
@ -59,8 +58,7 @@ namespace Spine
typedef void (*OnAnimationEventFunc) (AnimationState* state, EventType type, TrackEntry* entry, Event* event);
/// State for the playback of an animation
class TrackEntry
{
class TrackEntry {
friend class EventQueue;
friend class AnimationState;
@ -241,8 +239,7 @@ namespace Spine
void reset();
};
class EventQueueEntry
{
class EventQueueEntry {
friend class EventQueue;
public:
@ -253,8 +250,7 @@ namespace Spine
EventQueueEntry(EventType eventType, TrackEntry* trackEntry, Event* event = NULL);
};
class EventQueue
{
class EventQueue {
friend class AnimationState;
private:
@ -287,8 +283,7 @@ namespace Spine
void drain();
};
class AnimationState
{
class AnimationState {
friend class TrackEntry;
friend class EventQueue;

View File

@ -42,8 +42,7 @@ namespace Spine
class Animation;
/// Stores mix (crossfade) durations to be applied when AnimationState animations are changed.
class AnimationStateData
{
class AnimationStateData {
friend class AnimationState;
public:
@ -70,8 +69,7 @@ namespace Spine
float getMix(Animation* from, Animation* to);
private:
class AnimationPair
{
class AnimationPair {
public:
Animation* _a1;
Animation* _a2;
@ -81,8 +79,7 @@ namespace Spine
bool operator==(const AnimationPair &other) const;
};
struct HashAnimationPair
{
struct HashAnimationPair {
std::size_t operator()(const Spine::AnimationStateData::AnimationPair& val) const;
};

View File

@ -38,8 +38,7 @@
namespace Spine
{
enum Format
{
enum Format {
Format_Alpha,
Format_Intensity,
Format_LuminanceAlpha,
@ -49,8 +48,7 @@ namespace Spine
Format_RGBA8888
};
enum TextureFilter
{
enum TextureFilter {
TextureFilter_Nearest,
TextureFilter_Linear,
TextureFilter_MipMap,
@ -60,15 +58,13 @@ namespace Spine
TextureFilter_MipMapLinearLinear
};
enum TextureWrap
{
enum TextureWrap {
TextureWrap_MirroredRepeat,
TextureWrap_ClampToEdge,
TextureWrap_Repeat
};
class AtlasPage
{
class AtlasPage {
public:
std::string name;
Format format;
@ -82,8 +78,7 @@ namespace Spine
AtlasPage(std::string inName) : name(inName) {}
};
class AtlasRegion
{
class AtlasRegion {
public:
AtlasPage* page;
std::string name;
@ -99,8 +94,7 @@ namespace Spine
class TextureLoader;
class Atlas
{
class Atlas {
public:
Atlas(const char* path, TextureLoader& textureLoader);
@ -124,8 +118,7 @@ namespace Spine
void load(const char* begin, int length, const char* dir);
class Str
{
class Str {
public:
const char* begin;
const char* end;

View File

@ -44,8 +44,7 @@ namespace Spine
/// An AttachmentLoader that configures attachments using texture regions from an Atlas.
/// See http://esotericsoftware.com/spine-loading-skeleton-data#JSON-and-binary-data about Loading Skeleton Data in the Spine Runtimes Guide.
///
class AtlasAttachmentLoader : public AttachmentLoader
{
class AtlasAttachmentLoader : public AttachmentLoader {
RTTI_DECL;
public:

View File

@ -37,8 +37,7 @@
namespace Spine
{
class Attachment
{
class Attachment {
RTTI_DECL;
public:

View File

@ -45,8 +45,7 @@ namespace Spine
class PointAttachment;
class ClippingAttachment;
class AttachmentLoader
{
class AttachmentLoader {
RTTI_DECL;
AttachmentLoader();

View File

@ -44,8 +44,7 @@ namespace Spine
class Skeleton;
class Event;
class AttachmentTimeline : public Timeline
{
class AttachmentTimeline : public Timeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -33,8 +33,7 @@
namespace Spine
{
enum AttachmentType
{
enum AttachmentType {
AttachmentType_Region,
AttachmentType_Boundingbox,
AttachmentType_Mesh,

View File

@ -33,8 +33,7 @@
namespace Spine
{
enum BlendMode
{
enum BlendMode {
BlendMode_Normal = 0,
BlendMode_Additive,
BlendMode_Multiply,

View File

@ -45,8 +45,7 @@ namespace Spine
/// A bone has a local transform which is used to compute its world transform. A bone also has an applied transform, which is a
/// local transform that can be applied to compute the world transform. The local transform and applied transform may differ if a
/// constraint or application code modifies the world transform after it was computed from the local transform.
class Bone : public Updatable
{
class Bone : public Updatable {
friend class AnimationState;
friend class RotateTimeline;

View File

@ -37,8 +37,7 @@
namespace Spine
{
class BoneData
{
class BoneData {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -36,8 +36,7 @@
namespace Spine
{
/// Attachment that has a polygon for bounds checking.
class BoundingBoxAttachment : public VertexAttachment
{
class BoundingBoxAttachment : public VertexAttachment {
RTTI_DECL;
BoundingBoxAttachment(std::string name);

View File

@ -37,8 +37,7 @@ namespace Spine
{
class SlotData;
class ClippingAttachment : public VertexAttachment
{
class ClippingAttachment : public VertexAttachment {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class ColorTimeline : public CurveTimeline
{
class ColorTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -36,8 +36,7 @@
namespace Spine
{
/// The interface for all constraints.
class Constraint : public Updatable
{
class Constraint : public Updatable {
RTTI_DECL;
public:

View File

@ -40,22 +40,18 @@
namespace Spine
{
class ContainerUtil
{
class ContainerUtil {
public:
/// Finds an item by comparing each item's name.
/// It is more efficient to cache the results of this method than to call it multiple times.
/// @return May be NULL.
template<typename T>
static T* findWithName(Vector<T*>& items, std::string name)
{
static T* findWithName(Vector<T*>& items, std::string name) {
assert(name.length() > 0);
for (T** i = items.begin(); i != items.end(); ++i)
{
for (T** i = items.begin(); i != items.end(); ++i) {
T* item = (*i);
if (item->getName() == name)
{
if (item->getName() == name) {
return item;
}
}
@ -65,15 +61,12 @@ namespace Spine
/// @return -1 if the item was not found.
template<typename T>
static int findIndexWithName(Vector<T*>& items, std::string name)
{
static int findIndexWithName(Vector<T*>& items, std::string name) {
assert(name.length() > 0);
for (size_t i = 0, len = items.size(); i < len; ++i)
{
for (size_t i = 0, len = items.size(); i < len; ++i) {
T* item = items[i];
if (item->getName() == name)
{
if (item->getName() == name) {
return static_cast<int>(i);
}
}
@ -85,15 +78,12 @@ namespace Spine
/// It is more efficient to cache the results of this method than to call it multiple times.
/// @return May be NULL.
template<typename T>
static T* findWithDataName(Vector<T*>& items, std::string name)
{
static T* findWithDataName(Vector<T*>& items, std::string name) {
assert(name.length() > 0);
for (T** i = items.begin(); i != items.end(); ++i)
{
for (T** i = items.begin(); i != items.end(); ++i) {
T* item = (*i);
if (item->getData().getName() == name)
{
if (item->getData().getName() == name) {
return item;
}
}
@ -103,15 +93,12 @@ namespace Spine
/// @return -1 if the item was not found.
template<typename T>
static int findIndexWithDataName(Vector<T*>& items, std::string name)
{
static int findIndexWithDataName(Vector<T*>& items, std::string name) {
assert(name.length() > 0);
for (size_t i = 0, len = items.size(); i < len; ++i)
{
for (size_t i = 0, len = items.size(); i < len; ++i) {
T* item = items[i];
if (item->getData().getName() == name)
{
if (item->getData().getName() == name) {
return static_cast<int>(i);
}
}
@ -120,10 +107,8 @@ namespace Spine
}
template<typename T>
static void cleanUpVectorOfPointers(Vector<T*>& items)
{
for (size_t i = 0; i < items.size(); )
{
static void cleanUpVectorOfPointers(Vector<T*>& items) {
for (size_t i = 0; i < items.size(); ) {
T* item = items[i];
DESTROY(T, item);

View File

@ -39,8 +39,7 @@
namespace Spine
{
/// Base class for frames that use an interpolation bezier curve.
class CurveTimeline : public Timeline
{
class CurveTimeline : public Timeline {
RTTI_DECL;
public:

View File

@ -37,8 +37,7 @@ namespace Spine
{
class VertexAttachment;
class DeformTimeline : public CurveTimeline
{
class DeformTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class DrawOrderTimeline : public Timeline
{
class DrawOrderTimeline : public Timeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -38,8 +38,7 @@ namespace Spine
class EventData;
/// Stores the current pose values for an Event.
class Event
{
class Event {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AnimationState;

View File

@ -36,8 +36,7 @@
namespace Spine
{
/// Stores the setup pose values for an Event.
class EventData
{
class EventData {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class Event;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class EventTimeline : public Timeline
{
class EventTimeline : public Timeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -49,8 +49,7 @@
namespace Spine
{
class SpineExtension
{
class SpineExtension {
public:
static void setInstance(SpineExtension* inSpineExtension);
@ -77,8 +76,7 @@ namespace Spine
static SpineExtension* _instance;
};
class DefaultSpineExtension : public SpineExtension
{
class DefaultSpineExtension : public SpineExtension {
public:
static DefaultSpineExtension* getInstance();

View File

@ -37,51 +37,42 @@
namespace Spine
{
template <typename K, typename V, typename H>
class HashMap
{
class HashMap {
private:
class Entry;
public:
class Iterator
{
class Iterator {
friend class HashMap;
public:
Iterator(Entry* entry = NULL) : _entry(entry)
{
Iterator(Entry* entry = NULL) : _entry(entry) {
// Empty
}
Iterator& operator++()
{
Iterator& operator++() {
_entry = _entry->next;
return *this;
}
Iterator& operator--()
{
Iterator& operator--() {
_entry = _entry->prev;
return *this;
}
bool operator==(const Iterator& p) const
{
bool operator==(const Iterator& p) const {
return _entry == p._entry;
}
bool operator!=(const Iterator& p) const
{
bool operator!=(const Iterator& p) const {
return _entry != p._entry;
}
K& first()
{
K& first() {
return _entry->_key;
}
V& second()
{
V& second() {
return _entry->_value;
}
@ -94,11 +85,9 @@ namespace Spine
_capacity(capacity),
_header(),
_trailer(),
_hashSize(0)
{
_hashSize(0) {
_hashTable.reserve(capacity);
for (int i = 0; i < _capacity; ++i)
{
for (int i = 0; i < _capacity; ++i) {
_hashTable.push_back(Entry());
}
@ -108,42 +97,34 @@ namespace Spine
_trailer.next = &_trailer;
}
~HashMap()
{
~HashMap() {
_hashSize = 0;
}
size_t size()
{
size_t size() {
return _hashSize;
}
Iterator begin()
{
Iterator begin() {
return Iterator(_header.next);
}
Iterator end()
{
Iterator end() {
return Iterator(&_trailer);
}
Iterator rbegin()
{
Iterator rbegin() {
return Iterator(_trailer.prev);
}
Iterator rend()
{
Iterator rend() {
return Iterator(_header);
}
std::pair<Iterator, bool> insert(const K& key, const V& value)
{
std::pair<Iterator, bool> insert(const K& key, const V& value) {
Iterator iter = find(key);
if (iter._entry != &_trailer)
{
if (iter._entry != &_trailer) {
return std::make_pair(iter, false);
}
@ -156,8 +137,7 @@ namespace Spine
_hashSize++;
if (_header.next == (&_trailer))
{
if (_header.next == (&_trailer)) {
_hashTable[index].next = entry;
_hashTable[index].prev = entry;
_header.next = entry;
@ -168,19 +148,16 @@ namespace Spine
return std::make_pair(Iterator(entry), true);
}
if (_hashTable[index].next == NULL)
{
if (_hashTable[index].next == NULL) {
_hashTable[index].next = entry;
_hashTable[index].prev = entry;
if (index < hash(_header.next->_key))
{
if (index < hash(_header.next->_key)) {
entry->next = _header.next;
entry->prev = &_header;
_header.next->prev = entry;
_header.next = entry;
}
else
{
else {
entry->next = &_trailer;
entry->prev = _trailer.prev;
_trailer.prev = entry;
@ -190,16 +167,14 @@ namespace Spine
return std::make_pair(Iterator(entry), true);
}
if (index == hash(_header.next->_key))
{
if (index == hash(_header.next->_key)) {
_header.next = entry;
entry->next = _hashTable[index].next;
entry->prev = &_header;
_hashTable[index].next->prev = entry;
_hashTable[index].next = entry;
}
else
{
else {
entry->next = _hashTable[index].next;
entry->prev = _hashTable[index].next->prev;
entry->next->prev = entry;
@ -210,17 +185,13 @@ namespace Spine
return std::make_pair(Iterator(entry), true);
}
Iterator find(const K& key)
{
Iterator find(const K& key) {
const size_t index = hash(key);
Iterator iter(_hashTable[index].next);
if (iter._entry != NULL)
{
for ( ; hash(iter._entry->_key) == index ; ++iter)
{
if (iter._entry->_key == key)
{
if (iter._entry != NULL) {
for ( ; hash(iter._entry->_key) == index ; ++iter) {
if (iter._entry->_key == key) {
return iter;
}
}
@ -229,71 +200,58 @@ namespace Spine
return Iterator(&_trailer);
}
Iterator erase(Iterator pos)
{
if (pos._entry != &_header && pos._entry != &_trailer)
{
Iterator erase(Iterator pos) {
if (pos._entry != &_header && pos._entry != &_trailer) {
Entry* next = pos._entry->next;
size_t index = hash(pos._entry->_key);
if (_hashTable[index].next == pos._entry && _hashTable[index].prev == pos._entry)
{
if (_hashTable[index].next == pos._entry && _hashTable[index].prev == pos._entry) {
_hashTable[index].next = NULL;
_hashTable[index].prev = NULL;
if (_header.next == pos._entry)
{
if (_header.next == pos._entry) {
_header.next = pos._entry->next;
pos._entry->next->prev = &_header;
}
else if (_trailer.prev == pos._entry)
{
else if (_trailer.prev == pos._entry) {
_trailer.prev = pos._entry->prev;
pos._entry->prev->next = &_trailer;
}
else
{
else {
pos._entry->prev->next = pos._entry->next;
pos._entry->next->prev = pos._entry->prev;
}
DESTROY(Entry, pos._entry);
}
else if (_hashTable[index].next == pos._entry)
{
else if (_hashTable[index].next == pos._entry) {
_hashTable[index].next = pos._entry->next;
if (_header.next == pos._entry)
{
if (_header.next == pos._entry) {
_header.next = pos._entry->next;
pos._entry->next->prev = &_header;
}
else
{
else {
pos._entry->prev->next = pos._entry->next;
pos._entry->next->prev = pos._entry->prev;
}
DESTROY(Entry, pos._entry);
}
else if (_hashTable[index].prev == pos._entry)
{
else if (_hashTable[index].prev == pos._entry) {
_hashTable[index].prev = pos._entry->prev;
if (_trailer.prev == pos._entry)
{
if (_trailer.prev == pos._entry) {
_trailer.prev = pos._entry->prev;
pos._entry->prev->next = &_trailer;
}
else
{
else {
pos._entry->prev->next = pos._entry->next;
pos._entry->next->prev = pos._entry->prev;
}
DESTROY(Entry, pos._entry);
}
else
{
else {
pos._entry->prev->next = pos._entry->next;
pos._entry->next->prev = pos._entry->prev;
@ -308,12 +266,10 @@ namespace Spine
return Iterator(&_trailer);
}
V operator[](const K& key)
{
V operator[](const K& key) {
Iterator iter = find(key);
if (iter._entry != _trailer)
{
if (iter._entry != _trailer) {
return iter._entry->_value;
}
@ -321,8 +277,7 @@ namespace Spine
}
private:
class Entry
{
class Entry {
public:
K _key;
V _value;
@ -337,8 +292,7 @@ namespace Spine
Entry _trailer;
size_t _hashSize;
size_t hash(const K& key)
{
size_t hash(const K& key) {
return _hashFunction(key) % _capacity;
}
};

View File

@ -41,8 +41,7 @@ namespace Spine
class Skeleton;
class Bone;
class IkConstraint : public Constraint
{
class IkConstraint : public Constraint {
friend class Skeleton;
friend class IkConstraintTimeline;

View File

@ -39,8 +39,7 @@ namespace Spine
{
class BoneData;
class IkConstraintData
{
class IkConstraintData {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class IkConstraint;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class IkConstraintTimeline : public CurveTimeline
{
class IkConstraintTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -38,8 +38,7 @@
namespace Spine
{
class Json
{
class Json {
friend class SkeletonJson;
public:

View File

@ -37,8 +37,7 @@ namespace Spine
{
class MeshAttachment;
class LinkedMesh
{
class LinkedMesh {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -51,18 +51,15 @@
namespace Spine
{
template <typename T>
int sign(T val)
{
int sign(T val) {
return (T(0) < val) - (val < T(0));
}
inline bool areFloatsPracticallyEqual(float A, float B, float maxDiff = 0.0000000000000001f, float maxRelDiff = FLT_EPSILON)
{
inline bool areFloatsPracticallyEqual(float A, float B, float maxDiff = 0.0000000000000001f, float maxRelDiff = FLT_EPSILON) {
// Check if the numbers are really close -- needed
// when comparing numbers near zero.
float diff = fabs(A - B);
if (diff <= maxDiff)
{
if (diff <= maxDiff) {
return true;
}
@ -71,21 +68,18 @@ namespace Spine
float largest = (B > A) ? B : A;
if (diff <= largest * maxRelDiff)
{
if (diff <= largest * maxRelDiff) {
return true;
}
return false;
}
inline float clamp(float x, float lower, float upper)
{
inline float clamp(float x, float lower, float upper) {
return fminf(upper, fmaxf(x, lower));
}
class MathUtil
{
class MathUtil {
public:
MathUtil();

View File

@ -40,8 +40,7 @@
namespace Spine
{
/// Attachment that displays a texture region using a mesh.
class MeshAttachment : public VertexAttachment
{
class MeshAttachment : public VertexAttachment {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AtlasAttachmentLoader;

View File

@ -36,8 +36,7 @@ namespace Spine
///
/// Indicates whether a timeline's alpha is mixing out over time toward 0 (the setup or current pose) or mixing in toward 1 (the timeline's pose).
/// See also Timeline::apply(Skeleton&, float, float, Vector&, float, MixPose, MixDirection)
enum MixDirection
{
enum MixDirection {
MixDirection_In = 0,
MixDirection_Out
};

View File

@ -36,8 +36,7 @@ namespace Spine
///
/// Controls how a timeline is mixed with the setup or current pose.
/// See also Timeline::apply(Skeleton&, float, float, Vector&, float, MixPose, MixDirection)
enum MixPose
{
enum MixPose {
/// The timeline value is mixed with the setup pose (the current pose is not used).
MixPose_Setup = 0,
/// The timeline value is mixed with the current pose. The setup pose is used as the timeline value before the first key,

View File

@ -35,8 +35,7 @@
namespace Spine
{
class PathAttachment : public VertexAttachment
{
class PathAttachment : public VertexAttachment {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -43,8 +43,7 @@ namespace Spine
class Bone;
class Slot;
class PathConstraint : public Constraint
{
class PathConstraint : public Constraint {
friend class Skeleton;
friend class PathConstraintMixTimeline;
friend class PathConstraintPositionTimeline;

View File

@ -43,8 +43,7 @@ namespace Spine
class BoneData;
class SlotData;
class PathConstraintData
{
class PathConstraintData {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class PathConstraintMixTimeline : public CurveTimeline
{
class PathConstraintMixTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class PathConstraintPositionTimeline : public CurveTimeline
{
class PathConstraintPositionTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class PathConstraintSpacingTimeline : public PathConstraintPositionTimeline
{
class PathConstraintSpacingTimeline : public PathConstraintPositionTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -44,8 +44,7 @@ namespace Spine
///
/// See http://esotericsoftware.com/spine-point-attachments for Point Attachments in the Spine User Guide.
///
class PointAttachment : public Attachment
{
class PointAttachment : public Attachment {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -38,31 +38,25 @@
namespace Spine
{
template <typename T>
class Pool
{
class Pool {
public:
Pool()
{
Pool() {
// Empty
}
~Pool()
{
~Pool() {
ContainerUtil::cleanUpVectorOfPointers(_objects);
}
T* obtain()
{
if (_objects.size() > 0)
{
T* obtain() {
if (_objects.size() > 0) {
T** object = _objects.begin();
T* ret = *object;
_objects.erase(0);
return ret;
}
else
{
else {
T* ret = NEW(T);
new (ret) T();
@ -70,10 +64,8 @@ namespace Spine
}
}
void free(T* object)
{
if (!_objects.contains(object))
{
void free(T* object) {
if (!_objects.contains(object)) {
_objects.push_back(object);
}
}

View File

@ -33,8 +33,7 @@
namespace Spine
{
enum PositionMode
{
enum PositionMode {
PositionMode_Fixed = 0,
PositionMode_Percent
};

View File

@ -35,8 +35,7 @@
namespace Spine
{
class RTTI
{
class RTTI {
public:
RTTI(const std::string& className);

View File

@ -44,8 +44,7 @@ namespace Spine
class Bone;
/// Attachment that displays a texture region.
class RegionAttachment : public Attachment
{
class RegionAttachment : public Attachment {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AtlasAttachmentLoader;

View File

@ -33,8 +33,7 @@
namespace Spine
{
enum RotateMode
{
enum RotateMode {
RotateMode_Tangent = 0,
RotateMode_Chain,
RotateMode_ChainScale

View File

@ -35,8 +35,7 @@
namespace Spine
{
class RotateTimeline : public CurveTimeline
{
class RotateTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class AnimationState;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class ScaleTimeline : public TranslateTimeline
{
class ScaleTimeline : public TranslateTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class ShearTimeline : public TranslateTimeline
{
class ShearTimeline : public TranslateTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -49,8 +49,7 @@ namespace Spine
class Skin;
class Attachment;
class Skeleton
{
class Skeleton {
friend class AnimationState;
friend class SkeletonBounds;
friend class SkeletonClipping;

View File

@ -48,8 +48,7 @@ namespace Spine
class Animation;
class CurveTimeline;
class SkeletonBinary
{
class SkeletonBinary {
public:
static const int BONE_ROTATE;
static const int BONE_TRANSLATE;
@ -81,8 +80,7 @@ namespace Spine
SkeletonData* readSkeletonDataFile(const char* path);
private:
struct DataInput
{
struct DataInput {
const unsigned char* cursor;
const unsigned char* end;
};

View File

@ -44,8 +44,7 @@ namespace Spine
/// Collects each BoundingBoxAttachment that is visible and computes the world vertices for its polygon.
/// The polygon vertices are provided along with convenience methods for doing hit detection.
///
class SkeletonBounds
{
class SkeletonBounds {
public:
SkeletonBounds();
@ -96,14 +95,12 @@ namespace Spine
void aabbCompute();
};
class Polygon
{
class Polygon {
public:
Vector<float> _vertices;
int _count;
Polygon() : _count(0)
{
Polygon() : _count(0) {
_vertices.reserve(16);
}
};

View File

@ -39,8 +39,7 @@ namespace Spine
class Slot;
class ClippingAttachment;
class SkeletonClipping
{
class SkeletonClipping {
public:
SkeletonClipping();

View File

@ -47,8 +47,7 @@ namespace Spine
class PathConstraintData;
/// Stores the setup pose and all of the stateless data for a skeleton.
class SkeletonData
{
class SkeletonData {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class Skeleton;

View File

@ -46,8 +46,7 @@ namespace Spine
class AttachmentLoader;
class LinkedMesh;
class SkeletonJson
{
class SkeletonJson {
public:
SkeletonJson(Vector<Atlas*>& atlasArray);

View File

@ -43,13 +43,11 @@ namespace Spine
/// Stores attachments by slot index and attachment name.
/// See SkeletonData::getDefaultSkin, Skeleton::getSkin, and
/// http://esotericsoftware.com/spine-runtime-skins in the Spine Runtimes Guide.
class Skin
{
class Skin {
friend class Skeleton;
public:
class AttachmentKey
{
class AttachmentKey {
public:
int _slotIndex;
std::string _name;
@ -59,8 +57,7 @@ namespace Spine
bool operator==(const AttachmentKey &other) const;
};
struct HashAttachmentKey
{
struct HashAttachmentKey {
std::size_t operator()(const Spine::Skin::AttachmentKey& val) const;
};

View File

@ -42,8 +42,7 @@ namespace Spine
class Skeleton;
class Attachment;
class Slot
{
class Slot {
friend class VertexAttachment;
friend class Skeleton;
friend class SkeletonBounds;

View File

@ -39,8 +39,7 @@ namespace Spine
{
class BoneData;
class SlotData
{
class SlotData {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -33,8 +33,7 @@
namespace Spine
{
enum SpacingMode
{
enum SpacingMode {
SpacingMode_Length = 0,
SpacingMode_Fixed,
SpacingMode_Percent

View File

@ -37,8 +37,7 @@ namespace Spine
{
class AtlasPage;
class TextureLoader
{
class TextureLoader {
public:
TextureLoader();

View File

@ -41,8 +41,7 @@ namespace Spine
class Skeleton;
class Event;
class Timeline
{
class Timeline {
RTTI_DECL;
public:

View File

@ -33,8 +33,7 @@
namespace Spine
{
enum TimelineType
{
enum TimelineType {
TimelineType_Rotate = 0,
TimelineType_Translate,
TimelineType_Scale,

View File

@ -41,8 +41,7 @@ namespace Spine
class Skeleton;
class Bone;
class TransformConstraint : public Constraint
{
class TransformConstraint : public Constraint {
friend class Skeleton;
friend class TransformConstraintTimeline;

View File

@ -39,8 +39,7 @@ namespace Spine
{
class BoneData;
class TransformConstraintData
{
class TransformConstraintData {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class TransformConstraintTimeline : public CurveTimeline
{
class TransformConstraintTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -33,8 +33,7 @@
namespace Spine
{
enum TransformMode
{
enum TransformMode {
//0000 0 Flip Scale Rotation
TransformMode_Normal = 0, // 0000
TransformMode_OnlyTranslation = 7, // 0111

View File

@ -38,8 +38,7 @@
namespace Spine
{
class TranslateTimeline : public CurveTimeline
{
class TranslateTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -36,8 +36,7 @@
namespace Spine
{
class Triangulator
{
class Triangulator {
public:
Vector<int>& triangulate(Vector<float>& vertices);

View File

@ -35,8 +35,7 @@
namespace Spine
{
class TwoColorTimeline : public CurveTimeline
{
class TwoColorTimeline : public CurveTimeline {
friend class SkeletonBinary;
friend class SkeletonJson;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class Updatable
{
class Updatable {
RTTI_DECL;
public:

View File

@ -40,30 +40,23 @@
namespace Spine
{
template <typename T>
class Vector
{
class Vector {
public:
Vector() : _size(0), _capacity(0), _buffer(NULL)
{
Vector() : _size(0), _capacity(0), _buffer(NULL) {
// Empty
}
Vector(const Vector& inVector) : _size(inVector._size), _capacity(inVector._capacity), _buffer(NULL)
{
if (_capacity > 0)
{
Vector(const Vector& inVector) : _size(inVector._size), _capacity(inVector._capacity), _buffer(NULL) {
if (_capacity > 0) {
_buffer = allocate(_capacity);
for (size_t i = 0; i < _size; ++i)
{
for (size_t i = 0; i < _size; ++i) {
construct(_buffer + i, inVector._buffer[i]);
}
}
}
Vector& operator=(Vector& inVector)
{
if (this != &inVector)
{
Vector& operator=(Vector& inVector) {
if (this != &inVector) {
clear();
deallocate(_buffer);
_buffer = NULL;
@ -71,11 +64,9 @@ namespace Spine
_size = inVector._size;
_capacity = inVector._capacity;
if (_capacity > 0)
{
if (_capacity > 0) {
_buffer = allocate(_capacity);
for (size_t i = 0; i < _size; ++i)
{
for (size_t i = 0; i < _size; ++i) {
construct(_buffer + i, inVector._buffer[i]);
}
}
@ -84,18 +75,14 @@ namespace Spine
return *this;
}
~Vector()
{
~Vector() {
clear();
deallocate(_buffer);
}
bool contains(const T& inValue)
{
for (size_t i = 0; i < _size; ++i)
{
if (_buffer[i] == inValue)
{
bool contains(const T& inValue) {
for (size_t i = 0; i < _size; ++i) {
if (_buffer[i] == inValue) {
return true;
}
}
@ -103,12 +90,9 @@ namespace Spine
return false;
}
int indexOf(const T& inValue)
{
for (size_t i = 0; i < _size; ++i)
{
if (_buffer[i] == inValue)
{
int indexOf(const T& inValue) {
for (size_t i = 0; i < _size; ++i) {
if (_buffer[i] == inValue) {
return static_cast<int>(i);
}
}
@ -116,27 +100,22 @@ namespace Spine
return -1;
}
void push_back(const T& inValue)
{
if (_size == _capacity)
{
void push_back(const T& inValue) {
if (_size == _capacity) {
reserve();
}
construct(_buffer + _size++, inValue);
}
void insert(size_t inIndex, const T& inValue)
{
void insert(size_t inIndex, const T& inValue) {
assert(inIndex < _size);
if (_size == _capacity)
{
if (_size == _capacity) {
reserve();
}
for (size_t i = ++_size - 1; i > inIndex; --i)
{
for (size_t i = ++_size - 1; i > inIndex; --i) {
construct(_buffer + i, _buffer[i - 1]);
destroy(_buffer + (i - 1));
}
@ -144,16 +123,13 @@ namespace Spine
construct(_buffer + inIndex, inValue);
}
void erase(size_t inIndex)
{
void erase(size_t inIndex) {
assert(inIndex < _size);
--_size;
if (inIndex != _size)
{
for (size_t i = inIndex; i < _size; ++i)
{
if (inIndex != _size) {
for (size_t i = inIndex; i < _size; ++i) {
std::swap(_buffer[i], _buffer[i + 1]);
}
}
@ -161,66 +137,53 @@ namespace Spine
destroy(_buffer + _size);
}
void clear()
{
for (size_t i = 0; i < _size; ++i)
{
void clear() {
for (size_t i = 0; i < _size; ++i) {
destroy(_buffer + (_size - 1 - i));
}
_size = 0;
}
size_t size() const
{
size_t size() const {
return _size;
}
T& operator[](size_t inIndex)
{
T& operator[](size_t inIndex) {
assert(inIndex < _size);
return _buffer[inIndex];
}
void reserve(size_t inCapacity = 0)
{
void reserve(size_t inCapacity = 0) {
size_t newCapacity = inCapacity > 0 ? inCapacity : _capacity > 0 ? _capacity * 2 : 1;
if (newCapacity > _capacity)
{
if (newCapacity > _capacity) {
_buffer = REALLOC(_buffer, T, newCapacity);
_capacity = newCapacity;
}
}
void setSize(size_t inValue)
{
void setSize(size_t inValue) {
assert(inValue <= _capacity);
_size = inValue;
}
T* begin()
{
T* begin() {
return &_buffer[0];
}
T* end()
{
T* end() {
return &_buffer[_size];
}
friend bool operator==(Vector<T>& lhs, Vector<T>& rhs)
{
if (lhs.size() != rhs.size())
{
friend bool operator==(Vector<T>& lhs, Vector<T>& rhs) {
if (lhs.size() != rhs.size()) {
return false;
}
for (int i = 0, n = static_cast<int>(lhs.size()); i < n; ++i)
{
if (lhs[i] != rhs[i])
{
for (int i = 0, n = static_cast<int>(lhs.size()); i < n; ++i) {
if (lhs[i] != rhs[i]) {
return false;
}
}
@ -228,8 +191,7 @@ namespace Spine
return true;
}
friend bool operator!=(Vector<T>& lhs, Vector<T>& rhs)
{
friend bool operator!=(Vector<T>& lhs, Vector<T>& rhs) {
return !(lhs == rhs);
}
@ -238,8 +200,7 @@ namespace Spine
size_t _capacity;
T* _buffer;
T* allocate(size_t n)
{
T* allocate(size_t n) {
assert(n > 0);
T* ptr = MALLOC(T, n);
@ -249,24 +210,20 @@ namespace Spine
return ptr;
}
void deallocate(T* buffer)
{
if (_buffer)
{
void deallocate(T* buffer) {
if (_buffer) {
FREE(buffer);
}
}
void construct(T* buffer, const T& val)
{
void construct(T* buffer, const T& val) {
/// This is a placement new operator
/// which basically means we are contructing a new object
/// using pre-allocated memory
new (buffer) T(val);
}
void destroy(T* buffer)
{
void destroy(T* buffer) {
buffer->~T();
}
};

View File

@ -40,8 +40,7 @@ namespace Spine
class Slot;
/// An attachment with vertices that are transformed by one or more bones and can be deformed by a slot's vertices.
class VertexAttachment : public Attachment
{
class VertexAttachment : public Attachment {
friend class SkeletonBinary;
friend class SkeletonJson;
friend class DeformTimeline;

View File

@ -35,8 +35,7 @@
namespace Spine
{
class Vertices
{
class Vertices {
public:
Vector<int> _bones;
Vector<float> _vertices;

View File

@ -44,82 +44,65 @@ namespace Spine
Animation::Animation(std::string name, Vector<Timeline*>& timelines, float duration) :
_timelines(timelines),
_duration(duration),
_name(name)
{
_name(name) {
assert(_name.length() > 0);
}
Animation::~Animation()
{
Animation::~Animation() {
ContainerUtil::cleanUpVectorOfPointers(_timelines);
}
void Animation::apply(Skeleton& skeleton, float lastTime, float time, bool loop, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)
{
if (loop && _duration != 0)
{
void Animation::apply(Skeleton& skeleton, float lastTime, float time, bool loop, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) {
if (loop && _duration != 0) {
time = fmod(time, _duration);
if (lastTime > 0)
{
if (lastTime > 0) {
lastTime = fmod(lastTime, _duration);
}
}
for (int i = 0, n = static_cast<int>(_timelines.size()); i < n; ++i)
{
for (int i = 0, n = static_cast<int>(_timelines.size()); i < n; ++i) {
_timelines[i]->apply(skeleton, lastTime, time, pEvents, alpha, pose, direction);
}
}
std::string Animation::getName()
{
std::string Animation::getName() {
return _name;
}
Vector<Timeline*> Animation::getTimelines()
{
Vector<Timeline*> Animation::getTimelines() {
return _timelines;
}
void Animation::setTimelines(Vector<Timeline*> inValue)
{
void Animation::setTimelines(Vector<Timeline*> inValue) {
_timelines = inValue;
}
float Animation::getDuration()
{
float Animation::getDuration() {
return _duration;
}
void Animation::setDuration(float inValue)
{
void Animation::setDuration(float inValue) {
_duration = inValue;
}
int Animation::binarySearch(Vector<float>& values, float target, int step)
{
int Animation::binarySearch(Vector<float>& values, float target, int step) {
int low = 0;
int size = static_cast<int>(values.size());
int high = size / step - 2;
if (high == 0)
{
if (high == 0) {
return step;
}
int current = (int)(static_cast<uint32_t>(high) >> 1);
while (true)
{
if (values[(current + 1) * step] <= target)
{
while (true) {
if (values[(current + 1) * step] <= target) {
low = current + 1;
}
else
{
else {
high = current;
}
if (low == high)
{
if (low == high) {
return (low + 1) * step;
}
@ -127,30 +110,24 @@ namespace Spine
}
}
int Animation::binarySearch(Vector<float>& values, float target)
{
int Animation::binarySearch(Vector<float>& values, float target) {
int low = 0;
int size = static_cast<int>(values.size());
int high = size - 2;
if (high == 0)
{
if (high == 0) {
return 1;
}
int current = (int)(static_cast<uint32_t>(high) >> 1);
while (true)
{
if (values[(current + 1)] <= target)
{
while (true) {
if (values[(current + 1)] <= target) {
low = current + 1;
}
else
{
else {
high = current;
}
if (low == high)
{
if (low == high) {
return (low + 1);
}
@ -158,12 +135,9 @@ namespace Spine
}
}
int Animation::linearSearch(Vector<float>& values, float target, int step)
{
for (int i = 0, last = static_cast<int>(values.size()) - step; i <= last; i += step)
{
if (values[i] > target)
{
int Animation::linearSearch(Vector<float>& values, float target, int step) {
for (int i = 0, last = static_cast<int>(values.size()) - step; i <= last; i += step) {
if (values[i] > target) {
return i;
}
}

View File

@ -48,13 +48,11 @@
namespace Spine
{
void dummyOnAnimationEventFunc(AnimationState* state, EventType type, TrackEntry* entry, Event* event = NULL)
{
void dummyOnAnimationEventFunc(AnimationState* state, EventType type, TrackEntry* entry, Event* event = NULL) {
// Empty
}
TrackEntry::TrackEntry() : _animation(NULL), _next(NULL), _mixingFrom(NULL), _trackIndex(0), _loop(false), _eventThreshold(0), _attachmentThreshold(0), _drawOrderThreshold(0), _animationStart(0), _animationEnd(0), _animationLast(0), _nextAnimationLast(0), _delay(0), _trackTime(0), _trackLast(0), _nextTrackLast(0), _trackEnd(0), _timeScale(1.0f), _alpha(0), _mixTime(0), _mixDuration(0), _interruptAlpha(0), _totalAlpha(0), _onAnimationEventFunc(dummyOnAnimationEventFunc)
{
TrackEntry::TrackEntry() : _animation(NULL), _next(NULL), _mixingFrom(NULL), _trackIndex(0), _loop(false), _eventThreshold(0), _attachmentThreshold(0), _drawOrderThreshold(0), _animationStart(0), _animationEnd(0), _animationLast(0), _nextAnimationLast(0), _delay(0), _trackTime(0), _trackLast(0), _nextTrackLast(0), _trackEnd(0), _timeScale(1.0f), _alpha(0), _mixTime(0), _mixDuration(0), _interruptAlpha(0), _totalAlpha(0), _onAnimationEventFunc(dummyOnAnimationEventFunc) {
// Empty
}
@ -81,19 +79,15 @@ namespace Spine
void TrackEntry::setAnimationEnd(float inValue) { _animationEnd = inValue; }
float TrackEntry::getAnimationLast() { return _animationLast; }
void TrackEntry::setAnimationLast(float inValue)
{
void TrackEntry::setAnimationLast(float inValue) {
_animationLast = inValue;
_nextAnimationLast = inValue;
}
float TrackEntry::getAnimationTime()
{
if (_loop)
{
float TrackEntry::getAnimationTime() {
if (_loop) {
float duration = _animationEnd - _animationStart;
if (duration == 0)
{
if (duration == 0) {
return _animationStart;
}
@ -120,8 +114,7 @@ namespace Spine
TrackEntry* TrackEntry::getNext() { return _next; }
bool TrackEntry::isComplete()
{
bool TrackEntry::isComplete() {
return _trackTime >= _animationEnd - _animationStart;
}
@ -133,27 +126,22 @@ namespace Spine
TrackEntry* TrackEntry::getMixingFrom() { return _mixingFrom; }
void TrackEntry::resetRotationDirections()
{
void TrackEntry::resetRotationDirections() {
_timelinesRotation.clear();
}
void TrackEntry::setOnAnimationEventFunc(OnAnimationEventFunc inValue)
{
void TrackEntry::setOnAnimationEventFunc(OnAnimationEventFunc inValue) {
_onAnimationEventFunc = inValue;
}
TrackEntry* TrackEntry::setTimelineData(TrackEntry* to, Vector<TrackEntry*>& mixingToArray, Vector<int>& propertyIDs)
{
if (to != NULL)
{
TrackEntry* TrackEntry::setTimelineData(TrackEntry* to, Vector<TrackEntry*>& mixingToArray, Vector<int>& propertyIDs) {
if (to != NULL) {
mixingToArray.push_back(to);
}
TrackEntry* lastEntry = _mixingFrom != NULL ? _mixingFrom->setTimelineData(this, mixingToArray, propertyIDs) : this;
if (to != NULL)
{
if (to != NULL) {
mixingToArray.erase(mixingToArray.size() - 1);
}
@ -167,30 +155,22 @@ namespace Spine
_timelineDipMix.setSize(timelinesCount);
// outer:
for (int i = 0; i < timelinesCount; ++i)
{
for (int i = 0; i < timelinesCount; ++i) {
int id = timelines[i]->getPropertyId();
if (propertyIDs.contains(id))
{
if (propertyIDs.contains(id)) {
_timelineData[i] = AnimationState::Subsequent;
}
else
{
else {
propertyIDs.push_back(id);
if (to == NULL || !to->hasTimeline(id))
{
if (to == NULL || !to->hasTimeline(id)) {
_timelineData[i] = AnimationState::First;
}
else
{
for (int ii = mixingToLast; ii >= 0; --ii)
{
else {
for (int ii = mixingToLast; ii >= 0; --ii) {
TrackEntry* entry = mixingToArray[ii];
if (!entry->hasTimeline(id))
{
if (entry->_mixDuration > 0)
{
if (!entry->hasTimeline(id)) {
if (entry->_mixDuration > 0) {
_timelineData[i] = AnimationState::DipMix;
_timelineDipMix[i] = entry;
goto continue_outer; // continue outer;
@ -207,21 +187,17 @@ namespace Spine
return lastEntry;
}
bool TrackEntry::hasTimeline(int inId)
{
bool TrackEntry::hasTimeline(int inId) {
Vector<Timeline*>& timelines = _animation->_timelines;
for (int i = 0, n = static_cast<int>(timelines.size()); i < n; ++i)
{
if (timelines[i]->getPropertyId() == inId)
{
for (int i = 0, n = static_cast<int>(timelines.size()); i < n; ++i) {
if (timelines[i]->getPropertyId() == inId) {
return true;
}
}
return false;
}
void TrackEntry::reset()
{
void TrackEntry::reset() {
_animation = NULL;
_next = NULL;
_mixingFrom = NULL;
@ -236,74 +212,61 @@ namespace Spine
EventQueueEntry::EventQueueEntry(EventType eventType, TrackEntry* trackEntry, Event* event) :
_type(eventType),
_entry(trackEntry),
_event(event)
{
_event(event) {
// Empty
}
EventQueue* EventQueue::newEventQueue(AnimationState& state, Pool<TrackEntry>& trackEntryPool)
{
EventQueue* EventQueue::newEventQueue(AnimationState& state, Pool<TrackEntry>& trackEntryPool) {
EventQueue* ret = NEW(EventQueue);
new (ret) EventQueue(state, trackEntryPool);
return ret;
}
EventQueueEntry* EventQueue::newEventQueueEntry(EventType eventType, TrackEntry* entry, Event* event)
{
EventQueueEntry* EventQueue::newEventQueueEntry(EventType eventType, TrackEntry* entry, Event* event) {
EventQueueEntry* ret = NEW(EventQueueEntry);
new (ret) EventQueueEntry(eventType, entry, event);
return ret;
}
EventQueue::EventQueue(AnimationState& state, Pool<TrackEntry>& trackEntryPool) : _state(state), _trackEntryPool(trackEntryPool), _drainDisabled(false)
{
EventQueue::EventQueue(AnimationState& state, Pool<TrackEntry>& trackEntryPool) : _state(state), _trackEntryPool(trackEntryPool), _drainDisabled(false) {
// Empty
}
EventQueue::~EventQueue()
{
EventQueue::~EventQueue() {
ContainerUtil::cleanUpVectorOfPointers(_eventQueueEntries);
}
void EventQueue::start(TrackEntry* entry)
{
void EventQueue::start(TrackEntry* entry) {
_eventQueueEntries.push_back(newEventQueueEntry(EventType_Start, entry));
_state._animationsChanged = true;
}
void EventQueue::interrupt(TrackEntry* entry)
{
void EventQueue::interrupt(TrackEntry* entry) {
_eventQueueEntries.push_back(newEventQueueEntry(EventType_Interrupt, entry));
}
void EventQueue::end(TrackEntry* entry)
{
void EventQueue::end(TrackEntry* entry) {
_eventQueueEntries.push_back(newEventQueueEntry(EventType_End, entry));
_state._animationsChanged = true;
}
void EventQueue::dispose(TrackEntry* entry)
{
void EventQueue::dispose(TrackEntry* entry) {
_eventQueueEntries.push_back(newEventQueueEntry(EventType_Dispose, entry));
}
void EventQueue::complete(TrackEntry* entry)
{
void EventQueue::complete(TrackEntry* entry) {
_eventQueueEntries.push_back(newEventQueueEntry(EventType_Complete, entry));
}
void EventQueue::event(TrackEntry* entry, Event* event)
{
void EventQueue::event(TrackEntry* entry, Event* event) {
_eventQueueEntries.push_back(newEventQueueEntry(EventType_Event, entry, event));
}
/// Raises all events in the queue and drains the queue.
void EventQueue::drain()
{
if (_drainDisabled)
{
void EventQueue::drain() {
if (_drainDisabled) {
return;
}
@ -312,13 +275,11 @@ namespace Spine
AnimationState& state = _state;
// Don't cache _eventQueueEntries.size() so callbacks can queue their own events (eg, call setAnimation in AnimationState_Complete).
for (int i = 0; i < _eventQueueEntries.size(); ++i)
{
for (int i = 0; i < _eventQueueEntries.size(); ++i) {
EventQueueEntry* queueEntry = _eventQueueEntries[i];
TrackEntry* trackEntry = queueEntry->_entry;
switch (queueEntry->_type)
{
switch (queueEntry->_type) {
case EventType_Start:
case EventType_Interrupt:
case EventType_Complete:
@ -356,24 +317,19 @@ namespace Spine
_queue(EventQueue::newEventQueue(*this, _trackEntryPool)),
_animationsChanged(false),
_onAnimationEventFunc(dummyOnAnimationEventFunc),
_timeScale(1)
{
_timeScale(1) {
// Empty
}
AnimationState::~AnimationState()
{
AnimationState::~AnimationState() {
DESTROY(EventQueue, _queue);
}
void AnimationState::update(float delta)
{
void AnimationState::update(float delta) {
delta *= _timeScale;
for (int i = 0, n = static_cast<int>(_tracks.size()); i < n; ++i)
{
for (int i = 0, n = static_cast<int>(_tracks.size()); i < n; ++i) {
TrackEntry* currentP = _tracks[i];
if (currentP == NULL)
{
if (currentP == NULL) {
continue;
}
@ -384,11 +340,9 @@ namespace Spine
float currentDelta = delta * current._timeScale;
if (current._delay > 0)
{
if (current._delay > 0) {
current._delay -= currentDelta;
if (current._delay > 0)
{
if (current._delay > 0) {
continue;
}
currentDelta = -current._delay;
@ -396,26 +350,22 @@ namespace Spine
}
TrackEntry* next = current._next;
if (next != NULL)
{
if (next != NULL) {
// When the next entry's delay is passed, change to the next entry, preserving leftover time.
float nextTime = current._trackLast - next->_delay;
if (nextTime >= 0)
{
if (nextTime >= 0) {
next->_delay = 0;
next->_trackTime = nextTime + (delta * next->_timeScale);
current._trackTime += currentDelta;
setCurrent(i, next, true);
while (next->_mixingFrom != NULL)
{
while (next->_mixingFrom != NULL) {
next->_mixTime += currentDelta;
next = next->_mixingFrom;
}
continue;
}
}
else if (current._trackLast >= current._trackEnd && current._mixingFrom == NULL)
{
else if (current._trackLast >= current._trackEnd && current._mixingFrom == NULL) {
// clear the track when there is no next entry, the track end time is reached, and there is no mixingFrom.
_tracks[i] = NULL;
@ -424,13 +374,11 @@ namespace Spine
continue;
}
if (current._mixingFrom != NULL && updateMixingFrom(currentP, delta))
{
if (current._mixingFrom != NULL && updateMixingFrom(currentP, delta)) {
// End mixing from entries once all have completed.
TrackEntry* from = current._mixingFrom;
current._mixingFrom = NULL;
while (from != NULL)
{
while (from != NULL) {
_queue->end(from);
from = from->_mixingFrom;
}
@ -442,19 +390,15 @@ namespace Spine
_queue->drain();
}
bool AnimationState::apply(Skeleton& skeleton)
{
if (_animationsChanged)
{
bool AnimationState::apply(Skeleton& skeleton) {
if (_animationsChanged) {
animationsChanged();
}
bool applied = false;
for (int i = 0, n = static_cast<int>(_tracks.size()); i < n; ++i)
{
for (int i = 0, n = static_cast<int>(_tracks.size()); i < n; ++i) {
TrackEntry* currentP = _tracks[i];
if (currentP == NULL || currentP->_delay > 0)
{
if (currentP == NULL || currentP->_delay > 0) {
continue;
}
@ -465,12 +409,10 @@ namespace Spine
// apply mixing from entries first.
float mix = current._alpha;
if (current._mixingFrom != NULL)
{
if (current._mixingFrom != NULL) {
mix *= applyMixingFrom(currentP, skeleton, currentPose);
}
else if (current._trackTime >= current._trackEnd && current._next == NULL) //
{
else if (current._trackTime >= current._trackEnd && current._next == NULL) {
mix = 0; // Set to setup pose the last time the entry will be applied.
}
@ -478,44 +420,36 @@ namespace Spine
float animationLast = current._animationLast, animationTime = current.getAnimationTime();
int timelineCount = static_cast<int>(current._animation->_timelines.size());
Vector<Timeline*>& timelines = current._animation->_timelines;
if (mix == 1)
{
for (int ii = 0; ii < timelineCount; ++ii)
{
if (mix == 1) {
for (int ii = 0; ii < timelineCount; ++ii) {
timelines[ii]->apply(skeleton, animationLast, animationTime, &_events, 1, MixPose_Setup, MixDirection_In);
}
}
else
{
else {
Vector<int>& timelineData = current._timelineData;
bool firstFrame = current._timelinesRotation.size() == 0;
if (firstFrame)
{
if (firstFrame) {
current._timelinesRotation.reserve(timelines.size() << 1);
current._timelinesRotation.setSize(timelines.size() << 1);
}
Vector<float>& timelinesRotation = current._timelinesRotation;
for (int ii = 0; ii < timelineCount; ++ii)
{
for (int ii = 0; ii < timelineCount; ++ii) {
Timeline* timeline = timelines[ii];
assert(timeline);
MixPose pose = timelineData[ii] >= AnimationState::First ? MixPose_Setup : currentPose;
RotateTimeline* rotateTimeline = NULL;
if (timeline->getRTTI().derivesFrom(RotateTimeline::rtti))
{
if (timeline->getRTTI().derivesFrom(RotateTimeline::rtti)) {
rotateTimeline = static_cast<RotateTimeline*>(timeline);
}
if (rotateTimeline != NULL)
{
if (rotateTimeline != NULL) {
applyRotateTimeline(rotateTimeline, skeleton, animationTime, mix, pose, timelinesRotation, ii << 1, firstFrame);
}
else
{
else {
timeline->apply(skeleton, animationLast, animationTime, &_events, mix, pose, MixDirection_In);
}
}
@ -531,12 +465,10 @@ namespace Spine
return applied;
}
void AnimationState::clearTracks()
{
void AnimationState::clearTracks() {
bool oldDrainDisabled = _queue->_drainDisabled;
_queue->_drainDisabled = true;
for (int i = 0, n = static_cast<int>(_tracks.size()); i < n; ++i)
{
for (int i = 0, n = static_cast<int>(_tracks.size()); i < n; ++i) {
clearTrack(i);
}
_tracks.clear();
@ -544,16 +476,13 @@ namespace Spine
_queue->drain();
}
void AnimationState::clearTrack(int trackIndex)
{
if (trackIndex >= _tracks.size())
{
void AnimationState::clearTrack(int trackIndex) {
if (trackIndex >= _tracks.size()) {
return;
}
TrackEntry* current = _tracks[trackIndex];
if (current == NULL)
{
if (current == NULL) {
return;
}
@ -562,11 +491,9 @@ namespace Spine
disposeNext(current);
TrackEntry* entry = current;
while (true)
{
while (true) {
TrackEntry* from = entry->_mixingFrom;
if (from == NULL)
{
if (from == NULL) {
break;
}
@ -580,24 +507,20 @@ namespace Spine
_queue->drain();
}
TrackEntry* AnimationState::setAnimation(int trackIndex, std::string animationName, bool loop)
{
TrackEntry* AnimationState::setAnimation(int trackIndex, std::string animationName, bool loop) {
Animation* animation = _data._skeletonData.findAnimation(animationName);
assert(animation != NULL);
return setAnimation(trackIndex, animation, loop);
}
TrackEntry* AnimationState::setAnimation(int trackIndex, Animation* animation, bool loop)
{
TrackEntry* AnimationState::setAnimation(int trackIndex, Animation* animation, bool loop) {
assert(animation != NULL);
bool interrupt = true;
TrackEntry* current = expandToIndex(trackIndex);
if (current != NULL)
{
if (current->_nextTrackLast == -1)
{
if (current != NULL) {
if (current->_nextTrackLast == -1) {
// Don't mix from an entry that was never applied.
_tracks[trackIndex] = current->_mixingFrom;
_queue->interrupt(current);
@ -606,8 +529,7 @@ namespace Spine
current = current->_mixingFrom;
interrupt = false;
}
else
{
else {
disposeNext(current);
}
}
@ -619,46 +541,37 @@ namespace Spine
return entry;
}
TrackEntry* AnimationState::addAnimation(int trackIndex, std::string animationName, bool loop, float delay)
{
TrackEntry* AnimationState::addAnimation(int trackIndex, std::string animationName, bool loop, float delay) {
Animation* animation = _data._skeletonData.findAnimation(animationName);
assert(animation != NULL);
return addAnimation(trackIndex, animation, loop, delay);
}
TrackEntry* AnimationState::addAnimation(int trackIndex, Animation* animation, bool loop, float delay)
{
TrackEntry* AnimationState::addAnimation(int trackIndex, Animation* animation, bool loop, float delay) {
assert(animation != NULL);
TrackEntry* last = expandToIndex(trackIndex);
if (last != NULL)
{
while (last->_next != NULL)
{
if (last != NULL) {
while (last->_next != NULL) {
last = last->_next;
}
}
TrackEntry* entry = newTrackEntry(trackIndex, animation, loop, last);
if (last == NULL)
{
if (last == NULL) {
setCurrent(trackIndex, entry, true);
_queue->drain();
}
else
{
else {
last->_next = entry;
if (delay <= 0)
{
if (delay <= 0) {
float duration = last->_animationEnd - last->_animationStart;
if (duration != 0)
{
if (duration != 0) {
delay += duration * (1 + (int)(last->_trackTime / duration)) - _data.getMix(last->_animation, animation);
}
else
{
else {
delay = 0;
}
}
@ -668,18 +581,15 @@ namespace Spine
return entry;
}
TrackEntry* AnimationState::setEmptyAnimation(int trackIndex, float mixDuration)
{
TrackEntry* AnimationState::setEmptyAnimation(int trackIndex, float mixDuration) {
TrackEntry* entry = setAnimation(trackIndex, AnimationState::getEmptyAnimation(), false);
entry->_mixDuration = mixDuration;
entry->_trackEnd = mixDuration;
return entry;
}
TrackEntry* AnimationState::addEmptyAnimation(int trackIndex, float mixDuration, float delay)
{
if (delay <= 0)
{
TrackEntry* AnimationState::addEmptyAnimation(int trackIndex, float mixDuration, float delay) {
if (delay <= 0) {
delay -= mixDuration;
}
@ -689,15 +599,12 @@ namespace Spine
return entry;
}
void AnimationState::setEmptyAnimations(float mixDuration)
{
void AnimationState::setEmptyAnimations(float mixDuration) {
bool oldDrainDisabled = _queue->_drainDisabled;
_queue->_drainDisabled = true;
for (int i = 0, n = static_cast<int>(_tracks.size()); i < n; ++i)
{
for (int i = 0, n = static_cast<int>(_tracks.size()); i < n; ++i) {
TrackEntry* current = _tracks[i];
if (current != NULL)
{
if (current != NULL) {
setEmptyAnimation(i, mixDuration);
}
}
@ -705,84 +612,69 @@ namespace Spine
_queue->drain();
}
TrackEntry* AnimationState::getCurrent(int trackIndex)
{
TrackEntry* AnimationState::getCurrent(int trackIndex) {
return trackIndex >= _tracks.size() ? NULL : _tracks[trackIndex];
}
AnimationStateData& AnimationState::getData()
{
AnimationStateData& AnimationState::getData() {
return _data;
}
Vector<TrackEntry*> AnimationState::getTracks()
{
Vector<TrackEntry*> AnimationState::getTracks() {
return _tracks;
}
float AnimationState::getTimeScale()
{
float AnimationState::getTimeScale() {
return _timeScale;
}
void AnimationState::setTimeScale(float inValue)
{
void AnimationState::setTimeScale(float inValue) {
_timeScale = inValue;
}
void AnimationState::setOnAnimationEventFunc(OnAnimationEventFunc inValue)
{
void AnimationState::setOnAnimationEventFunc(OnAnimationEventFunc inValue) {
_onAnimationEventFunc = inValue;
}
void AnimationState::setRendererObject(void* inValue)
{
void AnimationState::setRendererObject(void* inValue) {
_rendererObject = inValue;
}
void* AnimationState::getRendererObject()
{
void* AnimationState::getRendererObject() {
return _rendererObject;
}
Animation* AnimationState::getEmptyAnimation()
{
Animation* AnimationState::getEmptyAnimation() {
static Vector<Timeline*> timelines;
static Animation ret(std::string("<empty>"), timelines, 0);
return &ret;
}
void AnimationState::applyRotateTimeline(RotateTimeline* rotateTimeline, Skeleton& skeleton, float time, float alpha, MixPose pose, Vector<float>& timelinesRotation, int i, bool firstFrame)
{
if (firstFrame)
{
void AnimationState::applyRotateTimeline(RotateTimeline* rotateTimeline, Skeleton& skeleton, float time, float alpha, MixPose pose, Vector<float>& timelinesRotation, int i, bool firstFrame) {
if (firstFrame) {
timelinesRotation[i] = 0;
}
if (alpha == 1)
{
if (alpha == 1) {
rotateTimeline->apply(skeleton, 0, time, NULL, 1, pose, MixDirection_In);
return;
}
Bone* bone = skeleton._bones[rotateTimeline->_boneIndex];
Vector<float> frames = rotateTimeline->_frames;
if (time < frames[0])
{
if (pose == MixPose_Setup)
{
if (time < frames[0]) {
if (pose == MixPose_Setup) {
bone->_rotation = bone->_data._rotation;
}
return;
}
float r2;
if (time >= frames[frames.size() - RotateTimeline::ENTRIES]) // Time is after last frame.
{
if (time >= frames[frames.size() - RotateTimeline::ENTRIES]) {
// Time is after last frame.
r2 = bone->_data._rotation + frames[frames.size() + RotateTimeline::PREV_ROTATION];
}
else
{
else {
// Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(frames, time, RotateTimeline::ENTRIES);
float prevRotation = frames[frame + RotateTimeline::PREV_ROTATION];
@ -798,40 +690,33 @@ namespace Spine
// Mix between rotations using the direction of the shortest route on the first frame while detecting crosses.
float r1 = pose == MixPose_Setup ? bone->_data._rotation : bone->_rotation;
float total, diff = r2 - r1;
if (diff == 0)
{
if (diff == 0) {
total = timelinesRotation[i];
}
else
{
else {
diff -= (16384 - (int)(16384.499999999996 - diff / 360)) * 360;
float lastTotal, lastDiff;
if (firstFrame)
{
if (firstFrame) {
lastTotal = 0;
lastDiff = diff;
}
else
{
else {
lastTotal = timelinesRotation[i]; // Angle and direction of mix, including loops.
lastDiff = timelinesRotation[i + 1]; // Difference between bones.
}
bool current = diff > 0, dir = lastTotal >= 0;
// Detect cross at 0 (not 180).
if (sign(lastDiff) != sign(diff) && fabs(lastDiff) <= 90)
{
if (sign(lastDiff) != sign(diff) && fabs(lastDiff) <= 90) {
// A cross after a 360 rotation is a loop.
if (fabs(lastTotal) > 180)
{
if (fabs(lastTotal) > 180) {
lastTotal += 360 * sign(lastTotal);
}
dir = current;
}
total = diff + lastTotal - fmod(lastTotal, 360); // Store loops as part of lastTotal.
if (dir != current)
{
if (dir != current) {
total += 360 * sign(lastTotal);
}
timelinesRotation[i] = total;
@ -841,22 +726,18 @@ namespace Spine
bone->_rotation = r1 - (16384 - (int)(16384.499999999996 - r1 / 360)) * 360;
}
bool AnimationState::updateMixingFrom(TrackEntry* to, float delta)
{
bool AnimationState::updateMixingFrom(TrackEntry* to, float delta) {
TrackEntry* from = to->_mixingFrom;
if (from == NULL)
{
if (from == NULL) {
return true;
}
bool finished = updateMixingFrom(from, delta);
// Require mixTime > 0 to ensure the mixing from entry was applied at least once.
if (to->_mixTime > 0 && (to->_mixTime >= to->_mixDuration || to->_timeScale == 0))
{
if (to->_mixTime > 0 && (to->_mixTime >= to->_mixDuration || to->_timeScale == 0)) {
// Require totalAlpha == 0 to ensure mixing is complete, unless mixDuration == 0 (the transition is a single frame).
if (from->_totalAlpha == 0 || to->_mixDuration == 0)
{
if (from->_totalAlpha == 0 || to->_mixDuration == 0) {
to->_mixingFrom = from->_mixingFrom;
to->_interruptAlpha = from->_interruptAlpha;
_queue->end(from);
@ -872,26 +753,21 @@ namespace Spine
return false;
}
float AnimationState::applyMixingFrom(TrackEntry* to, Skeleton& skeleton, MixPose currentPose)
{
float AnimationState::applyMixingFrom(TrackEntry* to, Skeleton& skeleton, MixPose currentPose) {
TrackEntry* from = to->_mixingFrom;
if (from->_mixingFrom != NULL)
{
if (from->_mixingFrom != NULL) {
applyMixingFrom(from, skeleton, currentPose);
}
float mix;
if (to->_mixDuration == 0)
{
if (to->_mixDuration == 0) {
// Single frame mix to undo mixingFrom changes.
mix = 1;
currentPose = MixPose_Setup;
}
else
{
else {
mix = to->_mixTime / to->_mixDuration;
if (mix > 1)
{
if (mix > 1) {
mix = 1;
}
}
@ -905,8 +781,7 @@ namespace Spine
Vector<TrackEntry*>& timelineDipMix = from->_timelineDipMix;
bool firstFrame = from->_timelinesRotation.size() == 0;
if (firstFrame)
{
if (firstFrame) {
// from.timelinesRotation.setSize
from->_timelinesRotation.reserve(timelines.size() << 1);
from->_timelinesRotation.setSize(timelines.size() << 1);
@ -917,18 +792,14 @@ namespace Spine
MixPose pose;
float alphaDip = from->_alpha * to->_interruptAlpha, alphaMix = alphaDip * (1 - mix), alpha;
from->_totalAlpha = 0;
for (int i = 0; i < timelineCount; ++i)
{
for (int i = 0; i < timelineCount; ++i) {
Timeline* timeline = timelines[i];
switch (timelineData[i])
{
switch (timelineData[i]) {
case Subsequent:
if (!attachments && timeline->getRTTI().derivesFrom(AttachmentTimeline::rtti))
{
if (!attachments && timeline->getRTTI().derivesFrom(AttachmentTimeline::rtti)) {
continue;
}
if (!drawOrder && timeline->getRTTI().derivesFrom(DrawOrderTimeline::rtti))
{
if (!drawOrder && timeline->getRTTI().derivesFrom(DrawOrderTimeline::rtti)) {
continue;
}
@ -952,23 +823,19 @@ namespace Spine
from->_totalAlpha += alpha;
RotateTimeline* rotateTimeline = NULL;
if (timeline->getRTTI().derivesFrom(RotateTimeline::rtti))
{
if (timeline->getRTTI().derivesFrom(RotateTimeline::rtti)) {
rotateTimeline = static_cast<RotateTimeline*>(timeline);
}
if (rotateTimeline != NULL)
{
if (rotateTimeline != NULL) {
applyRotateTimeline(rotateTimeline, skeleton, animationTime, alpha, pose, timelinesRotation, i << 1, firstFrame);
}
else
{
else {
timeline->apply(skeleton, animationLast, animationTime, eventBuffer, alpha, pose, MixDirection_Out);
}
}
if (to->_mixDuration > 0)
{
if (to->_mixDuration > 0) {
queueEvents(from, animationTime);
}
@ -979,23 +846,19 @@ namespace Spine
return mix;
}
void AnimationState::queueEvents(TrackEntry* entry, float animationTime)
{
void AnimationState::queueEvents(TrackEntry* entry, float animationTime) {
float animationStart = entry->_animationStart, animationEnd = entry->_animationEnd;
float duration = animationEnd - animationStart;
float trackLastWrapped = fmodf(entry->_trackLast, duration);
// Queue events before complete.
int i = 0, n = static_cast<int>(_events.size());
for (; i < n; ++i)
{
for (; i < n; ++i) {
Event* e = _events[i];
if (e->_time < trackLastWrapped)
{
if (e->_time < trackLastWrapped) {
break;
}
if (e->_time > animationEnd)
{
if (e->_time > animationEnd) {
// Discard events outside animation start/end.
continue;
}
@ -1003,17 +866,14 @@ namespace Spine
}
// Queue complete if completed a loop iteration or the animation.
if (entry->_loop ? (trackLastWrapped > fmod(entry->_trackTime, duration)) : (animationTime >= animationEnd && entry->_animationLast < animationEnd))
{
if (entry->_loop ? (trackLastWrapped > fmod(entry->_trackTime, duration)) : (animationTime >= animationEnd && entry->_animationLast < animationEnd)) {
_queue->complete(entry);
}
// Queue events after complete.
for (; i < n; ++i)
{
for (; i < n; ++i) {
Event* e = _events[i];
if (e->_time < animationStart)
{
if (e->_time < animationStart) {
// Discard events outside animation start/end.
continue;
}
@ -1021,15 +881,12 @@ namespace Spine
}
}
void AnimationState::setCurrent(int index, TrackEntry* current, bool interrupt)
{
void AnimationState::setCurrent(int index, TrackEntry* current, bool interrupt) {
TrackEntry* from = expandToIndex(index);
_tracks[index] = current;
if (from != NULL)
{
if (interrupt)
{
if (from != NULL) {
if (interrupt) {
_queue->interrupt(from);
}
@ -1037,8 +894,7 @@ namespace Spine
current->_mixTime = 0;
// Store interrupted mix percentage.
if (from->_mixingFrom != NULL && from->_mixDuration > 0)
{
if (from->_mixingFrom != NULL && from->_mixDuration > 0) {
current->_interruptAlpha *= MIN(1, from->_mixTime / from->_mixDuration);
}
@ -1048,23 +904,19 @@ namespace Spine
_queue->start(current); // triggers animationsChanged
}
TrackEntry* AnimationState::expandToIndex(int index)
{
if (index < _tracks.size())
{
TrackEntry* AnimationState::expandToIndex(int index) {
if (index < _tracks.size()) {
return _tracks[index];
}
while (index >= _tracks.size())
{
while (index >= _tracks.size()) {
_tracks.push_back(NULL);
}
return NULL;
}
TrackEntry* AnimationState::newTrackEntry(int trackIndex, Animation* animation, bool loop, TrackEntry* last)
{
TrackEntry* AnimationState::newTrackEntry(int trackIndex, Animation* animation, bool loop, TrackEntry* last) {
TrackEntry* entryP = _trackEntryPool.obtain(); // Pooling
TrackEntry& entry = *entryP;
@ -1096,28 +948,23 @@ namespace Spine
return entryP;
}
void AnimationState::disposeNext(TrackEntry* entry)
{
void AnimationState::disposeNext(TrackEntry* entry) {
TrackEntry* next = entry->_next;
while (next != NULL)
{
while (next != NULL) {
_queue->dispose(next);
next = next->_next;
}
entry->_next = NULL;
}
void AnimationState::animationsChanged()
{
void AnimationState::animationsChanged() {
_animationsChanged = false;
_propertyIDs.clear();
for (int i = 0, n = static_cast<int>(_tracks.size()); i < n; ++i)
{
for (int i = 0, n = static_cast<int>(_tracks.size()); i < n; ++i) {
TrackEntry* entry = _tracks[i];
if (entry != NULL)
{
if (entry != NULL) {
entry->setTimelineData(NULL, _mixingTo, _propertyIDs);
}
}

View File

@ -35,21 +35,18 @@
namespace Spine
{
AnimationStateData::AnimationStateData(SkeletonData& skeletonData) : _skeletonData(skeletonData), _defaultMix(0)
{
AnimationStateData::AnimationStateData(SkeletonData& skeletonData) : _skeletonData(skeletonData), _defaultMix(0) {
// Empty
}
void AnimationStateData::setMix(std::string fromName, std::string toName, float duration)
{
void AnimationStateData::setMix(std::string fromName, std::string toName, float duration) {
Animation* from = _skeletonData.findAnimation(fromName);
Animation* to = _skeletonData.findAnimation(toName);
setMix(from, to, duration);
}
void AnimationStateData::setMix(Animation* from, Animation* to, float duration)
{
void AnimationStateData::setMix(Animation* from, Animation* to, float duration) {
assert(from != NULL);
assert(to != NULL);
@ -59,8 +56,7 @@ namespace Spine
_animationToMixTime.insert(key, duration);
}
float AnimationStateData::getMix(Animation* from, Animation* to)
{
float AnimationStateData::getMix(Animation* from, Animation* to) {
assert(from != NULL);
assert(to != NULL);
@ -68,52 +64,43 @@ namespace Spine
HashMap<AnimationPair, float, HashAnimationPair>::Iterator i = _animationToMixTime.find(key);
if (i != _animationToMixTime.end())
{
if (i != _animationToMixTime.end()) {
return i.second();
}
return _defaultMix;
}
SkeletonData& AnimationStateData::getSkeletonData()
{
SkeletonData& AnimationStateData::getSkeletonData() {
return _skeletonData;
}
float AnimationStateData::getDefaultMix()
{
float AnimationStateData::getDefaultMix() {
return _defaultMix;
}
void AnimationStateData::setDefaultMix(float inValue)
{
void AnimationStateData::setDefaultMix(float inValue) {
_defaultMix = inValue;
}
AnimationStateData::AnimationPair::AnimationPair(Animation* a1, Animation* a2) : _a1(a1), _a2(a2)
{
AnimationStateData::AnimationPair::AnimationPair(Animation* a1, Animation* a2) : _a1(a1), _a2(a2) {
// Empty
}
bool AnimationStateData::AnimationPair::operator==(const AnimationPair &other) const
{
bool AnimationStateData::AnimationPair::operator==(const AnimationPair &other) const {
return _a1->_name == other._a1->_name && _a2->_name == other._a2->_name;
}
std::size_t AnimationStateData::HashAnimationPair::operator()(const Spine::AnimationStateData::AnimationPair& val) const
{
std::size_t AnimationStateData::HashAnimationPair::operator()(const Spine::AnimationStateData::AnimationPair& val) const {
std::size_t h1 = 7;
size_t strlen = val._a1->_name.length();
for (int i = 0; i < strlen; ++i)
{
for (int i = 0; i < strlen; ++i) {
h1 = h1 * 31 + val._a1->_name.at(i);
}
std::size_t h2 = 7;
strlen = val._a2->_name.length();
for (int i = 0; i < strlen; ++i)
{
for (int i = 0; i < strlen; ++i) {
h2 = h2 * 31 + val._a2->_name.at(i);
}

View File

@ -38,8 +38,7 @@
namespace Spine
{
Atlas::Atlas(const char* path, TextureLoader& textureLoader) : _textureLoader(textureLoader)
{
Atlas::Atlas(const char* path, TextureLoader& textureLoader) : _textureLoader(textureLoader) {
int dirLength;
char *dir;
int length;
@ -56,8 +55,7 @@ namespace Spine
dir[dirLength] = '\0';
data = SPINE_EXTENSION->spineReadFile(path, &length);
if (data)
{
if (data) {
load(data, length, dir);
}
@ -65,21 +63,17 @@ namespace Spine
FREE(dir);
}
Atlas::Atlas(const char* data, int length, const char* dir, TextureLoader& textureLoader) : _textureLoader(textureLoader)
{
Atlas::Atlas(const char* data, int length, const char* dir, TextureLoader& textureLoader) : _textureLoader(textureLoader) {
load(data, length, dir);
}
Atlas::~Atlas()
{
Atlas::~Atlas() {
ContainerUtil::cleanUpVectorOfPointers(_pages);
ContainerUtil::cleanUpVectorOfPointers(_regions);
}
void Atlas::flipV()
{
for (size_t i = 0, n = _regions.size(); i < n; ++i)
{
void Atlas::flipV() {
for (size_t i = 0, n = _regions.size(); i < n; ++i) {
AtlasRegion* regionP = _regions[i];
AtlasRegion& region = *regionP;
region.v = 1 - region.v;
@ -87,12 +81,9 @@ namespace Spine
}
}
AtlasRegion* Atlas::findRegion(std::string name)
{
for (size_t i = 0, n = _regions.size(); i < n; ++i)
{
if (_regions[i]->name == name)
{
AtlasRegion* Atlas::findRegion(std::string name) {
for (size_t i = 0, n = _regions.size(); i < n; ++i) {
if (_regions[i]->name == name) {
return _regions[i];
}
}
@ -100,16 +91,13 @@ namespace Spine
return NULL;
}
void Atlas::dispose()
{
for (size_t i = 0, n = _pages.size(); i < n; ++i)
{
void Atlas::dispose() {
for (size_t i = 0, n = _pages.size(); i < n; ++i) {
_textureLoader.unload(_pages[i]->rendererObject);
}
}
void Atlas::load(const char* begin, int length, const char* dir)
{
void Atlas::load(const char* begin, int length, const char* dir) {
static const char* formatNames[] = { "", "Alpha", "Intensity", "LuminanceAlpha", "RGB565", "RGBA4444", "RGB888", "RGBA8888" };
static const char* textureFilterNames[] = { "", "Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest",
"MipMapNearestLinear", "MipMapLinearLinear" };
@ -123,19 +111,15 @@ namespace Spine
Str str;
Str tuple[4];
while (readLine(&begin, end, &str))
{
if (str.end - str.begin == 0)
{
while (readLine(&begin, end, &str)) {
if (str.end - str.begin == 0) {
page = 0;
}
else if (!page)
{
else if (!page) {
char* name = mallocString(&str);
char* path = MALLOC(char, dirLength + needsSlash + strlen(name) + 1);
memcpy(path, dir, dirLength);
if (needsSlash)
{
if (needsSlash) {
path[dirLength] = '/';
}
strcpy(path + dirLength + needsSlash, name);
@ -163,21 +147,16 @@ namespace Spine
page->uWrap = TextureWrap_ClampToEdge;
page->vWrap = TextureWrap_ClampToEdge;
if (!equals(&str, "none"))
{
if (str.end - str.begin == 1)
{
if (*str.begin == 'x')
{
if (!equals(&str, "none")) {
if (str.end - str.begin == 1) {
if (*str.begin == 'x') {
page->uWrap = TextureWrap_Repeat;
}
else if (*str.begin == 'y')
{
else if (*str.begin == 'y') {
page->vWrap = TextureWrap_Repeat;
}
}
else if (equals(&str, "xy"))
{
else if (equals(&str, "xy")) {
page->uWrap = TextureWrap_Repeat;
page->vWrap = TextureWrap_Repeat;
}
@ -189,8 +168,7 @@ namespace Spine
_pages.push_back(page);
}
else
{
else {
AtlasRegion* region = NEW(AtlasRegion);
new (region) AtlasRegion();
@ -210,13 +188,11 @@ namespace Spine
region->u = region->x / (float)page->width;
region->v = region->y / (float)page->height;
if (region->rotate)
{
if (region->rotate) {
region->u2 = (region->x + region->height) / (float)page->width;
region->v2 = (region->y + region->width) / (float)page->height;
}
else
{
else {
region->u2 = (region->x + region->width) / (float)page->width;
region->v2 = (region->y + region->height) / (float)page->height;
}
@ -224,8 +200,7 @@ namespace Spine
count = readTuple(&begin, end, tuple);
assert(count);
if (count == 4)
{
if (count == 4) {
/* split is optional */
region->splits.reserve(4);
region->splits.setSize(4);
@ -237,8 +212,7 @@ namespace Spine
count = readTuple(&begin, end, tuple);
assert(count);
if (count == 4)
{
if (count == 4) {
/* pad is optional, but only present with splits */
region->pads.reserve(4);
region->pads.setSize(4);
@ -267,67 +241,55 @@ namespace Spine
}
}
void Atlas::trim(Str* str)
{
while (isspace((unsigned char)*str->begin) && str->begin < str->end)
{
void Atlas::trim(Str* str) {
while (isspace((unsigned char)*str->begin) && str->begin < str->end) {
(str->begin)++;
}
if (str->begin == str->end)
{
if (str->begin == str->end) {
return;
}
str->end--;
while (isspace((unsigned char)*str->end) && str->end >= str->begin)
{
while (isspace((unsigned char)*str->end) && str->end >= str->begin) {
str->end--;
}
str->end++;
}
int Atlas::readLine(const char** begin, const char* end, Str* str)
{
if (*begin == end)
{
int Atlas::readLine(const char** begin, const char* end, Str* str) {
if (*begin == end) {
return 0;
}
str->begin = *begin;
/* Find next delimiter. */
while (*begin != end && **begin != '\n')
{
while (*begin != end && **begin != '\n') {
(*begin)++;
}
str->end = *begin;
trim(str);
if (*begin != end)
{
if (*begin != end) {
(*begin)++;
}
return 1;
}
int Atlas::beginPast(Str* str, char c)
{
int Atlas::beginPast(Str* str, char c) {
const char* begin = str->begin;
while (1)
{
while (1) {
char lastSkippedChar = *begin;
if (begin == str->end)
{
if (begin == str->end) {
return 0;
}
begin++;
if (lastSkippedChar == c)
{
if (lastSkippedChar == c) {
break;
}
}
@ -335,11 +297,9 @@ namespace Spine
return 1;
}
int Atlas::readValue(const char** begin, const char* end, Str* str)
{
int Atlas::readValue(const char** begin, const char* end, Str* str) {
readLine(begin, end, str);
if (!beginPast(str, ':'))
{
if (!beginPast(str, ':')) {
return 0;
}
@ -347,21 +307,17 @@ namespace Spine
return 1;
}
int Atlas::readTuple(const char** begin, const char* end, Str tuple[])
{
int Atlas::readTuple(const char** begin, const char* end, Str tuple[]) {
int i;
Str str = { NULL, NULL };
readLine(begin, end, &str);
if (!beginPast(&str, ':'))
{
if (!beginPast(&str, ':')) {
return 0;
}
for (i = 0; i < 3; ++i)
{
for (i = 0; i < 3; ++i) {
tuple[i].begin = str.begin;
if (!beginPast(&str, ','))
{
if (!beginPast(&str, ',')) {
break;
}
@ -376,8 +332,7 @@ namespace Spine
return i + 1;
}
char* Atlas::mallocString(Str* str)
{
char* Atlas::mallocString(Str* str) {
int length = (int)(str->end - str->begin);
char* string = MALLOC(char, length + 1);
memcpy(string, str->begin, length);
@ -385,27 +340,22 @@ namespace Spine
return string;
}
int Atlas::indexOf(const char** array, int count, Str* str)
{
int Atlas::indexOf(const char** array, int count, Str* str) {
int length = (int)(str->end - str->begin);
int i;
for (i = count - 1; i >= 0; i--)
{
if (strncmp(array[i], str->begin, length) == 0)
{
for (i = count - 1; i >= 0; i--) {
if (strncmp(array[i], str->begin, length) == 0) {
return i;
}
}
return 0;
}
int Atlas::equals(Str* str, const char* other)
{
int Atlas::equals(Str* str, const char* other) {
return strncmp(other, str->begin, str->end - str->begin) == 0;
}
int Atlas::toInt(Str* str)
{
int Atlas::toInt(Str* str) {
return (int)strtol(str->begin, (char**)&str->end, 10);
}
}

View File

@ -44,13 +44,11 @@ namespace Spine
{
RTTI_IMPL(AtlasAttachmentLoader, AttachmentLoader);
AtlasAttachmentLoader::AtlasAttachmentLoader(Vector<Atlas*>& inAtlasArray) : AttachmentLoader(), _atlasArray(inAtlasArray)
{
AtlasAttachmentLoader::AtlasAttachmentLoader(Vector<Atlas*>& inAtlasArray) : AttachmentLoader(), _atlasArray(inAtlasArray) {
// Empty
}
RegionAttachment* AtlasAttachmentLoader::newRegionAttachment(Skin& skin, std::string name, std::string path)
{
RegionAttachment* AtlasAttachmentLoader::newRegionAttachment(Skin& skin, std::string name, std::string path) {
AtlasRegion* regionP = findRegion(path);
assert(regionP != NULL);
@ -72,8 +70,7 @@ namespace Spine
return attachmentP;
}
MeshAttachment* AtlasAttachmentLoader::newMeshAttachment(Skin& skin, std::string name, std::string path)
{
MeshAttachment* AtlasAttachmentLoader::newMeshAttachment(Skin& skin, std::string name, std::string path) {
AtlasRegion* regionP = findRegion(path);
assert(regionP != NULL);
@ -99,47 +96,40 @@ namespace Spine
return attachmentP;
}
BoundingBoxAttachment* AtlasAttachmentLoader::newBoundingBoxAttachment(Skin& skin, std::string name)
{
BoundingBoxAttachment* AtlasAttachmentLoader::newBoundingBoxAttachment(Skin& skin, std::string name) {
BoundingBoxAttachment* attachmentP = NEW(BoundingBoxAttachment);
new (attachmentP) BoundingBoxAttachment(name);
return attachmentP;
}
PathAttachment* AtlasAttachmentLoader::newPathAttachment(Skin& skin, std::string name)
{
PathAttachment* AtlasAttachmentLoader::newPathAttachment(Skin& skin, std::string name) {
PathAttachment* attachmentP = NEW(PathAttachment);
new (attachmentP) PathAttachment(name);
return attachmentP;
}
PointAttachment* AtlasAttachmentLoader::newPointAttachment(Skin& skin, std::string name)
{
PointAttachment* AtlasAttachmentLoader::newPointAttachment(Skin& skin, std::string name) {
PointAttachment* attachmentP = NEW(PointAttachment);
new (attachmentP) PointAttachment(name);
return attachmentP;
}
ClippingAttachment* AtlasAttachmentLoader::newClippingAttachment(Skin& skin, std::string name)
{
ClippingAttachment* AtlasAttachmentLoader::newClippingAttachment(Skin& skin, std::string name) {
ClippingAttachment* attachmentP = NEW(ClippingAttachment);
new (attachmentP) ClippingAttachment(name);
return attachmentP;
}
AtlasRegion* AtlasAttachmentLoader::findRegion(std::string name)
{
AtlasRegion* AtlasAttachmentLoader::findRegion(std::string name) {
AtlasRegion* ret;
for (int i = 0; i < _atlasArray.size(); i++)
{
for (int i = 0; i < _atlasArray.size(); i++) {
ret = _atlasArray[i]->findRegion(name);
if (ret != NULL)
{
if (ret != NULL) {
return ret;
}
}

View File

@ -36,13 +36,11 @@ namespace Spine
{
RTTI_IMPL_NOPARENT(Attachment);
Attachment::Attachment(std::string name) : _name(name)
{
Attachment::Attachment(std::string name) : _name(name) {
assert(_name.length() > 0);
}
const std::string& Attachment::getName()
{
const std::string& Attachment::getName() {
return _name;
}
}

View File

@ -42,13 +42,11 @@ namespace Spine
{
RTTI_IMPL_NOPARENT(AttachmentLoader);
AttachmentLoader::AttachmentLoader()
{
AttachmentLoader::AttachmentLoader() {
// Empty
}
AttachmentLoader::~AttachmentLoader()
{
AttachmentLoader::~AttachmentLoader() {
// Empty
}
}

View File

@ -42,38 +42,32 @@ namespace Spine
{
RTTI_IMPL(AttachmentTimeline, Timeline);
AttachmentTimeline::AttachmentTimeline(int frameCount) : Timeline(), _slotIndex(0)
{
AttachmentTimeline::AttachmentTimeline(int frameCount) : Timeline(), _slotIndex(0) {
_frames.reserve(frameCount);
_attachmentNames.reserve(frameCount);
_frames.setSize(frameCount);
for (int i = 0; i < frameCount; ++i)
{
for (int i = 0; i < frameCount; ++i) {
_attachmentNames.push_back(std::string(""));
}
}
void AttachmentTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)
{
void AttachmentTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) {
assert(_slotIndex < skeleton._slots.size());
std::string attachmentName;
Slot* slotP = skeleton._slots[_slotIndex];
Slot& slot = *slotP;
if (direction == MixDirection_Out && pose == MixPose_Setup)
{
if (direction == MixDirection_Out && pose == MixPose_Setup) {
attachmentName = slot._data._attachmentName;
slot._attachment = attachmentName.length() == 0 ? NULL : skeleton.getAttachment(_slotIndex, attachmentName);
return;
}
if (time < _frames[0])
{
if (time < _frames[0]) {
// Time is before first frame.
if (pose == MixPose_Setup)
{
if (pose == MixPose_Setup) {
attachmentName = slot._data._attachmentName;
slot._attachment = attachmentName.length() == 0 ? NULL : skeleton.getAttachment(_slotIndex, attachmentName);
}
@ -81,12 +75,11 @@ namespace Spine
}
int frameIndex;
if (time >= _frames[_frames.size() - 1]) // Time is after last frame.
{
if (time >= _frames[_frames.size() - 1]) {
// Time is after last frame.
frameIndex = static_cast<int>(_frames.size()) - 1;
}
else
{
else {
frameIndex = Animation::binarySearch(_frames, time, 1) - 1;
}
@ -94,49 +87,40 @@ namespace Spine
slot._attachment = attachmentName.length() == 0 ? NULL : skeleton.getAttachment(_slotIndex, attachmentName);
}
int AttachmentTimeline::getPropertyId()
{
int AttachmentTimeline::getPropertyId() {
return ((int)TimelineType_Attachment << 24) + _slotIndex;
}
void AttachmentTimeline::setFrame(int frameIndex, float time, std::string attachmentName)
{
void AttachmentTimeline::setFrame(int frameIndex, float time, std::string attachmentName) {
_frames[frameIndex] = time;
_attachmentNames[frameIndex] = attachmentName;
}
int AttachmentTimeline::getSlotIndex()
{
int AttachmentTimeline::getSlotIndex() {
return _slotIndex;
}
void AttachmentTimeline::setSlotIndex(int inValue)
{
void AttachmentTimeline::setSlotIndex(int inValue) {
_slotIndex = inValue;
}
Vector<float>& AttachmentTimeline::getFrames()
{
Vector<float>& AttachmentTimeline::getFrames() {
return _frames;
}
void AttachmentTimeline::setFrames(Vector<float>& inValue)
{
void AttachmentTimeline::setFrames(Vector<float>& inValue) {
_frames = inValue;
}
Vector<std::string> AttachmentTimeline::getAttachmentNames()
{
Vector<std::string> AttachmentTimeline::getAttachmentNames() {
return _attachmentNames;
}
void AttachmentTimeline::setAttachmentNames(Vector<std::string>& inValue)
{
void AttachmentTimeline::setAttachmentNames(Vector<std::string>& inValue) {
_attachmentNames = inValue;
}
int AttachmentTimeline::getFrameCount()
{
int AttachmentTimeline::getFrameCount() {
return static_cast<int>(_frames.size());
}
}

View File

@ -42,13 +42,11 @@ namespace Spine
bool Bone::yDown = false;
void Bone::setYDown(bool inValue)
{
void Bone::setYDown(bool inValue) {
yDown = inValue;
}
bool Bone::isYDown()
{
bool Bone::isYDown() {
return yDown;
}
@ -77,23 +75,19 @@ namespace Spine
_c(0),
_d(0),
_worldY(0),
_sorted(false)
{
_sorted(false) {
setToSetupPose();
}
void Bone::update()
{
void Bone::update() {
updateWorldTransform(_x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY);
}
void Bone::updateWorldTransform()
{
void Bone::updateWorldTransform() {
updateWorldTransform(_x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY);
}
void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY)
{
void Bone::updateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY) {
_ax = x;
_ay = y;
_arotation = rotation;
@ -105,23 +99,20 @@ namespace Spine
Skeleton& skeleton = _skeleton;
Bone* parent = _parent;
if (!parent)
{
if (!parent) {
// Root bone.
float rotationY = rotation + 90 + shearY;
float la = MathUtil::cosDeg(rotation + shearX) * scaleX;
float lb = MathUtil::cosDeg(rotationY) * scaleY;
float lc = MathUtil::sinDeg(rotation + shearX) * scaleX;
float ld = MathUtil::sinDeg(rotationY) * scaleY;
if (_skeleton.getFlipX())
{
if (_skeleton.getFlipX()) {
x = -x;
la = -la;
lb = -lb;
}
if (_skeleton.getFlipY() != Bone::isYDown())
{
if (_skeleton.getFlipY() != Bone::isYDown()) {
y = -y;
lc = -lc;
ld = -ld;
@ -145,10 +136,8 @@ namespace Spine
_worldX = pa * x + pb * y + parent->_worldX;
_worldY = pc * x + pd * y + parent->_worldY;
switch (_data.getTransformMode())
{
case TransformMode_Normal:
{
switch (_data.getTransformMode()) {
case TransformMode_Normal: {
float rotationY = rotation + 90 + shearY;
float la = MathUtil::cosDeg(rotation + shearX) * scaleX;
float lb = MathUtil::cosDeg(rotationY) * scaleY;
@ -161,8 +150,7 @@ namespace Spine
return;
}
case TransformMode_OnlyTranslation:
{
case TransformMode_OnlyTranslation: {
float rotationY = rotation + 90 + shearY;
_a = MathUtil::cosDeg(rotation + shearX) * scaleX;
_b = MathUtil::cosDeg(rotationY) * scaleY;
@ -171,18 +159,15 @@ namespace Spine
break;
}
case TransformMode_NoRotationOrReflection:
{
case TransformMode_NoRotationOrReflection: {
float s = pa * pa + pc * pc, prx;
if (s > 0.0001f)
{
if (s > 0.0001f) {
s = fabs(pa * pd - pb * pc) / s;
pb = pc * s;
pd = pa * s;
prx = MathUtil::atan2(pc, pa) * RadDeg;
}
else
{
else {
pa = 0;
pc = 0;
prx = 90 - MathUtil::atan2(pd, pb) * RadDeg;
@ -202,15 +187,13 @@ namespace Spine
break;
}
case TransformMode_NoScale:
case TransformMode_NoScaleOrReflection:
{
case TransformMode_NoScaleOrReflection: {
float cos = MathUtil::cosDeg(rotation);
float sin = MathUtil::sinDeg(rotation);
float za = pa * cos + pb * sin;
float zc = pc * cos + pd * sin;
float s = sqrt(za * za + zc * zc);
if (s > 0.00001f)
{
if (s > 0.00001f) {
s = 1 / s;
}
@ -225,8 +208,7 @@ namespace Spine
float lc = MathUtil::sinDeg(shearX) * scaleX;
float ld = MathUtil::sinDeg(90 + shearY) * scaleY;
if (_data.getTransformMode() != TransformMode_NoScaleOrReflection ? pa * pd - pb * pc < 0 : _skeleton.getFlipX() != _skeleton.getFlipY())
{
if (_data.getTransformMode() != TransformMode_NoScaleOrReflection ? pa * pd - pb * pc < 0 : _skeleton.getFlipX() != _skeleton.getFlipY()) {
zb = -zb;
zd = -zd;
}
@ -240,21 +222,18 @@ namespace Spine
}
}
if (_skeleton.getFlipX())
{
if (_skeleton.getFlipX()) {
_a = -_a;
_b = -_b;
}
if (skeleton.getFlipY() != Bone::isYDown())
{
if (skeleton.getFlipY() != Bone::isYDown()) {
_c = -_c;
_d = -_d;
}
}
void Bone::setToSetupPose()
{
void Bone::setToSetupPose() {
BoneData& data = _data;
_x = data.getX();
_y = data.getY();
@ -265,8 +244,7 @@ namespace Spine
_shearY = data.getShearY();
}
void Bone::worldToLocal(float worldX, float worldY, float& outLocalX, float& outLocalY)
{
void Bone::worldToLocal(float worldX, float worldY, float& outLocalX, float& outLocalY) {
float a = _a;
float b = _b;
float c = _c;
@ -280,30 +258,26 @@ namespace Spine
outLocalY = (y * a * invDet - x * c * invDet);
}
void Bone::localToWorld(float localX, float localY, float& outWorldX, float& outWorldY)
{
void Bone::localToWorld(float localX, float localY, float& outWorldX, float& outWorldY) {
outWorldX = localX * _a + localY * _b + _worldX;
outWorldY = localX * _c + localY * _d + _worldY;
}
float Bone::worldToLocalRotation(float worldRotation)
{
float Bone::worldToLocalRotation(float worldRotation) {
float sin = MathUtil::sinDeg(worldRotation);
float cos = MathUtil::cosDeg(worldRotation);
return MathUtil::atan2(_a * sin - _c * cos, _d * cos - _b * sin) * RadDeg;
}
float Bone::localToWorldRotation(float localRotation)
{
float Bone::localToWorldRotation(float localRotation) {
float sin = MathUtil::sinDeg(localRotation);
float cos = MathUtil::cosDeg(localRotation);
return MathUtil::atan2(cos * _c + sin * _d, cos * _a + sin * _b) * RadDeg;
}
void Bone::rotateWorld(float degrees)
{
void Bone::rotateWorld(float degrees) {
float a = _a;
float b = _b;
float c = _c;
@ -320,11 +294,9 @@ namespace Spine
_appliedValid = false;
}
float Bone::getWorldToLocalRotationX()
{
float Bone::getWorldToLocalRotationX() {
Bone* parent = _parent;
if (!parent)
{
if (!parent) {
return _arotation;
}
@ -338,11 +310,9 @@ namespace Spine
return MathUtil::atan2(pa * c - pc * a, pd * a - pb * c) * RadDeg;
}
float Bone::getWorldToLocalRotationY()
{
float Bone::getWorldToLocalRotationY() {
Bone* parent = _parent;
if (!parent)
{
if (!parent) {
return _arotation;
}
@ -356,252 +326,202 @@ namespace Spine
return MathUtil::atan2(pa * d - pc * b, pd * b - pb * d) * RadDeg;
}
BoneData& Bone::getData()
{
BoneData& Bone::getData() {
return _data;
}
Skeleton& Bone::getSkeleton()
{
Skeleton& Bone::getSkeleton() {
return _skeleton;
}
Bone* Bone::getParent()
{
Bone* Bone::getParent() {
return _parent;
}
Vector<Bone*>& Bone::getChildren()
{
Vector<Bone*>& Bone::getChildren() {
return _children;
}
float Bone::getX()
{
float Bone::getX() {
return _x;
}
void Bone::setX(float inValue)
{
void Bone::setX(float inValue) {
_x = inValue;
}
float Bone::getY()
{
float Bone::getY() {
return _y;
}
void Bone::setY(float inValue)
{
void Bone::setY(float inValue) {
_y = inValue;
}
float Bone::getRotation()
{
float Bone::getRotation() {
return _rotation;
}
void Bone::setRotation(float inValue)
{
void Bone::setRotation(float inValue) {
_rotation = inValue;
}
float Bone::getScaleX()
{
float Bone::getScaleX() {
return _scaleX;
}
void Bone::setScaleX(float inValue)
{
void Bone::setScaleX(float inValue) {
_scaleX = inValue;
}
float Bone::getScaleY()
{
float Bone::getScaleY() {
return _scaleY;
}
void Bone::setScaleY(float inValue)
{
void Bone::setScaleY(float inValue) {
_scaleY = inValue;
}
float Bone::getShearX()
{
float Bone::getShearX() {
return _shearX;
}
void Bone::setShearX(float inValue)
{
void Bone::setShearX(float inValue) {
_shearX = inValue;
}
float Bone::getShearY()
{
float Bone::getShearY() {
return _shearY;
}
void Bone::setShearY(float inValue)
{
void Bone::setShearY(float inValue) {
_shearY = inValue;
}
float Bone::getAppliedRotation()
{
float Bone::getAppliedRotation() {
return _arotation;
}
void Bone::setAppliedRotation(float inValue)
{
void Bone::setAppliedRotation(float inValue) {
_arotation = inValue;
}
float Bone::getAX()
{
float Bone::getAX() {
return _ax;
}
void Bone::setAX(float inValue)
{
void Bone::setAX(float inValue) {
_ax = inValue;
}
float Bone::getAY()
{
float Bone::getAY() {
return _ay;
}
void Bone::setAY(float inValue)
{
void Bone::setAY(float inValue) {
_ay = inValue;
}
float Bone::getAScaleX()
{
float Bone::getAScaleX() {
return _ascaleX;
}
void Bone::setAScaleX(float inValue)
{
void Bone::setAScaleX(float inValue) {
_ascaleX = inValue;
}
float Bone::getAScaleY()
{
float Bone::getAScaleY() {
return _ascaleY;
}
void Bone::setAScaleY(float inValue)
{
void Bone::setAScaleY(float inValue) {
_ascaleY = inValue;
}
float Bone::getAShearX()
{
float Bone::getAShearX() {
return _ashearX;
}
void Bone::setAShearX(float inValue)
{
void Bone::setAShearX(float inValue) {
_ashearX = inValue;
}
float Bone::getAShearY()
{
float Bone::getAShearY() {
return _ashearY;
}
void Bone::setAShearY(float inValue)
{
void Bone::setAShearY(float inValue) {
_ashearY = inValue;
}
float Bone::getA()
{
float Bone::getA() {
return _a;
}
void Bone::setA(float inValue)
{
void Bone::setA(float inValue) {
_a = inValue;
}
float Bone::getB()
{
float Bone::getB() {
return _b;
}
void Bone::setB(float inValue)
{
void Bone::setB(float inValue) {
_b = inValue;
}
float Bone::getC()
{
float Bone::getC() {
return _c;
}
void Bone::setC(float inValue)
{
void Bone::setC(float inValue) {
_c = inValue;
}
float Bone::getD()
{
float Bone::getD() {
return _d;
}
void Bone::setD(float inValue)
{
void Bone::setD(float inValue) {
_d = inValue;
}
float Bone::getWorldX()
{
float Bone::getWorldX() {
return _worldX;
}
void Bone::setWorldX(float inValue)
{
void Bone::setWorldX(float inValue) {
_worldX = inValue;
}
float Bone::getWorldY()
{
float Bone::getWorldY() {
return _worldY;
}
void Bone::setWorldY(float inValue)
{
void Bone::setWorldY(float inValue) {
_worldY = inValue;
}
float Bone::getWorldRotationX()
{
float Bone::getWorldRotationX() {
return MathUtil::atan2(_c, _a) * RadDeg;
}
float Bone::getWorldRotationY()
{
float Bone::getWorldRotationY() {
return MathUtil::atan2(_d, _b) * RadDeg;
}
float Bone::getWorldScaleX()
{
float Bone::getWorldScaleX() {
return sqrt(_a * _a + _c * _c);
}
float Bone::getWorldScaleY()
{
float Bone::getWorldScaleY() {
return sqrt(_b * _b + _d * _d);
}
void Bone::updateAppliedTransform()
{
void Bone::updateAppliedTransform() {
_appliedValid = true;
Bone* parent = _parent;
if (!parent)
{
if (!parent) {
_ax = _worldX;
_ay = _worldY;
_arotation = MathUtil::atan2(_c, _a) * RadDeg;
@ -638,15 +558,13 @@ namespace Spine
_ashearX = 0;
_ascaleX = sqrt(ra * ra + rc * rc);
if (_ascaleX > 0.0001f)
{
if (_ascaleX > 0.0001f) {
float det = ra * rd - rb * rc;
_ascaleY = det / _ascaleX;
_ashearY = MathUtil::atan2(ra * rb + rc * rd, det) * RadDeg;
_arotation = MathUtil::atan2(rc, ra) * RadDeg;
}
else
{
else {
_ascaleX = 0;
_ascaleY = sqrt(rb * rb + rd * rd);
_ashearY = 0;

View File

@ -46,114 +46,92 @@ namespace Spine
_scaleY(1),
_shearX(0),
_shearY(0),
_transformMode(TransformMode_Normal)
{
_transformMode(TransformMode_Normal) {
assert(index >= 0);
assert(_name.length() > 0);
}
const int BoneData::getIndex()
{
const int BoneData::getIndex() {
return _index;
}
const std::string& BoneData::getName()
{
const std::string& BoneData::getName() {
return _name;
}
BoneData* BoneData::getParent()
{
BoneData* BoneData::getParent() {
return _parent;
}
float BoneData::getLength()
{
float BoneData::getLength() {
return _length;
}
void BoneData::setLength(float inValue)
{
void BoneData::setLength(float inValue) {
_length = inValue;
}
float BoneData::getX()
{
float BoneData::getX() {
return _x;
}
void BoneData::setX(float inValue)
{
void BoneData::setX(float inValue) {
_x = inValue;
}
float BoneData::getY()
{
float BoneData::getY() {
return _y;
}
void BoneData::setY(float inValue)
{
void BoneData::setY(float inValue) {
_y = inValue;
}
float BoneData::getRotation()
{
float BoneData::getRotation() {
return _rotation;
}
void BoneData::setRotation(float inValue)
{
void BoneData::setRotation(float inValue) {
_rotation = inValue;
}
float BoneData::getScaleX()
{
float BoneData::getScaleX() {
return _scaleX;
}
void BoneData::setScaleX(float inValue)
{
void BoneData::setScaleX(float inValue) {
_scaleX = inValue;
}
float BoneData::getScaleY()
{
float BoneData::getScaleY() {
return _scaleY;
}
void BoneData::setScaleY(float inValue)
{
void BoneData::setScaleY(float inValue) {
_scaleY = inValue;
}
float BoneData::getShearX()
{
float BoneData::getShearX() {
return _shearX;
}
void BoneData::setShearX(float inValue)
{
void BoneData::setShearX(float inValue) {
_shearX = inValue;
}
float BoneData::getShearY()
{
float BoneData::getShearY() {
return _shearY;
}
void BoneData::setShearY(float inValue)
{
void BoneData::setShearY(float inValue) {
_shearY = inValue;
}
TransformMode BoneData::getTransformMode()
{
TransformMode BoneData::getTransformMode() {
return _transformMode;
}
void BoneData::setTransformMode(TransformMode inValue)
{
void BoneData::setTransformMode(TransformMode inValue) {
_transformMode = inValue;
}
}

View File

@ -34,8 +34,7 @@ namespace Spine
{
RTTI_IMPL(BoundingBoxAttachment, VertexAttachment);
BoundingBoxAttachment::BoundingBoxAttachment(std::string name) : VertexAttachment(name)
{
BoundingBoxAttachment::BoundingBoxAttachment(std::string name) : VertexAttachment(name) {
// Empty
}
}

View File

@ -36,18 +36,15 @@ namespace Spine
{
RTTI_IMPL(ClippingAttachment, VertexAttachment);
ClippingAttachment::ClippingAttachment(std::string name) : VertexAttachment(name), _endSlot(NULL)
{
ClippingAttachment::ClippingAttachment(std::string name) : VertexAttachment(name), _endSlot(NULL) {
// Empty
}
SlotData* ClippingAttachment::getEndSlot()
{
SlotData* ClippingAttachment::getEndSlot() {
return _endSlot;
}
void ClippingAttachment::setEndSlot(SlotData* inValue)
{
void ClippingAttachment::setEndSlot(SlotData* inValue) {
_endSlot = inValue;
}
}

View File

@ -53,21 +53,17 @@ namespace Spine
const int ColorTimeline::B = 3;
const int ColorTimeline::A = 4;
ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0)
{
ColorTimeline::ColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0) {
_frames.reserve(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES);
}
void ColorTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)
{
void ColorTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) {
Slot* slotP = skeleton._slots[_slotIndex];
Slot& slot = *slotP;
if (time < _frames[0])
{
if (time < _frames[0]) {
SlotData& slotData = slot._data;
switch (pose)
{
switch (pose) {
case MixPose_Setup:
slot._r = slotData._r;
slot._g = slotData._g;
@ -87,8 +83,7 @@ namespace Spine
}
float r, g, b, a;
if (time >= _frames[_frames.size() - ENTRIES])
{
if (time >= _frames[_frames.size() - ENTRIES]) {
// Time is after last frame.
int i = static_cast<int>(_frames.size());
r = _frames[i + PREV_R];
@ -96,8 +91,7 @@ namespace Spine
b = _frames[i + PREV_B];
a = _frames[i + PREV_A];
}
else
{
else {
// Interpolate between the previous frame and the current frame.
int frame = Animation::binarySearch(_frames, time, ENTRIES);
r = _frames[frame + PREV_R];
@ -113,25 +107,21 @@ namespace Spine
a += (_frames[frame + A] - a) * percent;
}
if (alpha == 1)
{
if (alpha == 1) {
slot._r = r;
slot._g = g;
slot._b = b;
slot._a = a;
}
else
{
else {
float br, bg, bb, ba;
if (pose == MixPose_Setup)
{
if (pose == MixPose_Setup) {
br = slot._data._r;
bg = slot._data._g;
bb = slot._data._b;
ba = slot._data._a;
}
else
{
else {
br = slot._r;
bg = slot._g;
bb = slot._b;
@ -144,13 +134,11 @@ namespace Spine
}
}
int ColorTimeline::getPropertyId()
{
int ColorTimeline::getPropertyId() {
return ((int)TimelineType_Color << 24) + _slotIndex;
}
void ColorTimeline::setFrame(int frameIndex, float time, float r, float g, float b, float a)
{
void ColorTimeline::setFrame(int frameIndex, float time, float r, float g, float b, float a) {
frameIndex *= ENTRIES;
_frames[frameIndex] = time;
_frames[frameIndex + R] = r;
@ -159,23 +147,19 @@ namespace Spine
_frames[frameIndex + A] = a;
}
int ColorTimeline::getSlotIndex()
{
int ColorTimeline::getSlotIndex() {
return _slotIndex;
}
void ColorTimeline::setSlotIndex(int inValue)
{
void ColorTimeline::setSlotIndex(int inValue) {
_slotIndex = inValue;
}
Vector<float>& ColorTimeline::getFrames()
{
Vector<float>& ColorTimeline::getFrames() {
return _frames;
}
void ColorTimeline::setFrames(Vector<float>& inValue)
{
void ColorTimeline::setFrames(Vector<float>& inValue) {
_frames = inValue;
}
}

View File

@ -34,13 +34,11 @@ namespace Spine
{
RTTI_IMPL(Constraint, Updatable);
Constraint::Constraint()
{
Constraint::Constraint() {
// Empty
}
Constraint::~Constraint()
{
Constraint::~Constraint() {
// Empty
}
}

View File

@ -41,31 +41,26 @@ namespace Spine
const float CurveTimeline::BEZIER = 2;
const int CurveTimeline::BEZIER_SIZE = 10 * 2 - 1;
CurveTimeline::CurveTimeline(int frameCount)
{
CurveTimeline::CurveTimeline(int frameCount) {
assert(frameCount > 0);
_curves.reserve((frameCount - 1) * BEZIER_SIZE);
_curves.setSize((frameCount - 1) * BEZIER_SIZE);
}
int CurveTimeline::getFrameCount()
{
int CurveTimeline::getFrameCount() {
return static_cast<int>(_curves.size() / BEZIER_SIZE + 1);
}
void CurveTimeline::setLinear(int frameIndex)
{
void CurveTimeline::setLinear(int frameIndex) {
_curves[frameIndex * BEZIER_SIZE] = LINEAR;
}
void CurveTimeline::setStepped(int frameIndex)
{
void CurveTimeline::setStepped(int frameIndex) {
_curves[frameIndex * BEZIER_SIZE] = STEPPED;
}
void CurveTimeline::setCurve(int frameIndex, float cx1, float cy1, float cx2, float cy2)
{
void CurveTimeline::setCurve(int frameIndex, float cx1, float cy1, float cx2, float cy2) {
float tmpx = (-cx1 * 2 + cx2) * 0.03f, tmpy = (-cy1 * 2 + cy2) * 0.03f;
float dddfx = ((cx1 - cx2) * 3 + 1) * 0.006f, dddfy = ((cy1 - cy2) * 3 + 1) * 0.006f;
float ddfx = tmpx * 2 + dddfx, ddfy = tmpy * 2 + dddfy;
@ -75,8 +70,7 @@ namespace Spine
_curves[i++] = BEZIER;
float x = dfx, y = dfy;
for (int n = i + BEZIER_SIZE - 1; i < n; i += 2)
{
for (int n = i + BEZIER_SIZE - 1; i < n; i += 2) {
_curves[i] = x;
_curves[i + 1] = y;
dfx += ddfx;
@ -88,37 +82,30 @@ namespace Spine
}
}
float CurveTimeline::getCurvePercent(int frameIndex, float percent)
{
float CurveTimeline::getCurvePercent(int frameIndex, float percent) {
percent = clamp(percent, 0, 1);
int i = frameIndex * BEZIER_SIZE;
float type = _curves[i];
if (type == LINEAR)
{
if (type == LINEAR) {
return percent;
}
if (type == STEPPED)
{
if (type == STEPPED) {
return 0;
}
i++;
float x = 0;
for (int start = i, n = i + BEZIER_SIZE - 1; i < n; i += 2)
{
for (int start = i, n = i + BEZIER_SIZE - 1; i < n; i += 2) {
x = _curves[i];
if (x >= percent)
{
if (x >= percent) {
float prevX, prevY;
if (i == start)
{
if (i == start) {
prevX = 0;
prevY = 0;
}
else
{
else {
prevX = _curves[i - 2];
prevY = _curves[i - 1];
}
@ -132,8 +119,7 @@ namespace Spine
return y + (1 - y) * (percent - x) / (1 - x); // Last point is 1,1.
}
float CurveTimeline::getCurveType(int frameIndex)
{
float CurveTimeline::getCurveType(int frameIndex) {
return _curves[frameIndex * BEZIER_SIZE];
}
}

View File

@ -44,54 +44,45 @@ namespace Spine
{
RTTI_IMPL(DeformTimeline, CurveTimeline);
DeformTimeline::DeformTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0), _attachment(NULL)
{
DeformTimeline::DeformTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0), _attachment(NULL) {
_frames.reserve(frameCount);
_frameVertices.reserve(frameCount);
_frames.setSize(frameCount);
for (int i = 0; i < frameCount; ++i)
{
for (int i = 0; i < frameCount; ++i) {
Vector<float> vec;
_frameVertices.push_back(vec);
}
}
void DeformTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)
{
void DeformTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) {
Slot* slotP = skeleton._slots[_slotIndex];
Slot& slot = *slotP;
if (slot._attachment == NULL || !slot._attachment->getRTTI().derivesFrom(VertexAttachment::rtti))
{
if (slot._attachment == NULL || !slot._attachment->getRTTI().derivesFrom(VertexAttachment::rtti)) {
return;
}
VertexAttachment* vertexAttachment = static_cast<VertexAttachment*>(slot._attachment);
if (!vertexAttachment->applyDeform(_attachment))
{
if (!vertexAttachment->applyDeform(_attachment)) {
return;
}
Vector<float>& vertices = slot._attachmentVertices;
if (vertices.size() == 0)
{
if (vertices.size() == 0) {
alpha = 1;
}
int vertexCount = static_cast<int>(_frameVertices[0].size());
if (time < _frames[0])
{
switch (pose)
{
if (time < _frames[0]) {
switch (pose) {
case MixPose_Setup:
vertices.clear();
return;
case MixPose_Current:
if (alpha == 1)
{
if (alpha == 1) {
vertices.clear();
return;
}
@ -100,21 +91,17 @@ namespace Spine
vertices.reserve(vertexCount);
vertices.setSize(vertexCount);
if (vertexAttachment->_bones.size() == 0)
{
if (vertexAttachment->_bones.size() == 0) {
// Unweighted vertex positions.
Vector<float>& setupVertices = vertexAttachment->_vertices;
for (int i = 0; i < vertexCount; ++i)
{
for (int i = 0; i < vertexCount; ++i) {
vertices[i] += (setupVertices[i] - vertices[i]) * alpha;
}
}
else
{
else {
// Weighted deform offsets.
alpha = 1 - alpha;
for (int i = 0; i < vertexCount; ++i)
{
for (int i = 0; i < vertexCount; ++i) {
vertices[i] *= alpha;
}
}
@ -128,46 +115,36 @@ namespace Spine
vertices.reserve(vertexCount);
vertices.setSize(vertexCount);
if (time >= _frames[_frames.size() - 1])
{
if (time >= _frames[_frames.size() - 1]) {
// Time is after last frame.
Vector<float>& lastVertices = _frameVertices[_frames.size() - 1];
if (alpha == 1)
{
if (alpha == 1) {
// Vertex positions or deform offsets, no alpha.
vertices.clear();
for (int i = 0; i < vertexCount; ++i)
{
for (int i = 0; i < vertexCount; ++i) {
float vertex = lastVertices[i];
vertices.push_back(vertex);
}
}
else if (pose == MixPose_Setup)
{
if (vertexAttachment->_bones.size() == 0)
{
else if (pose == MixPose_Setup) {
if (vertexAttachment->_bones.size() == 0) {
// Unweighted vertex positions, with alpha.
Vector<float>& setupVertices = vertexAttachment->_vertices;
for (int i = 0; i < vertexCount; i++)
{
for (int i = 0; i < vertexCount; i++) {
float setup = setupVertices[i];
vertices[i] = setup + (lastVertices[i] - setup) * alpha;
}
}
else
{
else {
// Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; ++i)
{
for (int i = 0; i < vertexCount; ++i) {
vertices[i] = lastVertices[i] * alpha;
}
}
}
else
{
else {
// Vertex positions or deform offsets, with alpha.
for (int i = 0; i < vertexCount; ++i)
{
for (int i = 0; i < vertexCount; ++i) {
vertices[i] += (lastVertices[i] - vertices[i]) * alpha;
}
}
@ -181,98 +158,79 @@ namespace Spine
float frameTime = _frames[frame];
float percent = getCurvePercent(frame - 1, 1 - (time - frameTime) / (_frames[frame - 1] - frameTime));
if (alpha == 1)
{
if (alpha == 1) {
// Vertex positions or deform offsets, no alpha.
for (int i = 0; i < vertexCount; ++i)
{
for (int i = 0; i < vertexCount; ++i) {
float prev = prevVertices[i];
vertices[i] = prev + (nextVertices[i] - prev) * percent;
}
}
else if (pose == MixPose_Setup)
{
if (vertexAttachment->_bones.size() == 0)
{
else if (pose == MixPose_Setup) {
if (vertexAttachment->_bones.size() == 0) {
// Unweighted vertex positions, with alpha.
Vector<float>& setupVertices = vertexAttachment->_vertices;
for (int i = 0; i < vertexCount; ++i)
{
for (int i = 0; i < vertexCount; ++i) {
float prev = prevVertices[i], setup = setupVertices[i];
vertices[i] = setup + (prev + (nextVertices[i] - prev) * percent - setup) * alpha;
}
}
else
{
else {
// Weighted deform offsets, with alpha.
for (int i = 0; i < vertexCount; ++i)
{
for (int i = 0; i < vertexCount; ++i) {
float prev = prevVertices[i];
vertices[i] = (prev + (nextVertices[i] - prev) * percent) * alpha;
}
}
}
else
{
else {
// Vertex positions or deform offsets, with alpha.
for (int i = 0; i < vertexCount; ++i)
{
for (int i = 0; i < vertexCount; ++i) {
float prev = prevVertices[i];
vertices[i] += (prev + (nextVertices[i] - prev) * percent - vertices[i]) * alpha;
}
}
}
int DeformTimeline::getPropertyId()
{
int DeformTimeline::getPropertyId() {
assert(_attachment != NULL);
return ((int)TimelineType_Deform << 24) + _attachment->_id + _slotIndex;
}
void DeformTimeline::setFrame(int frameIndex, float time, Vector<float>& vertices)
{
void DeformTimeline::setFrame(int frameIndex, float time, Vector<float>& vertices) {
_frames[frameIndex] = time;
_frameVertices[frameIndex] = vertices;
}
int DeformTimeline::getSlotIndex()
{
int DeformTimeline::getSlotIndex() {
return _slotIndex;
}
void DeformTimeline::setSlotIndex(int inValue)
{
void DeformTimeline::setSlotIndex(int inValue) {
_slotIndex = inValue;
}
Vector<float>& DeformTimeline::getFrames()
{
Vector<float>& DeformTimeline::getFrames() {
return _frames;
}
void DeformTimeline::setFrames(Vector<float>& inValue)
{
void DeformTimeline::setFrames(Vector<float>& inValue) {
_frames = inValue;
}
Vector< Vector<float> >& DeformTimeline::getVertices()
{
Vector< Vector<float> >& DeformTimeline::getVertices() {
return _frameVertices;
}
void DeformTimeline::setVertices(Vector< Vector<float> >& inValue)
{
void DeformTimeline::setVertices(Vector< Vector<float> >& inValue) {
_frameVertices = inValue;
}
VertexAttachment* DeformTimeline::getAttachment()
{
VertexAttachment* DeformTimeline::getAttachment() {
return _attachment;
}
void DeformTimeline::setAttachment(VertexAttachment* inValue)
{
void DeformTimeline::setAttachment(VertexAttachment* inValue) {
_attachment = inValue;
}
}

View File

@ -42,43 +42,35 @@ namespace Spine
{
RTTI_IMPL(DrawOrderTimeline, Timeline);
DrawOrderTimeline::DrawOrderTimeline(int frameCount) : Timeline()
{
DrawOrderTimeline::DrawOrderTimeline(int frameCount) : Timeline() {
_frames.reserve(frameCount);
_drawOrders.reserve(frameCount);
_frames.setSize(frameCount);
for (int i = 0; i < frameCount; ++i)
{
for (int i = 0; i < frameCount; ++i) {
Vector<int> vec;
_drawOrders.push_back(vec);
}
}
void DrawOrderTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)
{
void DrawOrderTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) {
Vector<Slot*>& drawOrder = skeleton._drawOrder;
Vector<Slot*>& slots = skeleton._slots;
if (direction == MixDirection_Out && pose == MixPose_Setup)
{
if (direction == MixDirection_Out && pose == MixPose_Setup) {
drawOrder.clear();
drawOrder.reserve(slots.size());
for (int i = 0, n = static_cast<int>(slots.size()); i < n; ++i)
{
for (int i = 0, n = static_cast<int>(slots.size()); i < n; ++i) {
drawOrder.push_back(slots[i]);
}
return;
}
if (time < _frames[0])
{
if (pose == MixPose_Setup)
{
if (time < _frames[0]) {
if (pose == MixPose_Setup) {
drawOrder.clear();
drawOrder.reserve(slots.size());
for (int i = 0, n = static_cast<int>(slots.size()); i < n; ++i)
{
for (int i = 0, n = static_cast<int>(slots.size()); i < n; ++i) {
drawOrder.push_back(slots[i]);
}
}
@ -86,67 +78,54 @@ namespace Spine
}
int frame;
if (time >= _frames[_frames.size() - 1])
{
if (time >= _frames[_frames.size() - 1]) {
// Time is after last frame.
frame = static_cast<int>(_frames.size()) - 1;
}
else
{
else {
frame = Animation::binarySearch(_frames, time) - 1;
}
Vector<int>& drawOrderToSetupIndex = _drawOrders[frame];
if (drawOrderToSetupIndex.size() == 0)
{
if (drawOrderToSetupIndex.size() == 0) {
drawOrder.clear();
for (int i = 0, n = static_cast<int>(slots.size()); i < n; ++i)
{
for (int i = 0, n = static_cast<int>(slots.size()); i < n; ++i) {
drawOrder.push_back(slots[i]);
}
}
else
{
for (int i = 0, n = static_cast<int>(drawOrderToSetupIndex.size()); i < n; ++i)
{
else {
for (int i = 0, n = static_cast<int>(drawOrderToSetupIndex.size()); i < n; ++i) {
drawOrder[i] = slots[drawOrderToSetupIndex[i]];
}
}
}
int DrawOrderTimeline::getPropertyId()
{
int DrawOrderTimeline::getPropertyId() {
return ((int)TimelineType_DrawOrder << 24);
}
void DrawOrderTimeline::setFrame(int frameIndex, float time, Vector<int>& drawOrder)
{
void DrawOrderTimeline::setFrame(int frameIndex, float time, Vector<int>& drawOrder) {
_frames[frameIndex] = time;
_drawOrders[frameIndex] = drawOrder;
}
Vector<float>& DrawOrderTimeline::getFrames()
{
Vector<float>& DrawOrderTimeline::getFrames() {
return _frames;
}
void DrawOrderTimeline::setFrames(Vector<float>& inValue)
{
void DrawOrderTimeline::setFrames(Vector<float>& inValue) {
_frames = inValue;
}
Vector< Vector<int> >& DrawOrderTimeline::getDrawOrders()
{
Vector< Vector<int> >& DrawOrderTimeline::getDrawOrders() {
return _drawOrders;
}
void DrawOrderTimeline::setDrawOrders(Vector< Vector<int> >& inValue)
{
void DrawOrderTimeline::setDrawOrders(Vector< Vector<int> >& inValue) {
_drawOrders = inValue;
}
int DrawOrderTimeline::getFrameCount()
{
int DrawOrderTimeline::getFrameCount() {
return static_cast<int>(_frames.size());
}
}

View File

@ -39,48 +39,39 @@ namespace Spine
_time(time),
_intValue(0),
_floatValue(0),
_stringValue()
{
_stringValue() {
// Empty
}
const EventData& Event::getData()
{
const EventData& Event::getData() {
return _data;
}
float Event::getTime()
{
float Event::getTime() {
return _time;
}
int Event::getIntValue()
{
int Event::getIntValue() {
return _intValue;
}
void Event::setIntValue(int inValue)
{
void Event::setIntValue(int inValue) {
_intValue = inValue;
}
float Event::getFloatValue()
{
float Event::getFloatValue() {
return _floatValue;
}
void Event::setFloatValue(int inValue)
{
void Event::setFloatValue(int inValue) {
_floatValue = inValue;
}
std::string Event::getStringValue()
{
std::string Event::getStringValue() {
return _stringValue;
}
void Event::setStringValue(std::string inValue)
{
void Event::setStringValue(std::string inValue) {
_stringValue = inValue;
}
}

View File

@ -38,44 +38,36 @@ namespace Spine
_name(name),
_intValue(0),
_floatValue(0),
_stringValue()
{
_stringValue() {
assert(_name.length() > 0);
}
/// The name of the event, which is unique within the skeleton.
const std::string& EventData::getName()
{
const std::string& EventData::getName() {
return _name;
}
int EventData::getIntValue()
{
int EventData::getIntValue() {
return _intValue;
}
void EventData::setIntValue(int inValue)
{
void EventData::setIntValue(int inValue) {
_intValue = inValue;
}
float EventData::getFloatValue()
{
float EventData::getFloatValue() {
return _floatValue;
}
void EventData::setFloatValue(float inValue)
{
void EventData::setFloatValue(float inValue) {
_floatValue = inValue;
}
std::string EventData::getStringValue()
{
std::string EventData::getStringValue() {
return _stringValue;
}
void EventData::setStringValue(std::string inValue)
{
void EventData::setStringValue(std::string inValue) {
_stringValue = inValue;
}
}

View File

@ -44,8 +44,7 @@ namespace Spine
{
RTTI_IMPL(EventTimeline, Timeline);
EventTimeline::EventTimeline(int frameCount) : Timeline()
{
EventTimeline::EventTimeline(int frameCount) : Timeline() {
_frames.reserve(frameCount);
_events.reserve(frameCount);
@ -53,76 +52,63 @@ namespace Spine
_events.setSize(frameCount);
}
EventTimeline::~EventTimeline()
{
EventTimeline::~EventTimeline() {
ContainerUtil::cleanUpVectorOfPointers(_events);
}
void EventTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)
{
if (pEvents == NULL)
{
void EventTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) {
if (pEvents == NULL) {
return;
}
Vector<Event*>& events = *pEvents;
if (events.size() == 0)
{
if (events.size() == 0) {
return;
}
int frameCount = static_cast<int>(_frames.size());
if (lastTime > time)
{
if (lastTime > time) {
// Fire events after last time for looped animations.
apply(skeleton, lastTime, std::numeric_limits<int>::max(), pEvents, alpha, pose, direction);
lastTime = -1.0f;
}
else if (lastTime >= _frames[frameCount - 1]) // Last time is after last frame.
{
else if (lastTime >= _frames[frameCount - 1]) {
// Last time is after last frame.
return;
}
if (time < _frames[0])
{
if (time < _frames[0]) {
return; // Time is before first frame.
}
int frame;
if (lastTime < _frames[0])
{
if (lastTime < _frames[0]) {
frame = 0;
}
else
{
else {
frame = Animation::binarySearch(_frames, lastTime);
float frameTime = _frames[frame];
while (frame > 0)
{
while (frame > 0) {
// Fire multiple events with the same frame.
if (_frames[frame - 1] != frameTime)
{
if (_frames[frame - 1] != frameTime) {
break;
}
frame--;
}
}
for (; frame < frameCount && time >= _frames[frame]; ++frame)
{
for (; frame < frameCount && time >= _frames[frame]; ++frame) {
events.push_back(_events[frame]);
}
}
int EventTimeline::getPropertyId()
{
int EventTimeline::getPropertyId() {
return ((int)TimelineType_Event << 24);
}
void EventTimeline::setFrame(int frameIndex, Event* event)
{
void EventTimeline::setFrame(int frameIndex, Event* event) {
_frames[frameIndex] = event->getTime();
_events[frameIndex] = event;
}

View File

@ -38,27 +38,23 @@ namespace Spine
{
SpineExtension* SpineExtension::_instance = NULL;
void SpineExtension::setInstance(SpineExtension* inValue)
{
void SpineExtension::setInstance(SpineExtension* inValue) {
assert(!_instance);
_instance = inValue;
}
SpineExtension* SpineExtension::getInstance()
{
SpineExtension* SpineExtension::getInstance() {
assert(_instance);
return _instance;
}
SpineExtension::~SpineExtension()
{
SpineExtension::~SpineExtension() {
// Empty
}
char* SpineExtension::spineReadFile(const char* path, int* length)
{
char* SpineExtension::spineReadFile(const char* path, int* length) {
char *data;
FILE *file = fopen(path, "rb");
if (!file) return 0;
@ -74,50 +70,41 @@ namespace Spine
return data;
}
SpineExtension::SpineExtension()
{
SpineExtension::SpineExtension() {
// Empty
}
DefaultSpineExtension* DefaultSpineExtension::getInstance()
{
DefaultSpineExtension* DefaultSpineExtension::getInstance() {
static DefaultSpineExtension ret;
return &ret;
}
DefaultSpineExtension::~DefaultSpineExtension()
{
DefaultSpineExtension::~DefaultSpineExtension() {
// Empty
}
void* DefaultSpineExtension::spineAlloc(size_t size, const char* file, int line)
{
void* DefaultSpineExtension::spineAlloc(size_t size, const char* file, int line) {
return malloc(size);
}
void* DefaultSpineExtension::spineCalloc(size_t num, size_t size, const char* file, int line)
{
void* DefaultSpineExtension::spineCalloc(size_t num, size_t size, const char* file, int line) {
void* ptr = spineAlloc(num * size, file, line);
if (ptr)
{
if (ptr) {
memset(ptr, 0, num * size);
}
return ptr;
}
void* DefaultSpineExtension::spineRealloc(void* ptr, size_t size, const char* file, int line)
{
void* DefaultSpineExtension::spineRealloc(void* ptr, size_t size, const char* file, int line) {
return realloc(ptr, size);
}
void DefaultSpineExtension::spineFree(void* mem)
{
void DefaultSpineExtension::spineFree(void* mem) {
free(mem);
}
DefaultSpineExtension::DefaultSpineExtension() : SpineExtension()
{
DefaultSpineExtension::DefaultSpineExtension() : SpineExtension() {
// Empty
}
}

View File

@ -41,10 +41,8 @@ namespace Spine
{
RTTI_IMPL(IkConstraint, Constraint);
void IkConstraint::apply(Bone& bone, float targetX, float targetY, float alpha)
{
if (!bone._appliedValid)
{
void IkConstraint::apply(Bone& bone, float targetX, float targetY, float alpha) {
if (!bone._appliedValid) {
bone.updateAppliedTransform();
}
@ -56,39 +54,32 @@ namespace Spine
float tx = (x * p._d - y * p._b) * id - bone._ax, ty = (y * p._a - x * p._c) * id - bone._ay;
float rotationIK = (float)atan2(ty, tx) * RadDeg - bone._ashearX - bone._arotation;
if (bone._ascaleX < 0)
{
if (bone._ascaleX < 0) {
rotationIK += 180;
}
if (rotationIK > 180)
{
if (rotationIK > 180) {
rotationIK -= 360;
}
else if (rotationIK < -180)
{
else if (rotationIK < -180) {
rotationIK += 360;
}
bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, bone._ascaleX, bone._ascaleY, bone._ashearX, bone._ashearY);
}
void IkConstraint::apply(Bone& parent, Bone& child, float targetX, float targetY, int bendDir, float alpha)
{
if (areFloatsPracticallyEqual(alpha, 0))
{
void IkConstraint::apply(Bone& parent, Bone& child, float targetX, float targetY, int bendDir, float alpha) {
if (areFloatsPracticallyEqual(alpha, 0)) {
child.updateWorldTransform();
return;
}
if (!parent._appliedValid)
{
if (!parent._appliedValid) {
parent.updateAppliedTransform();
}
if (!child._appliedValid)
{
if (!child._appliedValid) {
child.updateAppliedTransform();
}
@ -99,31 +90,26 @@ namespace Spine
float csx = child._ascaleX;
int os1, os2, s2;
if (psx < 0)
{
if (psx < 0) {
psx = -psx;
os1 = 180;
s2 = -1;
}
else
{
else {
os1 = 0;
s2 = 1;
}
if (psy < 0)
{
if (psy < 0) {
psy = -psy;
s2 = -s2;
}
if (csx < 0)
{
if (csx < 0) {
csx = -csx;
os2 = 180;
}
else
{
else {
os2 = 0;
}
@ -137,14 +123,12 @@ namespace Spine
float d = parent._d;
bool u = fabs(psx - psy) <= 0.0001f;
if (!u)
{
if (!u) {
cy = 0;
cwx = a * cx + parent._worldX;
cwy = c * cx + parent._worldY;
}
else
{
else {
cy = child._ay;
cwx = a * cx + b * cy + parent._worldX;
cwy = c * cx + d * cy + parent._worldY;
@ -164,16 +148,13 @@ namespace Spine
y = cwy - pp._worldY;
float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
float l1 = (float)sqrt(dx * dx + dy * dy), l2 = child._data.getLength() * csx, a1, a2;
if (u)
{
if (u) {
l2 *= psx;
float cos = (tx * tx + ty * ty - l1 * l1 - l2 * l2) / (2 * l1 * l2);
if (cos < -1)
{
if (cos < -1) {
cos = -1;
}
else if (cos > 1)
{
else if (cos > 1) {
cos = 1;
}
@ -182,23 +163,20 @@ namespace Spine
b = l2 * (float)sin(a2);
a1 = (float)atan2(ty * a - tx * b, tx * a + ty * b);
}
else
{
else {
a = psx * l2;
b = psy * l2;
float aa = a * a, bb = b * b, dd = tx * tx + ty * ty, ta = (float)atan2(ty, tx);
c = bb * l1 * l1 + aa * dd - aa * bb;
float c1 = -2 * bb * l1, c2 = bb - aa;
d = c1 * c1 - 4 * c2 * c;
if (d >= 0)
{
if (d >= 0) {
float q = (float)sqrt(d);
if (c1 < 0) q = -q;
q = -(c1 + q) / 2;
float r0 = q / c2, r1 = c / q;
float r = fabs(r0) < fabs(r1) ? r0 : r1;
if (r * r <= dd)
{
if (r * r <= dd) {
y = (float)sqrt(dd - r * r) * bendDir;
a1 = ta - (float)atan2(y, r);
a2 = (float)atan2(y / psy, (r - l1) / psx);
@ -206,12 +184,10 @@ namespace Spine
float os = (float)atan2(cy, cx) * s2;
float rotation = parent._arotation;
a1 = (a1 - os) * RadDeg + os1 - rotation;
if (a1 > 180)
{
if (a1 > 180) {
a1 -= 360;
}
else if (a1 < -180)
{
else if (a1 < -180) {
a1 += 360;
}
@ -219,12 +195,10 @@ namespace Spine
rotation = child._arotation;
a2 = ((a2 + os) * RadDeg - child._ashearX) * s2 + os2 - rotation;
if (a2 > 180)
{
if (a2 > 180) {
a2 -= 360;
}
else if (a2 < -180)
{
else if (a2 < -180) {
a2 += 360;
}
@ -237,23 +211,20 @@ namespace Spine
float minAngle = SPINE_PI, minX = l1 - a, minDist = minX * minX, minY = 0;
float maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
c = -a * l1 / (aa - bb);
if (c >= -1 && c <= 1)
{
if (c >= -1 && c <= 1) {
c = (float)acos(c);
x = a * (float)cos(c) + l1;
y = b * (float)sin(c);
d = x * x + y * y;
if (d < minDist)
{
if (d < minDist) {
minAngle = c;
minDist = d;
minX = x;
minY = y;
}
if (d > maxDist)
{
if (d > maxDist) {
maxAngle = c;
maxDist = d;
maxX = x;
@ -261,13 +232,11 @@ namespace Spine
}
}
if (dd <= (minDist + maxDist) / 2)
{
if (dd <= (minDist + maxDist) / 2) {
a1 = ta - (float)atan2(minY * bendDir, minX);
a2 = minAngle * bendDir;
}
else
{
else {
a1 = ta - (float)atan2(maxY * bendDir, maxX);
a2 = maxAngle * bendDir;
}
@ -278,11 +247,9 @@ namespace Spine
_data(data),
_mix(data.getMix()),
_bendDirection(data.getBendDirection()),
_target(skeleton.findBone(data.getTarget()->getName()))
{
_target(skeleton.findBone(data.getTarget()->getName())) {
_bones.reserve(_data.getBones().size());
for (BoneData** i = _data.getBones().begin(); i != _data.getBones().end(); ++i)
{
for (BoneData** i = _data.getBones().begin(); i != _data.getBones().end(); ++i) {
BoneData* boneData = (*i);
_bones.push_back(skeleton.findBone(boneData->getName()));
@ -290,23 +257,18 @@ namespace Spine
}
/// Applies the constraint to the constrained bones.
void IkConstraint::apply()
{
void IkConstraint::apply() {
update();
}
void IkConstraint::update()
{
switch (_bones.size())
{
case 1:
{
void IkConstraint::update() {
switch (_bones.size()) {
case 1: {
Bone* bone0 = _bones[0];
apply(*bone0, _target->getWorldX(), _target->getWorldY(), _mix);
}
break;
case 2:
{
case 2: {
Bone* bone0 = _bones[0];
Bone* bone1 = _bones[1];
apply(*bone0, *bone1, _target->getWorldX(), _target->getWorldY(), _bendDirection, _mix);
@ -315,48 +277,39 @@ namespace Spine
}
}
int IkConstraint::getOrder()
{
int IkConstraint::getOrder() {
return _data.getOrder();
}
IkConstraintData& IkConstraint::getData()
{
IkConstraintData& IkConstraint::getData() {
return _data;
}
Vector<Bone*>& IkConstraint::getBones()
{
Vector<Bone*>& IkConstraint::getBones() {
return _bones;
}
Bone* IkConstraint::getTarget()
{
Bone* IkConstraint::getTarget() {
return _target;
}
void IkConstraint::setTarget(Bone* inValue)
{
void IkConstraint::setTarget(Bone* inValue) {
_target = inValue;
}
int IkConstraint::getBendDirection()
{
int IkConstraint::getBendDirection() {
return _bendDirection;
}
void IkConstraint::setBendDirection(int inValue)
{
void IkConstraint::setBendDirection(int inValue) {
_bendDirection = inValue;
}
float IkConstraint::getMix()
{
float IkConstraint::getMix() {
return _mix;
}
void IkConstraint::setMix(float inValue)
{
void IkConstraint::setMix(float inValue) {
_mix = inValue;
}
}

View File

@ -39,58 +39,47 @@ namespace Spine
_order(0),
_target(NULL),
_bendDirection(1),
_mix(1)
{
_mix(1) {
// Empty
}
const std::string& IkConstraintData::getName()
{
const std::string& IkConstraintData::getName() {
return _name;
}
int IkConstraintData::getOrder()
{
int IkConstraintData::getOrder() {
return _order;
}
void IkConstraintData::setOrder(int inValue)
{
void IkConstraintData::setOrder(int inValue) {
_order = inValue;
}
Vector<BoneData*>& IkConstraintData::getBones()
{
Vector<BoneData*>& IkConstraintData::getBones() {
return _bones;
}
BoneData* IkConstraintData::getTarget()
{
BoneData* IkConstraintData::getTarget() {
return _target;
}
void IkConstraintData::setTarget(BoneData* inValue)
{
void IkConstraintData::setTarget(BoneData* inValue) {
_target = inValue;
}
int IkConstraintData::getBendDirection()
{
int IkConstraintData::getBendDirection() {
return _bendDirection;
}
void IkConstraintData::setBendDirection(int inValue)
{
void IkConstraintData::setBendDirection(int inValue) {
_bendDirection = inValue;
}
float IkConstraintData::getMix()
{
float IkConstraintData::getMix() {
return _mix;
}
void IkConstraintData::setMix(float inValue)
{
void IkConstraintData::setMix(float inValue) {
_mix = inValue;
}
}

View File

@ -51,20 +51,16 @@ namespace Spine
const int IkConstraintTimeline::MIX = 1;
const int IkConstraintTimeline::BEND_DIRECTION = 2;
IkConstraintTimeline::IkConstraintTimeline(int frameCount) : CurveTimeline(frameCount), _ikConstraintIndex(0)
{
IkConstraintTimeline::IkConstraintTimeline(int frameCount) : CurveTimeline(frameCount), _ikConstraintIndex(0) {
_frames.reserve(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES);
}
void IkConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction)
{
void IkConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) {
IkConstraint* constraintP = skeleton._ikConstraints[_ikConstraintIndex];
IkConstraint& constraint = *constraintP;
if (time < _frames[0])
{
switch (pose)
{
if (time < _frames[0]) {
switch (pose) {
case MixPose_Setup:
constraint._mix = constraint._data._mix;
constraint._bendDirection = constraint._data._bendDirection;
@ -79,20 +75,16 @@ namespace Spine
}
}
if (time >= _frames[_frames.size() - ENTRIES])
{
if (time >= _frames[_frames.size() - ENTRIES]) {
// Time is after last frame.
if (pose == MixPose_Setup)
{
if (pose == MixPose_Setup) {
constraint._mix = constraint._data._mix + (_frames[_frames.size() + PREV_MIX] - constraint._data._mix) * alpha;
constraint._bendDirection = direction == MixDirection_Out ? constraint._data._bendDirection
: (int)_frames[_frames.size() + PREV_BEND_DIRECTION];
}
else
{
else {
constraint._mix += (_frames[_frames.size() + PREV_MIX] - constraint._mix) * alpha;
if (direction == MixDirection_In)
{
if (direction == MixDirection_In) {
constraint._bendDirection = (int)_frames[_frames.size() + PREV_BEND_DIRECTION];
}
}
@ -105,28 +97,23 @@ namespace Spine
float frameTime = _frames[frame];
float percent = getCurvePercent(frame / ENTRIES - 1, 1 - (time - frameTime) / (_frames[frame + PREV_TIME] - frameTime));
if (pose == MixPose_Setup)
{
if (pose == MixPose_Setup) {
constraint._mix = constraint._data._mix + (mix + (_frames[frame + MIX] - mix) * percent - constraint._data._mix) * alpha;
constraint._bendDirection = direction == MixDirection_Out ? constraint._data._bendDirection : (int)_frames[frame + PREV_BEND_DIRECTION];
}
else
{
else {
constraint._mix += (mix + (_frames[frame + MIX] - mix) * percent - constraint._mix) * alpha;
if (direction == MixDirection_In)
{
if (direction == MixDirection_In) {
constraint._bendDirection = (int)_frames[frame + PREV_BEND_DIRECTION];
}
}
}
int IkConstraintTimeline::getPropertyId()
{
int IkConstraintTimeline::getPropertyId() {
return ((int)TimelineType_IkConstraint << 24) + _ikConstraintIndex;
}
void IkConstraintTimeline::setFrame(int frameIndex, float time, float mix, int bendDirection)
{
void IkConstraintTimeline::setFrame(int frameIndex, float time, float mix, int bendDirection) {
frameIndex *= ENTRIES;
_frames[frameIndex] = time;
_frames[frameIndex + MIX] = mix;

View File

@ -64,41 +64,34 @@ namespace Spine
const char* Json::_error = NULL;
Json* Json::getItem(Json *object, const char* string)
{
Json* Json::getItem(Json *object, const char* string) {
Json *c = object->_child;
while (c && json_strcasecmp(c->_name, string))
{
while (c && json_strcasecmp(c->_name, string)) {
c = c->_next;
}
return c;
}
const char* Json::getString(Json *object, const char* name, const char* defaultValue)
{
const char* Json::getString(Json *object, const char* name, const char* defaultValue) {
object = getItem(object, name);
if (object)
{
if (object) {
return object->_valueString;
}
return defaultValue;
}
float Json::getFloat(Json *value, const char* name, float defaultValue)
{
float Json::getFloat(Json *value, const char* name, float defaultValue) {
value = getItem(value, name);
return value ? value->_valueFloat : defaultValue;
}
int Json::getInt(Json *value, const char* name, int defaultValue)
{
int Json::getInt(Json *value, const char* name, int defaultValue) {
value = getItem(value, name);
return value ? value->_valueInt : defaultValue;
}
const char* Json::getError()
{
const char* Json::getError() {
return _error;
}
@ -113,92 +106,73 @@ namespace Spine
_valueString(NULL),
_valueInt(0),
_valueFloat(0),
_name(NULL)
{
if (value)
{
_name(NULL) {
if (value) {
value = parseValue(this, skip(value));
assert(value);
}
}
Json::~Json()
{
if (_child)
{
Json::~Json() {
if (_child) {
DESTROY(Json, _child);
}
if (_valueString)
{
if (_valueString) {
FREE(_valueString);
}
if (_name)
{
if (_name) {
FREE(_name);
}
if (_next)
{
if (_next) {
DESTROY(Json, _next);
}
}
const char* Json::skip(const char* inValue)
{
if (!inValue)
{
const char* Json::skip(const char* inValue) {
if (!inValue) {
/* must propagate NULL since it's often called in skip(f(...)) form */
return NULL;
}
while (*inValue && (unsigned char)*inValue <= 32)
{
while (*inValue && (unsigned char)*inValue <= 32) {
inValue++;
}
return inValue;
}
const char* Json::parseValue(Json *item, const char* value)
{
const char* Json::parseValue(Json *item, const char* value) {
/* Referenced by constructor, parseArray(), and parseObject(). */
/* Always called with the result of skip(). */
#if SPINE_JSON_DEBUG /* Checked at entry to graph, constructor, and after every parse call. */
if (!value)
{
if (!value) {
/* Fail on null. */
return NULL;
}
#endif
switch (*value)
{
case 'n':
{
if (!strncmp(value + 1, "ull", 3))
{
switch (*value) {
case 'n': {
if (!strncmp(value + 1, "ull", 3)) {
item->_type = JSON_NULL;
return value + 4;
}
break;
}
case 'f':
{
if (!strncmp(value + 1, "alse", 4))
{
case 'f': {
if (!strncmp(value + 1, "alse", 4)) {
item->_type = JSON_FALSE;
/* calloc prevents us needing item->_type = JSON_FALSE or valueInt = 0 here */
return value + 5;
}
break;
}
case 't':
{
if (!strncmp(value + 1, "rue", 3))
{
case 't': {
if (!strncmp(value + 1, "rue", 3)) {
item->_type = JSON_TRUE;
item->_valueInt = 1;
return value + 4;
@ -232,47 +206,38 @@ namespace Spine
}
static const unsigned char firstByteMark[7] = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC};
const char* Json::parseString(Json *item, const char* str)
{
const char* Json::parseString(Json *item, const char* str) {
const char* ptr = str + 1;
char* ptr2;
char* out;
int len = 0;
unsigned uc, uc2;
if (*str != '\"')
{
if (*str != '\"') {
/* TODO: don't need this check when called from parseValue, but do need from parseObject */
_error = str;
return 0;
} /* not a string! */
while (*ptr != '\"' && *ptr && ++len)
{
if (*ptr++ == '\\')
{
while (*ptr != '\"' && *ptr && ++len) {
if (*ptr++ == '\\') {
ptr++; /* Skip escaped quotes. */
}
}
out = MALLOC(char, len + 1); /* The length needed for the string, roughly. */
if (!out)
{
if (!out) {
return 0;
}
ptr = str + 1;
ptr2 = out;
while (*ptr != '\"' && *ptr)
{
if (*ptr != '\\')
{
while (*ptr != '\"' && *ptr) {
if (*ptr != '\\') {
*ptr2++ = *ptr++;
}
else
{
else {
ptr++;
switch (*ptr)
{
switch (*ptr) {
case 'b':
*ptr2++ = '\b';
break;
@ -288,50 +253,41 @@ namespace Spine
case 't':
*ptr2++ = '\t';
break;
case 'u':
{
case 'u': {
/* transcode utf16 to utf8. */
sscanf(ptr + 1, "%4x", &uc);
ptr += 4; /* get the unicode char. */
if ((uc >= 0xDC00 && uc <= 0xDFFF) || uc == 0)
{
if ((uc >= 0xDC00 && uc <= 0xDFFF) || uc == 0) {
break; /* check for invalid. */
}
/* TODO provide an option to ignore surrogates, use unicode replacement character? */
if (uc >= 0xD800 && uc <= 0xDBFF) /* UTF16 surrogate pairs. */
{
if (ptr[1] != '\\' || ptr[2] != 'u')
{
if (uc >= 0xD800 && uc <= 0xDBFF) /* UTF16 surrogate pairs. */ {
if (ptr[1] != '\\' || ptr[2] != 'u') {
break; /* missing second-half of surrogate. */
}
sscanf(ptr + 3, "%4x", &uc2);
ptr += 6;
if (uc2 < 0xDC00 || uc2 > 0xDFFF)
{
if (uc2 < 0xDC00 || uc2 > 0xDFFF) {
break; /* invalid second-half of surrogate. */
}
uc = 0x10000 + (((uc & 0x3FF) << 10) | (uc2 & 0x3FF));
}
len = 4;
if (uc < 0x80)
{
if (uc < 0x80) {
len = 1;
}
else if (uc < 0x800)
{
else if (uc < 0x800) {
len = 2;
}
else if (uc < 0x10000)
{
else if (uc < 0x10000) {
len = 3;
}
ptr2 += len;
switch (len)
{
switch (len) {
case 4:
*--ptr2 = ((uc | 0x80) & 0xBF);
uc >>= 6;
@ -360,8 +316,7 @@ namespace Spine
*ptr2 = NULL;
if (*ptr == '\"')
{
if (*ptr == '\"') {
ptr++; /* TODO error handling if not \" or \0 ? */
}
@ -371,32 +326,27 @@ namespace Spine
return ptr;
}
const char* Json::parseNumber(Json *item, const char* num)
{
const char* Json::parseNumber(Json *item, const char* num) {
double result = 0.0;
int negative = 0;
char* ptr = (char*)num;
if (*ptr == '-')
{
if (*ptr == '-') {
negative = -1;
++ptr;
}
while (*ptr >= '0' && *ptr <= '9')
{
while (*ptr >= '0' && *ptr <= '9') {
result = result * 10.0 + (*ptr - '0');
++ptr;
}
if (*ptr == '.')
{
if (*ptr == '.') {
double fraction = 0.0;
int n = 0;
++ptr;
while (*ptr >= '0' && *ptr <= '9')
{
while (*ptr >= '0' && *ptr <= '9') {
fraction = (fraction * 10.0) + (*ptr - '0');
++ptr;
++n;
@ -404,68 +354,57 @@ namespace Spine
result += fraction / pow(10.0, n);
}
if (negative)
{
if (negative) {
result = -result;
}
if (*ptr == 'e' || *ptr == 'E')
{
if (*ptr == 'e' || *ptr == 'E') {
double exponent = 0;
int expNegative = 0;
int n = 0;
++ptr;
if (*ptr == '-')
{
if (*ptr == '-') {
expNegative = -1;
++ptr;
}
else if (*ptr == '+')
{
else if (*ptr == '+') {
++ptr;
}
while (*ptr >= '0' && *ptr <= '9')
{
while (*ptr >= '0' && *ptr <= '9') {
exponent = (exponent * 10.0) + (*ptr - '0');
++ptr;
++n;
}
if (expNegative)
{
if (expNegative) {
result = result / pow(10, exponent);
}
else
{
else {
result = result * pow(10, exponent);
}
}
if (ptr != num)
{
if (ptr != num) {
/* Parse success, number found. */
item->_valueFloat = result;
item->_valueInt = static_cast<int>(result);
item->_type = JSON_NUMBER;
return ptr;
}
else
{
else {
/* Parse failure, _error is set. */
_error = num;
return NULL;
}
}
const char* Json::parseArray(Json *item, const char* value)
{
const char* Json::parseArray(Json *item, const char* value) {
Json *child;
#if SPINE_JSON_DEBUG /* unnecessary, only callsite (parse_value) verifies this */
if (*value != '[')
{
if (*value != '[') {
ep = value;
return 0;
} /* not an array! */
@ -473,33 +412,28 @@ namespace Spine
item->_type = JSON_ARRAY;
value = skip(value + 1);
if (*value == ']')
{
if (*value == ']') {
return value + 1; /* empty array. */
}
item->_child = child = NEW(Json);
new (item->_child) Json(NULL);
if (!item->_child)
{
if (!item->_child) {
return NULL; /* memory fail */
}
value = skip(parseValue(child, skip(value))); /* skip any spacing, get the value. */
if (!value)
{
if (!value) {
return NULL;
}
item->_size = 1;
while (*value == ',')
{
while (*value == ',') {
Json *new_item = NEW(Json);
new (new_item) Json(NULL);
if (!new_item)
{
if (!new_item) {
return NULL; /* memory fail */
}
child->_next = new_item;
@ -508,15 +442,13 @@ namespace Spine
#endif
child = new_item;
value = skip(parseValue(child, skip(value + 1)));
if (!value)
{
if (!value) {
return NULL; /* parse fail */
}
item->_size++;
}
if (*value == ']')
{
if (*value == ']') {
return value + 1; /* end of array */
}
@ -526,13 +458,11 @@ namespace Spine
}
/* Build an object from the text. */
const char* Json::parseObject(Json *item, const char* value)
{
const char* Json::parseObject(Json *item, const char* value) {
Json *child;
#if SPINE_JSON_DEBUG /* unnecessary, only callsite (parse_value) verifies this */
if (*value != '{')
{
if (*value != '{') {
ep = value;
return 0;
} /* not an object! */
@ -540,44 +470,37 @@ namespace Spine
item->_type = JSON_OBJECT;
value = skip(value + 1);
if (*value == '}')
{
if (*value == '}') {
return value + 1; /* empty array. */
}
item->_child = child = NEW(Json);
new (item->_child) Json(NULL);
if (!item->_child)
{
if (!item->_child) {
return NULL;
}
value = skip(parseString(child, skip(value)));
if (!value)
{
if (!value) {
return NULL;
}
child->_name = child->_valueString;
child->_valueString = 0;
if (*value != ':')
{
if (*value != ':') {
_error = value;
return NULL;
} /* fail! */
value = skip(parseValue(child, skip(value + 1))); /* skip any spacing, get the value. */
if (!value)
{
if (!value) {
return NULL;
}
item->_size = 1;
while (*value == ',')
{
while (*value == ',') {
Json *new_item = NEW(Json);
new (new_item) Json(NULL);
if (!new_item)
{
if (!new_item) {
return NULL; /* memory fail */
}
child->_next = new_item;
@ -586,28 +509,24 @@ namespace Spine
#endif
child = new_item;
value = skip(parseString(child, skip(value + 1)));
if (!value)
{
if (!value) {
return NULL;
}
child->_name = child->_valueString;
child->_valueString = 0;
if (*value != ':')
{
if (*value != ':') {
_error = value;
return NULL;
} /* fail! */
value = skip(parseValue(child, skip(value + 1))); /* skip any spacing, get the value. */
if (!value)
{
if (!value) {
return NULL;
}
item->_size++;
}
if (*value == '}')
{
if (*value == '}') {
return value + 1; /* end of array */
}
@ -616,31 +535,25 @@ namespace Spine
return NULL; /* malformed. */
}
int Json::json_strcasecmp(const char* s1, const char* s2)
{
int Json::json_strcasecmp(const char* s1, const char* s2) {
/* TODO we may be able to elide these NULL checks if we can prove
* the graph and input (only callsite is Json_getItem) should not have NULLs
*/
if (s1 && s2)
{
if (s1 && s2) {
#if defined(_WIN32)
return _stricmp(s1, s2);
#else
return strcasecmp( s1, s2 );
#endif
}
else
{
if (s1 < s2)
{
else {
if (s1 < s2) {
return -1; /* s1 is null, s2 is not */
}
else if (s1 == s2)
{
else if (s1 == s2) {
return 0; /* both are null */
}
else
{
else {
return 1; /* s2 is nul s1 is not */
}
}

View File

@ -38,8 +38,7 @@ namespace Spine
_mesh(mesh),
_skin(skin),
_slotIndex(slotIndex),
_parent(parent)
{
_parent(parent) {
// Empty
}
}

View File

@ -34,56 +34,45 @@ namespace Spine
{
float MathUtil::SIN_TABLE[SIN_COUNT] = {0.0f};
MathUtil::MathUtil()
{
for (int i = 0; i < SIN_COUNT; ++i)
{
MathUtil::MathUtil() {
for (int i = 0; i < SIN_COUNT; ++i) {
SIN_TABLE[i] = (float)sin((i + 0.5f) / SIN_COUNT * RadFull);
}
for (int i = 0; i < 360; i += 90)
{
for (int i = 0; i < 360; i += 90) {
SIN_TABLE[(int)(i * DegToIndex) & SIN_MASK] = (float)sin(i * DegRad);
}
}
/// Returns the sine in radians from a lookup table.
float MathUtil::sin(float radians)
{
float MathUtil::sin(float radians) {
return SIN_TABLE[(int)(radians * RadToIndex) & SIN_MASK];
}
/// Returns the cosine in radians from a lookup table.
float MathUtil::cos(float radians)
{
float MathUtil::cos(float radians) {
return SIN_TABLE[(int)((radians + SPINE_PI / 2) * RadToIndex) & SIN_MASK];
}
/// Returns the sine in radians from a lookup table.
float MathUtil::sinDeg(float degrees)
{
float MathUtil::sinDeg(float degrees) {
return SIN_TABLE[(int)(degrees * DegToIndex) & SIN_MASK];
}
/// Returns the cosine in radians from a lookup table.
float MathUtil::cosDeg(float degrees)
{
float MathUtil::cosDeg(float degrees) {
return SIN_TABLE[(int)((degrees + 90) * DegToIndex) & SIN_MASK];
}
/// Returns atan2 in radians, faster but less accurate than Math.Atan2. Average error of 0.00231 radians (0.1323
/// degrees), largest error of 0.00488 radians (0.2796 degrees).
float MathUtil::atan2(float y, float x)
{
if (areFloatsPracticallyEqual(x, 0.0f))
{
if (y > 0.0f)
{
float MathUtil::atan2(float y, float x) {
if (areFloatsPracticallyEqual(x, 0.0f)) {
if (y > 0.0f) {
return SPINE_PI / 2;
}
if (areFloatsPracticallyEqual(y, 0.0f))
{
if (areFloatsPracticallyEqual(y, 0.0f)) {
return 0.0f;
}
@ -92,11 +81,9 @@ namespace Spine
float atan, z = y / x;
if (fabs(z) < 1.0f)
{
if (fabs(z) < 1.0f) {
atan = z / (1.0f + 0.28f * z * z);
if (x < 0.0f)
{
if (x < 0.0f) {
return atan + (y < 0.0f ? -SPINE_PI : SPINE_PI);
}

Some files were not shown because too many files have changed in this diff Show More