[cpp] 4.3 porting WIP

This commit is contained in:
Mario Zechner 2025-07-05 02:10:45 +02:00
parent d7891870bf
commit c04f89e8ee
13 changed files with 709 additions and 715 deletions

View File

@ -30,6 +30,8 @@
#ifndef Spine_AttachmentType_h
#define Spine_AttachmentType_h
#include <string.h>
namespace spine {
enum AttachmentType {
AttachmentType_Region,
@ -40,6 +42,17 @@ namespace spine {
AttachmentType_Point,
AttachmentType_Clipping
};
inline AttachmentType AttachmentType_valueOf(const char* value) {
if (strcmp(value, "region") == 0) return AttachmentType_Region;
else if (strcmp(value, "mesh") == 0) return AttachmentType_Mesh;
else if (strcmp(value, "linkedmesh") == 0) return AttachmentType_Linkedmesh;
else if (strcmp(value, "boundingbox") == 0) return AttachmentType_Boundingbox;
else if (strcmp(value, "path") == 0) return AttachmentType_Path;
else if (strcmp(value, "clipping") == 0) return AttachmentType_Clipping;
else if (strcmp(value, "point") == 0) return AttachmentType_Point;
else return AttachmentType_Region; // default
}
}
#endif /* Spine_AttachmentType_h */

View File

@ -30,6 +30,8 @@
#ifndef Spine_BlendMode_h
#define Spine_BlendMode_h
#include <string.h>
namespace spine {
enum BlendMode {
BlendMode_Normal = 0,
@ -37,6 +39,14 @@ namespace spine {
BlendMode_Multiply,
BlendMode_Screen
};
inline BlendMode BlendMode_valueOf(const char* value) {
if (strcmp(value, "normal") == 0) return BlendMode_Normal;
else if (strcmp(value, "additive") == 0) return BlendMode_Additive;
else if (strcmp(value, "multiply") == 0) return BlendMode_Multiply;
else if (strcmp(value, "screen") == 0) return BlendMode_Screen;
else return BlendMode_Normal; // default
}
}
#endif /* Spine_BlendMode_h */

View File

@ -31,6 +31,8 @@
#define SPINE_COLOR_H
#include <spine/MathUtil.h>
#include <string.h>
#include <stdlib.h>
namespace spine {
class SP_API Color : public SpineObject {
@ -102,6 +104,32 @@ namespace spine {
return *this;
}
// Parse hex color string like "ff0000ff" (RRGGBBAA) or "ff0000" (RRGGBB)
static Color valueOf(const char* hexString) {
Color color;
valueOf(hexString, color);
return color;
}
// Parse hex color string into existing Color object
static void valueOf(const char* hexString, Color& color) {
size_t len = strlen(hexString);
if (len >= 6) {
color.r = parseHex(hexString, 0);
color.g = parseHex(hexString, 1);
color.b = parseHex(hexString, 2);
color.a = len >= 8 ? parseHex(hexString, 3) : 1.0f;
}
}
static float parseHex(const char* value, size_t index) {
char digits[3];
digits[0] = value[index * 2];
digits[1] = value[index * 2 + 1];
digits[2] = '\0';
return strtoul(digits, NULL, 16) / 255.0f;
}
float r, g, b, a;
};
}

View File

@ -30,6 +30,8 @@
#ifndef Spine_TransformMode_h
#define Spine_TransformMode_h
#include <string.h>
namespace spine {
/// Determines how a bone inherits world transforms from parent bones.
enum Inherit {
@ -39,6 +41,15 @@ namespace spine {
Inherit_NoScale,
Inherit_NoScaleOrReflection
};
inline Inherit Inherit_valueOf(const char* value) {
if (strcmp(value, "normal") == 0) return Inherit_Normal;
else if (strcmp(value, "onlyTranslation") == 0) return Inherit_OnlyTranslation;
else if (strcmp(value, "noRotationOrReflection") == 0) return Inherit_NoRotationOrReflection;
else if (strcmp(value, "noScale") == 0) return Inherit_NoScale;
else if (strcmp(value, "noScaleOrReflection") == 0) return Inherit_NoScaleOrReflection;
else return Inherit_Normal; // default
}
}
#endif /* Spine_TransformMode_h */

View File

@ -51,6 +51,14 @@ namespace spine {
static const int JSON_ARRAY;
static const int JSON_OBJECT;
template <typename T>
static bool asArray(Json *value, Vector<T> &array) {
array.setSize(value->_size, 0);
Json *vertex = value->_child;
for (int i = 0; vertex; vertex = vertex->_next, i++)
array[i] = vertex->_valueInt;
}
/* Get item "string" from object. Case insensitive. */
static Json *getItem(Json *object, const char *string);

View File

@ -30,6 +30,8 @@
#ifndef Spine_PositionMode_h
#define Spine_PositionMode_h
#include <string.h>
namespace spine {
/// Controls how the first bone is positioned along the path.
///
@ -38,6 +40,12 @@ namespace spine {
PositionMode_Fixed = 0,
PositionMode_Percent
};
inline PositionMode PositionMode_valueOf(const char* value) {
if (strcmp(value, "fixed") == 0) return PositionMode_Fixed;
else if (strcmp(value, "percent") == 0) return PositionMode_Percent;
else return PositionMode_Percent; // default
}
}
#endif /* Spine_PositionMode_h */

View File

@ -30,6 +30,8 @@
#ifndef Spine_RotateMode_h
#define Spine_RotateMode_h
#include <string.h>
namespace spine {
/// Controls how bones are rotated, translated, and scaled to match the path.
///
@ -41,6 +43,13 @@ namespace spine {
/// doesn't affect other constrained bones.
RotateMode_ChainScale
};
inline RotateMode RotateMode_valueOf(const char* value) {
if (strcmp(value, "tangent") == 0) return RotateMode_Tangent;
else if (strcmp(value, "chain") == 0) return RotateMode_Chain;
else if (strcmp(value, "chainScale") == 0) return RotateMode_ChainScale;
else return RotateMode_Tangent; // default
}
}
#endif /* Spine_RotateMode_h */

View File

@ -61,6 +61,10 @@ namespace spine {
class Sequence;
class Skin;
class Attachment;
class SP_API SkeletonJson : public SpineObject {
public:
explicit SkeletonJson(Atlas *atlas);
@ -95,14 +99,16 @@ namespace spine {
readCurve(Json *curve, CurveTimeline *timeline, int bezier, int frame, int value, float time1, float time2,
float value1, float value2, float scale);
static Timeline *readTimeline(Json *keyMap, CurveTimeline1 *timeline, float defaultValue, float scale);
static void readTimeline(Vector<Timeline *> &timelines, Json *keyMap, CurveTimeline1 *timeline, float defaultValue, float scale);
static Timeline *
readTimeline(Json *keyMap, CurveTimeline2 *timeline, const char *name1, const char *name2, float defaultValue,
static void
readTimeline(Vector<Timeline *> &timelines, Json *keyMap, CurveTimeline2 *timeline, const char *name1, const char *name2, float defaultValue,
float scale);
Animation *readAnimation(Json *root, SkeletonData *skeletonData);
Attachment *readAttachment(Json *map, Skin *skin, int slotIndex, const char *name, SkeletonData *skeletonData);
void readVertices(Json *attachmentMap, VertexAttachment *attachment, size_t verticesLength);
void setError(Json *root, const String &value1, const String &value2);

View File

@ -30,6 +30,8 @@
#ifndef Spine_SpacingMode_h
#define Spine_SpacingMode_h
#include <string.h>
namespace spine {
/// Controls how bones after the first bone are positioned along the path.
///
@ -40,6 +42,14 @@ namespace spine {
SpacingMode_Percent,
SpacingMode_Proportional
};
inline SpacingMode SpacingMode_valueOf(const char* value) {
if (strcmp(value, "length") == 0) return SpacingMode_Length;
else if (strcmp(value, "fixed") == 0) return SpacingMode_Fixed;
else if (strcmp(value, "percent") == 0) return SpacingMode_Percent;
else if (strcmp(value, "proportional") == 0) return SpacingMode_Proportional;
else return SpacingMode_Length; // default
}
}
#endif /* Spine_SpacingMode_h */

View File

@ -129,8 +129,10 @@ namespace spine {
}
inline void clearAndAddAll(const Vector<T> &inValue) {
this->clear();
this->addAll(inValue);
ensureCapacity(inValue.size());
for (size_t i = 0; i < inValue.size(); i++)
_buffer[i] = inValue[i];
_size = inValue.size();
}
inline void removeAt(size_t inIndex) {

View File

@ -36,7 +36,7 @@ namespace spine {
class SP_API Vertices : public SpineObject {
public:
Vector <int> _bones;
Vector<float> _vertices;
Vector<float> _weights;
};
}

View File

@ -37,6 +37,7 @@ THE SOFTWARE.
#include <spine/Json.h>
#include <spine/Extension.h>
#include <spine/SpineString.h>
#include <spine/Vector.h>
#include <assert.h>
#include <math.h>

File diff suppressed because it is too large Load Diff