This commit is contained in:
Stephen Gowen 2017-10-13 15:31:58 -04:00
parent 54e54b21ca
commit fc09ed9745
31 changed files with 645 additions and 202 deletions

View File

@ -44,8 +44,6 @@ namespace Spine
private:
const std::string _name;
friend std::ostream& operator <<(std::ostream& os, const Attachment& ref);
};
}

View File

@ -388,8 +388,6 @@ namespace Spine
this.d = sin * b + cos * d;
appliedValid = false;
}
friend std::ostream& operator <<(std::ostream& os, const Bone& ref);
};
}

View File

@ -93,8 +93,6 @@ namespace Spine
float _length;
float _x, _y, _rotation, _scaleX, _scaleY, _shearX, _shearY;
TransformMode _transformMode;
friend std::ostream& operator <<(std::ostream& os, const BoneData& ref);
};
}

View File

@ -32,8 +32,8 @@
#define Spine_CurveTimeline_h
#include <spine/Timeline.h>
#include <spine/SimpleArray.h>
#include <vector>
#include <assert.h>
namespace Spine
@ -44,7 +44,7 @@ namespace Spine
public:
CurveTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector<Event*>& events, float alpha, MixPose pose, MixDirection direction) = 0;
virtual void apply(Skeleton& skeleton, float lastTime, float time, SimpleArray<Event*>& events, float alpha, MixPose pose, MixDirection direction) = 0;
virtual int getPropertyId() = 0;
@ -70,7 +70,7 @@ namespace Spine
static const int BEZIER_SIZE;
private:
std::vector<float> _curves; // type, x, y, ...
SimpleArray<float> _curves; // type, x, y, ...
};
}

View File

@ -63,8 +63,6 @@ namespace Spine
int _intValue;
float _floatValue;
std::string _stringValue;
friend std::ostream& operator <<(std::ostream& os, const Event& ref);
};
}

View File

@ -60,8 +60,6 @@ namespace Spine
private:
friend class Event;
const std::string _name;
friend std::ostream& operator <<(std::ostream& os, const EventData& ref);
};
}

View File

