mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 01:06:00 +08:00
Fixes issue with visual studio not defining M_PI in math.h. Fixed all compiler warnings.
This commit is contained in:
parent
0833be847e
commit
4e61263551
@ -1,6 +1,7 @@
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <cctype>
|
||||
#include <stdexcept>
|
||||
#include <spine/BaseAtlas.h>
|
||||
@ -168,8 +169,8 @@ void BaseAtlas::load (const char *current, const char *end) {
|
||||
region->originalHeight = atoi(tuple[1].c_str());
|
||||
|
||||
readTuple(current, end, value, tuple);
|
||||
region->offsetX = atoi(tuple[0].c_str());
|
||||
region->offsetY = atoi(tuple[1].c_str());
|
||||
region->offsetX = (float)atoi(tuple[0].c_str());
|
||||
region->offsetY = (float)atoi(tuple[1].c_str());
|
||||
|
||||
region->index = atoi(readValue(current, end, value).c_str());
|
||||
}
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
#include <math.h>
|
||||
#include <spine/BaseRegionAttachment.h>
|
||||
|
||||
#ifndef M_PI // fix for windows removing precious information
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
namespace spine {
|
||||
|
||||
BaseRegionAttachment::BaseRegionAttachment () :
|
||||
@ -22,7 +26,7 @@ void BaseRegionAttachment::updateOffset () {
|
||||
localY *= scaleY;
|
||||
localX2 *= scaleX;
|
||||
localY2 *= scaleY;
|
||||
float radians = rotation * M_PI / 180;
|
||||
float radians = (float)(rotation * M_PI / 180);
|
||||
float cos = cosf(radians);
|
||||
float sin = sinf(radians);
|
||||
float localXCos = localX * cos + x;
|
||||
|
||||
@ -91,25 +91,25 @@ Bone* BaseSkeleton::getRootBone () const {
|
||||
}
|
||||
|
||||
Bone* BaseSkeleton::findBone (const string &boneName) const {
|
||||
for (int i = 0; i < bones.size(); i++)
|
||||
for (unsigned int i = 0; i < bones.size(); i++)
|
||||
if (data->bones[i]->name == boneName) return bones[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BaseSkeleton::findBoneIndex (const string &boneName) const {
|
||||
for (int i = 0; i < bones.size(); i++)
|
||||
for (unsigned int i = 0; i < bones.size(); i++)
|
||||
if (data->bones[i]->name == boneName) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Slot* BaseSkeleton::findSlot (const string &slotName) const {
|
||||
for (int i = 0; i < slots.size(); i++)
|
||||
for (unsigned int i = 0; i < slots.size(); i++)
|
||||
if (data->slots[i]->name == slotName) return slots[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BaseSkeleton::findSlotIndex (const string &slotName) const {
|
||||
for (int i = 0; i < slots.size(); i++)
|
||||
for (unsigned int i = 0; i < slots.size(); i++)
|
||||
if (data->slots[i]->name == slotName) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
||||
|
||||
Json::Value bones = root["bones"];
|
||||
skeletonData->bones.reserve(bones.size());
|
||||
for (int i = 0; i < bones.size(); ++i) {
|
||||
for (unsigned int i = 0; i < bones.size(); ++i) {
|
||||
Json::Value boneMap = bones[i];
|
||||
string boneName = boneMap["name"].asString();
|
||||
|
||||
@ -85,12 +85,12 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
||||
if (!boneData->parent) throw runtime_error("Parent bone not found: " + boneName);
|
||||
}
|
||||
|
||||
boneData->length = boneMap.get("length", 0).asDouble() * scale;
|
||||
boneData->x = boneMap.get("x", 0).asDouble() * scale;
|
||||
boneData->y = boneMap.get("y", 0).asDouble() * scale;
|
||||
boneData->rotation = boneMap.get("rotation", 0).asDouble();
|
||||
boneData->scaleX = boneMap.get("scaleX", 1).asDouble();
|
||||
boneData->scaleY = boneMap.get("scaleY", 1).asDouble();
|
||||
boneData->length = (float)(boneMap.get("length", 0).asDouble() * scale);
|
||||
boneData->x = (float)(boneMap.get("x", 0).asDouble() * scale);
|
||||
boneData->y = (float)(boneMap.get("y", 0).asDouble() * scale);
|
||||
boneData->rotation = (float)(boneMap.get("rotation", 0).asDouble());
|
||||
boneData->scaleX = (float)(boneMap.get("scaleX", 1).asDouble());
|
||||
boneData->scaleY = (float)(boneMap.get("scaleY", 1).asDouble());
|
||||
boneData->flipY = flipY;
|
||||
|
||||
skeletonData->bones.push_back(boneData);
|
||||
@ -99,7 +99,7 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
||||
Json::Value slots = root["slots"];
|
||||
if (!slots.isNull()) {
|
||||
skeletonData->slots.reserve(slots.size());
|
||||
for (int i = 0; i < slots.size(); ++i) {
|
||||
for (unsigned int i = 0; i < slots.size(); ++i) {
|
||||
Json::Value slotMap = slots[i];
|
||||
string slotName = slotMap["name"].asString();
|
||||
|
||||
@ -127,7 +127,7 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
||||
Json::Value skinsMap = root["skins"];
|
||||
vector<string> skinNames = skinsMap.getMemberNames();
|
||||
skeletonData->skins.reserve(skinNames.size());
|
||||
for (int i = 0; i < skinNames.size(); i++) {
|
||||
for (unsigned int i = 0; i < skinNames.size(); i++) {
|
||||
string skinName = skinNames[i];
|
||||
Skin *skin = new Skin(skinName);
|
||||
skeletonData->skins.push_back(skin);
|
||||
@ -135,13 +135,13 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
||||
|
||||
Json::Value slotMap = skinsMap[skinName];
|
||||
vector<string> slotNames = slotMap.getMemberNames();
|
||||
for (int i = 0; i < slotNames.size(); i++) {
|
||||
for (unsigned int i = 0; i < slotNames.size(); i++) {
|
||||
string slotName = slotNames[i];
|
||||
int slotIndex = skeletonData->findSlotIndex(slotName);
|
||||
|
||||
Json::Value attachmentsMap = slotMap[slotName];
|
||||
vector<string> attachmentNames = attachmentsMap.getMemberNames();
|
||||
for (int i = 0; i < attachmentNames.size(); i++) {
|
||||
for (unsigned int i = 0; i < attachmentNames.size(); i++) {
|
||||
string attachmentName = attachmentNames[i];
|
||||
Json::Value attachmentMap = attachmentsMap[attachmentName];
|
||||
|
||||
@ -159,13 +159,13 @@ SkeletonData* BaseSkeletonJson::readSkeletonData (const char *begin, const char
|
||||
|
||||
if (type == region || type == regionSequence) {
|
||||
BaseRegionAttachment *regionAttachment = reinterpret_cast<BaseRegionAttachment*>(attachment);
|
||||
regionAttachment->x = attachmentMap.get("x", 0).asDouble() * scale;
|
||||
regionAttachment->y = attachmentMap.get("y", 0).asDouble() * scale;
|
||||
regionAttachment->scaleX = attachmentMap.get("scaleX", 1).asDouble();
|
||||
regionAttachment->scaleY = attachmentMap.get("scaleY", 1).asDouble();
|
||||
regionAttachment->rotation = attachmentMap.get("rotation", 0).asDouble();
|
||||
regionAttachment->width = attachmentMap.get("width", 32).asDouble() * scale;
|
||||
regionAttachment->height = attachmentMap.get("height", 32).asDouble() * scale;
|
||||
regionAttachment->x = (float)(attachmentMap.get("x", 0).asDouble() * scale);
|
||||
regionAttachment->y = (float)(attachmentMap.get("y", 0).asDouble() * scale);
|
||||
regionAttachment->scaleX = (float)(attachmentMap.get("scaleX", 1).asDouble());
|
||||
regionAttachment->scaleY = (float)(attachmentMap.get("scaleY", 1).asDouble());
|
||||
regionAttachment->rotation = (float)(attachmentMap.get("rotation", 0).asDouble());
|
||||
regionAttachment->width = (float)(attachmentMap.get("width", 32).asDouble() * scale);
|
||||
regionAttachment->height = (float)(attachmentMap.get("height", 32).asDouble() * scale);
|
||||
}
|
||||
|
||||
skin->addAttachment(slotIndex, attachmentName, attachment);
|
||||
@ -204,7 +204,7 @@ static void readCurve (CurveTimeline *timeline, int keyframeIndex, const Json::V
|
||||
if (curve.isString() && curve.asString() == "stepped")
|
||||
timeline->setStepped(keyframeIndex);
|
||||
else if (curve.isArray())
|
||||
timeline->setCurve(keyframeIndex, curve[0u].asDouble(), curve[1u].asDouble(), curve[2u].asDouble(), curve[3u].asDouble());
|
||||
timeline->setCurve(keyframeIndex, (float)curve[0u].asDouble(), (float)curve[1u].asDouble(), (float)curve[2u].asDouble(), (float)curve[3u].asDouble());
|
||||
}
|
||||
|
||||
Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end, const SkeletonData *skeletonData) const {
|
||||
@ -228,14 +228,14 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
||||
|
||||
Json::Value bones = root["bones"];
|
||||
vector<string> boneNames = bones.getMemberNames();
|
||||
for (int i = 0; i < boneNames.size(); i++) {
|
||||
for (unsigned int i = 0; i < boneNames.size(); i++) {
|
||||
string boneName = boneNames[i];
|
||||
int boneIndex = skeletonData->findBoneIndex(boneName);
|
||||
if (boneIndex == -1) throw runtime_error("Bone not found: " + boneName);
|
||||
|
||||
Json::Value timelineMap = bones[boneName];
|
||||
vector<string> timelineNames = timelineMap.getMemberNames();
|
||||
for (int i = 0; i < timelineNames.size(); i++) {
|
||||
for (unsigned int i = 0; i < timelineNames.size(); i++) {
|
||||
string timelineName = timelineNames[i];
|
||||
Json::Value values = timelineMap[timelineName];
|
||||
|
||||
@ -244,11 +244,11 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
||||
timeline->boneIndex = boneIndex;
|
||||
|
||||
int keyframeIndex = 0;
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
for (unsigned int i = 0; i < values.size(); i++) {
|
||||
Json::Value valueMap = values[i];
|
||||
|
||||
float time = valueMap["time"].asDouble();
|
||||
timeline->setKeyframe(keyframeIndex, time, valueMap["angle"].asDouble());
|
||||
float time = (float)valueMap["time"].asDouble();
|
||||
timeline->setKeyframe(keyframeIndex, time, (float)valueMap["angle"].asDouble());
|
||||
readCurve(timeline, keyframeIndex, valueMap);
|
||||
keyframeIndex++;
|
||||
}
|
||||
@ -267,14 +267,14 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
||||
timeline->boneIndex = boneIndex;
|
||||
|
||||
int keyframeIndex = 0;
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
for (unsigned int i = 0; i < values.size(); i++) {
|
||||
Json::Value valueMap = values[i];
|
||||
|
||||
float time = valueMap["time"].asDouble();
|
||||
float time = (float)valueMap["time"].asDouble();
|
||||
timeline->setKeyframe(keyframeIndex, //
|
||||
valueMap["time"].asDouble(), //
|
||||
valueMap.get("x", 0).asDouble() * timelineScale, //
|
||||
valueMap.get("y", 0).asDouble() * timelineScale);
|
||||
(float)valueMap["time"].asDouble(), //
|
||||
(float)valueMap.get("x", 0).asDouble() * timelineScale, //
|
||||
(float)valueMap.get("y", 0).asDouble() * timelineScale);
|
||||
readCurve(timeline, keyframeIndex, valueMap);
|
||||
keyframeIndex++;
|
||||
}
|
||||
@ -290,14 +290,14 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
||||
Json::Value slots = root["slots"];
|
||||
if (!slots.isNull()) {
|
||||
vector<string> slotNames = slots.getMemberNames();
|
||||
for (int i = 0; i < slotNames.size(); i++) {
|
||||
for (unsigned int i = 0; i < slotNames.size(); i++) {
|
||||
string slotName = slotNames[i];
|
||||
int slotIndex = skeletonData->findSlotIndex(slotName);
|
||||
if (slotIndex == -1) throw runtime_error("Slot not found: " + slotName);
|
||||
|
||||
Json::Value timelineMap = slots[slotName];
|
||||
vector<string> timelineNames = timelineMap.getMemberNames();
|
||||
for (int i = 0; i < timelineNames.size(); i++) {
|
||||
for (unsigned int i = 0; i < timelineNames.size(); i++) {
|
||||
string timelineName = timelineNames[i];
|
||||
Json::Value values = timelineMap[timelineName];
|
||||
|
||||
@ -306,11 +306,11 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
||||
timeline->slotIndex = slotIndex;
|
||||
|
||||
int keyframeIndex = 0;
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
for (unsigned int i = 0; i < values.size(); i++) {
|
||||
Json::Value valueMap = values[i];
|
||||
|
||||
string s = valueMap["color"].asString();
|
||||
timeline->setKeyframe(keyframeIndex, valueMap["time"].asDouble(), //
|
||||
timeline->setKeyframe(keyframeIndex, (float)valueMap["time"].asDouble(), //
|
||||
toColor(s, 0), toColor(s, 1), toColor(s, 2), toColor(s, 3));
|
||||
readCurve(timeline, keyframeIndex, valueMap);
|
||||
keyframeIndex++;
|
||||
@ -323,11 +323,11 @@ Animation* BaseSkeletonJson::readAnimation (const char *begin, const char *end,
|
||||
timeline->slotIndex = slotIndex;
|
||||
|
||||
int keyframeIndex = 0;
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
for (unsigned int i = 0; i < values.size(); i++) {
|
||||
Json::Value valueMap = values[i];
|
||||
|
||||
Json::Value name = valueMap["name"];
|
||||
timeline->setKeyframe(keyframeIndex++, valueMap["time"].asDouble(), name.isNull() ? "" : name.asString());
|
||||
timeline->setKeyframe(keyframeIndex++, (float)valueMap["time"].asDouble(), name.isNull() ? "" : name.asString());
|
||||
}
|
||||
timelines.push_back(timeline);
|
||||
if (timeline->getDuration() > duration) duration = timeline->getDuration();
|
||||
|
||||
@ -3,6 +3,11 @@
|
||||
#include <spine/Bone.h>
|
||||
#include <spine/BoneData.h>
|
||||
|
||||
|
||||
#ifndef M_PI // fix for windows removing precious information
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
namespace spine {
|
||||
|
||||
Bone::Bone (BoneData *data) :
|
||||
@ -38,7 +43,7 @@ void Bone::updateWorldTransform (bool flipX, bool flipY) {
|
||||
worldScaleY = scaleY;
|
||||
worldRotation = rotation;
|
||||
}
|
||||
float radians = worldRotation * M_PI / 180;
|
||||
float radians = (float)(worldRotation * M_PI / 180);
|
||||
float cos = cosf(radians);
|
||||
float sin = sinf(radians);
|
||||
m00 = cos * worldScaleX;
|
||||
|
||||
@ -21,31 +21,31 @@ SkeletonData::~SkeletonData () {
|
||||
}
|
||||
|
||||
BoneData* SkeletonData::findBone (const string &boneName) const {
|
||||
for (int i = 0; i < bones.size(); i++)
|
||||
for (unsigned int i = 0; i < bones.size(); i++)
|
||||
if (bones[i]->name == boneName) return bones[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SkeletonData::findBoneIndex (const string &boneName) const {
|
||||
for (int i = 0; i < bones.size(); i++)
|
||||
for (unsigned int i = 0; i < bones.size(); i++)
|
||||
if (bones[i]->name == boneName) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SlotData* SkeletonData::findSlot (const string &slotName) const {
|
||||
for (int i = 0; i < slots.size(); i++)
|
||||
for (unsigned int i = 0; i < slots.size(); i++)
|
||||
if (slots[i]->name == slotName) return slots[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SkeletonData::findSlotIndex (const string &slotName) const {
|
||||
for (int i = 0; i < slots.size(); i++)
|
||||
for (unsigned int i = 0; i < slots.size(); i++)
|
||||
if (slots[i]->name == slotName) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Skin* SkeletonData::findSkin (const string &skinName) {
|
||||
for (int i = 0; i < skins.size(); i++)
|
||||
for (unsigned int i = 0; i < skins.size(); i++)
|
||||
if (skins[i]->name == skinName) return skins[i];
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user