diff --git a/spine-cpp/spine-cpp/include/spine/Skeleton.h b/spine-cpp/spine-cpp/include/spine/Skeleton.h new file mode 100644 index 000000000..0ea3e5db1 --- /dev/null +++ b/spine-cpp/spine-cpp/include/spine/Skeleton.h @@ -0,0 +1,39 @@ +/****************************************************************************** + * 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_Skeleton_h +#define Spine_Skeleton_h + +namespace Spine +{ + // TODO +} + +#endif /* Spine_Skeleton_h */ diff --git a/spine-cpp/spine-cpp/include/spine/Skin.h b/spine-cpp/spine-cpp/include/spine/Skin.h index 910e2585e..7a8b0f31a 100644 --- a/spine-cpp/spine-cpp/include/spine/Skin.h +++ b/spine-cpp/spine-cpp/include/spine/Skin.h @@ -40,14 +40,23 @@ namespace Spine class Attachment; class Skeleton; - class AttachmentKey; - /// 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 { public: + class AttachmentKey + { + public: + const int _slotIndex; + const std::string _name; + + AttachmentKey(int slotIndex, std::string name); + + bool operator==(const AttachmentKey &other) const; + }; + Skin(std::string name); /// Adds an attachment to the skin for the specified slot index and name. @@ -77,32 +86,21 @@ namespace Spine /// Attach all attachments from this skin if the corresponding attachment from the old skin is currently attached. void attachAll(Skeleton& skeleton, Skin& oldSkin); - class AttachmentKey - { - public: - const int _slotIndex; - const std::string _name; - - AttachmentKey(int slotIndex, std::string name); - - bool operator==(const AttachmentKey &other) const; - }; - friend std::ostream& operator <<(std::ostream& os, const Skin& ref); - - namespace std + }; +} + +namespace std +{ + template <> + struct hash + { + std::size_t operator()(const Spine::Skin::AttachmentKey& val) const { - template <> - struct hash - { - size_t operator()(const AttachmentKey& val) const - { - size_t h1 = hash{}(val._slotIndex); - size_t h2 = hash{}(val._name); - - return h1 ^ (h2 << 1); - } - }; + size_t h1 = hash{}(val._slotIndex); + size_t h2 = hash{}(val._name); + + return h1 ^ (h2 << 1); } }; } diff --git a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp new file mode 100644 index 000000000..bb4d2ccfe --- /dev/null +++ b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp @@ -0,0 +1,34 @@ +/****************************************************************************** +* 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. +*****************************************************************************/ + +namespace Spine +{ + // TODO +} diff --git a/spine-cpp/spine-cpp/src/spine/Skin.cpp b/spine-cpp/spine-cpp/src/spine/Skin.cpp index 8ee4f916a..c4e9ab0d5 100644 --- a/spine-cpp/spine-cpp/src/spine/Skin.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skin.cpp @@ -30,10 +30,27 @@ #include +#include +#include + +#include + #include namespace Spine { + Skin::AttachmentKey::AttachmentKey(int slotIndex, std::string name) : + _slotIndex(slotIndex), + _name(name) + { + // Empty + } + + bool Skin::AttachmentKey::operator==(const AttachmentKey &other) const + { + return _slotIndex == other._slotIndex && _name == other._name; + } + Skin::Skin(std::string name) : _name(name) { assert(_name.length() > 0); @@ -46,10 +63,9 @@ namespace Spine _attachments[AttachmentKey(slotIndex, name)] = attachment; } - /// Returns the attachment for the specified slot index and name, or null. Attachment* Skin::getAttachment(int slotIndex, std::string name) { - std::iterator q = _attachments.find(AttachmentKey(slotIndex, name)); + std::unordered_map::iterator q = _attachments.find(AttachmentKey(slotIndex, name)); Attachment* ret = nullptr; @@ -61,73 +77,59 @@ namespace Spine return ret; } - struct sum - { - sum(int * t):total(t){}; - int * total; - - void operator()(AttachmentKey key) - { - *total+=element; - } - }; - - /// Finds the skin keys for a given slot. The results are added to the passed vector 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 Skin::findNamesForSlot(int slotIndex, std::vector& names) { - foreach (AttachmentKey key in attachments.Keys) - if (key.slotIndex == slotIndex) names.Add(key.name); - } - - /// Finds the attachments for a given slot. The results are added to the passed List(Attachment). - /// @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 Skin::findAttachmentsForSlot(int slotIndex, std::vector& attachments) - { - foreach (KeyValuePair entry in this.attachments) - if (entry.Key.slotIndex == slotIndex) attachments.Add(entry.Value); - } - - const std::string& Skin::getName() - { - // - } - - std::unordered_map& Skin::getAttachments() - { - // - } - - void Skin::attachAll(Skeleton& skeleton, Skin& oldSkin) - { - foreach (KeyValuePair entry in oldSkin.attachments) + for (std::unordered_map::iterator i = _attachments.begin(); i != _attachments.end(); ++i) { - int slotIndex = entry.Key.slotIndex; - Slot slot = skeleton.slots.Items[slotIndex]; - if (slot.Attachment == entry.Value) { - Attachment attachment = GetAttachment(slotIndex, entry.Key.name); - if (attachment != null) slot.Attachment = attachment; + if (i->first._slotIndex == slotIndex) + { + names.push_back(i->first._name); } } } - AttachmentKey::AttachmentKey(int slotIndex, std::string name) : - _slotIndex(slotIndex), - _name(name) + void Skin::findAttachmentsForSlot(int slotIndex, std::vector& attachments) { - // Empty + for (std::unordered_map::iterator i = _attachments.begin(); i != _attachments.end(); ++i) + { + if (i->first._slotIndex == slotIndex) + { + attachments.push_back(i->second); + } + } } - bool AttachmentKey::operator==(const AttachmentKey &other) const + const std::string& Skin::getName() { - return _slotIndex == other._slotIndex && _name == other._name; + return _name; + } + + std::unordered_map& Skin::getAttachments() + { + return _attachments; + } + + void Skin::attachAll(Skeleton& skeleton, Skin& oldSkin) + { + for (std::unordered_map::iterator i = oldSkin.getAttachments().begin(); i != oldSkin.getAttachments().end(); ++i) + { + int slotIndex = i->first._slotIndex; + Slot* slot = skeleton.getSlots().at(slotIndex); + + if (slot->getAttachment() == i->second) + { + Attachment* attachment = nullptr; + if ((attachment = getAttachment(slotIndex, i->first._name))) + { + slot->setAttachment(attachment); + } + } + } } std::ostream& operator <<(std::ostream& os, const Skin& ref) { - os << ref.getName(); + os << ref._name; return os; }