@ -0,0 +1,352 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_HashMap_h
#define Spine_HashMap_h
#include <iostream>
#include <string>
namespace Spine
{
template <typename K, typename V, typename H>
class HashMap
{
private:
class Entry;
public:
class Iterator
{
friend class HashMap;
public:
Iterator(Entry* entry = NULL) : _entry(entry)
{
// Empty
}
Iterator& operator++()
{
_entry = _entry->next;
return *this;
}
Iterator& operator--()
{
_entry = _entry->prev;
return *this;
}
bool operator==(const Iterator& p) const
{
return _entry == p._entry;
}
bool operator!=(const Iterator& p) const
{
return _entry != p._entry;
}
K& first()
{
return _entry->_key;
}
V& second()
{
return _entry->_value;
}
private:
Entry* _entry;
};
HashMap(int capacity) : _capacity(capacity), _hashFunction(), _header(), _trailer()
{
_hashTable = new Entry[capacity];
for (int i = 0; i < _capacity; ++i)
{
_hashTable[i] = Entry();
}
_header.prev = &_header;
_header.next = &_trailer;
_trailer.prev = &_header;
_trailer.next = &_trailer;
_hashSize = 0;
}
~HashMap()
{
delete [] _hashTable;
_hashSize = 0;
}
size_t size()
{
return _hashSize;
}
Iterator begin()
{
return Iterator(_header.next);
}
Iterator end()
{
return Iterator(&_trailer);
}
Iterator rbegin()
{
return Iterator(_trailer.prev);
}
Iterator rend()
{
return Iterator(_header);
}
Iterator insert(const K& key, const V& value)
{
Iterator iter = find(key);
if (iter._entry != &_trailer)
{
return Iterator(&_trailer);
}
size_t index = hash(key);
Entry* entry = new Entry;
entry->_key = key;
entry->_value = value;
_hashSize++;
if (_header.next == (&_trailer))
{
_hashTable[index].next = entry;
_hashTable[index].prev = entry;
_header.next = entry;
entry->prev = &_header;
entry->next = &_trailer;
_trailer.prev = entry;
return Iterator(entry);
}
if (_hashTable[index].next == NULL)
{
_hashTable[index].next = entry;
_hashTable[index].prev = entry;
if (index < hash(_header.next->_key))
{
entry->next = _header.next;
entry->prev = &_header;
_header.next->prev = entry;
_header.next = entry;
}
else if (index > hash(_header.next->_key) && index < hash(_trailer.prev->_key))
{
size_t prev_index = index;
while (_hashTable[--prev_index].next != NULL)
{
// Empty
}
entry->next = _hashTable[prev_index].prev->next;
entry->prev = _hashTable[prev_index].prev;
_hashTable[prev_index].prev->next = entry;
entry->next->prev = entry;
}
else
{
entry->next = &_trailer;
entry->prev = _trailer.prev;
_trailer.prev = entry;
entry->prev->next = entry;
}
return Iterator(entry);
}
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
{
entry->next = _hashTable[index].next;
entry->prev = _hashTable[index].next->prev;
entry->next->prev = entry;
entry->prev->next = entry;
_hashTable[index].next = entry;
}
return Iterator(entry);
}
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)
{
return iter;
}
}
}
return Iterator(&_trailer);
}
void erase(Iterator pos)
{
if (pos._entry != &_header && pos._entry != &_trailer)
{
size_t index = hash(pos._entry->_key);
if (_hashTable[index].next == pos._entry && _hashTable[index].prev == pos._entry)
{
_hashTable[index].next = NULL;
_hashTable[index].prev = NULL;
if (_header.next == pos._entry)
{
_header.next = pos._entry->next;
pos._entry->next->prev = &_header;
}
else if (_trailer.prev == pos._entry)
{
_trailer.prev = pos._entry->prev;
pos._entry->prev->next = &_trailer;
}
else
{
pos._entry->prev->next = pos._entry->next;
pos._entry->next->prev = pos._entry->prev;
}
delete pos._entry;
}
else if (_hashTable[index].next == pos._entry)
{
_hashTable[index].next = pos._entry->next;
if (_header.next == pos._entry)
{
_header.next = pos._entry->next;
pos._entry->next->prev = &_header;
}
else
{
pos._entry->prev->next = pos._entry->next;
pos._entry->next->prev = pos._entry->prev;
}
delete pos._entry;
}
else if (_hashTable[index].prev == pos._entry)
{
_hashTable[index].prev = pos._entry->prev;
if (_trailer.prev == pos._entry)
{
_trailer.prev = pos._entry->prev;
pos._entry->prev->next = &_trailer;
}
else
{
pos._entry->prev->next = pos._entry->next;
pos._entry->next->prev = pos._entry->prev;
}
delete pos._entry;
}
else
{
pos._entry->prev->next = pos._entry->next;
pos._entry->next->prev = pos._entry->prev;
delete pos._entry;
}
_hashSize--;
}
}
V operator[](const K& key)
{
Iterator iter = find(key);
if (iter._entry != _trailer)
{
return iter._entry->_value;
}
return V();
}
private:
class Entry
{
public:
K _key;
V _value;
Entry* next;
Entry* prev;
};
const H _hashFunction;
const int _capacity;
Entry* _hashTable;
Entry _header;
Entry _trailer;
size_t _hashSize;
size_t hash(const K& key)
{
return _hashFunction(key) % _capacity;
}
};
}
#endif /* Spine_HashMap_h */

View File

@ -31,8 +31,9 @@
#ifndef Spine_IkConstraintData_h
#define Spine_IkConstraintData_h
#include <spine/SimpleArray.h>
#include <string>
#include <vector>
class BoneData;
@ -50,7 +51,7 @@ namespace Spine
void setOrder(int inValue);
/// The bones that are constrained by this IK Constraint.
std::vector<BoneData*>& getBones();
SimpleArray<BoneData*>& getBones();
/// The bone that is the IK target.
BoneData* getTarget();
@ -66,12 +67,10 @@ namespace Spine
private:
const std::string _name;
int _order;
std::vector<BoneData*> _bones;
SimpleArray<BoneData*> _bones;
BoneData* _target;
int _bendDirection;
float _mix;
friend std::ostream& operator <<(std::ostream& os, const IkConstraintData& ref);
};
}

View File

