From 107c18e237269838dc09ab0d295a25882dde865b Mon Sep 17 00:00:00 2001 From: Stephen Gowen Date: Fri, 24 Nov 2017 18:13:14 -0500 Subject: [PATCH] Closer still. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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! --- .../include/spine/AtlasAttachmentLoader.h | 92 +++----------- .../include/spine/AttachmentLoader.h | 8 +- .../spine-cpp/include/spine/MeshAttachment.h | 2 + .../include/spine/RegionAttachment.h | 2 + spine-cpp/spine-cpp/src/spine/Atlas.cpp | 11 +- .../src/spine/AtlasAttachmentLoader.cpp | 113 ++++++++++++++++++ .../spine-cpp/src/spine/AttachmentLoader.cpp | 18 +++ .../spine-cpp/src/spine/IkConstraint.cpp | 4 +- .../spine-cpp/src/spine/PathConstraint.cpp | 8 +- spine-cpp/spine-cpp/src/spine/Skeleton.cpp | 10 +- .../src/spine/TransformConstraint.cpp | 8 +- .../spine-cpp/src/spine/VertexAttachment.cpp | 4 +- 12 files changed, 180 insertions(+), 100 deletions(-) diff --git a/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h b/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h index a226f36a6..2805482af 100644 --- a/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h +++ b/spine-cpp/spine-cpp/include/spine/AtlasAttachmentLoader.h @@ -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& inAtlasArray) : _atlasArray(inAtlasArray) - { - // Empty - } + AtlasAttachmentLoader(Vector& 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 _atlasArray; diff --git a/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h b/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h index 7712e4cc1..e194e019b 100644 --- a/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h +++ b/spine-cpp/spine-cpp/include/spine/AttachmentLoader.h @@ -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; diff --git a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h index dee544d61..c29e93fb4 100644 --- a/spine-cpp/spine-cpp/include/spine/MeshAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/MeshAttachment.h @@ -44,6 +44,8 @@ namespace Spine { SPINE_RTTI_DECL; + friend class AtlasAttachmentLoader; + public: MeshAttachment(std::string name); diff --git a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h index 9151691c0..780c5b8ce 100644 --- a/spine-cpp/spine-cpp/include/spine/RegionAttachment.h +++ b/spine-cpp/spine-cpp/include/spine/RegionAttachment.h @@ -48,6 +48,8 @@ namespace Spine { SPINE_RTTI_DECL; + friend class AtlasAttachmentLoader; + public: RegionAttachment(std::string name); diff --git a/spine-cpp/spine-cpp/src/spine/Atlas.cpp b/spine-cpp/spine-cpp/src/spine/Atlas.cpp index 1ceca89b7..8a9db562a 100644 --- a/spine-cpp/spine-cpp/src/spine/Atlas.cpp +++ b/spine-cpp/spine-cpp/src/spine/Atlas.cpp @@ -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) { diff --git a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp index 0d5a99aca..bea6e30e7 100644 --- a/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp +++ b/spine-cpp/spine-cpp/src/spine/AtlasAttachmentLoader.cpp @@ -30,7 +30,120 @@ #include +#include +#include +#include +#include +#include +#include +#include + +#include + namespace Spine { SPINE_RTTI_IMPL(AtlasAttachmentLoader, AttachmentLoader); + + AtlasAttachmentLoader::AtlasAttachmentLoader(Vector& 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; + } } diff --git a/spine-cpp/spine-cpp/src/spine/AttachmentLoader.cpp b/spine-cpp/spine-cpp/src/spine/AttachmentLoader.cpp index 04c5e3979..af55271f2 100644 --- a/spine-cpp/spine-cpp/src/spine/AttachmentLoader.cpp +++ b/spine-cpp/spine-cpp/src/spine/AttachmentLoader.cpp @@ -30,7 +30,25 @@ #include +#include +#include +#include +#include +#include +#include +#include + namespace Spine { SPINE_RTTI_IMPL_NOPARENT(AttachmentLoader); + + AttachmentLoader::AttachmentLoader() + { + // Empty + } + + AttachmentLoader::~AttachmentLoader() + { + // Empty + } } diff --git a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp index 4c6c0e8c5..f0838c6af 100644 --- a/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/IkConstraint.cpp @@ -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; diff --git a/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp b/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp index 5d90c2ea7..c44a495ba 100644 --- a/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/PathConstraint.cpp @@ -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 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(); diff --git a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp index d5cf4ce62..b295f83d7 100644 --- a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp @@ -232,7 +232,7 @@ namespace Spine for (int i = 0, n = static_cast(_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(_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(_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(_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(_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) { diff --git a/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp b/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp index 04cd07a1c..166713279 100644 --- a/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp +++ b/spine-cpp/spine-cpp/src/spine/TransformConstraint.cpp @@ -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(); diff --git a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp index e16de993e..9968a77ce 100644 --- a/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp +++ b/spine-cpp/spine-cpp/src/spine/VertexAttachment.cpp @@ -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];