mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
wip
This commit is contained in:
parent
6c81a6e392
commit
4b48dae7f5
39
spine-cpp/spine-cpp/include/spine/Skeleton.h
Normal file
39
spine-cpp/spine-cpp/include/spine/Skeleton.h
Normal file
@ -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 */
|
||||
@ -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<Spine::Skin::AttachmentKey>
|
||||
{
|
||||
std::size_t operator()(const Spine::Skin::AttachmentKey& val) const
|
||||
{
|
||||
template <>
|
||||
struct hash<AttachmentKey>
|
||||
{
|
||||
size_t operator()(const AttachmentKey& val) const
|
||||
{
|
||||
size_t h1 = hash<int>{}(val._slotIndex);
|
||||
size_t h2 = hash<string>{}(val._name);
|
||||
|
||||
return h1 ^ (h2 << 1);
|
||||
}
|
||||
};
|
||||
size_t h1 = hash<int>{}(val._slotIndex);
|
||||
size_t h2 = hash<string>{}(val._name);
|
||||
|
||||
return h1 ^ (h2 << 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
34
spine-cpp/spine-cpp/src/spine/Skeleton.cpp
Normal file
34
spine-cpp/spine-cpp/src/spine/Skeleton.cpp
Normal file
@ -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
|
||||
}
|
||||
@ -30,10 +30,27 @@
|
||||
|
||||
#include <spine/Skin.h>
|
||||
|
||||
#include <spine/Attachment.h>
|
||||
#include <spine/Skeleton.h>
|
||||
|
||||
#include <spine/Slot.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
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<AttachmentKey, Attachment*> q = _attachments.find(AttachmentKey(slotIndex, name));
|
||||
std::unordered_map<AttachmentKey, Attachment*>::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<std::string>& 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<Attachment*>& attachments)
|
||||
{
|
||||
foreach (KeyValuePair<AttachmentKey, Attachment> entry in this.attachments)
|
||||
if (entry.Key.slotIndex == slotIndex) attachments.Add(entry.Value);
|
||||
}
|
||||
|
||||
const std::string& Skin::getName()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
std::unordered_map<AttachmentKey, Attachment*>& Skin::getAttachments()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
void Skin::attachAll(Skeleton& skeleton, Skin& oldSkin)
|
||||
{
|
||||
foreach (KeyValuePair<AttachmentKey, Attachment> entry in oldSkin.attachments)
|
||||
for (std::unordered_map<AttachmentKey, Attachment*>::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<Attachment*>& attachments)
|
||||
{
|
||||
// Empty
|
||||
for (std::unordered_map<AttachmentKey, Attachment*>::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::AttachmentKey, Attachment*>& 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user