@ -35,7 +35,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, std::vector&, float, MixPose, MixDirection)
/// See also Timeline::apply(Skeleton&, float, float, SimpleArray&, float, MixPose, MixDirection)
enum MixDirection
{
MixDirection_In = 0,

View File

@ -35,7 +35,7 @@ namespace Spine
{
///
/// Controls how a timeline is mixed with the setup or current pose.
/// See also Timeline::apply(Skeleton&, float, float, std::vector&, float, MixPose, MixDirection)
/// See also Timeline::apply(Skeleton&, float, float, SimpleArray&, float, MixPose, MixDirection)
enum MixPose
{
/// The timeline value is mixed with the setup pose (the current pose is not used).

View File

@ -34,9 +34,9 @@
#include <spine/PositionMode.h>
#include <spine/SpacingMode.h>
#include <spine/RotateMode.h>
#include <spine/SimpleArray.h>
#include <string>
#include <vector>
namespace Spine
{
@ -53,7 +53,7 @@ namespace Spine
int getOrder();
void setOrder(int inValue);
std::vector<BoneData*>& getBones();
SimpleArray<BoneData*>& getBones();
SlotData* getTarget();
void setTarget(SlotData* inValue);
@ -85,15 +85,13 @@ namespace Spine
private:
const std::string _name;
int _order;
std::vector<BoneData*> _bones;
SimpleArray<BoneData*> _bones;
SlotData* _target;
PositionMode _positionMode;
SpacingMode _spacingMode;
RotateMode _rotateMode;
float _offsetRotation;
float _position, _spacing, _rotateMix, _translateMix;
friend std::ostream& operator <<(std::ostream& os, const PathConstraintData& ref);
};
}

View File

@ -42,7 +42,7 @@ namespace Spine
RotateTimeline(int frameCount);
virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual void apply(Skeleton& skeleton, float lastTime, float time, SimpleArray<Event*>& events, float alpha, MixPose pose, MixDirection direction);
virtual int getPropertyId();
@ -52,8 +52,8 @@ namespace Spine
int getBoneIndex();
void setBoneIndex(int inValue);
std::vector<float>& getFrames();
void setFrames(std::vector<float> inValue);
SimpleArray<float>& getFrames();
void setFrames(SimpleArray<float> inValue);
private:
static const int PREV_TIME = -2;
@ -61,7 +61,7 @@ namespace Spine
static const int ROTATION = 1;
int _boneIndex;
std::vector<float> _frames; // time, angle, ...
SimpleArray<float> _frames; // time, angle, ...
};
}

View File

@ -0,0 +1,187 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef Spine_SimpleArray_h
#define Spine_SimpleArray_h
#include <memory>
#include <assert.h>
namespace Spine
{
template <typename T>
class SimpleArray
{
public:
SimpleArray() : _size(0), _capacity(0), _buffer(nullptr)
{
// Empty
}
SimpleArray(const SimpleArray& inArray)
{
_size = inArray._size;
_capacity = inArray._capacity;
if (_capacity)
{
_buffer = allocate(_capacity);
for (size_t i = 0; i < _size; ++i)
{
construct(_buffer + i, inArray._buffer[i]);
}
}
}
~SimpleArray()
{
clear();
deallocate(_buffer);
}
void push_back(const T& _value)
{
if (_size == _capacity)
{
reserve();
}
construct(_buffer + _size++, _value);
}
void insert(size_t _index, const T& _value)
{
assert(_index < _size);
if (_size == _capacity)
{
reserve();
}
for (size_t i = ++_size - 1; i > _index; --i)
{
construct(_buffer + i, _buffer[i - 1]);
destroy(_buffer + (i - 1));
}
construct(_buffer + _index, _value);
}
void erase(size_t _index)
{
assert(_index < _size);
--_size;
if (_index != _size)
{
for (size_t i = _index; i < _size; ++i)
{
_buffer[i] = std::move(_buffer[i + 1]);
}
}
destroy(_buffer + _size);
}
void clear()
{
for (size_t i = 0; i < _size; ++i)
{
destroy(_buffer + (_size - 1 - i));
}
_size = 0;
}
size_t size() const
{
return _size;
}
T& operator[](size_t _index)
{
assert(_index < _size);
return _buffer[_index];
}
void reserve(long inCapacity = -1)
{
size_t newCapacity = inCapacity != -1 ? inCapacity : _capacity ? _capacity * 2 : 1;
_buffer = static_cast<T*>(realloc(_buffer, newCapacity * sizeof(T)));
_capacity = newCapacity;
}
T* begin()
{
return &_buffer[0];
}
T* end()
{
return &_buffer[_size];
}
private:
size_t _size;
size_t _capacity;
T* _buffer;
T* allocate(size_t n)
{
assert(n > 0);
void* ptr = malloc(n * sizeof(T));
assert(ptr);
return static_cast<T*>(ptr);
}
void deallocate(T* buffer)
{
free(buffer);
}
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)
{
buffer->~T();
}
};
}
#endif /* Spine_SimpleArray_h */

