Formatting

This commit is contained in:
Mario Zechner 2024-05-21 13:17:23 +02:00
parent 5abed8a7f6
commit aaa9b81628
9 changed files with 138 additions and 134 deletions

View File

@ -1525,7 +1525,7 @@ spine_bounds spine_skeleton_get_bounds(spine_skeleton skeleton) {
if (skeleton == nullptr) return (spine_bounds) bounds;
Skeleton *_skeleton = (Skeleton *) skeleton;
Vector<float> vertices;
SkeletonClipping clipper;
SkeletonClipping clipper;
_skeleton->getBounds(bounds->x, bounds->y, bounds->width, bounds->height, vertices, &clipper);
return (spine_bounds) bounds;

View File

@ -458,8 +458,8 @@ Skeleton::findPhysicsConstraint(const String &constraintName) {
}
void Skeleton::getBounds(float &outX, float &outY, float &outWidth,
float &outHeight, Vector<float> &outVertexBuffer) {
getBounds(outX, outY, outWidth, outHeight, outVertexBuffer, NULL);
float &outHeight, Vector<float> &outVertexBuffer) {
getBounds(outX, outY, outWidth, outHeight, outVertexBuffer, NULL);
}
static unsigned short quadIndices[] = {0, 1, 2, 2, 3, 0};
@ -477,8 +477,8 @@ void Skeleton::getBounds(float &outX, float &outY, float &outWidth,
continue;
size_t verticesLength = 0;
Attachment *attachment = slot->getAttachment();
unsigned short *triangles = NULL;
size_t trianglesLength = 0;
unsigned short *triangles = NULL;
size_t trianglesLength = 0;
if (attachment != NULL &&
attachment->getRTTI().instanceOf(RegionAttachment::rtti)) {
@ -490,8 +490,8 @@ void Skeleton::getBounds(float &outX, float &outY, float &outWidth,
outVertexBuffer.setSize(8, 0);
}
regionAttachment->computeWorldVertices(*slot, outVertexBuffer, 0);
triangles = quadIndices;
trianglesLength = 6;
triangles = quadIndices;
trianglesLength = 6;
} else if (attachment != NULL &&
attachment->getRTTI().instanceOf(MeshAttachment::rtti)) {
MeshAttachment *mesh = static_cast<MeshAttachment *>(attachment);
@ -503,33 +503,33 @@ void Skeleton::getBounds(float &outX, float &outY, float &outWidth,
mesh->computeWorldVertices(*slot, 0, verticesLength,
outVertexBuffer.buffer(), 0);
triangles = mesh->getTriangles().buffer();
trianglesLength = mesh->getTriangles().size();
triangles = mesh->getTriangles().buffer();
trianglesLength = mesh->getTriangles().size();
} else if (attachment != NULL &&
attachment->getRTTI().instanceOf(ClippingAttachment::rtti) && clipper != NULL) {
clipper->clipStart(*slot, static_cast<ClippingAttachment *>(attachment));
}
attachment->getRTTI().instanceOf(ClippingAttachment::rtti) && clipper != NULL) {
clipper->clipStart(*slot, static_cast<ClippingAttachment *>(attachment));
}
if (verticesLength > 0) {
float *vertices = outVertexBuffer.buffer();
if (clipper != NULL && clipper->isClipping()) {
clipper->clipTriangles(outVertexBuffer.buffer(), triangles, trianglesLength);
vertices = clipper->getClippedVertices().buffer();
verticesLength = clipper->getClippedVertices().size();
}
for (size_t ii = 0; ii < verticesLength; ii += 2) {
float vx = vertices[ii];
float vy = vertices[ii + 1];
if (verticesLength > 0) {
float *vertices = outVertexBuffer.buffer();
if (clipper != NULL && clipper->isClipping()) {
clipper->clipTriangles(outVertexBuffer.buffer(), triangles, trianglesLength);
vertices = clipper->getClippedVertices().buffer();
verticesLength = clipper->getClippedVertices().size();
}
for (size_t ii = 0; ii < verticesLength; ii += 2) {
float vx = vertices[ii];
float vy = vertices[ii + 1];
minX = MathUtil::min(minX, vx);
minY = MathUtil::min(minY, vy);
maxX = MathUtil::max(maxX, vx);
maxY = MathUtil::max(maxY, vy);
}
}
if (clipper != NULL) clipper->clipEnd(*slot);
minX = MathUtil::min(minX, vx);
minY = MathUtil::min(minY, vy);
maxX = MathUtil::max(maxX, vx);
maxY = MathUtil::max(maxY, vy);
}
}
if (clipper != NULL) clipper->clipEnd(*slot);
}
if (clipper != NULL) clipper->clipEnd();
if (clipper != NULL) clipper->clipEnd();
outX = minX;
outY = minY;

View File

@ -83,76 +83,76 @@ void SkeletonClipping::clipEnd() {
}
void SkeletonClipping::clipTriangles(float *vertices, unsigned short *triangles,
size_t trianglesLength) {
Vector<float> &clipOutput = _clipOutput;
Vector<float> &clippedVertices = _clippedVertices;
Vector<unsigned short> &clippedTriangles = _clippedTriangles;
Vector<Vector<float> *> &polygons = *_clippingPolygons;
size_t polygonsCount = (*_clippingPolygons).size();
size_t trianglesLength) {
Vector<float> &clipOutput = _clipOutput;
Vector<float> &clippedVertices = _clippedVertices;
Vector<unsigned short> &clippedTriangles = _clippedTriangles;
Vector<Vector<float> *> &polygons = *_clippingPolygons;
size_t polygonsCount = (*_clippingPolygons).size();
size_t index = 0;
clippedVertices.clear();
_clippedUVs.clear();
clippedTriangles.clear();
size_t index = 0;
clippedVertices.clear();
_clippedUVs.clear();
clippedTriangles.clear();
int stride = 2;
size_t i = 0;
continue_outer:
for (; i < trianglesLength; i += 3) {
int vertexOffset = triangles[i] * stride;
float x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
int stride = 2;
size_t i = 0;
continue_outer:
for (; i < trianglesLength; i += 3) {
int vertexOffset = triangles[i] * stride;
float x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
vertexOffset = triangles[i + 1] * stride;
float x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
vertexOffset = triangles[i + 1] * stride;
float x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
vertexOffset = triangles[i + 2] * stride;
float x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
vertexOffset = triangles[i + 2] * stride;
float x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
for (size_t p = 0; p < polygonsCount; p++) {
size_t s = clippedVertices.size();
if (clip(x1, y1, x2, y2, x3, y3, &(*polygons[p]), &clipOutput)) {
size_t clipOutputLength = clipOutput.size();
if (clipOutputLength == 0) continue;
for (size_t p = 0; p < polygonsCount; p++) {
size_t s = clippedVertices.size();
if (clip(x1, y1, x2, y2, x3, y3, &(*polygons[p]), &clipOutput)) {
size_t clipOutputLength = clipOutput.size();
if (clipOutputLength == 0) continue;
size_t clipOutputCount = clipOutputLength >> 1;
clippedVertices.setSize(s + clipOutputCount * 2, 0);
for (size_t ii = 0; ii < clipOutputLength; ii += 2) {
float x = clipOutput[ii], y = clipOutput[ii + 1];
clippedVertices[s] = x;
clippedVertices[s + 1] = y;
s += 2;
}
size_t clipOutputCount = clipOutputLength >> 1;
clippedVertices.setSize(s + clipOutputCount * 2, 0);
for (size_t ii = 0; ii < clipOutputLength; ii += 2) {
float x = clipOutput[ii], y = clipOutput[ii + 1];
clippedVertices[s] = x;
clippedVertices[s + 1] = y;
s += 2;
}
s = clippedTriangles.size();
clippedTriangles.setSize(s + 3 * (clipOutputCount - 2), 0);
clipOutputCount--;
for (size_t ii = 1; ii < clipOutputCount; ii++) {
clippedTriangles[s] = (unsigned short) (index);
clippedTriangles[s + 1] = (unsigned short) (index + ii);
clippedTriangles[s + 2] = (unsigned short) (index + ii + 1);
s += 3;
}
index += clipOutputCount + 1;
} else {
clippedVertices.setSize(s + 3 * 2, 0);
clippedVertices[s] = x1;
clippedVertices[s + 1] = y1;
clippedVertices[s + 2] = x2;
clippedVertices[s + 3] = y2;
clippedVertices[s + 4] = x3;
clippedVertices[s + 5] = y3;
s = clippedTriangles.size();
clippedTriangles.setSize(s + 3 * (clipOutputCount - 2), 0);
clipOutputCount--;
for (size_t ii = 1; ii < clipOutputCount; ii++) {
clippedTriangles[s] = (unsigned short) (index);
clippedTriangles[s + 1] = (unsigned short) (index + ii);
clippedTriangles[s + 2] = (unsigned short) (index + ii + 1);
s += 3;
}
index += clipOutputCount + 1;
} else {
clippedVertices.setSize(s + 3 * 2, 0);
clippedVertices[s] = x1;
clippedVertices[s + 1] = y1;
clippedVertices[s + 2] = x2;
clippedVertices[s + 3] = y2;
clippedVertices[s + 4] = x3;
clippedVertices[s + 5] = y3;
s = clippedTriangles.size();
clippedTriangles.setSize(s + 3, 0);
clippedTriangles[s] = (unsigned short) index;
clippedTriangles[s + 1] = (unsigned short) (index + 1);
clippedTriangles[s + 2] = (unsigned short) (index + 2);
index += 3;
i += 3;
goto continue_outer;
}
}
}
s = clippedTriangles.size();
clippedTriangles.setSize(s + 3, 0);
clippedTriangles[s] = (unsigned short) index;
clippedTriangles[s + 1] = (unsigned short) (index + 1);
clippedTriangles[s + 2] = (unsigned short) (index + 2);
index += 3;
i += 3;
goto continue_outer;
}
}
}
}
void SkeletonClipping::clipTriangles(Vector<float> &vertices, Vector<unsigned short> &triangles, Vector<float> &uvs,

View File

@ -9,7 +9,11 @@
"request": "launch",
"name": "debug scene v4",
"program": "godot/bin/godot.windows.editor.dev.x86_64.exe",
"args": ["--path", "example-v4", "examples/07-slot-node/slot-node.tscn"],
"args": [
"--path",
"example-v4",
"examples/03-mix-and-match/mix-and-match.tscn"
],
"cwd": "${workspaceFolder}",
"preLaunchTask": "build-v4",
"linux": {

View File

@ -54,7 +54,7 @@ int main() {
spAnimationStateData *animationStateData = spAnimationStateData_create(skeletonData);
animationStateData->defaultMix = 0.2f;
spSkeletonDrawable *drawable = spSkeletonDrawable_create(skeletonData, animationStateData);
drawable->usePremultipliedAlpha = -1;
drawable->usePremultipliedAlpha = -1;
drawable->skeleton->x = 400;
drawable->skeleton->y = 500;
spSkeleton_setToSetupPose(drawable->skeleton);

View File

@ -54,13 +54,13 @@ int main(int argc, char **argv) {
json.setScale(0.5f);
spine::SkeletonData *skeletonData = json.readSkeletonDataFile("data/spineboy-pro.json");
spine::SkeletonDrawable drawable(skeletonData);
drawable.usePremultipliedAlpha = true;
drawable.usePremultipliedAlpha = true;
drawable.animationState->getData()->setDefaultMix(0.2f);
drawable.skeleton->setPosition(400, 500);
drawable.skeleton->setToSetupPose();
drawable.animationState->setAnimation(0, "portal", true);
drawable.animationState->addAnimation(0, "run", true, 0);
drawable.update(0, spine::Physics_Update);
drawable.update(0, spine::Physics_Update);
bool quit = false;
uint64_t lastFrameTime = SDL_GetPerformanceCounter();

View File

@ -42,7 +42,7 @@ spSkeletonDrawable *spSkeletonDrawable_create(spSkeletonData *skeletonData, spAn
spSkeletonDrawable *self = NEW(spSkeletonDrawable);
self->skeleton = spSkeleton_create(skeletonData);
self->animationState = spAnimationState_create(animationStateData);
self->usePremultipliedAlpha = 0;
self->usePremultipliedAlpha = 0;
self->sdlIndices = spIntArray_create(12);
self->sdlVertices = spSdlVertexArray_create(12);
self->worldVertices = spFloatArray_create(12);
@ -164,41 +164,41 @@ void spSkeletonDrawable_draw(spSkeletonDrawable *self, struct SDL_Renderer *rend
for (int ii = 0; ii < (int) indicesCount; ii++)
spIntArray_add(self->sdlIndices, indices[ii]);
if (!self->usePremultipliedAlpha) {
switch (slot->data->blendMode) {
case SP_BLEND_MODE_NORMAL:
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
break;
case SP_BLEND_MODE_MULTIPLY:
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
break;
case SP_BLEND_MODE_ADDITIVE:
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_ADD);
break;
case SP_BLEND_MODE_SCREEN:
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
break;
}
} else {
SDL_BlendMode target;
switch (slot->data->blendMode) {
case SP_BLEND_MODE_NORMAL:
target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD);
SDL_SetTextureBlendMode(texture, target);
break;
case SP_BLEND_MODE_MULTIPLY:
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
break;
case SP_BLEND_MODE_ADDITIVE:
target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_ADD);
break;
case SP_BLEND_MODE_SCREEN:
target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
break;
}
}
if (!self->usePremultipliedAlpha) {
switch (slot->data->blendMode) {
case SP_BLEND_MODE_NORMAL:
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
break;
case SP_BLEND_MODE_MULTIPLY:
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
break;
case SP_BLEND_MODE_ADDITIVE:
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_ADD);
break;
case SP_BLEND_MODE_SCREEN:
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
break;
}
} else {
SDL_BlendMode target;
switch (slot->data->blendMode) {
case SP_BLEND_MODE_NORMAL:
target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD);
SDL_SetTextureBlendMode(texture, target);
break;
case SP_BLEND_MODE_MULTIPLY:
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
break;
case SP_BLEND_MODE_ADDITIVE:
target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_ADD);
break;
case SP_BLEND_MODE_SCREEN:
target = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
break;
}
}
SDL_RenderGeometry(renderer, texture, self->sdlVertices->items, self->sdlVertices->size, self->sdlIndices->items,
indicesCount);

View File

@ -43,7 +43,7 @@ _SP_ARRAY_DECLARE_TYPE(spSdlVertexArray, struct SDL_Vertex)
typedef struct spSkeletonDrawable {
spSkeleton *skeleton;
spAnimationState *animationState;
int usePremultipliedAlpha;
int usePremultipliedAlpha;
spSkeletonClipping *clipper;
spFloatArray *worldVertices;

View File

@ -46,7 +46,7 @@ namespace spine {
Skeleton *skeleton;
AnimationState *animationState;
bool usePremultipliedAlpha;
bool usePremultipliedAlpha;
private:
bool ownsAnimationStateData;