[c][cpp] Formatter pass.

This commit is contained in:
Mario Zechner 2022-03-25 13:31:58 +01:00
parent 7cf42c814b
commit 2022713bd2
25 changed files with 70 additions and 68 deletions

View File

@ -26,7 +26,7 @@ spotless {
'spine-sfml/**/*.h',
'spine-ue4/**/*.cpp',
'spine-ue4/**/*.h'
clangFormat("12.0.1").pathToExe("$System.env.CLANGFORMAT").style('file')
clangFormat("13.0.1").pathToExe("$System.env.CLANGFORMAT").style('file')
}
typescript {

View File

@ -28,9 +28,11 @@ setup
# Execute spotless and dotnet-format
pushd $dir/..
./formatters/gradlew spotlessApply
dotnet-format spine-csharp/spine-csharp.sln
dotnet-format -f spine-monogame
dotnet-format -f spine-unity
if [ "$1" != "skipdotnet" ] ; then
dotnet-format spine-csharp/spine-csharp.sln
dotnet-format -f spine-monogame
dotnet-format -f spine-unity
fi
popd
# Delete Gradle, dotnet-format, and clang-format config files in root

View File

@ -101,7 +101,7 @@ static char *string_append(char *str, const char *b) {
}
static char *string_append_int(char *str, int value) {
char intStr[20];;
char intStr[20];
sprintf(intStr, "%i", value);
return string_append(str, intStr);
}

View File

@ -109,7 +109,7 @@ static int readInt(_dataInput *input) {
result |= readByte(input);
result <<= 8;
result |= readByte(input);
return (int)result;
return (int) result;
}
static int readVarint(_dataInput *input, int /*bool*/ optimizePositive) {
@ -124,12 +124,12 @@ static int readVarint(_dataInput *input, int /*bool*/ optimizePositive) {
if (b & 0x80) {
b = readByte(input);
value |= (b & 0x7F) << 21;
if (b & 0x80) value |= (uint32_t)(readByte(input) & 0x7F) << 28;
if (b & 0x80) value |= (uint32_t) (readByte(input) & 0x7F) << 28;
}
}
}
if (!optimizePositive) value = (((unsigned int) value >> 1) ^ -(value & 1));
return (int)value;
return (int) value;
}
float readFloat(_dataInput *input) {

View File

@ -94,14 +94,14 @@ void Animation::setDuration(float inValue) {
int Animation::search(Vector<float> &frames, float target) {
size_t n = (int) frames.size();
for (size_t i = 1; i < n; i++) {
if (frames[i] > target) return (int)(i - 1);
if (frames[i] > target) return (int) (i - 1);
}
return (int)(n - 1);
return (int) (n - 1);
}
int Animation::search(Vector<float> &frames, float target, int step) {
size_t n = frames.size();
for (size_t i = step; i < n; i += step)
if (frames[i] > target) return (int)(i - step);
return (int)(n - step);
if (frames[i] > target) return (int) (i - step);
return (int) (n - step);
}

View File

@ -489,7 +489,7 @@ bool AnimationState::apply(Skeleton &skeleton) {
int setupState = _unkeyedState + Setup;
Vector<Slot *> &slots = skeleton.getSlots();
for (int i = 0, n = (int)slots.size(); i < n; i++) {
for (int i = 0, n = (int) slots.size(); i < n; i++) {
Slot *slot = slots[i];
if (slot->getAttachmentState() == setupState) {
const String &attachmentName = slot->getData().getAttachmentName();
@ -951,7 +951,7 @@ TrackEntry *AnimationState::newTrackEntry(size_t trackIndex, Animation *animatio
TrackEntry *entryP = _trackEntryPool.obtain();// Pooling
TrackEntry &entry = *entryP;
entry._trackIndex = (int)trackIndex;
entry._trackIndex = (int) trackIndex;
entry._animation = animation;
entry._loop = loop;
entry._holdPrevious = 0;

View File

@ -155,7 +155,7 @@ struct SimpleString {
}
bool equals(const char *str) {
int otherLen = (int)strlen(str);
int otherLen = (int) strlen(str);
if (length != otherLen) return false;
for (int i = 0; i < length; i++) {
if (start[i] != str[i]) return false;

View File

@ -46,7 +46,7 @@ namespace spine {
bool loadSequence(Atlas *atlas, const String &basePath, Sequence *sequence) {
Vector<TextureRegion *> &regions = sequence->getRegions();
for (int i = 0, n = (int)regions.size(); i < n; i++) {
for (int i = 0, n = (int) regions.size(); i < n; i++) {
String path = sequence->getPath(basePath, i);
regions[i] = atlas->findRegion(path);
if (!regions[i]) return false;

View File

@ -111,7 +111,7 @@ void CurveTimeline1::setFrame(size_t frame, float time, float value) {
}
float CurveTimeline1::getCurveValue(float time) {
int i = (int)_frames.size() - 2;
int i = (int) _frames.size() - 2;
for (int ii = 2; ii <= i; ii += 2) {
if (_frames[ii] > time) {
i = ii - 2;

View File

@ -288,7 +288,7 @@ void IkConstraint::update() {
}
int IkConstraint::getOrder() {
return (int)_data.getOrder();
return (int) _data.getOrder();
}
IkConstraintData &IkConstraint::getData() {

View File

@ -37,7 +37,7 @@ void spine::spDebug_printSkeletonData(SkeletonData *skeletonData) {
int i, n;
spDebug_printBoneDatas(skeletonData->getBones());
for (i = 0, n = (int)skeletonData->getAnimations().size(); i < n; i++) {
for (i = 0, n = (int) skeletonData->getAnimations().size(); i < n; i++) {
spDebug_printAnimation(skeletonData->getAnimations()[i]);
}
}
@ -69,7 +69,7 @@ void spine::spDebug_printAnimation(Animation *animation) {
int i, n;
printf("Animation %s: %zu timelines\n", animation->getName().buffer(), animation->getTimelines().size());
for (i = 0, n = (int)animation->getTimelines().size(); i < n; i++) {
for (i = 0, n = (int) animation->getTimelines().size(); i < n; i++) {
Timeline *timeline = animation->getTimelines()[i];
spDebug_printTimeline(timeline);
}
@ -77,7 +77,7 @@ void spine::spDebug_printAnimation(Animation *animation) {
void spine::spDebug_printBoneDatas(Vector<BoneData *> &boneDatas) {
int i, n;
for (i = 0, n = (int)boneDatas.size(); i < n; i++) {
for (i = 0, n = (int) boneDatas.size(); i < n; i++) {
spDebug_printBoneData(boneDatas[i]);
}
}
@ -94,7 +94,7 @@ void spine::spDebug_printSkeleton(Skeleton *skeleton) {
void spine::spDebug_printBones(Vector<Bone *> &bones) {
int i, n;
for (i = 0, n = (int)bones.size(); i < n; i++) {
for (i = 0, n = (int) bones.size(); i < n; i++) {
spDebug_printBone(bones[i]);
}
}
@ -116,7 +116,7 @@ void spine::spDebug_printFloats(float *values, int numFloats) {
void spine::spDebug_printFloats(Vector<float> &values) {
int i, n;
printf("(%zu) [", values.size());
for (i = 0, n = (int)values.size(); i < n; i++) {
for (i = 0, n = (int) values.size(); i < n; i++) {
printf("%f, ", values[i]);
}
printf("]");

View File

@ -53,7 +53,7 @@ void MeshAttachment::updateRegion() {
_uvs.setSize(_regionUVs.size(), 0);
}
int i = 0, n = (int)_regionUVs.size();
int i = 0, n = (int) _regionUVs.size();
float u = _region->u, v = _region->v;
float width = 0, height = 0;

View File

@ -26,7 +26,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#include <spine/PathConstraint.h>
#include <spine/Bone.h>
@ -148,7 +148,7 @@ void PathConstraint::update() {
}
}
Vector<float> &positions = computeWorldPositions(*attachment, (int)spacesCount, tangents);
Vector<float> &positions = computeWorldPositions(*attachment, (int) spacesCount, tangents);
float boneX = positions[0];
float boneY = positions[1];
float offsetRotation = data.getOffsetRotation();
@ -221,7 +221,7 @@ void PathConstraint::update() {
}
int PathConstraint::getOrder() {
return (int)_data.getOrder();
return (int) _data.getOrder();
}
float PathConstraint::getPosition() {
@ -288,7 +288,7 @@ PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, boo
Vector<float> &out = _positions;
Vector<float> &world = _world;
bool closed = path.isClosed();
int verticesLength = (int)path.getWorldVerticesLength();
int verticesLength = (int) path.getWorldVerticesLength();
int curveCount = verticesLength / 6;
int prevCurve = NONE;

View File

@ -47,7 +47,7 @@ Sequence::~Sequence() {
}
Sequence *Sequence::copy() {
Sequence *copy = new (__FILE__, __LINE__) Sequence((int)_regions.size());
Sequence *copy = new (__FILE__, __LINE__) Sequence((int) _regions.size());
for (size_t i = 0; i < _regions.size(); i++) {
copy->_regions[i] = _regions[i];
}
@ -60,7 +60,7 @@ Sequence *Sequence::copy() {
void Sequence::apply(Slot *slot, Attachment *attachment) {
int index = slot->getSequenceIndex();
if (index == -1) index = _setupIndex;
if (index >= (int) _regions.size()) index = (int)_regions.size() - 1;
if (index >= (int) _regions.size()) index = (int) _regions.size() - 1;
TextureRegion *region = _regions[index];
if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) {
@ -86,7 +86,7 @@ String Sequence::getPath(const String &basePath, int index) {
String result(basePath);
String frame;
frame.append(_start + index);
for (int i = _digits - (int)frame.length(); i > 0; i--)
for (int i = _digits - (int) frame.length(); i > 0; i--)
result.append("0");
result.append(frame);
return result;

View File

@ -89,7 +89,7 @@ void SequenceTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vec
Sequence *sequence = NULL;
if (_attachment->getRTTI().instanceOf(RegionAttachment::rtti)) sequence = ((RegionAttachment *) _attachment)->getSequence();
if (_attachment->getRTTI().instanceOf(MeshAttachment::rtti)) sequence = ((MeshAttachment *) _attachment)->getSequence();
int index = modeAndIndex >> 4, count = (int)sequence->getRegions().size();
int index = modeAndIndex >> 4, count = (int) sequence->getRegions().size();
int mode = modeAndIndex & 0xf;
if (mode != SequenceMode::hold) {
index += (int) (((time - before) / delay + 0.00001));

View File

@ -368,7 +368,7 @@ void Skeleton::setAttachment(const String &slotName, const String &attachmentNam
if (slot->_data.getName() == slotName) {
Attachment *attachment = NULL;
if (attachmentName.length() > 0) {
attachment = getAttachment((int)i, attachmentName);
attachment = getAttachment((int) i, attachmentName);
assert(attachment != NULL);
}

View File

@ -287,7 +287,7 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons
}
/* Linked meshes. */
for (int i = 0, n = (int)_linkedMeshes.size(); i < n; ++i) {
for (int i = 0, n = (int) _linkedMeshes.size(); i < n; ++i) {
LinkedMesh *linkedMesh = _linkedMeshes[i];
Skin *skin = linkedMesh->_skin.length() == 0 ? skeletonData->getDefaultSkin() : skeletonData->findSkin(linkedMesh->_skin);
if (skin == NULL) {
@ -753,7 +753,7 @@ void SkeletonBinary::setBezier(DataInput *input, CurveTimeline *timeline, int be
Timeline *SkeletonBinary::readTimeline(DataInput *input, CurveTimeline1 *timeline, float scale) {
float time = readFloat(input);
float value = readFloat(input) * scale;
for (int frame = 0, bezier = 0, frameLast = (int)timeline->getFrameCount() - 1;; frame++) {
for (int frame = 0, bezier = 0, frameLast = (int) timeline->getFrameCount() - 1;; frame++) {
timeline->setFrame(frame, time, value);
if (frame == frameLast) break;
float time2 = readFloat(input);
@ -775,7 +775,7 @@ Timeline *SkeletonBinary::readTimeline2(DataInput *input, CurveTimeline2 *timeli
float time = readFloat(input);
float value1 = readFloat(input) * scale;
float value2 = readFloat(input) * scale;
for (int frame = 0, bezier = 0, frameLast = (int)timeline->getFrameCount() - 1;; frame++) {
for (int frame = 0, bezier = 0, frameLast = (int) timeline->getFrameCount() - 1;; frame++) {
timeline->setFrame(frame, time, value1, value2);
if (frame == frameLast) break;
float time2 = readFloat(input);
@ -1198,7 +1198,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
float mixRotate = readFloat(input);
float mixX = readFloat(input);
float mixY = readFloat(input);
for (int frame = 0, bezier = 0, frameLast = (int)timeline->getFrameCount() - 1;; frame++) {
for (int frame = 0, bezier = 0, frameLast = (int) timeline->getFrameCount() - 1;; frame++) {
timeline->setFrame(frame, time, mixRotate, mixX, mixY);
if (frame == frameLast) break;
float time2 = readFloat(input);
@ -1246,7 +1246,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
case ATTACHMENT_DEFORM: {
bool weighted = attachment->_bones.size() > 0;
Vector<float> &vertices = attachment->_vertices;
int deformLength = weighted ? (int)vertices.size() / 3 * 2 : (int)vertices.size();
int deformLength = weighted ? (int) vertices.size() / 3 * 2 : (int) vertices.size();
int bezierCount = readVarint(input, true);
DeformTimeline *timeline = new (__FILE__, __LINE__) DeformTimeline(frameCount, bezierCount, slotIndex,
@ -1336,15 +1336,15 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
size_t slotIndex = (size_t) readVarint(input, true);
// Collect unchanged items.
while (originalIndex != slotIndex)
unchanged[unchangedIndex++] = (int)originalIndex++;
unchanged[unchangedIndex++] = (int) originalIndex++;
// Set changed items.
size_t index = originalIndex;
drawOrder[index + (size_t) readVarint(input, true)] = (int)originalIndex++;
drawOrder[index + (size_t) readVarint(input, true)] = (int) originalIndex++;
}
// Collect remaining unchanged items.
while (originalIndex < slotCount) {
unchanged[unchangedIndex++] = (int)originalIndex++;
unchanged[unchangedIndex++] = (int) originalIndex++;
}
// Fill in unchanged items.
@ -1382,7 +1382,7 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
}
float duration = 0;
for (int i = 0, n = (int)timelines.size(); i < n; i++) {
for (int i = 0, n = (int) timelines.size(); i < n; i++) {
duration = MathUtil::max(duration, (timelines[i])->getDuration());
}
return new (__FILE__, __LINE__) Animation(String(name), timelines, duration);

View File

@ -74,7 +74,7 @@ void SkeletonBounds::update(Skeleton &skeleton, bool updateAabb) {
Polygon &polygon = *polygonP;
size_t count = boundingBox->getWorldVerticesLength();
polygon._count = (int)count;
polygon._count = (int) count;
if (polygon._vertices.size() < count) {
polygon._vertices.setSize(count, 0);
}

View File

@ -48,7 +48,7 @@ size_t SkeletonClipping::clipStart(Slot &slot, ClippingAttachment *clip) {
_clipAttachment = clip;
int n = (int)clip->getWorldVerticesLength();
int n = (int) clip->getWorldVerticesLength();
_clippingPolygon.setSize(n, 0);
clip->computeWorldVertices(slot, 0, n, _clippingPolygon, 0, 2);
makeClockwise(_clippingPolygon);
@ -103,15 +103,15 @@ void SkeletonClipping::clipTriangles(float *vertices, unsigned short *triangles,
size_t i = 0;
continue_outer:
for (; i < trianglesLength; i += 3) {
int vertexOffset = triangles[i] * (int)stride;
int vertexOffset = triangles[i] * (int) stride;
float x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1];
float u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1];
vertexOffset = triangles[i + 1] * (int)stride;
vertexOffset = triangles[i + 1] * (int) stride;
float x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1];
float u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1];
vertexOffset = triangles[i + 2] * (int)stride;
vertexOffset = triangles[i + 2] * (int) stride;
float x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1];
float u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1];
@ -314,7 +314,7 @@ void SkeletonClipping::makeClockwise(Vector<float> &polygon) {
for (size_t i = 0, lastX = verticeslength - 2, n = verticeslength >> 1; i < n; i += 2) {
float x = polygon[i], y = polygon[i + 1];
int other = (int)(lastX - i);
int other = (int) (lastX - i);
polygon[i] = polygon[other];
polygon[i + 1] = polygon[other + 1];
polygon[other] = x;

View File

@ -711,7 +711,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
}
/* Linked meshes. */
int n = (int)_linkedMeshes.size();
int n = (int) _linkedMeshes.size();
for (i = 0; i < n; ++i) {
LinkedMesh *linkedMesh = _linkedMeshes[i];
Skin *skin = linkedMesh->_skin.length() == 0 ? skeletonData->getDefaultSkin() : skeletonData->findSkin(linkedMesh->_skin);
@ -1276,7 +1276,7 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) {
VertexAttachment *vertexAttachment = static_cast<VertexAttachment *>(attachment);
bool weighted = vertexAttachment->_bones.size() != 0;
Vector<float> &verts = vertexAttachment->_vertices;
int deformLength = weighted ? (int)verts.size() / 3 * 2 : (int)verts.size();
int deformLength = weighted ? (int) verts.size() / 3 * 2 : (int) verts.size();
DeformTimeline *timeline = new (__FILE__, __LINE__) DeformTimeline(frames,
frames, slotIndex, vertexAttachment);
@ -1376,14 +1376,14 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) {
/* Collect unchanged items. */
while (originalIndex != (size_t) slotIndex)
unchanged[unchangedIndex++] = (int)originalIndex++;
unchanged[unchangedIndex++] = (int) originalIndex++;
/* Set changed items. */
drawOrder2[originalIndex + Json::getInt(offsetMap, "offset", 0)] = (int)originalIndex;
drawOrder2[originalIndex + Json::getInt(offsetMap, "offset", 0)] = (int) originalIndex;
originalIndex++;
}
/* Collect remaining unchanged items. */
while ((int)originalIndex < (int)skeletonData->_slots.size())
unchanged[unchangedIndex++] = (int)originalIndex++;
while ((int) originalIndex < (int) skeletonData->_slots.size())
unchanged[unchangedIndex++] = (int) originalIndex++;
/* Fill in unchanged items. */
for (ii = (int) skeletonData->_slots.size() - 1; ii >= 0; ii--)
if (drawOrder2[ii] == -1) drawOrder2[ii] = unchanged[--unchangedIndex];

View File

@ -80,7 +80,7 @@ void Skin::AttachmentMap::remove(size_t slotIndex, const String &attachmentName)
int Skin::AttachmentMap::findInBucket(Vector<Entry> &bucket, const String &attachmentName) {
for (size_t i = 0; i < bucket.size(); i++)
if (bucket[i]._name == attachmentName) return (int)i;
if (bucket[i]._name == attachmentName) return (int) i;
return -1;
}
@ -144,7 +144,7 @@ void Skin::attachAll(Skeleton &skeleton, Skin &oldSkin) {
Skin::AttachmentMap::Entries entries = oldSkin.getAttachments();
while (entries.hasNext()) {
Skin::AttachmentMap::Entry &entry = entries.next();
int slotIndex = (int)entry._slotIndex;
int slotIndex = (int) entry._slotIndex;
Slot *slot = slots[slotIndex];
if (slot->getAttachment() == entry._attachment) {

View File

@ -78,7 +78,7 @@ void TransformConstraint::update() {
}
int TransformConstraint::getOrder() {
return (int)_data.getOrder();
return (int) _data.getOrder();
}
TransformConstraintData &TransformConstraint::getData() {

View File

@ -45,15 +45,15 @@ Vector<int> &Triangulator::triangulate(Vector<float> &vertices) {
indices.clear();
indices.ensureCapacity(vertexCount);
indices.setSize(vertexCount, 0);
for (int i = 0; i < (int)vertexCount; ++i) {
for (int i = 0; i < (int) vertexCount; ++i) {
indices[i] = i;
}
Vector<bool> &isConcaveArray = _isConcaveArray;
isConcaveArray.ensureCapacity(vertexCount);
isConcaveArray.setSize(vertexCount, 0);
for (int i = 0, n = (int)vertexCount; i < n; ++i) {
isConcaveArray[i] = isConcave(i, (int)vertexCount, vertices, indices);
for (int i = 0, n = (int) vertexCount; i < n; ++i) {
isConcaveArray[i] = isConcave(i, (int) vertexCount, vertices, indices);
}
Vector<int> &triangles = _triangles;
@ -109,10 +109,10 @@ Vector<int> &Triangulator::triangulate(Vector<float> &vertices) {
isConcaveArray.removeAt(i);
vertexCount--;
int previousIndex = (int)((vertexCount + i - 1) % vertexCount);
int nextIndex = (int)(i == vertexCount ? 0 : i);
isConcaveArray[previousIndex] = isConcave(previousIndex, (int)vertexCount, vertices, indices);
isConcaveArray[nextIndex] = isConcave(nextIndex, (int)vertexCount, vertices, indices);
int previousIndex = (int) ((vertexCount + i - 1) % vertexCount);
int nextIndex = (int) (i == vertexCount ? 0 : i);
isConcaveArray[previousIndex] = isConcave(previousIndex, (int) vertexCount, vertices, indices);
isConcaveArray[nextIndex] = isConcave(nextIndex, (int) vertexCount, vertices, indices);
}
if (vertexCount == 3) {

View File

@ -83,7 +83,7 @@ void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t cou
int v = 0, skip = 0;
for (size_t i = 0; i < start; i += 2) {
int n = (int)bones[v];
int n = (int) bones[v];
v += n + 1;
skip += n;
}
@ -92,7 +92,7 @@ void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t cou
if (deformArray->size() == 0) {
for (size_t w = offset, b = skip * 3; w < count; w += stride) {
float wx = 0, wy = 0;
int n = (int)bones[v++];
int n = (int) bones[v++];
n += v;
for (; v < n; v++, b += 3) {
Bone *boneP = skeletonBones[bones[v]];
@ -109,7 +109,7 @@ void VertexAttachment::computeWorldVertices(Slot &slot, size_t start, size_t cou
} else {
for (size_t w = offset, b = skip * 3, f = skip << 1; w < count; w += stride) {
float wx = 0, wy = 0;
int n = (int)bones[v++];
int n = (int) bones[v++];
n += v;
for (; v < n; v++, b += 3, f += 2) {
Bone *boneP = skeletonBones[bones[v]];

View File

@ -137,7 +137,7 @@ void USpineSkeletonDataAsset::SetRawData(TArray<uint8> &Data) {
static bool checkVersion(const char *version) {
if (!version) return false;
char* result = (char*)(strstr(version, SPINE_VERSION_STRING) - version);
char *result = (char *) (strstr(version, SPINE_VERSION_STRING) - version);
return result == 0;
}