View File

@ -31,8 +31,9 @@
#ifndef Spine_Skeleton_h
#define Spine_Skeleton_h
#include <spine/SimpleArray.h>
#include <string>
#include <vector>
namespace Spine
{
@ -49,13 +50,13 @@ namespace Spine
{
public:
SkeletonData* getData();
std::vector<Bone*> getBones();
std::vector<Updatable*> getUpdateCacheList();
std::vector<Slot*> getSlots();
std::vector<Slot*> getDrawOrder();
std::vector<IkConstraint*> getIkConstraints();
std::vector<PathConstraint*> getPathConstraints();
std::vector<TransformConstraint*> getTransformConstraints();
SimpleArray<Bone*> getBones();
SimpleArray<Updatable*> getUpdateCacheList();
SimpleArray<Slot*> getSlots();
SimpleArray<Slot*> getDrawOrder();
SimpleArray<IkConstraint*> getIkConstraints();
SimpleArray<PathConstraint*> getPathConstraints();
SimpleArray<TransformConstraint*> getTransformConstraints();
Skin* getSkin { get { return skin; } set { skin = value; } }
float getR { get { return r; } set { r = value; } }
@ -83,7 +84,7 @@ namespace Spine
this.data = data;
bones = new std::vector<Bone>(data.bones.Count);
bones = new SimpleArray<Bone>(data.bones.Count);
foreach (BoneData boneData in data.bones)
{
Bone bone;
@ -100,8 +101,8 @@ namespace Spine
bones.Add(bone);
}
slots = new std::vector<Slot>(data.slots.Count);
drawOrder = new std::vector<Slot>(data.slots.Count);
slots = new SimpleArray<Slot>(data.slots.Count);
drawOrder = new SimpleArray<Slot>(data.slots.Count);
foreach (SlotData slotData in data.slots)
{
Bone bone = bones.Items[slotData.boneData.index];
@ -110,15 +111,15 @@ namespace Spine
drawOrder.Add(slot);
}
ikConstraints = new std::vector<IkConstraint>(data.ikConstraints.Count);
ikConstraints = new SimpleArray<IkConstraint>(data.ikConstraints.Count);
foreach (IkConstraintData ikConstraintData in data.ikConstraints)
ikConstraints.Add(new IkConstraint(ikConstraintData, this));
transformConstraints = new std::vector<TransformConstraint>(data.transformConstraints.Count);
transformConstraints = new SimpleArray<TransformConstraint>(data.transformConstraints.Count);
foreach (TransformConstraintData transformConstraintData in data.transformConstraints)
transformConstraints.Add(new TransformConstraint(transformConstraintData, this));
pathConstraints = new std::vector<PathConstraint> (data.pathConstraints.Count);
pathConstraints = new SimpleArray<PathConstraint> (data.pathConstraints.Count);
foreach (PathConstraintData pathConstraintData in data.pathConstraints)
pathConstraints.Add(new PathConstraint(pathConstraintData, this));
@ -135,17 +136,17 @@ namespace Spine
/// or removed.
void updateCache()
{
std::vector<IUpdatable> updateCache = this.updateCache;
SimpleArray<IUpdatable> updateCache = this.updateCache;
updateCache.Clear();
this.updateCacheReset.Clear();
std::vector<Bone> bones = this.bones;
SimpleArray<Bone> bones = this.bones;
for (int i = 0, n = bones.Count; i < n; i++)
{
bones.Items[i].sorted = false;
}
std::vector<IkConstraint> ikConstraints = this.ikConstraints;
SimpleArray<IkConstraint> ikConstraints = this.ikConstraints;
var transformConstraints = this.transformConstraints;
var pathConstraints = this.pathConstraints;
int ikCount = IkConstraints.Count, transformCount = transformConstraints.Count, pathCount = pathConstraints.Count;
@ -391,7 +392,7 @@ namespace Spine
}
else
{
std::vector<Slot> slots = this.slots;
SimpleArray<Slot> slots = this.slots;
for (int i = 0, n = slots.Count; i < n; i++)
{
Slot slot = slots.Items[i];
@ -445,7 +446,7 @@ namespace Spine
throw new ArgumentNullException("slotName", "slotName cannot be null.");
}
std::vector<Slot> slots = this.slots;
SimpleArray<Slot> slots = this.slots;
for (int i = 0, n = slots.Count; i < n; i++)
{
Slot slot = slots.Items[i];
@ -478,7 +479,7 @@ namespace Spine
throw new ArgumentNullException("constraintName", "constraintName cannot be null.");
}
std::vector<IkConstraint> ikConstraints = this.ikConstraints;
SimpleArray<IkConstraint> ikConstraints = this.ikConstraints;
for (int i = 0, n = ikConstraints.Count; i < n; i++)
{
IkConstraint ikConstraint = ikConstraints.Items[i];
@ -496,7 +497,7 @@ namespace Spine
throw new ArgumentNullException("constraintName", "constraintName cannot be null.");
}
std::vector<TransformConstraint> transformConstraints = this.transformConstraints;
SimpleArray<TransformConstraint> transformConstraints = this.transformConstraints;
for (int i = 0, n = transformConstraints.Count; i < n; i++)
{
TransformConstraint transformConstraint = transformConstraints.Items[i];
@ -514,7 +515,7 @@ namespace Spine
throw new ArgumentNullException("constraintName", "constraintName cannot be null.");
}
std::vector<PathConstraint> pathConstraints = this.pathConstraints;
SimpleArray<PathConstraint> pathConstraints = this.pathConstraints;
for (int i = 0, n = pathConstraints.Count; i < n; i++)
{
PathConstraint constraint = pathConstraints.Items[i];
@ -594,14 +595,14 @@ namespace Spine
private:
SkeletonData* _data;
std::vector<Bone*> _bones;
std::vector<Slot*> _slots;
std::vector<Slot*> _drawOrder;
std::vector<IkConstraint*> _ikConstraints;
std::vector<TransformConstraint*> _transformConstraints;
std::vector<PathConstraint*> _pathConstraints;
std::vector<IUpdatable*> _updateCache = new std::vector<IUpdatable>();
std::vector<Bone*> _updateCacheReset = new std::vector<Bone>();
SimpleArray<Bone*> _bones;
SimpleArray<Slot*> _slots;
SimpleArray<Slot*> _drawOrder;
SimpleArray<IkConstraint*> _ikConstraints;
SimpleArray<TransformConstraint*> _transformConstraints;
SimpleArray<PathConstraint*> _pathConstraints;
SimpleArray<IUpdatable*> _updateCache = new SimpleArray<IUpdatable>();
SimpleArray<Bone*> _updateCacheReset = new SimpleArray<Bone>();
Skin _skin;
float _r = 1, _g = 1, _b = 1, _a = 1;
float _time;
@ -763,7 +764,7 @@ namespace Spine
updateCache.Add(bone);
}
static void sortReset(std::vector<Bone*>& bones)
static void sortReset(SimpleArray<Bone*>& bones)
{
var bonesItems = bones.Items;
for (int i = 0, n = bones.Count; i < n; i++)

View File

@ -32,8 +32,10 @@
#define Spine_Skin_h
#include <string>
#include <vector>
#include <unordered_map>
#include <spine/HashMap.h>
#include <spine/SimpleArray.h>
struct HashAttachmentKey;
namespace Spine
{
@ -66,43 +68,37 @@ namespace Spine
/// Returns the attachment for the specified slot index and name, or null.
Attachment* getAttachment(int slotIndex, std::string name);
/// Finds the skin keys for a given slot. The results are added to the passed vector names.
/// Finds the skin keys for a given slot. The results are added to the passed array of names.
/// @param slotIndex The target slotIndex. To find the slot index, use Skeleton::findSlotIndex or SkeletonData::findSlotIndex
/// @param names Found skin key names will be added to this vector.
void findNamesForSlot(int slotIndex, std::vector<std::string>& names);
/// @param names Found skin key names will be added to this array.
void findNamesForSlot(int slotIndex, SimpleArray<std::string>& names);
/// Finds the attachments for a given slot. The results are added to the passed List(Attachment).
/// Finds the attachments for a given slot. The results are added to the passed array of Attachments.
/// @param slotIndex The target slotIndex. To find the slot index, use Skeleton::findSlotIndex or SkeletonData::findSlotIndex
/// @param attachments Found Attachments will be added to this vector.
void findAttachmentsForSlot(int slotIndex, std::vector<Attachment*>& attachments);
/// @param attachments Found Attachments will be added to this array.
void findAttachmentsForSlot(int slotIndex, SimpleArray<Attachment*>& attachments);
const std::string& getName();
std::unordered_map<AttachmentKey, Attachment*>& getAttachments();
HashMap<AttachmentKey, Attachment*, HashAttachmentKey>& getAttachments();
private:
const std::string _name;
std::unordered_map<AttachmentKey, Attachment*> _attachments;
HashMap<AttachmentKey, Attachment*, HashAttachmentKey> _attachments;
/// Attach all attachments from this skin if the corresponding attachment from the old skin is currently attached.
void attachAll(Skeleton& skeleton, Skin& oldSkin);
friend std::ostream& operator <<(std::ostream& os, const Skin& ref);
};
}
namespace std
struct HashAttachmentKey
{
template <>
struct hash<Spine::Skin::AttachmentKey>
std::size_t operator()(const Spine::Skin::AttachmentKey& val) const
{
std::size_t operator()(const Spine::Skin::AttachmentKey& val) const
{
size_t h1 = hash<int>{}(val._slotIndex);
size_t h2 = hash<string>{}(val._name);
return h1 ^ (h2 << 1);
}
};
}
std::size_t h1 = std::hash<int>{}(val._slotIndex);
std::size_t h2 = std::hash<std::string>{}(val._name);
return h1 ^ (h2 << 1);
}
};
#endif /* Spine_Skin_h */

View File

@ -31,8 +31,9 @@
#ifndef Spine_Slot_h
#define Spine_Slot_h
#include <spine/SimpleArray.h>
#include <string>
#include <vector>
namespace Spine
{
@ -77,8 +78,8 @@ namespace Spine
float getAttachmentTime();
void setAttachmentTime(float inValue);
std::vector<float>& getAttachmentVertices();
void setAttachmentVertices(std::vector<float> inValue);
SimpleArray<float>& getAttachmentVertices();
void setAttachmentVertices(SimpleArray<float> inValue);
private:
const SlotData& _slotData;
@ -89,10 +90,8 @@ namespace Spine
bool _hasSecondColor;
Attachment* _attachment;
float _attachmentTime;
std::vector<float> _attachmentVertices;
friend std::ostream& operator <<(std::ostream& os, const Slot& ref);
}
SimpleArray<float> _attachmentVertices;
};
}
#endif /* Spine_Slot_h */

