diff --git a/spine-cpp/spine-cpp/include/spine/Animation.h b/spine-cpp/spine-cpp/include/spine/Animation.h index 9f0ca70ef..fa674382e 100644 --- a/spine-cpp/spine-cpp/include/spine/Animation.h +++ b/spine-cpp/spine-cpp/include/spine/Animation.h @@ -43,8 +43,7 @@ namespace Spine class Skeleton; class Event; - class Animation - { + class Animation { friend class AnimationState; friend class TrackEntry; friend class AnimationStateData; diff --git a/spine-cpp/spine-cpp/include/spine/AnimationState.h b/spine-cpp/spine-cpp/include/spine/AnimationState.h index 09821da5b..4e81c40d3 100644 --- a/spine-cpp/spine-cpp/include/spine/AnimationState.h +++ b/spine-cpp/spine-cpp/include/spine/AnimationState.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/AnimationStateData.h b/spine-cpp/spine-cpp/include/spine/AnimationStateData.h index 952b33256..c2befdd01 100644 --- a/spine-cpp/spine-cpp/include/spine/AnimationStateData.h +++ b/spine-cpp/spine-cpp/include/spine/AnimationStateData.h @@ -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; }; diff --git a/spine-cpp/spine-cpp/include/spine/Atlas.h b/spine-cpp/spine-cpp/include/spine/Atlas.h index eb9150cff..606a35faa 100644 --- a/spine-cpp/spine-cpp/include/spine/Atlas.h +++ b/spine-cpp/spine-cpp/include/spine/Atlas.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h b/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h index 440b5ac5b..2052bb69b 100644 --- a/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h +++ b/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h @@ -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: diff --git a/spine-cpp/spine-cpp/include/spine/Attachment.h b/spine-cpp/spine-cpp/include/spine/Attachment.h index fdf5a1a58..35ae099b7 100644 --- a/spine-cpp/spine-cpp/include/spine/Attachment.h +++ b/spine-cpp/spine-cpp/include/spine/Attachment.h @@ -37,8 +37,7 @@ namespace Spine { - class Attachment - { + class Attachment { RTTI_DECL; public: diff --git a/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h b/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h index 91f59705e..1da82e4f7 100644 --- a/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h +++ b/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h @@ -45,8 +45,7 @@ namespace Spine class PointAttachment; class ClippingAttachment; - class AttachmentLoader - { + class AttachmentLoader { RTTI_DECL; AttachmentLoader(); diff --git a/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h b/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h index 6fca8296c..c0a1fad41 100644 --- a/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/AttachmentTimeline.h @@ -44,8 +44,7 @@ namespace Spine class Skeleton; class Event; - class AttachmentTimeline : public Timeline - { + class AttachmentTimeline : public Timeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/AttachmentType.h b/spine-cpp/spine-cpp/include/spine/AttachmentType.h index 3799207cd..1ad7a4d62 100644 --- a/spine-cpp/spine-cpp/include/spine/AttachmentType.h +++ b/spine-cpp/spine-cpp/include/spine/AttachmentType.h @@ -33,8 +33,7 @@ namespace Spine { - enum AttachmentType - { + enum AttachmentType { AttachmentType_Region, AttachmentType_Boundingbox, AttachmentType_Mesh, diff --git a/spine-cpp/spine-cpp/include/spine/BlendMode.h b/spine-cpp/spine-cpp/include/spine/BlendMode.h index 0f0afa645..d61fcdd77 100644 --- a/spine-cpp/spine-cpp/include/spine/BlendMode.h +++ b/spine-cpp/spine-cpp/include/spine/BlendMode.h @@ -33,8 +33,7 @@ namespace Spine { - enum BlendMode - { + enum BlendMode { BlendMode_Normal = 0, BlendMode_Additive, BlendMode_Multiply, diff --git a/spine-cpp/spine-cpp/include/spine/Bone.h b/spine-cpp/spine-cpp/include/spine/Bone.h index c7f1c7bf6..4413be97d 100644 --- a/spine-cpp/spine-cpp/include/spine/Bone.h +++ b/spine-cpp/spine-cpp/include/spine/Bone.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/BoneData.h b/spine-cpp/spine-cpp/include/spine/BoneData.h index 040696871..4825ed4fe 100644 --- a/spine-cpp/spine-cpp/include/spine/BoneData.h +++ b/spine-cpp/spine-cpp/include/spine/BoneData.h @@ -37,8 +37,7 @@ namespace Spine { - class BoneData - { + class BoneData { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h b/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h index 996af9f94..aef2b7c47 100644 --- a/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/BoundingBoxAttachment.h @@ -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); diff --git a/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h b/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h index bbf784429..8740407b3 100644 --- a/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/ClippingAttachment.h @@ -37,8 +37,7 @@ namespace Spine { class SlotData; - class ClippingAttachment : public VertexAttachment - { + class ClippingAttachment : public VertexAttachment { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/ColorTimeline.h b/spine-cpp/spine-cpp/include/spine/ColorTimeline.h index 740743134..03295baff 100644 --- a/spine-cpp/spine-cpp/include/spine/ColorTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ColorTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class ColorTimeline : public CurveTimeline - { + class ColorTimeline : public CurveTimeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/Constraint.h b/spine-cpp/spine-cpp/include/spine/Constraint.h index aa0122c34..ced362987 100644 --- a/spine-cpp/spine-cpp/include/spine/Constraint.h +++ b/spine-cpp/spine-cpp/include/spine/Constraint.h @@ -36,8 +36,7 @@ namespace Spine { /// The interface for all constraints. - class Constraint : public Updatable - { + class Constraint : public Updatable { RTTI_DECL; public: diff --git a/spine-cpp/spine-cpp/include/spine/ContainerUtil.h b/spine-cpp/spine-cpp/include/spine/ContainerUtil.h index 053a56634..c44c18817 100644 --- a/spine-cpp/spine-cpp/include/spine/ContainerUtil.h +++ b/spine-cpp/spine-cpp/include/spine/ContainerUtil.h @@ -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 - static T* findWithName(Vector& items, std::string name) - { + static T* findWithName(Vector& 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 - static int findIndexWithName(Vector& items, std::string name) - { + static int findIndexWithName(Vector& 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(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 - static T* findWithDataName(Vector& items, std::string name) - { + static T* findWithDataName(Vector& 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 - static int findIndexWithDataName(Vector& items, std::string name) - { + static int findIndexWithDataName(Vector& 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(i); } } @@ -120,10 +107,8 @@ namespace Spine } template - static void cleanUpVectorOfPointers(Vector& items) - { - for (size_t i = 0; i < items.size(); ) - { + static void cleanUpVectorOfPointers(Vector& items) { + for (size_t i = 0; i < items.size(); ) { T* item = items[i]; DESTROY(T, item); diff --git a/spine-cpp/spine-cpp/include/spine/CurveTimeline.h b/spine-cpp/spine-cpp/include/spine/CurveTimeline.h index 45854a7a0..286d53c4a 100644 --- a/spine-cpp/spine-cpp/include/spine/CurveTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/CurveTimeline.h @@ -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: diff --git a/spine-cpp/spine-cpp/include/spine/DeformTimeline.h b/spine-cpp/spine-cpp/include/spine/DeformTimeline.h index b601ca9f9..7510ce509 100644 --- a/spine-cpp/spine-cpp/include/spine/DeformTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/DeformTimeline.h @@ -37,8 +37,7 @@ namespace Spine { class VertexAttachment; - class DeformTimeline : public CurveTimeline - { + class DeformTimeline : public CurveTimeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h b/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h index 4d1adc00c..e11d74c0f 100644 --- a/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/DrawOrderTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class DrawOrderTimeline : public Timeline - { + class DrawOrderTimeline : public Timeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/Event.h b/spine-cpp/spine-cpp/include/spine/Event.h index 7c7330744..9956d9030 100644 --- a/spine-cpp/spine-cpp/include/spine/Event.h +++ b/spine-cpp/spine-cpp/include/spine/Event.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/EventData.h b/spine-cpp/spine-cpp/include/spine/EventData.h index acc4c9fec..dcb0c774c 100644 --- a/spine-cpp/spine-cpp/include/spine/EventData.h +++ b/spine-cpp/spine-cpp/include/spine/EventData.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/EventTimeline.h b/spine-cpp/spine-cpp/include/spine/EventTimeline.h index 5fb6fd5e9..f474e637b 100644 --- a/spine-cpp/spine-cpp/include/spine/EventTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/EventTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class EventTimeline : public Timeline - { + class EventTimeline : public Timeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/Extension.h b/spine-cpp/spine-cpp/include/spine/Extension.h index 6c3a3f9c4..0a9379308 100644 --- a/spine-cpp/spine-cpp/include/spine/Extension.h +++ b/spine-cpp/spine-cpp/include/spine/Extension.h @@ -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(); diff --git a/spine-cpp/spine-cpp/include/spine/HashMap.h b/spine-cpp/spine-cpp/include/spine/HashMap.h index aab044374..e32cf4e30 100755 --- a/spine-cpp/spine-cpp/include/spine/HashMap.h +++ b/spine-cpp/spine-cpp/include/spine/HashMap.h @@ -37,51 +37,42 @@ namespace Spine { template - 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 insert(const K& key, const V& value) - { + std::pair 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; } }; diff --git a/spine-cpp/spine-cpp/include/spine/IkConstraint.h b/spine-cpp/spine-cpp/include/spine/IkConstraint.h index 387efb900..dbaf59786 100644 --- a/spine-cpp/spine-cpp/include/spine/IkConstraint.h +++ b/spine-cpp/spine-cpp/include/spine/IkConstraint.h @@ -41,8 +41,7 @@ namespace Spine class Skeleton; class Bone; - class IkConstraint : public Constraint - { + class IkConstraint : public Constraint { friend class Skeleton; friend class IkConstraintTimeline; diff --git a/spine-cpp/spine-cpp/include/spine/IkConstraintData.h b/spine-cpp/spine-cpp/include/spine/IkConstraintData.h index 5c4732dee..286bcddb2 100644 --- a/spine-cpp/spine-cpp/include/spine/IkConstraintData.h +++ b/spine-cpp/spine-cpp/include/spine/IkConstraintData.h @@ -39,8 +39,7 @@ namespace Spine { class BoneData; - class IkConstraintData - { + class IkConstraintData { friend class SkeletonBinary; friend class SkeletonJson; friend class IkConstraint; diff --git a/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h b/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h index 295bd1d9c..957fd9178 100644 --- a/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/IkConstraintTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class IkConstraintTimeline : public CurveTimeline - { + class IkConstraintTimeline : public CurveTimeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/Json.h b/spine-cpp/spine-cpp/include/spine/Json.h index 3cf273a1c..df73ddd4d 100644 --- a/spine-cpp/spine-cpp/include/spine/Json.h +++ b/spine-cpp/spine-cpp/include/spine/Json.h @@ -38,8 +38,7 @@ namespace Spine { - class Json - { + class Json { friend class SkeletonJson; public: diff --git a/spine-cpp/spine-cpp/include/spine/LinkedMesh.h b/spine-cpp/spine-cpp/include/spine/LinkedMesh.h index 56c7c46bf..136c53bb8 100644 --- a/spine-cpp/spine-cpp/include/spine/LinkedMesh.h +++ b/spine-cpp/spine-cpp/include/spine/LinkedMesh.h @@ -37,8 +37,7 @@ namespace Spine { class MeshAttachment; - class LinkedMesh - { + class LinkedMesh { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/MathUtil.h b/spine-cpp/spine-cpp/include/spine/MathUtil.h index 325b95d2a..cbd31b755 100644 --- a/spine-cpp/spine-cpp/include/spine/MathUtil.h +++ b/spine-cpp/spine-cpp/include/spine/MathUtil.h @@ -51,18 +51,15 @@ namespace Spine { template - 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(); diff --git a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h index edf6c24a6..7c73488f8 100644 --- a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/MixDirection.h b/spine-cpp/spine-cpp/include/spine/MixDirection.h index ab14a3823..3dd096ea7 100644 --- a/spine-cpp/spine-cpp/include/spine/MixDirection.h +++ b/spine-cpp/spine-cpp/include/spine/MixDirection.h @@ -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 }; diff --git a/spine-cpp/spine-cpp/include/spine/MixPose.h b/spine-cpp/spine-cpp/include/spine/MixPose.h index f95fce969..b9aeec4ae 100644 --- a/spine-cpp/spine-cpp/include/spine/MixPose.h +++ b/spine-cpp/spine-cpp/include/spine/MixPose.h @@ -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, diff --git a/spine-cpp/spine-cpp/include/spine/PathAttachment.h b/spine-cpp/spine-cpp/include/spine/PathAttachment.h index aaaa2c68e..f5abcc32c 100644 --- a/spine-cpp/spine-cpp/include/spine/PathAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/PathAttachment.h @@ -35,8 +35,7 @@ namespace Spine { - class PathAttachment : public VertexAttachment - { + class PathAttachment : public VertexAttachment { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraint.h b/spine-cpp/spine-cpp/include/spine/PathConstraint.h index a88e5a4cc..2daa91ebb 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraint.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraint.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintData.h b/spine-cpp/spine-cpp/include/spine/PathConstraintData.h index 8736a1d32..68991f8c8 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintData.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintData.h @@ -43,8 +43,7 @@ namespace Spine class BoneData; class SlotData; - class PathConstraintData - { + class PathConstraintData { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h index c2cce00e9..7e64ac85d 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintMixTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class PathConstraintMixTimeline : public CurveTimeline - { + class PathConstraintMixTimeline : public CurveTimeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h index b5fe6916b..172a897a7 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintPositionTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class PathConstraintPositionTimeline : public CurveTimeline - { + class PathConstraintPositionTimeline : public CurveTimeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h b/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h index 68aad43c9..c30394f79 100644 --- a/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/PathConstraintSpacingTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class PathConstraintSpacingTimeline : public PathConstraintPositionTimeline - { + class PathConstraintSpacingTimeline : public PathConstraintPositionTimeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/PointAttachment.h b/spine-cpp/spine-cpp/include/spine/PointAttachment.h index cdb13fdd0..f1f5f0b1d 100644 --- a/spine-cpp/spine-cpp/include/spine/PointAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/PointAttachment.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/Pool.h b/spine-cpp/spine-cpp/include/spine/Pool.h index 963fd6b55..29a447a13 100644 --- a/spine-cpp/spine-cpp/include/spine/Pool.h +++ b/spine-cpp/spine-cpp/include/spine/Pool.h @@ -38,31 +38,25 @@ namespace Spine { template - 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); } } diff --git a/spine-cpp/spine-cpp/include/spine/PositionMode.h b/spine-cpp/spine-cpp/include/spine/PositionMode.h index 66a601cac..c5ad9bdfc 100644 --- a/spine-cpp/spine-cpp/include/spine/PositionMode.h +++ b/spine-cpp/spine-cpp/include/spine/PositionMode.h @@ -33,8 +33,7 @@ namespace Spine { - enum PositionMode - { + enum PositionMode { PositionMode_Fixed = 0, PositionMode_Percent }; diff --git a/spine-cpp/spine-cpp/include/spine/RTTI.h b/spine-cpp/spine-cpp/include/spine/RTTI.h index 79f413efa..362c3548a 100644 --- a/spine-cpp/spine-cpp/include/spine/RTTI.h +++ b/spine-cpp/spine-cpp/include/spine/RTTI.h @@ -35,8 +35,7 @@ namespace Spine { - class RTTI - { + class RTTI { public: RTTI(const std::string& className); diff --git a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h index d48f0c976..acdb6a870 100644 --- a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/RotateMode.h b/spine-cpp/spine-cpp/include/spine/RotateMode.h index a8ccd6f97..3c5cbe789 100644 --- a/spine-cpp/spine-cpp/include/spine/RotateMode.h +++ b/spine-cpp/spine-cpp/include/spine/RotateMode.h @@ -33,8 +33,7 @@ namespace Spine { - enum RotateMode - { + enum RotateMode { RotateMode_Tangent = 0, RotateMode_Chain, RotateMode_ChainScale diff --git a/spine-cpp/spine-cpp/include/spine/RotateTimeline.h b/spine-cpp/spine-cpp/include/spine/RotateTimeline.h index aed7eb822..778fd9a15 100644 --- a/spine-cpp/spine-cpp/include/spine/RotateTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/RotateTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class RotateTimeline : public CurveTimeline - { + class RotateTimeline : public CurveTimeline { friend class SkeletonBinary; friend class SkeletonJson; friend class AnimationState; diff --git a/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h b/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h index a0788fe1c..f02c40afa 100644 --- a/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ScaleTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class ScaleTimeline : public TranslateTimeline - { + class ScaleTimeline : public TranslateTimeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/ShearTimeline.h b/spine-cpp/spine-cpp/include/spine/ShearTimeline.h index d3b46ac70..a42e2ec45 100644 --- a/spine-cpp/spine-cpp/include/spine/ShearTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/ShearTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class ShearTimeline : public TranslateTimeline - { + class ShearTimeline : public TranslateTimeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/Skeleton.h b/spine-cpp/spine-cpp/include/spine/Skeleton.h index 72a305daa..c6f9564f3 100644 --- a/spine-cpp/spine-cpp/include/spine/Skeleton.h +++ b/spine-cpp/spine-cpp/include/spine/Skeleton.h @@ -49,8 +49,7 @@ namespace Spine class Skin; class Attachment; - class Skeleton - { + class Skeleton { friend class AnimationState; friend class SkeletonBounds; friend class SkeletonClipping; diff --git a/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h b/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h index c26ad8ea8..96c970019 100644 --- a/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h +++ b/spine-cpp/spine-cpp/include/spine/SkeletonBinary.h @@ -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; }; diff --git a/spine-cpp/spine-cpp/include/spine/SkeletonBounds.h b/spine-cpp/spine-cpp/include/spine/SkeletonBounds.h index 424bc2a7f..c000cbe44 100644 --- a/spine-cpp/spine-cpp/include/spine/SkeletonBounds.h +++ b/spine-cpp/spine-cpp/include/spine/SkeletonBounds.h @@ -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 _vertices; int _count; - Polygon() : _count(0) - { + Polygon() : _count(0) { _vertices.reserve(16); } }; diff --git a/spine-cpp/spine-cpp/include/spine/SkeletonClipping.h b/spine-cpp/spine-cpp/include/spine/SkeletonClipping.h index f61e4aa7d..19baa4746 100644 --- a/spine-cpp/spine-cpp/include/spine/SkeletonClipping.h +++ b/spine-cpp/spine-cpp/include/spine/SkeletonClipping.h @@ -39,8 +39,7 @@ namespace Spine class Slot; class ClippingAttachment; - class SkeletonClipping - { + class SkeletonClipping { public: SkeletonClipping(); diff --git a/spine-cpp/spine-cpp/include/spine/SkeletonData.h b/spine-cpp/spine-cpp/include/spine/SkeletonData.h index 96b4584cc..04e195a8c 100644 --- a/spine-cpp/spine-cpp/include/spine/SkeletonData.h +++ b/spine-cpp/spine-cpp/include/spine/SkeletonData.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/SkeletonJson.h b/spine-cpp/spine-cpp/include/spine/SkeletonJson.h index 9fbbf11fb..6c0ea928b 100644 --- a/spine-cpp/spine-cpp/include/spine/SkeletonJson.h +++ b/spine-cpp/spine-cpp/include/spine/SkeletonJson.h @@ -46,8 +46,7 @@ namespace Spine class AttachmentLoader; class LinkedMesh; - class SkeletonJson - { + class SkeletonJson { public: SkeletonJson(Vector& atlasArray); diff --git a/spine-cpp/spine-cpp/include/spine/Skin.h b/spine-cpp/spine-cpp/include/spine/Skin.h index 4ec62317d..8836b692e 100644 --- a/spine-cpp/spine-cpp/include/spine/Skin.h +++ b/spine-cpp/spine-cpp/include/spine/Skin.h @@ -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; }; diff --git a/spine-cpp/spine-cpp/include/spine/Slot.h b/spine-cpp/spine-cpp/include/spine/Slot.h index 780db4425..c85713a5c 100644 --- a/spine-cpp/spine-cpp/include/spine/Slot.h +++ b/spine-cpp/spine-cpp/include/spine/Slot.h @@ -42,8 +42,7 @@ namespace Spine class Skeleton; class Attachment; - class Slot - { + class Slot { friend class VertexAttachment; friend class Skeleton; friend class SkeletonBounds; diff --git a/spine-cpp/spine-cpp/include/spine/SlotData.h b/spine-cpp/spine-cpp/include/spine/SlotData.h index 45eeb834d..444195aa6 100644 --- a/spine-cpp/spine-cpp/include/spine/SlotData.h +++ b/spine-cpp/spine-cpp/include/spine/SlotData.h @@ -39,8 +39,7 @@ namespace Spine { class BoneData; - class SlotData - { + class SlotData { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/SpacingMode.h b/spine-cpp/spine-cpp/include/spine/SpacingMode.h index 76b2986b4..e3b52dd07 100644 --- a/spine-cpp/spine-cpp/include/spine/SpacingMode.h +++ b/spine-cpp/spine-cpp/include/spine/SpacingMode.h @@ -33,8 +33,7 @@ namespace Spine { - enum SpacingMode - { + enum SpacingMode { SpacingMode_Length = 0, SpacingMode_Fixed, SpacingMode_Percent diff --git a/spine-cpp/spine-cpp/include/spine/TextureLoader.h b/spine-cpp/spine-cpp/include/spine/TextureLoader.h index 82f469945..5502922f7 100644 --- a/spine-cpp/spine-cpp/include/spine/TextureLoader.h +++ b/spine-cpp/spine-cpp/include/spine/TextureLoader.h @@ -37,8 +37,7 @@ namespace Spine { class AtlasPage; - class TextureLoader - { + class TextureLoader { public: TextureLoader(); diff --git a/spine-cpp/spine-cpp/include/spine/Timeline.h b/spine-cpp/spine-cpp/include/spine/Timeline.h index 606854138..0e1e0e3fe 100644 --- a/spine-cpp/spine-cpp/include/spine/Timeline.h +++ b/spine-cpp/spine-cpp/include/spine/Timeline.h @@ -41,8 +41,7 @@ namespace Spine class Skeleton; class Event; - class Timeline - { + class Timeline { RTTI_DECL; public: diff --git a/spine-cpp/spine-cpp/include/spine/TimelineType.h b/spine-cpp/spine-cpp/include/spine/TimelineType.h index 06f085b6e..f055fb599 100644 --- a/spine-cpp/spine-cpp/include/spine/TimelineType.h +++ b/spine-cpp/spine-cpp/include/spine/TimelineType.h @@ -33,8 +33,7 @@ namespace Spine { - enum TimelineType - { + enum TimelineType { TimelineType_Rotate = 0, TimelineType_Translate, TimelineType_Scale, diff --git a/spine-cpp/spine-cpp/include/spine/TransformConstraint.h b/spine-cpp/spine-cpp/include/spine/TransformConstraint.h index 7c5061f60..ad837b54d 100644 --- a/spine-cpp/spine-cpp/include/spine/TransformConstraint.h +++ b/spine-cpp/spine-cpp/include/spine/TransformConstraint.h @@ -41,8 +41,7 @@ namespace Spine class Skeleton; class Bone; - class TransformConstraint : public Constraint - { + class TransformConstraint : public Constraint { friend class Skeleton; friend class TransformConstraintTimeline; diff --git a/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h b/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h index aa8e737d6..c12cb40c6 100644 --- a/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h +++ b/spine-cpp/spine-cpp/include/spine/TransformConstraintData.h @@ -39,8 +39,7 @@ namespace Spine { class BoneData; - class TransformConstraintData - { + class TransformConstraintData { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h b/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h index 2324234cb..ddefa6f20 100644 --- a/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TransformConstraintTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class TransformConstraintTimeline : public CurveTimeline - { + class TransformConstraintTimeline : public CurveTimeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/TransformMode.h b/spine-cpp/spine-cpp/include/spine/TransformMode.h index 35c1ae55b..8b9c6df53 100644 --- a/spine-cpp/spine-cpp/include/spine/TransformMode.h +++ b/spine-cpp/spine-cpp/include/spine/TransformMode.h @@ -33,8 +33,7 @@ namespace Spine { - enum TransformMode - { + enum TransformMode { //0000 0 Flip Scale Rotation TransformMode_Normal = 0, // 0000 TransformMode_OnlyTranslation = 7, // 0111 diff --git a/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h b/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h index 424125ebb..d5014894d 100644 --- a/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TranslateTimeline.h @@ -38,8 +38,7 @@ namespace Spine { - class TranslateTimeline : public CurveTimeline - { + class TranslateTimeline : public CurveTimeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/Triangulator.h b/spine-cpp/spine-cpp/include/spine/Triangulator.h index b8da189fc..8e43659ea 100644 --- a/spine-cpp/spine-cpp/include/spine/Triangulator.h +++ b/spine-cpp/spine-cpp/include/spine/Triangulator.h @@ -36,8 +36,7 @@ namespace Spine { - class Triangulator - { + class Triangulator { public: Vector& triangulate(Vector& vertices); diff --git a/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h b/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h index 266eba418..0f8aee052 100644 --- a/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h +++ b/spine-cpp/spine-cpp/include/spine/TwoColorTimeline.h @@ -35,8 +35,7 @@ namespace Spine { - class TwoColorTimeline : public CurveTimeline - { + class TwoColorTimeline : public CurveTimeline { friend class SkeletonBinary; friend class SkeletonJson; diff --git a/spine-cpp/spine-cpp/include/spine/Updatable.h b/spine-cpp/spine-cpp/include/spine/Updatable.h index fac634191..8bf9df75c 100644 --- a/spine-cpp/spine-cpp/include/spine/Updatable.h +++ b/spine-cpp/spine-cpp/include/spine/Updatable.h @@ -35,8 +35,7 @@ namespace Spine { - class Updatable - { + class Updatable { RTTI_DECL; public: diff --git a/spine-cpp/spine-cpp/include/spine/Vector.h b/spine-cpp/spine-cpp/include/spine/Vector.h index 7c7dc3394..5272122b5 100644 --- a/spine-cpp/spine-cpp/include/spine/Vector.h +++ b/spine-cpp/spine-cpp/include/spine/Vector.h @@ -40,30 +40,23 @@ namespace Spine { template - 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(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& lhs, Vector& rhs) - { - if (lhs.size() != rhs.size()) - { + friend bool operator==(Vector& lhs, Vector& rhs) { + if (lhs.size() != rhs.size()) { return false; } - for (int i = 0, n = static_cast(lhs.size()); i < n; ++i) - { - if (lhs[i] != rhs[i]) - { + for (int i = 0, n = static_cast(lhs.size()); i < n; ++i) { + if (lhs[i] != rhs[i]) { return false; } } @@ -228,8 +191,7 @@ namespace Spine return true; } - friend bool operator!=(Vector& lhs, Vector& rhs) - { + friend bool operator!=(Vector& lhs, Vector& 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(); } }; diff --git a/spine-cpp/spine-cpp/include/spine/VertexAttachment.h b/spine-cpp/spine-cpp/include/spine/VertexAttachment.h index 56c057674..a60031dd8 100644 --- a/spine-cpp/spine-cpp/include/spine/VertexAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/VertexAttachment.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/Vertices.h b/spine-cpp/spine-cpp/include/spine/Vertices.h index bd14260f1..f8ba613b7 100644 --- a/spine-cpp/spine-cpp/include/spine/Vertices.h +++ b/spine-cpp/spine-cpp/include/spine/Vertices.h @@ -35,8 +35,7 @@ namespace Spine { - class Vertices - { + class Vertices { public: Vector _bones; Vector _vertices; diff --git a/spine-cpp/spine-cpp/src/spine/Animation.cpp b/spine-cpp/spine-cpp/src/spine/Animation.cpp index d494c4154..b18b502f2 100644 --- a/spine-cpp/spine-cpp/src/spine/Animation.cpp +++ b/spine-cpp/spine-cpp/src/spine/Animation.cpp @@ -44,82 +44,65 @@ namespace Spine Animation::Animation(std::string name, Vector& 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* pEvents, float alpha, MixPose pose, MixDirection direction) - { - if (loop && _duration != 0) - { + void Animation::apply(Skeleton& skeleton, float lastTime, float time, bool loop, Vector* 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(_timelines.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_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 Animation::getTimelines() - { + Vector Animation::getTimelines() { return _timelines; } - void Animation::setTimelines(Vector inValue) - { + void Animation::setTimelines(Vector 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& values, float target, int step) - { + int Animation::binarySearch(Vector& values, float target, int step) { int low = 0; int size = static_cast(values.size()); int high = size / step - 2; - if (high == 0) - { + if (high == 0) { return step; } int current = (int)(static_cast(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& values, float target) - { + int Animation::binarySearch(Vector& values, float target) { int low = 0; int size = static_cast(values.size()); int high = size - 2; - if (high == 0) - { + if (high == 0) { return 1; } int current = (int)(static_cast(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& values, float target, int step) - { - for (int i = 0, last = static_cast(values.size()) - step; i <= last; i += step) - { - if (values[i] > target) - { + int Animation::linearSearch(Vector& values, float target, int step) { + for (int i = 0, last = static_cast(values.size()) - step; i <= last; i += step) { + if (values[i] > target) { return i; } } diff --git a/spine-cpp/spine-cpp/src/spine/AnimationState.cpp b/spine-cpp/spine-cpp/src/spine/AnimationState.cpp index 48e2485c9..9650053b6 100644 --- a/spine-cpp/spine-cpp/src/spine/AnimationState.cpp +++ b/spine-cpp/spine-cpp/src/spine/AnimationState.cpp @@ -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& mixingToArray, Vector& propertyIDs) - { - if (to != NULL) - { + TrackEntry* TrackEntry::setTimelineData(TrackEntry* to, Vector& mixingToArray, Vector& 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& timelines = _animation->_timelines; - for (int i = 0, n = static_cast(timelines.size()); i < n; ++i) - { - if (timelines[i]->getPropertyId() == inId) - { + for (int i = 0, n = static_cast(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& trackEntryPool) - { + EventQueue* EventQueue::newEventQueue(AnimationState& state, Pool& 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& trackEntryPool) : _state(state), _trackEntryPool(trackEntryPool), _drainDisabled(false) - { + EventQueue::EventQueue(AnimationState& state, Pool& 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(_tracks.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_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(_tracks.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_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(current._animation->_timelines.size()); Vector& 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& 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& 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(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(_tracks.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_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(_tracks.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_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 AnimationState::getTracks() - { + Vector 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 timelines; static Animation ret(std::string(""), timelines, 0); return &ret; } - void AnimationState::applyRotateTimeline(RotateTimeline* rotateTimeline, Skeleton& skeleton, float time, float alpha, MixPose pose, Vector& timelinesRotation, int i, bool firstFrame) - { - if (firstFrame) - { + void AnimationState::applyRotateTimeline(RotateTimeline* rotateTimeline, Skeleton& skeleton, float time, float alpha, MixPose pose, Vector& 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 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& 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(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(_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(_tracks.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_tracks.size()); i < n; ++i) { TrackEntry* entry = _tracks[i]; - if (entry != NULL) - { + if (entry != NULL) { entry->setTimelineData(NULL, _mixingTo, _propertyIDs); } } diff --git a/spine-cpp/spine-cpp/src/spine/AnimationStateData.cpp b/spine-cpp/spine-cpp/src/spine/AnimationStateData.cpp index 00dc79ced..3f1e9e173 100644 --- a/spine-cpp/spine-cpp/src/spine/AnimationStateData.cpp +++ b/spine-cpp/spine-cpp/src/spine/AnimationStateData.cpp @@ -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::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); } diff --git a/spine-cpp/spine-cpp/src/spine/Atlas.cpp b/spine-cpp/spine-cpp/src/spine/Atlas.cpp index 478bb0aec..5c41d1918 100644 --- a/spine-cpp/spine-cpp/src/spine/Atlas.cpp +++ b/spine-cpp/spine-cpp/src/spine/Atlas.cpp @@ -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); } } diff --git a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp index 3cbc3c5c8..4509a071c 100644 --- a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp +++ b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp @@ -44,13 +44,11 @@ namespace Spine { RTTI_IMPL(AtlasAttachmentLoader, AttachmentLoader); - AtlasAttachmentLoader::AtlasAttachmentLoader(Vector& inAtlasArray) : AttachmentLoader(), _atlasArray(inAtlasArray) - { + AtlasAttachmentLoader::AtlasAttachmentLoader(Vector& 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; } } diff --git a/spine-cpp/spine-cpp/src/spine/Attachment.cpp b/spine-cpp/spine-cpp/src/spine/Attachment.cpp index 74a734f27..b977277a0 100644 --- a/spine-cpp/spine-cpp/src/spine/Attachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/Attachment.cpp @@ -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; } } diff --git a/spine-cpp/spine-cpp/src/spine/AttachmentLoader.cpp b/spine-cpp/spine-cpp/src/spine/AttachmentLoader.cpp index 93e848ab7..b6ab71714 100644 --- a/spine-cpp/spine-cpp/src/spine/AttachmentLoader.cpp +++ b/spine-cpp/spine-cpp/src/spine/AttachmentLoader.cpp @@ -42,13 +42,11 @@ namespace Spine { RTTI_IMPL_NOPARENT(AttachmentLoader); - AttachmentLoader::AttachmentLoader() - { + AttachmentLoader::AttachmentLoader() { // Empty } - AttachmentLoader::~AttachmentLoader() - { + AttachmentLoader::~AttachmentLoader() { // Empty } } diff --git a/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp b/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp index 1fb01c0dc..f6a68c62c 100644 --- a/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/AttachmentTimeline.cpp @@ -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* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void AttachmentTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* 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(_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& AttachmentTimeline::getFrames() - { + Vector& AttachmentTimeline::getFrames() { return _frames; } - void AttachmentTimeline::setFrames(Vector& inValue) - { + void AttachmentTimeline::setFrames(Vector& inValue) { _frames = inValue; } - Vector AttachmentTimeline::getAttachmentNames() - { + Vector AttachmentTimeline::getAttachmentNames() { return _attachmentNames; } - void AttachmentTimeline::setAttachmentNames(Vector& inValue) - { + void AttachmentTimeline::setAttachmentNames(Vector& inValue) { _attachmentNames = inValue; } - int AttachmentTimeline::getFrameCount() - { + int AttachmentTimeline::getFrameCount() { return static_cast(_frames.size()); } } diff --git a/spine-cpp/spine-cpp/src/spine/Bone.cpp b/spine-cpp/spine-cpp/src/spine/Bone.cpp index 14ffbf850..1b4db4928 100644 --- a/spine-cpp/spine-cpp/src/spine/Bone.cpp +++ b/spine-cpp/spine-cpp/src/spine/Bone.cpp @@ -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::getChildren() - { + Vector& 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; diff --git a/spine-cpp/spine-cpp/src/spine/BoneData.cpp b/spine-cpp/spine-cpp/src/spine/BoneData.cpp index ce90ef754..2e5ac3fbd 100644 --- a/spine-cpp/spine-cpp/src/spine/BoneData.cpp +++ b/spine-cpp/spine-cpp/src/spine/BoneData.cpp @@ -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; } } diff --git a/spine-cpp/spine-cpp/src/spine/BoundingBoxAttachment.cpp b/spine-cpp/spine-cpp/src/spine/BoundingBoxAttachment.cpp index ffa7f7355..02d662233 100644 --- a/spine-cpp/spine-cpp/src/spine/BoundingBoxAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/BoundingBoxAttachment.cpp @@ -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 } } diff --git a/spine-cpp/spine-cpp/src/spine/ClippingAttachment.cpp b/spine-cpp/spine-cpp/src/spine/ClippingAttachment.cpp index 1f2f9dd2b..3c8efc3b5 100644 --- a/spine-cpp/spine-cpp/src/spine/ClippingAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/ClippingAttachment.cpp @@ -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; } } diff --git a/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp index 80d41a1c7..4c6bea7a4 100644 --- a/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ColorTimeline.cpp @@ -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* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void ColorTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* 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(_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& ColorTimeline::getFrames() - { + Vector& ColorTimeline::getFrames() { return _frames; } - void ColorTimeline::setFrames(Vector& inValue) - { + void ColorTimeline::setFrames(Vector& inValue) { _frames = inValue; } } diff --git a/spine-cpp/spine-cpp/src/spine/Constraint.cpp b/spine-cpp/spine-cpp/src/spine/Constraint.cpp index bad9d1a0b..85618372b 100644 --- a/spine-cpp/spine-cpp/src/spine/Constraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/Constraint.cpp @@ -34,13 +34,11 @@ namespace Spine { RTTI_IMPL(Constraint, Updatable); - Constraint::Constraint() - { + Constraint::Constraint() { // Empty } - Constraint::~Constraint() - { + Constraint::~Constraint() { // Empty } } diff --git a/spine-cpp/spine-cpp/src/spine/CurveTimeline.cpp b/spine-cpp/spine-cpp/src/spine/CurveTimeline.cpp index 6f66e760f..88b25e375 100644 --- a/spine-cpp/spine-cpp/src/spine/CurveTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/CurveTimeline.cpp @@ -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(_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]; } } diff --git a/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp b/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp index 8f9333220..bede7342e 100644 --- a/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp @@ -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 vec; _frameVertices.push_back(vec); } } - void DeformTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void DeformTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* 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(slot._attachment); - if (!vertexAttachment->applyDeform(_attachment)) - { + if (!vertexAttachment->applyDeform(_attachment)) { return; } Vector& vertices = slot._attachmentVertices; - if (vertices.size() == 0) - { + if (vertices.size() == 0) { alpha = 1; } int vertexCount = static_cast(_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& 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& 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& 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& 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& vertices) - { + void DeformTimeline::setFrame(int frameIndex, float time, Vector& 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& DeformTimeline::getFrames() - { + Vector& DeformTimeline::getFrames() { return _frames; } - void DeformTimeline::setFrames(Vector& inValue) - { + void DeformTimeline::setFrames(Vector& inValue) { _frames = inValue; } - Vector< Vector >& DeformTimeline::getVertices() - { + Vector< Vector >& DeformTimeline::getVertices() { return _frameVertices; } - void DeformTimeline::setVertices(Vector< Vector >& inValue) - { + void DeformTimeline::setVertices(Vector< Vector >& inValue) { _frameVertices = inValue; } - VertexAttachment* DeformTimeline::getAttachment() - { + VertexAttachment* DeformTimeline::getAttachment() { return _attachment; } - void DeformTimeline::setAttachment(VertexAttachment* inValue) - { + void DeformTimeline::setAttachment(VertexAttachment* inValue) { _attachment = inValue; } } diff --git a/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp b/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp index 2d9577cf3..83ad3259a 100644 --- a/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/DrawOrderTimeline.cpp @@ -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 vec; _drawOrders.push_back(vec); } } - void DrawOrderTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void DrawOrderTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) { Vector& drawOrder = skeleton._drawOrder; Vector& 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(slots.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(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(slots.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(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(_frames.size()) - 1; } - else - { + else { frame = Animation::binarySearch(_frames, time) - 1; } Vector& drawOrderToSetupIndex = _drawOrders[frame]; - if (drawOrderToSetupIndex.size() == 0) - { + if (drawOrderToSetupIndex.size() == 0) { drawOrder.clear(); - for (int i = 0, n = static_cast(slots.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(slots.size()); i < n; ++i) { drawOrder.push_back(slots[i]); } } - else - { - for (int i = 0, n = static_cast(drawOrderToSetupIndex.size()); i < n; ++i) - { + else { + for (int i = 0, n = static_cast(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& drawOrder) - { + void DrawOrderTimeline::setFrame(int frameIndex, float time, Vector& drawOrder) { _frames[frameIndex] = time; _drawOrders[frameIndex] = drawOrder; } - Vector& DrawOrderTimeline::getFrames() - { + Vector& DrawOrderTimeline::getFrames() { return _frames; } - void DrawOrderTimeline::setFrames(Vector& inValue) - { + void DrawOrderTimeline::setFrames(Vector& inValue) { _frames = inValue; } - Vector< Vector >& DrawOrderTimeline::getDrawOrders() - { + Vector< Vector >& DrawOrderTimeline::getDrawOrders() { return _drawOrders; } - void DrawOrderTimeline::setDrawOrders(Vector< Vector >& inValue) - { + void DrawOrderTimeline::setDrawOrders(Vector< Vector >& inValue) { _drawOrders = inValue; } - int DrawOrderTimeline::getFrameCount() - { + int DrawOrderTimeline::getFrameCount() { return static_cast(_frames.size()); } } diff --git a/spine-cpp/spine-cpp/src/spine/Event.cpp b/spine-cpp/spine-cpp/src/spine/Event.cpp index 09ba067b2..1bce25bdb 100644 --- a/spine-cpp/spine-cpp/src/spine/Event.cpp +++ b/spine-cpp/spine-cpp/src/spine/Event.cpp @@ -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; } } diff --git a/spine-cpp/spine-cpp/src/spine/EventData.cpp b/spine-cpp/spine-cpp/src/spine/EventData.cpp index e0eccf90b..e6c95dc0b 100644 --- a/spine-cpp/spine-cpp/src/spine/EventData.cpp +++ b/spine-cpp/spine-cpp/src/spine/EventData.cpp @@ -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; } } diff --git a/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp b/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp index 56722d579..66505930b 100644 --- a/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/EventTimeline.cpp @@ -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* pEvents, float alpha, MixPose pose, MixDirection direction) - { - if (pEvents == NULL) - { + void EventTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) { + if (pEvents == NULL) { return; } Vector& events = *pEvents; - if (events.size() == 0) - { + if (events.size() == 0) { return; } int frameCount = static_cast(_frames.size()); - if (lastTime > time) - { + if (lastTime > time) { // Fire events after last time for looped animations. apply(skeleton, lastTime, std::numeric_limits::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; } diff --git a/spine-cpp/spine-cpp/src/spine/Extension.cpp b/spine-cpp/spine-cpp/src/spine/Extension.cpp index 5cfe0b3ab..09ce5543d 100644 --- a/spine-cpp/spine-cpp/src/spine/Extension.cpp +++ b/spine-cpp/spine-cpp/src/spine/Extension.cpp @@ -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 } } diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp index 0359854d8..933eb9c62 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp @@ -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& IkConstraint::getBones() - { + Vector& 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; } } diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraintData.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraintData.cpp index 13378993f..c06fcdccc 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraintData.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraintData.cpp @@ -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& IkConstraintData::getBones() - { + Vector& 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; } } diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp index ed747c7a4..e0bb67c07 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraintTimeline.cpp @@ -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* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void IkConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* 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; diff --git a/spine-cpp/spine-cpp/src/spine/Json.cpp b/spine-cpp/spine-cpp/src/spine/Json.cpp index bc6dfdd97..6e967e552 100644 --- a/spine-cpp/spine-cpp/src/spine/Json.cpp +++ b/spine-cpp/spine-cpp/src/spine/Json.cpp @@ -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(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 */ } } diff --git a/spine-cpp/spine-cpp/src/spine/LinkedMesh.cpp b/spine-cpp/spine-cpp/src/spine/LinkedMesh.cpp index a1c25db11..c4e5cdb6e 100644 --- a/spine-cpp/spine-cpp/src/spine/LinkedMesh.cpp +++ b/spine-cpp/spine-cpp/src/spine/LinkedMesh.cpp @@ -38,8 +38,7 @@ namespace Spine _mesh(mesh), _skin(skin), _slotIndex(slotIndex), - _parent(parent) - { + _parent(parent) { // Empty } } diff --git a/spine-cpp/spine-cpp/src/spine/MathUtil.cpp b/spine-cpp/spine-cpp/src/spine/MathUtil.cpp index ddcde2f1e..ac1b25b69 100644 --- a/spine-cpp/spine-cpp/src/spine/MathUtil.cpp +++ b/spine-cpp/spine-cpp/src/spine/MathUtil.cpp @@ -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); } diff --git a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp index 7d507b8f5..2c6c459a4 100644 --- a/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/MeshAttachment.cpp @@ -56,273 +56,218 @@ namespace Spine _a(1), _hullLength(0), _inheritDeform(false), - _regionRotate(false) - { + _regionRotate(false) { // Empty } - void MeshAttachment::updateUVs() - { + void MeshAttachment::updateUVs() { float u = _regionU, v = _regionV, width = _regionU2 - _regionU, height = _regionV2 - _regionV; - if (_uvs.size() != _regionUVs.size()) - { + if (_uvs.size() != _regionUVs.size()) { _uvs.reserve(_regionUVs.size()); _uvs.setSize(_regionUVs.size()); } - if (_regionRotate) - { - for (size_t i = 0, n = _uvs.size(); i < n; i += 2) - { + if (_regionRotate) { + for (size_t i = 0, n = _uvs.size(); i < n; i += 2) { _uvs[i] = u + _regionUVs[i + 1] * width; _uvs[i + 1] = v + height - _regionUVs[i] * height; } } - else - { - for (size_t i = 0, n = _uvs.size(); i < n; i += 2) - { + else { + for (size_t i = 0, n = _uvs.size(); i < n; i += 2) { _uvs[i] = u + _regionUVs[i] * width; _uvs[i + 1] = v + _regionUVs[i + 1] * height; } } } - bool MeshAttachment::applyDeform(VertexAttachment* sourceAttachment) - { + bool MeshAttachment::applyDeform(VertexAttachment* sourceAttachment) { return this == sourceAttachment || (_inheritDeform && _parentMesh == sourceAttachment); } - int MeshAttachment::getHullLength() - { + int MeshAttachment::getHullLength() { return _hullLength; } - void MeshAttachment::setHullLength(float inValue) - { + void MeshAttachment::setHullLength(float inValue) { _hullLength = inValue; } - Vector& MeshAttachment::getRegionUVs() - { + Vector& MeshAttachment::getRegionUVs() { return _regionUVs; } - void MeshAttachment::setRegionUVs(Vector& inValue) - { + void MeshAttachment::setRegionUVs(Vector& inValue) { _regionUVs = inValue; } - Vector& MeshAttachment::getUVs() - { + Vector& MeshAttachment::getUVs() { return _uvs; } - void MeshAttachment::setUVs(Vector& inValue) - { + void MeshAttachment::setUVs(Vector& inValue) { _uvs = inValue; } - Vector& MeshAttachment::getTriangles() - { + Vector& MeshAttachment::getTriangles() { return _triangles; } - void MeshAttachment::setTriangles(Vector& inValue) - { + void MeshAttachment::setTriangles(Vector& inValue) { _triangles = inValue; } - float MeshAttachment::getR() - { + float MeshAttachment::getR() { return _r; } - void MeshAttachment::setR(float inValue) - { + void MeshAttachment::setR(float inValue) { _r = inValue; } - float MeshAttachment::getG() - { + float MeshAttachment::getG() { return _g; } - void MeshAttachment::setG(float inValue) - { + void MeshAttachment::setG(float inValue) { _g = inValue; } - float MeshAttachment::getB() - { + float MeshAttachment::getB() { return _b; } - void MeshAttachment::setB(float inValue) - { + void MeshAttachment::setB(float inValue) { _b = inValue; } - float MeshAttachment::getA() - { + float MeshAttachment::getA() { return _a; } - void MeshAttachment::setA(float inValue) - { + void MeshAttachment::setA(float inValue) { _a = inValue; } - std::string MeshAttachment::getPath() - { + std::string MeshAttachment::getPath() { return _path; } - void MeshAttachment::setPath(std::string inValue) - { + void MeshAttachment::setPath(std::string inValue) { _path = inValue; } - void* MeshAttachment::getRendererObject() - { + void* MeshAttachment::getRendererObject() { return _rendererObject; } - void MeshAttachment::setRendererObject(void* inValue) - { + void MeshAttachment::setRendererObject(void* inValue) { _rendererObject = inValue; } - float MeshAttachment::getRegionU() - { + float MeshAttachment::getRegionU() { return _regionU; } - void MeshAttachment::setRegionU(float inValue) - { + void MeshAttachment::setRegionU(float inValue) { _regionU = inValue; } - float MeshAttachment::getRegionV() - { + float MeshAttachment::getRegionV() { return _regionV; } - void MeshAttachment::setRegionV(float inValue) - { + void MeshAttachment::setRegionV(float inValue) { _regionV = inValue; } - float MeshAttachment::getRegionU2() - { + float MeshAttachment::getRegionU2() { return _regionU2; } - void MeshAttachment::setRegionU2(float inValue) - { + void MeshAttachment::setRegionU2(float inValue) { _regionU2 = inValue; } - float MeshAttachment::getRegionV2() - { + float MeshAttachment::getRegionV2() { return _regionV2; } - void MeshAttachment::setRegionV2(float inValue) - { + void MeshAttachment::setRegionV2(float inValue) { _regionV2 = inValue; } - bool MeshAttachment::getRegionRotate() - { + bool MeshAttachment::getRegionRotate() { return _regionRotate; } - void MeshAttachment::setRegionRotate(float inValue) - { + void MeshAttachment::setRegionRotate(float inValue) { _regionRotate = inValue; } - float MeshAttachment::getRegionOffsetX() - { + float MeshAttachment::getRegionOffsetX() { return _regionOffsetX; } - void MeshAttachment::setRegionOffsetX(float inValue) - { + void MeshAttachment::setRegionOffsetX(float inValue) { _regionOffsetX = inValue; } - float MeshAttachment::getRegionOffsetY() - { + float MeshAttachment::getRegionOffsetY() { return _regionOffsetY; } - void MeshAttachment::setRegionOffsetY(float inValue) - { + void MeshAttachment::setRegionOffsetY(float inValue) { _regionOffsetY = inValue; } - float MeshAttachment::getRegionWidth() - { + float MeshAttachment::getRegionWidth() { return _regionWidth; } - void MeshAttachment::setRegionWidth(float inValue) - { + void MeshAttachment::setRegionWidth(float inValue) { _regionWidth = inValue; } - float MeshAttachment::getRegionHeight() - { + float MeshAttachment::getRegionHeight() { return _regionHeight; } - void MeshAttachment::setRegionHeight(float inValue) - { + void MeshAttachment::setRegionHeight(float inValue) { _regionHeight = inValue; } - float MeshAttachment::getRegionOriginalWidth() - { + float MeshAttachment::getRegionOriginalWidth() { return _regionOriginalWidth; } - void MeshAttachment::setRegionOriginalWidth(float inValue) - { + void MeshAttachment::setRegionOriginalWidth(float inValue) { _regionOriginalWidth = inValue; } - float MeshAttachment::getRegionOriginalHeight() - { + float MeshAttachment::getRegionOriginalHeight() { return _regionOriginalHeight; } - void MeshAttachment::setRegionOriginalHeight(float inValue) - { + void MeshAttachment::setRegionOriginalHeight(float inValue) { _regionOriginalHeight = inValue; } - bool MeshAttachment::getInheritDeform() - { + bool MeshAttachment::getInheritDeform() { return _inheritDeform; } - void MeshAttachment::setInheritDeform(bool inValue) - { + void MeshAttachment::setInheritDeform(bool inValue) { _inheritDeform = inValue; } - MeshAttachment* MeshAttachment::getParentMesh() - { + MeshAttachment* MeshAttachment::getParentMesh() { return _parentMesh; } - void MeshAttachment::setParentMesh(MeshAttachment* inValue) - { + void MeshAttachment::setParentMesh(MeshAttachment* inValue) { _parentMesh = inValue; - if (inValue != NULL) - { + if (inValue != NULL) { _bones = inValue->_bones; _vertices = inValue->_vertices; _worldVerticesLength = inValue->_worldVerticesLength; @@ -335,33 +280,27 @@ namespace Spine } } - Vector& MeshAttachment::getEdges() - { + Vector& MeshAttachment::getEdges() { return _edges; } - void MeshAttachment::setEdges(Vector& inValue) - { + void MeshAttachment::setEdges(Vector& inValue) { _edges = inValue; } - float MeshAttachment::getWidth() - { + float MeshAttachment::getWidth() { return _width; } - void MeshAttachment::setWidth(float inValue) - { + void MeshAttachment::setWidth(float inValue) { _width = inValue; } - float MeshAttachment::getHeight() - { + float MeshAttachment::getHeight() { return _height; } - void MeshAttachment::setHeight(float inValue) - { + void MeshAttachment::setHeight(float inValue) { _height = inValue; } } diff --git a/spine-cpp/spine-cpp/src/spine/PathAttachment.cpp b/spine-cpp/spine-cpp/src/spine/PathAttachment.cpp index 28a06940b..866405ee2 100644 --- a/spine-cpp/spine-cpp/src/spine/PathAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathAttachment.cpp @@ -34,38 +34,31 @@ namespace Spine { RTTI_IMPL(PathAttachment, VertexAttachment); - PathAttachment::PathAttachment(std::string name) : VertexAttachment(name), _closed(false), _constantSpeed(false) - { + PathAttachment::PathAttachment(std::string name) : VertexAttachment(name), _closed(false), _constantSpeed(false) { // Empty } - Vector& PathAttachment::getLengths() - { + Vector& PathAttachment::getLengths() { return _lengths; } - void PathAttachment::setLengths(Vector inValue) - { + void PathAttachment::setLengths(Vector inValue) { _lengths = inValue; } - bool PathAttachment::isClosed() - { + bool PathAttachment::isClosed() { return _closed; } - void PathAttachment::setClosed(bool inValue) - { + void PathAttachment::setClosed(bool inValue) { _closed = inValue; } - bool PathAttachment::isConstantSpeed() - { + bool PathAttachment::isConstantSpeed() { return _constantSpeed; } - void PathAttachment::setConstantSpeed(bool inValue) - { + void PathAttachment::setConstantSpeed(bool inValue) { _constantSpeed = inValue; } } diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp index ad06cd4fd..686886290 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp @@ -58,11 +58,9 @@ namespace Spine _position(data.getPosition()), _spacing(data.getSpacing()), _rotateMix(data.getRotateMix()), - _translateMix(data.getTranslateMix()) - { + _translateMix(data.getTranslateMix()) { _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())); @@ -72,16 +70,13 @@ namespace Spine _segments.setSize(10); } - void PathConstraint::apply() - { + void PathConstraint::apply() { update(); } - void PathConstraint::update() - { + void PathConstraint::update() { Attachment* baseAttachment = _target->getAttachment(); - if (baseAttachment == NULL || !baseAttachment->getRTTI().derivesFrom(PathAttachment::rtti)) - { + if (baseAttachment == NULL || !baseAttachment->getRTTI().derivesFrom(PathAttachment::rtti)) { return; } @@ -91,8 +86,7 @@ namespace Spine float translateMix = _translateMix; bool translate = translateMix > 0; bool rotate = rotateMix > 0; - if (!translate && !rotate) - { + if (!translate && !rotate) { return; } @@ -106,34 +100,27 @@ namespace Spine _spaces.reserve(spacesCount); _spaces.setSize(spacesCount); float spacing = _spacing; - if (scale || lengthSpacing) - { - if (scale) - { + if (scale || lengthSpacing) { + if (scale) { _lengths.reserve(boneCount); _lengths.setSize(boneCount); } - for (int i = 0, n = spacesCount - 1; i < n;) - { + for (int i = 0, n = spacesCount - 1; i < n;) { Bone* boneP = _bones[i]; Bone& bone = *boneP; float setupLength = bone._data.getLength(); - if (setupLength < PathConstraint::EPSILON) - { - if (scale) - { + if (setupLength < PathConstraint::EPSILON) { + if (scale) { _lengths[i] = 0; } _spaces[++i] = 0; } - else - { + else { float x = setupLength * bone._a; float y = setupLength * bone._c; float length = (float)sqrt(x * x + y * y); - if (scale) - { + if (scale) { _lengths[i] = length; } @@ -141,10 +128,8 @@ namespace Spine } } } - else - { - for (int i = 1; i < spacesCount; ++i) - { + else { + for (int i = 1; i < spacesCount; ++i) { _spaces[i] = spacing; } } @@ -154,19 +139,16 @@ namespace Spine float boneY = positions[1]; float offsetRotation = data.getOffsetRotation(); bool tip; - if (offsetRotation == 0) - { + if (offsetRotation == 0) { tip = rotateMode == RotateMode_Chain; } - else - { + else { tip = false; Bone p = _target->getBone(); offsetRotation *= p.getA() * p.getD() - p.getB() * p.getC() > 0 ? DegRad : -DegRad; } - for (int i = 0, p = 3; i < boneCount; i++, p += 3) - { + for (int i = 0, p = 3; i < boneCount; i++, p += 3) { Bone* boneP = _bones[i]; Bone& bone = *boneP; bone._worldX += (boneX - bone._worldX) * translateMix; @@ -175,11 +157,9 @@ namespace Spine float y = positions[p + 1]; float dx = x - boneX; float dy = y - boneY; - if (scale) - { + if (scale) { float length = _lengths[i]; - if (length >= PathConstraint::EPSILON) - { + if (length >= PathConstraint::EPSILON) { float s = ((float)sqrt(dx * dx + dy * dy) / length - 1) * rotateMix + 1; bone._a *= s; bone._c *= s; @@ -189,43 +169,35 @@ namespace Spine boneX = x; boneY = y; - if (rotate) - { + if (rotate) { float a = bone._a, b = bone._b, c = bone._c, d = bone._d, r, cos, sin; - if (tangents) - { + if (tangents) { r = positions[p - 1]; } - else if (_spaces[i + 1] < PathConstraint::EPSILON) - { + else if (_spaces[i + 1] < PathConstraint::EPSILON) { r = positions[p + 2]; } - else - { + else { r = MathUtil::atan2(dy, dx); } r -= MathUtil::atan2(c, a); - if (tip) - { + if (tip) { cos = MathUtil::cos(r); sin = MathUtil::sin(r); float length = bone._data.getLength(); boneX += (length * (cos * a - sin * c) - dx) * rotateMix; boneY += (length * (sin * a + cos * c) - dy) * rotateMix; } - else - { + else { r += offsetRotation; } - if (r > SPINE_PI) - { + if (r > SPINE_PI) { r -= SPINE_PI_2; } - else if (r < -SPINE_PI) - { + else if (r < -SPINE_PI) { r += SPINE_PI_2; } @@ -242,73 +214,59 @@ namespace Spine } } - int PathConstraint::getOrder() - { + int PathConstraint::getOrder() { return _data.getOrder(); } - float PathConstraint::getPosition() - { + float PathConstraint::getPosition() { return _position; } - void PathConstraint::setPosition(float inValue) - { + void PathConstraint::setPosition(float inValue) { _position = inValue; } - float PathConstraint::getSpacing() - { + float PathConstraint::getSpacing() { return _spacing; } - void PathConstraint::setSpacing(float inValue) - { + void PathConstraint::setSpacing(float inValue) { _spacing = inValue; } - float PathConstraint::getRotateMix() - { + float PathConstraint::getRotateMix() { return _rotateMix; } - void PathConstraint::setRotateMix(float inValue) - { + void PathConstraint::setRotateMix(float inValue) { _rotateMix = inValue; } - float PathConstraint::getTranslateMix() - { + float PathConstraint::getTranslateMix() { return _translateMix; } - void PathConstraint::setTranslateMix(float inValue) - { + void PathConstraint::setTranslateMix(float inValue) { _translateMix = inValue; } - Vector& PathConstraint::getBones() - { + Vector& PathConstraint::getBones() { return _bones; } - Slot* PathConstraint::getTarget() - { + Slot* PathConstraint::getTarget() { return _target; } - void PathConstraint::setTarget(Slot* inValue) - { + void PathConstraint::setTarget(Slot* inValue) { _target = inValue; } - PathConstraintData& PathConstraint::getData() - { + PathConstraintData& PathConstraint::getData() { return _data; } - Vector PathConstraint::computeWorldPositions(PathAttachment& path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing) - { + Vector PathConstraint::computeWorldPositions(PathAttachment& path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing) { Slot& target = *_target; float position = _position; _positions.reserve(spacesCount * 3 + 2); @@ -319,46 +277,37 @@ namespace Spine int prevCurve = NONE; float pathLength; - if (!path.isConstantSpeed()) - { + if (!path.isConstantSpeed()) { Vector& lengths = path.getLengths(); curveCount -= closed ? 1 : 2; pathLength = lengths[curveCount]; - if (percentPosition) - { + if (percentPosition) { position *= pathLength; } - if (percentSpacing) - { - for (int i = 0; i < spacesCount; ++i) - { + if (percentSpacing) { + for (int i = 0; i < spacesCount; ++i) { _spaces[i] *= pathLength; } } _world.reserve(8); _world.setSize(8); - for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) - { + for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) { float space = _spaces[i]; position += space; float p = position; - if (closed) - { + if (closed) { p = fmod(p, pathLength); - if (p < 0) - { + if (p < 0) { p += pathLength; } curve = 0; } - else if (p < 0) - { - if (prevCurve != BEFORE) - { + else if (p < 0) { + if (prevCurve != BEFORE) { prevCurve = BEFORE; path.computeWorldVertices(target, 2, 4, _world, 0); } @@ -367,10 +316,8 @@ namespace Spine continue; } - else if (p > pathLength) - { - if (prevCurve != AFTER) - { + else if (p > pathLength) { + if (prevCurve != AFTER) { prevCurve = AFTER; path.computeWorldVertices(target, verticesLength - 6, 4, _world, 0); } @@ -381,36 +328,29 @@ namespace Spine } // Determine curve containing position. - for (;; curve++) - { + for (;; curve++) { float length = lengths[curve]; - if (p > length) - { + if (p > length) { continue; } - if (curve == 0) - { + if (curve == 0) { p /= length; } - else - { + else { float prev = lengths[curve - 1]; p = (p - prev) / (length - prev); } break; } - if (curve != prevCurve) - { + if (curve != prevCurve) { prevCurve = curve; - if (closed && curve == curveCount) - { + if (closed && curve == curveCount) { path.computeWorldVertices(target, verticesLength - 4, 4, _world, 0); path.computeWorldVertices(target, 0, 4, _world, 4); } - else - { + else { path.computeWorldVertices(target, curve * 6 + 2, 8, _world, 0); } } @@ -421,8 +361,7 @@ namespace Spine } // World vertices. - if (closed) - { + if (closed) { verticesLength += 2; _world.reserve(verticesLength); _world.setSize(verticesLength); @@ -431,8 +370,7 @@ namespace Spine _world[verticesLength - 2] = _world[0]; _world[verticesLength - 1] = _world[1]; } - else - { + else { curveCount--; verticesLength -= 4; _world.reserve(verticesLength); @@ -446,8 +384,7 @@ namespace Spine pathLength = 0; float x1 = _world[0], y1 = _world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0; float tmpx, tmpy, dddfx, dddfy, ddfx, ddfy, dfx, dfy; - for (int i = 0, w = 2; i < curveCount; i++, w += 6) - { + for (int i = 0, w = 2; i < curveCount; i++, w += 6) { cx1 = _world[w]; cy1 = _world[w + 1]; cx2 = _world[w + 2]; @@ -479,62 +416,50 @@ namespace Spine y1 = y2; } - if (percentPosition) - { + if (percentPosition) { position *= pathLength; } - if (percentSpacing) - { - for (int i = 0; i < spacesCount; ++i) - { + if (percentSpacing) { + for (int i = 0; i < spacesCount; ++i) { _spaces[i] *= pathLength; } } float curveLength = 0; - for (int i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) - { + for (int i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) { float space = _spaces[i]; position += space; float p = position; - if (closed) - { + if (closed) { p = fmod(p, pathLength); - if (p < 0) - { + if (p < 0) { p += pathLength; } curve = 0; } - else if (p < 0) - { + else if (p < 0) { addBeforePosition(p, _world, 0, _positions, o); continue; } - else if (p > pathLength) - { + else if (p > pathLength) { addAfterPosition(p - pathLength, _world, verticesLength - 4, _positions, o); continue; } // Determine curve containing position. - for (;; curve++) - { + for (;; curve++) { float length = _curves[curve]; - if (p > length) - { + if (p > length) { continue; } - if (curve == 0) - { + if (curve == 0) { p /= length; } - else - { + else { float prev = _curves[curve - 1]; p = (p - prev) / (length - prev); } @@ -542,8 +467,7 @@ namespace Spine } // Curve segment lengths. - if (curve != prevCurve) - { + if (curve != prevCurve) { prevCurve = curve; int ii = curve * 6; x1 = _world[ii]; @@ -564,8 +488,7 @@ namespace Spine dfy = (cy1 - y1) * 0.3f + tmpy + dddfy * 0.16666667f; curveLength = (float)sqrt(dfx * dfx + dfy * dfy); _segments[0] = curveLength; - for (ii = 1; ii < 8; ii++) - { + for (ii = 1; ii < 8; ii++) { dfx += ddfx; dfy += ddfy; ddfx += dddfx; @@ -586,20 +509,16 @@ namespace Spine // Weight by segment length. p *= curveLength; - for (;; segment++) - { + for (;; segment++) { float length = _segments[segment]; - if (p > length) - { + if (p > length) { continue; } - if (segment == 0) - { + if (segment == 0) { p /= length; } - else - { + else { float prev = _segments[segment - 1]; p = segment + (p - prev) / (length - prev); } @@ -611,8 +530,7 @@ namespace Spine return _positions; } - void PathConstraint::addBeforePosition(float p, Vector& temp, int i, Vector& output, int o) - { + void PathConstraint::addBeforePosition(float p, Vector& temp, int i, Vector& output, int o) { float x1 = temp[i]; float y1 = temp[i + 1]; float dx = temp[i + 2] - x1; @@ -624,8 +542,7 @@ namespace Spine output[o + 2] = r; } - void PathConstraint::addAfterPosition(float p, Vector& temp, int i, Vector& output, int o) - { + void PathConstraint::addAfterPosition(float p, Vector& temp, int i, Vector& output, int o) { float x1 = temp[i + 2]; float y1 = temp[i + 3]; float dx = x1 - temp[i]; @@ -636,10 +553,8 @@ namespace Spine output[o + 2] = r; } - void PathConstraint::addCurvePosition(float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, Vector& output, int o, bool tangents) - { - if (p < EPSILON || isnan(p)) - { + void PathConstraint::addCurvePosition(float p, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, Vector& output, int o, bool tangents) { + if (p < EPSILON || isnan(p)) { p = EPSILON; } @@ -648,8 +563,7 @@ namespace Spine float x = x1 * uuu + cx1 * uut3 + cx2 * utt3 + x2 * ttt, y = y1 * uuu + cy1 * uut3 + cy2 * utt3 + y2 * ttt; output[o] = x; output[o + 1] = y; - if (tangents) - { + if (tangents) { output[o + 2] = (float)atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt)); } } diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintData.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintData.cpp index f3ef57df7..380719527 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintData.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintData.cpp @@ -48,118 +48,95 @@ namespace Spine _position(0), _spacing(0), _rotateMix(0), - _translateMix(0) - { + _translateMix(0) { assert(_name.length() > 0); } - const std::string& PathConstraintData::getName() - { + const std::string& PathConstraintData::getName() { return _name; } - int PathConstraintData::getOrder() - { + int PathConstraintData::getOrder() { return _order; } - void PathConstraintData::setOrder(int inValue) - { + void PathConstraintData::setOrder(int inValue) { _order = inValue; } - Vector& PathConstraintData::getBones() - { + Vector& PathConstraintData::getBones() { return _bones; } - SlotData* PathConstraintData::getTarget() - { + SlotData* PathConstraintData::getTarget() { return _target; } - void PathConstraintData::setTarget(SlotData* inValue) - { + void PathConstraintData::setTarget(SlotData* inValue) { _target = inValue; } - PositionMode PathConstraintData::getPositionMode() - { + PositionMode PathConstraintData::getPositionMode() { return _positionMode; } - void PathConstraintData::setPositionMode(PositionMode inValue) - { + void PathConstraintData::setPositionMode(PositionMode inValue) { _positionMode = inValue; } - SpacingMode PathConstraintData::getSpacingMode() - { + SpacingMode PathConstraintData::getSpacingMode() { return _spacingMode; } - void PathConstraintData::setSpacingMode(SpacingMode inValue) - { + void PathConstraintData::setSpacingMode(SpacingMode inValue) { _spacingMode = inValue; } - RotateMode PathConstraintData::getRotateMode() - { + RotateMode PathConstraintData::getRotateMode() { return _rotateMode; } - void PathConstraintData::setRotateMode(RotateMode inValue) - { + void PathConstraintData::setRotateMode(RotateMode inValue) { _rotateMode = inValue; } - float PathConstraintData::getOffsetRotation() - { + float PathConstraintData::getOffsetRotation() { return _offsetRotation; } - void PathConstraintData::setOffsetRotation(float inValue) - { + void PathConstraintData::setOffsetRotation(float inValue) { _offsetRotation = inValue; } - float PathConstraintData::getPosition() - { + float PathConstraintData::getPosition() { return _position; } - void PathConstraintData::setPosition(float inValue) - { + void PathConstraintData::setPosition(float inValue) { _position = inValue; } - float PathConstraintData::getSpacing() - { + float PathConstraintData::getSpacing() { return _spacing; } - void PathConstraintData::setSpacing(float inValue) - { + void PathConstraintData::setSpacing(float inValue) { _spacing = inValue; } - float PathConstraintData::getRotateMix() - { + float PathConstraintData::getRotateMix() { return _rotateMix; } - void PathConstraintData::setRotateMix(float inValue) - { + void PathConstraintData::setRotateMix(float inValue) { _rotateMix = inValue; } - float PathConstraintData::getTranslateMix() - { + float PathConstraintData::getTranslateMix() { return _translateMix; } - void PathConstraintData::setTranslateMix(float inValue) - { + void PathConstraintData::setTranslateMix(float inValue) { _translateMix = inValue; } } diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp index e3ad99d41..606d71b9e 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintMixTimeline.cpp @@ -51,20 +51,16 @@ namespace Spine const int PathConstraintMixTimeline::ROTATE = 1; const int PathConstraintMixTimeline::TRANSLATE = 2; - PathConstraintMixTimeline::PathConstraintMixTimeline(int frameCount) : CurveTimeline(frameCount), _pathConstraintIndex(0) - { + PathConstraintMixTimeline::PathConstraintMixTimeline(int frameCount) : CurveTimeline(frameCount), _pathConstraintIndex(0) { _frames.reserve(frameCount * ENTRIES); _frames.setSize(frameCount * ENTRIES); } - void PathConstraintMixTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void PathConstraintMixTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) { PathConstraint* constraintP = skeleton._pathConstraints[_pathConstraintIndex]; PathConstraint& constraint = *constraintP; - if (time < _frames[0]) - { - switch (pose) - { + if (time < _frames[0]) { + switch (pose) { case MixPose_Setup: constraint._rotateMix = constraint._data._rotateMix; constraint._translateMix = constraint._data._translateMix; @@ -80,14 +76,12 @@ namespace Spine } float rotate, translate; - if (time >= _frames[_frames.size() - ENTRIES]) - { + if (time >= _frames[_frames.size() - ENTRIES]) { // Time is after last frame. rotate = _frames[_frames.size() + PREV_ROTATE]; translate = _frames[_frames.size() + PREV_TRANSLATE]; } - else - { + else { // Interpolate between the previous frame and the current frame. int frame = Animation::binarySearch(_frames, time, ENTRIES); rotate = _frames[frame + PREV_ROTATE]; @@ -100,25 +94,21 @@ namespace Spine translate += (_frames[frame + TRANSLATE] - translate) * percent; } - if (pose == MixPose_Setup) - { + if (pose == MixPose_Setup) { constraint._rotateMix = constraint._data._rotateMix + (rotate - constraint._data._rotateMix) * alpha; constraint._translateMix = constraint._data._translateMix + (translate - constraint._data._translateMix) * alpha; } - else - { + else { constraint._rotateMix += (rotate - constraint._rotateMix) * alpha; constraint._translateMix += (translate - constraint._translateMix) * alpha; } } - int PathConstraintMixTimeline::getPropertyId() - { + int PathConstraintMixTimeline::getPropertyId() { return ((int)TimelineType_PathConstraintMix << 24) + _pathConstraintIndex; } - void PathConstraintMixTimeline::setFrame(int frameIndex, float time, float rotateMix, float translateMix) - { + void PathConstraintMixTimeline::setFrame(int frameIndex, float time, float rotateMix, float translateMix) { frameIndex *= ENTRIES; _frames[frameIndex] = time; _frames[frameIndex + ROTATE] = rotateMix; diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp index c60c2941f..ba0a63555 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintPositionTimeline.cpp @@ -49,20 +49,16 @@ namespace Spine const int PathConstraintPositionTimeline::PREV_VALUE = -1; const int PathConstraintPositionTimeline::VALUE = 1; - PathConstraintPositionTimeline::PathConstraintPositionTimeline(int frameCount) : CurveTimeline(frameCount), _pathConstraintIndex(0) - { + PathConstraintPositionTimeline::PathConstraintPositionTimeline(int frameCount) : CurveTimeline(frameCount), _pathConstraintIndex(0) { _frames.reserve(frameCount * ENTRIES); _frames.setSize(frameCount * ENTRIES); } - void PathConstraintPositionTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void PathConstraintPositionTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) { PathConstraint* constraintP = skeleton._pathConstraints[_pathConstraintIndex]; PathConstraint& constraint = *constraintP; - if (time < _frames[0]) - { - switch (pose) - { + if (time < _frames[0]) { + switch (pose) { case MixPose_Setup: constraint._position = constraint._data._position; return; @@ -76,12 +72,11 @@ namespace Spine } float position; - if (time >= _frames[_frames.size() - ENTRIES]) // Time is after last frame. - { + if (time >= _frames[_frames.size() - ENTRIES]) { + // Time is after last frame. position = _frames[_frames.size() + PREV_VALUE]; } - else - { + else { // Interpolate between the previous frame and the current frame. int frame = Animation::binarySearch(_frames, time, ENTRIES); position = _frames[frame + PREV_VALUE]; @@ -91,23 +86,19 @@ namespace Spine position += (_frames[frame + VALUE] - position) * percent; } - if (pose == MixPose_Setup) - { + if (pose == MixPose_Setup) { constraint._position = constraint._data._position + (position - constraint._data._position) * alpha; } - else - { + else { constraint._position += (position - constraint._position) * alpha; } } - int PathConstraintPositionTimeline::getPropertyId() - { + int PathConstraintPositionTimeline::getPropertyId() { return ((int)TimelineType_PathConstraintPosition << 24) + _pathConstraintIndex; } - void PathConstraintPositionTimeline::setFrame(int frameIndex, float time, float value) - { + void PathConstraintPositionTimeline::setFrame(int frameIndex, float time, float value) { frameIndex *= ENTRIES; _frames[frameIndex] = time; _frames[frameIndex + VALUE] = value; diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp index 44d132596..f029a9e4a 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraintSpacingTimeline.cpp @@ -44,19 +44,15 @@ namespace Spine { RTTI_IMPL(PathConstraintSpacingTimeline, PathConstraintPositionTimeline); - PathConstraintSpacingTimeline::PathConstraintSpacingTimeline(int frameCount) : PathConstraintPositionTimeline(frameCount) - { + PathConstraintSpacingTimeline::PathConstraintSpacingTimeline(int frameCount) : PathConstraintPositionTimeline(frameCount) { // Empty } - void PathConstraintSpacingTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void PathConstraintSpacingTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) { PathConstraint* constraintP = skeleton._pathConstraints[_pathConstraintIndex]; PathConstraint& constraint = *constraintP; - if (time < _frames[0]) - { - switch (pose) - { + if (time < _frames[0]) { + switch (pose) { case MixPose_Setup: constraint._spacing = constraint._data._spacing; return; @@ -70,12 +66,11 @@ namespace Spine } float spacing; - if (time >= _frames[_frames.size() - ENTRIES]) // Time is after last frame. - { + if (time >= _frames[_frames.size() - ENTRIES]) { + // Time is after last frame. spacing = _frames[_frames.size() + PREV_VALUE]; } - else - { + else { // Interpolate between the previous frame and the current frame. int frame = Animation::binarySearch(_frames, time, ENTRIES); spacing = _frames[frame + PREV_VALUE]; @@ -86,18 +81,15 @@ namespace Spine spacing += (_frames[frame + VALUE] - spacing) * percent; } - if (pose == MixPose_Setup) - { + if (pose == MixPose_Setup) { constraint._spacing = constraint._data._spacing + (spacing - constraint._data._spacing) * alpha; } - else - { + else { constraint._spacing += (spacing - constraint._spacing) * alpha; } } - int PathConstraintSpacingTimeline::getPropertyId() - { + int PathConstraintSpacingTimeline::getPropertyId() { return ((int)TimelineType_PathConstraintSpacing << 24) + _pathConstraintIndex; } } diff --git a/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp b/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp index 693eb837c..09c32d43c 100644 --- a/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/PointAttachment.cpp @@ -38,18 +38,15 @@ namespace Spine { RTTI_IMPL(PointAttachment, Attachment); - PointAttachment::PointAttachment(std::string name) : Attachment(name), _x(0), _y(0), _rotation(0) - { + PointAttachment::PointAttachment(std::string name) : Attachment(name), _x(0), _y(0), _rotation(0) { // Empty } - void PointAttachment::computeWorldPosition(Bone& bone, float& ox, float& oy) - { + void PointAttachment::computeWorldPosition(Bone& bone, float& ox, float& oy) { bone.localToWorld(_x, _y, ox, oy); } - float PointAttachment::computeWorldRotation(Bone& bone) - { + float PointAttachment::computeWorldRotation(Bone& bone) { float cos = MathUtil::cosDeg(_rotation); float sin = MathUtil::sinDeg(_rotation); float ix = cos * bone._a + sin * bone._b; @@ -58,33 +55,27 @@ namespace Spine return MathUtil::atan2(iy, ix) * RadDeg; } - float PointAttachment::getX() - { + float PointAttachment::getX() { return _x; } - void PointAttachment::setX(float inValue) - { + void PointAttachment::setX(float inValue) { _x = inValue; } - float PointAttachment::getY() - { + float PointAttachment::getY() { return _y; } - void PointAttachment::setY(float inValue) - { + void PointAttachment::setY(float inValue) { _y = inValue; } - float PointAttachment::getRotation() - { + float PointAttachment::getRotation() { return _rotation; } - void PointAttachment::setRotation(float inValue) - { + void PointAttachment::setRotation(float inValue) { _rotation = inValue; } } diff --git a/spine-cpp/spine-cpp/src/spine/RTTI.cpp b/spine-cpp/spine-cpp/src/spine/RTTI.cpp index 9d271f894..8a734a898 100644 --- a/spine-cpp/spine-cpp/src/spine/RTTI.cpp +++ b/spine-cpp/spine-cpp/src/spine/RTTI.cpp @@ -32,34 +32,27 @@ namespace Spine { - RTTI::RTTI(const std::string& className) : m_className(className), m_pBaseRTTI(NULL) - { + RTTI::RTTI(const std::string& className) : m_className(className), m_pBaseRTTI(NULL) { // Empty } - RTTI::RTTI(const std::string& className, const RTTI& baseRTTI) : m_className(className), m_pBaseRTTI(&baseRTTI) - { + RTTI::RTTI(const std::string& className, const RTTI& baseRTTI) : m_className(className), m_pBaseRTTI(&baseRTTI) { // Empty } - const std::string& RTTI::getClassName() const - { + const std::string& RTTI::getClassName() const { return m_className; } - bool RTTI::isExactly(const RTTI& rtti) const - { + bool RTTI::isExactly(const RTTI& rtti) const { return (this == &rtti); } - bool RTTI::derivesFrom(const RTTI& rtti) const - { + bool RTTI::derivesFrom(const RTTI& rtti) const { const RTTI * pCompare = this; - while (pCompare) - { - if (pCompare == &rtti) - { + while (pCompare) { + if (pCompare == &rtti) { return true; } diff --git a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp index 98d9a9f7d..b2e38ba79 100644 --- a/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/RegionAttachment.cpp @@ -72,8 +72,7 @@ namespace Spine _r(0), _g(0), _b(0), - _a(0) - { + _a(0) { _offset.reserve(NUM_UVS); _uvs.reserve(NUM_UVS); @@ -81,8 +80,7 @@ namespace Spine _uvs.setSize(NUM_UVS); } - void RegionAttachment::updateOffset() - { + void RegionAttachment::updateOffset() { float regionScaleX = _width / _regionOriginalWidth * _scaleX; float regionScaleY = _height / _regionOriginalHeight * _scaleY; float localX = -_width / 2 * _scaleX + _regionOffsetX * regionScaleX; @@ -110,10 +108,8 @@ namespace Spine _offset[BRY] = localYCos + localX2Sin; } - void RegionAttachment::setUVs(float u, float v, float u2, float v2, bool rotate) - { - if (rotate) - { + void RegionAttachment::setUVs(float u, float v, float u2, float v2, bool rotate) { + if (rotate) { _uvs[URX] = u; _uvs[URY] = v2; _uvs[BRX] = u; @@ -123,8 +119,7 @@ namespace Spine _uvs[ULX] = u2; _uvs[ULY] = v2; } - else - { + else { _uvs[ULX] = u; _uvs[ULY] = v2; _uvs[URX] = u; @@ -136,8 +131,7 @@ namespace Spine } } - void RegionAttachment::computeWorldVertices(Bone& bone, Vector& worldVertices, int offset, int stride) - { + void RegionAttachment::computeWorldVertices(Bone& bone, Vector& worldVertices, int offset, int stride) { assert(worldVertices.size() >= (offset + 8)); float bwx = bone._worldX, bwy = bone._worldY; @@ -168,203 +162,163 @@ namespace Spine worldVertices[offset + 1] = offsetX * c + offsetY * d + bwy; } - float RegionAttachment::getX() - { + float RegionAttachment::getX() { return _x; } - void RegionAttachment::setX(float inValue) - { + void RegionAttachment::setX(float inValue) { _x = inValue; } - float RegionAttachment::getY() - { + float RegionAttachment::getY() { return _y; } - void RegionAttachment::setY(float inValue) - { + void RegionAttachment::setY(float inValue) { _y = inValue; } - float RegionAttachment::getRotation() - { + float RegionAttachment::getRotation() { return _rotation; } - void RegionAttachment::setRotation(float inValue) - { + void RegionAttachment::setRotation(float inValue) { _rotation = inValue; } - float RegionAttachment::getScaleX() - { + float RegionAttachment::getScaleX() { return _scaleX; } - void RegionAttachment::setScaleX(float inValue) - { + void RegionAttachment::setScaleX(float inValue) { _scaleX = inValue; } - float RegionAttachment::getScaleY() - { + float RegionAttachment::getScaleY() { return _scaleY; } - void RegionAttachment::setScaleY(float inValue) - { + void RegionAttachment::setScaleY(float inValue) { _scaleY = inValue; } - float RegionAttachment::getWidth() - { + float RegionAttachment::getWidth() { return _width; } - void RegionAttachment::setWidth(float inValue) - { + void RegionAttachment::setWidth(float inValue) { _width = inValue; } - float RegionAttachment::getHeight() - { + float RegionAttachment::getHeight() { return _height; } - void RegionAttachment::setHeight(float inValue) - { + void RegionAttachment::setHeight(float inValue) { _height = inValue; } - float RegionAttachment::getR() - { + float RegionAttachment::getR() { return _r; } - void RegionAttachment::setR(float inValue) - { + void RegionAttachment::setR(float inValue) { _r = inValue; } - float RegionAttachment::getG() - { + float RegionAttachment::getG() { return _g; } - void RegionAttachment::setG(float inValue) - { + void RegionAttachment::setG(float inValue) { _g = inValue; } - float RegionAttachment::getB() - { + float RegionAttachment::getB() { return _b; } - void RegionAttachment::setB(float inValue) - { + void RegionAttachment::setB(float inValue) { _b = inValue; } - float RegionAttachment::getA() - { + float RegionAttachment::getA() { return _a; } - void RegionAttachment::setA(float inValue) - { + void RegionAttachment::setA(float inValue) { _a = inValue; } - std::string RegionAttachment::getPath() - { + std::string RegionAttachment::getPath() { return _path; } - void RegionAttachment::setPath(std::string inValue) - { + void RegionAttachment::setPath(std::string inValue) { _path = inValue; } - void* RegionAttachment::getRendererObject() - { + void* RegionAttachment::getRendererObject() { return _rendererObject; } - void RegionAttachment::setRendererObject(void* inValue) - { + void RegionAttachment::setRendererObject(void* inValue) { _rendererObject = inValue; } - float RegionAttachment::getRegionOffsetX() - { + float RegionAttachment::getRegionOffsetX() { return _regionOffsetX; } - void RegionAttachment::setRegionOffsetX(float inValue) - { + void RegionAttachment::setRegionOffsetX(float inValue) { _regionOffsetX = inValue; } - float RegionAttachment::getRegionOffsetY() - { + float RegionAttachment::getRegionOffsetY() { return _regionOffsetY; } - void RegionAttachment::setRegionOffsetY(float inValue) - { + void RegionAttachment::setRegionOffsetY(float inValue) { _regionOffsetY = inValue; } - float RegionAttachment::getRegionWidth() - { + float RegionAttachment::getRegionWidth() { return _regionWidth; } - void RegionAttachment::setRegionWidth(float inValue) - { + void RegionAttachment::setRegionWidth(float inValue) { _regionWidth = inValue; } - float RegionAttachment::getRegionHeight() - { + float RegionAttachment::getRegionHeight() { return _regionHeight; } - void RegionAttachment::setRegionHeight(float inValue) - { + void RegionAttachment::setRegionHeight(float inValue) { _regionHeight = inValue; } - float RegionAttachment::getRegionOriginalWidth() - { + float RegionAttachment::getRegionOriginalWidth() { return _regionOriginalWidth; } - void RegionAttachment::setRegionOriginalWidth(float inValue) - { + void RegionAttachment::setRegionOriginalWidth(float inValue) { _regionOriginalWidth = inValue; } - float RegionAttachment::getRegionOriginalHeight() - { + float RegionAttachment::getRegionOriginalHeight() { return _regionOriginalHeight; } - void RegionAttachment::setRegionOriginalHeight(float inValue) - { + void RegionAttachment::setRegionOriginalHeight(float inValue) { _regionOriginalHeight = inValue; } - Vector& RegionAttachment::getOffset() - { + Vector& RegionAttachment::getOffset() { return _offset; } - Vector& RegionAttachment::getUVs() - { + Vector& RegionAttachment::getUVs() { return _uvs; } } diff --git a/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp b/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp index 16ceee334..b17a406f7 100644 --- a/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/RotateTimeline.cpp @@ -42,34 +42,27 @@ namespace Spine { RTTI_IMPL(RotateTimeline, CurveTimeline); - RotateTimeline::RotateTimeline(int frameCount) : CurveTimeline(frameCount), _boneIndex(0) - { + RotateTimeline::RotateTimeline(int frameCount) : CurveTimeline(frameCount), _boneIndex(0) { _frames.reserve(frameCount << 1); _frames.setSize(frameCount << 1); } - void RotateTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void RotateTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) { Bone* bone = skeleton.getBones()[_boneIndex]; - if (time < _frames[0]) - { - switch (pose) - { - case MixPose_Setup: - { + if (time < _frames[0]) { + switch (pose) { + case MixPose_Setup: { bone->_rotation = bone->_data._rotation; break; } - case MixPose_Current: - { + case MixPose_Current: { float rr = bone->_data._rotation - bone->_rotation; rr -= (16384 - (int)(16384.499999999996 - rr / 360)) * 360; bone->_rotation += rr * alpha; break; } - case MixPose_CurrentLayered: - { + case MixPose_CurrentLayered: { // TODO? break; } @@ -78,15 +71,12 @@ namespace Spine return; } - 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) { bone->_rotation = bone->_data._rotation + _frames[_frames.size() + PREV_ROTATION] * alpha; } - else - { + else { float rr = bone->_data._rotation + _frames[_frames.size() + PREV_ROTATION] - bone->_rotation; rr -= (16384 - (int)(16384.499999999996 - rr / 360)) * 360; // Wrap within -180 and 180. bone->_rotation += rr * alpha; @@ -105,48 +95,40 @@ namespace Spine r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; r = prevRotation + r * percent; - if (pose == MixPose_Setup) - { + if (pose == MixPose_Setup) { r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; bone->_rotation = bone->_data._rotation + r * alpha; } - else - { + else { r = bone->_data._rotation + r - bone->_rotation; r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; bone->_rotation += r * alpha; } } - int RotateTimeline::getPropertyId() - { + int RotateTimeline::getPropertyId() { return ((int)TimelineType_Rotate << 24) + _boneIndex; } - void RotateTimeline::setFrame(int frameIndex, float time, float degrees) - { + void RotateTimeline::setFrame(int frameIndex, float time, float degrees) { frameIndex <<= 1; _frames[frameIndex] = time; _frames[frameIndex + ROTATION] = degrees; } - int RotateTimeline::getBoneIndex() - { + int RotateTimeline::getBoneIndex() { return _boneIndex; } - void RotateTimeline::setBoneIndex(int inValue) - { + void RotateTimeline::setBoneIndex(int inValue) { _boneIndex = inValue; } - Vector& RotateTimeline::getFrames() - { + Vector& RotateTimeline::getFrames() { return _frames; } - void RotateTimeline::setFrames(Vector inValue) - { + void RotateTimeline::setFrames(Vector inValue) { _frames = inValue; } } diff --git a/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp index 9c110a064..fe5ccc6fc 100644 --- a/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ScaleTimeline.cpp @@ -44,20 +44,16 @@ namespace Spine { RTTI_IMPL(ScaleTimeline, TranslateTimeline); - ScaleTimeline::ScaleTimeline(int frameCount) : TranslateTimeline(frameCount) - { + ScaleTimeline::ScaleTimeline(int frameCount) : TranslateTimeline(frameCount) { // Empty } - void ScaleTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void ScaleTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) { Bone* boneP = skeleton._bones[_boneIndex]; Bone& bone = *boneP; - if (time < _frames[0]) - { - switch (pose) - { + if (time < _frames[0]) { + switch (pose) { case MixPose_Setup: bone._scaleX = bone._data._scaleX; bone._scaleY = bone._data._scaleY; @@ -73,14 +69,12 @@ namespace Spine } float x, y; - if (time >= _frames[_frames.size() - ENTRIES]) - { + if (time >= _frames[_frames.size() - ENTRIES]) { // Time is after last frame. x = _frames[_frames.size() + PREV_X] * bone._data._scaleX; y = _frames[_frames.size() + PREV_Y] * bone._data._scaleY; } - else - { + else { // Interpolate between the previous frame and the current frame. int frame = Animation::binarySearch(_frames, time, ENTRIES); x = _frames[frame + PREV_X]; @@ -93,32 +87,26 @@ namespace Spine y = (y + (_frames[frame + Y] - y) * percent) * bone._data._scaleY; } - if (alpha == 1) - { + if (alpha == 1) { bone._scaleX = x; bone._scaleY = y; } - else - { + else { float bx, by; - if (pose == MixPose_Setup) - { + if (pose == MixPose_Setup) { bx = bone._data._scaleX; by = bone._data._scaleY; } - else - { + else { bx = bone._scaleX; by = bone._scaleY; } // Mixing out uses sign of setup or current pose, else use sign of key. - if (direction == MixDirection_Out) - { + if (direction == MixDirection_Out) { x = (x >= 0 ? x : -x) * (bx >= 0 ? 1 : -1); y = (y >= 0 ? y : -y) * (by >= 0 ? 1 : -1); } - else - { + else { bx = (bx >= 0 ? bx : -bx) * (x >= 0 ? 1 : -1); by = (by >= 0 ? by : -by) * (y >= 0 ? 1 : -1); } @@ -127,8 +115,7 @@ namespace Spine } } - int ScaleTimeline::getPropertyId() - { + int ScaleTimeline::getPropertyId() { return ((int)TimelineType_Scale << 24) + _boneIndex; } } diff --git a/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp b/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp index 2089e7de4..3cf98aefc 100644 --- a/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/ShearTimeline.cpp @@ -44,20 +44,16 @@ namespace Spine { RTTI_IMPL(ShearTimeline, TranslateTimeline); - ShearTimeline::ShearTimeline(int frameCount) : TranslateTimeline(frameCount) - { + ShearTimeline::ShearTimeline(int frameCount) : TranslateTimeline(frameCount) { // Empty } - void ShearTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void ShearTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) { Bone* boneP = skeleton._bones[_boneIndex]; Bone& bone = *boneP; - if (time < _frames[0]) - { - switch (pose) - { + if (time < _frames[0]) { + switch (pose) { case MixPose_Setup: bone._shearX = bone._data._shearX; bone._shearY = bone._data._shearY; @@ -73,14 +69,12 @@ namespace Spine } float x, y; - if (time >= _frames[_frames.size() - ENTRIES]) - { + if (time >= _frames[_frames.size() - ENTRIES]) { // Time is after last frame. x = _frames[_frames.size() + PREV_X]; y = _frames[_frames.size() + PREV_Y]; } - else - { + else { // Interpolate between the previous frame and the current frame. int frame = Animation::binarySearch(_frames, time, ENTRIES); x = _frames[frame + PREV_X]; @@ -93,20 +87,17 @@ namespace Spine y = y + (_frames[frame + Y] - y) * percent; } - if (pose == MixPose_Setup) - { + if (pose == MixPose_Setup) { bone._shearX = bone._data._shearX + x * alpha; bone._shearY = bone._data._shearY + y * alpha; } - else - { + else { bone._shearX += (bone._data._shearX + x - bone._shearX) * alpha; bone._shearY += (bone._data._shearY + y - bone._shearY) * alpha; } } - int ShearTimeline::getPropertyId() - { + int ShearTimeline::getPropertyId() { return ((int)TimelineType_Shear << 24) + _boneIndex; } } diff --git a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp index c7a3e63d9..1913be075 100644 --- a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp @@ -65,21 +65,17 @@ namespace Spine _flipX(false), _flipY(false), _x(0), - _y(0) - { + _y(0) { _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* data = (*i); Bone* bone; - if (data->getParent() == NULL) - { + if (data->getParent() == NULL) { bone = NEW(Bone); new (bone) Bone(*data, *this, NULL); } - else - { + else { Bone* parent = _bones[data->getParent()->getIndex()]; bone = NEW(Bone); new (bone) Bone(*data, *this, parent); @@ -91,8 +87,7 @@ namespace Spine _slots.reserve(_data.getSlots().size()); _drawOrder.reserve(_data.getSlots().size()); - for (SlotData** i = _data.getSlots().begin(); i != _data.getSlots().end(); ++i) - { + for (SlotData** i = _data.getSlots().begin(); i != _data.getSlots().end(); ++i) { SlotData* data = (*i); Bone* bone = _bones[data->getBoneData().getIndex()]; @@ -104,8 +99,7 @@ namespace Spine } _ikConstraints.reserve(_data.getIkConstraints().size()); - for (IkConstraintData** i = _data.getIkConstraints().begin(); i != _data.getIkConstraints().end(); ++i) - { + for (IkConstraintData** i = _data.getIkConstraints().begin(); i != _data.getIkConstraints().end(); ++i) { IkConstraintData* data = (*i); IkConstraint* constraint = NEW(IkConstraint); @@ -115,8 +109,7 @@ namespace Spine } _transformConstraints.reserve(_data.getTransformConstraints().size()); - for (TransformConstraintData** i = _data.getTransformConstraints().begin(); i != _data.getTransformConstraints().end(); ++i) - { + for (TransformConstraintData** i = _data.getTransformConstraints().begin(); i != _data.getTransformConstraints().end(); ++i) { TransformConstraintData* data = (*i); TransformConstraint* constraint = NEW(TransformConstraint); @@ -126,8 +119,7 @@ namespace Spine } _pathConstraints.reserve(_data.getPathConstraints().size()); - for (PathConstraintData** i = _data.getPathConstraints().begin(); i != _data.getPathConstraints().end(); ++i) - { + for (PathConstraintData** i = _data.getPathConstraints().begin(); i != _data.getPathConstraints().end(); ++i) { PathConstraintData* data = (*i); PathConstraint* constraint = NEW(PathConstraint); @@ -140,8 +132,7 @@ namespace Spine updateWorldTransform(); } - Skeleton::~Skeleton() - { + Skeleton::~Skeleton() { ContainerUtil::cleanUpVectorOfPointers(_bones); ContainerUtil::cleanUpVectorOfPointers(_slots); ContainerUtil::cleanUpVectorOfPointers(_ikConstraints); @@ -149,13 +140,11 @@ namespace Spine ContainerUtil::cleanUpVectorOfPointers(_pathConstraints); } - void Skeleton::updateCache() - { + void Skeleton::updateCache() { _updateCache.clear(); _updateCacheReset.clear(); - for (int i = 0, n = static_cast(_bones.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_bones.size()); i < n; ++i) { _bones[i]->_sorted = false; } @@ -165,15 +154,12 @@ namespace Spine int constraintCount = ikCount + transformCount + pathCount; - for (int i = 0; i < constraintCount; ++i) - { + for (int i = 0; i < constraintCount; ++i) { bool gotoNextConstraintCount = false; - for (int ii = 0; ii < ikCount; ++ii) - { + for (int ii = 0; ii < ikCount; ++ii) { IkConstraint* constraint = _ikConstraints[ii]; - if (constraint->getData().getOrder() == i) - { + if (constraint->getData().getOrder() == i) { sortIkConstraint(constraint); gotoNextConstraintCount = true; @@ -181,16 +167,13 @@ namespace Spine } } - if (gotoNextConstraintCount) - { + if (gotoNextConstraintCount) { break; } - for (int ii = 0; ii < transformCount; ++ii) - { + for (int ii = 0; ii < transformCount; ++ii) { TransformConstraint* constraint = _transformConstraints[ii]; - if (constraint->getData().getOrder() == i) - { + if (constraint->getData().getOrder() == i) { sortTransformConstraint(constraint); gotoNextConstraintCount = true; @@ -198,16 +181,13 @@ namespace Spine } } - if (gotoNextConstraintCount) - { + if (gotoNextConstraintCount) { break; } - for (int ii = 0; ii < pathCount; ++ii) - { + for (int ii = 0; ii < pathCount; ++ii) { PathConstraint* constraint = _pathConstraints[ii]; - if (constraint->getData().getOrder() == i) - { + if (constraint->getData().getOrder() == i) { sortPathConstraint(constraint); gotoNextConstraintCount = true; @@ -215,22 +195,18 @@ namespace Spine } } - if (gotoNextConstraintCount) - { + if (gotoNextConstraintCount) { break; } } - for (int i = 0, n = static_cast(_bones.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_bones.size()); i < n; ++i) { sortBone(_bones[i]); } } - void Skeleton::updateWorldTransform() - { - for (int i = 0, n = static_cast(_updateCacheReset.size()); i < n; ++i) - { + void Skeleton::updateWorldTransform() { + for (int i = 0, n = static_cast(_updateCacheReset.size()); i < n; ++i) { Bone* boneP = _updateCacheReset[i]; Bone& bone = *boneP; bone._ax = bone._x; @@ -243,27 +219,22 @@ namespace Spine bone._appliedValid = true; } - for (int i = 0, n = static_cast(_updateCache.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_updateCache.size()); i < n; ++i) { _updateCache[i]->update(); } } - void Skeleton::setToSetupPose() - { + void Skeleton::setToSetupPose() { setBonesToSetupPose(); setSlotsToSetupPose(); } - void Skeleton::setBonesToSetupPose() - { - for (int i = 0, n = static_cast(_bones.size()); i < n; ++i) - { + void Skeleton::setBonesToSetupPose() { + for (int i = 0, n = static_cast(_bones.size()); i < n; ++i) { _bones[i]->setToSetupPose(); } - for (int i = 0, n = static_cast(_ikConstraints.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_ikConstraints.size()); i < n; ++i) { IkConstraint* constraintP = _ikConstraints[i]; IkConstraint& constraint = *constraintP; @@ -271,8 +242,7 @@ namespace Spine constraint._mix = constraint._data._mix; } - for (int i = 0, n = static_cast(_transformConstraints.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_transformConstraints.size()); i < n; ++i) { TransformConstraint* constraintP = _transformConstraints[i]; TransformConstraint& constraint = *constraintP; TransformConstraintData& constraintData = constraint._data; @@ -283,8 +253,7 @@ namespace Spine constraint._shearMix = constraintData._shearMix; } - for (int i = 0, n = static_cast(_pathConstraints.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_pathConstraints.size()); i < n; ++i) { PathConstraint* constraintP = _pathConstraints[i]; PathConstraint& constraint = *constraintP; PathConstraintData& constraintData = constraint._data; @@ -296,42 +265,34 @@ namespace Spine } } - void Skeleton::setSlotsToSetupPose() - { + void Skeleton::setSlotsToSetupPose() { _drawOrder.clear(); - for (int i = 0, n = static_cast(_slots.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_slots.size()); i < n; ++i) { _drawOrder.push_back(_slots[i]); } - for (int i = 0, n = static_cast(_slots.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_slots.size()); i < n; ++i) { _slots[i]->setToSetupPose(); } } - Bone* Skeleton::findBone(std::string boneName) - { + Bone* Skeleton::findBone(std::string boneName) { return ContainerUtil::findWithDataName(_bones, boneName); } - int Skeleton::findBoneIndex(std::string boneName) - { + int Skeleton::findBoneIndex(std::string boneName) { return ContainerUtil::findIndexWithDataName(_bones, boneName); } - Slot* Skeleton::findSlot(std::string slotName) - { + Slot* Skeleton::findSlot(std::string slotName) { return ContainerUtil::findWithDataName(_slots, slotName); } - int Skeleton::findSlotIndex(std::string slotName) - { + int Skeleton::findSlotIndex(std::string slotName) { return ContainerUtil::findIndexWithDataName(_slots, slotName); } - void Skeleton::setSkin(std::string skinName) - { + void Skeleton::setSkin(std::string skinName) { Skin* foundSkin = _data.findSkin(skinName); assert(foundSkin != NULL); @@ -339,27 +300,20 @@ namespace Spine setSkin(foundSkin); } - void Skeleton::setSkin(Skin* newSkin) - { - if (newSkin != NULL) - { - if (_skin != NULL) - { + void Skeleton::setSkin(Skin* newSkin) { + if (newSkin != NULL) { + if (_skin != NULL) { Skeleton& thisRef = *this; newSkin->attachAll(thisRef, *_skin); } - else - { - for (int i = 0, n = static_cast(_slots.size()); i < n; ++i) - { + else { + for (int i = 0, n = static_cast(_slots.size()); i < n; ++i) { Slot* slotP = _slots[i]; Slot& slot = *slotP; std::string name = slot._data.getAttachmentName(); - if (name.length() > 0) - { + if (name.length() > 0) { Attachment* attachment = newSkin->getAttachment(i, name); - if (attachment != NULL) - { + if (attachment != NULL) { slot.setAttachment(attachment); } } @@ -370,20 +324,16 @@ namespace Spine _skin = newSkin; } - Attachment* Skeleton::getAttachment(std::string slotName, std::string attachmentName) - { + Attachment* Skeleton::getAttachment(std::string slotName, std::string attachmentName) { return getAttachment(_data.findSlotIndex(slotName), attachmentName); } - Attachment* Skeleton::getAttachment(int slotIndex, std::string attachmentName) - { + Attachment* Skeleton::getAttachment(int slotIndex, std::string attachmentName) { assert(attachmentName.length() > 0); - if (_skin != NULL) - { + if (_skin != NULL) { Attachment* attachment = _skin->getAttachment(slotIndex, attachmentName); - if (attachment != NULL) - { + if (attachment != NULL) { return attachment; } } @@ -391,18 +341,14 @@ namespace Spine return _data.getDefaultSkin() != NULL ? _data.getDefaultSkin()->getAttachment(slotIndex, attachmentName) : NULL; } - void Skeleton::setAttachment(std::string slotName, std::string attachmentName) - { + void Skeleton::setAttachment(std::string slotName, std::string attachmentName) { assert(slotName.length() > 0); - for (int i = 0, n = static_cast(_slots.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_slots.size()); i < n; ++i) { Slot* slot = _slots[i]; - if (slot->_data.getName() == slotName) - { + if (slot->_data.getName() == slotName) { Attachment* attachment = NULL; - if (attachmentName.length() > 0) - { + if (attachmentName.length() > 0) { attachment = getAttachment(i, attachmentName); assert(attachment != NULL); @@ -419,30 +365,24 @@ namespace Spine assert(false); } - IkConstraint* Skeleton::findIkConstraint(std::string constraintName) - { + IkConstraint* Skeleton::findIkConstraint(std::string constraintName) { assert(constraintName.length() > 0); - for (int i = 0, n = static_cast(_ikConstraints.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_ikConstraints.size()); i < n; ++i) { IkConstraint* ikConstraint = _ikConstraints[i]; - if (ikConstraint->_data.getName() == constraintName) - { + if (ikConstraint->_data.getName() == constraintName) { return ikConstraint; } } return NULL; } - TransformConstraint* Skeleton::findTransformConstraint(std::string constraintName) - { + TransformConstraint* Skeleton::findTransformConstraint(std::string constraintName) { assert(constraintName.length() > 0); - for (int i = 0, n = static_cast(_transformConstraints.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_transformConstraints.size()); i < n; ++i) { TransformConstraint* transformConstraint = _transformConstraints[i]; - if (transformConstraint->_data.getName() == constraintName) - { + if (transformConstraint->_data.getName() == constraintName) { return transformConstraint; } } @@ -450,15 +390,12 @@ namespace Spine return NULL; } - PathConstraint* Skeleton::findPathConstraint(std::string constraintName) - { + PathConstraint* Skeleton::findPathConstraint(std::string constraintName) { assert(constraintName.length() > 0); - for (int i = 0, n = static_cast(_pathConstraints.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_pathConstraints.size()); i < n; ++i) { PathConstraint* constraint = _pathConstraints[i]; - if (constraint->_data.getName() == constraintName) - { + if (constraint->_data.getName() == constraintName) { return constraint; } } @@ -466,43 +403,36 @@ namespace Spine return NULL; } - void Skeleton::update(float delta) - { + void Skeleton::update(float delta) { _time += delta; } - void Skeleton::getBounds(float& outX, float& outY, float& outWidth, float& outHeight, Vector& outVertexBuffer) - { + void Skeleton::getBounds(float& outX, float& outY, float& outWidth, float& outHeight, Vector& outVertexBuffer) { float minX = std::numeric_limits::max(); float minY = std::numeric_limits::max(); float maxX = std::numeric_limits::min(); float maxY = std::numeric_limits::min(); - for (Slot** i = _drawOrder.begin(); i != _drawOrder.end(); ++i) - { + for (Slot** i = _drawOrder.begin(); i != _drawOrder.end(); ++i) { Slot* slot = (*i); int verticesLength = 0; Attachment* attachment = slot->getAttachment(); - if (attachment != NULL && attachment->getRTTI().derivesFrom(RegionAttachment::rtti)) - { + if (attachment != NULL && attachment->getRTTI().derivesFrom(RegionAttachment::rtti)) { RegionAttachment* regionAttachment = static_cast(attachment); verticesLength = 8; - if (outVertexBuffer.size() < 8) - { + if (outVertexBuffer.size() < 8) { outVertexBuffer.reserve(8); outVertexBuffer.setSize(8); } regionAttachment->computeWorldVertices(slot->getBone(), outVertexBuffer, 0); } - else if (attachment != NULL && attachment->getRTTI().derivesFrom(MeshAttachment::rtti)) - { + else if (attachment != NULL && attachment->getRTTI().derivesFrom(MeshAttachment::rtti)) { MeshAttachment* mesh = static_cast(attachment); verticesLength = mesh->getWorldVerticesLength(); - if (outVertexBuffer.size() < verticesLength) - { + if (outVertexBuffer.size() < verticesLength) { outVertexBuffer.reserve(verticesLength); outVertexBuffer.setSize(verticesLength); } @@ -510,8 +440,7 @@ namespace Spine mesh->computeWorldVertices(*slot, 0, verticesLength, outVertexBuffer, 0); } - for (int ii = 0; ii < verticesLength; ii += 2) - { + for (int ii = 0; ii < verticesLength; ii += 2) { float vx = outVertexBuffer[ii]; float vy = outVertexBuffer[ii + 1]; @@ -528,148 +457,119 @@ namespace Spine outHeight = maxY - minY; } - Bone* Skeleton::getRootBone() - { + Bone* Skeleton::getRootBone() { return _bones.size() == 0 ? NULL : _bones[0]; } - const SkeletonData& Skeleton::getData() - { + const SkeletonData& Skeleton::getData() { return _data; } - Vector& Skeleton::getBones() - { + Vector& Skeleton::getBones() { return _bones; } - Vector& Skeleton::getUpdateCacheList() - { + Vector& Skeleton::getUpdateCacheList() { return _updateCache; } - Vector& Skeleton::getSlots() - { + Vector& Skeleton::getSlots() { return _slots; } - Vector& Skeleton::getDrawOrder() - { + Vector& Skeleton::getDrawOrder() { return _drawOrder; } - Vector& Skeleton::getIkConstraints() - { + Vector& Skeleton::getIkConstraints() { return _ikConstraints; } - Vector& Skeleton::getPathConstraints() - { + Vector& Skeleton::getPathConstraints() { return _pathConstraints; } - Vector& Skeleton::getTransformConstraints() - { + Vector& Skeleton::getTransformConstraints() { return _transformConstraints; } - Skin* Skeleton::getSkin() - { + Skin* Skeleton::getSkin() { return _skin; } - float Skeleton::getR() - { + float Skeleton::getR() { return _r; } - void Skeleton::setR(float inValue) - { + void Skeleton::setR(float inValue) { _r = inValue; } - float Skeleton::getG() - { + float Skeleton::getG() { return _g; } - void Skeleton::setG(float inValue) - { + void Skeleton::setG(float inValue) { _g = inValue; } - float Skeleton::getB() - { + float Skeleton::getB() { return _b; } - void Skeleton::setB(float inValue) - { + void Skeleton::setB(float inValue) { _b = inValue; } - float Skeleton::getA() - { + float Skeleton::getA() { return _a; } - void Skeleton::setA(float inValue) - { + void Skeleton::setA(float inValue) { _a = inValue; } - float Skeleton::getTime() - { + float Skeleton::getTime() { return _time; } - void Skeleton::setTime(float inValue) - { + void Skeleton::setTime(float inValue) { _time = inValue; } - float Skeleton::getX() - { + float Skeleton::getX() { return _x; } - void Skeleton::setX(float inValue) - { + void Skeleton::setX(float inValue) { _x = inValue; } - float Skeleton::getY() - { + float Skeleton::getY() { return _y; } - void Skeleton::setY(float inValue) - { + void Skeleton::setY(float inValue) { _y = inValue; } - bool Skeleton::getFlipX() - { + bool Skeleton::getFlipX() { return _flipX; } - void Skeleton::setFlipX(float inValue) - { + void Skeleton::setFlipX(float inValue) { _flipX = inValue; } - bool Skeleton::getFlipY() - { + bool Skeleton::getFlipY() { return _flipY; } - void Skeleton::setFlipY(float inValue) - { + void Skeleton::setFlipY(float inValue) { _flipY = inValue; } - void Skeleton::sortIkConstraint(IkConstraint* constraint) - { + void Skeleton::sortIkConstraint(IkConstraint* constraint) { Bone* target = constraint->getTarget(); sortBone(target); @@ -677,11 +577,9 @@ namespace Spine Bone* parent = constrained[0]; sortBone(parent); - if (constrained.size() > 1) - { + if (constrained.size() > 1) { Bone* child = constrained[constrained.size() - 1]; - if (!_updateCache.contains(child)) - { + if (!_updateCache.contains(child)) { _updateCacheReset.push_back(child); } } @@ -692,147 +590,119 @@ namespace Spine constrained[constrained.size() - 1]->_sorted = true; } - void Skeleton::sortPathConstraint(PathConstraint* constraint) - { + void Skeleton::sortPathConstraint(PathConstraint* constraint) { Slot* slot = constraint->getTarget(); int slotIndex = slot->_data.getIndex(); Bone& slotBone = slot->_bone; - if (_skin != NULL) - { + if (_skin != NULL) { sortPathConstraintAttachment(_skin, slotIndex, slotBone); } - if (_data._defaultSkin != NULL && _data._defaultSkin != _skin) - { + if (_data._defaultSkin != NULL && _data._defaultSkin != _skin) { sortPathConstraintAttachment(_data._defaultSkin, slotIndex, slotBone); } - for (int ii = 0, nn = static_cast(_data._skins.size()); ii < nn; ++ii) - { + for (int ii = 0, nn = static_cast(_data._skins.size()); ii < nn; ++ii) { sortPathConstraintAttachment(_data._skins[ii], slotIndex, slotBone); } Attachment* attachment = slot->_attachment; - if (attachment != NULL && attachment->getRTTI().derivesFrom(PathAttachment::rtti)) - { + if (attachment != NULL && attachment->getRTTI().derivesFrom(PathAttachment::rtti)) { sortPathConstraintAttachment(attachment, slotBone); } Vector& constrained = constraint->getBones(); int boneCount = static_cast(constrained.size()); - for (int i = 0; i < boneCount; ++i) - { + for (int i = 0; i < boneCount; ++i) { sortBone(constrained[i]); } _updateCache.push_back(constraint); - for (int i = 0; i < boneCount; ++i) - { + for (int i = 0; i < boneCount; ++i) { sortReset(constrained[i]->getChildren()); } - for (int i = 0; i < boneCount; ++i) - { + for (int i = 0; i < boneCount; ++i) { constrained[i]->_sorted = true; } } - void Skeleton::sortTransformConstraint(TransformConstraint* constraint) - { + void Skeleton::sortTransformConstraint(TransformConstraint* constraint) { sortBone(constraint->getTarget()); Vector& constrained = constraint->getBones(); int boneCount = static_cast(constrained.size()); - if (constraint->_data.isLocal()) - { - for (int i = 0; i < boneCount; ++i) - { + if (constraint->_data.isLocal()) { + for (int i = 0; i < boneCount; ++i) { Bone* child = constrained[i]; sortBone(child->getParent()); - if (!_updateCache.contains(child)) - { + if (!_updateCache.contains(child)) { _updateCacheReset.push_back(child); } } } - else - { - for (int i = 0; i < boneCount; ++i) - { + else { + for (int i = 0; i < boneCount; ++i) { sortBone(constrained[i]); } } _updateCache.push_back(constraint); - for (int i = 0; i < boneCount; ++i) - { + for (int i = 0; i < boneCount; ++i) { sortReset(constrained[i]->getChildren()); } - for (int i = 0; i < boneCount; ++i) - { + for (int i = 0; i < boneCount; ++i) { constrained[i]->_sorted = true; } } - void Skeleton::sortPathConstraintAttachment(Skin* skin, int slotIndex, Bone& slotBone) - { + void Skeleton::sortPathConstraintAttachment(Skin* skin, int slotIndex, Bone& slotBone) { HashMap& attachments = skin->getAttachments(); - for (typename HashMap::Iterator i = attachments.begin(); i != attachments.end(); ++i) - { + for (typename HashMap::Iterator i = attachments.begin(); i != attachments.end(); ++i) { Skin::AttachmentKey key = i.first(); - if (key._slotIndex == slotIndex) - { + if (key._slotIndex == slotIndex) { Attachment* value = i.second(); sortPathConstraintAttachment(value, slotBone); } } } - void Skeleton::sortPathConstraintAttachment(Attachment* attachment, Bone& slotBone) - { - if (attachment == NULL || attachment->getRTTI().derivesFrom(PathAttachment::rtti)) - { + void Skeleton::sortPathConstraintAttachment(Attachment* attachment, Bone& slotBone) { + if (attachment == NULL || attachment->getRTTI().derivesFrom(PathAttachment::rtti)) { return; } PathAttachment* pathAttachment = static_cast(attachment); Vector& pathBonesRef = pathAttachment->getBones(); Vector pathBones = pathBonesRef; - if (pathBones.size() == 0) - { + if (pathBones.size() == 0) { sortBone(&slotBone); } - else - { - for (int i = 0, n = static_cast(pathBones.size()); i < n;) - { + else { + for (int i = 0, n = static_cast(pathBones.size()); i < n;) { int nn = pathBones[i++]; nn += i; - while (i < nn) - { + while (i < nn) { sortBone(_bones[pathBones[i++]]); } } } } - void Skeleton::sortBone(Bone* bone) - { + void Skeleton::sortBone(Bone* bone) { assert(bone != NULL); - if (bone->_sorted) - { + if (bone->_sorted) { return; } Bone* parent = bone->_parent; - if (parent != NULL) - { + if (parent != NULL) { sortBone(parent); } @@ -841,13 +711,10 @@ namespace Spine _updateCache.push_back(bone); } - void Skeleton::sortReset(Vector& bones) - { - for (Bone** i = bones.begin(); i != bones.end(); ++i) - { + void Skeleton::sortReset(Vector& bones) { + for (Bone** i = bones.begin(); i != bones.end(); ++i) { Bone* bone = (*i); - if (bone->_sorted) - { + if (bone->_sorted) { sortReset(bone->getChildren()); } diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp index 16c44cee2..68709ac59 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp @@ -107,28 +107,23 @@ namespace Spine TransformMode_NoScaleOrReflection }; - SkeletonBinary::SkeletonBinary(Vector& atlasArray) : _attachmentLoader(NEW(AtlasAttachmentLoader)), _error(), _scale(1), _ownsLoader(true) - { + SkeletonBinary::SkeletonBinary(Vector& atlasArray) : _attachmentLoader(NEW(AtlasAttachmentLoader)), _error(), _scale(1), _ownsLoader(true) { new (_attachmentLoader) AtlasAttachmentLoader(atlasArray); } - SkeletonBinary::SkeletonBinary(AttachmentLoader* attachmentLoader) : _attachmentLoader(attachmentLoader), _error(), _scale(1), _ownsLoader(false) - { + SkeletonBinary::SkeletonBinary(AttachmentLoader* attachmentLoader) : _attachmentLoader(attachmentLoader), _error(), _scale(1), _ownsLoader(false) { assert(_attachmentLoader != NULL); } - SkeletonBinary::~SkeletonBinary() - { + SkeletonBinary::~SkeletonBinary() { ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes); - if (_ownsLoader) - { + if (_ownsLoader) { DESTROY(AttachmentLoader, _attachmentLoader); } } - SkeletonData* SkeletonBinary::readSkeletonData(const unsigned char* binary, const int length) - { + SkeletonData* SkeletonBinary::readSkeletonData(const unsigned char* binary, const int length) { int i, ii, nonessential; SkeletonData* skeletonData; @@ -154,8 +149,7 @@ namespace Spine nonessential = readBoolean(input); - if (nonessential) - { + if (nonessential) { /* Skip images path & fps */ readFloat(input); FREE(readString(input)); @@ -165,8 +159,7 @@ namespace Spine int bonesCount = readVarint(input, 1); skeletonData->_bones.reserve(bonesCount); skeletonData->_bones.setSize(bonesCount); - for (i = 0; i < bonesCount; ++i) - { + for (i = 0; i < bonesCount; ++i) { BoneData* data; int mode; const char* name = readString(input); @@ -187,8 +180,7 @@ namespace Spine data->_length = readFloat(input) * _scale; mode = readVarint(input, 1); - switch (mode) - { + switch (mode) { case 0: data->_transformMode = TransformMode_Normal; break; @@ -206,8 +198,7 @@ namespace Spine break; } - if (nonessential) - { + if (nonessential) { /* Skip bone color. */ readInt(input); } @@ -219,8 +210,7 @@ namespace Spine int slotsCount = readVarint(input, 1); skeletonData->_slots.reserve(slotsCount); skeletonData->_slots.setSize(slotsCount); - for (i = 0; i < slotsCount; ++i) - { + for (i = 0; i < slotsCount; ++i) { int r, g, b, a; const char* slotName = readString(input); BoneData* boneData = skeletonData->_bones[readVarint(input, 1)]; @@ -234,8 +224,7 @@ namespace Spine g = readByte(input); b = readByte(input); a = readByte(input); - if (!(r == 0xff && g == 0xff && b == 0xff && a == 0xff)) - { + if (!(r == 0xff && g == 0xff && b == 0xff && a == 0xff)) { slotData->_r2 = r / 255.0f; slotData->_g2 = g / 255.0f; slotData->_b2 = b / 255.0f; @@ -252,8 +241,7 @@ namespace Spine int ikConstraintsCount = readVarint(input, 1); skeletonData->_ikConstraints.reserve(ikConstraintsCount); skeletonData->_ikConstraints.setSize(ikConstraintsCount); - for (i = 0; i < ikConstraintsCount; ++i) - { + for (i = 0; i < ikConstraintsCount; ++i) { const char* name = readString(input); IkConstraintData* data = NEW(IkConstraintData); @@ -265,8 +253,7 @@ namespace Spine int bonesCount = readVarint(input, 1); data->_bones.reserve(bonesCount); data->_bones.setSize(bonesCount); - for (ii = 0; ii < bonesCount; ++ii) - { + for (ii = 0; ii < bonesCount; ++ii) { data->_bones[ii] = skeletonData->_bones[readVarint(input, 1)]; } data->_target = skeletonData->_bones[readVarint(input, 1)]; @@ -280,8 +267,7 @@ namespace Spine int transformConstraintsCount = readVarint(input, 1); skeletonData->_transformConstraints.reserve(transformConstraintsCount); skeletonData->_transformConstraints.setSize(transformConstraintsCount); - for (i = 0; i < transformConstraintsCount; ++i) - { + for (i = 0; i < transformConstraintsCount; ++i) { const char* name = readString(input); TransformConstraintData* data = NEW(TransformConstraintData); @@ -292,8 +278,7 @@ namespace Spine int bonesCount = readVarint(input, 1); data->_bones.reserve(bonesCount); data->_bones.setSize(bonesCount); - for (ii = 0; ii < bonesCount; ++ii) - { + for (ii = 0; ii < bonesCount; ++ii) { data->_bones[ii] = skeletonData->_bones[readVarint(input, 1)]; } data->_target = skeletonData->_bones[readVarint(input, 1)]; @@ -317,8 +302,7 @@ namespace Spine int pathConstraintsCount = readVarint(input, 1); skeletonData->_pathConstraints.reserve(pathConstraintsCount); skeletonData->_pathConstraints.setSize(pathConstraintsCount); - for (i = 0; i < pathConstraintsCount; ++i) - { + for (i = 0; i < pathConstraintsCount; ++i) { const char* name = readString(input); PathConstraintData* data = NEW(PathConstraintData); @@ -330,8 +314,7 @@ namespace Spine int bonesCount = readVarint(input, 1); data->_bones.reserve(bonesCount); data->_bones.setSize(bonesCount); - for (ii = 0; ii < bonesCount; ++ii) - { + for (ii = 0; ii < bonesCount; ++ii) { data->_bones[ii] = skeletonData->_bones[readVarint(input, 1)]; } data->_target = skeletonData->_slots[readVarint(input, 1)]; @@ -340,14 +323,12 @@ namespace Spine data->_rotateMode = static_cast(readVarint(input, 1)); data->_offsetRotation = readFloat(input); data->_position = readFloat(input); - if (data->_positionMode == PositionMode_Fixed) - { + if (data->_positionMode == PositionMode_Fixed) { data->_position *= _scale; } data->_spacing = readFloat(input); - if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) - { + if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) { data->_spacing *= _scale; } data->_rotateMix = readFloat(input); @@ -360,42 +341,36 @@ namespace Spine skeletonData->_defaultSkin = readSkin(input, "default", skeletonData, nonessential); int skinsCount = readVarint(input, 1); - if (skeletonData->_defaultSkin) - { + if (skeletonData->_defaultSkin) { ++skinsCount; } skeletonData->_skins.reserve(skinsCount); skeletonData->_skins.setSize(skinsCount); - if (skeletonData->_defaultSkin) - { + if (skeletonData->_defaultSkin) { skeletonData->_skins[0] = skeletonData->_defaultSkin; } /* Skins. */ - for (i = skeletonData->_defaultSkin ? 1 : 0; i < skeletonData->_skins.size(); ++i) - { + for (i = skeletonData->_defaultSkin ? 1 : 0; i < skeletonData->_skins.size(); ++i) { const char* skinName = readString(input); skeletonData->_skins[i] = readSkin(input, skinName, skeletonData, nonessential); FREE(skinName); } /* Linked meshes. */ - for (int i = 0, n = static_cast(_linkedMeshes.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_linkedMeshes.size()); i < n; ++i) { LinkedMesh* linkedMesh = _linkedMeshes[i]; Skin* skin = linkedMesh->_skin.length() == 0 ? skeletonData->getDefaultSkin() : skeletonData->findSkin(linkedMesh->_skin); - if (skin == NULL) - { + if (skin == NULL) { FREE(input); DESTROY(SkeletonData, skeletonData); setError("Skin not found: ", linkedMesh->_skin.c_str()); return NULL; } Attachment* parent = skin->getAttachment(linkedMesh->_slotIndex, linkedMesh->_parent); - if (parent == NULL) - { + if (parent == NULL) { FREE(input); DESTROY(SkeletonData, skeletonData); setError("Parent mesh not found: ", linkedMesh->_parent.c_str()); @@ -410,8 +385,7 @@ namespace Spine int eventsCount = readVarint(input, 1); skeletonData->_events.reserve(eventsCount); skeletonData->_events.setSize(eventsCount); - for (i = 0; i < eventsCount; ++i) - { + for (i = 0; i < eventsCount; ++i) { const char* name = readString(input); EventData* eventData = NEW(EventData); new (eventData) EventData(std::string(name)); @@ -428,13 +402,11 @@ namespace Spine int animationsCount = readVarint(input, 1); skeletonData->_animations.reserve(animationsCount); skeletonData->_animations.setSize(animationsCount); - for (i = 0; i < animationsCount; ++i) - { + for (i = 0; i < animationsCount; ++i) { const char* name = readString(input); Animation* animation = readAnimation(name, input, skeletonData); FREE(name); - if (!animation) - { + if (!animation) { FREE(input); DESTROY(SkeletonData, skeletonData); return NULL; @@ -447,13 +419,11 @@ namespace Spine return skeletonData; } - SkeletonData* SkeletonBinary::readSkeletonDataFile(const char* path) - { + SkeletonData* SkeletonBinary::readSkeletonDataFile(const char* path) { int length; SkeletonData* skeletonData; const char* binary = SPINE_EXTENSION->spineReadFile(path, &length); - if (length == 0 || !binary) - { + if (length == 0 || !binary) { setError("Unable to read skeleton file: ", path); return NULL; } @@ -462,22 +432,19 @@ namespace Spine return skeletonData; } - void SkeletonBinary::setError(const char* value1, const char* value2) - { + void SkeletonBinary::setError(const char* value1, const char* value2) { char message[256]; int length; strcpy(message, value1); length = (int)strlen(value1); - if (value2) - { + if (value2) { strncat(message + length, value2, 255 - length); } _error = std::string(message); } - char* SkeletonBinary::readString(DataInput* input) - { + char* SkeletonBinary::readString(DataInput* input) { int length = readVarint(input, 1); char* string; if (length == 0) { @@ -490,10 +457,8 @@ namespace Spine return string; } - float SkeletonBinary::readFloat(DataInput* input) - { - union - { + float SkeletonBinary::readFloat(DataInput* input) { + union { int intValue; float floatValue; } intToFloat; @@ -503,23 +468,19 @@ namespace Spine return intToFloat.floatValue; } - unsigned char SkeletonBinary::readByte(DataInput* input) - { + unsigned char SkeletonBinary::readByte(DataInput* input) { return *input->cursor++; } - signed char SkeletonBinary::readSByte(DataInput* input) - { + signed char SkeletonBinary::readSByte(DataInput* input) { return (signed char)readByte(input); } - int SkeletonBinary::readBoolean(DataInput* input) - { + int SkeletonBinary::readBoolean(DataInput* input) { return readByte(input) != 0; } - int SkeletonBinary::readInt(DataInput* input) - { + int SkeletonBinary::readInt(DataInput* input) { int result = readByte(input); result <<= 8; result |= readByte(input); @@ -530,28 +491,23 @@ namespace Spine return result; } - void SkeletonBinary::readColor(DataInput* input, float *r, float *g, float *b, float *a) - { + void SkeletonBinary::readColor(DataInput* input, float *r, float *g, float *b, float *a) { *r = readByte(input) / 255.0f; *g = readByte(input) / 255.0f; *b = readByte(input) / 255.0f; *a = readByte(input) / 255.0f; } - int SkeletonBinary::readVarint(DataInput* input, bool optimizePositive) - { + int SkeletonBinary::readVarint(DataInput* input, bool optimizePositive) { unsigned char b = readByte(input); int value = b & 0x7F; - if (b & 0x80) - { + if (b & 0x80) { b = readByte(input); value |= (b & 0x7F) << 7; - if (b & 0x80) - { + if (b & 0x80) { b = readByte(input); value |= (b & 0x7F) << 14; - if (b & 0x80) - { + if (b & 0x80) { b = readByte(input); value |= (b & 0x7F) << 21; if (b & 0x80) value |= (readByte(input) & 0x7F) << 28; @@ -559,36 +515,30 @@ namespace Spine } } - if (!optimizePositive) - { + if (!optimizePositive) { value = (((unsigned int)value >> 1) ^ -(value & 1)); } return value; } - Skin* SkeletonBinary::readSkin(DataInput* input, const char* skinName, SkeletonData* skeletonData, bool nonessential) - { + Skin* SkeletonBinary::readSkin(DataInput* input, const char* skinName, SkeletonData* skeletonData, bool nonessential) { Skin* skin = NULL; int slotCount = readVarint(input, 1); int i, ii, nn; - if (slotCount == 0) - { + if (slotCount == 0) { return NULL; } skin = NEW(Skin); new (skin) Skin(std::string(skinName)); - for (i = 0; i < slotCount; ++i) - { + for (i = 0; i < slotCount; ++i) { int slotIndex = readVarint(input, 1); - for (ii = 0, nn = readVarint(input, 1); ii < nn; ++ii) - { + for (ii = 0, nn = readVarint(input, 1); ii < nn; ++ii) { const char* name = readString(input); Attachment* attachment = readAttachment(input, skin, slotIndex, name, skeletonData, nonessential); - if (attachment) - { + if (attachment) { skin->addAttachment(slotIndex, std::string(name), attachment); } FREE(name); @@ -598,28 +548,23 @@ namespace Spine return skin; } - Attachment* SkeletonBinary::readAttachment(DataInput* input, Skin* skin, int slotIndex, const char* attachmentName, SkeletonData* skeletonData, bool nonessential) - { + Attachment* SkeletonBinary::readAttachment(DataInput* input, Skin* skin, int slotIndex, const char* attachmentName, SkeletonData* skeletonData, bool nonessential) { int i; AttachmentType type; const char* name = readString(input); int freeName = name != 0; - if (!name) - { + if (!name) { freeName = 0; name = attachmentName; } type = static_cast(readByte(input)); - switch (type) - { - case AttachmentType_Region: - { + switch (type) { + case AttachmentType_Region: { const char* path = readString(input); RegionAttachment* region; - if (!path) - { + if (!path) { path = name; } region = _attachmentLoader->newRegionAttachment(*skin, std::string(name), std::string(path)); @@ -634,37 +579,31 @@ namespace Spine readColor(input, ®ion->_r, ®ion->_g, ®ion->_b, ®ion->_a); region->updateOffset(); - if (freeName) - { + if (freeName) { FREE(name); } return region; } - case AttachmentType_Boundingbox: - { + case AttachmentType_Boundingbox: { int vertexCount = readVarint(input, 1); BoundingBoxAttachment* box = _attachmentLoader->newBoundingBoxAttachment(*skin, std::string(name)); readVertices(input, static_cast(box), vertexCount); - if (nonessential) - { + if (nonessential) { /* Skip color. */ readInt(input); } - if (freeName) - { + if (freeName) { FREE(name); } return box; } - case AttachmentType_Mesh: - { + case AttachmentType_Mesh: { int vertexCount; MeshAttachment* mesh; const char* path = readString(input); - if (!path) - { + if (!path) { path = name; } mesh = _attachmentLoader->newMeshAttachment(*skin, std::string(name), std::string(path)); @@ -678,34 +617,29 @@ namespace Spine readVertices(input, static_cast(mesh), vertexCount); mesh->updateUVs(); mesh->_hullLength = readVarint(input, 1) << 1; - if (nonessential) - { + if (nonessential) { Vector edges = readShortArray(input); mesh->setEdges(edges); mesh->_width = readFloat(input) * _scale; mesh->_height = readFloat(input) * _scale; } - else - { + else { mesh->_width = 0; mesh->_height = 0; } - if (freeName) - { + if (freeName) { FREE(name); } return mesh; } - case AttachmentType_Linkedmesh: - { + case AttachmentType_Linkedmesh: { const char* skinName; const char* parent; MeshAttachment* mesh; const char* path = readString(input); - if (!path) - { + if (!path) { path = name; } @@ -715,8 +649,7 @@ namespace Spine skinName = readString(input); parent = readString(input); mesh->_inheritDeform = readBoolean(input); - if (nonessential) - { + if (nonessential) { mesh->_width = readFloat(input) * _scale; mesh->_height = readFloat(input) * _scale; } @@ -725,8 +658,7 @@ namespace Spine new (linkedMesh) LinkedMesh(mesh, std::string(skinName), slotIndex, std::string(parent)); _linkedMeshes.push_back(linkedMesh); - if (freeName) - { + if (freeName) { FREE(name); } @@ -735,8 +667,7 @@ namespace Spine return mesh; } - case AttachmentType_Path: - { + case AttachmentType_Path: { PathAttachment* path = _attachmentLoader->newPathAttachment(*skin, std::string(name)); int vertexCount = 0; path->_closed = readBoolean(input); @@ -746,56 +677,48 @@ namespace Spine int lengthsLength = vertexCount / 3; path->_lengths.reserve(lengthsLength); path->_lengths.setSize(lengthsLength); - for (i = 0; i < lengthsLength; ++i) - { + for (i = 0; i < lengthsLength; ++i) { path->_lengths[i] = readFloat(input) * _scale; } - if (nonessential) - { + if (nonessential) { /* Skip color. */ readInt(input); } - if (freeName) - { + if (freeName) { FREE(name); } return path; } - case AttachmentType_Point: - { + case AttachmentType_Point: { PointAttachment* point = _attachmentLoader->newPointAttachment(*skin, std::string(name)); point->_rotation = readFloat(input); point->_x = readFloat(input) * _scale; point->_y = readFloat(input) * _scale; - if (nonessential) - { + if (nonessential) { /* Skip color. */ readInt(input); } return point; } - case AttachmentType_Clipping: - { + case AttachmentType_Clipping: { int endSlotIndex = readVarint(input, 1); int vertexCount = readVarint(input, 1); ClippingAttachment* clip = _attachmentLoader->newClippingAttachment(*skin, name); readVertices(input, static_cast(clip), vertexCount); - if (nonessential) - { + if (nonessential) { /* Skip color. */ readInt(input); } clip->_endSlot = skeletonData->_slots[endSlotIndex]; - if (freeName) - { + if (freeName) { FREE(name); } @@ -803,21 +726,18 @@ namespace Spine } } - if (freeName) - { + if (freeName) { FREE(name); } return NULL; } - void SkeletonBinary::readVertices(DataInput* input, VertexAttachment* attachment, int vertexCount) - { + void SkeletonBinary::readVertices(DataInput* input, VertexAttachment* attachment, int vertexCount) { float scale = _scale; int verticesLength = vertexCount << 1; - if (!readBoolean(input)) - { + if (!readBoolean(input)) { attachment->setVertices(readFloatArray(input, verticesLength, scale)); return; } @@ -826,12 +746,10 @@ namespace Spine vertices._bones.reserve(verticesLength * 3); vertices._vertices.reserve(verticesLength * 3 * 3); - for (int i = 0; i < vertexCount; ++i) - { + for (int i = 0; i < vertexCount; ++i) { int boneCount = readVarint(input, true); vertices._bones.push_back(boneCount); - for (int ii = 0; ii < boneCount; ++ii) - { + for (int ii = 0; ii < boneCount; ++ii) { vertices._bones.push_back(readVarint(input, true)); vertices._vertices.push_back(readFloat(input) * scale); vertices._vertices.push_back(readFloat(input) * scale); @@ -843,24 +761,19 @@ namespace Spine attachment->setBones(vertices._bones); } - Vector SkeletonBinary::readFloatArray(DataInput *input, int n, float scale) - { + Vector SkeletonBinary::readFloatArray(DataInput *input, int n, float scale) { Vector array; array.reserve(n); array.setSize(n); int i; - if (scale == 1) - { - for (i = 0; i < n; ++i) - { + if (scale == 1) { + for (i = 0; i < n; ++i) { array[i] = readFloat(input); } } - else - { - for (i = 0; i < n; ++i) - { + else { + for (i = 0; i < n; ++i) { array[i] = readFloat(input) * scale; } } @@ -868,8 +781,7 @@ namespace Spine return array; } - Vector SkeletonBinary::readShortArray(DataInput *input) - { + Vector SkeletonBinary::readShortArray(DataInput *input) { int n = readVarint(input, 1); Vector array; @@ -877,8 +789,7 @@ namespace Spine array.setSize(n); int i; - for (i = 0; i < n; ++i) - { + for (i = 0; i < n; ++i) { array[i] = readByte(input) << 8; array[i] |= readByte(input); } @@ -886,29 +797,23 @@ namespace Spine return array; } - Animation* SkeletonBinary::readAnimation(const char* name, DataInput* input, SkeletonData *skeletonData) - { + Animation* SkeletonBinary::readAnimation(const char* name, DataInput* input, SkeletonData *skeletonData) { Vector timelines; float scale = _scale; float duration = 0; // Slot timelines. - for (int i = 0, n = readVarint(input, true); i < n; ++i) - { + for (int i = 0, n = readVarint(input, true); i < n; ++i) { int slotIndex = readVarint(input, true); - for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) - { + for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) { unsigned char timelineType = readByte(input); int frameCount = readVarint(input, true); - switch (timelineType) - { - case SLOT_ATTACHMENT: - { + switch (timelineType) { + case SLOT_ATTACHMENT: { AttachmentTimeline* timeline = NEW(AttachmentTimeline); new(timeline) AttachmentTimeline(frameCount); timeline->_slotIndex = slotIndex; - for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) - { + for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { const char* attachmentName = readString(input); timeline->setFrame(frameIndex, readFloat(input), std::string(attachmentName)); FREE(attachmentName); @@ -917,13 +822,11 @@ namespace Spine duration = MAX(duration, timeline->_frames[frameCount - 1]); break; } - case SLOT_COLOR: - { + case SLOT_COLOR: { ColorTimeline* timeline = NEW(ColorTimeline); new(timeline) ColorTimeline(frameCount); timeline->_slotIndex = slotIndex; - for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) - { + for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { float time = readFloat(input); int color = readInt(input); float r = ((color & 0xff000000) >> 24) / 255.0f; @@ -931,8 +834,7 @@ namespace Spine float b = ((color & 0x0000ff00) >> 8) / 255.0f; float a = ((color & 0x000000ff)) / 255.0f; timeline->setFrame(frameIndex, time, r, g, b, a); - if (frameIndex < frameCount - 1) - { + if (frameIndex < frameCount - 1) { readCurve(input, frameIndex, timeline); } } @@ -940,13 +842,11 @@ namespace Spine duration = MAX(duration, timeline->_frames[(frameCount - 1) * ColorTimeline::ENTRIES]); break; } - case SLOT_TWO_COLOR: - { + case SLOT_TWO_COLOR: { TwoColorTimeline* timeline = NEW(TwoColorTimeline); new(timeline) TwoColorTimeline(frameCount); timeline->_slotIndex = slotIndex; - for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) - { + for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { float time = readFloat(input); int color = readInt(input); float r = ((color & 0xff000000) >> 24) / 255.0f; @@ -959,8 +859,7 @@ namespace Spine float b2 = ((color2 & 0x000000ff)) / 255.0f; timeline->setFrame(frameIndex, time, r, g, b, a, r2, g2, b2); - if (frameIndex < frameCount - 1) - { + if (frameIndex < frameCount - 1) { readCurve(input, frameIndex, timeline); } } @@ -968,8 +867,7 @@ namespace Spine duration = MAX(duration, timeline->_frames[(frameCount - 1) * TwoColorTimeline::ENTRIES]); break; } - default: - { + default: { ContainerUtil::cleanUpVectorOfPointers(timelines); setError("Invalid timeline type for a slot: ", skeletonData->_slots[slotIndex]->_name.c_str()); return NULL; @@ -979,25 +877,19 @@ namespace Spine } // Bone timelines. - for (int i = 0, n = readVarint(input, true); i < n; ++i) - { + for (int i = 0, n = readVarint(input, true); i < n; ++i) { int boneIndex = readVarint(input, true); - for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) - { + for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) { unsigned char timelineType = readByte(input); int frameCount = readVarint(input, true); - switch (timelineType) - { - case BONE_ROTATE: - { + switch (timelineType) { + case BONE_ROTATE: { RotateTimeline* timeline = NEW(RotateTimeline); new(timeline) RotateTimeline(frameCount); timeline->_boneIndex = boneIndex; - for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) - { + for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { timeline->setFrame(frameIndex, readFloat(input), readFloat(input)); - if (frameIndex < frameCount - 1) - { + if (frameIndex < frameCount - 1) { readCurve(input, frameIndex, timeline); } } @@ -1007,32 +899,26 @@ namespace Spine } case BONE_TRANSLATE: case BONE_SCALE: - case BONE_SHEAR: - { + case BONE_SHEAR: { TranslateTimeline* timeline; float timelineScale = 1; - if (timelineType == BONE_SCALE) - { + if (timelineType == BONE_SCALE) { timeline = NEW(ScaleTimeline); new(timeline) ScaleTimeline(frameCount); } - else if (timelineType == BONE_SHEAR) - { + else if (timelineType == BONE_SHEAR) { timeline = NEW(ShearTimeline); new(timeline) ShearTimeline(frameCount); } - else - { + else { timeline = NEW(TranslateTimeline); new(timeline) TranslateTimeline(frameCount); timelineScale = scale; } timeline->_boneIndex = boneIndex; - for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) - { + for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { timeline->setFrame(frameIndex, readFloat(input), readFloat(input) * timelineScale, readFloat(input) * timelineScale); - if (frameIndex < frameCount - 1) - { + if (frameIndex < frameCount - 1) { readCurve(input, frameIndex, timeline); } } @@ -1040,8 +926,7 @@ namespace Spine duration = MAX(duration, timeline->_frames[(frameCount - 1) * TranslateTimeline::ENTRIES]); break; } - default: - { + default: { ContainerUtil::cleanUpVectorOfPointers(timelines); setError("Invalid timeline type for a bone: ", skeletonData->_bones[boneIndex]->_name.c_str()); return NULL; @@ -1051,18 +936,15 @@ namespace Spine } // IK timelines. - for (int i = 0, n = readVarint(input, true); i < n; ++i) - { + for (int i = 0, n = readVarint(input, true); i < n; ++i) { int index = readVarint(input, true); int frameCount = readVarint(input, true); IkConstraintTimeline* timeline = NEW(IkConstraintTimeline); new(timeline) IkConstraintTimeline(frameCount); timeline->_ikConstraintIndex = index; - for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) - { + for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { timeline->setFrame(frameIndex, readFloat(input), readFloat(input), readSByte(input)); - if (frameIndex < frameCount - 1) - { + if (frameIndex < frameCount - 1) { readCurve(input, frameIndex, timeline); } } @@ -1071,18 +953,15 @@ namespace Spine } // Transform constraint timelines. - for (int i = 0, n = readVarint(input, true); i < n; ++i) - { + for (int i = 0, n = readVarint(input, true); i < n; ++i) { int index = readVarint(input, true); int frameCount = readVarint(input, true); TransformConstraintTimeline* timeline = NEW(TransformConstraintTimeline); new(timeline) TransformConstraintTimeline(frameCount); timeline->_transformConstraintIndex = index; - for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) - { + for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { timeline->setFrame(frameIndex, readFloat(input), readFloat(input), readFloat(input), readFloat(input), readFloat(input)); - if (frameIndex < frameCount - 1) - { + if (frameIndex < frameCount - 1) { readCurve(input, frameIndex, timeline); } } @@ -1091,47 +970,37 @@ namespace Spine } // Path constraint timelines. - for (int i = 0, n = readVarint(input, true); i < n; ++i) - { + for (int i = 0, n = readVarint(input, true); i < n; ++i) { int index = readVarint(input, true); PathConstraintData* data = skeletonData->_pathConstraints[index]; - for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) - { + for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) { int timelineType = readSByte(input); int frameCount = readVarint(input, true); - switch(timelineType) - { + switch(timelineType) { case PATH_POSITION: - case PATH_SPACING: - { + case PATH_SPACING: { PathConstraintPositionTimeline* timeline; float timelineScale = 1; - if (timelineType == PATH_SPACING) - { + if (timelineType == PATH_SPACING) { timeline = NEW(PathConstraintSpacingTimeline); new(timeline) PathConstraintSpacingTimeline(frameCount); - if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) - { + if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) { timelineScale = scale; } } - else - { + else { timeline = NEW(PathConstraintPositionTimeline); new(timeline) PathConstraintPositionTimeline(frameCount); - if (data->_positionMode == PositionMode_Fixed) - { + if (data->_positionMode == PositionMode_Fixed) { timelineScale = scale; } } timeline->_pathConstraintIndex = index; - for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) - { + for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { timeline->setFrame(frameIndex, readFloat(input), readFloat(input) * timelineScale); - if (frameIndex < frameCount - 1) - { + if (frameIndex < frameCount - 1) { readCurve(input, frameIndex, timeline); } } @@ -1139,17 +1008,14 @@ namespace Spine duration = MAX(duration, timeline->_frames[(frameCount - 1) * PathConstraintPositionTimeline::ENTRIES]); break; } - case PATH_MIX: - { + case PATH_MIX: { PathConstraintMixTimeline* timeline = NEW(PathConstraintMixTimeline); new(timeline) PathConstraintMixTimeline(frameCount); timeline->_pathConstraintIndex = index; - for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) - { + for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { timeline->setFrame(frameIndex, readFloat(input), readFloat(input), readFloat(input)); - if (frameIndex < frameCount - 1) - { + if (frameIndex < frameCount - 1) { readCurve(input, frameIndex, timeline); } } @@ -1162,19 +1028,15 @@ namespace Spine } // Deform timelines. - for (int i = 0, n = readVarint(input, true); i < n; ++i) - { + for (int i = 0, n = readVarint(input, true); i < n; ++i) { Skin* skin = skeletonData->_skins[readVarint(input, true)]; - for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) - { + for (int ii = 0, nn = readVarint(input, true); ii < nn; ++ii) { int slotIndex = readVarint(input, true); - for (int iii = 0, nnn = readVarint(input, true); iii < nnn; iii++) - { + for (int iii = 0, nnn = readVarint(input, true); iii < nnn; iii++) { const char* attachmentName = readString(input); Attachment* baseAttachment = skin->getAttachment(slotIndex, std::string(attachmentName)); - if (!baseAttachment) - { + if (!baseAttachment) { ContainerUtil::cleanUpVectorOfPointers(timelines); setError("Attachment not found: ", attachmentName); FREE(attachmentName); @@ -1197,58 +1059,45 @@ namespace Spine timeline->_slotIndex = slotIndex; timeline->_attachment = attachment; - for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) - { + for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) { float time = readFloat(input); Vector deform; int end = readVarint(input, true); - if (end == 0) - { - if (weighted) - { + if (end == 0) { + if (weighted) { deform.reserve(deformLength); - for (int i = 0; i < deformLength; ++i) - { + for (int i = 0; i < deformLength; ++i) { deform.push_back(0); } } - else - { + else { deform = vertices; } } - else - { + else { deform.reserve(deformLength); int start = readVarint(input, true); end += start; - if (scale == 1) - { - for (int v = start; v < end; ++v) - { + if (scale == 1) { + for (int v = start; v < end; ++v) { deform[v] = readFloat(input); } } - else - { - for (int v = start; v < end; ++v) - { + else { + for (int v = start; v < end; ++v) { deform[v] = readFloat(input) * scale; } } - if (!weighted) - { - for (int v = 0, vn = static_cast(deform.size()); v < vn; ++v) - { + if (!weighted) { + for (int v = 0, vn = static_cast(deform.size()); v < vn; ++v) { deform[v] += vertices[v]; } } } timeline->setFrame(frameIndex, time, deform); - if (frameIndex < frameCount - 1) - { + if (frameIndex < frameCount - 1) { readCurve(input, frameIndex, timeline); } } @@ -1261,33 +1110,28 @@ namespace Spine // Draw order timeline. int drawOrderCount = readVarint(input, true); - if (drawOrderCount > 0) - { + if (drawOrderCount > 0) { DrawOrderTimeline* timeline = NEW(DrawOrderTimeline); new(timeline) DrawOrderTimeline(drawOrderCount); int slotCount = static_cast(skeletonData->_slots.size()); - for (int i = 0; i < drawOrderCount; ++i) - { + for (int i = 0; i < drawOrderCount; ++i) { float time = readFloat(input); int offsetCount = readVarint(input, true); Vector drawOrder; drawOrder.reserve(slotCount); - for (int ii = slotCount - 1; ii >= 0; --ii) - { + for (int ii = slotCount - 1; ii >= 0; --ii) { drawOrder[ii] = -1; } Vector unchanged; unchanged.reserve(slotCount - offsetCount); int originalIndex = 0, unchangedIndex = 0; - for (int ii = 0; ii < offsetCount; ++ii) - { + for (int ii = 0; ii < offsetCount; ++ii) { int slotIndex = readVarint(input, true); // Collect unchanged items. - while (originalIndex != slotIndex) - { + while (originalIndex != slotIndex) { unchanged[unchangedIndex++] = originalIndex++; } // Set changed items. @@ -1296,16 +1140,13 @@ namespace Spine } // Collect remaining unchanged items. - while (originalIndex < slotCount) - { + while (originalIndex < slotCount) { unchanged[unchangedIndex++] = originalIndex++; } // Fill in unchanged items. - for (int ii = slotCount - 1; ii >= 0; --ii) - { - if (drawOrder[ii] == -1) - { + for (int ii = slotCount - 1; ii >= 0; --ii) { + if (drawOrder[ii] == -1) { drawOrder[ii] = unchanged[--unchangedIndex]; } } @@ -1317,13 +1158,11 @@ namespace Spine // Event timeline. int eventCount = readVarint(input, true); - if (eventCount > 0) - { + if (eventCount > 0) { EventTimeline* timeline = NEW(EventTimeline); new(timeline) EventTimeline(eventCount); - for (int i = 0; i < eventCount; ++i) - { + for (int i = 0; i < eventCount; ++i) { float time = readFloat(input); EventData* eventData = skeletonData->_events[readVarint(input, true)]; Event* event = NEW(Event); @@ -1334,8 +1173,7 @@ namespace Spine bool freeString = readBoolean(input); const char* event_stringValue = freeString ? readString(input) : eventData->_stringValue.c_str(); event->_stringValue = std::string(event_stringValue); - if (freeString) - { + if (freeString) { FREE(event_stringValue); } timeline->setFrame(i, event); @@ -1351,17 +1189,13 @@ namespace Spine return ret; } - void SkeletonBinary::readCurve(DataInput* input, int frameIndex, CurveTimeline* timeline) - { - switch (readByte(input)) - { - case CURVE_STEPPED: - { + void SkeletonBinary::readCurve(DataInput* input, int frameIndex, CurveTimeline* timeline) { + switch (readByte(input)) { + case CURVE_STEPPED: { timeline->setStepped(frameIndex); break; } - case CURVE_BEZIER: - { + case CURVE_BEZIER: { float cx1 = readFloat(input); float cy1 = readFloat(input); float cx2 = readFloat(input); diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonBounds.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonBounds.cpp index a5a6e3c8a..a1e171e03 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonBounds.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonBounds.cpp @@ -38,30 +38,25 @@ namespace Spine { - SkeletonBounds::SkeletonBounds() : _minX(0), _minY(0), _maxX(0), _maxY(0) - { + SkeletonBounds::SkeletonBounds() : _minX(0), _minY(0), _maxX(0), _maxY(0) { // Empty } - void SkeletonBounds::update(Skeleton& skeleton, bool updateAabb) - { + void SkeletonBounds::update(Skeleton& skeleton, bool updateAabb) { Vector& slots = skeleton._slots; int slotCount = static_cast(slots.size()); _boundingBoxes.clear(); - for (int i = 0, n = static_cast(_polygons.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_polygons.size()); i < n; ++i) { _polygonPool.push_back(_polygons[i]); } _polygons.clear(); - for (int i = 0; i < slotCount; i++) - { + for (int i = 0; i < slotCount; i++) { Slot* slot = slots[i]; Attachment* attachment = slot->_attachment; - if (attachment == NULL || !attachment->getRTTI().derivesFrom(BoundingBoxAttachment::rtti)) - { + if (attachment == NULL || !attachment->getRTTI().derivesFrom(BoundingBoxAttachment::rtti)) { continue; } BoundingBoxAttachment* boundingBox = static_cast(attachment); @@ -69,13 +64,11 @@ namespace Spine Polygon* polygonP = NULL; int poolCount = static_cast(_polygonPool.size()); - if (poolCount > 0) - { + if (poolCount > 0) { polygonP = _polygonPool[poolCount - 1]; _polygonPool.erase(poolCount - 1); } - else - { + else { Polygon* polygonP = NEW(Polygon); new (polygonP) Polygon(); } @@ -86,19 +79,16 @@ namespace Spine int count = boundingBox->getWorldVerticesLength(); polygon._count = count; - if (polygon._vertices.size() < count) - { + if (polygon._vertices.size() < count) { polygon._vertices.reserve(count); } boundingBox->computeWorldVertices(*slot, polygon._vertices); } - if (updateAabb) - { + if (updateAabb) { aabbCompute(); } - else - { + else { _minX = std::numeric_limits::min(); _minY = std::numeric_limits::min(); _maxX = std::numeric_limits::max(); @@ -106,68 +96,56 @@ namespace Spine } } - bool SkeletonBounds::aabbcontainsPoint(float x, float y) - { + bool SkeletonBounds::aabbcontainsPoint(float x, float y) { return x >= _minX && x <= _maxX && y >= _minY && y <= _maxY; } - bool SkeletonBounds::aabbintersectsSegment(float x1, float y1, float x2, float y2) - { + bool SkeletonBounds::aabbintersectsSegment(float x1, float y1, float x2, float y2) { float minX = _minX; float minY = _minY; float maxX = _maxX; float maxY = _maxY; - if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) || (y1 >= maxY && y2 >= maxY)) - { + if ((x1 <= minX && x2 <= minX) || (y1 <= minY && y2 <= minY) || (x1 >= maxX && x2 >= maxX) || (y1 >= maxY && y2 >= maxY)) { return false; } float m = (y2 - y1) / (x2 - x1); float y = m * (minX - x1) + y1; - if (y > minY && y < maxY) - { + if (y > minY && y < maxY) { return true; } y = m * (maxX - x1) + y1; - if (y > minY && y < maxY) - { + if (y > minY && y < maxY) { return true; } float x = (minY - y1) / m + x1; - if (x > minX && x < maxX) - { + if (x > minX && x < maxX) { return true; } x = (maxY - y1) / m + x1; - if (x > minX && x < maxX) - { + if (x > minX && x < maxX) { return true; } return false; } - bool SkeletonBounds::aabbIntersectsSkeleton(SkeletonBounds bounds) - { + bool SkeletonBounds::aabbIntersectsSkeleton(SkeletonBounds bounds) { return _minX < bounds._maxX && _maxX > bounds._minX && _minY < bounds._maxY && _maxY > bounds._minY; } - bool SkeletonBounds::containsPoint(Polygon* polygon, float x, float y) - { + bool SkeletonBounds::containsPoint(Polygon* polygon, float x, float y) { Vector& vertices = polygon->_vertices; int nn = polygon->_count; int prevIndex = nn - 2; bool inside = false; - for (int ii = 0; ii < nn; ii += 2) - { + for (int ii = 0; ii < nn; ii += 2) { float vertexY = vertices[ii + 1]; float prevY = vertices[prevIndex + 1]; - if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) - { + if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) { float vertexX = vertices[ii]; - if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x) - { + if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x) { inside = !inside; } } @@ -176,12 +154,9 @@ namespace Spine return inside; } - BoundingBoxAttachment* SkeletonBounds::containsPoint(float x, float y) - { - for (int i = 0, n = static_cast(_polygons.size()); i < n; ++i) - { - if (containsPoint(_polygons[i], x, y)) - { + BoundingBoxAttachment* SkeletonBounds::containsPoint(float x, float y) { + for (int i = 0, n = static_cast(_polygons.size()); i < n; ++i) { + if (containsPoint(_polygons[i], x, y)) { return _boundingBoxes[i]; } } @@ -189,38 +164,31 @@ namespace Spine return NULL; } - BoundingBoxAttachment* SkeletonBounds::intersectsSegment(float x1, float y1, float x2, float y2) - { - for (int i = 0, n = static_cast(_polygons.size()); i < n; ++i) - { - if (intersectsSegment(_polygons[i], x1, y1, x2, y2)) - { + BoundingBoxAttachment* SkeletonBounds::intersectsSegment(float x1, float y1, float x2, float y2) { + for (int i = 0, n = static_cast(_polygons.size()); i < n; ++i) { + if (intersectsSegment(_polygons[i], x1, y1, x2, y2)) { return _boundingBoxes[i]; } } return NULL; } - bool SkeletonBounds::intersectsSegment(Polygon* polygon, float x1, float y1, float x2, float y2) - { + bool SkeletonBounds::intersectsSegment(Polygon* polygon, float x1, float y1, float x2, float y2) { Vector& vertices = polygon->_vertices; int nn = polygon->_count; float width12 = x1 - x2, height12 = y1 - y2; float det1 = x1 * y2 - y1 * x2; float x3 = vertices[nn - 2], y3 = vertices[nn - 1]; - for (int ii = 0; ii < nn; ii += 2) - { + for (int ii = 0; ii < nn; ii += 2) { float x4 = vertices[ii], y4 = vertices[ii + 1]; float det2 = x3 * y4 - y3 * x4; float width34 = x3 - x4, height34 = y3 - y4; float det3 = width12 * height34 - height12 * width34; float x = (det1 * width34 - width12 * det2) / det3; - if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) - { + if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) { float y = (det1 * height34 - height12 * det2) / det3; - if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1))) - { + if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1))) { return true; } } @@ -231,36 +199,30 @@ namespace Spine return false; } - Polygon* SkeletonBounds::getPolygon(BoundingBoxAttachment* attachment) - { + Polygon* SkeletonBounds::getPolygon(BoundingBoxAttachment* attachment) { int index = _boundingBoxes.indexOf(attachment); return index == -1 ? NULL : _polygons[index]; } - float SkeletonBounds::getWidth() - { + float SkeletonBounds::getWidth() { return _maxX - _minX; } - float SkeletonBounds::getHeight() - { + float SkeletonBounds::getHeight() { return _maxY - _minY; } - void SkeletonBounds::aabbCompute() - { + void SkeletonBounds::aabbCompute() { float minX = std::numeric_limits::min(); float minY = std::numeric_limits::min(); float maxX = std::numeric_limits::max(); float maxY = std::numeric_limits::max(); - for (int i = 0, n = static_cast(_polygons.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_polygons.size()); i < n; ++i) { Polygon* polygon = _polygons[i]; Vector& vertices = polygon->_vertices; - for (int ii = 0, nn = polygon->_count; ii < nn; ii += 2) - { + for (int ii = 0, nn = polygon->_count; ii < nn; ii += 2) { float x = vertices[ii]; float y = vertices[ii + 1]; minX = MIN(minX, x); diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonClipping.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonClipping.cpp index 69e7a958f..252856bf3 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonClipping.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonClipping.cpp @@ -35,18 +35,15 @@ namespace Spine { - SkeletonClipping::SkeletonClipping() : _clipAttachment(NULL) - { + SkeletonClipping::SkeletonClipping() : _clipAttachment(NULL) { _clipOutput.reserve(128); _clippedVertices.reserve(128); _clippedTriangles.reserve(128); _clippedUVs.reserve(128); } - int SkeletonClipping::clipStart(Slot& slot, ClippingAttachment* clip) - { - if (_clipAttachment != NULL) - { + int SkeletonClipping::clipStart(Slot& slot, ClippingAttachment* clip) { + if (_clipAttachment != NULL) { return 0; } @@ -61,8 +58,7 @@ namespace Spine _clippingPolygons = clippingPolygons; - for (Vector** i = _clippingPolygons.begin(); i != _clippingPolygons.end(); ++i) - { + for (Vector** i = _clippingPolygons.begin(); i != _clippingPolygons.end(); ++i) { Vector* polygonP = (*i); Vector& polygon = *polygonP; makeClockwise(polygon); @@ -73,18 +69,14 @@ namespace Spine return static_cast(_clippingPolygons.size()); } - void SkeletonClipping::clipEnd(Slot& slot) - { - if (_clipAttachment != NULL && _clipAttachment->_endSlot == &slot._data) - { + void SkeletonClipping::clipEnd(Slot& slot) { + if (_clipAttachment != NULL && _clipAttachment->_endSlot == &slot._data) { clipEnd(); } } - void SkeletonClipping::clipEnd() - { - if (_clipAttachment == NULL) - { + void SkeletonClipping::clipEnd() { + if (_clipAttachment == NULL) { return; } @@ -95,8 +87,7 @@ namespace Spine _clippingPolygon.clear(); } - void SkeletonClipping::clipTriangles(Vector& vertices, int verticesLength, Vector& triangles, int trianglesLength, Vector& uvs) - { + void SkeletonClipping::clipTriangles(Vector& vertices, int verticesLength, Vector& triangles, int trianglesLength, Vector& uvs) { Vector& clipOutput = _clipOutput; Vector& clippedVertices = _clippedVertices; Vector& clippedTriangles = _clippedTriangles; @@ -108,8 +99,7 @@ namespace Spine _clippedUVs.clear(); clippedTriangles.clear(); - for (int i = 0; i < trianglesLength; i += 3) - { + for (int i = 0; i < trianglesLength; i += 3) { int vertexOffset = triangles[i] << 1; float x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1]; float u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1]; @@ -122,14 +112,11 @@ namespace Spine float x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1]; float u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1]; - for (int p = 0; p < polygonsCount; p++) - { + for (int p = 0; p < polygonsCount; p++) { int s = static_cast(clippedVertices.size()); - if (clip(x1, y1, x2, y2, x3, y3, *polygons[p], clipOutput)) - { + if (clip(x1, y1, x2, y2, x3, y3, *polygons[p], clipOutput)) { int clipOutputLength = static_cast(clipOutput.size()); - if (clipOutputLength == 0) - { + if (clipOutputLength == 0) { continue; } float d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1; @@ -140,8 +127,7 @@ namespace Spine clippedVertices.setSize(s + clipOutputCount * 2); _clippedUVs.reserve(s + clipOutputCount * 2); _clippedUVs.setSize(s + clipOutputCount * 2); - for (int ii = 0; ii < clipOutputLength; ii += 2) - { + for (int ii = 0; ii < clipOutputLength; ii += 2) { float x = clipOutput[ii], y = clipOutput[ii + 1]; clippedVertices[s] = x; clippedVertices[s + 1] = y; @@ -158,8 +144,7 @@ namespace Spine clippedTriangles.reserve(s + 3 * (clipOutputCount - 2)); clippedTriangles.setSize(s + 3 * (clipOutputCount - 2)); clipOutputCount--; - for (int ii = 1; ii < clipOutputCount; ii++) - { + for (int ii = 1; ii < clipOutputCount; ii++) { clippedTriangles[s] = index; clippedTriangles[s + 1] = index + ii; clippedTriangles[s + 2] = index + ii + 1; @@ -167,8 +152,7 @@ namespace Spine } index += clipOutputCount + 1; } - else - { + else { clippedVertices.reserve(s + 3 * 2); clippedVertices.setSize(s + 3 * 2); _clippedUVs.reserve(s + 3 * 2); @@ -200,40 +184,33 @@ namespace Spine } } - bool SkeletonClipping::isClipping() - { + bool SkeletonClipping::isClipping() { return _clipAttachment != NULL; } - Vector& SkeletonClipping::getClippedVertices() - { + Vector& SkeletonClipping::getClippedVertices() { return _clippedVertices; } - Vector& SkeletonClipping::getClippedTriangles() - { + Vector& SkeletonClipping::getClippedTriangles() { return _clippedTriangles; } - Vector& SkeletonClipping::getClippedUVs() - { + Vector& SkeletonClipping::getClippedUVs() { return _clippedUVs; } - bool SkeletonClipping::clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector& clippingArea, Vector& output) - { + bool SkeletonClipping::clip(float x1, float y1, float x2, float y2, float x3, float y3, Vector& clippingArea, Vector& output) { Vector& originalOutput = output; bool clipped = false; // Avoid copy at the end. Vector input; - if (clippingArea.size() % 4 >= 2) - { + if (clippingArea.size() % 4 >= 2) { input = output; output = _scratch; } - else - { + else { input = _scratch; } @@ -250,23 +227,19 @@ namespace Spine Vector& clippingVertices = clippingArea; int clippingVerticesLast = static_cast(clippingArea.size()) - 4; - for (int i = 0; ; i += 2) - { + for (int i = 0; ; i += 2) { float edgeX = clippingVertices[i], edgeY = clippingVertices[i + 1]; float edgeX2 = clippingVertices[i + 2], edgeY2 = clippingVertices[i + 3]; float deltaX = edgeX - edgeX2, deltaY = edgeY - edgeY2; Vector& inputVertices = input; int inputVerticesLength = static_cast(input.size()) - 2, outputStart = static_cast(output.size()); - for (int ii = 0; ii < inputVerticesLength; ii += 2) - { + for (int ii = 0; ii < inputVerticesLength; ii += 2) { float inputX = inputVertices[ii], inputY = inputVertices[ii + 1]; float inputX2 = inputVertices[ii + 2], inputY2 = inputVertices[ii + 3]; bool side2 = deltaX * (inputY2 - edgeY2) - deltaY * (inputX2 - edgeX2) > 0; - if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) - { - if (side2) - { + if (deltaX * (inputY - edgeY2) - deltaY * (inputX - edgeX2) > 0) { + if (side2) { // v1 inside, v2 inside output.push_back(inputX2); output.push_back(inputY2); @@ -278,8 +251,7 @@ namespace Spine output.push_back(edgeX + (edgeX2 - edgeX) * ua); output.push_back(edgeY + (edgeY2 - edgeY) * ua); } - else if (side2) - { + else if (side2) { // v1 outside, v2 inside float c0 = inputY2 - inputY, c2 = inputX2 - inputX; float ua = (c2 * (edgeY - inputY) - c0 * (edgeX - inputX)) / (c0 * (edgeX2 - edgeX) - c2 * (edgeY2 - edgeY)); @@ -291,8 +263,7 @@ namespace Spine clipped = true; } - if (outputStart == output.size()) - { + if (outputStart == output.size()) { // All edges outside. originalOutput.clear(); return true; @@ -301,8 +272,7 @@ namespace Spine output.push_back(output[0]); output.push_back(output[1]); - if (i == clippingVerticesLast) - { + if (i == clippingVerticesLast) { break; } Vector temp = output; @@ -311,16 +281,13 @@ namespace Spine input = temp; } - if (originalOutput != output) - { + if (originalOutput != output) { originalOutput.clear(); - for (int i = 0, n = static_cast(output.size()) - 2; i < n; ++i) - { + for (int i = 0, n = static_cast(output.size()) - 2; i < n; ++i) { originalOutput.push_back(output[i]); } } - else - { + else { originalOutput.reserve(originalOutput.size() - 2); originalOutput.setSize(originalOutput.size() - 2); } @@ -328,14 +295,12 @@ namespace Spine return clipped; } - void SkeletonClipping::makeClockwise(Vector& polygon) - { + void SkeletonClipping::makeClockwise(Vector& polygon) { int verticeslength = static_cast(polygon.size()); float area = polygon[verticeslength - 2] * polygon[1] - polygon[0] * polygon[verticeslength - 1], p1x, p1y, p2x, p2y; - for (int i = 0, n = verticeslength - 3; i < n; i += 2) - { + for (int i = 0, n = verticeslength - 3; i < n; i += 2) { p1x = polygon[i]; p1y = polygon[i + 1]; p2x = polygon[i + 2]; @@ -343,13 +308,11 @@ namespace Spine area += p1x * p2y - p2x * p1y; } - if (area < 0) - { + if (area < 0) { return; } - for (int i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) - { + for (int i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) { float x = polygon[i], y = polygon[i + 1]; int other = lastX - i; polygon[i] = polygon[other]; diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonData.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonData.cpp index 8f5a337cc..6c8e09e1a 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonData.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonData.cpp @@ -53,13 +53,11 @@ namespace Spine _version(), _hash(), _fps(0), - _imagesPath() - { + _imagesPath() { // Empty } - SkeletonData::~SkeletonData() - { + SkeletonData::~SkeletonData() { ContainerUtil::cleanUpVectorOfPointers(_bones); ContainerUtil::cleanUpVectorOfPointers(_slots); ContainerUtil::cleanUpVectorOfPointers(_skins); @@ -73,208 +71,167 @@ namespace Spine ContainerUtil::cleanUpVectorOfPointers(_pathConstraints); } - BoneData* SkeletonData::findBone(std::string boneName) - { + BoneData* SkeletonData::findBone(std::string boneName) { return ContainerUtil::findWithName(_bones, boneName); } - int SkeletonData::findBoneIndex(std::string boneName) - { + int SkeletonData::findBoneIndex(std::string boneName) { return ContainerUtil::findIndexWithName(_bones, boneName); } - SlotData* SkeletonData::findSlot(std::string slotName) - { + SlotData* SkeletonData::findSlot(std::string slotName) { return ContainerUtil::findWithName(_slots, slotName); } - int SkeletonData::findSlotIndex(std::string slotName) - { + int SkeletonData::findSlotIndex(std::string slotName) { return ContainerUtil::findIndexWithName(_slots, slotName); } - Skin* SkeletonData::findSkin(std::string skinName) - { + Skin* SkeletonData::findSkin(std::string skinName) { return ContainerUtil::findWithName(_skins, skinName); } - EventData* SkeletonData::findEvent(std::string eventDataName) - { + EventData* SkeletonData::findEvent(std::string eventDataName) { return ContainerUtil::findWithName(_events, eventDataName); } - Animation* SkeletonData::findAnimation(std::string animationName) - { + Animation* SkeletonData::findAnimation(std::string animationName) { return ContainerUtil::findWithName(_animations, animationName); } - IkConstraintData* SkeletonData::findIkConstraint(std::string constraintName) - { + IkConstraintData* SkeletonData::findIkConstraint(std::string constraintName) { return ContainerUtil::findWithName(_ikConstraints, constraintName); } - TransformConstraintData* SkeletonData::findTransformConstraint(std::string constraintName) - { + TransformConstraintData* SkeletonData::findTransformConstraint(std::string constraintName) { return ContainerUtil::findWithName(_transformConstraints, constraintName); } - PathConstraintData* SkeletonData::findPathConstraint(std::string constraintName) - { + PathConstraintData* SkeletonData::findPathConstraint(std::string constraintName) { return ContainerUtil::findWithName(_pathConstraints, constraintName); } - int SkeletonData::findPathConstraintIndex(std::string pathConstraintName) - { + int SkeletonData::findPathConstraintIndex(std::string pathConstraintName) { return ContainerUtil::findIndexWithName(_pathConstraints, pathConstraintName); } - std::string SkeletonData::getName() - { + std::string SkeletonData::getName() { return _name; } - void SkeletonData::setName(std::string inValue) - { + void SkeletonData::setName(std::string inValue) { _name = inValue; } - Vector& SkeletonData::getBones() - { + Vector& SkeletonData::getBones() { return _bones; } - Vector& SkeletonData::getSlots() - { + Vector& SkeletonData::getSlots() { return _slots; } - Vector& SkeletonData::getSkins() - { + Vector& SkeletonData::getSkins() { return _skins; } - void SkeletonData::setSkins(Vector& inValue) - { + void SkeletonData::setSkins(Vector& inValue) { _skins = inValue; } - Skin* SkeletonData::getDefaultSkin() - { + Skin* SkeletonData::getDefaultSkin() { return _defaultSkin; } - void SkeletonData::setDefaultSkin(Skin* inValue) - { + void SkeletonData::setDefaultSkin(Skin* inValue) { _defaultSkin = inValue; } - Vector& SkeletonData::getEvents() - { + Vector& SkeletonData::getEvents() { return _events; } - void SkeletonData::setEvents(Vector& inValue) - { + void SkeletonData::setEvents(Vector& inValue) { _events = inValue; } - Vector& SkeletonData::getAnimations() - { + Vector& SkeletonData::getAnimations() { return _animations; } - void SkeletonData::setAnimations(Vector& inValue) - { + void SkeletonData::setAnimations(Vector& inValue) { _animations = inValue; } - Vector& SkeletonData::getIkConstraints() - { + Vector& SkeletonData::getIkConstraints() { return _ikConstraints; } - void SkeletonData::setIkConstraints(Vector& inValue) - { + void SkeletonData::setIkConstraints(Vector& inValue) { _ikConstraints = inValue; } - Vector& SkeletonData::getTransformConstraints() - { + Vector& SkeletonData::getTransformConstraints() { return _transformConstraints; } - void SkeletonData::setTransformConstraints(Vector& inValue) - { + void SkeletonData::setTransformConstraints(Vector& inValue) { _transformConstraints = inValue; } - Vector& SkeletonData::getPathConstraints() - { + Vector& SkeletonData::getPathConstraints() { return _pathConstraints; } - void SkeletonData::setPathConstraints(Vector& inValue) - { + void SkeletonData::setPathConstraints(Vector& inValue) { _pathConstraints = inValue; } - float SkeletonData::getWidth() - { + float SkeletonData::getWidth() { return _width; } - void SkeletonData::setWidth(float inValue) - { + void SkeletonData::setWidth(float inValue) { _width = inValue; } - float SkeletonData::getHeight() - { + float SkeletonData::getHeight() { return _height; } - void SkeletonData::setHeight(float inValue) - { + void SkeletonData::setHeight(float inValue) { _height = inValue; } - std::string SkeletonData::getVersion() - { + std::string SkeletonData::getVersion() { return _version; } - void SkeletonData::setVersion(std::string inValue) - { + void SkeletonData::setVersion(std::string inValue) { _version = inValue; } - std::string SkeletonData::getHash() - { + std::string SkeletonData::getHash() { return _hash; } - void SkeletonData::setHash(std::string inValue) - { + void SkeletonData::setHash(std::string inValue) { _hash = inValue; } - std::string SkeletonData::getImagesPath() - { + std::string SkeletonData::getImagesPath() { return _imagesPath; } - void SkeletonData::setImagesPath(std::string inValue) - { + void SkeletonData::setImagesPath(std::string inValue) { _imagesPath = inValue; } - float SkeletonData::getFps() - { + float SkeletonData::getFps() { return _fps; } - void SkeletonData::setFps(float inValue) - { + void SkeletonData::setFps(float inValue) { _fps = inValue; } } diff --git a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp index 2642e069d..fe11fe698 100644 --- a/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp +++ b/spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp @@ -87,33 +87,27 @@ namespace Spine { - SkeletonJson::SkeletonJson(Vector& atlasArray) : _attachmentLoader(NEW(AtlasAttachmentLoader)), _scale(1), _ownsLoader(true) - { + SkeletonJson::SkeletonJson(Vector& atlasArray) : _attachmentLoader(NEW(AtlasAttachmentLoader)), _scale(1), _ownsLoader(true) { new (_attachmentLoader) AtlasAttachmentLoader(atlasArray); } - SkeletonJson::SkeletonJson(AttachmentLoader* attachmentLoader) : _attachmentLoader(attachmentLoader), _scale(1), _ownsLoader(false) - { + SkeletonJson::SkeletonJson(AttachmentLoader* attachmentLoader) : _attachmentLoader(attachmentLoader), _scale(1), _ownsLoader(false) { assert(_attachmentLoader != NULL); } - SkeletonJson::~SkeletonJson() - { + SkeletonJson::~SkeletonJson() { ContainerUtil::cleanUpVectorOfPointers(_linkedMeshes); - if (_ownsLoader) - { + if (_ownsLoader) { DESTROY(AttachmentLoader, _attachmentLoader); } } - SkeletonData* SkeletonJson::readSkeletonDataFile(const char* path) - { + SkeletonData* SkeletonJson::readSkeletonDataFile(const char* path) { int length; SkeletonData* skeletonData; const char* json = SPINE_EXTENSION->spineReadFile(path, &length); - if (length == 0 || !json) - { + if (length == 0 || !json) { setError(NULL, "Unable to read skeleton file: ", path); return NULL; } @@ -125,8 +119,7 @@ namespace Spine return skeletonData; } - SkeletonData* SkeletonJson::readSkeletonData(const char* json) - { + SkeletonData* SkeletonJson::readSkeletonData(const char* json) { int i, ii; SkeletonData* skeletonData; Json *root, *skeleton, *bones, *boneMap, *ik, *transform, *path, *slots, *skins, *animations, *events; @@ -137,8 +130,7 @@ namespace Spine root = NEW(Json); new (root) Json(json); - if (!root) - { + if (!root) { setError(NULL, "Invalid skeleton JSON: ", Json::getError()); return NULL; } @@ -147,8 +139,7 @@ namespace Spine new (skeletonData) SkeletonData(); skeleton = Json::getItem(root, "skeleton"); - if (skeleton) - { + if (skeleton) { skeletonData->_hash = Json::getString(skeleton, "hash", 0); skeletonData->_version = Json::getString(skeleton, "spine", 0); skeletonData->_width = Json::getFloat(skeleton, "width", 0); @@ -160,18 +151,15 @@ namespace Spine skeletonData->_bones.reserve(bones->_size); skeletonData->_bones.setSize(bones->_size); int bonesCount = 0; - for (boneMap = bones->_child, i = 0; boneMap; boneMap = boneMap->_next, ++i) - { + for (boneMap = bones->_child, i = 0; boneMap; boneMap = boneMap->_next, ++i) { BoneData* data; const char* transformMode; BoneData* parent = 0; const char* parentName = Json::getString(boneMap, "parent", 0); - if (parentName) - { + if (parentName) { parent = skeletonData->findBone(parentName); - if (!parent) - { + if (!parent) { DESTROY(SkeletonData, skeletonData); setError(root, "Parent bone not found: ", parentName); return NULL; @@ -191,24 +179,19 @@ namespace Spine data->_shearY = Json::getFloat(boneMap, "shearY", 0); transformMode = Json::getString(boneMap, "transform", "normal"); data->_transformMode = TransformMode_Normal; - if (strcmp(transformMode, "normal") == 0) - { + if (strcmp(transformMode, "normal") == 0) { data->_transformMode = TransformMode_Normal; } - if (strcmp(transformMode, "onlyTranslation") == 0) - { + if (strcmp(transformMode, "onlyTranslation") == 0) { data->_transformMode = TransformMode_OnlyTranslation; } - if (strcmp(transformMode, "noRotationOrReflection") == 0) - { + if (strcmp(transformMode, "noRotationOrReflection") == 0) { data->_transformMode = TransformMode_NoRotationOrReflection; } - if (strcmp(transformMode, "noScale") == 0) - { + if (strcmp(transformMode, "noScale") == 0) { data->_transformMode = TransformMode_NoScale; } - if (strcmp(transformMode, "noScaleOrReflection") == 0) - { + if (strcmp(transformMode, "noScaleOrReflection") == 0) { data->_transformMode = TransformMode_NoScaleOrReflection; } @@ -218,13 +201,11 @@ namespace Spine /* Slots. */ slots = Json::getItem(root, "slots"); - if (slots) - { + if (slots) { Json *slotMap; skeletonData->_slots.reserve(slots->_size); skeletonData->_slots.setSize(slots->_size); - for (slotMap = slots->_child, i = 0; slotMap; slotMap = slotMap->_next, ++i) - { + for (slotMap = slots->_child, i = 0; slotMap; slotMap = slotMap->_next, ++i) { SlotData* data; const char* color; const char* dark; @@ -232,8 +213,7 @@ namespace Spine const char* boneName = Json::getString(slotMap, "bone", 0); BoneData* boneData = skeletonData->findBone(boneName); - if (!boneData) - { + if (!boneData) { DESTROY(SkeletonData, skeletonData); setError(root, "Slot bone not found: ", boneName); return NULL; @@ -243,8 +223,7 @@ namespace Spine new (data) SlotData(i, Json::getString(slotMap, "name", 0), *boneData); color = Json::getString(slotMap, "color", 0); - if (color) - { + if (color) { data->_r = toColor(color, 0); data->_g = toColor(color, 1); data->_b = toColor(color, 2); @@ -252,8 +231,7 @@ namespace Spine } dark = Json::getString(slotMap, "dark", 0); - if (dark) - { + if (dark) { data->_r2 = toColor(dark, 0); data->_g2 = toColor(dark, 1); data->_b2 = toColor(dark, 2); @@ -262,24 +240,19 @@ namespace Spine } item = Json::getItem(slotMap, "attachment"); - if (item) - { + if (item) { data->setAttachmentName(item->_valueString); } item = Json::getItem(slotMap, "blend"); - if (item) - { - if (strcmp(item->_valueString, "additive") == 0) - { + if (item) { + if (strcmp(item->_valueString, "additive") == 0) { data->_blendMode = BlendMode_Additive; } - else if (strcmp(item->_valueString, "multiply") == 0) - { + else if (strcmp(item->_valueString, "multiply") == 0) { data->_blendMode = BlendMode_Multiply; } - else if (strcmp(item->_valueString, "screen") == 0) - { + else if (strcmp(item->_valueString, "screen") == 0) { data->_blendMode = BlendMode_Screen; } } @@ -290,13 +263,11 @@ namespace Spine /* IK constraints. */ ik = Json::getItem(root, "ik"); - if (ik) - { + if (ik) { Json *constraintMap; skeletonData->_ikConstraints.reserve(ik->_size); skeletonData->_ikConstraints.setSize(ik->_size); - for (constraintMap = ik->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) - { + for (constraintMap = ik->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) { const char* targetName; IkConstraintData* data = NEW(IkConstraintData); @@ -307,11 +278,9 @@ namespace Spine boneMap = Json::getItem(constraintMap, "bones"); data->_bones.reserve(boneMap->_size); data->_bones.setSize(boneMap->_size); - for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii) - { + for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii) { data->_bones[ii] = skeletonData->findBone(boneMap->_valueString); - if (!data->_bones[ii]) - { + if (!data->_bones[ii]) { DESTROY(SkeletonData, skeletonData); setError(root, "IK bone not found: ", boneMap->_valueString); return NULL; @@ -320,8 +289,7 @@ namespace Spine targetName = Json::getString(constraintMap, "target", 0); data->_target = skeletonData->findBone(targetName); - if (!data->_target) - { + if (!data->_target) { DESTROY(SkeletonData, skeletonData); setError(root, "Target bone not found: ", boneMap->_name); return NULL; @@ -336,13 +304,11 @@ namespace Spine /* Transform constraints. */ transform = Json::getItem(root, "transform"); - if (transform) - { + if (transform) { Json *constraintMap; skeletonData->_transformConstraints.reserve(transform->_size); skeletonData->_transformConstraints.setSize(transform->_size); - for (constraintMap = transform->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) - { + for (constraintMap = transform->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) { const char* name; TransformConstraintData* data = NEW(TransformConstraintData); @@ -353,11 +319,9 @@ namespace Spine boneMap = Json::getItem(constraintMap, "bones"); data->_bones.reserve(boneMap->_size); data->_bones.setSize(boneMap->_size); - for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii) - { + for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii) { data->_bones[ii] = skeletonData->findBone(boneMap->_valueString); - if (!data->_bones[ii]) - { + if (!data->_bones[ii]) { DESTROY(SkeletonData, skeletonData); setError(root, "Transform bone not found: ", boneMap->_valueString); return NULL; @@ -366,8 +330,7 @@ namespace Spine name = Json::getString(constraintMap, "target", 0); data->_target = skeletonData->findBone(name); - if (!data->_target) - { + if (!data->_target) { DESTROY(SkeletonData, skeletonData); setError(root, "Target bone not found: ", boneMap->_name); return NULL; @@ -393,13 +356,11 @@ namespace Spine /* Path constraints */ path = Json::getItem(root, "path"); - if (path) - { + if (path) { Json *constraintMap; skeletonData->_pathConstraints.reserve(path->_size); skeletonData->_pathConstraints.setSize(path->_size); - for (constraintMap = path->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) - { + for (constraintMap = path->_child, i = 0; constraintMap; constraintMap = constraintMap->_next, ++i) { const char* name; const char* item; @@ -411,11 +372,9 @@ namespace Spine boneMap = Json::getItem(constraintMap, "bones"); data->_bones.reserve(boneMap->_size); data->_bones.setSize(boneMap->_size); - for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii) - { + for (boneMap = boneMap->_child, ii = 0; boneMap; boneMap = boneMap->_next, ++ii) { data->_bones[ii] = skeletonData->findBone(boneMap->_valueString); - if (!data->_bones[ii]) - { + if (!data->_bones[ii]) { DESTROY(SkeletonData, skeletonData); setError(root, "Path bone not found: ", boneMap->_valueString); return NULL; @@ -424,60 +383,49 @@ namespace Spine name = Json::getString(constraintMap, "target", 0); data->_target = skeletonData->findSlot(name); - if (!data->_target) - { + if (!data->_target) { DESTROY(SkeletonData, skeletonData); setError(root, "Target slot not found: ", boneMap->_name); return NULL; } item = Json::getString(constraintMap, "positionMode", "percent"); - if (strcmp(item, "fixed") == 0) - { + if (strcmp(item, "fixed") == 0) { data->_positionMode = PositionMode_Fixed; } - else if (strcmp(item, "percent") == 0) - { + else if (strcmp(item, "percent") == 0) { data->_positionMode = PositionMode_Percent; } item = Json::getString(constraintMap, "spacingMode", "length"); - if (strcmp(item, "length") == 0) - { + if (strcmp(item, "length") == 0) { data->_spacingMode = SpacingMode_Length; } - else if (strcmp(item, "fixed") == 0) - { + else if (strcmp(item, "fixed") == 0) { data->_spacingMode = SpacingMode_Fixed; } - else if (strcmp(item, "percent") == 0) - { + else if (strcmp(item, "percent") == 0) { data->_spacingMode = SpacingMode_Percent; } item = Json::getString(constraintMap, "rotateMode", "tangent"); - if (strcmp(item, "tangent") == 0) - { + if (strcmp(item, "tangent") == 0) { data->_rotateMode = RotateMode_Tangent; } - else if (strcmp(item, "chain") == 0) - { + else if (strcmp(item, "chain") == 0) { data->_rotateMode = RotateMode_Chain; } - else if (strcmp(item, "chainScale") == 0) - { + else if (strcmp(item, "chainScale") == 0) { data->_rotateMode = RotateMode_ChainScale; } data->_offsetRotation = Json::getFloat(constraintMap, "rotation", 0); data->_position = Json::getFloat(constraintMap, "position", 0); - if (data->_positionMode == PositionMode_Fixed) - { + if (data->_positionMode == PositionMode_Fixed) { data->_position *= _scale; } data->_spacing = Json::getFloat(constraintMap, "spacing", 0); - if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) - { + if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) { data->_spacing *= _scale; } data->_rotateMix = Json::getFloat(constraintMap, "rotateMix", 1); @@ -489,14 +437,12 @@ namespace Spine /* Skins. */ skins = Json::getItem(root, "skins"); - if (skins) - { + if (skins) { Json *skinMap; skeletonData->_skins.reserve(skins->_size); skeletonData->_skins.setSize(skins->_size); int skinsIndex = 0; - for (skinMap = skins->_child, i = 0; skinMap; skinMap = skinMap->_next, ++i) - { + for (skinMap = skins->_child, i = 0; skinMap; skinMap = skinMap->_next, ++i) { Json *attachmentsMap; Json *curves; @@ -504,18 +450,15 @@ namespace Spine new (skin) Skin(skinMap->_name); skeletonData->_skins[skinsIndex++] = skin; - if (strcmp(skinMap->_name, "default") == 0) - { + if (strcmp(skinMap->_name, "default") == 0) { skeletonData->_defaultSkin = skin; } - for (attachmentsMap = skinMap->_child; attachmentsMap; attachmentsMap = attachmentsMap->_next) - { + for (attachmentsMap = skinMap->_child; attachmentsMap; attachmentsMap = attachmentsMap->_next) { int slotIndex = skeletonData->findSlotIndex(attachmentsMap->_name); Json *attachmentMap; - for (attachmentMap = attachmentsMap->_child; attachmentMap; attachmentMap = attachmentMap->_next) - { + for (attachmentMap = attachmentsMap->_child; attachmentMap; attachmentMap = attachmentMap->_next) { Attachment* attachment; const char* skinAttachmentName = attachmentMap->_name; const char* attachmentName = Json::getString(attachmentMap, "name", skinAttachmentName); @@ -525,44 +468,34 @@ namespace Spine const char* typeString = Json::getString(attachmentMap, "type", "region"); AttachmentType type; - if (strcmp(typeString, "region") == 0) - { + if (strcmp(typeString, "region") == 0) { type = AttachmentType_Region; } - else if (strcmp(typeString, "mesh") == 0) - { + else if (strcmp(typeString, "mesh") == 0) { type = AttachmentType_Mesh; } - else if (strcmp(typeString, "linkedmesh") == 0) - { + else if (strcmp(typeString, "linkedmesh") == 0) { type = AttachmentType_Linkedmesh; } - else if (strcmp(typeString, "boundingbox") == 0) - { + else if (strcmp(typeString, "boundingbox") == 0) { type = AttachmentType_Boundingbox; } - else if (strcmp(typeString, "path") == 0) - { + else if (strcmp(typeString, "path") == 0) { type = AttachmentType_Path; } - else if (strcmp(typeString, "clipping") == 0) - { + else if (strcmp(typeString, "clipping") == 0) { type = AttachmentType_Clipping; } - else - { + else { DESTROY(SkeletonData, skeletonData); setError(root, "Unknown attachment type: ", typeString); return NULL; } - switch (type) - { - case AttachmentType_Region: - { + switch (type) { + case AttachmentType_Region: { attachment = _attachmentLoader->newRegionAttachment(*skin, attachmentName, attachmentPath); - if (!attachment) - { + if (!attachment) { DESTROY(SkeletonData, skeletonData); setError(root, "Error reading attachment: ", skinAttachmentName); return NULL; @@ -580,8 +513,7 @@ namespace Spine region->_height = Json::getFloat(attachmentMap, "height", 32) * _scale; color = Json::getString(attachmentMap, "color", 0); - if (color) - { + if (color) { region->_r = toColor(color, 0); region->_g = toColor(color, 1); region->_b = toColor(color, 2); @@ -593,16 +525,14 @@ namespace Spine break; } case AttachmentType_Mesh: - case AttachmentType_Linkedmesh: - { + case AttachmentType_Linkedmesh: { attachment = _attachmentLoader->newMeshAttachment(*skin, attachmentName, attachmentPath); MeshAttachment* mesh = static_cast(attachment); mesh->_path = attachmentPath; color = Json::getString(attachmentMap, "color", 0); - if (color) - { + if (color) { mesh->_r = toColor(color, 0); mesh->_g = toColor(color, 1); mesh->_b = toColor(color, 2); @@ -613,14 +543,12 @@ namespace Spine mesh->_height = Json::getFloat(attachmentMap, "height", 32) * _scale; entry = Json::getItem(attachmentMap, "parent"); - if (!entry) - { + if (!entry) { int verticesLength; entry = Json::getItem(attachmentMap, "triangles"); mesh->_triangles.reserve(entry->_size); mesh->_triangles.setSize(entry->_size); - for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) - { + for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) { mesh->_triangles[ii] = (unsigned short)entry->_valueInt; } @@ -628,8 +556,7 @@ namespace Spine verticesLength = entry->_size; mesh->_regionUVs.reserve(verticesLength); mesh->_regionUVs.setSize(verticesLength); - for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) - { + for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) { mesh->_regionUVs[ii] = entry->_valueFloat; } @@ -640,18 +567,15 @@ namespace Spine mesh->_hullLength = Json::getInt(attachmentMap, "hull", 0); entry = Json::getItem(attachmentMap, "edges"); - if (entry) - { + if (entry) { mesh->_edges.reserve(entry->_size); mesh->_edges.setSize(entry->_size); - for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) - { + for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii) { mesh->_edges[ii] = entry->_valueInt; } } } - else - { + else { mesh->_inheritDeform = Json::getInt(attachmentMap, "deform", 1); LinkedMesh* linkedMesh = NEW(LinkedMesh); new (linkedMesh) LinkedMesh(mesh, std::string(Json::getString(attachmentMap, "skin", 0)), slotIndex, std::string(entry->_valueString)); @@ -659,8 +583,7 @@ namespace Spine } break; } - case AttachmentType_Boundingbox: - { + case AttachmentType_Boundingbox: { attachment = _attachmentLoader->newBoundingBoxAttachment(*skin, attachmentName); BoundingBoxAttachment* box = static_cast(attachment); @@ -669,8 +592,7 @@ namespace Spine readVertices(attachmentMap, box, vertexCount); break; } - case AttachmentType_Path: - { + case AttachmentType_Path: { attachment = _attachmentLoader->newPathAttachment(*skin, attachmentName); PathAttachment* pathAttatchment = static_cast(attachment); @@ -685,14 +607,12 @@ namespace Spine pathAttatchment->_lengths.setSize(vertexCount / 3); curves = Json::getItem(attachmentMap, "lengths"); - for (curves = curves->_child, ii = 0; curves; curves = curves->_next, ++ii) - { + for (curves = curves->_child, ii = 0; curves; curves = curves->_next, ++ii) { pathAttatchment->_lengths[ii] = curves->_valueFloat * _scale; } break; } - case AttachmentType_Point: - { + case AttachmentType_Point: { attachment = _attachmentLoader->newPointAttachment(*skin, attachmentName); PointAttachment* point = static_cast(attachment); @@ -702,16 +622,14 @@ namespace Spine point->_rotation = Json::getFloat(attachmentMap, "rotation", 0); break; } - case AttachmentType_Clipping: - { + case AttachmentType_Clipping: { attachment = _attachmentLoader->newClippingAttachment(*skin, attachmentName); ClippingAttachment* clip = static_cast(attachment); int vertexCount = 0; const char* end = Json::getString(attachmentMap, "end", 0); - if (end) - { + if (end) { SlotData* slot = skeletonData->findSlot(end); clip->_endSlot = slot; } @@ -728,19 +646,16 @@ namespace Spine } /* Linked meshes. */ - for (int i = 0, n = static_cast(_linkedMeshes.size()); i < n; ++i) - { + for (int i = 0, n = static_cast(_linkedMeshes.size()); i < n; ++i) { LinkedMesh* linkedMesh = _linkedMeshes[i]; Skin* skin = linkedMesh->_skin.length() == 0 ? skeletonData->getDefaultSkin() : skeletonData->findSkin(linkedMesh->_skin); - if (skin == NULL) - { + if (skin == NULL) { DESTROY(SkeletonData, skeletonData); setError(root, "Skin not found: ", linkedMesh->_skin.c_str()); return NULL; } Attachment* parent = skin->getAttachment(linkedMesh->_slotIndex, linkedMesh->_parent); - if (parent == NULL) - { + if (parent == NULL) { DESTROY(SkeletonData, skeletonData); setError(root, "Parent mesh not found: ", linkedMesh->_parent.c_str()); return NULL; @@ -752,13 +667,11 @@ namespace Spine /* Events. */ events = Json::getItem(root, "events"); - if (events) - { + if (events) { Json *eventMap; skeletonData->_events.reserve(events->_size); skeletonData->_events.setSize(events->_size); - for (eventMap = events->_child, i = 0; eventMap; eventMap = eventMap->_next, ++i) - { + for (eventMap = events->_child, i = 0; eventMap; eventMap = eventMap->_next, ++i) { EventData* eventData = NEW(EventData); new (eventData) EventData(std::string(eventMap->_name)); @@ -772,17 +685,14 @@ namespace Spine /* Animations. */ animations = Json::getItem(root, "animations"); - if (animations) - { + if (animations) { Json *animationMap; skeletonData->_animations.reserve(animations->_size); skeletonData->_animations.setSize(animations->_size); int animationsIndex = 0; - for (animationMap = animations->_child; animationMap; animationMap = animationMap->_next) - { + for (animationMap = animations->_child; animationMap; animationMap = animationMap->_next) { Animation* animation = readAnimation(animationMap, skeletonData); - if (!animation) - { + if (!animation) { DESTROY(SkeletonData, skeletonData); DESTROY(Json, root); return NULL; @@ -796,14 +706,12 @@ namespace Spine return skeletonData; } - float SkeletonJson::toColor(const char* value, int index) - { + float SkeletonJson::toColor(const char* value, int index) { char digits[3]; char *error; int color; - if (index >= strlen(value) / 2) - { + if (index >= strlen(value) / 2) { return -1; } @@ -813,27 +721,22 @@ namespace Spine digits[1] = *(value + 1); digits[2] = '\0'; color = (int)strtoul(digits, &error, 16); - if (*error != 0) - { + if (*error != 0) { return -1; } return color / (float)255; } - void SkeletonJson::readCurve(Json* frame, CurveTimeline* timeline, int frameIndex) - { + void SkeletonJson::readCurve(Json* frame, CurveTimeline* timeline, int frameIndex) { Json* curve = Json::getItem(frame, "curve"); - if (!curve) - { + if (!curve) { return; } - if (curve->_type == Json::JSON_STRING && strcmp(curve->_valueString, "stepped") == 0) - { + if (curve->_type == Json::JSON_STRING && strcmp(curve->_valueString, "stepped") == 0) { timeline->setStepped(frameIndex); } - else if (curve->_type == Json::JSON_ARRAY) - { + else if (curve->_type == Json::JSON_ARRAY) { Json* child0 = curve->_child; Json* child1 = child0->_next; Json* child2 = child1->_next; @@ -842,8 +745,7 @@ namespace Spine } } - Animation* SkeletonJson::readAnimation(Json* root, SkeletonData *skeletonData) - { + Animation* SkeletonJson::readAnimation(Json* root, SkeletonData *skeletonData) { Vector timelines; float duration = 0; @@ -860,71 +762,58 @@ namespace Spine Json* drawOrder = Json::getItem(root, "drawOrder"); Json* events = Json::getItem(root, "events"); Json *boneMap, *slotMap, *constraintMap; - if (!drawOrder) - { + if (!drawOrder) { drawOrder = Json::getItem(root, "draworder"); } - for (boneMap = bones ? bones->_child : NULL; boneMap; boneMap = boneMap->_next) - { + for (boneMap = bones ? bones->_child : NULL; boneMap; boneMap = boneMap->_next) { timelinesCount += boneMap->_size; } - for (slotMap = slots ? slots->_child : NULL; slotMap; slotMap = slotMap->_next) - { + for (slotMap = slots ? slots->_child : NULL; slotMap; slotMap = slotMap->_next) { timelinesCount += slotMap->_size; } timelinesCount += ik ? ik->_size : 0; timelinesCount += transform ? transform->_size : 0; - for (constraintMap = paths ? paths->_child : NULL; constraintMap; constraintMap = constraintMap->_next) - { + for (constraintMap = paths ? paths->_child : NULL; constraintMap; constraintMap = constraintMap->_next) { timelinesCount += constraintMap->_size; } - for (constraintMap = deform ? deform->_child : NULL; constraintMap; constraintMap = constraintMap->_next) - { - for (slotMap = constraintMap->_child; slotMap; slotMap = slotMap->_next) - { + for (constraintMap = deform ? deform->_child : NULL; constraintMap; constraintMap = constraintMap->_next) { + for (slotMap = constraintMap->_child; slotMap; slotMap = slotMap->_next) { timelinesCount += slotMap->_size; } } - if (drawOrder) - { + if (drawOrder) { ++timelinesCount; } - if (events) - { + if (events) { ++timelinesCount; } /** Slot timelines. */ - for (slotMap = slots ? slots->_child : 0; slotMap; slotMap = slotMap->_next) - { + for (slotMap = slots ? slots->_child : 0; slotMap; slotMap = slotMap->_next) { Json *timelineMap; int slotIndex = skeletonData->findSlotIndex(slotMap->_name); - if (slotIndex == -1) - { + if (slotIndex == -1) { ContainerUtil::cleanUpVectorOfPointers(timelines); setError(NULL, "Slot not found: ", slotMap->_name); return NULL; } - for (timelineMap = slotMap->_child; timelineMap; timelineMap = timelineMap->_next) - { - if (strcmp(timelineMap->_name, "attachment") == 0) - { + for (timelineMap = slotMap->_child; timelineMap; timelineMap = timelineMap->_next) { + if (strcmp(timelineMap->_name, "attachment") == 0) { AttachmentTimeline *timeline = NEW(AttachmentTimeline); new (timeline) AttachmentTimeline(timelineMap->_size); timeline->_slotIndex = slotIndex; - for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { Json* name = Json::getItem(valueMap, "name"); std::string attachmentName = name->_type == Json::JSON_NULL ? std::string("") : std::string(name->_valueString); timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), attachmentName); @@ -934,15 +823,13 @@ namespace Spine duration = MAX(duration, timeline->_frames[timelineMap->_size - 1]); } - else if (strcmp(timelineMap->_name, "color") == 0) - { + else if (strcmp(timelineMap->_name, "color") == 0) { ColorTimeline *timeline = NEW(ColorTimeline); new (timeline) ColorTimeline(timelineMap->_size); timeline->_slotIndex = slotIndex; - for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { const char* s = Json::getString(valueMap, "color", 0); timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), toColor(s, 0), toColor(s, 1), toColor(s, 2), toColor(s, 3)); readCurve(valueMap, timeline, frameIndex); @@ -952,15 +839,13 @@ namespace Spine duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * ColorTimeline::ENTRIES]); } - else if (strcmp(timelineMap->_name, "twoColor") == 0) - { + else if (strcmp(timelineMap->_name, "twoColor") == 0) { TwoColorTimeline *timeline = NEW(TwoColorTimeline); new (timeline) TwoColorTimeline(timelineMap->_size); timeline->_slotIndex = slotIndex; - for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { const char* s = Json::getString(valueMap, "light", 0); const char* ds = Json::getString(valueMap, "dark", 0); timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), toColor(s, 0), toColor(s, 1), toColor(s, 2), @@ -971,8 +856,7 @@ namespace Spine timelinesCount++; duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * TwoColorTimeline::ENTRIES]); } - else - { + else { ContainerUtil::cleanUpVectorOfPointers(timelines); setError(NULL, "Invalid timeline type for a slot: ", timelineMap->_name); return NULL; @@ -981,29 +865,24 @@ namespace Spine } /** Bone timelines. */ - for (boneMap = bones ? bones->_child : 0; boneMap; boneMap = boneMap->_next) - { + for (boneMap = bones ? bones->_child : 0; boneMap; boneMap = boneMap->_next) { Json *timelineMap; int boneIndex = skeletonData->findBoneIndex(boneMap->_name); - if (boneIndex == -1) - { + if (boneIndex == -1) { ContainerUtil::cleanUpVectorOfPointers(timelines); setError(NULL, "Bone not found: ", boneMap->_name); return NULL; } - for (timelineMap = boneMap->_child; timelineMap; timelineMap = timelineMap->_next) - { - if (strcmp(timelineMap->_name, "rotate") == 0) - { + for (timelineMap = boneMap->_child; timelineMap; timelineMap = timelineMap->_next) { + if (strcmp(timelineMap->_name, "rotate") == 0) { RotateTimeline *timeline = NEW(RotateTimeline); new (timeline) RotateTimeline(timelineMap->_size); timeline->_boneIndex = boneIndex; - for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "angle", 0)); readCurve(valueMap, timeline, frameIndex); } @@ -1011,34 +890,28 @@ namespace Spine timelinesCount++; duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * RotateTimeline::ENTRIES]); } - else - { + else { int isScale = strcmp(timelineMap->_name, "scale") == 0; int isTranslate = strcmp(timelineMap->_name, "translate") == 0; int isShear = strcmp(timelineMap->_name, "shear") == 0; - if (isScale || isTranslate || isShear) - { + if (isScale || isTranslate || isShear) { float timelineScale = isTranslate ? _scale: 1; TranslateTimeline *timeline = 0; - if (isScale) - { + if (isScale) { timeline = NEW(ScaleTimeline); new (timeline) ScaleTimeline(timelineMap->_size); } - else if (isTranslate) - { + else if (isTranslate) { timeline = NEW(TranslateTimeline); new (timeline) TranslateTimeline(timelineMap->_size); } - else if (isShear) - { + else if (isShear) { timeline = NEW(ShearTimeline); new (timeline) ShearTimeline(timelineMap->_size); } timeline->_boneIndex = boneIndex; - for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "x", 0) * timelineScale, Json::getFloat(valueMap, "y", 0) * timelineScale); readCurve(valueMap, timeline, frameIndex); } @@ -1047,8 +920,7 @@ namespace Spine timelinesCount++; duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * TranslateTimeline::ENTRIES]); } - else - { + else { ContainerUtil::cleanUpVectorOfPointers(timelines); setError(NULL, "Invalid timeline type for a bone: ", timelineMap->_name); return NULL; @@ -1058,22 +930,18 @@ namespace Spine } /** IK constraint timelines. */ - for (constraintMap = ik ? ik->_child : 0; constraintMap; constraintMap = constraintMap->_next) - { + for (constraintMap = ik ? ik->_child : 0; constraintMap; constraintMap = constraintMap->_next) { IkConstraintData* constraint = skeletonData->findIkConstraint(constraintMap->_name); IkConstraintTimeline *timeline = NEW(IkConstraintTimeline); new (timeline) IkConstraintTimeline(constraintMap->_size); - for (frameIndex = 0; frameIndex < static_cast(skeletonData->_ikConstraints.size()); ++frameIndex) - { - if (constraint == skeletonData->_ikConstraints[frameIndex]) - { + for (frameIndex = 0; frameIndex < static_cast(skeletonData->_ikConstraints.size()); ++frameIndex) { + if (constraint == skeletonData->_ikConstraints[frameIndex]) { timeline->_ikConstraintIndex = frameIndex; break; } } - for (valueMap = constraintMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = constraintMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "mix", 1), Json::getInt(valueMap, "bendPositive", 1) ? 1 : -1); readCurve(valueMap, timeline, frameIndex); } @@ -1083,22 +951,18 @@ namespace Spine } /** Transform constraint timelines. */ - for (constraintMap = transform ? transform->_child : 0; constraintMap; constraintMap = constraintMap->_next) - { + for (constraintMap = transform ? transform->_child : 0; constraintMap; constraintMap = constraintMap->_next) { TransformConstraintData* constraint = skeletonData->findTransformConstraint(constraintMap->_name); TransformConstraintTimeline *timeline = NEW(TransformConstraintTimeline); new (timeline) TransformConstraintTimeline(constraintMap->_size); - for (frameIndex = 0; frameIndex < skeletonData->_transformConstraints.size(); ++frameIndex) - { - if (constraint == skeletonData->_transformConstraints[frameIndex]) - { + for (frameIndex = 0; frameIndex < skeletonData->_transformConstraints.size(); ++frameIndex) { + if (constraint == skeletonData->_transformConstraints[frameIndex]) { timeline->_transformConstraintIndex = frameIndex; break; } } - for (valueMap = constraintMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = constraintMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "rotateMix", 1), Json::getFloat(valueMap, "translateMix", 1), Json::getFloat(valueMap, "scaleMix", 1), Json::getFloat(valueMap, "shearMix", 1)); readCurve(valueMap, timeline, frameIndex); } @@ -1108,59 +972,48 @@ namespace Spine } /** Path constraint timelines. */ - for (constraintMap = paths ? paths->_child : 0; constraintMap; constraintMap = constraintMap->_next) - { + for (constraintMap = paths ? paths->_child : 0; constraintMap; constraintMap = constraintMap->_next) { int constraintIndex = 0, i; Json* timelineMap; PathConstraintData* data = skeletonData->findPathConstraint(constraintMap->_name); - if (!data) - { + if (!data) { ContainerUtil::cleanUpVectorOfPointers(timelines); setError(NULL, "Path constraint not found: ", constraintMap->_name); return NULL; } - for (i = 0; i < skeletonData->_pathConstraints.size(); i++) - { - if (skeletonData->_pathConstraints[i] == data) - { + for (i = 0; i < skeletonData->_pathConstraints.size(); i++) { + if (skeletonData->_pathConstraints[i] == data) { constraintIndex = i; break; } } - for (timelineMap = constraintMap->_child; timelineMap; timelineMap = timelineMap->_next) - { + for (timelineMap = constraintMap->_child; timelineMap; timelineMap = timelineMap->_next) { const char* timelineName = timelineMap->_name; - if (strcmp(timelineName, "position") == 0 || strcmp(timelineName, "spacing") == 0) - { + if (strcmp(timelineName, "position") == 0 || strcmp(timelineName, "spacing") == 0) { PathConstraintPositionTimeline* timeline; float timelineScale = 1; - if (strcmp(timelineName, "spacing") == 0) - { + if (strcmp(timelineName, "spacing") == 0) { timeline = NEW(PathConstraintSpacingTimeline); new (timeline) PathConstraintSpacingTimeline(timelineMap->_size); - if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) - { + if (data->_spacingMode == SpacingMode_Length || data->_spacingMode == SpacingMode_Fixed) { timelineScale = _scale; } } - else - { + else { timeline = NEW(PathConstraintPositionTimeline); new (timeline) PathConstraintPositionTimeline(timelineMap->_size); - if (data->_positionMode == PositionMode_Fixed) - { + if (data->_positionMode == PositionMode_Fixed) { timelineScale = _scale; } } timeline->_pathConstraintIndex = constraintIndex; - for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, timelineName, 0) * timelineScale); readCurve(valueMap, timeline, frameIndex); } @@ -1168,13 +1021,11 @@ namespace Spine timelinesCount++; duration = MAX(duration, timeline->_frames[(timelineMap->_size - 1) * PathConstraintPositionTimeline::ENTRIES]); } - else if (strcmp(timelineName, "mix") == 0) - { + else if (strcmp(timelineName, "mix") == 0) { PathConstraintMixTimeline* timeline = NEW(PathConstraintMixTimeline); new (timeline) PathConstraintMixTimeline(timelineMap->_size); timeline->_pathConstraintIndex = constraintIndex; - for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), Json::getFloat(valueMap, "rotateMix", 1), Json::getFloat(valueMap, "translateMix", 1)); readCurve(valueMap, timeline, frameIndex); } @@ -1186,22 +1037,18 @@ namespace Spine } /** Deform timelines. */ - for (constraintMap = deform ? deform->_child : NULL; constraintMap; constraintMap = constraintMap->_next) - { + for (constraintMap = deform ? deform->_child : NULL; constraintMap; constraintMap = constraintMap->_next) { Skin* skin = skeletonData->findSkin(constraintMap->_name); - for (slotMap = constraintMap->_child; slotMap; slotMap = slotMap->_next) - { + for (slotMap = constraintMap->_child; slotMap; slotMap = slotMap->_next) { int slotIndex = skeletonData->findSlotIndex(slotMap->_name); Json* timelineMap; - for (timelineMap = slotMap->_child; timelineMap; timelineMap = timelineMap->_next) - { + for (timelineMap = slotMap->_child; timelineMap; timelineMap = timelineMap->_next) { DeformTimeline *timeline; int weighted, deformLength; Attachment* baseAttachment = skin->getAttachment(slotIndex, timelineMap->_name); - if (!baseAttachment) - { + if (!baseAttachment) { ContainerUtil::cleanUpVectorOfPointers(timelines); setError(NULL, "Attachment not found: ", timelineMap->_name); return NULL; @@ -1214,8 +1061,7 @@ namespace Spine deformLength = weighted ? static_cast(vertices.size()) / 3 * 2 : static_cast(vertices.size()); Vector tempDeform; tempDeform.reserve(deformLength); - for (int i = 0; i < deformLength; ++i) - { + for (int i = 0; i < deformLength; ++i) { tempDeform.push_back(0); } @@ -1225,45 +1071,34 @@ namespace Spine timeline->_slotIndex = slotIndex; timeline->_attachment = attachment; - for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { Json* vertices = Json::getItem(valueMap, "vertices"); Vector deform; - if (!vertices) - { - if (weighted) - { + if (!vertices) { + if (weighted) { deform = tempDeform; } - else - { + else { deform = attachment->_vertices; } } - else - { + else { int v, start = Json::getInt(valueMap, "offset", 0); Json* vertex; deform = tempDeform; - if (_scale == 1) - { - for (vertex = vertices->_child, v = start; vertex; vertex = vertex->_next, ++v) - { + if (_scale == 1) { + for (vertex = vertices->_child, v = start; vertex; vertex = vertex->_next, ++v) { deform[v] = vertex->_valueFloat; } } - else - { - for (vertex = vertices->_child, v = start; vertex; vertex = vertex->_next, ++v) - { + else { + for (vertex = vertices->_child, v = start; vertex; vertex = vertex->_next, ++v) { deform[v] = vertex->_valueFloat * _scale; } } - if (!weighted) - { + if (!weighted) { Vector& verticesAttachment = attachment->_vertices; - for (v = 0; v < deformLength; ++v) - { + for (v = 0; v < deformLength; ++v) { deform[v] += verticesAttachment[v]; } } @@ -1280,18 +1115,15 @@ namespace Spine } /** Draw order timeline. */ - if (drawOrder) - { + if (drawOrder) { DrawOrderTimeline* timeline = NEW(DrawOrderTimeline); new (timeline) DrawOrderTimeline(drawOrder->_size); - for (valueMap = drawOrder->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = drawOrder->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { int ii; Vector drawOrder2; Json* offsets = Json::getItem(valueMap, "offsets"); - if (offsets) - { + if (offsets) { Json* offsetMap; Vector unchanged; unchanged.reserve(skeletonData->_slots.size() - offsets->_size); @@ -1300,23 +1132,19 @@ namespace Spine drawOrder2.reserve(skeletonData->_slots.size()); drawOrder2.setSize(skeletonData->_slots.size()); - for (ii = static_cast(skeletonData->_slots.size()) - 1; ii >= 0; --ii) - { + for (ii = static_cast(skeletonData->_slots.size()) - 1; ii >= 0; --ii) { drawOrder2[ii] = -1; } - for (offsetMap = offsets->_child; offsetMap; offsetMap = offsetMap->_next) - { + for (offsetMap = offsets->_child; offsetMap; offsetMap = offsetMap->_next) { int slotIndex = skeletonData->findSlotIndex(Json::getString(offsetMap, "slot", 0)); - if (slotIndex == -1) - { + if (slotIndex == -1) { ContainerUtil::cleanUpVectorOfPointers(timelines); setError(NULL, "Slot not found: ", Json::getString(offsetMap, "slot", 0)); return NULL; } /* Collect unchanged items. */ - while (originalIndex != slotIndex) - { + while (originalIndex != slotIndex) { unchanged[unchangedIndex++] = originalIndex++; } /* Set changed items. */ @@ -1324,15 +1152,12 @@ namespace Spine originalIndex++; } /* Collect remaining unchanged items. */ - while (originalIndex < skeletonData->_slots.size()) - { + while (originalIndex < skeletonData->_slots.size()) { unchanged[unchangedIndex++] = originalIndex++; } /* Fill in unchanged items. */ - for (ii = static_cast(skeletonData->_slots.size()) - 1; ii >= 0; ii--) - { - if (drawOrder2[ii] == -1) - { + for (ii = static_cast(skeletonData->_slots.size()) - 1; ii >= 0; ii--) { + if (drawOrder2[ii] == -1) { drawOrder2[ii] = unchanged[--unchangedIndex]; } } @@ -1345,17 +1170,14 @@ namespace Spine } /** Event timeline. */ - if (events) - { + if (events) { EventTimeline* timeline = NEW(EventTimeline); new (timeline) EventTimeline(events->_size); - for (valueMap = events->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) - { + for (valueMap = events->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) { Event* event; EventData* eventData = skeletonData->findEvent(Json::getString(valueMap, "name", 0)); - if (!eventData) - { + if (!eventData) { ContainerUtil::cleanUpVectorOfPointers(timelines); setError(NULL, "Event not found: ", Json::getString(valueMap, "name", 0)); return NULL; @@ -1379,8 +1201,7 @@ namespace Spine return ret; } - void SkeletonJson::readVertices(Json* attachmentMap, VertexAttachment* attachment, int verticesLength) - { + void SkeletonJson::readVertices(Json* attachmentMap, VertexAttachment* attachment, int verticesLength) { Json* entry; int i, n, nn, entrySize; Vector vertices; @@ -1391,17 +1212,13 @@ namespace Spine entrySize = entry->_size; vertices.reserve(entrySize); vertices.setSize(entrySize); - for (entry = entry->_child, i = 0; entry; entry = entry->_next, ++i) - { + for (entry = entry->_child, i = 0; entry; entry = entry->_next, ++i) { vertices[i] = entry->_valueFloat; } - if (verticesLength == entrySize) - { - if (_scale != 1) - { - for (i = 0; i < entrySize; ++i) - { + if (verticesLength == entrySize) { + if (_scale != 1) { + for (i = 0; i < entrySize; ++i) { vertices[i] *= _scale; } } @@ -1414,12 +1231,10 @@ namespace Spine bonesAndWeights._bones.reserve(verticesLength * 3); bonesAndWeights._vertices.reserve(verticesLength * 3 * 3); - for (i = 0, n = entrySize; i < n;) - { + for (i = 0, n = entrySize; i < n;) { int boneCount = (int)vertices[i++]; bonesAndWeights._bones.push_back(boneCount); - for (nn = i + boneCount * 4; i < nn; i += 4) - { + for (nn = i + boneCount * 4; i < nn; i += 4) { bonesAndWeights._bones.push_back((int)vertices[i]); bonesAndWeights._vertices.push_back(vertices[i + 1] * _scale); bonesAndWeights._vertices.push_back(vertices[i + 2] * _scale); @@ -1431,21 +1246,18 @@ namespace Spine attachment->setBones(bonesAndWeights._bones); } - void SkeletonJson::setError(Json* root, const char* value1, const char* value2) - { + void SkeletonJson::setError(Json* root, const char* value1, const char* value2) { char message[256]; int length; strcpy(message, value1); length = (int)strlen(value1); - if (value2) - { + if (value2) { strncat(message + length, value2, 255 - length); } _error = std::string(message); - if (root) - { + if (root) { DESTROY(Json, root); } } diff --git a/spine-cpp/spine-cpp/src/spine/Skin.cpp b/spine-cpp/spine-cpp/src/spine/Skin.cpp index 522e34e02..c02f20dfa 100644 --- a/spine-cpp/spine-cpp/src/spine/Skin.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skin.cpp @@ -41,95 +41,76 @@ namespace Spine { Skin::AttachmentKey::AttachmentKey(int slotIndex, std::string name) : _slotIndex(slotIndex), - _name(name) - { + _name(name) { // Empty } - bool Skin::AttachmentKey::operator==(const AttachmentKey &other) const - { + bool Skin::AttachmentKey::operator==(const AttachmentKey &other) const { return _slotIndex == other._slotIndex && _name == other._name; } - std::size_t Skin::HashAttachmentKey::operator()(const Spine::Skin::AttachmentKey& val) const - { + std::size_t Skin::HashAttachmentKey::operator()(const Spine::Skin::AttachmentKey& val) const { std::size_t h1 = val._slotIndex; return h1; } - Skin::Skin(std::string name) : _name(name) - { + Skin::Skin(std::string name) : _name(name) { assert(_name.length() > 0); } - void Skin::addAttachment(int slotIndex, std::string name, Attachment* attachment) - { + void Skin::addAttachment(int slotIndex, std::string name, Attachment* attachment) { assert(attachment); _attachments.insert(AttachmentKey(slotIndex, name), attachment); } - Attachment* Skin::getAttachment(int slotIndex, std::string name) - { + Attachment* Skin::getAttachment(int slotIndex, std::string name) { HashMap::Iterator i = _attachments.find(AttachmentKey(slotIndex, name)); Attachment* ret = NULL; - if (i != _attachments.end()) - { + if (i != _attachments.end()) { ret = i.second(); } return ret; } - void Skin::findNamesForSlot(int slotIndex, Vector& names) - { - for (HashMap::Iterator i = _attachments.begin(); i != _attachments.end(); ++i) - { - if (i.first()._slotIndex == slotIndex) - { + void Skin::findNamesForSlot(int slotIndex, Vector& names) { + for (HashMap::Iterator i = _attachments.begin(); i != _attachments.end(); ++i) { + if (i.first()._slotIndex == slotIndex) { names.push_back(i.first()._name); } } } - void Skin::findAttachmentsForSlot(int slotIndex, Vector& attachments) - { - for (HashMap::Iterator i = _attachments.begin(); i != _attachments.end(); ++i) - { - if (i.first()._slotIndex == slotIndex) - { + void Skin::findAttachmentsForSlot(int slotIndex, Vector& attachments) { + for (HashMap::Iterator i = _attachments.begin(); i != _attachments.end(); ++i) { + if (i.first()._slotIndex == slotIndex) { attachments.push_back(i.second()); } } } - const std::string& Skin::getName() - { + const std::string& Skin::getName() { return _name; } - HashMap& Skin::getAttachments() - { + HashMap& Skin::getAttachments() { return _attachments; } - void Skin::attachAll(Skeleton& skeleton, Skin& oldSkin) - { + void Skin::attachAll(Skeleton& skeleton, Skin& oldSkin) { Vector& slots = skeleton.getSlots(); - for (HashMap::Iterator i = oldSkin.getAttachments().begin(); i != oldSkin.getAttachments().end(); ++i) - { + for (HashMap::Iterator i = oldSkin.getAttachments().begin(); i != oldSkin.getAttachments().end(); ++i) { int slotIndex = i.first()._slotIndex; Slot* slot = slots[slotIndex]; - if (slot->getAttachment() == i.second()) - { + if (slot->getAttachment() == i.second()) { Attachment* attachment = NULL; - if ((attachment = getAttachment(slotIndex, i.first()._name))) - { + if ((attachment = getAttachment(slotIndex, i.first()._name))) { slot->setAttachment(attachment); } } diff --git a/spine-cpp/spine-cpp/src/spine/Slot.cpp b/spine-cpp/spine-cpp/src/spine/Slot.cpp index d245533ad..65fb1585c 100644 --- a/spine-cpp/spine-cpp/src/spine/Slot.cpp +++ b/spine-cpp/spine-cpp/src/spine/Slot.cpp @@ -50,134 +50,108 @@ namespace Spine _b2(0), _hasSecondColor(false), _attachment(NULL), - _attachmentTime(0) - { + _attachmentTime(0) { setToSetupPose(); } - void Slot::setToSetupPose() - { + void Slot::setToSetupPose() { _r = _data.getR(); _g = _data.getG(); _b = _data.getB(); _a = _data.getA(); std::string attachmentName = _data.getAttachmentName(); - if (attachmentName.length() > 0) - { + if (attachmentName.length() > 0) { _attachment = NULL; setAttachment(_skeleton.getAttachment(_data.getIndex(), attachmentName)); } - else - { + else { setAttachment(NULL); } } - SlotData& Slot::getData() - { + SlotData& Slot::getData() { return _data; } - Bone& Slot::getBone() - { + Bone& Slot::getBone() { return _bone; } - Skeleton& Slot::getSkeleton() - { + Skeleton& Slot::getSkeleton() { return _skeleton; } - float Slot::getR() - { + float Slot::getR() { return _r; } - void Slot::setR(float inValue) - { + void Slot::setR(float inValue) { _r = inValue; } - float Slot::getG() - { + float Slot::getG() { return _g; } - void Slot::setG(float inValue) - { + void Slot::setG(float inValue) { _g = inValue; } - float Slot::getB() - { + float Slot::getB() { return _b; } - void Slot::setB(float inValue) - { + void Slot::setB(float inValue) { _b = inValue; } - float Slot::getA() - { + float Slot::getA() { return _a; } - void Slot::setA(float inValue) - { + void Slot::setA(float inValue) { _a = inValue; } - float Slot::getR2() - { + float Slot::getR2() { return _r2; } - void Slot::setR2(float inValue) - { + void Slot::setR2(float inValue) { _r2 = inValue; } - float Slot::getG2() - { + float Slot::getG2() { return _g2; } - void Slot::setG2(float inValue) - { + void Slot::setG2(float inValue) { _g2 = inValue; } - float Slot::getB2() - { + float Slot::getB2() { return _b2; } - void Slot::setB2(float inValue) - { + void Slot::setB2(float inValue) { _b2 = inValue; } - bool Slot::hasSecondColor() - { + bool Slot::hasSecondColor() { return _hasSecondColor; } - void Slot::setHasSecondColor(bool inValue) - { + void Slot::setHasSecondColor(bool inValue) { _hasSecondColor = inValue; } - Attachment* Slot::getAttachment() - { + Attachment* Slot::getAttachment() { return _attachment; } - void Slot::setAttachment(Attachment* inValue) - { - if (_attachment == inValue) - { + void Slot::setAttachment(Attachment* inValue) { + if (_attachment == inValue) { return; } @@ -186,23 +160,19 @@ namespace Spine _attachmentVertices.clear(); } - float Slot::getAttachmentTime() - { + float Slot::getAttachmentTime() { return _skeleton.getTime() - _attachmentTime; } - void Slot::setAttachmentTime(float inValue) - { + void Slot::setAttachmentTime(float inValue) { _attachmentTime = _skeleton.getTime() - inValue; } - Vector& Slot::getAttachmentVertices() - { + Vector& Slot::getAttachmentVertices() { return _attachmentVertices; } - void Slot::setAttachmentVertices(Vector inValue) - { + void Slot::setAttachmentVertices(Vector inValue) { _attachmentVertices = inValue; } } diff --git a/spine-cpp/spine-cpp/src/spine/SlotData.cpp b/spine-cpp/spine-cpp/src/spine/SlotData.cpp index 775b69aca..8ef6adaf7 100644 --- a/spine-cpp/spine-cpp/src/spine/SlotData.cpp +++ b/spine-cpp/spine-cpp/src/spine/SlotData.cpp @@ -48,124 +48,100 @@ namespace Spine _a2(1), _hasSecondColor(false), _attachmentName(), - _blendMode(BlendMode_Normal) - { + _blendMode(BlendMode_Normal) { assert(_index >= 0); assert(_name.length() > 0); } - const int SlotData::getIndex() - { + const int SlotData::getIndex() { return _index; } - const std::string& SlotData::getName() - { + const std::string& SlotData::getName() { return _name; } - BoneData& SlotData::getBoneData() - { + BoneData& SlotData::getBoneData() { return _boneData; } - float SlotData::getR() - { + float SlotData::getR() { return _r; } - void SlotData::setR(float inValue) - { + void SlotData::setR(float inValue) { _r = inValue; } - float SlotData::getG() - { + float SlotData::getG() { return _g; } - void SlotData::setG(float inValue) - { + void SlotData::setG(float inValue) { _g = inValue; } - float SlotData::getB() - { + float SlotData::getB() { return _b; } - void SlotData::setB(float inValue) - { + void SlotData::setB(float inValue) { _b = inValue; } - float SlotData::getA() - { + float SlotData::getA() { return _a; } - void SlotData::setA(float inValue) - { + void SlotData::setA(float inValue) { _a = inValue; } - float SlotData::getR2() - { + float SlotData::getR2() { return _r2; } - void SlotData::setR2(float inValue) - { + void SlotData::setR2(float inValue) { _r2 = inValue; } - float SlotData::getG2() - { + float SlotData::getG2() { return _g2; } - void SlotData::setG2(float inValue) - { + void SlotData::setG2(float inValue) { _g2 = inValue; } - float SlotData::getB2() - { + float SlotData::getB2() { return _b2; } - void SlotData::setB2(float inValue) - { + void SlotData::setB2(float inValue) { _b2 = inValue; } - bool SlotData::hasSecondColor() - { + bool SlotData::hasSecondColor() { return _hasSecondColor; } - void SlotData::setHasSecondColor(bool inValue) - { + void SlotData::setHasSecondColor(bool inValue) { _hasSecondColor = inValue; } - std::string SlotData::getAttachmentName() - { + std::string SlotData::getAttachmentName() { return _attachmentName; } - void SlotData::setAttachmentName(std::string inValue) - { + void SlotData::setAttachmentName(std::string inValue) { _attachmentName = inValue; } - BlendMode SlotData::getBlendMode() - { + BlendMode SlotData::getBlendMode() { return _blendMode; } - void SlotData::setBlendMode(BlendMode inValue) - { + void SlotData::setBlendMode(BlendMode inValue) { _blendMode = inValue; } } diff --git a/spine-cpp/spine-cpp/src/spine/TextureLoader.cpp b/spine-cpp/spine-cpp/src/spine/TextureLoader.cpp index 57073cdfe..155f316d0 100644 --- a/spine-cpp/spine-cpp/src/spine/TextureLoader.cpp +++ b/spine-cpp/spine-cpp/src/spine/TextureLoader.cpp @@ -32,13 +32,11 @@ namespace Spine { - TextureLoader::TextureLoader() - { + TextureLoader::TextureLoader() { // Empty } - TextureLoader::~TextureLoader() - { + TextureLoader::~TextureLoader() { // Empty } } diff --git a/spine-cpp/spine-cpp/src/spine/Timeline.cpp b/spine-cpp/spine-cpp/src/spine/Timeline.cpp index 6dac2f210..32d22dffa 100644 --- a/spine-cpp/spine-cpp/src/spine/Timeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/Timeline.cpp @@ -37,13 +37,11 @@ namespace Spine { RTTI_IMPL_NOPARENT(Timeline); - Timeline::Timeline() - { + Timeline::Timeline() { // Empty } - Timeline::~Timeline() - { + Timeline::~Timeline() { // Empty } } diff --git a/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp b/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp index 3f970e502..e9defe296 100644 --- a/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp @@ -47,138 +47,110 @@ namespace Spine _rotateMix(data.getRotateMix()), _translateMix(data.getTranslateMix()), _scaleMix(data.getScaleMix()), - _shearMix(data.getShearMix()) - { + _shearMix(data.getShearMix()) { _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())); } } - void TransformConstraint::apply() - { + void TransformConstraint::apply() { update(); } - void TransformConstraint::update() - { - if (_data.isLocal()) - { - if (_data.isRelative()) - { + void TransformConstraint::update() { + if (_data.isLocal()) { + if (_data.isRelative()) { applyRelativeLocal(); } - else - { + else { applyAbsoluteLocal(); } } - else - { - if (_data.isRelative()) - { + else { + if (_data.isRelative()) { applyRelativeWorld(); } - else - { + else { applyAbsoluteWorld(); } } } - int TransformConstraint::getOrder() - { + int TransformConstraint::getOrder() { return _data.getOrder(); } - TransformConstraintData& TransformConstraint::getData() - { + TransformConstraintData& TransformConstraint::getData() { return _data; } - Vector& TransformConstraint::getBones() - { + Vector& TransformConstraint::getBones() { return _bones; } - Bone* TransformConstraint::getTarget() - { + Bone* TransformConstraint::getTarget() { return _target; } - void TransformConstraint::setTarget(Bone* inValue) - { + void TransformConstraint::setTarget(Bone* inValue) { _target = inValue; } - float TransformConstraint::getRotateMix() - { + float TransformConstraint::getRotateMix() { return _rotateMix; } - void TransformConstraint::setRotateMix(float inValue) - { + void TransformConstraint::setRotateMix(float inValue) { _rotateMix = inValue; } - float TransformConstraint::getTranslateMix() - { + float TransformConstraint::getTranslateMix() { return _translateMix; } - void TransformConstraint::setTranslateMix(float inValue) - { + void TransformConstraint::setTranslateMix(float inValue) { _translateMix = inValue; } - float TransformConstraint::getScaleMix() - { + float TransformConstraint::getScaleMix() { return _scaleMix; } - void TransformConstraint::setScaleMix(float inValue) - { + void TransformConstraint::setScaleMix(float inValue) { _scaleMix = inValue; } - float TransformConstraint::getShearMix() - { + float TransformConstraint::getShearMix() { return _shearMix; } - void TransformConstraint::setShearMix(float inValue) - { + void TransformConstraint::setShearMix(float inValue) { _shearMix = inValue; } - void TransformConstraint::applyAbsoluteWorld() - { + void TransformConstraint::applyAbsoluteWorld() { float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix; Bone& target = *_target; float ta = target._a, tb = target._b, tc = target._c, td = target._d; float degRadReflect = ta * td - tb * tc > 0 ? DegRad : -DegRad; float offsetRotation = _data._offsetRotation * degRadReflect, offsetShearY = _data._offsetShearY * degRadReflect; - for (Bone** i = _bones.begin(); i != _bones.end(); ++i) - { + for (Bone** i = _bones.begin(); i != _bones.end(); ++i) { Bone* item = (*i); Bone& bone = *item; bool modified = false; - if (rotateMix != 0) - { + if (rotateMix != 0) { float a = bone._a, b = bone._b, c = bone._c, d = bone._d; float r = MathUtil::atan2(tc, ta) - MathUtil::atan2(c, a) + offsetRotation; - if (r > SPINE_PI) - { + if (r > SPINE_PI) { r -= SPINE_PI_2; } - else if (r < -SPINE_PI) - { + else if (r < -SPINE_PI) { r += SPINE_PI_2; } @@ -191,8 +163,7 @@ namespace Spine modified = true; } - if (translateMix != 0) - { + if (translateMix != 0) { float tx, ty; target.localToWorld(_data._offsetX, _data._offsetY, tx, ty); bone._worldX += (tx - bone._worldX) * translateMix; @@ -200,20 +171,17 @@ namespace Spine modified = true; } - if (scaleMix > 0) - { + if (scaleMix > 0) { float s = (float)sqrt(bone._a * bone._a + bone._c * bone._c); - if (s > 0.00001f) - { + if (s > 0.00001f) { s = (s + ((float)sqrt(ta * ta + tc * tc) - s + _data._offsetScaleX) * scaleMix) / s; } bone._a *= s; bone._c *= s; s = (float)sqrt(bone._b * bone._b + bone._d * bone._d); - if (s > 0.00001f) - { + if (s > 0.00001f) { s = (s + ((float)sqrt(tb * tb + td * td) - s + _data._offsetScaleY) * scaleMix) / s; } bone._b *= s; @@ -221,17 +189,14 @@ namespace Spine modified = true; } - if (shearMix > 0) - { + if (shearMix > 0) { float b = bone._b, d = bone._d; float by = MathUtil::atan2(d, b); float r = MathUtil::atan2(td, tb) - MathUtil::atan2(tc, ta) - (by - MathUtil::atan2(bone._c, bone._a)); - if (r > SPINE_PI) - { + if (r > SPINE_PI) { r -= SPINE_PI_2; } - else if (r < -SPINE_PI) - { + else if (r < -SPINE_PI) { r += SPINE_PI_2; } @@ -242,37 +207,31 @@ namespace Spine modified = true; } - if (modified) - { + if (modified) { bone._appliedValid = false; } } } - void TransformConstraint::applyRelativeWorld() - { + void TransformConstraint::applyRelativeWorld() { float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix; Bone& target = *_target; float ta = target._a, tb = target._b, tc = target._c, td = target._d; float degRadReflect = ta * td - tb * tc > 0 ? DegRad : -DegRad; float offsetRotation = _data._offsetRotation * degRadReflect, offsetShearY = _data._offsetShearY * degRadReflect; - for (Bone** i = _bones.begin(); i != _bones.end(); ++i) - { + for (Bone** i = _bones.begin(); i != _bones.end(); ++i) { Bone* item = (*i); Bone& bone = *item; bool modified = false; - if (rotateMix != 0) - { + if (rotateMix != 0) { float a = bone._a, b = bone._b, c = bone._c, d = bone._d; float r = MathUtil::atan2(tc, ta) + offsetRotation; - if (r > SPINE_PI) - { + if (r > SPINE_PI) { r -= SPINE_PI_2; } - else if (r < -SPINE_PI) - { + else if (r < -SPINE_PI) { r += SPINE_PI_2; } @@ -285,8 +244,7 @@ namespace Spine modified = true; } - if (translateMix != 0) - { + if (translateMix != 0) { float tx, ty; target.localToWorld(_data._offsetX, _data._offsetY, tx, ty); bone._worldX += tx * translateMix; @@ -294,8 +252,7 @@ namespace Spine modified = true; } - if (scaleMix > 0) - { + if (scaleMix > 0) { float s = ((float)sqrt(ta * ta + tc * tc) - 1 + _data._offsetScaleX) * scaleMix + 1; bone._a *= s; bone._c *= s; @@ -305,15 +262,12 @@ namespace Spine modified = true; } - if (shearMix > 0) - { + if (shearMix > 0) { float r = MathUtil::atan2(td, tb) - MathUtil::atan2(tc, ta); - if (r > SPINE_PI) - { + if (r > SPINE_PI) { r -= SPINE_PI_2; } - else if (r < -SPINE_PI) - { + else if (r < -SPINE_PI) { r += SPINE_PI_2; } @@ -325,64 +279,53 @@ namespace Spine modified = true; } - if (modified) - { + if (modified) { bone._appliedValid = false; } } } - void TransformConstraint::applyAbsoluteLocal() - { + void TransformConstraint::applyAbsoluteLocal() { float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix; Bone& target = *_target; - if (!target._appliedValid) - { + if (!target._appliedValid) { target.updateAppliedTransform(); } - for (Bone** i = _bones.begin(); i != _bones.end(); ++i) - { + for (Bone** i = _bones.begin(); i != _bones.end(); ++i) { Bone* item = (*i); Bone& bone = *item; - if (!bone._appliedValid) - { + if (!bone._appliedValid) { bone.updateAppliedTransform(); } float rotation = bone._arotation; - if (rotateMix != 0) - { + if (rotateMix != 0) { float r = target._arotation - rotation + _data._offsetRotation; r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; rotation += r * rotateMix; } float x = bone._ax, y = bone._ay; - if (translateMix != 0) - { + if (translateMix != 0) { x += (target._ax - x + _data._offsetX) * translateMix; y += (target._ay - y + _data._offsetY) * translateMix; } float scaleX = bone._ascaleX, scaleY = bone._ascaleY; - if (scaleMix > 0) - { - if (scaleX > 0.00001f) - { + if (scaleMix > 0) { + if (scaleX > 0.00001f) { scaleX = (scaleX + (target._ascaleX - scaleX + _data._offsetScaleX) * scaleMix) / scaleX; } - if (scaleY > 0.00001f) - { + if (scaleY > 0.00001f) { scaleY = (scaleY + (target._ascaleY - scaleY + _data._offsetScaleY) * scaleMix) / scaleY; } } float shearY = bone._ashearY; - if (shearMix > 0) - { + if (shearMix > 0) { float r = target._ashearY - shearY + _data._offsetShearY; r -= (16384 - (int)(16384.499999999996 - r / 360)) * 360; bone._shearY += r * shearMix; @@ -392,55 +335,45 @@ namespace Spine } } - void TransformConstraint::applyRelativeLocal() - { + void TransformConstraint::applyRelativeLocal() { float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix; Bone& target = *_target; - if (!target._appliedValid) - { + if (!target._appliedValid) { target.updateAppliedTransform(); } - for (Bone** i = _bones.begin(); i != _bones.end(); ++i) - { + for (Bone** i = _bones.begin(); i != _bones.end(); ++i) { Bone* item = (*i); Bone& bone = *item; - if (!bone._appliedValid) - { + if (!bone._appliedValid) { bone.updateAppliedTransform(); } float rotation = bone._arotation; - if (rotateMix != 0) - { + if (rotateMix != 0) { rotation += (target._arotation + _data._offsetRotation) * rotateMix; } float x = bone._ax, y = bone._ay; - if (translateMix != 0) - { + if (translateMix != 0) { x += (target._ax + _data._offsetX) * translateMix; y += (target._ay + _data._offsetY) * translateMix; } float scaleX = bone._ascaleX, scaleY = bone._ascaleY; - if (scaleMix > 0) - { - if (scaleX > 0.00001f) - { + if (scaleMix > 0) { + if (scaleX > 0.00001f) { scaleX *= ((target._ascaleX - 1 + _data._offsetScaleX) * scaleMix) + 1; } - if (scaleY > 0.00001f) - { + if (scaleY > 0.00001f) { scaleY *= ((target._ascaleY - 1 + _data._offsetScaleY) * scaleMix) + 1; } } float shearY = bone._ashearY; - if (shearMix > 0) - { + if (shearMix > 0) { shearY += (target._ashearY + _data._offsetShearY) * shearMix; } diff --git a/spine-cpp/spine-cpp/src/spine/TransformConstraintData.cpp b/spine-cpp/spine-cpp/src/spine/TransformConstraintData.cpp index 6a9942c32..e1daf92a6 100644 --- a/spine-cpp/spine-cpp/src/spine/TransformConstraintData.cpp +++ b/spine-cpp/spine-cpp/src/spine/TransformConstraintData.cpp @@ -51,87 +51,70 @@ namespace Spine _offsetScaleY(0), _offsetShearY(0), _relative(false), - _local(false) - { + _local(false) { assert(_name.length() > 0); } - const std::string& TransformConstraintData::getName() - { + const std::string& TransformConstraintData::getName() { return _name; } - int TransformConstraintData::getOrder() - { + int TransformConstraintData::getOrder() { return _order; } - Vector& TransformConstraintData::getBones() - { + Vector& TransformConstraintData::getBones() { return _bones; } - BoneData* TransformConstraintData::getTarget() - { + BoneData* TransformConstraintData::getTarget() { return _target; } - float TransformConstraintData::getRotateMix() - { + float TransformConstraintData::getRotateMix() { return _rotateMix; } - float TransformConstraintData::getTranslateMix() - { + float TransformConstraintData::getTranslateMix() { return _translateMix; } - float TransformConstraintData::getScaleMix() - { + float TransformConstraintData::getScaleMix() { return _scaleMix; } - float TransformConstraintData::getShearMix() - { + float TransformConstraintData::getShearMix() { return _shearMix; } - float TransformConstraintData::getOffsetRotation() - { + float TransformConstraintData::getOffsetRotation() { return _offsetRotation; } - float TransformConstraintData::getOffsetX() - { + float TransformConstraintData::getOffsetX() { return _offsetX; } - float TransformConstraintData::getOffsetY() - { + float TransformConstraintData::getOffsetY() { return _offsetY; } - float TransformConstraintData::getOffsetScaleX() - { + float TransformConstraintData::getOffsetScaleX() { return _offsetScaleX; } - float TransformConstraintData::getOffsetScaleY() - { + float TransformConstraintData::getOffsetScaleY() { return _offsetScaleY; } - float TransformConstraintData::getOffsetShearY() - { + float TransformConstraintData::getOffsetShearY() { return _offsetShearY; } - bool TransformConstraintData::isRelative() - { + bool TransformConstraintData::isRelative() { return _relative; } - bool TransformConstraintData::isLocal() - { + bool TransformConstraintData::isLocal() { return _local; } } diff --git a/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp index 534be4439..2b2f9c5d6 100644 --- a/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TransformConstraintTimeline.cpp @@ -55,21 +55,17 @@ namespace Spine const int TransformConstraintTimeline::SCALE = 3; const int TransformConstraintTimeline::SHEAR = 4; - TransformConstraintTimeline::TransformConstraintTimeline(int frameCount) : CurveTimeline(frameCount), _transformConstraintIndex(0) - { + TransformConstraintTimeline::TransformConstraintTimeline(int frameCount) : CurveTimeline(frameCount), _transformConstraintIndex(0) { _frames.reserve(frameCount * ENTRIES); _frames.setSize(frameCount * ENTRIES); } - void TransformConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void TransformConstraintTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) { TransformConstraint* constraintP = skeleton._transformConstraints[_transformConstraintIndex]; TransformConstraint& constraint = *constraintP; - if (time < _frames[0]) - { - switch (pose) - { + if (time < _frames[0]) { + switch (pose) { case MixPose_Setup: constraint._rotateMix = constraint._data._rotateMix; constraint._translateMix = constraint._data._translateMix; @@ -89,8 +85,7 @@ namespace Spine } float rotate, translate, scale, shear; - if (time >= _frames[_frames.size() - ENTRIES]) - { + if (time >= _frames[_frames.size() - ENTRIES]) { // Time is after last frame. int i = static_cast(_frames.size()); rotate = _frames[i + PREV_ROTATE]; @@ -98,8 +93,7 @@ namespace Spine scale = _frames[i + PREV_SCALE]; shear = _frames[i + PREV_SHEAR]; } - else - { + else { // Interpolate between the previous frame and the current frame. int frame = Animation::binarySearch(_frames, time, ENTRIES); rotate = _frames[frame + PREV_ROTATE]; @@ -116,16 +110,14 @@ namespace Spine shear += (_frames[frame + SHEAR] - shear) * percent; } - if (pose == MixPose_Setup) - { + if (pose == MixPose_Setup) { TransformConstraintData& data = constraint._data; constraint._rotateMix = data._rotateMix + (rotate - data._rotateMix) * alpha; constraint._translateMix = data._translateMix + (translate - data._translateMix) * alpha; constraint._scaleMix = data._scaleMix + (scale - data._scaleMix) * alpha; constraint._shearMix = data._shearMix + (shear - data._shearMix) * alpha; } - else - { + else { constraint._rotateMix += (rotate - constraint._rotateMix) * alpha; constraint._translateMix += (translate - constraint._translateMix) * alpha; constraint._scaleMix += (scale - constraint._scaleMix) * alpha; @@ -133,13 +125,11 @@ namespace Spine } } - int TransformConstraintTimeline::getPropertyId() - { + int TransformConstraintTimeline::getPropertyId() { return ((int)TimelineType_TransformConstraint << 24) + _transformConstraintIndex; } - void TransformConstraintTimeline::setFrame(int frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix) - { + void TransformConstraintTimeline::setFrame(int frameIndex, float time, float rotateMix, float translateMix, float scaleMix, float shearMix) { frameIndex *= ENTRIES; _frames[frameIndex] = time; _frames[frameIndex + ROTATE] = rotateMix; diff --git a/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp index 8c23b0e58..c8dfb639e 100644 --- a/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TranslateTimeline.cpp @@ -51,21 +51,17 @@ namespace Spine const int TranslateTimeline::X = 1; const int TranslateTimeline::Y = 2; - TranslateTimeline::TranslateTimeline(int frameCount) : CurveTimeline(frameCount), _boneIndex(0) - { + TranslateTimeline::TranslateTimeline(int frameCount) : CurveTimeline(frameCount), _boneIndex(0) { _frames.reserve(frameCount * ENTRIES); _frames.setSize(frameCount * ENTRIES); } - void TranslateTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void TranslateTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) { Bone* boneP = skeleton._bones[_boneIndex]; Bone& bone = *boneP; - if (time < _frames[0]) - { - switch (pose) - { + if (time < _frames[0]) { + switch (pose) { case MixPose_Setup: bone._x = bone._data._x; bone._y = bone._data._y; @@ -81,14 +77,12 @@ namespace Spine } float x, y; - if (time >= _frames[_frames.size() - ENTRIES]) - { + if (time >= _frames[_frames.size() - ENTRIES]) { // Time is after last frame. x = _frames[_frames.size() + PREV_X]; y = _frames[_frames.size() + PREV_Y]; } - else - { + else { // Interpolate between the previous frame and the current frame. int frame = Animation::binarySearch(_frames, time, ENTRIES); x = _frames[frame + PREV_X]; @@ -100,25 +94,21 @@ namespace Spine y += (_frames[frame + Y] - y) * percent; } - if (pose == MixPose_Setup) - { + if (pose == MixPose_Setup) { bone._x = bone._data._x + x * alpha; bone._y = bone._data._y + y * alpha; } - else - { + else { bone._x += (bone._data._x + x - bone._x) * alpha; bone._y += (bone._data._y + y - bone._y) * alpha; } } - int TranslateTimeline::getPropertyId() - { + int TranslateTimeline::getPropertyId() { return ((int)TimelineType_Translate << 24) + _boneIndex; } - void TranslateTimeline::setFrame(int frameIndex, float time, float x, float y) - { + void TranslateTimeline::setFrame(int frameIndex, float time, float x, float y) { frameIndex *= ENTRIES; _frames[frameIndex] = time; _frames[frameIndex + X] = x; diff --git a/spine-cpp/spine-cpp/src/spine/Triangulator.cpp b/spine-cpp/spine-cpp/src/spine/Triangulator.cpp index edf536367..1b715609f 100644 --- a/spine-cpp/spine-cpp/src/spine/Triangulator.cpp +++ b/spine-cpp/spine-cpp/src/spine/Triangulator.cpp @@ -34,24 +34,21 @@ namespace Spine { - Vector& Triangulator::triangulate(Vector& vertices) - { + Vector& Triangulator::triangulate(Vector& vertices) { int vertexCount = static_cast(vertices.size() >> 1); Vector& indices = _indices; indices.clear(); indices.reserve(vertexCount); indices.setSize(vertexCount); - for (int i = 0; i < vertexCount; ++i) - { + for (int i = 0; i < vertexCount; ++i) { indices[i] = i; } Vector& isConcaveArray = _isConcaveArray; isConcaveArray.reserve(vertexCount); isConcaveArray.setSize(vertexCount); - for (int i = 0, n = vertexCount; i < n; ++i) - { + for (int i = 0, n = vertexCount; i < n; ++i) { isConcaveArray[i] = isConcave(i, vertexCount, vertices, indices); } @@ -59,35 +56,27 @@ namespace Spine triangles.clear(); triangles.reserve(MAX(0, vertexCount - 2) << 2); - while (vertexCount > 3) - { + while (vertexCount > 3) { // Find ear tip. int previous = vertexCount - 1, i = 0, next = 1; // outer: - while (true) - { - if (!isConcaveArray[i]) - { + while (true) { + if (!isConcaveArray[i]) { int p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1; float p1x = vertices[p1], p1y = vertices[p1 + 1]; float p2x = vertices[p2], p2y = vertices[p2 + 1]; float p3x = vertices[p3], p3y = vertices[p3 + 1]; - for (int ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) - { - if (!isConcaveArray[ii]) - { + for (int ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) { + if (!isConcaveArray[ii]) { continue; } int v = indices[ii] << 1; float& vx = vertices[v], vy = vertices[v + 1]; - if (positiveArea(p3x, p3y, p1x, p1y, vx, vy)) - { - if (positiveArea(p1x, p1y, p2x, p2y, vx, vy)) - { - if (positiveArea(p2x, p2y, p3x, p3y, vx, vy)) - { + if (positiveArea(p3x, p3y, p1x, p1y, vx, vy)) { + if (positiveArea(p1x, p1y, p2x, p2y, vx, vy)) { + if (positiveArea(p2x, p2y, p3x, p3y, vx, vy)) { goto break_outer; // break outer; } } @@ -97,12 +86,9 @@ namespace Spine } break_outer: - if (next == 0) - { - do - { - if (!isConcaveArray[i]) - { + if (next == 0) { + do { + if (!isConcaveArray[i]) { break; } i--; @@ -129,8 +115,7 @@ namespace Spine isConcaveArray[nextIndex] = isConcave(nextIndex, vertexCount, vertices, indices); } - if (vertexCount == 3) - { + if (vertexCount == 3) { triangles.push_back(indices[2]); triangles.push_back(indices[0]); triangles.push_back(indices[1]); @@ -139,18 +124,15 @@ namespace Spine return triangles; } - Vector< Vector* > Triangulator::decompose(Vector& vertices, Vector& triangles) - { + Vector< Vector* > Triangulator::decompose(Vector& vertices, Vector& triangles) { Vector< Vector* >&convexPolygons = _convexPolygons; - for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) - { + for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) { _polygonPool.free(convexPolygons[i]); } convexPolygons.clear(); Vector< Vector* > convexPolygonsIndices = _convexPolygonsIndices; - for (size_t i = 0, n = convexPolygonsIndices.size(); i < n; ++i) - { + for (size_t i = 0, n = convexPolygonsIndices.size(); i < n; ++i) { _polygonIndicesPool.free(convexPolygonsIndices[i]); } convexPolygonsIndices.clear(); @@ -165,8 +147,7 @@ namespace Spine // Merge subsequent triangles if they form a triangle fan. int fanBaseIndex = -1, lastwinding = 0; - for (size_t i = 0, n = triangles.size(); i < n; i += 3) - { + for (size_t i = 0, n = triangles.size(); i < n; i += 3) { int t1 = triangles[i] << 1, t2 = triangles[i + 1] << 1, t3 = triangles[i + 2] << 1; float x1 = vertices[t1], y1 = vertices[t1 + 1]; float x2 = vertices[t2], y2 = vertices[t2 + 1]; @@ -174,14 +155,12 @@ namespace Spine // If the base of the last triangle is the same as this triangle, check if they form a convex polygon (triangle fan). bool merged = false; - if (fanBaseIndex == t1) - { + if (fanBaseIndex == t1) { size_t o = polygon.size() - 4; Vector& p = polygon; int winding1 = winding(p[o], p[o + 1], p[o + 2], p[o + 3], x3, y3); int winding2 = winding(x3, y3, p[0], p[1], p[2], p[3]); - if (winding1 == lastwinding && winding2 == lastwinding) - { + if (winding1 == lastwinding && winding2 == lastwinding) { polygon.push_back(x3); polygon.push_back(y3); polygonIndices.push_back(t3); @@ -190,15 +169,12 @@ namespace Spine } // Otherwise make this triangle the new base. - if (!merged) - { - if (polygon.size() > 0) - { + if (!merged) { + if (polygon.size() > 0) { convexPolygons.push_back(&polygon); convexPolygonsIndices.push_back(&polygonIndices); } - else - { + else { _polygonPool.free(&polygon); _polygonIndicesPool.free(&polygonIndices); } @@ -221,15 +197,13 @@ namespace Spine } } - if (polygon.size() > 0) - { + if (polygon.size() > 0) { convexPolygons.push_back(&polygon); convexPolygonsIndices.push_back(&polygonIndices); } // Go through the list of polygons and try to merge the remaining triangles with the found triangle fans. - for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) - { + for (size_t i = 0, n = convexPolygons.size(); i < n; ++i) { polygonIndicesP = convexPolygonsIndices[i]; polygonIndices = *polygonIndicesP; @@ -246,18 +220,15 @@ namespace Spine float secondX = p[2], secondY = p[3]; int winding0 = winding(prevPrevX, prevPrevY, prevX, prevY, firstX, firstY); - for (int ii = 0; ii < n; ++ii) - { - if (ii == i) - { + for (int ii = 0; ii < n; ++ii) { + if (ii == i) { continue; } Vector* otherIndicesP = convexPolygonsIndices[ii]; Vector& otherIndices = *otherIndicesP; - if (otherIndices.size() != 3) - { + if (otherIndices.size() != 3) { continue; } @@ -270,15 +241,13 @@ namespace Spine float x3 = otherPoly[otherPoly.size() - 2], y3 = otherPoly[otherPoly.size() - 1]; - if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) - { + if (otherFirstIndex != firstIndex || otherSecondIndex != lastIndex) { continue; } int winding1 = winding(prevPrevX, prevPrevY, prevX, prevY, x3, y3); int winding2 = winding(x3, y3, firstX, firstY, secondX, secondY); - if (winding1 == winding0 && winding2 == winding0) - { + if (winding1 == winding0 && winding2 == winding0) { otherPoly.clear(); otherIndices.clear(); polygon.push_back(x3); @@ -294,11 +263,9 @@ namespace Spine } // Remove empty polygons that resulted from the merge step above. - for (int i = static_cast(convexPolygons.size()) - 1; i >= 0; --i) - { + for (int i = static_cast(convexPolygons.size()) - 1; i >= 0; --i) { polygon = *convexPolygons[i]; - if (polygon.size() == 0) - { + if (polygon.size() == 0) { convexPolygons.erase(i); _polygonPool.free(&polygon); polygonIndices = *convexPolygonsIndices[i]; @@ -310,8 +277,7 @@ namespace Spine return convexPolygons; } - bool Triangulator::isConcave(int index, int vertexCount, Vector& vertices, Vector& indices) - { + bool Triangulator::isConcave(int index, int vertexCount, Vector& vertices, Vector& indices) { int previous = indices[(vertexCount + index - 1) % vertexCount] << 1; int current = indices[index] << 1; int next = indices[(index + 1) % vertexCount] << 1; @@ -319,13 +285,11 @@ namespace Spine return !positiveArea(vertices[previous], vertices[previous + 1], vertices[current], vertices[current + 1], vertices[next], vertices[next + 1]); } - bool Triangulator::positiveArea(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) - { + bool Triangulator::positiveArea(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { return p1x * (p3y - p2y) + p2x * (p1y - p3y) + p3x * (p2y - p1y) >= 0; } - int Triangulator::winding(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) - { + int Triangulator::winding(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) { float px = p2x - p1x, py = p2y - p1y; return p3x * py - p3y * px + px * p1y - p1x * py >= 0 ? 1 : -1; diff --git a/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp b/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp index 16c28b180..5cb546b26 100644 --- a/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/TwoColorTimeline.cpp @@ -59,22 +59,18 @@ namespace Spine const int TwoColorTimeline::G2 = 6; const int TwoColorTimeline::B2 = 7; - TwoColorTimeline::TwoColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0) - { + TwoColorTimeline::TwoColorTimeline(int frameCount) : CurveTimeline(frameCount), _slotIndex(0) { _frames.reserve(frameCount * ENTRIES); _frames.setSize(frameCount * ENTRIES); } - void TwoColorTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) - { + void TwoColorTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector* pEvents, float alpha, MixPose pose, MixDirection direction) { Slot* slotP = skeleton._slots[_slotIndex]; Slot& slot = *slotP; - if (time < _frames[0]) - { + if (time < _frames[0]) { // Time is before first frame. - switch (pose) - { + switch (pose) { case MixPose_Setup: slot._r = slot._data._r; slot._g = slot._data._g; @@ -100,8 +96,7 @@ namespace Spine } float r, g, b, a, r2, g2, b2; - if (time >= _frames[_frames.size() - ENTRIES]) - { + if (time >= _frames[_frames.size() - ENTRIES]) { // Time is after last frame. int i = static_cast(_frames.size()); r = _frames[i + PREV_R]; @@ -112,8 +107,7 @@ namespace Spine g2 = _frames[i + PREV_G2]; b2 = _frames[i + PREV_B2]; } - else - { + else { // Interpolate between the previous frame and the current frame. int frame = Animation::binarySearch(_frames, time, ENTRIES); r = _frames[frame + PREV_R]; @@ -136,8 +130,7 @@ namespace Spine b2 += (_frames[frame + B2] - b2) * percent; } - if (alpha == 1) - { + if (alpha == 1) { slot._r = r; slot._g = g; slot._b = b; @@ -146,11 +139,9 @@ namespace Spine slot._g2 = g2; slot._b2 = b2; } - else - { + else { float br, bg, bb, ba, br2, bg2, bb2; - if (pose == MixPose_Setup) - { + if (pose == MixPose_Setup) { br = slot._data._r; bg = slot._data._g; bb = slot._data._b; @@ -159,8 +150,7 @@ namespace Spine bg2 = slot._data._g2; bb2 = slot._data._b2; } - else - { + else { br = slot._r; bg = slot._g; bb = slot._b; @@ -180,13 +170,11 @@ namespace Spine } } - int TwoColorTimeline::getPropertyId() - { + int TwoColorTimeline::getPropertyId() { return ((int)TimelineType_TwoColor << 24) + _slotIndex; } - void TwoColorTimeline::setFrame(int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, float b2) - { + void TwoColorTimeline::setFrame(int frameIndex, float time, float r, float g, float b, float a, float r2, float g2, float b2) { frameIndex *= ENTRIES; _frames[frameIndex] = time; _frames[frameIndex + R] = r; @@ -198,13 +186,11 @@ namespace Spine _frames[frameIndex + B2] = b2; } - int TwoColorTimeline::getSlotIndex() - { + int TwoColorTimeline::getSlotIndex() { return _slotIndex; } - void TwoColorTimeline::setSlotIndex(int inValue) - { + void TwoColorTimeline::setSlotIndex(int inValue) { assert(inValue >= 0); _slotIndex = inValue; } diff --git a/spine-cpp/spine-cpp/src/spine/Updatable.cpp b/spine-cpp/spine-cpp/src/spine/Updatable.cpp index 598955a9a..8993b94ae 100644 --- a/spine-cpp/spine-cpp/src/spine/Updatable.cpp +++ b/spine-cpp/spine-cpp/src/spine/Updatable.cpp @@ -34,13 +34,11 @@ namespace Spine { RTTI_IMPL_NOPARENT(Updatable); - Updatable::Updatable() - { + Updatable::Updatable() { // Empty } - Updatable::~Updatable() - { + Updatable::~Updatable() { // Empty } } diff --git a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp index 6cfa69a34..318b15263 100644 --- a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp @@ -39,27 +39,22 @@ namespace Spine { RTTI_IMPL(VertexAttachment, Attachment); - VertexAttachment::VertexAttachment(std::string name) : Attachment(name), _worldVerticesLength(0), _id(getNextID()) - { + VertexAttachment::VertexAttachment(std::string name) : Attachment(name), _worldVerticesLength(0), _id(getNextID()) { // Empty } - void VertexAttachment::computeWorldVertices(Slot& slot, Vector& worldVertices) - { + void VertexAttachment::computeWorldVertices(Slot& slot, Vector& worldVertices) { computeWorldVertices(slot, 0, _worldVerticesLength, worldVertices, 0); } - void VertexAttachment::computeWorldVertices(Slot& slot, int start, int count, Vector& worldVertices, int offset, int stride) - { + void VertexAttachment::computeWorldVertices(Slot& slot, int start, int count, Vector& worldVertices, int offset, int stride) { count = offset + (count >> 1) * stride; Skeleton& skeleton = slot._bone._skeleton; Vector& deformArray = slot.getAttachmentVertices(); Vector& vertices = _vertices; Vector& bones = _bones; - if (bones.size() == 0) - { - if (deformArray.size() > 0) - { + if (bones.size() == 0) { + if (deformArray.size() > 0) { vertices = deformArray; } @@ -67,8 +62,7 @@ namespace Spine float x = bone._worldX; float y = bone._worldY; float a = bone._a, b = bone._b, c = bone._c, d = bone._d; - for (int vv = start, w = offset; w < count; vv += 2, w += stride) - { + for (int vv = start, w = offset; w < count; vv += 2, w += stride) { float vx = vertices[vv]; float vy = vertices[vv + 1]; worldVertices[w] = vx * a + vy * b + x; @@ -78,23 +72,19 @@ namespace Spine } int v = 0, skip = 0; - for (int i = 0; i < start; i += 2) - { + for (int i = 0; i < start; i += 2) { int n = bones[v]; v += n + 1; skip += n; } Vector& skeletonBones = skeleton.getBones(); - if (deformArray.size() == 0) - { - for (int w = offset, b = skip * 3; w < count; w += stride) - { + if (deformArray.size() == 0) { + for (int w = offset, b = skip * 3; w < count; w += stride) { float wx = 0, wy = 0; int n = bones[v++]; n += v; - for (; v < n; v++, b += 3) - { + for (; v < n; v++, b += 3) { Bone* boneP = skeletonBones[bones[v]]; Bone& bone = *boneP; float vx = vertices[b]; @@ -107,15 +97,12 @@ namespace Spine worldVertices[w + 1] = wy; } } - else - { - for (int w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) - { + else { + for (int w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) { float wx = 0, wy = 0; int n = bones[v++]; n += v; - for (; v < n; v++, b += 3, f += 2) - { + for (; v < n; v++, b += 3, f += 2) { Bone* boneP = skeletonBones[bones[v]]; Bone& bone = *boneP; float vx = vertices[b] + deformArray[f]; @@ -130,48 +117,39 @@ namespace Spine } } - bool VertexAttachment::applyDeform(VertexAttachment* sourceAttachment) - { + bool VertexAttachment::applyDeform(VertexAttachment* sourceAttachment) { return this == sourceAttachment; } - int VertexAttachment::getId() - { + int VertexAttachment::getId() { return _id; } - Vector& VertexAttachment::getBones() - { + Vector& VertexAttachment::getBones() { return _bones; } - void VertexAttachment::setBones(Vector inValue) - { + void VertexAttachment::setBones(Vector inValue) { _bones = inValue; } - Vector& VertexAttachment::getVertices() - { + Vector& VertexAttachment::getVertices() { return _vertices; } - void VertexAttachment::setVertices(Vector inValue) - { + void VertexAttachment::setVertices(Vector inValue) { _vertices = inValue; } - int VertexAttachment::getWorldVerticesLength() - { + int VertexAttachment::getWorldVerticesLength() { return _worldVerticesLength; } - void VertexAttachment::setWorldVerticesLength(int inValue) - { + void VertexAttachment::setWorldVerticesLength(int inValue) { _worldVerticesLength = inValue; } - int VertexAttachment::getNextID() - { + int VertexAttachment::getNextID() { static int nextID = 0; return (nextID++ & 65535) << 11;