SkeletonBinary.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated May 1, 2019. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2019, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY EXPRESS
  19. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  21. * NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS
  24. * INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  27. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #ifndef Spine_SkeletonBinary_h
  30. #define Spine_SkeletonBinary_h
  31. #include <spine/TransformMode.h>
  32. #include <spine/Vector.h>
  33. #include <spine/SpineObject.h>
  34. #include <spine/SpineString.h>
  35. #include <spine/Color.h>
  36. namespace spine {
  37. class SkeletonData;
  38. class Atlas;
  39. class AttachmentLoader;
  40. class LinkedMesh;
  41. class Skin;
  42. class Attachment;
  43. class VertexAttachment;
  44. class Animation;
  45. class CurveTimeline;
  46. class SP_API SkeletonBinary : public SpineObject {
  47. public:
  48. static const int BONE_ROTATE;
  49. static const int BONE_TRANSLATE;
  50. static const int BONE_SCALE;
  51. static const int BONE_SHEAR;
  52. static const int SLOT_ATTACHMENT;
  53. static const int SLOT_COLOR;
  54. static const int SLOT_TWO_COLOR;
  55. static const int PATH_POSITION;
  56. static const int PATH_SPACING;
  57. static const int PATH_MIX;
  58. static const int CURVE_LINEAR;
  59. static const int CURVE_STEPPED;
  60. static const int CURVE_BEZIER;
  61. explicit SkeletonBinary(Atlas* atlasArray);
  62. explicit SkeletonBinary(AttachmentLoader* attachmentLoader);
  63. ~SkeletonBinary();
  64. SkeletonData* readSkeletonData(const unsigned char* binary, int length);
  65. SkeletonData* readSkeletonDataFile(const String& path);
  66. void setScale(float scale) { _scale = scale; }
  67. String& getError() { return _error; }
  68. private:
  69. struct DataInput : public SpineObject {
  70. const unsigned char* cursor;
  71. const unsigned char* end;
  72. };
  73. AttachmentLoader* _attachmentLoader;
  74. Vector<LinkedMesh*> _linkedMeshes;
  75. String _error;
  76. float _scale;
  77. const bool _ownsLoader;
  78. void setError(const char* value1, const char* value2);
  79. char* readString(DataInput* input);
  80. char* readStringRef(DataInput* input, SkeletonData* skeletonData);
  81. float readFloat(DataInput* input);
  82. unsigned char readByte(DataInput* input);
  83. signed char readSByte(DataInput* input);
  84. bool readBoolean(DataInput* input);
  85. int readInt(DataInput* input);
  86. void readColor(DataInput* input, Color& color);
  87. int readVarint(DataInput* input, bool optimizePositive);
  88. Skin* readSkin(DataInput* input, bool defaultSkin, SkeletonData* skeletonData, bool nonessential);
  89. Attachment* readAttachment(DataInput* input, Skin* skin, int slotIndex, const String& attachmentName, SkeletonData* skeletonData, bool nonessential);
  90. void readVertices(DataInput* input, VertexAttachment* attachment, int vertexCount);
  91. void readFloatArray(DataInput *input, int n, float scale, Vector<float>& array);
  92. void readShortArray(DataInput *input, Vector<unsigned short>& array);
  93. Animation* readAnimation(const String& name, DataInput* input, SkeletonData *skeletonData);
  94. void readCurve(DataInput* input, int frameIndex, CurveTimeline* timeline);
  95. };
  96. }
  97. #endif /* Spine_SkeletonBinary_h */