View File

@ -84,8 +84,6 @@ namespace Spine
bool _hasSecondColor;
std::string _attachmentName;
BlendMode _blendMode;
friend std::ostream& operator <<(std::ostream& os, const SlotData& ref);
};
}

View File

@ -31,11 +31,10 @@
#ifndef Spine_Timeline_h
#define Spine_Timeline_h
#include <spine/SimpleArray.h>
#include <spine/MixPose.h>
#include <spine/MixDirection.h>
#include <vector>
namespace Spine
{
class Skeleton;
@ -52,14 +51,14 @@ namespace Spine
/// @param skeleton The skeleton the timeline is being applied to. This provides access to the bones, slots, and other skeleton components the timeline may change.
/// @param lastTime lastTime The time this timeline was last applied. Timelines such as EventTimeline trigger only at specific times rather than every frame. In that case, the timeline triggers everything between lastTime (exclusive) and time (inclusive).
/// @param time The time within the animation. Most timelines find the key before and the key after this time so they can interpolate between the keys.
/// @param events If any events are fired, they are added to this list. Can be null to ignore firing events or if the timeline does not fire events. May be null.
/// @param events If any events are fired, they are added to this array. Can be null to ignore firing events or if the timeline does not fire events. May be null.
/// @param alpha alpha 0 applies the current or setup pose value (depending on pose parameter). 1 applies the timeline
/// value. Between 0 and 1 applies a value between the current or setup pose and the timeline value. By adjusting
/// alpha over time, an animation can be mixed in or out. alpha can also be useful to
/// apply animations on top of each other (layered).
/// @param pose Controls how mixing is applied when alpha is than 1.
/// @param direction Indicates whether the timeline is mixing in or out. Used by timelines which perform instant transitions such as DrawOrderTimeline and AttachmentTimeline.
virtual void apply(Skeleton& skeleton, float lastTime, float time, std::vector<Event*>& events, float alpha, MixPose pose, MixDirection direction) = 0;
virtual void apply(Skeleton& skeleton, float lastTime, float time, SimpleArray<Event*>& events, float alpha, MixPose pose, MixDirection direction) = 0;
virtual int getPropertyId() = 0;
};

