mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-13 18:48:44 +08:00
Closer still.
So here is what I have left: 1. Implement the Timeline classes (from Animation) 2. Implement AnimationState 3. Implement SkeletonJson 4. Implement SkeletonBinary Seems like a lot, but most of the file IO stuff is going to get more or less ripped directly from the C runtime, so I’m actually pretty close I think!
This commit is contained in:
parent
b02c2aaaa4
commit
107c18e237
@ -38,6 +38,7 @@
|
||||
namespace Spine
|
||||
{
|
||||
class Atlas;
|
||||
class AtlasRegion;
|
||||
|
||||
///
|
||||
/// An AttachmentLoader that configures attachments using texture regions from an Atlas.
|
||||
@ -48,84 +49,21 @@ namespace Spine
|
||||
SPINE_RTTI_DECL;
|
||||
|
||||
public:
|
||||
AtlasAttachmentLoader (Vector<Atlas*>& inAtlasArray) : _atlasArray(inAtlasArray)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
AtlasAttachmentLoader(Vector<Atlas*>& inAtlasArray);
|
||||
|
||||
// RegionAttachment newRegionAttachment(Skin skin, std::string name, std::string path)
|
||||
// {
|
||||
// AtlasRegion* region = findRegion(path);
|
||||
// if (region == NULL) throw new ArgumentException(std::string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name));
|
||||
// RegionAttachment attachment = new RegionAttachment(name);
|
||||
// attachment.RendererObject = region;
|
||||
// attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate);
|
||||
// attachment.regionOffsetX = region.offsetX;
|
||||
// attachment.regionOffsetY = region.offsetY;
|
||||
// attachment.regionWidth = region.width;
|
||||
// attachment.regionHeight = region.height;
|
||||
// attachment.regionOriginalWidth = region.originalWidth;
|
||||
// attachment.regionOriginalHeight = region.originalHeight;
|
||||
// return attachment;
|
||||
// }
|
||||
//
|
||||
// MeshAttachment newMeshAttachment(Skin skin, std::string name, std::string path)
|
||||
// {
|
||||
// AtlasRegion region = findRegion(path);
|
||||
// if (region == NULL) throw new ArgumentException(std::string.Format("Region not found in atlas: {0} (region attachment: {1})", path, name));
|
||||
//
|
||||
// MeshAttachment attachment = new MeshAttachment(name);
|
||||
// attachment.RendererObject = region;
|
||||
// attachment.RegionU = region.u;
|
||||
// attachment.RegionV = region.v;
|
||||
// attachment.RegionU2 = region.u2;
|
||||
// attachment.RegionV2 = region.v2;
|
||||
// attachment.RegionRotate = region.rotate;
|
||||
// attachment.regionOffsetX = region.offsetX;
|
||||
// attachment.regionOffsetY = region.offsetY;
|
||||
// attachment.regionWidth = region.width;
|
||||
// attachment.regionHeight = region.height;
|
||||
// attachment.regionOriginalWidth = region.originalWidth;
|
||||
// attachment.regionOriginalHeight = region.originalHeight;
|
||||
//
|
||||
// return attachment;
|
||||
// }
|
||||
//
|
||||
// BoundingBoxAttachment NewBoundingBoxAttachment (Skin skin, std::string name)
|
||||
// {
|
||||
// return new BoundingBoxAttachment(name);
|
||||
// }
|
||||
//
|
||||
// PathAttachment newPathAttachment(Skin skin, std::string name)
|
||||
// {
|
||||
// return new PathAttachment(name);
|
||||
// }
|
||||
//
|
||||
// PointAttachment newPointAttachment(Skin skin, std::string name)
|
||||
// {
|
||||
// return new PointAttachment(name);
|
||||
// }
|
||||
//
|
||||
// ClippingAttachment newClippingAttachment(Skin skin, std::string name)
|
||||
// {
|
||||
// return new ClippingAttachment(name);
|
||||
// }
|
||||
//
|
||||
// AtlasRegion* findRegion(std::string name)
|
||||
// {
|
||||
// AtlasRegion* ret;
|
||||
//
|
||||
// for (int i = 0; i < _atlasArray.size(); i++)
|
||||
// {
|
||||
// ret = _atlasArray[i]->findRegion(name);
|
||||
// if (ret != NULL)
|
||||
// {
|
||||
// return ret;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return NULL;
|
||||
// }
|
||||
virtual RegionAttachment* newRegionAttachment(Skin& skin, std::string name, std::string path);
|
||||
|
||||
virtual MeshAttachment* newMeshAttachment(Skin& skin, std::string name, std::string path);
|
||||
|
||||
virtual BoundingBoxAttachment* newBoundingBoxAttachment(Skin& skin, std::string name);
|
||||
|
||||
virtual PathAttachment* newPathAttachment(Skin& skin, std::string name);
|
||||
|
||||
virtual PointAttachment* newPointAttachment(Skin& skin, std::string name);
|
||||
|
||||
virtual ClippingAttachment* newClippingAttachment(Skin& skin, std::string name);
|
||||
|
||||
AtlasRegion* findRegion(std::string name);
|
||||
|
||||
private:
|
||||
Vector<Atlas*> _atlasArray;
|
||||
|
||||
@ -37,18 +37,22 @@
|
||||
|
||||
namespace Spine
|
||||
{
|
||||
class Skin;
|
||||
class RegionAttachment;
|
||||
class MeshAttachment;
|
||||
class BoundingBoxAttachment;
|
||||
class PathAttachment;
|
||||
class PointAttachment;
|
||||
class ClippingAttachment;
|
||||
class Skin;
|
||||
|
||||
class AttachmentLoader
|
||||
{
|
||||
SPINE_RTTI_DECL;
|
||||
|
||||
AttachmentLoader();
|
||||
|
||||
virtual ~AttachmentLoader();
|
||||
|
||||
/// @return May be NULL to not load any attachment.
|
||||
virtual RegionAttachment* newRegionAttachment(Skin& skin, std::string name, std::string path) = 0;
|
||||
|
||||
@ -56,7 +60,7 @@ namespace Spine
|
||||
virtual MeshAttachment* newMeshAttachment(Skin& skin, std::string name, std::string path) = 0;
|
||||
|
||||
/// @return May be NULL to not load any attachment.
|
||||
virtual BoundingBoxAttachment* NewBoundingBoxAttachment(Skin& skin, std::string name) = 0;
|
||||
virtual BoundingBoxAttachment* newBoundingBoxAttachment(Skin& skin, std::string name) = 0;
|
||||
|
||||
/// @return May be NULL to not load any attachment
|
||||
virtual PathAttachment* newPathAttachment(Skin& skin, std::string name) = 0;
|
||||
|
||||
@ -44,6 +44,8 @@ namespace Spine
|
||||
{
|
||||
SPINE_RTTI_DECL;
|
||||
|
||||
friend class AtlasAttachmentLoader;
|
||||
|
||||
public:
|
||||
MeshAttachment(std::string name);
|
||||
|
||||
|
||||
@ -48,6 +48,8 @@ namespace Spine
|
||||
{
|
||||
SPINE_RTTI_DECL;
|
||||
|
||||
friend class AtlasAttachmentLoader;
|
||||
|
||||
public:
|
||||
RegionAttachment(std::string name);
|
||||
|
||||
|
||||
@ -77,7 +77,7 @@ namespace Spine
|
||||
for (size_t i = 0, n = _regions.size(); i < n; ++i)
|
||||
{
|
||||
AtlasRegion* regionP = _regions[i];
|
||||
AtlasRegion region = *regionP;
|
||||
AtlasRegion& region = *regionP;
|
||||
region.v = 1 - region.v;
|
||||
region.v2 = 1 - region.v2;
|
||||
}
|
||||
@ -284,7 +284,11 @@ namespace Spine
|
||||
|
||||
int Atlas::readLine(const char** begin, const char* end, Str* str)
|
||||
{
|
||||
if (*begin == end) return 0;
|
||||
if (*begin == end)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
str->begin = *begin;
|
||||
|
||||
/* Find next delimiter. */
|
||||
@ -307,7 +311,8 @@ namespace Spine
|
||||
int Atlas::beginPast(Str* str, char c)
|
||||
{
|
||||
const char* begin = str->begin;
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
char lastSkippedChar = *begin;
|
||||
if (begin == str->end)
|
||||
{
|
||||
|
||||
@ -30,7 +30,120 @@
|
||||
|
||||
#include <spine/AtlasAttachmentLoader.h>
|
||||
|
||||
#include <spine/Skin.h>
|
||||
#include <spine/RegionAttachment.h>
|
||||
#include <spine/MeshAttachment.h>
|
||||
#include <spine/BoundingBoxAttachment.h>
|
||||
#include <spine/PathAttachment.h>
|
||||
#include <spine/PointAttachment.h>
|
||||
#include <spine/ClippingAttachment.h>
|
||||
|
||||
#include <spine/Atlas.h>
|
||||
|
||||
namespace Spine
|
||||
{
|
||||
SPINE_RTTI_IMPL(AtlasAttachmentLoader, AttachmentLoader);
|
||||
|
||||
AtlasAttachmentLoader::AtlasAttachmentLoader(Vector<Atlas*>& inAtlasArray) : AttachmentLoader(), _atlasArray(inAtlasArray)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
RegionAttachment* AtlasAttachmentLoader::newRegionAttachment(Skin& skin, std::string name, std::string path)
|
||||
{
|
||||
AtlasRegion* regionP = findRegion(path);
|
||||
assert(regionP != NULL);
|
||||
|
||||
AtlasRegion& region = *regionP;
|
||||
|
||||
RegionAttachment* attachmentP = MALLOC(RegionAttachment, 1);
|
||||
new (attachmentP) RegionAttachment(name);
|
||||
|
||||
RegionAttachment& attachment = *attachmentP;
|
||||
attachment._rendererObject = regionP;
|
||||
attachment.setUVs(region.u, region.v, region.u2, region.v2, region.rotate);
|
||||
attachment._regionOffsetX = region.offsetX;
|
||||
attachment._regionOffsetY = region.offsetY;
|
||||
attachment._regionWidth = region.width;
|
||||
attachment._regionHeight = region.height;
|
||||
attachment._regionOriginalWidth = region.originalWidth;
|
||||
attachment._regionOriginalHeight = region.originalHeight;
|
||||
|
||||
return attachmentP;
|
||||
}
|
||||
|
||||
MeshAttachment* AtlasAttachmentLoader::newMeshAttachment(Skin& skin, std::string name, std::string path)
|
||||
{
|
||||
AtlasRegion* regionP = findRegion(path);
|
||||
assert(regionP != NULL);
|
||||
|
||||
AtlasRegion& region = *regionP;
|
||||
|
||||
MeshAttachment* attachmentP = MALLOC(MeshAttachment, 1);
|
||||
new (attachmentP) MeshAttachment(name);
|
||||
|
||||
MeshAttachment& attachment = *attachmentP;
|
||||
attachment._rendererObject = regionP;
|
||||
attachment._regionU = region.u;
|
||||
attachment._regionV = region.v;
|
||||
attachment._regionU2 = region.u2;
|
||||
attachment._regionV2 = region.v2;
|
||||
attachment._regionRotate = region.rotate;
|
||||
attachment._regionOffsetX = region.offsetX;
|
||||
attachment._regionOffsetY = region.offsetY;
|
||||
attachment._regionWidth = region.width;
|
||||
attachment._regionHeight = region.height;
|
||||
attachment._regionOriginalWidth = region.originalWidth;
|
||||
attachment._regionOriginalHeight = region.originalHeight;
|
||||
|
||||
return attachmentP;
|
||||
}
|
||||
|
||||
BoundingBoxAttachment* AtlasAttachmentLoader::newBoundingBoxAttachment(Skin& skin, std::string name)
|
||||
{
|
||||
BoundingBoxAttachment* attachmentP = MALLOC(BoundingBoxAttachment, 1);
|
||||
new (attachmentP) BoundingBoxAttachment(name);
|
||||
|
||||
return attachmentP;
|
||||
}
|
||||
|
||||
PathAttachment* AtlasAttachmentLoader::newPathAttachment(Skin& skin, std::string name)
|
||||
{
|
||||
PathAttachment* attachmentP = MALLOC(PathAttachment, 1);
|
||||
new (attachmentP) PathAttachment(name);
|
||||
|
||||
return attachmentP;
|
||||
}
|
||||
|
||||
PointAttachment* AtlasAttachmentLoader::newPointAttachment(Skin& skin, std::string name)
|
||||
{
|
||||
PointAttachment* attachmentP = MALLOC(PointAttachment, 1);
|
||||
new (attachmentP) PointAttachment(name);
|
||||
|
||||
return attachmentP;
|
||||
}
|
||||
|
||||
ClippingAttachment* AtlasAttachmentLoader::newClippingAttachment(Skin& skin, std::string name)
|
||||
{
|
||||
ClippingAttachment* attachmentP = MALLOC(ClippingAttachment, 1);
|
||||
new (attachmentP) ClippingAttachment(name);
|
||||
|
||||
return attachmentP;
|
||||
}
|
||||
|
||||
AtlasRegion* AtlasAttachmentLoader::findRegion(std::string name)
|
||||
{
|
||||
AtlasRegion* ret;
|
||||
|
||||
for (int i = 0; i < _atlasArray.size(); i++)
|
||||
{
|
||||
ret = _atlasArray[i]->findRegion(name);
|
||||
if (ret != NULL)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,25 @@
|
||||
|
||||
#include <spine/AttachmentLoader.h>
|
||||
|
||||
#include <spine/Skin.h>
|
||||
#include <spine/RegionAttachment.h>
|
||||
#include <spine/MeshAttachment.h>
|
||||
#include <spine/BoundingBoxAttachment.h>
|
||||
#include <spine/PathAttachment.h>
|
||||
#include <spine/PointAttachment.h>
|
||||
#include <spine/ClippingAttachment.h>
|
||||
|
||||
namespace Spine
|
||||
{
|
||||
SPINE_RTTI_IMPL_NOPARENT(AttachmentLoader);
|
||||
|
||||
AttachmentLoader::AttachmentLoader()
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
AttachmentLoader::~AttachmentLoader()
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ namespace Spine
|
||||
}
|
||||
|
||||
Bone* parent = bone.getParent();
|
||||
Bone p = *parent;
|
||||
Bone& p = *parent;
|
||||
|
||||
float id = 1 / (p._a * p._d - p._b * p._c);
|
||||
float x = targetX - p._worldX, y = targetY - p._worldY;
|
||||
@ -151,7 +151,7 @@ namespace Spine
|
||||
}
|
||||
|
||||
Bone* parentparent = parent._parent;
|
||||
Bone pp = *parentparent;
|
||||
Bone& pp = *parentparent;
|
||||
|
||||
a = pp._a;
|
||||
b = pp._b;
|
||||
|
||||
@ -114,7 +114,7 @@ namespace Spine
|
||||
for (int i = 0, n = spacesCount - 1; i < n;)
|
||||
{
|
||||
Bone* boneP = _bones[i];
|
||||
Bone bone = *boneP;
|
||||
Bone& bone = *boneP;
|
||||
float setupLength = bone._data.getLength();
|
||||
if (setupLength < PathConstraint::EPSILON)
|
||||
{
|
||||
@ -165,7 +165,7 @@ namespace Spine
|
||||
for (int i = 0, p = 3; i < boneCount; i++, p += 3)
|
||||
{
|
||||
Bone* boneP = _bones[i];
|
||||
Bone bone = *boneP;
|
||||
Bone& bone = *boneP;
|
||||
bone._worldX += (boneX - bone._worldX) * translateMix;
|
||||
bone._worldY += (boneY - bone._worldY) * translateMix;
|
||||
float x = positions[p];
|
||||
@ -306,10 +306,8 @@ namespace Spine
|
||||
|
||||
Vector<float> PathConstraint::computeWorldPositions(PathAttachment& path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing)
|
||||
{
|
||||
Slot target = *_target;
|
||||
Slot& target = *_target;
|
||||
float position = _position;
|
||||
// float[] spacesItems = _spaces.Items;
|
||||
// float[] output = _positions.Resize(spacesCount * 3 + 2).Items;
|
||||
_positions.reserve(spacesCount * 3 + 2);
|
||||
bool closed = path.isClosed();
|
||||
int verticesLength = path.getWorldVerticesLength();
|
||||
|
||||
@ -232,7 +232,7 @@ namespace Spine
|
||||
for (int i = 0, n = static_cast<int>(_updateCacheReset.size()); i < n; ++i)
|
||||
{
|
||||
Bone* boneP = _updateCacheReset[i];
|
||||
Bone bone = *boneP;
|
||||
Bone& bone = *boneP;
|
||||
bone._ax = bone._x;
|
||||
bone._ay = bone._y;
|
||||
bone._arotation = bone._rotation;
|
||||
@ -265,7 +265,7 @@ namespace Spine
|
||||
for (int i = 0, n = static_cast<int>(_ikConstraints.size()); i < n; ++i)
|
||||
{
|
||||
IkConstraint* constraintP = _ikConstraints[i];
|
||||
IkConstraint constraint = *constraintP;
|
||||
IkConstraint& constraint = *constraintP;
|
||||
|
||||
constraint._bendDirection = constraint._data._bendDirection;
|
||||
constraint._mix = constraint._data._mix;
|
||||
@ -274,7 +274,7 @@ namespace Spine
|
||||
for (int i = 0, n = static_cast<int>(_transformConstraints.size()); i < n; ++i)
|
||||
{
|
||||
TransformConstraint* constraintP = _transformConstraints[i];
|
||||
TransformConstraint constraint = *constraintP;
|
||||
TransformConstraint& constraint = *constraintP;
|
||||
TransformConstraintData& constraintData = constraint._data;
|
||||
|
||||
constraint._rotateMix = constraintData._rotateMix;
|
||||
@ -286,7 +286,7 @@ namespace Spine
|
||||
for (int i = 0, n = static_cast<int>(_pathConstraints.size()); i < n; ++i)
|
||||
{
|
||||
PathConstraint* constraintP = _pathConstraints[i];
|
||||
PathConstraint constraint = *constraintP;
|
||||
PathConstraint& constraint = *constraintP;
|
||||
PathConstraintData& constraintData = constraint._data;
|
||||
|
||||
constraint._position = constraintData._position;
|
||||
@ -353,7 +353,7 @@ namespace Spine
|
||||
for (int i = 0, n = static_cast<int>(_slots.size()); i < n; ++i)
|
||||
{
|
||||
Slot* slotP = _slots[i];
|
||||
Slot slot = *slotP;
|
||||
Slot& slot = *slotP;
|
||||
std::string name = slot._data.getAttachmentName();
|
||||
if (name.length() > 0)
|
||||
{
|
||||
|
||||
@ -157,7 +157,7 @@ namespace Spine
|
||||
void TransformConstraint::applyAbsoluteWorld()
|
||||
{
|
||||
float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix;
|
||||
Bone target = *_target;
|
||||
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;
|
||||
@ -252,7 +252,7 @@ namespace Spine
|
||||
void TransformConstraint::applyRelativeWorld()
|
||||
{
|
||||
float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix;
|
||||
Bone target = *_target;
|
||||
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;
|
||||
@ -335,7 +335,7 @@ namespace Spine
|
||||
void TransformConstraint::applyAbsoluteLocal()
|
||||
{
|
||||
float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix;
|
||||
Bone target = *_target;
|
||||
Bone& target = *_target;
|
||||
if (!target._appliedValid)
|
||||
{
|
||||
target.updateAppliedTransform();
|
||||
@ -395,7 +395,7 @@ namespace Spine
|
||||
void TransformConstraint::applyRelativeLocal()
|
||||
{
|
||||
float rotateMix = _rotateMix, translateMix = _translateMix, scaleMix = _scaleMix, shearMix = _shearMix;
|
||||
Bone target = *_target;
|
||||
Bone& target = *_target;
|
||||
if (!target._appliedValid)
|
||||
{
|
||||
target.updateAppliedTransform();
|
||||
|
||||
@ -96,7 +96,7 @@ namespace Spine
|
||||
for (; v < n; v++, b += 3)
|
||||
{
|
||||
Bone* boneP = skeletonBones[bones[v]];
|
||||
Bone bone = *boneP;
|
||||
Bone& bone = *boneP;
|
||||
float vx = vertices[b];
|
||||
float vy = vertices[b + 1];
|
||||
float weight = vertices[b + 2];
|
||||
@ -117,7 +117,7 @@ namespace Spine
|
||||
for (; v < n; v++, b += 3, f += 2)
|
||||
{
|
||||
Bone* boneP = skeletonBones[bones[v]];
|
||||
Bone bone = *boneP;
|
||||
Bone& bone = *boneP;
|
||||
float vx = vertices[b] + deformArray[f];
|
||||
float vy = vertices[b + 1] + deformArray[f + 1];
|
||||
float weight = vertices[b + 2];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user