[cpp] Resolve shadowed variables, see #1250.

This commit is contained in:
badlogic 2019-01-16 15:57:49 +01:00
parent ccc1013461
commit bc5dc2b70b
8 changed files with 31 additions and 29 deletions

View File

@ -6,8 +6,8 @@ if(MSVC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c89")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wnon-virtual-dtor -pedantic -std=c++03 -fno-exceptions -fno-rtti")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Wshadow -std=c89")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wnon-virtual-dtor -pedantic -Wshadow -std=c++03 -fno-exceptions -fno-rtti")
endif()
set(CMAKE_INSTALL_PREFIX "./")

View File

@ -74,8 +74,8 @@ void DeformTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
return;
}
VertexAttachment *vertexAttachment = static_cast<VertexAttachment *>(slotAttachment);
if (!vertexAttachment->applyDeform(_attachment)) {
VertexAttachment *attachment = static_cast<VertexAttachment *>(slotAttachment);
if (!attachment->applyDeform(_attachment)) {
return;
}
@ -100,9 +100,9 @@ void DeformTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
}
verticesArray.setSize(vertexCount, 0);
Vector<float> &vertices = verticesArray;
if (vertexAttachment->getBones().size() == 0) {
if (attachment->getBones().size() == 0) {
// Unweighted vertex positions.
Vector<float> &setupVertices = vertexAttachment->getVertices();
Vector<float> &setupVertices = attachment->getVertices();
for (size_t i = 0; i < vertexCount; i++)
vertices[i] += (setupVertices[i] - vertices[i]) * alpha;
} else {

View File

@ -60,7 +60,7 @@ void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress
float sy = bone._ascaleY;
if (compress || stretch) {
float b = bone._data.getLength() * sx, dd = MathUtil::sqrt(tx * tx + ty * ty);
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001f) {
if (((compress && dd < b) || (stretch && dd > b)) && (b > 0.0001f)) {
float s = (dd / b - 1) * alpha + 1;
sx *= s;
if (uniform) sy *= s;

View File

@ -176,7 +176,8 @@ void Skeleton::updateCache() {
}
}
for (size_t i = 0, n = _bones.size(); i < n; ++i) {
size_t n = _bones.size();
for (i = 0; i < n; ++i) {
sortBone(_bones[i]);
}
}

View File

@ -144,9 +144,9 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons
}
/* Bones. */
int bonesCount = readVarint(input, true);
skeletonData->_bones.setSize(bonesCount, 0);
for (int i = 0; i < bonesCount; ++i) {
int numBones = readVarint(input, true);
skeletonData->_bones.setSize(numBones, 0);
for (int i = 0; i < numBones; ++i) {
const char *name = readString(input);
BoneData *parent = i == 0 ? 0 : skeletonData->_bones[readVarint(input, true)];
BoneData *data = new(__FILE__, __LINE__) BoneData(i, String(name, true), parent);
@ -916,8 +916,8 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
if (end == 0) {
if (weighted) {
deform.setSize(deformLength, 0);
for (size_t i = 0; i < deformLength; ++i) {
deform[i] = 0;
for (size_t iiii = 0; iiii < deformLength; ++iiii) {
deform[iiii] = 0;
}
} else {
deform.clearAndAddAll(vertices);

View File

@ -643,7 +643,8 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
}
/* Linked meshes. */
for (int i = 0, n = _linkedMeshes.size(); i < n; ++i) {
int n = _linkedMeshes.size();
for (i = 0; i < n; ++i) {
LinkedMesh *linkedMesh = _linkedMeshes[i];
Skin *skin = linkedMesh->_skin.length() == 0 ? skeletonData->getDefaultSkin() : skeletonData->findSkin(
linkedMesh->_skin);
@ -1062,8 +1063,8 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) {
VertexAttachment *attachment = static_cast<VertexAttachment *>(baseAttachment);
weighted = attachment->_bones.size() != 0;
Vector<float> &vertices = attachment->_vertices;
deformLength = weighted ? vertices.size() / 3 * 2 : vertices.size();
Vector<float> &verts = attachment->_vertices;
deformLength = weighted ? verts.size() / 3 * 2 : verts.size();
timeline = new(__FILE__, __LINE__) DeformTimeline(timelineMap->_size);
@ -1072,34 +1073,34 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) {
for (valueMap = timelineMap->_child, frameIndex = 0; valueMap; valueMap = valueMap->_next, ++frameIndex) {
Json *vertices = Json::getItem(valueMap, "vertices");
Vector<float> deform;
Vector<float> deformed;
if (!vertices) {
if (weighted) {
deform.setSize(deformLength, 0);
deformed.setSize(deformLength, 0);
} else {
deform.clearAndAddAll(attachment->_vertices);
deformed.clearAndAddAll(attachment->_vertices);
}
} else {
int v, start = Json::getInt(valueMap, "offset", 0);
Json *vertex;
deform.setSize(deformLength, 0);
deformed.setSize(deformLength, 0);
if (_scale == 1) {
for (vertex = vertices->_child, v = start; vertex; vertex = vertex->_next, ++v) {
deform[v] = vertex->_valueFloat;
deformed[v] = vertex->_valueFloat;
}
} else {
for (vertex = vertices->_child, v = start; vertex; vertex = vertex->_next, ++v) {
deform[v] = vertex->_valueFloat * _scale;
deformed[v] = vertex->_valueFloat * _scale;
}
}
if (!weighted) {
Vector<float> &verticesAttachment = attachment->_vertices;
for (v = 0; v < deformLength; ++v) {
deform[v] += verticesAttachment[v];
deformed[v] += verticesAttachment[v];
}
}
}
timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), deform);
timeline->setFrame(frameIndex, Json::getFloat(valueMap, "time", 0), deformed);
readCurve(valueMap, timeline, frameIndex);
}

View File

@ -233,11 +233,11 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
if (vertexEffect != 0) {
tempUvs.clear();
tempColors.clear();
for (int i = 0; i < verticesCount; i++) {
for (int ii = 0; ii < verticesCount; ii++) {
Color vertexColor = light;
Color dark;
dark.r = dark.g = dark.b = dark.a = 0;
int index = i << 1;
int index = ii << 1;
float x = (*vertices)[index];
float y = (*vertices)[index + 1];
float u = (*uvs)[index];
@ -250,8 +250,8 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
tempColors.add(vertexColor);
}
for (int i = 0; i < indicesCount; ++i) {
int index = (*indices)[i] << 1;
for (int ii = 0; ii < indicesCount; ++ii) {
int index = (*indices)[ii] << 1;
vertex.position.x = (*vertices)[index];
vertex.position.y = (*vertices)[index + 1];
vertex.texCoords.x = (*uvs)[index] * size.x;