View File

@ -31,8 +31,9 @@
#ifndef Spine_TransformConstraintData_h
#define Spine_TransformConstraintData_h
#include <spine/SimpleArray.h>
#include <string>
#include <vector>
namespace Spine
{
@ -45,7 +46,7 @@ namespace Spine
const std::string& getName();
int getOrder();
std::vector<BoneData*>& getBones();
SimpleArray<BoneData*>& getBones();
BoneData* getTarget();
float getRotateMix();
float getTranslateMix();
@ -65,13 +66,11 @@ namespace Spine
private:
const std::string _name;
int _order;
std::vector<BoneData*> _bones;
SimpleArray<BoneData*> _bones;
BoneData* _target;
float _rotateMix, _translateMix, _scaleMix, _shearMix;
float _offsetRotation, _offsetX, _offsetY, _offsetScaleX, _offsetScaleY, _offsetShearY;
bool _relative, _local;
friend std::ostream& operator <<(std::ostream& os, const TransformConstraintData& ref);
};
}

View File

@ -43,11 +43,4 @@ namespace Spine
{
return _name;
}
std::ostream& operator <<(std::ostream& os, const Attachment& ref)
{
os << ref._name;
return os;
}
}

View File

@ -32,10 +32,5 @@
namespace Spine
{
std::ostream& operator <<(std::ostream& os, const Bone& ref)
{
os << ref._data._name;
return os;
}
// TODO
}

View File

@ -156,11 +156,4 @@ namespace Spine
{
_transformMode = inValue;
}
std::ostream& operator <<(std::ostream& os, const BoneData& ref)
{
os << ref._name;
return os;
}
}

View File

@ -83,11 +83,4 @@ namespace Spine
{
_stringValue = inValue;
}
std::ostream& operator <<(std::ostream& os, const Event& ref)
{
os << ref._data;
return os;
}
}

View File

@ -78,11 +78,4 @@ namespace Spine
{
_stringValue = inValue;
}
std::ostream& operator <<(std::ostream& os, const EventData& ref)
{
os << ref._name;
return os;
}
}

View File

@ -57,7 +57,7 @@ namespace Spine
_order = inValue;
}
std::vector<BoneData*>& IkConstraintData::getBones()
SimpleArray<BoneData*>& IkConstraintData::getBones()
{
return _bones;
}
@ -91,11 +91,4 @@ namespace Spine
{
_mix = inValue;
}
std::ostream& operator <<(std::ostream& os, const IkConstraintData& ref)
{
os << ref._name;
return os;
}
}

View File

@ -68,7 +68,7 @@ namespace Spine
_order = inValue;
}
std::vector<BoneData*>& PathConstraintData::getBones()
SimpleArray<BoneData*>& PathConstraintData::getBones()
{
return _bones;
}
@ -162,11 +162,4 @@ namespace Spine
{
_translateMix = inValue;
}
std::ostream& operator <<(std::ostream& os, const PathConstraintData& ref)
{
os << ref._name;
return os;
}
}

View File

@ -43,7 +43,7 @@ namespace Spine
_frames.reserve(frameCount << 1);
}
void RotateTimeline::apply(Skeleton& skeleton, float lastTime, float time, std::vector<Event*>& events, float alpha, MixPose pose, MixDirection direction)
void RotateTimeline::apply(Skeleton& skeleton, float lastTime, float time, SimpleArray<Event*>& events, float alpha, MixPose pose, MixDirection direction)
{
Bone* bone = skeleton.getBones().at(_boneIndex);
@ -127,12 +127,12 @@ namespace Spine
_boneIndex = inValue;
}
std::vector<float>& RotateTimeline::getFrames()
SimpleArray<float>& RotateTimeline::getFrames()
{
return _frames;
}
void RotateTimeline::setFrames(std::vector<float> inValue)
void RotateTimeline::setFrames(SimpleArray<float> inValue)
{
_frames = inValue;
}

View File

@ -65,36 +65,36 @@ namespace Spine
Attachment* Skin::getAttachment(int slotIndex, std::string name)
{
std::unordered_map<AttachmentKey, Attachment*>::iterator q = _attachments.find(AttachmentKey(slotIndex, name));
HashMap<AttachmentKey, Attachment*, HashAttachmentKey>::Iterator i = _attachments.find(AttachmentKey(slotIndex, name));
Attachment* ret = nullptr;
if (q != _attachments.end())
if (i != _attachments.end())
{
ret = q->second;
ret = i.second();
}
return ret;
}
void Skin::findNamesForSlot(int slotIndex, std::vector<std::string>& names)
void Skin::findNamesForSlot(int slotIndex, SimpleArray<std::string>& names)
{
for (std::unordered_map<AttachmentKey, Attachment*>::iterator i = _attachments.begin(); i != _attachments.end(); ++i)
for (HashMap<AttachmentKey, Attachment*, HashAttachmentKey>::Iterator i = _attachments.begin(); i != _attachments.end(); ++i)
{
if (i->first._slotIndex == slotIndex)
if (i.first()._slotIndex == slotIndex)
{
names.push_back(i->first._name);
names.push_back(i.first()._name);
}
}
}
void Skin::findAttachmentsForSlot(int slotIndex, std::vector<Attachment*>& attachments)
void Skin::findAttachmentsForSlot(int slotIndex, SimpleArray<Attachment*>& attachments)
{
for (std::unordered_map<AttachmentKey, Attachment*>::iterator i = _attachments.begin(); i != _attachments.end(); ++i)
for (HashMap<AttachmentKey, Attachment*, HashAttachmentKey>::Iterator i = _attachments.begin(); i != _attachments.end(); ++i)
{
if (i->first._slotIndex == slotIndex)
if (i.first()._slotIndex == slotIndex)
{
attachments.push_back(i->second);
attachments.push_back(i.second());
}
}
}
@ -104,33 +104,26 @@ namespace Spine
return _name;
}
std::unordered_map<Skin::AttachmentKey, Attachment*>& Skin::getAttachments()
HashMap<Skin::AttachmentKey, Attachment*, HashAttachmentKey>& Skin::getAttachments()
{
return _attachments;
}
void Skin::attachAll(Skeleton& skeleton, Skin& oldSkin)
{
for (std::unordered_map<AttachmentKey, Attachment*>::iterator i = oldSkin.getAttachments().begin(); i != oldSkin.getAttachments().end(); ++i)
for (HashMap<AttachmentKey, Attachment*, HashAttachmentKey>::Iterator i = oldSkin.getAttachments().begin(); i != oldSkin.getAttachments().end(); ++i)
{
int slotIndex = i->first._slotIndex;
int slotIndex = i.first()._slotIndex;
Slot* slot = skeleton.getSlots().at(slotIndex);
if (slot->getAttachment() == i->second)
if (slot->getAttachment() == i.second())
{
Attachment* attachment = nullptr;
if ((attachment = getAttachment(slotIndex, i->first._name)))
if ((attachment = getAttachment(slotIndex, i.first()._name)))
{
slot->setAttachment(attachment);
}
}
}
}
std::ostream& operator <<(std::ostream& os, const Skin& ref)
{
os << ref._name;
return os;
}
}

View File

@ -196,20 +196,13 @@ namespace Spine
_attachmentTime = _skeleton.getTime() - inValue;
}
std::vector<float>& Slot::getAttachmentVertices()
SimpleArray<float>& Slot::getAttachmentVertices()
{
return _attachmentVertices;
}
void Slot::setAttachmentVertices(std::vector<float> inValue)
void Slot::setAttachmentVertices(SimpleArray<float> inValue)
{
_attachmentVertices = inValue;
}
std::ostream& operator <<(std::ostream& os, const Slot& ref)
{
os << ref._slotData.getName();
return os;
}
}

View File

@ -167,11 +167,4 @@ namespace Spine
{
_blendMode = inValue;
}
std::ostream& operator <<(std::ostream& os, const SlotData& ref)
{
os << ref._name;
return os;
}
}

View File

@ -65,7 +65,7 @@ namespace Spine
{
return _order;
}
std::vector<BoneData*>& TransformConstraintData::getBones()
SimpleArray<BoneData*>& TransformConstraintData::getBones()
{
return _bones;
}
@ -134,11 +134,4 @@ namespace Spine
{
return _local;
}
std::ostream& operator <<(std::ostream& os, const TransformConstraintData& ref)
{
os << ref._name;
return os;
}
}